a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

platform.h (1292B)


      1 #pragma once
      2 
      3 #include "types.h"
      4 
      5 #define PLATFORM_READ_ENTIRE_FILE(name) u8 *(name)(char *file_path, size_t *out_num_bytes, struct StackAllocator *a)
      6 typedef PLATFORM_READ_ENTIRE_FILE(platform_read_entire_file_func);
      7 
      8 // TODO: Remove this from the platform api
      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_memory_free_func* platform_memory_free;
     16 };
     17 
     18 struct GameMemory
     19 {
     20     u64 buffer_size;
     21     void *buffer;
     22     struct PlatformApi platform;
     23 };
     24 
     25 #ifdef PLATFORM_HOTLOAD_GAME_CODE
     26 #include <time.h>
     27 // We need to call this from the platform layer in order for the game, when
     28 // built as a shared object library to have access to the OpenGL symbols.
     29 // https://github.com/Dav1dde/glad/issues/151
     30 typedef void (game_load_opengl_symbols_func)(void);
     31 
     32 typedef void (game_update_and_render_func)(struct GameMemory *game_memory, struct GameInput *game_input, v2u framebuffer);
     33 
     34 struct GameCode
     35 {
     36     bool is_valid;
     37     void *game_code_library;
     38     time_t last_write_time;
     39     game_load_opengl_symbols_func *game_load_opengl_symbols;
     40     game_update_and_render_func *game_update_and_render;
     41 };
     42 #endif // PLATFORM_HOTLOAD_GAME_CODE