changeset 46:b815621df3e3

core: remove all fixed width integers, closes #2460
author David Demelier <markand@malikania.fr>
date Wed, 15 Jan 2020 22:31:17 +0100
parents e10fd1b6323f
children f053a9f38c0e
files src/animation.c src/animation.h src/clock.c src/clock.h src/event.h src/font.c src/font.h src/main.c src/map.c src/map.h src/message.c src/message.h src/painter.c src/painter.h src/splashscreen.c src/sprite.c src/sprite.h src/texture.c src/texture.h src/walksprite.c src/walksprite.h src/window.c src/window.h
diffstat 23 files changed, 82 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/src/animation.c	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/animation.c	Wed Jan 15 22:31:17 2020 +0100
@@ -22,7 +22,7 @@
 #include "sprite.h"
 
 void
-animation_init(struct animation *an, struct sprite *sprite, uint16_t delay)
+animation_init(struct animation *an, struct sprite *sprite, unsigned int delay)
 {
 	assert(an);
 	assert(sprite);
@@ -55,7 +55,7 @@
 }
 
 void
-animation_update(struct animation *an, unsigned ticks)
+animation_update(struct animation *an, unsigned int ticks)
 {
 	assert(an);
 
--- a/src/animation.h	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/animation.h	Wed Jan 15 22:31:17 2020 +0100
@@ -25,7 +25,6 @@
  */
 
 #include <stdbool.h>
-#include <stdint.h>
 
 struct sprite;
 
@@ -34,10 +33,10 @@
  */
 struct animation {
 	struct sprite *sprite;  /*!< Sprite to use (RW) */
-	uint16_t row;           /*!< current row (RO) */
-	uint16_t column;        /*!< current column (RO) */
-	uint16_t delay;         /*!< delay between frames (RW) */
-	uint16_t elapsed;       /*!< elapsed time since last frame (RO) */
+	unsigned int row;       /*!< current row (RO) */
+	unsigned int column;    /*!< current column (RO) */
+	unsigned int delay;     /*!< delay between frames (RW) */
+	unsigned int elapsed;   /*!< elapsed time since last frame (RO) */
 };
 
 /**
@@ -53,7 +52,7 @@
  * \param delay the delay between frames in milliseconds
  */
 void
-animation_init(struct animation *an, struct sprite *sprite, uint16_t delay);
+animation_init(struct animation *an, struct sprite *sprite, unsigned int delay);
 
 /**
  * Tells if the animation is complete.
@@ -85,7 +84,7 @@
  * \param ticks the elapsed ticks since the last call
  */
 void
-animation_update(struct animation *an, unsigned ticks);
+animation_update(struct animation *an, unsigned int ticks);
 
 /**
  * Draw the animation.
--- a/src/clock.c	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/clock.c	Wed Jan 15 22:31:17 2020 +0100
@@ -26,7 +26,7 @@
 	clock->ticks = SDL_GetTicks();
 }
 
-uint64_t
+unsigned int
 clock_elapsed(const struct clock *clock)
 {
 	return SDL_GetTicks() - clock->ticks;
--- a/src/clock.h	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/clock.h	Wed Jan 15 22:31:17 2020 +0100
@@ -24,13 +24,11 @@
  * \brief Track elapsed time.
  */
 
-#include <stdint.h>
-
 /**
  * \brief Clock structure.
  */
 struct clock {
-	uint64_t ticks;         /*!< time point on initialization */
+	unsigned int ticks;     /*!< time point on initialization */
 };
 
 /**
@@ -49,7 +47,7 @@
  * \param clock the clock
  * \return the elapsed time in milliseconds
  */
-uint64_t
+unsigned int
 clock_elapsed(const struct clock *clock);
 
 #endif /* !MOLKO_CLOCK_H */
--- a/src/event.h	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/event.h	Wed Jan 15 22:31:17 2020 +0100
@@ -25,7 +25,6 @@
  */
 
 #include <stdbool.h>
-#include <stdint.h>
 
 #include "key.h"
 #include "mouse.h"
@@ -62,8 +61,8 @@
 	struct {
 		enum event_type type;           /*!< EVENT_MOUSE */
 		enum mouse_button buttons;      /*!< OR'ed buttons that are pressed */
-		int32_t x;                      /*!< Mouse position in x */
-		int32_t y;                      /*!< Mouse position in y */
+		int x;                          /*!< Mouse position in x */
+		int y;                          /*!< Mouse position in y */
 	} mouse;
 
 	/**
@@ -72,8 +71,8 @@
 	struct {
 		enum event_type type;           /*!< EVENT_CLICKDOWN or EVENT_CLICKUP */
 		enum mouse_button button;       /*!< Unique button that was pressed */
-		int32_t x;                      /*!< Mouse position in x */
-		int32_t y;                      /*!< Mouse position in y */
+		int x;                          /*!< Mouse position in x */
+		int y;                          /*!< Mouse position in y */
 	} click;
 };
 
