From a6d19eee1bc8db0a75dd61052d54765541dcf9c4 Mon Sep 17 00:00:00 2001 From: MegaMech <7255464+MegaMech@users.noreply.github.com> Date: Fri, 28 Mar 2025 19:58:35 -0600 Subject: [PATCH] Fix Rotator --- src/engine/Actor.h | 2 + src/engine/CoreMath.h | 58 +++++++++++++++-- src/engine/HM_Intro.cpp | 65 ++++++------------- src/engine/HM_Intro.h | 4 +- src/engine/Matrix.cpp | 16 +++-- src/engine/StaticMeshActor.h | 2 +- src/engine/World.cpp | 16 +++-- src/engine/actors/Ship.cpp | 11 ++-- src/engine/actors/Ship.h | 5 +- src/engine/actors/SpaghettiShip.cpp | 4 +- src/engine/editor/Collision.h | 2 +- src/engine/editor/Editor.cpp | 5 +- src/engine/editor/Editor.h | 4 +- src/engine/editor/EditorMath.cpp | 10 +-- src/engine/editor/EditorMath.h | 4 +- src/engine/editor/GameObject.cpp | 4 +- src/engine/editor/GameObject.h | 6 +- src/engine/editor/Gizmo.cpp | 14 ++-- src/engine/editor/Gizmo.h | 2 +- src/engine/editor/Handle.cpp | 2 +- src/engine/editor/Handle.h | 2 +- src/engine/editor/Light.cpp | 22 ++----- src/engine/editor/Light.h | 5 +- src/engine/editor/ObjectPicker.cpp | 2 +- src/engine/editor/ObjectPicker.h | 2 +- src/engine/editor/SceneManager.cpp | 8 +-- src/engine/editor/SceneManager.h | 2 +- src/port/Engine.cpp | 11 +++- src/port/Game.h | 1 + src/port/SpaghettiGui.cpp | 6 +- .../importers/ActorSpawnDataFactory.cpp | 8 ++- .../importers/ActorSpawnDataFactory.h | 3 +- src/port/resource/importers/ArrayFactory.cpp | 6 +- src/port/resource/importers/ArrayFactory.h | 2 +- .../resource/importers/AudioBankFactory.cpp | 8 ++- .../resource/importers/AudioBankFactory.h | 3 +- .../resource/importers/AudioSampleFactory.cpp | 8 ++- .../resource/importers/AudioSampleFactory.h | 3 +- .../importers/AudioSequenceFactory.cpp | 8 ++- .../resource/importers/AudioSequenceFactory.h | 3 +- .../resource/importers/CourseVtxFactory.cpp | 8 ++- .../resource/importers/CourseVtxFactory.h | 3 +- .../importers/GenericArrayFactory.cpp | 8 ++- .../resource/importers/GenericArrayFactory.h | 3 +- src/port/resource/importers/KartAIFactory.cpp | 8 ++- src/port/resource/importers/KartAIFactory.h | 3 +- .../importers/TrackSectionsFactory.cpp | 8 ++- .../resource/importers/TrackSectionsFactory.h | 3 +- .../importers/TrackWaypointFactory.cpp | 8 ++- .../resource/importers/TrackWaypointFactory.h | 3 +- .../importers/UnkActorSpawnDataFactory.cpp | 7 +- .../importers/UnkActorSpawnDataFactory.h | 3 +- src/port/resource/importers/Vec3fFactory.cpp | 8 ++- src/port/resource/importers/Vec3fFactory.h | 3 +- src/port/resource/importers/Vec3sFactory.cpp | 8 ++- src/port/resource/importers/Vec3sFactory.h | 3 +- src/port/ui/ContentBrowser.cpp | 36 +++++----- src/port/ui/ContentBrowser.h | 5 ++ src/port/ui/Properties.cpp | 1 + src/port/ui/UIWidgets.cpp | 2 +- src/stubs.c | 3 - 61 files changed, 277 insertions(+), 206 deletions(-) diff --git a/src/engine/Actor.h b/src/engine/Actor.h index 7e91a7e63..63585d97d 100644 --- a/src/engine/Actor.h +++ b/src/engine/Actor.h @@ -1,6 +1,7 @@ #pragma once #include +#include "CoreMath.h" extern "C" { #include "macros.h" @@ -25,6 +26,7 @@ public: /* 0x30 */ Collision Unk30; uint8_t uuid[16]; const char* Name = ""; + FVector Scale = {1, 1, 1}; Gfx* Model = NULL; diff --git a/src/engine/CoreMath.h b/src/engine/CoreMath.h index fe589d87f..f3dcab046 100644 --- a/src/engine/CoreMath.h +++ b/src/engine/CoreMath.h @@ -112,25 +112,69 @@ typedef struct IVector2D { #endif // __cplusplus } IVector2D; -// IRot is an int16_t not a float. +/** + * This struct immediately converts float pitch/yaw/roll in degrees to n64 int16_t binary angles 0-0xFFFF == 0-360 degrees + * ToDegrees() Receive an FRotator of float degrees back. + * Set() Set an n64 int16_t binary angles 0-0xFFFF + */ struct IRotator { - int16_t pitch, yaw, roll; + uint16_t pitch, yaw, roll; #ifdef __cplusplus IRotator& operator=(const IRotator& other) { pitch = other.pitch; - yaw = other.yaw; - roll = other.roll; + yaw = other.yaw; + roll = other.roll; + return *this; + } + + [[nodiscard]] IRotator Set(uint16_t p, uint16_t y, uint16_t r) { + pitch = p; + yaw = y; + roll = r; + } + + IRotator() : pitch(0), yaw(0), roll(0) {} + IRotator(float p, float y, float r) { + pitch = p * (UINT16_MAX / 360); + yaw = y * (UINT16_MAX / 360); + roll = r * (UINT16_MAX / 360); + } +#endif // __cplusplus +}; + +/** + * Use IRotator unless you want to do some math in degrees. + * Always use ToBinary() or Rotator when sending into matrices or apply translation functions + * Convert from IRotator to FRotator float degrees by doing FRotator(myIRotator); + */ +struct FRotator { + float pitch, yaw, roll; + +#ifdef __cplusplus + FRotator& operator=(const FRotator& other) { + pitch = other.pitch; + yaw = other.yaw; + roll = other.roll; return *this; } // Convert to binary rotator 0 --> INT16_MAX [[nodiscard]] IRotator ToBinary() const { - return IRotator(pitch * INT16_MAX / 180, yaw * INT16_MAX / 180, roll * INT16_MAX / 180); + return IRotator( + static_cast(pitch * (UINT16_MAX / 360)), + static_cast(yaw * (UINT16_MAX / 360)), + static_cast(roll * (UINT16_MAX / 360)) + ); } - IRotator() : pitch(0), yaw(0), roll(0) {} - IRotator(int16_t p, int16_t y, int16_t r) : pitch(p), yaw(y), roll(r) {} + FRotator() : pitch(0), yaw(0), roll(0) {} + FRotator(float p, float y, float r) : pitch(p), yaw(y), roll(r) {} + FRotator(IRotator rot) { + pitch = static_cast(rot.pitch * (360 / UINT16_MAX)); + yaw = static_cast(rot.yaw * (360 / UINT16_MAX)); + roll = static_cast(rot.roll * (360 / UINT16_MAX)); + } #endif // __cplusplus }; diff --git a/src/engine/HM_Intro.cpp b/src/engine/HM_Intro.cpp index 9341bce7a..a81fe5daf 100644 --- a/src/engine/HM_Intro.cpp +++ b/src/engine/HM_Intro.cpp @@ -40,8 +40,7 @@ void HarbourMastersIntro::HM_InitIntro() { _pos = FVector(-1000, -205, -800); // -1000, -210, -800 _rot = IRotator(-5, 100, 0); - _scale = 0.7f; - _trackScale = 2.0f; + _scale = {0.7f, 0.7f, 0.7f}; _ship2Pos = FVector(300, -210, -1960); _ship2Rot = IRotator(0, 45, 0); @@ -53,7 +52,8 @@ void HarbourMastersIntro::HM_InitIntro() { _rotHM64 = IRotator(0, -90, -4); // -0x2100 _hPos = FVector(-2000, 100, -4900); - _hRot = IRotator(0, 0, 0); + _hRot = IRotator(0, -45.0f, 0); + _hScale = {2.0f, 2.0f, 2.0f}; ground_f3d_material_013_lights = gdSPDefLights1( 0x7F, 0x30, 0x80, @@ -61,15 +61,6 @@ void HarbourMastersIntro::HM_InitIntro() { ); } -const float BOB_AMPLITUDE = 1.1f; -const float BOB_SPEED = 0.05f; - -const float TILT_AMPLITUDE = 1.5f; -const float TILT_SPEED = 0.05f; - -const float ROLL_AMPLITUDE = 1.0f; -const float ROLL_SPEED = 0.03f; - void HarbourMastersIntro::HM_TickIntro() { _water += 1; if (_water > 255) { @@ -93,15 +84,14 @@ void HarbourMastersIntro::HM_TickIntro() { find_and_set_tile_size((uintptr_t) ((void*)mat_water_water2), _water, 0);; } -// @args amplitudes void HarbourMastersIntro::Bob(FVector& pos, IRotator& rot, f32 bobAmp, f32 bobSpeed, f32 tiltAmp, f32 tiltSpeed, f32 rollAmp, f32 rollSpeed) { float time = (float)gGlobalTimer; pos.y = -210 + bobAmp * sin(time * bobSpeed); - rot.pitch = tiltAmp * sin(time * tiltSpeed); + rot.pitch = (tiltAmp * sin(time * tiltSpeed)) * (UINT16_MAX / 360); - rot.roll = rollAmp * sin(time * rollSpeed); + rot.roll = (rollAmp * sin(time * rollSpeed)) * (UINT16_MAX / 360); } void HarbourMastersIntro::SpagBob(FVector& pos, IRotator& rot, f32 bobAmp, f32 bobSpeed, f32 tiltAmp, f32 tiltSpeed, f32 rollAmp, f32 rollSpeed) { @@ -109,54 +99,37 @@ void HarbourMastersIntro::SpagBob(FVector& pos, IRotator& rot, f32 bobAmp, f32 b pos.y = -205 + bobAmp * sin(time * bobSpeed); - rot.pitch = -5 + tiltAmp * sin(time * tiltSpeed); + rot.pitch = (-5 + tiltAmp * sin(time * tiltSpeed)) * (UINT16_MAX / 360); - rot.roll = rollAmp * sin(time * rollSpeed); + rot.roll = (rollAmp * sin(time * rollSpeed)) * (UINT16_MAX / 360); } void HarbourMastersIntro::HM_DrawIntro() { - const f32 conv = 8192.0f / 45.0f; // Convert to hex degrees - Mtx* mtx = &gGfxPool->mtxObject[0]; HarbourMastersIntro::Setup(); - Mat4 someMtx; gSPMatrix(gDisplayListHead++, &gGfxPool->mtxScreen, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); gSPMatrix(gDisplayListHead++, &gGfxPool->mtxLookAt[0], G_MTX_NOPUSH | G_MTX_MUL | G_MTX_PROJECTION); - mtxf_identity(someMtx); - render_set_position(someMtx, 0); gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2); gDPSetEnvColor(gDisplayListHead++, 0x00, 0x00, 0x00, 0x00); - Vec3f pos = {_pos.x, _pos.y, _pos.z}; - Vec3s rot = {_rot.pitch * conv, _rot.yaw * conv, _rot.roll * conv}; - Mat4 matrix; - mtxf_pos_rotation_xyz(matrix, pos, rot); - mtxf_scale(matrix, _scale); - render_set_position(matrix, 0); + Mat4 mtx_spaghettiShip; + ApplyMatrixTransformations(mtx_spaghettiShip, _pos, _rot, _scale); + render_set_position(mtx_spaghettiShip, 0); gSPDisplayList(gDisplayListHead++, ship1_spag1_mesh); - Mat4 matrix2; - Vec3s rot2 = {_ship2Rot.pitch * conv, _ship2Rot.yaw * conv, _ship2Rot.roll * conv}; - Vec3f pos2 = {_ship2Pos.x, _ship2Pos.y, _ship2Pos.z}; - mtxf_pos_rotation_xyz(matrix2, pos2, rot2); - mtxf_scale(matrix2, _scale); - render_set_position(matrix2, 0); + Mat4 mtx_ship2; + ApplyMatrixTransformations(mtx_ship2, _ship2Pos, _ship2Rot, _scale); + render_set_position(mtx_ship2, 0); gSPDisplayList(gDisplayListHead++, ship2_SoH_mesh); - Mat4 matrix3; - Vec3s rot3 = {_shipRot.pitch * conv, _shipRot.yaw * conv, _shipRot.roll * conv}; - Vec3f pos3 = {_shipPos.x, _shipPos.y, _shipPos.z}; - mtxf_pos_rotation_xyz(matrix3, pos3, rot3); - mtxf_scale(matrix3, _scale); - render_set_position(matrix3, 0); + Mat4 mtx_ship3; + ApplyMatrixTransformations(mtx_ship3, _shipPos, _shipRot, _scale); + render_set_position(mtx_ship3, 0); gSPDisplayList(gDisplayListHead++, ship3_2Ship_mesh); - Mat4 hMatrix; - Vec3f hPos = {_hPos.x, _hPos.y, _hPos.z}; - Vec3s hRot = {_hRot.pitch * conv, -0x2100, _hRot.roll * conv}; - mtxf_pos_rotation_xyz(hMatrix, hPos, hRot); - mtxf_scale(hMatrix, _trackScale); - render_set_position(hMatrix, 0); + Mat4 mtx_geo; + ApplyMatrixTransformations(mtx_geo, _hPos, _hRot, _hScale); + render_set_position(mtx_geo, 0); gSPDisplayList(gDisplayListHead++, ground_map_mesh); gSPDisplayList(gDisplayListHead++, powered_Text_mesh); diff --git a/src/engine/HM_Intro.h b/src/engine/HM_Intro.h index 227d64755..0bdf57b6c 100644 --- a/src/engine/HM_Intro.h +++ b/src/engine/HM_Intro.h @@ -40,9 +40,8 @@ private: f32 _cameraAcceleration; FVector _pos; - f32 _scale; - f32 _trackScale; IRotator _rot; + FVector _scale; FVector _shipPos; IRotator _shipRot; @@ -57,6 +56,7 @@ private: FVector _hPos; IRotator _hRot; + FVector _hScale; }; extern "C" { diff --git a/src/engine/Matrix.cpp b/src/engine/Matrix.cpp index 14cf7edfb..2ecf8e538 100644 --- a/src/engine/Matrix.cpp +++ b/src/engine/Matrix.cpp @@ -28,7 +28,7 @@ Mtx* GetMatrix(std::vector& stack) { } /** - * Use GetMatrix first + * Use GetMatrix() first */ void AddMatrixFixed(std::vector& stack, s32 flags) { // Load the matrix @@ -65,8 +65,6 @@ void ApplyMatrixTransformations(Mat4 mtx, FVector pos, IRotator rot, FVector sca f32 sine2, cosine2; f32 sine3, cosine3; - rot = rot.ToBinary(); - // Compute the sine and cosine of the orientation (Euler angles) sine1 = sins(rot.pitch); cosine1 = coss(rot.pitch); @@ -80,20 +78,26 @@ void ApplyMatrixTransformations(Mat4 mtx, FVector pos, IRotator rot, FVector sca mtx[1][0] = (-cosine2 * sine3) + ((sine1 * sine2) * cosine3); mtx[2][0] = cosine1 * sine2; mtx[3][0] = pos.x; - + mtx[0][1] = cosine1 * sine3; mtx[1][1] = cosine1 * cosine3; mtx[2][1] = -sine1; mtx[3][1] = pos.y; - + mtx[0][2] = (-sine2 * cosine3) + ((sine1 * cosine2) * sine3); mtx[1][2] = (sine2 * sine3) + ((sine1 * cosine2) * cosine3); mtx[2][2] = cosine1 * cosine2; mtx[3][2] = pos.z; - // Apply scaling: modify the diagonal of the rotation matrix + // Apply scaling mtx[0][0] *= scale.x; + mtx[1][0] *= scale.x; + mtx[2][0] *= scale.x; + mtx[0][1] *= scale.y; mtx[1][1] *= scale.y; + mtx[2][1] *= scale.y; + mtx[0][2] *= scale.z; + mtx[1][2] *= scale.z; mtx[2][2] *= scale.z; // Set the last row and column for the homogeneous coordinate system diff --git a/src/engine/StaticMeshActor.h b/src/engine/StaticMeshActor.h index 02573744f..4007aa2c1 100644 --- a/src/engine/StaticMeshActor.h +++ b/src/engine/StaticMeshActor.h @@ -40,7 +40,7 @@ public: void from_json(const nlohmann::json& j) { Name = j.at("Name").get(); Pos = FVector(j.at("Position")[0].get(), j.at("Position")[1].get(), j.at("Position")[2].get()); - Rot = IRotator(j.at("Rotation")[0].get(), j.at("Rotation")[1].get(), j.at("Rotation")[2].get()); + Rot.Set(j.at("Rotation")[0].get(), j.at("Rotation")[1].get(), j.at("Rotation")[2].get()); Scale = FVector(j.at("Scale")[0].get(), j.at("Scale")[1].get(), j.at("Scale")[2].get()); // Deserialize the Model string diff --git a/src/engine/World.cpp b/src/engine/World.cpp index 487178057..5f469b255 100644 --- a/src/engine/World.cpp +++ b/src/engine/World.cpp @@ -119,9 +119,11 @@ AActor* World::AddActor(AActor* actor) { Actors.push_back(actor); if (actor->Model != NULL) { - gEditor.AddObject(actor->Name, (FVector*) &actor->Pos, &actor->Rot, nullptr, (Gfx*)LOAD_ASSET_RAW(actor->Model), 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->Type, 0); + gEditor.AddObject(actor->Name, (FVector*) &actor->Pos, (IRotator*)&actor->Rot, nullptr, + (Gfx*) LOAD_ASSET_RAW(actor->Model), 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, + 0.0f, (int32_t*) &actor->Type, 0); } else { - gEditor.AddObject(actor->Name, (FVector*) &actor->Pos, &actor->Rot, nullptr, nullptr, 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->Type, 0); + gEditor.AddObject(actor->Name, (FVector*) &actor->Pos, (IRotator*)&actor->Rot, nullptr, nullptr, 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->Type, 0); } return Actors.back(); } @@ -137,9 +139,9 @@ struct Actor* World::AddBaseActor() { void World::AddEditorObject(Actor* actor, const char* name) { if (actor->model != NULL) { - gEditor.AddObject(name, (FVector*) &actor->pos, &actor->rot, nullptr, (Gfx*)LOAD_ASSET_RAW(actor->model), 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->type, 0); + gEditor.AddObject(name, (FVector*) &actor->pos, (IRotator*)&actor->rot, nullptr, (Gfx*)LOAD_ASSET_RAW(actor->model), 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->type, 0); } else { - gEditor.AddObject(name, (FVector*) &actor->pos, &actor->rot, nullptr, nullptr, 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->type, 0); + gEditor.AddObject(name, (FVector*) &actor->pos, (IRotator*)&actor->rot, nullptr, nullptr, 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*)&actor->type, 0); } } @@ -178,7 +180,7 @@ void World::TickActors() { StaticMeshActor* World::AddStaticMeshActor(std::string name, FVector pos, IRotator rot, FVector scale, std::string model, int32_t* collision) { StaticMeshActors.push_back(new StaticMeshActor(name, pos, rot, scale, model, collision)); auto actor = StaticMeshActors.back(); - gEditor.AddObject(actor->Name.c_str(), &actor->Pos, (Vec3s*) &actor->Rot, &actor->Scale, (Gfx*) LOAD_ASSET_RAW(actor->Model.c_str()), 1.0f, + auto gameObj = gEditor.AddObject(actor->Name.c_str(), &actor->Pos, &actor->Rot, &actor->Scale, (Gfx*) LOAD_ASSET_RAW(actor->Model.c_str()), 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, (int32_t*) &actor->bPendingDestroy, (int32_t) true); return actor; } @@ -207,9 +209,9 @@ OObject* World::AddObject(OObject* object) { Object* cObj = &gObjectList[object->_objectIndex]; if (cObj->model != NULL) { - gEditor.AddObject(object->Name, (FVector*) &cObj->origin_pos[0], (Vec3s*)&cObj->orientation, nullptr, (Gfx*)LOAD_ASSET_RAW(cObj->model), 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, &object->_objectIndex, -1); + gEditor.AddObject(object->Name, (FVector*) &cObj->origin_pos[0], (IRotator*)&cObj->orientation, nullptr, (Gfx*)LOAD_ASSET_RAW(cObj->model), 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, &object->_objectIndex, -1); } else { - gEditor.AddObject(object->Name, (FVector*) &cObj->origin_pos[0], (Vec3s*)&cObj->orientation, nullptr, nullptr, 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, &object->_objectIndex, -1); + gEditor.AddObject(object->Name, (FVector*) &cObj->origin_pos[0], (IRotator*)&cObj->orientation, nullptr, nullptr, 1.0f, Editor::GameObject::CollisionType::VTX_INTERSECT, 0.0f, &object->_objectIndex, -1); } } diff --git a/src/engine/actors/Ship.cpp b/src/engine/actors/Ship.cpp index 3670a122d..e27e33bbd 100644 --- a/src/engine/actors/Ship.cpp +++ b/src/engine/actors/Ship.cpp @@ -2,6 +2,7 @@ #include #include "CoreMath.h" +#include "Matrix.h" extern "C" { #include "common_structs.h" @@ -15,6 +16,10 @@ extern "C" { AShip::AShip(FVector pos, AShip::Skin skin) { Spawn = pos; Spawn.y += 10; + Pos[0] = pos.x; + Pos[1] = pos.y; + Pos[2] = pos.z; + Scale = FVector(0.4, 0.4, 0.4); switch(skin) { case GHOSTSHIP: @@ -49,15 +54,11 @@ void AShip::Tick() { void AShip::Draw(Camera *camera) { Mat4 shipMtx; - Vec3f hullPos = {Pos.x, Pos.y, Pos.z}; - //Vec3s hullRot = {Rot.pitch, Rot.yaw, Rot.roll}; gSPSetGeometryMode(gDisplayListHead++, G_SHADING_SMOOTH); gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); - IRotator rot = Rot.ToBinary(); - mtxf_pos_rotation_xyz(shipMtx, hullPos, *(Vec3s*) &Rot); - mtxf_scale(shipMtx, 0.4); + ApplyMatrixTransformations(shipMtx, *(FVector*)Pos, *(IRotator*)Rot, Scale); if (render_set_position(shipMtx, 0) != 0) { gSPDisplayList(gDisplayListHead++, _skin); } diff --git a/src/engine/actors/Ship.h b/src/engine/actors/Ship.h index 4d4f9e8c0..d81fc630d 100644 --- a/src/engine/actors/Ship.h +++ b/src/engine/actors/Ship.h @@ -27,8 +27,9 @@ public: virtual bool IsMod() override; FVector Spawn; - FVector Pos; - IRotator Rot = {0, 0, 0}; + //FVector Pos; + ///IRotator Rot = {0, 0, 0}; + //FVector Scale = {0.4, 0.4, 0.4}; private: Gfx* _skin; }; diff --git a/src/engine/actors/SpaghettiShip.cpp b/src/engine/actors/SpaghettiShip.cpp index 357985487..322268793 100644 --- a/src/engine/actors/SpaghettiShip.cpp +++ b/src/engine/actors/SpaghettiShip.cpp @@ -44,9 +44,7 @@ void ASpaghettiShip::Draw(Camera *camera) { gSPSetGeometryMode(gDisplayListHead++, G_SHADING_SMOOTH); gSPClearGeometryMode(gDisplayListHead++, G_LIGHTING); - // empty/null mtx as a base - IRotator iRot = Rot.ToBinary(); - mtxf_pos_rotation_xyz(shipMtx, hullPos, *(Vec3s*)&iRot); + mtxf_pos_rotation_xyz(shipMtx, hullPos, *(Vec3s*)&Rot); mtxf_scale(shipMtx, 0.4); if (render_set_position(shipMtx, 0) != 0) {} diff --git a/src/engine/editor/Collision.h b/src/engine/editor/Collision.h index 2b6c99848..8ae4660e4 100644 --- a/src/engine/editor/Collision.h +++ b/src/engine/editor/Collision.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include "GameObject.h" diff --git a/src/engine/editor/Editor.cpp b/src/engine/editor/Editor.cpp index 9f35f6780..efe1d7ecf 100644 --- a/src/engine/editor/Editor.cpp +++ b/src/engine/editor/Editor.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include "../CoreMath.h" #include @@ -99,7 +99,7 @@ namespace Editor { } } - void Editor::AddObject(const char* name, FVector* pos, Vec3s* rot, FVector* scale, Gfx* model, float collScale, GameObject::CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue) { + GameObject* Editor::AddObject(const char* name, FVector* pos, IRotator* rot, FVector* scale, Gfx* model, float collScale, GameObject::CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue) { //printf("After AddObj: Pos(%f, %f, %f), Name: %s, Model: %s\n", // pos->x, pos->y, pos->z, name, model); if (model != nullptr) { @@ -109,6 +109,7 @@ namespace Editor { eGameObjects.push_back(new GameObject(name, pos, rot, scale, model, {}, GameObject::CollisionType::BOUNDING_BOX, 22.0f, despawnFlag, despawnValue)); } + return eGameObjects.back(); } void Editor::AddLight(const char* name, FVector* pos, s8* rot) { diff --git a/src/engine/editor/Editor.h b/src/engine/editor/Editor.h index 0109b2e90..6466ad922 100644 --- a/src/engine/editor/Editor.h +++ b/src/engine/editor/Editor.h @@ -1,7 +1,7 @@ #ifndef __EDITOR_H__ #define __EDITOR_H__ -#include +#include #include #include "GameObject.h" @@ -21,7 +21,7 @@ public: void Tick(); void Draw(); void Load(); - void AddObject(const char* name, FVector* pos, Vec3s* rot, FVector* scale, Gfx* model, float collScale, GameObject::CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue); + GameObject* AddObject(const char* name, FVector* pos, IRotator* rot, FVector* scale, Gfx* model, float collScale, GameObject::CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue); void AddLight(const char* name, FVector* pos, s8* rot); void ClearObjects(); void RemoveObject(); diff --git a/src/engine/editor/EditorMath.cpp b/src/engine/editor/EditorMath.cpp index 69f92722e..d590a954a 100644 --- a/src/engine/editor/EditorMath.cpp +++ b/src/engine/editor/EditorMath.cpp @@ -1,6 +1,6 @@ #include "EditorMath.h" -#include +#include #include "port/Game.h" #include "port/Engine.h" #include @@ -323,9 +323,11 @@ float CalculateAngle(const FVector& start, const FVector& end) { return acos(cosAngle); } -void SetDirectionFromRotator(s16 rotator[3], s8 direction[3]) { - float yaw = rotator[1] * (M_PI / 32768.0f); // Convert from s16 (0 to 32767) to radians - float pitch = rotator[0] * (M_PI / 32768.0f); +// Used for gSPLights1 +void SetDirectionFromRotator(IRotator rot, s8 direction[3]) { + // Subtract 0x4000 to lineup the rotator with the light direction + float yaw = (rot.yaw - 0x4000) * (M_PI / 32768.0f); // Convert from n64 binary angles 0-0xFFFF 0-360 degrees to radians + float pitch = rot.pitch * (M_PI / 32768.0f); // Compute unit direction vector float x = cosf(yaw) * cosf(pitch); diff --git a/src/engine/editor/EditorMath.h b/src/engine/editor/EditorMath.h index 8e607aa2c..f2b9e8835 100644 --- a/src/engine/editor/EditorMath.h +++ b/src/engine/editor/EditorMath.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include "../CoreMath.h" @@ -44,5 +44,5 @@ bool IntersectRaySphere(const Ray& ray, const FVector& sphereCenter, float radiu void Editor_AddMatrix(Mat4 mtx, int32_t flags); float CalculateAngle(const FVector& start, const FVector& end); -void SetDirectionFromRotator(s16 rotator[3], s8 direction[3]); +void SetDirectionFromRotator(IRotator rot, s8 direction[3]); FVector GetPositionAheadOfCamera(f32 dist); diff --git a/src/engine/editor/GameObject.cpp b/src/engine/editor/GameObject.cpp index ceae71440..6f52c8ac8 100644 --- a/src/engine/editor/GameObject.cpp +++ b/src/engine/editor/GameObject.cpp @@ -1,9 +1,9 @@ -#include +#include #include "GameObject.h" namespace Editor { - GameObject::GameObject(const char* name, FVector* pos, Vec3s* rot, FVector* scale, Gfx* model, std::vector triangles, CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue) { + GameObject::GameObject(const char* name, FVector* pos, IRotator* rot, FVector* scale, Gfx* model, std::vector triangles, CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue) { Name = name; Pos = pos; Rot = rot; diff --git a/src/engine/editor/GameObject.h b/src/engine/editor/GameObject.h index a613c9bf8..ca08d8ba9 100644 --- a/src/engine/editor/GameObject.h +++ b/src/engine/editor/GameObject.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include "../CoreMath.h" @@ -22,7 +22,7 @@ public: BOUNDING_SPHERE }; - GameObject(const char* name, FVector* pos, Vec3s* rot, FVector* scale, Gfx* model, std::vector triangles, CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue); + GameObject(const char* name, FVector* pos, IRotator* rot, FVector* scale, Gfx* model, std::vector triangles, CollisionType collision, float boundingBoxSize, int32_t* despawnFlag, int32_t despawnValue); GameObject(FVector* pos, Vec3s* rot); GameObject(); virtual void Tick(); @@ -31,7 +31,7 @@ public: const char* Name; FVector* Pos; - Vec3s* Rot; + IRotator* Rot; FVector* Scale; Gfx* Model; std::vector Triangles; diff --git a/src/engine/editor/Gizmo.cpp b/src/engine/editor/Gizmo.cpp index eb1d73908..8a7ae6886 100644 --- a/src/engine/editor/Gizmo.cpp +++ b/src/engine/editor/Gizmo.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include "../CoreMath.h" #include @@ -173,21 +173,21 @@ void Gizmo::Rotate() { float angle = CalculateAngle(_cursorOffset, cameraPos) * 100; - // printf("start %f %f %f end %f %f %f angle %f\n", _cursorOffset.x, _cursorOffset.y, _cursorOffset.z, cameraPos.x, cameraPos.y, cameraPos.z, angle); + // printf("start %f %f %f end %f %f %f angle %f\n", _cursorOffset.x, _cursorOffset.y, _cursorOffset.z, cameraPos.x, cameraPos.y, cameraPos.z, angle); // Depending on which axis or handle you want to rotate, apply rotation. switch(SelectedHandle) { case GizmoHandle::All_Axis: - (*_selected->Rot)[0] = static_cast((s16)((*_selected->Rot)[0] + angle) & 0xFFFF); // Wrap to 0xFFFF - (*_selected->Rot)[1] = static_cast((s16)((*_selected->Rot)[1] + angle) & 0xFFFF); // Wrap to 0xFFFF + _selected->Rot->pitch = _selected->Rot->pitch + angle; + _selected->Rot->yaw = _selected->Rot->yaw + angle; break; case GizmoHandle::X_Axis: - (*_selected->Rot)[0] = static_cast((s16)((*_selected->Rot)[0] + angle) & 0xFFFF); // Wrap to 0xFFFF + _selected->Rot->pitch = _selected->Rot->pitch + angle; break; case GizmoHandle::Y_Axis: - (*_selected->Rot)[1] = static_cast((s16)((*_selected->Rot)[1] + angle) & 0xFFFF); // Wrap to 0xFFFF + _selected->Rot->yaw = _selected->Rot->yaw + angle; break; case GizmoHandle::Z_Axis: - (*_selected->Rot)[2] = static_cast((s16)((*_selected->Rot)[2] + angle) & 0xFFFF); // Wrap to 0xFFFF + _selected->Rot->roll = _selected->Rot->roll + angle; break; } } diff --git a/src/engine/editor/Gizmo.h b/src/engine/editor/Gizmo.h index 30f4f640d..b9c88254a 100644 --- a/src/engine/editor/Gizmo.h +++ b/src/engine/editor/Gizmo.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include "Collision.h" #include "GameObject.h" diff --git a/src/engine/editor/Handle.cpp b/src/engine/editor/Handle.cpp index 212e802eb..dca551826 100644 --- a/src/engine/editor/Handle.cpp +++ b/src/engine/editor/Handle.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include "Handle.h" diff --git a/src/engine/editor/Handle.h b/src/engine/editor/Handle.h index 7db4595f7..18d0c03b1 100644 --- a/src/engine/editor/Handle.h +++ b/src/engine/editor/Handle.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include extern Gfx handle_Cylinder_mesh[]; diff --git a/src/engine/editor/Light.cpp b/src/engine/editor/Light.cpp index f8deb3f8b..8f2764f3c 100644 --- a/src/engine/editor/Light.cpp +++ b/src/engine/editor/Light.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include "../CoreMath.h" #include @@ -33,41 +33,31 @@ size_t LightObject::NumLights = 0; LightObject::LightObject(const char* name, FVector* pos, s8* direction) : GameObject(nullptr, nullptr) { Name = name; - // If pos is nullptr, allocate memory, otherwise assign pos - // if (pos != nullptr) { - // Pos = pos; - // } Pos = &LightPos; Rot = &LightRot; + Scale = &LightScale; - // Pos = &LightPos; DespawnFlag = &_despawnFlag; DespawnValue = -1; Direction = direction; + Collision = CollisionType::BOUNDING_BOX; + BoundingBoxSize = 4.0f; + NumLights += 1; } void LightObject::Load() { - //Pos = &LightPos; } void LightObject::Tick() { - //Pos = &LightPos; SetDirectionFromRotator(*Rot, Direction); - //Direction[0] = static_cast(((*Rot)[0] / 256 - 128) & 0xFF); - //Direction[1] = static_cast(((*Rot)[1] / 256 - 128) & 0xFF); - //Direction[2] = static_cast(((*Rot)[2] / 256 - 128) & 0xFF); - //printf("Light rot %d %d %d %d %d %d\n", Direction[0], Direction[1], Direction[2], (*Rot)[0], (*Rot)[1], (*Rot)[2]); } void LightObject::Draw() { Mat4 mtx; - Vec3f pos = {Pos->x, Pos->y, Pos->z}; - Vec3s rot = {(*Rot)[0], (*Rot)[1] + 0x4000, (*Rot)[2]}; - mtxf_pos_rotation_xyz(mtx, pos, rot); - mtxf_scale(mtx, 0.3); + ApplyMatrixTransformations(mtx, LightPos, LightRot, LightScale); Editor_AddMatrix(mtx, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); gSPDisplayList(gDisplayListHead++, sun_LightModel_mesh); gSPDisplayList(gDisplayListHead++, handle_Cylinder_mesh); diff --git a/src/engine/editor/Light.h b/src/engine/editor/Light.h index f01842b1d..972942663 100644 --- a/src/engine/editor/Light.h +++ b/src/engine/editor/Light.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include "Collision.h" #include "Gizmo.h" @@ -18,8 +18,9 @@ public: static size_t NumLights; FVector LightPos = FVector(0, 100, 0); + IRotator LightRot = IRotator(0, 0, 0); + FVector LightScale = FVector(0.1, 0.1, 0.1); s8* Direction; - Vec3s LightRot = {0, 0, 0}; s32 _despawnFlag = 0; u8 sun_sun_rgba32[16384] = { diff --git a/src/engine/editor/ObjectPicker.cpp b/src/engine/editor/ObjectPicker.cpp index d94f60ebb..689433a24 100644 --- a/src/engine/editor/ObjectPicker.cpp +++ b/src/engine/editor/ObjectPicker.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include "../CoreMath.h" #include diff --git a/src/engine/editor/ObjectPicker.h b/src/engine/editor/ObjectPicker.h index 788604838..d1f64da89 100644 --- a/src/engine/editor/ObjectPicker.h +++ b/src/engine/editor/ObjectPicker.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include "Collision.h" #include "Gizmo.h" diff --git a/src/engine/editor/SceneManager.cpp b/src/engine/editor/SceneManager.cpp index 65c199808..81e0a3c60 100644 --- a/src/engine/editor/SceneManager.cpp +++ b/src/engine/editor/SceneManager.cpp @@ -95,10 +95,10 @@ namespace Editor { gWorldInstance.StaticMeshActors.push_back(new StaticMeshActor("", FVector(0, 0, 0), IRotator(0, 0, 0), FVector(1, 1, 1), "", nullptr)); auto actor = gWorldInstance.StaticMeshActors.back(); actor->from_json(actorJson); - -printf("After from_json: Pos(%f, %f, %f), Name: %s, Model: %s\n", - actor->Pos.x, actor->Pos.y, actor->Pos.z, actor->Name.c_str(), actor->Model.c_str()); - gEditor.AddObject(actor->Name.c_str(), &actor->Pos, (Vec3s*)&actor->Rot, &actor->Scale, (Gfx*) nullptr, 1.0f, + + printf("After from_json: Pos(%f, %f, %f), Name: %s, Model: %s\n", + actor->Pos.x, actor->Pos.y, actor->Pos.z, actor->Name.c_str(), actor->Model.c_str()); + gEditor.AddObject(actor->Name.c_str(), &actor->Pos, &actor->Rot, &actor->Scale, (Gfx*) nullptr, 1.0f, GameObject::CollisionType::BOUNDING_BOX, 20.0f, (int32_t*) &actor->bPendingDestroy, (int32_t) 1); } diff --git a/src/engine/editor/SceneManager.h b/src/engine/editor/SceneManager.h index d2915888c..76aa02c02 100644 --- a/src/engine/editor/SceneManager.h +++ b/src/engine/editor/SceneManager.h @@ -1,4 +1,4 @@ -#include +#include #include "Course.h" namespace Editor { diff --git a/src/port/Engine.cpp b/src/port/Engine.cpp index dd6f6e3f4..d1c61e6fa 100644 --- a/src/port/Engine.cpp +++ b/src/port/Engine.cpp @@ -256,7 +256,6 @@ void GameEngine::StartFrame() const { default: break; } - this->context->GetWindow()->StartFrame(); } // void GameEngine::ProcessFrame(void (*run_one_game_iter)()) const { @@ -265,13 +264,19 @@ void GameEngine::StartFrame() const { // } void GameEngine::RunCommands(Gfx* Commands) { - gfx_run(Commands, {}); - gfx_end_frame(); + auto wnd = std::dynamic_pointer_cast(Ship::Context::GetInstance()->GetWindow()); if (ShouldClearTextureCacheAtEndOfFrame) { gfx_texture_cache_clear(); ShouldClearTextureCacheAtEndOfFrame = false; } + + if (nullptr == wnd) { + return; + } + + wnd->HandleEvents(); + wnd->DrawAndRunGraphicsCommands(Commands, {}); } void GameEngine::ProcessGfxCommands(Gfx* commands) { diff --git a/src/port/Game.h b/src/port/Game.h index 25b4398dc..472b4f6bf 100644 --- a/src/port/Game.h +++ b/src/port/Game.h @@ -17,6 +17,7 @@ extern s32 gTrophyIndex; #ifdef __cplusplus extern Editor::Editor gEditor; +extern HarbourMastersIntro gMenuIntro; #endif Properties* CM_GetProps(); diff --git a/src/port/SpaghettiGui.cpp b/src/port/SpaghettiGui.cpp index 20b42084b..4a97d9a05 100644 --- a/src/port/SpaghettiGui.cpp +++ b/src/port/SpaghettiGui.cpp @@ -82,6 +82,9 @@ namespace Ship { ImGuiID bottomId = ImGui::DockBuilderSplitNode(dockId, ImGuiDir_Down, 0.25f, nullptr, nullptr); ImGui::DockBuilderSetNodeSize(bottomId, ImVec2(viewport->Size.x, viewport->Size.y * 0.1f)); + ImGuiID bottomLeftId = ImGui::DockBuilderSplitNode(bottomId, ImGuiDir_Left, 0.25f, nullptr, nullptr); + ImGui::DockBuilderSetNodeSize(bottomId, ImVec2(viewport->Size.x, viewport->Size.y * 0.1f)); + ImGuiID rightId = ImGui::DockBuilderSplitNode(dockId, ImGuiDir_Right, 0.25f, nullptr, nullptr); ImGui::DockBuilderSetNodeSize(rightId, ImVec2(viewport->Size.x * 0.15f, viewport->Size.y)); @@ -91,10 +94,11 @@ namespace Ship { ImGuiID rightBottomId = ImGui::DockBuilderSplitNode(rightId, ImGuiDir_Down, 0.25f, nullptr, nullptr); ImGui::DockBuilderSetNodeSize(rightBottomId, ImVec2(viewport->Size.x, viewport->Size.y * 0.25)); - + ImGui::DockBuilderDockWindow("Properties", rightBottomId); ImGui::DockBuilderDockWindow("Tools", topId); ImGui::DockBuilderDockWindow("Content Browser", bottomId); + ImGui::DockBuilderDockWindow("File Explorer", bottomLeftId); ImGui::DockBuilderFinish(dockId); } diff --git a/src/port/resource/importers/ActorSpawnDataFactory.cpp b/src/port/resource/importers/ActorSpawnDataFactory.cpp index 59c25caf8..a06f18000 100644 --- a/src/port/resource/importers/ActorSpawnDataFactory.cpp +++ b/src/port/resource/importers/ActorSpawnDataFactory.cpp @@ -5,12 +5,14 @@ #include namespace MK64 { -std::shared_ptr ResourceFactoryBinaryActorSpawnDataV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader(file)) { +std::shared_ptr +ResourceFactoryBinaryActorSpawnDataV0::ReadResource(std::shared_ptr file, + std::shared_ptr initData) { + if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } - auto section = std::make_shared(file->InitData); + auto section = std::make_shared(initData); auto reader = std::get>(file->Reader); uint32_t count = reader->ReadUInt32(); diff --git a/src/port/resource/importers/ActorSpawnDataFactory.h b/src/port/resource/importers/ActorSpawnDataFactory.h index 3dc5c4498..1c05c3ef2 100644 --- a/src/port/resource/importers/ActorSpawnDataFactory.h +++ b/src/port/resource/importers/ActorSpawnDataFactory.h @@ -6,7 +6,8 @@ namespace MK64 { class ResourceFactoryBinaryActorSpawnDataV0 : public Ship::ResourceFactoryBinary { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file, + std::shared_ptr initData) override; }; } // namespace MK64 diff --git a/src/port/resource/importers/ArrayFactory.cpp b/src/port/resource/importers/ArrayFactory.cpp index 78fe3a831..07f166be1 100644 --- a/src/port/resource/importers/ArrayFactory.cpp +++ b/src/port/resource/importers/ArrayFactory.cpp @@ -4,12 +4,12 @@ #include "graphic/Fast3D/lus_gbi.h" namespace MK64 { -std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader(file)) { +std::shared_ptr ResourceFactoryBinaryArrayV0::ReadResource(std::shared_ptr file, std::shared_ptr initData) { + if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } - auto array = std::make_shared(file->InitData); + auto array = std::make_shared(initData); auto reader = std::get>(file->Reader); array->ArrayType = (ArrayResourceType) reader->ReadUInt32(); diff --git a/src/port/resource/importers/ArrayFactory.h b/src/port/resource/importers/ArrayFactory.h index ee3182531..5b1fff4cb 100644 --- a/src/port/resource/importers/ArrayFactory.h +++ b/src/port/resource/importers/ArrayFactory.h @@ -6,6 +6,6 @@ namespace MK64 { class ResourceFactoryBinaryArrayV0 : public Ship::ResourceFactoryBinary { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file, std::shared_ptr initData) override; }; } // namespace MK64 diff --git a/src/port/resource/importers/AudioBankFactory.cpp b/src/port/resource/importers/AudioBankFactory.cpp index 90d70b9aa..ee400c1b5 100644 --- a/src/port/resource/importers/AudioBankFactory.cpp +++ b/src/port/resource/importers/AudioBankFactory.cpp @@ -4,12 +4,14 @@ #include "resourcebridge.h" #include "ResourceUtil.h" -std::shared_ptr SM64::AudioBankFactoryV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader(file)) { +std::shared_ptr +SM64::AudioBankFactoryV0::ReadResource(std::shared_ptr file, + std::shared_ptr initData) { + if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } - std::shared_ptr bank = std::make_shared(file->InitData); + std::shared_ptr bank = std::make_shared(initData); auto reader = std::get>(file->Reader); uint8_t bankId = reader->ReadUInt32(); diff --git a/src/port/resource/importers/AudioBankFactory.h b/src/port/resource/importers/AudioBankFactory.h index f76e2d830..eddf256e9 100644 --- a/src/port/resource/importers/AudioBankFactory.h +++ b/src/port/resource/importers/AudioBankFactory.h @@ -6,6 +6,7 @@ namespace SM64 { class AudioBankFactoryV0 : public Ship::ResourceFactoryBinary { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file, + std::shared_ptr initData) override; }; } diff --git a/src/port/resource/importers/AudioSampleFactory.cpp b/src/port/resource/importers/AudioSampleFactory.cpp index f21389666..a253c533d 100644 --- a/src/port/resource/importers/AudioSampleFactory.cpp +++ b/src/port/resource/importers/AudioSampleFactory.cpp @@ -3,12 +3,14 @@ #include "../type/AudioSample.h" #include "spdlog/spdlog.h" -std::shared_ptr SM64::AudioSampleFactoryV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader(file)) { +std::shared_ptr +SM64::AudioSampleFactoryV0::ReadResource(std::shared_ptr file, + std::shared_ptr initData) { + if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } - std::shared_ptr bank = std::make_shared(file->InitData); + std::shared_ptr bank = std::make_shared(initData); auto reader = std::get>(file->Reader); bank->loop.start = reader->ReadUInt32(); diff --git a/src/port/resource/importers/AudioSampleFactory.h b/src/port/resource/importers/AudioSampleFactory.h index cf640bd5c..b1fe50455 100644 --- a/src/port/resource/importers/AudioSampleFactory.h +++ b/src/port/resource/importers/AudioSampleFactory.h @@ -6,6 +6,7 @@ namespace SM64 { class AudioSampleFactoryV0 : public Ship::ResourceFactoryBinary { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file, + std::shared_ptr initData) override; }; } diff --git a/src/port/resource/importers/AudioSequenceFactory.cpp b/src/port/resource/importers/AudioSequenceFactory.cpp index d021e8dc0..c8b421d46 100644 --- a/src/port/resource/importers/AudioSequenceFactory.cpp +++ b/src/port/resource/importers/AudioSequenceFactory.cpp @@ -4,12 +4,14 @@ #include "spdlog/spdlog.h" #include "port/Engine.h" -std::shared_ptr SM64::AudioSequenceFactoryV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader(file)) { +std::shared_ptr +SM64::AudioSequenceFactoryV0::ReadResource(std::shared_ptr file, + std::shared_ptr initData) { + if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } - std::shared_ptr bank = std::make_shared(file->InitData); + std::shared_ptr bank = std::make_shared(initData); auto reader = std::get>(file->Reader); uint8_t id = reader->ReadUInt32(); diff --git a/src/port/resource/importers/AudioSequenceFactory.h b/src/port/resource/importers/AudioSequenceFactory.h index dd08e5152..1132b78fb 100644 --- a/src/port/resource/importers/AudioSequenceFactory.h +++ b/src/port/resource/importers/AudioSequenceFactory.h @@ -7,6 +7,7 @@ namespace SM64 { class AudioSequenceFactoryV0 : public Ship::ResourceFactoryBinary { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file, + std::shared_ptr initData) override; }; } diff --git a/src/port/resource/importers/CourseVtxFactory.cpp b/src/port/resource/importers/CourseVtxFactory.cpp index 95f865698..2f2b60c33 100644 --- a/src/port/resource/importers/CourseVtxFactory.cpp +++ b/src/port/resource/importers/CourseVtxFactory.cpp @@ -4,12 +4,14 @@ #include "libultraship/libultra/gbi.h" namespace MK64 { -std::shared_ptr ResourceFactoryBinaryCourseVtxV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader(file)) { +std::shared_ptr +ResourceFactoryBinaryCourseVtxV0::ReadResource(std::shared_ptr file, + std::shared_ptr initData) { + if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } - auto cvtx = std::make_shared(file->InitData); + auto cvtx = std::make_shared(initData); auto reader = std::get>(file->Reader); uint32_t count = reader->ReadUInt32(); diff --git a/src/port/resource/importers/CourseVtxFactory.h b/src/port/resource/importers/CourseVtxFactory.h index aaa823515..e26088ef2 100644 --- a/src/port/resource/importers/CourseVtxFactory.h +++ b/src/port/resource/importers/CourseVtxFactory.h @@ -6,7 +6,8 @@ namespace MK64 { class ResourceFactoryBinaryCourseVtxV0 : public Ship::ResourceFactoryBinary { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file, + std::shared_ptr initData) override; }; } // namespace MK64 diff --git a/src/port/resource/importers/GenericArrayFactory.cpp b/src/port/resource/importers/GenericArrayFactory.cpp index 58f5ce6c7..a265b020d 100644 --- a/src/port/resource/importers/GenericArrayFactory.cpp +++ b/src/port/resource/importers/GenericArrayFactory.cpp @@ -3,12 +3,14 @@ #include "spdlog/spdlog.h" namespace SF64 { -std::shared_ptr ResourceFactoryBinaryGenericArrayV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader(file)) { +std::shared_ptr +ResourceFactoryBinaryGenericArrayV0::ReadResource(std::shared_ptr file, + std::shared_ptr initData) { + if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } - auto arr = std::make_shared(file->InitData); + auto arr = std::make_shared(initData); auto reader = std::get>(file->Reader); auto type = reader->ReadUInt32(); diff --git a/src/port/resource/importers/GenericArrayFactory.h b/src/port/resource/importers/GenericArrayFactory.h index 6984c1df0..9f21d44e6 100644 --- a/src/port/resource/importers/GenericArrayFactory.h +++ b/src/port/resource/importers/GenericArrayFactory.h @@ -6,6 +6,7 @@ namespace SF64 { class ResourceFactoryBinaryGenericArrayV0 : public Ship::ResourceFactoryBinary { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file, + std::shared_ptr initData) override; }; }; // namespace SF64 diff --git a/src/port/resource/importers/KartAIFactory.cpp b/src/port/resource/importers/KartAIFactory.cpp index 9459837da..e61fb52b5 100644 --- a/src/port/resource/importers/KartAIFactory.cpp +++ b/src/port/resource/importers/KartAIFactory.cpp @@ -4,12 +4,14 @@ #include "libultraship/libultra/gbi.h" namespace MK64 { -std::shared_ptr ResourceFactoryBinaryKartAIV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader(file)) { +std::shared_ptr +ResourceFactoryBinaryKartAIV0::ReadResource(std::shared_ptr file, + std::shared_ptr initData) { + if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } - auto ai = std::make_shared(file->InitData); + auto ai = std::make_shared(initData); auto reader = std::get>(file->Reader); uint32_t count = reader->ReadUInt32(); diff --git a/src/port/resource/importers/KartAIFactory.h b/src/port/resource/importers/KartAIFactory.h index b79d222de..7005f45dd 100644 --- a/src/port/resource/importers/KartAIFactory.h +++ b/src/port/resource/importers/KartAIFactory.h @@ -6,7 +6,8 @@ namespace MK64 { class ResourceFactoryBinaryKartAIV0 : public Ship::ResourceFactoryBinary { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file, + std::shared_ptr initData) override; }; } // namespace MK64 diff --git a/src/port/resource/importers/TrackSectionsFactory.cpp b/src/port/resource/importers/TrackSectionsFactory.cpp index 3a5f781b4..f1614fbb4 100644 --- a/src/port/resource/importers/TrackSectionsFactory.cpp +++ b/src/port/resource/importers/TrackSectionsFactory.cpp @@ -9,12 +9,14 @@ void* segmented_uintptr_t_to_virtual(uintptr_t); } namespace MK64 { -std::shared_ptr ResourceFactoryBinaryTrackSectionsV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader(file)) { +std::shared_ptr +ResourceFactoryBinaryTrackSectionsV0::ReadResource(std::shared_ptr file, + std::shared_ptr initData) { + if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } - auto section = std::make_shared(file->InitData); + auto section = std::make_shared(initData); auto reader = std::get>(file->Reader); uint32_t count = reader->ReadUInt32(); diff --git a/src/port/resource/importers/TrackSectionsFactory.h b/src/port/resource/importers/TrackSectionsFactory.h index 95d328e8c..5b9e67d09 100644 --- a/src/port/resource/importers/TrackSectionsFactory.h +++ b/src/port/resource/importers/TrackSectionsFactory.h @@ -6,7 +6,8 @@ namespace MK64 { class ResourceFactoryBinaryTrackSectionsV0 : public Ship::ResourceFactoryBinary { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file, + std::shared_ptr initData) override; }; } // namespace MK64 diff --git a/src/port/resource/importers/TrackWaypointFactory.cpp b/src/port/resource/importers/TrackWaypointFactory.cpp index 99b880427..0034cc607 100644 --- a/src/port/resource/importers/TrackWaypointFactory.cpp +++ b/src/port/resource/importers/TrackWaypointFactory.cpp @@ -4,12 +4,14 @@ #include "libultraship/libultra/gbi.h" namespace MK64 { -std::shared_ptr ResourceFactoryBinaryTrackWaypointsV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader(file)) { +std::shared_ptr +ResourceFactoryBinaryTrackWaypointsV0::ReadResource(std::shared_ptr file, + std::shared_ptr initData) { + if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } - auto section = std::make_shared(file->InitData); + auto section = std::make_shared(initData); auto reader = std::get>(file->Reader); uint32_t count = reader->ReadUInt32(); diff --git a/src/port/resource/importers/TrackWaypointFactory.h b/src/port/resource/importers/TrackWaypointFactory.h index 3f77aded5..311cd32b5 100644 --- a/src/port/resource/importers/TrackWaypointFactory.h +++ b/src/port/resource/importers/TrackWaypointFactory.h @@ -6,7 +6,8 @@ namespace MK64 { class ResourceFactoryBinaryTrackWaypointsV0 : public Ship::ResourceFactoryBinary { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file, + std::shared_ptr initData) override; }; } // namespace MK64 diff --git a/src/port/resource/importers/UnkActorSpawnDataFactory.cpp b/src/port/resource/importers/UnkActorSpawnDataFactory.cpp index 9307adbad..666aad618 100644 --- a/src/port/resource/importers/UnkActorSpawnDataFactory.cpp +++ b/src/port/resource/importers/UnkActorSpawnDataFactory.cpp @@ -6,12 +6,13 @@ namespace MK64 { std::shared_ptr -ResourceFactoryBinaryUnkActorSpawnDataV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader(file)) { +ResourceFactoryBinaryUnkActorSpawnDataV0::ReadResource(std::shared_ptr file, + std::shared_ptr initData) { + if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } - auto section = std::make_shared(file->InitData); + auto section = std::make_shared(initData); auto reader = std::get>(file->Reader); uint32_t count = reader->ReadUInt32(); diff --git a/src/port/resource/importers/UnkActorSpawnDataFactory.h b/src/port/resource/importers/UnkActorSpawnDataFactory.h index 5803bce00..28ddd9ce2 100644 --- a/src/port/resource/importers/UnkActorSpawnDataFactory.h +++ b/src/port/resource/importers/UnkActorSpawnDataFactory.h @@ -6,7 +6,8 @@ namespace MK64 { class ResourceFactoryBinaryUnkActorSpawnDataV0 : public Ship::ResourceFactoryBinary { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file, + std::shared_ptr initData) override; }; } // namespace MK64 diff --git a/src/port/resource/importers/Vec3fFactory.cpp b/src/port/resource/importers/Vec3fFactory.cpp index fc8f4d722..db9a571a9 100644 --- a/src/port/resource/importers/Vec3fFactory.cpp +++ b/src/port/resource/importers/Vec3fFactory.cpp @@ -3,12 +3,14 @@ #include "spdlog/spdlog.h" namespace SF64 { -std::shared_ptr ResourceFactoryBinaryVec3fV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader(file)) { +std::shared_ptr +ResourceFactoryBinaryVec3fV0::ReadResource(std::shared_ptr file, + std::shared_ptr initData) { + if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } - auto vec = std::make_shared(file->InitData); + auto vec = std::make_shared(initData); auto reader = std::get>(file->Reader); auto vecCount = reader->ReadUInt32(); diff --git a/src/port/resource/importers/Vec3fFactory.h b/src/port/resource/importers/Vec3fFactory.h index 73fb47e37..c1ed3749d 100644 --- a/src/port/resource/importers/Vec3fFactory.h +++ b/src/port/resource/importers/Vec3fFactory.h @@ -6,6 +6,7 @@ namespace SF64 { class ResourceFactoryBinaryVec3fV0 : public Ship::ResourceFactoryBinary { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file, + std::shared_ptr initData) override; }; }; // namespace SF64 diff --git a/src/port/resource/importers/Vec3sFactory.cpp b/src/port/resource/importers/Vec3sFactory.cpp index 8df00185c..df39b42d2 100644 --- a/src/port/resource/importers/Vec3sFactory.cpp +++ b/src/port/resource/importers/Vec3sFactory.cpp @@ -3,12 +3,14 @@ #include "spdlog/spdlog.h" namespace SF64 { -std::shared_ptr ResourceFactoryBinaryVec3sV0::ReadResource(std::shared_ptr file) { - if (!FileHasValidFormatAndReader(file)) { +std::shared_ptr +ResourceFactoryBinaryVec3sV0::ReadResource(std::shared_ptr file, + std::shared_ptr initData) { + if (!FileHasValidFormatAndReader(file, initData)) { return nullptr; } - auto vec = std::make_shared(file->InitData); + auto vec = std::make_shared(initData); auto reader = std::get>(file->Reader); auto vecCount = reader->ReadUInt32(); diff --git a/src/port/resource/importers/Vec3sFactory.h b/src/port/resource/importers/Vec3sFactory.h index f2339f146..5a05ec3ea 100644 --- a/src/port/resource/importers/Vec3sFactory.h +++ b/src/port/resource/importers/Vec3sFactory.h @@ -6,6 +6,7 @@ namespace SF64 { class ResourceFactoryBinaryVec3sV0 : public Ship::ResourceFactoryBinary { public: - std::shared_ptr ReadResource(std::shared_ptr file) override; + std::shared_ptr ReadResource(std::shared_ptr file, + std::shared_ptr initData) override; }; }; // namespace SF64 diff --git a/src/port/ui/ContentBrowser.cpp b/src/port/ui/ContentBrowser.cpp index 554c3b120..2cba6086c 100644 --- a/src/port/ui/ContentBrowser.cpp +++ b/src/port/ui/ContentBrowser.cpp @@ -26,13 +26,6 @@ namespace Editor { } void ContentBrowserWindow::DrawElement() { - static bool actorContent = false; - static bool objectContent = false; - static bool customContent = false; - static bool trackContent = false; - - - if (ImGui::Button(ICON_FA_REFRESH)) { Refresh = true; } @@ -49,31 +42,40 @@ namespace Editor { return; } - ContentBrowserWindow::FolderButton("Tracks", trackContent); - ContentBrowserWindow::FolderButton("Actors", actorContent); - ContentBrowserWindow::FolderButton("Objects", objectContent); - ContentBrowserWindow::FolderButton("Custom", customContent); + ImGui::BeginChild("LeftPanel", ImVec2(120, 0), true, ImGuiWindowFlags_None); - if (trackContent) { + ContentBrowserWindow::FolderButton("Tracks", TrackContent); + ContentBrowserWindow::FolderButton("Actors", ActorContent); + ContentBrowserWindow::FolderButton("Objects", ObjectContent); + ContentBrowserWindow::FolderButton("Custom", CustomContent); + ImGui::EndChild(); + ImGui::SameLine(); + ImGui::BeginChild("RightPanel", ImVec2(0, 0), true, ImGuiWindowFlags_None); + if (TrackContent) { AddTrackContent(); } - if (actorContent) { + if (ActorContent) { AddActorContent(); } - if (objectContent) { + if (ObjectContent) { AddObjectContent(); } - if (customContent) { + if (CustomContent) { AddCustomContent(); } + ImGui::EndChild(); } void ContentBrowserWindow::FolderButton(const char* label, bool& contentFlag, const ImVec2& size) { std::string buttonText = fmt::format("{0} {1}", contentFlag ? ICON_FA_FOLDER_OPEN_O : ICON_FA_FOLDER_O, label); if (ImGui::Button(buttonText.c_str(), size)) { + TrackContent = false; + ActorContent = false; + ObjectContent = false; + CustomContent = false; contentFlag = !contentFlag; } } @@ -189,6 +191,8 @@ namespace Editor { } void ContentBrowserWindow::AddCustomContent() { + FVector pos = GetPositionAheadOfCamera(300.0f); + size_t i_custom = 0; for (const auto& file : Content) { if ((i_custom != 0) && (i_custom % 10 == 0)) { @@ -201,7 +205,7 @@ namespace Editor { int coll; //printf("ContentBrowser.cpp: name: %s\n", test.c_str()); std::string name = file.substr(file.find_last_of('/') + 1); - auto actor = gWorldInstance.AddStaticMeshActor(name, FVector(50, 100, 0), IRotator(0, 90, 0), FVector(1, 1, 1), "__OTR__" + file, &coll); + auto actor = gWorldInstance.AddStaticMeshActor(name, FVector(pos), IRotator(0, 0, 0), FVector(1, 1, 1), "__OTR__" + file, &coll); // This is required because ptr gets cleaned up. actor->Model = "__OTR__" + file; diff --git a/src/port/ui/ContentBrowser.h b/src/port/ui/ContentBrowser.h index 49a503995..988947185 100644 --- a/src/port/ui/ContentBrowser.h +++ b/src/port/ui/ContentBrowser.h @@ -14,6 +14,11 @@ public: std::unordered_map TrackPath; bool Refresh = true; + + bool ActorContent = false; + bool ObjectContent = false; + bool CustomContent = false; + bool TrackContent = false; protected: void InitElement() override {}; void DrawElement() override; diff --git a/src/port/ui/Properties.cpp b/src/port/ui/Properties.cpp index 70a2728e9..29cbe8858 100644 --- a/src/port/ui/Properties.cpp +++ b/src/port/ui/Properties.cpp @@ -13,6 +13,7 @@ #include "engine/editor/Editor.h" #include "port/Game.h" +#include "src/engine/World.h" namespace Editor { diff --git a/src/port/ui/UIWidgets.cpp b/src/port/ui/UIWidgets.cpp index 1368cf420..2495aef4e 100644 --- a/src/port/ui/UIWidgets.cpp +++ b/src/port/ui/UIWidgets.cpp @@ -263,7 +263,7 @@ bool Checkbox(const char* _label, bool* value, const CheckboxOptions& options) { : ImGuiCol_FrameBg), true, style.FrameRounding); ImU32 check_col = ImGui::GetColorU32(ImGuiCol_CheckMark); - bool mixed_value = (g.LastItemData.InFlags & ImGuiItemFlags_MixedValue) != 0; + bool mixed_value = (g.LastItemData.ItemFlags & ImGuiItemFlags_MixedValue) != 0; if (mixed_value) { // Undocumented tristate/mixed/indeterminate checkbox (#2644) // This may seem awkwardly designed because the aim is to make ImGuiItemFlags_MixedValue supported by all diff --git a/src/stubs.c b/src/stubs.c index 7d4e39f1c..b197ec6e3 100644 --- a/src/stubs.c +++ b/src/stubs.c @@ -96,9 +96,6 @@ s32 osPfsAllocateFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name return PFS_NO_ERROR; } -void osSetTime(OSTime time) { -} - s32 osPfsIsPlug(OSMesgQueue* queue, u8* pattern) { }