summaryrefslogtreecommitdiff
path: root/src/engine/editor
diff options
context:
space:
mode:
authorcoco875 <59367621+coco875@users.noreply.github.com>2025-12-22 22:48:07 +0100
committerGitHub <noreply@github.com>2025-12-22 14:48:07 -0700
commitce92773a602cca246c44dbec9fb87656fedfa323 (patch)
tree19bee63b1ae4ad566eaeb66d83f90257d6407fea /src/engine/editor
parent31c2063a61feddb340a48beb7c0376b885c8ce00 (diff)
Clean ptr and fix (#610)
* use more unique ptr and fix a shell crash * remove useless mods folder * add even more unique_ptr * Update KoopaTroopaBeach.cpp * restore a throw * Update Game.cpp * automatically create mods folder * fix oob in external by assuming that all 8 player can make sound * better texture loading * add destructor for gameobject * avoid out of bound in audio sample * Update FrameInterpolation.cpp * Update torch
Diffstat (limited to 'src/engine/editor')
-rw-r--r--src/engine/editor/Editor.cpp21
-rw-r--r--src/engine/editor/Editor.h2
-rw-r--r--src/engine/editor/GameObject.h1
-rw-r--r--src/engine/editor/ObjectPicker.cpp4
4 files changed, 15 insertions, 13 deletions
diff --git a/src/engine/editor/Editor.cpp b/src/engine/editor/Editor.cpp
index 87bca2a82..d8eeecda9 100644
--- a/src/engine/editor/Editor.cpp
+++ b/src/engine/editor/Editor.cpp
@@ -40,7 +40,7 @@ namespace TrackEditor {
printf("Editor: Loading Editor...\n");
eObjectPicker.Load();
for (auto& object : eGameObjects) {
- GenerateCollisionMesh(object, (Gfx*)object->Model, 1.0f);
+ GenerateCollisionMesh(object.get(), (Gfx*)object->Model, 1.0f);
object->Load();
}
@@ -150,7 +150,11 @@ namespace TrackEditor {
eObjectPicker.eGizmo.SelectedHandle = Gizmo::GizmoHandle::None;
eObjectPicker.eGizmo.ManipulationStart = true;
if (!isDragging) {
- eObjectPicker.SelectObject(eGameObjects);
+ std::vector<GameObject*> objects;
+ for (auto& object : eGameObjects) {
+ objects.push_back(object.get());
+ }
+ eObjectPicker.SelectObject(objects);
}
}
@@ -178,25 +182,22 @@ namespace TrackEditor {
// pos->x, pos->y, pos->z, name, model);
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);
+ eGameObjects.push_back(std::make_unique<GameObject>(pos, rot, scale, model, std::vector<Triangle>(), collision, boundingBoxSize));
+ GenerateCollisionMesh(eGameObjects.back().get(), (Gfx*)LOAD_ASSET_RAW(model), collScale);
} else { // to bounding box or sphere collision
- eGameObjects.push_back(new GameObject(pos, rot, scale, model, {}, GameObject::CollisionType::BOUNDING_BOX,
+ eGameObjects.push_back(std::make_unique<GameObject>(pos, rot, scale, model, std::vector<Triangle>(), GameObject::CollisionType::BOUNDING_BOX,
10.0f));
}
- return eGameObjects.back();
+ return eGameObjects.back().get();
}
void Editor::AddLight(const char* name, FVector* pos, s8* rot) {
- eGameObjects.push_back(new LightObject(name, pos, rot));
+ eGameObjects.push_back(std::make_unique<LightObject>(name, pos, rot));
}
void Editor::ClearObjects() {
ResetGizmo();
- for (auto& obj : eGameObjects) {
- delete obj;
- }
eGameObjects.clear();
}
diff --git a/src/engine/editor/Editor.h b/src/engine/editor/Editor.h
index 956d795b7..8708bb1c9 100644
--- a/src/engine/editor/Editor.h
+++ b/src/engine/editor/Editor.h
@@ -23,7 +23,7 @@ public:
~Editor();
ObjectPicker eObjectPicker;
- std::vector<GameObject*> eGameObjects;
+ std::vector<std::unique_ptr<GameObject>> eGameObjects;
void Load();
void Enable();
diff --git a/src/engine/editor/GameObject.h b/src/engine/editor/GameObject.h
index 00087105e..342ee8192 100644
--- a/src/engine/editor/GameObject.h
+++ b/src/engine/editor/GameObject.h
@@ -27,6 +27,7 @@ public:
GameObject(FVector pos, IRotator rot, FVector scale, const char* model, std::vector<Triangle> triangles, CollisionType collision, float boundingBoxSize);
GameObject();
+ virtual ~GameObject() = default;
virtual void Tick();
virtual void Draw();
virtual void Load() {};
diff --git a/src/engine/editor/ObjectPicker.cpp b/src/engine/editor/ObjectPicker.cpp
index 7fd4cc407..013ad983e 100644
--- a/src/engine/editor/ObjectPicker.cpp
+++ b/src/engine/editor/ObjectPicker.cpp
@@ -203,7 +203,7 @@ std::pair<GameObject*, float> ObjectPicker::CheckEditorObjectRay(Ray ray) {
if (IntersectRayTriangleAndTransform(ray, object->Pos, tri, t)) {
if (t < hitDistance) {
hitDistance = t;
- hitObject = object;
+ hitObject = object.get();
}
}
}
@@ -222,7 +222,7 @@ std::pair<GameObject*, float> ObjectPicker::CheckEditorObjectRay(Ray ray) {
if (QueryCollisionRayActor(&ray.Origin.x, &ray.Direction.x, boxMin, boxMax, &t)) {
if (t < hitDistance) {
hitDistance = t;
- hitObject = object;
+ hitObject = object.get();
printf("FOUND BOUNDING BOX OBJECT\n");
}
break;