diff --git a/src/foldhaus_app.cpp b/src/foldhaus_app.cpp index 9de8cd3..4673861 100644 --- a/src/foldhaus_app.cpp +++ b/src/foldhaus_app.cpp @@ -336,12 +336,6 @@ UnloadAssembly (s32 AssemblyIndex, app_state* State, context Context) //////////////////////////////////////////////////////////////////////// -internal void -RegisterTextEntryCommands (input_command_registry* CommandRegistry) -{ - -} - RELOAD_STATIC_DATA(ReloadStaticData) { app_state* State = (app_state*)Context.MemoryBase; @@ -515,27 +509,20 @@ UPDATE_AND_RENDER(UpdateAndRender) { input_entry Event = InputQueue.Entries[EventIdx]; - input_command* Command = FindExistingCommand(ActiveCommands, Event.Key, (key_code)0); - if (Command) + // NOTE(Peter): These are in the order Down, Up, Held because we want to privalege + // Down and Up over Held. In other words, we don't want to call a Held command on the + // frame when the button was released, even if the command is registered to both events + if (KeyTransitionedDown(Event)) { - if ((KeyTransitionedDown(Event) && ((Command->Flags & Command_Began) > 0))) - { - PushCommandOnQueue(&State->CommandQueue, - *Command, - Event, - (Command->Flags & Command_Held) == 0); - } - else if (KeyTransitionedUp(Event) && ((Command->Flags & Command_Ended) > 0)) - { - if ((Command->Flags & Command_Held) == 0) - { - PushCommandOnQueue(&State->CommandQueue, *Command, Event, true); - } - else - { - FlagCommandForRemoval(&State->CommandQueue, *Command, Event); - } - } + FindAndPushExistingCommand(State->ActiveCommands, Event, Command_Began, &State->CommandQueue); + } + else if (KeyTransitionedUp(Event)) + { + FindAndPushExistingCommand(State->ActiveCommands, Event, Command_Ended, &State->CommandQueue); + } + else if (KeyHeldDown(Event)) + { + FindAndPushExistingCommand(State->ActiveCommands, Event, Command_Held, &State->CommandQueue); } if (Event.Key == KeyCode_MouseLeftButton) diff --git a/src/foldhaus_app.h b/src/foldhaus_app.h index 1dd3ac8..57126ad 100644 --- a/src/foldhaus_app.h +++ b/src/foldhaus_app.h @@ -102,8 +102,6 @@ struct app_state node_render_settings NodeRenderSettings; - - string GeneralPurposeSearchString; }; diff --git a/src/foldhaus_command_dispatch.cpp b/src/foldhaus_command_dispatch.cpp index 03c5604..9e9baf3 100644 --- a/src/foldhaus_command_dispatch.cpp +++ b/src/foldhaus_command_dispatch.cpp @@ -8,47 +8,6 @@ InitializeInputCommandRegistry (input_command_registry* CommandRegistry, CommandRegistry->Used = 0; } -internal input_command* -FindExistingCommand (input_command_registry* CommandRegistry, key_code Key, key_code Mdfr) -{ - input_command* Result = 0; - - for (s32 Cmd = 0; Cmd < CommandRegistry->Used; Cmd++) - { - input_command* Command = CommandRegistry->Commands + Cmd; - if (Command->Key == Key && Command->Mdfr == Mdfr) - { - Result = Command; - break; - } - } - - return Result; -} - -internal void -RegisterKeyPressCommand (input_command_registry* CommandRegistry, - key_code Key, - b32 Flags, - key_code Mdfr, - input_command_proc* Proc) -{ - input_command* Command = FindExistingCommand(CommandRegistry, Key, Mdfr); - - if (!Command) - { - Assert(CommandRegistry->Size > CommandRegistry->Used); - Assert(Mdfr == KeyCode_Invalid || Mdfr == KeyCode_LeftShift || Mdfr == KeyCode_RightShift || - Mdfr == KeyCode_LeftCtrl || Mdfr == KeyCode_RightCtrl || Mdfr == KeyCode_Alt); - Command = CommandRegistry->Commands + CommandRegistry->Used++; - } - - Command->Key = Key; - Command->Flags = Flags; - Command->Mdfr = Mdfr; - Command->Proc = Proc; -} - internal void RegisterMouseWheelCommand (input_command_registry* CommandRegistry, input_command_proc* Proc) @@ -85,6 +44,7 @@ InitializeCommandQueue(command_queue_entry* Memory, s32 MemorySize) internal void RemoveNonPersistantCommandsFromQueueAndUpdatePersistentEvents(input_command_queue* Queue) { +#if 0 s32 PersistantCommandsCount = 0; for (s32 i = 0; i < Queue->Used; i++) { @@ -102,26 +62,21 @@ RemoveNonPersistantCommandsFromQueueAndUpdatePersistentEvents(input_command_queu } } Queue->Used = PersistantCommandsCount; +#else + Queue->Used = 0; +#endif } internal void -PushCommandOnQueue(input_command_queue* Queue, input_command Command, input_entry Event, b32 RemoveOnExecute) +PushCommandOnQueue(input_command_queue* Queue, input_command Command, input_entry Event) { Assert(Queue->Used < Queue->Size); command_queue_entry Entry = {}; Entry.Command = Command; Entry.Event = Event; - Entry.RemoveOnExecute = RemoveOnExecute; Queue->Commands[Queue->Used++] = Entry; } -internal void -FlagCommandForRemoval(input_command_queue* Queue, input_command Command, input_entry Event) -{ - s32 CommandIndex = GetCommandIndexInQueue(Queue, Command, Event); - Queue->Commands[CommandIndex].RemoveOnExecute = true; -} - internal void RemoveCommandFromQueue(input_command_queue* Queue, s32 Index) { @@ -169,4 +124,62 @@ ActivateQueuedCommandRegistry (app_state* State) State->ActiveCommands = State->NextCommandRegistry; State->NextCommandRegistry = 0; } -} \ No newline at end of file +} + +internal input_command* +FindExistingCommand (input_command_registry* CommandRegistry, key_code Key, key_code Mdfr, b32 Flags) +{ + input_command* Result = 0; + + for (s32 Cmd = 0; Cmd < CommandRegistry->Used; Cmd++) + { + input_command* Command = CommandRegistry->Commands + Cmd; + if (Command->Key == Key && Command->Mdfr == Mdfr) + { + b32 FlagsOverlap = Flags & Command->Flags; + if (FlagsOverlap) + { + Result = Command; + break; + } + } + } + + return Result; +} + +internal b32 +FindAndPushExistingCommand(input_command_registry* CommandRegistry, input_entry Event, b32 Flags, input_command_queue* CommandQueue) +{ + b32 CommandFound = false; + input_command* Command = FindExistingCommand(CommandRegistry, Event.Key, (key_code)0, Flags); + if (Command) + { + PushCommandOnQueue(CommandQueue, *Command, Event); + CommandFound = true; + } + return CommandFound; +} + +internal void +RegisterKeyPressCommand (input_command_registry* CommandRegistry, + key_code Key, + b32 Flags, + key_code Mdfr, + input_command_proc* Proc) +{ + input_command* Command = FindExistingCommand(CommandRegistry, Key, Mdfr, Flags); + + if (!Command) + { + Assert(CommandRegistry->Size > CommandRegistry->Used); + Assert(Mdfr == KeyCode_Invalid || Mdfr == KeyCode_LeftShift || Mdfr == KeyCode_RightShift || + Mdfr == KeyCode_LeftCtrl || Mdfr == KeyCode_RightCtrl || Mdfr == KeyCode_Alt); + Command = CommandRegistry->Commands + CommandRegistry->Used++; + } + + Command->Key = Key; + Command->Flags = Flags; + Command->Mdfr = Mdfr; + Command->Proc = Proc; +} diff --git a/src/foldhaus_command_dispatch.h b/src/foldhaus_command_dispatch.h index 8f26752..5fa3d0c 100644 --- a/src/foldhaus_command_dispatch.h +++ b/src/foldhaus_command_dispatch.h @@ -8,6 +8,8 @@ enum input_command_flags Command_Ended = 1 << 2, }; +#define Command_Any Command_Began | Command_Held | Command_Ended + // TODO(Peter): At the moment these are all key press commands. Need a way to differentiate between // press and hold. Probably add a second array to input_command_Registry struct input_command @@ -31,7 +33,6 @@ struct command_queue_entry { input_command Command; input_entry Event; - b32 RemoveOnExecute; }; struct input_command_queue diff --git a/todo.txt b/todo.txt index 252185e..2b9a76a 100644 --- a/todo.txt +++ b/todo.txt @@ -8,7 +8,7 @@ x Allow one operation at a time at first x Push/pop operations on a list? - Current Operations: - - View Sculpture (this might be an exception since its so central) -x - View/Edit Nodes +- x View/Edit Nodes - x Add Node (needs nesting) - x View SACN