summaryrefslogtreecommitdiff
path: root/src/KingSystem/ActorSystem/actActorCaptureMgr.cpp
blob: 32f1525b2fb723e01c75767b0bbcd2b0c9bc2fde (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "KingSystem/ActorSystem/actActorCaptureMgr.h"
#include "KingSystem/ActorSystem/actActor.h"
#include "KingSystem/Resource/resEntryFactory.h"
#include "KingSystem/Resource/resLoadRequest.h"
#include "KingSystem/Resource/resResourceMgrTask.h"
#include "KingSystem/Resource/resSystem.h"
#include "KingSystem/Utils/SafeDelete.h"

namespace ksys::act {

ActorCaptureMgr::ActorCaptureMgr() {
    mRes.reset();
    mTimer.reset(30.0);
}

ActorCaptureMgr::~ActorCaptureMgr() {
    mActor = nullptr;
    mCamera = nullptr;
    res::unregisterEntryFactory(mFactory);
    util::safeDelete(mFactory);
}

void ActorCaptureMgr::init(const InitArg& arg) {
    mFactory = new (arg.heap) res::EntryFactory<res::ActorCapture>(1.0, 0x1000);
    res::registerEntryFactory(mFactory, "bactcapt");

    res::LoadRequest req;
    req.mRequester = "ActorCaptureMgr";
    req._26 = false;
    mDummyFile.load("Actor/ActorCapture/Dummy.bactcapt", &req);
}

void ActorCaptureMgr::setCamera(Camera* camera) {
    if (camera)
        mCamera = camera;
}

void ActorCaptureMgr::loadCaptureParam() {
    if (!mActor || !mActor->getParam())
        return;

    const char* name = getCapturedActorName();
    if (!name)
        return;

    res::ActorCapture* param = nullptr;

    {
        res::LoadRequest req;
        req.mRequester = "ActorCaptureMgr";
        sead::FormatFixedSafeString<128> path("Actor/ActorCapture/%s.bactcapt", name);
        res::ResourceMgrTask::instance()->controlField9c0d88(false);
        auto* file = sead::DynamicCast<res::ActorCapture>(mCaptureParamFile.load(path, &req));
        res::ResourceMgrTask::instance()->controlField9c0d88(true);
        if (file)
            param = file;
        if (!param)
            param = sead::DynamicCast<res::ActorCapture>(mDummyFile.getResource());
    }

    mRes.mCameraInfoObj.copy(param->mCameraInfoObj);
    mRes.mActorInfoObj.copy(param->mActorInfoObj);
    mRes.mLightInfoObj.copy(param->mLightInfoObj);
}

}  // namespace ksys::act