From de9c5d510175bba11ab8704e67be3a3a94f9149e Mon Sep 17 00:00:00 2001 From: MegaMech Date: Sun, 9 Nov 2025 19:07:44 -0700 Subject: Implement SpawnParams struct (#536) * Impl SpawnParams * Added json submodule * Update json * Update * Works * Remove comment * Works refactor * Snowman and thwomp working * Impl hot air balloon * More progress * All OObjects are done * cleanup * Refactor 2Dpath to normal path * Update nlohmann json & fix compile * Rest of actors * MORE CHANGES * Finish actors * Done PR, some fix to collision viewer * Impl falling rocks * Add const * wip editor refactor * Property work * continue * Overridable editor properties * Actor saving/loading works now * Fix light alignment * Clarification * Impl penguin * params impl signs * properties impl falling rock * More property impls * impl air balloon * Add spawnParams to OObject Translate * Snowman translate better * impl hedgehog properly * properties impl trophy * thwomp progress * Finish impl properties * Fix compile * Fix cursor collisions * Move registered actors * Rename pathPoint XYZ to xyz * Fix editor pause bug * Clean up * Review comments * Remove SpawnParams struct from actor classes * Rename * Player Label First Iteration * Work now * Working 3d text * Fix boo bug * Finish AText actor * Fix spawnparams compile * Register AText * Finish Text Actor * Fix thwomp interpolation * Fix compile * Fix crab and hedgehog * Fix loading flagpole * Fix Hot Air Balloon * Turn zbuffer on for AText * Update --------- Co-authored-by: MegaMech <7255464+MegaMech@users.noreply.github.com> --- src/engine/objects/Hedgehog.cpp | 99 ++++++++++++++++++++++++++++------------- 1 file changed, 67 insertions(+), 32 deletions(-) (limited to 'src/engine/objects/Hedgehog.cpp') diff --git a/src/engine/objects/Hedgehog.cpp b/src/engine/objects/Hedgehog.cpp index 1c2aada9d..a36853a91 100644 --- a/src/engine/objects/Hedgehog.cpp +++ b/src/engine/objects/Hedgehog.cpp @@ -1,5 +1,7 @@ #include "Hedgehog.h" -#include "World.h" +#include "engine/World.h" +#include "port/Game.h" +#include "port/interpolation/FrameInterpolation.h" extern "C" { #include "render_objects.h" @@ -11,60 +13,64 @@ extern "C" { #include "code_80086E70.h" #include "code_80057C60.h" } -#include "port/interpolation/FrameInterpolation.h" size_t OHedgehog::_count = 0; -OHedgehog::OHedgehog(const FVector& pos, const FVector2D& patrolPoint, s16 unk) { +OHedgehog::OHedgehog(const SpawnParams& params) : OObject(params) { Name = "Hedgehog"; + ResourceName = "mk:hedgehog"; _idx = _count; - _pos = pos; - - s32 objectId = indexObjectList2[_idx]; - _objectIndex = objectId; - init_object(objectId, 0); - gObjectList[objectId].pos[0] = gObjectList[objectId].origin_pos[0] = pos.x * xOrientation; - gObjectList[objectId].pos[1] = gObjectList[objectId].surfaceHeight = pos.y + 6.0; - gObjectList[objectId].pos[2] = gObjectList[objectId].origin_pos[2] = pos.z; - gObjectList[objectId].unk_0D5 = (u8) unk; - gObjectList[objectId].unk_09C = patrolPoint.x * xOrientation; - gObjectList[objectId].unk_09E = patrolPoint.z; + SpawnPos = params.Location.value_or(FVector(0, 0, 0)); + PatrolEnd = params.PatrolEnd.value_or(FVector2D(0, 0)); + + find_unused_obj_index(&_objectIndex); + + init_object(_objectIndex, 0); + gObjectList[_objectIndex].pos[0] = gObjectList[_objectIndex].origin_pos[0] = SpawnPos.x * xOrientation; + gObjectList[_objectIndex].pos[1] = gObjectList[_objectIndex].surfaceHeight = SpawnPos.y + 6.0; + gObjectList[_objectIndex].pos[2] = gObjectList[_objectIndex].origin_pos[2] = SpawnPos.z; + gObjectList[_objectIndex].unk_0D5 = (u8) params.Behaviour.value_or(9); + gObjectList[_objectIndex].unk_09C = PatrolEnd.x * xOrientation; + gObjectList[_objectIndex].unk_09E = PatrolEnd.z; _count++; } -void OHedgehog::Tick() { - s32 objectIndex = indexObjectList2[_idx]; +void OHedgehog::SetSpawnParams(SpawnParams& params) { + params.Name = std::string(ResourceName); + params.Location = SpawnPos; + params.PatrolEnd = PatrolEnd; +} - OHedgehog::func_800833D0(objectIndex, _idx); - OHedgehog::func_80083248(objectIndex); - OHedgehog::func_80083474(objectIndex); +void OHedgehog::Tick() { + OHedgehog::func_800833D0(_objectIndex, _idx); + OHedgehog::func_80083248(_objectIndex); + OHedgehog::func_80083474(_objectIndex); // This func clears a bit from all hedgehogs. This results in setting the height of all hedgehogs to zero. // The solution is to only clear the bit from the current instance; `self` or `this` // func_80072120(indexObjectList2, NUM_HEDGEHOGS); - clear_object_flag(objectIndex, 0x00600000); // The fix + clear_object_flag(_objectIndex, 0x00600000); // The fix } void OHedgehog::Draw(s32 cameraId) { - s32 objectIndex = indexObjectList2[_idx]; - u32 something = func_8008A364(objectIndex, cameraId, 0x4000U, 0x000003E8); + u32 something = func_8008A364(_objectIndex, cameraId, 0x4000U, 0x000003E8); if (CVarGetInteger("gNoCulling", 0) == 1) { something = MIN(something, 0x52211U - 1); } - if (is_obj_flag_status_active(objectIndex, VISIBLE) != 0) { - set_object_flag(objectIndex, 0x00200000); + if (is_obj_flag_status_active(_objectIndex, VISIBLE) != 0) { + set_object_flag(_objectIndex, 0x00200000); if (something < 0x2711U) { - set_object_flag(objectIndex, 0x00000020); + set_object_flag(_objectIndex, 0x00000020); } else { - clear_object_flag(objectIndex, 0x00000020); + clear_object_flag(_objectIndex, 0x00000020); } if (something < 0x57E41U) { - set_object_flag(objectIndex, 0x00400000); + set_object_flag(_objectIndex, 0x00400000); } if (something < 0x52211U) { - OHedgehog::func_800555BC(objectIndex, cameraId); + OHedgehog::func_800555BC(_objectIndex, cameraId); } } } @@ -113,7 +119,7 @@ void OHedgehog::func_8004A870(s32 objectIndex, f32 arg1) { const char* sHedgehogTexList[] = { d_course_yoshi_valley_hedgehog }; -void OHedgehog::func_8008311C(s32 objectIndex, s32 arg1) { +void OHedgehog::func_8008311C(s32 objectIndex, s32 id) { Object* object; Vtx* vtx = (Vtx*) LOAD_ASSET_RAW(common_vtx_hedgehog); @@ -128,7 +134,7 @@ void OHedgehog::func_8008311C(s32 objectIndex, s32 arg1) { object_next_state(objectIndex); set_obj_origin_offset(objectIndex, 0.0f, 0.0f, 0.0f); set_obj_orientation(objectIndex, 0U, 0U, 0x8000U); - object->unk_034 = ((arg1 % 6) * 0.1) + 0.5; + object->unk_034 = ((id % 6) * 0.1) + 0.5; func_80086E70(objectIndex); set_object_flag(objectIndex, 0x04000600); object->boundingBoxSize = 2; @@ -168,12 +174,12 @@ void OHedgehog::func_80083248(s32 objectIndex) { } } -void OHedgehog::func_800833D0(s32 objectIndex, s32 arg1) { +void OHedgehog::func_800833D0(s32 objectIndex, s32 id) { switch (gObjectList[objectIndex].state) { case 0: break; case 1: - OHedgehog::func_8008311C(objectIndex, arg1); + OHedgehog::func_8008311C(objectIndex, id); break; case 2: func_80072D3C(objectIndex, 0, 1, 4, -1); @@ -193,3 +199,32 @@ void OHedgehog::func_80083474(s32 objectIndex) { func_80089F24(objectIndex); } } + +void OHedgehog::DrawEditorProperties() { + Object* obj = &gObjectList[_objectIndex]; + + ImGui::Text("Location"); + ImGui::SameLine(); + FVector location = FVector(obj->pos[0], obj->pos[1], obj->pos[2]); + if (ImGui::DragFloat3("##Location", (float*)&location)) { + Translate(location); + gEditor.eObjectPicker.eGizmo.Pos = location; + } + + ImGui::SameLine(); + if (ImGui::Button(ICON_FA_UNDO "##ResetPos")) { + FVector location = FVector(0, 0, 0); + Translate(location); + gEditor.eObjectPicker.eGizmo.Pos = location; + } + + ImGui::Text("Patrol Location"); + ImGui::SameLine(); + + if (ImGui::DragFloat2("##PatrolLoc", (float*)&PatrolEnd)) { + } + ImGui::SameLine(); + if (ImGui::Button(ICON_FA_UNDO "##ResetPatrolLoc")) { + PatrolEnd = FVector2D(0.0f, 0.0f); + } +} \ No newline at end of file -- cgit v1.2.3