Added reading configuration from config_vars and config.cfg located at root folder of assets

dev
shariq 8 years ago
parent e38cc2ec36
commit c81d3f9d12
  1. 18
      assets/config.cfg
  2. 1
      build/linux/makefile
  3. 21
      orgfile.org
  4. 83
      src/config_vars.c
  5. 37
      src/game.c
  6. 36
      src/hashmap.c
  7. 9
      src/hashmap.h
  8. 1
      src/input.c
  9. 21
      src/main.c
  10. 13
      src/platform.c
  11. 2
      src/platform.h
  12. 24
      src/renderer.c
  13. 28
      src/variant.c
  14. 4
      src/variant.h

@ -0,0 +1,18 @@
# This is a comment
render_width: 800
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
msaa_enabled: true
msaa_levels: 4
debug_draw_enabled: false
debug_draw_mode: 0
debug_draw_color: 0 1 0 1

@ -56,6 +56,7 @@ dist: release
-@echo './Symmetry' >> $(DIST_DIR)/$(PROJECT_NAME)/Launch.sh -@echo './Symmetry' >> $(DIST_DIR)/$(PROJECT_NAME)/Launch.sh
-@chmod +x $(DIST_DIR)/$(PROJECT_NAME)/Launch.sh -@chmod +x $(DIST_DIR)/$(PROJECT_NAME)/Launch.sh
-@cp $(PROJECT_NAME) $(DIST_DIR)/$(PROJECT_NAME) -@cp $(PROJECT_NAME) $(DIST_DIR)/$(PROJECT_NAME)
-@chmod +x $(DIST_DIR)/$(PROJECT_NAME)/$(PROJECT_NAME)
-@echo DONE creating distribution -@echo DONE creating distribution
clean: clean:

@ -24,15 +24,15 @@ diffuse_texture: "checkered.tga"
specular: 0.55 specular: 0.55
*** Configuration Variables a.k.a cfg-vars *** Configuration Variables a.k.a cfg-vars
// Comment # Comment
render_width: 1024 render_width: 1024
render_height: 1024 render_height: 1024
fog_enabled: 1 debug_draw_enabled: true
fog_color: 0.5 0.2 0.2 1 fog_color: 0.5 0.2 0.2 1
// There can be comments or empty newlines in between unlike entity definitions # There can be comments or empty newlines in between unlike entity definitions
ambient_light: 0.1 0.1 0.1 1 ambient_light: 0.1 0.1 0.1 1
msaa: 1 msaa: true
msaa_levels: 8 msaa_levels: 8
*** Keybindings *** Keybindings
@ -89,7 +89,8 @@ msaa_levels: 8
- State "DONE" from "TODO" [2015-08-19 Wed 13:30] - State "DONE" from "TODO" [2015-08-19 Wed 13:30]
** TODO Bounding Boxes ** TODO Bounding Boxes
- Recalculated bounding boxes for rotated meshes? - Recalculated bounding boxes for rotated meshes?
** TODO Fix input lag and other framerate related issues ** DONE Fix input lag and other framerate related issues
- State "DONE" from "TODO" [2017-05-07 Sun 18:40]
** TODO File extension checking for asset loading ** TODO File extension checking for asset loading
** DONE Materials ** DONE Materials
- State "DONE" from "TODO" [2015-10-13 Tue 19:38] - State "DONE" from "TODO" [2015-10-13 Tue 19:38]
@ -138,7 +139,12 @@ x Font atlas proper cleanup
- Decoupled event handling of gui and input if possible - Decoupled event handling of gui and input if possible
- Custom rendering for gui - Custom rendering for gui
** TODO Allow passsing base path as commandline argument? ** TODO Allow passsing base path as commandline argument?
** TODO Variant -> String conversion procedure. Use in editor for debug var slots ** TODO Show SDL dialogbox if we cannot launch at all?
** TODO Writing back to config file + maybe with comments intact?
** 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
- State "DONE" from "TODO" [2017-05-07 Sun 18:43]
** DONE Add strings and booleans to variant types ** DONE Add strings and booleans to variant types
- State "DONE" from "TODO" [2017-03-29 Wed 00:23] - State "DONE" from "TODO" [2017-03-29 Wed 00:23]
** DONE Fix Key release not being reported ** DONE Fix Key release not being reported
@ -155,7 +161,8 @@ 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 Array-based Hashmaps ** DONE Array-based Hashmaps
- State "DONE" from "TODO" [2017-05-07 Sun 18:42]
** TODO Sprite sheet animations ** TODO Sprite sheet animations
** TODO Replace orgfile with simple text readme and reduce duplication? ** TODO Replace orgfile with simple text readme and reduce duplication?
** TODO Ray picking ** TODO Ray picking

