Fixed bugs with key release by changing key polling behaviour

dev
Shariq Shah 9 years ago
parent d47a13ad5d
commit fb77575f04
  1. 5
      orgfile.org
  2. 34
      src/game.c
  3. 25
      src/input.c
  4. 2
      src/input.h
  5. 17
      src/model.c
  6. 2
      src/platform.c
  7. 2
      src/platform.h

@ -111,7 +111,8 @@ 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 Fix Key release not being reported ** DONE Fix Key release not being reported
- State "DONE" from "TODO" [2017-03-26 Sun 01:16]
** TODO Better handling incase assets folder is not found? ** TODO Better handling incase assets folder is not found?
** DONE OpenAL not working in releasebuilds ** DONE OpenAL not working in releasebuilds
- State "DONE" from "TODO" [2017-03-25 Sat 02:06] - State "DONE" from "TODO" [2017-03-25 Sat 02:06]
@ -124,6 +125,8 @@ x Font atlas proper cleanup
** TODO Array-based Hashmaps ** TODO Array-based Hashmaps
** 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 Do input maps really need to be queried by their string names?
** DONE Live data views in editor ** DONE Live data views in editor
- State "DONE" from "TODO" [2017-03-22 Wed 02:14] - State "DONE" from "TODO" [2017-03-22 Wed 02:14]
** DONE Camera resize on window reisze ** DONE Camera resize on window reisze

