mirror of
https://github.com/HarbourMasters/SpaghettiKart
synced 2026-09-03 02:33:55 -04:00
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
This commit is contained in:
@@ -106,7 +106,7 @@ void World::TickCameras() {
|
||||
}
|
||||
}
|
||||
|
||||
for (GameCamera* camera : Cameras) {
|
||||
for (auto& camera : Cameras) {
|
||||
if (camera->IsActive()) {
|
||||
camera->Tick();
|
||||
}
|
||||
@@ -215,9 +215,9 @@ void World::TickObjects60fps() {
|
||||
}
|
||||
}
|
||||
|
||||
ParticleEmitter* World::AddEmitter(ParticleEmitter* emitter) {
|
||||
Emitters.push_back(emitter);
|
||||
return Emitters.back();
|
||||
ParticleEmitter* World::AddEmitter(std::unique_ptr<ParticleEmitter> emitter) {
|
||||
Emitters.push_back(std::move(emitter));
|
||||
return Emitters.back().get();
|
||||
}
|
||||
|
||||
void World::DrawObjects(s32 cameraId) {
|
||||
@@ -259,10 +259,6 @@ void World::CleanWorld(void) {
|
||||
|
||||
World::Reset(); // Reset OObjects
|
||||
|
||||
for (auto& emitter : Emitters) {
|
||||
delete emitter;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < ARRAY_COUNT(mPlayerBombKart); i++) {
|
||||
mPlayerBombKart[i].state = PlayerBombKart::PlayerBombKartState::DISABLED;
|
||||
mPlayerBombKart[i]._primAlpha = 0;
|
||||
|
||||
+4
-4
@@ -86,10 +86,10 @@ public:
|
||||
|
||||
void TickParticles();
|
||||
void DrawParticles(s32 cameraId);
|
||||
ParticleEmitter* AddEmitter(ParticleEmitter* emitter);
|
||||
ParticleEmitter* AddEmitter(std::unique_ptr<ParticleEmitter> emitter);
|
||||
void Reset(void); // Sets OObjects or AActors static member variables back to default values
|
||||
|
||||
void AddCup(Cup*);
|
||||
void AddCup(Cup* cup);
|
||||
void SetCurrentCup(Cup* cup);
|
||||
Cup* GetCurrentCup() {
|
||||
return CurrentCup;
|
||||
@@ -115,12 +115,12 @@ public:
|
||||
std::vector<Cup*> Cups;
|
||||
size_t CupIndex = 1;
|
||||
|
||||
std::vector<GameCamera*> Cameras;
|
||||
std::vector<std::unique_ptr<GameCamera>> Cameras;
|
||||
|
||||
std::vector<std::unique_ptr<StaticMeshActor>> StaticMeshActors;
|
||||
std::vector<std::unique_ptr<AActor>> Actors;
|
||||
std::vector<std::unique_ptr<OObject>> Objects;
|
||||
std::vector<ParticleEmitter*> Emitters;
|
||||
std::vector<std::unique_ptr<ParticleEmitter>> Emitters;
|
||||
|
||||
std::unordered_map<s32, OLakitu*> Lakitus;
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ public:
|
||||
~Editor();
|
||||
|
||||
ObjectPicker eObjectPicker;
|
||||
std::vector<GameObject*> eGameObjects;
|
||||
std::vector<std::unique_ptr<GameObject>> eGameObjects;
|
||||
|
||||
void Load();
|
||||
void Enable();
|
||||
|
||||
@@ -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() {};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -79,6 +79,12 @@ std::vector<std::string> ListMods() {
|
||||
|
||||
const std::string mods_path = Ship::Context::GetPathRelativeToAppDirectory("mods");
|
||||
|
||||
// Create mods folder if it doesn't exist
|
||||
if (!std::filesystem::exists(mods_path)) {
|
||||
std::filesystem::create_directories(mods_path);
|
||||
SPDLOG_INFO("Created mods folder at: {}", mods_path);
|
||||
}
|
||||
|
||||
if (std::filesystem::exists(mods_path) && std::filesystem::is_directory(mods_path)) {
|
||||
for (const auto& p : std::filesystem::directory_iterator(mods_path)) {
|
||||
auto ext = p.path().extension().string();
|
||||
|
||||
@@ -92,7 +92,7 @@ OTrophy::OTrophy(const SpawnParams& params) : OObject(params) {
|
||||
object->pos[1] = spawnPos.y;
|
||||
object->pos[2] = spawnPos.z;
|
||||
|
||||
_emitter = reinterpret_cast<StarEmitter*>(GetWorld()->AddEmitter(new StarEmitter()));
|
||||
_emitter = reinterpret_cast<StarEmitter*>(GetWorld()->AddEmitter(std::make_unique<StarEmitter>()));
|
||||
}
|
||||
|
||||
void OTrophy::SetSpawnParams(SpawnParams& params) {
|
||||
|
||||
@@ -287,6 +287,7 @@ void KoopaTroopaBeach::ScrollingTextures() {
|
||||
}
|
||||
|
||||
void KoopaTroopaBeach::DrawWater(ScreenContext* screen, uint16_t pathCounter, uint16_t cameraRot, uint16_t playerDirection) {
|
||||
Mat4 matrix;
|
||||
Vec3f vector;
|
||||
|
||||
gDPPipeSync(gDisplayListHead++);
|
||||
@@ -312,6 +313,13 @@ void KoopaTroopaBeach::DrawWater(ScreenContext* screen, uint16_t pathCounter, ui
|
||||
vector[0] = 0.0f;
|
||||
vector[1] = Props.WaterLevel;
|
||||
vector[2] = 0.0f;
|
||||
mtxf_translate(matrix, vector);
|
||||
if (gIsMirrorMode != 0) {
|
||||
matrix[0][0] = -1.0f;
|
||||
// matrix[1][1] = -1.0f;
|
||||
// matrix[2][2] = -1.0f;
|
||||
}
|
||||
render_set_position(matrix, 0);
|
||||
|
||||
gDPSetRenderMode(gDisplayListHead++, G_RM_AA_ZB_XLU_INTER, G_RM_NOOP2);
|
||||
gDPSetBlendMask(gDisplayListHead++, 0xFF);
|
||||
|
||||
Reference in New Issue
Block a user