-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.cpp
100 lines (80 loc) · 1.77 KB
/
game.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "game.h"
#include "io.h"
#include "scene.h"
#include "ui.h"
#include "messages.h"
#include "basemessage.h"
#include "toolkit.h"
Game::Game()
: quit(false) {
}
Game::~Game() {
}
int Game::Init() {
START
sys[GamePart::IO] = new IO(&messages, &quit);
sys[GamePart::SCENE] = new Scene(&messages);
sys[GamePart::UI] = new UI(&messages);
/*
for (int i = 0; i < GamePart::MAX; i++) {
if (err) break;
switch (i) {
case GamePart::IO: {
err += (io*)sys[i]->Init();
} break;
case GamePart::SCENE: {
err += (scene*)sys[i]->Init();
} break;
//ACTORS, // Player, enemies, creatures, NPCs... (anything living)
//ITEM, // Stones, budles of mud, cookies, swords... (anything movable/usable/interactable, non-living thing)
//PROPS, // Boulder, wall, floor, ocean of mud (anything unmovable)
case GamePart::UI: {
err += (ui*)sys[i]->Init();
} break;
}
}
*/
for (int i = 0; i < GamePart::MAX; i++)
err += sys[i]->Init();
STOP
}
int Game::Update() {
START
while (!quit) {
for (int i = 0; i < GamePart::MAX; i++) {
LOGF("Updating GamePart: %d", i);
err += sys[i]->UpdateMsgs();
err += sys[i]->Update();
}
err += UpdateMsgs();
}
STOP
}
int Game::UpdateMsgs() {
START
list<BaseMessage*>::iterator it;
// rm invalid, split to net
for (it = messages.begin(); it != messages.end();) {
if (!(*it)->GetValid()) {
if ((*it)->GetNext() != (BaseMessage*)0) {
messages.push_back((*it)->GetNext());
(*it)->SetNext((BaseMessage*)0);
}
BaseMessage* tmp_msg = (*it);
it = messages.erase(it);
delete tmp_msg;
}
else {
it++;
}
}
STOP
}
// Quiting/stopping systems and exits
int Game::Deinit() {
START
for (int i = 0; i < GamePart::MAX; i++) {
err += sys[i]->Deinit();
}
STOP
}