@ -87,7 +87,8 @@ void scene_setup(void)
int turn_up_keys[1] = {KEY_I}; int turn_up_keys[1] = {KEY_I};
int turn_down_keys[1] = {KEY_K}; int turn_down_keys[1] = {KEY_K};
int sprint_keys[2] = {KEY_LSHIFT, KEY_RSHIFT}; int sprint_keys[2] = {KEY_LSHIFT, KEY_RSHIFT};
int recompute_keys[2] = {KEY_F5, KEY_H}; int recompute_keys[2] = {KEY_F5, KEY_H};
int ed_toggle_keys[1] = {KEY_F1};
input_map_create("Move_Forward", forward_keys, 2); input_map_create("Move_Forward", forward_keys, 2);
input_map_create("Move_Backward", backward_keys, 2); input_map_create("Move_Backward", backward_keys, 2);
input_map_create("Move_Up", up_keys, 1); input_map_create("Move_Up", up_keys, 1);
@ -100,6 +101,7 @@ void scene_setup(void)
input_map_create("Turn_Down", turn_down_keys, 1); input_map_create("Turn_Down", turn_down_keys, 1);
input_map_create("Sprint", sprint_keys, 2); input_map_create("Sprint", sprint_keys, 2);
input_map_create("Recompute", recompute_keys, 2); input_map_create("Recompute", recompute_keys, 2);
input_map_create("Editor_Toggle", ed_toggle_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;
@ -149,8 +151,8 @@ void scene_setup(void)
int y = rand() % num_suz; int y = rand() % num_suz;
int z = rand() % num_suz; int z = rand() % num_suz;
x++; y++; z++; x++; y++; z++;
//struct Entity* suz = scene_add_as_child("Suzanne", NULL, parent_node); struct Entity* suz = scene_add_as_child("Suzanne", NULL, parent_node);
struct Entity* suz = scene_add_new("Suzanne", NULL); //struct Entity* suz = scene_add_new("Suzanne", NULL);
struct Model* suz_model = entity_component_add(suz, C_MODEL, "suzanne.pamesh", "Blinn_Phong"); struct Model* suz_model = entity_component_add(suz, C_MODEL, "suzanne.pamesh", "Blinn_Phong");
model_set_material_param(suz_model, "diffuse_color", &color); model_set_material_param(suz_model, "diffuse_color", &color);
float spec_str = 80.f; float spec_str = 80.f;
@ -211,7 +213,7 @@ void scene_setup(void)
void debug(float dt) void debug(float dt)
{ {
//struct Entity* entity = entity_get(player_node); //struct Entity* entity = entity_get(player_node);
struct Entity* entity = !input_key_state_get('C', KS_PRESSED) ? entity_get(game_state->player_node) : scene_find("Screen_Camera"); struct Entity* entity = entity_get(game_state->player_node);
struct Camera* cam = entity_component_get(entity, C_CAMERA); struct Camera* cam = entity_component_get(entity, C_CAMERA);
camera_set_primary_viewer(cam); camera_set_primary_viewer(cam);
struct Transform* transform = entity_component_get(entity, C_TRANSFORM); struct Transform* transform = entity_component_get(entity, C_TRANSFORM);
@ -235,8 +237,8 @@ void debug(float dt)
log_message("Regenerating Bounding Volumes"); log_message("Regenerating Bounding Volumes");
geom_bounding_volume_generate_all(); geom_bounding_volume_generate_all();
} }
/* if(input_key_state_get(KEY_TAB, KS_PRESSED)) */ /* if(input_is_key_pressed(KEY_TAB, KS_PRESSED)) */
/* if(input_key_state_get(KEY_TAB, KS_PRESSED) && input_key_state_get(KEY_LSHIFT, KS_PRESSED)) input_mouse_mode_set(MM_NORMAL); */ /* 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))
{ {
@ -308,7 +310,7 @@ void debug(float dt)
//log_message("Position : %s", tostr_vec3(&transform->position)); //log_message("Position : %s", tostr_vec3(&transform->position));
} }
if(input_key_state_get(KEY_SPACE, KS_PRESSED)) if(input_is_key_pressed(KEY_SPACE))
{ {
struct Entity* model = scene_find("Model_Entity"); struct Entity* model = scene_find("Model_Entity");
struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM); struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM);
@ -316,7 +318,7 @@ void debug(float dt)
transform_rotate(mod_tran, &x_axis, 25.f * dt, TS_WORLD); transform_rotate(mod_tran, &x_axis, 25.f * dt, TS_WORLD);
} }
if(input_key_state_get(KEY_M, KS_PRESSED)) if(input_is_key_pressed(KEY_M))
{ {
struct Entity* model = scene_find("Model_Entity"); struct Entity* model = scene_find("Model_Entity");
struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM); struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM);
@ -326,7 +328,7 @@ void debug(float dt)
transform_translate(mod_tran, &amount, TS_LOCAL); transform_translate(mod_tran, &amount, TS_LOCAL);
} }
if(input_key_state_get(KEY_N, KS_PRESSED)) if(input_is_key_pressed(KEY_N))
{ {
struct Entity* model = scene_find("Model_Entity"); struct Entity* model = scene_find("Model_Entity");
struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM); struct Transform* mod_tran = entity_component_get(model, C_TRANSFORM);
@ -336,14 +338,14 @@ void debug(float dt)
transform_translate(mod_tran, &amount, TS_LOCAL); transform_translate(mod_tran, &amount, TS_LOCAL);
} }
/* if(input_key_state_get(GLFW_KEY_C, KS_PRESSED)) */ /* if(input_is_key_pressed(GLFW_KEY_C, KS_PRESSED)) */
/* { */ /* { */
/* struct Entity* cam_ent = scene_find("Screen_Camera"); */ /* struct Entity* cam_ent = scene_find("Screen_Camera"); */
/* struct Camera* cam = entity_component_get(cam_ent, C_CAMERA); */ /* struct Camera* cam = entity_component_get(cam_ent, C_CAMERA); */
/* camera_set_primary_viewer(cam); */ /* camera_set_primary_viewer(cam); */
/* } */ /* } */
/* if(input_key_state_get(GLFW_KEY_V, KS_PRESSED)) */ /* if(input_is_key_pressed(GLFW_KEY_V, KS_PRESSED)) */
/* { */ /* { */
/* struct Camera* cam = entity_component_get(entity, C_CAMERA); */ /* struct Camera* cam = entity_component_get(entity, C_CAMERA); */
/* camera_set_priimary_viewer(cam); */ /* camera_set_priimary_viewer(cam); */
@ -370,15 +372,15 @@ void run(void)
} }
void update(float dt, int* window_should_close) void update(float dt, int* window_should_close)
{ {
input_update(); if(input_is_key_pressed(KEY_ESCAPE)) *window_should_close = 1;
if(input_map_state_get("Editor_Toggle", KS_RELEASED)) editor_toggle();
if(input_key_state_get(KEY_ESCAPE, KS_PRESSED)) *window_should_close = 1;
if(input_key_state_get(KEY_F1, KS_PRESSED)) editor_toggle();
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
* put this in post update? */
} }
void debug_gui(float dt) void debug_gui(float dt)

@ -70,6 +70,7 @@ void input_mouse_pos_set(int xpos, int ypos)
void input_on_key(int key, int scancode, int state, int mod_ctrl, int mod_shift) void input_on_key(int key, int scancode, int state, int mod_ctrl, int mod_shift)
{ {
log_message("Key %s", state == KS_PRESSED ? "Pressed" : "Released");
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];
@ -119,25 +120,11 @@ int input_map_state_get(const char* map_name, int state)
result = 1; result = 1;
} }
return result; return result;
}
//return state == current_state ? 1 : 0;
/* if(state == KS_PRESSED) */ int input_is_key_pressed(int key)
/* { */ {
/* if(current_state == KS_PRESSED)// || current_state == GLFW_REPEAT) */ return platform_is_key_pressed(key);
/* return 1; */
/* else */
/* return 0; */
/* } */
/* else */
/* { */
/* return state == current_state ? 1 : 0; */
/* } */
}
int input_key_state_get(int key, int state_type)
{
int current_state = platform_key_state_get(key);
return state_type == current_state ? 1 : 0;
} }
int input_mousebutton_state_get(uint button, int state_type) int input_mousebutton_state_get(uint button, int state_type)

