Added option to read/write files from installation directory or user preferences directory

dev
shariq 8 years ago
parent 595038e0a0
commit baab23980e
  1. 2
      assets/config.cfg
  2. 11
      assets/keybindings.cfg
  3. 4
      orgfile.org
  4. 4
      src/config_vars.c
  5. 2
      src/editor.c
  6. 21
      src/file_io.c
  7. 16
      src/file_io.h
  8. 110
      src/game.c
  9. 2
      src/geometry.c
  10. 2
      src/gui.c
  11. 44
      src/input.c
  12. 11
      src/main.c
  13. 19
      src/platform.c
  14. 3
      src/platform.h
  15. 6
      src/shader.c
  16. 2
      src/sound.c
  17. 2
      src/texture.c

@ -1,6 +1,6 @@
msaa_levels: 4 msaa_levels: 4
debug_draw_color : 1.000, 0.000, 0.000, 1.000 debug_draw_color : 1.000, 0.000, 0.000, 1.000
render_width : 800 render_width : 1024
fog_density : 0.0020 fog_density : 0.0020
render_height : 600 render_height : 600
fog_mode : 2 fog_mode : 2

@ -1,7 +1,14 @@
# This is a comment, this should be ignored
Move_Forward : Left Ctrl-E, W, Left Alt-Left Shift-Up Move_Forward : Left Ctrl-E, W, Left Alt-Left Shift-Up
Move_Backward : S, Down, S, Down Move_Backward : S, Down, S, Down
Move_Left : A, Left Move_Left : A, Left
Move_Right : D, Right Move_Right : D, Right
Move_Up : Q
Move_Down : E
Sprint : Left Shift Sprint : Left Shift
Turn_Left : J
Turn_Right : L
Turn_Up : I
Turn_Down : K
Editor_Toggle : F1
Window_Fullscreen : F11
Window_Maximize : F12

@ -207,9 +207,11 @@ x Keybindings in config
** TODO Do input maps really need to be queried by their string names? ** 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 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 Separate Debug/Editor camera from the active camera in the scene that can be switched to at any time
** TODO Add option to specify where to read/write files from instead of being hard-coded assets dir ** DONE Add option to specify where to read/write files from instead of being hard-coded assets dir
- State "DONE" from "TODO" [2017-05-24 Wed 17:12]
** TODO Add default keybindings ** TODO Add default keybindings
** TODO Write default config/keybindings etc to file if none are found in preferences dir ** TODO Write default config/keybindings etc to file if none are found in preferences dir
** TODO Fix input map bugs
** TODO Use hashmap for debugvar slots in editor ** TODO Use hashmap for debugvar slots in editor
** TODO Use hashmap to store input maps ** TODO Use hashmap to store input maps
** DONE Live data views in editor ** DONE Live data views in editor

