|
|
@@ -1,6 +1,35 @@ |
|
|
|
#include "IZ_app.h" |
|
|
|
|
|
|
|
IZ_ProcedureResult IZ_AppWSClientCallback( |
|
|
|
struct lws* wsi, |
|
|
|
enum lws_callback_reasons reason, |
|
|
|
void* userraw, |
|
|
|
void* in, |
|
|
|
size_t len |
|
|
|
) { |
|
|
|
IZ_App* user = userraw; |
|
|
|
switch (reason) { |
|
|
|
case LWS_CALLBACK_CLIENT_CONNECTION_ERROR: |
|
|
|
printf("Client Connection Error %llu\n", len); |
|
|
|
return 1; |
|
|
|
case LWS_CALLBACK_CLIENT_CLOSED: |
|
|
|
printf("Client Closed %llu\n", len); |
|
|
|
return 0; |
|
|
|
case LWS_CALLBACK_CLIENT_RECEIVE: |
|
|
|
printf("Client Receive %llu\n", len); |
|
|
|
break; |
|
|
|
case LWS_CALLBACK_CLIENT_ESTABLISHED: |
|
|
|
printf("Client Established %llu\n", len); |
|
|
|
break; |
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
IZ_ProcedureResult IZ_AppInitialize(IZ_App* app) { |
|
|
|
memset(app, 0, sizeof(IZ_App)); |
|
|
|
u32 flags = ( |
|
|
|
SDL_INIT_VIDEO |
|
|
|
| SDL_INIT_GAMECONTROLLER |
|
|
@@ -40,12 +69,21 @@ void IZ_AppTeardown(IZ_App* app) { |
|
|
|
} |
|
|
|
|
|
|
|
IZ_ProcedureResult IZ_AppHandleSDLEvents(IZ_App* app) { |
|
|
|
while (SDL_PollEvent(&app->input_state.sdl_event) != 0) { |
|
|
|
if (app->input_state.sdl_event.type == SDL_QUIT) { |
|
|
|
SDL_Event e; |
|
|
|
while (SDL_PollEvent(&e) != 0) { |
|
|
|
if (e.type == SDL_QUIT) { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
IZ_InputHandleSDLEvents(&app->input_state); |
|
|
|
if (e.type == SDL_KEYDOWN) { |
|
|
|
if (e.key.keysym.sym == SDLK_PAGEUP) { |
|
|
|
// TODO connect |
|
|
|
} else if (e.key.keysym.sym == SDLK_PAGEDOWN) { |
|
|
|
// TODO disconnect |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
IZ_InputHandleSDLEvents(&app->input_state, e); |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
@@ -55,9 +93,14 @@ void IZ_AppHandlePortMIDIEvents(IZ_App* app) { |
|
|
|
i32* midi_events_count; |
|
|
|
u32 midi_event_index; |
|
|
|
for (player_index = 0; player_index < PLAYERS; player_index += 1) { |
|
|
|
if (!app->input_state.midi_input_state[player_index].device_info) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
midi_events_count = &app->input_state.midi_input_state[player_index].midi_events_count; |
|
|
|
*midi_events_count = Pm_Read( |
|
|
|
app->input_state.midi_input_state[player_index].stream, |
|
|
|
// TODO bind buffers and streams to device instead of player input state |
|
|
|
app->input_state.midi_input_state[player_index].event_buffer, |
|
|
|
1024 |
|
|
|
); |
|
|
@@ -83,11 +126,15 @@ IZ_ProcedureResult IZ_AppHandleEvents(IZ_App* app) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
IZ_ProcedureResult IZ_AppRun(IZ_App* app, u8 arg_count, char* arg_values[]) { |
|
|
|
printf_s("Args (%u):\n", arg_count); |
|
|
|
IZ_ProcedureResult IZ_AppRunNetworkingThread(void* ptr) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
IZ_ProcedureResult IZ_AppRun(IZ_App* app, u8 argc, const char* argv[]) { |
|
|
|
printf_s("Args (%u):\n", argc); |
|
|
|
u8 arg_index; |
|
|
|
for (arg_index = 0; arg_index < arg_count; arg_index += 1) { |
|
|
|
printf_s(" %s\n", arg_values[arg_index]); |
|
|
|
for (arg_index = 0; arg_index < argc; arg_index += 1) { |
|
|
|
printf_s(" %s\n", argv[arg_index]); |
|
|
|
} |
|
|
|
|
|
|
|
IZ_ProcedureResult init_result = IZ_AppInitialize(app); |
|
|
@@ -95,25 +142,29 @@ IZ_ProcedureResult IZ_AppRun(IZ_App* app, u8 arg_count, char* arg_values[]) { |
|
|
|
return init_result; |
|
|
|
} |
|
|
|
|
|
|
|
if (IZ_WSClientConnect(&app->client, (IZ_WSClientConnectParams) { |
|
|
|
.userdata = app, |
|
|
|
.path = "/", |
|
|
|
.protocol = "http", // TODO handle ws protocol correctly |
|
|
|
.address = "localhost", |
|
|
|
.port = 6969, |
|
|
|
})) { |
|
|
|
return IZ_APP_RUN_NETWORKING_ERROR; |
|
|
|
} |
|
|
|
// if (IZ_WSClientConnect(&app->client, (IZ_WSClientConnectParams) { |
|
|
|
// .userdata = app, |
|
|
|
// .path = "/", |
|
|
|
// .protocol = NETWORK_PROTOCOL, // TODO handle ws protocol correctly |
|
|
|
// .address = "localhost", |
|
|
|
// .port = 42069, |
|
|
|
// .callback = IZ_AppWSClientCallback, |
|
|
|
// })) { |
|
|
|
// return IZ_APP_RUN_NETWORKING_ERROR; |
|
|
|
// } |
|
|
|
|
|
|
|
//app->client_thread = SDL_CreateThread(IZ_AppRunNetworkingThread, "Networking", app); |
|
|
|
//SDL_DetachThread(app->client_thread); |
|
|
|
|
|
|
|
while (true) { |
|
|
|
app->ticks = SDL_GetTicks64(); |
|
|
|
|
|
|
|
// TODO do audio processing |
|
|
|
// TODO do networking |
|
|
|
if (app->client.connection) { |
|
|
|
//if (app->client.connection) { |
|
|
|
// FIXME stuck in infinite loop |
|
|
|
IZ_WSClientHandle(&app->client); |
|
|
|
} |
|
|
|
//IZ_WSClientHandle(&app->client); |
|
|
|
//} |
|
|
|
|
|
|
|
if (IZ_AppHandleEvents(app)) { |
|
|
|
// TODO refactor input handlers to have same function signature. |
|
|
|