Added option to specify if config file is to be loaded from install or user directory, fixed input bug

dev
shariq 8 years ago
parent 363b42758f
commit 18304569f6
  1. 4
      orgfile.org
  2. 16
      src/config_vars.c
  3. 6
      src/config_vars.h
  4. 8
      src/editor.c
  5. 13
      src/game.c
  6. 17
      src/input.c
  7. 4
      src/main.c

@ -207,7 +207,8 @@ x Font atlas proper cleanup
** TODO Allow passsing base path as commandline argument? ** 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 Remove components and switch to "Fat Entities" i.e. one entity struct contains all combinations
** TODO Use variants for material params ** 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? ** DONE Show SDL dialogbox if we cannot launch at all?
- State "DONE" from "TODO" [2017-05-26 Fri 00:41] - State "DONE" from "TODO" [2017-05-26 Fri 00:41]
** DONE Writing back to config file ** DONE Writing back to config file
@ -232,6 +233,7 @@ x Font atlas proper cleanup
** TODO Ingame console and console commands etc ** 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 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 Better handling of wav format checking at load time
** TODO Fix frustum culling bugs
** DONE Array-based Hashmaps ** DONE Array-based Hashmaps
- State "DONE" from "TODO" [2017-05-07 Sun 18:42] - State "DONE" from "TODO" [2017-05-07 Sun 18:42]
** TODO Sprite sheet animations ** TODO Sprite sheet animations

@ -41,10 +41,10 @@ struct Hashmap* config_vars_get(void)
return cvars; return cvars;
} }
int config_vars_load(const char* filename) bool config_vars_load(const char* filename, int directory_type)
{ {
int success = 0; bool success = false;
FILE* config_file = io_file_open(DT_USER, filename, "r"); FILE* config_file = io_file_open(directory_type, filename, "r");
if(!config_file) if(!config_file)
{ {
log_error("config:vars_load", "Could not open %s", filename); 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); variant_from_str(value, value_str, value->type);
} }
success = 1; success = true;
fclose(config_file); fclose(config_file);
return success; return success;
} }
int config_vars_save(const char* filename) bool config_vars_save(const char* filename, int directory_type)
{ {
int success = 0; bool success = false;
FILE* config_file = io_file_open(DT_USER, filename, "w"); FILE* config_file = io_file_open(directory_type, filename, "w");
if(!config_file) if(!config_file)
{ {
log_error("config:vars_save", "Failed to open config file %s for writing"); 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); fprintf(config_file, "%s: %s\n", key, variant_str);
} }
log_message("Config file %s written.", filename); log_message("Config file %s written.", filename);
success = 1; success = true;
fclose(config_file); fclose(config_file);
return success; return success;
} }

@ -1,12 +1,14 @@
#ifndef CONFIG_VARS_H #ifndef CONFIG_VARS_H
#define CONFIG_VARS_H #define CONFIG_VARS_H
#include "num_types.h"
struct Hashmap; struct Hashmap;
void config_vars_init(void); void config_vars_init(void);
void config_vars_cleanup(void); void config_vars_cleanup(void);
int config_vars_load(const char* filename); bool config_vars_load(const char* filename, int directory_type);
int config_vars_save(const char* filename); bool config_vars_save(const char* filename, int directory_types);
struct Hashmap* config_vars_get(void); struct Hashmap* config_vars_get(void);

