From 7d2ef1d6b2a7cdfdc54c956a39e21abf994c5594 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sun, 8 Nov 2020 18:47:26 +0100 Subject: [PATCH] ksys/act: Start adding ActorCaptureMgr --- data/uking_functions.csv | 14 ++-- src/KingSystem/ActorSystem/CMakeLists.txt | 2 + .../ActorSystem/actActorCaptureMgr.cpp | 66 +++++++++++++++++++ .../ActorSystem/actActorCaptureMgr.h | 59 +++++++++++++++++ .../Resource/resResourceActorCapture.cpp | 18 +++++ .../Resource/resResourceActorCapture.h | 2 + src/KingSystem/Resource/resSystem.h | 1 + 7 files changed, 155 insertions(+), 7 deletions(-) create mode 100644 src/KingSystem/ActorSystem/actActorCaptureMgr.cpp create mode 100644 src/KingSystem/ActorSystem/actActorCaptureMgr.h diff --git a/data/uking_functions.csv b/data/uking_functions.csv index 53dfdd8e..8936c72e 100644 --- a/data/uking_functions.csv +++ b/data/uking_functions.csv @@ -51834,19 +51834,19 @@ 0x000000710089ca9c,sub_710089CA9C,88, 0x000000710089caf4,sub_710089CAF4,88, 0x000000710089cb4c,sub_710089CB4C,40, -0x000000710089cb74,ActorCaptureMgr::ctor,276, -0x000000710089cc88,ActorCaptureMgr::init,332, -0x000000710089cdd4,ActorCaptureMgr::init2,12, +0x000000710089cb74,ActorCaptureMgr::ctor,276,_ZN4ksys3act15ActorCaptureMgrC1Ev +0x000000710089cc88,ActorCaptureMgr::init,332,_ZN4ksys3act15ActorCaptureMgr4initERKNS1_7InitArgE +0x000000710089cdd4,ActorCaptureMgr::init2,12,_ZN4ksys3act15ActorCaptureMgr9setCameraEPNS0_6CameraE 0x000000710089cde0,sub_710089CDE0,4112, 0x000000710089ddf0,_ZN4sead21FormatFixedSafeStringILi1024EEC2EPKcz,224, 0x000000710089ded0,sub_710089DED0,572, 0x000000710089e10c,sub_710089E10C,804, 0x000000710089e430,sub_710089E430,1028, -0x000000710089e834,ActorCaptureMgr::loadActorCapture,492, +0x000000710089e834,ActorCaptureMgr::loadActorCapture,492,_ZN4ksys3act15ActorCaptureMgr16loadCaptureParamEv 0x000000710089ea20,sub_710089EA20,1612, 0x000000710089f06c,sub_710089F06C,244, -0x000000710089f160,sub_710089F160,244, -0x000000710089f254,sub_710089F254,36, +0x000000710089f160,sub_710089F160,244,_ZN4ksys3act15ActorCaptureMgrD1Ev +0x000000710089f254,sub_710089F254,36,_ZN4ksys3act15ActorCaptureMgrD0Ev 0x000000710089f278,sub_710089F278,216, 0x000000710089f350,sub_710089F350,224, 0x000000710089f430,EntryFactoryBactcapt::rtti1,132, @@ -85567,7 +85567,7 @@ 0x0000007101089518,nullsub_4456,4,_ZThn632_N4ksys3res12ActorCapture9doCreate_EPhjPN4sead4HeapE 0x000000710108951c,sub_710108951C,72,_ZN4ksys3res12ActorCapture6parse_EPhmPN4sead4HeapE 0x0000007101089564,sub_7101089564,72,_ZThn632_N4ksys3res12ActorCapture6parse_EPhmPN4sead4HeapE -0x00000071010895ac,sub_71010895AC,664, +0x00000071010895ac,sub_71010895AC,664,_ZN4ksys3res12ActorCapture5resetEv 0x0000007101089844,sub_7101089844,180, 0x00000071010898f8,sub_71010898F8,168, 0x00000071010899a0,sub_71010899A0,8, diff --git a/src/KingSystem/ActorSystem/CMakeLists.txt b/src/KingSystem/ActorSystem/CMakeLists.txt index 5281ca87..a54d0e02 100644 --- a/src/KingSystem/ActorSystem/CMakeLists.txt +++ b/src/KingSystem/ActorSystem/CMakeLists.txt @@ -1,5 +1,7 @@ target_sources(uking PRIVATE actActor.h + actActorCaptureMgr.cpp + actActorCaptureMgr.h actActorConstDataAccess.cpp actActorConstDataAccess.h actActorCreator.cpp diff --git a/src/KingSystem/ActorSystem/actActorCaptureMgr.cpp b/src/KingSystem/ActorSystem/actActorCaptureMgr.cpp new file mode 100644 index 00000000..e1a530b5 --- /dev/null +++ b/src/KingSystem/ActorSystem/actActorCaptureMgr.cpp @@ -0,0 +1,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(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->mActorParam) + 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(mCaptureParamFile.load(path, &req)); + res::ResourceMgrTask::instance()->controlField9c0d88(true); + if (file) + param = file; + if (!param) + param = sead::DynamicCast(mDummyFile.getResource()); + } + + mRes.mCameraInfoObj.copy(param->mCameraInfoObj); + mRes.mActorInfoObj.copy(param->mActorInfoObj); + mRes.mLightInfoObj.copy(param->mLightInfoObj); +} + +} // namespace ksys::act diff --git a/src/KingSystem/ActorSystem/actActorCaptureMgr.h b/src/KingSystem/ActorSystem/actActorCaptureMgr.h new file mode 100644 index 00000000..c66e8ad3 --- /dev/null +++ b/src/KingSystem/ActorSystem/actActorCaptureMgr.h @@ -0,0 +1,59 @@ +#pragma once + +#include +#include +#include "KingSystem/Resource/resHandle.h" +#include "KingSystem/Resource/resResourceActorCapture.h" +#include "KingSystem/System/Timer.h" +#include "KingSystem/Utils/Types.h" + +namespace ksys::res { +class EntryFactoryBase; +} + +namespace ksys::act { + +class Actor; +class Camera; + +// TODO: incomplete +class ActorCaptureMgr { +public: + struct InitArg { + sead::Heap* heap; + }; + + ActorCaptureMgr(); + virtual ~ActorCaptureMgr(); + + void init(const InitArg& arg); + void setCamera(Camera* camera); + + void loadCaptureParam(); + const char* getCapturedActorName() const; + +private: + Actor* mActor{}; + Camera* mCamera{}; + res::EntryFactoryBase* mFactory{}; + res::Handle mDummyFile; + res::Handle mCaptureParamFile; + sead::FixedSafeString<64> mStr; + sead::FixedSafeString<256> mStr2; + res::ActorCapture mRes; + struct Field768 { + Field768() { + _76c = 0; + _768 = 0; + } + u32 _768; + u8 _76c; + } _768; + s32 _770 = -1; + u32 _774{}; + u32 _778{}; + Timer mTimer; +}; +KSYS_CHECK_SIZE_NX150(ActorCaptureMgr, 0x788); + +} // namespace ksys::act diff --git a/src/KingSystem/Resource/resResourceActorCapture.cpp b/src/KingSystem/Resource/resResourceActorCapture.cpp index 920d0737..f74f5c0e 100644 --- a/src/KingSystem/Resource/resResourceActorCapture.cpp +++ b/src/KingSystem/Resource/resResourceActorCapture.cpp @@ -40,4 +40,22 @@ bool ActorCapture::parse_(u8* data, size_t, sead::Heap*) { return true; } +void ActorCapture::reset() { + mCameraInfoObj.position.ref() = sConstants.camera_position; + mCameraInfoObj.direction.ref() = sConstants.camera_direction; + mCameraInfoObj.fov.ref() = 50; + mCameraInfoObj.tilt.ref() = 0; + + mActorInfoObj.position.ref() = sConstants.actor_position; + mActorInfoObj.rotation.ref() = sConstants.actor_rotation; + mActorInfoObj.as_name.ref().copy(sead::FixedSafeString<32>(sead::SafeString::cEmptyString)); + mActorInfoObj.apply_skel_anim.ref() = false; + mActorInfoObj.frame.ref() = 0; + mActorInfoObj.bounding_adjustment.ref() = false; + mActorInfoObj.force_idle.ref() = false; + mActorInfoObj.disable_cloth.ref() = false; + + mLightInfoObj.direction.ref() = sConstants.light_direction; +} + } // namespace ksys::res diff --git a/src/KingSystem/Resource/resResourceActorCapture.h b/src/KingSystem/Resource/resResourceActorCapture.h index a47b2105..f4c8e0da 100644 --- a/src/KingSystem/Resource/resResourceActorCapture.h +++ b/src/KingSystem/Resource/resResourceActorCapture.h @@ -55,6 +55,8 @@ public: bool needsParse() const override { return true; } bool ParamIO_m0() override { return true; } + void reset(); + static const ActorCaptureConstants& getConstants(); CameraInfo mCameraInfoObj; diff --git a/src/KingSystem/Resource/resSystem.h b/src/KingSystem/Resource/resSystem.h index f8a0d333..b617d323 100644 --- a/src/KingSystem/Resource/resSystem.h +++ b/src/KingSystem/Resource/resSystem.h @@ -7,6 +7,7 @@ namespace ksys::res { class EntryFactoryBase; void registerEntryFactory(EntryFactoryBase* factory, const sead::SafeString& name); +void unregisterEntryFactory(EntryFactoryBase* factory); // In release builds, the only thing this function does is return 1. // TODO: figure out what this is used for. Stubbed log function?