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/editor/Editor.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/editor/Editor.cpp')
| -rw-r--r-- | src/engine/editor/Editor.cpp | 78 |
1 files changed, 50 insertions, 28 deletions
diff --git a/src/engine/editor/Editor.cpp b/src/engine/editor/Editor.cpp index 1741cafa5..2fada8a29 100644 --- a/src/engine/editor/Editor.cpp +++ b/src/engine/editor/Editor.cpp @@ -24,9 +24,6 @@ extern "C" { } namespace Editor { - int gfx_create_framebuffer(uint32_t width, uint32_t height, uint32_t native_width, uint32_t native_height, - uint8_t resize); - Editor::Editor() { } @@ -39,21 +36,35 @@ namespace Editor { printf("Editor: Loading Editor...\n"); eObjectPicker.Load(); for (auto& object : eGameObjects) { - GenerateCollisionMesh(object, object->Model, 1.0f); + GenerateCollisionMesh(object, (Gfx*)object->Model, 1.0f); object->Load(); } + printf("Editor: Loading Complete!\n"); } - void Editor::Tick() { + void Editor::GenerateCollision() { + // for (auto& actor : gWorldInstance.Actors) { + // GenerateCollisionMesh(actor, (Gfx*)actor->Model, 1.0f); + // } + } + void Editor::Tick() { if (CVarGetInteger("gEditorEnabled", 0) == true) { bEditorEnabled = true; } else { bEditorEnabled = false; + gIsEditorPaused = false; // Prevents game being paused with the editor closed. return; } + // Set camera + if (CVarGetInteger("gFreecam", 0) == true) { + eCamera = &cameras[CAMERA_FREECAM]; + } else { + eCamera = &cameras[0]; + } + auto wnd = GameEngine::Instance->context->GetWindow(); static bool wasMouseDown = false; @@ -63,16 +74,16 @@ namespace Editor { Ship::Coords mousePos = wnd->GetMousePos(); bool isMouseDown = wnd->GetMouseState(Ship::LUS_MOUSE_BTN_LEFT); - auto it = std::remove_if(eGameObjects.begin(), eGameObjects.end(), - [](auto& object) { - if (*object->DespawnFlag == object->DespawnValue) { - delete object; // Free the pointed-to memory - return true; // Remove the pointer from the vector - } - return false; - }); + //auto it = std::remove_if(eGameObjects.begin(), eGameObjects.end(), + // [](auto& object) { + // if (*object->DespawnFlag == object->DespawnValue) { + // delete object; // Free the pointed-to memory + // return true; // Remove the pointer from the vector + // } + // return false; + // }); - eGameObjects.erase(it, eGameObjects.end()); + //eGameObjects.erase(it, eGameObjects.end()); if (isMouseDown && !wasMouseDown) { // Mouse just pressed (Pressed state) @@ -80,7 +91,7 @@ namespace Editor { isDragging = false; } - if (isMouseDown) { + if (isMouseDown) { // Mouse is being held (Held state) int dx = mousePos.x - mouseStartPos.x; int dy = mousePos.y - mouseStartPos.y; @@ -122,15 +133,16 @@ namespace Editor { } } - 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) { + GameObject* Editor::AddObject(FVector pos, IRotator rot, FVector scale, const char* model, float collScale, GameObject::CollisionType collision, float boundingBoxSize) { //printf("After AddObj: Pos(%f, %f, %f), Name: %s, Model: %s\n", // pos->x, pos->y, pos->z, name, model); - if (model != nullptr) { - eGameObjects.push_back(new GameObject(name, pos, rot, scale, model, {}, collision, boundingBoxSize, despawnFlag, despawnValue)); - GenerateCollisionMesh(eGameObjects.back(), model, collScale); + + if (nullptr != model && model[0] != '\0') { + eGameObjects.push_back(new GameObject(pos, rot, scale, model, {}, collision, boundingBoxSize)); + GenerateCollisionMesh(eGameObjects.back(), (Gfx*)LOAD_ASSET_RAW(model), collScale); } else { // to bounding box or sphere collision - eGameObjects.push_back(new GameObject(name, pos, rot, scale, model, {}, GameObject::CollisionType::BOUNDING_BOX, - 10.0f, despawnFlag, despawnValue)); + eGameObjects.push_back(new GameObject(pos, rot, scale, model, {}, GameObject::CollisionType::BOUNDING_BOX, + 10.0f)); } return eGameObjects.back(); } @@ -140,27 +152,37 @@ namespace Editor { } void Editor::ClearObjects() { + ResetGizmo(); + for (auto& obj : eGameObjects) { delete obj; } eGameObjects.clear(); } + // Reset the gizmo + void Editor::ResetGizmo() { + eObjectPicker.eGizmo._selected = static_cast<GameObject*>(nullptr); + eObjectPicker._selected = static_cast<GameObject*>(nullptr); + eObjectPicker.eGizmo.Pos = FVector(0, 0, 0); + eObjectPicker.eGizmo.Enabled = false; + } + void Editor::DeleteObject() { - Gizmo* gizmo = &eObjectPicker.eGizmo; - if (gizmo->_selected && gizmo->_selected->DespawnFlag) { - *gizmo->_selected->DespawnFlag = gizmo->_selected->DespawnValue; - gizmo->_selected = nullptr; - eObjectPicker._selected = nullptr; - } + std::visit([this](auto* obj) { + if (nullptr != obj) { + gEditor.ResetGizmo(); // Unselect the object to prevent crashes + obj->Destroy(); + } + }, eObjectPicker.eGizmo._selected); } void Editor::ClearMatrixPool() { EditorMatrix.clear(); } - void Editor::SelectObjectFromSceneExplorer(GameObject* object) { + void Editor::SelectObjectFromSceneExplorer(std::variant<AActor*, OObject*, GameObject*> object) { eObjectPicker._selected = object; eObjectPicker.eGizmo.Enabled = true; eObjectPicker.eGizmo.SetGizmoNoCursor(object); |
