Przeglądaj źródła

Update name of app and network binding member

Make the member name generic to accommodate other potential
implementations beyond Websockets.
feature/data-structs
TheoryOfNekomata 2 lat temu
rodzic
commit
3ee49cf7e9
5 zmienionych plików z 22 dodań i 23 usunięć
  1. +1
    -2
      src/packages/game/IZ_app.c
  2. +4
    -4
      src/packages/game/net/IZ_app.c
  3. +14
    -14
      src/packages/game/net/IZ_net.c
  4. +2
    -2
      src/packages/game/net/IZ_net.h
  5. +1
    -1
      src/packages/game/output/video/IZ_app.c

+ 1
- 2
src/packages/game/IZ_app.c Wyświetl plik

@@ -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;
}


+ 4
- 4
src/packages/game/net/IZ_app.c Wyświetl plik

@@ -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;
}

+ 14
- 14
src/packages/game/net/IZ_net.c Wyświetl plik

@@ -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);
}

+ 2
- 2
src/packages/game/net/IZ_net.h Wyświetl plik

@@ -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,


+ 1
- 1
src/packages/game/output/video/IZ_app.c Wyświetl plik

@@ -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;
}



Ładowanie…
Anuluj
Zapisz