@@ -40,3 +40,6 @@ | |||
[submodule "subprojects/midi-utils"] | |||
path = subprojects/midi-utils | |||
url = https://code.modal.sh/TheoryOfNekomata/midi-utils.git | |||
[submodule "subprojects/ini-config"] | |||
path = subprojects/ini-config | |||
url = https://code.modal.sh/TheoryOfNekomata/ini-config.git |
@@ -67,7 +67,8 @@ include_directories( | |||
"${CMAKE_HOME_DIRECTORY}/dependencies/SDL2_image" | |||
"${CMAKE_HOME_DIRECTORY}/dependencies/SDL2_image/include" | |||
"${CMAKE_HOME_DIRECTORY}/dependencies/SDL2_ttf/include" | |||
"${CMAKE_HOME_DIRECTORY}/subprojects/minIni/dev" | |||
"${CMAKE_HOME_DIRECTORY}/subprojects/ini-config/subprojects/minIni/dev" | |||
"${CMAKE_HOME_DIRECTORY}/subprojects/ini-config" | |||
"${CMAKE_HOME_DIRECTORY}/subprojects/bdd-for-c" | |||
"${CMAKE_HOME_DIRECTORY}/subprojects/bdd-for-c-mocks" | |||
"${CMAKE_HOME_DIRECTORY}/subprojects/midi-utils" | |||
@@ -137,8 +138,10 @@ endif() | |||
add_executable( | |||
game | |||
${IZ_EXECUTABLE_TYPE} | |||
subprojects/minIni/dev/minIni.h | |||
subprojects/minIni/dev/minIni.c | |||
subprojects/ini-config/subprojects/minIni/dev/minIni.h | |||
subprojects/ini-config/subprojects/minIni/dev/minIni.c | |||
subprojects/ini-config/ini-config.h | |||
subprojects/ini-config/ini-config.c | |||
subprojects/midi-utils/midi-utils.h | |||
subprojects/midi-utils/midi-utils.c | |||
${IZ_GETOPT_DEPENDENCIES} | |||
@@ -153,8 +156,6 @@ add_executable( | |||
src/packages/game/input/IZ_joystick.h | |||
src/packages/game/input/IZ_keyboard.c | |||
src/packages/game/input/IZ_keyboard.h | |||
src/packages/config/IZ_config.c | |||
src/packages/config/IZ_config.h | |||
src/packages/game/geometry/IZ_vector2d.c | |||
src/packages/game/geometry/IZ_vector2d.h | |||
src/packages/game/geometry/IZ_rect.c | |||
@@ -203,6 +204,8 @@ add_executable( | |||
src/packages/compat/IZ_compat.h | |||
src/packages/stdinc/IZ_stdlib.c | |||
src/packages/stdinc/IZ_stdlib.h | |||
src/packages/config/IZ_config_guid.c | |||
src/packages/config/IZ_config_guid.h | |||
) | |||
target_link_libraries( | |||
@@ -225,7 +228,7 @@ add_executable( | |||
src/packages/game/geometry/IZ_rect.c | |||
src/packages/game/geometry/IZ_vector2d.h | |||
src/packages/game/geometry/IZ_vector2d.c | |||
__tests__/src/packages/game/geometry.test.c | |||
__tests__/src/packages/game/geometry.test.c | |||
) | |||
add_executable( | |||
@@ -240,8 +243,6 @@ add_executable( | |||
__mocks__/subprojects/SDL/SDL_stdinc.mock.h | |||
__mocks__/subprojects/portmidi/portmidi.mock.h | |||
src/packages/config/IZ_config.h | |||
src/packages/game/input/IZ_keyboard.h | |||
src/packages/game/input/IZ_keyboard.c | |||
@@ -260,7 +261,7 @@ add_executable( | |||
src/packages/stdinc/IZ_stdlib.h | |||
__mocks__/src/packages/stdinc/IZ_stdlib.mock.h | |||
__tests__/src/packages/game/input.test.c | |||
__tests__/src/packages/game/input.test.c | |||
__mocks__/src/packages/config/IZ_config.mock.h | |||
) | |||
@@ -279,10 +280,9 @@ add_executable( | |||
__mocks__/subprojects/SDL/SDL_stdinc.mock.h | |||
__mocks__/subprojects/SDL/SDL_render.mock.h | |||
src/packages/config/IZ_config.h | |||
src/packages/game/output/video/IZ_video.h | |||
src/packages/game/output/video/IZ_video.c | |||
__tests__/src/packages/game/output.test.c | |||
__tests__/src/packages/game/output.test.c | |||
) | |||
add_executable( | |||
@@ -306,7 +306,7 @@ add_executable( | |||
src/packages/game/data/IZ_list.h | |||
src/packages/game/memory/IZ_pool.h | |||
src/packages/game/memory/IZ_pool.c | |||
__tests__/src/packages/game/memory.test.c | |||
__tests__/src/packages/game/memory.test.c | |||
) | |||
target_link_libraries( | |||
@@ -338,8 +338,10 @@ add_executable( | |||
server | |||
dependencies/sqlite/sqlite3.h | |||
dependencies/sqlite/sqlite3.c | |||
subprojects/minIni/dev/minIni.h | |||
subprojects/minIni/dev/minIni.c | |||
subprojects/ini-config/subprojects/minIni/dev/minIni.h | |||
subprojects/ini-config/subprojects/minIni/dev/minIni.c | |||
subprojects/ini-config/ini-config.h | |||
subprojects/ini-config/ini-config.c | |||
src/packages/log/IZ_intercept.h | |||
src/packages/log/IZ_intercept.c | |||
src/packages/server/main.c | |||
@@ -351,8 +353,6 @@ add_executable( | |||
src/packages/net/svc/IZ_wsserver.h | |||
src/packages/net/core/IZ_websocket.h | |||
src/packages/net/core/IZ_websocket.c | |||
src/packages/config/IZ_config.h | |||
src/packages/config/IZ_config.c | |||
src/packages/net/IZ_net_server.c | |||
src/packages/net/IZ_net_server.h | |||
src/packages/server/db/IZ_repo.c | |||
@@ -378,8 +378,10 @@ target_link_libraries( | |||
add_executable( | |||
asset-inv | |||
subprojects/minIni/dev/minIni.h | |||
subprojects/minIni/dev/minIni.c | |||
subprojects/ini-config/subprojects/minIni/dev/minIni.h | |||
subprojects/ini-config/subprojects/minIni/dev/minIni.c | |||
subprojects/ini-config/ini-config.h | |||
subprojects/ini-config/ini-config.c | |||
src/packages/common/IZ_common.h | |||
src/packages/asset-inv/main.c | |||
) | |||
@@ -2,14 +2,14 @@ | |||
#define IZ_CONFIG_MOCK_H | |||
#include <bdd-for-c-mocks.h> | |||
#include "../../../src/packages/config/IZ_config.h" | |||
#include <ini-config.h> | |||
mock(IZ_ConfigInitialize) IZ_ConfigInitializeResult IZ_ConfigInitialize(IZ_ConfigItem _item[], const char* _config_path, u8 _argc, const char* _argv[]) { | |||
mock_return(IZ_ConfigInitialize) IZ_CONFIG_INITIALIZE_RESULT_OK; | |||
mock(INI_ConfigInitialize) INI_ConfigInitializeResult INI_ConfigInitialize(INI_ConfigItem _item[], const char* _config_path, u8 _argc, const char* _argv[]) { | |||
mock_return(INI_ConfigInitialize) INI_CONFIG_INITIALIZE_RESULT_OK; | |||
} | |||
mock(IZ_ConfigSave) IZ_ConfigSaveResult IZ_ConfigSave(IZ_ConfigItem _item[], const char* _config_path) { | |||
mock_return(IZ_ConfigSave) 0; | |||
mock(INI_ConfigSave) INI_ConfigSaveResult INI_ConfigSave(INI_ConfigItem _item[], const char* _config_path) { | |||
mock_return(INI_ConfigSave) 0; | |||
} | |||
#endif |
@@ -1,359 +0,0 @@ | |||
#include <SDL_guid.h> | |||
#include "IZ_config.h" | |||
const char* IZ_ConfigGetCommandlineOption(u8 argc, const char* argv[], const char* val) { | |||
size_t n = strlen(val); | |||
int c = argc; | |||
while (--c > 0) { | |||
if (!strncmp(argv[c], val, n)) { | |||
if (!*(argv[c] + n) && c < argc - 1) { | |||
/* coverity treats unchecked argv as "tainted" */ | |||
if (!argv[c + 1] || strlen(argv[c + 1]) > 1024) | |||
return NULL; | |||
return argv[c + 1]; | |||
} | |||
if (argv[c][n] == '=') | |||
return &argv[c][n + 1]; | |||
return argv[c] + n; | |||
} | |||
} | |||
return NULL; | |||
} | |||
typedef enum { | |||
IZ_CONFIG_SAVE_ITEM_ERROR = -1, | |||
IZ_CONFIG_SAVE_ITEM_OK, | |||
} IZ_ConfigSaveItemResult; | |||
#define IZ_CONFIG_REGISTER_INT_TYPE(ID, T) \ | |||
typedef bool IZ_ConfigValidate##ID(T); \ | |||
\ | |||
typedef T IZ_ConfigDeserialize##ID(const char*); \ | |||
\ | |||
typedef void IZ_ConfigSerialize##ID(T, const char[128]); \ | |||
\ | |||
void IZ_ConfigEnsureValid##ID(IZ_ConfigItem* item, T raw_value, T default_value) { \ | |||
T* dest = item->dest; \ | |||
if (item->validator) { \ | |||
IZ_ConfigValidate##ID* validate = item->validator; \ | |||
if (validate(raw_value)) { \ | |||
*dest = raw_value; \ | |||
return; \ | |||
} \ | |||
*dest = default_value; \ | |||
return; \ | |||
} \ | |||
*dest = raw_value; \ | |||
} \ | |||
\ | |||
void IZ_ConfigLoad##ID(IZ_ConfigItem* item, const char* config_path) { \ | |||
static T raw_value; \ | |||
static T default_value; \ | |||
default_value = *((T*) item->default_value); \ | |||
if (item->transformer.deserialize && item->transformer.serialize) { \ | |||
IZ_ConfigDeserialize##ID* deserialize = item->transformer.deserialize; \ | |||
IZ_ConfigSerialize##ID* serialize = item->transformer.serialize; \ | |||
const char serialized_default_value[128]; \ | |||
if (default_value) { \ | |||
serialize(default_value, serialized_default_value); \ | |||
} \ | |||
char buffer[128]; \ | |||
ini_gets(item->section, item->key, serialized_default_value, buffer, 128, config_path); \ | |||
raw_value = deserialize(buffer); \ | |||
} else { \ | |||
raw_value = ini_getl(item->section, item->key, default_value, config_path); \ | |||
} \ | |||
IZ_ConfigEnsureValid##ID(item, raw_value, default_value); \ | |||
} \ | |||
\ | |||
IZ_ConfigSaveItemResult IZ_ConfigSave##ID(IZ_ConfigItem* item, const char* config_path) { \ | |||
T dest = *((T*) item->dest); \ | |||
if (item->validator) { \ | |||
IZ_ConfigValidate##ID* validate = item->validator; \ | |||
if (!validate(dest)) { \ | |||
dest = *((const T*) item->default_value); \ | |||
} \ | |||
} \ | |||
\ | |||
if (item->transformer.deserialize && item->transformer.serialize) { \ | |||
IZ_ConfigSerialize##ID* serialize = item->transformer.serialize; \ | |||
const char serialized_value[128]; \ | |||
serialize(dest, serialized_value); \ | |||
if (!ini_puts(item->section, item->key, serialized_value, config_path)) { \ | |||
return -1; \ | |||
} \ | |||
return 0; \ | |||
} \ | |||
\ | |||
if (!ini_putl(item->section, item->key, dest, config_path)) { \ | |||
return -1; \ | |||
} \ | |||
\ | |||
return 0; \ | |||
} \ | |||
\ | |||
void IZ_ConfigOverride##ID(IZ_ConfigItem* item, u8 argc, const char* argv[]) { \ | |||
if (!item->cmdline_option) { \ | |||
return; \ | |||
} \ | |||
const char* cmdline_buffer; \ | |||
char* rest_of_string; \ | |||
static T dest; \ | |||
static T config_value; \ | |||
config_value = *((T*) item->dest); \ | |||
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, item->cmdline_option))) { \ | |||
dest = strtol(cmdline_buffer, &rest_of_string, 10); \ | |||
if (strcmp(cmdline_buffer, rest_of_string) != 0) { \ | |||
IZ_ConfigEnsureValid##ID(item, dest, config_value); \ | |||
return; \ | |||
} \ | |||
} \ | |||
} | |||
IZ_CONFIG_REGISTER_INT_TYPE(U8, u8); | |||
IZ_CONFIG_REGISTER_INT_TYPE(U16, u16); | |||
IZ_CONFIG_REGISTER_INT_TYPE(I32, i32); | |||
typedef bool IZ_ConfigLoadParamsStringValidator(const char*); | |||
void IZ_ConfigEnsureValidString(IZ_ConfigItem* item, const char* buffer) { | |||
if (item->validator) { | |||
IZ_ConfigLoadParamsStringValidator* validator = item->validator; | |||
if (validator(buffer)) { | |||
IZ_memcpy(item->dest, item->dest_size, buffer, item->dest_size); | |||
return; | |||
} | |||
IZ_memcpy(item->dest, item->dest_size, item->default_value, item->dest_size); | |||
return; | |||
} | |||
IZ_memcpy(item->dest, item->dest_size, buffer, item->dest_size); | |||
} | |||
void IZ_ConfigLoadString(IZ_ConfigItem* item, const char* config_path) { | |||
char buffer[item->dest_size]; | |||
ini_gets(item->section, item->key, item->default_value, buffer, (i32) item->dest_size, config_path); | |||
IZ_ConfigEnsureValidString(item, buffer); | |||
} | |||
IZ_ConfigSaveItemResult IZ_ConfigSaveString(IZ_ConfigItem* item, const char* config_path) { | |||
const char* dest = (const char*) item->dest; | |||
if (item->validator) { | |||
IZ_ConfigLoadParamsStringValidator* validator = item->validator; | |||
if (!validator(dest)) { | |||
dest = (const char*) item->default_value; | |||
} | |||
} | |||
if (!ini_puts(item->section, item->key, dest, config_path)) { | |||
return IZ_CONFIG_SAVE_ITEM_ERROR; | |||
} | |||
return IZ_CONFIG_SAVE_ITEM_OK; | |||
} | |||
void IZ_ConfigOverrideString(IZ_ConfigItem* item, u8 argc, const char* argv[]) { | |||
if (!item->cmdline_option) { | |||
return; | |||
} | |||
const char* cmdline_buffer; | |||
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, item->cmdline_option))) { | |||
IZ_ConfigEnsureValidString(item, cmdline_buffer); | |||
} | |||
} | |||
typedef bool IZ_ConfigLoadParamsGuidValidator(SDL_GUID); | |||
void IZ_ConfigEnsureValidGuid(IZ_ConfigItem* item, SDL_GUID raw_value, SDL_GUID default_value) { | |||
SDL_GUID* dest = item->dest; | |||
if (item->validator) { | |||
IZ_ConfigLoadParamsGuidValidator* validate = item->validator; | |||
if (validate(raw_value)) { | |||
// within valid values | |||
*dest = raw_value; | |||
return; | |||
} | |||
// outside valid values, we use default value | |||
// | |||
// TODO: what if the default value is also invalid? | |||
*dest = default_value; | |||
return; | |||
} | |||
// no validator, get whatever is the deserialized value | |||
*dest = raw_value; | |||
} | |||
typedef SDL_GUID IZ_ConfigDeserializeGUID(const char*); | |||
typedef void IZ_ConfigSerializeGUID(SDL_GUID, const char[128]); | |||
void IZ_ConfigLoadGuid(IZ_ConfigItem* item, const char* config_path) { | |||
static SDL_GUID raw_value; | |||
static SDL_GUID default_value = { | |||
.data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, | |||
}; | |||
if (item->default_value) { | |||
default_value = *((SDL_GUID *) item->default_value); | |||
} | |||
char buffer[33]; | |||
if (item->transformer.deserialize && item->transformer.serialize) { | |||
IZ_ConfigDeserializeGUID* deserialize = item->transformer.deserialize; | |||
IZ_ConfigSerializeGUID* serialize = item->transformer.serialize; | |||
const char serialized_default_value[33]; | |||
serialize(default_value, serialized_default_value); | |||
ini_gets(item->section, item->key, serialized_default_value, buffer, 33, config_path); | |||
raw_value = deserialize(buffer); | |||
} else { | |||
char guid_string_default_value[33]; | |||
SDL_GUIDToString(default_value, guid_string_default_value, 33); | |||
ini_gets(item->section, item->key, guid_string_default_value, buffer, 33, config_path); | |||
raw_value = SDL_GUIDFromString(buffer); | |||
} | |||
IZ_ConfigEnsureValidGuid(item, raw_value, default_value); | |||
} | |||
void IZ_ConfigLoad(IZ_ConfigItem item[], const char* config_path) { | |||
u8 i; | |||
for (i = 0; item[i].type != IZ_CONFIG_TYPE_VOID; i += 1) { | |||
switch (item[i].type) { | |||
case IZ_CONFIG_TYPE_STRING: | |||
IZ_ConfigLoadString(&item[i], config_path); | |||
break; | |||
case IZ_CONFIG_TYPE_U8: | |||
IZ_ConfigLoadU8(&item[i], config_path); | |||
break; | |||
case IZ_CONFIG_TYPE_U16: | |||
IZ_ConfigLoadU16(&item[i], config_path); | |||
break; | |||
case IZ_CONFIG_TYPE_I32: | |||
IZ_ConfigLoadI32(&item[i], config_path); | |||
break; | |||
case IZ_CONFIG_TYPE_GUID: | |||
IZ_ConfigLoadGuid(&item[i], config_path); | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
} | |||
IZ_ConfigSaveItemResult IZ_ConfigSaveGuid(IZ_ConfigItem* item, const char* config_path) { | |||
SDL_GUID dest = *((SDL_GUID*) item->dest); | |||
if (item->validator) { | |||
IZ_ConfigLoadParamsGuidValidator* validate = item->validator; | |||
if (!validate(dest)) { | |||
dest = *((const SDL_GUID*) item->default_value); | |||
} | |||
} | |||
if (item->transformer.deserialize && item->transformer.serialize) { | |||
IZ_ConfigSerializeGUID* serialize = item->transformer.serialize; | |||
const char serialized_value[128]; | |||
serialize(dest, serialized_value); | |||
if (!ini_puts(item->section, item->key, serialized_value, config_path)) { | |||
return -1; | |||
} | |||
return 0; | |||
} | |||
char guid_str[33]; | |||
IZ_memset(guid_str, 0, 33); | |||
SDL_GUIDToString(dest, guid_str, 33); | |||
if (!ini_puts(item->section, item->key, guid_str, config_path)) { | |||
return -1; | |||
} | |||
return 0; | |||
} | |||
void IZ_ConfigOverrideGuid(IZ_ConfigItem* item, u8 argc, const char* argv[]) { | |||
if (!item->cmdline_option) { | |||
return; | |||
} | |||
const char* cmdline_buffer; | |||
static SDL_GUID dest; | |||
static SDL_GUID config_value; | |||
config_value = *((SDL_GUID*) item->dest); | |||
if((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, item->cmdline_option))) { | |||
dest = SDL_GUIDFromString(cmdline_buffer); | |||
IZ_ConfigEnsureValidGuid(item, dest, config_value); | |||
} | |||
} | |||
IZ_ConfigSaveResult IZ_ConfigSave(IZ_ConfigItem item[], const char* config_path) { | |||
u8 i; | |||
i64 problems = 0; | |||
for (i = 0; item[i].type != IZ_CONFIG_TYPE_VOID; i += 1) { | |||
i8 result = 0; | |||
switch (item[i].type) { | |||
case IZ_CONFIG_TYPE_STRING: | |||
result = IZ_ConfigSaveString(&item[i], config_path); | |||
break; | |||
case IZ_CONFIG_TYPE_GUID: | |||
result = IZ_ConfigSaveGuid(&item[i], config_path); | |||
break; | |||
case IZ_CONFIG_TYPE_U8: | |||
result = IZ_ConfigSaveU8(&item[i], config_path); | |||
break; | |||
case IZ_CONFIG_TYPE_U16: | |||
result = IZ_ConfigSaveU16(&item[i], config_path); | |||
break; | |||
case IZ_CONFIG_TYPE_I32: | |||
result = IZ_ConfigSaveI32(&item[i], config_path); | |||
default: | |||
break; | |||
} | |||
if (result < 0) { | |||
problems |= (1u << (i64) i); | |||
} | |||
} | |||
return -problems; | |||
} | |||
void IZ_ConfigOverride(IZ_ConfigItem item[], u8 argc, const char* argv[]) { | |||
u8 i; | |||
for (i = 0; item[i].type != IZ_CONFIG_TYPE_VOID; i += 1) { | |||
switch (item[i].type) { | |||
case IZ_CONFIG_TYPE_STRING: | |||
IZ_ConfigOverrideString(&item[i], argc, argv); | |||
break; | |||
case IZ_CONFIG_TYPE_U8: | |||
IZ_ConfigOverrideU8(&item[i], argc, argv); | |||
break; | |||
case IZ_CONFIG_TYPE_U16: | |||
IZ_ConfigOverrideU16(&item[i], argc, argv); | |||
break; | |||
case IZ_CONFIG_TYPE_I32: | |||
IZ_ConfigOverrideI32(&item[i], argc, argv); | |||
break; | |||
case IZ_CONFIG_TYPE_GUID: | |||
IZ_ConfigOverrideGuid(&item[i], argc, argv); | |||
break; | |||
default: | |||
break; | |||
} | |||
} | |||
} | |||
IZ_ConfigInitializeResult IZ_ConfigInitialize(IZ_ConfigItem item[], const char* config_path, u8 argc, const char* argv[]) { | |||
IZ_ConfigLoad(item, config_path); | |||
IZ_ConfigSaveResult save_result = IZ_ConfigSave(item, config_path); | |||
if (save_result < 0) { | |||
IZ_LogError("config", "Sync failed! Result: %u", save_result); | |||
return IZ_CONFIG_INITIALIZE_RESULT_ERROR; | |||
} | |||
IZ_ConfigOverride(item, argc, argv); | |||
if (save_result > 0) { | |||
IZ_LogWarn(false, "config", "Sync encountered issues. Result: %u", save_result); | |||
return IZ_CONFIG_INITIALIZE_RESULT_WARNING; | |||
} | |||
IZ_LogInfo(IZ_LOG_CATEGORY_GLOBAL, "config", "Sync successful."); | |||
return IZ_CONFIG_INITIALIZE_RESULT_OK; | |||
} |
@@ -1,68 +0,0 @@ | |||
#ifndef IZ_CONFIG_H | |||
#define IZ_CONFIG_H | |||
#include <stdlib.h> | |||
#include <string.h> | |||
#include <minIni.h> | |||
#include "../common/IZ_common.h" | |||
#include "../log/IZ_log.h" | |||
#include "../stdinc/IZ_string.h" | |||
typedef enum { | |||
IZ_CONFIG_TYPE_VOID, | |||
IZ_CONFIG_TYPE_STRING, | |||
IZ_CONFIG_TYPE_U8, | |||
IZ_CONFIG_TYPE_U16, | |||
IZ_CONFIG_TYPE_I32, | |||
IZ_CONFIG_TYPE_GUID, | |||
} IZ_ConfigType; | |||
typedef struct { | |||
void* serialize; | |||
void* deserialize; | |||
} IZ_ConfigSerializerPair; | |||
typedef struct { | |||
IZ_ConfigType type; | |||
size_t dest_size; | |||
const char* section; | |||
const char* key; | |||
const char* cmdline_option; | |||
const void* default_value; | |||
void* validator; | |||
IZ_ConfigSerializerPair transformer; | |||
void* dest; | |||
} IZ_ConfigItem; | |||
void IZ_ConfigGetDefaultPath(char*, size_t); | |||
const char* IZ_ConfigGetCommandlineOption(u8, const char*[], const char*); | |||
typedef enum { | |||
IZ_CONFIG_INITIALIZE_RESULT_ERROR = -1, | |||
IZ_CONFIG_INITIALIZE_RESULT_OK, | |||
IZ_CONFIG_INITIALIZE_RESULT_WARNING | |||
} IZ_ConfigInitializeResult; | |||
IZ_ConfigInitializeResult IZ_ConfigInitialize(IZ_ConfigItem[], const char*, u8, const char*[]); | |||
typedef i64 IZ_ConfigSaveResult; | |||
IZ_ConfigSaveResult IZ_ConfigSave(IZ_ConfigItem[], const char*); | |||
#define IZ_CONFIG_ITEM_NULL (IZ_ConfigItem) { \ | |||
IZ_CONFIG_TYPE_VOID, \ | |||
0, \ | |||
NULL, \ | |||
NULL, \ | |||
NULL, \ | |||
NULL, \ | |||
NULL, \ | |||
{ \ | |||
.serialize = NULL, \ | |||
.deserialize = NULL, \ | |||
}, \ | |||
NULL, \ | |||
} | |||
#endif |
@@ -0,0 +1,97 @@ | |||
#include "IZ_config_guid.h" | |||
typedef SDL_GUID INI_ConfigDeserializeGUID(const char*); | |||
typedef void INI_ConfigSerializeGUID(SDL_GUID, const char[128]); | |||
typedef bool INI_ConfigLoadParamsGuidValidator(SDL_GUID); | |||
void INI_ConfigEnsureValidGuid(INI_ConfigItem* item, SDL_GUID raw_value, SDL_GUID default_value) { | |||
SDL_GUID* dest = item->dest; | |||
if (item->validator) { | |||
INI_ConfigLoadParamsGuidValidator* validate = item->validator; | |||
if (validate(raw_value)) { | |||
// within valid values | |||
*dest = raw_value; | |||
return; | |||
} | |||
// outside valid values, we use default value | |||
// | |||
// TODO: what if the default value is also invalid? | |||
*dest = default_value; | |||
return; | |||
} | |||
// no validator, get whatever is the deserialized value | |||
*dest = raw_value; | |||
} | |||
void INI_ConfigLoadGuid(INI_ConfigItem* item, const char* config_path) { | |||
static SDL_GUID raw_value; | |||
static SDL_GUID default_value = { | |||
.data = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, | |||
}; | |||
if (item->default_value) { | |||
default_value = *((SDL_GUID *) item->default_value); | |||
} | |||
char buffer[33]; | |||
if (item->transformer.deserialize && item->transformer.serialize) { | |||
INI_ConfigDeserializeGUID* deserialize = item->transformer.deserialize; | |||
INI_ConfigSerializeGUID* serialize = item->transformer.serialize; | |||
const char serialized_default_value[33]; | |||
serialize(default_value, serialized_default_value); | |||
ini_gets(item->section, item->key, serialized_default_value, buffer, 33, config_path); | |||
raw_value = deserialize(buffer); | |||
} else { | |||
char guid_string_default_value[33]; | |||
SDL_GUIDToString(default_value, guid_string_default_value, 33); | |||
ini_gets(item->section, item->key, guid_string_default_value, buffer, 33, config_path); | |||
raw_value = SDL_GUIDFromString(buffer); | |||
} | |||
INI_ConfigEnsureValidGuid(item, raw_value, default_value); | |||
} | |||
INI_ConfigSaveItemResult INI_ConfigSaveGuid(INI_ConfigItem* item, const char* config_path) { | |||
SDL_GUID dest = *((SDL_GUID*) item->dest); | |||
if (item->validator) { | |||
INI_ConfigLoadParamsGuidValidator* validate = item->validator; | |||
if (!validate(dest)) { | |||
dest = *((const SDL_GUID*) item->default_value); | |||
} | |||
} | |||
if (item->transformer.deserialize && item->transformer.serialize) { | |||
INI_ConfigSerializeGUID* serialize = item->transformer.serialize; | |||
const char serialized_value[128]; | |||
serialize(dest, serialized_value); | |||
if (!ini_puts(item->section, item->key, serialized_value, config_path)) { | |||
return -1; | |||
} | |||
return 0; | |||
} | |||
char guid_str[33]; | |||
memset(guid_str, 0, 33); | |||
SDL_GUIDToString(dest, guid_str, 33); | |||
if (!ini_puts(item->section, item->key, guid_str, config_path)) { | |||
return -1; | |||
} | |||
return 0; | |||
} | |||
void INI_ConfigOverrideGuid(INI_ConfigItem* item, uint8_t argc, const char* argv[]) { | |||
if (!item->cmdline_option) { | |||
return; | |||
} | |||
const char* cmdline_buffer; | |||
static SDL_GUID dest; | |||
static SDL_GUID config_value; | |||
config_value = *((SDL_GUID*) item->dest); | |||
if((cmdline_buffer = INI_ConfigGetCommandlineOption(argc, argv, item->cmdline_option))) { | |||
dest = SDL_GUIDFromString(cmdline_buffer); | |||
INI_ConfigEnsureValidGuid(item, dest, config_value); | |||
} | |||
} |
@@ -0,0 +1,18 @@ | |||
#ifndef IZ_CONFIG_GUID_H | |||
#define IZ_CONFIG_GUID_H | |||
#include <SDL_guid.h> | |||
#include <ini-config.h> | |||
void INI_ConfigLoadGuid(INI_ConfigItem*, const char*); | |||
INI_ConfigSaveItemResult INI_ConfigSaveGuid(INI_ConfigItem*, const char*); | |||
void INI_ConfigOverrideGuid(INI_ConfigItem*, uint8_t, const char*[]); | |||
#define INI_CONFIG_TYPE_FNS_GUID (INI_ConfigTypeFns) { \ | |||
.size = sizeof(SDL_GUID), \ | |||
.load = INI_ConfigLoadGuid, \ | |||
.save = INI_ConfigSaveGuid, \ | |||
.override = INI_ConfigOverrideGuid, \ | |||
} | |||
#endif |
@@ -35,10 +35,10 @@ IZ_AppInitializeResult IZ_AppInitialize(struct IZ_App* app, u8 argc, const char* | |||
const char* cmdline_buffer; | |||
char config_path[128]; | |||
// TODO abstract command line args parsing | |||
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-c"))) { | |||
if ((cmdline_buffer = INI_ConfigGetCommandlineOption(argc, argv, "-c"))) { | |||
IZ_memcpy(config_path, 128, cmdline_buffer, 128); | |||
} else { | |||
IZ_ConfigGetDefaultPath(config_path, 128); | |||
INI_ConfigGetDefaultPath(config_path, 128); | |||
} | |||
u32 flags = ( | |||
@@ -115,7 +115,7 @@ void IZ_AppPrintHelp() { | |||
IZ_AppResult IZ_AppRun(struct IZ_App* app, u8 argc, const char* argv[]) { | |||
IZ_TimerStart(); | |||
if (IZ_ConfigGetCommandlineOption(argc, argv, "-h")) { | |||
if (INI_ConfigGetCommandlineOption(argc, argv, "-h")) { | |||
IZ_AppPrintHelp(); | |||
return IZ_APP_RESULT_OK; | |||
} | |||
@@ -1,6 +1,6 @@ | |||
#include "IZ_app_config.h" | |||
void IZ_ConfigGetDefaultPath(char* config_path, size_t string_size) { | |||
void INI_ConfigGetDefaultPath(char* config_path, size_t string_size) { | |||
//#ifdef IZ_DEBUG | |||
const char* config_path_dir = SDL_GetBasePath(); | |||
//#else | |||
@@ -2,8 +2,8 @@ | |||
#define IZ_APP_CONFIG_H | |||
#include <SDL_filesystem.h> | |||
#include <ini-config.h> | |||
#include "IZ_subsystem.h" | |||
#include "../config/IZ_config.h" | |||
#include "../stdinc/IZ_string.h" | |||
#endif |
@@ -5,6 +5,7 @@ | |||
#include "IZ_keyboard.h" | |||
#include "IZ_joystick.h" | |||
#include "IZ_midi.h" | |||
#include "../../log/IZ_log.h" | |||
typedef struct { | |||
IZ_Action action[IZ_PLAYERS]; | |||
@@ -1,6 +1,6 @@ | |||
#include "IZ_joystick.h" | |||
static IZ_ConfigItem joystick_config_items[IZ_PLAYERS * (IZ_CONTROLS - 4 + 2) + 1]; | |||
static INI_ConfigItem joystick_config_items[IZ_PLAYERS * (IZ_CONTROLS - 4 + 2) + 1]; | |||
bool IZ_JoystickIsValidAxisThreshold(u16 value) { | |||
return (4000 <= value && value <= 12000); | |||
@@ -175,7 +175,7 @@ void IZ_JoystickHandleEvents(IZ_JoystickState(* state)[IZ_PLAYERS], IZ_Action(* | |||
} | |||
} | |||
void IZ_JoystickBindStateToConfig(IZ_JoystickState(* state)[IZ_PLAYERS], IZ_ConfigItem config_items[]) { | |||
void IZ_JoystickBindStateToConfig(IZ_JoystickState(* state)[IZ_PLAYERS], INI_ConfigItem config_items[]) { | |||
u8 player_index; | |||
u8 control_index; | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
@@ -191,10 +191,10 @@ void IZ_JoystickBindStateToConfig(IZ_JoystickState(* state)[IZ_PLAYERS], IZ_Conf | |||
IZ_ProcedureResult IZ_JoystickSaveConfig(IZ_JoystickState(* state)[IZ_PLAYERS], const char* config_path) { | |||
IZ_JoystickBindStateToConfig(state, joystick_config_items); | |||
return IZ_ConfigSave(joystick_config_items, config_path); | |||
return INI_ConfigSave(joystick_config_items, config_path); | |||
} | |||
void IZ_JoystickInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
void IZ_JoystickInitializeConfigItems(INI_ConfigItem config_items[]) { | |||
u8 player_index; | |||
u8 control_index; | |||
char* main_section_name; | |||
@@ -203,9 +203,8 @@ void IZ_JoystickInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
main_section_name = IZ_calloc(64, sizeof(char)); | |||
sprintf(main_section_name, "Joystick.%d", player_index); | |||
u8 base_index = (player_index * (IZ_CONTROLS - 4 + 2)); | |||
config_items[base_index] = (IZ_ConfigItem) { | |||
IZ_CONFIG_TYPE_I32, | |||
sizeof(i32), | |||
config_items[base_index] = (INI_ConfigItem) { | |||
INI_CONFIG_TYPE_FNS_I32, | |||
main_section_name, | |||
"DeviceID", | |||
NULL, | |||
@@ -214,9 +213,8 @@ void IZ_JoystickInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
NULL, | |||
}; | |||
config_items[base_index + 1] = (IZ_ConfigItem) { | |||
IZ_CONFIG_TYPE_U16, | |||
sizeof(u16), | |||
config_items[base_index + 1] = (INI_ConfigItem) { | |||
INI_CONFIG_TYPE_FNS_U16, | |||
main_section_name, | |||
"AxisThreshold", | |||
NULL, | |||
@@ -225,9 +223,8 @@ void IZ_JoystickInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
NULL, | |||
}; | |||
config_items[base_index + 2] = (IZ_ConfigItem) { | |||
IZ_CONFIG_TYPE_GUID, | |||
sizeof(SDL_GUID), | |||
config_items[base_index + 2] = (INI_ConfigItem) { | |||
INI_CONFIG_TYPE_FNS_GUID, | |||
main_section_name, | |||
"GUID", | |||
NULL, | |||
@@ -241,9 +238,8 @@ void IZ_JoystickInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
control_mapping_section_name = IZ_calloc(64, sizeof(char)); | |||
sprintf(control_mapping_section_name, "Joystick.%d.ControlMapping", player_index); | |||
for (control_index = 4; control_index < IZ_CONTROLS; control_index += 1) { | |||
config_items[base_index + 3 + (control_index - 4)] = (IZ_ConfigItem) { | |||
IZ_CONFIG_TYPE_U8, | |||
sizeof(u8), | |||
config_items[base_index + 3 + (control_index - 4)] = (INI_ConfigItem) { | |||
INI_CONFIG_TYPE_FNS_U8, | |||
control_mapping_section_name, | |||
IZ_ACTION_NAMES[control_index], | |||
NULL, | |||
@@ -254,22 +250,13 @@ void IZ_JoystickInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
} | |||
} | |||
config_items[IZ_PLAYERS * (IZ_CONTROLS - 4 + 2)] = (IZ_ConfigItem) { | |||
IZ_CONFIG_TYPE_VOID, | |||
0, | |||
NULL, | |||
NULL, | |||
NULL, | |||
NULL, | |||
NULL, | |||
NULL, | |||
}; | |||
config_items[IZ_PLAYERS * (IZ_CONTROLS - 4 + 2) + 1] = INI_CONFIG_ITEM_NULL; | |||
} | |||
IZ_ProcedureResult IZ_JoystickInitializeConfig(IZ_JoystickState(* state)[IZ_PLAYERS], const char* config_path, u8 argc, const char* argv[]) { | |||
IZ_JoystickInitializeConfigItems(joystick_config_items); | |||
IZ_JoystickBindStateToConfig(state, joystick_config_items); | |||
if (IZ_ConfigInitialize(joystick_config_items, config_path, argc, argv) < 0) { | |||
if (INI_ConfigInitialize(joystick_config_items, config_path, argc, argv) < 0) { | |||
return -1; | |||
} | |||
return 0; | |||
@@ -311,7 +298,7 @@ IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(* state)[IZ_PLAYERS], | |||
// Post config (after joystick GUIDs have been queried), this is unique to joysticks since they can be plugged in any | |||
// time. | |||
IZ_ConfigSaveResult post_config_save_result = IZ_JoystickSaveConfig(state, config_path); | |||
INI_ConfigSaveResult post_config_save_result = IZ_JoystickSaveConfig(state, config_path); | |||
if (post_config_save_result < 0) { | |||
return -3; | |||
} | |||
@@ -4,9 +4,9 @@ | |||
#include <SDL_joystick.h> | |||
#include <SDL_gamecontroller.h> | |||
#include <SDL_events.h> | |||
#include <minIni.h> | |||
#include <ini-config.h> | |||
#include "../../config/IZ_config_guid.h" | |||
#include "../../common/IZ_common.h" | |||
#include "../../config/IZ_config.h" | |||
#include "../../stdinc/IZ_string.h" | |||
#include "../../stdinc/IZ_stdlib.h" | |||
#include "IZ_action.h" | |||
@@ -1,6 +1,6 @@ | |||
#include "IZ_keyboard.h" | |||
static IZ_ConfigItem keyboard_config_items[IZ_PLAYERS * IZ_CONTROLS + 1]; | |||
static INI_ConfigItem keyboard_config_items[IZ_PLAYERS * IZ_CONTROLS + 1]; | |||
void IZ_KeyboardSerializeControl(i32 value, char control[128]) { | |||
const char* serialized = SDL_GetKeyName(value); | |||
@@ -34,7 +34,7 @@ void IZ_KeyboardHandleEvents(IZ_KeyboardState(* state)[IZ_PLAYERS], IZ_Action(* | |||
} | |||
} | |||
void IZ_KeyboardBindStateToConfig(IZ_KeyboardState(* state)[IZ_PLAYERS], IZ_ConfigItem config_items[]) { | |||
void IZ_KeyboardBindStateToConfig(IZ_KeyboardState(* state)[IZ_PLAYERS], INI_ConfigItem config_items[]) { | |||
u8 player_index; | |||
u8 control_index; | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
@@ -46,10 +46,10 @@ void IZ_KeyboardBindStateToConfig(IZ_KeyboardState(* state)[IZ_PLAYERS], IZ_Conf | |||
IZ_ProcedureResult IZ_KeyboardSaveConfig(IZ_KeyboardState(* state)[IZ_PLAYERS], const char* config_path) { | |||
IZ_KeyboardBindStateToConfig(state, keyboard_config_items); | |||
return IZ_ConfigSave(keyboard_config_items, config_path); | |||
return INI_ConfigSave(keyboard_config_items, config_path); | |||
} | |||
void IZ_KeyboardInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
void IZ_KeyboardInitializeConfigItems(INI_ConfigItem config_items[]) { | |||
u8 player_index; | |||
u8 control_index; | |||
char* control_mapping_section_name; | |||
@@ -57,9 +57,8 @@ void IZ_KeyboardInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
control_mapping_section_name = IZ_calloc(64, sizeof(char)); | |||
sprintf(control_mapping_section_name, "Keyboard.%d.ControlMapping", player_index); | |||
for (control_index = 0; control_index < IZ_CONTROLS; control_index += 1) { | |||
config_items[player_index * IZ_CONTROLS + control_index] = (IZ_ConfigItem) { | |||
IZ_CONFIG_TYPE_I32, | |||
sizeof(i32), | |||
config_items[player_index * IZ_CONTROLS + control_index] = (INI_ConfigItem) { | |||
INI_CONFIG_TYPE_FNS_I32, | |||
control_mapping_section_name, | |||
IZ_ACTION_NAMES[control_index], | |||
NULL, | |||
@@ -74,13 +73,13 @@ void IZ_KeyboardInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
} | |||
} | |||
config_items[IZ_PLAYERS * IZ_CONTROLS] = IZ_CONFIG_ITEM_NULL; | |||
config_items[IZ_PLAYERS * IZ_CONTROLS] = INI_CONFIG_ITEM_NULL; | |||
} | |||
IZ_ProcedureResult IZ_KeyboardInitializeConfig(IZ_KeyboardState(* state)[IZ_PLAYERS], const char* config_path, u8 argc, const char* argv[]) { | |||
IZ_KeyboardInitializeConfigItems(keyboard_config_items); | |||
IZ_KeyboardBindStateToConfig(state, keyboard_config_items); | |||
if (IZ_ConfigInitialize(keyboard_config_items, config_path, argc, argv) < 0) { | |||
if (INI_ConfigInitialize(keyboard_config_items, config_path, argc, argv) < 0) { | |||
return -1; | |||
} | |||
return 0; | |||
@@ -92,7 +91,7 @@ IZ_ProcedureResult IZ_KeyboardInitialize(IZ_KeyboardState(* state)[IZ_PLAYERS], | |||
return -2; | |||
} | |||
IZ_ConfigSaveResult post_config_save_result = IZ_KeyboardSaveConfig(state, config_path); | |||
INI_ConfigSaveResult post_config_save_result = IZ_KeyboardSaveConfig(state, config_path); | |||
if (post_config_save_result < 0) { | |||
return -3; | |||
} | |||
@@ -3,8 +3,7 @@ | |||
#include <SDL_keyboard.h> | |||
#include <SDL_events.h> | |||
#include <minIni.h> | |||
#include "../../config/IZ_config.h" | |||
#include <ini-config.h> | |||
#include "../../stdinc/IZ_string.h" | |||
#include "../../stdinc/IZ_stdlib.h" | |||
#include "IZ_action.h" | |||
@@ -1,6 +1,6 @@ | |||
#include "IZ_midi.h" | |||
static IZ_ConfigItem midi_input_config_items[(IZ_PLAYERS * (IZ_CONTROLS + 2)) + 1]; | |||
static INI_ConfigItem midi_input_config_items[(IZ_PLAYERS * (IZ_CONTROLS + 2)) + 1]; | |||
bool IZ_MIDIInputIsValidChannel(u8 value) { | |||
return (0 <= value && value <= 15); | |||
@@ -51,7 +51,7 @@ void IZ_MIDIInputHandleEvents(IZ_MIDIInputState(* state)[IZ_PLAYERS], IZ_Action( | |||
} | |||
} | |||
void IZ_MIDIInputBindStateToConfig(IZ_MIDIInputState(* state)[IZ_PLAYERS], IZ_ConfigItem config_items[]) { | |||
void IZ_MIDIInputBindStateToConfig(IZ_MIDIInputState(* state)[IZ_PLAYERS], INI_ConfigItem config_items[]) { | |||
u8 player_index; | |||
u8 control_index; | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
@@ -66,10 +66,10 @@ void IZ_MIDIInputBindStateToConfig(IZ_MIDIInputState(* state)[IZ_PLAYERS], IZ_Co | |||
IZ_ProcedureResult IZ_MIDIInputSaveConfig(IZ_MIDIInputState(* state)[IZ_PLAYERS], const char* config_path) { | |||
IZ_MIDIInputBindStateToConfig(state, midi_input_config_items); | |||
return IZ_ConfigSave(midi_input_config_items, config_path); | |||
return INI_ConfigSave(midi_input_config_items, config_path); | |||
} | |||
void IZ_MIDIInputInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
void IZ_MIDIInputInitializeConfigItems(INI_ConfigItem config_items[]) { | |||
u8 player_index; | |||
u8 control_index; | |||
@@ -80,9 +80,8 @@ void IZ_MIDIInputInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
sprintf(main_section_name, "MIDIInput.%d", player_index); | |||
u16 base_index = (player_index * (IZ_CONTROLS + 2)); | |||
config_items[base_index] = (IZ_ConfigItem) { | |||
IZ_CONFIG_TYPE_I32, | |||
sizeof(i32), | |||
config_items[base_index] = (INI_ConfigItem) { | |||
INI_CONFIG_TYPE_FNS_I32, | |||
main_section_name, | |||
"DeviceID", | |||
NULL, | |||
@@ -95,9 +94,8 @@ void IZ_MIDIInputInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
NULL, | |||
}; | |||
config_items[base_index + 1] = (IZ_ConfigItem) { | |||
IZ_CONFIG_TYPE_U8, | |||
sizeof(u8), | |||
config_items[base_index + 1] = (INI_ConfigItem) { | |||
INI_CONFIG_TYPE_FNS_U8, | |||
main_section_name, | |||
"Channel", | |||
NULL, | |||
@@ -113,9 +111,8 @@ void IZ_MIDIInputInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
control_mapping_section_name = IZ_calloc(64, sizeof(char)); | |||
sprintf(control_mapping_section_name, "MIDIInput.%d.ControlMapping", player_index); | |||
for (control_index = 0; control_index < IZ_CONTROLS; control_index += 1) { | |||
config_items[base_index + 2 + control_index] = (IZ_ConfigItem) { | |||
IZ_CONFIG_TYPE_U8, | |||
sizeof(u8), | |||
config_items[base_index + 2 + control_index] = (INI_ConfigItem) { | |||
INI_CONFIG_TYPE_FNS_U8, | |||
control_mapping_section_name, | |||
IZ_ACTION_NAMES[control_index], | |||
NULL, | |||
@@ -130,13 +127,13 @@ void IZ_MIDIInputInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
} | |||
} | |||
config_items[IZ_PLAYERS * (IZ_CONTROLS + 2)] = IZ_CONFIG_ITEM_NULL; | |||
config_items[IZ_PLAYERS * (IZ_CONTROLS + 2)] = INI_CONFIG_ITEM_NULL; | |||
} | |||
IZ_ProcedureResult IZ_MIDIInputInitializeConfig(IZ_MIDIInputState(* state)[IZ_PLAYERS], const char* config_path, u8 argc, const char* argv[]) { | |||
IZ_MIDIInputInitializeConfigItems(midi_input_config_items); | |||
IZ_MIDIInputBindStateToConfig(state, midi_input_config_items); | |||
if (IZ_ConfigInitialize(midi_input_config_items, config_path, argc, argv) < 0) { | |||
if (INI_ConfigInitialize(midi_input_config_items, config_path, argc, argv) < 0) { | |||
return -1; | |||
} | |||
return 0; | |||
@@ -181,7 +178,7 @@ IZ_ProcedureResult IZ_MIDIInputInitialize(IZ_MIDIInputState(* state)[IZ_PLAYERS] | |||
); | |||
} | |||
IZ_ConfigSaveResult post_config_save_result = IZ_MIDIInputSaveConfig(state, config_path); | |||
INI_ConfigSaveResult post_config_save_result = IZ_MIDIInputSaveConfig(state, config_path); | |||
if (post_config_save_result < 0) { | |||
return -3; | |||
} | |||
@@ -4,9 +4,8 @@ | |||
#include <string.h> | |||
#include <portmidi.h> | |||
#include <minIni.h> | |||
#include <midi-utils.h> | |||
#include "../../config/IZ_config.h" | |||
#include <ini-config.h> | |||
#include "../../stdinc/IZ_string.h" | |||
#include "../../stdinc/IZ_stdlib.h" | |||
#include "IZ_action.h" | |||
@@ -14,10 +14,9 @@ bool IZ_VideoIsValidMaxFPS(u8 max_fps) { | |||
return (10 <= max_fps && max_fps <= 200); | |||
} | |||
static IZ_ConfigItem video_config_items[] = { | |||
static INI_ConfigItem video_config_items[] = { | |||
{ | |||
IZ_CONFIG_TYPE_U16, | |||
sizeof(u16), | |||
INI_CONFIG_TYPE_FNS_U16, | |||
"Video", | |||
"Width", | |||
NULL, | |||
@@ -25,8 +24,7 @@ static IZ_ConfigItem video_config_items[] = { | |||
IZ_VideoIsValidWidth, | |||
}, | |||
{ | |||
IZ_CONFIG_TYPE_U16, | |||
sizeof(u16), | |||
INI_CONFIG_TYPE_FNS_U16, | |||
"Video", | |||
"Height", | |||
NULL, | |||
@@ -34,18 +32,17 @@ static IZ_ConfigItem video_config_items[] = { | |||
IZ_VideoIsValidHeight, | |||
}, | |||
{ | |||
IZ_CONFIG_TYPE_U8, | |||
sizeof(u8), | |||
INI_CONFIG_TYPE_FNS_U8, | |||
"Video", | |||
"MaxFps", | |||
"-f", | |||
&IZ_VIDEO_DEFAULT_STATE.config.max_fps, | |||
IZ_VideoIsValidMaxFPS, | |||
}, | |||
IZ_CONFIG_ITEM_NULL, | |||
INI_CONFIG_ITEM_NULL, | |||
}; | |||
void IZ_VideoBindStateToConfig(IZ_VideoState* state, IZ_ConfigItem config_items[]) { | |||
void IZ_VideoBindStateToConfig(IZ_VideoState* state, INI_ConfigItem config_items[]) { | |||
config_items[0].dest = &state->config.width; | |||
config_items[1].dest = &state->config.height; | |||
config_items[2].dest = &state->config.max_fps; | |||
@@ -53,12 +50,12 @@ void IZ_VideoBindStateToConfig(IZ_VideoState* state, IZ_ConfigItem config_items[ | |||
IZ_ProcedureResult IZ_VideoSaveConfig(IZ_VideoState* state, const char* config_path) { | |||
IZ_VideoBindStateToConfig(state, video_config_items); | |||
return IZ_ConfigSave(video_config_items, config_path); | |||
return INI_ConfigSave(video_config_items, config_path); | |||
} | |||
IZ_ProcedureResult IZ_VideoInitializeConfig(IZ_VideoState* state, const char* config_path, u8 argc, const char* argv[]) { | |||
IZ_VideoBindStateToConfig(state, video_config_items); | |||
if (IZ_ConfigInitialize(video_config_items, config_path, argc, argv) < 0) { | |||
if (INI_ConfigInitialize(video_config_items, config_path, argc, argv) < 0) { | |||
return -1; | |||
} | |||
return 0; | |||
@@ -2,12 +2,12 @@ | |||
#define IZ_VIDEO_H | |||
#include <stdio.h> | |||
#include "minIni.h" | |||
#include "SDL_render.h" | |||
#include <SDL_render.h> | |||
#include <SDL_image.h> | |||
#include <ini-config.h> | |||
#include "../../../log/IZ_log.h" | |||
#include "../../../net/IZ_net_client.h" | |||
#include "../../../config/IZ_config.h" | |||
#include "../../../common/IZ_common.h" | |||
#include "../../../io/IZ_io.h" | |||
#include "../../../stdinc/IZ_string.h" | |||
@@ -12,12 +12,11 @@ bool IZ_NetClientIsValidReconnectIntervalSeconds(long reconnect_interval_secs) { | |||
return (3 <= reconnect_interval_secs && reconnect_interval_secs <= 10); | |||
} | |||
static IZ_ConfigItem net_client_config_items[IZ_PLAYERS + 3 + 1]; | |||
static INI_ConfigItem net_client_config_items[IZ_PLAYERS + 3 + 1]; | |||
void IZ_NetClientInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
config_items[0] = (IZ_ConfigItem) { | |||
IZ_CONFIG_TYPE_U16, | |||
sizeof(u16), | |||
void IZ_NetClientInitializeConfigItems(INI_ConfigItem config_items[]) { | |||
config_items[0] = (INI_ConfigItem) { | |||
INI_CONFIG_TYPE_FNS_U16, | |||
"Network", | |||
"PacketIntervalMs", | |||
"-i", | |||
@@ -25,9 +24,8 @@ void IZ_NetClientInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
IZ_NetClientIsValidPacketIntervalMs, | |||
NULL, | |||
}; | |||
config_items[1] = (IZ_ConfigItem) { | |||
IZ_CONFIG_TYPE_U8, | |||
sizeof(u8), | |||
config_items[1] = (INI_ConfigItem) { | |||
INI_CONFIG_TYPE_FNS_U8, | |||
"Network", | |||
"MaxReconnectRetries", | |||
NULL, | |||
@@ -35,9 +33,8 @@ void IZ_NetClientInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
IZ_NetClientIsValidMaxReconnectRetries, | |||
NULL, | |||
}; | |||
config_items[2] = (IZ_ConfigItem) { | |||
IZ_CONFIG_TYPE_U8, | |||
sizeof(u8), | |||
config_items[2] = (INI_ConfigItem) { | |||
INI_CONFIG_TYPE_FNS_U8, | |||
"Network", | |||
"ReconnectIntervalSeconds", | |||
NULL, | |||
@@ -51,9 +48,8 @@ void IZ_NetClientInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
main_section_name = malloc(sizeof(char) * 64); | |||
sprintf(main_section_name, "Network.%d", player_index); | |||
config_items[3 + player_index] = (IZ_ConfigItem) { | |||
IZ_CONFIG_TYPE_STRING, | |||
32, | |||
config_items[3 + player_index] = (INI_ConfigItem) { | |||
INI_CONFIG_TYPE_FNS_STRING(32), | |||
main_section_name, | |||
"Username", | |||
NULL, | |||
@@ -63,10 +59,10 @@ void IZ_NetClientInitializeConfigItems(IZ_ConfigItem config_items[]) { | |||
}; | |||
} | |||
config_items[3 + IZ_PLAYERS] = IZ_CONFIG_ITEM_NULL; | |||
config_items[3 + IZ_PLAYERS] = INI_CONFIG_ITEM_NULL; | |||
} | |||
void IZ_NetClientBindStateToConfig(IZ_NetClientState* state, IZ_ConfigItem config_items[]) { | |||
void IZ_NetClientBindStateToConfig(IZ_NetClientState* state, INI_ConfigItem config_items[]) { | |||
config_items[0].dest = &state->config.packet_interval_ms; | |||
config_items[1].dest = &state->config.max_reconnect_retries; | |||
config_items[2].dest = &state->config.reconnect_interval_secs; | |||
@@ -78,7 +74,7 @@ void IZ_NetClientBindStateToConfig(IZ_NetClientState* state, IZ_ConfigItem confi | |||
IZ_ProcedureResult IZ_NetClientSaveConfig(IZ_NetClientState* state, const char* config_path) { | |||
IZ_NetClientBindStateToConfig(state, net_client_config_items); | |||
return IZ_ConfigSave(net_client_config_items, config_path); | |||
return INI_ConfigSave(net_client_config_items, config_path); | |||
} | |||
IZ_ProcedureResult IZ_NetClientInitializeConfig( | |||
@@ -89,7 +85,7 @@ IZ_ProcedureResult IZ_NetClientInitializeConfig( | |||
) { | |||
IZ_NetClientInitializeConfigItems(net_client_config_items); | |||
IZ_NetClientBindStateToConfig(state, net_client_config_items); | |||
if (IZ_ConfigInitialize(net_client_config_items, config_path, argc, argv) < 0) { | |||
if (INI_ConfigInitialize(net_client_config_items, config_path, argc, argv) < 0) { | |||
return -1; | |||
} | |||
return 0; | |||
@@ -1,11 +1,12 @@ | |||
#ifndef IZ_NET_CLIENT_H | |||
#define IZ_NET_CLIENT_H | |||
#include "minIni.h" | |||
#include "SDL_thread.h" | |||
#include "../config/IZ_config.h" | |||
#include <SDL_thread.h> | |||
#include <ini-config.h> | |||
#include "../common/IZ_common.h" | |||
#include "../game/input/IZ_action.h" | |||
#include "../log/IZ_log.h" | |||
#include "../stdinc/IZ_string.h" | |||
#include "svc/IZ_wsclient.h" | |||
@@ -4,10 +4,9 @@ bool IZ_NetServerIsValidPort(u16 port) { | |||
return (1000 <= port && port <= 59999); | |||
} | |||
static IZ_ConfigItem net_server_config_items[] = { | |||
static INI_ConfigItem net_server_config_items[] = { | |||
{ | |||
IZ_CONFIG_TYPE_STRING, | |||
sizeof(char) * 64, | |||
INI_CONFIG_TYPE_FNS_STRING(64), | |||
"Network", | |||
"Name", | |||
"-n", | |||
@@ -20,8 +19,7 @@ static IZ_ConfigItem net_server_config_items[] = { | |||
NULL, | |||
}, | |||
{ | |||
IZ_CONFIG_TYPE_STRING, | |||
sizeof(char) * 128, | |||
INI_CONFIG_TYPE_FNS_STRING(128), | |||
"Network", | |||
"Motd", | |||
"-m", | |||
@@ -34,8 +32,7 @@ static IZ_ConfigItem net_server_config_items[] = { | |||
NULL, | |||
}, | |||
{ | |||
IZ_CONFIG_TYPE_U16, | |||
sizeof(u16), | |||
INI_CONFIG_TYPE_FNS_U16, | |||
"Network", | |||
"Port", | |||
"-p", | |||
@@ -47,10 +44,10 @@ static IZ_ConfigItem net_server_config_items[] = { | |||
}, | |||
NULL, | |||
}, | |||
IZ_CONFIG_ITEM_NULL, | |||
INI_CONFIG_ITEM_NULL, | |||
}; | |||
void IZ_NetServerBindStateToConfig(IZ_NetServerState* state, IZ_ConfigItem config_items[]) { | |||
void IZ_NetServerBindStateToConfig(IZ_NetServerState* state, INI_ConfigItem config_items[]) { | |||
config_items[0].dest = &state->config.name; | |||
config_items[1].dest = &state->config.motd; | |||
config_items[2].dest = &state->config.port; | |||
@@ -58,7 +55,7 @@ void IZ_NetServerBindStateToConfig(IZ_NetServerState* state, IZ_ConfigItem confi | |||
IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetServerState* state, const char* config_path) { | |||
IZ_NetServerBindStateToConfig(state, net_server_config_items); | |||
return IZ_ConfigSave(net_server_config_items, config_path); | |||
return INI_ConfigSave(net_server_config_items, config_path); | |||
} | |||
IZ_ProcedureResult IZ_NetServerInitializeConfig( | |||
@@ -68,7 +65,7 @@ IZ_ProcedureResult IZ_NetServerInitializeConfig( | |||
const char* argv[] | |||
) { | |||
IZ_NetServerBindStateToConfig(state, net_server_config_items); | |||
if (IZ_ConfigInitialize(net_server_config_items, config_path, argc, argv) < 0) { | |||
if (INI_ConfigInitialize(net_server_config_items, config_path, argc, argv) < 0) { | |||
return -1; | |||
} | |||
return 0; | |||
@@ -1,8 +1,7 @@ | |||
#ifndef IZ_NET_SERVER_H | |||
#define IZ_NET_SERVER_H | |||
#include <minIni.h> | |||
#include "../config/IZ_config.h" | |||
#include <ini-config.h> | |||
#include "../common/IZ_common.h" | |||
#include "../stdinc/IZ_string.h" | |||
#include "core/IZ_websocket.h" | |||
@@ -20,10 +20,10 @@ IZ_ProcedureResult IZ_AppInitialize(IZ_App *app, u8 argc, const char **argv) { | |||
const char* cmdline_buffer; | |||
char config_path[128]; | |||
// TODO abstract command line args parsing | |||
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-c"))) { | |||
if ((cmdline_buffer = INI_ConfigGetCommandlineOption(argc, argv, "-c"))) { | |||
IZ_memcpy(config_path, 128, cmdline_buffer, 128); | |||
} else { | |||
IZ_ConfigGetDefaultPath(config_path, 128); | |||
INI_ConfigGetDefaultPath(config_path, 128); | |||
} | |||
if (IZ_NetServerInitialize(&app->net_state, app, config_path, argc, argv)) { | |||
@@ -80,7 +80,7 @@ void IZ_AppPrintHelp() { | |||
IZ_ProcedureResult IZ_AppRun(IZ_App *app, u8 argc, const char **argv) { | |||
// TODO have a config subsystem that handles these. | |||
if (IZ_ConfigGetCommandlineOption(argc, argv, "-h")) { | |||
if (INI_ConfigGetCommandlineOption(argc, argv, "-h")) { | |||
IZ_AppPrintHelp(); | |||
return 0; | |||
} | |||
@@ -1,6 +1,6 @@ | |||
#include "IZ_app_config.h" | |||
void IZ_ConfigGetDefaultPath(char* config_path, size_t string_size) { | |||
void INI_ConfigGetDefaultPath(char* config_path, size_t string_size) { | |||
//#ifdef IZ_DEBUG | |||
const char* config_path_dir = SDL_GetBasePath(); | |||
//#else | |||
@@ -2,7 +2,7 @@ | |||
#define IZ_APP_CONFIG_H | |||
#include <SDL_filesystem.h> | |||
#include "../config/IZ_config.h" | |||
#include <ini-config.h> | |||
#include "../stdinc/IZ_string.h" | |||
#include "IZ_subsystem.h" | |||
@@ -1,9 +1,8 @@ | |||
#include "IZ_repo.h" | |||
static IZ_ConfigItem repo_config_items[] = { | |||
static INI_ConfigItem repo_config_items[] = { | |||
{ | |||
IZ_CONFIG_TYPE_STRING, | |||
sizeof(char) * 64, | |||
INI_CONFIG_TYPE_FNS_STRING(64), | |||
"Database", | |||
"Path", | |||
"-d", | |||
@@ -15,21 +14,21 @@ static IZ_ConfigItem repo_config_items[] = { | |||
}, | |||
NULL, | |||
}, | |||
IZ_CONFIG_ITEM_NULL, | |||
INI_CONFIG_ITEM_NULL, | |||
}; | |||
void IZ_RepoBindStateToConfig(IZ_RepoState* state, IZ_ConfigItem config_items[]) { | |||
void IZ_RepoBindStateToConfig(IZ_RepoState* state, INI_ConfigItem config_items[]) { | |||
config_items[0].dest = &state->config.path; | |||
} | |||
IZ_ProcedureResult IZ_RepoSaveConfig(IZ_RepoState* state, const char* config_path) { | |||
IZ_RepoBindStateToConfig(state, repo_config_items); | |||
return IZ_ConfigSave(repo_config_items, config_path); | |||
return INI_ConfigSave(repo_config_items, config_path); | |||
} | |||
IZ_ProcedureResult IZ_RepoInitializeConfig(IZ_RepoState* state, const char* config_path, u8 argc, const char* argv[]) { | |||
IZ_RepoBindStateToConfig(state, repo_config_items); | |||
if (IZ_ConfigInitialize(repo_config_items, config_path, argc, argv) < 0) { | |||
if (INI_ConfigInitialize(repo_config_items, config_path, argc, argv) < 0) { | |||
return -1; | |||
} | |||
return 0; | |||
@@ -47,7 +46,7 @@ IZ_ProcedureResult IZ_RepoInitialize(IZ_RepoState* state, const char* config_pat | |||
IZ_strcat(config_path_dir, 128, state->config.path); | |||
sqlite3_open_v2(config_path_dir, &state->db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); | |||
IZ_ConfigSaveResult post_config_save_result = IZ_RepoSaveConfig(state, config_path); | |||
INI_ConfigSaveResult post_config_save_result = IZ_RepoSaveConfig(state, config_path); | |||
if (post_config_save_result < 0) { | |||
return -3; | |||
} | |||
@@ -1,12 +1,11 @@ | |||
#ifndef IZ_REPO_H | |||
#define IZ_REPO_H | |||
#include <minIni.h> | |||
#include <sqlite3.h> | |||
#include <ini-config.h> | |||
#include <string.h> | |||
#include <SDL_filesystem.h> | |||
#include "../../common/IZ_common.h" | |||
#include "../../config/IZ_config.h" | |||
#include "../../stdinc/IZ_string.h" | |||
typedef struct { | |||
@@ -0,0 +1 @@ | |||
Subproject commit 6dbbef47a430649aec60a327512379b8dc0719a3 |
@@ -1 +1 @@ | |||
Subproject commit 696da13fc3cdf04fa4f2d01b94b7034a444a067e | |||
Subproject commit d0f60f929957eaa817270784f036ae72d9dbdebe |