Fixed bug in input map creation

dev
shariq 8 years ago
parent 8d56005853
commit 529629d32b
  1. 2
      src/game.c
  2. 13
      src/input.c
  3. 2
      src/utils.c
  4. 4
      src/utils.h

@ -160,7 +160,7 @@ void scene_setup(void)
} }
int parent_node = new_ent->node; int parent_node = new_ent->node;
int num_suz = 200; int num_suz = 2;
srand(time(NULL)); srand(time(NULL));
for(int i = 0; i < num_suz; i++) for(int i = 0; i < num_suz; i++)
{ {

@ -7,10 +7,11 @@
#include "log.h" #include "log.h"
#include "gui.h" #include "gui.h"
#include "file_io.h" #include "file_io.h"
#include "string_utils.h"
struct Input_Map struct Input_Map
{ {
const char* name; char* name;
struct Key_Combination* keys; struct Key_Combination* keys;
int state; int state;
}; };
@ -39,6 +40,8 @@ void input_cleanup(void)
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("Map : %s, Num keys : %d", map->name, array_len(map->keys));
if(map->name) free(map->name);
array_free(map->keys); array_free(map->keys);
} }
array_free(input_map_list); array_free(input_map_list);
@ -70,7 +73,7 @@ int input_keybinds_load(const char* filename)
if(line_buffer[0] == '#' || strlen(line_buffer) == 0) if(line_buffer[0] == '#' || strlen(line_buffer) == 0)
continue; continue;
log_message("Line : %s", line_buffer); //log_message("Line : %s", line_buffer);
memset(key_str, '\0', MAX_KEYBIND_LEN); memset(key_str, '\0', MAX_KEYBIND_LEN);
char* value_str = strstr(line_buffer, ":"); char* value_str = strstr(line_buffer, ":");
if(!value_str) if(!value_str)
@ -96,7 +99,7 @@ int input_keybinds_load(const char* filename)
while(val) while(val)
{ {
log_message("Key read : %s", val); //log_message("Key read : %s", val);
/* Check if there are any Modifiers */ /* Check if there are any Modifiers */
int modifiers = KMD_NONE; int modifiers = KMD_NONE;
@ -109,7 +112,7 @@ int input_keybinds_load(const char* filename)
{ {
memset(key_name, '\0', max_key_str_len); memset(key_name, '\0', max_key_str_len);
strncpy(key_name, start_loc, (keys - start_loc)); strncpy(key_name, start_loc, (keys - start_loc));
log_message("key_name : %s", key_name); //log_message("key_name : %s", key_name);
int key_modifier = platform_key_from_name(key_name); int key_modifier = platform_key_from_name(key_name);
@ -280,7 +283,7 @@ void input_map_create(const char* name, struct Key_Combination* keys, size_t num
else else
{ {
struct Input_Map* new_map = array_grow(input_map_list, struct Input_Map); struct Input_Map* new_map = array_grow(input_map_list, struct Input_Map);
new_map->name = name; new_map->name = str_new(name);
new_map->keys = array_new_cap(struct Key_Combination, num_keys); new_map->keys = array_new_cap(struct Key_Combination, num_keys);
new_map->state = KS_INACTIVE; new_map->state = KS_INACTIVE;
for(size_t i = 0; i < num_keys; i++) for(size_t i = 0; i < num_keys; i++)

@ -2,7 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#define BUFF_SIZE 64 #define BUFF_SIZE 128
static char str_buff[BUFF_SIZE]; static char str_buff[BUFF_SIZE];
const char* tostr_vec3(vec3* v) const char* tostr_vec3(vec3* v)

@ -1,5 +1,5 @@
#ifndef utils_H #ifndef UTILS_H
#define utils_H #define UTILS_H
#include "linmath.h" #include "linmath.h"

Loading…
Cancel
Save