@ -16,6 +16,8 @@
#include "gui.h" #include "gui.h"
#include "array.h" #include "array.h"
#include "variant.h" #include "variant.h"
#include "num_types.h"
#include "file_io.h"
#include "config_vars.h" #include "config_vars.h"
#include "string_utils.h" #include "string_utils.h"
@ -26,7 +28,7 @@
struct Editor_State struct Editor_State
{ {
int enabled; bool enabled;
int renderer_settings_window; int renderer_settings_window;
int debug_vars_window; int debug_vars_window;
int top_panel_height; int top_panel_height;
@ -46,7 +48,7 @@ static void editor_color_combo(struct nk_context* context, vec4* color, int widt
void editor_init(void) void editor_init(void)
{ {
editor_state.enabled = 1; editor_state.enabled = true;
editor_state.renderer_settings_window = 0; editor_state.renderer_settings_window = 0;
editor_state.debug_vars_window = 1; editor_state.debug_vars_window = 1;
editor_state.top_panel_height = 30; editor_state.top_panel_height = 30;
@ -166,7 +168,7 @@ void editor_update(float dt)
if(nk_button_label(context, "Debug Variables")) if(nk_button_label(context, "Debug Variables"))
editor_state.debug_vars_window = !editor_state.debug_vars_window; editor_state.debug_vars_window = !editor_state.debug_vars_window;
if(nk_button_label(context, "Save config")) if(nk_button_label(context, "Save config"))
config_vars_save("config.cfg"); config_vars_save("config.cfg", DT_USER);
nk_spacing(context, 1); nk_spacing(context, 1);
nk_labelf(context, NK_TEXT_ALIGN_RIGHT | NK_TEXT_ALIGN_MIDDLE, "FPS : %.d", fps); nk_labelf(context, NK_TEXT_ALIGN_RIGHT | NK_TEXT_ALIGN_MIDDLE, "FPS : %.d", fps);
} }

@ -120,7 +120,7 @@ void scene_setup(void)
sound_source_play(sound_ent); sound_source_play(sound_ent);
int parent_node = new_ent->id; int parent_node = new_ent->id;
int num_suz = 20; int num_suz = 200;
srand(time(NULL)); srand(time(NULL));
for(int i = 0; i < num_suz; i++) for(int i = 0; i < num_suz; i++)
{ {
@ -128,14 +128,14 @@ void scene_setup(void)
int y = rand() % num_suz; int y = rand() % num_suz;
int z = rand() % num_suz; int z = rand() % num_suz;
x++; y++; z++; 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); //struct Entity* suz = scene_add_new("Suzanne", ET_STATIC_MESH);
suz->renderable = true; suz->renderable = true;
model_create(suz, "suzanne.pamesh", "Blinn_Phong"); model_create(suz, "suzanne.pamesh", "Blinn_Phong");
model_set_material_param(suz, "diffuse_color", &color); model_set_material_param(suz, "diffuse_color", &color);
float spec_str = 80.f; float spec_str = 80.f;
model_set_material_param(suz, "specular_strength", &spec_str); 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); transform_translate(suz, &s_pos, TS_WORLD);
} }
@ -148,8 +148,8 @@ void scene_setup(void)
model_set_material_param(ground, "diffuse_texture", &white_tex); model_set_material_param(ground, "diffuse_texture", &white_tex);
float spec_str = 80.f; float spec_str = 80.f;
model_set_material_param(ground, "specular_strength", &spec_str); model_set_material_param(ground, "specular_strength", &spec_str);
vec3 pos = {0, -15, 0}; vec3 pos = {0, -5, 0};
vec3 scale_ground = {100.f, 2.f, 100.f}; vec3 scale_ground = {400.f, 2.f, 400.f};
transform_set_position(ground, &pos); transform_set_position(ground, &pos);
transform_scale(ground, &scale_ground); transform_scale(ground, &scale_ground);
@ -181,6 +181,7 @@ void scene_setup(void)
light_ent->light.intensity = 1.f; light_ent->light.intensity = 1.f;
} }
log_message("Sizeof Entity : %d", sizeof(struct Entity));
/* struct Entity* sun = scene_add_new("Sun", NULL); */ /* struct Entity* sun = scene_add_new("Sun", NULL); */
/* struct Light* sun_light = entity_component_add(sun, C_LIGHT, LT_DIR); */ /* struct Light* sun_light = entity_component_add(sun, C_LIGHT, LT_DIR); */
/* sun_light->intensity = 0.8f; */ /* sun_light->intensity = 0.8f; */

@ -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) 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; int mods = KMD_NONE;
if(mod_ctrl) mods |= KMD_CTRL; if(mod_ctrl) mods |= KMD_CTRL;
if(mod_shift) mods |= KMD_SHIFT; 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]; struct Input_Map* map = &input_map_list[i];
for(int j = 0; j < array_len(map->keys); j++) for(int j = 0; j < array_len(map->keys); j++)
{ {
if(map->state == KS_PRESSED && /* if(map->state == KS_PRESSED && */
state == KS_RELEASED && /* state == KS_RELEASED && */
((map->keys[j].mods & mods) == map->keys[j].mods)) /* ((map->keys[j].mods & mods) == map->keys[j].mods)) */
{ /* { */
map->state = state; /* map->state = state; */
} /* } */
if(map->keys[j].key == key && ((map->keys[j].mods & mods) == map->keys[j].mods)) if(map->keys[j].key == key && ((map->keys[j].mods & mods) == map->keys[j].mods))
{ {
map->state = state; map->state = state;

@ -50,10 +50,10 @@ int init(void)
io_file_init(install_path, user_path); io_file_init(install_path, user_path);
free(install_path); free(install_path);
free(user_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"); 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(); struct Hashmap* cvars = config_vars_get();

Loading…
Cancel
Save