mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
milek7/sim branch network code import
This commit is contained in:
75
command.h
75
command.h
@@ -260,13 +260,42 @@ enum class user_command {
|
||||
speedcontrolbutton7,
|
||||
speedcontrolbutton8,
|
||||
speedcontrolbutton9,
|
||||
|
||||
globalradiostop,
|
||||
timejump,
|
||||
timejumplarge,
|
||||
timejumpsmall,
|
||||
setdatetime,
|
||||
setweather,
|
||||
settemperature,
|
||||
vehiclemoveforwards,
|
||||
vehiclemovebackwards,
|
||||
vehicleboost,
|
||||
debugtoggle,
|
||||
focuspauseset,
|
||||
pausetoggle,
|
||||
entervehicle,
|
||||
resetconsist,
|
||||
fillcompressor,
|
||||
consistreleaser,
|
||||
queueevent,
|
||||
setlight,
|
||||
insertmodel,
|
||||
deletemodel,
|
||||
dynamicmove,
|
||||
consistteleport,
|
||||
pullalarmchain,
|
||||
sendaicommand,
|
||||
spawntrainset,
|
||||
destroytrainset,
|
||||
quitsimulation,
|
||||
|
||||
none = -1
|
||||
};
|
||||
|
||||
enum class command_target {
|
||||
|
||||
userinterface,
|
||||
simulation,
|
||||
/*
|
||||
// NOTE: there's no need for consist- and unit-specific commands at this point, but it's a possibility.
|
||||
// since command targets are mutually exclusive these don't reduce ranges for individual vehicles etc
|
||||
@@ -276,7 +305,9 @@ enum class command_target {
|
||||
// values are combined with object id. 0xffff objects of each type should be quite enough ("for everyone")
|
||||
vehicle = 0x10000,
|
||||
signal = 0x20000,
|
||||
entity = 0x40000
|
||||
entity = 0x40000,
|
||||
|
||||
simulation = 0x80000
|
||||
};
|
||||
|
||||
struct command_description {
|
||||
@@ -292,6 +323,11 @@ struct command_data {
|
||||
double param1;
|
||||
double param2;
|
||||
double time_delta;
|
||||
|
||||
bool freefly;
|
||||
glm::vec3 location;
|
||||
|
||||
std::string payload;
|
||||
};
|
||||
|
||||
// command_queues: collects and holds commands from input sources, for processing by their intended recipients
|
||||
@@ -301,6 +337,9 @@ struct command_data {
|
||||
class command_queue {
|
||||
|
||||
public:
|
||||
// types
|
||||
typedef std::deque<command_data> commanddata_sequence;
|
||||
typedef std::unordered_map<uint32_t, commanddata_sequence> commands_map;
|
||||
// methods
|
||||
// posts specified command for specified recipient
|
||||
void
|
||||
@@ -308,16 +347,36 @@ public:
|
||||
// retrieves oldest posted command for specified recipient, if any. returns: true on retrieval, false if there's nothing to retrieve
|
||||
bool
|
||||
pop( command_data &Command, std::size_t const Recipient );
|
||||
// checks if given command must be scheduled on server
|
||||
bool
|
||||
is_network_target(const uint32_t Recipient);
|
||||
|
||||
// pops commands from intercept queue
|
||||
commands_map pop_intercept_queue();
|
||||
|
||||
// pushes commands into main queue
|
||||
void push_commands(const commands_map &commands);
|
||||
|
||||
private:
|
||||
// types
|
||||
typedef std::queue<command_data> commanddata_sequence;
|
||||
typedef std::unordered_map<std::size_t, commanddata_sequence> commanddatasequence_map;
|
||||
// members
|
||||
commanddatasequence_map m_commands;
|
||||
// contains command ready to execution
|
||||
commands_map m_commands;
|
||||
|
||||
// contains intercepted commands to be read by application layer
|
||||
commands_map m_intercept_queue;
|
||||
|
||||
void push_direct( command_data const &Command, uint32_t const Recipient );
|
||||
};
|
||||
|
||||
template<typename A, typename B>
|
||||
void add_to_dequemap(std::unordered_map<A, std::deque<B>> &lhs, const std::unordered_map<A, std::deque<B>> &rhs) {
|
||||
for (auto const &kv : rhs) {
|
||||
auto lookup = lhs.emplace(kv.first, std::deque<B>());
|
||||
for (B const &data : kv.second)
|
||||
lookup.first->second.emplace_back(data);
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: simulation should be a (light) wrapper rather than namespace so we could potentially instance it,
|
||||
// but realistically it's not like we're going to run more than one simulation at a time
|
||||
namespace simulation {
|
||||
@@ -340,8 +399,8 @@ public:
|
||||
// posts specified command for the specified recipient
|
||||
// TODO: replace uint16_t with recipient handle, based on item id
|
||||
void
|
||||
post( user_command const Command, double const Param1, double const Param2,
|
||||
int const Action, std::uint16_t const Recipient ) const;
|
||||
post(user_command const Command, double const Param1, double const Param2,
|
||||
int const Action, uint16_t Recipient, glm::vec3 Position = glm::vec3(0.0f) , const std::string *Payload = nullptr) const;
|
||||
private:
|
||||
// types
|
||||
// members
|
||||
|
||||
Reference in New Issue
Block a user