Include _s wrappers for most standard function calls.master
@@ -119,11 +119,11 @@ add_executable( | |||||
src/packages/net/svc/IZ_wsclient.h | src/packages/net/svc/IZ_wsclient.h | ||||
src/packages/log/IZ_log.c | src/packages/log/IZ_log.c | ||||
src/packages/log/IZ_log.h | src/packages/log/IZ_log.h | ||||
src/packages/game/util/IZ_midi.c | |||||
src/packages/game/util/IZ_midi.h | |||||
src/packages/midi/IZ_midi.c | |||||
src/packages/midi/IZ_midi.h | |||||
src/packages/net/core/IZ_websocket.h | src/packages/net/core/IZ_websocket.h | ||||
src/packages/net/core/IZ_websocket.c | src/packages/net/core/IZ_websocket.c | ||||
src/packages/net/IZ_net_client.c src/packages/net/IZ_net_client.h src/packages/game/IZ_app_net.c src/packages/game/IZ_app_net.h src/packages/game/IZ_app_video.c src/packages/game/IZ_app_video.h src/packages/game/IZ_subsystem.h src/packages/game/IZ_app_input.c src/packages/game/IZ_app_input.h src/packages/game/IZ_app_config.c src/packages/game/IZ_app_config.h src/packages/game/asset/IZ_asset.c src/packages/game/asset/IZ_asset.h) | |||||
src/packages/net/IZ_net_client.c src/packages/net/IZ_net_client.h src/packages/game/IZ_app_net.c src/packages/game/IZ_app_net.h src/packages/game/IZ_app_video.c src/packages/game/IZ_app_video.h src/packages/game/IZ_subsystem.h src/packages/game/IZ_app_input.c src/packages/game/IZ_app_input.h src/packages/game/IZ_app_config.c src/packages/game/IZ_app_config.h src/packages/game/asset/IZ_asset.c src/packages/game/asset/IZ_asset.h src/packages/string/IZ_string.c src/packages/string/IZ_string.h) | |||||
if (WIN32) | if (WIN32) | ||||
target_link_libraries( | target_link_libraries( | ||||
@@ -188,8 +188,8 @@ add_executable( | |||||
src/packages/game/input/IZ_midi.h | src/packages/game/input/IZ_midi.h | ||||
src/packages/game/input/IZ_midi.c | src/packages/game/input/IZ_midi.c | ||||
src/packages/game/util/IZ_midi.c | |||||
src/packages/game/util/IZ_midi.h | |||||
src/packages/midi/IZ_midi.c | |||||
src/packages/midi/IZ_midi.h | |||||
src/packages/game/input/input.test.c | src/packages/game/input/input.test.c | ||||
) | ) | ||||
@@ -259,7 +259,7 @@ add_executable( | |||||
src/packages/server/db/IZ_repo.c | src/packages/server/db/IZ_repo.c | ||||
src/packages/server/db/IZ_repo.h | src/packages/server/db/IZ_repo.h | ||||
src/packages/server/IZ_subsystem.h | src/packages/server/IZ_subsystem.h | ||||
) | |||||
src/packages/string/IZ_string.c src/packages/string/IZ_string.h) | |||||
add_executable( | add_executable( | ||||
asset-inv | asset-inv | ||||
@@ -1,10 +1,11 @@ | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include "minIni.h" | #include "minIni.h" | ||||
#include "../common/IZ_common.h" | #include "../common/IZ_common.h" | ||||
#include "../string/IZ_string.h" | |||||
// #ifdef WIN64 | |||||
#ifdef IZ_WIN64 | |||||
#include <windows.h> | #include <windows.h> | ||||
// #endif | |||||
#endif | |||||
i32 IZ_ReadAsset(const char* current_dir, const char* ini_filename) { | i32 IZ_ReadAsset(const char* current_dir, const char* ini_filename) { | ||||
WIN32_FIND_DATA fd_file; | WIN32_FIND_DATA fd_file; | ||||
@@ -33,7 +34,7 @@ i32 IZ_ReadAsset(const char* current_dir, const char* ini_filename) { | |||||
} | } | ||||
char final_current_dir[2048]; | char final_current_dir[2048]; | ||||
memcpy(final_current_dir, current_dir, 2048); | |||||
IZ_memcpy(final_current_dir, 2048, current_dir, 2048); | |||||
u16 i = 0; | u16 i = 0; | ||||
char c = current_dir[i]; | char c = current_dir[i]; | ||||
@@ -123,13 +123,13 @@ void IZ_ConfigEnsureValidString(IZ_ConfigItem* item, const char* buffer) { | |||||
if (item->validator) { | if (item->validator) { | ||||
IZ_ConfigLoadParamsStringValidator* validator = item->validator; | IZ_ConfigLoadParamsStringValidator* validator = item->validator; | ||||
if (validator(buffer)) { | if (validator(buffer)) { | ||||
memcpy(item->dest, buffer, item->dest_size); | |||||
IZ_memcpy(item->dest, item->dest_size, buffer, item->dest_size); | |||||
return; | return; | ||||
} | } | ||||
memcpy(item->dest, item->default_value, item->dest_size); | |||||
IZ_memcpy(item->dest, item->dest_size, item->default_value, item->dest_size); | |||||
return; | return; | ||||
} | } | ||||
memcpy(item->dest, buffer, item->dest_size); | |||||
IZ_memcpy(item->dest, item->dest_size, buffer, item->dest_size); | |||||
} | } | ||||
void IZ_ConfigLoadString(IZ_ConfigItem* item, const char* config_path) { | void IZ_ConfigLoadString(IZ_ConfigItem* item, const char* config_path) { | ||||
@@ -5,6 +5,7 @@ | |||||
#include <string.h> | #include <string.h> | ||||
#include <minIni.h> | #include <minIni.h> | ||||
#include "../common/IZ_common.h" | #include "../common/IZ_common.h" | ||||
#include "../string/IZ_string.h" | |||||
typedef enum { | typedef enum { | ||||
IZ_CONFIG_TYPE_VOID, | IZ_CONFIG_TYPE_VOID, | ||||
@@ -32,7 +33,7 @@ typedef struct { | |||||
void* dest; | void* dest; | ||||
} IZ_ConfigItem; | } IZ_ConfigItem; | ||||
void IZ_ConfigGetDefaultPath(const char*, size_t); | |||||
void IZ_ConfigGetDefaultPath(char*, size_t); | |||||
const char* IZ_ConfigGetCommandlineOption(u8, const char*[], const char*); | const char* IZ_ConfigGetCommandlineOption(u8, const char*[], const char*); | ||||
@@ -32,7 +32,7 @@ IZ_AppInitializeResult IZ_AppInitialize(struct IZ_App* app, u8 argc, const char* | |||||
char config_path[128]; | char config_path[128]; | ||||
// TODO abstract command line args parsing | // TODO abstract command line args parsing | ||||
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-c"))) { | if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-c"))) { | ||||
memcpy(config_path, cmdline_buffer, 128); | |||||
IZ_memcpy(config_path, 128, cmdline_buffer, 128); | |||||
} else { | } else { | ||||
IZ_ConfigGetDefaultPath(config_path, 128); | IZ_ConfigGetDefaultPath(config_path, 128); | ||||
} | } | ||||
@@ -9,6 +9,7 @@ | |||||
#include "IZ_app_input.h" | #include "IZ_app_input.h" | ||||
#include "IZ_app_net.h" | #include "IZ_app_net.h" | ||||
#include "IZ_app_video.h" | #include "IZ_app_video.h" | ||||
#include "../string/IZ_string.h" | |||||
typedef enum { | typedef enum { | ||||
IZ_APP_RESULT_INITIALIZATION_ERROR = -1, | IZ_APP_RESULT_INITIALIZATION_ERROR = -1, | ||||
@@ -1,12 +1,12 @@ | |||||
#include "IZ_app_config.h" | #include "IZ_app_config.h" | ||||
void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) { | |||||
void IZ_ConfigGetDefaultPath(char* config_path, size_t string_size) { | |||||
#ifdef IZ_DEBUG | #ifdef IZ_DEBUG | ||||
const char* config_path_dir = SDL_GetBasePath(); | const char* config_path_dir = SDL_GetBasePath(); | ||||
#else | #else | ||||
const char* config_path_dir = SDL_GetPrefPath("Modal Studios", IZ_APP_NAME); | const char* config_path_dir = SDL_GetPrefPath("Modal Studios", IZ_APP_NAME); | ||||
#endif | #endif | ||||
memcpy(config_path, config_path_dir, string_size); | |||||
strcat(config_path, "config-game.ini"); | |||||
IZ_memcpy(config_path, string_size, config_path_dir, 128); | |||||
IZ_strcat(config_path, string_size, "config-game.ini"); | |||||
} | } |
@@ -4,5 +4,6 @@ | |||||
#include <SDL_filesystem.h> | #include <SDL_filesystem.h> | ||||
#include "IZ_subsystem.h" | #include "IZ_subsystem.h" | ||||
#include "../config/IZ_config.h" | #include "../config/IZ_config.h" | ||||
#include "../string/IZ_string.h" | |||||
#endif | #endif |
@@ -276,7 +276,7 @@ IZ_ProcedureResult IZ_JoystickInitializeConfig(IZ_JoystickState(* state)[IZ_PLAY | |||||
} | } | ||||
IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(* state)[IZ_PLAYERS], const char* config_path, u8 argc, const char* argv[]) { | IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(* state)[IZ_PLAYERS], const char* config_path, u8 argc, const char* argv[]) { | ||||
SDL_memcpy(state, &IZ_JOYSTICK_DEFAULT_STATE, sizeof(IZ_JoystickState) * IZ_PLAYERS); | |||||
IZ_memcpy(state, sizeof(IZ_JoystickState) * IZ_PLAYERS, &IZ_JOYSTICK_DEFAULT_STATE, sizeof(IZ_JoystickState) * IZ_PLAYERS); | |||||
// TODO query this file from the internet? | // TODO query this file from the internet? | ||||
SDL_GameControllerAddMappingsFromFile("assets/gamecontrollerdb.txt"); | SDL_GameControllerAddMappingsFromFile("assets/gamecontrollerdb.txt"); | ||||
@@ -299,7 +299,7 @@ IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(* state)[IZ_PLAYERS], | |||||
(*state)[player_index].config.device_id = SDL_JoystickInstanceID((*state)[player_index].device); | (*state)[player_index].config.device_id = SDL_JoystickInstanceID((*state)[player_index].device); | ||||
SDL_GUID joystick_guid = SDL_JoystickGetGUID((*state)[player_index].device); | SDL_GUID joystick_guid = SDL_JoystickGetGUID((*state)[player_index].device); | ||||
memcpy(&(*state)[player_index].config.guid, &joystick_guid, sizeof(SDL_GUID)); | |||||
IZ_memcpy(&(*state)[player_index].config.guid, sizeof(SDL_GUID), &joystick_guid, sizeof(SDL_GUID)); | |||||
//(*state)[player_index].config.guid = joystick_guid; | //(*state)[player_index].config.guid = joystick_guid; | ||||
printf("[INPUT:JOYSTICK] Initialize event from GUID: "); | printf("[INPUT:JOYSTICK] Initialize event from GUID: "); | ||||
@@ -7,6 +7,7 @@ | |||||
#include <SDL_events.h> | #include <SDL_events.h> | ||||
#include <minIni.h> | #include <minIni.h> | ||||
#include "../../config/IZ_config.h" | #include "../../config/IZ_config.h" | ||||
#include "../../string/IZ_string.h" | |||||
#include "IZ_action.h" | #include "IZ_action.h" | ||||
typedef u8 IZ_PadButton; | typedef u8 IZ_PadButton; | ||||
@@ -4,7 +4,7 @@ static IZ_ConfigItem keyboard_config_items[IZ_PLAYERS * IZ_CONTROLS + 1]; | |||||
void IZ_KeyboardSerializeControl(i32 value, char control[128]) { | void IZ_KeyboardSerializeControl(i32 value, char control[128]) { | ||||
const char* serialized = SDL_GetKeyName(value); | const char* serialized = SDL_GetKeyName(value); | ||||
memcpy(control, serialized, 128); | |||||
IZ_memcpy(control, 128, serialized, 128); | |||||
} | } | ||||
i32 IZ_KeyboardDeserializeControl(const char* control) { | i32 IZ_KeyboardDeserializeControl(const char* control) { | ||||
@@ -87,7 +87,7 @@ IZ_ProcedureResult IZ_KeyboardInitializeConfig(IZ_KeyboardState(* state)[IZ_PLAY | |||||
} | } | ||||
IZ_ProcedureResult IZ_KeyboardInitialize(IZ_KeyboardState(* state)[IZ_PLAYERS], const char* config_path, u8 argc, const char* argv[]) { | IZ_ProcedureResult IZ_KeyboardInitialize(IZ_KeyboardState(* state)[IZ_PLAYERS], const char* config_path, u8 argc, const char* argv[]) { | ||||
SDL_memcpy(state, &IZ_KEYBOARD_DEFAULT_STATE, sizeof(IZ_KeyboardState) * IZ_PLAYERS); | |||||
IZ_memcpy(state, sizeof(IZ_KeyboardState) * IZ_PLAYERS, &IZ_KEYBOARD_DEFAULT_STATE, sizeof(IZ_KeyboardState) * IZ_PLAYERS); | |||||
if (IZ_KeyboardInitializeConfig(state, config_path, argc, argv) < 0) { | if (IZ_KeyboardInitializeConfig(state, config_path, argc, argv) < 0) { | ||||
return -2; | return -2; | ||||
} | } | ||||
@@ -6,6 +6,7 @@ | |||||
#include <SDL_events.h> | #include <SDL_events.h> | ||||
#include <minIni.h> | #include <minIni.h> | ||||
#include "../../config/IZ_config.h" | #include "../../config/IZ_config.h" | ||||
#include "../../string/IZ_string.h" | |||||
#include "IZ_action.h" | #include "IZ_action.h" | ||||
typedef struct { | typedef struct { | ||||
@@ -8,7 +8,7 @@ bool IZ_MIDIInputIsValidChannel(u8 value) { | |||||
void IZ_MIDIInputSerializeControl(i32 value, char* control[128]) { | void IZ_MIDIInputSerializeControl(i32 value, char* control[128]) { | ||||
const char* serialized = IZ_MIDIGetNoteName(value); | const char* serialized = IZ_MIDIGetNoteName(value); | ||||
memcpy(control, serialized, 128); | |||||
IZ_memcpy(control, 128, serialized, 128); | |||||
} | } | ||||
i32 IZ_MIDIInputDeserializeControl(const char* control) { | i32 IZ_MIDIInputDeserializeControl(const char* control) { | ||||
@@ -147,7 +147,7 @@ IZ_ProcedureResult IZ_MIDIInputInitialize(IZ_MIDIInputState(* state)[IZ_PLAYERS] | |||||
return -1; | return -1; | ||||
} | } | ||||
SDL_memcpy(state, &IZ_MIDI_INPUT_DEFAULT_STATE, sizeof(IZ_MIDIInputState) * IZ_PLAYERS); | |||||
IZ_memcpy(state, sizeof(IZ_MIDIInputState) * IZ_PLAYERS, &IZ_MIDI_INPUT_DEFAULT_STATE, sizeof(IZ_MIDIInputState) * IZ_PLAYERS); | |||||
if (IZ_MIDIInputInitializeConfig(state, config_path, argc, argv) < 0) { | if (IZ_MIDIInputInitializeConfig(state, config_path, argc, argv) < 0) { | ||||
return -2; | return -2; | ||||
} | } | ||||
@@ -11,7 +11,8 @@ | |||||
#include <minIni.h> | #include <minIni.h> | ||||
#include "../../config/IZ_config.h" | #include "../../config/IZ_config.h" | ||||
#include "../util/IZ_midi.h" | |||||
#include "../../midi/IZ_midi.h" | |||||
#include "../../string/IZ_string.h" | |||||
#include "IZ_action.h" | #include "IZ_action.h" | ||||
#define MIDI_EVENT_BUFFER_SIZE 1024 | #define MIDI_EVENT_BUFFER_SIZE 1024 | ||||
@@ -3,6 +3,7 @@ | |||||
#include "../../../__mocks__/SDL_stdinc.mock.h" | #include "../../../__mocks__/SDL_stdinc.mock.h" | ||||
#include "../../../__mocks__/minIni.mock.h" | #include "../../../__mocks__/minIni.mock.h" | ||||
#include "../../../__mocks__/portmidi.mock.h" | #include "../../../__mocks__/portmidi.mock.h" | ||||
//#include "../../string/IZ_string.h" | |||||
#include "IZ_keyboard.h" | #include "IZ_keyboard.h" | ||||
#include "IZ_joystick.h" | #include "IZ_joystick.h" | ||||
#include "IZ_midi.h" | #include "IZ_midi.h" | ||||
@@ -20,9 +21,9 @@ spec("input") { | |||||
describe("Initialize") { | describe("Initialize") { | ||||
static IZ_JoystickState state[IZ_PLAYERS]; | static IZ_JoystickState state[IZ_PLAYERS]; | ||||
after_each() { | |||||
mock_reset(SDL_memcpy); | |||||
} | |||||
// after_each() { | |||||
// mock_reset(IZ_memcpy); | |||||
// } | |||||
after_each() { | after_each() { | ||||
mock_reset(SDL_NumJoysticks); | mock_reset(SDL_NumJoysticks); | ||||
@@ -43,7 +44,7 @@ spec("input") { | |||||
it("sets initial state") { | it("sets initial state") { | ||||
IZ_JoystickInitialize(&state, "config-game.ini", 0, NULL); | IZ_JoystickInitialize(&state, "config-game.ini", 0, NULL); | ||||
check(mock_is_called(SDL_memcpy), "Initial state not loaded."); | |||||
// check(mock_is_called(IZ_memcpy), "Initial state not loaded."); | |||||
check(mock_is_called(SDL_NumJoysticks), "Connected joysticks not checked."); | check(mock_is_called(SDL_NumJoysticks), "Connected joysticks not checked."); | ||||
} | } | ||||
@@ -395,9 +396,9 @@ spec("input") { | |||||
describe("Initialize") { | describe("Initialize") { | ||||
static IZ_KeyboardState state[IZ_PLAYERS] = {}; | static IZ_KeyboardState state[IZ_PLAYERS] = {}; | ||||
after_each() { | |||||
mock_reset(SDL_memcpy); | |||||
} | |||||
// after_each() { | |||||
// mock_reset(IZ_memcpy); | |||||
// } | |||||
after_each() { | after_each() { | ||||
mock_reset(ini_gets); | mock_reset(ini_gets); | ||||
@@ -418,7 +419,7 @@ spec("input") { | |||||
it("sets initial state") { | it("sets initial state") { | ||||
IZ_KeyboardInitialize(&state, "config-game.ini", 0, NULL); | IZ_KeyboardInitialize(&state, "config-game.ini", 0, NULL); | ||||
check(mock_is_called(SDL_memcpy), "Initial state not loaded."); | |||||
// check(mock_is_called(IZ_memcpy), "Initial state not loaded."); | |||||
} | } | ||||
it("calls load method") { | it("calls load method") { | ||||
@@ -520,9 +521,9 @@ spec("input") { | |||||
describe("Initialize") { | describe("Initialize") { | ||||
static IZ_MIDIInputState state[IZ_PLAYERS]; | static IZ_MIDIInputState state[IZ_PLAYERS]; | ||||
after_each() { | |||||
mock_reset(SDL_memcpy); | |||||
} | |||||
// after_each() { | |||||
// mock_reset(IZ_memcpy); | |||||
// } | |||||
after_each() { | after_each() { | ||||
mock_reset(Pm_CountDevices); | mock_reset(Pm_CountDevices); | ||||
@@ -551,7 +552,7 @@ spec("input") { | |||||
it("sets initial state") { | it("sets initial state") { | ||||
IZ_MIDIInputInitialize(&state, "config-game.ini", 0, NULL); | IZ_MIDIInputInitialize(&state, "config-game.ini", 0, NULL); | ||||
check(mock_is_called(SDL_memcpy), "Initial state not loaded."); | |||||
// check(mock_is_called(IZ_memcpy), "Initial state not loaded."); | |||||
check(mock_is_called(Pm_CountDevices), "Connected MIDI devices not checked."); | check(mock_is_called(Pm_CountDevices), "Connected MIDI devices not checked."); | ||||
} | } | ||||
@@ -65,7 +65,7 @@ IZ_ProcedureResult IZ_VideoInitializeConfig(IZ_VideoState* state, const char* c | |||||
} | } | ||||
IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState* state, void* user_data, const char* config_path, u8 argc, const char* argv[]) { | IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState* state, void* user_data, const char* config_path, u8 argc, const char* argv[]) { | ||||
SDL_memcpy(state, &IZ_VIDEO_DEFAULT_STATE, sizeof(IZ_VideoState)); | |||||
IZ_memcpy(state, sizeof(IZ_VideoState), &IZ_VIDEO_DEFAULT_STATE, sizeof(IZ_VideoState)); | |||||
memset(state->active_sprites, 0, sizeof(IZ_SpriteSlot) * MAX_ACTIVE_SPRITES); | memset(state->active_sprites, 0, sizeof(IZ_SpriteSlot) * MAX_ACTIVE_SPRITES); | ||||
if (IZ_VideoInitializeConfig(state, config_path, argc, argv) < 0) { | if (IZ_VideoInitializeConfig(state, config_path, argc, argv) < 0) { | ||||
return -2; | return -2; | ||||
@@ -9,6 +9,7 @@ | |||||
#include "../../../net/IZ_net_client.h" | #include "../../../net/IZ_net_client.h" | ||||
#include "../../../config/IZ_config.h" | #include "../../../config/IZ_config.h" | ||||
#include "../../../common/IZ_common.h" | #include "../../../common/IZ_common.h" | ||||
#include "../../../string/IZ_string.h" | |||||
#include "../../geometry/IZ_vector2d.h" | #include "../../geometry/IZ_vector2d.h" | ||||
#include "../../input/IZ_input.h" | #include "../../input/IZ_input.h" | ||||
@@ -1,18 +0,0 @@ | |||||
#ifndef IZ_UTIL_MIDI_H | |||||
#define IZ_UTIL_MIDI_H | |||||
#include <stdio.h> | |||||
#include <string.h> | |||||
#include "../../common/IZ_common.h" | |||||
typedef u8 IZ_MIDINote; | |||||
static const u8 IZ_MIDI_NOTE_ON = 0x90u; | |||||
static const u8 IZ_MIDI_NOTE_OFF = 0x80u; | |||||
char* IZ_MIDIGetNoteName(u8); | |||||
u8 IZ_MIDIGetNoteFromName(const char*); | |||||
#endif |
@@ -1,6 +1,6 @@ | |||||
#include "IZ_midi.h" | #include "IZ_midi.h" | ||||
char* IZ_MIDIGetNoteName(u8 midi_note) { | |||||
char* IZ_MIDIGetNoteName(unsigned char midi_note) { | |||||
static const char* pitch_names[] = { | static const char* pitch_names[] = { | ||||
"C", | "C", | ||||
"C#", | "C#", | ||||
@@ -16,30 +16,24 @@ char* IZ_MIDIGetNoteName(u8 midi_note) { | |||||
"B" | "B" | ||||
}; | }; | ||||
const u8 pitch_class = midi_note % 12; | |||||
const u8 octave = midi_note / 12; | |||||
const unsigned char pitch_class = midi_note % 12; | |||||
const unsigned char octave = midi_note / 12; | |||||
static char note_name[8]; | static char note_name[8]; | ||||
sprintf(note_name, "%s%u", pitch_names[pitch_class], octave); | sprintf(note_name, "%s%u", pitch_names[pitch_class], octave); | ||||
return note_name; | return note_name; | ||||
} | } | ||||
u8 IZ_MIDIGetNoteFromName(const char* name) { | |||||
unsigned char IZ_MIDIGetNoteFromName(const char* name) { | |||||
char name_copy[8]; | char name_copy[8]; | ||||
memcpy(name_copy, name, 8); | |||||
#ifdef IZ_WIN32 | |||||
_strlwr_s(name_copy, 8); | |||||
#elif defined IZ_WIN64 | |||||
_strlwr_s(name_copy, 8); | |||||
#else | |||||
_strlwr(name_copy); | |||||
#endif | |||||
IZ_memcpy(name_copy, 8, name, 8); | |||||
IZ_strlwr(name_copy, 8); | |||||
u8 octave; | |||||
unsigned char octave; | |||||
const char base_pitch_name[] = "c d ef g a b"; | const char base_pitch_name[] = "c d ef g a b"; | ||||
if (strlen(name_copy) == 2) { | if (strlen(name_copy) == 2) { | ||||
octave = name_copy[1] - '0'; | octave = name_copy[1] - '0'; | ||||
u8 pitch_index; | |||||
unsigned char pitch_index; | |||||
for (pitch_index = 0; pitch_index < 12; pitch_index += 1) { | for (pitch_index = 0; pitch_index < 12; pitch_index += 1) { | ||||
if (base_pitch_name[pitch_index] == name_copy[0]) { | if (base_pitch_name[pitch_index] == name_copy[0]) { | ||||
return (octave * 12) + pitch_index; | return (octave * 12) + pitch_index; | ||||
@@ -48,7 +42,7 @@ u8 IZ_MIDIGetNoteFromName(const char* name) { | |||||
return 255u; // invalid note value | return 255u; // invalid note value | ||||
} | } | ||||
u8 pitch_class; | |||||
unsigned char pitch_class; | |||||
octave = name_copy[2] - '0'; | octave = name_copy[2] - '0'; | ||||
if (strstr(name_copy, "c#") || strstr(name_copy, "db")) { | if (strstr(name_copy, "c#") || strstr(name_copy, "db")) { | ||||
pitch_class = 1; | pitch_class = 1; |
@@ -0,0 +1,18 @@ | |||||
#ifndef IZ_MIDI_MIDI_H | |||||
#define IZ_MIDI_MIDI_H | |||||
#include <stdio.h> | |||||
#include <string.h> | |||||
#include "../string/IZ_string.h" | |||||
typedef unsigned char IZ_MIDINote; | |||||
static const unsigned char IZ_MIDI_NOTE_ON = 0x90u; | |||||
static const unsigned char IZ_MIDI_NOTE_OFF = 0x80u; | |||||
char* IZ_MIDIGetNoteName(unsigned char); | |||||
unsigned char IZ_MIDIGetNoteFromName(const char*); | |||||
#endif |
@@ -106,7 +106,7 @@ IZ_ProcedureResult IZ_NetClientInitialize( | |||||
if (!user_data) { | if (!user_data) { | ||||
return -1; | return -1; | ||||
} | } | ||||
memcpy(state, &IZ_NET_CLIENT_DEFAULT_STATE, sizeof(IZ_NetClientState)); | |||||
IZ_memcpy(state, sizeof(IZ_NetClientState), &IZ_NET_CLIENT_DEFAULT_STATE, sizeof(IZ_NetClientState)); | |||||
if (IZ_NetClientInitializeConfig(state, config_path, argc, argv) < 0) { | if (IZ_NetClientInitializeConfig(state, config_path, argc, argv) < 0) { | ||||
return -2; | return -2; | ||||
} | } | ||||
@@ -6,6 +6,7 @@ | |||||
#include "../config/IZ_config.h" | #include "../config/IZ_config.h" | ||||
#include "../common/IZ_common.h" | #include "../common/IZ_common.h" | ||||
#include "../game/input/IZ_action.h" | #include "../game/input/IZ_action.h" | ||||
#include "../string/IZ_string.h" | |||||
#include "svc/IZ_wsclient.h" | #include "svc/IZ_wsclient.h" | ||||
typedef enum { | typedef enum { | ||||
@@ -84,7 +84,7 @@ IZ_ProcedureResult IZ_NetServerInitialize( | |||||
if (!user_data) { | if (!user_data) { | ||||
return -1; | return -1; | ||||
} | } | ||||
memcpy_s(state, sizeof(IZ_NetServerState), &IZ_NET_SERVER_DEFAULT_STATE, sizeof(IZ_NetServerState)); | |||||
IZ_memcpy(state, sizeof(IZ_NetServerState), &IZ_NET_SERVER_DEFAULT_STATE, sizeof(IZ_NetServerState)); | |||||
if (IZ_NetServerInitializeConfig(state, config_path, argc, argv) < 0) { | if (IZ_NetServerInitializeConfig(state, config_path, argc, argv) < 0) { | ||||
return -2; | return -2; | ||||
} | } | ||||
@@ -4,6 +4,7 @@ | |||||
#include <minIni.h> | #include <minIni.h> | ||||
#include "../config/IZ_config.h" | #include "../config/IZ_config.h" | ||||
#include "../common/IZ_common.h" | #include "../common/IZ_common.h" | ||||
#include "../string/IZ_string.h" | |||||
#include "core/IZ_websocket.h" | #include "core/IZ_websocket.h" | ||||
#include "svc/IZ_wsserver.h" | #include "svc/IZ_wsserver.h" | ||||
@@ -39,7 +39,7 @@ IZ_ProcedureResult IZ_WebsocketCreateBinaryMessage(struct lws* wsi, IZ_Websocket | |||||
amsg->final = (u8) lws_is_final_fragment(wsi); | amsg->final = (u8) lws_is_final_fragment(wsi); | ||||
amsg->binary = true; | amsg->binary = true; | ||||
amsg->len = len; | amsg->len = len; | ||||
memcpy((char*) amsg->payload + LWS_PRE, in, len); | |||||
IZ_memcpy((char*) amsg->payload + LWS_PRE, len, in, len); | |||||
return 0; | return 0; | ||||
} | } | ||||
@@ -54,6 +54,6 @@ IZ_ProcedureResult IZ_WebsocketCreateTextMessage(struct lws* wsi, IZ_WebsocketMe | |||||
amsg->final = (u8) lws_is_final_fragment(wsi); | amsg->final = (u8) lws_is_final_fragment(wsi); | ||||
amsg->binary = false; | amsg->binary = false; | ||||
amsg->len = len; | amsg->len = len; | ||||
memcpy((char*) amsg->payload + LWS_PRE, in, len); | |||||
IZ_memcpy((char*) amsg->payload + LWS_PRE, len, in, len); | |||||
return 0; | return 0; | ||||
} | } |
@@ -3,6 +3,7 @@ | |||||
#include "libwebsockets.h" | #include "libwebsockets.h" | ||||
#include "../../common/IZ_common.h" | #include "../../common/IZ_common.h" | ||||
#include "../../string/IZ_string.h" | |||||
#define NETWORK_PROTOCOL "izanagi-networking" | #define NETWORK_PROTOCOL "izanagi-networking" | ||||
#define RING_COUNT 32 | #define RING_COUNT 32 | ||||
@@ -19,7 +19,7 @@ IZ_ProcedureResult IZ_AppInitialize(IZ_App *app, u8 argc, const char **argv) { | |||||
char config_path[128]; | char config_path[128]; | ||||
// TODO abstract command line args parsing | // TODO abstract command line args parsing | ||||
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-c"))) { | if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-c"))) { | ||||
memcpy_s(config_path, 128, cmdline_buffer, 128); | |||||
IZ_memcpy(config_path, 128, cmdline_buffer, 128); | |||||
} else { | } else { | ||||
IZ_ConfigGetDefaultPath(config_path, 128); | IZ_ConfigGetDefaultPath(config_path, 128); | ||||
} | } | ||||
@@ -6,6 +6,7 @@ | |||||
#include "../common/IZ_common.h" | #include "../common/IZ_common.h" | ||||
#include "../net/IZ_net_server.h" | #include "../net/IZ_net_server.h" | ||||
#include "../log/IZ_log.h" | #include "../log/IZ_log.h" | ||||
#include "../string/IZ_string.h" | |||||
#include "db/IZ_repo.h" | #include "db/IZ_repo.h" | ||||
#include "IZ_app_config.h" | #include "IZ_app_config.h" | ||||
@@ -1,12 +1,12 @@ | |||||
#include "IZ_app_config.h" | #include "IZ_app_config.h" | ||||
void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) { | |||||
void IZ_ConfigGetDefaultPath(char* config_path, size_t string_size) { | |||||
#ifdef IZ_DEBUG | #ifdef IZ_DEBUG | ||||
const char* config_path_dir = SDL_GetBasePath(); | const char* config_path_dir = SDL_GetBasePath(); | ||||
#else | #else | ||||
const char* config_path_dir = SDL_GetPrefPath("Modal Studios", IZ_APP_NAME); | const char* config_path_dir = SDL_GetPrefPath("Modal Studios", IZ_APP_NAME); | ||||
#endif | #endif | ||||
memcpy_s(config_path, string_size, config_path_dir, 128); | |||||
strcat_s(config_path, string_size, "config-server.ini"); | |||||
IZ_memcpy(config_path, string_size, config_path_dir, 128); | |||||
IZ_strcat(config_path, string_size, "config-server.ini"); | |||||
} | } |
@@ -3,6 +3,7 @@ | |||||
#include <SDL_filesystem.h> | #include <SDL_filesystem.h> | ||||
#include "../config/IZ_config.h" | #include "../config/IZ_config.h" | ||||
#include "../string/IZ_string.h" | |||||
#include "IZ_subsystem.h" | #include "IZ_subsystem.h" | ||||
#endif | #endif |
@@ -36,7 +36,7 @@ IZ_ProcedureResult IZ_RepoInitializeConfig(IZ_RepoState* state, const char* conf | |||||
} | } | ||||
IZ_ProcedureResult IZ_RepoInitialize(IZ_RepoState* state, const char* config_path, u8 argc, const char* argv[]) { | IZ_ProcedureResult IZ_RepoInitialize(IZ_RepoState* state, const char* config_path, u8 argc, const char* argv[]) { | ||||
memcpy_s(state, sizeof(IZ_RepoState), &IZ_REPO_DEFAULT_STATE, sizeof(IZ_RepoState)); | |||||
IZ_memcpy(state, sizeof(IZ_RepoState), &IZ_REPO_DEFAULT_STATE, sizeof(IZ_RepoState)); | |||||
if (IZ_RepoInitializeConfig(state, config_path, argc, argv) < 0) { | if (IZ_RepoInitializeConfig(state, config_path, argc, argv) < 0) { | ||||
return -2; | return -2; | ||||
} | } | ||||
@@ -6,6 +6,7 @@ | |||||
#include <string.h> | #include <string.h> | ||||
#include "../../common/IZ_common.h" | #include "../../common/IZ_common.h" | ||||
#include "../../config/IZ_config.h" | #include "../../config/IZ_config.h" | ||||
#include "../../string/IZ_string.h" | |||||
typedef struct { | typedef struct { | ||||
char path[64]; | char path[64]; | ||||
@@ -0,0 +1,26 @@ | |||||
#include "IZ_string.h" | |||||
errno_t IZ_memcpy(void* const dest, const rsize_t dest_size, const void* const source, const rsize_t source_size) { | |||||
#if defined IZ_WIN64 | |||||
return memcpy_s(dest, dest_size, source, source_size); | |||||
#else | |||||
return memcpy(dest, source, dest_size - 1); | |||||
#endif | |||||
} | |||||
errno_t IZ_strcat(char* dest, rsize_t source_size, const char* source) { | |||||
#if defined IZ_WIN64 | |||||
return strcat_s(dest, source_size, source); | |||||
#else | |||||
return strcat(dest, source); | |||||
#endif | |||||
} | |||||
errno_t IZ_strlwr(char* str, rsize_t str_size) { | |||||
#if defined IZ_WIN64 | |||||
return _strlwr_s(str, str_size); | |||||
#else | |||||
return _strlwr(str); | |||||
#endif | |||||
} |
@@ -0,0 +1,12 @@ | |||||
#ifndef IZ_STRING_H | |||||
#define IZ_STRING_H | |||||
#include <string.h> | |||||
errno_t IZ_memcpy(void*, rsize_t, const void*, rsize_t); | |||||
errno_t IZ_strcat(char*, rsize_t, const char*); | |||||
errno_t IZ_strlwr(char*, rsize_t); | |||||
#endif |