Cleaned settings a bit
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#include "system/system.h"
|
#include "system/system.h"
|
||||||
#include "console/console.h"
|
#include "console/console.h"
|
||||||
#include "save/save.h"
|
#include "save/save.h"
|
||||||
|
#include "save/savesettings.h"
|
||||||
|
|
||||||
engine_t ENGINE;
|
engine_t ENGINE;
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ errorret_t engineInit(const int32_t argc, const char_t **argv) {
|
|||||||
errorChain(inputInit());
|
errorChain(inputInit());
|
||||||
errorChain(assetInit());
|
errorChain(assetInit());
|
||||||
errorChain(saveInit());
|
errorChain(saveInit());
|
||||||
errorChain(inputLoadSettings());
|
errorChain(saveSettingsLoad());
|
||||||
errorChain(localeManagerInit());
|
errorChain(localeManagerInit());
|
||||||
errorChain(displayInit());
|
errorChain(displayInit());
|
||||||
errorChain(uiInit());
|
errorChain(uiInit());
|
||||||
|
|||||||
@@ -11,8 +11,6 @@
|
|||||||
#include "util/string.h"
|
#include "util/string.h"
|
||||||
#include "util/math.h"
|
#include "util/math.h"
|
||||||
#include "time/time.h"
|
#include "time/time.h"
|
||||||
#include "event/event.h"
|
|
||||||
#include "save/save.h"
|
|
||||||
|
|
||||||
input_t INPUT;
|
input_t INPUT;
|
||||||
|
|
||||||
@@ -24,20 +22,6 @@ errorret_t inputInit(void) {
|
|||||||
INPUT.actions[i].action = (inputaction_t)i;
|
INPUT.actions[i].action = (inputaction_t)i;
|
||||||
INPUT.actions[i].lastValue = 0.0f;
|
INPUT.actions[i].lastValue = 0.0f;
|
||||||
INPUT.actions[i].currentValue = 0.0f;
|
INPUT.actions[i].currentValue = 0.0f;
|
||||||
|
|
||||||
eventInit(
|
|
||||||
&INPUT.actions[i].onPressed,
|
|
||||||
INPUT.actions[i].onPressedCallbacks,
|
|
||||||
INPUT.actions[i].onPressedUsers,
|
|
||||||
INPUT_ACTION_CALLBACK_COUNT_MAX
|
|
||||||
);
|
|
||||||
|
|
||||||
eventInit(
|
|
||||||
&INPUT.actions[i].onReleased,
|
|
||||||
INPUT.actions[i].onReleasedCallbacks,
|
|
||||||
INPUT.actions[i].onReleasedUsers,
|
|
||||||
INPUT_ACTION_CALLBACK_COUNT_MAX
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef inputInitPlatform
|
#ifdef inputInitPlatform
|
||||||
@@ -47,43 +31,6 @@ errorret_t inputInit(void) {
|
|||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
errorret_t inputSaveSettings(void) {
|
|
||||||
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
|
|
||||||
yyjson_mut_val *root = yyjson_mut_obj(doc);
|
|
||||||
yyjson_mut_doc_set_root(doc, root);
|
|
||||||
|
|
||||||
yyjson_mut_val *settings = yyjson_mut_obj(doc);
|
|
||||||
yyjson_mut_obj_add_val(doc, root, "settings", settings);
|
|
||||||
|
|
||||||
yyjson_mut_val *inputSettings = yyjson_mut_obj(doc);
|
|
||||||
yyjson_mut_obj_add_val(doc, settings, "input", inputSettings);
|
|
||||||
|
|
||||||
yyjson_mut_obj_add_real(doc, inputSettings, "deadzone", INPUT.deadzone);
|
|
||||||
|
|
||||||
errorret_t ret = saveWrite(SAVE_SETTINGS_SLOT, doc);
|
|
||||||
yyjson_mut_doc_free(doc);
|
|
||||||
|
|
||||||
if(errorIsNotOk(ret)) return ret;
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
errorret_t inputLoadSettings(void) {
|
|
||||||
yyjson_doc *doc = NULL;
|
|
||||||
errorChain(saveLoad(SAVE_SETTINGS_SLOT, &doc));
|
|
||||||
|
|
||||||
if(!doc) errorOk();
|
|
||||||
|
|
||||||
yyjson_val *root = yyjson_doc_get_root(doc);
|
|
||||||
yyjson_val *settings = yyjson_obj_get(root, "settings");
|
|
||||||
yyjson_val *inputSettings = yyjson_obj_get(settings, "input");
|
|
||||||
yyjson_val *deadzone = yyjson_obj_get(inputSettings, "deadzone");
|
|
||||||
|
|
||||||
if(deadzone) INPUT.deadzone = (float_t)yyjson_get_num(deadzone);
|
|
||||||
|
|
||||||
yyjson_doc_free(doc);
|
|
||||||
errorOk();
|
|
||||||
}
|
|
||||||
|
|
||||||
void inputUpdate(void) {
|
void inputUpdate(void) {
|
||||||
#ifdef inputUpdatePlatform
|
#ifdef inputUpdatePlatform
|
||||||
inputUpdatePlatform();
|
inputUpdatePlatform();
|
||||||
@@ -136,18 +83,6 @@ void inputUpdate(void) {
|
|||||||
|
|
||||||
cur++;
|
cur++;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DUSK_TIME_DYNAMIC
|
|
||||||
if(TIME.dynamicUpdate) return;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for(uint8_t i = INPUT_ACTION_NULL + 1; i < INPUT_ACTION_COUNT; i++) {
|
|
||||||
inputactiondata_t *act = &INPUT.actions[i];
|
|
||||||
bool_t isDown = act->currentValue > 0.0f;
|
|
||||||
bool_t wasDown = act->lastValue > 0.0f;
|
|
||||||
if(isDown && !wasDown) eventInvoke(&act->onPressed, act);
|
|
||||||
if(!isDown && wasDown) eventInvoke(&act->onReleased, act);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float_t inputGetCurrentValue(const inputaction_t action) {
|
float_t inputGetCurrentValue(const inputaction_t action) {
|
||||||
|
|||||||
@@ -37,23 +37,6 @@ errorret_t inputInit(void);
|
|||||||
*/
|
*/
|
||||||
void inputUpdate(void);
|
void inputUpdate(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* Persists the current input settings (currently just the gamepad
|
|
||||||
* deadzone) to the save system as JSON, under settings.input.
|
|
||||||
*
|
|
||||||
* @return An error code if serialization or the write fails.
|
|
||||||
*/
|
|
||||||
errorret_t inputSaveSettings(void);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Loads input settings (currently just the gamepad deadzone) from the
|
|
||||||
* save system's JSON payload under settings.input and applies them to
|
|
||||||
* INPUT. Leaves INPUT unchanged if no settings file exists yet.
|
|
||||||
*
|
|
||||||
* @return An error code if the load or parse fails.
|
|
||||||
*/
|
|
||||||
errorret_t inputLoadSettings(void);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the current value of a specific input action.
|
* Gets the current value of a specific input action.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -8,9 +8,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "time/time.h"
|
#include "time/time.h"
|
||||||
#include "input/inputactiondefs.h"
|
#include "input/inputactiondefs.h"
|
||||||
#include "event/event.h"
|
|
||||||
|
|
||||||
#define INPUT_ACTION_CALLBACK_COUNT_MAX 4
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
inputaction_t action;
|
inputaction_t action;
|
||||||
@@ -21,13 +18,6 @@ typedef struct {
|
|||||||
float_t lastDynamicValue;
|
float_t lastDynamicValue;
|
||||||
float_t currentDynamicValue;
|
float_t currentDynamicValue;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
eventcallback_t onPressedCallbacks[INPUT_ACTION_CALLBACK_COUNT_MAX];
|
|
||||||
void *onPressedUsers[INPUT_ACTION_CALLBACK_COUNT_MAX];
|
|
||||||
event_t onPressed;
|
|
||||||
eventcallback_t onReleasedCallbacks[INPUT_ACTION_CALLBACK_COUNT_MAX];
|
|
||||||
void *onReleasedUsers[INPUT_ACTION_CALLBACK_COUNT_MAX];
|
|
||||||
event_t onReleased;
|
|
||||||
} inputactiondata_t;
|
} inputactiondata_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
|||||||
PUBLIC
|
PUBLIC
|
||||||
save.c
|
save.c
|
||||||
savestream.c
|
savestream.c
|
||||||
|
savesettings.c
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "save/savesettings.h"
|
||||||
|
#include "save/save.h"
|
||||||
|
#include "input/input.h"
|
||||||
|
|
||||||
|
errorret_t saveSettingsWrite(void) {
|
||||||
|
yyjson_mut_doc *doc = yyjson_mut_doc_new(NULL);
|
||||||
|
yyjson_mut_val *root = yyjson_mut_obj(doc);
|
||||||
|
yyjson_mut_doc_set_root(doc, root);
|
||||||
|
|
||||||
|
yyjson_mut_val *settings = yyjson_mut_obj(doc);
|
||||||
|
yyjson_mut_obj_add_val(doc, root, "settings", settings);
|
||||||
|
|
||||||
|
yyjson_mut_val *input = yyjson_mut_obj(doc);
|
||||||
|
yyjson_mut_obj_add_val(doc, settings, "input", input);
|
||||||
|
yyjson_mut_obj_add_real(doc, input, "deadzone", INPUT.deadzone);
|
||||||
|
|
||||||
|
errorret_t ret = saveWrite(SAVE_SETTINGS_SLOT, doc);
|
||||||
|
yyjson_mut_doc_free(doc);
|
||||||
|
|
||||||
|
if(errorIsNotOk(ret)) return ret;
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
|
|
||||||
|
errorret_t saveSettingsLoad(void) {
|
||||||
|
yyjson_doc *doc = NULL;
|
||||||
|
errorChain(saveLoad(SAVE_SETTINGS_SLOT, &doc));
|
||||||
|
|
||||||
|
if(!doc) errorOk();
|
||||||
|
|
||||||
|
yyjson_val *root = yyjson_doc_get_root(doc);
|
||||||
|
yyjson_val *settings = yyjson_obj_get(root, "settings");
|
||||||
|
yyjson_val *input = yyjson_obj_get(settings, "input");
|
||||||
|
yyjson_val *deadzone = yyjson_obj_get(input, "deadzone");
|
||||||
|
|
||||||
|
if(deadzone) INPUT.deadzone = (float_t)yyjson_get_num(deadzone);
|
||||||
|
|
||||||
|
yyjson_doc_free(doc);
|
||||||
|
errorOk();
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "error/error.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gathers all game settings (currently just the input gamepad deadzone)
|
||||||
|
* from their owning runtime state and persists them to the save system
|
||||||
|
* as JSON, under settings.<domain>. Nothing is retained after this call
|
||||||
|
* returns - the JSON is built and written fresh every time.
|
||||||
|
*
|
||||||
|
* @return An error code if serialization or the write fails.
|
||||||
|
*/
|
||||||
|
errorret_t saveSettingsWrite(void);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads all game settings from the save system's JSON payload and
|
||||||
|
* applies them directly to their owning runtime state (e.g.
|
||||||
|
* INPUT.deadzone). Leaves runtime state unchanged if no settings file
|
||||||
|
* exists yet. Nothing is retained after this call returns.
|
||||||
|
*
|
||||||
|
* @return An error code if the load or parse fails.
|
||||||
|
*/
|
||||||
|
errorret_t saveSettingsLoad(void);
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "locale/localemanager.h"
|
#include "locale/localemanager.h"
|
||||||
#include "asset/loader/locale/assetlocaleloader.h"
|
#include "asset/loader/locale/assetlocaleloader.h"
|
||||||
#include "input/input.h"
|
#include "input/input.h"
|
||||||
|
#include "save/savesettings.h"
|
||||||
|
|
||||||
void uiSettingsInputSelected(
|
void uiSettingsInputSelected(
|
||||||
const uimenu_t *menu,
|
const uimenu_t *menu,
|
||||||
@@ -66,7 +67,7 @@ void uiSettingsInputApply(void) {
|
|||||||
&UI_SETTINGS.data.input.items[UI_SETTINGS_INPUT_INDEX_DEADZONE].slider
|
&UI_SETTINGS.data.input.items[UI_SETTINGS_INPUT_INDEX_DEADZONE].slider
|
||||||
);
|
);
|
||||||
#endif
|
#endif
|
||||||
errorCatch(errorPrint(inputSaveSettings()));
|
errorCatch(errorPrint(saveSettingsWrite()));
|
||||||
uiMenuClose(&UI_SETTINGS.data.input.menu);
|
uiMenuClose(&UI_SETTINGS.data.input.menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user