Improved function of the Input Command Dispatch
This commit is contained in:
parent
22e15858e5
commit
d90b275cff
|
@ -336,12 +336,6 @@ UnloadAssembly (s32 AssemblyIndex, app_state* State, context Context)
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
internal void
|
|
||||||
RegisterTextEntryCommands (input_command_registry* CommandRegistry)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
RELOAD_STATIC_DATA(ReloadStaticData)
|
RELOAD_STATIC_DATA(ReloadStaticData)
|
||||||
{
|
{
|
||||||
app_state* State = (app_state*)Context.MemoryBase;
|
app_state* State = (app_state*)Context.MemoryBase;
|
||||||
|
@ -515,27 +509,20 @@ UPDATE_AND_RENDER(UpdateAndRender)
|
||||||
{
|
{
|
||||||
input_entry Event = InputQueue.Entries[EventIdx];
|
input_entry Event = InputQueue.Entries[EventIdx];
|
||||||
|
|
||||||
input_command* Command = FindExistingCommand(ActiveCommands, Event.Key, (key_code)0);
|
// NOTE(Peter): These are in the order Down, Up, Held because we want to privalege
|
||||||
if (Command)
|
// 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)))
|
FindAndPushExistingCommand(State->ActiveCommands, Event, Command_Began, &State->CommandQueue);
|
||||||
{
|
}
|
||||||
PushCommandOnQueue(&State->CommandQueue,
|
else if (KeyTransitionedUp(Event))
|
||||||
*Command,
|
{
|
||||||
Event,
|
FindAndPushExistingCommand(State->ActiveCommands, Event, Command_Ended, &State->CommandQueue);
|
||||||
(Command->Flags & Command_Held) == 0);
|
}
|
||||||
}
|
else if (KeyHeldDown(Event))
|
||||||
else if (KeyTransitionedUp(Event) && ((Command->Flags & Command_Ended) > 0))
|
{
|
||||||
{
|
FindAndPushExistingCommand(State->ActiveCommands, Event, Command_Held, &State->CommandQueue);
|
||||||
if ((Command->Flags & Command_Held) == 0)
|
|
||||||
{
|
|
||||||
PushCommandOnQueue(&State->CommandQueue, *Command, Event, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FlagCommandForRemoval(&State->CommandQueue, *Command, Event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Event.Key == KeyCode_MouseLeftButton)
|
if (Event.Key == KeyCode_MouseLeftButton)
|
||||||
|
|
|
@ -102,8 +102,6 @@ struct app_state
|
||||||
|
|
||||||
node_render_settings NodeRenderSettings;
|
node_render_settings NodeRenderSettings;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
string GeneralPurposeSearchString;
|
string GeneralPurposeSearchString;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -8,47 +8,6 @@ InitializeInputCommandRegistry (input_command_registry* CommandRegistry,
|
||||||
CommandRegistry->Used = 0;
|
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
|
internal void
|
||||||
RegisterMouseWheelCommand (input_command_registry* CommandRegistry,
|
RegisterMouseWheelCommand (input_command_registry* CommandRegistry,
|
||||||
input_command_proc* Proc)
|
input_command_proc* Proc)
|
||||||
|
@ -85,6 +44,7 @@ InitializeCommandQueue(command_queue_entry* Memory, s32 MemorySize)
|
||||||
internal void
|
internal void
|
||||||
RemoveNonPersistantCommandsFromQueueAndUpdatePersistentEvents(input_command_queue* Queue)
|
RemoveNonPersistantCommandsFromQueueAndUpdatePersistentEvents(input_command_queue* Queue)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
s32 PersistantCommandsCount = 0;
|
s32 PersistantCommandsCount = 0;
|
||||||
for (s32 i = 0; i < Queue->Used; i++)
|
for (s32 i = 0; i < Queue->Used; i++)
|
||||||
{
|
{
|
||||||
|
@ -102,26 +62,21 @@ RemoveNonPersistantCommandsFromQueueAndUpdatePersistentEvents(input_command_queu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Queue->Used = PersistantCommandsCount;
|
Queue->Used = PersistantCommandsCount;
|
||||||
|
#else
|
||||||
|
Queue->Used = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
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);
|
Assert(Queue->Used < Queue->Size);
|
||||||
command_queue_entry Entry = {};
|
command_queue_entry Entry = {};
|
||||||
Entry.Command = Command;
|
Entry.Command = Command;
|
||||||
Entry.Event = Event;
|
Entry.Event = Event;
|
||||||
Entry.RemoveOnExecute = RemoveOnExecute;
|
|
||||||
Queue->Commands[Queue->Used++] = Entry;
|
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
|
internal void
|
||||||
RemoveCommandFromQueue(input_command_queue* Queue, s32 Index)
|
RemoveCommandFromQueue(input_command_queue* Queue, s32 Index)
|
||||||
{
|
{
|
||||||
|
@ -169,4 +124,62 @@ ActivateQueuedCommandRegistry (app_state* State)
|
||||||
State->ActiveCommands = State->NextCommandRegistry;
|
State->ActiveCommands = State->NextCommandRegistry;
|
||||||
State->NextCommandRegistry = 0;
|
State->NextCommandRegistry = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@ enum input_command_flags
|
||||||
Command_Ended = 1 << 2,
|
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
|
// 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
|
// press and hold. Probably add a second array to input_command_Registry
|
||||||
struct input_command
|
struct input_command
|
||||||
|
@ -31,7 +33,6 @@ struct command_queue_entry
|
||||||
{
|
{
|
||||||
input_command Command;
|
input_command Command;
|
||||||
input_entry Event;
|
input_entry Event;
|
||||||
b32 RemoveOnExecute;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct input_command_queue
|
struct input_command_queue
|
||||||
|
|
2
todo.txt
2
todo.txt
|
@ -8,7 +8,7 @@ x Allow one operation at a time at first
|
||||||
x Push/pop operations on a list?
|
x Push/pop operations on a list?
|
||||||
- Current Operations:
|
- Current Operations:
|
||||||
- - View Sculpture (this might be an exception since its so central)
|
- - 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 Add Node (needs nesting)
|
||||||
- x View SACN
|
- x View SACN
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue