Files
Tower-Defense2/include/td/protocol/command/Commands.h
2025-07-10 16:34:28 +02:00

64 lines
1.9 KiB
C++

#pragma once
/**
* \file Commands.h
* \brief File containing the definitions of the lockstep commands
*/
#include <memory>
#include <sp/protocol/ConcreteMessage.h>
#include <sp/protocol/MessageDispatcher.h>
#include <sp/protocol/MessageFactory.h>
#include <sp/protocol/MessageHandler.h>
#include <td/Types.h>
#include <td/common/NonCopyable.h>
#include <td/protocol/command/CommandData.h>
namespace td {
namespace protocol {
/** A Command id is 8 bits wide */
enum class CommandID : std::uint8_t {
End = 0,
PlaceTower,
PlayerJoin,
SpawnTroop,
TeamChange,
UpgradeTower,
UseItem,
};
class CommandHandler;
using CommandBase = sp::MessageBase<CommandID, CommandHandler>;
template <typename TData, CommandID ID>
using CommandMessage = sp::ConcreteMessage<TData, CommandID, ID, CommandHandler>;
namespace commands {
using EndCommand = CommandMessage<cdata::End, CommandID::End>;
using PlaceTowerCommand = CommandMessage<cdata::PlaceTower, CommandID::PlaceTower>;
using PlayerJoinCommand = CommandMessage<cdata::PlayerJoin, CommandID::PlayerJoin>;
using SpawnTroopCommand = CommandMessage<cdata::SpawnTroop, CommandID::SpawnTroop>;
using TeamChangeCommand = CommandMessage<cdata::TeamChange, CommandID::TeamChange>;
using UpgradeTowerCommand = CommandMessage<cdata::UpgradeTower, CommandID::UpgradeTower>;
using UseItemCommand = CommandMessage<cdata::UseItem, CommandID::UseItem>;
} // namespace commands
using AllCommands = std::tuple<commands::EndCommand, commands::PlaceTowerCommand, commands::PlayerJoinCommand,
commands::SpawnTroopCommand, commands::TeamChangeCommand, commands::UpgradeTowerCommand, commands::UseItemCommand>;
class CommandHandler : public sp::MessageHandler<AllCommands> {};
using CommandDispatcher = sp::MessageDispatcher<CommandBase>;
using CommandFactory = sp::MessageFactory<CommandBase, AllCommands>;
using LockStep = std::vector<std::shared_ptr<CommandBase>>;
} // namespace protocol
} // namespace td