build 170708. cursor-based item picking, mouse support for cab controls, rudimentary render modes support in renderer

This commit is contained in:
tmj-fstate
2017-07-09 16:45:40 +02:00
parent d3b812ee9f
commit 9a008ecff5
26 changed files with 1931 additions and 931 deletions

View File

@@ -11,6 +11,13 @@ http://mozilla.org/MPL/2.0/.
#include "keyboardinput.h"
#include "logs.h"
#include "parser.h"
#include "globals.h"
#include "timer.h"
//#include "world.h"
#include "train.h"
#include "renderer.h"
extern TWorld World;
bool
keyboard_input::recall_bindings() {
@@ -168,6 +175,78 @@ keyboard_input::mouse( double Mousex, double Mousey ) {
0 );
}
void
keyboard_input::mouse( int const Button, int const Action ) {
if( false == Global::ControlPicking ) { return; }
if( true == FreeFlyModeFlag ) {
// for now we're only interested in cab controls
return;
}
user_command &mousecommand = (
Button == GLFW_MOUSE_BUTTON_LEFT ?
m_mousecommandleft :
m_mousecommandright
);
if( Action == GLFW_RELEASE ) {
if( mousecommand != 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( mousecommand, 0, 0, Action, 0 );
mousecommand = user_command::none;
}
}
else {
// if not release then it's press
auto train = World.train();
if( train != nullptr ) {
auto lookup = m_mousecommands.find( train->GetLabel( GfxRenderer.Update_Pick_Control() ) );
if( lookup != m_mousecommands.end() ) {
mousecommand = (
Button == GLFW_MOUSE_BUTTON_LEFT ?
lookup->second.left :
lookup->second.right
);
if( mousecommand != 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( mousecommand, 0, 0, Action, 0 );
m_updateaccumulator = 0.0; // prevent potential command repeat right after issuing one
}
}
}
}
}
void
keyboard_input::poll() {
m_updateaccumulator += Timer::GetDeltaRenderTime();
if( m_updateaccumulator < 0.2 ) {
// too early for any work
return;
}
m_updateaccumulator -= 0.2;
if( m_mousecommandleft != 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_mousecommandleft, 0, 0, GLFW_REPEAT, 0 );
}
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 );
}
}
void
keyboard_input::default_bindings() {
@@ -366,6 +445,183 @@ const int k_WalkMode = 73;
};
bind();
m_mousecommands = {
{ "mainctrl:", {
user_command::mastercontrollerincrease,
user_command::mastercontrollerdecrease } },
{ "scndctrl:", {
user_command::secondcontrollerincrease,
user_command::secondcontrollerdecrease } },
{ "dirkey:", {
user_command::reverserincrease,
user_command::reverserdecrease } },
{ "brakectrl:", {
user_command::trainbrakedecrease,
user_command::trainbrakeincrease } },
{ "localbrake:", {
user_command::independentbrakedecrease,
user_command::independentbrakeincrease } },
{ "manualbrake:", {
user_command::none,
user_command::none } },
{ "brakeprofile_sw:", {
user_command::brakeactingspeedincrease,
user_command::brakeactingspeeddecrease } },
{ "brakeprofileg_sw:", {
user_command::brakeactingspeeddecrease,
user_command::none } },
{ "brakeprofiler_sw:", {
user_command::brakeactingspeedincrease,
user_command::none } },
{ "maxcurrent_sw:", {
user_command::motoroverloadrelaythresholdtoggle,
user_command::none } },
{ "main_off_bt:", {
user_command::linebreakertoggle,
user_command::none } },
{ "main_on_bt:",{
user_command::linebreakertoggle,
user_command::none } }, // TODO: dedicated on and off line breaker commands
{ "security_reset_bt:", {
user_command::alerteracknowledge,
user_command::none } },
{ "releaser_bt:", {
user_command::independentbrakebailoff,
user_command::none } },
{ "sand_bt:", {
user_command::sandboxactivate,
user_command::none } },
{ "antislip_bt:", {
user_command::wheelspinbrakeactivate,
user_command::none } },
{ "horn_bt:", {
user_command::hornhighactivate,
user_command::hornlowactivate } },
{ "hornlow_bt:", {
user_command::hornlowactivate,
user_command::none } },
{ "hornhigh_bt:", {
user_command::hornhighactivate,
user_command::none } },
{ "fuse_bt:", {
user_command::motoroverloadrelayreset,
user_command::none } },
{ "converterfuse_bt:", {
user_command::converteroverloadrelayreset,
user_command::none } },
{ "stlinoff_bt:", {
user_command::motorconnectorsopen,
user_command::none } },
{ "door_left_sw:", {
user_command::doortoggleleft,
user_command::none } },
{ "door_right_sw:", {
user_command::doortoggleright,
user_command::none } },
{ "departure_signal_bt:", {
user_command::departureannounce,
user_command::none } },
{ "upperlight_sw:", {
user_command::headlighttoggleupper,
user_command::none } },
{ "leftlight_sw:", {
user_command::headlighttoggleleft,
user_command::none } },
{ "rightlight_sw:", {
user_command::headlighttoggleright,
user_command::none } },
{ "dimheadlights_sw:", {
user_command::headlightsdimtoggle,
user_command::none } },
{ "leftend_sw:", {
user_command::redmarkertoggleleft,
user_command::none } },
{ "rightend_sw:", {
user_command::redmarkertoggleright,
user_command::none } },
{ "lights_sw:", {
user_command::none,
user_command::none } }, // TODO: implement commands for lights controller
{ "rearupperlight_sw:", {
user_command::headlighttogglerearupper,
user_command::none } },
{ "rearleftlight_sw:", {
user_command::headlighttogglerearleft,
user_command::none } },
{ "rearrightlight_sw:", {
user_command::headlighttogglerearright,
user_command::none } },
{ "rearleftend_sw:", {
user_command::redmarkertogglerearleft,
user_command::none } },
{ "rearrightend_sw:", {
user_command::redmarkertogglerearright,
user_command::none } },
{ "compressor_sw:", {
user_command::compressortoggle,
user_command::none } },
{ "compressorlocal_sw:", {
user_command::compressortogglelocal,
user_command::none } },
{ "converter_sw:", {
user_command::convertertoggle,
user_command::none } },
{ "converterlocal_sw:", {
user_command::convertertogglelocal,
user_command::none } },
{ "converteroff_sw:", {
user_command::convertertoggle,
user_command::none } }, // TODO: dedicated converter shutdown command
{ "main_sw:", {
user_command::linebreakertoggle,
user_command::none } },
{ "radio_sw:", {
user_command::radiotoggle,
user_command::none } },
{ "pantfront_sw:", {
user_command::pantographtogglefront,
user_command::none } },
{ "pantrear_sw:", {
user_command::pantographtogglerear,
user_command::none } },
{ "pantfrontoff_sw:", {
user_command::pantographtogglefront,
user_command::none } }, // TODO: dedicated lower pantograph commands
{ "pantrearoff_sw:", {
user_command::pantographtogglerear,
user_command::none } }, // TODO: dedicated lower pantograph commands
{ "pantalloff_sw:", {
user_command::pantographlowerall,
user_command::none } },
{ "pantselected_sw:", {
user_command::none,
user_command::none } }, // TODO: selected pantograph(s) operation command
{ "pantselectedoff_sw:", {
user_command::none,
user_command::none } }, // TODO: lower selected pantograp(s) command
{ "trainheating_sw:", {
user_command::heatingtoggle,
user_command::none } },
{ "signalling_sw:", {
user_command::mubrakingindicatortoggle,
user_command::none } },
{ "door_signalling_sw:", {
user_command::doorlocktoggle,
user_command::none } },
{ "nextcurrent_sw:", {
user_command::mucurrentindicatorothersourceactivate,
user_command::none } },
{ "cablight_sw:", {
user_command::interiorlighttoggle,
user_command::none } },
{ "cablightdim_sw:", {
user_command::interiorlightdimtoggle,
user_command::none } },
{ "battery_sw:", {
user_command::batterytoggle,
user_command::none } }
};
}
void