Peoplemon  0.1.0
Peoplemon 3 game source documentation
BattleController.hpp
Go to the documentation of this file.
1 #ifndef GAME_BATTLES_BATTLECONTROLLER_HPP
2 #define GAME_BATTLES_BATTLECONTROLLER_HPP
3 
5 #include <cstdint>
6 #include <queue>
7 
8 namespace core
9 {
10 namespace battle
11 {
12 struct Battle;
13 class BattleView;
14 class BattleState;
15 
24 public:
30 
35  virtual ~BattleController() = default;
36 
45 
50  void update();
51 
58  void queueCommand(Command&& command, bool addWait = false);
59 
60 protected:
64 
71  virtual void onCommandQueued(const Command& cmd) = 0;
72 
79  virtual void onCommandProcessed(const Command& cmd) = 0;
80 
88  virtual void onUpdate(bool viewSynced, bool queueEmpty) = 0;
89 
90 private:
91  enum struct SubState : std::uint8_t { WaitingView = 1, Done = 2 };
92 
93  std::queue<Command> commandQueue;
94  SubState subState;
95 
96  bool updateCommandQueue();
97 };
98 } // namespace battle
99 } // namespace core
100 
101 #endif
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...
Definition: Battle.hpp:23
Interface for battle controllers. Battle controllers manage the flow of state and interaction for bat...
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 ~BattleController()=default
Destroy the Battle Controller object.
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...
Definition: BattleState.hpp:18
This is the top level class for rendering battles. It takes commands and state from a BattleControlle...
Definition: BattleView.hpp:29
Emitted by the BattleFSM. All UI is handled via a queue of commands. Commands are resolved in the ord...
Definition: Command.hpp:22