summaryrefslogtreecommitdiff
path: root/src/Main/Actor/ActorType.cpp
blob: cef37bb48b2aac3626561eb1d417b7bb4d86ddab (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "Actor/ActorType.hpp"

ActorTypeList sActorTypeList;

ARM ActorType::ActorType(ActorTypeId id, ActorCreateFunc create, unk32 (*unk_08)()) {
    this->id     = id;
    this->create = create;
    this->unk_08 = unk_08;
    this->unk_0c = 0;
    this->next   = NULL;
    this->Register();
    sActorTypeList.tail = this;
}

ARM ActorType::~ActorType() {
    this->Unregister();
}

ARM unk32 ActorType::func_0203e7c8() {
    if (this->unk_08 == NULL) {
        return 0;
    }
    return (*unk_08)();
}

ARM void ActorType::Register() {
    ActorType *actorType;
    ActorType **tail = &sActorTypeList.head;

    for (actorType = sActorTypeList.head; actorType != NULL; actorType = actorType->next) {
        tail = &actorType->next;
    }

    *tail = this;
}

ARM void ActorType::Unregister() {
    ActorType *actorType;

    ActorType **current  = &sActorTypeList.head;
    ActorType **previous = NULL;

    for (actorType = sActorTypeList.head; actorType != NULL; actorType = actorType->next) {
        if (actorType == this) {
            break;
        }
        previous = current;
        current  = &actorType->next;
    }

    if (previous != NULL) {
        (*previous)->next = this->next;
    }
}

ARM ActorType *ActorType::Find(ActorTypeId id) {
    ActorType *actorType;

    for (actorType = sActorTypeList.head; actorType != NULL; actorType = actorType->next) {
        if (id == actorType->id) {
            return actorType;
        }
    }

    return NULL;
}