From 3ee49cf7e957d171d4e66fb944f19286c37789a1 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Sun, 19 Jun 2022 20:11:06 +0800 Subject: [PATCH] Update name of app and network binding member Make the member name generic to accommodate other potential implementations beyond Websockets. --- src/packages/game/IZ_app.c | 3 +-- src/packages/game/net/IZ_app.c | 8 +++---- src/packages/game/net/IZ_net.c | 28 ++++++++++++------------- src/packages/game/net/IZ_net.h | 4 ++-- src/packages/game/output/video/IZ_app.c | 2 +- 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/packages/game/IZ_app.c b/src/packages/game/IZ_app.c index aee9d8f..9d6dc76 100644 --- a/src/packages/game/IZ_app.c +++ b/src/packages/game/IZ_app.c @@ -5,7 +5,7 @@ u64 IZ_AppGetTicks(struct IZ_App* app) { } void IZ_AppBindConnection(struct IZ_App* app, struct lws* wsi) { - app->net_state.ws.connection = wsi; + app->net_state.binding.connection = wsi; } IZ_NetState* IZ_AppGetNetState(struct IZ_App* app) { @@ -52,7 +52,6 @@ IZ_ProcedureResult IZ_AppInitialize(struct IZ_App* app, u8 argc, const char* arg IZ_PoolInitialize(&app->pool, POOL_MAX_SIZE); - // TODO put into its timer module app->ticks = 0; return IZ_APP_RUN_RESULT_OK; } diff --git a/src/packages/game/net/IZ_app.c b/src/packages/game/net/IZ_app.c index ec6af69..f7006ba 100644 --- a/src/packages/game/net/IZ_app.c +++ b/src/packages/game/net/IZ_app.c @@ -289,22 +289,22 @@ void IZ_WSClientOnReceive(struct lws* wsi, IZ_WSClientSessionData* pss, void* in IZ_ProcedureResult IZ_AppRunNetworkingThread(struct IZ_App* app) { IZ_NetState* net_state = IZ_AppGetNetState(app); - if (IZ_WSClientInitialize(&net_state->ws, net_state->params)) { + if (IZ_WSClientInitialize(&net_state->binding, net_state->params)) { return -1; } i32 result = 0; while (true) { - if (IZ_WSClientHandle(&net_state->ws)) { + if (IZ_WSClientHandle(&net_state->binding)) { result = -1; break; } - if (net_state->ws.interrupted) { + if (net_state->binding.interrupted) { break; } } - IZ_WSClientTeardown(&net_state->ws); + IZ_WSClientTeardown(&net_state->binding); return result; } diff --git a/src/packages/game/net/IZ_net.c b/src/packages/game/net/IZ_net.c index e12f4be..f34486c 100644 --- a/src/packages/game/net/IZ_net.c +++ b/src/packages/game/net/IZ_net.c @@ -66,7 +66,7 @@ IZ_ProcedureResult IZ_NetInitialize( if (!user_data) { return -2; } - state->ws.user_data = user_data; + state->binding.user_data = user_data; state->callback = callback; state->retries = state->config.max_reconnect_retries; u8 player_index; @@ -96,7 +96,7 @@ void IZ_NetConnect(IZ_NetState* state, IZ_WSClientInitializeParams params) { state->retries = 0; state->params = params; - state->client_thread = SDL_CreateThread(state->callback, "networking", state->ws.user_data); + state->client_thread = SDL_CreateThread(state->callback, "networking", state->binding.user_data); SDL_DetachThread(state->client_thread); } @@ -104,17 +104,17 @@ void IZ_NetDisconnect(IZ_NetState* state) { if (state->status == IZ_NET_STATUS_PRISTINE) { return; } - if (state->ws.connection) { + if (state->binding.connection) { IZ_WSClientVHostData *vhd = (IZ_WSClientVHostData *) lws_protocol_vh_priv_get( - lws_get_vhost(state->ws.connection), - lws_get_protocol(state->ws.connection) + lws_get_vhost(state->binding.connection), + lws_get_protocol(state->binding.connection) ); if (vhd) { lws_sul_cancel(&vhd->sul); } } state->retries = state->config.max_reconnect_retries; - IZ_WSClientCancelService(&state->ws); + IZ_WSClientCancelService(&state->binding); } void IZ_NetSendBinaryMessage(IZ_NetState* state, void* in, size_t len) { @@ -123,20 +123,20 @@ void IZ_NetSendBinaryMessage(IZ_NetState* state, void* in, size_t len) { } IZ_WSClientVHostData* vhd = (IZ_WSClientVHostData*) lws_protocol_vh_priv_get( - lws_get_vhost(state->ws.connection), - lws_get_protocol(state->ws.connection) + lws_get_vhost(state->binding.connection), + lws_get_protocol(state->binding.connection) ); IZ_WebsocketMessage amsg; i32 result; - result = IZ_WebsocketCreateBinaryMessage(state->ws.connection, &amsg, in, len); + result = IZ_WebsocketCreateBinaryMessage(state->binding.connection, &amsg, in, len); if (result < 0) { return; } lws_ring_insert(vhd->ring, &amsg, 1); - lws_callback_on_writable(state->ws.connection); + lws_callback_on_writable(state->binding.connection); } void IZ_NetSendTextMessage(IZ_NetState* state, char* in, size_t len) { @@ -145,18 +145,18 @@ void IZ_NetSendTextMessage(IZ_NetState* state, char* in, size_t len) { } IZ_WSClientVHostData* vhd = (IZ_WSClientVHostData*) lws_protocol_vh_priv_get( - lws_get_vhost(state->ws.connection), - lws_get_protocol(state->ws.connection) + lws_get_vhost(state->binding.connection), + lws_get_protocol(state->binding.connection) ); IZ_WebsocketMessage amsg; i32 result; - result = IZ_WebsocketCreateTextMessage(state->ws.connection, &amsg, in, len); + result = IZ_WebsocketCreateTextMessage(state->binding.connection, &amsg, in, len); if (result < 0) { return; } lws_ring_insert(vhd->ring, &amsg, 1); - lws_callback_on_writable(state->ws.connection); + lws_callback_on_writable(state->binding.connection); } diff --git a/src/packages/game/net/IZ_net.h b/src/packages/game/net/IZ_net.h index 51d9e15..8e1c066 100644 --- a/src/packages/game/net/IZ_net.h +++ b/src/packages/game/net/IZ_net.h @@ -26,7 +26,7 @@ typedef struct { typedef struct { SDL_Thread* client_thread; IZ_NetConfig config; - IZ_Websocket ws; + IZ_Websocket binding; IZ_WSClientInitializeParams params; void* callback; IZ_Action action[IZ_PLAYERS]; @@ -43,7 +43,7 @@ static IZ_NetState IZ_NET_DEFAULT_STATE = { .reconnect_interval_secs = 3, .username = "Player", }, - .ws = { + .binding = { .interrupted = false, .context = NULL, .connection = NULL, diff --git a/src/packages/game/output/video/IZ_app.c b/src/packages/game/output/video/IZ_app.c index 6f3aae3..9da9196 100644 --- a/src/packages/game/output/video/IZ_app.c +++ b/src/packages/game/output/video/IZ_app.c @@ -76,7 +76,7 @@ void IZ_VideoUpdateForDebugNet(IZ_VideoState* video_state, IZ_NetState* net_stat size, }); - if (!net_state->ws.connection) { + if (!net_state->binding.connection) { return; }