2019-11-01 12:46:40 +00:00
|
|
|
typedef struct operation_mode operation_mode;
|
|
|
|
|
2019-11-01 14:38:44 +00:00
|
|
|
#define OPERATION_RENDER_PROC(name) void name(app_state* State, render_command_buffer* RenderBuffer, operation_mode Operation, mouse_state Mouse)
|
2019-11-01 12:46:40 +00:00
|
|
|
typedef OPERATION_RENDER_PROC(operation_render_proc);
|
|
|
|
|
2019-11-01 11:17:46 +00:00
|
|
|
struct operation_mode
|
|
|
|
{
|
|
|
|
input_command_registry Commands;
|
2019-11-01 12:46:40 +00:00
|
|
|
operation_render_proc* Render;
|
|
|
|
u8* OpStateMemory;
|
2019-11-01 11:17:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define OPERATION_MODES_MAX 32
|
|
|
|
struct operation_mode_system
|
|
|
|
{
|
|
|
|
s32 ActiveModesCount;
|
|
|
|
operation_mode ActiveModes[OPERATION_MODES_MAX];
|
2019-11-01 12:46:40 +00:00
|
|
|
arena_snapshot ModeMemorySnapshots[OPERATION_MODES_MAX];
|
|
|
|
|
|
|
|
// NOTE(Peter): This acts as mode scoped memory. When a mode gets activated, it can allocate
|
|
|
|
// temporary memory which then gets freed when the mode is deactivated
|
|
|
|
memory_arena Arena;
|
2019-11-01 11:17:46 +00:00
|
|
|
};
|
|
|
|
|
2019-11-01 12:46:40 +00:00
|
|
|
internal operation_mode*
|
2019-11-12 04:34:56 +00:00
|
|
|
ActivateOperationMode (operation_mode_system* System)
|
2019-11-01 11:17:46 +00:00
|
|
|
{
|
|
|
|
Assert(System->ActiveModesCount < OPERATION_MODES_MAX);
|
2019-11-01 12:46:40 +00:00
|
|
|
s32 ModeIndex = System->ActiveModesCount++;
|
2019-11-02 17:29:51 +00:00
|
|
|
|
2019-11-01 12:46:40 +00:00
|
|
|
System->ModeMemorySnapshots[ModeIndex] = TakeSnapshotOfArena(System->Arena);
|
2019-11-02 17:29:51 +00:00
|
|
|
|
|
|
|
operation_mode NewMode = {};
|
|
|
|
System->ActiveModes[ModeIndex] = NewMode;
|
|
|
|
|
2019-11-01 12:46:40 +00:00
|
|
|
return &System->ActiveModes[ModeIndex];
|
2019-11-01 11:17:46 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 04:34:56 +00:00
|
|
|
#define ActivateOperationModeWithCommands(sys, cmds) \
|
|
|
|
ActivateOperationModeWithCommands_(sys, cmds, (s32)(sizeof(cmds) / sizeof(cmds[0])));
|
2019-11-02 17:29:51 +00:00
|
|
|
|
|
|
|
internal operation_mode*
|
2019-11-12 04:34:56 +00:00
|
|
|
ActivateOperationModeWithCommands_(operation_mode_system* System, input_command* Commands, s32 CommandsCount)
|
2019-11-02 17:29:51 +00:00
|
|
|
{
|
2019-11-12 04:34:56 +00:00
|
|
|
operation_mode* NewMode = ActivateOperationMode(System);
|
2019-11-02 17:29:51 +00:00
|
|
|
|
|
|
|
InitializeInputCommandRegistry(&NewMode->Commands, CommandsCount, &System->Arena);
|
|
|
|
for (s32 i = 0; i < CommandsCount; i++)
|
|
|
|
{
|
|
|
|
input_command Command = Commands[i];
|
|
|
|
RegisterKeyPressCommand(&NewMode->Commands, Command.Key, Command.Flags, Command.Mdfr, Command.Proc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewMode;
|
|
|
|
}
|
|
|
|
|
2019-11-01 11:17:46 +00:00
|
|
|
internal void
|
|
|
|
DeactivateCurrentOperationMode (operation_mode_system* System)
|
|
|
|
{
|
|
|
|
Assert(System->ActiveModesCount > 0);
|
2019-11-01 12:46:40 +00:00
|
|
|
s32 ModeIndex = --System->ActiveModesCount;
|
|
|
|
ClearArenaToSnapshot(&System->Arena, System->ModeMemorySnapshots[ModeIndex]);
|
2019-11-01 13:16:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define CreateOperationState(mode, modeSystem, stateType) \
|
|
|
|
(stateType*)CreateOperationState_(mode, modeSystem, sizeof(stateType))
|
|
|
|
|
2019-11-02 17:29:51 +00:00
|
|
|
#define GetCurrentOperationState(modeSystem, stateType) \
|
|
|
|
(stateType*)State->Modes.ActiveModes[State->Modes.ActiveModesCount - 1].OpStateMemory;
|
|
|
|
|
|
|
|
|
2019-11-01 13:16:30 +00:00
|
|
|
internal u8*
|
|
|
|
CreateOperationState_ (operation_mode* Mode, operation_mode_system* System, s32 StateSize)
|
|
|
|
{
|
|
|
|
Mode->OpStateMemory = PushSize(&System->Arena, StateSize);
|
|
|
|
return Mode->OpStateMemory;
|
2019-11-02 17:29:51 +00:00
|
|
|
}
|