comparison libmlk-rpg/rpg/battle-entity-state.h @ 243:71b3b7036de7

misc: lot of cleanups, - prefix libraries with libmlk, - move assets from source directories closes #2520, - prefix header guards closes #2519
author David Demelier <markand@malikania.fr>
date Sat, 28 Nov 2020 22:37:30 +0100
parents librpg/rpg/battle-entity-state.h@86b71e1f9dd5
children 6367b976112d
comparison
equal deleted inserted replaced
242:4c24604efcab 243:71b3b7036de7
1 /*
2 * battle-entity-state.h -- abstract battle entity state
3 *
4 * Copyright (c) 2020 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 #ifndef MOLKO_RPG_BATTLE_ENTITY_STATE_H
20 #define MOLKO_RPG_BATTLE_ENTITY_STATE_H
21
22 /**
23 * \file battle-entity-state.h
24 * \brief Abstract battle entity state.
25 *
26 * To animate and update battle entities this structure help splitting the logic
27 * into differents parts.
28 *
29 * In contrast to battle states, battle entity states should not switch
30 * themselves into an other one because battle states may need to wait until the
31 * entity state has finished to continue their own work.
32 *
33 * \note Do not call pointer functions directly but use the functions from this
34 * file since they may do additional work.
35 */
36
37 #include <stdbool.h>
38
39 struct battle_entity;
40
41 /**
42 * \brief Abstract battle entity state.
43 */
44 struct battle_entity_state {
45 /**
46 * (+&?) Optional state data.
47 */
48 void *data;
49
50 /**
51 * (+?) Update the entity.
52 *
53 * This function should understand a value of 0 as ticks to just request
54 * the state's status.
55 *
56 * \pre st != NULL
57 * \pre et != NULL
58 * \param st this state
59 * \param et the entity owner
60 * \param ticks elapsed milliseconds since last frame
61 * \return True if complete.
62 */
63 bool (*update)(struct battle_entity_state *st, struct battle_entity *et, unsigned int ticks);
64
65 /**
66 * (+?) Draw the entity.
67 *
68 * If this function is NULL, the default behavior is to draw the entity
69 * sprite at its current position.
70 *
71 * \pre st != NULL
72 * \pre et != NULL
73 * \param st this state
74 * \param et the entity owner
75 */
76 void (*draw)(const struct battle_entity_state *st, const struct battle_entity *et);
77
78 /**
79 * (+?) Clear resources.
80 *
81 * \pre st != NULL
82 * \pre et != NULL
83 * \param st this state
84 * \param et the entity owner
85 */
86 void (*finish)(struct battle_entity_state *st, struct battle_entity *et);
87 };
88
89 /**
90 * Shortcut for st->update (if not NULL).
91 *
92 * \pre st != NULL
93 * \pre et != NULL
94 * \param st this state
95 * \param et the entity owner
96 * \param ticks elapsed milliseconds since last frame
97 * \return True if complete.
98 */
99 bool
100 battle_entity_state_update(struct battle_entity_state *st, struct battle_entity *et, unsigned int ticks);
101
102 /**
103 * Call st->draw or default implementation if NULL.
104 *
105 * \pre st != NULL
106 * \pre et != NULL
107 * \param st this state
108 * \param et the entity owner
109 */
110 void
111 battle_entity_state_draw(const struct battle_entity_state *st, const struct battle_entity *et);
112
113 /**
114 * Shortcut for st->finish (if not NULL).
115 *
116 * \pre st != NULL
117 * \pre et != NULL
118 * \param st this state
119 * \param et the entity owner
120 */
121 void
122 battle_entity_state_finish(struct battle_entity_state *st, struct battle_entity *et);
123
124 #endif /* !MOLKO_RPG_BATTLE_ENTITY_STATE_H */