@ -396,7 +396,7 @@ enum Keyboard_Scancode
void input_init(void); void input_init(void);
void input_cleanup(void); void input_cleanup(void);
int input_mousebutton_state_get(uint button, int state_type); int input_mousebutton_state_get(uint button, int state_type);
int input_key_state_get(int key, int state_type); int input_is_key_pressed(int key);
void input_mouse_pos_get(int* xpos, int* ypos); void input_mouse_pos_get(int* xpos, int* ypos);
void input_mouse_delta_get(int* xpos, int* ypos); // Use with relative mouse mode void input_mouse_delta_get(int* xpos, int* ypos); // Use with relative mouse mode
void input_mouse_pos_set(int xpos, int ypos); void input_mouse_pos_set(int xpos, int ypos);

@ -403,22 +403,9 @@ void model_render_all_debug(struct Camera* camera,
struct Entity* entity = entity_get(model->node); struct Entity* entity = entity_get(model->node);
struct Transform* transform = entity_component_get(entity, C_TRANSFORM); struct Transform* transform = entity_component_get(entity, C_TRANSFORM);
int geometry_ac = model->geometry_index; int geometry_ac = model->geometry_index;
struct Bounding_Sphere* sphere = geom_bounding_sphere_get(geometry_ac);
struct Transform temp_trans;
memcpy(&temp_trans, transform, sizeof(struct Transform));
temp_trans.node = -1;
vec3_scale(&temp_trans.scale, &temp_trans.scale, sphere->radius);
transform_update_transmat(&temp_trans);
struct Entity* parent = entity_get(entity->parent);
if(parent)
{
struct Transform* parent_transform = entity_component_get(parent, C_TRANSFORM);
mat4_mul(&temp_trans.trans_mat, &temp_trans.trans_mat, &parent_transform->trans_mat);
}
//log_message("Radius %.3f", sphere->radius);
mat4_identity(&mvp); mat4_identity(&mvp);
//mat4_mul(&mvp, &camera->view_proj_mat, &transform->trans_mat); mat4_mul(&mvp, &camera->view_proj_mat, &transform->trans_mat);
mat4_mul(&mvp, &camera->view_proj_mat, &temp_trans.trans_mat); //mat4_mul(&mvp, &camera->view_proj_mat, &temp_trans.trans_mat);
shader_set_uniform_mat4(debug_shader, "mvp", &mvp); shader_set_uniform_mat4(debug_shader, "mvp", &mvp);
geom_render(geometry, draw_mode); geom_render(geometry, draw_mode);
} }

@ -266,7 +266,7 @@ void platform_windowresize_callback_set(Windowresize_Event_Func func)
platform_state->on_windowresize_func = func; platform_state->on_windowresize_func = func;
} }
int platform_key_state_get(int key) int platform_is_key_pressed(int key)
{ {
/* Returns 1 if key is pressed, 0 otherwise */ /* Returns 1 if key is pressed, 0 otherwise */
const Uint8* keyboard_state = SDL_GetKeyboardState(NULL); const Uint8* keyboard_state = SDL_GetKeyboardState(NULL);

@ -36,7 +36,7 @@ void platform_mousemotion_callback_set(Mousemotion_Event_Func func);
void platform_mousewheel_callback_set(Mousewheel_Event_Func func); void platform_mousewheel_callback_set(Mousewheel_Event_Func func);
void platform_windowresize_callback_set(Windowresize_Event_Func func); void platform_windowresize_callback_set(Windowresize_Event_Func func);
void platform_textinput_callback_set(Textinput_Event_Func func); void platform_textinput_callback_set(Textinput_Event_Func func);
int platform_key_state_get(int key); int platform_is_key_pressed(int key);
int platform_mousebutton_state_get(uint button); int platform_mousebutton_state_get(uint button);
void platform_mouse_position_get(int* x, int* y); void platform_mouse_position_get(int* x, int* y);
void platform_mouse_delta_get(int* x, int* y); // Use with relative mouse mode void platform_mouse_delta_get(int* x, int* y); // Use with relative mouse mode

Loading…
Cancel
Save