build 170712. increased amount of generic cab items, varying command repeat rate for mouse control

This commit is contained in:
tmj-fstate
2017-07-12 18:09:51 +02:00
parent 16718d53bb
commit 9877b37e1f
17 changed files with 403 additions and 186 deletions

View File

@@ -68,7 +68,7 @@ namespace input {
keyboard_input Keyboard;
mouse_input Mouse;
gamepad_input Gamepad;
glm::dvec2 mouse_pos; // stores last mouse position in control picking mode
glm::dvec2 mouse_pickmodepos; // stores last mouse position in control picking mode
}
@@ -144,8 +144,8 @@ void mouse_button_callback( GLFWwindow* window, int button, int action, int mods
}
}
void key_callback( GLFWwindow *window, int key, int scancode, int action, int mods )
{
void key_callback( GLFWwindow *window, int key, int scancode, int action, int mods ) {
input::Keyboard.key( key, action );
Global::shiftState = ( mods & GLFW_MOD_SHIFT ) ? true : false;
@@ -159,14 +159,14 @@ void key_callback( GLFWwindow *window, int key, int scancode, int action, int mo
if( Global::ControlPicking ) {
// switch off
glfwGetCursorPos( window, &input::mouse_pos.x, &input::mouse_pos.y );
glfwGetCursorPos( window, &input::mouse_pickmodepos.x, &input::mouse_pickmodepos.y );
glfwSetInputMode( window, GLFW_CURSOR, GLFW_CURSOR_DISABLED );
glfwSetCursorPos( window, 0, 0 );
}
else {
// enter picking mode
glfwSetInputMode( window, GLFW_CURSOR, GLFW_CURSOR_NORMAL );
glfwSetCursorPos( window, input::mouse_pos.x, input::mouse_pos.y );
glfwSetCursorPos( window, input::mouse_pickmodepos.x, input::mouse_pickmodepos.y );
}
// actually toggle the mode
Global::ControlPicking = !Global::ControlPicking;
@@ -183,8 +183,8 @@ void key_callback( GLFWwindow *window, int key, int scancode, int action, int mo
return;
}
if( action == GLFW_PRESS || action == GLFW_REPEAT )
{
if( action == GLFW_PRESS || action == GLFW_REPEAT ) {
World.OnKeyDown( key );
switch( key )

View File

@@ -47,16 +47,6 @@ void SetDeltaTime(double t)
DeltaTime = t;
}
double GetSimulationTime()
{
return fSimulationTime;
}
void SetSimulationTime(double t)
{
fSimulationTime = t;
}
bool GetSoundTimer()
{ // Ra: być może, by dźwięki nie modyfikowały się zbyt często, po 0.1s zeruje się ten licznik
return (fSoundTimer == 0.0f);

View File

@@ -21,10 +21,6 @@ double GetfSinceStart();
void SetDeltaTime(double v);
double GetSimulationTime();
void SetSimulationTime(double v);
bool GetSoundTimer();
double GetFPS();

190
Train.cpp
View File

@@ -225,7 +225,17 @@ TTrain::commandhandler_map const TTrain::m_commandhandlers = {
{ user_command::departureannounce, &TTrain::OnCommand_departureannounce },
{ user_command::hornlowactivate, &TTrain::OnCommand_hornlowactivate },
{ user_command::hornhighactivate, &TTrain::OnCommand_hornhighactivate },
{ user_command::radiotoggle, &TTrain::OnCommand_radiotoggle }
{ user_command::radiotoggle, &TTrain::OnCommand_radiotoggle },
{ user_command::generictoggle0, &TTrain::OnCommand_generictoggle },
{ user_command::generictoggle1, &TTrain::OnCommand_generictoggle },
{ user_command::generictoggle2, &TTrain::OnCommand_generictoggle },
{ user_command::generictoggle3, &TTrain::OnCommand_generictoggle },
{ user_command::generictoggle4, &TTrain::OnCommand_generictoggle },
{ user_command::generictoggle5, &TTrain::OnCommand_generictoggle },
{ user_command::generictoggle6, &TTrain::OnCommand_generictoggle },
{ user_command::generictoggle7, &TTrain::OnCommand_generictoggle },
{ user_command::generictoggle8, &TTrain::OnCommand_generictoggle },
{ user_command::generictoggle9, &TTrain::OnCommand_generictoggle }
};
std::vector<std::string> const TTrain::fPress_labels = {
@@ -233,9 +243,10 @@ std::vector<std::string> const TTrain::fPress_labels = {
"ch1: ", "ch2: ", "ch3: ", "ch4: ", "ch5: ", "ch6: ", "ch7: ", "ch8: ", "ch9: ", "ch0: "
};
TTrain::TTrain()
{
ActiveUniversal4 = false;
TTrain::TTrain() {
/*
Universal4Active = false;
*/
ShowNextCurrent = false;
// McZapkie-240302 - przyda sie do tachometru
fTachoVelocity = 0;
@@ -257,7 +268,7 @@ TTrain::TTrain()
bCabLightDim = false;
//-----
pMechSittingPosition = vector3(0, 0, 0); // ABu: 180404
LampkaUniversal3_st = false; // ABu: 030405
InstrumentLightActive = false; // ABu: 030405
dsbNastawnikJazdy = NULL;
dsbNastawnikBocz = NULL;
dsbRelay = NULL;
@@ -424,7 +435,7 @@ PyObject *TTrain::GetTrainState() {
PyDict_SetItemString( dict, "ca", PyGetBool( TestFlag( mvOccupied->SecuritySystem.Status, s_aware ) ) );
PyDict_SetItemString( dict, "shp", PyGetBool( TestFlag( mvOccupied->SecuritySystem.Status, s_active ) ) );
PyDict_SetItemString( dict, "pantpress", PyGetFloat( mvControlled->PantPress ) );
PyDict_SetItemString( dict, "universal3", PyGetBool( LampkaUniversal3_st ) );
PyDict_SetItemString( dict, "universal3", PyGetBool( InstrumentLightActive ) );
// movement data
PyDict_SetItemString( dict, "velocity", PyGetFloat( mover->Vel ) );
PyDict_SetItemString( dict, "tractionforce", PyGetFloat( mover->Ft ) );
@@ -2665,7 +2676,7 @@ void TTrain::OnCommand_instrumentlighttoggle( TTrain *Train, command_data const
// NOTE: the check is disabled, as we're presuming light control is present in every vehicle
// TODO: proper control deviced definition for the interiors, that doesn't hinge of presence of 3d submodels
if( Train->ggUniversal3Button.SubModel == nullptr ) {
if( Train->ggInstrumentLightButton.SubModel == nullptr ) {
if( Command.action == GLFW_PRESS ) {
WriteLog( "Universal3 switch is missing, or wasn't defined" );
}
@@ -2675,25 +2686,25 @@ void TTrain::OnCommand_instrumentlighttoggle( TTrain *Train, command_data const
if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
// NOTE: instrument lighting isn't fully implemented, so we have to rely on the state of the 'button' i.e. light itself
if( false == Train->LampkaUniversal3_st ) {
if( false == Train->InstrumentLightActive ) {
// turn on
Train->LampkaUniversal3_st = true;
Train->InstrumentLightActive = true;
// audio feedback
if( Train->ggUniversal3Button.GetValue() < 0.5 ) {
if( Train->ggInstrumentLightButton.GetValue() < 0.5 ) {
Train->play_sound( Train->dsbSwitch );
}
// visual feedback
Train->ggUniversal3Button.UpdateValue( 1.0 );
Train->ggInstrumentLightButton.UpdateValue( 1.0 );
}
else {
//turn off
Train->LampkaUniversal3_st = false;
Train->InstrumentLightActive = false;
// audio feedback
if( Train->ggUniversal3Button.GetValue() > 0.5 ) {
if( Train->ggInstrumentLightButton.GetValue() > 0.5 ) {
Train->play_sound( Train->dsbSwitch );
}
// visual feedback
Train->ggUniversal3Button.UpdateValue( 0.0 );
Train->ggInstrumentLightButton.UpdateValue( 0.0 );
}
}
}
@@ -2732,6 +2743,41 @@ void TTrain::OnCommand_heatingtoggle( TTrain *Train, command_data const &Command
}
}
void TTrain::OnCommand_generictoggle( TTrain *Train, command_data const &Command ) {
auto const itemindex = static_cast<int>( Command.command ) - static_cast<int>( user_command::generictoggle0 );
auto &item = Train->ggUniversals[ itemindex ];
if( item.SubModel == nullptr ) {
if( Command.action == GLFW_PRESS ) {
WriteLog( "Train generic item " + std::to_string( itemindex ) + " is missing, or wasn't defined" );
}
return;
}
if( Command.action == GLFW_PRESS ) {
// only reacting to press, so the switch doesn't flip back and forth if key is held down
if( item.GetValue() < 0.25 ) {
// turn on
// audio feedback
if( item.GetValue() < 0.5 ) {
Train->play_sound( Train->dsbSwitch );
}
// visual feedback
item.UpdateValue( 1.0 );
}
else {
//turn off
// audio feedback
if( item.GetValue() > 0.5 ) {
Train->play_sound( Train->dsbSwitch );
}
// visual feedback
item.UpdateValue( 0.0 );
}
}
}
void TTrain::OnCommand_doorlocktoggle( TTrain *Train, command_data const &Command ) {
if( Train->ggDoorSignallingButton.SubModel == nullptr ) {
@@ -5193,7 +5239,6 @@ bool TTrain::Update( double const Deltatime )
}
else
ggMainOffButton.UpdateValue(0);
#endif
/* if (cKey==Global::Keys[k_Main]) //z shiftem
{
ggMainOnButton.PutValue(1);
@@ -5220,7 +5265,6 @@ bool TTrain::Update( double const Deltatime )
}
}
else */
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
//----------------
// hunter-131211: czuwak przeniesiony z OnKeyPress
// hunter-091012: zrobiony test czuwaka
@@ -5253,7 +5297,6 @@ bool TTrain::Update( double const Deltatime )
}
CAflag = false;
}
#endif
/*
if ( Console::Pressed(Global::Keys[k_Czuwak]) )
{
@@ -5292,7 +5335,6 @@ bool TTrain::Update( double const Deltatime )
}
*/
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
if( Console::Pressed( Global::Keys[ k_Sand ] ) )
{
if (mvControlled->TrainType != dt_EZT && ggSandButton.SubModel != NULL)
@@ -5375,7 +5417,6 @@ bool TTrain::Update( double const Deltatime )
ggCompressorButton.PutValue(0);
mvControlled->CompressorSwitch(false);
}
#endif
/*
bez szifta
if (cKey==Global::Keys[k_Converter]) //NBMX wyl przetwornicy
@@ -5398,7 +5439,6 @@ bool TTrain::Update( double const Deltatime )
else
*/
//-----------------
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
if ((!FreeFlyModeFlag) &&
(!(DynamicObject->Mechanik ? DynamicObject->Mechanik->AIControllFlag : false)))
{
@@ -5422,7 +5462,6 @@ bool TTrain::Update( double const Deltatime )
else
mvOccupied->BrakeReleaser(0);
} // FFMF
#endif
if (Console::Pressed(Global::Keys[k_Univ1]))
{
@@ -5435,13 +5474,11 @@ bool TTrain::Update( double const Deltatime )
ggUniversal1Button.DecValue(dt / 2);
}
}
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
if (!Console::Pressed(Global::Keys[k_SmallCompressor]))
// Ra: przecieść to na zwolnienie klawisza
if (DynamicObject->Mechanik ? !DynamicObject->Mechanik->AIControllFlag :
false) // nie wyłączać, gdy AI
mvControlled->PantCompFlag = false; // wyłączona, gdy nie trzymamy klawisza
#else
/*
// NOTE: disabled to allow 'prototypical' 'tricking' pantograph compressor into running unattended
if( ( ( DynamicObject->Mechanik != nullptr )
@@ -5454,7 +5491,6 @@ bool TTrain::Update( double const Deltatime )
mvControlled->PantCompFlag = false;
}
*/
#endif
if (Console::Pressed(Global::Keys[k_Univ2]))
{
if (!DebugModeFlag)
@@ -5467,7 +5503,6 @@ bool TTrain::Update( double const Deltatime )
}
}
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
// hunter-091012: zrobione z uwzglednieniem przelacznika swiatla
if (Console::Pressed(Global::Keys[k_Univ3]))
{
@@ -5484,13 +5519,13 @@ bool TTrain::Update( double const Deltatime )
}
else
{
if (ggUniversal3Button.SubModel)
if (ggInstrumentLightButton.SubModel)
{
ggUniversal3Button.PutValue(1); // hunter-131211: z UpdateValue na
ggInstrumentLightButton.PutValue(1); // hunter-131211: z UpdateValue na
// PutValue - by zachowywal sie jak
// pozostale przelaczniki
if (btLampkaUniversal3.Active())
LampkaUniversal3_st = true;
if (btInstrumentLight.Active())
InstrumentLightActive = true;
}
}
}
@@ -5507,37 +5542,37 @@ bool TTrain::Update( double const Deltatime )
}
else
{
if (ggUniversal3Button.SubModel)
if (ggInstrumentLightButton.SubModel)
{
ggUniversal3Button.PutValue(0); // hunter-131211: z UpdateValue na
ggInstrumentLightButton.PutValue(0); // hunter-131211: z UpdateValue na
// PutValue - by zachowywal sie jak
// pozostale przelaczniki
if (btLampkaUniversal3.Active())
LampkaUniversal3_st = false;
if (btInstrumentLight.Active())
InstrumentLightActive = false;
}
}
}
}
#endif
// ABu030405 obsluga lampki uniwersalnej:
if (btLampkaUniversal3.Active()) // w ogóle jest
if (LampkaUniversal3_st) // załączona
switch (LampkaUniversal3_typ)
if (btInstrumentLight.Active()) // w ogóle jest
if (InstrumentLightActive) // załączona
switch (InstrumentLightType)
{
case 0:
btLampkaUniversal3.Turn( mvControlled->Battery || mvControlled->ConverterFlag );
btInstrumentLight.Turn( mvControlled->Battery || mvControlled->ConverterFlag );
break;
case 1:
btLampkaUniversal3.Turn(mvControlled->Mains);
btInstrumentLight.Turn(mvControlled->Mains);
break;
case 2:
btLampkaUniversal3.Turn(mvControlled->ConverterFlag);
btInstrumentLight.Turn(mvControlled->ConverterFlag);
break;
default:
btLampkaUniversal3.TurnOff();
btInstrumentLight.TurnOff();
}
else
btLampkaUniversal3.TurnOff();
btInstrumentLight.TurnOff();
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
// hunter-091012: przepisanie univ4 i zrobione z uwzglednieniem przelacznika
@@ -5556,7 +5591,7 @@ bool TTrain::Update( double const Deltatime )
}
else
{
ActiveUniversal4 = true;
Universal4Active = true;
// ggUniversal4Button.UpdateValue(1);
}
}
@@ -5574,7 +5609,7 @@ bool TTrain::Update( double const Deltatime )
}
else
{
ActiveUniversal4 = false;
Universal4Active = false;
// ggUniversal4Button.UpdateValue(0);
}
}
@@ -5889,18 +5924,23 @@ bool TTrain::Update( double const Deltatime )
ggHornButton.Update();
ggHornLowButton.Update();
ggHornHighButton.Update();
/*
ggUniversal1Button.Update();
ggUniversal2Button.Update();
ggUniversal3Button.Update();
if( Universal4Active ) {
ggUniversal4Button.PermIncValue( dt );
}
ggUniversal4Button.Update();
*/
for( auto &universal : ggUniversals ) {
universal.Update();
}
// hunter-091012
ggInstrumentLightButton.Update();
ggCabLightButton.Update();
ggCabLightDimButton.Update();
ggBatteryButton.Update();
//------
if (ActiveUniversal4)
ggUniversal4Button.PermIncValue(dt);
ggUniversal4Button.Update();
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
ggMainOffButton.UpdateValue(0);
ggMainOnButton.UpdateValue(0);
@@ -6460,7 +6500,9 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
DynamicObject
->mdModel; // McZapkie-170103: szukaj elementy kabiny w glownym modelu
}
ActiveUniversal4 = false;
/*
Universal4Active = false;
*/
clear_cab_controls();
}
if (nullptr == DynamicObject->mdKabina)
@@ -6706,14 +6748,19 @@ void TTrain::clear_cab_controls()
ggHornLowButton.Clear();
ggHornHighButton.Clear();
ggNextCurrentButton.Clear();
/*
ggUniversal1Button.Clear();
ggUniversal2Button.Clear();
ggUniversal3Button.Clear();
ggUniversal4Button.Clear();
*/
for( auto &universal : ggUniversals ) {
universal.Clear();
}
ggInstrumentLightButton.Clear();
// hunter-091012
ggCabLightButton.Clear();
ggCabLightDimButton.Clear();
//-------
ggUniversal4Button.Clear();
ggFuseButton.Clear();
ggConverterFuseButton.Clear();
ggStLinOffButton.Clear();
@@ -6772,7 +6819,7 @@ void TTrain::clear_cab_controls()
btLampkaRadio.Clear();
btLampkaHamulecReczny.Clear();
btLampkaBlokadaDrzwi.Clear();
btLampkaUniversal3.Clear();
btInstrumentLight.Clear();
btLampkaWentZaluzje.Clear();
btLampkaOgrzewanieSkladu.Clear(11);
btLampkaSHP.Clear(0);
@@ -6930,8 +6977,8 @@ void TTrain::set_cab_controls() {
if( true == bCabLightDim ) {
ggCabLightDimButton.PutValue( 1.0 );
}
if( true == LampkaUniversal3_st ) {
ggUniversal3Button.PutValue( 1.0 );
if( true == InstrumentLightActive ) {
ggInstrumentLightButton.PutValue( 1.0 );
}
// doors
// NOTE: we're relying on the cab models to have switches reversed for the rear cab(?)
@@ -7073,20 +7120,20 @@ bool TTrain::initialize_button(cParser &Parser, std::string const &Label, int co
{
btLampkaWysRozr.Load(Parser, DynamicObject->mdKabina);
}
else if (Label == "i-universal3:")
else if (Label == "i-instrumentlight:")
{
btLampkaUniversal3.Load(Parser, DynamicObject->mdKabina, DynamicObject->mdModel);
LampkaUniversal3_typ = 0;
btInstrumentLight.Load(Parser, DynamicObject->mdKabina, DynamicObject->mdModel);
InstrumentLightType = 0;
}
else if (Label == "i-universal3_M:")
else if (Label == "i-instrumentlight_M:")
{
btLampkaUniversal3.Load(Parser, DynamicObject->mdKabina, DynamicObject->mdModel);
LampkaUniversal3_typ = 1;
btInstrumentLight.Load(Parser, DynamicObject->mdKabina, DynamicObject->mdModel);
InstrumentLightType = 1;
}
else if (Label == "i-universal3_C:")
else if (Label == "i-instrumentlight_C:")
{
btLampkaUniversal3.Load(Parser, DynamicObject->mdKabina, DynamicObject->mdModel);
LampkaUniversal3_typ = 2;
btInstrumentLight.Load(Parser, DynamicObject->mdKabina, DynamicObject->mdModel);
InstrumentLightType = 2;
}
else if (Label == "i-vent_trim:")
{
@@ -7279,9 +7326,20 @@ bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int con
{ "signalling_sw:", ggSignallingButton },
{ "door_signalling_sw:", ggDoorSignallingButton },
{ "nextcurrent_sw:", ggNextCurrentButton },
{ "instrumentlight_sw:", ggInstrumentLightButton },
{ "cablight_sw:", ggCabLightButton },
{ "cablightdim_sw:", ggCabLightDimButton },
{ "battery_sw:", ggBatteryButton }
{ "battery_sw:", ggBatteryButton },
{ "universal0:", ggUniversals[ 0 ] },
{ "universal1:", ggUniversals[ 1 ] },
{ "universal2:", ggUniversals[ 2 ] },
{ "universal3:", ggUniversals[ 3 ] },
{ "universal4:", ggUniversals[ 4 ] },
{ "universal5:", ggUniversals[ 5 ] },
{ "universal6:", ggUniversals[ 6 ] },
{ "universal7:", ggUniversals[ 7 ] },
{ "universal8:", ggUniversals[ 8 ] },
{ "universal9:", ggUniversals[ 9 ] }
};
auto lookup = gauges.find( Label );
if( lookup != gauges.end() ) {
@@ -7292,6 +7350,7 @@ bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int con
else if( Label == "mainctrlact:" ) {
ggMainCtrlAct.Load( Parser, DynamicObject->mdKabina, DynamicObject->mdModel );
}
/*
else if (Label == "universal1:")
{
ggUniversal1Button.Load(Parser, DynamicObject->mdKabina, DynamicObject->mdModel);
@@ -7302,12 +7361,13 @@ bool TTrain::initialize_gauge(cParser &Parser, std::string const &Label, int con
}
else if (Label == "universal3:")
{
ggUniversal3Button.Load(Parser, DynamicObject->mdKabina, DynamicObject->mdModel);
ggInstrumentLightButton.Load(Parser, DynamicObject->mdKabina, DynamicObject->mdModel);
}
else if (Label == "universal4:")
{
ggUniversal4Button.Load(Parser, DynamicObject->mdKabina, DynamicObject->mdModel);
}
*/
// SEKCJA WSKAZNIKOW
else if ((Label == "tachometer:") || (Label == "tachometerb:"))
{

14
Train.h
View File

@@ -73,7 +73,6 @@ class TTrain
{
public:
bool CabChange(int iDirection);
bool ActiveUniversal4;
bool ShowNextCurrent; // pokaz przd w podlaczonej lokomotywie (ET41)
bool InitializeCab(int NewCabNo, std::string const &asFileName);
TTrain();
@@ -189,6 +188,7 @@ class TTrain
static void OnCommand_hornlowactivate( TTrain *Train, command_data const &Command );
static void OnCommand_hornhighactivate( TTrain *Train, command_data const &Command );
static void OnCommand_radiotoggle( TTrain *Train, command_data const &Command );
static void OnCommand_generictoggle( TTrain *Train, command_data const &Command );
// members
TDynamicObject *DynamicObject; // przestawia zmiana pojazdu [F5]
@@ -277,12 +277,16 @@ public: // reszta może by?publiczna
TGauge ggHornLowButton;
TGauge ggHornHighButton;
TGauge ggNextCurrentButton;
/*
// ABu 090305 - uniwersalne przyciski
TGauge ggUniversal1Button;
TGauge ggUniversal2Button;
TGauge ggUniversal3Button;
TGauge ggUniversal4Button;
bool Universal4Active;
*/
std::array<TGauge, 10> ggUniversals; // NOTE: temporary arrangement until we have dynamically built control table
TGauge ggInstrumentLightButton;
TGauge ggCabLightButton; // hunter-091012: przelacznik oswietlania kabiny
TGauge ggCabLightDimButton; // hunter-091012: przelacznik przyciemnienia
TGauge ggBatteryButton; // Stele 161228 hebelek baterii
@@ -335,9 +339,9 @@ public: // reszta może by?publiczna
// TButton btLampkaUnknown;
TButton btLampkaOpory;
TButton btLampkaWysRozr;
TButton btLampkaUniversal3;
int LampkaUniversal3_typ; // ABu 030405 - swiecenie uzaleznione od: 0-nic, 1-obw.gl, 2-przetw.
bool LampkaUniversal3_st;
TButton btInstrumentLight;
int InstrumentLightType; // ABu 030405 - swiecenie uzaleznione od: 0-nic, 1-obw.gl, 2-przetw.
bool InstrumentLightActive;
TButton btLampkaWentZaluzje; // ET22
TButton btLampkaOgrzewanieSkladu;
TButton btLampkaSHP;

View File

@@ -30,6 +30,7 @@ http://mozilla.org/MPL/2.0/.
#include "Console.h"
#include "color.h"
#include "uilayer.h"
#include "translation.h"
//---------------------------------------------------------------------------
@@ -180,20 +181,6 @@ simulation_time::julian_day() const {
return JD;
}
namespace locale {
std::string
control( std::string const &Label ) {
auto const lookup = m_controls.find( Label );
return (
lookup != m_controls.end() ?
lookup->second :
"" );
}
}
TWorld::TWorld()
{
// randomize();
@@ -717,8 +704,8 @@ void TWorld::OnKeyDown(int cKey)
Global::iTextMode = GLFW_KEY_F1; // to wyświetlić zegar i informację
}
}
else if( ( cKey == GLFW_KEY_PAUSE ) && ( Global::ctrlState ) ) {
//[Ctrl]+[Break] hamowanie wszystkich pojazdów w okolicy
else if( ( cKey == GLFW_KEY_PAUSE ) && ( Global::ctrlState ) && ( Global::shiftState ) ) {
//[Ctrl]+[Break] hamowanie wszystkich pojazdów w okolicy // added shift to prevent odd issue with glfw producing pause presses on its own
if (Controlled->MoverParameters->Radio)
Ground.RadioStop(Camera.Pos);
}
@@ -1288,7 +1275,7 @@ TWorld::Update_UI() {
if( ( Train != nullptr ) && ( false == FreeFlyModeFlag ) ) {
if( false == DebugModeFlag ) {
// in regular mode show control functions, for defined controls
UILayer.set_tooltip( locale::control( Train->GetLabel( GfxRenderer.Pick_Control() ) ) );
UILayer.set_tooltip( locale::label_cab_control( Train->GetLabel( GfxRenderer.Pick_Control() ) ) );
}
else {
// in debug mode show names of submodels, to help with cab setup and/or debugging

68
World.h
View File

@@ -60,74 +60,6 @@ extern simulation_time Time;
}
namespace locale {
std::string
control( std::string const &Label );
static std::unordered_map<std::string, std::string> m_controls = {
{ "mainctrl:", "master controller" },
{ "scndctrl:", "second controller" },
{ "dirkey:" , "reverser" },
{ "brakectrl:", "train brake" },
{ "localbrake:", "independent brake" },
{ "manualbrake:", "manual brake" },
{ "brakeprofile_sw:", "brake acting speed" },
{ "brakeprofileg_sw:", "brake acting speed: cargo" },
{ "brakeprofiler_sw:", "brake acting speed: rapid" },
{ "maxcurrent_sw:", "motor overload relay threshold" },
{ "main_off_bt:", "line breaker" },
{ "main_on_bt:", "line breaker" },
{ "security_reset_bt:", "alerter" },
{ "releaser_bt:", "independent brake releaser" },
{ "sand_bt:", "sandbox" },
{ "antislip_bt:", "wheelspin brake" },
{ "horn_bt:", "horn" },
{ "hornlow_bt:", "low tone horn" },
{ "hornhigh_bt:", "high tone horn" },
{ "fuse_bt:", "motor overload relay reset" },
{ "converterfuse_bt:", "converter overload relay reset" },
{ "stlinoff_bt:", "motor connectors" },
{ "door_left_sw:", "left door" },
{ "door_right_sw:", "right door" },
{ "departure_signal_bt:", "departure signal" },
{ "upperlight_sw:", "upper headlight" },
{ "leftlight_sw:", "left headlight" },
{ "rightlight_sw:", "right headlight" },
{ "dimheadlights_sw:", "headlights dimmer" },
{ "leftend_sw:", "left marker light" },
{ "rightend_sw:", "right marker light" },
{ "lights_sw:", "light pattern" },
{ "rearupperlight_sw:", "rear upper headlight" },
{ "rearleftlight_sw:", "rear left headlight" },
{ "rearrightlight_sw:", "rear right headlight" },
{ "rearleftend_sw:", "rear left marker light" },
{ "rearrightend_sw:", "rear right marker light" },
{ "compressor_sw:", "compressor" },
{ "compressorlocal_sw:", "local compressor" },
{ "converter_sw:", "converter" },
{ "converterlocal_sw:", "local converter" },
{ "converteroff_sw:", "converter" },
{ "main_sw:", "line breaker" },
{ "radio_sw:", "radio" },
{ "pantfront_sw:", "front pantograph" },
{ "pantrear_sw:", "rear pantograph" },
{ "pantfrontoff_sw:", "front pantograph" },
{ "pantrearoff_sw:", "rear pantograph" },
{ "pantalloff_sw:", "all pantographs" },
{ "pantselected_sw:", "selected pantograph" },
{ "pantselectedoff_sw:", "selected pantograph" },
{ "trainheating_sw:", "heating" },
{ "signalling_sw:", "braking indicator" },
{ "door_signalling_sw:", "door locking" },
{ "nextcurrent_sw:", "current indicator source" },
{ "cablight_sw:", "interior light" },
{ "cablightdim_sw:", "interior light dimmer" },
{ "battery_sw:", "battery" }
};
}
// wrapper for environment elements -- sky, sun, stars, clouds etc
class world_environment {

View File

@@ -125,6 +125,16 @@ const int k_Univ4 = 69;
const int k_EndSign = 70;
const int k_Active = 71;
*/
{ "generictoggle0", command_target::vehicle },
{ "generictoggle1", command_target::vehicle },
{ "generictoggle2", command_target::vehicle },
{ "generictoggle3", command_target::vehicle },
{ "generictoggle4", command_target::vehicle },
{ "generictoggle5", command_target::vehicle },
{ "generictoggle6", command_target::vehicle },
{ "generictoggle7", command_target::vehicle },
{ "generictoggle8", command_target::vehicle },
{ "generictoggle9", command_target::vehicle },
{ "batterytoggle", command_target::vehicle }
/*
const int k_WalkMode = 73;

View File

@@ -120,6 +120,16 @@ const int k_Univ4 = 69;
const int k_EndSign = 70;
const int k_Active = 71;
*/
generictoggle0,
generictoggle1,
generictoggle2,
generictoggle3,
generictoggle4,
generictoggle5,
generictoggle6,
generictoggle7,
generictoggle8,
generictoggle9,
batterytoggle,
/*
const int k_WalkMode = 73;
@@ -149,8 +159,6 @@ struct command_description {
command_target target;
};
typedef std::vector<command_description> commanddescription_sequence;
struct command_data {
user_command command;
@@ -188,6 +196,8 @@ private:
// but realistically it's not like we're going to run more than one simulation at a time
namespace simulation {
typedef std::vector<command_description> commanddescription_sequence;
extern command_queue Commands;
// TODO: add name to command map, and wrap these two into helper object
extern commanddescription_sequence Commands_descriptions;

View File

@@ -28,6 +28,8 @@ keyboard_input::recall_bindings() {
++commandid;
}
std::unordered_map<std::string, int> nametokeymap = {
{ "0", GLFW_KEY_0 }, { "1", GLFW_KEY_1 }, { "2", GLFW_KEY_2 }, { "3", GLFW_KEY_3 }, { "4", GLFW_KEY_4 },
{ "5", GLFW_KEY_5 }, { "6", GLFW_KEY_6 }, { "7", GLFW_KEY_7 }, { "8", GLFW_KEY_8 }, { "9", GLFW_KEY_9 },
{ "a", GLFW_KEY_A }, { "b", GLFW_KEY_B }, { "c", GLFW_KEY_C }, { "d", GLFW_KEY_D }, { "e", GLFW_KEY_E },
{ "f", GLFW_KEY_F }, { "g", GLFW_KEY_G }, { "h", GLFW_KEY_H }, { "i", GLFW_KEY_I }, { "j", GLFW_KEY_J },
{ "k", GLFW_KEY_K }, { "l", GLFW_KEY_L }, { "m", GLFW_KEY_M }, { "n", GLFW_KEY_N }, { "o", GLFW_KEY_O },
@@ -348,6 +350,26 @@ const int k_Univ4 = 69;
const int k_EndSign = 70;
const int k_Active = 71;
*/
// "generictoggle0"
{ GLFW_KEY_0 },
// "generictoggle1"
{ GLFW_KEY_1 },
// "generictoggle2"
{ GLFW_KEY_2 },
// "generictoggle3"
{ GLFW_KEY_3 },
// "generictoggle4"
{ GLFW_KEY_4 },
// "generictoggle5"
{ GLFW_KEY_5 },
// "generictoggle6"
{ GLFW_KEY_6 },
// "generictoggle7"
{ GLFW_KEY_7 },
// "generictoggle8"
{ GLFW_KEY_8 },
// "generictoggle9"
{ GLFW_KEY_9 },
// "batterytoggle"
{ GLFW_KEY_J }
/*

View File

@@ -228,6 +228,9 @@
<ClCompile Include="mouseinput.cpp">
<Filter>Source Files\input</Filter>
</ClCompile>
<ClCompile Include="translation.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Globals.h">
@@ -446,6 +449,9 @@
<ClInclude Include="mouseinput.h">
<Filter>Header Files\input</Filter>
</ClInclude>
<ClInclude Include="translation.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="maszyna.rc">

View File

@@ -9,6 +9,7 @@ http://mozilla.org/MPL/2.0/.
#include "stdafx.h"
#include "mouseinput.h"
#include "usefull.h"
#include "globals.h"
#include "timer.h"
#include "world.h"
@@ -17,6 +18,17 @@ http://mozilla.org/MPL/2.0/.
extern TWorld World;
bool
mouse_input::init() {
#ifdef _WINDOWS
DWORD systemkeyboardspeed;
::SystemParametersInfo( SPI_GETKEYBOARDSPEED, 0, &systemkeyboardspeed, 0 );
m_updaterate = interpolate( 0.5, 0.04, systemkeyboardspeed / 31.0 );
#endif
return true;
}
void
mouse_input::move( double Mousex, double Mousey ) {
@@ -76,11 +88,13 @@ mouse_input::button( int const Button, int const Action ) {
mousecommand = user_command::none;
}
else {
// if it's the right mouse button that got released, stop view panning
// if it's the right mouse button that got released and we had no command active, we were potentially in view panning mode; stop it
if( Button == GLFW_MOUSE_BUTTON_RIGHT ) {
m_pickmodepanning = false;
}
}
// if we were in varying command repeat rate, we can stop that now. done without any conditions, to catch some unforeseen edge cases
m_varyingpollrate = false;
}
else {
// if not release then it's press
@@ -114,6 +128,25 @@ mouse_input::button( int const Button, int const Action ) {
if( mousecommand == user_command::mastercontrollerincrease ) {
m_updateaccumulator -= 0.15; // extra pause on first increase of master controller
}
switch( mousecommand ) {
case user_command::mastercontrollerincrease:
case user_command::mastercontrollerdecrease:
case user_command::secondcontrollerincrease:
case user_command::secondcontrollerdecrease:
case user_command::trainbrakeincrease:
case user_command::trainbrakedecrease:
case user_command::independentbrakeincrease:
case user_command::independentbrakedecrease: {
// these commands trigger varying repeat rate mode,
// which scales the rate based on the distance of the cursor from its point when the command was first issued
m_commandstartcursor = m_cursorposition;
m_varyingpollrate = true;
break;
}
default: {
break;
}
}
}
}
else {
@@ -131,11 +164,16 @@ mouse_input::poll() {
m_updateaccumulator += Timer::GetDeltaRenderTime();
if( m_updateaccumulator < 0.1 ) {
auto updaterate { m_updaterate };
if( m_varyingpollrate ) {
updaterate /= std::max( 0.15, 2.0 * glm::length( m_cursorposition - m_commandstartcursor ) / std::max( 1, Global::ScreenHeight ) );
}
if( m_updateaccumulator < updaterate ) {
// too early for any work
return;
}
m_updateaccumulator -= 0.1;
m_updateaccumulator -= updaterate;
if( m_mousecommandleft != user_command::none ) {
// NOTE: basic keyboard controls don't have any parameters
@@ -320,6 +358,9 @@ mouse_input::default_bindings() {
{ "nextcurrent_sw:", {
user_command::mucurrentindicatorothersourceactivate,
user_command::none } },
{ "instrumentlight_sw:", {
user_command::instrumentlighttoggle,
user_command::none } },
{ "cablight_sw:", {
user_command::interiorlighttoggle,
user_command::none } },
@@ -328,6 +369,36 @@ mouse_input::default_bindings() {
user_command::none } },
{ "battery_sw:", {
user_command::batterytoggle,
user_command::none } },
{ "universal0:", {
user_command::generictoggle0,
user_command::none } },
{ "universal1:", {
user_command::generictoggle1,
user_command::none } },
{ "universal2:", {
user_command::generictoggle2,
user_command::none } },
{ "universal3:", {
user_command::generictoggle3,
user_command::none } },
{ "universal4:", {
user_command::generictoggle4,
user_command::none } },
{ "universal5:", {
user_command::generictoggle5,
user_command::none } },
{ "universal6:", {
user_command::generictoggle6,
user_command::none } },
{ "universal7:", {
user_command::generictoggle7,
user_command::none } },
{ "universal8:", {
user_command::generictoggle8,
user_command::none } },
{ "universal9:", {
user_command::generictoggle9,
user_command::none } }
};
}

View File

@@ -10,7 +10,6 @@ http://mozilla.org/MPL/2.0/.
#pragma once
#include <unordered_map>
#include <array>
#include "command.h"
class mouse_input {
@@ -21,7 +20,7 @@ public:
// methods
bool
init() { return true; }
init();
void
move( double const Mousex, double const Mousey );
void
@@ -48,13 +47,16 @@ private:
default_bindings();
// members
command_relay m_relay;
controlcommands_map m_mousecommands;
user_command m_mousecommandleft { user_command::none }; // last if any command issued with left mouse button
user_command m_mousecommandright { user_command::none }; // last if any command issued with right mouse button
command_relay m_relay;
double m_updaterate { 0.075 };
double m_updateaccumulator { 0.0 };
bool m_pickmodepanning { false }; // indicates mouse is in view panning mode
glm::dvec2 m_cursorposition; // stored last mouse position, used for panning
glm::dvec2 m_cursorposition; // stored last cursor position, used for panning
glm::dvec2 m_commandstartcursor; // helper, cursor position when the command was initiated
bool m_varyingpollrate { false }; // indicates rate of command repeats is affected by the cursor position
};
//---------------------------------------------------------------------------

View File

@@ -39,6 +39,7 @@
#include <fstream>
#include <sstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>

31
translation.cpp Normal file
View File

@@ -0,0 +1,31 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
/*
MaSzyna EU07 locomotive simulator
Copyright (C) 2001-2004 Marcin Wozniak, Maciej Czapkiewicz and others
*/
#include "stdafx.h"
#include "translation.h"
namespace locale {
std::string
label_cab_control( std::string const &Label ) {
auto const lookup = m_cabcontrols.find( Label );
return (
lookup != m_cabcontrols.end() ?
lookup->second :
"" );
}
} // namespace locale
//---------------------------------------------------------------------------

95
translation.h Normal file
View File

@@ -0,0 +1,95 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <string>
#include <unordered_map>
namespace locale {
std::string
label_cab_control( std::string const &Label );
static std::unordered_map<std::string, std::string> m_cabcontrols = {
{ "mainctrl:", "master controller" },
{ "scndctrl:", "second controller" },
{ "dirkey:" , "reverser" },
{ "brakectrl:", "train brake" },
{ "localbrake:", "independent brake" },
{ "manualbrake:", "manual brake" },
{ "brakeprofile_sw:", "brake acting speed" },
{ "brakeprofileg_sw:", "brake acting speed: cargo" },
{ "brakeprofiler_sw:", "brake acting speed: rapid" },
{ "maxcurrent_sw:", "motor overload relay threshold" },
{ "main_off_bt:", "line breaker" },
{ "main_on_bt:", "line breaker" },
{ "security_reset_bt:", "alerter" },
{ "releaser_bt:", "independent brake releaser" },
{ "sand_bt:", "sandbox" },
{ "antislip_bt:", "wheelspin brake" },
{ "horn_bt:", "horn" },
{ "hornlow_bt:", "low tone horn" },
{ "hornhigh_bt:", "high tone horn" },
{ "fuse_bt:", "motor overload relay reset" },
{ "converterfuse_bt:", "converter overload relay reset" },
{ "stlinoff_bt:", "motor connectors" },
{ "door_left_sw:", "left door" },
{ "door_right_sw:", "right door" },
{ "departure_signal_bt:", "departure signal" },
{ "upperlight_sw:", "upper headlight" },
{ "leftlight_sw:", "left headlight" },
{ "rightlight_sw:", "right headlight" },
{ "dimheadlights_sw:", "headlights dimmer" },
{ "leftend_sw:", "left marker light" },
{ "rightend_sw:", "right marker light" },
{ "lights_sw:", "light pattern" },
{ "rearupperlight_sw:", "rear upper headlight" },
{ "rearleftlight_sw:", "rear left headlight" },
{ "rearrightlight_sw:", "rear right headlight" },
{ "rearleftend_sw:", "rear left marker light" },
{ "rearrightend_sw:", "rear right marker light" },
{ "compressor_sw:", "compressor" },
{ "compressorlocal_sw:", "local compressor" },
{ "converter_sw:", "converter" },
{ "converterlocal_sw:", "local converter" },
{ "converteroff_sw:", "converter" },
{ "main_sw:", "line breaker" },
{ "radio_sw:", "radio" },
{ "pantfront_sw:", "front pantograph" },
{ "pantrear_sw:", "rear pantograph" },
{ "pantfrontoff_sw:", "front pantograph" },
{ "pantrearoff_sw:", "rear pantograph" },
{ "pantalloff_sw:", "all pantographs" },
{ "pantselected_sw:", "selected pantograph" },
{ "pantselectedoff_sw:", "selected pantograph" },
{ "trainheating_sw:", "heating" },
{ "signalling_sw:", "braking indicator" },
{ "door_signalling_sw:", "door locking" },
{ "nextcurrent_sw:", "current indicator source" },
{ "instrumentlight_sw:", "instrument light" },
{ "cablight_sw:", "interior light" },
{ "cablightdim_sw:", "interior light dimmer" },
{ "battery_sw:", "battery" },
{ "universal0:", "generic" },
{ "universal1:", "generic" },
{ "universal2:", "generic" },
{ "universal3:", "generic" },
{ "universal4:", "generic" },
{ "universal5:", "generic" },
{ "universal6:", "generic" },
{ "universal7:", "generic" },
{ "universal8:", "generic" },
{ "universal9:", "generic" }
};
}
//---------------------------------------------------------------------------

View File

@@ -1,5 +1,5 @@
#pragma once
#define VERSION_MAJOR 17
#define VERSION_MINOR 710
#define VERSION_MINOR 712
#define VERSION_REVISION 0