diff --git a/assets/config.cfg b/assets/config.cfg index 64608fa..472d78c 100644 --- a/assets/config.cfg +++ b/assets/config.cfg @@ -1,18 +1,13 @@ -# This is a comment -render_width: 800 +msaa_levels: 4 +debug_draw_color: 0.000, 1.000, 0.000, 1.000 +render_width: 800 +fog_density: 0.0020 render_height: 600 -#fog_mode : 0 = off, 1 = linear, 2 = exponential, 3 = exponential squared fog_mode: 2 -fog_color: 0.5 0.2 0.2 -fog_density: 0.002 -fog_start_dist: 20 -fog_max_dist: 150 -# There can be comments or empty newlines in between unlike entity definitions - -ambient_light: 0.1 0.1 0.12 +fog_color: 0.500, 0.200, 0.200 +fog_max_dist: 150.0000 msaa_enabled: true -msaa_levels: 4 - +fog_start_dist: 20.0000 debug_draw_enabled: false debug_draw_mode: 0 -debug_draw_color: 0 1 0 1 \ No newline at end of file +ambient_light: 0.100, 0.100, 0.120 diff --git a/orgfile.org b/orgfile.org index af380f1..079a29e 100644 --- a/orgfile.org +++ b/orgfile.org @@ -140,7 +140,8 @@ x Font atlas proper cleanup - Custom rendering for gui ** TODO Allow passsing base path as commandline argument? ** TODO Show SDL dialogbox if we cannot launch at all? -** TODO Writing back to config file + maybe with comments intact? +** DONE Writing back to config file +- State "DONE" from "TODO" [2017-05-08 Mon 00:57] ** DONE Reading from config file - State "DONE" from "TODO" [2017-05-07 Sun 23:52] ** DONE Variant -> String conversion procedure. Use in editor for debug var slots @@ -166,6 +167,7 @@ x Font atlas proper cleanup ** TODO Sprite sheet animations ** TODO Replace orgfile with simple text readme and reduce duplication? ** TODO Ray picking +** TODO Remove reduntant "settings" structures and move all configuration stuff to config variables ** TODO Shadow maps ** TODO Log output to file on every run ** TODO Print processor stats and machine capabilites RAM etc on every run to log. @@ -175,7 +177,7 @@ x Font atlas proper cleanup - Makefile additions. Try to compile game as a dynamically loaded library with ability to reload on recompile - Separation between game and engine base - Game .so with init, update and cleanup functions -- Configuration files and "cvars" load/reload +x Configuration files and "cvars" load/reload - Keybindings in config - Log output on every run. ** TODO Do input maps really need to be queried by their string names? diff --git a/src/config_vars.c b/src/config_vars.c index aede75e..d5d2dd1 100644 --- a/src/config_vars.c +++ b/src/config_vars.c @@ -81,28 +81,13 @@ int config_vars_load(const char* filename) key_str[key_str_len] = '\0'; value_str++; /* Ignore the colon(:) */ - //char* key = NULL; struct Variant* value = hashmap_value_get(cvars, key_str); if(!value) { log_warning("Unknown value in config file %s, line %d", filename, current_line); continue; } - variant_from_str(value, value_str, value->type); - /* HASHMAP_FOREACH(cvars, key, value) */ - /* { */ - /* if(strncmp(line_buffer, key, strlen(key)) == 0) */ - /* { */ - /* char* value_str = strstr(line_buffer, ":"); */ - /* if(value_str) */ - /* { */ - /* value_str++; */ - /* variant_from_str(value, value_str, value->type); */ - /* } */ - /* break; */ - /* } */ - /* } */ } success = 1; @@ -110,7 +95,28 @@ int config_vars_load(const char* filename) return success; } -void config_vars_save(const char* filename) +int config_vars_save(const char* filename) { - + int success = 0; + FILE* config_file = io_file_open(filename, "w"); + if(!config_file) + { + log_error("config:vars_save", "Failed to open config file %s for writing"); + return success; + } + + char* key = NULL; + struct Variant* value = NULL; + char variant_str[MAX_VARIANT_STR_LEN]; + HASHMAP_FOREACH(cvars, key, value) + { + memset(variant_str, '\0', MAX_VARIANT_STR_LEN); + variant_to_str(value, variant_str, MAX_VARIANT_STR_LEN); + log_message("Writing : %s: %s", key, variant_str); + fprintf(config_file, "%s: %s\n", key, variant_str); + } + log_message("Config file %s written.", filename); + success = 1; + fclose(config_file); + return success; } diff --git a/src/config_vars.h b/src/config_vars.h index 5c64575..8cb5ded 100644 --- a/src/config_vars.h +++ b/src/config_vars.h @@ -6,7 +6,7 @@ struct Hashmap; void config_vars_init(void); void config_vars_cleanup(void); int config_vars_load(const char* filename); -void config_vars_save(const char* filename); +int config_vars_save(const char* filename); struct Hashmap* config_vars_get(void); diff --git a/src/editor.c b/src/editor.c index 980bc35..a3d9417 100644 --- a/src/editor.c +++ b/src/editor.c @@ -16,6 +16,7 @@ #include "gui.h" #include "array.h" #include "variant.h" +#include "config_vars.h" #include "string_utils.h" #include @@ -147,7 +148,7 @@ void editor_update(float dt) if(nk_begin(context, "Top_Panel", nk_recti(0, 0, win_width, win_height - (win_height - editor_state.top_panel_height)), NK_WINDOW_BORDER | NK_WINDOW_NO_SCROLLBAR)) { - float ratios[] = {0.1f, 0.1f, 0.7f, 0.1f}; + float ratios[] = {0.1f, 0.1f, 0.1f, 0.6f, 0.1f}; static int frames = 0; static int fps = 0; static float seconds = 0.f; @@ -159,11 +160,13 @@ void editor_update(float dt) seconds = 0.f; frames = 0; } - nk_layout_row(context, NK_DYNAMIC, 22, 4, ratios); + nk_layout_row(context, NK_DYNAMIC, 22, sizeof(ratios), ratios); if(nk_button_label(context, "Render Settings")) editor_state.renderer_settings_window = !editor_state.renderer_settings_window; 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"); nk_spacing(context, 1); nk_labelf(context, NK_TEXT_ALIGN_RIGHT | NK_TEXT_ALIGN_MIDDLE, "FPS : %.d", fps); }