a-game

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

commit 5a27d3f5c4e4ad57d311a5de1f74316dedd9f8dc
parent 759b9e5046a8f2a9e6215d64510f66bcf4589034
Author: amin <dev@aminmesbah.com>
Date:   Thu,  4 Jul 2019 21:14:43 +0000

Return u8, not char buffers when loading files

FossilOrigin-Name: d3acd525605e7d5f27704c45d6f94969869da7b75cf8396a00c3b2e03e40a66a
Diffstat:
Msrc/game.c | 6+++---
Msrc/platform.h | 2+-
Msrc/platform_linux.c | 6+++---
Msrc/platform_wasm.c | 2+-
Msrc/platform_windows.c | 6+++---
Msrc/render.c | 1-
6 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -167,11 +167,11 @@ internal void game_init(struct GameMemory *game_memory, v2u framebuffer) } } + struct PlatformApi platform = game_memory->platform; // game_shader_load { - struct PlatformApi platform = game_memory->platform; - char *v_source = platform.platform_read_entire_file("shader/main_v.glsl"); - char *f_source = platform.platform_read_entire_file("shader/main_f.glsl"); + char *v_source = (char *)platform.platform_read_entire_file("shader/main_v.glsl"); + char *f_source = (char *)platform.platform_read_entire_file("shader/main_f.glsl"); struct Shader main_shader = {0}; if (!shader_compile(v_source, f_source, &main_shader)) { diff --git a/src/platform.h b/src/platform.h @@ -5,7 +5,7 @@ #define KIBIBYTES(n) (n) * 1024LL #define MEBIBYTES(n) KIBIBYTES((n) * 1024LL) -#define PLATFORM_READ_ENTIRE_FILE(name) char *(name)(char *file_path) +#define PLATFORM_READ_ENTIRE_FILE(name) u8 *(name)(char *file_path) typedef PLATFORM_READ_ENTIRE_FILE(platform_read_entire_file_func); #define PLATFORM_MEMORY_FREE(name) void (name)(void *ptr) diff --git a/src/platform_linux.c b/src/platform_linux.c @@ -210,7 +210,7 @@ PLATFORM_MEMORY_FREE(linux_memory_free) internal PLATFORM_READ_ENTIRE_FILE(linux_read_entire_file) { FILE *handle = fopen(file_path, "r"); - char *buffer = NULL; + u8 *buffer = NULL; if (handle) { @@ -220,9 +220,9 @@ internal PLATFORM_READ_ENTIRE_FILE(linux_read_entire_file) rewind(handle); // TODO: replace malloc with own allocator so I stop having nightmares - buffer = (char*) malloc(sizeof(char) * (num_bytes_in_file + 1) ); + buffer = (u8*) malloc(sizeof(u8) * (num_bytes_in_file + 1) ); - u32 bytes_read = fread(buffer, sizeof(char), num_bytes_in_file, handle); + u32 bytes_read = fread(buffer, sizeof(u8), num_bytes_in_file, handle); // IMPORTANT! fread() doesn't add the '\0' buffer[num_bytes_in_file] = '\0'; diff --git a/src/platform_wasm.c b/src/platform_wasm.c @@ -118,7 +118,7 @@ PLATFORM_MEMORY_FREE(wasm_memory_free) PLATFORM_READ_ENTIRE_FILE(wasm_read_entire_file) { g_mem_buffer_i++; - char *buf = &g_mem_buffer[g_mem_buffer_i]; + u8 *buf = &g_mem_buffer[g_mem_buffer_i]; if(js_read_entire_file((i32)file_path, str_length(file_path), buf)) { i32 file_data_length = str_length(buf); diff --git a/src/platform_windows.c b/src/platform_windows.c @@ -174,7 +174,7 @@ PLATFORM_MEMORY_FREE(windows_memory_free) internal PLATFORM_READ_ENTIRE_FILE(windows_read_entire_file) { FILE *handle = fopen(file_path, "rb"); - char *buffer = NULL; + u8 *buffer = NULL; if (handle) { @@ -184,9 +184,9 @@ internal PLATFORM_READ_ENTIRE_FILE(windows_read_entire_file) rewind(handle); // TODO: replace malloc with own allocator so I stop having nightmares - buffer = (char*) malloc(sizeof(char) * (num_bytes_in_file + 1) ); + buffer = (u8*) malloc(sizeof(u8) * (num_bytes_in_file + 1) ); - u32 bytes_read = fread(buffer, sizeof(char), num_bytes_in_file, handle); + u32 bytes_read = fread(buffer, sizeof(u8), num_bytes_in_file, handle); // IMPORTANT! fread() doesn't add the '\0' buffer[num_bytes_in_file] = '\0'; diff --git a/src/render.c b/src/render.c @@ -69,7 +69,6 @@ internal void renderer_init(struct RendererState *renderer, struct StackAllocato u32 g = xor_value << 8; u32 b = xor_value; test_texture[y][x] = r | g | b; - printf("%X\n", test_texture[y][x]); } }