#ifndef OS_H #define OS_H #include #include #include typedef struct { size_t size; u8 *p; } OSMemory; b32 os_memory_allocate(OSMemory *memory, size_t size); void os_memory_free(OSMemory *memory); typedef struct { i64 seconds; i64 nanoseconds; } OSTime; OSTime os_time_get_now(void); typedef void OSLibrary; OSLibrary* os_library_open(const char *path); void os_library_close(OSLibrary *lib); void* os_library_get_proc(OSLibrary *lib, const char *name); char* os_file_read_as_string(Arena *arena, char *path, size_t *outlen); typedef enum { OS_EVENT_KEY_PRESS, OS_EVENT_KEY_RELEASE, OS_EVENT_WINDOW_RESIZE, OS_EVENT_WINDOW_DESTROYED, } OSEventType; typedef enum { OS_KEYCODE_LEFT, OS_KEYCODE_RIGHT, OS_KEYCODE_UP, OS_KEYCODE_DOWN, } OSEventKeySpecial; typedef struct { b32 is_unicode; // else it's "special", see OSKeySpecial u32 code; // unicode character or some other keyboard keys } OSEventKeyPress; typedef struct { b32 is_special; u32 code; // unicode character or some other keyboard keys } OSEventKeyRelease; typedef struct { i32 width; i32 height; } OSEventResize; typedef struct OSEvent { OSEventType type; union { OSEventKeyPress key_press; OSEventKeyRelease key_release; OSEventResize resize; } ev; } OSEvent; typedef struct { u8 red_shift; u8 green_shift; u8 blue_shift; u8 alpha_shift; i32 width; i32 height; u32 *pixels; } OSOffscreenBuffer; typedef struct OSWindow OSWindow; OSWindow* os_window_create(const char *name, i32 width, i32 height); void os_window_destroy(OSWindow *window); b32 os_window_get_event(OSWindow *window, OSEvent *event); OSOffscreenBuffer* os_window_get_offscreen_buffer(OSWindow *window); void os_window_swap_buffers(OSWindow *window, OSOffscreenBuffer *offscreen_buffer); typedef enum { OS_NET_SECURE_STREAM_ERROR, OS_NET_SECURE_STREAM_DISCONNECTED, OS_NET_SECURE_STREAM_CONNECTED, OS_NET_SECURE_STREAM_HANDSHAKING, } OSNetSecureStreamStatus; #define OS_NET_SECURE_STREAM_ID_INVALID U32_MAX void os_net_secure_streams_init(Arena *arena, size_t max_count); u32 os_net_secure_stream_listen(u16 port, EVP_PKEY *server_rsa_pri); u32 os_net_secure_stream_accept(u32 listener_id); u32 os_net_secure_stream_connect(char *address, u16 port, EVP_PKEY *server_rsa_pub); void os_net_secure_stream_close(u32 id); OSNetSecureStreamStatus os_net_secure_stream_get_status(u32 id); i64 os_net_secure_stream_error(u32 id); // 0 if no error, else tbd i64 os_net_secure_stream_send(u32 id, u8 *buffer, size_t size); i64 os_net_secure_stream_recv(u32 id, u8 *buffer, size_t size); int os_net_secure_stream_get_fd(u32 id); typedef struct OSSoundPlayer OSSoundPlayer; typedef struct { i32 play_cursor; i32 max_sample_count; i32 sample_count; i32 samples_per_second; i16 *samples; } OSSoundBuffer; // Todo: maybe change api by replacing get_buffer with play_buffer OSSoundPlayer* os_sound_player_create(Arena *arena, i32 samples_per_second); OSSoundBuffer* os_sound_player_get_buffer(OSSoundPlayer *player); void os_sound_player_close(OSSoundPlayer *player); // Note: api unused and in progress typedef struct { void (*fn_worker)(void *data); void *data; } OSWork; typedef struct OSThreadPool OSThreadPool; typedef u32 OSThreadId; OSThreadPool* os_thread_pool_create(Arena *arena, u32 thread_count, u32 work_queue_size); OSThreadId os_thread_pool_start(OSThreadPool *pool, OSWork work); void os_thread_pool_finish(OSThreadPool *pool, OSThreadId id); #endif // OS_H