@ -2,14 +2,33 @@
#include "string_utils.h" #include "string_utils.h"
#include "variant.h" #include "variant.h"
#include "hashmap.h" #include "hashmap.h"
#include "file_io.h"
#include "log.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#define MAX_LINE_LEN 512
static struct Hashmap* cvars = NULL; static struct Hashmap* cvars = NULL;
void config_vars_init(void) void config_vars_init(void)
{ {
cvars = hashmap_new(); cvars = hashmap_new();
/* Initialize with default values incase there is no config file */
hashmap_int_set(cvars, "render_width", 1024);
hashmap_int_set(cvars, "render_height", 768);
hashmap_int_set(cvars, "fog_mode", 0);
hashmap_vec3_setf(cvars, "fog_color", 0.5f, 0.2f, 0.2f);
hashmap_float_set(cvars, "fog_density", 0.1);
hashmap_float_set(cvars, "fog_start_dist", 10.f);
hashmap_float_set(cvars, "fog_max_dist", 50.f);
hashmap_vec3_setf(cvars, "ambient_light", 0.1f, 0.1f, 0.1f);
hashmap_bool_set(cvars, "msaa_enabled", 1);
hashmap_int_set(cvars, "msaa_levels", 4);
hashmap_bool_set(cvars, "debug_draw_enabled", 1);
hashmap_int_set(cvars, "debug_draw_mode", 0);
hashmap_vec4_setf(cvars, "debug_draw_color", 1.f, 0.f, 0.f, 1.f);
} }
void config_vars_cleanup(void) void config_vars_cleanup(void)
@ -24,7 +43,71 @@ struct Hashmap* config_vars_get(void)
int config_vars_load(const char* filename) int config_vars_load(const char* filename)
{ {
int success = 0;
FILE* config_file = io_file_open(filename, "r");
if(!config_file)
{
log_error("config:vars_load", "Could not open %s", filename);
return success;
}
/* Read line by line, ignore comments */
char key_str[HASH_MAX_KEY_LEN];
char line_buffer[MAX_LINE_LEN];
memset(key_str, '\0', HASH_MAX_KEY_LEN);
memset(line_buffer, '\0', MAX_LINE_LEN);
int current_line = 0;
while(fgets(line_buffer, MAX_LINE_LEN - 1, config_file))
{
current_line++;
line_buffer[strcspn(line_buffer, "\r\n")] = '\0';
if(line_buffer[0] == '#' || strlen(line_buffer) == 0)
continue;
log_message("Line : %s", line_buffer);
memset(key_str, '\0', HASH_MAX_KEY_LEN);
char* value_str = strstr(line_buffer, ":");
if(!value_str)
{
log_warning("Malformed value in config file %s, line %d", filename, current_line);
continue;
}
int key_str_len = value_str - line_buffer;
strncpy(key_str, line_buffer, key_str_len);
if(key_str_len >= HASH_MAX_KEY_LEN)
key_str[HASH_MAX_KEY_LEN - 1] = '\0';
else
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;
fclose(config_file);
return success;
} }
void config_vars_save(const char* filename) void config_vars_save(const char* filename)

@ -66,9 +66,6 @@ int game_init(struct Window* window)
/* TODO: Decouple systems' init/cleanup from game, they should exist and run even if there's no "game" */ /* TODO: Decouple systems' init/cleanup from game, they should exist and run even if there's no "game" */
/* Init systems */ /* Init systems */
input_init(); input_init();
char* base_path = platform_base_path_get();
io_file_init(base_path);
free(base_path);
sound_init(); sound_init();
shader_init(); shader_init();
texture_init(); texture_init();
@ -82,7 +79,6 @@ int game_init(struct Window* window)
editor_init(); editor_init();
model_init(); model_init();
entity_init(); entity_init();
config_vars_init();
scene_init(); scene_init();
/* Debug scene setup */ /* Debug scene setup */
@ -230,22 +226,22 @@ void scene_setup(void)
/* 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; */
struct Hashmap* cvars = config_vars_get(); /* struct Hashmap* cvars = config_vars_get(); */
hashmap_int_set(cvars, "My_Int", 20); /* hashmap_int_set(cvars, "My_Int", 20); */
hashmap_str_set(cvars, "My_String", "This is my string"); /* hashmap_str_set(cvars, "My_String", "This is my string"); */
hashmap_float_set(cvars, "Some_FLOAT", 42.222f); /* hashmap_float_set(cvars, "Some_FLOAT", 42.222f); */
hashmap_double_set(cvars, "Some_Double", 99.999); /* hashmap_double_set(cvars, "Some_Double", 99.999); */
hashmap_bool_set(cvars, "The_Truth", 0); /* hashmap_bool_set(cvars, "The_Truth", 0); */
char* key = NULL; /* char* key = NULL; */
struct Variant* value = NULL; /* struct Variant* value = NULL; */
char variant_str[256]; /* char variant_str[256]; */
HASHMAP_FOREACH(cvars, key, value) /* HASHMAP_FOREACH(cvars, key, value) */
{ /* { */
variant_to_str(value, variant_str, 256); /* variant_to_str(value, variant_str, 256); */
log_message("VAL :(%s) : (%s)", key, variant_str); /* log_message("VAL :(%s) : (%s)", key, variant_str); */
memset(variant_str, '\0', 256); /* memset(variant_str, '\0', 256); */
} /* } */
/* hashmap_float_set(cvars, "Some_FLOAT", 99.3f); */ /* hashmap_float_set(cvars, "Some_FLOAT", 99.3f); */
/* hashmap_debug_print(cvars); */ /* hashmap_debug_print(cvars); */
@ -1654,7 +1650,6 @@ void game_cleanup(void)
{ {
editor_cleanup(); editor_cleanup();
scene_cleanup(); scene_cleanup();
config_vars_cleanup();
entity_cleanup(); entity_cleanup();
model_cleanup(); model_cleanup();
material_cleanup(); material_cleanup();

@ -7,8 +7,6 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#define HASH_MAX_KEY_LEN 128
struct Hashmap_Entry struct Hashmap_Entry
{ {
char* key; char* key;
@ -94,14 +92,16 @@ void hashmap_value_set(struct Hashmap* hashmap, const char* key, const struct Va
variant_copy(&new_entry->value, value); variant_copy(&new_entry->value, value);
} }
const struct Variant* hashmap_value_get(const struct Hashmap* hashmap, const char* key) struct Variant* hashmap_value_get(const struct Hashmap* hashmap, const char* key)
{ {
if(!hashmap || !key) return NULL; if(!hashmap || !key) return NULL;
struct Variant* value = NULL; struct Variant* value = NULL;
unsigned int index = hashmap_generate_hash(key); unsigned int index = hashmap_generate_hash(key);
int key_len = strlen(key);
int compare_len = key_len < HASH_MAX_KEY_LEN ? key_len : HASH_MAX_KEY_LEN;
for(int i = 0; i < array_len(hashmap->buckets[index]); i++) for(int i = 0; i < array_len(hashmap->buckets[index]); i++)
{ {
if(strncmp(key, hashmap->buckets[index][i].key, HASH_MAX_KEY_LEN) == 0) if(strncmp(key, hashmap->buckets[index][i].key, compare_len) == 0)
{ {
value = &hashmap->buckets[index][i].value; value = &hashmap->buckets[index][i].value;
break; break;
@ -175,6 +175,30 @@ void hashmap_quat_set(struct Hashmap* hashmap, const char* key, const quat* valu
variant_assign_quat(&new_entry->value, value); variant_assign_quat(&new_entry->value, value);
} }
void hashmap_vec2_setf(struct Hashmap* hashmap, const char* key, const float x, const float y)
{
struct Hashmap_Entry* new_entry = hashmap_entry_new(hashmap, key);
variant_assign_vec2f(&new_entry->value, x, y);
}
void hashmap_vec3_setf(struct Hashmap* hashmap, const char* key, const float x, const float y, const float z)
{
struct Hashmap_Entry* new_entry = hashmap_entry_new(hashmap, key);
variant_assign_vec3f(&new_entry->value, x, y, z);
}
void hashmap_vec4_setf(struct Hashmap* hashmap, const char* key, const float x, const float y, const float z, const float w)
{
struct Hashmap_Entry* new_entry = hashmap_entry_new(hashmap, key);
variant_assign_vec4f(&new_entry->value, x, y, z, w);
}
void hashmap_quat_setf(struct Hashmap* hashmap, const char* key, const float x, const float y, const float z, const float w)
{
struct Hashmap_Entry* new_entry = hashmap_entry_new(hashmap, key);
variant_assign_quatf(&new_entry->value, x, y, z, w);
}
void hashmap_mat4_set(struct Hashmap* hashmap, const char* key, const mat4* value) void hashmap_mat4_set(struct Hashmap* hashmap, const char* key, const mat4* value)
{ {
struct Hashmap_Entry* new_entry = hashmap_entry_new(hashmap, key); struct Hashmap_Entry* new_entry = hashmap_entry_new(hashmap, key);
@ -211,7 +235,7 @@ double hashmap_double_get(const struct Hashmap* hashmap, const char* key)
return variant->val_double; return variant->val_double;
} }
int hashmap_get_bool(const struct Hashmap* hashmap, const char* key) int hashmap_bool_get(const struct Hashmap* hashmap, const char* key)
{ {
const struct Variant* variant = hashmap_value_get(hashmap, key); const struct Variant* variant = hashmap_value_get(hashmap, key);
return variant->val_bool; return variant->val_bool;

@ -5,6 +5,7 @@
#include "array.h" #include "array.h"
#define HASH_MAP_NUM_BUCKETS 10 #define HASH_MAP_NUM_BUCKETS 10
#define HASH_MAX_KEY_LEN 128
struct Hashmap; struct Hashmap;
struct Variant; struct Variant;
@ -13,7 +14,7 @@ struct Hashmap* hashmap_new(void);
void hashmap_free(struct Hashmap* hashmap); void hashmap_free(struct Hashmap* hashmap);
void hashmap_value_remove(struct Hashmap* hashmap, const char* key); void hashmap_value_remove(struct Hashmap* hashmap, const char* key);
void hashmap_value_set(struct Hashmap* hashmap, const char* key, const struct Variant* value); void hashmap_value_set(struct Hashmap* hashmap, const char* key, const struct Variant* value);
const struct Variant* hashmap_value_get(const struct Hashmap* hashmap, const char* key); struct Variant* hashmap_value_get(const struct Hashmap* hashmap, const char* key);
void hashmap_float_set(struct Hashmap* hashmap, const char* key, const float value); void hashmap_float_set(struct Hashmap* hashmap, const char* key, const float value);
void hashmap_int_set(struct Hashmap* hashmap, const char* key, const int value); void hashmap_int_set(struct Hashmap* hashmap, const char* key, const int value);
@ -23,6 +24,10 @@ void hashmap_vec2_set(struct Hashmap* hashmap, const char* key, const
void hashmap_vec3_set(struct Hashmap* hashmap, const char* key, const vec3* value); void hashmap_vec3_set(struct Hashmap* hashmap, const char* key, const vec3* value);
void hashmap_vec4_set(struct Hashmap* hashmap, const char* key, const vec4* value); void hashmap_vec4_set(struct Hashmap* hashmap, const char* key, const vec4* value);
void hashmap_quat_set(struct Hashmap* hashmap, const char* key, const quat* value); void hashmap_quat_set(struct Hashmap* hashmap, const char* key, const quat* value);
void hashmap_vec2_setf(struct Hashmap* hashmap, const char* key, const float x, const float y);
void hashmap_vec3_setf(struct Hashmap* hashmap, const char* key, const float x, const float y, const float z);
void hashmap_vec4_setf(struct Hashmap* hashmap, const char* key, const float x, const float y, const float z, const float w);
void hashmap_quat_setf(struct Hashmap* hashmap, const char* key, const float x, const float y, const float z, const float w);
void hashmap_mat4_set(struct Hashmap* hashmap, const char* key, const mat4* value); void hashmap_mat4_set(struct Hashmap* hashmap, const char* key, const mat4* value);
void hashmap_str_set(struct Hashmap* hashmap, const char* key, const char* value); void hashmap_str_set(struct Hashmap* hashmap, const char* key, const char* value);
void hashmap_ptr_set(struct Hashmap* hashmap, const char* key, void* value); void hashmap_ptr_set(struct Hashmap* hashmap, const char* key, void* value);
@ -30,7 +35,7 @@ void hashmap_ptr_set(struct Hashmap* hashmap, const char* key, void*
float hashmap_float_get(const struct Hashmap* hashmap, const char* key); float hashmap_float_get(const struct Hashmap* hashmap, const char* key);
int hashmap_int_get(const struct Hashmap* hashmap, const char* key); int hashmap_int_get(const struct Hashmap* hashmap, const char* key);
double hashmap_double_get(const struct Hashmap* hashmap, const char* key); double hashmap_double_get(const struct Hashmap* hashmap, const char* key);
int hashmap_get_bool(const struct Hashmap* hashmap, const char* key); int hashmap_bool_get(const struct Hashmap* hashmap, const char* key);
vec2 hashmap_vec2_get(const struct Hashmap* hashmap, const char* key); vec2 hashmap_vec2_get(const struct Hashmap* hashmap, const char* key);
vec3 hashmap_vec3_get(const struct Hashmap* hashmap, const char* key); vec3 hashmap_vec3_get(const struct Hashmap* hashmap, const char* key);
vec4 hashmap_vec4_get(const struct Hashmap* hashmap, const char* key); vec4 hashmap_vec4_get(const struct Hashmap* hashmap, const char* key);

@ -72,7 +72,6 @@ void input_on_key(int key, int scancode, int state, int repeat, int mod_ctrl, in
{ {
if(repeat) if(repeat)
{ {
log_message("Repeat ignored");
return; /* Ignore key repeat */ return; /* Ignore key repeat */
} }

@ -5,10 +5,10 @@
#include "platform.h" #include "platform.h"
#include "gl_load.h" #include "gl_load.h"
#include "game.h" #include "game.h"
#include "file_io.h"
#include "config_vars.h"
#include "hashmap.h"
const int WIN_WIDTH = 1024;
const int WIN_HEIGHT = 768;
static struct Window* window = NULL; static struct Window* window = NULL;
int init(); int init();
@ -34,6 +34,7 @@ int init(void)
} }
else else
{ {
config_vars_init();
if(platform_init()) if(platform_init())
{ {
success = gl_load_library(); success = gl_load_library();
@ -43,7 +44,18 @@ int init(void)
} }
else else
{ {
window = window_create("Symmetry", WIN_WIDTH, WIN_HEIGHT); char* base_path = platform_base_path_get();
io_file_init(base_path);
free(base_path);
if(!config_vars_load("config.cfg"))
log_error("main:init", "Could not load config, reverting to defaults");
struct Hashmap* cvars = config_vars_get();
int width = hashmap_int_get(cvars, "render_width");
int height = hashmap_int_get(cvars, "render_height");
int msaa = hashmap_bool_get(cvars, "msaa_enabled");
int msaa_levels = hashmap_int_get(cvars, "msaa_levels");
window = window_create("Symmetry", width, height, msaa, msaa_levels);
if(!window) if(!window)
{ {
log_error("main:init", "Window creation failed"); log_error("main:init", "Window creation failed");
@ -68,5 +80,6 @@ void cleanup()
{ {
game_cleanup(); game_cleanup();
platform_cleanup(); platform_cleanup();
config_vars_cleanup();
log_message("Program exiting!"); log_message("Program exiting!");
} }

@ -1,11 +1,11 @@
#include "platform.h" #include "platform.h"
#include "log.h" #include "log.h"
#include "input.h" #include "input.h"
#include "config_vars.h"
#include "hashmap.h"
#include "string_utils.h" #include "string_utils.h"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
//#define GL_DEBUG_CONTEXT
struct Window struct Window
{ {
void* sdl_window; void* sdl_window;
@ -26,7 +26,7 @@ struct Platform_State
/* TODO: Find a better way to handle internal state */ /* TODO: Find a better way to handle internal state */
static struct Platform_State* platform_state = NULL; static struct Platform_State* platform_state = NULL;
struct Window* window_create(const char* title, int width, int height) struct Window* window_create(const char* title, int width, int height, int msaa, int msaa_levels)
{ {
struct Window* new_window = NULL; struct Window* new_window = NULL;
if(!new_window) if(!new_window)
@ -47,8 +47,11 @@ struct Window* window_create(const char* title, int width, int height)
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1); if(msaa)
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4); {
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, msaa);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa_levels);
}
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 24); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);

@ -14,7 +14,7 @@ typedef void (*Textinput_Event_Func) (const char* text);
// Window Related functions // Window Related functions
struct Window; struct Window;
struct Window* window_create(const char* title, int width, int height); struct Window* window_create(const char* title, int width, int height, int msaa, int msaa_levels);
void window_destroy(struct Window* window); void window_destroy(struct Window* window);
void window_show(struct Window* window); void window_show(struct Window* window);
void window_hide(struct Window* window); void window_hide(struct Window* window);

@ -14,6 +14,8 @@
#include "transform.h" #include "transform.h"
#include "game.h" #include "game.h"
#include "gui.h" #include "gui.h"
#include "config_vars.h"
#include "hashmap.h"
static int def_fbo = -1; static int def_fbo = -1;
static int def_albedo_tex = -1; static int def_albedo_tex = -1;
@ -36,17 +38,21 @@ void renderer_init(void)
glCullFace(GL_BACK); glCullFace(GL_BACK);
platform_windowresize_callback_set(on_framebuffer_size_change); platform_windowresize_callback_set(on_framebuffer_size_change);
settings.fog.mode = FM_EXPONENTIAL; struct Hashmap* cvars = config_vars_get();
settings.fog.density = 0.01f; settings.fog.mode = hashmap_int_get(cvars, "fog_mode");
settings.fog.start_dist = 50.f; settings.fog.density = hashmap_float_get(cvars, "fog_density");
settings.fog.max_dist = 150.f; settings.fog.start_dist = hashmap_float_get(cvars, "fog_start_dist");
settings.debug_draw_enabled = 1; settings.fog.max_dist = hashmap_float_get(cvars, "fog_max_dist");
settings.debug_draw_mode = GDM_TRIANGLES; settings.fog.color = hashmap_vec3_get(cvars, "fog_color");
settings.debug_draw_enabled = hashmap_bool_get(cvars, "debug_draw_enabled");
settings.debug_draw_mode = hashmap_int_get(cvars, "debug_draw_mode");
settings.debug_draw_color = hashmap_vec4_get(cvars, "debug_draw_color");
settings.ambient_light = hashmap_vec3_get(cvars, "ambient_light");
settings.max_gui_vertex_memory = MAX_GUI_VERTEX_MEMORY; settings.max_gui_vertex_memory = MAX_GUI_VERTEX_MEMORY;
settings.max_gui_element_memory = MAX_GUI_ELEMENT_MEMORY; settings.max_gui_element_memory = MAX_GUI_ELEMENT_MEMORY;
vec3_fill(&settings.fog.color, 60.f/255.f, 60.f/255.f, 75.f/255.f); /* vec3_fill(&settings.fog.color, 60.f/255.f, 60.f/255.f, 75.f/255.f); */
vec3_fill(&settings.ambient_light, 0.1f, 0.1f, 0.12f); /* vec3_fill(&settings.ambient_light, 0.1f, 0.1f, 0.12f); */
vec4_fill(&settings.debug_draw_color, 0.f, 1.f, 0.f, 1.f); /* vec4_fill(&settings.debug_draw_color, 0.f, 1.f, 0.f, 1.f); */
gui_init(); gui_init();

@ -78,6 +78,34 @@ void variant_assign_quat(struct Variant* variant, const quat* value)
quat_assign(&variant->val_quat, value); quat_assign(&variant->val_quat, value);
} }
void variant_assign_vec2f(struct Variant* variant, const float x, const float y)
{
if(variant->type != VT_VEC2) variant_free(variant);
variant->type = VT_VEC2;
vec2_fill(&variant->val_vec2, x, y);
}
void variant_assign_vec3f(struct Variant* variant, const float x, const float y, const float z)
{
if(variant->type != VT_VEC3) variant_free(variant);
variant->type = VT_VEC3;
vec3_fill(&variant->val_vec3, x, y, z);
}
void variant_assign_vec4f(struct Variant* variant, const float x, const float y, const float z, const float w)
{
if(variant->type != VT_VEC4) variant_free(variant);
variant->type = VT_VEC4;
vec4_fill(&variant->val_vec4, x, y, z, w);
}
void variant_assign_quatf(struct Variant* variant, const float x, const float y, const float z, const float w)
{
if(variant->type != VT_QUAT) variant_free(variant);
variant->type = VT_QUAT;
quat_fill(&variant->val_quat, x, y, z, w);
}
void variant_assign_mat4(struct Variant* variant, const mat4* source) void variant_assign_mat4(struct Variant* variant, const mat4* source)
{ {
if(variant->type != VT_MAT4) variant_free(variant); if(variant->type != VT_MAT4) variant_free(variant);

@ -51,6 +51,10 @@ void variant_assign_vec2(struct Variant* variant, const vec2* value);
void variant_assign_vec3(struct Variant* variant, const vec3* value); void variant_assign_vec3(struct Variant* variant, const vec3* value);
void variant_assign_vec4(struct Variant* variant, const vec4* value); void variant_assign_vec4(struct Variant* variant, const vec4* value);
void variant_assign_quat(struct Variant* variant, const quat* value); void variant_assign_quat(struct Variant* variant, const quat* value);
void variant_assign_vec2f(struct Variant* variant, const float x, const float y);
void variant_assign_vec3f(struct Variant* variant, const float x, const float y, const float z);
void variant_assign_vec4f(struct Variant* variant, const float x, const float y, const float z, const float w);
void variant_assign_quatf(struct Variant* variant, const float x, const float y, const float z, const float w);
void variant_assign_mat4(struct Variant* variant, const mat4* source); void variant_assign_mat4(struct Variant* variant, const mat4* source);
void variant_assign_ptr(struct Variant* variant, void* source); void variant_assign_ptr(struct Variant* variant, void* source);
void variant_copy(struct Variant* to, const struct Variant* from); void variant_copy(struct Variant* to, const struct Variant* from);

Loading…
Cancel
Save