Document what the functions actually do instead of that they can fail
The Doxygen comments were generated from the declarations, so 217 @throws lines across 21 headers read "When the corresponding validation or operation fails" and told a caller nothing beyond the status name. The @param lines were the same shape: every output was "Output destination populated by the function", every instance "Object to initialize, inspect, or modify". Rewritten against the implementations, following the pattern libakstdlib already uses: - @throws names the condition. akgl_sprite_load_json separated AKERR_KEY (absent) from AKERR_TYPE (present, wrong type) from AKERR_OUTOFBOUNDS (filename too long, or array indexed past its end), and gained AKGL_ERR_SDL and AKGL_ERR_HEAP, which it raises and never declared. - Parameters say whether they are required, what a NULL means, and what is written on a failure path. Where an argument is not checked, the doc says so: akgl_heap_next_actor's dest is a crash on NULL, not an error, and akgl_render_2d_frame_start dereferences self before testing it. - The conventions move up to the file blocks so the per-function docs stay short. json_helpers.h states once that absence is an error here and that json_t * results are borrowed; heap.h explains the pool model and the acquire asymmetry; physics.h carries the thrust/environmental/velocity table. - Struct fields, enum values, macros and exported globals are documented, including the dead ones - sprite_w/sprite_h, movetimer, p_scale and timer_gravity are read by nothing, and say so. Also fixes ten comments in error.h and audio.h that opened with /** rather than /**<, so Doxygen attached them to the following entity and rendered the text as part of the macro's value. Verified against the generated HTML. Comments only - no declaration changed. Doxygen builds clean under WARN_AS_ERROR, scripts/reindent.sh --check passes, 19/19 suites pass. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
156
src/game.c
156
src/game.c
@@ -190,10 +190,24 @@ void akgl_game_updateFPS()
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Serializes an actor name-to-pointer entry.
|
||||
* @param userdata Open output stream supplied by the caller.
|
||||
* @param props Actor registry being iterated.
|
||||
* @param name Actor registry key to serialize.
|
||||
* @brief Write one actor's name and save-time address to the name table.
|
||||
*
|
||||
* An `SDL_EnumerateProperties` callback. The name is written at a fixed
|
||||
* #AKGL_ACTOR_MAX_NAME_LENGTH bytes so the reader can walk the table without a
|
||||
* length prefix, and the pointer is written raw -- it is not a pointer the
|
||||
* loader will ever dereference, only a key it maps back to the object that has
|
||||
* the same name next run.
|
||||
*
|
||||
* @param userdata The open output stream, as a `FILE *`. Required.
|
||||
* @param props #AKGL_REGISTRY_ACTOR, supplied by SDL.
|
||||
* @param name The actor's registry key. Read for
|
||||
* #AKGL_ACTOR_MAX_NAME_LENGTH bytes regardless of its actual
|
||||
* length, so a shorter key is read past its end.
|
||||
*
|
||||
* @warning Ends in `FINISH_NORETURN`: an unhandled error here logs a stack trace
|
||||
* and then calls libakerror's unhandled-error handler, which by default
|
||||
* **exits the process**. A failed write during a save terminates the
|
||||
* game rather than returning an error.
|
||||
*/
|
||||
void akgl_game_save_actorname_iterator(void *userdata, SDL_PropertiesID props, const char *name)
|
||||
{
|
||||
@@ -211,10 +225,17 @@ void akgl_game_save_actorname_iterator(void *userdata, SDL_PropertiesID props, c
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Game save spritename iterator.
|
||||
* @param userdata Caller data supplied to the SDL property iterator.
|
||||
* @param props SDL property collection being iterated.
|
||||
* @param name Registry key or human-readable object name.
|
||||
* @brief Write one sprite's name and save-time address to the name table.
|
||||
*
|
||||
* As akgl_game_save_actorname_iterator, but the name field is
|
||||
* #AKGL_SPRITE_MAX_NAME_LENGTH wide.
|
||||
*
|
||||
* @param userdata The open output stream, as a `FILE *`. Required.
|
||||
* @param props #AKGL_REGISTRY_SPRITE, supplied by SDL.
|
||||
* @param name The sprite's registry key, written at fixed width.
|
||||
*
|
||||
* @warning Terminates the process on an unhandled error. See
|
||||
* akgl_game_save_actorname_iterator.
|
||||
*/
|
||||
void akgl_game_save_spritename_iterator(void *userdata, SDL_PropertiesID props, const char *name)
|
||||
{
|
||||
@@ -232,10 +253,21 @@ void akgl_game_save_spritename_iterator(void *userdata, SDL_PropertiesID props,
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Game save spritesheetname iterator.
|
||||
* @param userdata Caller data supplied to the SDL property iterator.
|
||||
* @param props SDL property collection being iterated.
|
||||
* @param name Registry key or human-readable object name.
|
||||
* @brief Write one spritesheet's name and save-time address to the name table.
|
||||
*
|
||||
* As akgl_game_save_actorname_iterator, but the name field is
|
||||
* #AKGL_SPRITE_SHEET_MAX_FILENAME_LENGTH wide -- the widest of the four, since
|
||||
* a spritesheet is keyed by its resolved path.
|
||||
*
|
||||
* @param userdata The open output stream, as a `FILE *`. Required.
|
||||
* @param props #AKGL_REGISTRY_SPRITESHEET, supplied by SDL.
|
||||
* @param name The spritesheet's registry key, written at fixed width.
|
||||
*
|
||||
* @warning Terminates the process on an unhandled error. See
|
||||
* akgl_game_save_actorname_iterator.
|
||||
* @note This is the table the loader disagrees with: it reads every table at
|
||||
* #AKGL_ACTOR_MAX_NAME_LENGTH, so a save containing any spritesheet cannot
|
||||
* be read back. TODO.md, "Known and still open" item 7.
|
||||
*/
|
||||
void akgl_game_save_spritesheetname_iterator(void *userdata, SDL_PropertiesID props, const char *name)
|
||||
{
|
||||
@@ -253,10 +285,17 @@ void akgl_game_save_spritesheetname_iterator(void *userdata, SDL_PropertiesID pr
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Game save charactername iterator.
|
||||
* @param userdata Caller data supplied to the SDL property iterator.
|
||||
* @param props SDL property collection being iterated.
|
||||
* @param name Registry key or human-readable object name.
|
||||
* @brief Write one character's name and save-time address to the name table.
|
||||
*
|
||||
* As akgl_game_save_actorname_iterator, but the name field is
|
||||
* #AKGL_SPRITE_MAX_CHARACTER_NAME_LENGTH wide.
|
||||
*
|
||||
* @param userdata The open output stream, as a `FILE *`. Required.
|
||||
* @param props #AKGL_REGISTRY_CHARACTER, supplied by SDL.
|
||||
* @param name The character's registry key, written at fixed width.
|
||||
*
|
||||
* @warning Terminates the process on an unhandled error. See
|
||||
* akgl_game_save_actorname_iterator.
|
||||
*/
|
||||
void akgl_game_save_charactername_iterator(void *userdata, SDL_PropertiesID props, const char *name)
|
||||
{
|
||||
@@ -274,10 +313,23 @@ void akgl_game_save_charactername_iterator(void *userdata, SDL_PropertiesID prop
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Game save actors.
|
||||
* @param fp Open save-game stream.
|
||||
* @brief Write all four name-to-address tables, each with its terminator.
|
||||
*
|
||||
* Actors, sprites, spritesheets, characters, in that order -- which is the order
|
||||
* akgl_game_load reads them back in. Each table is the registry enumerated one
|
||||
* entry at a time, followed by a zeroed name field and a zeroed pointer that the
|
||||
* reader stops on.
|
||||
*
|
||||
* @param fp The open save-game stream. Required.
|
||||
* @return `NULL` on success, otherwise an error context owned by the caller.
|
||||
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
||||
* @throws AKERR_NULLPOINTER If @p fp is `NULL`.
|
||||
* @throws AKERR_IO On a stream error or a short write while emitting a
|
||||
* terminator.
|
||||
*
|
||||
* @note Only the terminators are written through the error-reporting path. The
|
||||
* entries themselves go through `SDL_EnumerateProperties`, whose callbacks
|
||||
* cannot report failure upward and instead terminate the process -- so a
|
||||
* write error mid-table never reaches this function's return value.
|
||||
*/
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_game_save_actors(FILE *fp)
|
||||
{
|
||||
@@ -352,14 +404,40 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_game_save(char *fpath)
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Game load objectnamemap.
|
||||
* @param fp Open save-game stream.
|
||||
* @param map Tilemap to inspect, draw, or modify.
|
||||
* @param namelength Fixed serialized name-field length.
|
||||
* @param ptrlength Serialized pointer-field length.
|
||||
* @param registry SDL property registry being queried.
|
||||
* @brief Read one name table back, building an old-address to current-object map.
|
||||
*
|
||||
* This is the mechanism that makes a save file portable across runs. Objects are
|
||||
* serialized carrying the addresses they had at save time; those addresses mean
|
||||
* nothing now, but the table says which *name* lived at each one, and the name
|
||||
* still resolves through the registry. So each entry becomes
|
||||
* `"0x7f..." -> current object`, and a deserialized pointer can be translated by
|
||||
* looking up its printed form.
|
||||
*
|
||||
* The keys are the old pointers rendered with `%p`, because SDL property sets
|
||||
* take string keys only.
|
||||
*
|
||||
* Reading stops at the terminator -- a zeroed name and a zeroed pointer.
|
||||
*
|
||||
* @param fp The open save-game stream, positioned at the start of a
|
||||
* table. Required.
|
||||
* @param map The property set to fill in. Required, and created by the
|
||||
* caller.
|
||||
* @param namelength Width of the table's name field, which must match what the
|
||||
* corresponding save iterator wrote. It also sizes a
|
||||
* variable-length array on the stack.
|
||||
* @param ptrlength Width of the table's pointer field, i.e. `sizeof` the
|
||||
* pointer type that table holds.
|
||||
* @param registry The registry to resolve names against -- #AKGL_REGISTRY_ACTOR
|
||||
* for the actor table, and so on.
|
||||
* @return `NULL` on success, otherwise an error context owned by the caller.
|
||||
* @throws AKERR_* Propagates an error reported by a delegated operation.
|
||||
* @throws AKERR_EOF If the stream ends before a terminator is found, which is
|
||||
* what a truncated save file looks like.
|
||||
* @throws AKERR_IO On a stream error.
|
||||
* @throws AKERR_NULLPOINTER If @p fp is `NULL`, by way of the read wrapper.
|
||||
*
|
||||
* @note A name in the table that is no longer in @p registry maps to `NULL`
|
||||
* rather than being reported: the entry is written with whatever
|
||||
* `SDL_GetPointerProperty` returned.
|
||||
*/
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_game_load_objectnamemap(FILE *fp, SDL_PropertiesID map, int namelength, int ptrlength, SDL_PropertiesID registry)
|
||||
{
|
||||
@@ -406,14 +484,24 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_game_load_objectnamemap(FILE *fp, SDL_Pr
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Game load versioncmp.
|
||||
* @param versiontype Description of the version being compared.
|
||||
* @param newversion Version read from the save data.
|
||||
* @param curversion Version supported by the running library.
|
||||
* @return `NULL` on success, otherwise an error context owned by the caller.
|
||||
* @throws AKERR_API When the corresponding validation or operation fails.
|
||||
* @throws AKERR_NULLPOINTER When the corresponding validation or operation fails.
|
||||
* @throws AKERR_VALUE When the corresponding validation or operation fails.
|
||||
* @brief Refuse a save file unless its version matches the running one exactly.
|
||||
*
|
||||
* Both strings are parsed as semver and compared with `"="` -- exact equality,
|
||||
* not compatibility. That is deliberate and strict: a save file is a raw memory
|
||||
* image of `akgl_Game` and the object tables, so any change to a struct layout
|
||||
* invalidates it, and semver has no way to say "the layout did not move".
|
||||
*
|
||||
* @param versiontype What is being compared -- `"library"` or `"game"`. Used
|
||||
* only to build the message, but required, since a bare
|
||||
* "incompatible version" error would not say which.
|
||||
* @param newversion The version read out of the save file. Required.
|
||||
* @param curversion The version of the running program or library. Required.
|
||||
* @return `NULL` when the two match, otherwise an error context owned by the
|
||||
* caller.
|
||||
* @throws AKERR_NULLPOINTER If any of the three arguments is `NULL`.
|
||||
* @throws AKERR_VALUE If either string is not valid semver. The message says
|
||||
* which side it came from.
|
||||
* @throws AKERR_API If both parse but are not equal. The message quotes both.
|
||||
*/
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_game_load_versioncmp(char *versiontype, char *newversion, char *curversion)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user