Remove symlinks and make codebase use common modules instead.feature/data-structs
@@ -51,7 +51,7 @@ add_executable( | |||||
dependencies/getopt-for-windows/getopt.c | dependencies/getopt-for-windows/getopt.c | ||||
src/packages/game/output/video/IZ_video.h | src/packages/game/output/video/IZ_video.h | ||||
src/packages/game/output/video/IZ_video.c | src/packages/game/output/video/IZ_video.c | ||||
src/packages/game/IZ_common.h | |||||
src/packages/common/IZ_common.h | |||||
src/packages/game/input/IZ_action.h | src/packages/game/input/IZ_action.h | ||||
src/packages/game/IZ_app.h | src/packages/game/IZ_app.h | ||||
src/packages/game/IZ_app.c | src/packages/game/IZ_app.c | ||||
@@ -60,8 +60,8 @@ add_executable( | |||||
src/packages/game/input/IZ_joystick.h | src/packages/game/input/IZ_joystick.h | ||||
src/packages/game/input/IZ_keyboard.c | src/packages/game/input/IZ_keyboard.c | ||||
src/packages/game/input/IZ_keyboard.h | src/packages/game/input/IZ_keyboard.h | ||||
src/packages/game/config/IZ_config.c | |||||
src/packages/game/config/IZ_config.h | |||||
src/packages/config/IZ_config.c | |||||
src/packages/config/IZ_config.h | |||||
src/packages/game/geometry/IZ_point2d.c | src/packages/game/geometry/IZ_point2d.c | ||||
src/packages/game/geometry/IZ_point2d.h | src/packages/game/geometry/IZ_point2d.h | ||||
src/packages/game/geometry/IZ_vector2d.c | src/packages/game/geometry/IZ_vector2d.c | ||||
@@ -82,15 +82,15 @@ add_executable( | |||||
src/packages/game/input/IZ_midi.h | src/packages/game/input/IZ_midi.h | ||||
src/packages/game/data/IZ_list.c | src/packages/game/data/IZ_list.c | ||||
src/packages/game/data/IZ_list.h | src/packages/game/data/IZ_list.h | ||||
src/packages/game/net/svc/IZ_wsclient.c | |||||
src/packages/game/net/svc/IZ_wsclient.h | |||||
src/packages/game/log/IZ_log.c | |||||
src/packages/game/log/IZ_log.h | |||||
src/packages/net/svc/IZ_wsclient.c | |||||
src/packages/net/svc/IZ_wsclient.h | |||||
src/packages/log/IZ_log.c | |||||
src/packages/log/IZ_log.h | |||||
src/packages/game/util/IZ_midi.c | src/packages/game/util/IZ_midi.c | ||||
src/packages/game/util/IZ_midi.h | src/packages/game/util/IZ_midi.h | ||||
src/packages/game/net/core/IZ_websocket.h | |||||
src/packages/game/net/core/IZ_websocket.c | |||||
src/packages/game/net/IZ_net.c src/packages/game/net/IZ_net.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/net/core/IZ_websocket.h | |||||
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) | |||||
target_link_libraries( | target_link_libraries( | ||||
game | game | ||||
@@ -130,7 +130,7 @@ add_executable( | |||||
__mocks__/SDL_stdinc.mock.h | __mocks__/SDL_stdinc.mock.h | ||||
__mocks__/portmidi.mock.h | __mocks__/portmidi.mock.h | ||||
src/packages/game/config/IZ_config.h | |||||
src/packages/config/IZ_config.h | |||||
src/packages/game/input/IZ_keyboard.h | src/packages/game/input/IZ_keyboard.h | ||||
src/packages/game/input/IZ_keyboard.c | src/packages/game/input/IZ_keyboard.c | ||||
@@ -157,7 +157,7 @@ add_executable( | |||||
__mocks__/SDL_stdinc.mock.h | __mocks__/SDL_stdinc.mock.h | ||||
__mocks__/SDL_render.mock.h | __mocks__/SDL_render.mock.h | ||||
src/packages/game/config/IZ_config.h | |||||
src/packages/config/IZ_config.h | |||||
src/packages/game/output/video/IZ_video.h | src/packages/game/output/video/IZ_video.h | ||||
src/packages/game/output/video/IZ_video.c | src/packages/game/output/video/IZ_video.c | ||||
@@ -194,19 +194,25 @@ add_executable( | |||||
dependencies/sqlite/sqlite3.c | dependencies/sqlite/sqlite3.c | ||||
dependencies/minIni/dev/minIni.h | dependencies/minIni/dev/minIni.h | ||||
dependencies/minIni/dev/minIni.c | dependencies/minIni/dev/minIni.c | ||||
src/packages/server/IZ_common.h | |||||
src/packages/server/log/IZ_log.h | |||||
src/packages/server/log/IZ_log.c | |||||
src/packages/log/IZ_log.h | |||||
src/packages/log/IZ_log.c | |||||
src/packages/server/main.c | src/packages/server/main.c | ||||
src/packages/server/IZ_app.c | src/packages/server/IZ_app.c | ||||
src/packages/server/IZ_app.h | src/packages/server/IZ_app.h | ||||
src/packages/server/IZ_config.c | |||||
src/packages/server/IZ_config.h | |||||
src/packages/server/net/svc/IZ_wsserver.c | |||||
src/packages/server/net/svc/IZ_wsserver.h | |||||
src/packages/server/net/core/IZ_websocket.h | |||||
src/packages/server/net/core/IZ_websocket.c | |||||
src/packages/server/net/IZ_net.c src/packages/server/net/IZ_net.h src/packages/server/db/IZ_repo.c src/packages/server/db/IZ_repo.h) | |||||
src/packages/server/IZ_app_config.h | |||||
src/packages/server/IZ_app_config.c | |||||
src/packages/net/svc/IZ_wsserver.c | |||||
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 | |||||
src/packages/server/db/IZ_repo.h | |||||
src/packages/server/IZ_subsystem.h | |||||
) | |||||
target_link_libraries( | target_link_libraries( | ||||
server | server | ||||
@@ -1,7 +1,7 @@ | |||||
#ifndef SDL_JOYSTICK_MOCK_H | #ifndef SDL_JOYSTICK_MOCK_H | ||||
#define SDL_JOYSTICK_MOCK_H | #define SDL_JOYSTICK_MOCK_H | ||||
#include "../src/packages/game/IZ_common.h" | |||||
#include "../src/packages/common/IZ_common.h" | |||||
#include "../src/packages/test/IZ_test.h" | #include "../src/packages/test/IZ_test.h" | ||||
typedef struct _SDL_Joystick {} SDL_Joystick; | typedef struct _SDL_Joystick {} SDL_Joystick; | ||||
@@ -1,7 +1,7 @@ | |||||
#ifndef SDL_KEYBOARD_MOCK_H | #ifndef SDL_KEYBOARD_MOCK_H | ||||
#define SDL_KEYBOARD_MOCK_H | #define SDL_KEYBOARD_MOCK_H | ||||
#include "../src/packages/game/IZ_common.h" | |||||
#include "../src/packages/common/IZ_common.h" | |||||
#include "../src/packages/test/IZ_test.h" | #include "../src/packages/test/IZ_test.h" | ||||
mock(SDL_GetKeyName) const char* SDL_GetKeyName(i32 key) { | mock(SDL_GetKeyName) const char* SDL_GetKeyName(i32 key) { | ||||
@@ -1,7 +1,7 @@ | |||||
#ifndef SDL_RENDER_MOCK_H | #ifndef SDL_RENDER_MOCK_H | ||||
#define SDL_RENDER_MOCK_H | #define SDL_RENDER_MOCK_H | ||||
#include "../src/packages/game/IZ_common.h" | |||||
#include "../src/packages/common/IZ_common.h" | |||||
#include "../src/packages/test/IZ_test.h" | #include "../src/packages/test/IZ_test.h" | ||||
typedef struct SDL_Renderer SDL_Renderer; | typedef struct SDL_Renderer SDL_Renderer; | ||||
@@ -2,7 +2,7 @@ | |||||
#define SDL_STDINC_MOCK_H | #define SDL_STDINC_MOCK_H | ||||
#include <string.h> | #include <string.h> | ||||
#include "../src/packages/game/IZ_common.h" | |||||
#include "../src/packages/common/IZ_common.h" | |||||
#include "../src/packages/test/IZ_test.h" | #include "../src/packages/test/IZ_test.h" | ||||
mock(SDL_memcpy) void* SDL_memcpy(void* dst, const void* src, size_t len) { | mock(SDL_memcpy) void* SDL_memcpy(void* dst, const void* src, size_t len) { | ||||
@@ -1,7 +1,7 @@ | |||||
#ifndef MININI_MOCK_H | #ifndef MININI_MOCK_H | ||||
#define MININI_MOCK_H | #define MININI_MOCK_H | ||||
#include "../src/packages/game/IZ_common.h" | |||||
#include "../src/packages/common/IZ_common.h" | |||||
#include "../src/packages/test/IZ_test.h" | #include "../src/packages/test/IZ_test.h" | ||||
mock(ini_getl) long ini_getl(const char *Section, const char *Key, long DefValue, const char *Filename) { | mock(ini_getl) long ini_getl(const char *Section, const char *Key, long DefValue, const char *Filename) { | ||||
@@ -3,7 +3,7 @@ | |||||
#define PORTMIDI_INCLUDED | #define PORTMIDI_INCLUDED | ||||
#include "../src/packages/game/IZ_common.h" | |||||
#include "../src/packages/common/IZ_common.h" | |||||
typedef i32 PmDeviceID; | typedef i32 PmDeviceID; | ||||
typedef void PortMidiStream; | typedef void PortMidiStream; | ||||
@@ -1,6 +1,6 @@ | |||||
[Network] | |||||
Name=Izanagi | |||||
Motd= | |||||
Port=42069 | |||||
[Database] | |||||
Path=db.sqlite | |||||
[Network] | |||||
Name=Izanagi Server | |||||
Motd= | |||||
Port=42069 | |||||
[Database] | |||||
Path=server.sqlite |
@@ -29,7 +29,7 @@ typedef bool IZ_ConfigLoadParamsU16Validator(u16); | |||||
typedef bool IZ_ConfigLoadParamsU8Validator(u8); | typedef bool IZ_ConfigLoadParamsU8Validator(u8); | ||||
void IZ_ConfigEnsureValidString(IZ_ConfigItem item, char* buffer) { | |||||
void IZ_ConfigEnsureValidString(IZ_ConfigItem item, const char* buffer) { | |||||
char dest[item.dest_size]; | char dest[item.dest_size]; | ||||
if (item.validator) { | if (item.validator) { | ||||
IZ_ConfigLoadParamsStringValidator* validator = item.validator; | IZ_ConfigLoadParamsStringValidator* validator = item.validator; | ||||
@@ -48,7 +48,7 @@ void IZ_ConfigEnsureValidString(IZ_ConfigItem item, char* buffer) { | |||||
void IZ_ConfigLoadString(IZ_ConfigItem item, const char* config_path) { | void IZ_ConfigLoadString(IZ_ConfigItem item, const char* config_path) { | ||||
char buffer[item.dest_size]; | char buffer[item.dest_size]; | ||||
ini_gets(item.section, item.key, item.default_value, buffer, item.dest_size, config_path); | |||||
ini_gets(item.section, item.key, item.default_value, buffer, (i32) item.dest_size, config_path); | |||||
IZ_ConfigEnsureValidString(item, buffer); | IZ_ConfigEnsureValidString(item, buffer); | ||||
} | } | ||||
@@ -1,10 +1,10 @@ | |||||
#ifndef IZ_CONFIG_H | #ifndef IZ_CONFIG_H | ||||
#define IZ_CONFIG_H | #define IZ_CONFIG_H | ||||
#include <string.h> | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | |||||
#include <minIni.h> | #include <minIni.h> | ||||
#include "../IZ_common.h" | |||||
#include "../common/IZ_common.h" | |||||
typedef enum { | typedef enum { | ||||
IZ_CONFIG_TYPE_VOID, | IZ_CONFIG_TYPE_VOID, | ||||
@@ -26,9 +26,9 @@ typedef struct { | |||||
void IZ_ConfigGetDefaultPath(const char*, size_t); | void IZ_ConfigGetDefaultPath(const char*, size_t); | ||||
const char* IZ_ConfigGetCommandlineOption(u8, const char**, const char*); | |||||
const char* IZ_ConfigGetCommandlineOption(u8, const char*[], const char*); | |||||
void IZ_ConfigInit(IZ_ConfigItem[], const char*, u8, const char**); | |||||
void IZ_ConfigInit(IZ_ConfigItem[], const char*, u8, const char*[]); | |||||
IZ_ProcedureResult IZ_ConfigSave(IZ_ConfigItem[], const char*); | IZ_ProcedureResult IZ_ConfigSave(IZ_ConfigItem[], const char*); | ||||
@@ -8,7 +8,7 @@ void IZ_AppBindConnection(struct IZ_App* app, struct lws* wsi) { | |||||
app->net_state.binding.connection = wsi; | app->net_state.binding.connection = wsi; | ||||
} | } | ||||
IZ_NetState* IZ_AppGetNetState(struct IZ_App* app) { | |||||
IZ_NetClientState* IZ_AppGetNetState(struct IZ_App* app) { | |||||
return &app->net_state; | return &app->net_state; | ||||
} | } | ||||
@@ -47,7 +47,7 @@ IZ_ProcedureResult IZ_AppInitialize(struct IZ_App* app, u8 argc, const char* arg | |||||
return IZ_APP_RUN_INPUT_INIT_ERROR; | return IZ_APP_RUN_INPUT_INIT_ERROR; | ||||
} | } | ||||
if (IZ_NetInitialize(&app->net_state, app, IZ_AppRunNetworkingThread, config_path, argc, argv)) { | |||||
if (IZ_NetClientInitialize(&app->net_state, app, IZ_AppRunNetworkingThread, config_path, argc, argv)) { | |||||
return IZ_APP_RUN_NETWORKING_ERROR; | return IZ_APP_RUN_NETWORKING_ERROR; | ||||
} | } | ||||
@@ -58,7 +58,7 @@ IZ_ProcedureResult IZ_AppInitialize(struct IZ_App* app, u8 argc, const char* arg | |||||
} | } | ||||
void IZ_AppTeardown(struct IZ_App* app) { | void IZ_AppTeardown(struct IZ_App* app) { | ||||
IZ_NetDisconnect(&app->net_state); | |||||
IZ_NetClientDisconnect(&app->net_state); | |||||
IZ_PoolTeardown(&app->pool); | IZ_PoolTeardown(&app->pool); | ||||
IZ_InputTeardown(&app->input_state); | IZ_InputTeardown(&app->input_state); | ||||
IZ_VideoTeardown(&app->video_state); | IZ_VideoTeardown(&app->video_state); | ||||
@@ -24,9 +24,9 @@ typedef struct IZ_App { | |||||
IZ_Pool pool; | IZ_Pool pool; | ||||
u64 ticks; | u64 ticks; | ||||
IZ_NetState net_state; | |||||
IZ_NetClientState net_state; | |||||
} IZ_App; | } IZ_App; | ||||
IZ_ProcedureResult IZ_AppRun(struct IZ_App*, u8, const char**); | |||||
IZ_ProcedureResult IZ_AppRun(struct IZ_App*, u8, const char*[]); | |||||
#endif | #endif |
@@ -1,8 +1,8 @@ | |||||
#ifndef IZ_APP_CONFIG_H | #ifndef IZ_APP_CONFIG_H | ||||
#define IZ_APP_CONFIG_H | #define IZ_APP_CONFIG_H | ||||
#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" | |||||
#endif | #endif |
@@ -3,7 +3,7 @@ | |||||
IZ_ProcedureResult IZ_AppHandleSDLEvents(struct IZ_App* app) { | IZ_ProcedureResult IZ_AppHandleSDLEvents(struct IZ_App* app) { | ||||
SDL_Event e; | SDL_Event e; | ||||
IZ_InputState* input_state = IZ_AppGetInputState(app); | IZ_InputState* input_state = IZ_AppGetInputState(app); | ||||
IZ_NetState* net_state = IZ_AppGetNetState(app); | |||||
IZ_NetClientState* net_state = IZ_AppGetNetState(app); | |||||
while (SDL_PollEvent(&e) != 0) { | while (SDL_PollEvent(&e) != 0) { | ||||
if (e.type == SDL_QUIT) { | if (e.type == SDL_QUIT) { | ||||
@@ -12,7 +12,7 @@ IZ_ProcedureResult IZ_AppHandleSDLEvents(struct IZ_App* app) { | |||||
if (e.type == SDL_KEYDOWN) { | if (e.type == SDL_KEYDOWN) { | ||||
if (e.key.keysym.sym == SDLK_PAGEUP) { | if (e.key.keysym.sym == SDLK_PAGEUP) { | ||||
IZ_NetConnect( | |||||
IZ_NetClientConnect( | |||||
net_state, | net_state, | ||||
(IZ_WSClientInitializeParams) { | (IZ_WSClientInitializeParams) { | ||||
.host = "127.0.0.1", | .host = "127.0.0.1", | ||||
@@ -21,9 +21,9 @@ IZ_ProcedureResult IZ_AppHandleSDLEvents(struct IZ_App* app) { | |||||
} | } | ||||
); | ); | ||||
} else if (e.key.keysym.sym == SDLK_PAGEDOWN) { | } else if (e.key.keysym.sym == SDLK_PAGEDOWN) { | ||||
IZ_NetDisconnect(net_state); | |||||
IZ_NetClientDisconnect(net_state); | |||||
} else if (e.key.keysym.sym == SDLK_INSERT) { | } else if (e.key.keysym.sym == SDLK_INSERT) { | ||||
IZ_NetSendTextMessage(net_state, "hello", 5); | |||||
IZ_NetClientSendTextMessage(net_state, "hello", 5); | |||||
} | } | ||||
} | } | ||||
@@ -16,7 +16,7 @@ void IZ_AppHandleNetworkingInboundTextEvents(struct IZ_App* app, const char* tex | |||||
void IZ_AppHandleOutboundNetworking(struct IZ_App* app) { | void IZ_AppHandleOutboundNetworking(struct IZ_App* app) { | ||||
// TODO implement queueing of messages | // TODO implement queueing of messages | ||||
IZ_NetState* net_state = IZ_AppGetNetState(app); | |||||
IZ_NetClientState* net_state = IZ_AppGetNetState(app); | |||||
IZ_InputState* input_state = IZ_AppGetInputState(app); | IZ_InputState* input_state = IZ_AppGetInputState(app); | ||||
u8 player_index; | u8 player_index; | ||||
@@ -34,7 +34,7 @@ void IZ_AppHandleOutboundNetworking(struct IZ_App* app) { | |||||
msg->action.player[0].index = player_index; | msg->action.player[0].index = player_index; | ||||
msg->action.player[0].value = input_state->action[player_index]; | msg->action.player[0].value = input_state->action[player_index]; | ||||
msg->action.player[0].state = 0; | msg->action.player[0].state = 0; | ||||
IZ_NetSendBinaryMessage( | |||||
IZ_NetClientSendBinaryMessage( | |||||
net_state, | net_state, | ||||
msg, | msg, | ||||
sizeof(*msg) | sizeof(*msg) | ||||
@@ -60,8 +60,8 @@ void IZ_WSClientAttemptConnect(struct lws_sorted_usec_list *sul) { | |||||
vhd->i.pwsi = &vhd->client_wsi; | vhd->i.pwsi = &vhd->client_wsi; | ||||
struct IZ_App* app = (struct IZ_App*) vhd->app; | struct IZ_App* app = (struct IZ_App*) vhd->app; | ||||
IZ_NetState* net_state = IZ_AppGetNetState(app); | |||||
net_state->status = IZ_NET_STATUS_CONNECTING; | |||||
IZ_NetClientState* net_state = IZ_AppGetNetState(app); | |||||
net_state->status = IZ_NET_CLIENT_STATUS_CONNECTING; | |||||
if (lws_client_connect_via_info(&vhd->i)) { | if (lws_client_connect_via_info(&vhd->i)) { | ||||
return; | return; | ||||
} | } | ||||
@@ -124,8 +124,8 @@ void IZ_WSClientProtocolTeardown(struct lws* wsi) { | |||||
lws_sul_cancel(&vhd->sul); | lws_sul_cancel(&vhd->sul); | ||||
struct IZ_App* app = (struct IZ_App*) vhd->app; | struct IZ_App* app = (struct IZ_App*) vhd->app; | ||||
IZ_NetState* net_state = IZ_AppGetNetState(app); | |||||
net_state->status = IZ_NET_STATUS_PRISTINE; | |||||
IZ_NetClientState* net_state = IZ_AppGetNetState(app); | |||||
net_state->status = IZ_NET_CLIENT_STATUS_PRISTINE; | |||||
} | } | ||||
IZ_ProcedureResult IZ_WSClientConnectionError(struct lws* wsi, void* in) { | IZ_ProcedureResult IZ_WSClientConnectionError(struct lws* wsi, void* in) { | ||||
@@ -142,13 +142,13 @@ IZ_ProcedureResult IZ_WSClientConnectionError(struct lws* wsi, void* in) { | |||||
struct IZ_App* app = (struct IZ_App*) vhd->app; | struct IZ_App* app = (struct IZ_App*) vhd->app; | ||||
IZ_AppBindConnection(app, NULL); | IZ_AppBindConnection(app, NULL); | ||||
vhd->client_wsi = NULL; | vhd->client_wsi = NULL; | ||||
IZ_NetState* net_state = IZ_AppGetNetState(app); | |||||
IZ_NetClientState* net_state = IZ_AppGetNetState(app); | |||||
if (net_state->retries == net_state->config.max_reconnect_retries) { | if (net_state->retries == net_state->config.max_reconnect_retries) { | ||||
lwsl_err("Max number of retries reached!\n"); | lwsl_err("Max number of retries reached!\n"); | ||||
net_state->status = IZ_NET_STATUS_PRISTINE; | |||||
net_state->status = IZ_NET_CLIENT_STATUS_PRISTINE; | |||||
return -1; | return -1; | ||||
} | } | ||||
net_state->status = IZ_NET_STATUS_ERROR; | |||||
net_state->status = IZ_NET_CLIENT_STATUS_ERROR; | |||||
net_state->retries += 1; | net_state->retries += 1; | ||||
lws_sul_schedule( | lws_sul_schedule( | ||||
vhd->context, | vhd->context, | ||||
@@ -167,15 +167,15 @@ IZ_ProcedureResult IZ_WSClientOnOpen(struct lws* wsi, IZ_WSClientSessionData* ps | |||||
lws_get_protocol(wsi) | lws_get_protocol(wsi) | ||||
); | ); | ||||
struct IZ_App* app = (struct IZ_App*) vhd->app; | struct IZ_App* app = (struct IZ_App*) vhd->app; | ||||
IZ_NetState* net_state = IZ_AppGetNetState(app); | |||||
IZ_NetClientState* net_state = IZ_AppGetNetState(app); | |||||
pss->ring = lws_ring_create(sizeof(IZ_WebsocketMessage), RING_COUNT,IZ_WebsocketDestroyMessage); | pss->ring = lws_ring_create(sizeof(IZ_WebsocketMessage), RING_COUNT,IZ_WebsocketDestroyMessage); | ||||
if (!pss->ring) { | if (!pss->ring) { | ||||
net_state->status = IZ_NET_STATUS_ERROR; | |||||
net_state->status = IZ_NET_CLIENT_STATUS_ERROR; | |||||
return -1; | return -1; | ||||
} | } | ||||
IZ_AppBindConnection(app, wsi); | IZ_AppBindConnection(app, wsi); | ||||
net_state->status = IZ_NET_STATUS_CONNECTED; | |||||
net_state->status = IZ_NET_CLIENT_STATUS_CONNECTED; | |||||
net_state->retries = 0; | net_state->retries = 0; | ||||
pss->tail = 0; | pss->tail = 0; | ||||
return 0; | return 0; | ||||
@@ -287,7 +287,7 @@ void IZ_WSClientOnReceive(struct lws* wsi, IZ_WSClientSessionData* pss, void* in | |||||
} | } | ||||
IZ_ProcedureResult IZ_AppRunNetworkingThread(struct IZ_App* app) { | IZ_ProcedureResult IZ_AppRunNetworkingThread(struct IZ_App* app) { | ||||
IZ_NetState* net_state = IZ_AppGetNetState(app); | |||||
IZ_NetClientState* net_state = IZ_AppGetNetState(app); | |||||
if (IZ_WSClientInitialize(&net_state->binding, net_state->params)) { | if (IZ_WSClientInitialize(&net_state->binding, net_state->params)) { | ||||
return -1; | return -1; | ||||
@@ -1,7 +1,6 @@ | |||||
#ifndef IZ_APP_NET_H | #ifndef IZ_APP_NET_H | ||||
#define IZ_APP_NET_H | #define IZ_APP_NET_H | ||||
#include "net/IZ_net.h" | |||||
#include "IZ_subsystem.h" | #include "IZ_subsystem.h" | ||||
typedef enum { | typedef enum { | ||||
@@ -52,19 +52,19 @@ void IZ_VideoUpdateForDebugInput(IZ_VideoState* video_state, IZ_InputState* inpu | |||||
} | } | ||||
} | } | ||||
void IZ_VideoUpdateForDebugNet(IZ_VideoState* video_state, IZ_NetState* net_state) { | |||||
void IZ_VideoUpdateForDebugNet(IZ_VideoState* video_state, IZ_NetClientState* net_state) { | |||||
const u8 size = 4; | const u8 size = 4; | ||||
switch (net_state->status) { | switch (net_state->status) { | ||||
default: | default: | ||||
return; | return; | ||||
case IZ_NET_STATUS_ERROR: | |||||
case IZ_NET_CLIENT_STATUS_ERROR: | |||||
SDL_SetRenderDrawColor(video_state->renderer, 0xff, 0x00, 0x00, 0xff); | SDL_SetRenderDrawColor(video_state->renderer, 0xff, 0x00, 0x00, 0xff); | ||||
break; | break; | ||||
case IZ_NET_STATUS_CONNECTING: | |||||
case IZ_NET_CLIENT_STATUS_CONNECTING: | |||||
SDL_SetRenderDrawColor(video_state->renderer, 0xff, 0xff, 0x00, 0xff); | SDL_SetRenderDrawColor(video_state->renderer, 0xff, 0xff, 0x00, 0xff); | ||||
break; | break; | ||||
case IZ_NET_STATUS_CONNECTED: | |||||
case IZ_NET_CLIENT_STATUS_CONNECTED: | |||||
SDL_SetRenderDrawColor(video_state->renderer, 0x00, 0xff, 0x00, 0xff); | SDL_SetRenderDrawColor(video_state->renderer, 0x00, 0xff, 0x00, 0xff); | ||||
break; | break; | ||||
} | } | ||||
@@ -108,7 +108,7 @@ void IZ_VideoUpdate(IZ_VideoState* video_state) { | |||||
struct IZ_App* app = video_state->user_data; | struct IZ_App* app = video_state->user_data; | ||||
u64 ticks = IZ_AppGetTicks(app); | u64 ticks = IZ_AppGetTicks(app); | ||||
IZ_InputState* input_state = IZ_AppGetInputState(app); | IZ_InputState* input_state = IZ_AppGetInputState(app); | ||||
IZ_NetState* net_state = IZ_AppGetNetState(app); | |||||
IZ_NetClientState* net_state = IZ_AppGetNetState(app); | |||||
if (ticks - video_state->last_update_at > 1000 / video_state->config.max_fps) { | if (ticks - video_state->last_update_at > 1000 / video_state->config.max_fps) { | ||||
// Update window | // Update window | ||||
@@ -1,15 +1,15 @@ | |||||
#ifndef IZ_SUBSYSTEM_H | #ifndef IZ_SUBSYSTEM_H | ||||
#define IZ_SUBSYSTEM_H | #define IZ_SUBSYSTEM_H | ||||
#include "IZ_common.h" | |||||
#include "net/IZ_net.h" | |||||
#include "../common/IZ_common.h" | |||||
#include "../net/IZ_net_client.h" | |||||
#include "input/IZ_input.h" | #include "input/IZ_input.h" | ||||
struct IZ_App; | struct IZ_App; | ||||
u64 IZ_AppGetTicks(struct IZ_App*); | u64 IZ_AppGetTicks(struct IZ_App*); | ||||
IZ_NetState* IZ_AppGetNetState(struct IZ_App*); | |||||
IZ_NetClientState* IZ_AppGetNetState(struct IZ_App*); | |||||
IZ_InputState* IZ_AppGetInputState(struct IZ_App*); | IZ_InputState* IZ_AppGetInputState(struct IZ_App*); | ||||
@@ -1,7 +1,7 @@ | |||||
#ifndef IZ_CREATURE_H | #ifndef IZ_CREATURE_H | ||||
#define IZ_CREATURE_H | #define IZ_CREATURE_H | ||||
#include "../IZ_common.h" | |||||
#include "../../common/IZ_common.h" | |||||
#include "IZ_object.h" | #include "IZ_object.h" | ||||
typedef struct { | typedef struct { | ||||
@@ -1,7 +1,7 @@ | |||||
#ifndef IZ_LIST_H | #ifndef IZ_LIST_H | ||||
#define IZ_LIST_H | #define IZ_LIST_H | ||||
#include "../IZ_common.h" | |||||
#include "../../common/IZ_common.h" | |||||
#include "SDL_stdinc.h" | #include "SDL_stdinc.h" | ||||
typedef struct IZ_ListNode { | typedef struct IZ_ListNode { | ||||
@@ -1,5 +1,5 @@ | |||||
#include "../../test/IZ_test.h" | #include "../../test/IZ_test.h" | ||||
#include "../../game/IZ_common.h" | |||||
#include "../../common/IZ_common.h" | |||||
#include "../../../__mocks__/SDL_stdinc.mock.h" | #include "../../../__mocks__/SDL_stdinc.mock.h" | ||||
#include "IZ_list.h" | #include "IZ_list.h" | ||||
@@ -1,7 +1,7 @@ | |||||
#ifndef IZ_POINT2D_H | #ifndef IZ_POINT2D_H | ||||
#define IZ_POINT2D_H | #define IZ_POINT2D_H | ||||
#include "../IZ_common.h" | |||||
#include "../../common/IZ_common.h" | |||||
typedef struct { | typedef struct { | ||||
f32 x; | f32 x; | ||||
@@ -1,7 +1,7 @@ | |||||
#ifndef IZ_ACTION_H | #ifndef IZ_ACTION_H | ||||
#define IZ_ACTION_H | #define IZ_ACTION_H | ||||
#include "../IZ_common.h" | |||||
#include "../../common/IZ_common.h" | |||||
#define CONTROLS (unsigned char) 16 | #define CONTROLS (unsigned char) 16 | ||||
@@ -9,7 +9,7 @@ void IZ_InputHandlePortMIDIEvents(IZ_InputState* state, PmEvent e) { | |||||
IZ_MIDIInputHandleEvents(&state->midi_input_state, &state->action, e); | IZ_MIDIInputHandleEvents(&state->midi_input_state, &state->action, e); | ||||
} | } | ||||
IZ_ProcedureResult IZ_InputInitialize(IZ_InputState* state, const char* config_path, u8 argc, const char** argv) { | |||||
IZ_ProcedureResult IZ_InputInitialize(IZ_InputState* state, const char* config_path, u8 argc, const char* argv[]) { | |||||
*state = (IZ_InputState) { | *state = (IZ_InputState) { | ||||
.action = {}, | .action = {}, | ||||
.joystick_state = {}, | .joystick_state = {}, | ||||
@@ -17,7 +17,7 @@ void IZ_InputHandleSDLEvents(IZ_InputState*, SDL_Event); | |||||
void IZ_InputHandlePortMIDIEvents(IZ_InputState*, PmEvent); | void IZ_InputHandlePortMIDIEvents(IZ_InputState*, PmEvent); | ||||
IZ_ProcedureResult IZ_InputInitialize(IZ_InputState*, const char*, u8, const char**); | |||||
IZ_ProcedureResult IZ_InputInitialize(IZ_InputState*, const char*, u8, const char*[]); | |||||
void IZ_InputTeardown(IZ_InputState*); | void IZ_InputTeardown(IZ_InputState*); | ||||
@@ -86,7 +86,7 @@ IZ_ProcedureResult IZ_JoystickSaveConfig(IZ_JoystickState(*)[IZ_PLAYERS], const | |||||
void IZ_JoystickHandleEvents(IZ_JoystickState(*)[IZ_PLAYERS], IZ_Action(*)[IZ_PLAYERS], SDL_Event); | void IZ_JoystickHandleEvents(IZ_JoystickState(*)[IZ_PLAYERS], IZ_Action(*)[IZ_PLAYERS], SDL_Event); | ||||
IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(*)[IZ_PLAYERS], const char*, u8, const char**); | |||||
IZ_ProcedureResult IZ_JoystickInitialize(IZ_JoystickState(*)[IZ_PLAYERS], const char*, u8, const char*[]); | |||||
void IZ_JoystickTeardown(IZ_JoystickState(*)[IZ_PLAYERS]); | void IZ_JoystickTeardown(IZ_JoystickState(*)[IZ_PLAYERS]); | ||||
@@ -66,6 +66,6 @@ IZ_ProcedureResult IZ_KeyboardSaveConfig(IZ_KeyboardState(*)[IZ_PLAYERS], const | |||||
void IZ_KeyboardHandleEvents(IZ_KeyboardState(*)[IZ_PLAYERS], IZ_Action(*)[IZ_PLAYERS], SDL_Event); | void IZ_KeyboardHandleEvents(IZ_KeyboardState(*)[IZ_PLAYERS], IZ_Action(*)[IZ_PLAYERS], SDL_Event); | ||||
IZ_ProcedureResult IZ_KeyboardInitialize(IZ_KeyboardState(*)[IZ_PLAYERS], const char*, u8, const char**); | |||||
IZ_ProcedureResult IZ_KeyboardInitialize(IZ_KeyboardState(*)[IZ_PLAYERS], const char*, u8, const char*[]); | |||||
#endif | #endif |
@@ -90,7 +90,7 @@ IZ_ProcedureResult IZ_MIDIInputSaveConfig(IZ_MIDIInputState(*)[IZ_PLAYERS], cons | |||||
void IZ_MIDIInputHandleEvents(IZ_MIDIInputState(*)[IZ_PLAYERS], IZ_Action(*)[IZ_PLAYERS], PmEvent); | void IZ_MIDIInputHandleEvents(IZ_MIDIInputState(*)[IZ_PLAYERS], IZ_Action(*)[IZ_PLAYERS], PmEvent); | ||||
IZ_ProcedureResult IZ_MIDIInputInitialize(IZ_MIDIInputState(*)[IZ_PLAYERS], const char*, u8, const char**); | |||||
IZ_ProcedureResult IZ_MIDIInputInitialize(IZ_MIDIInputState(*)[IZ_PLAYERS], const char*, u8, const char*[]); | |||||
void IZ_MIDIInputTeardown(IZ_MIDIInputState(*)[IZ_PLAYERS]); | void IZ_MIDIInputTeardown(IZ_MIDIInputState(*)[IZ_PLAYERS]); | ||||
@@ -2,7 +2,7 @@ | |||||
#define IZ_POOL_H | #define IZ_POOL_H | ||||
#include <SDL_stdinc.h> | #include <SDL_stdinc.h> | ||||
#include "../IZ_common.h" | |||||
#include "../../common/IZ_common.h" | |||||
#include "../data/IZ_list.h" | #include "../data/IZ_list.h" | ||||
#define POOL_MAX_SIZE (1llu << 23) // 16MB | #define POOL_MAX_SIZE (1llu << 23) // 16MB | ||||
@@ -1,75 +0,0 @@ | |||||
#ifndef IZ_NET_H | |||||
#define IZ_NET_H | |||||
#include <minIni.h> | |||||
#include <SDL_thread.h> | |||||
#include "../IZ_common.h" | |||||
#include "../config/IZ_config.h" | |||||
#include "../input/IZ_action.h" | |||||
#include "core/IZ_websocket.h" | |||||
#include "svc/IZ_wsclient.h" | |||||
typedef enum { | |||||
IZ_NET_STATUS_PRISTINE, | |||||
IZ_NET_STATUS_CONNECTING, | |||||
IZ_NET_STATUS_ERROR, | |||||
IZ_NET_STATUS_CONNECTED, | |||||
} IZ_NetStatus; | |||||
typedef struct { | |||||
u16 packet_interval_ms; | |||||
u8 max_reconnect_retries; | |||||
u8 reconnect_interval_secs; | |||||
char username[32]; | |||||
} IZ_NetConfig; | |||||
typedef struct { | |||||
SDL_Thread* client_thread; | |||||
IZ_NetConfig config; | |||||
IZ_Websocket binding; | |||||
IZ_WSClientInitializeParams params; | |||||
void* callback; | |||||
IZ_Action action[IZ_PLAYERS]; | |||||
u8 retries; | |||||
IZ_NetStatus status; | |||||
// TODO add message queue | |||||
} IZ_NetState; | |||||
static IZ_NetState IZ_NET_DEFAULT_STATE = { | |||||
.client_thread = NULL, | |||||
.config = { | |||||
.packet_interval_ms = 200, | |||||
.max_reconnect_retries = 3, | |||||
.reconnect_interval_secs = 3, | |||||
.username = "Player", | |||||
}, | |||||
.binding = { | |||||
.interrupted = false, | |||||
.context = NULL, | |||||
.connection = NULL, | |||||
.user_data = NULL, | |||||
}, | |||||
.params = { | |||||
.port = 42069, | |||||
.path = "/", | |||||
.host = "localhost", | |||||
}, | |||||
.callback = NULL, | |||||
.action = {}, | |||||
.retries = 3, | |||||
.status = IZ_NET_STATUS_PRISTINE, | |||||
}; | |||||
IZ_ProcedureResult IZ_NetInitialize(IZ_NetState*, void*, void*, const char*, u8, const char**); | |||||
void IZ_NetConnect(IZ_NetState*, IZ_WSClientInitializeParams); | |||||
void IZ_NetDisconnect(IZ_NetState*); | |||||
IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState*, const char*); | |||||
void IZ_NetSendBinaryMessage(IZ_NetState*, void*, size_t); | |||||
void IZ_NetSendTextMessage(IZ_NetState*, char*, size_t); | |||||
#endif |
@@ -5,10 +5,10 @@ | |||||
#include "minIni.h" | #include "minIni.h" | ||||
#include "SDL_render.h" | #include "SDL_render.h" | ||||
#include "../../../net/IZ_net_client.h" | |||||
#include "../../../config/IZ_config.h" | |||||
#include "../../input/IZ_input.h" | #include "../../input/IZ_input.h" | ||||
#include "../../net/IZ_net.h" | |||||
#include "../../IZ_common.h" | |||||
#include "../../config/IZ_config.h" | |||||
#include "../../../common/IZ_common.h" | |||||
#define MAX_ACTIVE_SPRITES 32 | #define MAX_ACTIVE_SPRITES 32 | ||||
@@ -43,7 +43,7 @@ static const IZ_VideoState IZ_VIDEO_DEFAULT_STATE = { | |||||
.active_sprites = {}, | .active_sprites = {}, | ||||
}; | }; | ||||
IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState*, void*, const char*, u8, const char**); | |||||
IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState*, void*, const char*, u8, const char*[]); | |||||
IZ_ProcedureResult IZ_VideoSaveConfig(IZ_VideoState*, const char*); | IZ_ProcedureResult IZ_VideoSaveConfig(IZ_VideoState*, const char*); | ||||
@@ -3,7 +3,7 @@ | |||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "../IZ_common.h" | |||||
#include "../../common/IZ_common.h" | |||||
typedef u8 IZ_MIDINote; | typedef u8 IZ_MIDINote; | ||||
@@ -1,9 +1,9 @@ | |||||
#ifndef IZ_LOG_H | #ifndef IZ_LOG_H | ||||
#define IZ_LOG_H | #define IZ_LOG_H | ||||
#include <SDL_log.h> | |||||
#include <libwebsockets.h> | |||||
#include "../IZ_common.h" | |||||
#include "SDL_log.h" | |||||
#include "libwebsockets.h" | |||||
#include "../common/IZ_common.h" | |||||
void IZ_LogInterceptWSMessages(i32); | void IZ_LogInterceptWSMessages(i32); | ||||
@@ -1,14 +1,14 @@ | |||||
#include "IZ_net.h" | |||||
#include "IZ_net_client.h" | |||||
bool IZ_NetIsValidPacketIntervalMs(long packet_interval_ms) { | |||||
bool IZ_NetClientIsValidPacketIntervalMs(long packet_interval_ms) { | |||||
return (100 <= packet_interval_ms && packet_interval_ms <= 500); | return (100 <= packet_interval_ms && packet_interval_ms <= 500); | ||||
} | } | ||||
bool IZ_NetIsValidMaxReconnectRetries(long max_reconnect_retries) { | |||||
bool IZ_NetClientIsValidMaxReconnectRetries(long max_reconnect_retries) { | |||||
return (0 <= max_reconnect_retries && max_reconnect_retries <= 8); | return (0 <= max_reconnect_retries && max_reconnect_retries <= 8); | ||||
} | } | ||||
bool IZ_NetIsValidReconnectIntervalSeconds(long reconnect_interval_secs) { | |||||
bool IZ_NetClientIsValidReconnectIntervalSeconds(long reconnect_interval_secs) { | |||||
return (3 <= reconnect_interval_secs && reconnect_interval_secs <= 10); | return (3 <= reconnect_interval_secs && reconnect_interval_secs <= 10); | ||||
} | } | ||||
@@ -19,7 +19,7 @@ static IZ_ConfigItem net_config_items[] = { | |||||
"Network", | "Network", | ||||
"Username", | "Username", | ||||
NULL, | NULL, | ||||
&IZ_NET_DEFAULT_STATE.config.username, | |||||
&IZ_NET_CLIENT_DEFAULT_STATE.config.username, | |||||
NULL | NULL | ||||
}, | }, | ||||
{ | { | ||||
@@ -28,8 +28,8 @@ static IZ_ConfigItem net_config_items[] = { | |||||
"Network", | "Network", | ||||
"PacketIntervalMs", | "PacketIntervalMs", | ||||
"-i", | "-i", | ||||
&IZ_NET_DEFAULT_STATE.config.packet_interval_ms, | |||||
IZ_NetIsValidPacketIntervalMs, | |||||
&IZ_NET_CLIENT_DEFAULT_STATE.config.packet_interval_ms, | |||||
IZ_NetClientIsValidPacketIntervalMs, | |||||
}, | }, | ||||
{ | { | ||||
IZ_CONFIG_TYPE_U8, | IZ_CONFIG_TYPE_U8, | ||||
@@ -37,8 +37,8 @@ static IZ_ConfigItem net_config_items[] = { | |||||
"Network", | "Network", | ||||
"MaxReconnectRetries", | "MaxReconnectRetries", | ||||
NULL, | NULL, | ||||
&IZ_NET_DEFAULT_STATE.config.max_reconnect_retries, | |||||
IZ_NetIsValidMaxReconnectRetries, | |||||
&IZ_NET_CLIENT_DEFAULT_STATE.config.max_reconnect_retries, | |||||
IZ_NetClientIsValidMaxReconnectRetries, | |||||
}, | }, | ||||
{ | { | ||||
IZ_CONFIG_TYPE_U8, | IZ_CONFIG_TYPE_U8, | ||||
@@ -46,33 +46,33 @@ static IZ_ConfigItem net_config_items[] = { | |||||
"Network", | "Network", | ||||
"ReconnectIntervalSeconds", | "ReconnectIntervalSeconds", | ||||
NULL, | NULL, | ||||
&IZ_NET_DEFAULT_STATE.config.reconnect_interval_secs, | |||||
IZ_NetIsValidReconnectIntervalSeconds, | |||||
&IZ_NET_CLIENT_DEFAULT_STATE.config.reconnect_interval_secs, | |||||
IZ_NetClientIsValidReconnectIntervalSeconds, | |||||
}, | }, | ||||
}; | }; | ||||
void IZ_NetBindStateToConfig(IZ_NetState* state, IZ_ConfigItem config_items[]) { | |||||
void IZ_NetClientBindStateToConfig(IZ_NetClientState* state, IZ_ConfigItem config_items[]) { | |||||
config_items[0].dest = &state->config.username; | config_items[0].dest = &state->config.username; | ||||
config_items[1].dest = &state->config.packet_interval_ms; | config_items[1].dest = &state->config.packet_interval_ms; | ||||
config_items[2].dest = &state->config.max_reconnect_retries; | config_items[2].dest = &state->config.max_reconnect_retries; | ||||
config_items[3].dest = &state->config.reconnect_interval_secs; | config_items[3].dest = &state->config.reconnect_interval_secs; | ||||
} | } | ||||
IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState* state, const char* config_path) { | |||||
IZ_NetBindStateToConfig(state, net_config_items); | |||||
IZ_ProcedureResult IZ_NetClientSaveConfig(IZ_NetClientState* state, const char* config_path) { | |||||
IZ_NetClientBindStateToConfig(state, net_config_items); | |||||
return IZ_ConfigSave(net_config_items, config_path); | return IZ_ConfigSave(net_config_items, config_path); | ||||
} | } | ||||
IZ_ProcedureResult IZ_NetInitialize( | |||||
IZ_NetState* state, | |||||
IZ_ProcedureResult IZ_NetClientInitialize( | |||||
IZ_NetClientState* state, | |||||
void* user_data, | void* user_data, | ||||
void* callback, | void* callback, | ||||
const char* config_path, | const char* config_path, | ||||
u8 argc, | u8 argc, | ||||
const char* argv[] | const char* argv[] | ||||
) { | ) { | ||||
memcpy_s(state, sizeof(IZ_NetState), &IZ_NET_DEFAULT_STATE, sizeof(IZ_NetState)); | |||||
IZ_NetBindStateToConfig(state, net_config_items); | |||||
memcpy_s(state, sizeof(IZ_NetClientState), &IZ_NET_CLIENT_DEFAULT_STATE, sizeof(IZ_NetClientState)); | |||||
IZ_NetClientBindStateToConfig(state, net_config_items); | |||||
IZ_ConfigInit(net_config_items, config_path, argc, argv); | IZ_ConfigInit(net_config_items, config_path, argc, argv); | ||||
if (!user_data) { | if (!user_data) { | ||||
return -2; | return -2; | ||||
@@ -88,16 +88,16 @@ IZ_ProcedureResult IZ_NetInitialize( | |||||
return 0; | return 0; | ||||
} | } | ||||
void IZ_NetConnect(IZ_NetState* state, IZ_WSClientInitializeParams params) { | |||||
void IZ_NetClientConnect(IZ_NetClientState* state, IZ_WSClientInitializeParams params) { | |||||
if (!state->callback) { | if (!state->callback) { | ||||
return; | return; | ||||
} | } | ||||
if (state->status == IZ_NET_STATUS_CONNECTED) { | |||||
if (state->status == IZ_NET_CLIENT_STATUS_CONNECTED) { | |||||
return; | return; | ||||
} | } | ||||
if (state->status == IZ_NET_STATUS_CONNECTING) { | |||||
if (state->status == IZ_NET_CLIENT_STATUS_CONNECTING) { | |||||
return; | return; | ||||
} | } | ||||
@@ -111,8 +111,8 @@ void IZ_NetConnect(IZ_NetState* state, IZ_WSClientInitializeParams params) { | |||||
SDL_DetachThread(state->client_thread); | SDL_DetachThread(state->client_thread); | ||||
} | } | ||||
void IZ_NetDisconnect(IZ_NetState* state) { | |||||
if (state->status == IZ_NET_STATUS_PRISTINE) { | |||||
void IZ_NetClientDisconnect(IZ_NetClientState* state) { | |||||
if (state->status == IZ_NET_CLIENT_STATUS_PRISTINE) { | |||||
return; | return; | ||||
} | } | ||||
if (state->binding.connection) { | if (state->binding.connection) { | ||||
@@ -128,8 +128,8 @@ void IZ_NetDisconnect(IZ_NetState* state) { | |||||
IZ_WSClientCancelService(&state->binding); | IZ_WSClientCancelService(&state->binding); | ||||
} | } | ||||
void IZ_NetSendBinaryMessage(IZ_NetState* state, void* in, size_t len) { | |||||
if (state->status != IZ_NET_STATUS_CONNECTED) { | |||||
void IZ_NetClientSendBinaryMessage(IZ_NetClientState* state, void* in, size_t len) { | |||||
if (state->status != IZ_NET_CLIENT_STATUS_CONNECTED) { | |||||
return; | return; | ||||
} | } | ||||
@@ -150,8 +150,8 @@ void IZ_NetSendBinaryMessage(IZ_NetState* state, void* in, size_t len) { | |||||
lws_callback_on_writable(state->binding.connection); | lws_callback_on_writable(state->binding.connection); | ||||
} | } | ||||
void IZ_NetSendTextMessage(IZ_NetState* state, char* in, size_t len) { | |||||
if (state->status != IZ_NET_STATUS_CONNECTED) { | |||||
void IZ_NetClientSendTextMessage(IZ_NetClientState* state, char* in, size_t len) { | |||||
if (state->status != IZ_NET_CLIENT_STATUS_CONNECTED) { | |||||
return; | return; | ||||
} | } | ||||
@@ -0,0 +1,74 @@ | |||||
#ifndef IZ_NET_CLIENT_H | |||||
#define IZ_NET_CLIENT_H | |||||
#include "minIni.h" | |||||
#include "SDL_thread.h" | |||||
#include "../config/IZ_config.h" | |||||
#include "../common/IZ_common.h" | |||||
#include "../game/input/IZ_action.h" | |||||
#include "svc/IZ_wsclient.h" | |||||
typedef enum { | |||||
IZ_NET_CLIENT_STATUS_PRISTINE, | |||||
IZ_NET_CLIENT_STATUS_CONNECTING, | |||||
IZ_NET_CLIENT_STATUS_ERROR, | |||||
IZ_NET_CLIENT_STATUS_CONNECTED, | |||||
} IZ_NetClientStatus; | |||||
typedef struct { | |||||
u16 packet_interval_ms; | |||||
u8 max_reconnect_retries; | |||||
u8 reconnect_interval_secs; | |||||
char username[32]; | |||||
} IZ_NetClientConfig; | |||||
typedef struct { | |||||
SDL_Thread* client_thread; | |||||
IZ_NetClientConfig config; | |||||
IZ_NetBinding binding; | |||||
IZ_NetInitializeParams params; | |||||
void* callback; | |||||
IZ_Action action[IZ_PLAYERS]; | |||||
u8 retries; | |||||
IZ_NetClientStatus status; | |||||
// TODO add message queue | |||||
} IZ_NetClientState; | |||||
static IZ_NetClientState IZ_NET_CLIENT_DEFAULT_STATE = { | |||||
.client_thread = NULL, | |||||
.config = { | |||||
.packet_interval_ms = 200, | |||||
.max_reconnect_retries = 3, | |||||
.reconnect_interval_secs = 3, | |||||
.username = "Player", | |||||
}, | |||||
.binding = { | |||||
.interrupted = false, | |||||
.context = NULL, | |||||
.connection = NULL, | |||||
.user_data = NULL, | |||||
}, | |||||
.params = { | |||||
.port = 42069, | |||||
.path = "/", | |||||
.host = "localhost", | |||||
}, | |||||
.callback = NULL, | |||||
.action = {}, | |||||
.retries = 3, | |||||
.status = IZ_NET_CLIENT_STATUS_PRISTINE, | |||||
}; | |||||
IZ_ProcedureResult IZ_NetClientInitialize(IZ_NetClientState*, void*, void*, const char *, u8, const char *[]); | |||||
void IZ_NetClientConnect(IZ_NetClientState*, IZ_WSClientInitializeParams); | |||||
void IZ_NetClientDisconnect(IZ_NetClientState*); | |||||
IZ_ProcedureResult IZ_NetClientSaveConfig(IZ_NetClientState*, const char*); | |||||
void IZ_NetClientSendBinaryMessage(IZ_NetClientState*, void*, size_t); | |||||
void IZ_NetClientSendTextMessage(IZ_NetClientState*, char*, size_t); | |||||
#endif |
@@ -1,18 +1,18 @@ | |||||
#include "IZ_net.h" | |||||
#include "IZ_net_server.h" | |||||
void IZ_NetLoadConfig(IZ_NetState* state, const char* config_path) { | |||||
void IZ_NetLoadConfig(IZ_NetServerState* state, const char* config_path) { | |||||
char buffer[128]; | char buffer[128]; | ||||
ini_gets("Network", "Name", IZ_NET_DEFAULT_STATE.config.name, buffer, 128, config_path); | |||||
ini_gets("Network", "Name", IZ_NET_SERVER_DEFAULT_STATE.config.name, buffer, 128, config_path); | |||||
memcpy_s(state->config.name, 64, buffer, 64); | memcpy_s(state->config.name, 64, buffer, 64); | ||||
ini_gets("Network", "Motd", IZ_NET_DEFAULT_STATE.config.motd, buffer, 128, config_path); | |||||
ini_gets("Network", "Motd", IZ_NET_SERVER_DEFAULT_STATE.config.motd, buffer, 128, config_path); | |||||
memcpy_s(state->config.motd, 128, buffer, 128); | memcpy_s(state->config.motd, 128, buffer, 128); | ||||
state->config.port = ini_getl("Network", "Port", IZ_NET_DEFAULT_STATE.config.port, config_path); | |||||
state->config.port = ini_getl("Network", "Port", IZ_NET_SERVER_DEFAULT_STATE.config.port, config_path); | |||||
} | } | ||||
IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState* state, const char* config_path) { | |||||
IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetServerState* state, const char* config_path) { | |||||
if (!ini_puts("Network", "Name", state->config.name, config_path)) { | if (!ini_puts("Network", "Name", state->config.name, config_path)) { | ||||
return -1; | return -1; | ||||
} | } | ||||
@@ -28,7 +28,7 @@ IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState* state, const char* config_path) | |||||
return 0; | return 0; | ||||
} | } | ||||
void IZ_NetOverrideConfig(IZ_NetState* state, u8 argc, const char* argv[]) { | |||||
void IZ_NetOverrideConfig(IZ_NetServerState* state, u8 argc, const char* argv[]) { | |||||
const char* cmdline_buffer; | const char* cmdline_buffer; | ||||
char* rest_of_string; | char* rest_of_string; | ||||
u16 port; | u16 port; | ||||
@@ -49,7 +49,7 @@ void IZ_NetOverrideConfig(IZ_NetState* state, u8 argc, const char* argv[]) { | |||||
} | } | ||||
IZ_ProcedureResult IZ_NetInitialize( | IZ_ProcedureResult IZ_NetInitialize( | ||||
IZ_NetState* state, | |||||
IZ_NetServerState* state, | |||||
void* user_data, | void* user_data, | ||||
const char* config_path, | const char* config_path, | ||||
u8 argc, | u8 argc, | ||||
@@ -58,7 +58,7 @@ IZ_ProcedureResult IZ_NetInitialize( | |||||
if (!user_data) { | if (!user_data) { | ||||
return -1; | return -1; | ||||
} | } | ||||
memcpy_s(state, sizeof(IZ_NetState), &IZ_NET_DEFAULT_STATE, sizeof(IZ_NetState)); | |||||
memcpy_s(state, sizeof(IZ_NetServerState), &IZ_NET_SERVER_DEFAULT_STATE, sizeof(IZ_NetServerState)); | |||||
IZ_NetLoadConfig(state, config_path); | IZ_NetLoadConfig(state, config_path); | ||||
if (IZ_NetSaveConfig(state, config_path) < 0) { | if (IZ_NetSaveConfig(state, config_path) < 0) { | ||||
return -2; | return -2; | ||||
@@ -68,3 +68,6 @@ IZ_ProcedureResult IZ_NetInitialize( | |||||
return 0; | return 0; | ||||
} | } | ||||
void IZ_NetServerCancelService(IZ_NetServerState* state) { | |||||
IZ_WSServerCancelService(&state->ws); | |||||
} |
@@ -0,0 +1,43 @@ | |||||
#ifndef IZ_NET_SERVER_H | |||||
#define IZ_NET_SERVER_H | |||||
#include <minIni.h> | |||||
#include "../config/IZ_config.h" | |||||
#include "../common/IZ_common.h" | |||||
#include "core/IZ_websocket.h" | |||||
#include "svc/IZ_wsserver.h" | |||||
#define IZ_DEFAULT_MOTD "" | |||||
typedef struct { | |||||
u16 port; | |||||
char name[64]; | |||||
char motd[128]; | |||||
} IZ_NetServerConfig; | |||||
typedef struct { | |||||
IZ_NetServerConfig config; | |||||
IZ_NetBinding ws; | |||||
} IZ_NetServerState; | |||||
static IZ_NetServerState IZ_NET_SERVER_DEFAULT_STATE = { | |||||
.config = { | |||||
.port = 42069, | |||||
.name = IZ_APP_NAME " Server", | |||||
.motd = IZ_DEFAULT_MOTD, | |||||
}, | |||||
.ws = { | |||||
.interrupted = false, | |||||
.context = NULL, | |||||
.connection = NULL, | |||||
.user_data = NULL, | |||||
}, | |||||
}; | |||||
IZ_ProcedureResult IZ_NetInitialize(IZ_NetServerState*, void*, const char*, u8, const char*[]); | |||||
IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetServerState*, const char*); | |||||
void IZ_NetServerCancelService(IZ_NetServerState*); | |||||
#endif |
@@ -2,7 +2,7 @@ | |||||
#define IZ_WEBSOCKET_H | #define IZ_WEBSOCKET_H | ||||
#include "libwebsockets.h" | #include "libwebsockets.h" | ||||
#include "../../IZ_common.h" | |||||
#include "../../common/IZ_common.h" | |||||
#define NETWORK_PROTOCOL "izanagi-networking" | #define NETWORK_PROTOCOL "izanagi-networking" | ||||
#define RING_COUNT 32 | #define RING_COUNT 32 | ||||
@@ -23,6 +23,8 @@ typedef struct { | |||||
u8 interrupted: 1; | u8 interrupted: 1; | ||||
} IZ_Websocket; | } IZ_Websocket; | ||||
typedef IZ_Websocket IZ_NetBinding; | |||||
void IZ_WebsocketInitialize(IZ_Websocket*); | void IZ_WebsocketInitialize(IZ_Websocket*); | ||||
IZ_ProcedureResult IZ_WebsocketHandle(IZ_Websocket*); | IZ_ProcedureResult IZ_WebsocketHandle(IZ_Websocket*); |
@@ -1,7 +1,7 @@ | |||||
#ifndef IZ_WSCLIENT_H | #ifndef IZ_WSCLIENT_H | ||||
#define IZ_WSCLIENT_H | #define IZ_WSCLIENT_H | ||||
#include "../../IZ_common.h" | |||||
#include "../../common/IZ_common.h" | |||||
#include "../core/IZ_websocket.h" | #include "../core/IZ_websocket.h" | ||||
typedef struct { | typedef struct { | ||||
@@ -35,6 +35,8 @@ typedef struct { | |||||
u16 port; | u16 port; | ||||
} IZ_WSClientInitializeParams; | } IZ_WSClientInitializeParams; | ||||
typedef IZ_WSClientInitializeParams IZ_NetInitializeParams; | |||||
IZ_ProcedureResult IZ_WSClientInitialize(IZ_Websocket*, IZ_WSClientInitializeParams); | IZ_ProcedureResult IZ_WSClientInitialize(IZ_Websocket*, IZ_WSClientInitializeParams); | ||||
IZ_ProcedureResult IZ_WSClientHandle(IZ_Websocket*); | IZ_ProcedureResult IZ_WSClientHandle(IZ_Websocket*); |
@@ -3,7 +3,7 @@ | |||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "../../IZ_common.h" | |||||
#include "../../common/IZ_common.h" | |||||
#include "../core/IZ_websocket.h" | #include "../core/IZ_websocket.h" | ||||
#ifndef S_ISDIR | #ifndef S_ISDIR |
@@ -4,7 +4,7 @@ static IZ_App* global_app; | |||||
void IZ_AppHandleSignal(i32 _signal) { | void IZ_AppHandleSignal(i32 _signal) { | ||||
global_app->net_state.ws.interrupted = true; | global_app->net_state.ws.interrupted = true; | ||||
IZ_WSServerCancelService(&global_app->net_state.ws); | |||||
IZ_NetServerCancelService(&global_app->net_state); | |||||
} | } | ||||
IZ_ProcedureResult IZ_AppInitialize(IZ_App *app, u8 argc, const char **argv) { | IZ_ProcedureResult IZ_AppInitialize(IZ_App *app, u8 argc, const char **argv) { | ||||
@@ -3,18 +3,17 @@ | |||||
#include <signal.h> | #include <signal.h> | ||||
#include <stdbool.h> | #include <stdbool.h> | ||||
#include "net/svc/IZ_wsserver.h" | |||||
#include "log/IZ_log.h" | |||||
#include "IZ_common.h" | |||||
#include "IZ_config.h" | |||||
#include "net/IZ_net.h" | |||||
#include "../common/IZ_common.h" | |||||
#include "../net/IZ_net_server.h" | |||||
#include "../log/IZ_log.h" | |||||
#include "db/IZ_repo.h" | #include "db/IZ_repo.h" | ||||
#include "IZ_app_config.h" | |||||
typedef struct { | typedef struct { | ||||
IZ_NetState net_state; | |||||
IZ_NetServerState net_state; | |||||
IZ_RepoState repo_state; | IZ_RepoState repo_state; | ||||
} IZ_App; | } IZ_App; | ||||
IZ_ProcedureResult IZ_AppRun(IZ_App*, u8, const char**); | |||||
IZ_ProcedureResult IZ_AppRun(IZ_App*, u8, const char*[]); | |||||
#endif | #endif |
@@ -0,0 +1,12 @@ | |||||
#include "IZ_app_config.h" | |||||
void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) { | |||||
#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-server.ini"); | |||||
} |
@@ -0,0 +1,8 @@ | |||||
#ifndef IZ_APP_CONFIG_H | |||||
#define IZ_APP_CONFIG_H | |||||
#include <SDL_filesystem.h> | |||||
#include "../config/IZ_config.h" | |||||
#include "IZ_subsystem.h" | |||||
#endif |
@@ -1 +0,0 @@ | |||||
../game/IZ_common.h |
@@ -1,31 +0,0 @@ | |||||
#include "IZ_config.h" | |||||
void IZ_ConfigGetDefaultPath(const char* config_path, size_t string_size) { | |||||
//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"); | |||||
} | |||||
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; | |||||
} |
@@ -1,13 +0,0 @@ | |||||
#ifndef IZ_CONFIG_H | |||||
#define IZ_CONFIG_H | |||||
#include <SDL_filesystem.h> | |||||
#include <string.h> | |||||
#include "IZ_common.h" | |||||
// TODO unify loading of config from cmdline and config file | |||||
void IZ_ConfigGetDefaultPath(const char*, size_t); | |||||
const char* IZ_ConfigGetCommandlineOption(u8, const char**, const char*); | |||||
#endif |
@@ -0,0 +1,4 @@ | |||||
#ifndef IZ_SUBSYSTEM_H | |||||
#define IZ_SUBSYSTEM_H | |||||
#endif |
@@ -1,11 +1,11 @@ | |||||
#ifndef IZ_REPO_H | #ifndef IZ_REPO_H | ||||
#define IZ_REPO_H | #define IZ_REPO_H | ||||
#include "minIni.h" | |||||
#include "sqlite3.h" | |||||
#include <minIni.h> | |||||
#include <sqlite3.h> | |||||
#include <string.h> | #include <string.h> | ||||
#include "../IZ_common.h" | |||||
#include "../IZ_config.h" | |||||
#include "../../common/IZ_common.h" | |||||
#include "../../config/IZ_config.h" | |||||
typedef struct { | typedef struct { | ||||
char path[64]; | char path[64]; | ||||
@@ -18,12 +18,12 @@ typedef struct { | |||||
static IZ_RepoState IZ_REPO_DEFAULT_STATE = { | static IZ_RepoState IZ_REPO_DEFAULT_STATE = { | ||||
.config = { | .config = { | ||||
.path = "db.sqlite", | |||||
.path = "server.sqlite", | |||||
}, | }, | ||||
.db = NULL, | .db = NULL, | ||||
}; | }; | ||||
IZ_ProcedureResult IZ_RepoInitialize(IZ_RepoState*, const char*, u8, const char**); | |||||
IZ_ProcedureResult IZ_RepoInitialize(IZ_RepoState*, const char*, u8, const char*[]); | |||||
void IZ_RepoTeardown(IZ_RepoState*); | void IZ_RepoTeardown(IZ_RepoState*); | ||||
@@ -1 +0,0 @@ | |||||
../game/log |
@@ -1,40 +0,0 @@ | |||||
#ifndef IZ_NET_H | |||||
#define IZ_NET_H | |||||
#include <minIni.h> | |||||
#include "../IZ_common.h" | |||||
#include "../IZ_config.h" | |||||
#include "core/IZ_websocket.h" | |||||
#define IZ_DEFAULT_MOTD "" | |||||
typedef struct { | |||||
u16 port; | |||||
char name[64]; | |||||
char motd[128]; | |||||
} IZ_NetConfig; | |||||
typedef struct { | |||||
IZ_NetConfig config; | |||||
IZ_Websocket ws; | |||||
} IZ_NetState; | |||||
static IZ_NetState IZ_NET_DEFAULT_STATE = { | |||||
.config = { | |||||
.port = 42069, | |||||
.name = IZ_APP_NAME " Server", | |||||
.motd = IZ_DEFAULT_MOTD, | |||||
}, | |||||
.ws = { | |||||
.interrupted = false, | |||||
.context = NULL, | |||||
.connection = NULL, | |||||
.user_data = NULL, | |||||
}, | |||||
}; | |||||
IZ_ProcedureResult IZ_NetInitialize(IZ_NetState*, void*, const char*, u8, const char**); | |||||
IZ_ProcedureResult IZ_NetSaveConfig(IZ_NetState*, const char*); | |||||
#endif |
@@ -1 +0,0 @@ | |||||
../../game/net/core |