Make server optionally have a mountpoint for putting assets.feature/data-structs
@@ -13,6 +13,11 @@ if (WIN32) | |||
endif () | |||
endif () | |||
add_definitions(-DIZ_APP_NAME="Izanagi" -DIZ_PLAYERS=1) | |||
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") | |||
add_definitions(-DIZ_DEBUG) | |||
endif() | |||
include_directories( | |||
"${PROJECT_SOURCE_DIR}/dependencies/SDL2/include" | |||
"${PROJECT_SOURCE_DIR}/dependencies/minIni/dev" | |||
@@ -140,7 +140,7 @@ void IZ_AppHandlePortMIDIEvents(IZ_App* app) { | |||
u8 player_index; | |||
i32* midi_events_count; | |||
u32 midi_event_index; | |||
for (player_index = 0; player_index < PLAYERS; player_index += 1) { | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
if (!app->input_state.midi_input_state[player_index].device_info) { | |||
continue; | |||
} | |||
@@ -385,7 +385,7 @@ IZ_ProcedureResult IZ_WSClientWritable(struct lws* wsi) { | |||
} | |||
IZ_WebsocketMessage* IZ_WSClientCreateMessage(struct lws* wsi, bool binary, void* in, size_t len) { | |||
IZ_WebsocketMessage amsg; | |||
static IZ_WebsocketMessage amsg; | |||
amsg.first = (char)lws_is_first_fragment(wsi); | |||
amsg.final = (char)lws_is_final_fragment(wsi); | |||
amsg.binary = binary; | |||
@@ -27,6 +27,46 @@ typedef struct { | |||
u64 ticks; | |||
} IZ_App; | |||
typedef struct { | |||
u8 player_index: 3; | |||
u8 player_state: 5; | |||
u16 action_set; | |||
} IZ_AppPlayerActionSyncMessage; | |||
typedef struct { | |||
u8 player_index: 3; | |||
f32 x; | |||
f32 y; | |||
f32 right; | |||
f32 up; | |||
} IZ_AppPlayerState; | |||
typedef enum { | |||
IZ_MESSAGE_KIND_ACTION_SYNC = 0, | |||
IZ_MESSAGE_KIND_STATE_SYNC = 1, | |||
} IZ_MessageKind; | |||
typedef struct { | |||
u8 message_kind; // player | |||
u64 client_elapsed_time; // for synchronization | |||
} IZ_AppMessageHeader; | |||
typedef struct { | |||
u8 player_actions_count; | |||
IZ_AppPlayerActionSyncMessage player_actions[]; | |||
} IZ_AppPlayerActionSection; | |||
typedef struct { | |||
IZ_AppMessageHeader header; | |||
IZ_AppPlayerActionSection player_actions; | |||
} IZ_AppActionSyncMessage; | |||
typedef struct { | |||
IZ_AppMessageHeader header; | |||
IZ_AppPlayerState player_state[IZ_PLAYERS]; | |||
IZ_AppPlayerActionSection player_actions; | |||
} IZ_AppStateSyncMessage; | |||
IZ_ProcedureResult IZ_AppRun(IZ_App*, u8, const char**); | |||
#endif |
@@ -4,9 +4,6 @@ | |||
#include <stdint.h> | |||
#include <stdbool.h> | |||
#define PLAYERS (unsigned char) 1 | |||
#define APP_NAME "SDL2" | |||
typedef uint8_t u8; | |||
typedef uint16_t u16; | |||
typedef uint32_t u32; | |||
@@ -1,8 +1,12 @@ | |||
#include "IZ_config.h" | |||
void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) { | |||
//const char* config_path_dir = SDL_GetPrefPath("Modal Studios", APP_NAME); | |||
#ifdef IZ_DEBUG | |||
const char* config_path_dir = SDL_GetBasePath(); | |||
#else | |||
const char* config_path_dir = SDL_GetPrefPath("Modal Studios", IZ_APP_NAME); | |||
#endif | |||
memcpy_s(config_path, string_size, config_path_dir, 128); | |||
strcat_s(config_path, string_size, "config-game.ini"); | |||
} | |||
@@ -32,7 +32,7 @@ IZ_ProcedureResult IZ_InputInitialize(IZ_InputState* state, const char* config_p | |||
} | |||
u8 player_index; | |||
for (player_index = 0; player_index < PLAYERS; player_index += 1) { | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
state->action[player_index] = 0; | |||
} | |||
@@ -7,10 +7,10 @@ | |||
#include "IZ_midi.h" | |||
typedef struct { | |||
IZ_Action action[PLAYERS]; | |||
IZ_KeyboardState keyboard_state[PLAYERS]; | |||
IZ_JoystickState joystick_state[PLAYERS]; | |||
IZ_MIDIInputState midi_input_state[PLAYERS]; | |||
IZ_Action action[IZ_PLAYERS]; | |||
IZ_KeyboardState keyboard_state[IZ_PLAYERS]; | |||
IZ_JoystickState joystick_state[IZ_PLAYERS]; | |||
IZ_MIDIInputState midi_input_state[IZ_PLAYERS]; | |||
} IZ_InputState; | |||
void IZ_InputHandleSDLEvents(IZ_InputState*, SDL_Event); | |||
@@ -2,7 +2,7 @@ | |||
void IZ_JoystickHandleDeviceEvents(IZ_JoystickState* state, SDL_Event e) { | |||
if (e.type == SDL_JOYDEVICEADDED) { | |||
if (SDL_NumJoysticks() <= PLAYERS && !state->device) { | |||
if (SDL_NumJoysticks() <= IZ_PLAYERS && !state->device) { | |||
state->device = SDL_JoystickOpen(e.jdevice.which); | |||
} | |||
return; | |||
@@ -83,9 +83,9 @@ void IZ_JoystickHandleButtonEvents(IZ_JoystickState* state, IZ_Action* action, S | |||
} | |||
} | |||
void IZ_JoystickHandleEvents(IZ_JoystickState(* state)[PLAYERS], IZ_Action(* action)[PLAYERS], SDL_Event e) { | |||
void IZ_JoystickHandleEvents(IZ_JoystickState(* state)[IZ_PLAYERS], IZ_Action(* action)[IZ_PLAYERS], SDL_Event e) { | |||
u8 player_index; | |||
for (player_index = 0; player_index < PLAYERS; player_index += 1) { | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
IZ_JoystickHandleDeviceEvents(&(*state)[player_index], e); | |||
IZ_JoystickHandleAxisEvents(&(*state)[player_index], &(*action)[player_index], e); | |||
IZ_JoystickHandleHatEvents(&(*action)[player_index], e); | |||
@@ -93,13 +93,13 @@ void IZ_JoystickHandleEvents(IZ_JoystickState(* state)[PLAYERS], IZ_Action(* act | |||
} | |||
} | |||
void IZ_JoystickLoadConfig(IZ_JoystickState(* state)[PLAYERS], const char* config_path) { | |||
void IZ_JoystickLoadConfig(IZ_JoystickState(* state)[IZ_PLAYERS], const char* config_path) { | |||
char control_mapping_section_name[26]; | |||
char main_section_name[11]; | |||
u8 player_index; | |||
u8 control_index; | |||
for (player_index = 0; player_index < PLAYERS; player_index += 1) { | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
sprintf_s(control_mapping_section_name, 26, "Joystick.%d.ControlMapping", player_index); | |||
for (control_index = 4; control_index < CONTROLS; control_index += 1) { | |||
@@ -117,7 +117,7 @@ void IZ_JoystickLoadConfig(IZ_JoystickState(* state)[PLAYERS], const char* confi | |||
} | |||
} | |||
IZ_ProcedureResult IZ_JoystickSaveConfig(IZ_JoystickState(* state)[PLAYERS], const char* config_path) { | |||
IZ_ProcedureResult IZ_JoystickSaveConfig(IZ_JoystickState(* state)[IZ_PLAYERS], const char* config_path) { | |||
u8 problem = 0; | |||
char control_mapping_section_name[26]; | |||
@@ -125,7 +125,7 @@ IZ_ProcedureResult IZ_JoystickSaveConfig(IZ_JoystickState(* state)[PLAYERS], con | |||
u8 player_index; | |||
u8 control_index; | |||
for (player_index = 0; player_index < PLAYERS; player_index += 1) { | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
sprintf_s(control_mapping_section_name, 26, "Joystick.%d.ControlMapping", player_index); | |||
for (control_index = 4; control_index < CONTROLS; control_index += 1) { | |||
if (!ini_putl( | |||
@@ -161,7 +161,7 @@ IZ_ProcedureResult IZ_JoystickSaveConfig(IZ_JoystickState(* state)[PLAYERS], con | |||
return -problem; | |||
} | |||
IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(* state)[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_DEFAULT_JOYSTICK_STATE, sizeof(IZ_JoystickState)); | |||
IZ_JoystickLoadConfig(state, config_path); | |||
@@ -172,7 +172,7 @@ IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(* state)[PLAYERS], con | |||
u8 joysticks_count = SDL_NumJoysticks(); | |||
u8 player_index; | |||
for (player_index = 0; player_index < joysticks_count; player_index += 1) { | |||
if (player_index >= PLAYERS) { | |||
if (player_index >= IZ_PLAYERS) { | |||
break; | |||
} | |||
(*state)[player_index].device = SDL_JoystickOpen(state[player_index]->config.device_id); | |||
@@ -181,9 +181,9 @@ IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(* state)[PLAYERS], con | |||
return 0; | |||
} | |||
void IZ_JoystickTeardown(IZ_JoystickState(* state)[PLAYERS]) { | |||
void IZ_JoystickTeardown(IZ_JoystickState(* state)[IZ_PLAYERS]) { | |||
u8 player_index; | |||
for (player_index = 0; player_index < PLAYERS; player_index += 1) { | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
if (!(*state)[player_index].device) { | |||
continue; | |||
} | |||
@@ -29,7 +29,7 @@ typedef struct { | |||
IZ_JoystickConfig config; | |||
} IZ_JoystickState; | |||
static const IZ_JoystickState IZ_DEFAULT_JOYSTICK_STATE[PLAYERS] = { | |||
static const IZ_JoystickState IZ_DEFAULT_JOYSTICK_STATE[IZ_PLAYERS] = { | |||
{ | |||
.config = { | |||
.control_mapping = { | |||
@@ -82,12 +82,12 @@ static const IZ_JoystickState IZ_DEFAULT_JOYSTICK_STATE[PLAYERS] = { | |||
}, | |||
}; | |||
IZ_ProcedureResult IZ_JoystickSaveConfig(IZ_JoystickState(*)[PLAYERS], const char*); | |||
IZ_ProcedureResult IZ_JoystickSaveConfig(IZ_JoystickState(*)[IZ_PLAYERS], const char*); | |||
void IZ_JoystickHandleEvents(IZ_JoystickState(*)[PLAYERS], IZ_Action(*)[PLAYERS], SDL_Event); | |||
void IZ_JoystickHandleEvents(IZ_JoystickState(*)[IZ_PLAYERS], IZ_Action(*)[IZ_PLAYERS], SDL_Event); | |||
IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(*)[PLAYERS], const char*, u8, const char**); | |||
IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(*)[IZ_PLAYERS], const char*, u8, const char**); | |||
void IZ_JoystickTeardown(IZ_JoystickState(*)[PLAYERS]); | |||
void IZ_JoystickTeardown(IZ_JoystickState(*)[IZ_PLAYERS]); | |||
#endif |
@@ -17,19 +17,19 @@ void IZ_KeyboardHandleKeyUpDownEvents(IZ_KeyboardState* state, IZ_Action* action | |||
} | |||
} | |||
void IZ_KeyboardHandleEvents(IZ_KeyboardState(* state)[PLAYERS], IZ_Action(* action)[PLAYERS], SDL_Event e) { | |||
for (u8 player_index = 0; player_index < PLAYERS; player_index += 1) { | |||
void IZ_KeyboardHandleEvents(IZ_KeyboardState(* state)[IZ_PLAYERS], IZ_Action(* action)[IZ_PLAYERS], SDL_Event e) { | |||
for (u8 player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
IZ_KeyboardHandleKeyUpDownEvents(&(*state)[player_index], &(*action)[player_index], e); | |||
} | |||
} | |||
IZ_ProcedureResult IZ_KeyboardSaveConfig(IZ_KeyboardState(* state)[PLAYERS], const char* config_path) { | |||
IZ_ProcedureResult IZ_KeyboardSaveConfig(IZ_KeyboardState(* state)[IZ_PLAYERS], const char* config_path) { | |||
u8 problem = 0; | |||
char control_mapping_section_name[26]; | |||
u8 player_index; | |||
u8 control_index; | |||
for (player_index = 0; player_index < PLAYERS; player_index += 1) { | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
sprintf_s(control_mapping_section_name, 26, "Keyboard.%d.ControlMapping", player_index); | |||
for (control_index = 0; control_index < CONTROLS; control_index += 1) { | |||
if (!ini_puts( | |||
@@ -46,13 +46,13 @@ IZ_ProcedureResult IZ_KeyboardSaveConfig(IZ_KeyboardState(* state)[PLAYERS], con | |||
return problem; | |||
} | |||
void IZ_KeyboardLoadConfig(IZ_KeyboardState(* state)[PLAYERS], const char* config_path) { | |||
void IZ_KeyboardLoadConfig(IZ_KeyboardState(* state)[IZ_PLAYERS], const char* config_path) { | |||
char buffer[128]; | |||
char keyboard_section_name[26]; | |||
u8 player_index; | |||
u8 control_index; | |||
for (player_index = 0; player_index < PLAYERS; player_index += 1) { | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
sprintf_s(keyboard_section_name, 26, "Keyboard.%d.ControlMapping", player_index); | |||
for (control_index = 0; control_index < CONTROLS; control_index += 1) { | |||
ini_gets( | |||
@@ -69,7 +69,7 @@ void IZ_KeyboardLoadConfig(IZ_KeyboardState(* state)[PLAYERS], const char* confi | |||
} | |||
} | |||
IZ_ProcedureResult IZ_KeyboardInitialize(IZ_KeyboardState(* state)[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_DEFAULT_KEYBOARD_STATE, sizeof(IZ_KeyboardState)); | |||
IZ_KeyboardLoadConfig(state, config_path); | |||
return IZ_KeyboardSaveConfig(state, config_path); | |||
@@ -15,7 +15,7 @@ typedef struct { | |||
IZ_KeyboardConfig config; | |||
} IZ_KeyboardState; | |||
static const IZ_KeyboardState IZ_DEFAULT_KEYBOARD_STATE[PLAYERS] = { | |||
static const IZ_KeyboardState IZ_DEFAULT_KEYBOARD_STATE[IZ_PLAYERS] = { | |||
{ | |||
.config = { | |||
.control_mapping = { | |||
@@ -62,10 +62,10 @@ static const IZ_KeyboardState IZ_DEFAULT_KEYBOARD_STATE[PLAYERS] = { | |||
}, | |||
}; | |||
IZ_ProcedureResult IZ_KeyboardSaveConfig(IZ_KeyboardState(*)[PLAYERS], const char*); | |||
IZ_ProcedureResult IZ_KeyboardSaveConfig(IZ_KeyboardState(*)[IZ_PLAYERS], const char*); | |||
void IZ_KeyboardHandleEvents(IZ_KeyboardState(*)[PLAYERS], IZ_Action(*)[PLAYERS], SDL_Event); | |||
void IZ_KeyboardHandleEvents(IZ_KeyboardState(*)[IZ_PLAYERS], IZ_Action(*)[IZ_PLAYERS], SDL_Event); | |||
IZ_ProcedureResult IZ_KeyboardInitialize(IZ_KeyboardState(*)[PLAYERS], const char*, u8, const char**); | |||
IZ_ProcedureResult IZ_KeyboardInitialize(IZ_KeyboardState(*)[IZ_PLAYERS], const char*, u8, const char**); | |||
#endif |
@@ -29,14 +29,14 @@ void IZ_MIDIInputHandleNoteOnOffEvents(IZ_MIDIInputState* state, IZ_Action* acti | |||
} | |||
} | |||
void IZ_MIDIInputHandleEvents(IZ_MIDIInputState(* state)[PLAYERS], IZ_Action(* action)[PLAYERS], PmEvent e) { | |||
void IZ_MIDIInputHandleEvents(IZ_MIDIInputState(* state)[IZ_PLAYERS], IZ_Action(* action)[IZ_PLAYERS], PmEvent e) { | |||
u8 player_index; | |||
for (player_index = 0; player_index < PLAYERS; player_index += 1) { | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
IZ_MIDIInputHandleNoteOnOffEvents(&(*state)[player_index], &(*action)[player_index], e); | |||
} | |||
} | |||
IZ_ProcedureResult IZ_MIDIInputSaveConfig(IZ_MIDIInputState(* state)[PLAYERS], const char* config_path) { | |||
IZ_ProcedureResult IZ_MIDIInputSaveConfig(IZ_MIDIInputState(* state)[IZ_PLAYERS], const char* config_path) { | |||
u8 problem = 0; | |||
char control_mapping_section_name[27]; | |||
@@ -44,7 +44,7 @@ IZ_ProcedureResult IZ_MIDIInputSaveConfig(IZ_MIDIInputState(* state)[PLAYERS], c | |||
u8 player_index; | |||
u8 control_index; | |||
for (player_index = 0; player_index < PLAYERS; player_index += 1) { | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
sprintf_s(control_mapping_section_name, 27, "MIDIInput.%d.ControlMapping", player_index); | |||
for (control_index = 0; control_index < CONTROLS; control_index += 1) { | |||
if (!ini_puts( | |||
@@ -80,14 +80,14 @@ IZ_ProcedureResult IZ_MIDIInputSaveConfig(IZ_MIDIInputState(* state)[PLAYERS], c | |||
return problem; | |||
} | |||
void IZ_MIDIInputLoadConfig(IZ_MIDIInputState(* state)[PLAYERS], const char* config_path) { | |||
void IZ_MIDIInputLoadConfig(IZ_MIDIInputState(* state)[IZ_PLAYERS], const char* config_path) { | |||
char buffer[128]; | |||
char control_mapping_section_name[27]; | |||
char main_section_name[12]; | |||
u8 player_index; | |||
u8 control_index; | |||
for (player_index = 0; player_index < PLAYERS; player_index += 1) { | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
sprintf_s(control_mapping_section_name, 27, "MIDIInput.%d.ControlMapping", player_index); | |||
for (control_index = 0; control_index < CONTROLS; control_index += 1) { | |||
ini_gets( | |||
@@ -108,7 +108,7 @@ void IZ_MIDIInputLoadConfig(IZ_MIDIInputState(* state)[PLAYERS], const char* con | |||
} | |||
} | |||
IZ_ProcedureResult IZ_MIDIInputInitialize(IZ_MIDIInputState(* state)[PLAYERS], const char* config_path, u8 argc, const char* argv[]) { | |||
IZ_ProcedureResult IZ_MIDIInputInitialize(IZ_MIDIInputState(* state)[IZ_PLAYERS], const char* config_path, u8 argc, const char* argv[]) { | |||
if (Pm_Initialize()) { | |||
return 1; | |||
} | |||
@@ -133,7 +133,7 @@ IZ_ProcedureResult IZ_MIDIInputInitialize(IZ_MIDIInputState(* state)[PLAYERS], c | |||
} | |||
for (player_index = 0; player_index < input_midi_devices_count; player_index += 1) { | |||
if (player_index >= PLAYERS) { | |||
if (player_index >= IZ_PLAYERS) { | |||
break; | |||
} | |||
(*state)[player_index].device_info = Pm_GetDeviceInfo((*state)[player_index].config.device_id); | |||
@@ -151,9 +151,9 @@ IZ_ProcedureResult IZ_MIDIInputInitialize(IZ_MIDIInputState(* state)[PLAYERS], c | |||
return 0; | |||
} | |||
void IZ_MIDIInputTeardown(IZ_MIDIInputState(* state)[PLAYERS]) { | |||
void IZ_MIDIInputTeardown(IZ_MIDIInputState(* state)[IZ_PLAYERS]) { | |||
u8 player_index; | |||
for (player_index = 0; player_index < PLAYERS; player_index += 1) { | |||
for (player_index = 0; player_index < IZ_PLAYERS; player_index += 1) { | |||
if (!(*state)[player_index].stream) { | |||
continue; | |||
} | |||
@@ -35,7 +35,7 @@ typedef struct { | |||
i32 midi_events_count; | |||
} IZ_MIDIInputState; | |||
static const IZ_MIDIInputState IZ_DEFAULT_MIDI_INPUT_STATE[PLAYERS] = { | |||
static const IZ_MIDIInputState IZ_DEFAULT_MIDI_INPUT_STATE[IZ_PLAYERS] = { | |||
{ | |||
.config = { | |||
.control_mapping = { | |||
@@ -92,12 +92,12 @@ static const IZ_MIDIInputState IZ_DEFAULT_MIDI_INPUT_STATE[PLAYERS] = { | |||
}, | |||
}; | |||
IZ_ProcedureResult IZ_MIDIInputSaveConfig(IZ_MIDIInputState(*)[PLAYERS], const char*); | |||
IZ_ProcedureResult IZ_MIDIInputSaveConfig(IZ_MIDIInputState(*)[IZ_PLAYERS], const char*); | |||
void IZ_MIDIInputHandleEvents(IZ_MIDIInputState(*)[PLAYERS], IZ_Action(*)[PLAYERS], PmEvent); | |||
void IZ_MIDIInputHandleEvents(IZ_MIDIInputState(*)[IZ_PLAYERS], IZ_Action(*)[IZ_PLAYERS], PmEvent); | |||
IZ_ProcedureResult IZ_MIDIInputInitialize(IZ_MIDIInputState(*)[PLAYERS], const char*, u8, const char**); | |||
IZ_ProcedureResult IZ_MIDIInputInitialize(IZ_MIDIInputState(*)[IZ_PLAYERS], const char*, u8, const char**); | |||
void IZ_MIDIInputTeardown(IZ_MIDIInputState(*)[PLAYERS]); | |||
void IZ_MIDIInputTeardown(IZ_MIDIInputState(*)[IZ_PLAYERS]); | |||
#endif |
@@ -18,7 +18,7 @@ i16 GenerateAxisValueOutsideThreshold(u16 threshold) { | |||
spec("input") { | |||
describe("joystick") { | |||
describe("Initialize") { | |||
static IZ_JoystickState state[PLAYERS]; | |||
static IZ_JoystickState state[IZ_PLAYERS]; | |||
after_each() { | |||
mock_reset(SDL_memcpy); | |||
@@ -48,7 +48,7 @@ spec("input") { | |||
} | |||
it("calls load method") { | |||
mock_set_expected_calls(ini_getl, ((CONTROLS - 4) + 2) * PLAYERS); | |||
mock_set_expected_calls(ini_getl, ((CONTROLS - 4) + 2) * IZ_PLAYERS); | |||
IZ_JoystickInitialize(&state, "config.ini", 0, NULL); | |||
@@ -61,7 +61,7 @@ spec("input") { | |||
} | |||
it("calls save method") { | |||
mock_set_expected_calls(ini_putl, ((CONTROLS - 4) + 2) * PLAYERS); | |||
mock_set_expected_calls(ini_putl, ((CONTROLS - 4) + 2) * IZ_PLAYERS); | |||
IZ_JoystickInitialize(&state, "config.ini", 0, NULL); | |||
@@ -89,11 +89,11 @@ spec("input") { | |||
describe("HandleEvents") { | |||
static SDL_Event e; | |||
static IZ_JoystickState state[PLAYERS] = {}; | |||
static IZ_Action action[PLAYERS] = {}; | |||
static IZ_JoystickState state[IZ_PLAYERS] = {}; | |||
static IZ_Action action[IZ_PLAYERS] = {}; | |||
u8 p; | |||
for (p = 0; p < PLAYERS; p += 1) { | |||
for (p = 0; p < IZ_PLAYERS; p += 1) { | |||
describe("on player %u", p) { | |||
describe("on axis motion events") { | |||
before_each() { | |||
@@ -334,14 +334,14 @@ spec("input") { | |||
} | |||
describe("SaveConfig") { | |||
static IZ_JoystickState state[PLAYERS]; | |||
static IZ_JoystickState state[IZ_PLAYERS]; | |||
after_each() { | |||
mock_reset(ini_putl); | |||
} | |||
before_each() { | |||
for (u8 p = 0; p < PLAYERS; p += 1) { | |||
for (u8 p = 0; p < IZ_PLAYERS; p += 1) { | |||
for (u8 i = 0; i < CONTROLS; i += 1) { | |||
state[p].config.control_mapping[i] = IZ_DEFAULT_JOYSTICK_STATE[p].config.control_mapping[i]; | |||
} | |||
@@ -349,7 +349,7 @@ spec("input") { | |||
} | |||
it("calls save method") { | |||
mock_set_expected_calls(ini_putl, ((CONTROLS - 4) + 2) * PLAYERS); | |||
mock_set_expected_calls(ini_putl, ((CONTROLS - 4) + 2) * IZ_PLAYERS); | |||
IZ_JoystickSaveConfig(&state, "config.ini"); | |||
@@ -364,10 +364,10 @@ spec("input") { | |||
describe("Teardown") { | |||
static SDL_Joystick device; | |||
static IZ_JoystickState state[PLAYERS] = {}; | |||
static IZ_JoystickState state[IZ_PLAYERS] = {}; | |||
before_each() { | |||
for (u8 p = 0; p < PLAYERS; p += 1) { | |||
for (u8 p = 0; p < IZ_PLAYERS; p += 1) { | |||
state[p].device = &device; | |||
} | |||
} | |||
@@ -377,7 +377,7 @@ spec("input") { | |||
} | |||
it("closes opened devices") { | |||
mock_set_expected_calls(SDL_JoystickClose, PLAYERS); | |||
mock_set_expected_calls(SDL_JoystickClose, IZ_PLAYERS); | |||
IZ_JoystickTeardown(&state); | |||
@@ -393,7 +393,7 @@ spec("input") { | |||
describe("keyboard") { | |||
describe("Initialize") { | |||
static IZ_KeyboardState state[PLAYERS] = {}; | |||
static IZ_KeyboardState state[IZ_PLAYERS] = {}; | |||
after_each() { | |||
mock_reset(SDL_memcpy); | |||
@@ -408,7 +408,7 @@ spec("input") { | |||
} | |||
before_each() { | |||
for (u8 p = 0; p < PLAYERS; p += 1) { | |||
for (u8 p = 0; p < IZ_PLAYERS; p += 1) { | |||
for (u8 i = 0; i < CONTROLS; i += 1) { | |||
state[p].config.control_mapping[i] = IZ_DEFAULT_KEYBOARD_STATE[p].config.control_mapping[i]; | |||
} | |||
@@ -422,7 +422,7 @@ spec("input") { | |||
} | |||
it("calls load method") { | |||
mock_set_expected_calls(ini_gets, CONTROLS * PLAYERS); | |||
mock_set_expected_calls(ini_gets, CONTROLS * IZ_PLAYERS); | |||
IZ_KeyboardInitialize(&state, "config.ini", 0, NULL); | |||
@@ -435,7 +435,7 @@ spec("input") { | |||
} | |||
it("calls save method") { | |||
mock_set_expected_calls(ini_puts, CONTROLS * PLAYERS); | |||
mock_set_expected_calls(ini_puts, CONTROLS * IZ_PLAYERS); | |||
IZ_KeyboardInitialize(&state, "config.ini", 0, NULL); | |||
@@ -450,10 +450,10 @@ spec("input") { | |||
describe("HandleEvents") { | |||
static SDL_Event e; | |||
static IZ_KeyboardState state[PLAYERS] = {}; | |||
static IZ_Action action[PLAYERS] = {}; | |||
static IZ_KeyboardState state[IZ_PLAYERS] = {}; | |||
static IZ_Action action[IZ_PLAYERS] = {}; | |||
for (u8 p = 0; p < PLAYERS; p += 1) { | |||
for (u8 p = 0; p < IZ_PLAYERS; p += 1) { | |||
describe("on player %u", p) { | |||
for (u8 i = 0; i < CONTROLS; i += 1) { | |||
it("handles %s action activation", ACTION_NAMES[i]) { | |||
@@ -487,14 +487,14 @@ spec("input") { | |||
} | |||
describe("SaveConfig") { | |||
static IZ_KeyboardState state[PLAYERS] = {}; | |||
static IZ_KeyboardState state[IZ_PLAYERS] = {}; | |||
after_each() { | |||
mock_reset(ini_puts); | |||
} | |||
before_each() { | |||
for (u8 p = 0; p < PLAYERS; p += 1) { | |||
for (u8 p = 0; p < IZ_PLAYERS; p += 1) { | |||
for (u8 i = 0; i < CONTROLS; i += 1) { | |||
state[p].config.control_mapping[i] = IZ_DEFAULT_KEYBOARD_STATE[p].config.control_mapping[i]; | |||
} | |||
@@ -502,7 +502,7 @@ spec("input") { | |||
} | |||
it("calls save method") { | |||
mock_set_expected_calls(ini_puts, CONTROLS * PLAYERS); | |||
mock_set_expected_calls(ini_puts, CONTROLS * IZ_PLAYERS); | |||
IZ_KeyboardSaveConfig("config.ini", &state); | |||
@@ -518,7 +518,7 @@ spec("input") { | |||
describe("midi") { | |||
describe("Initialize") { | |||
static IZ_MIDIInputState state[PLAYERS]; | |||
static IZ_MIDIInputState state[IZ_PLAYERS]; | |||
after_each() { | |||
mock_reset(SDL_memcpy); | |||
@@ -556,8 +556,8 @@ spec("input") { | |||
} | |||
it("calls load method") { | |||
mock_set_expected_calls(ini_gets, CONTROLS * PLAYERS); | |||
mock_set_expected_calls(ini_getl, 2 * PLAYERS); | |||
mock_set_expected_calls(ini_gets, CONTROLS * IZ_PLAYERS); | |||
mock_set_expected_calls(ini_getl, 2 * IZ_PLAYERS); | |||
IZ_MIDIInputInitialize(&state, "config.ini", 0, NULL); | |||
@@ -577,8 +577,8 @@ spec("input") { | |||
} | |||
it("calls save method") { | |||
mock_set_expected_calls(ini_puts, CONTROLS * PLAYERS); | |||
mock_set_expected_calls(ini_putl, 2 * PLAYERS); | |||
mock_set_expected_calls(ini_puts, CONTROLS * IZ_PLAYERS); | |||
mock_set_expected_calls(ini_putl, 2 * IZ_PLAYERS); | |||
IZ_MIDIInputInitialize(&state, "config.ini", 0, NULL); | |||
@@ -612,7 +612,7 @@ spec("input") { | |||
} | |||
describe("SaveConfig") { | |||
static IZ_MIDIInputState state[PLAYERS]; | |||
static IZ_MIDIInputState state[IZ_PLAYERS]; | |||
after_each() { | |||
mock_reset(ini_puts); | |||
@@ -623,8 +623,8 @@ spec("input") { | |||
} | |||
it("calls save method") { | |||
mock_set_expected_calls(ini_puts, CONTROLS * PLAYERS); | |||
mock_set_expected_calls(ini_putl, 2 * PLAYERS); | |||
mock_set_expected_calls(ini_puts, CONTROLS * IZ_PLAYERS); | |||
mock_set_expected_calls(ini_putl, 2 * IZ_PLAYERS); | |||
IZ_MIDIInputSaveConfig("config.ini", &state); | |||
@@ -646,10 +646,10 @@ spec("input") { | |||
describe("HandleEvents") { | |||
static PmEvent e; | |||
static IZ_MIDIInputState state[PLAYERS] = {}; | |||
static IZ_Action action[PLAYERS] = {}; | |||
static IZ_MIDIInputState state[IZ_PLAYERS] = {}; | |||
static IZ_Action action[IZ_PLAYERS] = {}; | |||
for (u8 p = 0; p < PLAYERS; p += 1) { | |||
for (u8 p = 0; p < IZ_PLAYERS; p += 1) { | |||
describe("on player %u", p) { | |||
for (u8 i = 0; i < CONTROLS; i += 1) { | |||
it("handles %s action activation", ACTION_NAMES[i]) { | |||
@@ -682,10 +682,10 @@ spec("input") { | |||
describe("Teardown") { | |||
static PmStream* stream; | |||
static IZ_MIDIInputState state[PLAYERS] = {}; | |||
static IZ_MIDIInputState state[IZ_PLAYERS] = {}; | |||
before_each() { | |||
for (u8 p = 0; p < PLAYERS; p += 1) { | |||
for (u8 p = 0; p < IZ_PLAYERS; p += 1) { | |||
state[p].stream = &stream; | |||
} | |||
} | |||
@@ -695,7 +695,7 @@ spec("input") { | |||
} | |||
it("closes opened devices") { | |||
mock_set_expected_calls(Pm_Close, PLAYERS); | |||
mock_set_expected_calls(Pm_Close, IZ_PLAYERS); | |||
IZ_MIDIInputTeardown(&state); | |||
@@ -38,7 +38,7 @@ IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState* state, const char* config_p | |||
state->last_update_at = 0u; | |||
SDL_Window* window = SDL_CreateWindow( | |||
APP_NAME, | |||
IZ_APP_NAME, | |||
SDL_WINDOWPOS_CENTERED, | |||
SDL_WINDOWPOS_CENTERED, | |||
state->config.width, | |||
@@ -87,7 +87,7 @@ void IZ_VideoUpdateForDebugInput(IZ_VideoState* video_state, IZ_InputState* inpu | |||
u8 p; | |||
u8 i; | |||
for (p = 0; p < PLAYERS; p += 1) { | |||
for (p = 0; p < IZ_PLAYERS; p += 1) { | |||
IZ_Action the_action = input_state->action[p]; | |||
for (i = 0; i < CONTROLS; i += 1) { | |||
column = (i % 4) + (p * 4); | |||
@@ -1,7 +1,7 @@ | |||
#include "IZ_config.h" | |||
void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) { | |||
//const char* config_path_dir = SDL_GetPrefPath("Modal Studios", APP_NAME); | |||
//const char* config_path_dir = SDL_GetPrefPath("Modal Studios", IZ_APP_NAME); | |||
const char* config_path_dir = SDL_GetBasePath(); | |||
memcpy_s(config_path, string_size, config_path_dir, 128); | |||
strcat_s(config_path, string_size, "config-server.ini"); | |||
@@ -42,6 +42,12 @@ void IZ_WSServerLoadConfig(IZ_WSServerState* state, const char* config_path, u8 | |||
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-p"))) { | |||
state->config.port = atoi(cmdline_buffer); | |||
} | |||
if ((cmdline_buffer = IZ_ConfigGetCommandlineOption(argc, argv, "-n"))) { | |||
sprintf_s(state->config.server_name, 64, "%s Dedicated Server [%s]", IZ_APP_NAME, cmdline_buffer); | |||
} else { | |||
sprintf_s(state->config.server_name, 128, "%s Dedicated Server", IZ_APP_NAME); | |||
} | |||
} | |||
IZ_ProcedureResult IZ_WSServerInitialize(IZ_WSServerState* state, void* userdata, const char* config_path, u8 argc, const char* argv[]) { | |||
@@ -52,32 +58,33 @@ IZ_ProcedureResult IZ_WSServerInitialize(IZ_WSServerState* state, void* userdata | |||
memset(&info, 0, sizeof info); | |||
info.port = state->config.port; | |||
static struct lws_http_mount mount = { | |||
.mount_next = NULL, /* linked-list "next" */ | |||
.mountpoint = "/", /* mountpoint URL */ | |||
.origin = "./public", /* serve from dir */ | |||
.def = "index.html", /* default filename */ | |||
.protocol = "http", | |||
.cgienv = NULL, | |||
.extra_mimetypes = NULL, | |||
.interpret = NULL, | |||
.cgi_timeout = 0, | |||
.cache_max_age = 0, | |||
.auth_mask = 0, | |||
.cache_reusable = 0, | |||
.cache_revalidate = 0, | |||
.cache_intermediaries = 0, | |||
.origin_protocol = LWSMPRO_FILE, /* files in a dir */ | |||
.mountpoint_len = 1, /* char count */ | |||
.basic_auth_login_file = NULL, | |||
}; | |||
if (state->config.origin) { | |||
mount.origin = state->config.origin; | |||
} | |||
if (state->config.default_filename) { | |||
mount.def = state->config.default_filename; | |||
const char* origin = "./public"; | |||
struct stat stats; | |||
stat(origin, &stats); | |||
if (S_ISDIR(stats.st_mode)) { | |||
static struct lws_http_mount mount = { | |||
.mount_next = NULL, /* linked-list "next" */ | |||
.mountpoint = "/", /* mountpoint URL */ | |||
.origin = NULL, /* serve from dir */ | |||
.def = "index.html", /* default filename */ | |||
.protocol = "http", | |||
.cgienv = NULL, | |||
.extra_mimetypes = NULL, | |||
.interpret = NULL, | |||
.cgi_timeout = 0, | |||
.cache_max_age = 0, | |||
.auth_mask = 0, | |||
.cache_reusable = 0, | |||
.cache_revalidate = 0, | |||
.cache_intermediaries = 0, | |||
.origin_protocol = LWSMPRO_FILE, /* files in a dir */ | |||
.mountpoint_len = 1, /* char count */ | |||
.basic_auth_login_file = NULL, | |||
}; | |||
mount.origin = origin; | |||
info.mounts = &mount; | |||
} | |||
info.mounts = &mount; | |||
static const struct lws_protocols protocols[] = { | |||
{ | |||
@@ -1,12 +1,17 @@ | |||
#ifndef IZ_WSSERVER_H | |||
#define IZ_WSSERVER_H | |||
#include "libwebsockets.h" | |||
#include <sys/stat.h> | |||
#include <libwebsockets.h> | |||
#include <string.h> | |||
#include "../IZ_common.h" | |||
#include "../IZ_config.h" | |||
#include "IZ_websocket.h" | |||
#ifndef S_ISDIR | |||
#define S_ISDIR(s) s & S_IFDIR | |||
#endif | |||
/* one of these is created for each client connecting to us */ | |||
typedef struct IZ_WSServerSessionData { | |||
struct IZ_WSServerSessionData* pss_list; | |||
@@ -28,8 +33,7 @@ typedef struct { | |||
typedef struct { | |||
u16 port; | |||
const char* origin; | |||
const char* default_filename; | |||
const char server_name[64]; | |||
} IZ_WSServerInitializeParams; | |||
typedef struct { | |||
@@ -41,8 +45,7 @@ typedef struct { | |||
static IZ_WSServerState IZ_DEFAULT_STATE = { | |||
.config = { | |||
.port = 42069, | |||
.origin = "./public", | |||
.default_filename = "index.html", | |||
.server_name = NULL, | |||
}, | |||
.userdata = NULL, | |||
.ws = { | |||