Files
Tower-Defense2/include/td/protocol/command/Commands.h
2025-08-01 13:21:31 +02:00

68 lines
2.0 KiB
C++

#pragma once
/**
* \file Commands.h
* \brief File containing the definitions of the lockstep commands
*/
#include <memory>
#include <sp/common/GenericHandler.h>
#include <sp/protocol/ConcreteMessage.h>
#include <sp/protocol/MessageDispatcher.h>
#include <sp/protocol/MessageFactory.h>
#include <td/Types.h>
#include <td/common/NonCopyable.h>
#include <td/protocol/command/CommandData.h>
#include <sp/io/SerializableMessage.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, CommandBase, ID>;
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::GenericHandler<AllCommands> {};
using CommandDispatcher = sp::MessageDispatcher<CommandBase>;
using CommandFactory = sp::MessageFactory<CommandBase, AllCommands>;
using CommandPtr = sp::SerializableMessage<CommandFactory>;
using LockStep = std::vector<CommandPtr>;
} // namespace protocol
} // namespace td