summaryrefslogtreecommitdiff
path: root/src/engine/GarbageCollector.cpp
blob: 926620fe1f2b4d80d519cf1beaf1ec7f3b8c4544 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "GarbageCollector.h"
#include "World.h"

void RunGarbageCollector() {
    //CleanActors();
    CleanObjects();
}

void CleanActors() {
    // for (auto actor = gWorldInstance.Actors.begin(); actor != gWorldInstance.Actors.end();) {
    //     OObject* act = *actor; // Get a mutable copy
    //     if (act->PendingDestroy) {
    //         delete act;
    //         actor = gWorldInstance.Objects.erase(actor); // Remove from container
    //         continue;
    //     }
    //     actor++;
    // }
}

void CleanObjects() {
    for (auto object = gWorldInstance.Objects.begin(); object != gWorldInstance.Objects.end();) {
        OObject* obj = *object; // Get a mutable copy
        if (obj->PendingDestroy) {
            delete obj;
            object = gWorldInstance.Objects.erase(object); // Remove from container
            continue;
        }
        object++;
    }
}