Game Scores
Source: src/game_scores.c · 51 lines · 3 functions.
Module entry points
These functions are exposed to the rest of the project. Open one to follow its decisions and the helpers it calls.
How to read these diagrams
Each function has its own expandable diagram using the actual expressions and statements from this file. Decisions split into True and False; loop bodies are indented. Returns end the function immediately; break and continue follow their C meanings. Arrows between statements show their order when execution reaches them.
These are structural source diagrams before preprocessing, not runtime traces. Conditional compilation and macros remain source expressions. Ternary choices remain inside their statement. Calls are linked separately; callback execution and task scheduling are not inferred.
Functions in this file
game_scores_load() · source line 16
game_score_result_t game_scores_load(game_score_id_t game, game_scores_t *scores)
Calls into this documentation:
- Decision
scores == NULLTrue- Exit this function
return SCORES_INVALID;
FalseContinue after this decision.
- Execute
*scores = (game_scores_t){0}; - Decision
(unsigned)game >= GAME_SCORE_COUNTTrue- Exit this function
return SCORES_INVALID;
FalseContinue after this decision.
- Execute
results_record_t record = {0}; - Execute
bool found = false; - Decision
!game_storage_read(RESULTS_NAMESPACE, results_keys[game], &record, sizeof(record), &found)True- Exit this function
return SCORES_IO_ERROR;
FalseContinue after this decision.
- Decision
!foundTrue- Exit this function
return SCORES_NOT_FOUND;
FalseContinue after this decision.
- Decision
record.version != 1UTrue- Exit this function
return SCORES_INVALID;
FalseContinue after this decision.
- Execute
*scores = record.scores; - Exit this function
return SCORES_OK;
Read original function source
game_score_result_t game_scores_load(game_score_id_t game, game_scores_t *scores)
{
if (scores == NULL) return SCORES_INVALID;
*scores = (game_scores_t){0};
if ((unsigned)game >= GAME_SCORE_COUNT) return SCORES_INVALID;
results_record_t record = {0};
bool found = false;
if (!game_storage_read(RESULTS_NAMESPACE, results_keys[game], &record, sizeof(record), &found)) {
return SCORES_IO_ERROR;
}
if (!found) return SCORES_NOT_FOUND;
if (record.version != 1U) return SCORES_INVALID;
*scores = record.scores;
return SCORES_OK;
}game_scores_save() · source line 32
bool game_scores_save(game_score_id_t game, const game_scores_t *scores)
Calls into this documentation:
- Decision
scores == NULL || (unsigned)game >= GAME_SCORE_COUNTTrue- Exit this function
return false;
FalseContinue after this decision.
- Execute
game_scores_t previous; - Execute
const game_score_result_t loaded = game_scores_load(game, &previous); - Decision
loaded != SCORES_OK && loaded != SCORES_NOT_FOUNDTrue- Exit this function
return false;
FalseContinue after this decision.
- Execute
const results_record_t record = {1U, *scores}; - Exit this function
return game_storage_write(RESULTS_NAMESPACE, results_keys[game], &record, sizeof(record));
Read original function source
bool game_scores_save(game_score_id_t game, const game_scores_t *scores)
{
if (scores == NULL || (unsigned)game >= GAME_SCORE_COUNT) return false;
game_scores_t previous;
const game_score_result_t loaded = game_scores_load(game, &previous);
if (loaded != SCORES_OK && loaded != SCORES_NOT_FOUND) return false;
const results_record_t record = {1U, *scores};
return game_storage_write(RESULTS_NAMESPACE, results_keys[game], &record, sizeof(record));
}game_scores_status_text() · source line 42
const char *game_scores_status_text(game_score_result_t result)
- Select a case
resultEnter matching case; follow source fall-through until a break, return or end.
- Case / label
case SCORES_OK: - Exit this function
return "SCORES OK"; - Case / label
case SCORES_NOT_FOUND: - Exit this function
return "NO SCORES YET"; - Case / label
case SCORES_UNAVAILABLE: - Exit this function
return "STORAGE UNAVAILABLE"; - Case / label
case SCORES_INVALID: - Exit this function
return "SCORE DATA ERROR"; - Case / label
default: - Exit this function
return "SCORE IO ERROR";
Read original function source
const char *game_scores_status_text(game_score_result_t result)
{
switch (result) {
case SCORES_OK: return "SCORES OK";
case SCORES_NOT_FOUND: return "NO SCORES YET";
case SCORES_UNAVAILABLE: return "STORAGE UNAVAILABLE";
case SCORES_INVALID: return "SCORE DATA ERROR";
default: return "SCORE IO ERROR";
}
}Complete original file, including constants and data
/* Coded By JD(2026) */
#error "Reference listing only — not provided as build-ready source."
#include "game_scores.h"
#include "game_storage.h"
// All game results use NVS; existing records retain their format and keys.
#define RESULTS_NAMESPACE "arcade_results"
typedef struct {
uint32_t version;
game_scores_t scores;
} results_record_t;
_Static_assert(sizeof(results_record_t) == 20, "Results record layout changed");
static const char *results_keys[GAME_SCORE_COUNT] = {
"checkers", "othello", "connect_four", "battleships", "yahtzee",
};
game_score_result_t game_scores_load(game_score_id_t game, game_scores_t *scores)
{
if (scores == NULL) return SCORES_INVALID;
*scores = (game_scores_t){0};
if ((unsigned)game >= GAME_SCORE_COUNT) return SCORES_INVALID;
results_record_t record = {0};
bool found = false;
if (!game_storage_read(RESULTS_NAMESPACE, results_keys[game], &record, sizeof(record), &found)) {
return SCORES_IO_ERROR;
}
if (!found) return SCORES_NOT_FOUND;
if (record.version != 1U) return SCORES_INVALID;
*scores = record.scores;
return SCORES_OK;
}
bool game_scores_save(game_score_id_t game, const game_scores_t *scores)
{
if (scores == NULL || (unsigned)game >= GAME_SCORE_COUNT) return false;
game_scores_t previous;
const game_score_result_t loaded = game_scores_load(game, &previous);
if (loaded != SCORES_OK && loaded != SCORES_NOT_FOUND) return false;
const results_record_t record = {1U, *scores};
return game_storage_write(RESULTS_NAMESPACE, results_keys[game], &record, sizeof(record));
}
const char *game_scores_status_text(game_score_result_t result)
{
switch (result) {
case SCORES_OK: return "SCORES OK";
case SCORES_NOT_FOUND: return "NO SCORES YET";
case SCORES_UNAVAILABLE: return "STORAGE UNAVAILABLE";
case SCORES_INVALID: return "SCORE DATA ERROR";
default: return "SCORE IO ERROR";
}
}