--- a/src/font.c	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/font.c	Wed Jan 15 22:31:17 2020 +0100
@@ -34,7 +34,7 @@
 };
 
 struct font *
-font_openf(const char *path, unsigned size)
+font_openf(const char *path, unsigned int size)
 {
 	assert(path);
 
@@ -52,7 +52,7 @@
 }
 
 struct font *
-font_openb(const void *buffer, size_t buflen, unsigned size)
+font_openb(const void *buffer, size_t buflen, unsigned int size)
 {
 	assert(buffer);
 
@@ -72,7 +72,7 @@
 }
 
 struct texture *
-font_render(struct font *font, const char *text, uint32_t color)
+font_render(struct font *font, const char *text, unsigned long color)
 {
 	assert(font);
 	assert(text);
--- a/src/font.h	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/font.h	Wed Jan 15 22:31:17 2020 +0100
@@ -25,7 +25,6 @@
  */
 
 #include <stddef.h>
-#include <stdint.h>
 
 /**
  * \brief Font object.
@@ -45,7 +44,7 @@
  * \return the font or NULL on error
  */
 struct font *
-font_openf(const char *path, unsigned size);
+font_openf(const char *path, unsigned int size);
 
 /**
  * Open font from memory buffer.
@@ -58,7 +57,7 @@
  * \return the font or NULL on error
  */
 struct font *
-font_openb(const void *buffer, size_t buflen, unsigned size);
+font_openb(const void *buffer, size_t buflen, unsigned int size);
 
 /**
  * Render a text.
@@ -70,7 +69,7 @@
  * \param color the color
  */
 struct texture *
-font_render(struct font *font, const char *text, uint32_t color);
+font_render(struct font *font, const char *text, unsigned long color);
 
 /**
  * Close the font.
--- a/src/main.c	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/main.c	Wed Jan 15 22:31:17 2020 +0100
@@ -48,7 +48,7 @@
 	clock_start(&clock);
 
 	for (;;) {
-		uint64_t elapsed = clock_elapsed(&clock);
+		unsigned int elapsed = clock_elapsed(&clock);
 
 		clock_start(&clock);
 
--- a/src/map.c	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/map.c	Wed Jan 15 22:31:17 2020 +0100
@@ -60,7 +60,7 @@
 	amount = map->width * map->height;
 	current = 0;
 
-	if (!(layer->tiles = calloc(amount, sizeof (uint16_t))))
+	if (!(layer->tiles = calloc(amount, sizeof (unsigned short))))
 		return;
 
 	for (int tile; fscanf(fp, "%d", &tile) && current < amount; ++current)
@@ -88,13 +88,13 @@
 	if (strncmp(line, "title", 5) == 0)
 		sscanf(line, "title|" MAX_F(MAP_TITLE_MAX), map->title);
 	else if (strncmp(line, "width", 5) == 0)
-		sscanf(line, "width|%hu", &map->width);
+		sscanf(line, "width|%u", &map->width);
 	else if (strncmp(line, "height", 6) == 0)
-		sscanf(line, "height|%hu", &map->height);
+		sscanf(line, "height|%u", &map->height);
 	else if (strncmp(line, "tilewidth", 9) == 0)
-		sscanf(line, "tilewidth|%hhu", &map->tilewidth);
+		sscanf(line, "tilewidth|%hu", &map->tilewidth);
 	else if (strncmp(line, "tileheight", 10) == 0)
-		sscanf(line, "tileheight|%hhu", &map->tileheight);
+		sscanf(line, "tileheight|%hu", &map->tileheight);
 	else if (strncmp(line, "tileset", 7) == 0)
 		parse_tileset(map, line);
 	else if (strncmp(line, "layer", 5) == 0)
@@ -124,13 +124,13 @@
 	assert(map);
 	assert(layer);
 
-	int16_t x = 0, y = 0;
+	int x = 0, y = 0;
 
-	for (uint16_t r = 0; r < map->width; ++r) {
-		for (uint16_t c = 0; c < map->height; ++c) {
-			size_t si = r * map->width + c;
-			size_t sr = (layer->tiles[si] - 1) / map->sprite.ncols;
-			size_t sc = (layer->tiles[si] - 1) % map->sprite.nrows;
+	for (unsigned int r = 0; r < map->width; ++r) {
+		for (unsigned int c = 0; c < map->height; ++c) {
+			unsigned int si = r * map->width + c;
+			unsigned int sr = (layer->tiles[si] - 1) / map->sprite.ncols;
+			unsigned int sc = (layer->tiles[si] - 1) % map->sprite.nrows;
 
 			if (layer->tiles[si] != 0)
 				sprite_draw(&map->sprite, sr, sc, x, y);
--- a/src/map.h	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/map.h	Wed Jan 15 22:31:17 2020 +0100
@@ -25,7 +25,6 @@
  */
 
 #include <stdbool.h>
-#include <stdint.h>
 
 #include "sprite.h"
 
@@ -40,7 +39,7 @@
  * \brief Map layer.
  */
 struct map_layer {
-	uint16_t *tiles;                /*!< Array of tiles, depending on the map size. */
+	unsigned short *tiles;          /*!< (RO) Array of tiles, depending on the map size. */
 };
 
 /**
@@ -51,10 +50,10 @@
 	struct texture *tileset;        /*!< (RW) Tileset to use */
 	struct texture *picture;        /*!< (RO) Map drawn into a picture */
 	struct sprite sprite;           /*!< (RO) Sprite to render */
-	uint16_t width;                 /*!< (RO) Map width in cells */
-	uint16_t height;                /*!< (RO) Map height in cells */
-	uint8_t tilewidth;              /*!< (RO) Pixels per cell (width) */
-	uint8_t tileheight;             /*!< (RO) Pixels per cell (height) */
+	unsigned int width;             /*!< (RO) Map width in cells */
+	unsigned int height;            /*!< (RO) Map height in cells */
+	unsigned short tilewidth;       /*!< (RO) Pixels per cell (width) */
+	unsigned short tileheight;      /*!< (RO) Pixels per cell (height) */
 	struct map_layer layers[2];     /*!< (RO) Layers (background, foreground) */
 };
 
