From 74d629665c05293cc22172330410258bd2ae7f47 Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Tue, 5 Mar 2024 18:02:33 -0500 Subject: [PATCH] JStudio_JStage control OK --- configure.py | 2 +- include/JSystem/JStage/JSGObject.h | 10 ++ include/JSystem/JStage/JSGSystem.h | 10 -- .../JSystem/JStudio/JStudio/jstudio-object.h | 2 +- .../JSystem/JStudio/JStudio_JStage/control.h | 37 ++-- .../JStudio/JStudio_JStage/control.cpp | 163 +++++++++++++++++- 6 files changed, 188 insertions(+), 36 deletions(-) diff --git a/configure.py b/configure.py index e4f4c17dd..6c0dc034c 100644 --- a/configure.py +++ b/configure.py @@ -616,7 +616,7 @@ config.libs = [ JSystemLib( "JStudio_JStage", [ - Object(NonMatching, "JSystem/JStudio/JStudio_JStage/control.cpp"), + Object(Matching, "JSystem/JStudio/JStudio_JStage/control.cpp"), Object(NonMatching, "JSystem/JStudio/JStudio_JStage/object.cpp"), Object(NonMatching, "JSystem/JStudio/JStudio_JStage/object-actor.cpp"), Object(NonMatching, "JSystem/JStudio/JStudio_JStage/object-ambientlight.cpp"), diff --git a/include/JSystem/JStage/JSGObject.h b/include/JSystem/JStage/JSGObject.h index f3e9c9532..6ea8593f4 100644 --- a/include/JSystem/JStage/JSGObject.h +++ b/include/JSystem/JStage/JSGObject.h @@ -4,6 +4,16 @@ #include "dolphin/mtx/mtxvec.h" namespace JStage { + enum TEObject { + /* 0x0 */ TOBJ_ACTOR_UNK, + /* 0x1 */ TOBJ_UNK1, + /* 0x2 */ TOBJ_ACTOR, + /* 0x3 */ TOBJ_CAMERA, + /* 0x4 */ TOBJ_AMBIENT, + /* 0x5 */ TOBJ_LIGHT, + /* 0x6 */ TOBJ_FOG, + }; + struct TObject { virtual ~TObject() = 0; virtual s32 JSGFGetType() const = 0; diff --git a/include/JSystem/JStage/JSGSystem.h b/include/JSystem/JStage/JSGSystem.h index 9b060f89e..b6d7ef711 100644 --- a/include/JSystem/JStage/JSGSystem.h +++ b/include/JSystem/JStage/JSGSystem.h @@ -4,16 +4,6 @@ #include "JSystem/JStage/JSGObject.h" namespace JStage { - enum TEObject { - /* 0x0 */ TOBJ_ACTOR_UNK, - /* 0x1 */ TOBJ_UNK1, - /* 0x2 */ TOBJ_ACTOR, - /* 0x3 */ TOBJ_CAMERA, - /* 0x4 */ TOBJ_AMBIENT, - /* 0x5 */ TOBJ_LIGHT, - /* 0x6 */ TOBJ_FOG, - }; - struct TSystem : public TObject { virtual ~TSystem() = 0; virtual s32 JSGFGetType() const; diff --git a/include/JSystem/JStudio/JStudio/jstudio-object.h b/include/JSystem/JStudio/JStudio/jstudio-object.h index 26c4da622..b5a2a7abd 100644 --- a/include/JSystem/JStudio/JStudio/jstudio-object.h +++ b/include/JSystem/JStudio/JStudio/jstudio-object.h @@ -256,7 +256,7 @@ struct TAdaptor_camera : public TAdaptor { } virtual ~TAdaptor_camera() = 0; - /* 0x10 */ TVariableValue mValue[12]; + /* 0x10 */ TVariableValue mValue[11]; static u8 const sauVariableValue_3_POSITION_XYZ[12]; static u8 const sauVariableValue_3_TARGET_POSITION_XYZ[12]; diff --git a/include/JSystem/JStudio/JStudio_JStage/control.h b/include/JSystem/JStudio/JStudio_JStage/control.h index 106b14d25..2c0c78e83 100644 --- a/include/JSystem/JStudio/JStudio_JStage/control.h +++ b/include/JSystem/JStudio/JStudio_JStage/control.h @@ -12,14 +12,14 @@ namespace JStudio_JStage { struct TCreateObject : public JStudio::TCreateObject { TCreateObject(const JStage::TSystem* pSystem) { - pJSGSystem_ = pSystem; + mSystem = pSystem; } virtual ~TCreateObject(); virtual bool create(JStudio::TObject**, JStudio::stb::data::TParse_TBlock_object const&); - virtual void find(const JStudio::stb::data::TParse_TBlock_object&, JStage::TEObject); + virtual JStage::TObject* find(const JStudio::stb::data::TParse_TBlock_object&, JStage::TEObject); - /* 0x0C */ const JStage::TSystem* pJSGSystem_; + /* 0x0C */ const JStage::TSystem* mSystem; }; struct TAdaptor_object_ { @@ -27,8 +27,8 @@ struct TAdaptor_object_ { void adaptor_ENABLE_(JStage::TObject*, JStudio::data::TEOperationData, void const*, u32); /* 0x0 */ JStudio::TAdaptor* field_0x0; - /* 0x4 */ JStage::TSystem* pJSGSystem_; - /* 0x8 */ JStage::TObject* pJSGObject_; + /* 0x4 */ JStage::TSystem* mSystem; + /* 0x8 */ JStage::TObject* mObject; }; struct TAdaptor_actor : public JStudio::TAdaptor_actor, public JStudio_JStage::TAdaptor_object_ { @@ -74,15 +74,8 @@ struct TAdaptor_actor : public JStudio::TAdaptor_actor, public JStudio_JStage::T static u8 saoVVOutput_[64]; static u8 saoVVOutput_ANIMATION_FRAME_[144 + 4 /* padding */]; - /* 0x134 */ u32 field_0x134; - /* 0x138 */ u32 field_0x138; - /* 0x13C */ u32 field_0x13c; - /* 0x140 */ u32 field_0x140; - /* 0x144 */ u32 field_0x144; - /* 0x148 */ u8 field_0x148; - /* 0x14C */ u32 field_0x14c; - /* 0x150 */ u32 field_0x150; -}; + /* 0x130 */ u8 field_0x130[0x144 - 0x130]; +}; // Size: 0x144 struct TAdaptor_ambientLight : public JStudio::TAdaptor_ambientLight { TAdaptor_ambientLight(JStage::TSystem const*, JStage::TAmbientLight*); @@ -93,7 +86,9 @@ struct TAdaptor_ambientLight : public JStudio::TAdaptor_ambientLight { virtual void adaptor_do_end(const JStudio::TObject*); virtual void adaptor_do_update(const JStudio::TObject*, u32); virtual void adaptor_do_data(const JStudio::TObject*, void const*, u32, void const*, u32); -}; + + /* 0x5C */ u8 field_0x5C[0x64- 0x5C]; +}; // Size: 0x64 struct TAdaptor_camera : public JStudio::TAdaptor_camera { TAdaptor_camera(JStage::TSystem const*, JStage::TCamera*); @@ -120,7 +115,9 @@ struct TAdaptor_camera : public JStudio::TAdaptor_camera { void getJSG_targetPosition_(JStudio::TControl const*); static u8 saoVVOutput_[160 + 4 /* padding */]; -}; + + /* 0xE8 */ u8 field_0xE8[0xF8 - 0xE8]; +}; // Size: 0xF8 struct TAdaptor_fog : public JStudio::TAdaptor_fog { TAdaptor_fog(JStage::TSystem const*, JStage::TFog*); @@ -132,7 +129,9 @@ struct TAdaptor_fog : public JStudio::TAdaptor_fog { virtual void adaptor_do_data(const JStudio::TObject*, void const*, u32, void const*, u32); static u8 saoVVOutput_[96 + 4 /* padding */]; -}; + + /* 0x84 */ u8 field_0x110[0x8C - 0x84]; +}; // Size: 0x8C struct TAdaptor_light : public JStudio::TAdaptor_light { struct TVVOutput_direction_ { @@ -151,7 +150,9 @@ struct TAdaptor_light : public JStudio::TAdaptor_light { virtual void adaptor_do_FACULTY(JStudio::data::TEOperationData, void const*, u32); static u8 saoVVOutput_direction_[72]; -}; + + /* 0x110 */ u8 field_0x110[0x11C - 0x110]; +}; // Size: 0x11C void transform_toGlobalFromLocal(f32 (*)[4], diff --git a/src/JSystem/JStudio/JStudio_JStage/control.cpp b/src/JSystem/JStudio/JStudio_JStage/control.cpp index 0c0495b7e..e7778930b 100644 --- a/src/JSystem/JStudio/JStudio_JStage/control.cpp +++ b/src/JSystem/JStudio/JStudio_JStage/control.cpp @@ -6,17 +6,168 @@ #include "JSystem/JStudio/JStudio_JStage/control.h" #include "dolphin/types.h" +namespace JStudio_JStage { + +namespace { +// Fake inline. +// TODO: supposed to use JStudio::TObject::createFromAdaptor instead of this somehow +static inline JStudio::TObject* doCreateObject(const JStudio::stb::data::TParse_TBlock_object& data, TAdaptor_actor* adaptor) +{ + JStudio::TObject* object = new JStudio::TObject_actor(data, adaptor); + if (object == NULL) { + // TODO: This should probably delete the adaptor in NONMATCHING builds, if the object couldn't get created. + return NULL; + } else { + if (object->mpAdaptor != NULL) { + object->mpAdaptor->adaptor_do_prepare(object); + } + } + return object; +} + +static inline JStudio::TObject* doCreateObject(const JStudio::stb::data::TParse_TBlock_object& data, TAdaptor_camera* adaptor) +{ + JStudio::TObject* object = new JStudio::TObject_camera(data, adaptor); + if (object == NULL) { + // TODO: This should probably delete the adaptor in NONMATCHING builds, if the object couldn't get created. + return NULL; + } else { + if (object->mpAdaptor != NULL) { + object->mpAdaptor->adaptor_do_prepare(object); + } + } + return object; +} + +static inline JStudio::TObject* doCreateObject(const JStudio::stb::data::TParse_TBlock_object& data, TAdaptor_ambientLight* adaptor) +{ + JStudio::TObject* object = new JStudio::TObject_ambientLight(data, adaptor); + if (object == NULL) { + // TODO: This should probably delete the adaptor in NONMATCHING builds, if the object couldn't get created. + return NULL; + } else { + if (object->mpAdaptor != NULL) { + object->mpAdaptor->adaptor_do_prepare(object); + } + } + return object; +} + +static inline JStudio::TObject* doCreateObject(const JStudio::stb::data::TParse_TBlock_object& data, TAdaptor_light* adaptor) +{ + JStudio::TObject* object = new JStudio::TObject_light(data, adaptor); + if (object == NULL) { + // TODO: This should probably delete the adaptor in NONMATCHING builds, if the object couldn't get created. + return NULL; + } else { + if (object->mpAdaptor != NULL) { + object->mpAdaptor->adaptor_do_prepare(object); + } + } + return object; +} + +static inline JStudio::TObject* doCreateObject(const JStudio::stb::data::TParse_TBlock_object& data, TAdaptor_fog* adaptor) +{ + JStudio::TObject* object = new JStudio::TObject_fog(data, adaptor); + if (object == NULL) { + // TODO: This should probably delete the adaptor in NONMATCHING builds, if the object couldn't get created. + return NULL; + } else { + if (object->mpAdaptor != NULL) { + object->mpAdaptor->adaptor_do_prepare(object); + } + } + return object; +} + +typedef JStudio::TObject* (*CreateObjectFunction)(const JStudio::stb::data::TParse_TBlock_object&, JStage::TObject*, + const JStage::TSystem*); + +template +JStudio::TObject* createObject_JSG_(const JStudio::stb::data::TParse_TBlock_object& data, JStage::TObject* stageObject, + const JStage::TSystem* system); + +} // namespace + /* 80275BAC-80275C0C .text __dt__Q214JStudio_JStage13TCreateObjectFv */ -JStudio_JStage::TCreateObject::~TCreateObject() { - /* Nonmatching */ +TCreateObject::~TCreateObject() {} + +static void dummy() { + // fakematch to reverse the weak function ordering + CreateObjectFunction function; + function = &createObject_JSG_; + function = &createObject_JSG_; + function = &createObject_JSG_; + function = &createObject_JSG_; + function = &createObject_JSG_; } /* 80275C0C-80275D5C .text create__Q214JStudio_JStage13TCreateObjectFPPQ27JStudio7TObjectRCQ47JStudio3stb4data20TParse_TBlock_object */ -bool JStudio_JStage::TCreateObject::create(JStudio::TObject**, const JStudio::stb::data::TParse_TBlock_object&) { - /* Nonmatching */ +bool TCreateObject::create(JStudio::TObject** newObject, const JStudio::stb::data::TParse_TBlock_object& data) { + JStage::TEObject type; + CreateObjectFunction function; + switch (data.get()->type) { + case 'JACT': + function = &createObject_JSG_; + type = JStage::TOBJ_ACTOR; + break; + case 'JCMR': + function = &createObject_JSG_; + type = JStage::TOBJ_CAMERA; + break; + case 'JABL': + function = &createObject_JSG_; + type = JStage::TOBJ_AMBIENT; + break; + case 'JLIT': + function = &createObject_JSG_; + type = JStage::TOBJ_LIGHT; + break; + case 'JFOG': + function = &createObject_JSG_; + type = JStage::TOBJ_FOG; + break; + default: + return false; + } + + JStage::TObject* stageObject = find(data, type); + if (stageObject == NULL) { + return false; + } + *newObject = function(data, stageObject, mSystem); + return true; } /* 80275D5C-80275DDC .text find__Q214JStudio_JStage13TCreateObjectFRCQ47JStudio3stb4data20TParse_TBlock_objectQ26JStage8TEObject */ -void JStudio_JStage::TCreateObject::find(const JStudio::stb::data::TParse_TBlock_object&, JStage::TEObject) { - /* Nonmatching */ +JStage::TObject* TCreateObject::find(const JStudio::stb::data::TParse_TBlock_object& data, JStage::TEObject type) { + JStage::TObject* stageObject = (JStage::TObject*)mSystem->JSGFindObject((const char*)data.get_ID(), type); + if (stageObject == NULL) { + return NULL; + } + JStage::TEObject foundType = (JStage::TEObject)stageObject->JSGFGetType(); + if (foundType != type) { + return NULL; + } + return stageObject; } + +namespace { + +template +JStudio::TObject* createObject_JSG_(const JStudio::stb::data::TParse_TBlock_object& data, JStage::TObject* stageObject, + const JStage::TSystem* system) +{ + Object* obj = (Object*)stageObject; + Adaptor* adaptor = new Adaptor(system, obj); + if (!adaptor) { + return NULL; + } + + return doCreateObject(data, adaptor); +} + +} // namespace + +} // namespace JStudio_JStage