mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-29 18:37:29 +01:00
First implementation of graph vehicles
This commit is contained in:
@@ -405,6 +405,7 @@ commanddescription_sequence Commands_descriptions = {
|
||||
{"wiperswitchincrease", command_target::vehicle, command_mode::oneoff},
|
||||
{"wiperswitchdecrease", command_target::vehicle, command_mode::oneoff},
|
||||
{"lightsset", command_target::vehicle, command_mode::oneoff},
|
||||
{"vehiclegraphcontrol", command_target::vehicle, command_mode::oneoff},
|
||||
};
|
||||
|
||||
// Maps of command and coresponding strings
|
||||
@@ -789,6 +790,7 @@ std::unordered_map<std::string, user_command> commandMap = {
|
||||
{"wiperswitchincrease", user_command::wiperswitchincrease},
|
||||
{"wiperswitchdecrease", user_command::wiperswitchdecrease},
|
||||
{"lightsset", user_command::lightsset},
|
||||
{"vehiclegraphcontrol", user_command::vehiclegraphcontrol},
|
||||
{"none", user_command::none}};
|
||||
|
||||
} // namespace simulation
|
||||
|
||||
@@ -403,6 +403,9 @@ enum class user_command
|
||||
wiperswitchincrease,
|
||||
wiperswitchdecrease,
|
||||
lightsset,
|
||||
// operates a control of a vehicle defined by a graph; the payload names the control (the id of its cab.switch block),
|
||||
// param1 is the direction: positive for the left mouse button or increase, negative for the right one or decrease
|
||||
vehiclegraphcontrol,
|
||||
none = -1
|
||||
};
|
||||
|
||||
|
||||
@@ -338,7 +338,7 @@ drivermouse_input::button( int const Button, int const Action ) {
|
||||
// NOTE: basic keyboard controls don't have any parameters
|
||||
// as we haven't yet implemented either item id system or multiplayer, the 'local' controlled vehicle and entity have temporary ids of 0
|
||||
// TODO: pass correct entity id once the missing systems are in place
|
||||
m_relay.post( mousecommand, 0, 0, Action, 0 );
|
||||
post( mousecommand, Action );
|
||||
mousecommand = user_command::none;
|
||||
}
|
||||
else {
|
||||
@@ -373,9 +373,14 @@ drivermouse_input::button( int const Button, int const Action ) {
|
||||
control->screen_touch_list->emplace_back(pos);
|
||||
}
|
||||
|
||||
auto const controlbindings { bindings( simulation::Train->GetLabel( control ) ) };
|
||||
auto const label { simulation::Train->GetLabel( control ) };
|
||||
auto const controlbindings { bindings( label ) };
|
||||
// if the recognized element under the cursor has a command associated with the pressed button, notify the recipient
|
||||
mousecommand = Button == GLFW_MOUSE_BUTTON_LEFT ? controlbindings.first : controlbindings.second;
|
||||
if( mousecommand == user_command::vehiclegraphcontrol ) {
|
||||
m_graphcontrol = label.substr( 6 );
|
||||
m_graphdirection = ( Button == GLFW_MOUSE_BUTTON_LEFT ? 1.0 : -1.0 );
|
||||
}
|
||||
|
||||
if( mousecommand == user_command::none ) {
|
||||
// if we don't have any recognized element under the cursor and the right button was pressed, enter view panning mode
|
||||
@@ -428,9 +433,9 @@ drivermouse_input::button( int const Button, int const Action ) {
|
||||
// NOTE: basic keyboard controls don't have any parameters
|
||||
// NOTE: as we haven't yet implemented either item id system or multiplayer, the 'local' controlled vehicle and entity have temporary ids of 0
|
||||
// TODO: pass correct entity id once the missing systems are in place
|
||||
m_relay.post( mousecommand, 0, 0, Action, 0 );
|
||||
post( mousecommand, Action );
|
||||
if (!pickwaiting) // already depressed
|
||||
m_relay.post( mousecommand, 0, 0, GLFW_RELEASE, 0 );
|
||||
post( mousecommand, GLFW_RELEASE );
|
||||
m_updateaccumulator = -0.25; // prevent potential command repeat right after issuing one
|
||||
} );
|
||||
}
|
||||
@@ -459,13 +464,13 @@ drivermouse_input::poll() {
|
||||
// NOTE: basic keyboard controls don't have any parameters
|
||||
// as we haven't yet implemented either item id system or multiplayer, the 'local' controlled vehicle and entity have temporary ids of 0
|
||||
// TODO: pass correct entity id once the missing systems are in place
|
||||
m_relay.post( m_mousecommandleft, 0, 0, GLFW_REPEAT, 0 );
|
||||
post( m_mousecommandleft, GLFW_REPEAT );
|
||||
}
|
||||
if( m_mousecommandright != user_command::none ) {
|
||||
// NOTE: basic keyboard controls don't have any parameters
|
||||
// as we haven't yet implemented either item id system or multiplayer, the 'local' controlled vehicle and entity have temporary ids of 0
|
||||
// TODO: pass correct entity id once the missing systems are in place
|
||||
m_relay.post( m_mousecommandright, 0, 0, GLFW_REPEAT, 0 );
|
||||
post( m_mousecommandright, GLFW_REPEAT );
|
||||
}
|
||||
m_updateaccumulator -= updaterate;
|
||||
}
|
||||
@@ -477,10 +482,28 @@ drivermouse_input::command() const {
|
||||
return m_slider.command() != user_command::none ? m_slider.command() : m_mousecommandleft != user_command::none ? m_mousecommandleft : m_mousecommandright;
|
||||
}
|
||||
|
||||
void
|
||||
drivermouse_input::post( user_command const Command, int const Action ) {
|
||||
|
||||
if( Command == user_command::vehiclegraphcontrol ) {
|
||||
m_relay.post( Command, m_graphdirection, 0, Action, 0, glm::vec3( 0.0f ), &m_graphcontrol );
|
||||
}
|
||||
else {
|
||||
// NOTE: basic keyboard controls don't have any parameters
|
||||
// as we haven't yet implemented either item id system or multiplayer, the 'local' controlled vehicle and entity have temporary ids of 0
|
||||
// TODO: pass correct entity id once the missing systems are in place
|
||||
m_relay.post( Command, 0, 0, Action, 0 );
|
||||
}
|
||||
}
|
||||
|
||||
// returns pair of bindings associated with specified cab control
|
||||
std::pair<user_command, user_command>
|
||||
drivermouse_input::bindings( std::string const &Control ) const {
|
||||
|
||||
if( Control.starts_with( "graph:" ) ) {
|
||||
// controls of vehicle graphs, operated with both buttons
|
||||
return { user_command::vehiclegraphcontrol, user_command::vehiclegraphcontrol };
|
||||
}
|
||||
auto const lookup{ m_buttonbindings.find( Control ) };
|
||||
|
||||
if( lookup != m_buttonbindings.end() )
|
||||
|
||||
@@ -92,6 +92,9 @@ private:
|
||||
// potentially replaces supplied command with a more relevant one
|
||||
user_command
|
||||
adjust_command( user_command Command );
|
||||
// posts the command; commands of vehicle graph controls carry the name of the control
|
||||
void
|
||||
post( user_command const Command, int const Action );
|
||||
|
||||
// members
|
||||
command_relay m_relay;
|
||||
@@ -109,6 +112,9 @@ private:
|
||||
glm::dvec2 m_varyingpollrateorigin; // helper, cursor position when the command was initiated
|
||||
std::array<int, GLFW_MOUSE_BUTTON_LAST> m_buttons;
|
||||
bool m_pickwaiting;
|
||||
// control of a vehicle graph under the cursor (label "graph:<id>"), and the direction given by the mouse button
|
||||
std::string m_graphcontrol;
|
||||
double m_graphdirection { 0.0 };
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user