Mercurial > molko
comparison libcore/core/game.c @ 136:30b68089ae70
core: rework actions and a bit of drawables, closes #2492
In the effort of having as less as possible memory allocation in libcore, the
usage of actions and drawable no longer copy the original source parameter to
let user pass a heap allocated variable or a static storage one.
Update predefined drawable and actions to match these new needs.
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 13 Oct 2020 09:38:44 +0200 |
parents | 09978921e281 |
children | b386d25832c8 |
comparison
equal
deleted
inserted
replaced
135:eadfed7674ac | 136:30b68089ae70 |
---|---|
23 #include "game.h" | 23 #include "game.h" |
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 | |
29 #if 0 | |
28 | 30 |
29 static struct action * | 31 static struct action * |
30 find_empty_action(void) | 32 find_empty_action(void) |
31 { | 33 { |
32 static struct action null; | 34 static struct action null; |
86 for (size_t i = 0; i < GAME_ACTIONS_MAX; ++i) | 88 for (size_t i = 0; i < GAME_ACTIONS_MAX; ++i) |
87 if (game.actions[i].draw) | 89 if (game.actions[i].draw) |
88 game.actions[i].draw(&game.actions[i]); | 90 game.actions[i].draw(&game.actions[i]); |
89 } | 91 } |
90 | 92 |
93 #endif | |
94 | |
91 void | 95 void |
92 game_switch(struct state *state, bool quick) | 96 game_switch(struct state *state, bool quick) |
93 { | 97 { |
94 assert(state); | 98 assert(state); |
95 | 99 |
107 assert(event); | 111 assert(event); |
108 | 112 |
109 if (game.state && !(game.inhibit & INHIBIT_STATE_INPUT)) | 113 if (game.state && !(game.inhibit & INHIBIT_STATE_INPUT)) |
110 game.state->handle(event); | 114 game.state->handle(event); |
111 | 115 |
116 #if 0 | |
112 handle_actions(event); | 117 handle_actions(event); |
118 #endif | |
113 } | 119 } |
114 | 120 |
115 void | 121 void |
116 game_update(unsigned int ticks) | 122 game_update(unsigned int ticks) |
117 { | 123 { |
124 | 130 |
125 game.state = game.state_next; | 131 game.state = game.state_next; |
126 game.state->enter(); | 132 game.state->enter(); |
127 game.state_next = NULL; | 133 game.state_next = NULL; |
128 | 134 |
135 #if 0 | |
129 /* Remove any actions that must be deleted. */ | 136 /* Remove any actions that must be deleted. */ |
130 clear_actions(); | 137 clear_actions(); |
138 #endif | |
131 } | 139 } |
132 | 140 |
133 if (game.state) | 141 if (game.state) |
134 game.state->update(ticks); | 142 game.state->update(ticks); |
135 } | 143 } |
136 | 144 |
145 #if 0 | |
137 update_actions(ticks); | 146 update_actions(ticks); |
147 #endif | |
138 } | 148 } |
139 | 149 |
140 void | 150 void |
141 game_draw(void) | 151 game_draw(void) |
142 { | 152 { |
143 if (game.state && !(game.inhibit & INHIBIT_STATE_DRAW)) | 153 if (game.state && !(game.inhibit & INHIBIT_STATE_DRAW)) |
144 game.state->draw(); | 154 game.state->draw(); |
145 | 155 |
156 #if 0 | |
146 draw_actions(); | 157 draw_actions(); |
158 #endif | |
147 painter_present(); | 159 painter_present(); |
148 } | 160 } |
149 | 161 |
162 #if 0 | |
150 void | 163 void |
151 game_add_action(const struct action *action) | 164 game_add_action(const struct action *action) |
152 { | 165 { |
153 assert(action); | 166 assert(action); |
154 | 167 |
155 struct action *pos; | 168 struct action *pos; |
156 | 169 |
157 if ((pos = find_empty_action())) | 170 if ((pos = find_empty_action())) |
158 memcpy(pos, action, sizeof (struct action)); | 171 memcpy(pos, action, sizeof (struct action)); |
159 } | 172 } |
173 #endif | |
160 | 174 |
161 void | 175 void |
162 game_quit(void) | 176 game_quit(void) |
163 { | 177 { |
164 if (game.state && game.state->leave) | 178 if (game.state && game.state->leave) |