@@ -4,6 +4,7 @@ | |||||
#include <SDL_filesystem.h> | #include <SDL_filesystem.h> | ||||
#include <string.h> | #include <string.h> | ||||
// TODO unify loading of config from cmdline and config file | |||||
void IZ_ConfigGetDefaultPath(const char*, size_t); | void IZ_ConfigGetDefaultPath(const char*, size_t); | ||||
#endif | #endif |
@@ -181,7 +181,6 @@ IZ_ProcedureResult IZ_MIDIInputInitialize(const char* config_path, IZ_MIDIInputS | |||||
} | } | ||||
u8 player_index; | u8 player_index; | ||||
// TODO Pm_CountDevices(), only filter input devices | |||||
u8 midi_devices_count = Pm_CountDevices(); | u8 midi_devices_count = Pm_CountDevices(); | ||||
u8 input_midi_devices_count = 0; | u8 input_midi_devices_count = 0; | ||||
u8 device_index; | u8 device_index; | ||||
@@ -62,8 +62,6 @@ spec("memory") { | |||||
it("assigns contiguous memory") { | it("assigns contiguous memory") { | ||||
IZ_PoolInitialize(&pool, POOL_MAX_SIZE); | IZ_PoolInitialize(&pool, POOL_MAX_SIZE); | ||||
// FIXME: access violation error | |||||
void* p1 = IZ_PoolAllocate(&pool, (IZ_PoolAllocationArgs){ | void* p1 = IZ_PoolAllocate(&pool, (IZ_PoolAllocationArgs){ | ||||
.size = sizeof(struct DummyStruct), | .size = sizeof(struct DummyStruct), | ||||
.priority = 0, | .priority = 0, | ||||
@@ -108,6 +108,12 @@ void IZ_VideoUpdate(IZ_VideoState* video_state, u64 ticks, IZ_InputState* input_ | |||||
// Update window | // Update window | ||||
SDL_SetRenderDrawColor(video_state->renderer, 0x00, 0x00, 0x00, 0xff); | SDL_SetRenderDrawColor(video_state->renderer, 0x00, 0x00, 0x00, 0xff); | ||||
SDL_RenderClear(video_state->renderer); | SDL_RenderClear(video_state->renderer); | ||||
for (u8 i = 0; i < MAX_ACTIVE_SPRITES; i += 1) { | |||||
if (!video_state->active_sprites[i]) { | |||||
continue; | |||||
} | |||||
// TODO draw sprites | |||||
} | |||||
IZ_VideoUpdateForDebug(video_state, input_state, ticks); | IZ_VideoUpdateForDebug(video_state, input_state, ticks); | ||||
SDL_RenderPresent(video_state->renderer); | SDL_RenderPresent(video_state->renderer); | ||||
video_state->last_update_at = ticks; | video_state->last_update_at = ticks; | ||||
@@ -5,11 +5,15 @@ | |||||
#include <minIni.h> | #include <minIni.h> | ||||
#include <SDL_render.h> | #include <SDL_render.h> | ||||
// TODO move this out from video, refer to app's state instead | |||||
#include "../input/IZ_input.h" | #include "../input/IZ_input.h" | ||||
#include "../IZ_common.h" | #include "../IZ_common.h" | ||||
#include "../IZ_config.h" | #include "../IZ_config.h" | ||||
#define MAX_ACTIVE_SPRITES 32 | |||||
// TODO properly define sprites | |||||
typedef char IZ_Sprite; | |||||
typedef struct { | typedef struct { | ||||
u16 width; | u16 width; | ||||
u16 height; | u16 height; | ||||
@@ -18,9 +22,10 @@ typedef struct { | |||||
typedef struct { | typedef struct { | ||||
IZ_VideoConfig config; | IZ_VideoConfig config; | ||||
uint64_t last_update_at; | |||||
u64 last_update_at; | |||||
SDL_Window* window; | SDL_Window* window; | ||||
SDL_Renderer* renderer; | SDL_Renderer* renderer; | ||||
IZ_Sprite active_sprites[MAX_ACTIVE_SPRITES]; | |||||
} IZ_VideoState; | } IZ_VideoState; | ||||
static const IZ_VideoState IZ_DEFAULT_VIDEO_STATE = { | static const IZ_VideoState IZ_DEFAULT_VIDEO_STATE = { | ||||
@@ -32,6 +37,7 @@ static const IZ_VideoState IZ_DEFAULT_VIDEO_STATE = { | |||||
.last_update_at = 0, | .last_update_at = 0, | ||||
.renderer = NULL, | .renderer = NULL, | ||||
.window = NULL, | .window = NULL, | ||||
.active_sprites = {}, | |||||
}; | }; | ||||
IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState*, const char*); | IZ_ProcedureResult IZ_VideoInitialize(IZ_VideoState*, const char*); | ||||
@@ -22,10 +22,16 @@ void IZ_AppLoadConfig(IZ_App *app, u8 argc, const char **argv) { | |||||
IZ_ProcedureResult IZ_AppInitialize(IZ_App *app, u8 argc, const char **argv) { | IZ_ProcedureResult IZ_AppInitialize(IZ_App *app, u8 argc, const char **argv) { | ||||
interrupted = false; | interrupted = false; | ||||
signal(SIGINT, IZ_AppHandleSignal); | signal(SIGINT, IZ_AppHandleSignal); | ||||
//signal(SIGTERM, IZ_AppHandleSignal); | |||||
IZ_AppLoadConfig(app, argc, argv); | IZ_AppLoadConfig(app, argc, argv); | ||||
IZ_LogInterceptWSMessages(app->config.log_level); | IZ_LogInterceptWSMessages(app->config.log_level); | ||||
if (IZ_WSServerCreateContext(&app->context, app->config.port)) { | |||||
if (IZ_WSServerCreateContext(&app->context, (IZ_WSServerCreateContextParams) { | |||||
.protocol = NULL, | |||||
.port = app->config.port, | |||||
.default_filename = NULL, | |||||
.origin = NULL, | |||||
})) { | |||||
return 1; | return 1; | ||||
} | } | ||||
@@ -1,47 +1,5 @@ | |||||
#include "IZ_wsserver.h" | #include "IZ_wsserver.h" | ||||
static struct lws_protocols protocols[] = { | |||||
{ | |||||
.name = NETWORK_PROTOCOL, | |||||
.callback = IZ_WSServerCallback, | |||||
.per_session_data_size = sizeof(IZ_WSServerSessionData), | |||||
.rx_buffer_size = 0, | |||||
.id = 0, | |||||
.user = NULL, | |||||
.tx_packet_size = 0, | |||||
}, | |||||
{ | |||||
.name = "http", | |||||
.callback = lws_callback_http_dummy, | |||||
.per_session_data_size = 0, | |||||
.rx_buffer_size = 0, | |||||
.id = 0, | |||||
.user = NULL, | |||||
.tx_packet_size = 0, | |||||
}, | |||||
LWS_PROTOCOL_LIST_TERM, | |||||
}; | |||||
static const struct lws_http_mount mount = { | |||||
.mount_next = NULL, /* linked-list "next" */ | |||||
.mountpoint = "/", /* mountpoint URL */ | |||||
.origin = "./mount-origin", /* serve from dir */ | |||||
.def = "index.html", /* default filename */ | |||||
.protocol = NULL, | |||||
.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, | |||||
}; | |||||
static void IZ_ProtocolCullLaggingClients(IZ_WSServerVHostData *vhd) { | static void IZ_ProtocolCullLaggingClients(IZ_WSServerVHostData *vhd) { | ||||
u32 oldest_tail = lws_ring_get_oldest_tail(vhd->ring); | u32 oldest_tail = lws_ring_get_oldest_tail(vhd->ring); | ||||
IZ_WSServerSessionData *old_pss = NULL; | IZ_WSServerSessionData *old_pss = NULL; | ||||
@@ -135,8 +93,8 @@ static void IZ_ProtocolCullLaggingClients(IZ_WSServerVHostData *vhd) { | |||||
/* destroys the message when everyone has had a copy of it */ | /* destroys the message when everyone has had a copy of it */ | ||||
void IZ_ProtocolDestroyMessage(void *_msg) { | |||||
IZ_WSServerMessage *msg = _msg; | |||||
void IZ_ProtocolDestroyMessage(void* msg_raw) { | |||||
IZ_WSServerMessage *msg = msg_raw; | |||||
free(msg->payload); | free(msg->payload); | ||||
msg->payload = NULL; | msg->payload = NULL; | ||||
@@ -324,13 +282,66 @@ i32 IZ_WSServerCallback( | |||||
return 0; | return 0; | ||||
} | } | ||||
IZ_ProcedureResult IZ_WSServerCreateContext(struct lws_context** context, u16 port) { | |||||
IZ_ProcedureResult IZ_WSServerCreateContext(struct lws_context** context, IZ_WSServerCreateContextParams params) { | |||||
struct lws_context_creation_info info; | struct lws_context_creation_info info; | ||||
memset(&info, 0, sizeof info); | memset(&info, 0, sizeof info); | ||||
info.port = port; | |||||
info.port = params.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 (params.origin) { | |||||
mount.origin = params.origin; | |||||
} | |||||
if (params.default_filename) { | |||||
mount.def = params.default_filename; | |||||
} | |||||
if (params.protocol) { | |||||
mount.protocol = params.protocol; | |||||
} | |||||
info.mounts = &mount; | info.mounts = &mount; | ||||
static const struct lws_protocols protocols[] = { | |||||
{ | |||||
.name = NETWORK_PROTOCOL, | |||||
.callback = IZ_WSServerCallback, | |||||
.per_session_data_size = sizeof(IZ_WSServerSessionData), | |||||
.rx_buffer_size = 0, | |||||
.id = 0, | |||||
.user = NULL, | |||||
.tx_packet_size = 0, | |||||
}, | |||||
{ | |||||
.name = "http", | |||||
.callback = lws_callback_http_dummy, | |||||
.per_session_data_size = 0, | |||||
.rx_buffer_size = 0, | |||||
.id = 0, | |||||
.user = NULL, | |||||
.tx_packet_size = 0, | |||||
}, | |||||
LWS_PROTOCOL_LIST_TERM, | |||||
}; | |||||
info.protocols = protocols; | info.protocols = protocols; | ||||
// TODO initialize protocols | |||||
info.options = ( | info.options = ( | ||||
LWS_SERVER_OPTION_VALIDATE_UTF8 | LWS_SERVER_OPTION_VALIDATE_UTF8 | ||||
| LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE | | LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE | ||||
@@ -40,6 +40,13 @@ i32 IZ_WSServerCallback( | |||||
size_t | size_t | ||||
); | ); | ||||
IZ_ProcedureResult IZ_WSServerCreateContext(struct lws_context**, u16); | |||||
typedef struct { | |||||
u16 port; | |||||
const char* origin; | |||||
const char* default_filename; | |||||
const char* protocol; | |||||
} IZ_WSServerCreateContextParams; | |||||
IZ_ProcedureResult IZ_WSServerCreateContext(struct lws_context**, IZ_WSServerCreateContextParams); | |||||
#endif | #endif |