--- a/src/message.c	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/message.c	Wed Jan 15 22:31:17 2020 +0100
@@ -37,7 +37,7 @@
 }
 
 void
-message_update(struct message *msg, unsigned ticks)
+message_update(struct message *msg, unsigned int ticks)
 {
 	assert(msg);
 
--- a/src/message.h	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/message.h	Wed Jan 15 22:31:17 2020 +0100
@@ -25,7 +25,6 @@
  */
 
 #include <stdbool.h>
-#include <stdint.h>
 
 struct sprite;
 struct font;
@@ -53,10 +52,10 @@
 	const char *text[3];            /*!< (RW) lines of text to show */
 	struct sprite *theme;           /*!< (RW) sprite to use for the frame */
 	struct texture *avatar;         /*!< (RW) optional avatar */
-        struct font *font;              /*!< (RW) font to use */
+	struct font *font;              /*!< (RW) font to use */
 	enum message_flags flags;       /*!< (RW) message flags */
 	enum message_state state;       /*!< (RO) current state */
-	uint16_t elapsed;               /*!< (RW) elapsed time while displaying */
+	unsigned int elapsed;           /*!< (RW) elapsed time while displaying */
 };
 
 /**
@@ -77,7 +76,7 @@
  * \param ticks the elapsed delay since last frame
  */
 void
-message_update(struct message *msg, unsigned ticks);
+message_update(struct message *msg, unsigned int ticks);
 
 /**
  * Draw the message into the screen.
--- a/src/painter.c	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/painter.c	Wed Jan 15 22:31:17 2020 +0100
@@ -36,7 +36,7 @@
 	SDL_SetRenderTarget(win.renderer, tex ? tex->handle : NULL);
 }
 
-uint32_t
+unsigned long
 painter_get_color(void)
 {
 	Uint8 r = 0, g = 0, b = 0, a = 0;
@@ -47,7 +47,7 @@
 }
 
 void
-painter_set_color(uint32_t color)
+painter_set_color(unsigned long color)
 {
 	SDL_SetRenderDrawColor(
 		win.renderer,
@@ -71,7 +71,7 @@
 }
 
 void
-painter_draw_rectangle(bool fill, int x, int y, unsigned width, unsigned height)
+painter_draw_rectangle(bool fill, int x, int y, unsigned int width, unsigned int height)
 {
 	const SDL_Rect rect = {
 		.w = width,
@@ -97,4 +97,3 @@
 {
 	SDL_RenderPresent(win.renderer);
 }
-
--- a/src/painter.h	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/painter.h	Wed Jan 15 22:31:17 2020 +0100
@@ -25,7 +25,6 @@
  */
 
 #include <stdbool.h>
-#include <stdint.h>
 
 struct texture;
 
