comparison libcore/core/game.c @ 147:b386d25832c8

doc: use new nomenclature, closes #2497
author David Demelier <markand@malikania.fr>
date Thu, 15 Oct 2020 09:21:04 +0200
parents 30b68089ae70
children 629f55f3961e
comparison
equal deleted inserted replaced
146:7d7ea7a9cf50 147:b386d25832c8
24 #include "state.h" 24 #include "state.h"
25 #include "painter.h" 25 #include "painter.h"
26 26
27 struct game game; 27 struct game game;
28 28
29 #if 0
30
31 static struct action *
32 find_empty_action(void)
33 {
34 static struct action null;
35
36 for (struct action *a = game.actions; a != &game.actions[GAME_ACTIONS_MAX]; ++a)
37 if (memcmp(a, &null, sizeof (struct action)) == 0)
38 return a;
39
40 return NULL;
41 }
42
43 static void
44 clear_actions(void)
45 {
46 for (struct action *a = game.actions; a != &game.actions[GAME_ACTIONS_MAX]; ++a) {
47 /* These actions are removed on state change. */
48 if (a->flags & ACTION_AUTO_LEAVE) {
49 if (a->finish)
50 a->finish(a);
51
52 memset(a, 0, sizeof (struct action));
53 }
54 }
55 }
56
57 static void
58 handle_actions(const union event *event)
59 {
60 for (struct action *a = game.actions; a != &game.actions[GAME_ACTIONS_MAX]; ++a)
61 if (a->handle)
62 a->handle(a, event);
63 }
64
65 static void
66 update_actions(unsigned int ticks)
67 {
68 for (size_t i = 0; i < GAME_ACTIONS_MAX; ++i) {
69 struct action *a = &game.actions[i];
70
71 if (!a->update)
72 continue;
73
74 if (a->update(a, ticks)) {
75 if (a->end)
76 a->end(a);
77 if (a->finish)
78 a->finish(a);
79
80 memset(&game.actions[i], 0, sizeof (struct action));
81 }
82 }
83 }
84
85 static void
86 draw_actions(void)
87 {
88 for (size_t i = 0; i < GAME_ACTIONS_MAX; ++i)
89 if (game.actions[i].draw)
90 game.actions[i].draw(&game.actions[i]);
91 }
92
93 #endif
94
95 void 29 void
96 game_switch(struct state *state, bool quick) 30 game_switch(struct state *state, bool quick)
97 { 31 {
98 assert(state); 32 assert(state);
99 33
110 { 44 {
111 assert(event); 45 assert(event);
112 46
113 if (game.state && !(game.inhibit & INHIBIT_STATE_INPUT)) 47 if (game.state && !(game.inhibit & INHIBIT_STATE_INPUT))
114 game.state->handle(event); 48 game.state->handle(event);
115
116 #if 0
117 handle_actions(event);
118 #endif
119 } 49 }
120 50
121 void 51 void
122 game_update(unsigned int ticks) 52 game_update(unsigned int ticks)
123 { 53 {
129 game.state->leave(); 59 game.state->leave();
130 60
131 game.state = game.state_next; 61 game.state = game.state_next;
132 game.state->enter(); 62 game.state->enter();
133 game.state_next = NULL; 63 game.state_next = NULL;
134
135 #if 0
136 /* Remove any actions that must be deleted. */
137 clear_actions();
138 #endif
139 } 64 }
140 65
141 if (game.state) 66 if (game.state)
142 game.state->update(ticks); 67 game.state->update(ticks);
143 } 68 }
144
145 #if 0
146 update_actions(ticks);
147 #endif
148 } 69 }
149 70
150 void 71 void
151 game_draw(void) 72 game_draw(void)
152 { 73 {
153 if (game.state && !(game.inhibit & INHIBIT_STATE_DRAW)) 74 if (game.state && !(game.inhibit & INHIBIT_STATE_DRAW))
154 game.state->draw(); 75 game.state->draw();
155 76
156 #if 0
157 draw_actions();
158 #endif
159 painter_present(); 77 painter_present();
160 } 78 }
161
162 #if 0
163 void
164 game_add_action(const struct action *action)
165 {
166 assert(action);
167
168 struct action *pos;
169
170 if ((pos = find_empty_action()))
171 memcpy(pos, action, sizeof (struct action));
172 }
173 #endif
174 79
175 void 80 void
176 game_quit(void) 81 game_quit(void)
177 { 82 {
178 if (game.state && game.state->leave) 83 if (game.state && game.state->leave)