mirror of
https://github.com/HarbourMasters/SpaghettiKart
synced 2026-06-06 11:47:59 -04:00
fffd3f7fe9
* Create RaceManager.cpp * Create RaceManager class for race lifecycle management Added RaceManager class to manage race events lifecycle. * Refactor World class and implement ClearWorld method Refactor World class constructor and destructor. Implement ClearWorld method to delete all objects and reset state. * Add RaceManager to World class * Update ValidateString for editor mode checks Refactor ValidateString to handle editor mode and empty strings. * Update Text.cpp * Add SetText method to Text class * Document RunGarbageCollector function Added documentation for the RunGarbageCollector function. * Refactor Game.cpp by removing dead code Removed unused ruleset handling and clean-up code. * Update Game.h * Remove CM_SpawnFromLevelProps call * Update Text.cpp * Update World.cpp * Add Clean method to RaceManager class * Update RaceManager.cpp * Update World.cpp * Update World.h * Update World.cpp
58 lines
1.7 KiB
C++
58 lines
1.7 KiB
C++
#include "GarbageCollector.h"
|
|
#include "World.h"
|
|
|
|
/**
|
|
* Removes objects if they are marked for deletion
|
|
*/
|
|
void RunGarbageCollector() {
|
|
CleanActors();
|
|
CleanObjects();
|
|
CleanStaticMeshActors();
|
|
}
|
|
|
|
void CleanActors() {
|
|
for (auto actor = gWorldInstance.Actors.begin(); actor != gWorldInstance.Actors.end();) {
|
|
AActor* act = *actor; // Get a mutable copy
|
|
if (act->bPendingDestroy) {
|
|
if (act->IsMod()) { // C++ actor
|
|
delete act;
|
|
actor = gWorldInstance.Actors.erase(actor); // Remove from container
|
|
} else { // Old C actor
|
|
act->Flags = 0;
|
|
act->Type = 0;
|
|
act->Name = "";
|
|
act->ResourceName = "";
|
|
actor++; // Manually advance the iterator since no deletion happens here
|
|
}
|
|
gNumActors -= 1;
|
|
continue;
|
|
}
|
|
actor++;
|
|
}
|
|
}
|
|
|
|
void CleanStaticMeshActors() {
|
|
for (auto actor = gWorldInstance.StaticMeshActors.begin(); actor != gWorldInstance.StaticMeshActors.end();) {
|
|
StaticMeshActor* act = *actor; // Get a mutable copy
|
|
if (act->bPendingDestroy) {
|
|
delete act;
|
|
actor = gWorldInstance.StaticMeshActors.erase(actor); // Remove from container
|
|
continue;
|
|
} else {
|
|
actor++;
|
|
}
|
|
}
|
|
}
|
|
|
|
void CleanObjects() {
|
|
for (auto object = gWorldInstance.Objects.begin(); object != gWorldInstance.Objects.end();) {
|
|
OObject* obj = *object; // Get a mutable copy
|
|
if (obj->bPendingDestroy) {
|
|
delete obj;
|
|
object = gWorldInstance.Objects.erase(object); // Remove from container
|
|
continue;
|
|
}
|
|
object++;
|
|
}
|
|
}
|