diff options
| author | MegaMech <MegaMech@users.noreply.github.com> | 2025-11-09 19:07:44 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-09 19:07:44 -0700 |
| commit | de9c5d510175bba11ab8704e67be3a3a94f9149e (patch) | |
| tree | 34c42dbfe9f2a6eb5fbce5f6a31b532ff2a3f243 /src/engine/Actor.cpp | |
| parent | 760fa3bf5226c2a6052a5d4d53fd0e27f2911e60 (diff) | |
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>
Diffstat (limited to 'src/engine/Actor.cpp')
| -rw-r--r-- | src/engine/Actor.cpp | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/src/engine/Actor.cpp b/src/engine/Actor.cpp index f3254fed0..c2526f392 100644 --- a/src/engine/Actor.cpp +++ b/src/engine/Actor.cpp @@ -1,13 +1,35 @@ #include <libultraship.h> #include "Matrix.h" - #include "Actor.h" +#include "engine/World.h" + +// Editor +#include "engine/editor/Collision.h" extern "C" { #include "math_util.h" } AActor::AActor() {} +AActor::AActor(SpawnParams params) { + ResourceName = "mk:actor"; // 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 AActor::BeginPlay() { + // This makes actors clickable in the editor + if (CVarGetInteger("gEditorEnabled", false) == true) { + if ((nullptr != Model) && (Model[0] != '\0')) { + // Prevent collision mesh from being generated extra times. + if (Triangles.size() == 0) { + Editor::GenerateCollisionMesh(this, (Gfx*)LOAD_ASSET_RAW(Model), 1.0f); + } + } + } +} // Virtual functions to be overridden by derived classes void AActor::Tick() { } @@ -20,15 +42,14 @@ void AActor::Draw(Camera *camera) { ApplyMatrixTransformations(mtx, *(FVector*)Pos, *(IRotator*)Rot, Scale); if (render_set_position(mtx, 0) != 0) { - gSPDisplayList(gDisplayListHead++, Model); + gSPDisplayList(gDisplayListHead++, (Gfx*)Model); } } } void AActor::Collision(Player* player, AActor* actor) {} void AActor::VehicleCollision(s32 playerId, Player* player){} void AActor::Destroy() { - // Set uuid to zero. - memset(uuid, 0, sizeof(uuid)); + bPendingDestroy = true; } bool AActor::IsMod() { return false; } void AActor::SetLocation(FVector pos) { @@ -39,3 +60,41 @@ void AActor::SetLocation(FVector pos) { FVector AActor::GetLocation() const { return FVector(Pos[0], Pos[1], Pos[2]); } + +IRotator AActor::GetRotation() const { + IRotator rot; + rot.Set(Rot[0], Rot[1], Rot[2]); + return rot; +} + +FVector AActor::GetScale() const { + return Scale; +} + +void AActor::SetSpawnParams(SpawnParams& params) { + params.Name = ResourceName; + params.Location = SpawnPos; + params.Rotation = SpawnRot; + params.Scale = SpawnScale; + params.Speed = Speed; +} + +void AActor::Translate(FVector pos) { + SpawnPos = pos; + Pos[0] = pos.x; + Pos[1] = pos.y; + Pos[2] = pos.z; +} + +void AActor::Rotate(IRotator rot) { + SpawnRot = rot; + Rot[0] = rot.pitch; + Rot[1] = rot.yaw; + Rot[2] = rot.roll; +} + +void AActor::SetScale(FVector scale) { + SpawnScale = scale; + Scale = scale; +} + |
