From 18304569f6495fd13de4e216408e79f575df1b20 Mon Sep 17 00:00:00 2001 From: shariq Date: Wed, 31 May 2017 22:15:02 +0500 Subject: [PATCH] Added option to specify if config file is to be loaded from install or user directory, fixed input bug --- orgfile.org | 4 +++- src/config_vars.c | 16 ++++++++-------- src/config_vars.h | 6 ++++-- src/editor.c | 14 ++++++++------ src/game.c | 13 +++++++------ src/input.c | 17 ++++++----------- src/main.c | 4 ++-- 7 files changed, 38 insertions(+), 36 deletions(-) diff --git a/orgfile.org b/orgfile.org index df12902..8f6b64f 100644 --- a/orgfile.org +++ b/orgfile.org @@ -207,7 +207,8 @@ x Font atlas proper cleanup ** TODO Allow passsing base path as commandline argument? ** TODO Remove components and switch to "Fat Entities" i.e. one entity struct contains all combinations ** TODO Use variants for material params -** TODO In second refactor pass, use entities everywhere, no need to pass in transform and model separately for example since they're both part of the same entity anyway +** DONE In second refactor pass, use entities everywhere, no need to pass in transform and model separately for example since they're both part of the same entity anyway +- State "DONE" from "TODO" [2017-05-31 Wed 21:44] ** DONE Show SDL dialogbox if we cannot launch at all? - State "DONE" from "TODO" [2017-05-26 Fri 00:41] ** DONE Writing back to config file @@ -232,6 +233,7 @@ x Font atlas proper cleanup ** TODO Ingame console and console commands etc ** TODO Allow binding/unbinding input maps to functions at runtime, for example if input map "Recompute" is triggered, it would call some function that can recompute bounding spheres. ** TODO Better handling of wav format checking at load time +** TODO Fix frustum culling bugs ** DONE Array-based Hashmaps - State "DONE" from "TODO" [2017-05-07 Sun 18:42] ** TODO Sprite sheet animations diff --git a/src/config_vars.c b/src/config_vars.c index 00b7482..d753c56 100644 --- a/src/config_vars.c +++ b/src/config_vars.c @@ -41,10 +41,10 @@ struct Hashmap* config_vars_get(void) return cvars; } -int config_vars_load(const char* filename) +bool config_vars_load(const char* filename, int directory_type) { - int success = 0; - FILE* config_file = io_file_open(DT_USER, filename, "r"); + bool success = false; + FILE* config_file = io_file_open(directory_type, filename, "r"); if(!config_file) { log_error("config:vars_load", "Could not open %s", filename); @@ -89,15 +89,15 @@ int config_vars_load(const char* filename) variant_from_str(value, value_str, value->type); } - success = 1; + success = true; fclose(config_file); return success; } -int config_vars_save(const char* filename) +bool config_vars_save(const char* filename, int directory_type) { - int success = 0; - FILE* config_file = io_file_open(DT_USER, filename, "w"); + bool success = false; + FILE* config_file = io_file_open(directory_type, filename, "w"); if(!config_file) { log_error("config:vars_save", "Failed to open config file %s for writing"); @@ -114,7 +114,7 @@ int config_vars_save(const char* filename) fprintf(config_file, "%s: %s\n", key, variant_str); } log_message("Config file %s written.", filename); - success = 1; + success = true; fclose(config_file); return success; } diff --git a/src/config_vars.h b/src/config_vars.h index 8cb5ded..7b89c62 100644 --- a/src/config_vars.h +++ b/src/config_vars.h @@ -1,12 +1,14 @@ #ifndef CONFIG_VARS_H #define CONFIG_VARS_H +#include "num_types.h" + struct Hashmap; void config_vars_init(void); void config_vars_cleanup(void); -int config_vars_load(const char* filename); -int config_vars_save(const char* filename); +bool config_vars_load(const char* filename, int directory_type); +bool config_vars_save(const char* filename, int directory_types); struct Hashmap* config_vars_get(void); diff --git a/src/editor.c b/src/editor.c index d9daf4a..cb25be3 100644 --- a/src/editor.c +++ b/src/editor.c @@ -16,6 +16,8 @@ #include "gui.h" #include "array.h" #include "variant.h" +#include "num_types.h" +#include "file_io.h" #include "config_vars.h" #include "string_utils.h" @@ -26,10 +28,10 @@ struct Editor_State { - int enabled; - int renderer_settings_window; - int debug_vars_window; - int top_panel_height; + bool enabled; + int renderer_settings_window; + int debug_vars_window; + int top_panel_height; }; struct Debug_Variable @@ -46,7 +48,7 @@ static void editor_color_combo(struct nk_context* context, vec4* color, int widt void editor_init(void) { - editor_state.enabled = 1; + editor_state.enabled = true; editor_state.renderer_settings_window = 0; editor_state.debug_vars_window = 1; editor_state.top_panel_height = 30; @@ -166,7 +168,7 @@ void editor_update(float dt) if(nk_button_label(context, "Debug Variables")) editor_state.debug_vars_window = !editor_state.debug_vars_window; if(nk_button_label(context, "Save config")) - config_vars_save("config.cfg"); + config_vars_save("config.cfg", DT_USER); nk_spacing(context, 1); nk_labelf(context, NK_TEXT_ALIGN_RIGHT | NK_TEXT_ALIGN_MIDDLE, "FPS : %.d", fps); } diff --git a/src/game.c b/src/game.c index 1970ea6..d8488d1 100644 --- a/src/game.c +++ b/src/game.c @@ -120,7 +120,7 @@ void scene_setup(void) sound_source_play(sound_ent); int parent_node = new_ent->id; - int num_suz = 20; + int num_suz = 200; srand(time(NULL)); for(int i = 0; i < num_suz; i++) { @@ -128,14 +128,14 @@ 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_new("Suzanne", ET_STATIC_MESH); + 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; model_create(suz, "suzanne.pamesh", "Blinn_Phong"); model_set_material_param(suz, "diffuse_color", &color); float spec_str = 80.f; model_set_material_param(suz, "specular_strength", &spec_str); - vec3 s_pos = {x, 5, z}; + vec3 s_pos = {x, 0, z}; transform_translate(suz, &s_pos, TS_WORLD); } @@ -148,8 +148,8 @@ void scene_setup(void) model_set_material_param(ground, "diffuse_texture", &white_tex); float spec_str = 80.f; model_set_material_param(ground, "specular_strength", &spec_str); - vec3 pos = {0, -15, 0}; - vec3 scale_ground = {100.f, 2.f, 100.f}; + vec3 pos = {0, -5, 0}; + vec3 scale_ground = {400.f, 2.f, 400.f}; transform_set_position(ground, &pos); transform_scale(ground, &scale_ground); @@ -181,6 +181,7 @@ void scene_setup(void) light_ent->light.intensity = 1.f; } + log_message("Sizeof Entity : %d", sizeof(struct Entity)); /* struct Entity* sun = scene_add_new("Sun", NULL); */ /* struct Light* sun_light = entity_component_add(sun, C_LIGHT, LT_DIR); */ /* sun_light->intensity = 0.8f; */ diff --git a/src/input.c b/src/input.c index 8441169..9a7d86c 100644 --- a/src/input.c +++ b/src/input.c @@ -264,11 +264,6 @@ void input_mouse_pos_set(int xpos, int ypos) void input_on_key(int key, int scancode, int state, int repeat, int mod_ctrl, int mod_shift, int mod_alt) { - /* if(repeat) */ - /* { */ - /* return; /\* Ignore key repeat *\/ */ - /* } */ - int mods = KMD_NONE; if(mod_ctrl) mods |= KMD_CTRL; if(mod_shift) mods |= KMD_SHIFT; @@ -278,12 +273,12 @@ void input_on_key(int key, int scancode, int state, int repeat, int mod_ctrl, in struct Input_Map* map = &input_map_list[i]; for(int j = 0; j < array_len(map->keys); j++) { - if(map->state == KS_PRESSED && - state == KS_RELEASED && - ((map->keys[j].mods & mods) == map->keys[j].mods)) - { - map->state = state; - } + /* if(map->state == KS_PRESSED && */ + /* state == KS_RELEASED && */ + /* ((map->keys[j].mods & mods) == map->keys[j].mods)) */ + /* { */ + /* map->state = state; */ + /* } */ if(map->keys[j].key == key && ((map->keys[j].mods & mods) == map->keys[j].mods)) { map->state = state; diff --git a/src/main.c b/src/main.c index 79f8ac9..5565238 100644 --- a/src/main.c +++ b/src/main.c @@ -50,10 +50,10 @@ int init(void) io_file_init(install_path, user_path); free(install_path); free(user_path); - if(!config_vars_load("config.cfg")) + if(!config_vars_load("config.cfg", DT_USER)) { log_error("main:init", "Could not load config, reverting to defaults"); - config_vars_save("config.cfg"); + config_vars_save("config.cfg", DT_USER); } struct Hashmap* cvars = config_vars_get();