Fix the type, macro and state-table defects, and the leftover debris
Closes internal-consistency items 19 through 36, 38 and 41. Item 37, the ~180 redundant casts, is deliberately left open with its reasoning in TODO.md: the benefit only arrives once the build turns on the warnings those casts suppress, and doing it before that is churn across the two files with the most outstanding functional defects. The two that were real bugs are in the actor state table. AKGL_ACTOR_STATE_STRING_NAMES was declared [AKGL_ACTOR_MAX_STATES+1] and defined [32], so a consumer trusting the declared bound read past the object; and indices 11 and 12 were named UNDEFINED_11 and UNDEFINED_12 where actor.h has MOVING_IN and MOVING_OUT, so no character JSON could bind a sprite to either state. tests/registry.c now walks the whole table -- every entry non-NULL, every entry resolving to its own bit, no two entries sharing a name. The bitmask macros are parenthesized and AKGL_BITMASK_CLEAR has lost the semicolon inside its body. Writing tests/bitmasks.c for that turned up something worth knowing: the obvious test does not catch it. For a bit that is set, the misparse `!(mask & bit) == bit` gives the same answer as the correct one. It only diverges for an unset bit whose value is not 1, and that is the shape the suite uses now. akgl_draw_background was the last public function outside the error protocol. It takes a backend like everything else in draw.h, restores the draw colour it found, and is tested -- TODO.md had it filed under "needs the offscreen renderer harness", which was never true; what it needed was to stop reading the global. All eight registry initializers go through one helper, so the seven that leaked an SDL_PropertiesID on every call after the first no longer do. Fixed in the same place because it is the same function: akgl_registry_init never called akgl_registry_init_properties, which made akgl_set_property a silent no-op for anyone not going through akgl_game_init -- Defects, Known and still open item 3. Also: AKGL_COLLIDE_RECTANGLES (three open parens, two closes) and akgl_Frame deleted, float32_t/float64_t used consistently, the developer-specific debug logging removed from the controller inner loop, the abandoned SDL_GetBasePath comments removed, nine unused locals removed, and dst renamed to dest. akgl_game_update's default flags no longer OR the same bit twice. That changes nothing today, and the reason is Performance item 32: the loop never reads either bit, which is why every actor is updated sixteen times a frame. Still open. 25/25 pass, memcheck clean, reindent --check clean. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -71,8 +71,8 @@
|
||||
|
||||
/** @brief One object placed in a Tiled object layer. */
|
||||
typedef struct {
|
||||
float x; /**< Position in map pixels, from the Tiled object. Copied onto the actor it spawns. */
|
||||
float y; /**< Position in map pixels. */
|
||||
float32_t x; /**< Position in map pixels, from the Tiled object. Copied onto the actor it spawns. */
|
||||
float32_t y; /**< Position in map pixels. */
|
||||
int gid; /**< Global tile id, for a tile object. Not read by the loader. */
|
||||
int id; /**< Tiled's object id. Not read by the loader. */
|
||||
int height; /**< Height in map pixels. Read into the map's perspective bands, not into this field. */
|
||||
@@ -87,7 +87,7 @@ typedef struct {
|
||||
/** @brief One layer of a tilemap: a tile grid, an image, or a group of objects. */
|
||||
typedef struct {
|
||||
short type; /**< Which of the `AKGL_TILEMAP_LAYER_TYPE_*` kinds this is; decides which of the members below mean anything. */
|
||||
float opacity; /**< 0.0 to 1.0, from Tiled. Recorded but not yet applied at draw time. */
|
||||
float32_t opacity; /**< 0.0 to 1.0, from Tiled. Recorded but not yet applied at draw time. */
|
||||
bool visible; /**< From Tiled. Recorded but not yet consulted at draw time. */
|
||||
int height; /**< Tile layer: height in tiles. Image layer: the texture's height in pixels. */
|
||||
int width; /**< Tile layer: width in tiles. Image layer: the texture's width in pixels. */
|
||||
@@ -143,10 +143,10 @@ typedef struct {
|
||||
int p_vanishing_y; /**< Y of the `p_vanishing` marker: the row at which actors are smallest. 0 disables perspective. */
|
||||
int p_foreground_h; /**< Height of the `p_foreground` marker object. Recorded; not used in the current rate calculation. */
|
||||
int p_vanishing_h; /**< Height of the `p_vanishing` marker object. Recorded, likewise. */
|
||||
float p_foreground_scale; /**< Actor scale at `p_foreground_y`. Defaults to 1.0. */
|
||||
float p_vanishing_scale; /**< Actor scale at `p_vanishing_y`. Defaults to 1.0. */
|
||||
float p_scale; /**< Unused. Left from an earlier formulation of the perspective maths. */
|
||||
float p_rate; /**< Scale change per pixel of y between the two markers. Derived at load; what akgl_tilemap_scale_actor interpolates with. */
|
||||
float32_t p_foreground_scale; /**< Actor scale at `p_foreground_y`. Defaults to 1.0. */
|
||||
float32_t p_vanishing_scale; /**< Actor scale at `p_vanishing_y`. Defaults to 1.0. */
|
||||
float32_t p_scale; /**< Unused. Left from an earlier formulation of the perspective maths. */
|
||||
float32_t p_rate; /**< Scale change per pixel of y between the two markers. Derived at load; what akgl_tilemap_scale_actor interpolates with. */
|
||||
akgl_Tileset tilesets[AKGL_TILEMAP_MAX_TILESETS]; /**< The tilesets, in the order Tiled listed them. */
|
||||
akgl_TilemapLayer layers[AKGL_TILEMAP_MAX_LAYERS]; /**< The layers, in draw order: index 0 is furthest back. */
|
||||
|
||||
@@ -505,7 +505,7 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_scale_actor(akgl_Tilemap *map, a
|
||||
* not numeric.
|
||||
* @throws AKGL_ERR_HEAP If the string pool is exhausted.
|
||||
*/
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_properties_number(json_t *obj, char *key, float *dest);
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_properties_number(json_t *obj, char *key, float32_t *dest);
|
||||
/**
|
||||
* @brief Read a Tiled custom property declared as `float`.
|
||||
*
|
||||
@@ -522,7 +522,7 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_properties_number(json_t *obj,
|
||||
* not numeric.
|
||||
* @throws AKGL_ERR_HEAP If the string pool is exhausted.
|
||||
*/
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_properties_float(json_t *obj, char *key, float *dest);
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_properties_float(json_t *obj, char *key, float32_t *dest);
|
||||
/**
|
||||
* @brief Read a Tiled custom property declared as `float`, at full precision.
|
||||
*
|
||||
@@ -541,7 +541,7 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_properties_float(json_t *obj, c
|
||||
* not numeric.
|
||||
* @throws AKGL_ERR_HEAP If the string pool is exhausted.
|
||||
*/
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_properties_double(json_t *obj, char *key, double *dest);
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_properties_double(json_t *obj, char *key, float64_t *dest);
|
||||
/**
|
||||
* @brief Turn one Tiled object into a live actor, creating it if it is not already registered.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user