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/Object.cpp | 79 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 2 deletions(-) (limited to 'src/engine/objects/Object.cpp') diff --git a/src/engine/objects/Object.cpp b/src/engine/objects/Object.cpp index 4e4fd6766..d7f9ac616 100644 --- a/src/engine/objects/Object.cpp +++ b/src/engine/objects/Object.cpp @@ -10,9 +10,25 @@ extern "C" { //GameActor() -OObject::OObject() {} +OObject::OObject() { +} +OObject::OObject(SpawnParams params) { + ResourceName = "mk:object"; // This needs to be overridden in derived classes + SpawnPos = params.Location.value_or(FVector{0.0f, 0.0f, 0.0f}); + SpawnRot = params.Rotation.value_or(IRotator{0, 0, 0}); + SpawnScale = params.Scale.value_or(FVector(0, 0, 0)); + Speed = params.Speed.value_or(0.0f); +} + +void OObject::SetSpawnParams(SpawnParams& params) { + params.Name = ResourceName; + params.Location = SpawnPos; + params.Rotation = SpawnRot; + params.Scale = SpawnScale; + params.Speed = Speed; +} - // Virtual functions to be overridden by derived classes +// Virtual functions to be overridden by derived classes void OObject::Tick() { } void OObject::Tick60fps() {} void OObject::Draw(s32 cameraId) { } @@ -21,3 +37,62 @@ void OObject::Destroy() { bPendingDestroy = true; } void OObject::Reset() { } + +FVector OObject::GetLocation() const { + if (_objectIndex != -1) { + Object* object = &gObjectList[_objectIndex]; + return FVector(object->pos[0], object->pos[1], object->pos[2]); + } + printf("Editor tried to get null OObject\n"); + return FVector(0, 0, 0); +}; + +IRotator OObject::GetRotation() const { + if (_objectIndex != -1) { + Object* object = &gObjectList[_objectIndex]; + return IRotator(object->orientation[0], object->orientation[1], object->orientation[2]); + } + printf("Editor tried to get null OObject\n"); + return IRotator(0, 0, 0); +} + +FVector OObject::GetScale() const { + if (_objectIndex != -1) { + Object* object = &gObjectList[_objectIndex]; + return FVector(object->sizeScaling, object->sizeScaling, object->sizeScaling); + } + printf("Editor tried to get null OObject\n"); + return FVector(0, 0, 0); +} + +void OObject::Translate(FVector pos) { + if (_objectIndex != -1) { + SpawnPos = pos; + + Object* object = &gObjectList[_objectIndex]; + + object->pos[0] = pos.x; + object->pos[1] = pos.y; + object->pos[2] = pos.z; + object->origin_pos[0] = pos.x; + object->origin_pos[1] = pos.y; + object->origin_pos[2] = pos.z; + } else { + printf("Editor tried to translate null OObject\n"); + } +} +void OObject::Rotate(IRotator rot) { + if (_objectIndex != -1) { + SpawnRot = rot; + Object* object = &gObjectList[_objectIndex]; + object->orientation[0] = rot.pitch; + object->orientation[1] = rot.yaw; + object->orientation[2] = rot.roll; + } else { + printf("Editor tried to rotate null OObject\n"); + } +} + +void OObject::SetScale(FVector scale) { + SpawnScale = scale; +} -- cgit v1.2.3