diff --git a/build/linux/makefile b/build/linux/makefile index 07153bd..184c8f2 100644 --- a/build/linux/makefile +++ b/build/linux/makefile @@ -11,7 +11,7 @@ OBJS_DEBUG = $(patsubst %.c,.debug/%.o,$(SRCS)) CFLAGS = -Wall -I$(INCLUDE_DIR) -DUSE_GLAD CFLAGS_DEBUG = -g -DGL_DEBUG_CONTEXT -DAL_DEBUG -std=c99 CFLAGS_RELEASE = -O3 -ffast-math -LFLAGS = -lSDL2 -lpthread -ldl -lm -lopenal -lsndio -lGL +LFLAGS = -lSDL2 -lpthread -ldl -lm -lopenal all: release diff --git a/include/SDL2/SDL_config_linux.h b/include/SDL2/SDL_config_linux.h index bac74e5..b9c8a5c 100644 --- a/include/SDL2/SDL_config_linux.h +++ b/include/SDL2/SDL_config_linux.h @@ -47,7 +47,7 @@ /* #undef HAVE_DSOUND_H */ /* #undef HAVE_DINPUT_H */ /* #undef HAVE_XAUDIO2_H */ -#define HAVE_XINPUT_H 1 +/* #undef HAVE_XINPUT_H */ /* #undef HAVE_DXGI_H */ /* Comment this if you want to build without any C library requirements */ @@ -73,10 +73,10 @@ #define HAVE_SIGNAL_H 1 /* #undef HAVE_ALTIVEC_H */ /* #undef HAVE_PTHREAD_NP_H */ -#define HAVE_LIBUDEV_H 1 -#define HAVE_DBUS_DBUS_H 1 -#define HAVE_IBUS_IBUS_H 1 -#define HAVE_FCITX_FRONTEND_H 1 +/* #undef HAVE_LIBUDEV_H */ +/* #undef HAVE_DBUS_DBUS_H */ +/* #undef HAVE_IBUS_IBUS_H */ +/* #undef HAVE_FCITX_FRONTEND_H */ /* C library functions */ #define HAVE_MALLOC 1 @@ -178,14 +178,14 @@ /* Allow disabling of core subsystems */ /* #undef SDL_ATOMIC_DISABLED */ -/* #undef SDL_AUDIO_DISABLED */ +#define SDL_AUDIO_DISABLED 1 /* #undef SDL_CPUINFO_DISABLED */ /* #undef SDL_EVENTS_DISABLED */ /* #undef SDL_FILE_DISABLED */ /* #undef SDL_JOYSTICK_DISABLED */ /* #undef SDL_HAPTIC_DISABLED */ /* #undef SDL_LOADSO_DISABLED */ -/* #undef SDL_RENDER_DISABLED */ +#define SDL_RENDER_DISABLED 1 /* #undef SDL_THREADS_DISABLED */ /* #undef SDL_TIMERS_DISABLED */ /* #undef SDL_VIDEO_DISABLED */ @@ -194,26 +194,26 @@ /* Enable various audio drivers */ /* #undef SDL_AUDIO_DRIVER_ANDROID */ -#define SDL_AUDIO_DRIVER_ALSA 1 -#define SDL_AUDIO_DRIVER_ALSA_DYNAMIC "libasound.so.2" +/* #undef SDL_AUDIO_DRIVER_ALSA */ +/* #undef SDL_AUDIO_DRIVER_ALSA_DYNAMIC */ /* #undef SDL_AUDIO_DRIVER_ARTS */ /* #undef SDL_AUDIO_DRIVER_ARTS_DYNAMIC */ -#define SDL_AUDIO_DRIVER_PULSEAUDIO 1 -#define SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "libpulse-simple.so.0" +/* #undef SDL_AUDIO_DRIVER_PULSEAUDIO */ +/* #undef SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC */ /* #undef SDL_AUDIO_DRIVER_HAIKU */ /* #undef SDL_AUDIO_DRIVER_BSD */ /* #undef SDL_AUDIO_DRIVER_COREAUDIO */ -#define SDL_AUDIO_DRIVER_DISK 1 -#define SDL_AUDIO_DRIVER_DUMMY 1 +/* #undef SDL_AUDIO_DRIVER_DISK */ +/* #undef SDL_AUDIO_DRIVER_DUMMY */ /* #undef SDL_AUDIO_DRIVER_XAUDIO2 */ /* #undef SDL_AUDIO_DRIVER_DSOUND */ -#define SDL_AUDIO_DRIVER_ESD 1 -#define SDL_AUDIO_DRIVER_ESD_DYNAMIC "libesd.so.0" -#define SDL_AUDIO_DRIVER_NAS 1 -#define SDL_AUDIO_DRIVER_NAS_DYNAMIC "libaudio.so.2" +/* #undef SDL_AUDIO_DRIVER_ESD */ +/* #undef SDL_AUDIO_DRIVER_ESD_DYNAMIC */ +/* #undef SDL_AUDIO_DRIVER_NAS */ +/* #undef SDL_AUDIO_DRIVER_NAS_DYNAMIC */ /* #undef SDL_AUDIO_DRIVER_SNDIO */ /* #undef SDL_AUDIO_DRIVER_SNDIO_DYNAMIC */ -#define SDL_AUDIO_DRIVER_OSS 1 +/* #undef SDL_AUDIO_DRIVER_OSS */ /* #undef SDL_AUDIO_DRIVER_OSS_SOUNDCARD_H */ /* #undef SDL_AUDIO_DRIVER_PAUDIO */ /* #undef SDL_AUDIO_DRIVER_QSA */ @@ -291,19 +291,19 @@ #define SDL_VIDEO_DRIVER_X11 1 #define SDL_VIDEO_DRIVER_X11_DYNAMIC "libX11.so.6" #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "libXext.so.6" -#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "libXcursor.so.1" -#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA "libXinerama.so.1" -#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "libXi.so.6" -#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "libXrandr.so.2" -#define SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "libXss.so.1" +/* #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR */ +/* #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINERAMA */ +/* #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 */ +/* #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR */ +/* #undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS */ #define SDL_VIDEO_DRIVER_X11_DYNAMIC_XVIDMODE "libXxf86vm.so.1" -#define SDL_VIDEO_DRIVER_X11_XCURSOR 1 +/* #undef SDL_VIDEO_DRIVER_X11_XCURSOR */ /* #undef SDL_VIDEO_DRIVER_X11_XDBE */ -#define SDL_VIDEO_DRIVER_X11_XINERAMA 1 -#define SDL_VIDEO_DRIVER_X11_XINPUT2 1 -#define SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 1 -#define SDL_VIDEO_DRIVER_X11_XRANDR 1 -#define SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1 +/* #undef SDL_VIDEO_DRIVER_X11_XINERAMA */ +/* #undef SDL_VIDEO_DRIVER_X11_XINPUT2 */ +/* #undef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH */ +/* #undef SDL_VIDEO_DRIVER_X11_XRANDR */ +/* #undef SDL_VIDEO_DRIVER_X11_XSCRNSAVER */ #define SDL_VIDEO_DRIVER_X11_XSHAPE 1 #define SDL_VIDEO_DRIVER_X11_XVIDMODE 1 #define SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS 1 @@ -313,19 +313,19 @@ /* #undef SDL_VIDEO_RENDER_D3D */ /* #undef SDL_VIDEO_RENDER_D3D11 */ #define SDL_VIDEO_RENDER_OGL 1 -#define SDL_VIDEO_RENDER_OGL_ES 1 -#define SDL_VIDEO_RENDER_OGL_ES2 1 +/* #undef SDL_VIDEO_RENDER_OGL_ES */ +/* #undef SDL_VIDEO_RENDER_OGL_ES2 */ /* #undef SDL_VIDEO_RENDER_DIRECTFB */ /* Enable OpenGL support */ #define SDL_VIDEO_OPENGL 1 -#define SDL_VIDEO_OPENGL_ES 1 -#define SDL_VIDEO_OPENGL_ES2 1 +/* #undef SDL_VIDEO_OPENGL_ES */ +/* #undef SDL_VIDEO_OPENGL_ES2 */ /* #undef SDL_VIDEO_OPENGL_BGL */ /* #undef SDL_VIDEO_OPENGL_CGL */ #define SDL_VIDEO_OPENGL_GLX 1 /* #undef SDL_VIDEO_OPENGL_WGL */ -#define SDL_VIDEO_OPENGL_EGL 1 +/* #undef SDL_VIDEO_OPENGL_EGL */ /* #undef SDL_VIDEO_OPENGL_OSMESA */ /* #undef SDL_VIDEO_OPENGL_OSMESA_DYNAMIC */ @@ -412,4 +412,5 @@ typedef unsigned int uintptr_t; # endif /* !_STDINT_H_ && !HAVE_STDINT_H */ #endif /* __WIN32__ */ + #endif diff --git a/libs/debug/linux64_gcc/libSDL2.a b/libs/debug/linux64_gcc/libSDL2.a index ae2180f..dc7d2cf 100644 Binary files a/libs/debug/linux64_gcc/libSDL2.a and b/libs/debug/linux64_gcc/libSDL2.a differ diff --git a/libs/debug/linux64_gcc/libopenal.a b/libs/debug/linux64_gcc/libopenal.a index 18c7586..640d758 100644 Binary files a/libs/debug/linux64_gcc/libopenal.a and b/libs/debug/linux64_gcc/libopenal.a differ diff --git a/libs/release/linux64_gcc/libSDL2.a b/libs/release/linux64_gcc/libSDL2.a index a235118..8e3f3c6 100644 Binary files a/libs/release/linux64_gcc/libSDL2.a and b/libs/release/linux64_gcc/libSDL2.a differ diff --git a/libs/release/linux64_gcc/libopenal.a b/libs/release/linux64_gcc/libopenal.a index 755c366..c2c0d1e 100644 Binary files a/libs/release/linux64_gcc/libopenal.a and b/libs/release/linux64_gcc/libopenal.a differ diff --git a/orgfile.org b/orgfile.org index 521d10a..e9f1f4d 100644 --- a/orgfile.org +++ b/orgfile.org @@ -95,6 +95,7 @@ msaa_levels: 8 ** DONE Mesh/Model - State "DONE" from "TODO" [2015-10-13 Tue 19:38] ** TODO Add modifiers to input maps to enable combinations for example, c-x, m-k etc +** TODO Only allocate hashmap bucket when required ** DONE Heirarchical Transforms ** DONE Materials with textures - State "DONE" from "TODO" [2015-10-15 Thu 21:21] @@ -171,6 +172,7 @@ x Font atlas proper cleanup ** TODO Do input maps really need to be queried by their string names? ** TODO Reloading all the things! (textures/shaders/models/settings/entities etc) ** TODO Separate Debug/Editor camera from the active camera in the scene that can be switched to at any time +** TODO Use hashmaps for debugvar slots in editor ** DONE Live data views in editor - State "DONE" from "TODO" [2017-03-22 Wed 02:14] ** DONE Camera resize on window reisze diff --git a/src/editor.c b/src/editor.c index a1f94c4..980bc35 100644 --- a/src/editor.c +++ b/src/editor.c @@ -21,6 +21,7 @@ #include #include #include +#include struct Editor_State { @@ -250,6 +251,7 @@ void editor_update(float dt) /* Debug Vars Window */ if(editor_state.debug_vars_window) { + static char variant_str[MAX_VARIANT_STR_LEN] = {'\0'}; if(nk_begin_titled(context, "Debug_Variables_Window", "Debug Variables", nk_rect(20, 20, 300, 300), default_window_flags)) { nk_layout_row_static(context, 250, 250, 2); @@ -261,18 +263,9 @@ void editor_update(float dt) if(debug_var->data.type == VT_NONE) continue; nk_layout_row_dynamic(context, 20, 2); nk_label(context, debug_var->name, NK_TEXT_ALIGN_LEFT); - struct Variant* var_data = &debug_var->data; - switch(debug_var->data.type) - { - case VT_INT: nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "%d", var_data->val_int); break; - case VT_FLOAT: nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "%.4f", var_data->val_float); break; - case VT_DOUBLE: nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "%d", var_data->val_double); break; - case VT_VEC2: nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "(%.2f, %.2f)", var_data->val_vec2.x, var_data->val_vec2.y); break; - case VT_VEC3: nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "(%.2f, %.2f, %.2f)", var_data->val_vec3.x, var_data->val_vec3.y, var_data->val_vec3.z); break; - case VT_VEC4: nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "(%.2f, %.2f, %.2f, %.2f)", var_data->val_vec4.x, var_data->val_vec4.y, var_data->val_vec4.z, var_data->val_vec4.w); break; - case VT_QUAT: nk_labelf(context, NK_TEXT_ALIGN_RIGHT, "(%.2f, %.2f, %.2f, %.2f)", var_data->val_quat.x, var_data->val_quat.y, var_data->val_quat.z, var_data->val_quat.w); break; - default: nk_label(context, "Unsupported Value type", NK_TEXT_ALIGN_RIGHT); break; - }; + variant_to_str(&debug_var->data, variant_str, MAX_VARIANT_STR_LEN); + nk_label(context, variant_str, NK_TEXT_ALIGN_RIGHT); + memset(variant_str, '\0', MAX_VARIANT_STR_LEN); } nk_group_end(context); } diff --git a/src/game.c b/src/game.c index aad59fa..3c5e13d 100644 --- a/src/game.c +++ b/src/game.c @@ -215,22 +215,32 @@ void scene_setup(void) /* struct Light* sun_light = entity_component_add(sun, C_LIGHT, LT_DIR); */ /* sun_light->intensity = 0.8f; */ -/* struct Hashmap* cvars = config_vars_get(); */ -/* hashmap_int_set(cvars, "My_Int", 20); */ -/* hashmap_str_set(cvars, "My_String", "This is my string"); */ -/* hashmap_float_set(cvars, "Some_FLOAT", 42.222f); */ -/* hashmap_double_set(cvars, "Some_Double", 99.999); */ -/* hashmap_bool_set(cvars, "The_Truth", 0); */ - + struct Hashmap* cvars = config_vars_get(); + hashmap_int_set(cvars, "My_Int", 20); + hashmap_str_set(cvars, "My_String", "This is my string"); + hashmap_float_set(cvars, "Some_FLOAT", 42.222f); + hashmap_double_set(cvars, "Some_Double", 99.999); + hashmap_bool_set(cvars, "The_Truth", 0); + + char* key = NULL; + struct Variant* value = NULL; + char variant_str[256]; + HASHMAP_FOREACH(cvars, key, value) + { + variant_to_str(value, variant_str, 256); + log_message("VAL :(%s) : (%s)", key, variant_str); + memset(variant_str, '\0', 256); + } + /* hashmap_float_set(cvars, "Some_FLOAT", 99.3f); */ -/* hashmap_debug_print(cvars); */ + /* hashmap_debug_print(cvars); */ /* log_message("The value of Some_FLOAT is : %f", hashmap_float_get(cvars, "Some_FLOAT")); */ /* } */ - struct Variant variant; - variant_from_str(&variant, "3.333333333333333333333", VT_DOUBLE); - log_message("Variant val : %lf", variant.val_double); - log_message("Variant type : %s", variant.type == VT_DOUBLE ? "expected" : "not what's expected"); + /* struct Variant variant; */ + /* variant_from_str(&variant, "3.333333333333333333333", VT_DOUBLE); */ + /* log_message("Variant val : %lf", variant.val_double); */ + /* log_message("Variant type : %s", variant.type == VT_DOUBLE ? "expected" : "not what's expected"); */ } diff --git a/src/hashmap.c b/src/hashmap.c index b5c5a55..3ec526d 100644 --- a/src/hashmap.c +++ b/src/hashmap.c @@ -1,13 +1,12 @@ #include "hashmap.h" -#include "array.h" #include "variant.h" #include "log.h" #include "string_utils.h" #include #include +#include -#define HASH_MAP_NUM_BUCKETS 10 #define HASH_MAX_KEY_LEN 128 struct Hashmap_Entry @@ -19,6 +18,7 @@ struct Hashmap_Entry struct Hashmap { struct Hashmap_Entry* buckets[HASH_MAP_NUM_BUCKETS]; + int iter_bucket, iter_index; }; static unsigned int hashmap_generate_hash(const char* key); @@ -58,6 +58,8 @@ struct Hashmap* hashmap_new(void) return NULL; for(int i = 0; i < HASH_MAP_NUM_BUCKETS; i++) hashmap->buckets[i] = array_new(struct Hashmap_Entry); + hashmap->iter_bucket = 0; + hashmap->iter_index = -1; return hashmap; } @@ -90,7 +92,7 @@ void hashmap_value_set(struct Hashmap* hashmap, const char* key, const struct Va variant_copy(&new_entry->value, value); } -const struct Variant* hashmap_value_get(struct Hashmap* hashmap, const char* key) +const struct Variant* hashmap_value_get(const struct Hashmap* hashmap, const char* key) { if(!hashmap || !key) return NULL; struct Variant* value = NULL; @@ -189,73 +191,73 @@ void hashmap_ptr_set(struct Hashmap* hashmap, const char* key, void* value) variant_assign_ptr(&new_entry->value, value); } -float hashmap_float_get(struct Hashmap* hashmap, const char* key) +float hashmap_float_get(const struct Hashmap* hashmap, const char* key) { const struct Variant* variant = hashmap_value_get(hashmap, key); return variant->val_float; } -int hashmap_int_get(struct Hashmap* hashmap, const char* key) +int hashmap_int_get(const struct Hashmap* hashmap, const char* key) { const struct Variant* variant = hashmap_value_get(hashmap, key); return variant->val_int; } -double hashmap_double_get(struct Hashmap* hashmap, const char* key) +double hashmap_double_get(const struct Hashmap* hashmap, const char* key) { const struct Variant* variant = hashmap_value_get(hashmap, key); return variant->val_double; } -int hashmap_get_bool(struct Hashmap* hashmap, const char* key) +int hashmap_get_bool(const struct Hashmap* hashmap, const char* key) { const struct Variant* variant = hashmap_value_get(hashmap, key); return variant->val_bool; } -vec2 hashmap_vec2_get(struct Hashmap* hashmap, const char* key) +vec2 hashmap_vec2_get(const struct Hashmap* hashmap, const char* key) { const struct Variant* variant = hashmap_value_get(hashmap, key); return variant->val_vec2; } -vec3 hashmap_vec3_get(struct Hashmap* hashmap, const char* key) +vec3 hashmap_vec3_get(const struct Hashmap* hashmap, const char* key) { const struct Variant* variant = hashmap_value_get(hashmap, key); return variant->val_vec3; } -vec4 hashmap_vec4_get(struct Hashmap* hashmap, const char* key) +vec4 hashmap_vec4_get(const struct Hashmap* hashmap, const char* key) { const struct Variant* variant = hashmap_value_get(hashmap, key); return variant->val_vec4; } -quat hashmap_quat_get(struct Hashmap* hashmap, const char* key) +quat hashmap_quat_get(const struct Hashmap* hashmap, const char* key) { const struct Variant* variant = hashmap_value_get(hashmap, key); return variant->val_quat; } -const mat4* hashmap_mat4_get(struct Hashmap* hashmap, const char* key) +const mat4* hashmap_mat4_get(const struct Hashmap* hashmap, const char* key) { const struct Variant* variant = hashmap_value_get(hashmap, key); return variant->val_mat4; } -const char* hashmap_str_get(struct Hashmap* hashmap, const char* key) +const char* hashmap_str_get(const struct Hashmap* hashmap, const char* key) { const struct Variant* variant = hashmap_value_get(hashmap, key); return variant->val_str; } -void* hashmap_ptr_get(struct Hashmap* hashmap, const char* key) +void* hashmap_ptr_get(const struct Hashmap* hashmap, const char* key) { const struct Variant* variant = hashmap_value_get(hashmap, key); return variant->val_voidptr; } -void hashmap_debug_print(struct Hashmap* hashmap) +void hashmap_debug_print(const struct Hashmap* hashmap) { if(!hashmap) return; static char str[128]; @@ -268,10 +270,40 @@ void hashmap_debug_print(struct Hashmap* hashmap) { struct Hashmap_Entry* entry = &hashmap->buckets[i][j]; const struct Variant* value = &entry->value; - log_message("Key : %s", entry->key); + const char* key = entry->key; + log_message("Key : %s", key); variant_to_str(value, str, 128); log_message("Value : %s", str); memset(str, '\0', 128); } } } + +void hashmap_iter_begin(struct Hashmap* hashmap) +{ + assert(hashmap); + hashmap->iter_bucket = 0; + hashmap->iter_index = -1; +} + +int hashmap_iter_next(struct Hashmap* hashmap, char** key, struct Variant** value) +{ + assert(hashmap); + for(;hashmap->iter_bucket < HASH_MAP_NUM_BUCKETS; hashmap->iter_bucket++) + { + if(hashmap->buckets[hashmap->iter_bucket]) + { + if(++hashmap->iter_index < array_len(hashmap->buckets[hashmap->iter_bucket])) + { + *key = hashmap->buckets[hashmap->iter_bucket][hashmap->iter_index].key; + *value = &hashmap->buckets[hashmap->iter_bucket][hashmap->iter_index].value; + return 1; + } + else + { + hashmap->iter_index = -1; + } + } + } + return 0; +} diff --git a/src/hashmap.h b/src/hashmap.h index 4ba4671..c61ff50 100644 --- a/src/hashmap.h +++ b/src/hashmap.h @@ -2,6 +2,9 @@ #define HASHMAP_H #include "linmath.h" +#include "array.h" + +#define HASH_MAP_NUM_BUCKETS 10 struct Hashmap; struct Variant; @@ -10,12 +13,12 @@ struct Hashmap* hashmap_new(void); void hashmap_free(struct Hashmap* hashmap); void hashmap_value_remove(struct Hashmap* hashmap, const char* key); void hashmap_value_set(struct Hashmap* hashmap, const char* key, const struct Variant* value); -const struct Variant* hashmap_value_get(struct Hashmap* hashmap, const char* key); +const struct Variant* hashmap_value_get(const struct Hashmap* hashmap, const char* key); -void hashmap_float_set(struct Hashmap* hashmap, const char* key, float value); -void hashmap_int_set(struct Hashmap* hashmap, const char* key, int value); -void hashmap_double_set(struct Hashmap* hashmap, const char* key, double value); -void hashmap_bool_set(struct Hashmap* hashmap, const char* key, int 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_double_set(struct Hashmap* hashmap, const char* key, const double value); +void hashmap_bool_set(struct Hashmap* hashmap, const char* key, const int value); void hashmap_vec2_set(struct Hashmap* hashmap, const char* key, const vec2* 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); @@ -24,18 +27,27 @@ void hashmap_mat4_set(struct Hashmap* hashmap, const char* key, const 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); -float hashmap_float_get(struct Hashmap* hashmap, const char* key); -int hashmap_int_get(struct Hashmap* hashmap, const char* key); -double hashmap_double_get(struct Hashmap* hashmap, const char* key); -int hashmap_get_bool(struct Hashmap* hashmap, const char* key); -vec2 hashmap_vec2_get(struct Hashmap* hashmap, const char* key); -vec3 hashmap_vec3_get(struct Hashmap* hashmap, const char* key); -vec4 hashmap_vec4_get(struct Hashmap* hashmap, const char* key); -quat hashmap_quat_get(struct Hashmap* hashmap, const char* key); -const mat4* hashmap_mat4_get(struct Hashmap* hashmap, const char* key); -const char* hashmap_str_get(struct Hashmap* hashmap, const char* key); -void* hashmap_ptr_get(struct Hashmap* hashmap, const char* key); - -void hashmap_debug_print(struct Hashmap* hashmap); +float hashmap_float_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); +int hashmap_get_bool(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); +vec4 hashmap_vec4_get(const struct Hashmap* hashmap, const char* key); +quat hashmap_quat_get(const struct Hashmap* hashmap, const char* key); +const mat4* hashmap_mat4_get(const struct Hashmap* hashmap, const char* key); +const char* hashmap_str_get(const struct Hashmap* hashmap, const char* key); +void* hashmap_ptr_get(const struct Hashmap* hashmap, const char* key); + +void hashmap_debug_print(const struct Hashmap* hashmap); +/* Only used during iteration */ +void hashmap_iter_begin(struct Hashmap* hashmap); +int hashmap_iter_next(struct Hashmap* hashmap, char** key, struct Variant** value); + +#define HASHMAP_FOREACH(hashmap, key, value) \ + hashmap_iter_begin(hashmap); \ + while(hashmap_iter_next(hashmap, &key, &value)) \ + + #endif diff --git a/src/variant.c b/src/variant.c index c4c7676..1e361ea 100644 --- a/src/variant.c +++ b/src/variant.c @@ -7,8 +7,6 @@ #include #include -#define MAX_VARIANT_STR_LEN 1024 - void variant_init_empty(struct Variant* variant) { variant->type = VT_NONE; @@ -148,6 +146,7 @@ void variant_copy(struct Variant* to, const struct Variant* from) void variant_to_str(const struct Variant* variant, char* str, int len) { + if(!variant) return; switch(variant->type) { case VT_BOOL: snprintf(str, len, "%s", variant->val_bool ? "true" : "false"); break; diff --git a/src/variant.h b/src/variant.h index 72d2058..6f65eb2 100644 --- a/src/variant.h +++ b/src/variant.h @@ -3,6 +3,8 @@ #include "linmath.h" +#define MAX_VARIANT_STR_LEN 1024 + enum Variant_Type { VT_NONE = 0,