3 #include <BLIB/Logging.hpp>
14 , subState(SubState::Done) {}
24 case SubState::WaitingView:
26 subState = SubState::Done;
35 if (!commandQueue.empty()) {
36 while (updateCommandQueue()) {}
41 BL_LOG_WARN <<
"Unknown substate: " << subState;
42 subState = SubState::Done;
50 commandQueue.emplace(std::forward<Command>(cmd));
58 bool BattleController::updateCommandQueue() {
59 if (commandQueue.empty())
return false;
61 const Command cmd = std::move(commandQueue.front());
66 case Command::Type::DisplayMessage:
67 case Command::Type::PlayAnimation:
68 case Command::Type::SyncStateNoSwitch:
69 case Command::Type::SyncStateSwitch:
73 case Command::Type::WaitForView:
74 subState = SubState::WaitingView;
77 case Command::Type::NotifyBattleWinner:
82 BL_LOG_WARN <<
"Unknown command type: " << cmd.
getType();
Core classes and functionality for both the editor and game.
Convenience struct that owns all the components required for a battle and resolves some boilerplate s...
void init(Battle &battle, BattleView &view, BattleState &state)
Sets internal references to the view and state of the battle.
void queueCommand(Command &&command, bool addWait=false)
Enqueues a command to manipulate battle state or the view.
void update()
Updates the processing of the command queue.
BattleController()
Initializes some internal state.
virtual void onCommandQueued(const Command &cmd)=0
Called when a command is first enqueued but not processed. May be used to send commands over the netw...
virtual void onCommandProcessed(const Command &cmd)=0
This is called after a command is processed. Derived classes may perform specific actions for command...
virtual void onUpdate(bool viewSynced, bool queueEmpty)=0
Derived controllers may use this method for update logic every frame.
Stores and represents the current state of a battle. This is the base class for local and remote batt...
This is the top level class for rendering battles. It takes commands and state from a BattleControlle...
void hideText()
Hides the battle text when the view is synced.
void processCommand(const Command &command)
Processes a command and updates the view.
bool actionsCompleted() const
Returns true if the view is done going through the queued commands and all components are synchronize...
Emitted by the BattleFSM. All UI is handled via a queue of commands. Commands are resolved in the ord...
Type getType() const
Returns the type of this command.