RobLoach / RobLoach/raylib-libretro
Replace fixed-size core-variable parallel arrays with MemAlloc'd LibretroCoreVariable array
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 38
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Description
Resolves the existing // TODO: Switch these to MemAlloc'ed strings. in LibretroCoreData. Follow-up from #180.
Core options storage is currently six parallel fixed-size arrays:
char variableKeys[LIBRETRO_MAX_CORE_VARIABLES][LIBRETRO_CORE_VARIABLE_KEY_LEN];
char variableValues[LIBRETRO_MAX_CORE_VARIABLES][LIBRETRO_CORE_VARIABLE_VALUE_LEN];
char variableLabels[LIBRETRO_MAX_CORE_VARIABLES][LIBRETRO_CORE_VARIABLE_LABEL_LEN];
char variableValuesList[LIBRETRO_MAX_CORE_VARIABLES][LIBRETRO_CORE_VARIABLE_VALUES_LEN];
char variableDisplayList[LIBRETRO_MAX_CORE_VARIABLES][LIBRETRO_CORE_VARIABLE_VALUES_LEN];
char variableTooltips[LIBRETRO_MAX_CORE_VARIABLES][LIBRETRO_CORE_VARIABLE_TOOLTIP_LEN];
bool variableVisible[LIBRETRO_MAX_CORE_VARIABLES];
unsigned variableCount;
Issues:
- Bloats
sizeof(LibretroCoreData)by hundreds of KB regardless of actual variable count. - Makes the
memset(0)reset enabled by #180 unnecessarily expensive. - Six parallel arrays are harder to reason about than a single struct.
Proposed:
typedef struct LibretroCoreVariable {
char key[LIBRETRO_CORE_VARIABLE_KEY_LEN];
char value[LIBRETRO_CORE_VARIABLE_VALUE_LEN];
char label[LIBRETRO_CORE_VARIABLE_LABEL_LEN];
char valuesList[LIBRETRO_CORE_VARIABLE_VALUES_LEN];
char displayList[LIBRETRO_CORE_VARIABLE_VALUES_LEN];
char tooltip[LIBRETRO_CORE_VARIABLE_TOOLTIP_LEN];
bool visible;
} LibretroCoreVariable;
typedef struct LibretroCoreData {
// ...
LibretroCoreVariable* variables;
unsigned variableCount;
unsigned variableCapacity;
// ...
} LibretroCoreData;
MemAlloc on first variable, grow as needed, MemFree in CloseLibretro before the trailing ResetLibretroCoreState() memset (so the memset just nulls the pointer).
Touches: LibretroInitCoreVariable, SetLibretroCoreOption, GetLibretroCoreOption, env handlers for RETRO_ENVIRONMENT_SET_VARIABLES / SET_CORE_OPTIONS / SET_CORE_OPTIONS_V2 / option visibility, menu rendering in raylib-libretro-menu.h.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating LibretroCoreData and the LibretroInitCoreVariable, SetLibretroCoreOption, and GetLibretroCoreOption paths, then trace the RETRO_ENVIRONMENT_SET_VARIABLES, SET_CORE_OPTIONS, SET_CORE_OPTIONS_V2, and option-visibility handlers. Review menu rendering in raylib-libretro-menu.h and the CloseLibretro/reset sequence. Done means variable storage is dynamically allocated and freed, all listed callers use the struct array, and reset leaves the state valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- api, frontend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100