setup consumer tracking on consumer's side
parent
e49249c7e4
commit
86f0537690
70
4ed.cpp
70
4ed.cpp
|
@ -3160,10 +3160,15 @@ enum Input_Types{
|
||||||
Input_Count
|
Input_Count
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Consumption_Record{
|
||||||
|
b32 consumed;
|
||||||
|
char consumer[32];
|
||||||
|
};
|
||||||
|
|
||||||
struct Available_Input{
|
struct Available_Input{
|
||||||
Key_Summary *keys;
|
Key_Summary *keys;
|
||||||
Mouse_State *mouse;
|
Mouse_State *mouse;
|
||||||
b32 consumed[Input_Count];
|
Consumption_Record records[Input_Count];
|
||||||
};
|
};
|
||||||
|
|
||||||
Available_Input
|
Available_Input
|
||||||
|
@ -3178,10 +3183,10 @@ Key_Summary
|
||||||
get_key_data(Available_Input *available){
|
get_key_data(Available_Input *available){
|
||||||
Key_Summary result = {0};
|
Key_Summary result = {0};
|
||||||
|
|
||||||
if (!available->consumed[Input_AnyKey]){
|
if (!available->records[Input_AnyKey].consumed){
|
||||||
result = *available->keys;
|
result = *available->keys;
|
||||||
}
|
}
|
||||||
else if (!available->consumed[Input_Esc]){
|
else if (!available->records[Input_Esc].consumed){
|
||||||
i32 i = 0;
|
i32 i = 0;
|
||||||
i32 count = available->keys->count;
|
i32 count = available->keys->count;
|
||||||
Key_Event_Data key = {0};
|
Key_Event_Data key = {0};
|
||||||
|
@ -3202,19 +3207,19 @@ get_key_data(Available_Input *available){
|
||||||
Mouse_State
|
Mouse_State
|
||||||
get_mouse_state(Available_Input *available){
|
get_mouse_state(Available_Input *available){
|
||||||
Mouse_State mouse = *available->mouse;
|
Mouse_State mouse = *available->mouse;
|
||||||
if (available->consumed[Input_MouseLeftButton]){
|
if (available->records[Input_MouseLeftButton].consumed){
|
||||||
mouse.l = 0;
|
mouse.l = 0;
|
||||||
mouse.press_l = 0;
|
mouse.press_l = 0;
|
||||||
mouse.release_l = 0;
|
mouse.release_l = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (available->consumed[Input_MouseRightButton]){
|
if (available->records[Input_MouseRightButton].consumed){
|
||||||
mouse.r = 0;
|
mouse.r = 0;
|
||||||
mouse.press_r = 0;
|
mouse.press_r = 0;
|
||||||
mouse.release_r = 0;
|
mouse.release_r = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (available->consumed[Input_MouseWheel]){
|
if (available->records[Input_MouseWheel].consumed){
|
||||||
mouse.wheel = 0;
|
mouse.wheel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3222,8 +3227,14 @@ get_mouse_state(Available_Input *available){
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
consume_input(Available_Input *available, i32 input_type){
|
consume_input(Available_Input *available, i32 input_type, char *consumer){
|
||||||
available->consumed[input_type] = 1;
|
Consumption_Record *record = &available->records[input_type];
|
||||||
|
record->consumed = 1;
|
||||||
|
if (consumer){
|
||||||
|
String str = make_fixed_width_string(record->consumer);
|
||||||
|
copy(&str, consumer);
|
||||||
|
terminate_with_null(&str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
App_Step_Sig(app_step){
|
App_Step_Sig(app_step){
|
||||||
|
@ -3559,7 +3570,7 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE(allen): Pass keyboard events to debug
|
// NOTE(allen): pass events to debug
|
||||||
Available_Input available_input = init_available_input(&key_summary, &input->mouse);
|
Available_Input available_input = init_available_input(&key_summary, &input->mouse);
|
||||||
|
|
||||||
#if FRED_INTERNAL
|
#if FRED_INTERNAL
|
||||||
|
@ -3572,6 +3583,7 @@ App_Step_Sig(app_step){
|
||||||
i32 count = key_data.count;
|
i32 count = key_data.count;
|
||||||
i32 preserved_inputs = ArrayCount(debug->input_events) - count;
|
i32 preserved_inputs = ArrayCount(debug->input_events) - count;
|
||||||
|
|
||||||
|
debug->this_frame_count = count;
|
||||||
memmove(events + count, events,
|
memmove(events + count, events,
|
||||||
sizeof(Debug_Input_Event)*preserved_inputs);
|
sizeof(Debug_Input_Event)*preserved_inputs);
|
||||||
|
|
||||||
|
@ -3579,6 +3591,8 @@ App_Step_Sig(app_step){
|
||||||
Key_Event_Data key = get_single_key(&key_data, i);
|
Key_Event_Data key = get_single_key(&key_data, i);
|
||||||
events[i].key = key.keycode;
|
events[i].key = key.keycode;
|
||||||
|
|
||||||
|
events[i].consumer[0] = 0;
|
||||||
|
|
||||||
events[i].is_hold = key.modifiers[MDFR_HOLD_INDEX];
|
events[i].is_hold = key.modifiers[MDFR_HOLD_INDEX];
|
||||||
events[i].is_ctrl = key.modifiers[MDFR_CONTROL_INDEX];
|
events[i].is_ctrl = key.modifiers[MDFR_CONTROL_INDEX];
|
||||||
events[i].is_alt = key.modifiers[MDFR_ALT_INDEX];
|
events[i].is_alt = key.modifiers[MDFR_ALT_INDEX];
|
||||||
|
@ -3625,13 +3639,15 @@ App_Step_Sig(app_step){
|
||||||
|
|
||||||
if (EventOnAnyKey & get_flags){
|
if (EventOnAnyKey & get_flags){
|
||||||
pass_in = 1;
|
pass_in = 1;
|
||||||
consume_input(&available_input, Input_AnyKey);
|
consume_input(&available_input, Input_AnyKey,
|
||||||
|
"command coroutine");
|
||||||
}
|
}
|
||||||
if (key.keycode == key_esc){
|
if (key.keycode == key_esc){
|
||||||
if (EventOnEsc & get_flags){
|
if (EventOnEsc & get_flags){
|
||||||
pass_in = 1;
|
pass_in = 1;
|
||||||
}
|
}
|
||||||
consume_input(&available_input, Input_Esc);
|
consume_input(&available_input, Input_Esc,
|
||||||
|
"command coroutine");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pass_in){
|
if (pass_in){
|
||||||
|
@ -3670,7 +3686,8 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
if (get_flags & EventOnMouseMove){
|
if (get_flags & EventOnMouseMove){
|
||||||
pass_in = 1;
|
pass_in = 1;
|
||||||
consume_input(&available_input, Input_MouseMove);
|
consume_input(&available_input, Input_MouseMove,
|
||||||
|
"command coroutine");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input->mouse.press_l || input->mouse.release_l || input->mouse.l){
|
if (input->mouse.press_l || input->mouse.release_l || input->mouse.l){
|
||||||
|
@ -3679,7 +3696,8 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
if (get_flags & EventOnLeftButton){
|
if (get_flags & EventOnLeftButton){
|
||||||
pass_in = 1;
|
pass_in = 1;
|
||||||
consume_input(&available_input, Input_MouseLeftButton);
|
consume_input(&available_input, Input_MouseLeftButton,
|
||||||
|
"command coroutine");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3689,7 +3707,8 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
if (get_flags & EventOnRightButton){
|
if (get_flags & EventOnRightButton){
|
||||||
pass_in = 1;
|
pass_in = 1;
|
||||||
consume_input(&available_input, Input_MouseRightButton);
|
consume_input(&available_input, Input_MouseRightButton,
|
||||||
|
"command coroutine");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3699,7 +3718,8 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
if (get_flags & EventOnWheel){
|
if (get_flags & EventOnWheel){
|
||||||
pass_in = 1;
|
pass_in = 1;
|
||||||
consume_input(&available_input, Input_MouseWheel);
|
consume_input(&available_input, Input_MouseWheel,
|
||||||
|
"command coroutine");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3757,10 +3777,12 @@ App_Step_Sig(app_step){
|
||||||
app_result.animating = 1;
|
app_result.animating = 1;
|
||||||
}
|
}
|
||||||
if (result.consume_keys){
|
if (result.consume_keys){
|
||||||
consume_input(&available_input, Input_AnyKey);
|
consume_input(&available_input, Input_AnyKey,
|
||||||
|
"step_file_view");
|
||||||
}
|
}
|
||||||
if (result.consume_keys || result.consume_esc){
|
if (result.consume_keys || result.consume_esc){
|
||||||
consume_input(&available_input, Input_Esc);
|
consume_input(&available_input, Input_Esc,
|
||||||
|
"step_file_view");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (view->changed_context_in_step == 0){
|
if (view->changed_context_in_step == 0){
|
||||||
|
@ -3846,15 +3868,25 @@ App_Step_Sig(app_step){
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hit_something){
|
if (hit_something){
|
||||||
consume_input(&available_input, Input_AnyKey);
|
consume_input(&available_input, Input_AnyKey,
|
||||||
|
"command dispatcher");
|
||||||
}
|
}
|
||||||
if (hit_esc){
|
if (hit_esc){
|
||||||
consume_input(&available_input, Input_Esc);
|
consume_input(&available_input, Input_Esc,
|
||||||
|
"command dispatcher");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
update_command_data(vars, cmd);
|
update_command_data(vars, cmd);
|
||||||
|
|
||||||
|
// NOTE(allen): pass consumption data to debug
|
||||||
|
#if FRED_INTERNAL
|
||||||
|
{
|
||||||
|
//Debug_Data *debug = &models->debug;
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// NOTE(allen): initialize message
|
// NOTE(allen): initialize message
|
||||||
if (input->first_step){
|
if (input->first_step){
|
||||||
String welcome =
|
String welcome =
|
||||||
|
|
|
@ -26,6 +26,8 @@ struct App_Settings{
|
||||||
struct Debug_Input_Event{
|
struct Debug_Input_Event{
|
||||||
char key;
|
char key;
|
||||||
|
|
||||||
|
char consumer[32];
|
||||||
|
|
||||||
b8 is_hold;
|
b8 is_hold;
|
||||||
b8 is_ctrl;
|
b8 is_ctrl;
|
||||||
b8 is_alt;
|
b8 is_alt;
|
||||||
|
@ -34,6 +36,7 @@ struct Debug_Input_Event{
|
||||||
|
|
||||||
struct Debug_Data{
|
struct Debug_Data{
|
||||||
Debug_Input_Event input_events[16];
|
Debug_Input_Event input_events[16];
|
||||||
|
i32 this_frame_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Models{
|
struct Models{
|
||||||
|
|
|
@ -4358,9 +4358,12 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
message = string_zero();
|
message = string_zero();
|
||||||
switch (buffer_get_sync(file)){
|
|
||||||
case SYNC_BEHIND_OS: message = message_unsynced; break;
|
if (!file->settings.unimportant){
|
||||||
case SYNC_UNSAVED: message = message_unsaved; break;
|
switch (buffer_get_sync(file)){
|
||||||
|
case SYNC_BEHIND_OS: message = message_unsynced; break;
|
||||||
|
case SYNC_UNSAVED: message = message_unsaved; break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
id.id[0] = (u64)(file);
|
id.id[0] = (u64)(file);
|
||||||
|
@ -4480,8 +4483,11 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
|
||||||
// - Command maps inspection
|
// - Command maps inspection
|
||||||
|
|
||||||
String empty_str = string_zero();
|
String empty_str = string_zero();
|
||||||
char space[512];
|
|
||||||
String string = make_fixed_width_string(space);
|
char space1[512];
|
||||||
|
String string = make_fixed_width_string(space1);
|
||||||
|
|
||||||
|
String message = string_zero();
|
||||||
|
|
||||||
// Time Watcher
|
// Time Watcher
|
||||||
{
|
{
|
||||||
|
@ -4572,7 +4578,12 @@ step_file_view(System_Functions *system, View *view, View *active_view, Input_Su
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gui_do_text_field(target, string, empty_str);
|
message.size = 0;
|
||||||
|
if (input_event->consumer[0] != 0){
|
||||||
|
message = make_string_slowly(input_event->consumer);
|
||||||
|
}
|
||||||
|
|
||||||
|
gui_do_text_field(target, string, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}break;
|
}break;
|
||||||
|
|
Loading…
Reference in New Issue