platform.h (1377B)
1 #pragma once 2 3 #define PLATFORM_READ_ENTIRE_FILE(name) char *(name)(char *file_path) 4 typedef PLATFORM_READ_ENTIRE_FILE(platform_read_entire_file_func); 5 6 #define PLATFORM_PRINT(name) int (name)(const char *format, ...) 7 typedef PLATFORM_PRINT(platform_print_func); 8 9 #define PLATFORM_MEMORY_FREE(name) void (name)(void *ptr) 10 typedef PLATFORM_MEMORY_FREE(platform_memory_free_func); 11 12 struct PlatformApi 13 { 14 platform_read_entire_file_func* platform_read_entire_file; 15 platform_print_func* platform_print; 16 platform_memory_free_func* platform_memory_free; 17 }; 18 19 struct GameState 20 { 21 u32 cube_vao; 22 u32 cube_vbo; 23 u32 cube_ebo; 24 struct Shader cube_shader; 25 struct PlatformApi platform; 26 }; 27 28 #ifdef PLATFORM_HOTLOAD_GAME_CODE 29 #include <time.h> 30 // We need to call this from the platform layer in order for the game, when 31 // built as a shared object library to have access to the OpenGL symbols. 32 // https://github.com/Dav1dde/glad/issues/151 33 typedef void (game_load_opengl_symbols_func)(void); 34 35 typedef void (game_update_and_render_func)(struct GameState *game_state, float dt, u32 screen_width, u32 screen_height); 36 37 struct GameCode 38 { 39 bool is_valid; 40 void *game_code_library; 41 time_t last_write_time; 42 game_load_opengl_symbols_func *game_load_opengl_symbols; 43 game_update_and_render_func *game_update_and_render; 44 }; 45 #endif // PLATFORM_HOTLOAD_GAME_CODE