# HG changeset patch # User David Demelier # Date 1615398548 -3600 # Node ID 196264679079c45b808f49c3a996cf2ffa850997 # Parent 6151152d009c5c173c8d3f9d95e520ccf0df9971 misc: remove usage of bool diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/action.md --- a/doc/docs/dev/api/core/action.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/action.md Wed Mar 10 18:49:08 2021 +0100 @@ -41,7 +41,7 @@ |-------------------|--------|--------------------------------------------------| | [data](#data) | (+&?) | `void *` | | [handle](#handle) | (+?) | `void (*)(struct action *, const union event *)` | -| [update](#update) | (+?) | `bool (*)(struct action *, unsigned int)` | +| [update](#update) | (+?) | `int (*)(struct action *, unsigned int)` | | [draw](#draw) | (+?) | `void (*)(struct action *)` | | [end](#end) | (+?) | `void (*)(struct action *)` | | [finish](#finish) | (+?) | `void (*)(struct action *)` | @@ -65,10 +65,10 @@ #### update Update the action `self` with the `ticks` since last frame. The callback should -return true if it is considered complete. +return non-zero if it is considered complete. ```c -bool (*update)(struct action *self, unsigned int ticks) +int (*update)(struct action *self, unsigned int ticks) ``` #### draw @@ -140,7 +140,7 @@ frame if it is not NULL. ```c -bool +int action_update(struct action *act, unsigned int ticks) ``` @@ -185,11 +185,11 @@ ### action\_stack\_add -Add the action `act` to the stack pointed by `st`. Returns true if there was +Add the action `act` to the stack pointed by `st`. Returns -1 if there wasn't enough room to insert. ```c -bool +int action_stack_add(struct action_stack *st, struct action *act) ``` @@ -207,7 +207,7 @@ Update all actions with `ticks` since last frame in the stack `st`. ```c -bool +int action_stack_update(struct action_stack *st, unsigned int ticks) ``` @@ -222,11 +222,11 @@ ### action\_stack\_completed -Tells if there is any pending action in the stack `st`. Returns true if there -are no actions or if they have all completed. +Tells if there is any pending action in the stack `st`. Returns non-zero if +there are no actions or if they have all completed. ```c -bool +int action_stack_completed(const struct action_stack *st) ``` diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/alloc.md --- a/doc/docs/dev/api/core/alloc.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/alloc.md Wed Mar 10 18:49:08 2021 +0100 @@ -35,9 +35,9 @@ | Field | Access | Type | |---------------------|--------|---------------------------------------------| -| [alloc](#alloc) | (+?) | `void *(*)(size_t)` | -| [realloc](#realloc) | (+?) | `void *(*)(void *, size_t)` | -| [free](#free) | (+?) | `void (*)(void *)` | +| [alloc](#alloc) | (+?) | `void *(*)(size_t)` | +| [realloc](#realloc) | (+?) | `void *(*)(void *, size_t)` | +| [free](#free) | (+?) | `void (*)(void *)` | #### alloc @@ -263,8 +263,8 @@ This will effectively create a initial storage according to [ALLOC_POOL_INIT_DEFAULT](#alloc_pool_init_default). -Returns false on errors depending on the result of the of the current -[alloc](#alloc) function set. +Returns -1 on error depending on the result of the of the current +[alloc](#alloc) function set or 0 otherwise. ```c bool diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/animation.md --- a/doc/docs/dev/api/core/animation.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/animation.md Wed Mar 10 18:49:08 2021 +0100 @@ -70,20 +70,20 @@ ### animation\_completed -Returns true if the animation `an` was completely shown. +Returns non-zero if the animation `an` was completely shown. ```c -bool +int animation_completed(const struct animation *an) ``` ### animation\_update -Update the animation `an` with `ticks` since last frame. Returns true if it has -completed. +Update the animation `an` with `ticks` since last frame. Returns non-zero if it +has completed. ```c -bool +int animation_update(struct animation *an, unsigned int ticks) ``` @@ -91,11 +91,13 @@ Draw the animation `an` to the given `x`, `y` coordinates. +Returns -1 in case of errors and 0 otherwise. + !!! warning You must not call this function is the animation is complete. ```c -bool +int animation_draw(const struct animation *an, int x, int y) ``` diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/core.md --- a/doc/docs/dev/api/core/core.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/core.md Wed Mar 10 18:49:08 2021 +0100 @@ -23,10 +23,10 @@ platforms so make sure to not use characters that may be illegal on some filesystems. -Returns false in case of errors. +Returns -1 in case of errors and 0 otherwise. ```c -bool +int core_init(const char *organization, const char *name) ``` diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/drawable.md --- a/doc/docs/dev/api/core/drawable.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/drawable.md Wed Mar 10 18:49:08 2021 +0100 @@ -34,7 +34,7 @@ | [data](#data) | (+&?) | `void *` | | [x](#x) | (+) | `int` | | [y](#y) | (+) | `int` | -| [update](#update) | (+?) | `bool (*)(struct drawable *, unsigned int)` | +| [update](#update) | (+?) | `int (*)(struct drawable *, unsigned int)` | | [draw](#draw) | (+?) | `void (*)(struct drawable *)` | | [end](#end) | (+?) | `void (*)(struct drawable *)` | | [finish](#finish) | (+?) | `void (*)(struct drawable *)` | @@ -50,10 +50,10 @@ #### update Update the drawable `self` with the `ticks` since last frame. The callback -should return true if it is considered complete. +should return non-zero if it is considered complete. ```c -bool (*update)(struct drawable *self, unsigned int ticks) +int (*update)(struct drawable *self, unsigned int ticks) ``` #### draw @@ -109,7 +109,7 @@ and `ticks` since last frame if it is not NULL. ```c -bool +int drawable_update(struct drawable *dw, unsigned int ticks) ``` @@ -154,11 +154,11 @@ ### drawable\_stack\_add -Add the drawable `dw` to the stack pointed by `st`. Returns true if there was +Add the drawable `dw` to the stack pointed by `st`. Returns -1 if there wasn't enough room to insert. ```c -bool +int drawable_stack_add(struct drawable_stack *st, struct drawable *dw) ``` @@ -167,7 +167,7 @@ Update all drawables with `ticks` since last frame in the stack `st`. ```c -bool +int drawable_stack_update(struct drawable_stack *st, unsigned int ticks) ``` @@ -182,11 +182,11 @@ ### drawable\_stack\_completed -Tells if there is any pending drawable in the stack `st`. Returns true if there -are no drawables or if they have all completed. +Tells if there is any pending drawable in the stack `st`. Returns non-zero if +there are no drawables or if they have all completed. ```c -bool +int drawable_stack_completed(const struct drawable_stack *st) ``` diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/error.md --- a/doc/docs/dev/api/core/error.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/error.md Wed Mar 10 18:49:08 2021 +0100 @@ -24,11 +24,11 @@ ### errorf -Set the global error using [printf][] format string. Also return false for +Set the global error using [printf][] format string. Also return -1 for convenience. ```c -bool +int errorf(const char *fmt, ...) ``` @@ -37,7 +37,7 @@ Similar to [errorf](#errorf) but using a `va_list` argument instead. ```c -bool +int errorva(const char *fmt, va_list ap) ``` diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/event.md --- a/doc/docs/dev/api/core/event.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/event.md Wed Mar 10 18:49:08 2021 +0100 @@ -121,9 +121,9 @@ ### event\_poll -Fetch the next event into `ev` or return false if there are not. +Fetch the next event into `ev` or returns 0 if there are none. ```c -bool +int event_poll(union event *ev) ``` diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/font.md --- a/doc/docs/dev/api/core/font.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/font.md Wed Mar 10 18:49:08 2021 +0100 @@ -37,33 +37,36 @@ ### font\_open -Open and load `font` of the given pixel `size` from file `path`. Returns false -on errors. +Open and load `font` of the given pixel `size` from file `path`. + +Returns -1 in case of errors and 0 otherwise. ```c -bool +int font_open(struct font *font, const char *path, unsigned int size) ``` ### font\_openmem Open font and load `font` from the const memory buffer pointed by `buffer` and -of size `buflen` using a pixel size of `size`. Returns false on errors. +of size `buflen` using a pixel size of `size`. + +Returns -1 in case of errors and 0 otherwise. !!! note The argument `buffer` must stay valid until the font is no longer used. ```c -bool +int font_openmem(struct font *font, const void *buffer, size_t buflen, unsigned int size) ``` ### font\_ok -Returns true if the `font` is properly loaded. +Returns non-zero if the `font` is properly loaded. ```c -bool +int font_ok(const struct font *font) ``` @@ -72,11 +75,11 @@ Render the UTF-8 `text` into the texture `tex` using the font pointed by `font`. The foreground `color` will be used to draw the text. -Returns false in case of rendering error, in this case `tex` remains +Returns -1 in case of rendering error, in this case `tex` remains uninitialized and must not be used. ```c -bool +int font_render(struct font *font, struct texture *tex, const char *text, unsigned int color) ``` @@ -94,11 +97,11 @@ Query the dimensions that the UTF-8 `text` would require with this `font`. Store the dimensions into the `w`, `h` pointers which can be both NULL. -Return false in case of error, in this case both `w` and `h` remain -uninitialized and must not be used. +Returns -1 in case of errors, in this case `w` and `h` are set to 0 if they are +not null. ```c -bool +int font_query(const struct font *font, const char *text, unsigned int *w, unsigned int *h) ``` diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/game.md --- a/doc/docs/dev/api/core/game.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/game.md Wed Mar 10 18:49:08 2021 +0100 @@ -64,12 +64,12 @@ The state will only be effective after the next call to [game_update](#game_update). -If argument `quick` is set to true, the state is changed immediately and the +If argument `quick` is non-zero, the state is changed immediately and the current state code should immediately return. ```c void -game_switch(struct state *state, bool quick) +game_switch(struct state *state, int quick) ``` #### game\_handle diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/image.md --- a/doc/docs/dev/api/core/image.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/image.md Wed Mar 10 18:49:08 2021 +0100 @@ -13,24 +13,23 @@ ### image\_open Load the image from `path` on disk and convert it as a texture into `tex`. -Returns false on errors, in this case `tex` remains uninitialized and must not -be used. + +Returns -1 in case of errors and 0 otherwise. ```c -bool +int image_open(struct texture *tex, const char *path) ``` ### image\_openmem Load the image from memory pointed by `buffer` of size `size` and convert it as -a texture into `tex`. Returns false on errors, in this case `tex` remains -uninitialized and must not be used. +a texture into `tex`. !!! note The argument `buffer` must stay valid until the font is no longer used. ```c -bool +int image_openmem(struct texture *tex, const void *buffer, size_t size) ``` diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/music.md --- a/doc/docs/dev/api/core/music.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/music.md Wed Mar 10 18:49:08 2021 +0100 @@ -31,34 +31,36 @@ ### music\_open -Open a music file from `path` and store the result into `mus`. Returns false on -errors, in this case `mus` remains uninitialized and must not be used. +Open a music file from `path` and store the result into `mus`. + +Returns -1 in case of errors and 0 otherwise. ```c -bool +int music_open(struct music *mus, const char *path) ``` ### music\_openmem Open a music from the memory `buffer` of size `buffersz` and store the result -into `mus`. Returns false on errors, in this case `mus` remains uninitialized -and must not be used. +into `mus`. + +Returns -1 in case of errors and 0 otherwise. !!! note The argument `buffer` must stay valid until the music is no longer used. ```c -bool +int music_openmem(struct music *mus, const void *buffer, size_t buffersz) ``` ### music\_ok -Returns true if the music `mus` is properly initialized. +Returns non-zero if the music `mus` is properly initialized. ```c -bool +int music_ok(const struct music *mus) ``` @@ -73,17 +75,19 @@ current music. If the music playing is currently fading out the playback will not start until it has finished. +Returns -1 in case of errors and 0 otherwise. + ``` -bool +int music_play(struct music *mus, enum music_flags flags, unsigned int fadein) ``` ### music\_playing -Returns true if a music is playing. +Returns non-zero if a music is playing. ```c -bool +int music_playing(void) ``` diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/script.md --- a/doc/docs/dev/api/core/script.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/script.md Wed Mar 10 18:49:08 2021 +0100 @@ -68,14 +68,14 @@ ### script\_append -Add the action `a` into the script `s`. Returns true if there was enough room +Add the action `a` into the script `s`. Returns -1 if there wasn't enough room to insert. !!! note The argument `a` must stay valid until the script is no longer used. ```c -bool +int script_append(struct script *s, struct action *a) ``` @@ -91,10 +91,11 @@ ### script\_update Update the current action in the script `s` with `ticks` since last frame. -Returns true if the script completed. + +Returns non-zero if the script completed. ```c -bool +int script_update(struct script *s, unsigned int ticks) ``` @@ -109,10 +110,10 @@ ### script\_completed -Returns true if the script `s` is complete. +Returns non-zero if the script `s` is complete. ```c -bool +int script_completed(const struct script *s) ``` diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/sprite.md --- a/doc/docs/dev/api/core/sprite.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/sprite.md Wed Mar 10 18:49:08 2021 +0100 @@ -64,10 +64,10 @@ ### sprite\_ok -Returns true if the `sprite` is properly initialized. +Returns non-zero if the `sprite` is properly initialized. ```c -bool +int sprite_ok(const struct sprite *sprite) ``` @@ -76,8 +76,10 @@ Similar to [sprite_scale](#sprite_scale) but use sprite cell dimensions for scaling. +Returns -1 in case of errors and 0 otherwise. + ```c -bool +int sprite_draw(const struct sprite *sprite, unsigned int r, unsigned int c, int x, int y) ``` @@ -86,10 +88,12 @@ Draw an individual cell from row `r` and column `c` at the coordinates `x`, `y` from the sprite `sprite` and scale the image to dimensions `w`, `h`. +Returns -1 in case of errors and 0 otherwise. + !!! caution Argument `r` and `c` must be out of bounds. ```c -bool +int sprite_scale(const struct sprite *sprite, unsigned int r, unsigned int c, int x, int y, unsigned int w, unsigned int h) ``` diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/sys.md --- a/doc/docs/dev/api/core/sys.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/sys.md Wed Mar 10 18:49:08 2021 +0100 @@ -33,8 +33,10 @@ This function is automatically called from [core_init](core.md#core_init) with the same arguments and not necessary from the user. +Returns -1 in case of errors and 0 otherwise. + ```c -bool +int sys_init(const char *organization, const char *name) ``` @@ -53,11 +55,11 @@ ### sys\_mkdir -Create the directory `path` recursively. Returns false on errors other than -already existing. +Create the directory `path` recursively. Returns -1 on errors other than +already existing or 0 otherwise. ```c -bool +int sys_mkdir(const char *path) ``` diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/texture.md --- a/doc/docs/dev/api/core/texture.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/texture.md Wed Mar 10 18:49:08 2021 +0100 @@ -41,20 +41,21 @@ ### texture\_new -Create a new texture in `tex` with `w` and `h` as dimensions. Returns false on -errors, in this case `tex` remains uninitialized and must not be used. +Create a new texture in `tex` with `w` and `h` as dimensions. + +Returns -1 in case of errors and 0 otherwise. ```c -bool +int texture_new(struct texture *tex, unsigned int w, unsigned int h) ``` ### texture\_ok -Returns true if the texture `tex` is properly initialized. +Returns non-zero if the texture `tex` is properly initialized. ```c -bool +int texture_ok(const struct texture *tex) ``` @@ -62,32 +63,36 @@ Set the blend mode to `blend` for future blend operations for the texture `tex`. +Returns -1 in case of errors and 0 otherwise. + ```c -bool +int texture_set_blend_mode(struct texture *tex, enum texture_blend blend) ``` ### texture\_set\_alpha\_mod -Apply the transparency `alpha` modulation to the texture `tex`. Returns false on -errors. +Apply the transparency `alpha` modulation to the texture `tex`. + +Returns -1 in case of errors and 0 otherwise. !!! note You may need to use [texture_set_blend_mode](#texture_set_blend_mode) before this function to work. ```c -bool +int texture_set_alpha_mod(struct texture *tex, unsigned int alpha) ``` ### texture\_set\_color\_mod -Apply the color `color` modulation to the texture `tex`. Returns false on -errors. +Apply the color `color` modulation to the texture `tex`. + +Returns -1 in case of errors and 0 otherwise. ```c -bool +int texture_set_color_mod(struct texture *tex, unsigned long color) ``` @@ -95,8 +100,10 @@ Draw whole texture `tex` at the position `x`, `y`. +Returns -1 in case of errors and 0 otherwise. + ```c -bool +int texture_draw(const struct texture *tex, int x, int y) ``` @@ -108,10 +115,10 @@ `src_h` at the region `dst_x`, `dst_y`, `dst_w`, `dst_h` with an optional `angle`. -Returns false on rendering error. +Returns -1 in case of errors and 0 otherwise. ```c -bool +int texture_scale(const struct texture *tex, int src_x, int src_y, diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/translate.md --- a/doc/docs/dev/api/core/translate.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/translate.md Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,10 @@ Initialize native language support for the given domain `name`. Returns false on errors. +Returns -1 in case of errors and 0 otherwise. + ```c -bool +int translate_init(const char *name) ``` diff -r 6151152d009c -r 196264679079 doc/docs/dev/api/core/window.md --- a/doc/docs/dev/api/core/window.md Wed Mar 10 18:49:00 2021 +0100 +++ b/doc/docs/dev/api/core/window.md Wed Mar 10 18:49:08 2021 +0100 @@ -57,10 +57,10 @@ Open a window with dimensions `width`, `height`. The argument `title` will set the window title if the platform supports it. -Returns false on errors, otherwise the global `window` object will be set. +Returns -1 in case of errors and 0 otherwise. ```c -bool +int window_open(const char *title, unsigned int width, unsigned int height) ``` diff -r 6151152d009c -r 196264679079 examples/example-action/main.c --- a/examples/example-action/main.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-action/main.c Wed Mar 10 18:49:08 2021 +0100 @@ -62,7 +62,7 @@ struct action msg_act; int x; int y; - bool opened; + int opened; struct texture image; struct sprite sprite; struct action event; @@ -176,14 +176,14 @@ } }; -static bool +static int guide_response_update(struct action *act, unsigned int ticks) { /* Immediately return to get access to end. */ (void)act; (void)ticks; - return true; + return 1; } static void @@ -252,7 +252,7 @@ static void guide_init(void) { - if (!image_open(&guide.image, PATH("sprites/people.png"))) + if (image_open(&guide.image, PATH("sprites/people.png")) < 0) panic(); sprite_init(&guide.sprite, &guide.image, 48, 48); @@ -276,7 +276,7 @@ case EVENT_CLICKDOWN: if (maths_is_boxed(chest.x, chest.y, chest.sprite.cellw, chest.sprite.cellh, ev->click.x, ev->click.y)) { - chest.opened = true; + chest.opened = 1; message_action(&chest.msg, &chest.msg_act); message_query(&chest.msg, NULL, &chest.msg.h); action_stack_add(&modal, &chest.msg_act); @@ -300,7 +300,7 @@ static void chest_init(void) { - if (!image_open(&chest.image, PATH("sprites/chest.png"))) + if (image_open(&chest.image, PATH("sprites/chest.png")) < 0) panic(); sprite_init(&chest.sprite, &chest.image, 32, 32); @@ -314,9 +314,9 @@ static void init(void) { - if (!core_init("fr.malikania", "actions") || !ui_init() || !rpg_init()) + if (core_init("fr.malikania", "actions") < 0 || ui_init() < 0 || rpg_init() < 0) panic(); - if (!window_open("Example - Action", W, H)) + if (window_open("Example - Action", W, H) < 0) panic(); guide_init(); @@ -372,7 +372,7 @@ action_stack_add(&events, &chest.event); action_stack_add(&events, &guide.event); - game_switch(&state, true); + game_switch(&state, 1); game_loop(); } diff -r 6151152d009c -r 196264679079 examples/example-animation/main.c --- a/examples/example-animation/main.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-animation/main.c Wed Mar 10 18:49:08 2021 +0100 @@ -47,16 +47,16 @@ static struct texture numbers; static struct animation animation; static struct sprite sprite; -static bool completed = true; +static int completed = 1; static void init(void) { - if (!core_init("fr.malikania", "animation") || !ui_init()) + if (core_init("fr.malikania", "animation") < 0 || ui_init() < 0) panic(); - if (!window_open("Example - Animation", W, H)) + if (window_open("Example - Animation", W, H) < 0) panic(); - if (!image_open(&numbers, PATH("sprites/numbers.png"))) + if (image_open(&numbers, PATH("sprites/numbers.png")) < 0) panic(); } @@ -120,7 +120,7 @@ sprite_init(&sprite, &numbers, 48, 48); animation_init(&animation, &sprite, 1000); - game_switch(&state, true); + game_switch(&state, 1); game_loop(); } diff -r 6151152d009c -r 196264679079 examples/example-audio/main.c --- a/examples/example-audio/main.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-audio/main.c Wed Mar 10 18:49:08 2021 +0100 @@ -56,12 +56,12 @@ static void init(void) { - if (!core_init("fr.malikania", "audio") || !ui_init()) + if (core_init("fr.malikania", "audio") < 0 || ui_init() < 0) panic(); - if (!window_open("Example - Audio", W, H)) + if (window_open("Example - Audio", W, H) < 0) panic(); - if (!music_open(&music, PATH("music/vabsounds-romance.ogg")) || - !sound_open(&sound, PATH("sounds/fire.wav"))) + if (music_open(&music, PATH("music/vabsounds-romance.ogg")) < 0 || + sound_open(&sound, PATH("sounds/fire.wav")) < 0) panic(); } @@ -80,7 +80,7 @@ switch (ev->type) { case EVENT_CLICKDOWN: - if (!sound_play(&sound, -1, 0)) + if (sound_play(&sound, -1, 0) < 0) panic(); break; case EVENT_KEYDOWN: @@ -138,7 +138,7 @@ .draw = draw }; - game_switch(&state, true); + game_switch(&state, 1); game_loop(); music_finish(&music); diff -r 6151152d009c -r 196264679079 examples/example-battle/main.c --- a/examples/example-battle/main.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-battle/main.c Wed Mar 10 18:49:08 2021 +0100 @@ -143,9 +143,9 @@ static void init(void) { - if (!core_init("fr.malikania", "battle") || !ui_init() || !rpg_init()) + if (core_init("fr.malikania", "battle") < 0 || ui_init() < 0 || rpg_init() < 0) panic(); - if (!window_open("Example - Battle", W, H)) + if (window_open("Example - Battle", W, H) < 0) panic(); registry_init(); @@ -182,7 +182,7 @@ battle_start(bt); fight_state.data = bt; - game_switch(&fight_state, false); + game_switch(&fight_state, 0); } @@ -239,7 +239,7 @@ struct battle *bt = st->data; if (battle_update(bt, ticks)) - game_switch(&empty_state, false); + game_switch(&empty_state, 0); } static void @@ -268,7 +268,7 @@ static void run(void) { - game_switch(&empty_state, true); + game_switch(&empty_state, 1); game_loop(); } diff -r 6151152d009c -r 196264679079 examples/example-battle/registry.c --- a/examples/example-battle/registry.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-battle/registry.c Wed Mar 10 18:49:08 2021 +0100 @@ -75,7 +75,7 @@ for (size_t i = 0; i < UTIL_SIZE(images); ++i) { struct texture *texture = ®istry_images[images[i].index]; - if (!image_open(texture, PATH(images[i].path))) + if (image_open(texture, PATH(images[i].path)) < 0) panic(); } } @@ -87,7 +87,7 @@ struct texture *texture = ®istry_textures[textures[i].index]; struct sprite *sprite = ®istry_sprites[textures[i].index]; - if (!image_open(texture, PATH(textures[i].path))) + if (image_open(texture, PATH(textures[i].path)) < 0) panic(); if (textures[i].cellw == 0 || textures[i].cellh == 0) @@ -103,7 +103,7 @@ for (size_t i = 0; i < UTIL_SIZE(sounds); ++i) { struct sound *sound = ®istry_sounds[sounds[i].index]; - if (!sound_open(sound, PATH(sounds[i].path))) + if (sound_open(sound, PATH(sounds[i].path)) < 0) panic(); } } diff -r 6151152d009c -r 196264679079 examples/example-battle/spell-fire.c --- a/examples/example-battle/spell-fire.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-battle/spell-fire.c Wed Mar 10 18:49:08 2021 +0100 @@ -39,7 +39,7 @@ unsigned int selection; }; -static bool +static int update(struct action *act, unsigned int ticks) { struct data *data = act->data; diff -r 6151152d009c -r 196264679079 examples/example-cursor/main.c --- a/examples/example-cursor/main.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-cursor/main.c Wed Mar 10 18:49:08 2021 +0100 @@ -48,9 +48,9 @@ static void init(void) { - if (!core_init("fr.malikania", "cursor") || !ui_init()) + if (core_init("fr.malikania", "cursor") < 0 || ui_init() < 0) panic(); - if (!window_open("Example - Cursor", W, H)) + if (window_open("Example - Cursor", W, H) < 0) panic(); } @@ -122,7 +122,7 @@ change(cursor); - game_switch(&state, true); + game_switch(&state, 1); game_loop(); } diff -r 6151152d009c -r 196264679079 examples/example-debug/main.c --- a/examples/example-debug/main.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-debug/main.c Wed Mar 10 18:49:08 2021 +0100 @@ -38,12 +38,12 @@ static void init(void) { - if (!core_init("fr.malikania", "debug") || !ui_init()) + if (core_init("fr.malikania", "debug") < 0 || ui_init() < 0) panic(); - if (!window_open("Example - Debug", W, H)) + if (window_open("Example - Debug", W, H) < 0) panic(); - debug_options.enable = true; + debug_options.enable = 1; } static void @@ -86,7 +86,7 @@ .draw = draw }; - game_switch(&state, true); + game_switch(&state, 1); game_loop(); } diff -r 6151152d009c -r 196264679079 examples/example-drawable/main.c --- a/examples/example-drawable/main.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-drawable/main.c Wed Mar 10 18:49:08 2021 +0100 @@ -70,19 +70,19 @@ static void init(void) { - if (!core_init("fr.malikania", "drawable") || !ui_init()) + if (core_init("fr.malikania", "drawable") < 0 || ui_init() < 0) panic(); - if (!window_open("Example - Drawable", W, H)) + if (window_open("Example - Drawable", W, H) < 0) panic(); /* 0: Explosion animation. */ - if (!image_open(&explosion_tex, PATH("sprites/explosion.png"))) + if (image_open(&explosion_tex, PATH("sprites/explosion.png")) < 0) panic(); sprite_init(&explosion_sprite, &explosion_tex, 256, 256); } -static bool +static int explosion_update(struct drawable *dw, unsigned int ticks) { struct explosion *ex = dw->data; @@ -177,7 +177,7 @@ .draw = draw }; - game_switch(&state, true); + game_switch(&state, 1); game_loop(); } diff -r 6151152d009c -r 196264679079 examples/example-font/main.c --- a/examples/example-font/main.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-font/main.c Wed Mar 10 18:49:08 2021 +0100 @@ -52,9 +52,9 @@ static void init(void) { - if (!core_init("fr.malikania", "font") || !ui_init()) + if (core_init("fr.malikania", "font") < 0 || ui_init() < 0) panic(); - if (!window_open("Example - Font", W, H)) + if (window_open("Example - Font", W, H) < 0) panic(); } @@ -104,7 +104,7 @@ painter_set_color(0xffffffff); painter_clear(); - if (!font_render(font, &tex, "Example of text. Use / to change color and to toggle antialiasing.", colors[ci])) + if (font_render(font, &tex, "Example of text. Use / to change color and to toggle antialiasing.", colors[ci]) < 0) panic(); texture_draw(&tex, 10, 10); @@ -120,7 +120,7 @@ .draw = draw }; - game_switch(&state, true); + game_switch(&state, 1); game_loop(); } diff -r 6151152d009c -r 196264679079 examples/example-gridmenu/main.c --- a/examples/example-gridmenu/main.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-gridmenu/main.c Wed Mar 10 18:49:08 2021 +0100 @@ -39,9 +39,9 @@ static void init(void) { - if (!core_init("fr.malikania", "grid-menu") || !ui_init()) + if (core_init("fr.malikania", "grid-menu") < 0 || ui_init() < 0) panic(); - if (!window_open("Example - Grid menu", W, H)) + if (window_open("Example - Grid menu", W, H) < 0) panic(); } @@ -123,7 +123,7 @@ /* Need to repaint at least once. */ gridmenu_repaint(&menu); - game_switch(&state, true); + game_switch(&state, 1); game_loop(); } diff -r 6151152d009c -r 196264679079 examples/example-label/main.c --- a/examples/example-label/main.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-label/main.c Wed Mar 10 18:49:08 2021 +0100 @@ -104,9 +104,9 @@ static void init(void) { - if (!core_init("fr.malikania", "label") || !ui_init()) + if (core_init("fr.malikania", "label") < 0 || ui_init() < 0) panic(); - if (!window_open("Example - Label", W, H)) + if (window_open("Example - Label", W, H) < 0) panic(); for (size_t i = 0; i < UTIL_SIZE(table); ++i) { @@ -167,7 +167,7 @@ .draw = draw }; - game_switch(&state, true); + game_switch(&state, 1); game_loop(); } diff -r 6151152d009c -r 196264679079 examples/example-message/main.c --- a/examples/example-message/main.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-message/main.c Wed Mar 10 18:49:08 2021 +0100 @@ -46,9 +46,9 @@ static void init(void) { - if (!core_init("fr.malikania", "message") || !ui_init() || !rpg_init()) + if (core_init("fr.malikania", "message") < 0 || ui_init() < 0 || rpg_init() < 0) panic(); - if (!window_open("Example - Message", W, H)) + if (window_open("Example - Message", W, H) < 0) panic(); } @@ -102,7 +102,7 @@ message_start(msg); - game_switch(&state, true); + game_switch(&state, 1); game_loop(); } diff -r 6151152d009c -r 196264679079 examples/example-sprite/main.c --- a/examples/example-sprite/main.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-sprite/main.c Wed Mar 10 18:49:08 2021 +0100 @@ -63,11 +63,11 @@ static void init(void) { - if (!core_init("fr.malikania", "sprite") || !ui_init()) + if (core_init("fr.malikania", "sprite") < 0 || ui_init() < 0) panic(); - if (!window_open("Example - Sprite", W, H)) + if (window_open("Example - Sprite", W, H) < 0) panic(); - if (!image_open(&texture, PATH("sprites/people.png"))) + if (image_open(&texture, PATH("sprites/people.png")) < 0) panic(); sprite_init(&sprite, &texture, 48, 48); @@ -136,7 +136,7 @@ changed(); - game_switch(&state, true); + game_switch(&state, 1); game_loop(); } diff -r 6151152d009c -r 196264679079 examples/example-trace/main.c --- a/examples/example-trace/main.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-trace/main.c Wed Mar 10 18:49:08 2021 +0100 @@ -38,9 +38,9 @@ static void init(void) { - if (!core_init("fr.malikania", "trace") || !ui_init()) + if (core_init("fr.malikania", "trace") < 0 || ui_init() < 0) panic(); - if (!window_open("Example - Trace", W, H)) + if (window_open("Example - Trace", W, H) < 0) panic(); trace_handler = trace_hud_handler; @@ -101,7 +101,7 @@ .draw = draw }; - game_switch(&state, true); + game_switch(&state, 1); game_loop(); } diff -r 6151152d009c -r 196264679079 examples/example-ui/main.c --- a/examples/example-ui/main.c Wed Mar 10 18:49:00 2021 +0100 +++ b/examples/example-ui/main.c Wed Mar 10 18:49:08 2021 +0100 @@ -65,7 +65,7 @@ struct action_stack st; struct { - bool active; + int active; int x; int y; } motion; @@ -129,9 +129,9 @@ static void init(void) { - if (!core_init("fr.malikania", "ui") || !ui_init()) + if (core_init("fr.malikania", "ui") < 0 || ui_init() < 0) panic(); - if (!window_open("Example - UI", W, H)) + if (window_open("Example - UI", W, H) < 0) panic(); } @@ -213,7 +213,7 @@ action_stack_add(&ui.st, &ui.quit.act); } -static bool +static int headerclick(int x, int y) { return maths_is_boxed( @@ -246,7 +246,7 @@ break; case EVENT_CLICKDOWN: if (headerclick(ev->click.x, ev->click.y)) { - ui.motion.active = true; + ui.motion.active = 1; ui.motion.x = ev->click.x; ui.motion.y = ev->click.y; window_set_cursor(WINDOW_CURSOR_SIZE); @@ -255,7 +255,7 @@ action_stack_handle(&ui.st, ev); break; case EVENT_CLICKUP: - ui.motion.active = false; + ui.motion.active = 0; window_set_cursor(WINDOW_CURSOR_ARROW); /* Fallthrough. */ default: @@ -298,7 +298,7 @@ prepare(); resize(); - game_switch(&state, true); + game_switch(&state, 1); game_loop(); } diff -r 6151152d009c -r 196264679079 libmlk-adventure/adventure/action/chest.c --- a/libmlk-adventure/adventure/action/chest.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-adventure/adventure/action/chest.c Wed Mar 10 18:49:08 2021 +0100 @@ -38,7 +38,7 @@ #define H(c) ((c)->animation.sprite->cellh) #define TOLERANCE (10) -static bool +static int is_near(const struct chest *c) { const int x = c->x - c->map->player_sprite->cellw - TOLERANCE; @@ -82,13 +82,13 @@ } } -static bool +static int update(struct action *act, unsigned int ticks) { struct chest *c = act->data; if (c->state != CHEST_STATE_ANIMATE) - return false; + return 0; if (animation_update(&c->animation, ticks)) { c->state = CHEST_STATE_OPEN; @@ -97,7 +97,7 @@ c->exec(c); } - return false; + return 0; } static void @@ -130,7 +130,7 @@ assert(c); if (c->save && c->property) { - if (!save_get_property(c->save, c->property)) + if (save_get_property(c->save, c->property) < 0) panic(); /* TODO: add an utility. */ diff -r 6151152d009c -r 196264679079 libmlk-adventure/adventure/action/spawner.c --- a/libmlk-adventure/adventure/action/spawner.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-adventure/adventure/action/spawner.c Wed Mar 10 18:49:08 2021 +0100 @@ -74,7 +74,7 @@ molko_fight(bt); } -static bool +static int update(struct action *act, unsigned int ticks) { (void)ticks; @@ -92,7 +92,7 @@ } } - return false; + return 0; } void diff -r 6151152d009c -r 196264679079 libmlk-adventure/adventure/action/teleport.c --- a/libmlk-adventure/adventure/action/teleport.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-adventure/adventure/action/teleport.c Wed Mar 10 18:49:08 2021 +0100 @@ -53,7 +53,7 @@ texture_draw(&tp->overlay, 0, 0); } -static bool +static int update_fadeout(struct action *act, unsigned int ticks) { struct teleport *tp = act->data; @@ -63,17 +63,17 @@ if (tp->elapsed >= 10) { if (tp->alpha >= 255) { molko_teleport(tp->destination, tp->origin_x, tp->origin_y); - return true; + return 1; } tp->elapsed = 0; tp->alpha += 5; } - return false; + return 0; } -static bool +static int update_touch(struct action *act, unsigned int ticks) { (void)ticks; @@ -93,14 +93,14 @@ * We change our update function and add a draw function that * fade the screen out. */ - if (!texture_new(&tp->overlay, window.w, window.h)) + if (texture_new(&tp->overlay, window.w, window.h) < 0) panic(); act->update = update_fadeout; act->draw = draw; } - return false; + return 0; } static void diff -r 6151152d009c -r 196264679079 libmlk-adventure/adventure/assets.c --- a/libmlk-adventure/adventure/assets.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-adventure/adventure/assets.c Wed Mar 10 18:49:08 2021 +0100 @@ -62,7 +62,7 @@ init_sprites(void) { for (size_t i = 0; i < UTIL_SIZE(table_sprites); ++i) { - if (!image_open(&table_sprites[i].texture, molko_path(table_sprites[i].path))) + if (image_open(&table_sprites[i].texture, molko_path(table_sprites[i].path)) < 0) panic(); sprite_init(&assets_sprites[table_sprites[i].index], @@ -75,7 +75,7 @@ init_sounds(void) { for (size_t i = 0; i < UTIL_SIZE(assets_sounds); ++i) { - if (!sound_open(&assets_sounds[table_sounds[i].index], molko_path(table_sounds[i].path))) + if (sound_open(&assets_sounds[table_sounds[i].index], molko_path(table_sounds[i].path)) < 0) panic(); } } diff -r 6151152d009c -r 196264679079 libmlk-adventure/adventure/dialog/save.c --- a/libmlk-adventure/adventure/dialog/save.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-adventure/adventure/dialog/save.c Wed Mar 10 18:49:08 2021 +0100 @@ -201,7 +201,7 @@ sprite_draw(sprite, 1, 2, x, y + (geo->saves[dlg->selected].h / 2) - (sprite->cellh / 2)); } -static bool +static int handle_keydown(struct dialog_save *s, const struct event_key *key) { assert(key->type == EVENT_KEYDOWN); @@ -225,10 +225,10 @@ break; } - return false; + return 0; } -static bool +static int handle_clickdown(struct dialog_save *s, const struct geo *geo, const struct event_click *clk) { assert(clk->type == EVENT_CLICKDOWN); @@ -254,7 +254,7 @@ save_open(&s->saves[i], i, SAVE_MODE_READ); } -bool +int dialog_save_handle(struct dialog_save *dlg, const union event *ev) { assert(dlg); @@ -271,7 +271,7 @@ break; } - return false; + return 0; } void diff -r 6151152d009c -r 196264679079 libmlk-adventure/adventure/dialog/save.h --- a/libmlk-adventure/adventure/dialog/save.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-adventure/adventure/dialog/save.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_ADVENTURE_SAVE_H #define MOLKO_ADVENTURE_SAVE_H -#include - #include #include @@ -42,7 +40,7 @@ void dialog_save_init(struct dialog_save *); -bool +int dialog_save_handle(struct dialog_save *, const union event *); void diff -r 6151152d009c -r 196264679079 libmlk-adventure/adventure/molko.c --- a/libmlk-adventure/adventure/molko.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-adventure/adventure/molko.c Wed Mar 10 18:49:08 2021 +0100 @@ -69,12 +69,11 @@ { setlocale(LC_ALL, ""); - if (!core_init("fr.malikania", "molko") || !ui_init() || !rpg_init()) + if (core_init("fr.malikania", "molko") < 0 || ui_init() < 0|| rpg_init() < 0) panic(); - - translate_init("libmlk-adventure"); - - if (!window_open("Molko's Adventure", WINDOW_WIDTH, WINDOW_HEIGHT)) + if (translate_init("libmlk-adventure") < 0) + panic(); + if (window_open("Molko's Adventure", WINDOW_WIDTH, WINDOW_HEIGHT) < 0) panic(); /* @@ -82,25 +81,20 @@ * to be running. */ - /* Init unrecoverable panic state. */ - molko.panic = state_panic_new(); - panic_handler = crash; - trace_handler = trace_hud_handler; - /* Init other stuff. */ assets_init(); /* Start to splash. */ -#if 0 - // TODO: put back this. - game_switch(state_splashscreen_ne(), true); -#else - game_switch(state_mainmenu_new(), true); + game_switch(state_mainmenu_new(), 1); molko.team.members[0] = &character_neth; molko.team.members[1] = &character_neth; inventory_add(&molko.inventory, &item_potion, 100); - molko_teleport("maps/map-world.map.zst", -1, -1); -#endif + molko_teleport("maps/map-world.map", -1, -1); + + /* Init unrecoverable panic state. */ + molko.panic = state_panic_new(); + panic_handler = crash; + trace_handler = trace_hud_handler; } void @@ -114,7 +108,7 @@ for (union event ev; event_poll(&ev); ) continue; - game_switch(molko.panic, true); + game_switch(molko.panic, 1); game_loop(); } } @@ -124,7 +118,7 @@ { molko.state = MOLKO_STATE_MAP; - game_switch(state_map_new(map, origin_x, origin_y), false); + game_switch(state_map_new(map, origin_x, origin_y), 0); game.inhibit = INHIBIT_NONE; } @@ -133,7 +127,7 @@ { molko.state = MOLKO_STATE_BATTLE; - game_switch(state_battle_new(bt), false); + game_switch(state_battle_new(bt), 0); } const char * diff -r 6151152d009c -r 196264679079 libmlk-adventure/adventure/spell/fire-minor.c --- a/libmlk-adventure/adventure/spell/fire-minor.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-adventure/adventure/spell/fire-minor.c Wed Mar 10 18:49:08 2021 +0100 @@ -41,7 +41,7 @@ struct animation animation; }; -static bool +static int update(struct action *act, unsigned int ticks) { struct rendering *rdr = act->data; diff -r 6151152d009c -r 196264679079 libmlk-adventure/adventure/state/continue.c --- a/libmlk-adventure/adventure/state/continue.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-adventure/adventure/state/continue.c Wed Mar 10 18:49:08 2021 +0100 @@ -44,7 +44,7 @@ handle(struct state *state, const union event *ev) { struct self *self = state->data; - bool selected = false; + int selected = 0; switch (ev->type) { case EVENT_QUIT: @@ -52,7 +52,7 @@ break; case EVENT_KEYDOWN: if (ev->key.key == KEY_ESCAPE) - game_switch(state_mainmenu_new(), false); + game_switch(state_mainmenu_new(), 0); else selected = dialog_save_handle(&self->dialog, ev); break; diff -r 6151152d009c -r 196264679079 libmlk-adventure/adventure/state/mainmenu.c --- a/libmlk-adventure/adventure/state/mainmenu.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-adventure/adventure/state/mainmenu.c Wed Mar 10 18:49:08 2021 +0100 @@ -76,7 +76,7 @@ static void resume(void) { - game_switch(state_continue_new(), false); + game_switch(state_continue_new(), 0); } static void @@ -102,7 +102,7 @@ static void init_title(struct self *self, struct font *font) { - if (!font_render(font, &self->texts[3].tex, "Molko's Adventure", 0x000000ff)) + if (font_render(font, &self->texts[3].tex, "Molko's Adventure", 0x000000ff) < 0) panic(); /* Align header. */ @@ -115,9 +115,9 @@ static void init_items(struct self *self, struct font *font) { - if (!font_render(font, &self->texts[0].tex, _("New"), 0x000000ff) || - !font_render(font, &self->texts[1].tex, _("Continue"), 0x000000ff) || - !font_render(font, &self->texts[2].tex, _("Quit"), 0x000000ff)) + if (font_render(font, &self->texts[0].tex, _("New"), 0x000000ff) < 0 || + font_render(font, &self->texts[1].tex, _("Continue"), 0x000000ff) < 0 || + font_render(font, &self->texts[2].tex, _("Quit"), 0x000000ff) < 0) panic(); self->texts[0].x = (window.w / 2) - (self->texts[0].tex.w / 2); @@ -136,8 +136,8 @@ struct self *self = state->data; struct font fonts[2]; - if (!font_open(&fonts[0], molko_path("fonts/teutonic.ttf"), 130) || - !font_open(&fonts[1], molko_path("fonts/pirata-one.ttf"), 30)) + if (font_open(&fonts[0], molko_path("fonts/teutonic.ttf"), 130) < 0|| + font_open(&fonts[1], molko_path("fonts/pirata-one.ttf"), 30) < 0) panic(); fonts[0].style = fonts[1].style = FONT_STYLE_ANTIALIASED; diff -r 6151152d009c -r 196264679079 libmlk-adventure/adventure/state/map.c --- a/libmlk-adventure/adventure/state/map.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-adventure/adventure/state/map.c Wed Mar 10 18:49:08 2021 +0100 @@ -54,11 +54,11 @@ self->map_file.load_action = mapscene_load_action; - if (!map_file_open(&self->map_file, &self->map, molko_path(self->name))) + if (map_file_open(&self->map_file, &self->map, molko_path(self->name)) < 0) panic(); /* TODO: find this from team maybe. */ - if (!image_open(&molko.map_player_texture, molko_path("sprites/john.png"))) + if (image_open(&molko.map_player_texture, molko_path("sprites/john.png")) < 0) panic(); sprite_init(&molko.map_player_sprite, &molko.map_player_texture, 48, 48); @@ -72,7 +72,7 @@ mapscene_load(&self->map); - if (!map_init(&self->map)) + if (map_init(&self->map) < 0) panic(); } diff -r 6151152d009c -r 196264679079 libmlk-adventure/adventure/state/panic.c --- a/libmlk-adventure/adventure/state/panic.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-adventure/adventure/state/panic.c Wed Mar 10 18:49:08 2021 +0100 @@ -118,10 +118,10 @@ theme = theme_default(); font = theme->fonts[THEME_FONT_INTERFACE]; - if (!font_render(font, &self->texts[0].tex, "An unrecoverable error occured and the game cannot continue.", FOREGROUND) || - !font_render(font, &self->texts[1].tex, "Please report the detailed error as provided below.", FOREGROUND) || - !font_render(font, &self->texts[2].tex, "Press to save information and generate a core dump.", FOREGROUND) || - !font_render(font, &self->texts[3].tex, "Press to quit without saving information.", FOREGROUND)) + if (font_render(font, &self->texts[0].tex, "An unrecoverable error occured and the game cannot continue.", FOREGROUND) < 0|| + font_render(font, &self->texts[1].tex, "Please report the detailed error as provided below.", FOREGROUND) < 0|| + font_render(font, &self->texts[2].tex, "Press to save information and generate a core dump.", FOREGROUND) < 0|| + font_render(font, &self->texts[3].tex, "Press to quit without saving information.", FOREGROUND) < 0) die("%s", error()); /* All align x the same. */ @@ -171,7 +171,7 @@ /* The error is only available here. */ font = theme->fonts[THEME_FONT_INTERFACE]; - if (!font_render(font, &tex, error(), FOREGROUND)) + if (font_render(font, &tex, error(), FOREGROUND) < 0) die("%s\n", error()); align(ALIGN_LEFT, &x, &y, tex.w, tex.h, 0, 0, window.w, window.h); diff -r 6151152d009c -r 196264679079 libmlk-adventure/adventure/state/splashscreen.c --- a/libmlk-adventure/adventure/state/splashscreen.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-adventure/adventure/state/splashscreen.c Wed Mar 10 18:49:08 2021 +0100 @@ -54,7 +54,7 @@ struct self *self = state->data; struct font font; - if (!font_open(&font, molko_path("fonts/cubic.ttf"), 80)) + if (font_open(&font, molko_path("fonts/cubic.ttf"), 80) < 0) panic(); font.style = FONT_STYLE_ANTIALIASED; @@ -75,7 +75,7 @@ self->elapsed += ticks; if (self->elapsed >= DELAY) - game_switch(state_mainmenu_new(), false); + game_switch(state_mainmenu_new(), 0); } static void diff -r 6151152d009c -r 196264679079 libmlk-adventure/adventure/trace_hud.c --- a/libmlk-adventure/adventure/trace_hud.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-adventure/adventure/trace_hud.c Wed Mar 10 18:49:08 2021 +0100 @@ -115,14 +115,14 @@ memset(&data, 0, sizeof (data)); } -static bool +static int update(struct action *a, unsigned int ticks) { (void)a; trace_hud_update(ticks); - return false; + return 0; } static void diff -r 6151152d009c -r 196264679079 libmlk-core/core/action.c --- a/libmlk-core/core/action.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/action.c Wed Mar 10 18:49:08 2021 +0100 @@ -35,7 +35,7 @@ act->handle(act, ev); } -bool +int action_update(struct action *act, unsigned int ticks) { assert(act); @@ -43,7 +43,8 @@ if (act->update) return act->update(act, ticks); - return false; + /* No function means immortal action. */ + return 0; } void @@ -81,7 +82,7 @@ memset(st, 0, sizeof (*st)); } -bool +int action_stack_add(struct action_stack *st, struct action *act) { assert(st); @@ -90,11 +91,11 @@ for (size_t i = 0; i < ACTION_STACK_MAX; ++i) { if (!st->actions[i]) { st->actions[i] = act; - return true; + return 0; } } - return false; + return -1; } void @@ -110,7 +111,7 @@ action_handle(act, ev); } -bool +int action_stack_update(struct action_stack *st, unsigned int ticks) { assert(st); @@ -146,7 +147,7 @@ action_draw(act); } -bool +int action_stack_completed(const struct action_stack *st) { assert(st); @@ -155,9 +156,9 @@ ACTION_FOREACH(st, act) if (act) - return false; + return 0; - return true; + return 1; } void diff -r 6151152d009c -r 196264679079 libmlk-core/core/action.h --- a/libmlk-core/core/action.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/action.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_CORE_ACTION_H #define MOLKO_CORE_ACTION_H -#include - #include "core.h" #define ACTION_STACK_MAX (128) @@ -29,11 +27,11 @@ struct action { void *data; - void (*handle)(struct action *act, const union event *ev); - bool (*update)(struct action *act, unsigned int ticks); - void (*draw)(struct action *act); - void (*end)(struct action *act); - void (*finish)(struct action *act); + void (*handle)(struct action *, const union event *); + int (*update)(struct action *, unsigned int); + void (*draw)(struct action *); + void (*end)(struct action *); + void (*finish)(struct action *); }; struct action_stack { @@ -43,40 +41,40 @@ CORE_BEGIN_DECLS void -action_handle(struct action *act, const union event *ev); +action_handle(struct action *, const union event *); -bool -action_update(struct action *act, unsigned int ticks); +int +action_update(struct action *, unsigned int); void -action_draw(struct action *act); +action_draw(struct action *); void -action_end(struct action *act); +action_end(struct action *); void -action_finish(struct action *act); +action_finish(struct action *); void -action_stack_init(struct action_stack *st); +action_stack_init(struct action_stack *); -bool -action_stack_add(struct action_stack *st, struct action *act); +int +action_stack_add(struct action_stack *, struct action *); void -action_stack_handle(struct action_stack *st, const union event *ev); +action_stack_handle(struct action_stack *, const union event *); -bool -action_stack_update(struct action_stack *st, unsigned int ticks); +int +action_stack_update(struct action_stack *, unsigned int); void -action_stack_draw(const struct action_stack *st); +action_stack_draw(const struct action_stack *); -bool -action_stack_completed(const struct action_stack *st); +int +action_stack_completed(const struct action_stack *); void -action_stack_finish(struct action_stack *st); +action_stack_finish(struct action_stack *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/alloc.c --- a/libmlk-core/core/alloc.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/alloc.c Wed Mar 10 18:49:08 2021 +0100 @@ -149,7 +149,7 @@ if (size / newlen != elemsize) return errorf("%s", strerror(ENOMEM)), NULL; if (!(ptr = funcs->realloc(ptr, size))) - return false; + return NULL; if (newlen > oldlen) memset((unsigned char *)ptr + (oldlen * elemsize), 0, (newlen - oldlen) * elemsize); @@ -185,21 +185,21 @@ return ret; } -bool +int alloc_pool_init(struct alloc_pool *pool, size_t elemsize, void (*finalizer)(void *)) { assert(pool); assert(elemsize != 0); if (!(pool->data = alloc_array(ALLOC_POOL_INIT_DEFAULT, elemsize))) - return false; + return -1; pool->elemsize = elemsize; pool->size = 0; pool->capacity = ALLOC_POOL_INIT_DEFAULT; pool->finalizer = finalizer; - return true; + return 0; } void * diff -r 6151152d009c -r 196264679079 libmlk-core/core/alloc.h --- a/libmlk-core/core/alloc.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/alloc.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,7 +19,6 @@ #ifndef MOLKO_CORE_ALLOC_H #define MOLKO_CORE_ALLOC_H -#include #include #include "core.h" @@ -30,9 +29,9 @@ /* Custom allocator. */ struct alloc_funcs { - void *(*alloc)(size_t size); - void *(*realloc)(void *ptr, size_t size); - void (*free)(void *ptr); + void *(*alloc)(size_t); + void *(*realloc)(void *, size_t); + void (*free)(void *); }; /* Minimalist growable array for loading data. */ @@ -41,54 +40,54 @@ size_t elemsize; size_t size; size_t capacity; - void (*finalizer)(void *data); + void (*finalizer)(void *); }; CORE_BEGIN_DECLS /* allocator functions. */ void -alloc_set(const struct alloc_funcs *funcs); +alloc_set(const struct alloc_funcs *); void * -alloc_new(size_t size); +alloc_new(size_t); void * -alloc_new0(size_t size); +alloc_new0(size_t); void * -alloc_array(size_t len, size_t elemsize); +alloc_array(size_t, size_t); void * -alloc_array0(size_t len, size_t elemsize); +alloc_array0(size_t, size_t); void * -alloc_renew(void *ptr, size_t size); +alloc_renew(void *, size_t); void * -alloc_rearray(void *ptr, size_t newlen, size_t elemsize); +alloc_rearray(void *, size_t, size_t); void * -alloc_rearray0(void *ptr, size_t oldlen, size_t newlen, size_t elemsize); +alloc_rearray0(void *, size_t, size_t, size_t); void * -alloc_dup(const void *ptr, size_t size); +alloc_dup(const void *, size_t); char * -alloc_sdup(const char *src); +alloc_sdup(const char *); /* alloc_pool functions. */ -bool -alloc_pool_init(struct alloc_pool *pool, size_t elemsize, void (*finalizer)(void *)); +int +alloc_pool_init(struct alloc_pool *, size_t , void (*)(void *)); void * -alloc_pool_new(struct alloc_pool *pool); +alloc_pool_new(struct alloc_pool *); void * -alloc_pool_get(const struct alloc_pool *pool, size_t index); +alloc_pool_get(const struct alloc_pool *, size_t); void -alloc_pool_finish(struct alloc_pool *pool); +alloc_pool_finish(struct alloc_pool *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/animation.c --- a/libmlk-core/core/animation.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/animation.c Wed Mar 10 18:49:08 2021 +0100 @@ -23,7 +23,7 @@ #include "animation.h" #include "sprite.h" -static bool +static int update(struct drawable *dw, unsigned int ticks) { return animation_update(dw->data, ticks); @@ -58,7 +58,7 @@ an->elapsed = 0; } -bool +int animation_completed(const struct animation *an) { assert(an); @@ -68,7 +68,7 @@ an->column >= an->sprite->ncols; } -bool +int animation_update(struct animation *an, unsigned int ticks) { assert(an); @@ -76,7 +76,7 @@ an->elapsed += ticks; if (an->elapsed < an->delay) - return false; + return 0; /* Increment column first */ if (++an->column >= an->sprite->ncols) { @@ -94,7 +94,7 @@ return animation_completed(an); } -bool +int animation_draw(const struct animation *an, int x, int y) { assert(an); diff -r 6151152d009c -r 196264679079 libmlk-core/core/animation.h --- a/libmlk-core/core/animation.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/animation.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_CORE_ANIMATION_H #define MOLKO_CORE_ANIMATION_H -#include - #include "core.h" struct drawable; @@ -37,22 +35,22 @@ CORE_BEGIN_DECLS void -animation_init(struct animation *an, const struct sprite *sprite, unsigned int delay); +animation_init(struct animation *, const struct sprite *, unsigned int); void -animation_start(struct animation *an); +animation_start(struct animation *); -bool -animation_completed(const struct animation *an); +int +animation_completed(const struct animation *); -bool -animation_update(struct animation *an, unsigned int ticks); +int +animation_update(struct animation *, unsigned int); -bool -animation_draw(const struct animation *an, int x, int y); +int +animation_draw(const struct animation *, int, int); void -animation_drawable(struct animation *an, struct drawable *dw, int x, int y); +animation_drawable(struct animation *, struct drawable *, int, int); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/clock.h --- a/libmlk-core/core/clock.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/clock.h Wed Mar 10 18:49:08 2021 +0100 @@ -28,10 +28,10 @@ CORE_BEGIN_DECLS void -clock_start(struct clock *clock); +clock_start(struct clock *); unsigned int -clock_elapsed(const struct clock *clock); +clock_elapsed(const struct clock *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/core.c --- a/libmlk-core/core/core.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/core.c Wed Mar 10 18:49:08 2021 +0100 @@ -25,7 +25,7 @@ #include "sys.h" #include "translate.h" -bool +int core_init(const char *organization, const char *name) { assert(organization); @@ -33,12 +33,12 @@ srand(time(NULL)); - if (!sys_init(organization, name)) - return false; + if (sys_init(organization, name) < 0) + return -1; translate_init("libmlk-core"); - return true; + return 0; } void diff -r 6151152d009c -r 196264679079 libmlk-core/core/core.h --- a/libmlk-core/core/core.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/core.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_CORE_CORE_H #define MOLKO_CORE_CORE_H -#include - #if defined(__cplusplus) # define CORE_BEGIN_DECLS extern "C" { # define CORE_END_DECLS } @@ -31,8 +29,8 @@ CORE_BEGIN_DECLS -bool -core_init(const char *organization, const char *name); +int +core_init(const char *, const char *); void core_finish(void); diff -r 6151152d009c -r 196264679079 libmlk-core/core/drawable.c --- a/libmlk-core/core/drawable.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/drawable.c Wed Mar 10 18:49:08 2021 +0100 @@ -29,7 +29,7 @@ #define DRAWABLE_FOREACH(st, iter) \ for (size_t i = 0; i < DRAWABLE_STACK_MAX && ((iter) = (st)->objects[i], 1); ++i) -bool +int drawable_update(struct drawable *dw, unsigned int ticks) { assert(dw); @@ -71,7 +71,7 @@ memset(st, 0, sizeof (*st)); } -bool +int drawable_stack_add(struct drawable_stack *st, struct drawable *dw) { assert(st); @@ -80,14 +80,14 @@ for (size_t i = 0; i < DRAWABLE_STACK_MAX; ++i) { if (!st->objects[i]) { st->objects[i] = dw; - return true; + return 0; } } - return false; + return -1; } -bool +int drawable_stack_update(struct drawable_stack *st, unsigned int ticks) { assert(st); @@ -121,7 +121,7 @@ drawable_draw(dw); } -bool +int drawable_stack_completed(const struct drawable_stack *st) { assert(st); @@ -130,9 +130,9 @@ DRAWABLE_FOREACH(st, dw) if (dw) - return false; + return 0; - return true; + return 1; } void diff -r 6151152d009c -r 196264679079 libmlk-core/core/drawable.h --- a/libmlk-core/core/drawable.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/drawable.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_CORE_DRAWABLE_H #define MOLKO_CORE_DRAWABLE_H -#include - #include "core.h" #define DRAWABLE_STACK_MAX (128) @@ -29,10 +27,10 @@ void *data; int x; int y; - bool (*update)(struct drawable *dw, unsigned int ticks); - void (*draw)(struct drawable *dw); - void (*end)(struct drawable *act); - void (*finish)(struct drawable *dw); + int (*update)(struct drawable *, unsigned int); + void (*draw)(struct drawable *); + void (*end)(struct drawable *); + void (*finish)(struct drawable *); }; struct drawable_stack { @@ -41,35 +39,35 @@ CORE_BEGIN_DECLS -bool -drawable_update(struct drawable *dw, unsigned int ticks); +int +drawable_update(struct drawable *, unsigned int); void -drawable_draw(struct drawable *dw); +drawable_draw(struct drawable *); void -drawable_end(struct drawable *dw); +drawable_end(struct drawable *); void -drawable_finish(struct drawable *dw); +drawable_finish(struct drawable *); void -drawable_stack_init(struct drawable_stack *st); +drawable_stack_init(struct drawable_stack *); -bool -drawable_stack_add(struct drawable_stack *st, struct drawable *dw); +int +drawable_stack_add(struct drawable_stack *, struct drawable *); -bool -drawable_stack_update(struct drawable_stack *st, unsigned int ticks); +int +drawable_stack_update(struct drawable_stack *, unsigned int); void -drawable_stack_draw(struct drawable_stack *st); +drawable_stack_draw(struct drawable_stack *); -bool -drawable_stack_completed(const struct drawable_stack *st); +int +drawable_stack_completed(const struct drawable_stack *); void -drawable_stack_finish(struct drawable_stack *st); +drawable_stack_finish(struct drawable_stack *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/error.c --- a/libmlk-core/core/error.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/error.c Wed Mar 10 18:49:08 2021 +0100 @@ -31,7 +31,7 @@ return buffer; } -bool +int errorf(const char *fmt, ...) { assert(fmt); @@ -42,15 +42,15 @@ errorva(fmt, ap); va_end(ap); - return false; + return -1; } -bool +int errorva(const char *fmt, va_list ap) { assert(fmt); vsnprintf(buffer, sizeof (buffer), fmt, ap); - return false; + return -1; } diff -r 6151152d009c -r 196264679079 libmlk-core/core/error.h --- a/libmlk-core/core/error.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/error.h Wed Mar 10 18:49:08 2021 +0100 @@ -20,7 +20,6 @@ #define MOLKO_CORE_ERROR_H #include -#include #include "core.h" @@ -29,11 +28,11 @@ const char * error(void); -bool -errorf(const char *fmt, ...); +int +errorf(const char *, ...); -bool -errorva(const char *fmt, va_list ap); +int +errorva(const char *, va_list); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/event.c --- a/libmlk-core/core/event.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/event.c Wed Mar 10 18:49:08 2021 +0100 @@ -222,7 +222,7 @@ } } -bool +int event_poll(union event *ev) { SDL_Event event; @@ -235,22 +235,22 @@ switch (event.type) { case SDL_QUIT: ev->type = EVENT_QUIT; - return true; + return 1; case SDL_KEYDOWN: case SDL_KEYUP: convert_key(&event, ev); - return true; + return 1; case SDL_MOUSEMOTION: convert_mouse(&event, ev); - return true; + return 1; case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: convert_click(&event, ev); - return true; + return 1; default: continue; } } - return false; + return 0; } diff -r 6151152d009c -r 196264679079 libmlk-core/core/event.h --- a/libmlk-core/core/event.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/event.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_CORE_EVENT_H #define MOLKO_CORE_EVENT_H -#include - #include "core.h" #include "key.h" #include "mouse.h" @@ -63,8 +61,8 @@ CORE_BEGIN_DECLS -bool -event_poll(union event *ev); +int +event_poll(union event *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/font.c --- a/libmlk-core/core/font.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/font.c Wed Mar 10 18:49:08 2021 +0100 @@ -27,7 +27,7 @@ #include "texture_p.h" #include "util.h" -bool +int font_open(struct font *font, const char *path, unsigned int size) { assert(font); @@ -36,10 +36,10 @@ if (!(font->handle = TTF_OpenFont(path, size))) return errorf("%s", SDL_GetError()); - return true; + return 0; } -bool +int font_openmem(struct font *font, const void *buffer, size_t buflen, unsigned int size) { assert(font); @@ -48,28 +48,19 @@ SDL_RWops *ops; if (!(ops = SDL_RWFromConstMem(buffer, buflen)) || - (!(font->handle = TTF_OpenFontRW(ops, true, size)))) + (!(font->handle = TTF_OpenFontRW(ops, 1, size)))) return errorf("%s", SDL_GetError()); - return true; + return 0; } -void -font_shallow(struct font *dst, const struct font *src) -{ - assert(dst); - assert(src); - - memcpy(dst, src, sizeof (*src)); -} - -bool +int font_ok(const struct font *font) { return font && font->handle; } -bool +int font_render(struct font *font, struct texture *tex, const char *text, unsigned int color) { assert(font_ok(font)); @@ -107,16 +98,21 @@ return TTF_FontHeight(font->handle); } -bool +int font_query(const struct font *font, const char *text, unsigned int *w, unsigned int *h) { assert(font_ok(font)); assert(text); + if (w) + *w = 0; + if (h) + *h = 0; + if (TTF_SizeUTF8(font->handle, text, (int *)w, (int *)h) != 0) return errorf("%s", SDL_GetError()); - return true; + return 0; } void diff -r 6151152d009c -r 196264679079 libmlk-core/core/font.h --- a/libmlk-core/core/font.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/font.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,7 +19,6 @@ #ifndef MOLKO_CORE_FONT_H #define MOLKO_CORE_FONT_H -#include #include #include "core.h" @@ -38,26 +37,26 @@ CORE_BEGIN_DECLS -bool -font_open(struct font *font, const char *path, unsigned int size); +int +font_open(struct font *, const char *, unsigned int); -bool -font_openmem(struct font *font, const void *buffer, size_t buflen, unsigned int size); +int +font_openmem(struct font *, const void *, size_t, unsigned int); -bool -font_ok(const struct font *font); +int +font_ok(const struct font *); -bool -font_render(struct font *font, struct texture *tex, const char *text, unsigned int color); +int +font_render(struct font *, struct texture *, const char *, unsigned int); unsigned int -font_height(const struct font *font); +font_height(const struct font *); -bool -font_query(const struct font *font, const char *text, unsigned int *w, unsigned int *h); +int +font_query(const struct font *, const char *, unsigned int *, unsigned int *); void -font_finish(struct font *font); +font_finish(struct font *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/game.c --- a/libmlk-core/core/game.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/game.c Wed Mar 10 18:49:08 2021 +0100 @@ -31,7 +31,7 @@ struct game game; void -game_switch(struct state *state, bool quick) +game_switch(struct state *state, int quick) { assert(state); diff -r 6151152d009c -r 196264679079 libmlk-core/core/game.h --- a/libmlk-core/core/game.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/game.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_CORE_GAME_H #define MOLKO_CORE_GAME_H -#include - #include "core.h" #include "inhibit.h" @@ -42,16 +40,16 @@ CORE_BEGIN_DECLS void -game_switch(struct state *state, bool quick); +game_switch(struct state *, int); struct state * -game_replace(struct state *state); +game_replace(struct state *); void -game_handle(const union event *event); +game_handle(const union event *); void -game_update(unsigned int ticks); +game_update(unsigned int); void game_draw(void); diff -r 6151152d009c -r 196264679079 libmlk-core/core/image.c --- a/libmlk-core/core/image.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/image.c Wed Mar 10 18:49:08 2021 +0100 @@ -17,7 +17,6 @@ */ #include -#include #include @@ -39,7 +38,7 @@ } } -bool +int image_open(struct texture *tex, const char *path) { assert(tex); @@ -50,20 +49,20 @@ dimensions(tex); - return true; + return 0; } -bool +int image_openmem(struct texture *tex, const void *buffer, size_t size) { assert(buffer); SDL_RWops *ops = SDL_RWFromConstMem(buffer, size); - if (!ops || !(tex->handle = IMG_LoadTexture_RW(RENDERER(), ops, true))) + if (!ops || !(tex->handle = IMG_LoadTexture_RW(RENDERER(), ops, 1))) return errorf("%s", SDL_GetError()); dimensions(tex); - return true; + return 0; } diff -r 6151152d009c -r 196264679079 libmlk-core/core/image.h --- a/libmlk-core/core/image.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/image.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,7 +19,6 @@ #ifndef MOLKO_CORE_IMAGE_H #define MOLKO_CORE_IMAGE_H -#include #include #include "core.h" @@ -28,11 +27,11 @@ CORE_BEGIN_DECLS -bool -image_open(struct texture *tex, const char *path); +int +image_open(struct texture *, const char *); -bool -image_openmem(struct texture *tex, const void *buffer, size_t size); +int +image_openmem(struct texture *, const void *, size_t); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/maths.c --- a/libmlk-core/core/maths.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/maths.c Wed Mar 10 18:49:08 2021 +0100 @@ -18,7 +18,7 @@ #include "maths.h" -bool +int maths_is_boxed(int x, int y, unsigned int w, unsigned int h, int px, int py) { return px > x && diff -r 6151152d009c -r 196264679079 libmlk-core/core/maths.h --- a/libmlk-core/core/maths.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/maths.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,17 +19,15 @@ #ifndef MOLKO_CORE_MATHS_H #define MOLKO_CORE_MATHS_H -#include - #include "core.h" CORE_BEGIN_DECLS -bool -maths_is_boxed(int x, int y, unsigned int w, unsigned int h, int px, int py); +int +maths_is_boxed(int, int, unsigned int, unsigned int, int, int); float -maths_scale(float v, float omin, float omax, float nmin, float nmax); +maths_scale(float, float, float, float, float); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/music.c --- a/libmlk-core/core/music.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/music.c Wed Mar 10 18:49:08 2021 +0100 @@ -24,7 +24,7 @@ #include "error.h" #include "music.h" -bool +int music_open(struct music *mus, const char *path) { assert(mus); @@ -33,10 +33,10 @@ if (!(mus->handle = Mix_LoadMUS(path))) return errorf("%s", SDL_GetError()); - return true; + return 0; } -bool +int music_openmem(struct music *mus, const void *buffer, size_t buffersz) { assert(mus); @@ -45,19 +45,19 @@ SDL_RWops *ops; if (!(ops = SDL_RWFromConstMem(buffer, buffersz)) || - !(mus->handle = Mix_LoadMUS_RW(ops, true))) + !(mus->handle = Mix_LoadMUS_RW(ops, 1))) return errorf("%s", SDL_GetError()); - return true; + return 0; } -bool +int music_ok(const struct music *mus) { return mus && mus->handle; } -bool +int music_play(struct music *mus, enum music_flags flags, unsigned int fadein) { assert(mus); @@ -73,10 +73,10 @@ if (ret < 0) return errorf("%s", SDL_GetError()); - return true; + return 0; } -bool +int music_playing(void) { return Mix_PlayingMusic(); diff -r 6151152d009c -r 196264679079 libmlk-core/core/music.h --- a/libmlk-core/core/music.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/music.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,7 +19,6 @@ #ifndef MOLKO_CORE_MUSIC_H #define MOLKO_CORE_MUSIC_H -#include #include #include "core.h" @@ -35,19 +34,19 @@ CORE_BEGIN_DECLS -bool -music_open(struct music *mus, const char *path); +int +music_open(struct music *, const char *); -bool -music_openmem(struct music *mus, const void *buffer, size_t buffersz); +int +music_openmem(struct music *, const void *, size_t); -bool -music_ok(const struct music *mus); +int +music_ok(const struct music *); -bool -music_play(struct music *mus, enum music_flags flags, unsigned int fadein); +int +music_play(struct music *, enum music_flags, unsigned int); -bool +int music_playing(void); void @@ -57,10 +56,10 @@ music_resume(void); void -music_stop(unsigned int fadeout); +music_stop(unsigned int); void -music_finish(struct music *mus); +music_finish(struct music *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/painter.h --- a/libmlk-core/core/painter.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/painter.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_CORE_PAINTER_H #define MOLKO_CORE_PAINTER_H -#include - #include "core.h" struct texture; @@ -31,25 +29,25 @@ painter_get_target(void); void -painter_set_target(struct texture *tex); +painter_set_target(struct texture *); unsigned long painter_get_color(void); void -painter_set_color(unsigned long color); +painter_set_color(unsigned long); void -painter_draw_line(int x1, int y1, int x2, int y2); +painter_draw_line(int, int, int, int); void -painter_draw_point(int x, int y); +painter_draw_point(int, int); void -painter_draw_rectangle(int x, int y, unsigned int w, unsigned int h); +painter_draw_rectangle(int, int, unsigned int, unsigned int); void -painter_draw_circle(int x, int y, int radius); +painter_draw_circle(int, int, int); void painter_clear(void); diff -r 6151152d009c -r 196264679079 libmlk-core/core/panic.h --- a/libmlk-core/core/panic.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/panic.h Wed Mar 10 18:49:08 2021 +0100 @@ -29,10 +29,10 @@ CORE_BEGIN_DECLS noreturn void -panicf(const char *fmt, ...); +panicf(const char *, ...); noreturn void -panicva(const char *fmt, va_list ap); +panicva(const char *, va_list); noreturn void panic(void); diff -r 6151152d009c -r 196264679079 libmlk-core/core/script.c --- a/libmlk-core/core/script.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/script.c Wed Mar 10 18:49:08 2021 +0100 @@ -39,7 +39,7 @@ script_handle(a->data, ev); } -static bool +static int update(struct action *a, unsigned int ticks) { return script_update(a->data, ticks); @@ -65,7 +65,7 @@ memset(s, 0, sizeof (*s)); } -bool +int script_append(struct script *s, struct action *a) { assert(s); @@ -76,7 +76,7 @@ s->actions[s->actionsz++] = a; - return true; + return 0; } void @@ -91,7 +91,7 @@ action_handle(a, ev); } -bool +int script_update(struct script *s, unsigned int ticks) { assert(s); @@ -99,7 +99,7 @@ struct action *a = current(s); if (!a) - return true; + return 1; if (action_update(a, ticks)) { action_end(a); @@ -120,7 +120,7 @@ action_draw(a); } -bool +int script_completed(const struct script *s) { assert(s); diff -r 6151152d009c -r 196264679079 libmlk-core/core/script.h --- a/libmlk-core/core/script.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/script.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,7 +19,6 @@ #ifndef MOLKO_CORE_SCRIPT_H #define MOLKO_CORE_SCRIPT_H -#include #include #include "core.h" @@ -39,28 +38,28 @@ CORE_BEGIN_DECLS void -script_init(struct script *s); +script_init(struct script *); -bool -script_append(struct script *s, struct action *a); +int +script_append(struct script *, struct action *); void -script_handle(struct script *s, const union event *ev); +script_handle(struct script *, const union event *); -bool -script_update(struct script *s, unsigned int ticks); +int +script_update(struct script *, unsigned int); void -script_draw(struct script *s); +script_draw(struct script *); -bool -script_completed(const struct script *s); +int +script_completed(const struct script *); void -script_finish(struct script *s); +script_finish(struct script *); void -script_action(struct script *s, struct action *dst); +script_action(struct script*s, struct action *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/sound.c --- a/libmlk-core/core/sound.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/sound.c Wed Mar 10 18:49:08 2021 +0100 @@ -24,7 +24,7 @@ #include "error.h" #include "sound.h" -bool +int sound_open(struct sound *snd, const char *path) { assert(snd); @@ -33,10 +33,10 @@ if (!(snd->handle = Mix_LoadWAV(path))) return errorf("%s", SDL_GetError()); - return true; + return 0; } -bool +int sound_openmem(struct sound *snd, const void *buffer, size_t buffersz) { assert(snd); @@ -45,19 +45,19 @@ SDL_RWops *ops; if (!(ops = SDL_RWFromConstMem(buffer, buffersz)) || - !(snd->handle = Mix_LoadWAV_RW(ops, true))) + !(snd->handle = Mix_LoadWAV_RW(ops, 1))) return errorf("%s", SDL_GetError()); - return true; + return 0; } -bool +int sound_ok(const struct sound *snd) { return snd && snd->handle; } -bool +int sound_play(struct sound *snd, int channel, unsigned int fadein) { assert(sound_ok(snd)); @@ -74,7 +74,7 @@ snd->channel = channel; - return true; + return 0; } void diff -r 6151152d009c -r 196264679079 libmlk-core/core/sound.h --- a/libmlk-core/core/sound.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/sound.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,7 +19,6 @@ #ifndef MOLKO_CORE_SOUND_H #define MOLKO_CORE_SOUND_H -#include #include #include "core.h" @@ -33,29 +32,29 @@ CORE_BEGIN_DECLS -bool -sound_open(struct sound *snd, const char *path); +int +sound_open(struct sound *, const char *); -bool -sound_openmem(struct sound *snd, const void *buffer, size_t buffersz); +int +sound_openmem(struct sound *, const void *, size_t); -bool -sound_ok(const struct sound *snd); +int +sound_ok(const struct sound *); -bool -sound_play(struct sound *snd, int channel, unsigned int fadein); +int +sound_play(struct sound *, int, unsigned int); void -sound_pause(struct sound *snd); +sound_pause(struct sound *); void -sound_resume(struct sound *snd); +sound_resume(struct sound *); void -sound_stop(struct sound *snd, unsigned int fadeout); +sound_stop(struct sound *, unsigned int); void -sound_finish(struct sound *snd); +sound_finish(struct sound *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/sprite.c --- a/libmlk-core/core/sprite.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/sprite.c Wed Mar 10 18:49:08 2021 +0100 @@ -37,22 +37,19 @@ sprite->ncols = tex->w / cellw; } -bool +int sprite_ok(const struct sprite *sprite) { - if (!sprite) - return false; - - return texture_ok(sprite->texture) && sprite->cellw != 0 && sprite->cellh != 0; + return sprite && texture_ok(sprite->texture) && sprite->cellw != 0 && sprite->cellh != 0; } -bool +int sprite_draw(const struct sprite *sprite, unsigned int r, unsigned int c, int x, int y) { return sprite_scale(sprite, r, c, x, y, sprite->cellw, sprite->cellh); } -bool +int sprite_scale(const struct sprite *sprite, unsigned int r, unsigned int c, diff -r 6151152d009c -r 196264679079 libmlk-core/core/sprite.h --- a/libmlk-core/core/sprite.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/sprite.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_CORE_SPRITE_H #define MOLKO_CORE_SPRITE_H -#include - #include "core.h" struct texture; @@ -36,25 +34,22 @@ CORE_BEGIN_DECLS void -sprite_init(struct sprite *sprite, - struct texture *tex, - unsigned int cellw, - unsigned int cellh); +sprite_init(struct sprite *, struct texture *, unsigned int, unsigned int); -bool -sprite_ok(const struct sprite *sprite); +int +sprite_ok(const struct sprite *); + +int +sprite_draw(const struct sprite *, unsigned int, unsigned int, int, int); -bool -sprite_draw(const struct sprite *sprite, unsigned int r, unsigned int c, int x, int y); - -bool -sprite_scale(const struct sprite *sprite, - unsigned int r, - unsigned int c, - int x, - int y, - unsigned int w, - unsigned int h); +int +sprite_scale(const struct sprite *, + unsigned int, + unsigned int, + int, + int, + unsigned int, + unsigned int); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/state.h --- a/libmlk-core/core/state.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/state.h Wed Mar 10 18:49:08 2021 +0100 @@ -25,33 +25,33 @@ struct state { void *data; - void (*start)(struct state *state); - void (*handle)(struct state *state, const union event *ev); - void (*update)(struct state *state, unsigned int ticks); - void (*draw)(struct state *state); - void (*end)(struct state *state); - void (*finish)(struct state *state); + void (*start)(struct state *); + void (*handle)(struct state *, const union event *); + void (*update)(struct state *, unsigned int); + void (*draw)(struct state *); + void (*end)(struct state *); + void (*finish)(struct state *); }; CORE_BEGIN_DECLS void -state_start(struct state *state); +state_start(struct state *); void -state_handle(struct state *state, const union event *ev); +state_handle(struct state *, const union event *); void -state_update(struct state *state, unsigned int ticks); +state_update(struct state *, unsigned int); void -state_draw(struct state *state); +state_draw(struct state *); void -state_end(struct state *state); +state_end(struct state *); void -state_finish(struct state *state); +state_finish(struct state *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/sys.c --- a/libmlk-core/core/sys.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/sys.c Wed Mar 10 18:49:08 2021 +0100 @@ -63,7 +63,7 @@ #if defined(_WIN32) -static bool +static inline int is_absolute(const char *path) { return !PathIsRelativeA(path); @@ -71,7 +71,7 @@ #else -static bool +static inline int is_absolute(const char *path) { return path[0] == '/'; @@ -79,7 +79,7 @@ #endif -static char * +static inline char * normalize(char *str) { for (char *p = str; *p; ++p) @@ -89,35 +89,7 @@ return str; } -bool -sys_init(const char *organization, const char *name) -{ -#if defined(__MINGW64__) - /* On MinGW buffering leads to painful debugging. */ - setbuf(stderr, NULL); - setbuf(stdout, NULL); -#endif - - strlcpy(info.organization, organization, sizeof (info.organization)); - strlcpy(info.name, name, sizeof (info.name)); - - if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) - return errorf("%s", SDL_GetError()); - if (IMG_Init(IMG_INIT_PNG) != IMG_INIT_PNG) - return errorf("%s", SDL_GetError()); - if (TTF_Init() < 0) - return errorf("%s", SDL_GetError()); - if (Mix_Init(MIX_INIT_OGG) != MIX_INIT_OGG) - return errorf("%s", SDL_GetError()); - if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) < 0) - return errorf("%s", SDL_GetError()); - - Mix_AllocateChannels(SOUND_CHANNELS_MAX); - - return true; -} - -static const char * +static inline const char * absolute(const char *which) { static char path[PATH_MAX]; @@ -193,7 +165,7 @@ return path; } -static bool +static inline int mkpath(const char *path) { #ifdef _WIN32 @@ -205,7 +177,35 @@ return errorf("%s", strerror(errno)); #endif - return true; + return 0; +} + +int +sys_init(const char *organization, const char *name) +{ +#if defined(__MINGW64__) + /* On MinGW buffering leads to painful debugging. */ + setbuf(stderr, NULL); + setbuf(stdout, NULL); +#endif + + strlcpy(info.organization, organization, sizeof (info.organization)); + strlcpy(info.name, name, sizeof (info.name)); + + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) + return errorf("%s", SDL_GetError()); + if (IMG_Init(IMG_INIT_PNG) != IMG_INIT_PNG) + return errorf("%s", SDL_GetError()); + if (TTF_Init() < 0) + return errorf("%s", SDL_GetError()); + if (Mix_Init(MIX_INIT_OGG) != MIX_INIT_OGG) + return errorf("%s", SDL_GetError()); + if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 4096) < 0) + return errorf("%s", SDL_GetError()); + + Mix_AllocateChannels(SOUND_CHANNELS_MAX); + + return 0; } const char * @@ -221,7 +221,7 @@ } } -bool +int sys_mkdir(const char *directory) { char path[PATH_MAX], *p; @@ -244,8 +244,8 @@ if (*p == '/') { *p = 0; - if (!mkpath(path)) - return false; + if (mkpath(path) < 0) + return -1; *p = '/'; } diff -r 6151152d009c -r 196264679079 libmlk-core/core/sys.h --- a/libmlk-core/core/sys.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/sys.h Wed Mar 10 18:49:08 2021 +0100 @@ -20,7 +20,6 @@ #define MOLKO_CORE_SYS_H #include -#include #include "core.h" @@ -33,14 +32,14 @@ CORE_BEGIN_DECLS -bool -sys_init(const char *organization, const char *name); +int +sys_init(const char *, const char *); const char * -sys_dir(enum sys_dir kind); +sys_dir(enum sys_dir); -bool -sys_mkdir(const char *path); +int +sys_mkdir(const char *); void sys_finish(void); diff -r 6151152d009c -r 196264679079 libmlk-core/core/texture.c --- a/libmlk-core/core/texture.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/texture.c Wed Mar 10 18:49:08 2021 +0100 @@ -26,7 +26,7 @@ #include "window.h" #include "window_p.h" -bool +int texture_new(struct texture *tex, unsigned int w, unsigned int h) { assert(tex); @@ -42,16 +42,16 @@ tex->w = w; tex->h = h; - return true; + return 0; } -bool +int texture_ok(const struct texture *tex) { return tex && tex->handle && tex->w && tex->h; } -bool +int texture_set_blend_mode(struct texture *tex, enum texture_blend blend) { assert(tex); @@ -67,10 +67,10 @@ if (SDL_SetTextureBlendMode(tex->handle, table[blend]) < 0) return errorf("%s", SDL_GetError()); - return true; + return 0; } -bool +int texture_set_alpha_mod(struct texture *tex, unsigned int alpha) { assert(texture_ok(tex)); @@ -79,10 +79,10 @@ if (SDL_SetTextureAlphaMod(tex->handle, alpha) < 0) return errorf("%s", SDL_GetError()); - return true; + return 0; } -bool +int texture_set_color_mod(struct texture *tex, unsigned long color) { assert(texture_ok(tex)); @@ -90,10 +90,10 @@ if (SDL_SetTextureColorMod(tex->handle, COLOR_R(color), COLOR_G(color), COLOR_B(color)) < 0) return errorf("%s", SDL_GetError()); - return true; + return 0; } -bool +int texture_draw(const struct texture *tex, int x, int y) { assert(tex); @@ -108,10 +108,10 @@ if (SDL_RenderCopy(RENDERER(), tex->handle, NULL, &dst) < 0) return errorf("%s", SDL_GetError()); - return true; + return 0; } -bool +int texture_scale(const struct texture *tex, int src_x, int src_y, @@ -139,7 +139,7 @@ if (SDL_RenderCopyEx(RENDERER(), tex->handle, &src, &dst, angle, NULL, SDL_FLIP_NONE) < 0) return errorf("%s", SDL_GetError()); - return true; + return 0; } void @@ -155,7 +155,7 @@ /* private */ -bool +int texture_from_surface(struct texture *tex, SDL_Surface *surface) { assert(tex); @@ -171,5 +171,5 @@ SDL_FreeSurface(surface); - return true; + return 0; } diff -r 6151152d009c -r 196264679079 libmlk-core/core/texture.h --- a/libmlk-core/core/texture.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/texture.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_CORE_TEXTURE_H #define MOLKO_CORE_TEXTURE_H -#include - #include "core.h" struct texture { @@ -39,38 +37,38 @@ CORE_BEGIN_DECLS -bool -texture_new(struct texture *tex, unsigned int w, unsigned int h); +int +texture_new(struct texture *, unsigned int, unsigned int); -bool -texture_ok(const struct texture *tex); +int +texture_ok(const struct texture *); -bool -texture_set_blend_mode(struct texture *tex, enum texture_blend blend); +int +texture_set_blend_mode(struct texture *, enum texture_blend); -bool -texture_set_alpha_mod(struct texture *tex, unsigned int alpha); +int +texture_set_alpha_mod(struct texture *, unsigned int); -bool -texture_set_color_mod(struct texture *tex, unsigned long color); +int +texture_set_color_mod(struct texture *, unsigned long); -bool -texture_draw(const struct texture *tex, int x, int y); +int +texture_draw(const struct texture *, int, int); -bool -texture_scale(const struct texture *tex, - int src_x, - int src_y, - unsigned src_w, - unsigned src_h, - int dst_x, - int dst_y, - unsigned dst_w, - unsigned dst_h, - double angle); +int +texture_scale(const struct texture *, + int, + int, + unsigned int, + unsigned int, + int, + int, + unsigned int, + unsigned int, + double); void -texture_finish(struct texture *tex); +texture_finish(struct texture *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/texture_p.h --- a/libmlk-core/core/texture_p.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/texture_p.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,13 +19,11 @@ #ifndef MOLKO_CORE_TEXTURE_P_H #define MOLKO_CORE_TEXTURE_P_H -#include - #include struct texture; -bool -texture_from_surface(struct texture *tex, SDL_Surface *surface); +int +texture_from_surface(struct texture *, SDL_Surface *); #endif /* !MOLKO_CORE_TEXTURE_P_H */ diff -r 6151152d009c -r 196264679079 libmlk-core/core/trace.h --- a/libmlk-core/core/trace.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/trace.h Wed Mar 10 18:49:08 2021 +0100 @@ -30,10 +30,10 @@ CORE_BEGIN_DECLS void -tracef(const char *fmt, ...); +tracef(const char *, ...); void -traceva(const char *fmt, va_list ap); +traceva(const char *, va_list); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/translate.c --- a/libmlk-core/core/translate.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/translate.c Wed Mar 10 18:49:08 2021 +0100 @@ -16,6 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include + #include "sysconfig.h" #if defined(MOLKO_WITH_NLS) @@ -26,16 +28,14 @@ #include "translate.h" #include "util.h" -#include - -bool +int translate_init(const char *name) { #if defined(MOLKO_WITH_NLS) if (!bindtextdomain(name, sys_dir(SYS_DIR_LOCALE))) - return false; + return -1; #endif - return true; + return 0; } void diff -r 6151152d009c -r 196264679079 libmlk-core/core/translate.h --- a/libmlk-core/core/translate.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/translate.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,14 +19,12 @@ #ifndef MOLKO_CORE_TRANSLATE_H #define MOLKO_CORE_TRANSLATE_H -#include - #include "core.h" CORE_BEGIN_DECLS -bool -translate_init(const char *name); +int +translate_init(const char *); void translate_finish(void); diff -r 6151152d009c -r 196264679079 libmlk-core/core/util.h --- a/libmlk-core/core/util.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/util.h Wed Mar 10 18:49:08 2021 +0100 @@ -26,13 +26,13 @@ CORE_BEGIN_DECLS void -util_delay(unsigned int ms); +util_delay(unsigned int); const char * -util_pathf(const char *fmt, ...); +util_pathf(const char *, ...); unsigned int -util_nrand(unsigned int lower, unsigned int upper); +util_nrand(unsigned int, unsigned int); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-core/core/window.c --- a/libmlk-core/core/window.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/window.c Wed Mar 10 18:49:08 2021 +0100 @@ -66,19 +66,19 @@ SDL_FreeCursor(cursors[i]); } -static bool +static int load_window(const char *title, unsigned int w, unsigned int h) { - return (handle.win = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, 0)); + return (handle.win = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, 0)) != NULL; } -static bool +static int load_renderer(void) { - return (handle.renderer = SDL_CreateRenderer(handle.win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC)); + return (handle.renderer = SDL_CreateRenderer(handle.win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC)) != NULL; } -bool +int window_open(const char *title, unsigned int w, unsigned int h) { assert(title); @@ -92,7 +92,7 @@ load_framerate(); load_cursors(); - return true; + return 0; } void diff -r 6151152d009c -r 196264679079 libmlk-core/core/window.h --- a/libmlk-core/core/window.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-core/core/window.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_CORE_WINDOW_H #define MOLKO_CORE_WINDOW_H -#include - #include "core.h" struct window { @@ -45,11 +43,11 @@ CORE_BEGIN_DECLS -bool -window_open(const char *title, unsigned int width, unsigned int height); +int +window_open(const char *, unsigned int, unsigned int); void -window_set_cursor(enum window_cursor cursor); +window_set_cursor(enum window_cursor); void window_finish(void); diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-bar.c --- a/libmlk-rpg/rpg/battle-bar.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-bar.c Wed Mar 10 18:49:08 2021 +0100 @@ -207,7 +207,7 @@ gridmenu_draw(&bar->sub_grid); } -static bool +static int handle_keydown(struct battle_bar *bar, const union event *ev) { assert(ev->type == EVENT_KEYDOWN); @@ -229,7 +229,7 @@ bar->menu = BATTLE_BAR_MENU_SPECIAL; break; case KEY_ENTER: - return true; + return 1; default: break; } @@ -242,10 +242,10 @@ break; } - return false; + return 0; } -static bool +static int handle_clickdown(struct battle_bar *bar, const union event *ev) { assert(ev->type == EVENT_CLICKDOWN); @@ -263,7 +263,7 @@ break; } - return false; + return 0; } void @@ -286,7 +286,7 @@ bar->status_frame.theme = bt->theme; } -bool +int battle_bar_handle(struct battle_bar *bar, const struct battle *bt, const union event *ev) { /* Not needed yet. */ @@ -297,7 +297,7 @@ assert(ev); if (bar->state == BATTLE_BAR_STATE_NONE) - return false; + return 0; switch (ev->type) { case EVENT_KEYDOWN: @@ -308,7 +308,7 @@ break; } - return false; + return 0; } void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-bar.h --- a/libmlk-rpg/rpg/battle-bar.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-bar.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,32 +19,6 @@ #ifndef MOLKO_RPG_BATTLE_BAR_H #define MOLKO_RPG_BATTLE_BAR_H -/* - * The bar is split into three individual pieces. - * - * +------------+--------+------------+ - * | Grid menu | Menu | Status | - * +------------+--------+------------+ - * - * - * The left grid menu is only shown when member field state is set to \ref - * BATTLE_BAR_STATE_SUB, it is usually opened when user select a magic or an - * object. - * - * The menu in the middle is the main selection and contains the enumeration - * battle_bar_menu using top, right, bottom left edges for short selection. - * - * The last part on the right is the status pane where the team characters stats - * are listed. - * - * By itself, the bar never modify the battle object, it is the responsability - * of the battle object or the battle state to change the bar object and to - * track change on events. As such, the battle object is always passed as const - * parameter. - */ - -#include - #include #include @@ -92,7 +66,7 @@ void battle_bar_positionate(struct battle_bar *bar, const struct battle *bt); -bool +int battle_bar_handle(struct battle_bar *bar, const struct battle *bt, const union event *ev); diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-entity-state-attacking.c --- a/libmlk-rpg/rpg/battle-entity-state-attacking.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-entity-state-attacking.c Wed Mar 10 18:49:08 2021 +0100 @@ -17,7 +17,6 @@ */ #include -#include #include #include @@ -33,7 +32,7 @@ struct animation anim; }; -static bool +static int update(struct battle_entity_state *st, struct battle_entity *et, unsigned int ticks) { (void)et; diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-entity-state-blinking.c --- a/libmlk-rpg/rpg/battle-entity-state-blinking.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-entity-state-blinking.c Wed Mar 10 18:49:08 2021 +0100 @@ -38,7 +38,7 @@ unsigned int count; }; -static bool +static int update(struct battle_entity_state *st, struct battle_entity *et, unsigned int ticks) { (void)et; diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-entity-state-moving.c --- a/libmlk-rpg/rpg/battle-entity-state-moving.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-entity-state-moving.c Wed Mar 10 18:49:08 2021 +0100 @@ -49,7 +49,7 @@ return pos->x < et->x ? 6 : 2; } -static bool +static int update(struct battle_entity_state *st, struct battle_entity *et, unsigned int ticks) { struct position *pos = st->data; diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-entity-state.c --- a/libmlk-rpg/rpg/battle-entity-state.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-entity-state.c Wed Mar 10 18:49:08 2021 +0100 @@ -21,7 +21,7 @@ #include "battle-entity.h" #include "battle-entity-state.h" -bool +int battle_entity_state_update(struct battle_entity_state *st, struct battle_entity *et, unsigned int ticks) { assert(st); @@ -30,7 +30,7 @@ if (st->update) return st->update(st, et, ticks); - return true; + return 1; } void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-entity-state.h --- a/libmlk-rpg/rpg/battle-entity-state.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-entity-state.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_RPG_BATTLE_ENTITY_STATE_H #define MOLKO_RPG_BATTLE_ENTITY_STATE_H -#include - #include struct battle_entity; @@ -28,34 +26,34 @@ struct battle_entity_state { void *data; - bool (*update)(struct battle_entity_state *st, struct battle_entity *et, unsigned int ticks); - void (*draw)(const struct battle_entity_state *st, const struct battle_entity *et); - void (*finish)(struct battle_entity_state *st, struct battle_entity *et); + int (*update)(struct battle_entity_state *, struct battle_entity *, unsigned int); + void (*draw)(const struct battle_entity_state *, const struct battle_entity *); + void (*finish)(struct battle_entity_state *, struct battle_entity *); }; CORE_BEGIN_DECLS -bool -battle_entity_state_update(struct battle_entity_state *st, struct battle_entity *et, unsigned int ticks); +int +battle_entity_state_update(struct battle_entity_state *, struct battle_entity *, unsigned int); void -battle_entity_state_draw(const struct battle_entity_state *st, const struct battle_entity *et); +battle_entity_state_draw(const struct battle_entity_state *, const struct battle_entity *); void -battle_entity_state_finish(struct battle_entity_state *st, struct battle_entity *et); +battle_entity_state_finish(struct battle_entity_state *, struct battle_entity *); /* Defined in their own files. */ void -battle_entity_state_normal(struct battle_entity *et); +battle_entity_state_normal(struct battle_entity *); void -battle_entity_state_moving(struct battle_entity *et, int destx, int desty); +battle_entity_state_moving(struct battle_entity *, int, int); void -battle_entity_state_blinking(struct battle_entity *et); +battle_entity_state_blinking(struct battle_entity *); void -battle_entity_state_attacking(struct battle_entity *et, struct sprite *which); +battle_entity_state_attacking(struct battle_entity *, struct sprite *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-entity.c --- a/libmlk-rpg/rpg/battle-entity.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-entity.c Wed Mar 10 18:49:08 2021 +0100 @@ -54,7 +54,7 @@ battle_entity_state_normal(et); } -bool +int battle_entity_ok(const struct battle_entity *et) { return et && character_ok(et->ch); @@ -72,7 +72,7 @@ et->state = st; } -bool +int battle_entity_update(struct battle_entity *et, unsigned int ticks) { assert(et); diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-entity.h --- a/libmlk-rpg/rpg/battle-entity.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-entity.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_RPG_BATTLE_ENTITY_H #define MOLKO_RPG_BATTLE_ENTITY_H -#include - #include #include @@ -29,39 +27,36 @@ struct battle_entity_state; struct character; -/** - * \brief In battle entity. - */ struct battle_entity { - struct character *ch; /*!< (+&?) Character to use. */ - int x; /*!< (+) Position on screen. */ - int y; /*!< (+) Position on screen. */ - struct label name; /*!< (*) Where its name label is located. */ - struct battle_entity_state *state; /*!< (+&) Update/draw state. */ + struct character *ch; + int x; + int y; + struct label name; + struct battle_entity_state *state; }; CORE_BEGIN_DECLS void -battle_entity_init(struct battle_entity *et); +battle_entity_init(struct battle_entity *); -bool -battle_entity_ok(const struct battle_entity *et); +int +battle_entity_ok(const struct battle_entity *); void -battle_entity_switch(struct battle_entity *et, struct battle_entity_state *st); +battle_entity_switch(struct battle_entity *, struct battle_entity_state *); -bool -battle_entity_update(struct battle_entity *et, unsigned int ticks); +int +battle_entity_update(struct battle_entity *, unsigned int); void -battle_entity_draw(const struct battle_entity *et, const struct battle *bt); +battle_entity_draw(const struct battle_entity *, const struct battle *); void -battle_entity_draw_sprite(const struct battle_entity *et); +battle_entity_draw_sprite(const struct battle_entity *); void -battle_entity_finish(struct battle_entity *et); +battle_entity_finish(struct battle_entity *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-indicator.c --- a/libmlk-rpg/rpg/battle-indicator.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-indicator.c Wed Mar 10 18:49:08 2021 +0100 @@ -39,7 +39,7 @@ return tgt > cmp ? fmin(cmp + STEP, tgt) : fmax(cmp - STEP, tgt); } -static inline bool +static inline int colored(const struct battle_indicator *bti) { /* Only check r, g, b and ignore alpha. */ @@ -62,12 +62,12 @@ bti->elapsed = 0; bti->alpha = 250; - if (!font_render(theme->fonts[THEME_FONT_INTERFACE], &bti->tex[0], buf, bti->cur) || - !font_render(theme->fonts[THEME_FONT_INTERFACE], &bti->tex[1], buf, 0x000000ff)) + if (font_render(theme->fonts[THEME_FONT_INTERFACE], &bti->tex[0], buf, bti->cur) < 0|| + font_render(theme->fonts[THEME_FONT_INTERFACE], &bti->tex[1], buf, 0x000000ff) < 0) panic(); } -bool +int battle_indicator_completed(const struct battle_indicator *bti) { assert(battle_indicator_ok(bti)); @@ -75,13 +75,13 @@ return colored(bti) && bti->alpha == 0; } -bool +int battle_indicator_ok(const struct battle_indicator *bti) { return bti && texture_ok(&bti->tex[0]) && texture_ok(&bti->tex[1]); } -bool +int battle_indicator_update(struct battle_indicator *bti, unsigned int ticks) { assert(battle_indicator_ok(bti)); diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-indicator.h --- a/libmlk-rpg/rpg/battle-indicator.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-indicator.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,108 +19,43 @@ #ifndef MOLKO_RPG_BATTLE_INDICATOR_H #define MOLKO_RPG_BATTLE_INDICATOR_H -/** - * \file battle-indicator.h - * \brief Drawable for rendering a hp/mp count usage. - * - * This small module creates an animation drawable that shows a label with a - * smooth color/fading transition, used to display hp/mp damage. - */ - -#include - #include #include -/** - * \brief Default color for HP indicator. - */ #define BATTLE_INDICATOR_HP_COLOR (0xa5303000) - -/** - * \brief Default color for MP indicator. - */ #define BATTLE_INDICATOR_MP_COLOR (0xa23e8c00) struct theme; -/** - * \brief Structure context for indicator animation. - * - * You must zero-initialize this structure and fill the color and amount field - * with the color target and the amount of damage to show respectively. Then use - * start, update and draw function in order until it completes. - */ struct battle_indicator { - unsigned int color; /*!< (+) Destination color. */ - unsigned int amount; /*!< (+) Amount text to draw. */ - const struct theme *theme; /*!< (+&?) Optional theme to use. */ - unsigned int cur; /*!< (-) Current color target. */ - unsigned int elapsed; /*!< (-) Elapsed time in transition. */ - unsigned int alpha; /*!< (-) Current alpha. */ - struct texture tex[2]; /*!< (*) Rendered texture. */ + unsigned int color; + unsigned int amount; + const struct theme *theme; + unsigned int cur; + unsigned int elapsed; + unsigned int alpha; + struct texture tex[2]; }; CORE_BEGIN_DECLS -/** - * Start the battle indicator. You must call this function only once. - * - * \pre bti != NULL - * \param bti the indicator - */ void -battle_indicator_start(struct battle_indicator *bti); +battle_indicator_start(struct battle_indicator *); -/** - * Tells if the indicator has completed. - * - * \pre battle_indicator_ok(bti) - * \param bti the indicator to check - * \return True if completed. - */ -bool -battle_indicator_completed(const struct battle_indicator *bti); +int +battle_indicator_completed(const struct battle_indicator *); -/** - * Tells if the indicator is valid. - * - * \param bti the indicator to check (may be NULL) - * \return True if correctly initialized. - */ -bool -battle_indicator_ok(const struct battle_indicator *bti); +int +battle_indicator_ok(const struct battle_indicator *); -/** - * Update the indicator. - * - * \pre battle_indicator_ok(bti) - * \param bti the indicator - * \param ticks the elapsed milliseconds since last frame - * \return True if completed. - */ -bool -battle_indicator_update(struct battle_indicator *bti, unsigned int ticks); +int +battle_indicator_update(struct battle_indicator *, unsigned int); -/** - * Draw the indicator. - * - * \pre battle_indicator_ok(bti) - * \param bti the indicator - * \param x the x coordinate - * \param y the y coordinate - */ void -battle_indicator_draw(const struct battle_indicator *bti, int x, int y); +battle_indicator_draw(const struct battle_indicator *, int, int); -/** - * Dispose resources. - * - * \pre battle_indicator_ok(bti) - * \param bti the indicator - */ void -battle_indicator_finish(struct battle_indicator *bti); +battle_indicator_finish(struct battle_indicator *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-message.c --- a/libmlk-rpg/rpg/battle-message.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-message.c Wed Mar 10 18:49:08 2021 +0100 @@ -28,7 +28,7 @@ #define DELAY 1500 -bool +int battle_message_update(struct battle_message *msg, unsigned int ticks) { assert(msg); diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-message.h --- a/libmlk-rpg/rpg/battle-message.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-message.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_ADVENTURE_BATTLE_MESSAGE_H #define MOLKO_ADVENTURE_BATTLE_MESSAGE_H -#include - #include struct theme; @@ -33,7 +31,7 @@ CORE_BEGIN_DECLS -bool +int battle_message_update(struct battle_message *, unsigned int); void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-state-ai.c --- a/libmlk-rpg/rpg/battle-state-ai.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-state-ai.c Wed Mar 10 18:49:08 2021 +0100 @@ -22,7 +22,7 @@ #include "battle-state.h" #include "character.h" -static bool +static int update(struct battle_state *st, struct battle *bt, unsigned int ticks) { (void)st; @@ -36,7 +36,7 @@ */ character_exec(ch, bt); - return false; + return 0; } void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-state-attacking.c --- a/libmlk-rpg/rpg/battle-state-attacking.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-state-attacking.c Wed Mar 10 18:49:08 2021 +0100 @@ -68,7 +68,7 @@ battle_indicator_hp(bt, target->ch, 50); } -static bool +static int update(struct battle_state *st, struct battle *bt, unsigned int ticks) { (void)bt; @@ -77,7 +77,7 @@ struct data *data = st->data; if (!battle_entity_update(data->source, 0)) - return false; + return 0; switch (data->substate) { case SUBSTATE_ADVANCING: @@ -107,7 +107,7 @@ break; } - return false; + return 0; } static void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-state-check.c --- a/libmlk-rpg/rpg/battle-state-check.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-state-check.c Wed Mar 10 18:49:08 2021 +0100 @@ -38,7 +38,7 @@ unsigned int elapsed; }; -static bool +static int fadeout_update(struct action *act, unsigned int ticks) { struct fadeout *fade = act->data; @@ -50,12 +50,12 @@ fade->elapsed = 0; if (fade->alpha == 0) - return true; + return 1; fade->alpha -= 10; } - return false; + return 0; } static void @@ -92,13 +92,13 @@ fade->action.update = fadeout_update; fade->action.finish = fadeout_finish; - if (!action_stack_add(&bt->actions[1], &fade->action)) + if (action_stack_add(&bt->actions[1], &fade->action) < 0) free(fade); memset(et, 0, sizeof (*et)); } -static bool +static int is_dead(const struct battle *bt) { const struct battle_entity *et; @@ -107,22 +107,22 @@ if (!character_ok(et->ch)) continue; if (et->ch->hp > 0) - return false; + return 0; } - return true; + return 1; } -static bool +static int is_won(const struct battle *bt) { const struct battle_entity *et; BATTLE_ENEMY_FOREACH(bt, et) if (character_ok(et->ch)) - return false; + return 0; - return true; + return 1; } static void @@ -135,7 +135,7 @@ fadeout(bt, et); } -static bool +static int update(struct battle_state *st, struct battle *bt, unsigned int ticks) { (void)st; @@ -150,7 +150,7 @@ else battle_next(bt); - return false; + return 0; } void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-state-closing.c --- a/libmlk-rpg/rpg/battle-state-closing.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-state-closing.c Wed Mar 10 18:49:08 2021 +0100 @@ -35,7 +35,7 @@ unsigned int elapsed; }; -static bool +static int update(struct battle_state *st, struct battle *bt, unsigned int ticks) { (void)bt; @@ -49,14 +49,14 @@ if (closing->alpha == 255) { music_stop(0); - return true; + return 1; } closing->alpha += 5; texture_set_alpha_mod(&closing->texture, closing->alpha); } - return false; + return 0; } static void @@ -88,7 +88,7 @@ struct closing *closing; if (!(closing = alloc_new0(sizeof (*closing))) || - !texture_new(&closing->texture, window.w, window.h)) + texture_new(&closing->texture, window.w, window.h) < 0) panic(); PAINTER_BEGIN(&closing->texture); diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-state-item.c --- a/libmlk-rpg/rpg/battle-state-item.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-state-item.c Wed Mar 10 18:49:08 2021 +0100 @@ -46,7 +46,7 @@ int origin_x; }; -static bool +static int update(struct battle_state *st, struct battle *bt, unsigned int ticks) { struct self *self = st->data; @@ -73,7 +73,7 @@ break; } - return false; + return 0; } static void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-state-lost.c --- a/libmlk-rpg/rpg/battle-state-lost.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-state-lost.c Wed Mar 10 18:49:08 2021 +0100 @@ -44,7 +44,7 @@ message_handle(&lost->msg, ev); } -static bool +static int update(struct battle_state *st, struct battle *bt, unsigned int ticks) { (void)bt; @@ -54,7 +54,7 @@ if (message_update(&lost->msg, ticks)) battle_state_closing(bt); - return false; + return 0; } static void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-state-menu.c --- a/libmlk-rpg/rpg/battle-state-menu.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-state-menu.c Wed Mar 10 18:49:08 2021 +0100 @@ -17,7 +17,6 @@ */ #include -#include #include "battle.h" #include "battle-bar.h" diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-state-opening.c --- a/libmlk-rpg/rpg/battle-state-opening.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-state-opening.c Wed Mar 10 18:49:08 2021 +0100 @@ -17,7 +17,6 @@ */ #include -#include #include #include @@ -35,7 +34,7 @@ unsigned int elapsed; }; -static bool +static int update(struct battle_state *st, struct battle *bt, unsigned int ticks) { assert(bt); @@ -51,7 +50,7 @@ if (opening->elapsed >= DELAY) battle_state_check(bt); - return false; + return 0; } static void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-state-sub.c --- a/libmlk-rpg/rpg/battle-state-sub.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-state-sub.c Wed Mar 10 18:49:08 2021 +0100 @@ -17,7 +17,6 @@ */ #include -#include #include #include diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-state-victory.c --- a/libmlk-rpg/rpg/battle-state-victory.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-state-victory.c Wed Mar 10 18:49:08 2021 +0100 @@ -44,7 +44,7 @@ message_handle(&vic->msg, ev); } -static bool +static int update(struct battle_state *st, struct battle *bt, unsigned int ticks) { (void)bt; @@ -54,7 +54,7 @@ if (message_update(&vic->msg, ticks)) battle_state_closing(bt); - return false; + return 0; } static void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-state.c --- a/libmlk-rpg/rpg/battle-state.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-state.c Wed Mar 10 18:49:08 2021 +0100 @@ -31,7 +31,7 @@ st->handle(st, bt, ev); } -bool +int battle_state_update(struct battle_state *st, struct battle *bt, unsigned int ticks) { assert(st); @@ -40,7 +40,7 @@ if (st->update) return st->update(st, bt, ticks); - return false; + return 0; } void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle-state.h --- a/libmlk-rpg/rpg/battle-state.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle-state.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,20 +19,6 @@ #ifndef MOLKO_RPG_BATTLE_STATE_H #define MOLKO_RPG_BATTLE_STATE_H -/** - * \file battle-state.h - * \brief Battle abstract state. - * - * As a game battle is split into different steps, they are implemented as - * multiple states to facilitate transitions and have a less complicated code. - * - * Each state can handle, update and draw the game logic. The battle itself - * does only few things by itself like playing music, handling custom actions - * and drawables and dispatch the rest to the current state. - */ - -#include - #include struct battle; @@ -44,62 +30,62 @@ struct battle_state { void *data; - void (*handle)(struct battle_state *st, struct battle *bt, const union event *ev); - bool (*update)(struct battle_state *st, struct battle *bt, unsigned int ticks); - void (*draw)(const struct battle_state *st, const struct battle *bt); - void (*finish)(struct battle_state *st, struct battle *bt); + void (*handle)(struct battle_state *, struct battle *, const union event *); + int (*update)(struct battle_state *, struct battle *, unsigned int); + void (*draw)(const struct battle_state *, const struct battle *); + void (*finish)(struct battle_state *, struct battle *); }; CORE_BEGIN_DECLS void -battle_state_handle(struct battle_state *st, struct battle *bt, const union event *ev); +battle_state_handle(struct battle_state *, struct battle *, const union event *); -bool -battle_state_update(struct battle_state *st, struct battle *bt, unsigned int ticks); +int +battle_state_update(struct battle_state *, struct battle *, unsigned int); void -battle_state_draw(const struct battle_state *st, const struct battle *bt); +battle_state_draw(const struct battle_state *, const struct battle *); void -battle_state_finish(struct battle_state *st, struct battle *bt); +battle_state_finish(struct battle_state *, struct battle *); /* States switchers, defined in their own files. */ void -battle_state_ai(struct battle *bt); +battle_state_ai(struct battle *); void -battle_state_attacking(struct battle *bt, struct character *source, struct character *target); +battle_state_attacking(struct battle *, struct character *, struct character *); void -battle_state_item(struct battle *bt, - struct character *source, - struct character *target, - struct inventory_slot *slot); +battle_state_item(struct battle *, + struct character *, + struct character *, + struct inventory_slot *); void -battle_state_check(struct battle *bt); +battle_state_check(struct battle *); void -battle_state_closing(struct battle *bt); +battle_state_closing(struct battle *); void -battle_state_lost(struct battle *bt); +battle_state_lost(struct battle *); void -battle_state_menu(struct battle *bt); +battle_state_menu(struct battle *); void -battle_state_opening(struct battle *bt); +battle_state_opening(struct battle *); void -battle_state_selection(struct battle *bt, const struct selection *slt); +battle_state_selection(struct battle *, const struct selection *); void -battle_state_sub(struct battle *bt); +battle_state_sub(struct battle *); void -battle_state_victory(struct battle *bt); +battle_state_victory(struct battle *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle.c --- a/libmlk-rpg/rpg/battle.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle.c Wed Mar 10 18:49:08 2021 +0100 @@ -49,7 +49,7 @@ struct battle_indicator bti; }; -static bool +static int indicator_update(struct drawable *dw, unsigned int ticks) { struct indicator *id = dw->data; @@ -113,14 +113,14 @@ return et1->ch->agt < et2->ch->agt; } -static bool +static int is_team(const struct battle *bt, const struct character *ch) { for (size_t i = 0; i < BATTLE_TEAM_MAX; ++i) if (bt->team[i].ch == ch) - return true; + return 1; - return false; + return 0; } static void @@ -386,7 +386,7 @@ battle_indicator_start(&id->bti); - if (!drawable_stack_add(&bt->effects, &id->dw)) + if (drawable_stack_add(&bt->effects, &id->dw) < 0) drawable_finish(&id->dw); } @@ -405,7 +405,7 @@ battle_state_handle(bt->state, bt, ev); } -bool +int battle_update(struct battle *bt, unsigned int ticks) { assert(bt && bt->state); @@ -419,7 +419,7 @@ /* Game cannot update if the actions[0] stack isn't completed. */ if (!action_stack_completed(&bt->actions[0])) - return false; + return 0; return battle_state_update(bt->state, bt, ticks); } diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/battle.h --- a/libmlk-rpg/rpg/battle.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/battle.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_RPG_BATTLE_H #define MOLKO_RPG_BATTLE_H -#include - #include #include #include @@ -111,7 +109,7 @@ void battle_handle(struct battle *, const union event *); -bool +int battle_update(struct battle *, unsigned int); void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/character.c --- a/libmlk-rpg/rpg/character.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/character.c Wed Mar 10 18:49:08 2021 +0100 @@ -27,7 +27,7 @@ #include "equipment.h" #include "save.h" -bool +int character_ok(const struct character *ch) { return ch && ch->name && ch->reset && sprite_ok(ch->sprites[CHARACTER_SPRITE_NORMAL]); @@ -70,7 +70,7 @@ ch->exec(ch, bt); } -bool +int character_save(const struct character *ch, struct save *s) { assert(ch); @@ -91,17 +91,17 @@ ); } -bool +int character_load(struct character *ch, struct save *s) { assert(ch); assert(save_ok(s)); struct save_stmt stmt; - bool ret; + int ret; - if (!save_stmt_init(s, &stmt, (const char *)sql_character_load, "s", ch->name)) - return false; + if (save_stmt_init(s, &stmt, (const char *)sql_character_load, "s", ch->name) < 0) + return -1; ret = save_stmt_next(&stmt, "iii i iiiiii", &ch->hp, @@ -118,5 +118,5 @@ save_stmt_finish(&stmt); - return ret; + return 0; } diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/character.h --- a/libmlk-rpg/rpg/character.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/character.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_RPG_CHARACTER_H #define MOLKO_RPG_CHARACTER_H -#include - #include #define CHARACTER_SPELL_MAX (64) @@ -88,7 +86,7 @@ CORE_BEGIN_DECLS -bool +int character_ok(const struct character *ch); const char * @@ -100,10 +98,10 @@ void character_exec(struct character *ch, struct battle *bt); -bool +int character_save(const struct character *ch, struct save *s); -bool +int character_load(struct character *, struct save *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/equipment.c --- a/libmlk-rpg/rpg/equipment.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/equipment.c Wed Mar 10 18:49:08 2021 +0100 @@ -21,7 +21,7 @@ #include "character.h" #include "equipment.h" -bool +int equipment_ok(const struct equipment *eq) { return eq && eq->name && eq->description; diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/equipment.h --- a/libmlk-rpg/rpg/equipment.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/equipment.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,84 +19,47 @@ #ifndef MOLKO_RPG_EQUIPMENT_H #define MOLKO_RPG_EQUIPMENT_H -/** - * \file equipment.h - * \brief Character equipment. - */ - -#include - #include struct character; struct texture; -/** - * \brief Kind of equipment. - * - * There are different kind of equipments. Weapons are listed in this - * enumeration even though a character can carry only one of them at a time. On - * the other hand, a character is able to carry each of the defensive item. - */ enum equipment_type { /* Attack weapons. */ - EQUIPMENT_TYPE_AXE, /*!< Axe. */ - EQUIPMENT_TYPE_BOW, /*!< Bow. */ - EQUIPMENT_TYPE_CROSSBOW, /*!< Cross bow. */ - EQUIPMENT_TYPE_DAGGER, /*!< Small dagger. */ - EQUIPMENT_TYPE_HAMMER, /*!< Large hammer. */ - EQUIPMENT_TYPE_SPIKE, /*!< Spike. */ - EQUIPMENT_TYPE_SWORD, /*!< Sword. */ - EQUIPMENT_TYPE_WAND, /*!< Magic wands. */ + EQUIPMENT_TYPE_AXE, + EQUIPMENT_TYPE_BOW, + EQUIPMENT_TYPE_CROSSBOW, + EQUIPMENT_TYPE_DAGGER, + EQUIPMENT_TYPE_HAMMER, + EQUIPMENT_TYPE_SPIKE, + EQUIPMENT_TYPE_SWORD, + EQUIPMENT_TYPE_WAND, /* Defense equipment. */ - EQUIPMENT_TYPE_GLOVES, /*!< Hand gloves. */ - EQUIPMENT_TYPE_HELMET, /*!< Head helmet. */ - EQUIPMENT_TYPE_SHIELD, /*!< Shield. */ - EQUIPMENT_TYPE_TOP, /*!< Top protection. */ - EQUIPMENT_TYPE_TROUSERS, /*!< Trousers. */ + EQUIPMENT_TYPE_GLOVES, + EQUIPMENT_TYPE_HELMET, + EQUIPMENT_TYPE_SHIELD, + EQUIPMENT_TYPE_TOP, + EQUIPMENT_TYPE_TROUSERS, }; -/** - * \brief Equipment structure. - */ struct equipment { - const char *name; /*!< (+&) Equipment short name. */ - const char *description; /*!< (+&) Longer description. */ - unsigned int price; /*!< (+) Standard price. */ - enum equipment_type type; /*!< (+) Kind of equipment. */ - struct texture *icon; /*!< (+&) Icon to show in menus. */ + const char *name; + const char *description; + unsigned int price; + enum equipment_type type; + struct texture *icon; - /** - * (+?) Function called when user equip the object. - * - * \param eq this equipment - * \param ch the character owner - */ - void (*equip)(const struct equipment *eq, struct character *ch); + void (*equip)(const struct equipment *, struct character *); }; CORE_BEGIN_DECLS -/** - * Tells if this equipment object is valid. - * - * \param eq the equipment to check (may be NULL) - * \return True if valid. - */ -bool -equipment_ok(const struct equipment *eq); +int +equipment_ok(const struct equipment *); -/** - * Shortcut for eq->equip (if not NULL). - * - * \pre equipment_ok(eq) - * \pre character_ok(ch) - * \param eq this equipment - * \param ch the character owner - */ void -equipment_equip(const struct equipment *eq, struct character *ch); +equipment_equip(const struct equipment *, struct character *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/inventory.c --- a/libmlk-rpg/rpg/inventory.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/inventory.c Wed Mar 10 18:49:08 2021 +0100 @@ -31,7 +31,7 @@ return NULL; } -bool +int inventory_add(struct inventory *iv, const struct item *item, unsigned int amount) { assert(iv); @@ -44,12 +44,12 @@ slot = find(iv, NULL); if (!slot) - return false; + return 0; slot->item = item; slot->amount += amount; - return true; + return -1; } void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/inventory.h --- a/libmlk-rpg/rpg/inventory.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/inventory.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,8 +19,6 @@ #ifndef MOLKO_RPG_INVENTORY_H #define MOLKO_RPG_INVENTORY_H -#include - #include #define INVENTORY_ITEM_MAX (512) @@ -38,11 +36,11 @@ CORE_BEGIN_DECLS -bool -inventory_add(struct inventory *iv, const struct item *item, unsigned int amount); +int +inventory_add(struct inventory *, const struct item *, unsigned int); void -inventory_consume(struct inventory *iv, const struct item *item, unsigned int amount); +inventory_consume(struct inventory *, const struct item *, unsigned int); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/item.h --- a/libmlk-rpg/rpg/item.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/item.h Wed Mar 10 18:49:08 2021 +0100 @@ -30,24 +30,24 @@ const char *description; struct texture *icon; - void (*exec_menu)(const struct item *item, struct character *ch); + void (*exec_menu)(const struct item *, struct character *); - void (*exec_battle)(const struct item *item, - struct battle *bt, - struct character *src, - struct character *tgt); + void (*exec_battle)(const struct item *, + struct battle *, + struct character *, + struct character *); }; CORE_BEGIN_DECLS void -item_exec_menu(const struct item *item, struct character *ch); +item_exec_menu(const struct item *, struct character *); void -item_exec_battle(const struct item *item, - struct battle *bt, - struct character *src, - struct character *tgt); +item_exec_battle(const struct item *, + struct battle *, + struct character *, + struct character *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/map-file.c --- a/libmlk-rpg/rpg/map-file.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/map-file.c Wed Mar 10 18:49:08 2021 +0100 @@ -44,7 +44,7 @@ char basedir[PATH_MAX]; /* Parent map directory */ }; -static bool +static int parse_layer_tiles(struct context *ctx, const char *layer_name) { enum map_layer_type layer_type; @@ -67,17 +67,17 @@ * that fill the layer tiles. */ if (!(ctx->mf->layers[layer_type].tiles = alloc_array0(amount, sizeof (unsigned short)))) - return false; + return -1; for (int tile; fscanf(ctx->fp, "%d\n", &tile) && current < amount; ++current) ctx->mf->layers[layer_type].tiles[current] = tile; ctx->map->layers[layer_type].tiles = ctx->mf->layers[layer_type].tiles; - return true; + return 0; } -static bool +static int parse_actions(struct context *ctx) { char exec[128 + 1]; @@ -103,7 +103,7 @@ */ if (block) { if (!(reg = alloc_pool_new(&ctx->mf->blocks))) - return false; + return -1; reg->x = x; reg->y = y; @@ -116,10 +116,10 @@ ctx->map->blocks = ctx->mf->blocks.data; ctx->map->blocksz = ctx->mf->blocks.size; - return true; + return 0; } -static bool +static int parse_layer(struct context *ctx, const char *line) { char layer_name[32 + 1] = {0}; @@ -138,7 +138,7 @@ return parse_layer_tiles(ctx, layer_name); } -static bool +static int parse_tileset(struct context *ctx, const char *line) { char path[PATH_MAX] = {0}, *p; @@ -150,15 +150,15 @@ snprintf(path, sizeof (path), "%s/%s", ctx->basedir, p + 1); - if (!tileset_file_open(tf, &mf->tileset, path)) - return false; + if (tileset_file_open(tf, &mf->tileset, path) < 0) + return -1; ctx->map->tileset = &mf->tileset; - return true; + return 0; } -static bool +static int parse_title(struct context *ctx, const char *line) { if (sscanf(line, "title|" MAX_F(MAP_FILE_TITLE_MAX), ctx->mf->title) != 1 || strlen(ctx->mf->title) == 0) @@ -166,42 +166,42 @@ ctx->map->title = ctx->mf->title; - return true; + return 0; } -static bool +static int parse_columns(struct context *ctx, const char *line) { if (sscanf(line, "columns|%u", &ctx->map->columns) != 1 || ctx->map->columns == 0) return errorf(_("null map columns")); - return true; + return 0; } -static bool +static int parse_rows(struct context *ctx, const char *line) { if (sscanf(line, "rows|%u", &ctx->map->rows) != 1 || ctx->map->rows == 0) return errorf(_("null map rows")); - return true; + return 0; } -static bool +static int parse_origin(struct context *ctx, const char *line) { if (sscanf(line, "origin|%d|%d", &ctx->map->player_x, &ctx->map->player_y) != 2) return errorf(_("invalid origin")); - return true; + return 0; } -static bool +static int parse_line(struct context *ctx, const char *line) { static const struct { const char *property; - bool (*read)(struct context *, const char *); + int (*read)(struct context *, const char *); } props[] = { { "title", parse_title }, { "columns", parse_columns }, @@ -215,10 +215,10 @@ if (strncmp(line, props[i].property, strlen(props[i].property)) == 0) return props[i].read(ctx, line); - return true; + return 0; } -static bool +static int parse(struct context *ctx, const char *path) { char line[1024]; @@ -231,14 +231,14 @@ /* Remove \n if any */ line[strcspn(line, "\n")] = '\0'; - if (!parse_line(ctx, line)) - return false; + if (parse_line(ctx, line) < 0) + return -1; } - return true; + return 0; } -static bool +static int check(struct map *map) { /* @@ -258,10 +258,10 @@ if (!tileset_ok(map->tileset)) return errorf(_("missing tileset")); - return true; + return 0; } -bool +int map_file_open(struct map_file *file, struct map *map, const char *path) { assert(file); @@ -273,30 +273,30 @@ .map = map, }; struct zfile zf; - bool ret = true; + int ret = 0; memset(map, 0, sizeof (*map)); - if (!alloc_pool_init(&file->blocks, sizeof (*map->blocks), NULL)) + if (alloc_pool_init(&file->blocks, sizeof (*map->blocks), NULL) < 0) goto fail; if (zfile_open(&zf, path) < 0) goto fail; ctx.fp = zf.fp; - if (!(ret = parse(&ctx, path)) || !(ret = check(map))) + if ((ret = parse(&ctx, path)) < 0 || (ret = check(map)) < 0) goto fail; zfile_close(&zf); - return true; + return 0; fail: map_finish(map); map_file_finish(file); zfile_close(&zf); - return false; + return -1; } void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/map-file.h --- a/libmlk-rpg/rpg/map-file.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/map-file.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,26 +19,6 @@ #ifndef MOLKO_RPG_MAP_FILE_H #define MOLKO_RPG_MAP_FILE_H -/** - * \file map-file.h - * \brief Map file loader. - * - * Because a map is a complicated object that require several components to be - * loaded, the way it is loaded from a source is implemented separately to keep - * the \ref map.h module as simple as possible. - * - * This module load map files generated from mlk-map tool and expect some - * convention from the user: - * - * - A tileset image must be present in the same directory as the map itself. - * - * This module allocates some dynamic data that are stored in the map object as - * such the map_file structure must be kept until the map is no longer used - * itself. - */ - -#include - #include #include #include @@ -48,58 +28,23 @@ #include "tileset.h" #include "tileset-file.h" -/** - * \brief Maximum title map length in file. - */ #define MAP_FILE_TITLE_MAX 64 -/** - * \brief Context for loading maps. - * - * Member fields should not be modified directly but must be modified in the - * underlying associated map object once loaded. - * - * Since the map object does not own resources, this map file will dynamically - * load and store them from the file and thus must not be destroyed until the - * map is no longer use itself. - */ struct map_file { - /** - * (+?) User function to create an action when it is listed in the map - * definition. - */ - void (*load_action)(struct map *map, int x, int y, int w, int h, const char *exec); + void (*load_action)(struct map *, int, int, int, int, const char *); - char title[MAP_FILE_TITLE_MAX]; /*!< \private */ - struct map_layer layers[MAP_LAYER_TYPE_NUM]; /*!< \private */ - struct tileset_file tileset_file; /*!< \private */ - struct tileset tileset; /*!< \private */ - struct alloc_pool blocks; /*!< \private */ + char title[MAP_FILE_TITLE_MAX]; + struct map_layer layers[MAP_LAYER_TYPE_NUM]; + struct tileset_file tileset_file; + struct tileset tileset; + struct alloc_pool blocks; }; CORE_BEGIN_DECLS -/** - * Try to open a map from a file path. - * - * \pre file != NULL - * \pre path != NULL - * \pre map != NULL - * \param file the loader to use - * \param map the map to set - * \param path the path to the map file - * \warning Keep file object until map is no longer used. - */ -bool +int map_file_open(struct map_file *file, struct map *map, const char *path); -/** - * Close resources from the loader. - * - * \pre file != NULL - * \param file the file to loader to destroy - * \warning Destroy the map itself before calling this function. - */ void map_file_finish(struct map_file *file); diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/map.c --- a/libmlk-rpg/rpg/map.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/map.c Wed Mar 10 18:49:08 2021 +0100 @@ -97,7 +97,7 @@ * player is moving upwards but the collision shape is below it is unnecessary * to check. */ -static bool +static int is_block_relevant(const struct map *map, const struct map_block *block, int drow, @@ -107,30 +107,30 @@ /* Object outside of left-right bounds. */ if (block->x + (int)block->w <= map->player_x || block->x >= map->player_x + (int)map->player_sprite->cellw) - return false; + return 0; if ((drow < 0 && block->y >= map->player_y + (int)map->player_sprite->cellh) || (drow > 0 && block->y + block->h <= map->player_y + map->player_sprite->cellh)) - return false; + return 0; } else if (dcol) { /* Object outside of up-down bounds. */ if (block->y + (int)block->h <= map->player_y || block->y >= map->player_y + (int)map->player_sprite->cellh) - return false; + return 0; if ((dcol < 0 && block->x >= map->player_x + (int)map->player_sprite->cellw) || (dcol > 0 && block->x + block->w <= map->player_x + map->player_sprite->cellw)) - return false; + return 0; } - return true; + return 1; } /* * Determine if this collision shape is "closer" to the player by checking the * new block coordinates with the previous one. */ -static bool +static int is_block_better(const struct map_block *now, const struct map_block *new, int drow, @@ -259,7 +259,7 @@ if (row < 0 || (unsigned int)row >= map->rows || col < 0 || (unsigned int)col >= map->columns) - return false; + return 0; if ((id = layer->tiles[col + row * map->columns]) == 0) return NULL; @@ -535,7 +535,7 @@ return; /* Show collision box if requested. */ - if (map->flags & MAP_FLAGS_SHOW_COLLIDE && texture_new(&colbox, 16, 16)) { + if (map->flags & MAP_FLAGS_SHOW_COLLIDE && texture_new(&colbox, 16, 16) == 0) { texture_set_blend_mode(&colbox, TEXTURE_BLEND_BLEND); texture_set_alpha_mod(&colbox, 100); PAINTER_BEGIN(&colbox); @@ -562,7 +562,7 @@ { struct texture box = {0}; - if (map->flags & MAP_FLAGS_SHOW_COLLIDE && texture_new(&box, 64, 64)) { + if (map->flags & MAP_FLAGS_SHOW_COLLIDE && texture_new(&box, 64, 64) == 0) { /* Draw collide box around player if requested. */ texture_set_alpha_mod(&box, 100); texture_set_blend_mode(&box, TEXTURE_BLEND_BLEND); @@ -591,7 +591,7 @@ } } -bool +int map_init(struct map *map) { assert(map); @@ -599,7 +599,7 @@ init(map); tileset_start(map->tileset); - return true; + return 0; } void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/map.h --- a/libmlk-rpg/rpg/map.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/map.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,11 +19,6 @@ #ifndef MOLKO_RPG_MAP_H #define MOLKO_RPG_MAP_H -/** - * \file map.h - * \brief Game map. - */ - #include #include @@ -35,51 +30,30 @@ union event; -/** - * \brief Map layer type. - */ enum map_layer_type { - MAP_LAYER_TYPE_BACKGROUND, /*!< Background layer. */ - MAP_LAYER_TYPE_FOREGROUND, /*!< Foreground layer. */ - MAP_LAYER_TYPE_ABOVE, /*!< Above foreground layer. */ - MAP_LAYER_TYPE_NUM /*!< Number of layers. */ + MAP_LAYER_TYPE_BACKGROUND, + MAP_LAYER_TYPE_FOREGROUND, + MAP_LAYER_TYPE_ABOVE, + MAP_LAYER_TYPE_NUM }; -/** - * \brief Map layer. - */ struct map_layer { - unsigned short *tiles; /*!< (+&) Array of tiles, depending on the map size. */ + unsigned short *tiles; }; -/** - * \brief Map view flags. - */ enum map_flags { - MAP_FLAGS_NONE = 0, /*!< No flags. */ - MAP_FLAGS_SHOW_GRID = (1 << 0), /*!< Show grid pattern. */ - MAP_FLAGS_SHOW_COLLIDE = (1 << 2) /*!< Show collision layer. */ + MAP_FLAGS_NONE = 0, + MAP_FLAGS_SHOW_GRID = (1 << 0), + MAP_FLAGS_SHOW_COLLIDE = (1 << 2) }; -/** - * \brief Map collision block. - */ struct map_block { - int x; /*!< (+) Position in x. */ - int y; /*!< (+) Position in y. */ - unsigned int w; /*!< (+) Width. */ - unsigned int h; /*!< (+) Height. */ + int x; + int y; + unsigned int w; + unsigned int h; }; -/** - * \brief Map object. - * - * The map object is used to move a player within the map according to the - * tilesets and collisions masks. - * - * By itself, a map does not know how to be loaded from a file and must be done - * from an helper like \ref map_file. - */ struct map { const char *title; /*!< (+) Map title name. */ unsigned int columns; /*!< (-) Number of columns. */ @@ -119,62 +93,24 @@ unsigned int margin_w; /*!< (+) Margin width. */ unsigned int margin_h; /*!< (+) Margin height. */ - /** - * Different tile layers. - */ + /* Different tile layers. */ struct map_layer layers[MAP_LAYER_TYPE_NUM]; }; CORE_BEGIN_DECLS -/** - * Initialize the map. - * - * This function will re-generate the terrain and center the view to the player - * position. - * - * \pre map != NULL - * \param map the map to initialize - */ -bool +int map_init(struct map *map); -/** - * Handle an event. - * - * \pre map != NULL - * \pre ev != NULL - * \param map the map - * \param ev the event to handle - */ void map_handle(struct map *map, const union event *ev); -/** - * Update the map. - * - * \pre map != NULL - * \param map the map - * \param ticks ellapsed milliseconds since last frame - */ void map_update(struct map *map, unsigned int ticks); -/** - * Render a map. - * - * \pre map != NULL - * \param map the map to render - */ void map_draw(const struct map *map); -/** - * Dispose map resources. - * - * \pre map != NULL - * \param map the map to close - */ void map_finish(struct map *map); diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/message.c --- a/libmlk-rpg/rpg/message.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/message.c Wed Mar 10 18:49:08 2021 +0100 @@ -49,7 +49,7 @@ message_handle(action->data, ev); } -static bool +static int update(struct action *action, unsigned int ticks) { assert(action); @@ -89,7 +89,7 @@ for (size_t i = 0; i < MESSAGE_LINES_MAX; ++i) { if (!msg->text[i]) continue; - if (!font_query(THEME(msg)->fonts[THEME_FONT_INTERFACE], msg->text[i], &w, NULL)) + if (font_query(THEME(msg)->fonts[THEME_FONT_INTERFACE], msg->text[i], &w, NULL) < 0) panic(); if (w > maxw) maxw = w; @@ -125,7 +125,7 @@ for (int i = 0; i < MESSAGE_LINES_MAX; ++i) { if (!msg->text[i]) continue; - if (!font_query(theme.fonts[THEME_FONT_INTERFACE], msg->text[i], &lw, &lh)) + if (font_query(theme.fonts[THEME_FONT_INTERFACE], msg->text[i], &lw, &lh) < 0) panic(); label.theme = &theme; @@ -216,7 +216,7 @@ } } -bool +int message_update(struct message *msg, unsigned int ticks) { assert(msg); @@ -278,7 +278,7 @@ return; } - if (!texture_new(&tex, msg->w, msg->h)) + if (texture_new(&tex, msg->w, msg->h) < 0) panic(); PAINTER_BEGIN(&tex); diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/message.h --- a/libmlk-rpg/rpg/message.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/message.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,63 +19,6 @@ #ifndef MOLKO_RPG_MESSAGE_H #define MOLKO_RPG_MESSAGE_H -/** - * \file message.h - * \brief Message dialog. - * \ingroup actions - * \ingroup drawing - * - * This module's purpose is to show a dialog box into the screen to show text - * and optionally ask the user a question. It is similar to what you're used to - * see in many RPGs. - * - * To use it use the following procedure: - * - * 1. Create a struct message object and set required properties, - * 2. Call \ref message_start to reset the state, - * 3. Call \ref message_handle and \ref message_update with appropriate values, - * 4. Call \ref message_draw to render the dialog. - * - * Depending on message flags or user input, step 3 may return true in this - * case you should stop using the message as it has completed rendering. - * - * \note All properties must exist until the object is no longer used. - * - * \code - * struct message msg = { - * // You can show up to 6 lines. - * .text = { - * "Hello, what's up?" - * }, - * // This indicates this message is a question. - * .flags = MESSAGE_FLAGS_QUESTION - * }; - * \endcode - * - * For performance reasons, flexibility and simplicity, the message box does - * not try to be clever about positions of lines. It will simply create an - * animation for opening the box, drawing the lines to the position according - * to the theme padding and spacing and interact with user. For convenience - * though, the \ref message_query can be used to determine dimensions required - * for a better final result. - * - * ## Example, computing the dimensions: - * - * \code - * // We create a message that we put on the center of the screen. - * struct message msg = { - * .text = { - * "Hi, have you tried turning it off and on again?" - * } - * }; - * - * message_query(&msg, &msg.w, &msg.h); - * align(ALIGN_CENTER, &msg.x, &msg.y, msg.w, msg.h, 0, 0, window.w, window.h); - * \endcode - */ - -#include - #include #include @@ -85,143 +28,61 @@ union event; -/** - * \brief Default animation speed in milliseconds. - */ #define MESSAGE_DELAY_DEFAULT (150) - -/** - * \brief Default timeout in milliseconds for automatic messages. - */ #define MESSAGE_TIMEOUT_DEFAULT (5000) - -/** - * \brief Maximum number of lines allowed in the message. - */ #define MESSAGE_LINES_MAX (3) -/** - * \brief Message flags. - */ enum message_flags { - MESSAGE_FLAGS_AUTOMATIC = (1 << 0), /*!< Will automatically change state by itself. */ - MESSAGE_FLAGS_QUESTION = (1 << 1), /*!< The message is a question. */ - MESSAGE_FLAGS_FADEIN = (1 << 2), /*!< Animate opening. */ - MESSAGE_FLAGS_FADEOUT = (1 << 3) /*!< Animate closing. */ + MESSAGE_FLAGS_AUTOMATIC = (1 << 0), + MESSAGE_FLAGS_QUESTION = (1 << 1), + MESSAGE_FLAGS_FADEIN = (1 << 2), + MESSAGE_FLAGS_FADEOUT = (1 << 3) }; -/** - * \brief Message state. - */ enum message_state { - MESSAGE_STATE_NONE, /*!< Message hasn't start yet or is finished */ - MESSAGE_STATE_OPENING, /*!< Message animation is opening */ - MESSAGE_STATE_SHOWING, /*!< Message is displaying */ - MESSAGE_STATE_HIDING /*!< Message animation for hiding */ + MESSAGE_STATE_NONE, + MESSAGE_STATE_OPENING, + MESSAGE_STATE_SHOWING, + MESSAGE_STATE_HIDING }; -/** - * \brief Message object. - */ struct message { - int x; /*!< (+) Position in x. */ - int y; /*!< (+) Position in y. */ - unsigned int w; /*!< (+) Width. */ - unsigned int h; /*!< (+) Height. */ - unsigned int spacing; /*!< (+) Spacing between lines. */ - unsigned int delay; /*!< (+) Delay for animations. */ - unsigned int timeout; /*!< (+) Timeout in milliseconds. */ - const char *text[MESSAGE_LINES_MAX]; /*!< (+) Lines of text to show. */ - unsigned int index; /*!< (+) Line selected */ - enum message_flags flags; /*!< (+) Message flags */ - enum message_state state; /*!< (-) Current state */ - const struct theme *theme; /*!< (+&?) Theme to use. */ - unsigned int elapsed; /*!< (-) Time elapsed. */ - double scale; /*!< (-) Current scale [0-1]. */ + int x; + int y; + unsigned int w; + unsigned int h; + unsigned int spacing; + unsigned int delay; + unsigned int timeout; + const char *text[MESSAGE_LINES_MAX]; + unsigned int index; + enum message_flags flags; + enum message_state state; + const struct theme *theme; + unsigned int elapsed; + double scale; }; CORE_BEGIN_DECLS -/** - * Start opening the message. This function will reset the message state and - * elapsed time. - * - * \pre msg != NULL - * \pre msg->delay > 0 if msg->flags contains MESSAGE_FLAGS_FADEIN or - * MESSAGE_FLAGS_FADEOUT - * \param msg the message - */ void message_start(struct message *msg); -/** - * Compute the minimal message dimensions required. - * - * \pre msg != NULL - * \param msg the message to query - * \param w the pointer to width (may be NULL) - * \param h the pointer to height (may be NULL) - */ void message_query(const struct message *msg, unsigned int *w, unsigned int *h); -/** - * Handle input events. - * - * This function will alter state of the message and change its selection in - * case of question. - * - * \pre msg != NULL - * \pre ev != NULL - * \param msg the message - * \param ev the event which occured - */ void message_handle(struct message *msg, const union event *ev); -/** - * Update the message state and elapsed time.. - * - * \pre msg != NULL - * \param msg the message - * \param ticks the elapsed delay since last frame - * \return true if it has finished - */ -bool +int message_update(struct message *msg, unsigned int ticks); -/** - * Draw the message into the screen. - * - * \pre msg != NULL - * \param msg the message - */ void message_draw(const struct message *msg); -/** - * Start hiding the message. - * - * \pre msg != NULL - * \param msg the message - * \note You should still continue to draw the message as the animation is not - * finished! - */ void message_hide(struct message *msg); -/** - * Convert message into an action. - * - * \pre msg != NULL - * \pre act != NULL - * \param msg the message to reference - * \param act the action to fill - * \post act->data contains msg - * \post act->handle invokes message_handle - * \post act->update invokes message_update - * \post act->draw invokes message_draw - */ void message_action(struct message *msg, struct action *act); diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/rpg.c --- a/libmlk-rpg/rpg/rpg.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/rpg.c Wed Mar 10 18:49:08 2021 +0100 @@ -21,14 +21,15 @@ #include "rpg.h" #include "rpg_p.h" -bool +int rpg_init(void) { #if defined(MOLKO_WITH_NLS) - translate_init("libmlk-rpg"); + if (translate_init("libmlk-rpg") < 0) + return -1; #endif - return true; + return 0; } void diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/rpg.h --- a/libmlk-rpg/rpg/rpg.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/rpg.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,28 +19,13 @@ #ifndef MOLKO_RPG_RPG_H #define MOLKO_RPG_RPG_H -/** - * \file rpg.h - * \brief librpg convenient header - */ - -#include - #include CORE_BEGIN_DECLS -/** - * Initialize the rpg library. - * - * \return False on errors. - */ -bool +int rpg_init(void); -/** - * Close the rpg library. - */ void rpg_finish(void); diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/save.c --- a/libmlk-rpg/rpg/save.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/save.c Wed Mar 10 18:49:08 2021 +0100 @@ -41,13 +41,13 @@ #define SQL_COMMIT "COMMIT" #define SQL_ROLLBACK "ROLLBACK" -static bool +static int exec(struct save *db, const char *sql) { if (sqlite3_exec(db->handle, sql, NULL, NULL, NULL) != SQLITE_OK) return errorf("%s", sqlite3_errmsg(db->handle)); - return true; + return 0; } static const char * @@ -56,13 +56,13 @@ return util_pathf("%s%u.db", sys_dir(SYS_DIR_SAVE), idx); } -static bool +static int execu(struct save *db, const unsigned char *sql) { return exec(db, (const char *)sql); } -static bool +static int verify(struct save *db) { struct { @@ -75,7 +75,7 @@ /* Ensure create and update dates are present. */ for (size_t i = 0; i < UTIL_SIZE(table); ++i) { - if (!save_get_property(db, &table[i].prop)) { + if (save_get_property(db, &table[i].prop) < 0) { sqlite3_close(db->handle); return errorf(_("database not initialized correctly")); } @@ -83,10 +83,10 @@ *table[i].date = strtoull(table[i].prop.value, NULL, 10); } - return true; + return 0; } -static bool +static int prepare(struct save *s, struct save_stmt *stmt, const char *sql, const char *args, va_list ap) { stmt->parent = s; @@ -100,15 +100,15 @@ case 'i': case 'u': if (sqlite3_bind_int(stmt->handle, i++, va_arg(ap, int)) != SQLITE_OK) - return false; + return -1; break; case 's': if (sqlite3_bind_text(stmt->handle, i++, va_arg(ap, const char *), -1, NULL) != SQLITE_OK) - return false; + return -1; break; case 't': if (sqlite3_bind_int64(stmt->handle, i++, va_arg(ap, time_t)) != SQLITE_OK) - return false; + return -1; break; case ' ': break; @@ -117,13 +117,13 @@ } } - return true; + return 0; sqlite3_err: return errorf("%s", sqlite3_errmsg(s->handle)); } -static bool +static int extract(struct save_stmt *stmt, const char *args, va_list ap) { const int ncols = sqlite3_column_count(stmt->handle); @@ -155,13 +155,13 @@ } } - return true; + return 0; sqlite3_err: return errorf("%s", sqlite3_errmsg(stmt->parent->handle)); } -bool +int save_open(struct save *db, unsigned int idx, enum save_mode mode) { assert(db); @@ -169,7 +169,7 @@ return save_open_path(db, path(idx), mode); } -bool +int save_open_path(struct save *db, const char *path, enum save_mode mode) { assert(db); @@ -189,7 +189,7 @@ if (sqlite3_open_v2(path, (sqlite3**)&db->handle, flags, NULL) != SQLITE_OK) goto sqlite3_err; - if (mode == SAVE_MODE_WRITE && !execu(db, sql_init)) + if (mode == SAVE_MODE_WRITE && execu(db, sql_init) < 0) goto sqlite3_err; return verify(db); @@ -200,10 +200,10 @@ memset(db, 0, sizeof (*db)); - return false; + return -1; } -bool +int save_ok(const struct save *db) { assert(db); @@ -211,7 +211,7 @@ return db && db->handle; } -bool +int save_set_property(struct save *db, const struct save_property *prop) { assert(db); @@ -219,8 +219,8 @@ sqlite3_stmt *stmt = NULL; - if (!exec(db, SQL_BEGIN)) - return false; + if (exec(db, SQL_BEGIN) < 0) + return -1; if (sqlite3_prepare(db->handle, (const char *)sql_property_set, -1, &stmt, NULL) != SQLITE_OK) goto sqlite3_err; if (sqlite3_bind_text(stmt, 1, prop->key, -1, NULL) != SQLITE_OK || @@ -241,17 +241,17 @@ exec(db, SQL_ROLLBACK); - return false; + return -1; } -bool +int save_get_property(struct save *db, struct save_property *prop) { assert(db); assert(prop); sqlite3_stmt *stmt = NULL; - bool ret = true; + int ret = 0; if (sqlite3_prepare(db->handle, (const char *)sql_property_get, sizeof (sql_property_get), &stmt, NULL) != SQLITE_OK) @@ -284,10 +284,10 @@ if (stmt) sqlite3_finalize(stmt); - return false; + return -1; } -bool +int save_remove_property(struct save *db, const struct save_property *prop) { assert(db); @@ -295,8 +295,8 @@ sqlite3_stmt *stmt = NULL; - if (!exec(db, SQL_BEGIN)) - return false; + if (exec(db, SQL_BEGIN) < 0) + return -1; if (sqlite3_prepare(db->handle, (const char *)sql_property_remove, sizeof (sql_property_remove), &stmt, NULL) != SQLITE_OK) goto sqlite3_err; @@ -317,25 +317,25 @@ exec(db, SQL_ROLLBACK); - return false; + return -1; } -bool +int save_exec(struct save *db, const char *sql, const char *args, ...) { assert(save_ok(db)); assert(sql && args); struct save_stmt stmt; - bool ret; + int ret; va_list ap; va_start(ap, args); ret = prepare(db, &stmt, sql, args, ap); va_end(ap); - if (!ret) - return false; + if (ret < 0) + return -1; ret = save_stmt_next(&stmt, NULL) == 0; save_stmt_finish(&stmt); @@ -354,7 +354,7 @@ memset(db, 0, sizeof (*db)); } -bool +int save_stmt_init(struct save *db, struct save_stmt *stmt, const char *sql, const char *args, ...) { assert(save_ok(db)); @@ -362,7 +362,7 @@ assert(args); va_list ap; - bool ret; + int ret; va_start(ap, args); ret = prepare(db, stmt, sql, args, ap); @@ -377,7 +377,7 @@ assert(stmt); va_list ap; - bool ret = -1; + int ret = -1; switch (sqlite3_step(stmt->handle)) { case SQLITE_ROW: diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/save.h --- a/libmlk-rpg/rpg/save.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/save.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,7 +19,6 @@ #ifndef MOLKO_RPG_SAVE_H #define MOLKO_RPG_SAVE_H -#include #include #include @@ -50,39 +49,39 @@ CORE_BEGIN_DECLS -bool -save_open(struct save *db, unsigned int idx, enum save_mode mode); +int +save_open(struct save *, unsigned int, enum save_mode); -bool -save_open_path(struct save *db, const char *path, enum save_mode mode); +int +save_open_path(struct save *, const char *, enum save_mode); -bool -save_ok(const struct save *db); +int +save_ok(const struct save *); -bool -save_set_property(struct save *db, const struct save_property *prop); +int +save_set_property(struct save *, const struct save_property *); -bool -save_get_property(struct save *db, struct save_property *prop); +int +save_get_property(struct save *, struct save_property *); -bool -save_remove_property(struct save *db, const struct save_property *prop); +int +save_remove_property(struct save *, const struct save_property *); -bool -save_exec(struct save *db, const char *sql, const char *args, ...); +int +save_exec(struct save *, const char *, const char *, ...); void -save_finish(struct save *db); +save_finish(struct save *); /* Prepared statements. */ -bool -save_stmt_init(struct save *db, struct save_stmt *stmt, const char *sql, const char *args, ...); +int +save_stmt_init(struct save *, struct save_stmt *, const char *, const char *, ...); int -save_stmt_next(struct save_stmt *stmt, const char *args, ...); +save_stmt_next(struct save_stmt *, const char *, ...); void -save_stmt_finish(struct save_stmt *stmt); +save_stmt_finish(struct save_stmt *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/spell.h --- a/libmlk-rpg/rpg/spell.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/spell.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,11 +19,6 @@ #ifndef MOLKO_RPG_SPELL_H #define MOLKO_RPG_SPELL_H -/** - * \file spell.h - * \brief Magic spells. - */ - #include #include "selection.h" @@ -59,13 +54,13 @@ CORE_BEGIN_DECLS void -spell_select(const struct spell *s, const struct battle *bt, struct selection *slt); +spell_select(const struct spell *, const struct battle *, struct selection *); void -spell_action(const struct spell *s, struct battle *bt, struct character *owner, const struct selection *slt); +spell_action(const struct spell *, struct battle *, struct character *, const struct selection *); void -spell_use(struct spell *s, struct character *owner, const struct selection *slt); +spell_use(struct spell *, struct character *, const struct selection *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/tileset-file.c --- a/libmlk-rpg/rpg/tileset-file.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/tileset-file.c Wed Mar 10 18:49:08 2021 +0100 @@ -126,25 +126,25 @@ return 0; } -static bool +static int parse_tilewidth(struct context *ctx, const char *line) { if (sscanf(line, "tilewidth|%u", &ctx->tilewidth) != 1 || ctx->tilewidth == 0) return errorf(_("tilewidth is null")); - return true; + return 0; } -static bool +static int parse_tileheight(struct context *ctx, const char *line) { if (sscanf(line, "tileheight|%u", &ctx->tileheight) != 1 || ctx->tileheight == 0) return errorf(_("tileheight is null")); - return true; + return 0; } -static bool +static int parse_tiledefs(struct context *ctx, const char *line) { (void)line; @@ -153,12 +153,12 @@ unsigned short id, w, h; struct tileset_tiledef *td; - if (!alloc_pool_init(&ctx->tf->tiledefs, sizeof (*td), NULL)) - return false; + if (alloc_pool_init(&ctx->tf->tiledefs, sizeof (*td), NULL) < 0) + return -1; while (fscanf(ctx->fp, "%hu|%hd|%hd|%hu|%hu\n", &id, &x, &y, &w, &h) == 5) { if (!(td = alloc_pool_new(&ctx->tf->tiledefs))) - return false; + return -1; td->id = id; td->x = x; @@ -172,10 +172,10 @@ ctx->tileset->tiledefs = ctx->tf->tiledefs.data; ctx->tileset->tiledefsz = ctx->tf->tiledefs.size; - return true; + return 0; } -static bool +static int parse_animations(struct context *ctx, const char *line) { (void)line; @@ -184,9 +184,9 @@ unsigned int delay; char filename[FILENAME_MAX + 1]; - if (!alloc_pool_init(&ctx->tf->anims[0], sizeof (struct tileset_animation_block), tileset_animation_block_finish) || - !alloc_pool_init(&ctx->tf->anims[1], sizeof (struct tileset_animation), NULL)) - return false; + if (alloc_pool_init(&ctx->tf->anims[0], sizeof (struct tileset_animation_block), tileset_animation_block_finish) < 0 || + alloc_pool_init(&ctx->tf->anims[1], sizeof (struct tileset_animation), NULL) < 0) + return -1; /* * 1. Create the first array of animation, sprite and texture that are @@ -196,9 +196,9 @@ struct tileset_animation_block *anim; if (!(anim = alloc_pool_new(&ctx->tf->anims[0]))) - return false; - if (!image_open(&anim->texture, util_pathf("%s/%s", ctx->basedir, filename))) - return false; + return -1; + if (image_open(&anim->texture, util_pathf("%s/%s", ctx->basedir, filename)) < 0) + return -1; sprite_init(&anim->sprite, &anim->texture, ctx->tilewidth, ctx->tileheight); animation_init(&anim->animation, &anim->sprite, delay); @@ -213,7 +213,7 @@ struct tileset_animation *ta; if (!(ta = alloc_pool_new(&ctx->tf->anims[1]))) - return false; + return -1; ta->id = id; ta->animation = &anim->animation; @@ -227,10 +227,10 @@ ctx->tileset->anims = ctx->tf->anims[1].data; ctx->tileset->animsz = ctx->tf->anims[1].size; - return true; + return 0; } -static bool +static int parse_image(struct context *ctx, const char *line) { char *p; @@ -240,21 +240,21 @@ if (!(p = strchr(line, '|'))) return errorf(_("could not parse image")); - if (!image_open(&ctx->tf->image, util_pathf("%s/%s", ctx->basedir, p + 1))) - return false; + if (image_open(&ctx->tf->image, util_pathf("%s/%s", ctx->basedir, p + 1)) < 0) + return -1; sprite_init(&ctx->tf->sprite, &ctx->tf->image, ctx->tilewidth, ctx->tileheight); ctx->tileset->sprite = &ctx->tf->sprite; - return true; + return 0; } -static bool +static int parse_line(struct context *ctx, const char *line) { static const struct { const char *property; - bool (*read)(struct context *, const char *); + int (*read)(struct context *, const char *); } props[] = { { "tilewidth", parse_tilewidth }, { "tileheight", parse_tileheight }, @@ -268,10 +268,10 @@ return props[i].read(ctx, line); } - return true; + return 0; } -static bool +static int parse(struct context *ctx, const char *path) { char line[1024]; @@ -284,23 +284,23 @@ /* Remove \n if any */ line[strcspn(line, "\n")] = '\0'; - if (!parse_line(ctx, line)) - return false; + if (parse_line(ctx, line) < 0) + return -1; } - return true; + return 0; } -static bool +static int check(const struct tileset *tileset) { if (!tileset->sprite) return errorf(_("missing tileset image")); - return true; + return 0; } -bool +int tileset_file_open(struct tileset_file *tf, struct tileset *tileset, const char *path) { assert(tf); @@ -312,7 +312,7 @@ .tileset = tileset }; struct zfile zf; - bool ret = true; + int ret = 0; memset(tileset, 0, sizeof (*tileset)); @@ -321,7 +321,7 @@ ctx.fp = zf.fp; - if (!(ret = parse(&ctx, path)) || !(ret = check(tileset))) + if ((ret = parse(&ctx, path)) < 0 || (ret = check(tileset)) < 0) tileset_file_finish(tf); zfile_close(&zf); diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/tileset-file.h --- a/libmlk-rpg/rpg/tileset-file.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/tileset-file.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,12 +19,6 @@ #ifndef MOLKO_RPG_TILESET_FILE_H #define MOLKO_RPG_TILESET_FILE_H -/** - * \file tileset-file.h - * \brief Tileset file loader. - */ - -#include #include #include @@ -35,51 +29,20 @@ struct tileset; struct tileset_tiledef; -/** - * \brief Context for loading tileset from files - * - * This structure own animations, tile definitions and sprites that are - * associated with the tileset. By this mean, the structure must be kept until - * the tileset is no longer used. - * - * Structure members should not be modified directly but only one exposed in - * the final tileset destination. - */ struct tileset_file { - struct alloc_pool tiledefs; /*!< (*) Tile definitions. */ - struct alloc_pool anims[2]; /*!< (*) Animations data. */ - struct texture image; /*!< (*) Image file. */ - struct sprite sprite; /*!< (*) Sprite. */ + struct alloc_pool tiledefs; + struct alloc_pool anims[2]; + struct texture image; + struct sprite sprite; }; CORE_BEGIN_DECLS -/** - * Try to load a tileset from a file. - * - * This function will load the tileset file along with optional animations in - * the same directory. - * - * \pre tf != NULL - * \pre tileset != NULL - * \pre path != NULL - * \param tf the context file - * \param tileset the destination tileset - * \param path path to the tileset - * \return False on errors. - */ -bool -tileset_file_open(struct tileset_file *tf, struct tileset *tileset, const char *path); +int +tileset_file_open(struct tileset_file *, struct tileset *, const char *); -/** - * Close all resources allocated from the tileset file context. - * - * \warning The tileset that was created must not be used anymore. - * \pre tf != NULL - * \param tf the tileset to clear - */ void -tileset_file_finish(struct tileset_file *tf); +tileset_file_finish(struct tileset_file *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/tileset.c --- a/libmlk-rpg/rpg/tileset.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/tileset.c Wed Mar 10 18:49:08 2021 +0100 @@ -48,7 +48,7 @@ return bsearch(&key, ts->anims, ts->animsz, sizeof (key), anim_cmp); } -bool +int tileset_ok(const struct tileset *ts) { return ts && sprite_ok(ts->sprite); diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/tileset.h --- a/libmlk-rpg/rpg/tileset.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/tileset.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,101 +19,46 @@ #ifndef MOLKO_RPG_TILESET_H #define MOLKO_RPG_TILESET_H -#include #include #include struct sprite; -/** - * \brief Describe a tile property in a tileset. - * - * It can contains an animation and a collision mask. - */ struct tileset_tiledef { - unsigned short id; /*!< (+) Tile index. */ - short x; /*!< (+) Collision region starts in y. */ - short y; /*!< (+) Collision region starts in y. */ - unsigned short w; /*!< (+) Collision width. */ - unsigned short h; /*!< (+) Collision height. */ + unsigned short id; + short x; + short y; + unsigned short w; + unsigned short h; }; -/** - * \brief Per tile animation. - * - * This structure is used to animate tiles by id. Create one for every tile - * that must be animated. - */ struct tileset_animation { - unsigned short id; /*!< (*) Tile index. */ - struct animation *animation; /*!< (+&?) Animation. */ + unsigned short id; + struct animation *animation; }; -/** - * \brief Tileset definition. - */ struct tileset { - struct tileset_tiledef *tiledefs; /*!< (+&?) Per tile properties (must be sorted by id). */ - size_t tiledefsz; /*!< (+) Number of tile properties. */ - struct tileset_animation *anims; /*!< (+&?) Per tile animations (must be sorted by id). */ - size_t animsz; /*!< (+) Number of tile animations. */ - struct sprite *sprite; /*!< (+&) Sprite to generate the terrain. */ + struct tileset_tiledef *tiledefs; + size_t tiledefsz; + struct tileset_animation *anims; + size_t animsz; + struct sprite *sprite; }; CORE_BEGIN_DECLS -/** - * Tells if the tileset is correctly initialized. - * - * \param ts the tileset to check (maybe NULL) - * \return True if correctly initialized. - */ -bool -tileset_ok(const struct tileset *ts); +int +tileset_ok(const struct tileset *); -/** - * Prepare the tileset before use. - * - * You must call this function once before using it in the rendering of the map - * because it will prepare animations. - * - * \pre ts != NULL - * \param ts the tileset to prepare - */ void -tileset_start(struct tileset *ts); +tileset_start(struct tileset *); -/** - * Update tileset. - * - * This function will update tileset animations. It is not necessary to call it - * if the tileset does not contain any animation. - * - * \pre ts != NULL - * \param ts the tileset to update - * \param ticks the elapsed milliseconds since last frame - */ void -tileset_update(struct tileset *ts, unsigned int ticks); +tileset_update(struct tileset *, unsigned int); -/** - * Draw a tileset cell at the given position. - * - * If the tileset at the given row, column is animated its animation will be - * rendered otherwise it uses the sprite row column. - * - * The argument r and c must not be out of bounds. - * - * \pre ts != NULL - * \param ts the tileset to use - * \param r the row number - * \param c the column number - * \param x the x coordinate - * \param y the y coordinate - */ void -tileset_draw(const struct tileset *ts, unsigned int r, unsigned int c, int x, int y); +tileset_draw(const struct tileset *, unsigned int, unsigned int, int, int); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-rpg/rpg/walksprite.h --- a/libmlk-rpg/rpg/walksprite.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-rpg/rpg/walksprite.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,12 +19,6 @@ #ifndef MOLKO_RPG_WALKSPRITE_H #define MOLKO_RPG_WALKSPRITE_H -/** - * \file walksprite.h - * \brief Sprite designed for walking entities. - * \ingroup drawing - */ - #include struct sprite; @@ -60,58 +54,25 @@ * ``` */ struct walksprite { - struct sprite *sprite; /*!< (+&) The sprite to use */ - unsigned int delay; /*!< (+) The delay between frames */ - unsigned int index; /*!< (-) Current column index */ - unsigned int elapsed; /*!< (-) Elapsed time since last frame */ + struct sprite *sprite; + unsigned int delay; + unsigned int index; + unsigned int elapsed; }; CORE_BEGIN_DECLS -/** - * Initialize the walking sprite. - * - * \pre ws != NULL - * \pre sprite != NULL - * \param ws the walking sprite - * \param sprite the sprite to use - * \param delay the delay between sprites - */ void -walksprite_init(struct walksprite *ws, struct sprite *sprite, unsigned int delay); +walksprite_init(struct walksprite *, struct sprite *, unsigned int); -/** - * Reset current column to inactive (aka no longer walking). - * - * \pre ws != NULL - * \param ws the walking sprite - */ void -walksprite_reset(struct walksprite *ws); +walksprite_reset(struct walksprite *); -/** - * Update the walking sprite - * - * \pre ws != NULL - * \param ws the walking sprite - * \param ticks the number of milliseconds between last frame - */ void -walksprite_update(struct walksprite *ws, unsigned int ticks); +walksprite_update(struct walksprite *, unsigned int); -/** - * Draw the appropriate sprite cell to the screen according to the orientation - * given. - * - * \pre ws != NULL - * \pre orientation < 8 - * \param ws the walking sprite - * \param orientation the orientation (or the row between 0 and 7) - * \param x the x coordinate - * \param y the y coordinate - */ void -walksprite_draw(const struct walksprite *ws, unsigned int orientation, int x, int y); +walksprite_draw(const struct walksprite *, unsigned int, int, int); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/align.h --- a/libmlk-ui/ui/align.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/align.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,89 +19,33 @@ #ifndef MOLKO_UI_ALIGN_H #define MOLKO_UI_ALIGN_H -/** - * \file align.h - * \brief User interface alignment. - */ - #include -/** - * \brief Label alignment in bounding box. - * - * The alignment is described as following: - * - * ``` - * +---------------------+ - * | 2 3 4 | - * | | - * | 9 1 5 | - * | | - * | 8 7 6 | - * +---------------------+ - * ``` - * - * The default value of 0 (LABEL_ALIGN_NONE) means the alignment isn't used. - */ enum align { - ALIGN_NONE, /*!< No alignment. */ - ALIGN_CENTER, /*!< Align to the center. */ - ALIGN_TOP_LEFT, /*!< Top left. */ - ALIGN_TOP, /*!< Top center (aligned horizontally). */ - ALIGN_TOP_RIGHT, /*!< Top right. */ - ALIGN_RIGHT, /*!< Right (aligned vertically). */ - ALIGN_BOTTOM_RIGHT, /*!< Bottom right. */ - ALIGN_BOTTOM, /*!< Bottom (aligned horizontally). */ - ALIGN_BOTTOM_LEFT, /*!< Bottom left. */ - ALIGN_LEFT /*!< Left (aligned vertically). */ + ALIGN_NONE, + ALIGN_CENTER, + ALIGN_TOP_LEFT, + ALIGN_TOP, + ALIGN_TOP_RIGHT, + ALIGN_RIGHT, + ALIGN_BOTTOM_RIGHT, + ALIGN_BOTTOM, + ALIGN_BOTTOM_LEFT, + ALIGN_LEFT }; CORE_BEGIN_DECLS -/** - * Align the given object relative to its parent region. - * - * The arguments are described as following: - * - * ``` - * Example of ALIGN_LEFT (centered vertically but placed on the left.) - * - * px, py - * +----------pw----------+ - * | | - * | x, y | - * | +---w---+ | - * ph h | | - * | +-------+ | - * | | - * | | - * +----------------------+ - * ``` - * - * As a convenience, x and y are left untouched if align is ALIGN_NONE which - * means you can set the coordinates to default values and still call the align - * function without need to check. - * - * \param align the desired alignment - * \param x the pointer to x coordinate to modify (may be NULL) - * \param y the pointer yo y coordinate to modify (may be NULL) - * \param w the object width - * \param h the object height - * \param px the parent region start - * \param py the parent region start - * \param pw the parent region width - * \param ph the parent region height - */ void -align(enum align align, - int *x, - int *y, - unsigned int w, - unsigned int h, - int px, - int py, - unsigned int pw, - unsigned int ph); +align(enum align, + int *, + int *, + unsigned int, + unsigned int, + int, + int, + unsigned int, + unsigned int); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/button.c --- a/libmlk-ui/ui/button.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/button.c Wed Mar 10 18:49:08 2021 +0100 @@ -31,7 +31,7 @@ #include "theme.h" #include "ui_p.h" -static bool +static int is_boxed(const struct button *button, const struct event_click *click) { assert(button); diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/button.h --- a/libmlk-ui/ui/button.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/button.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,12 +19,6 @@ #ifndef MOLKO_UI_BUTTON_H #define MOLKO_UI_BUTTON_H -/** - * \file button.h - * \brief GUI button. - * \ingroup ui - */ - #include union event; @@ -32,94 +26,38 @@ struct action; struct theme; -/** - * \brief Button state. - */ enum button_state { - BUTTON_STATE_NONE, /*!< Button is inactive. */ - BUTTON_STATE_PRESSED, /*!< Button is currently pressed. */ - BUTTON_STATE_ACTIVATED /*!< Button is considered activated. */ + BUTTON_STATE_NONE, + BUTTON_STATE_PRESSED, + BUTTON_STATE_ACTIVATED }; -/** - * \brief GUI button. - */ struct button { - int x; /*!< (+) Position in x. */ - int y; /*!< (+) Position in y. */ - unsigned int w; /*!< (+) Width. */ - unsigned int h; /*!< (+) Height. */ - const char *text; /*!< (+&) Text to draw. */ - enum button_state state; /*!< (+) Button state. */ - const struct theme *theme; /*!< (+&?) Theme to use. */ + int x; + int y; + unsigned int w; + unsigned int h; + const char *text; + enum button_state state; + const struct theme *theme; }; CORE_BEGIN_DECLS -/** - * Handle the event. - * - * You should always call this function even if the event is completely - * unrelated. - * - * \pre button != NULL - * \pre ev != NULL - * \param button the button - * \param ev the event - */ void -button_handle(struct button *button, const union event *ev); +button_handle(struct button *, const union event *); -/** - * Use this function once the button has been considered activated. - * - * \pre button != NULL - * \param button the button - */ void -button_reset(struct button *button); +button_reset(struct button *); -/** - * Default drawing function. - * - * \pre t != NULL - * \pre frame != NULL - * \param t the theme - * \param button the button - */ void -button_draw_default(const struct theme *t, const struct button *button); - -/** - * Draw the button. - * - * \pre button != NULL - * \param button the button - */ -void -button_draw(const struct button *button); +button_draw_default(const struct theme *, const struct button *); -/** - * Convert the button into an action. - * - * The following field will be set into the action: - * - * - act->data: points to button (reference), - * - act->handle: a wrapper to button_handle, - * - act->draw: a wrapper to button_draw. - * - * The button being an UI element is considered to never completes, as such - * you will need to handle this case or to use a custom update function. - * - * \note You will still need to check the button state and reset it at some - * point. - * \pre button != NULL - * \pre act != NULL - * \param button the button to reference - * \param act the action to fill - */ void -button_action(struct button *button, struct action *act); +button_draw(const struct button *); + +void +button_action(struct button *, struct action *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/checkbox.c --- a/libmlk-ui/ui/checkbox.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/checkbox.c Wed Mar 10 18:49:08 2021 +0100 @@ -28,7 +28,7 @@ #include "checkbox.h" #include "theme.h" -static bool +static int is_boxed(const struct checkbox *cb, const struct event_click *click) { assert(cb); diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/checkbox.h --- a/libmlk-ui/ui/checkbox.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/checkbox.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,14 +19,6 @@ #ifndef MOLKO_UI_CHECKBOX_H #define MOLKO_UI_CHECKBOX_H -/** - * \file checkbox.h - * \brief GUI checkbox. - * \ingroup ui - */ - -#include - #include union event; @@ -34,72 +26,28 @@ struct action; struct theme; -/** - * \brief GUI checkbox. - */ struct checkbox { - int x; /*!< (+) Position in x. */ - int y; /*!< (+) Position in y. */ - unsigned int w; /*!< (+) Width. */ - unsigned int h; /*!< (+) Height. */ - bool checked; /*!< (+) Is activated? */ - const struct theme *theme; /*!< (+&?) Theme to use. */ + int x; + int y; + unsigned int w; + unsigned int h; + int checked; + const struct theme *theme; }; CORE_BEGIN_DECLS -/** - * Default drawing function. - * - * \pre t != NULL - * \pre cb != NULL - * \param t the theme - * \param cb the checkbox - */ void -checkbox_draw_default(const struct theme *t, const struct checkbox *cb); +checkbox_draw_default(const struct theme *, const struct checkbox *); -/** - * Draw the checkbox. - * - * \pre cb != NULL - * \pre ev != NULL - * \param cb the checkbox - * \param ev the event - */ void -checkbox_handle(struct checkbox *cb, const union event *ev); +checkbox_handle(struct checkbox *, const union event *); -/** - * Draw the checkbox. - * - * \pre cb != NULL - * \param cb the checkbox - */ void -checkbox_draw(const struct checkbox *cb); +checkbox_draw(const struct checkbox *); -/** - * Convert the checkbox into an action. - * - * The following field will be set into the action: - * - * - act->data: points to cb (reference), - * - act->handle: a wrapper to checkbox_handle, - * - act->draw: a wrapper to checkbox_draw. - * - * The checkbox being an UI element is considered to never completes, as such - * you will need to handle this case or to use a custom update function. - * - * \note You will still need to check the checkbox state and reset it at some - * point. - * \pre cb != NULL - * \pre act != NULL - * \param cb the checkbox to reference - * \param act the action to fill - */ void -checkbox_action(struct checkbox *cb, struct action *act); +checkbox_action(struct checkbox *, struct action *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/debug.c --- a/libmlk-ui/ui/debug.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/debug.c Wed Mar 10 18:49:08 2021 +0100 @@ -26,7 +26,7 @@ struct debug_options debug_options = { #if !defined(NDEBUG) - .enable = true + .enable = 1 #endif }; @@ -66,7 +66,7 @@ theme = report->theme ? report->theme : theme_default(); font = theme->fonts[THEME_FONT_DEBUG]; - if (!font_render(font, &tex, line, theme->colors[THEME_COLOR_DEBUG])) + if (font_render(font, &tex, line, theme->colors[THEME_COLOR_DEBUG]) < 0) return; x = theme->padding; diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/debug.h --- a/libmlk-ui/ui/debug.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/debug.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,87 +19,34 @@ #ifndef MOLKO_UI_DEBUG_H #define MOLKO_UI_DEBUG_H -/** - * \file debug.h - * \brief Debugging interfaces. - * - * This module provides functions to draw debugging information within the game - * window. It is mostly used for information only when state of the game is - * better inspected via direct window information rather than writing in the - * console. - * - * Predefined core states may print debugging information if - * debug_options.enabled variable is set to true. However, you need to specify - * the font to use in order to work. - * - * Each call to \ref debugf or \ref vdebugf automatically adjust - * next coordinate for rendering the text. As such, user may simply print - * several lines of text without having to deal with that manually. - */ - -#include #include #include #include -/** - * Maximum content length per report. - */ #define DEBUG_LINE_MAX 1024 struct theme; -/** - * \brief Debugging options. - * - * Fill this structure with appropriate values to change debugging behavior - * in core API. - */ struct debug_options { - bool enable; /*!< (+) Enable core API debugging. */ + int enable; }; -/** - * \brief Debug context. - * - * Use this structure each time you need to print one or more messages. - */ struct debug_report { - const struct theme *theme; /*!< (+&?) Theme to use. */ - unsigned int count; /*!< (-) Number of messages already printed. */ + const struct theme *theme; + unsigned int count; }; CORE_BEGIN_DECLS -/** - * Global debugging options. - */ extern struct debug_options debug_options; -/** - * Print debugging information into the screen. - * - * \pre report != NULL - * \pre fmt != NULL - * \param report the reporting context - * \param fmt the printf(3) format string - * \note The message length must not exceed DEBUG_LINE_MAX, otherwise its - * result is truncated. - */ void -debugf(struct debug_report *report, const char *fmt, ...); +debugf(struct debug_report *, const char *, ...); + -/** - * Similar to \ref debugf with a va_list arguments pointer. - * - * \pre fmt != NULL - * \param report the reporting context - * \param fmt the printf(3) format string - * \param ap the argument list - */ void -vdebugf(struct debug_report *report, const char *fmt, va_list ap); +vdebugf(struct debug_report *, const char *, va_list); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/frame.h --- a/libmlk-ui/ui/frame.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/frame.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,77 +19,35 @@ #ifndef MOLKO_UI_FRAME_H #define MOLKO_UI_FRAME_H -/** - * \file frame.h - * \brief GUI frame. - * \ingroup ui - */ - #include struct action; struct theme; -/** - * \brief Frame style. - */ enum frame_style { FRAME_STYLE_NORMAL, FRAME_STYLE_BOX }; -/** - * \brief GUI frame. - */ struct frame { - int x; /*!< (+) Position in x. */ - int y; /*!< (+) Position in y. */ - unsigned int w; /*!< (+) Width. */ - unsigned int h; /*!< (+) Height. */ - enum frame_style style; /*!< (+) Frame style. */ - const struct theme *theme; /*!< (+&?) Theme to use. */ + int x; + int y; + unsigned int w; + unsigned int h; + enum frame_style style; + const struct theme *theme; }; CORE_BEGIN_DECLS -/** - * Default drawing function. - * - * \pre t != NULL - * \pre frame != NULL - * \param t the theme - * \param frame the frame - */ void -frame_draw_default(const struct theme *t, const struct frame *frame); +frame_draw_default(const struct theme *, const struct frame *); -/** - * Draw the frame. - * - * \pre frame != NULL - * \param frame the frame to draw - */ void -frame_draw(const struct frame *frame); +frame_draw(const struct frame *); -/** - * Convert the frame into an action. - * - * The following field will be set into the action: - * - * - act->data: points to frame (reference), - * - act->draw: a wrapper to checkbox_draw. - * - * The frame being an UI element is considered to never completes, as such - * you will need to handle this case or to use a custom update function. - * - * \pre frame != NULL - * \pre act != NULL - * \param frame the frame to reference - * \param act the action to fill - */ void -frame_action(struct frame *frame, struct action *act); +frame_action(struct frame *, struct action *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/gridmenu.c --- a/libmlk-ui/ui/gridmenu.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/gridmenu.c Wed Mar 10 18:49:08 2021 +0100 @@ -146,7 +146,7 @@ { struct texture *tex = &menu->tex.texture; - if (!texture_ok(tex) && !texture_new(tex, menu->w, menu->tex.relh)) + if (!texture_ok(tex) && texture_new(tex, menu->w, menu->tex.relh) < 0) panic(); PAINTER_BEGIN(tex); diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/gridmenu.h --- a/libmlk-ui/ui/gridmenu.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/gridmenu.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,11 +19,6 @@ #ifndef MOLKO_UI_GRIDMENU_H #define MOLKO_UI_GRIDMENU_H -/** - * \file gridmenu.h - * \brief GUI grid menu. - */ - #include #include @@ -31,146 +26,58 @@ #include "label.h" -/** - * \brief Maximum number of entries. - */ #define GRIDMENU_ENTRY_MAX (256) struct theme; union event; -/** - * \brief Grid menu state. - */ enum gridmenu_state { - GRIDMENU_STATE_NONE, /*!< No state yet. */ - GRIDMENU_STATE_ACTIVATED /*!< An entry has been selected. */ + GRIDMENU_STATE_NONE, + GRIDMENU_STATE_ACTIVATED }; -/** - * \brief Internal texture representation. - * - * This structure contain several information for rendering the underlying grid - * into the screen. - */ struct gridmenu_texture { - int rely; /*!< (-) View start in y. */ - unsigned int relh; /*!< (-) Real texture height. */ - unsigned int eltw; /*!< (-) Maximum label width */ - unsigned int elth; /*!< (-) Maximum label height. */ - unsigned int spacev; /*!< (-) Vertical space between labels. */ - unsigned int spaceh; /*!< (-) Horizontal space between labels. */ - struct texture texture; /*!< (*) The texture itself. */ - - /** - * (-) The list of labels. - */ + int rely; + unsigned int relh; + unsigned int eltw; + unsigned int elth; + unsigned int spacev; + unsigned int spaceh; + struct texture texture; struct label labels[GRIDMENU_ENTRY_MAX]; }; -/** - * \brief Grid menu for selecting items. - * - * This menu offers a grid where user can specify a maximum number of columns to - * show entries. Content is automatically paginated vertically according to the - * current selection and the menu's length. - * - * It uses \ref frame.h and \ref label.h to draw elements so you may change the - * referenced theme if you want a different style. - * - * This module being a bit complex uses internal data for rendering that is - * repainted in case of event (when using \ref gridmenu_handle) but if you do - * modify the menu, you'll have to call \ref gridmenu_repaint yourself and you - * need to call it at least once before drawing. - */ struct gridmenu { - int x; /*!< (+) Position in x. */ - int y; /*!< (+) Position in y. */ - unsigned int w; /*!< (+) Width. */ - unsigned int h; /*!< (+) Height. */ - enum gridmenu_state state; /*!< (+) Menu state. */ - size_t selected; /*!< (+) User selection. */ - const struct theme *theme; /*!< (+&?) Optional theme to use. */ - - /** - * (+&?) List of entries to show. - */ + int x; + int y; + unsigned int w; + unsigned int h; + enum gridmenu_state state; + size_t selected; + const struct theme *theme; const char *menu[GRIDMENU_ENTRY_MAX]; - - /** - * (+) Number of rows allowed per page. - */ unsigned int nrows; - - /** - * (+) Number of columns allowed per page. - * - * \warning You must make sure to use a number of columns that can fit - * GRIDMENU_ENTRY_MAX, in other terms - * `GRIDMENU_ENTRY_MAX % ncols == 0` - */ unsigned int ncols; - - /** - * (*) Internal grid menu texture. - */ struct gridmenu_texture tex; }; CORE_BEGIN_DECLS -/** - * Reset the menu->state flag. - * - * \pre menu != NULL - * \param menu the menu to reset - */ void -gridmenu_reset(struct gridmenu *menu); +gridmenu_reset(struct gridmenu *); -/** - * Rebuild internal texture for rendering. - * - * \pre menu != NULL - * \pre GRIDMENU_ENTRY_MAX % menu->ncols == 0 - * \param menu the menu to repaint - */ void -gridmenu_repaint(struct gridmenu *menu); +gridmenu_repaint(struct gridmenu *); -/** - * Handle an event in the menu. - * - * Mouse click will test the coordinate of the mouse to check if the pointer is - * on a menu item region but keyboard events aren't so make sure to have user - * "focus" prior to calling this function. - * - * \pre menu != NULL - * \pre ev != NULL - * \param menu the menu to use - * \param ev the event - */ void -gridmenu_handle(struct gridmenu *menu, const union event *ev); +gridmenu_handle(struct gridmenu *, const union event *); -/** - * Draw the menu. - * - * \pre menu != NULL && menu->nrows > 0 && menu->ncols > 0 - * \param menu the menu to draw - */ void -gridmenu_draw(const struct gridmenu *menu); +gridmenu_draw(const struct gridmenu *); -/** - * Close internal resources. - * - * \pre menu != NULL - * \param menu the menu to close - */ void -gridmenu_finish(struct gridmenu *menu); +gridmenu_finish(struct gridmenu *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/label.c --- a/libmlk-ui/ui/label.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/label.c Wed Mar 10 18:49:08 2021 +0100 @@ -46,7 +46,7 @@ /* Shadow text, only if enabled. */ if (label->flags & LABEL_FLAGS_SHADOW) { - if (!font_render(font, &tex, label->text, t->colors[THEME_COLOR_SHADOW])) + if (font_render(font, &tex, label->text, t->colors[THEME_COLOR_SHADOW]) < 0) panic(); texture_draw(&tex, label->x + 1, label->y + 1); @@ -54,14 +54,14 @@ } /* Normal text. */ - if (!font_render(font, &tex, label->text, t->colors[THEME_COLOR_NORMAL])) + if (font_render(font, &tex, label->text, t->colors[THEME_COLOR_NORMAL]) < 0) panic(); texture_draw(&tex, label->x, label->y); texture_finish(&tex); } -bool +int label_ok(const struct label *label) { return label && label->text && strlen(label->text) > 0; @@ -75,7 +75,7 @@ const struct theme *t = label->theme ? label->theme : theme_default(); - if (!font_query(t->fonts[THEME_FONT_INTERFACE], label->text, w, h)) + if (font_query(t->fonts[THEME_FONT_INTERFACE], label->text, w, h) < 0) panic(); } diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/label.h --- a/libmlk-ui/ui/label.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/label.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,99 +19,40 @@ #ifndef MOLKO_UI_LABEL_H #define MOLKO_UI_LABEL_H -/** - * \file label.h - * \brief GUI label. - * \ingroup ui - */ - -#include - #include struct action; struct theme; -/** - * \brief Label flags. - */ enum label_flags { - LABEL_FLAGS_NONE, /*!< No flags. */ - LABEL_FLAGS_SHADOW = (1 << 0), /*!< Enable shadow. */ + LABEL_FLAGS_NONE, + LABEL_FLAGS_SHADOW = (1 << 0), }; -/** - * \brief GUI label. - */ struct label { - int x; /*!< (+) Position in x. */ - int y; /*!< (+) Position in y. */ - const char *text; /*!< (+&) Text to show. */ - enum label_flags flags; /*!< (+) Optional flags. */ - const struct theme *theme; /*!< (+&?) Theme to use. */ + int x; + int y; + const char *text; + enum label_flags flags; + const struct theme *theme; }; CORE_BEGIN_DECLS -/** - * Default drawing function. - * - * \pre t != NULL - * \pre label != NULL - * \param t the theme - * \param label the label - */ void -label_draw_default(const struct theme *t, const struct label *label); +label_draw_default(const struct theme *, const struct label *); -/** - * Tells if the label is usable. - * - * \param label the label to check (may be NULL) - * \return False if label is null or as empty text. - */ -bool -label_ok(const struct label *label); +int +label_ok(const struct label *); -/** - * Update the `w` and `h` fields with the dimensions the text would needs with - * the current theme. - * - * \pre label != NULL - * \param label the label - * \param w the pointer to width (may be NULL) - * \param h the pointer to height (may be NULL) - */ void -label_query(const struct label *label, unsigned int *w, unsigned int *h); - -/** - * Draw the label. - * - * \pre label != NULL - * \param label the label to draw - */ -void -label_draw(const struct label *label); +label_query(const struct label *, unsigned int *, unsigned int *); -/** - * Convert the label into an action. - * - * The following field will be set into the action: - * - * - act->data: points to label (reference), - * - act->draw: a wrapper to label_draw. - * - * The label being an UI element is considered to never completes, as such - * you will need to handle this case or to use a custom update function. - * - * \pre frame != NULL - * \pre act != NULL - * \param label the label to reference - * \param act the action to fill - */ void -label_action(struct label *label, struct action *act); +label_draw(const struct label *); + +void +label_action(struct label *, struct action *); CORE_END_DECLS diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/theme.c --- a/libmlk-ui/ui/theme.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/theme.c Wed Mar 10 18:49:08 2021 +0100 @@ -69,26 +69,26 @@ FONT(fonts_opensans_regular, 14, THEME_FONT_INTERFACE) }; -bool +int theme_init(void) { /* Open all fonts. */ for (size_t i = 0; i < UTIL_SIZE(default_fonts); ++i) { struct font_catalog *fc = &default_fonts[i]; - if (!font_openmem(&fc->font, fc->data, fc->datasz, fc->size)) + if (font_openmem(&fc->font, fc->data, fc->datasz, fc->size) < 0) goto failed; /* Reference this font into the catalog. */ *default_fonts[i].dest = &default_fonts[i].font; } - return true; + return 0; failed: theme_finish(); - return false; + return -1; } struct theme * diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/theme.h --- a/libmlk-ui/ui/theme.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/theme.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,14 +19,6 @@ #ifndef MOLKO_UI_THEME_H #define MOLKO_UI_THEME_H -/** - * \file theme.h - * \brief Abstract theming. - * \ingroup ui - */ - -#include - #include struct button; @@ -36,200 +28,60 @@ struct label; struct sprite; -/** - * \brief Font component. - */ enum theme_font { - THEME_FONT_DEBUG, /*!< Font for debug messages. */ - THEME_FONT_INTERFACE, /*!< Font for interface elements. */ - THEME_FONT_LAST /*!< Unused. */ + THEME_FONT_DEBUG, + THEME_FONT_INTERFACE, + THEME_FONT_NUM }; -/** - * \brief Theme colors. - */ enum theme_color { - THEME_COLOR_DEBUG, /*!< Debug color font. */ - THEME_COLOR_NORMAL, /*!< Normal font color. */ - THEME_COLOR_SELECTED, /*!< Font color for selected elements. */ - THEME_COLOR_SHADOW, /*!< Shadow color. */ - THEME_COLOR_LAST /*!< Unused. */ -}; - -/** - * \brief Special sprites. - */ -enum theme_sprite { - THEME_SPRITE_CURSOR, /*!< Sprite cursor. */ - THEME_SPRITE_LAST, + THEME_COLOR_DEBUG, + THEME_COLOR_NORMAL, + THEME_COLOR_SELECTED, + THEME_COLOR_SHADOW, + THEME_COLOR_NUM }; -/** - * \brief Abstract theme structure. - */ -struct theme { - /** - * (+&) Fonts catalog. - */ - struct font *fonts[THEME_FONT_LAST]; +enum theme_sprite { + THEME_SPRITE_CURSOR, + THEME_SPRITE_NUM +}; - /** - * (+&?) Special sprites catalog. - */ - const struct sprite *sprites[THEME_SPRITE_LAST]; - - /** - * (+) User interface colors. - */ - unsigned long colors[THEME_COLOR_LAST]; - - /** - * (+) Padding between GUI elements. - */ +struct theme { + struct font *fonts[THEME_FONT_NUM]; + const struct sprite *sprites[THEME_SPRITE_NUM]; + unsigned long colors[THEME_COLOR_NUM]; unsigned int padding; - /** - * (+) Draw a frame. - * - * This function is used to draw a box usually as a container where UI - * elements will be put. - * - * \see \ref theme_draw_frame - */ void (*draw_frame)(const struct theme *, const struct frame *); - - /** - * (+) Draw a label. - * - * \see \ref theme_draw_label - */ void (*draw_label)(const struct theme *, const struct label *); - - /** - * (+) Draw a button. - * - * \see \ref theme_draw_button - */ void (*draw_button)(const struct theme *, const struct button *); - - /** - * (+) Draw a checkbox. - * - * \see \ref theme_draw_button - */ void (*draw_checkbox)(const struct theme *t, const struct checkbox *); }; CORE_BEGIN_DECLS -/** - * Initialize the theming system. - * - * This function is automatically called from \ref ui_init and thus not - * necessary from user. - * - * \return False on error. - */ -bool +int theme_init(void); -/** - * Get a reference to the default theme. - * - * The returned theme may be modified to modify the whole UI. - * - * \return A non-owning pointer to a static storage for the default theme. - */ struct theme * theme_default(void); -/** - * Convenient shortcut to shallow copy src into dst. - * - * Use this function when you want your own local copy of a theme because you - * want to modify some attributes. - * - * You should not modify underlying objects within the new theme because they - * still point to the same region and you may erase the user settings. - * - * This code is incorrect: - * - * ```c - * struct theme th; - * - * theme_shallow(&th, theme_default()); - * th.fonts[THEME_FONT_INTERFACE].style = FONT_STYLE_NONE; - * - * // - * // Since th.fonts contain same pointers to theme_default, you'll erase - * // the default theme settings. - * // - * ``` - * - * Instead, if you really need to modify an underlying object, you have to copy - * it too. - * - * ```c - * struct font font; - * - * font_shallow(&font, theme_default()->fonts[THEME_FONT_INTERFACE]; - * font.style = FONT_STYLE_NONE; - * - * // No font_finish needed either, it is only a shallow copy. - * ``` - * - * This is a shortcut to `memcpy(dst, src, sizeof (*src))`. - * - * \pre dst != NULL - * \param dst the destination theme - * \param src the source theme (may be NULL) - */ void -theme_shallow(struct theme *dst, const struct theme *src); +theme_shallow(struct theme *, const struct theme *); + +void +theme_draw_frame(const struct theme *, const struct frame *); -/** - * Draw a frame. - * - * \pre frame != NULL - * \param t the theme to use (may be NULL) - * \param frame the frame - */ void -theme_draw_frame(const struct theme *t, const struct frame *frame); - -/** - * Draw a label. - * - * \pre label != NULL - * \param t the theme to use (may be NULL) - * \param label the label - */ -void -theme_draw_label(const struct theme *t, const struct label *label); +theme_draw_label(const struct theme *, const struct label *); -/** - * Draw a button. - * - * \pre button != NULL - * \param t the theme to use (may be NULL) - * \param button the button - */ void -theme_draw_button(const struct theme *t, const struct button *button); +theme_draw_button(const struct theme *, const struct button *); -/** - * Draw a checkbox. - * - * \param t the theme to use (may be NULL) - * \param cb the checkbox - */ void -theme_draw_checkbox(const struct theme *t, const struct checkbox *cb); +theme_draw_checkbox(const struct theme *, const struct checkbox *); -/** - * This function is automatically called from \ref ui_finish and thus not - * necessary from user. - */ void theme_finish(void); diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/ui.c --- a/libmlk-ui/ui/ui.c Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/ui.c Wed Mar 10 18:49:08 2021 +0100 @@ -22,11 +22,12 @@ #include "ui.h" #include "theme.h" -bool +int ui_init(void) { #if defined(MOLKO_WITH_NLS) - translate_init("libmlk-ui"); + if (translate_init("libmlk-ui") < 0) + return -1; #endif return theme_init(); diff -r 6151152d009c -r 196264679079 libmlk-ui/ui/ui.h --- a/libmlk-ui/ui/ui.h Wed Mar 10 18:49:00 2021 +0100 +++ b/libmlk-ui/ui/ui.h Wed Mar 10 18:49:08 2021 +0100 @@ -19,28 +19,13 @@ #ifndef MOLKO_UI_UI_H #define MOLKO_UI_UI_H -/** - * \file ui.h - * \brief libui convenient header. - */ - -#include - #include CORE_BEGIN_DECLS -/** - * Initialize the ui library. - * - * \return False on errors. - */ -bool +int ui_init(void); -/** - * Close the ui library. - */ void ui_finish(void); diff -r 6151152d009c -r 196264679079 tests/test-action-script.c --- a/tests/test-action-script.c Wed Mar 10 18:49:00 2021 +0100 +++ b/tests/test-action-script.c Wed Mar 10 18:49:08 2021 +0100 @@ -48,24 +48,24 @@ ((struct invokes *)act->data)->handle++; } -static bool +static int my_update_false(struct action *act, unsigned int ticks) { (void)ticks; ((struct invokes *)act->data)->update++; - return false; + return 0; } -static bool +static int my_update_true(struct action *act, unsigned int ticks) { (void)ticks; ((struct invokes *)act->data)->update++; - return true; + return 1; } static void @@ -105,18 +105,18 @@ struct action act[3] = {0}; struct script sc = {0}; - GREATEST_ASSERT(script_append(&sc, &act[0])); + GREATEST_ASSERT(script_append(&sc, &act[0]) == 0); GREATEST_ASSERT_EQ(sc.cur, 0U); GREATEST_ASSERT_EQ(sc.actionsz, 1U); GREATEST_ASSERT_EQ(sc.actions[0], &act[0]); - GREATEST_ASSERT(script_append(&sc, &act[1])); + GREATEST_ASSERT(script_append(&sc, &act[1]) == 0); GREATEST_ASSERT_EQ(sc.cur, 0U); GREATEST_ASSERT_EQ(sc.actionsz, 2U); GREATEST_ASSERT_EQ(sc.actions[0], &act[0]); GREATEST_ASSERT_EQ(sc.actions[1], &act[1]); - GREATEST_ASSERT(script_append(&sc, &act[2])); + GREATEST_ASSERT(script_append(&sc, &act[2]) == 0); GREATEST_ASSERT_EQ(sc.cur, 0U); GREATEST_ASSERT_EQ(sc.actionsz, 3U); GREATEST_ASSERT_EQ(sc.actions[0], &act[0]); @@ -142,9 +142,9 @@ struct script sc = {0}; - GREATEST_ASSERT(script_append(&sc, &table[0].act)); - GREATEST_ASSERT(script_append(&sc, &table[1].act)); - GREATEST_ASSERT(script_append(&sc, &table[2].act)); + GREATEST_ASSERT(script_append(&sc, &table[0].act) == 0); + GREATEST_ASSERT(script_append(&sc, &table[1].act) == 0); + GREATEST_ASSERT(script_append(&sc, &table[2].act) == 0); /* [0] */ script_handle(&sc, &(union event){0}); @@ -221,9 +221,9 @@ struct script sc = {0}; - GREATEST_ASSERT(script_append(&sc, &table[0].act)); - GREATEST_ASSERT(script_append(&sc, &table[1].act)); - GREATEST_ASSERT(script_append(&sc, &table[2].act)); + GREATEST_ASSERT(script_append(&sc, &table[0].act) == 0); + GREATEST_ASSERT(script_append(&sc, &table[1].act) == 0); + GREATEST_ASSERT(script_append(&sc, &table[2].act) == 0); /* 0 -> 1 */ GREATEST_ASSERT(!script_update(&sc, 0)); @@ -317,9 +317,9 @@ struct script sc = {0}; - GREATEST_ASSERT(script_append(&sc, &table[0].act)); - GREATEST_ASSERT(script_append(&sc, &table[1].act)); - GREATEST_ASSERT(script_append(&sc, &table[2].act)); + GREATEST_ASSERT(script_append(&sc, &table[0].act) == 0); + GREATEST_ASSERT(script_append(&sc, &table[1].act) == 0); + GREATEST_ASSERT(script_append(&sc, &table[2].act) == 0); /* [0] */ script_draw(&sc); @@ -396,9 +396,9 @@ struct script sc = {0}; - GREATEST_ASSERT(script_append(&sc, &table[0].act)); - GREATEST_ASSERT(script_append(&sc, &table[1].act)); - GREATEST_ASSERT(script_append(&sc, &table[2].act)); + GREATEST_ASSERT(script_append(&sc, &table[0].act) == 0); + GREATEST_ASSERT(script_append(&sc, &table[1].act) == 0); + GREATEST_ASSERT(script_append(&sc, &table[2].act) == 0); /* Update once so that the current action goes to 1. */ GREATEST_ASSERT(!script_update(&sc, 0)); @@ -449,9 +449,9 @@ struct script sc = {0}; struct action act; - GREATEST_ASSERT(script_append(&sc, &table[0].act)); - GREATEST_ASSERT(script_append(&sc, &table[1].act)); - GREATEST_ASSERT(script_append(&sc, &table[2].act)); + GREATEST_ASSERT(script_append(&sc, &table[0].act) == 0); + GREATEST_ASSERT(script_append(&sc, &table[1].act) == 0); + GREATEST_ASSERT(script_append(&sc, &table[2].act) == 0); /* Now convert this script into an action itself. */ script_action(&sc, &act); diff -r 6151152d009c -r 196264679079 tests/test-action.c --- a/tests/test-action.c Wed Mar 10 18:49:00 2021 +0100 +++ b/tests/test-action.c Wed Mar 10 18:49:08 2021 +0100 @@ -23,11 +23,11 @@ #include struct invokes { - bool handle; - bool update; - bool draw; - bool end; - bool finish; + int handle; + int update; + int draw; + int end; + int finish; }; static union event dummy; @@ -46,45 +46,45 @@ { (void)ev; - ((struct invokes *)act->data)->handle = true; + ((struct invokes *)act->data)->handle = 1; } -static bool +static int my_update_false(struct action *act, unsigned int ticks) { (void)ticks; - ((struct invokes *)act->data)->update = true; + ((struct invokes *)act->data)->update = 1; - return false; + return 0; } -static bool +static int my_update_true(struct action *act, unsigned int ticks) { (void)ticks; - ((struct invokes *)act->data)->update = true; + ((struct invokes *)act->data)->update = 1; - return true; + return 1; } static void my_draw(struct action *act) { - ((struct invokes *)act->data)->draw = true; + ((struct invokes *)act->data)->draw = 1; } static void my_end(struct action *act) { - ((struct invokes *)act->data)->end = true; + ((struct invokes *)act->data)->end = 1; } static void my_finish(struct action *act) { - ((struct invokes *)act->data)->finish = true; + ((struct invokes *)act->data)->finish = 1; } GREATEST_TEST @@ -196,14 +196,14 @@ struct action_stack st = {0}; struct action act = {0}; - GREATEST_ASSERT(action_stack_add(&st, &act)); + GREATEST_ASSERT(action_stack_add(&st, &act) == 0); /* Now fill up. */ for (int i = 0; i < ACTION_STACK_MAX - 1; ++i) - GREATEST_ASSERT(action_stack_add(&st, &act)); + GREATEST_ASSERT(action_stack_add(&st, &act) == 0); /* This one should not fit in. */ - GREATEST_ASSERT(!action_stack_add(&st, &act)); + GREATEST_ASSERT(action_stack_add(&st, &act) < 0); GREATEST_PASS(); } @@ -212,12 +212,12 @@ stack_handle(void) { struct { - bool called; + int called; struct action act; } table[] = { - { false, { .data = &table[0].called, .handle = my_handle } }, - { false, { .data = &table[1].called, .handle = my_handle } }, - { false, { .data = &table[2].called, .handle = my_handle } }, + { 0, { .data = &table[0].called, .handle = my_handle } }, + { 0, { .data = &table[1].called, .handle = my_handle } }, + { 0, { .data = &table[2].called, .handle = my_handle } }, }; struct action_stack st = {0}; @@ -313,7 +313,7 @@ GREATEST_ASSERT_EQ(st.actions[5], NULL); /* - * Now make all actions to return true and check if it cleans the stack. + * Now make all actions to return 1 and check if it cleans the stack. */ table[0].act.update = table[2].act.update = diff -r 6151152d009c -r 196264679079 tests/test-alloc.c --- a/tests/test-alloc.c Wed Mar 10 18:49:00 2021 +0100 +++ b/tests/test-alloc.c Wed Mar 10 18:49:08 2021 +0100 @@ -66,7 +66,7 @@ struct alloc_pool pool; struct point *p; - GREATEST_ASSERT(alloc_pool_init(&pool, sizeof (*p), NULL)); + GREATEST_ASSERT(alloc_pool_init(&pool, sizeof (*p), NULL) == 0); GREATEST_ASSERT_EQ(sizeof (*p), pool.elemsize); GREATEST_ASSERT_EQ(0, pool.size); GREATEST_ASSERT_EQ(ALLOC_POOL_INIT_DEFAULT, pool.capacity); diff -r 6151152d009c -r 196264679079 tests/test-character.c --- a/tests/test-character.c Wed Mar 10 18:49:00 2021 +0100 +++ b/tests/test-character.c Wed Mar 10 18:49:08 2021 +0100 @@ -51,14 +51,14 @@ .luckbonus = 1004 }; - GREATEST_ASSERT(save_open_path(&db, "test.db", SAVE_MODE_WRITE)); + GREATEST_ASSERT(save_open_path(&db, "test.db", SAVE_MODE_WRITE) == 0); GREATEST_ASSERT(character_save(&ch, &db)); /* Restore. */ memset(&ch, 0, sizeof (ch)); ch.name = "david"; - GREATEST_ASSERT(character_load(&ch, &db)); + GREATEST_ASSERT(character_load(&ch, &db) == 0); GREATEST_ASSERT_EQ(1989, ch.hp); GREATEST_ASSERT_EQ(1, ch.mp); GREATEST_ASSERT_EQ(18, ch.level); diff -r 6151152d009c -r 196264679079 tests/test-drawable.c --- a/tests/test-drawable.c Wed Mar 10 18:49:00 2021 +0100 +++ b/tests/test-drawable.c Wed Mar 10 18:49:08 2021 +0100 @@ -23,10 +23,10 @@ #include struct invokes { - bool update; - bool draw; - bool end; - bool finish; + int update; + int draw; + int end; + int finish; }; #define INIT(dat, up) { \ @@ -37,42 +37,42 @@ .finish = my_finish \ } -static bool +static int my_update_false(struct drawable *dw, unsigned int ticks) { (void)ticks; - ((struct invokes *)dw->data)->update = true; + ((struct invokes *)dw->data)->update = 1; - return false; + return 0; } -static bool +static int my_update_true(struct drawable *dw, unsigned int ticks) { (void)ticks; - ((struct invokes *)dw->data)->update = true; + ((struct invokes *)dw->data)->update = 1; - return true; + return 1; } static void my_draw(struct drawable *dw) { - ((struct invokes *)dw->data)->draw = true; + ((struct invokes *)dw->data)->draw = 1; } static void my_end(struct drawable *dw) { - ((struct invokes *)dw->data)->end = true; + ((struct invokes *)dw->data)->end = 1; } static void my_finish(struct drawable *dw) { - ((struct invokes *)dw->data)->finish = true; + ((struct invokes *)dw->data)->finish = 1; } GREATEST_TEST @@ -162,14 +162,14 @@ struct drawable_stack st = {0}; struct drawable dw = {0}; - GREATEST_ASSERT(drawable_stack_add(&st, &dw)); + GREATEST_ASSERT(drawable_stack_add(&st, &dw) == 0); /* Now fill up. */ for (int i = 0; i < DRAWABLE_STACK_MAX - 1; ++i) - GREATEST_ASSERT(drawable_stack_add(&st, &dw)); + GREATEST_ASSERT(drawable_stack_add(&st, &dw) == 0); /* This one should not fit in. */ - GREATEST_ASSERT(!drawable_stack_add(&st, &dw)); + GREATEST_ASSERT(drawable_stack_add(&st, &dw) < 0); GREATEST_PASS(); } @@ -246,7 +246,7 @@ GREATEST_ASSERT_EQ(st.objects[5], NULL); /* - * Now make all actions to return true and check if it cleans the stack. + * Now make all actions to return 1 and check if it cleans the stack. */ table[0].dw.update = table[2].dw.update = diff -r 6151152d009c -r 196264679079 tests/test-map.c --- a/tests/test-map.c Wed Mar 10 18:49:00 2021 +0100 +++ b/tests/test-map.c Wed Mar 10 18:49:08 2021 +0100 @@ -159,7 +159,7 @@ * we will skip if it fails to initialize. */ - if (core_init("fr.malikania", "test") && window_open("test-map", 100, 100)) { + if (core_init("fr.malikania", "test") == 0 && window_open("test-map", 100, 100)) { GREATEST_RUN_SUITE(suite_basics); GREATEST_RUN_SUITE(suite_errors); } diff -r 6151152d009c -r 196264679079 tests/test-save.c --- a/tests/test-save.c Wed Mar 10 18:49:00 2021 +0100 +++ b/tests/test-save.c Wed Mar 10 18:49:08 2021 +0100 @@ -38,7 +38,7 @@ struct save db; /* Non-existent should return false. */ - GREATEST_ASSERT(!save_open_path(&db, "1.db", SAVE_MODE_READ)); + GREATEST_ASSERT(save_open_path(&db, "1.db", SAVE_MODE_READ) < 0); save_finish(&db); @@ -51,8 +51,8 @@ struct save db[2] = {0}; /* Write should work on both non-existent and existent database. */ - GREATEST_ASSERT(save_open_path(&db[0], "1.db", SAVE_MODE_WRITE)); - GREATEST_ASSERT(save_open_path(&db[1], "2.db", SAVE_MODE_WRITE)); + GREATEST_ASSERT(save_open_path(&db[0], "1.db", SAVE_MODE_WRITE) == 0); + GREATEST_ASSERT(save_open_path(&db[1], "2.db", SAVE_MODE_WRITE) == 0); /* Update and create date must not be 0. */ GREATEST_ASSERT(db[0].created > 0); @@ -64,8 +64,8 @@ save_finish(&db[1]); /* Should work again. */ - GREATEST_ASSERT(save_open_path(&db[0], "1.db", SAVE_MODE_WRITE)); - GREATEST_ASSERT(save_open_path(&db[1], "2.db", SAVE_MODE_WRITE)); + GREATEST_ASSERT(save_open_path(&db[0], "1.db", SAVE_MODE_WRITE) == 0); + GREATEST_ASSERT(save_open_path(&db[1], "2.db", SAVE_MODE_WRITE) == 0); GREATEST_ASSERT(db[0].created > 0); GREATEST_ASSERT(db[0].updated > 0); GREATEST_ASSERT(db[1].created > 0); @@ -91,20 +91,20 @@ struct save db; struct save_property prop; - GREATEST_ASSERT(save_open_path(&db, "1.db", SAVE_MODE_WRITE)); + GREATEST_ASSERT(save_open_path(&db, "1.db", SAVE_MODE_WRITE) == 0); /* Insert a new property 'state'. */ prop = (struct save_property){.key = "state", .value = "intro"}; - GREATEST_ASSERT(save_set_property(&db, &prop)); + GREATEST_ASSERT(save_set_property(&db, &prop) == 0); prop = (struct save_property){.key = "state"}; - GREATEST_ASSERT(save_get_property(&db, &prop)); + GREATEST_ASSERT(save_get_property(&db, &prop) == 0); GREATEST_ASSERT_STR_EQ(prop.value, "intro"); /* Now we replace the value. */ prop = (struct save_property){.key = "state", .value = "map"}; - GREATEST_ASSERT(save_set_property(&db, &prop)); + GREATEST_ASSERT(save_set_property(&db, &prop) == 0); prop = (struct save_property){.key = "state"}; - GREATEST_ASSERT(save_get_property(&db, &prop)); + GREATEST_ASSERT(save_get_property(&db, &prop) == 0); GREATEST_ASSERT_STR_EQ(prop.value, "map"); save_finish(&db); @@ -118,8 +118,8 @@ struct save db; struct save_property prop = {.key = "state"}; - GREATEST_ASSERT(save_open_path(&db, "1.db", SAVE_MODE_WRITE)); - GREATEST_ASSERT(!save_get_property(&db, &prop)); + GREATEST_ASSERT(save_open_path(&db, "1.db", SAVE_MODE_WRITE) == 0); + GREATEST_ASSERT(save_get_property(&db, &prop) < 0); GREATEST_ASSERT_STR_EQ(prop.value, ""); GREATEST_PASS(); @@ -131,15 +131,15 @@ struct save db; struct save_property prop; - GREATEST_ASSERT(save_open_path(&db, "1.db", SAVE_MODE_WRITE)); + GREATEST_ASSERT(save_open_path(&db, "1.db", SAVE_MODE_WRITE) == 0); /* Insert a new property 'initialized'. */ prop = (struct save_property){.key = "state", .value = "intro"}; - GREATEST_ASSERT(save_set_property(&db, &prop)); + GREATEST_ASSERT(save_set_property(&db, &prop) == 0); prop = (struct save_property){.key = "state"}; - GREATEST_ASSERT(save_remove_property(&db, &prop)); + GREATEST_ASSERT(save_remove_property(&db, &prop) == 0); prop = (struct save_property){.key = "state"}; - GREATEST_ASSERT(!save_get_property(&db, &prop)); + GREATEST_ASSERT(save_get_property(&db, &prop) < 0); GREATEST_ASSERT_STR_EQ(prop.value, ""); GREATEST_PASS(); diff -r 6151152d009c -r 196264679079 tests/test-state.c --- a/tests/test-state.c Wed Mar 10 18:49:00 2021 +0100 +++ b/tests/test-state.c Wed Mar 10 18:49:08 2021 +0100 @@ -209,7 +209,7 @@ } GREATEST_TEST -switch_quick_true(void) +switch_quick_1(void) { struct { struct invokes inv; @@ -220,11 +220,11 @@ }; /* - * When set to true, switching quickly state will immediately set the + * When set to 1, switching quickly state will immediately set the * current state to the specified one and call start on it. However, * if there was already a planned state, it is finished immediately. */ - game_switch(&table[0].state, true); + game_switch(&table[0].state, 1); GREATEST_ASSERT_EQ(table[0].inv.start, 1); GREATEST_ASSERT_EQ(table[0].inv.handle, 0); @@ -242,7 +242,7 @@ /* Switch from [0] to [1] quickly, [0] should be closed immediately. */ zero(&table[0].inv); - game_switch(&table[1].state, true); + game_switch(&table[1].state, 1); GREATEST_ASSERT_EQ(table[0].inv.start, 0); GREATEST_ASSERT_EQ(table[0].inv.handle, 0); @@ -262,7 +262,7 @@ } GREATEST_TEST -switch_quick_false(void) +switch_quick_0(void) { struct { struct invokes inv; @@ -272,7 +272,7 @@ { .state = INIT(&table[1]) } }; - game_switch(&table[0].state, true); + game_switch(&table[0].state, 1); GREATEST_ASSERT_EQ(table[0].inv.start, 1); GREATEST_ASSERT_EQ(table[0].inv.handle, 0); @@ -293,7 +293,7 @@ * be done on the next game_update call instead. */ zero(&table[0].inv); - game_switch(&table[1].state, false); + game_switch(&table[1].state, 0); GREATEST_ASSERT_EQ(table[0].inv.start, 0); GREATEST_ASSERT_EQ(table[0].inv.handle, 0); @@ -324,11 +324,11 @@ }; /* Start with 0. */ - game_switch(&table[0].state, true); + game_switch(&table[0].state, 1); /* Ask to switch to 1. */ zero(&table[0].inv); - game_switch(&table[1].state, true); + game_switch(&table[1].state, 1); game_update(0); GREATEST_ASSERT_EQ(table[0].inv.start, 0); @@ -351,8 +351,8 @@ GREATEST_SUITE(suite_switch) { GREATEST_SET_SETUP_CB(switch_startup, &game); - GREATEST_RUN_TEST(switch_quick_true); - GREATEST_RUN_TEST(switch_quick_false); + GREATEST_RUN_TEST(switch_quick_1); + GREATEST_RUN_TEST(switch_quick_0); GREATEST_RUN_TEST(switch_invoke); } diff -r 6151152d009c -r 196264679079 tests/test-tileset.c --- a/tests/test-tileset.c Wed Mar 10 18:49:00 2021 +0100 +++ b/tests/test-tileset.c Wed Mar 10 18:49:08 2021 +0100 @@ -31,7 +31,7 @@ struct tileset_file loader = {0}; struct tileset tileset; - GREATEST_ASSERT(tileset_file_open(&loader, &tileset, DIRECTORY "sample-tileset.tileset")); + GREATEST_ASSERT(tileset_file_open(&loader, &tileset, DIRECTORY "sample-tileset.tileset") == 0); GREATEST_ASSERT_EQ(64U, tileset.sprite->cellw); GREATEST_ASSERT_EQ(32U, tileset.sprite->cellh); @@ -77,7 +77,7 @@ struct tileset_file loader = {0}; struct tileset tileset = {0}; - GREATEST_ASSERT(!tileset_file_open(&loader, &tileset, DIRECTORY "error-tilewidth.tileset")); + GREATEST_ASSERT(tileset_file_open(&loader, &tileset, DIRECTORY "error-tilewidth.tileset") < 0); GREATEST_PASS(); } @@ -87,7 +87,7 @@ struct tileset_file loader = {0}; struct tileset tileset = {0}; - GREATEST_ASSERT(!tileset_file_open(&loader, &tileset, DIRECTORY "error-tileheight.tileset")); + GREATEST_ASSERT(tileset_file_open(&loader, &tileset, DIRECTORY "error-tileheight.tileset") < 0); GREATEST_PASS(); } @@ -97,7 +97,7 @@ struct tileset_file loader = {0}; struct tileset tileset = {0}; - GREATEST_ASSERT(!tileset_file_open(&loader, &tileset, DIRECTORY "error-image.tileset")); + GREATEST_ASSERT(tileset_file_open(&loader, &tileset, DIRECTORY "error-image.tileset") < 0); GREATEST_PASS(); } @@ -115,7 +115,7 @@ { GREATEST_MAIN_BEGIN(); - if (core_init("fr.malikania", "test") && window_open("test-tileset", 100, 100)) { + if (core_init("fr.malikania", "test") == 0 && window_open("test-tileset", 100, 100)) { GREATEST_RUN_SUITE(suite_basics); GREATEST_RUN_SUITE(suite_errors); }