@@ -59,7 +58,7 @@
  *
  * \return the color in RRGGBBAA format
  */
-uint32_t
+unsigned long
 painter_get_color(void);
 
 /**
@@ -68,7 +67,7 @@
  * \param color in RRGGBBAA format
  */
 void
-painter_set_color(uint32_t color);
+painter_set_color(unsigned long color);
 
 /**
  * Draw a line.
@@ -100,7 +99,7 @@
  * \param h the rectangle height
  */
 void
-painter_draw_rectangle(bool fill, int x, int y, unsigned w, unsigned h);
+painter_draw_rectangle(bool fill, int x, int y, unsigned int w, unsigned int h);
 
 /**
  * Clear the window.
--- a/src/splashscreen.c	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/splashscreen.c	Wed Jan 15 22:31:17 2020 +0100
@@ -45,8 +45,8 @@
 		error_fatal();
 
 	/* Compute position. */
-	uint16_t w = 0;
-	uint16_t h = 0;
+	unsigned int w = 0;
+	unsigned int h = 0;
 
 	if (!texture_get_size(text, &w, &h))
 		error_fatal();
--- a/src/sprite.c	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/sprite.c	Wed Jan 15 22:31:17 2020 +0100
@@ -23,7 +23,10 @@
 #include "texture.h"
 
 void
-sprite_init(struct sprite *sprite, struct texture *tex, uint8_t cellw, uint8_t cellh)
+sprite_init(struct sprite *sprite,
+            struct texture *tex,
+            unsigned int cellw,
+            unsigned int cellh)
 {
 	int w = 0;
 	int h = 0;
@@ -31,6 +34,7 @@
 	assert(sprite);
 	assert(tex);
 
+	/* TODO: use texture_get_size */
 	SDL_QueryTexture(tex->handle, NULL, NULL, &w, &h);
 
 	sprite->texture = tex;
@@ -41,7 +45,7 @@
 }
 
 void