@ -44,7 +44,7 @@ struct Hashmap* config_vars_get(void)
int config_vars_load(const char* filename) int config_vars_load(const char* filename)
{ {
int success = 0; int success = 0;
FILE* config_file = io_file_open(filename, "r"); FILE* config_file = io_file_open(DT_USER, 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);
@ -97,7 +97,7 @@ int config_vars_load(const char* filename)
int config_vars_save(const char* filename) int config_vars_save(const char* filename)
{ {
int success = 0; int success = 0;
FILE* config_file = io_file_open(filename, "w"); FILE* config_file = io_file_open(DT_USER, 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");

@ -219,7 +219,7 @@ void editor_update(float dt)
nk_slider_float(context, 0.f, &render_settings->fog.density, 1.f, 0.005); nk_slider_float(context, 0.f, &render_settings->fog.density, 1.f, 0.005);
if(nk_input_is_mouse_hovering_rect(&context->input, bounds)) if(nk_input_is_mouse_hovering_rect(&context->input, bounds))
{ {
static char float_str[7]; static char float_str[10] = {'\0'};
snprintf(float_str, 6, "%.4f", render_settings->fog.density); snprintf(float_str, 6, "%.4f", render_settings->fog.density);
float_str[6] = '\0'; float_str[6] = '\0';
nk_tooltip(context, float_str); nk_tooltip(context, float_str);

@ -5,21 +5,24 @@
#include "log.h" #include "log.h"
#include "string_utils.h" #include "string_utils.h"
static char* base_assets_path; static char* install_directory = NULL;
static char* user_directory = NULL;
void io_file_init(const char* assets_path) void io_file_init(const char* install_dir, const char* user_dir)
{ {
base_assets_path = str_new("%s/assets/", assets_path); install_directory = str_new("%s/assets/", install_dir);
user_directory = str_new("%s/", user_dir);
} }
void io_file_cleanup(void) void io_file_cleanup(void)
{ {
if(base_assets_path) free(base_assets_path); if(install_directory) free(install_directory);
if(user_directory) free(user_directory);
} }
char* io_file_read(const char* path, const char* mode, long* file_size) char* io_file_read(const int directory_type, const char* path, const char* mode, long* file_size)
{ {
FILE* file = io_file_open(path, mode); FILE* file = io_file_open(directory_type, path, mode);
char* data = NULL; char* data = NULL;
if(!file) return data; if(!file) return data;
int rc = fseek(file, 0, SEEK_END); int rc = fseek(file, 0, SEEK_END);
@ -54,9 +57,11 @@ char* io_file_read(const char* path, const char* mode, long* file_size)
return data; return data;
} }
FILE* io_file_open(const char* path, const char* mode) FILE* io_file_open(int directory_type, const char* path, const char* mode)
{ {
char* relative_path = str_new(base_assets_path); assert(directory_type >= 0 && directory_type <= DT_INSTALL);
char* relative_path = str_new(directory_type == DT_INSTALL ? install_directory : user_directory);
relative_path = str_concat(relative_path, path); relative_path = str_concat(relative_path, path);
FILE* file = fopen(relative_path, mode); FILE* file = fopen(relative_path, mode);
if(!file) log_error("io:file", "Failed to open file '%s'", relative_path); if(!file) log_error("io:file", "Failed to open file '%s'", relative_path);

@ -1,11 +1,17 @@
#ifndef file_io_H #ifndef FILE_IO_H
#define file_io_H #define FILE_IO_H
#include <stdio.h> #include <stdio.h>
void io_file_init(const char* assets_path); enum Directory_Type
char* io_file_read(const char* path, const char* mode, long* file_size); {
FILE* io_file_open(const char* path, const char* mode); DT_USER, /* User directory or preferences directory */
DT_INSTALL /* Directory where the game's executable is, usually where the game is installed */
};
void io_file_init(const char* install_dir, const char* user_dir);
char* io_file_read(const int directory_type, const char* path, const char* mode, long* file_size);
FILE* io_file_open(const int directory_type, const char* path, const char* mode);
void io_file_cleanup(void); void io_file_cleanup(void);
#endif #endif

@ -88,38 +88,7 @@ int game_init(struct Window* window)
} }
void scene_setup(void) void scene_setup(void)
{ {
/* struct Key_Combination forward_keys[2] = {{KEY_W, KMD_NONE}, {KEY_UP, KMD_ALT | KMD_SHIFT}}; */
/* struct Key_Combination backward_keys[2] = {{KEY_S, KMD_NONE}, {KEY_DOWN, KMD_NONE}}; */
/* struct Key_Combination up_keys[2] = {KEY_Q}; */
/* struct Key_Combination down_keys[2] = {KEY_E}; */
/* struct Key_Combination left_keys[2] = {KEY_A, KEY_LEFT}; */
/* struct Key_Combination right_keys[2] = {KEY_D, KEY_RIGHT}; */
/* struct Key_Combination turn_right_keys[1] = {KEY_L}; */
/* struct Key_Combination turn_left_keys[1] = {KEY_J}; */
/* struct Key_Combination turn_up_keys[1] = {KEY_I}; */
/* struct Key_Combination turn_down_keys[1] = {KEY_K}; */
/* struct Key_Combination sprint_keys[2] = {KEY_LSHIFT, KEY_RSHIFT}; */
/* struct Key_Combination recompute_keys[2] = {KEY_F5, KEY_H}; */
/* struct Key_Combination ed_toggle_keys[1] = {KEY_F1}; */
/* struct Key_Combination win_fullscr_keys[1] = {KEY_F11}; */
/* struct Key_Combination win_max_keys[1] = {KEY_F12}; */
/* input_map_create("Move_Forward", forward_keys, 2); */
/* input_map_create("Move_Backward", backward_keys, 2); */
/* input_map_create("Move_Up", up_keys, 1); */
/* input_map_create("Move_Down", down_keys, 1); */
/* input_map_create("Move_Left", left_keys, 2); */
/* input_map_create("Move_Right", right_keys, 2); */
/* input_map_create("Turn_Right", turn_right_keys, 1); */
/* input_map_create("Turn_Left", turn_left_keys, 1); */
/* input_map_create("Turn_Up", turn_up_keys, 1); */
/* input_map_create("Turn_Down", turn_down_keys, 1); */
/* input_map_create("Sprint", sprint_keys, 2); */
/* input_map_create("Recompute", recompute_keys, 2); */
/* input_map_create("Editor_Toggle", ed_toggle_keys, 1); */
/* input_map_create("Window_Fullscreen", win_fullscr_keys, 1); */
/* input_map_create("Window_Maximize", win_max_keys, 1); */
struct Entity* player = scene_add_new("player", "None"); struct Entity* player = scene_add_new("player", "None");
game_state->player_node = player->node; game_state->player_node = player->node;
vec3 viewer_pos = {10, 5, 100}; vec3 viewer_pos = {10, 5, 100};
@ -225,34 +194,6 @@ void scene_setup(void)
/* 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; */
/* 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); */
/* 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"); */
} }
void debug(float dt) void debug(float dt)
@ -272,18 +213,10 @@ void debug(float dt)
vec3 rot_axis_left_right = {0, 1, 0}; vec3 rot_axis_left_right = {0, 1, 0};
/* Look around */ /* Look around */
/* if(input_map_state_get("Turn_Up", KS_PRESSED)) turn_up_down += turn_speed; */ if(input_map_state_get("Turn_Up", KS_PRESSED)) turn_up_down += turn_speed;
/* if(input_map_state_get("Turn_Down", KS_PRESSED)) turn_up_down -= turn_speed; */ if(input_map_state_get("Turn_Down", KS_PRESSED)) turn_up_down -= turn_speed;
/* if(input_map_state_get("Turn_Right", KS_PRESSED)) turn_left_right += turn_speed; */ if(input_map_state_get("Turn_Right", KS_PRESSED)) turn_left_right += turn_speed;
/* if(input_map_state_get("Turn_Left", KS_PRESSED)) turn_left_right -= turn_speed; */ if(input_map_state_get("Turn_Left", KS_PRESSED)) turn_left_right -= turn_speed;
/* if(input_map_state_get("Recompute", KS_PRESSED)) */
/* { */
/* log_message("Regenerating Bounding Volumes"); */
/* geom_bounding_volume_generate_all(); */
/* } */
/* if(input_is_key_pressed(KEY_TAB, KS_PRESSED)) */
/* if(input_is_key_pressed(KEY_TAB, KS_PRESSED) && input_is_key_pressed(KEY_LSHIFT, KS_PRESSED)) input_mouse_mode_set(MM_NORMAL); */
if(input_mousebutton_state_get(MSB_RIGHT, KS_PRESSED)) if(input_mousebutton_state_get(MSB_RIGHT, KS_PRESSED))
{ {
@ -340,13 +273,13 @@ void debug(float dt)
} }
/* Movement */ /* Movement */
/* if(input_map_state_get("Sprint", KS_PRESSED)) move_speed *= move_scale; */ if(input_map_state_get("Sprint", KS_PRESSED)) move_speed *= move_scale;
if(input_map_state_get("Move_Forward", KS_PRESSED)) offset.z -= move_speed; if(input_map_state_get("Move_Forward", KS_PRESSED)) offset.z -= move_speed;
if(input_map_state_get("Move_Backward", KS_PRESSED)) offset.z += move_speed; if(input_map_state_get("Move_Backward", KS_PRESSED)) offset.z += move_speed;
/* if(input_map_state_get("Move_Left", KS_PRESSED)) offset.x -= move_speed; */ if(input_map_state_get("Move_Left", KS_PRESSED)) offset.x -= move_speed;
/* if(input_map_state_get("Move_Right", KS_PRESSED)) offset.x += move_speed; */ if(input_map_state_get("Move_Right", KS_PRESSED)) offset.x += move_speed;
/* if(input_map_state_get("Move_Up", KS_PRESSED)) offset.y += move_speed; */ if(input_map_state_get("Move_Up", KS_PRESSED)) offset.y += move_speed;
/* if(input_map_state_get("Move_Down", KS_PRESSED)) offset.y -= move_speed; */ if(input_map_state_get("Move_Down", KS_PRESSED)) offset.y -= move_speed;
vec3_scale(&offset, &offset, dt); vec3_scale(&offset, &offset, dt);
if(offset.x != 0 || offset.y != 0 || offset.z != 0) if(offset.x != 0 || offset.y != 0 || offset.z != 0)
@ -381,20 +314,7 @@ void debug(float dt)
/* transform_rotate(mod_tran, &y_axis, 25.f * dt, TS_WORLD); */ /* transform_rotate(mod_tran, &y_axis, 25.f * dt, TS_WORLD); */
vec3 amount = {0, 0, 5 * dt}; vec3 amount = {0, 0, 5 * dt};
transform_translate(mod_tran, &amount, TS_LOCAL); transform_translate(mod_tran, &amount, TS_LOCAL);
} }
/* if(input_is_key_pressed(GLFW_KEY_C, KS_PRESSED)) */
/* { */
/* struct Entity* cam_ent = scene_find("Screen_Camera"); */
/* struct Camera* cam = entity_component_get(cam_ent, C_CAMERA); */
/* camera_set_primary_viewer(cam); */
/* } */
/* if(input_is_key_pressed(GLFW_KEY_V, KS_PRESSED)) */
/* { */
/* struct Camera* cam = entity_component_get(entity, C_CAMERA); */
/* camera_set_priimary_viewer(cam); */
/* } */
} }
int run(void) int run(void)
@ -422,12 +342,12 @@ int run(void)
void update(float dt, int* window_should_close) void update(float dt, int* window_should_close)
{ {
if(input_is_key_pressed(KEY_ESCAPE)) *window_should_close = 1; if(input_is_key_pressed(KEY_ESCAPE)) *window_should_close = 1;
/* if(input_map_state_get("Editor_Toggle", KS_RELEASED)) editor_toggle(); */ if(input_map_state_get("Editor_Toggle", KS_RELEASED)) editor_toggle();
/* if(input_map_state_get("Window_Fullscreen", KS_RELEASED)) window_fullscreen_set(game_state->window, 1); */ if(input_map_state_get("Window_Fullscreen", KS_RELEASED)) window_fullscreen_set(game_state->window, 1);
/* if(input_map_state_get("Window_Maximize", KS_RELEASED)) window_fullscreen_set(game_state->window, 0); */ if(input_map_state_get("Window_Maximize", KS_RELEASED)) window_fullscreen_set(game_state->window, 0);
debug(dt); debug(dt);
debug_gui(dt); //debug_gui(dt);
editor_update(dt); editor_update(dt);
input_update(); /* This should always be the last thing. Probably input_update(); /* This should always be the last thing. Probably
* put this in post update? */ * put this in post update? */

@ -236,7 +236,7 @@ static int load_from_file(struct Geometry* geometry, const char* filename)
int success = 1; int success = 1;
char* full_path = str_new("models/%s", filename); char* full_path = str_new("models/%s", filename);
FILE* file = io_file_open(full_path, "rb"); FILE* file = io_file_open(DT_INSTALL, full_path, "rb");
free(full_path); free(full_path);
if(file) if(file)
{ {

@ -369,7 +369,7 @@ void gui_font_set(const char* font_name, float font_size)
struct nk_font_atlas* atlas = &gui_state->atlas; struct nk_font_atlas* atlas = &gui_state->atlas;
long size = 0; long size = 0;
char* font_file_name = str_new("fonts/%s", font_name); char* font_file_name = str_new("fonts/%s", font_name);
char* font_data = io_file_read(font_file_name, "rb", &size); char* font_data = io_file_read(DT_INSTALL, font_file_name, "rb", &size);
free(font_file_name); free(font_file_name);
if(!font_data) if(!font_data)
{ {

@ -32,12 +32,44 @@ void input_init(void)
platform_mousewheel_callback_set(&input_on_mousewheel); platform_mousewheel_callback_set(&input_on_mousewheel);
input_map_list = array_new(struct Input_Map); input_map_list = array_new(struct Input_Map);
input_keybinds_load("keybindings.cfg"); if(!input_keybinds_load("keybindings.cfg"))
log_error("input:init", "Failed to load keybindings");
/* struct Key_Combination forward_keys[2] = {{KEY_W, KMD_NONE}, {KEY_UP, KMD_ALT | KMD_SHIFT}}; */
/* struct Key_Combination backward_keys[2] = {{KEY_S, KMD_NONE}, {KEY_DOWN, KMD_NONE}}; */
/* struct Key_Combination up_keys[2] = {KEY_Q}; */
/* struct Key_Combination down_keys[2] = {KEY_E}; */
/* struct Key_Combination left_keys[2] = {KEY_A, KEY_LEFT}; */
/* struct Key_Combination right_keys[2] = {KEY_D, KEY_RIGHT}; */
/* struct Key_Combination turn_right_keys[1] = {KEY_L}; */
/* struct Key_Combination turn_left_keys[1] = {KEY_J}; */
/* struct Key_Combination turn_up_keys[1] = {KEY_I}; */
/* struct Key_Combination turn_down_keys[1] = {KEY_K}; */
/* struct Key_Combination sprint_keys[2] = {KEY_LSHIFT, KEY_RSHIFT}; */
/* struct Key_Combination recompute_keys[2] = {KEY_F5, KEY_H}; */
/* struct Key_Combination ed_toggle_keys[1] = {KEY_F1}; */
/* struct Key_Combination win_fullscr_keys[1] = {KEY_F11}; */
/* struct Key_Combination win_max_keys[1] = {KEY_F12}; */
/* input_map_create("Move_Forward", forward_keys, 2); */
/* input_map_create("Move_Backward", backward_keys, 2); */
/* input_map_create("Move_Up", up_keys, 1); */
/* input_map_create("Move_Down", down_keys, 1); */
/* input_map_create("Move_Left", left_keys, 2); */
/* input_map_create("Move_Right", right_keys, 2); */
/* input_map_create("Turn_Right", turn_right_keys, 1); */
/* input_map_create("Turn_Left", turn_left_keys, 1); */
/* input_map_create("Turn_Up", turn_up_keys, 1); */
/* input_map_create("Turn_Down", turn_down_keys, 1); */
/* input_map_create("Sprint", sprint_keys, 2); */
/* input_map_create("Recompute", recompute_keys, 2); */
/* input_map_create("Editor_Toggle", ed_toggle_keys, 1); */
/* input_map_create("Window_Fullscreen", win_fullscr_keys, 1); */
/* input_map_create("Window_Maximize", win_max_keys, 1); */
} }
void input_cleanup(void) void input_cleanup(void)
{ {
input_keybinds_save("keybindings.cfg"); //input_keybinds_save("keybindings.cfg");
for(int i = 0; i < array_len(input_map_list); i++) for(int i = 0; i < array_len(input_map_list); i++)
{ {
struct Input_Map* map = &input_map_list[i]; struct Input_Map* map = &input_map_list[i];
@ -53,7 +85,7 @@ int input_keybinds_load(const char* filename)
int success = 0; int success = 0;
const int MAX_KEYBIND_LEN = 128; const int MAX_KEYBIND_LEN = 128;
const int MAX_LINE_LEN = 512; const int MAX_LINE_LEN = 512;
FILE* config_file = io_file_open(filename, "r"); FILE* config_file = io_file_open(DT_USER, filename, "r");
if(!config_file) if(!config_file)
{ {
log_error("input:keybinds_load", "Could not open %s", filename); log_error("input:keybinds_load", "Could not open %s", filename);
@ -167,7 +199,7 @@ int input_keybinds_save(const char* filename)
{ {
int success = 0; int success = 0;
FILE* config_file = io_file_open(filename, "w"); FILE* config_file = io_file_open(DT_USER, filename, "w");
if(!config_file) if(!config_file)
{ {
log_error("input:keybinds_save", "Could not open %s", filename); log_error("input:keybinds_save", "Could not open %s", filename);
@ -379,7 +411,7 @@ int input_map_name_set(const char* name, const char* new_name)
if(index > -1) if(index > -1)
{ {
struct Input_Map* map = &input_map_list[index]; struct Input_Map* map = &input_map_list[index];
map->name = new_name; map->name = str_new(new_name);
success = 1; success = 1;
} }
if(!success) log_error("input:map_name_set", "Map %s not found", name); if(!success) log_error("input:map_name_set", "Map %s not found", name);
@ -392,7 +424,6 @@ int map_find(const char* name)
for(int i = 0; i < array_len(input_map_list); i++) for(int i = 0; i < array_len(input_map_list); i++)
{ {
struct Input_Map* map = &input_map_list[i]; struct Input_Map* map = &input_map_list[i];
log_message("Len : %d, Comparing %s and %s", array_len(input_map_list), name, map->name);
if(strcmp(name, map->name) == 0) if(strcmp(name, map->name) == 0)
{ {
index = i; index = i;
@ -409,7 +440,6 @@ int input_mouse_mode_get(void)
return mouse_mode; return mouse_mode;
} }
void input_mouse_delta_get(int* xpos, int* ypos) void input_mouse_delta_get(int* xpos, int* ypos)
{ {
platform_mouse_delta_get(xpos, ypos); platform_mouse_delta_get(xpos, ypos);

@ -44,11 +44,16 @@ int init(void)
} }
else else
{ {
char* base_path = platform_base_path_get(); char* install_path = platform_install_directory_get();
io_file_init(base_path); char* user_path = platform_user_directory_get("SS_Games", "Symmetry");
free(base_path); 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"))
{
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");
}
struct Hashmap* cvars = config_vars_get(); struct Hashmap* cvars = config_vars_get();
int width = hashmap_int_get(cvars, "render_width"); int width = hashmap_int_get(cvars, "render_width");

@ -355,7 +355,7 @@ void platform_mouse_delta_get(int* x, int* y)
SDL_GetRelativeMouseState(x, y); SDL_GetRelativeMouseState(x, y);
} }
char* platform_base_path_get(void) char* platform_install_directory_get(void)
{ {
char* returned_path = SDL_GetBasePath(); char* returned_path = SDL_GetBasePath();
char* path = NULL; char* path = NULL;
@ -399,7 +399,6 @@ int platform_key_from_name(const char* key_name)
while(isspace(end_ptr[0])) end_ptr--; while(isspace(end_ptr[0])) end_ptr--;
strncpy(trimmed_key_name, start_ptr, (end_ptr - start_ptr)); strncpy(trimmed_key_name, start_ptr, (end_ptr - start_ptr));
log_message("trimmed : %s", trimmed_key_name);
return SDL_GetKeyFromName(trimmed_key_name); return SDL_GetKeyFromName(trimmed_key_name);
} }
@ -408,3 +407,19 @@ const char* platform_key_name_get(int key)
if(key < 0) return "SDLK_UNKNOWN"; if(key < 0) return "SDLK_UNKNOWN";
return SDL_GetKeyName(key); return SDL_GetKeyName(key);
} }
char* platform_user_directory_get(const char* organization, const char* application)
{
char* user_directory = NULL;
char* temp_path = SDL_GetPrefPath(organization, application);
if(temp_path)
{
user_directory = str_new(temp_path);
SDL_free(temp_path);
}
else
{
log_error("platform:user_directory_get", "Error getting user directory, %s", SDL_GetError());
}
return user_directory;
}

@ -46,7 +46,8 @@ void platform_mouse_global_position_set(int x, int y);
void platform_mouse_relative_mode_set(int relative_mode); void platform_mouse_relative_mode_set(int relative_mode);
int platform_mouse_relative_mode_get(void); int platform_mouse_relative_mode_get(void);
uint32 platform_ticks_get(void); uint32 platform_ticks_get(void);
char* platform_base_path_get(void); char* platform_install_directory_get(void);
char* platform_user_directory_get(const char* organization, const char* application);
void platform_clipboard_text_set(const char* text); void platform_clipboard_text_set(const char* text);
char* platform_clipboard_text_get(void); char* platform_clipboard_text_get(void);
int platform_key_from_name(const char* key_name); int platform_key_from_name(const char* key_name);

@ -56,7 +56,7 @@ char* run_preprocessor(char* shader_text)
{ {
char* path = str_new("shaders/"); char* path = str_new("shaders/");
path = str_concat(path, filename); path = str_concat(path, filename);
char* file = io_file_read(path, "r", NULL); char* file = io_file_read(DT_INSTALL, path, "r", NULL);
char* shader_copy = str_new(shader_text); char* shader_copy = str_new(shader_text);
char* temp = realloc(shader_text, (strlen(shader_text) + strlen(file) + 2)); char* temp = realloc(shader_text, (strlen(shader_text) + strlen(file) + 2));
if(temp) if(temp)
@ -96,8 +96,8 @@ int shader_create(const char* vert_shader_name, const char* frag_shader_name)
GLuint vert_shader = glCreateShader(GL_VERTEX_SHADER); GLuint vert_shader = glCreateShader(GL_VERTEX_SHADER);
GLuint frag_shader = glCreateShader(GL_FRAGMENT_SHADER); GLuint frag_shader = glCreateShader(GL_FRAGMENT_SHADER);
char* vert_source = io_file_read(vs_path, "r", NULL); char* vert_source = io_file_read(DT_INSTALL, vs_path, "r", NULL);
char* frag_source = io_file_read(fs_path, "r", NULL); char* frag_source = io_file_read(DT_INSTALL, fs_path, "r", NULL);
assert(vert_source != NULL); assert(vert_source != NULL);
assert(frag_source != NULL); assert(frag_source != NULL);

@ -244,7 +244,7 @@ void sound_source_load_wav(struct Sound_Source* source, const char* file_name)
} }
char* full_path = str_new("sounds/%s", file_name); char* full_path = str_new("sounds/%s", file_name);
FILE* wav_file = io_file_open(full_path, "rb"); FILE* wav_file = io_file_open(DT_INSTALL, full_path, "rb");
free(full_path); free(full_path);
if(!wav_file) if(!wav_file)
{ {

@ -68,7 +68,7 @@ int texture_create_from_file(const char* filename, int texture_unit)
} }
/* If texture not already loaded then try to load it */ /* If texture not already loaded then try to load it */
char* full_path = str_new("textures/%s", filename); char* full_path = str_new("textures/%s", filename);
FILE* file = io_file_open(full_path, "rb"); FILE* file = io_file_open(DT_INSTALL, full_path, "rb");
int img_load_success = -1; int img_load_success = -1;
if(file) if(file)

Loading…
Cancel
Save