Mercurial > molko
comparison src/libmlk-rpg/rpg/battle-state-rendering.c @ 398:14ce7c4871e3
rpg: overhaul of battle bar
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 27 Feb 2022 10:08:51 +0100 |
parents | |
children | 8f59201dc76b |
comparison
equal
deleted
inserted
replaced
397:73eabfd50410 | 398:14ce7c4871e3 |
---|---|
1 /* | |
2 * battle-state-rendering.c -- battle state (rendering an action) | |
3 * | |
4 * Copyright (c) 2020-2022 David Demelier <markand@malikania.fr> | |
5 * | |
6 * Permission to use, copy, modify, and/or distribute this software for any | |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
9 * | |
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
17 */ | |
18 | |
19 #include <assert.h> | |
20 #include <stdlib.h> | |
21 | |
22 #include <core/alloc.h> | |
23 #include <core/drawable.h> | |
24 | |
25 #include "battle-state-rendering.h" | |
26 #include "battle.h" | |
27 | |
28 struct self { | |
29 struct battle_state_rendering data; | |
30 struct battle_state state; | |
31 }; | |
32 | |
33 static int | |
34 update(struct battle_state *st, struct battle *bt, unsigned int ticks) | |
35 { | |
36 battle_state_rendering_update(st->data, bt, ticks); | |
37 | |
38 return 0; | |
39 } | |
40 | |
41 static void | |
42 draw(const struct battle_state *st, const struct battle *bt) | |
43 { | |
44 battle_state_rendering_draw(st->data, bt); | |
45 } | |
46 | |
47 static void | |
48 finish(struct battle_state *st, struct battle *bt) | |
49 { | |
50 (void)bt; | |
51 | |
52 battle_state_rendering_finish(st->data); | |
53 free(st->data); | |
54 } | |
55 | |
56 void | |
57 battle_state_rendering_init(struct battle_state_rendering *rdr, struct drawable *dw) | |
58 { | |
59 assert(rdr); | |
60 assert(dw); | |
61 | |
62 rdr->drawable = dw; | |
63 } | |
64 | |
65 int | |
66 battle_state_rendering_update(struct battle_state_rendering *rdr, struct battle *bt, unsigned int ticks) | |
67 { | |
68 assert(rdr); | |
69 assert(battle_ok(bt)); | |
70 | |
71 battle_update_component(bt, BATTLE_COMPONENT_ALL, ticks); | |
72 | |
73 if (drawable_update(rdr->drawable, ticks)) { | |
74 drawable_end(rdr->drawable); | |
75 return 1; | |
76 } | |
77 | |
78 return 0; | |
79 } | |
80 | |
81 void | |
82 battle_state_rendering_draw(const struct battle_state_rendering *rdr, const struct battle *bt) | |
83 { | |
84 assert(rdr); | |
85 | |
86 battle_draw_component(bt, BATTLE_COMPONENT_ALL); | |
87 drawable_draw(rdr->drawable); | |
88 } | |
89 | |
90 void | |
91 battle_state_rendering_finish(struct battle_state_rendering *rdr) | |
92 { | |
93 assert(rdr); | |
94 | |
95 drawable_finish(rdr->drawable); | |
96 } | |
97 | |
98 void | |
99 battle_state_rendering(struct battle *bt, struct drawable *dw) | |
100 { | |
101 assert(bt); | |
102 assert(dw); | |
103 | |
104 struct self *self; | |
105 | |
106 self = alloc_new0(sizeof (*self)); | |
107 self->state.data = self; | |
108 self->state.update = update; | |
109 self->state.draw = draw; | |
110 self->state.finish = finish; | |
111 | |
112 battle_state_rendering_init(&self->data, dw); | |
113 battle_switch(bt, &self->state); | |
114 } |