-sprite_draw(struct sprite *sprite, uint16_t r, uint16_t c, int x, int y)
+sprite_draw(struct sprite *sprite, unsigned int r, unsigned int c, int x, int y)
 {
 	assert(sprite);
 
--- a/src/sprite.h	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/sprite.h	Wed Jan 15 22:31:17 2020 +0100
@@ -24,8 +24,6 @@
  * \brief Image sprites.
  */
 
-#include <stdint.h>
-
 struct texture;
 
 /**
@@ -33,10 +31,10 @@
  */
 struct sprite {
 	struct texture *texture;        /*!< Texture to access (RO) */
-	uint8_t cellw;                 /*!< Width per cell (RW) */
-	uint8_t cellh;                 /*!< Height per cell (RW) */
-	uint16_t nrows;                 /*!< Number of rows (RW) */
-	uint16_t ncols;                 /*!< Number of columns (RW) */
+	unsigned int cellw;             /*!< Width per cell (RW) */
+	unsigned int cellh;             /*!< Height per cell (RW) */
+	unsigned int nrows;             /*!< Number of rows (RW) */
+	unsigned int ncols;             /*!< Number of columns (RW) */
 };
 
 /**
@@ -61,8 +59,8 @@
 void
 sprite_init(struct sprite *sprite,
             struct texture *tex,
-            uint8_t cellw,
-            uint8_t cellh);
+            unsigned int cellw,
+            unsigned int cellh);
 
 /**
  * Draw the sprite component from row `r' and column `c'.
@@ -76,6 +74,6 @@
  * \warning No bounds checking
  */
 void
-sprite_draw(struct sprite *sprite, uint16_t r, uint16_t c, int x, int y);
+sprite_draw(struct sprite *sprite, unsigned int r, unsigned int c, int x, int y);
 
 #endif /* !MOLKO_SPRITE_H */
--- a/src/texture.c	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/texture.c	Wed Jan 15 22:31:17 2020 +0100
@@ -26,7 +26,7 @@
 #include "window_p.h"
 
 struct texture *
-texture_new(uint16_t w, uint16_t h)
+texture_new(unsigned int w, unsigned int h)
 {
 	struct texture *tex = emalloc(sizeof (struct texture));
 
@@ -41,7 +41,7 @@
 }
 
 bool
-texture_get_size(struct texture *tex, uint16_t *w, uint16_t *h)
+texture_get_size(struct texture *tex, unsigned int *w, unsigned int *h)
 {
 	assert(tex);
 
--- a/src/texture.h	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/texture.h	Wed Jan 15 22:31:17 2020 +0100
@@ -27,7 +27,6 @@
  */
 
 #include <stdbool.h>
-#include <stdint.h>
 
 /**
  * \brief Texture object.
@@ -45,7 +44,7 @@
  * \return the texture or NULL on error
  */
 struct texture *
-texture_new(uint16_t w, uint16_t h);
+texture_new(unsigned int w, unsigned int h);
 
 /**
  * Get texture size.
@@ -56,7 +55,7 @@
  * \param h the height
  */
 bool
-texture_get_size(struct texture *tex, uint16_t *w, uint16_t *h);
+texture_get_size(struct texture *tex, unsigned int *w, unsigned int *h);
 
 /**
  * Simple texture drawing.
--- a/src/walksprite.c	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/walksprite.c	Wed Jan 15 22:31:17 2020 +0100
@@ -23,7 +23,7 @@
 #include "sprite.h"
 
 void
-walksprite_init(struct walksprite *ws, struct sprite *sprite, uint16_t delay)
+walksprite_init(struct walksprite *ws, struct sprite *sprite, unsigned int delay)
 {
 	assert(ws);
 	assert(sprite);
@@ -34,7 +34,7 @@
 }
 
 void
-walksprite_update(struct walksprite *ws, unsigned ticks)
+walksprite_update(struct walksprite *ws, unsigned int ticks)
 {
 	assert(ws);
 
@@ -51,7 +51,7 @@
 }
 
 void
-walksprite_draw(struct walksprite *ws, uint8_t orientation, int x, int y)
+walksprite_draw(struct walksprite *ws, unsigned int orientation, int x, int y)
 {
 	assert(ws);
 	assert(orientation < 8);
--- a/src/walksprite.h	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/walksprite.h	Wed Jan 15 22:31:17 2020 +0100
@@ -24,8 +24,6 @@
  * \brief Sprite designed for walking entities.
  */
 
-#include <stdint.h>
-
 struct sprite;
 
 /**
@@ -60,9 +58,9 @@
  */
 struct walksprite {
 	struct sprite *sprite;  /*!< (RW) The sprite to use */
-	uint16_t delay;         /*!< (RW) The delay between frames */
-	uint8_t index;          /*!< (RO) Current column index */
-	uint16_t elapsed;       /*!< (RO) Elapsed time since last frame */
+	unsigned int delay;     /*!< (RW) The delay between frames */
+	unsigned int index;     /*!< (RO) Current column index */
+	unsigned int elapsed;   /*!< (RO) Elapsed time since last frame */
 };
 
 /**
@@ -75,7 +73,7 @@
  * \param delay the delay between sprites
  */
 void
-walksprite_init(struct walksprite *ws, struct sprite *sprite, uint16_t delay);
+walksprite_init(struct walksprite *ws, struct sprite *sprite, unsigned int delay);
 
 /**
  * Update the walking sprite
@@ -85,7 +83,7 @@
  * \param ticks the number of milliseconds between last frame
  */
 void
-walksprite_update(struct walksprite *ws, unsigned ticks);
+walksprite_update(struct walksprite *ws, unsigned int ticks);
 
 /**
  * Draw the appropriate sprite cell to the screen according to the orientation
@@ -99,6 +97,6 @@
  * \param y the y coordinate
  */
 void
-walksprite_draw(struct walksprite *ws, uint8_t orientation, int x, int y);
+walksprite_draw(struct walksprite *ws, unsigned int orientation, int x, int y);
 
 #endif /* !MOLKO_WALKSPRITE_H */
--- a/src/window.c	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/window.c	Wed Jan 15 22:31:17 2020 +0100
@@ -31,7 +31,7 @@
 };
 
 bool
-window_init(const char *title, unsigned width, unsigned height)
+window_init(const char *title, unsigned int width, unsigned int height)
 {
 	assert(title);
 
@@ -44,7 +44,7 @@
 	return true;
 }
 
-unsigned
+unsigned int
 window_width(void)
 {
 	int width;
@@ -54,7 +54,7 @@
 	return width;
 }
 
-unsigned
+unsigned int
 window_height(void)
 {
 	int height;
--- a/src/window.h	Wed Jan 15 22:31:17 2020 +0100
+++ b/src/window.h	Wed Jan 15 22:31:17 2020 +0100
@@ -36,14 +36,14 @@
  * \return true on success
  */
 bool
-window_init(const char *title, unsigned width, unsigned height);
+window_init(const char *title, unsigned int width, unsigned int height);
 
 /**
  * Get the current window's width.
  *
  * \return the width
  */
-unsigned
+unsigned int
 window_width(void);
 
 /**
@@ -51,7 +51,7 @@
  *
  * \return the height
  */
-unsigned
+unsigned int
 window_height(void);
 
 /**