diff --git a/build/win_mingw64/makefile b/build/win_mingw64/makefile index 9ea60d2..58310e8 100644 --- a/build/win_mingw64/makefile +++ b/build/win_mingw64/makefile @@ -6,7 +6,7 @@ PROJECT_DIST_NAME = $(patsubst %.exe,%, $(PROJECT_NAME)) BUILD_TYPE = release SRCS = $(patsubst $(SRC_DIR)/%.c, %.c, $(wildcard ../../src/*.c)) OBJS_RELEASE = $(patsubst %.c,.release/%.o,$(SRCS)) -CFLAGS = -Wall -I$(INCLUDE_DIR) -DUSE_GLAD -std=c99 +CFLAGS = -Wall -I$(INCLUDE_DIR) -DUSE_GLAD -std=c99 -DCOLOURED_STDOUT CFLAGS_RELEASE = -O3 -ffast-math LFLAGS = $(shell mingw64-pkg-config --libs --static sdl2 openal) LIB_BINARY_DIR = $(patsubst -L%/lib,%/bin, $(shell mingw64-pkg-config --libs-only-L sdl2)) diff --git a/orgfile.org b/orgfile.org index 88a052b..df12902 100644 --- a/orgfile.org +++ b/orgfile.org @@ -262,6 +262,7 @@ x Log output on every run. ** TODO Add default keybindings ** TODO Write default config/keybindings etc to file if none are found in preferences dir ** TODO Fix input map bugs +** TODO Wrap malloc and free calls in custom functions to track usage ** TODO Flatpak packaging for linux releases ** TODO Use hashmap for debugvar slots in editor ** TODO Use hashmap to store input maps diff --git a/src/game.c b/src/game.c index 7adbff9..2acb4b3 100644 --- a/src/game.c +++ b/src/game.c @@ -110,6 +110,7 @@ void scene_setup(void) vec3 position = {0, 0, -5}; transform_translate(tran, &position, TS_WORLD); struct Model* box_model = &new_ent->model; + new_ent->renderable = true; model_create(box_model, new_ent->id, "default.pamesh", "Blinn_Phong"); model_set_material_param(box_model, "diffuse_color", &color); int tex = texture_create_from_file("white.tga", TU_DIFFUSE); @@ -130,7 +131,7 @@ void scene_setup(void) } int parent_node = new_ent->id; - int num_suz = 2; + int num_suz = 20; srand(time(NULL)); for(int i = 0; i < num_suz; i++) { @@ -138,7 +139,9 @@ void scene_setup(void) int y = rand() % num_suz; int z = rand() % num_suz; x++; y++; z++; - struct Entity* suz = scene_add_as_child("Suzanne", ET_STATIC_MESH, parent_node); + //struct Entity* suz = scene_add_as_child("Suzanne", ET_STATIC_MESH, parent_node); + struct Entity* suz = scene_add_new("Suzanne", ET_STATIC_MESH); + suz->renderable = true; struct Model* suz_model = &suz->model; model_create(suz_model, suz->id, "suzanne.pamesh", "Blinn_Phong"); model_set_material_param(suz_model, "diffuse_color", &color); @@ -150,15 +153,16 @@ void scene_setup(void) struct Entity* ground = scene_add_new("Ground", ET_STATIC_MESH); + ground->renderable = true; struct Model* ground_model = &ground->model; - model_create(ground_model, ground->id, "plane.pamesh", "Blinn_Phong"); + model_create(ground_model, ground->id, "default.pamesh", "Blinn_Phong"); model_set_material_param(ground_model, "diffuse_color", &color); int white_tex = texture_create_from_file("white.tga", TU_DIFFUSE); model_set_material_param(ground_model, "diffuse_texture", &white_tex); float spec_str = 80.f; model_set_material_param(ground_model, "specular_strength", &spec_str); vec3 pos = {0, -15, 0}; - vec3 scale_ground = {200.f, 1.f, 200.f}; + vec3 scale_ground = {100.f, 2.f, 100.f}; transform_set_position(&ground->transform, &pos); transform_scale(&ground->transform, &scale_ground); diff --git a/src/input.c b/src/input.c index bbc0a6b..8441169 100644 --- a/src/input.c +++ b/src/input.c @@ -32,8 +32,19 @@ void input_init(void) platform_mousewheel_callback_set(&input_on_mousewheel); input_map_list = array_new(struct Input_Map); - if(!input_keybinds_load("keybindings.cfg")) + if(!input_keybinds_load("keybindings.cfg", DT_USER)) + { log_error("input:init", "Failed to load keybindings"); + log_message("Reverting to default keybindings"); + if(!input_keybinds_load("keybindings.cfg", DT_INSTALL)) + { + log_error("input:init", "Failed to load default keybindings"); + } + else + { + input_keybinds_save("keybindings.cfg"); + } + } /* struct Key_Combination forward_keys[2] = {{KEY_W, KMD_NONE}, {KEY_UP, KMD_ALT | KMD_SHIFT}}; */ /* struct Key_Combination backward_keys[2] = {{KEY_S, KMD_NONE}, {KEY_DOWN, KMD_NONE}}; */ @@ -80,12 +91,12 @@ void input_cleanup(void) array_free(input_map_list); } -int input_keybinds_load(const char* filename) +bool input_keybinds_load(const char* filename, int directory_type) { - int success = 0; + bool success = false; const int MAX_KEYBIND_LEN = 128; const int MAX_LINE_LEN = 512; - FILE* config_file = io_file_open(DT_USER, filename, "r"); + FILE* config_file = io_file_open(directory_type, filename, "r"); if(!config_file) { log_error("input:keybinds_load", "Could not open %s", filename); @@ -190,14 +201,14 @@ int input_keybinds_load(const char* filename) } } - success = 1; + success = true; fclose(config_file); return success; } -int input_keybinds_save(const char* filename) +bool input_keybinds_save(const char* filename) { - int success = 0; + bool success = false; FILE* config_file = io_file_open(DT_USER, filename, "w"); if(!config_file) @@ -224,7 +235,7 @@ int input_keybinds_save(const char* filename) fclose(config_file); log_message("Keybindings saved to %s", filename); - success = 1; + success = true; return success; } @@ -298,7 +309,7 @@ void input_mouse_mode_set(enum Mouse_Mode mode) platform_mouse_relative_mode_set(mode == MM_NORMAL ? 0 : 1); } -int input_map_state_get(const char* map_name, int state) +bool input_map_state_get(const char* map_name, int state) { int current_state = KS_INACTIVE; for(int i = 0; i < array_len(input_map_list); i++) @@ -311,23 +322,23 @@ int input_map_state_get(const char* map_name, int state) } } - int result = 0; + bool result = false; if(current_state == state) { - result = 1; + result = true; } return result; } -int input_is_key_pressed(int key) +bool input_is_key_pressed(int key) { return platform_is_key_pressed(key); } -int input_mousebutton_state_get(uint button, int state_type) +bool input_mousebutton_state_get(uint button, int state_type) { int current_state = platform_mousebutton_state_get(button); - return state_type == current_state ? 1 : 0; + return state_type == current_state ? true : false; } void input_map_create(const char* name, struct Key_Combination* keys, int num_keys) @@ -350,7 +361,7 @@ void input_map_create(const char* name, struct Key_Combination* keys, int num_ke new_map->name = str_new(name); new_map->keys = array_new_cap(struct Key_Combination, num_keys); new_map->state = KS_INACTIVE; - for(size_t i = 0; i < num_keys; i++) + for(int i = 0; i < num_keys; i++) new_map->keys[i] = keys[i]; log_message("Created Input Map : %s", name); } @@ -366,25 +377,25 @@ void input_update(void) } } -int input_map_remove(const char* name) +bool input_map_remove(const char* name) { assert(name); - int success = 0; + bool success = false; int index = map_find(name); if(index > -1) { array_remove_at(input_map_list, (int)index); - success = 1; + success = true; } if(!success) log_error("input:map_remove", "Map %s not found", name); return success; } -int input_map_keys_set(const char* name, struct Key_Combination* keys, int num_keys) +bool input_map_keys_set(const char* name, struct Key_Combination* keys, int num_keys) { assert(name && keys && num_keys > 0); - int success = 0; + bool success = false; int index = map_find(name); if(index > -1) { @@ -395,23 +406,23 @@ int input_map_keys_set(const char* name, struct Key_Combination* keys, int num_k map->keys[i] = keys[i]; map->state = KS_INACTIVE; - success = 1; + success = true; } if(!success) log_error("input:map_keys_set", "Map %s not found", name); return success; } -int input_map_name_set(const char* name, const char* new_name) +bool input_map_name_set(const char* name, const char* new_name) { assert(name && new_name); - int success = 0; + bool success = false; int index = map_find(name); if(index > -1) { struct Input_Map* map = &input_map_list[index]; map->name = str_new(new_name); - success = 1; + success = true; } if(!success) log_error("input:map_name_set", "Map %s not found", name); return success; diff --git a/src/input.h b/src/input.h index bca3aec..0f63e7f 100644 --- a/src/input.h +++ b/src/input.h @@ -1,5 +1,5 @@ -#ifndef input_H -#define input_H +#ifndef INPUT_H +#define INPUT_H #include #include "num_types.h" @@ -410,21 +410,21 @@ enum Keyboard_Scancode }; void input_init(void); -int input_keybinds_load(const char* filename); -int input_keybinds_save(const char* filename); +bool input_keybinds_load(const char* filename, int directory_type); +bool input_keybinds_save(const char* filename); void input_cleanup(void); -int input_mousebutton_state_get(uint button, int state_type); -int input_is_key_pressed(int key); +bool input_mousebutton_state_get(uint button, int state_type); +bool input_is_key_pressed(int key); void input_mouse_pos_get(int* xpos, int* ypos); void input_mouse_delta_get(int* xpos, int* ypos); // Use with relative mouse mode void input_mouse_pos_set(int xpos, int ypos); void input_mouse_mode_set(enum Mouse_Mode mode); int input_mouse_mode_get(void); void input_update(void); -int input_map_state_get(const char* map_name, int state); +bool input_map_state_get(const char* map_name, int state); void input_map_create(const char* name, struct Key_Combination* keys, int num_keys); -int input_map_keys_set(const char* name, struct Key_Combination* keys, int num_keys); -int input_map_remove(const char* name); -int input_map_name_set(const char* name, const char* new_name); +bool input_map_keys_set(const char* name, struct Key_Combination* keys, int num_keys); +bool input_map_remove(const char* name); +bool input_map_name_set(const char* name, const char* new_name); #endif diff --git a/src/log.c b/src/log.c index a0c5ee7..80151a5 100644 --- a/src/log.c +++ b/src/log.c @@ -7,6 +7,10 @@ #include "platform.h" #ifdef __linux__ +#define COLOURED_STDOUT +#endif + +#ifdef COLOURED_STDOUT #define COL_RED "\e[31m" #define COL_GREEN "\e[32m"