mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-23 15:39:19 +02:00
merge (with bugs)
This commit is contained in:
@@ -10,6 +10,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "stdafx.h"
|
||||
#include "Button.h"
|
||||
#include "Console.h"
|
||||
#include "logs.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -57,6 +58,8 @@ void TButton::Load(cParser &Parser, TModel3d *pModel1, TModel3d *pModel2)
|
||||
{
|
||||
pModelOn = NULL;
|
||||
pModelOff = NULL;
|
||||
|
||||
ErrorLog( "Failed to locate sub-model \"" + token + "\" in 3d model \"" + pModel1->NameGet() + "\"" );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -66,6 +66,9 @@ set(SOURCES
|
||||
"uilayer.cpp"
|
||||
"openglmatrixstack.cpp"
|
||||
"moon.cpp"
|
||||
"command.cpp"
|
||||
"keyboardinput.cpp"
|
||||
"gamepadinput.cpp"
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
|
||||
359
Camera.cpp
359
Camera.cpp
@@ -15,23 +15,19 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "Console.h"
|
||||
#include "Timer.h"
|
||||
#include "mover.h"
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
// TViewPyramid TCamera::OrgViewPyramid;
|
||||
//={vector3(-1,1,1),vector3(1,1,1),vector3(-1,-1,1),vector3(1,-1,1),vector3(0,0,0)};
|
||||
|
||||
const vector3 OrgCrossPos = vector3(0, -10, 0);
|
||||
|
||||
void TCamera::Init(vector3 NPos, vector3 NAngle)
|
||||
{
|
||||
|
||||
pOffset = vector3(-0.0, 0, 0);
|
||||
vUp = vector3(0, 1, 0);
|
||||
// pOffset= vector3(-0.8,0,0);
|
||||
CrossPos = OrgCrossPos;
|
||||
CrossDist = 10;
|
||||
Velocity = vector3(0, 0, 0);
|
||||
OldVelocity = vector3(0, 0, 0);
|
||||
Pitch = NAngle.x;
|
||||
Yaw = NAngle.y;
|
||||
Roll = NAngle.z;
|
||||
@@ -54,51 +50,332 @@ void TCamera::OnCursorMove(double x, double y)
|
||||
if (Type == tp_Follow) // jeżeli jazda z pojazdem
|
||||
{
|
||||
clamp(Pitch, -M_PI_4, M_PI_4); // ograniczenie kąta spoglądania w dół i w górę
|
||||
// Fix(Yaw,-M_PI,M_PI);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TCamera::OnCommand( command_data const &Command ) {
|
||||
|
||||
double const walkspeed = 1.0;
|
||||
double const runspeed = ( DebugModeFlag ? 50.0 : 7.5 );
|
||||
double const speedmultiplier = ( DebugModeFlag ? 7.5 : 1.0 );
|
||||
|
||||
switch( Command.command ) {
|
||||
|
||||
case user_command::viewturn: {
|
||||
|
||||
OnCursorMove(
|
||||
reinterpret_cast<double const &>( Command.param1 ) * 0.005 * Global::fMouseXScale / Global::ZoomFactor,
|
||||
reinterpret_cast<double const &>( Command.param2 ) * -0.01 * Global::fMouseYScale / Global::ZoomFactor );
|
||||
break;
|
||||
}
|
||||
|
||||
case user_command::movevector: {
|
||||
|
||||
auto const movespeed =
|
||||
( Type == tp_Free ?
|
||||
runspeed * speedmultiplier :
|
||||
walkspeed );
|
||||
|
||||
// left-right
|
||||
double const movex = reinterpret_cast<double const &>( Command.param1 );
|
||||
if( movex > 0.0 ) {
|
||||
m_keys.right = true;
|
||||
m_keys.left = false;
|
||||
}
|
||||
else if( movex < 0.0 ) {
|
||||
m_keys.right = false;
|
||||
m_keys.left = true;
|
||||
}
|
||||
else {
|
||||
m_keys.right = false;
|
||||
m_keys.left = false;
|
||||
}
|
||||
// 2/3rd of the stick range enables walk speed, past that we lerp between walk and run speed
|
||||
m_moverate.x =
|
||||
walkspeed
|
||||
+ ( std::max( 0.0, std::abs( movex ) - 0.65 ) / 0.35 ) * ( movespeed - walkspeed );
|
||||
|
||||
// forward-back
|
||||
double const movez = reinterpret_cast<double const &>( Command.param2 );
|
||||
if( movez > 0.0 ) {
|
||||
m_keys.forward = true;
|
||||
m_keys.back = false;
|
||||
}
|
||||
else if( movez < 0.0 ) {
|
||||
m_keys.forward = false;
|
||||
m_keys.back = true;
|
||||
}
|
||||
else {
|
||||
m_keys.forward = false;
|
||||
m_keys.back = false;
|
||||
}
|
||||
m_moverate.z =
|
||||
walkspeed
|
||||
+ ( std::max( 0.0, std::abs( movez ) - 0.65 ) / 0.35 ) * ( movespeed - walkspeed );
|
||||
break;
|
||||
}
|
||||
|
||||
case user_command::moveforward: {
|
||||
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
m_keys.forward = true;
|
||||
m_moverate.z =
|
||||
( Type == tp_Free ?
|
||||
walkspeed * speedmultiplier :
|
||||
walkspeed );
|
||||
}
|
||||
else {
|
||||
m_keys.forward = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case user_command::moveback: {
|
||||
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
m_keys.back = true;
|
||||
m_moverate.z =
|
||||
( Type == tp_Free ?
|
||||
walkspeed * speedmultiplier :
|
||||
walkspeed );
|
||||
}
|
||||
else {
|
||||
m_keys.back = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case user_command::moveleft: {
|
||||
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
m_keys.left = true;
|
||||
m_moverate.x =
|
||||
( Type == tp_Free ?
|
||||
walkspeed * speedmultiplier :
|
||||
walkspeed );
|
||||
}
|
||||
else {
|
||||
m_keys.left = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case user_command::moveright: {
|
||||
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
m_keys.right = true;
|
||||
m_moverate.x =
|
||||
( Type == tp_Free ?
|
||||
walkspeed * speedmultiplier :
|
||||
walkspeed );
|
||||
}
|
||||
else {
|
||||
m_keys.right = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case user_command::moveup: {
|
||||
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
m_keys.up = true;
|
||||
m_moverate.y =
|
||||
( Type == tp_Free ?
|
||||
walkspeed * speedmultiplier :
|
||||
walkspeed );
|
||||
}
|
||||
else {
|
||||
m_keys.up = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case user_command::movedown: {
|
||||
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
m_keys.down = true;
|
||||
m_moverate.y =
|
||||
( Type == tp_Free ?
|
||||
walkspeed * speedmultiplier :
|
||||
walkspeed );
|
||||
}
|
||||
else {
|
||||
m_keys.down = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case user_command::moveforwardfast: {
|
||||
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
m_keys.forward = true;
|
||||
m_moverate.z =
|
||||
( Type == tp_Free ?
|
||||
runspeed * speedmultiplier :
|
||||
walkspeed );
|
||||
}
|
||||
else {
|
||||
m_keys.forward = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case user_command::movebackfast: {
|
||||
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
m_keys.back = true;
|
||||
m_moverate.z =
|
||||
( Type == tp_Free ?
|
||||
runspeed * speedmultiplier :
|
||||
walkspeed );
|
||||
}
|
||||
else {
|
||||
m_keys.back = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case user_command::moveleftfast: {
|
||||
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
m_keys.left = true;
|
||||
m_moverate.x =
|
||||
( Type == tp_Free ?
|
||||
runspeed * speedmultiplier :
|
||||
walkspeed );
|
||||
}
|
||||
else {
|
||||
m_keys.left = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case user_command::moverightfast: {
|
||||
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
m_keys.right = true;
|
||||
m_moverate.x =
|
||||
( Type == tp_Free ?
|
||||
runspeed * speedmultiplier :
|
||||
walkspeed );
|
||||
}
|
||||
else {
|
||||
m_keys.right = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case user_command::moveupfast: {
|
||||
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
m_keys.up = true;
|
||||
m_moverate.y =
|
||||
( Type == tp_Free ?
|
||||
runspeed * speedmultiplier :
|
||||
walkspeed );
|
||||
}
|
||||
else {
|
||||
m_keys.up = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case user_command::movedownfast: {
|
||||
|
||||
if( Command.action != GLFW_RELEASE ) {
|
||||
m_keys.down = true;
|
||||
m_moverate.y =
|
||||
( Type == tp_Free ?
|
||||
runspeed * speedmultiplier :
|
||||
walkspeed );
|
||||
}
|
||||
else {
|
||||
m_keys.down = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TCamera::Update()
|
||||
{
|
||||
// ABu: zmiana i uniezaleznienie predkosci od FPS
|
||||
double a = ( Global::shiftState ? 5.00 : 1.00);
|
||||
if (Global::ctrlState)
|
||||
a = a * 100;
|
||||
// OldVelocity=Velocity;
|
||||
if (FreeFlyModeFlag == true)
|
||||
Type = tp_Free;
|
||||
else
|
||||
Type = tp_Follow;
|
||||
if (Type == tp_Free)
|
||||
{
|
||||
if (Console::Pressed(Global::Keys[k_MechUp]))
|
||||
Velocity.y += a;
|
||||
if (Console::Pressed(Global::Keys[k_MechDown]))
|
||||
Velocity.y -= a;
|
||||
if( FreeFlyModeFlag == true ) { Type = tp_Free; }
|
||||
else { Type = tp_Follow; }
|
||||
|
||||
// check for sent user commands
|
||||
// NOTE: this is a temporary arrangement, for the transition period from old command setup to the new one
|
||||
// ultimately we'll need to track position of camera/driver for all human entities present in the scenario
|
||||
command_data command;
|
||||
// NOTE: currently we're only storing commands for local entity and there's no id system in place,
|
||||
// so we're supplying 'default' entity id of 0
|
||||
while( simulation::Commands.pop( command, static_cast<std::size_t>( command_target::entity ) | 0 ) ) {
|
||||
|
||||
OnCommand( command );
|
||||
}
|
||||
|
||||
auto const deltatime = Timer::GetDeltaRenderTime(); // czas bez pauzy
|
||||
|
||||
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
|
||||
double a = 0.8; // default (walk) movement speed
|
||||
if( Type == tp_Free ) {
|
||||
// when not in the cab the speed modifiers are active
|
||||
if( Global::shiftState ) { a = 2.5; }
|
||||
if( Global::ctrlState ) { a *= 10.0; }
|
||||
}
|
||||
|
||||
if( ( Type == tp_Free )
|
||||
|| ( false == Global::ctrlState ) ) {
|
||||
// ctrl is used for mirror view, so we ignore the controls when in vehicle if ctrl is pressed
|
||||
if( Console::Pressed( Global::Keys[ k_MechUp ] ) )
|
||||
Velocity.y = clamp( Velocity.y + a * 10.0 * deltatime, -a, a );
|
||||
if( Console::Pressed( Global::Keys[ k_MechDown ] ) )
|
||||
Velocity.y = clamp( Velocity.y - a * 10.0 * deltatime, -a, a );
|
||||
|
||||
// McZapkie-170402: poruszanie i rozgladanie we free takie samo jak w follow
|
||||
if (Console::Pressed(Global::Keys[k_MechRight]))
|
||||
Velocity.x += a;
|
||||
if (Console::Pressed(Global::Keys[k_MechLeft]))
|
||||
Velocity.x -= a;
|
||||
if (Console::Pressed(Global::Keys[k_MechForward]))
|
||||
Velocity.z -= a;
|
||||
if (Console::Pressed(Global::Keys[k_MechBackward]))
|
||||
Velocity.z += a;
|
||||
// gora-dol
|
||||
// if (Console::Pressed(GLFW_KEY_KP_9)) Pos.y+=0.1;
|
||||
// if (Console::Pressed(GLFW_KEY_KP_3)) Pos.y-=0.1;
|
||||
if( Console::Pressed( Global::Keys[ k_MechRight ] ) )
|
||||
Velocity.x = clamp( Velocity.x + a * 10.0 * deltatime, -a, a );
|
||||
if( Console::Pressed( Global::Keys[ k_MechLeft ] ) )
|
||||
Velocity.x = clamp( Velocity.x - a * 10.0 * deltatime, -a, a );
|
||||
if( Console::Pressed( Global::Keys[ k_MechForward ] ) )
|
||||
Velocity.z = clamp( Velocity.z - a * 10.0 * deltatime, -a, a );
|
||||
if( Console::Pressed( Global::Keys[ k_MechBackward ] ) )
|
||||
Velocity.z = clamp( Velocity.z + a * 10.0 * deltatime, -a, a );
|
||||
}
|
||||
#else
|
||||
/*
|
||||
m_moverate = 0.8; // default (walk) movement speed
|
||||
if( Type == tp_Free ) {
|
||||
// when not in the cab the speed modifiers are active
|
||||
if( Global::shiftState ) { m_moverate = 2.5; }
|
||||
if( Global::ctrlState ) { m_moverate *= 10.0; }
|
||||
}
|
||||
*/
|
||||
if( ( Type == tp_Free )
|
||||
|| ( false == Global::ctrlState ) ) {
|
||||
// ctrl is used for mirror view, so we ignore the controls when in vehicle if ctrl is pressed
|
||||
if( m_keys.up )
|
||||
Velocity.y = clamp( Velocity.y + m_moverate.y * 10.0 * deltatime, -m_moverate.y, m_moverate.y );
|
||||
if( m_keys.down )
|
||||
Velocity.y = clamp( Velocity.y - m_moverate.y * 10.0 * deltatime, -m_moverate.y, m_moverate.y );
|
||||
|
||||
// McZapkie: zeby nie hustalo przy malym FPS:
|
||||
// Velocity= (Velocity+OldVelocity)/2;
|
||||
// matrix4x4 mat;
|
||||
// McZapkie-170402: poruszanie i rozgladanie we free takie samo jak w follow
|
||||
if( m_keys.right )
|
||||
Velocity.x = clamp( Velocity.x + m_moverate.x * 10.0 * deltatime, -m_moverate.x, m_moverate.x );
|
||||
if( m_keys.left )
|
||||
Velocity.x = clamp( Velocity.x - m_moverate.x * 10.0 * deltatime, -m_moverate.x, m_moverate.x );
|
||||
if( m_keys.forward )
|
||||
Velocity.z = clamp( Velocity.z - m_moverate.z * 10.0 * deltatime, -m_moverate.z, m_moverate.z );
|
||||
if( m_keys.back )
|
||||
Velocity.z = clamp( Velocity.z + m_moverate.z * 10.0 * deltatime, -m_moverate.z, m_moverate.z );
|
||||
}
|
||||
#endif
|
||||
|
||||
if( Type == tp_Free ) {
|
||||
// free movement position update is handled here, movement while in vehicle is handled by train update
|
||||
vector3 Vec = Velocity;
|
||||
Vec.RotateY(Yaw);
|
||||
Pos = Pos + Vec * Timer::GetDeltaRenderTime(); // czas bez pauzy
|
||||
Velocity = Velocity / 2; // płynne hamowanie ruchu
|
||||
// double tmp= 10*DeltaTime;
|
||||
// Velocity+= -Velocity*10 * Timer::GetDeltaTime();//( tmp<1 ? tmp : 1 );
|
||||
// Type= tp_Free;
|
||||
Vec.RotateY( Yaw );
|
||||
Pos += Vec * 5.0 * deltatime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
17
Camera.h
17
Camera.h
@@ -11,6 +11,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "dumb3d.h"
|
||||
#include "dynobj.h"
|
||||
#include "command.h"
|
||||
|
||||
using namespace Math3D;
|
||||
|
||||
@@ -25,7 +26,16 @@ enum TCameraType
|
||||
class TCamera
|
||||
{
|
||||
private:
|
||||
vector3 pOffset; // nie używane (zerowe)
|
||||
struct keys {
|
||||
bool forward{ false };
|
||||
bool back{ false };
|
||||
bool left{ false };
|
||||
bool right{ false };
|
||||
bool up{ false };
|
||||
bool down{ false };
|
||||
bool run{ false };
|
||||
} m_keys;
|
||||
glm::dvec3 m_moverate;
|
||||
|
||||
public: // McZapkie: potrzebuje do kiwania na boki
|
||||
double Pitch;
|
||||
@@ -36,7 +46,6 @@ class TCamera
|
||||
vector3 LookAt; // współrzędne punktu, na który ma patrzeć
|
||||
vector3 vUp;
|
||||
vector3 Velocity;
|
||||
vector3 OldVelocity; // lepiej usredniac zeby nie bylo rozbiezne przy malym FPS
|
||||
vector3 CrossPos;
|
||||
double CrossDist;
|
||||
void Init(vector3 NPos, vector3 NAngle);
|
||||
@@ -44,10 +53,10 @@ class TCamera
|
||||
{
|
||||
Pitch = Yaw = Roll = 0;
|
||||
};
|
||||
void OnCursorMove(double x, double y);
|
||||
void OnCursorMove(double const x, double const y);
|
||||
void OnCommand( command_data const &Command );
|
||||
void Update();
|
||||
vector3 GetDirection();
|
||||
// vector3 inline GetCrossPos() { return Pos+GetDirection()*CrossDist+CrossPos; };
|
||||
bool SetMatrix();
|
||||
bool SetMatrix(glm::mat4 &Matrix);
|
||||
void SetCabMatrix( vector3 &p );
|
||||
|
||||
57
Console.cpp
57
Console.cpp
@@ -82,29 +82,14 @@ public static Int32 GetScreenSaverTimeout()
|
||||
// static class member storage allocation
|
||||
TKeyTrans Console::ktTable[4 * 256];
|
||||
|
||||
// Ra: do poprawienia
|
||||
void SetLedState(unsigned char Code, bool bOn){
|
||||
// Ra: bajer do migania LED-ami w klawiaturze
|
||||
// NOTE: disabled for the time being
|
||||
// TODO: find non Borland specific equivalent, or get rid of it
|
||||
/* if (Win32Platform == VER_PLATFORM_WIN32_NT)
|
||||
{
|
||||
// WriteLog(AnsiString(int(GetAsyncKeyState(Code))));
|
||||
if (bool(GetAsyncKeyState(Code)) != bOn)
|
||||
{
|
||||
keybd_event(Code, MapVirtualKey(Code, 0), KEYEVENTF_EXTENDEDKEY, 0);
|
||||
keybd_event(Code, MapVirtualKey(Code, 0), KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
|
||||
0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TKeyboardState KBState;
|
||||
GetKeyboardState(KBState);
|
||||
KBState[Code] = bOn ? 1 : 0;
|
||||
SetKeyboardState(KBState);
|
||||
};
|
||||
*/
|
||||
// Ra: bajer do migania LED-ami w klawiaturze
|
||||
void SetLedState( unsigned char Code, bool bOn ) {
|
||||
#ifdef _WINDOWS
|
||||
if( bOn != ( ::GetKeyState( Code ) != 0 ) ) {
|
||||
keybd_event( Code, MapVirtualKey( Code, 0 ), KEYEVENTF_EXTENDEDKEY | 0, 0 );
|
||||
keybd_event( Code, MapVirtualKey( Code, 0 ), KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0 );
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -243,22 +228,24 @@ void Console::BitsUpdate(int mask)
|
||||
switch (iMode)
|
||||
{
|
||||
case 1: // sterowanie światełkami klawiatury: CA/SHP+opory
|
||||
if (mask & 3) // gdy SHP albo CA
|
||||
SetLedState(VK_CAPITAL, (iBits & 3) != 0);
|
||||
if (mask & 4) // gdy jazda na oporach
|
||||
{ // Scroll Lock ma jakoś dziwnie... zmiana stanu na przeciwny
|
||||
SetLedState(VK_SCROLL, true); // przyciśnięty
|
||||
SetLedState(VK_SCROLL, false); // zwolniony
|
||||
if( mask & 3 ) {
|
||||
// gdy SHP albo CA
|
||||
SetLedState( VK_CAPITAL, ( iBits & 3 ) != 0 );
|
||||
}
|
||||
if (mask & 4) {
|
||||
// gdy jazda na oporach
|
||||
SetLedState( VK_SCROLL, ( iBits & 4 ) != 0 );
|
||||
++iConfig; // licznik użycia Scroll Lock
|
||||
}
|
||||
break;
|
||||
case 2: // sterowanie światełkami klawiatury: CA+SHP
|
||||
if (mask & 2) // gdy CA
|
||||
SetLedState(VK_CAPITAL, (iBits & 2) != 0);
|
||||
if (mask & 1) // gdy SHP
|
||||
{ // Scroll Lock ma jakoś dziwnie... zmiana stanu na przeciwny
|
||||
SetLedState(VK_SCROLL, true); // przyciśnięty
|
||||
SetLedState(VK_SCROLL, false); // zwolniony
|
||||
if( mask & 2 ) {
|
||||
// gdy CA
|
||||
SetLedState( VK_CAPITAL, ( iBits & 2 ) != 0 );
|
||||
}
|
||||
if (mask & 1) {
|
||||
// gdy SHP
|
||||
SetLedState( VK_SCROLL, ( iBits & 1 ) != 0 );
|
||||
++iConfig; // licznik użycia Scroll Lock
|
||||
}
|
||||
break;
|
||||
|
||||
14
Driver.cpp
14
Driver.cpp
@@ -828,12 +828,12 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN
|
||||
#if LOGSTOPS
|
||||
WriteLog(
|
||||
pVehicle->asName + " as " + TrainParams->TrainName
|
||||
+ ": at " + std::to_string(Simulation::Time.data().wHour) + ":" + std::to_string(Simulation::Time.data().wMinute)
|
||||
+ ": at " + std::to_string(simulation::Time.data().wHour) + ":" + std::to_string(simulation::Time.data().wMinute)
|
||||
+ " skipped " + asNextStop); // informacja
|
||||
#endif
|
||||
// przy jakim dystansie (stanie licznika) ma przesunąć na następny postój
|
||||
fLastStopExpDist = mvOccupied->DistCounter + 0.250 + 0.001 * fLength;
|
||||
TrainParams->UpdateMTable( Simulation::Time, asNextStop );
|
||||
TrainParams->UpdateMTable( simulation::Time, asNextStop );
|
||||
TrainParams->StationIndexInc(); // przejście do następnej
|
||||
asNextStop = TrainParams->NextStop(); // pobranie kolejnego miejsca zatrzymania
|
||||
// TableClear(); //aby od nowa sprawdziło W4 z inną nazwą już - to nie
|
||||
@@ -930,7 +930,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN
|
||||
// niezależne od sposobu obsługi drzwi, bo
|
||||
// opóźnia również kierownika
|
||||
}
|
||||
if (TrainParams->UpdateMTable( Simulation::Time, asNextStop) )
|
||||
if (TrainParams->UpdateMTable( simulation::Time, asNextStop) )
|
||||
{ // to się wykona tylko raz po zatrzymaniu na W4
|
||||
if (TrainParams->CheckTrainLatency() < 0.0)
|
||||
iDrivigFlags |= moveLate; // odnotowano spóźnienie
|
||||
@@ -976,7 +976,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN
|
||||
if (TrainParams->StationIndex < TrainParams->StationCount)
|
||||
{ // jeśli są dalsze stacje, czekamy do godziny odjazdu
|
||||
|
||||
if (TrainParams->IsTimeToGo(Simulation::Time.data().wHour, Simulation::Time.data().wMinute))
|
||||
if (TrainParams->IsTimeToGo(simulation::Time.data().wHour, simulation::Time.data().wMinute))
|
||||
{ // z dalszą akcją czekamy do godziny odjazdu
|
||||
/* potencjalny problem z ruszaniem z w4
|
||||
if (TrainParams->CheckTrainLatency() < 0)
|
||||
@@ -995,7 +995,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN
|
||||
#if LOGSTOPS
|
||||
WriteLog(
|
||||
pVehicle->asName + " as " + TrainParams->TrainName
|
||||
+ ": at " + std::to_string(Simulation::Time.data().wHour) + ":" + std::to_string(Simulation::Time.data().wMinute)
|
||||
+ ": at " + std::to_string(simulation::Time.data().wHour) + ":" + std::to_string(simulation::Time.data().wMinute)
|
||||
+ " next " + asNextStop); // informacja
|
||||
#endif
|
||||
if (int(floor(sSpeedTable[i].evEvent->ValueGet(1))) & 1)
|
||||
@@ -1022,7 +1022,7 @@ TCommandType TController::TableUpdate(double &fVelDes, double &fDist, double &fN
|
||||
#if LOGSTOPS
|
||||
WriteLog(
|
||||
pVehicle->asName + " as " + TrainParams->TrainName
|
||||
+ ": at " + std::to_string(Simulation::Time.data().wHour) + ":" + std::to_string(Simulation::Time.data().wMinute)
|
||||
+ ": at " + std::to_string(simulation::Time.data().wHour) + ":" + std::to_string(simulation::Time.data().wMinute)
|
||||
+ " end of route."); // informacja
|
||||
#endif
|
||||
asNextStop = TrainParams->NextStop(); // informacja o końcu trasy
|
||||
@@ -2865,7 +2865,7 @@ bool TController::PutCommand(std::string NewCommand, double NewValue1, double Ne
|
||||
}
|
||||
else
|
||||
{ // inicjacja pierwszego przystanku i pobranie jego nazwy
|
||||
TrainParams->UpdateMTable( Simulation::Time, TrainParams->NextStationName );
|
||||
TrainParams->UpdateMTable( simulation::Time, TrainParams->NextStationName );
|
||||
TrainParams->StationIndexInc(); // przejście do następnej
|
||||
iStationStart = TrainParams->StationIndex;
|
||||
asNextStop = TrainParams->NextStop();
|
||||
|
||||
89
DynObj.cpp
89
DynObj.cpp
@@ -986,11 +986,8 @@ TDynamicObject * TDynamicObject::ABuFindNearestObject(TTrack *Track, TDynamicObj
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
TDynamicObject * TDynamicObject::ABuScanNearestObject(TTrack *Track, double ScanDir,
|
||||
double ScanDist, int &CouplNr)
|
||||
{ // skanowanie toru w poszukiwaniu obiektu najblizszego
|
||||
// kamerze
|
||||
// double MyScanDir=ScanDir; //Moja orientacja na torze. //Ra: nie używane
|
||||
TDynamicObject * TDynamicObject::ABuScanNearestObject(TTrack *Track, double ScanDir, double ScanDist, int &CouplNr)
|
||||
{ // skanowanie toru w poszukiwaniu obiektu najblizszego kamerze
|
||||
if (ABuGetDirection() < 0)
|
||||
ScanDir = -ScanDir;
|
||||
TDynamicObject *FoundedObj;
|
||||
@@ -2914,11 +2911,12 @@ bool TDynamicObject::Update(double dt, double dt1)
|
||||
|
||||
// fragment "z EXE Kursa"
|
||||
if (MoverParameters->Mains) // nie wchodzić w funkcję bez potrzeby
|
||||
if ((!MoverParameters->Battery) && (Controller == Humandriver) &&
|
||||
(MoverParameters->EngineType != DieselEngine) &&
|
||||
(MoverParameters->EngineType != WheelsDriven))
|
||||
{ // jeśli bateria wyłączona, a nie diesel ani drezyna
|
||||
// reczna
|
||||
if ( ( false == MoverParameters->Battery)
|
||||
&& ( false == MoverParameters->ConverterFlag ) // added alternative power source. TODO: more generic power check
|
||||
&& ( Controller == Humandriver)
|
||||
&& ( MoverParameters->EngineType != DieselEngine )
|
||||
&& ( MoverParameters->EngineType != WheelsDriven ) )
|
||||
{ // jeśli bateria wyłączona, a nie diesel ani drezyna reczna
|
||||
if (MoverParameters->MainSwitch(false)) // wyłączyć zasilanie
|
||||
MoverParameters->EventFlag = true;
|
||||
}
|
||||
@@ -3291,8 +3289,7 @@ bool TDynamicObject::Update(double dt, double dt1)
|
||||
if (tmpTraction.TractionVoltage == 0)
|
||||
{ // to coś wyłączało dźwięk silnika w ST43!
|
||||
MoverParameters->ConverterFlag = false;
|
||||
MoverParameters->CompressorFlag = false; // Ra: to jest wątpliwe - wyłączenie
|
||||
// sprężarki powinno być w jednym miejscu!
|
||||
MoverParameters->CompressorFlag = false; // Ra: to jest wątpliwe - wyłączenie sprężarki powinno być w jednym miejscu!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4297,45 +4294,47 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
|
||||
}
|
||||
#else
|
||||
{ // tekstura wymienna jest raczej jedynie w "dynamic\"
|
||||
ReplacableSkin = Global::asCurrentTexturePath + ReplacableSkin; // skory tez z dynamic/...
|
||||
std::string x = TextureTest(Global::asCurrentTexturePath + "nowhere"); // na razie prymitywnie
|
||||
if (!x.empty())
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.GetTextureId( Global::asCurrentTexturePath + "nowhere", "", 9 );
|
||||
// ReplacableSkin = Global::asCurrentTexturePath + ReplacableSkin; // skory tez z dynamic/...
|
||||
std::string nowheretexture = TextureTest(Global::asCurrentTexturePath + "nowhere"); // na razie prymitywnie
|
||||
if( false == nowheretexture.empty() ) {
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.GetTextureId( nowheretexture, "", 9 );
|
||||
}
|
||||
|
||||
if (m_materialdata.multi_textures > 0)
|
||||
{ // jeśli model ma 4 tekstury
|
||||
m_materialdata.replacable_skins[ 1 ] = GfxRenderer.GetTextureId(
|
||||
ReplacableSkin + ",1", "", Global::iDynamicFiltering);
|
||||
if( m_materialdata.replacable_skins[ 1 ] )
|
||||
{ // pierwsza z zestawu znaleziona
|
||||
m_materialdata.replacable_skins[ 2 ] = GfxRenderer.GetTextureId(
|
||||
ReplacableSkin + ",2", "", Global::iDynamicFiltering);
|
||||
if( m_materialdata.replacable_skins[ 2 ] )
|
||||
{
|
||||
m_materialdata.multi_textures = 2; // już są dwie
|
||||
m_materialdata.replacable_skins[ 3 ] = GfxRenderer.GetTextureId(
|
||||
ReplacableSkin + ",3", "", Global::iDynamicFiltering);
|
||||
if( m_materialdata.replacable_skins[ 3 ] )
|
||||
{
|
||||
m_materialdata.multi_textures = 3; // a teraz nawet trzy
|
||||
m_materialdata.replacable_skins[ 4 ] = GfxRenderer.GetTextureId(
|
||||
ReplacableSkin + ",4", "", Global::iDynamicFiltering);
|
||||
if( m_materialdata.replacable_skins[ 4 ] )
|
||||
m_materialdata.multi_textures = 4; // jak są cztery, to blokujemy podmianę tekstury
|
||||
// rozkładem
|
||||
}
|
||||
if (m_materialdata.multi_textures > 0) {
|
||||
// jeśli model ma 4 tekstury
|
||||
// check for the pipe method first
|
||||
if( ReplacableSkin.find( '|' ) != std::string::npos ) {
|
||||
cParser nameparser( ReplacableSkin );
|
||||
nameparser.getTokens( 4, true, "|" );
|
||||
int skinindex = 0;
|
||||
std::string texturename; nameparser >> texturename;
|
||||
while( ( texturename != "" ) && ( skinindex < 4 ) ) {
|
||||
m_materialdata.replacable_skins[ skinindex + 1 ] = GfxRenderer.GetTextureId( Global::asCurrentTexturePath + texturename, "" );
|
||||
++skinindex;
|
||||
texturename = ""; nameparser >> texturename;
|
||||
}
|
||||
m_materialdata.multi_textures = skinindex;
|
||||
}
|
||||
else
|
||||
{ // zestaw nie zadziałał, próbujemy normanie
|
||||
m_materialdata.multi_textures = 0;
|
||||
m_materialdata.replacable_skins[ 1 ] = GfxRenderer.GetTextureId(
|
||||
ReplacableSkin, "", Global::iDynamicFiltering);
|
||||
else {
|
||||
// otherwise try the basic approach
|
||||
int skinindex = 0;
|
||||
do {
|
||||
texture_manager::size_type texture = GfxRenderer.GetTextureId( Global::asCurrentTexturePath + ReplacableSkin + "," + std::to_string( skinindex + 1 ), "", Global::iDynamicFiltering, true );
|
||||
if( false == GfxRenderer.Texture( texture ).is_ready ) {
|
||||
break;
|
||||
}
|
||||
m_materialdata.replacable_skins[ skinindex + 1 ] = texture;
|
||||
++skinindex;
|
||||
} while( skinindex < 4 );
|
||||
m_materialdata.multi_textures = skinindex;
|
||||
if( m_materialdata.multi_textures == 0 ) {
|
||||
// zestaw nie zadziałał, próbujemy normanie
|
||||
m_materialdata.replacable_skins[ 1 ] = GfxRenderer.GetTextureId( Global::asCurrentTexturePath + ReplacableSkin, "", Global::iDynamicFiltering );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
m_materialdata.replacable_skins[ 1 ] = GfxRenderer.GetTextureId(
|
||||
ReplacableSkin, "", Global::iDynamicFiltering);
|
||||
m_materialdata.replacable_skins[ 1 ] = GfxRenderer.GetTextureId( Global::asCurrentTexturePath + ReplacableSkin, "", Global::iDynamicFiltering );
|
||||
if( GfxRenderer.Texture( m_materialdata.replacable_skins[ 1 ] ).has_alpha )
|
||||
m_materialdata.textures_alpha = 0x31310031; // tekstura -1 z kanałem alfa - nie renderować w cyklu nieprzezroczystych
|
||||
else
|
||||
|
||||
79
EU07.cpp
79
EU07.cpp
@@ -20,9 +20,12 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others
|
||||
#include "stdafx.h"
|
||||
#include <png.h>
|
||||
#include <thread>
|
||||
#include <direct.h>
|
||||
|
||||
#include "Globals.h"
|
||||
#include "Logs.h"
|
||||
#include "keyboardinput.h"
|
||||
#include "gamepadinput.h"
|
||||
#include "Console.h"
|
||||
#include "PyInt.h"
|
||||
#include "World.h"
|
||||
@@ -40,7 +43,14 @@ Stele, firleju, szociu, hunter, ZiomalCl, OLI_EU and others
|
||||
|
||||
TWorld World;
|
||||
|
||||
void screenshot_save_thread(char *img)
|
||||
namespace input {
|
||||
|
||||
keyboard_input Keyboard;
|
||||
gamepad_input Gamepad;
|
||||
|
||||
}
|
||||
|
||||
void screenshot_save_thread( char *img )
|
||||
{
|
||||
png_image png;
|
||||
memset(&png, 0, sizeof(png_image));
|
||||
@@ -91,12 +101,17 @@ void window_resize_callback(GLFWwindow *window, int w, int h)
|
||||
|
||||
void cursor_pos_callback(GLFWwindow *window, double x, double y)
|
||||
{
|
||||
input::Keyboard.mouse( x, y );
|
||||
#ifdef EU07_USE_OLD_COMMAND_SYSTEM
|
||||
World.OnMouseMove(x * 0.005, y * 0.01);
|
||||
#endif
|
||||
glfwSetCursorPos(window, 0.0, 0.0);
|
||||
}
|
||||
|
||||
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;
|
||||
Global::ctrlState = ( mods & GLFW_MOD_CONTROL ) ? true : false;
|
||||
|
||||
@@ -116,54 +131,15 @@ void key_callback( GLFWwindow *window, int key, int scancode, int action, int mo
|
||||
|
||||
switch( key )
|
||||
{
|
||||
case GLFW_KEY_F11:
|
||||
make_screenshot();
|
||||
break;
|
||||
case GLFW_KEY_ESCAPE: {
|
||||
/*
|
||||
if( ( DebugModeFlag ) //[Esc] pauzuje tylko bez Debugmode
|
||||
&& ( Global::iPause == 0 ) ) { // but unpausing should work always
|
||||
|
||||
break;
|
||||
}
|
||||
*/
|
||||
if( Global::iPause & 1 ) // jeśli pauza startowa
|
||||
Global::iPause &= ~1; // odpauzowanie, gdy po wczytaniu miało nie startować
|
||||
else if( !( Global::iMultiplayer & 2 ) ) // w multiplayerze pauza nie ma sensu
|
||||
if( !Global::ctrlState ) // z [Ctrl] to radiostop jest
|
||||
Global::iPause ^= 2; // zmiana stanu zapauzowania
|
||||
if( Global::iPause ) {// jak pauza
|
||||
Global::iTextMode = GLFW_KEY_F1; // to wyświetlić zegar i informację
|
||||
}
|
||||
|
||||
case GLFW_KEY_F11: {
|
||||
make_screenshot();
|
||||
break;
|
||||
}
|
||||
case GLFW_KEY_F7:
|
||||
if( DebugModeFlag ) {
|
||||
|
||||
if( Global::ctrlState ) {
|
||||
// ctrl + f7 toggles static daylight
|
||||
World.ToggleDaylight();
|
||||
break;
|
||||
}
|
||||
// f7: wireframe toggle
|
||||
// siatki wyświetlane tyko w trybie testowym
|
||||
Global::bWireFrame = !Global::bWireFrame;
|
||||
if( true == Global::bWireFrame ) {
|
||||
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
||||
}
|
||||
else {
|
||||
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
|
||||
}
|
||||
++Global::iReCompile; // odświeżyć siatki
|
||||
// Ra: jeszcze usunąć siatki ze skompilowanych obiektów!
|
||||
}
|
||||
break;
|
||||
default: { break; }
|
||||
}
|
||||
}
|
||||
else if( action == GLFW_RELEASE )
|
||||
{
|
||||
World.OnKeyUp( key );
|
||||
}
|
||||
}
|
||||
|
||||
void focus_callback( GLFWwindow *window, int focus )
|
||||
@@ -204,7 +180,11 @@ int main(int argc, char *argv[])
|
||||
if (!glfwInit())
|
||||
return -1;
|
||||
|
||||
DeleteFile("errors.txt");
|
||||
#ifdef _WINDOWS
|
||||
DeleteFile( "log.txt" );
|
||||
DeleteFile( "errors.txt" );
|
||||
mkdir("logs");
|
||||
#endif
|
||||
Global::LoadIniFile("eu07.ini");
|
||||
Global::InitKeys();
|
||||
|
||||
@@ -321,6 +301,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
return -1;
|
||||
}
|
||||
input::Keyboard.init();
|
||||
input::Gamepad.init();
|
||||
|
||||
Global::pWorld = &World; // Ra: wskaźnik potrzebny do usuwania pojazdów
|
||||
try
|
||||
@@ -338,9 +320,10 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
Console *pConsole = new Console(); // Ra: nie wiem, czy ma to sens, ale jakoś zainicjowac trzeba
|
||||
|
||||
/*
|
||||
if( !joyGetNumDevs() )
|
||||
WriteLog( "No joystick" );
|
||||
*/
|
||||
if( Global::iModifyTGA < 0 ) { // tylko modyfikacja TGA, bez uruchamiania symulacji
|
||||
Global::iMaxTextureSize = 64; //żeby nie zamulać pamięci
|
||||
World.ModifyTGA(); // rekurencyjne przeglądanie katalogów
|
||||
@@ -357,7 +340,8 @@ int main(int argc, char *argv[])
|
||||
&& World.Update()
|
||||
&& GfxRenderer.Render())
|
||||
{
|
||||
glfwPollEvents();
|
||||
glfwPollEvents();
|
||||
input::Gamepad.poll();
|
||||
}
|
||||
Console::Off(); // wyłączenie konsoli (komunikacji zwrotnej)
|
||||
}
|
||||
@@ -367,5 +351,6 @@ int main(int argc, char *argv[])
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -175,9 +175,9 @@ bool TEventLauncher::Render()
|
||||
}
|
||||
else
|
||||
{ // jeśli nie cykliczny, to sprawdzić czas
|
||||
if (Simulation::Time.data().wHour == iHour)
|
||||
if (simulation::Time.data().wHour == iHour)
|
||||
{
|
||||
if (Simulation::Time.data().wMinute == iMinute)
|
||||
if (simulation::Time.data().wMinute == iMinute)
|
||||
{ // zgodność czasu uruchomienia
|
||||
if (UpdatedTime < 10)
|
||||
{
|
||||
|
||||
26
Float3d.h
26
Float3d.h
@@ -66,7 +66,7 @@ inline float3 operator/( float3 const &v, float const k )
|
||||
};
|
||||
inline float3 SafeNormalize(const float3 &v)
|
||||
{ // bezpieczna normalizacja (wektor długości 1.0)
|
||||
double l = v.Length();
|
||||
auto const l = v.Length();
|
||||
float3 retVal;
|
||||
if (l == 0)
|
||||
retVal.x = retVal.y = retVal.z = 0;
|
||||
@@ -104,11 +104,11 @@ class float4
|
||||
z = c;
|
||||
w = d;
|
||||
};
|
||||
double inline float4::LengthSquared() const
|
||||
float inline float4::LengthSquared() const
|
||||
{
|
||||
return x * x + y * y + z * z + w * w;
|
||||
};
|
||||
double inline float4::Length() const
|
||||
float inline float4::Length() const
|
||||
{
|
||||
return sqrt(x * x + y * y + z * z + w * w);
|
||||
};
|
||||
@@ -132,26 +132,26 @@ inline float4 operator+(const float4 &v1, const float4 &v2)
|
||||
{
|
||||
return float4(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w);
|
||||
};
|
||||
inline float4 operator/(const float4 &v, double k)
|
||||
inline float4 operator/(const float4 &v, float const k)
|
||||
{
|
||||
return float4(v.x / k, v.y / k, v.z / k, v.w / k);
|
||||
};
|
||||
inline float4 Normalize(const float4 &v)
|
||||
{ // bezpieczna normalizacja (wektor długości 1.0)
|
||||
double l = v.LengthSquared();
|
||||
if (l == 1.0)
|
||||
auto const lengthsquared = v.LengthSquared();
|
||||
if (lengthsquared == 1.0)
|
||||
return v;
|
||||
if (l == 0.0)
|
||||
if (lengthsquared == 0.0)
|
||||
return float4(); // wektor zerowy, w=1
|
||||
else
|
||||
return v / sqrt(l); // pierwiastek liczony tylko jeśli trzeba wykonać dzielenia
|
||||
return v / std::sqrt(lengthsquared); // pierwiastek liczony tylko jeśli trzeba wykonać dzielenia
|
||||
};
|
||||
inline
|
||||
float Dot(const float4 &q1, const float4 &q2)
|
||||
{ // iloczyn skalarny
|
||||
return q1.x * q2.x + q1.y * q2.y + q1.z * q2.z + q1.w * q2.w;
|
||||
}
|
||||
inline float4 &operator*=(float4 &v1, double d)
|
||||
inline float4 &operator*=(float4 &v1, float const d)
|
||||
{ // mnożenie przez skalar, jaki ma sens?
|
||||
v1.x *= d;
|
||||
v1.y *= d;
|
||||
@@ -172,7 +172,7 @@ inline float4 Slerp(const float4 &q0, const float4 &q1, float t)
|
||||
new_q1.w = -new_q1.w;
|
||||
cosOmega = -cosOmega;
|
||||
}
|
||||
double k0, k1;
|
||||
float k0, k1;
|
||||
if (cosOmega > 0.9999f)
|
||||
{ // jeśli jesteśmy z (t) na maksimum kosinusa, to tam prawie liniowo jest
|
||||
k0 = 1.0f - t;
|
||||
@@ -180,9 +180,9 @@ inline float4 Slerp(const float4 &q0, const float4 &q1, float t)
|
||||
}
|
||||
else
|
||||
{ // a w ogólnym przypadku trzeba liczyć na trygonometrię
|
||||
double sinOmega = sqrt(1.0f - cosOmega * cosOmega); // sinus z jedynki tryg.
|
||||
double omega = atan2(sinOmega, cosOmega); // wyznaczenie kąta
|
||||
double oneOverSinOmega = 1.0f / sinOmega; // odwrotność sinusa, bo sinus w mianowniku
|
||||
auto const sinOmega = std::sqrt(1.0f - cosOmega * cosOmega); // sinus z jedynki tryg.
|
||||
auto const omega = std::atan2(sinOmega, cosOmega); // wyznaczenie kąta
|
||||
auto const oneOverSinOmega = 1.0f / sinOmega; // odwrotność sinusa, bo sinus w mianowniku
|
||||
k0 = sin((1.0f - t) * omega) * oneOverSinOmega;
|
||||
k1 = sin(t * omega) * oneOverSinOmega;
|
||||
}
|
||||
|
||||
28
Gauge.cpp
28
Gauge.cpp
@@ -15,9 +15,10 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "Gauge.h"
|
||||
#include "Timer.h"
|
||||
#include "parser.h"
|
||||
#include "Model3d.h"
|
||||
#include "Timer.h"
|
||||
#include "logs.h"
|
||||
|
||||
TGauge::TGauge()
|
||||
{
|
||||
@@ -86,10 +87,18 @@ bool TGauge::Load(cParser &Parser, TModel3d *md1, TModel3d *md2, double mul)
|
||||
>> val5;
|
||||
val3 *= mul;
|
||||
TSubModel *sm = md1->GetFromName( str1.c_str() );
|
||||
if( val3 == 0.0 ) {
|
||||
ErrorLog( "Scale of 0.0 defined for sub-model \"" + str1 + "\" in 3d model \"" + md1->NameGet() + "\". Forcing scale of 1.0 to prevent division by 0" );
|
||||
val3 = 1.0;
|
||||
}
|
||||
if (sm) // jeśli nie znaleziony
|
||||
md2 = NULL; // informacja, że znaleziony
|
||||
else if (md2) // a jest podany drugi model (np. zewnętrzny)
|
||||
sm = md2->GetFromName(str1.c_str()); // to może tam będzie, co za różnica gdzie
|
||||
if( sm == nullptr ) {
|
||||
ErrorLog( "Failed to locate sub-model \"" + str1 + "\" in 3d model \"" + md1->NameGet() + "\"" );
|
||||
}
|
||||
|
||||
if (str2 == "mov")
|
||||
Init(sm, gt_Move, val3, val4, val5);
|
||||
else if (str2 == "wip")
|
||||
@@ -136,19 +145,22 @@ void TGauge::PutValue(double fNewDesired)
|
||||
fValue = fDesiredValue;
|
||||
};
|
||||
|
||||
double TGauge::GetValue() const {
|
||||
// we feed value in range 0-1 so we should be getting it reported in the same range
|
||||
return ( fValue - fOffset ) / fScale;
|
||||
}
|
||||
|
||||
void TGauge::Update()
|
||||
{
|
||||
float dt = Timer::GetDeltaTime();
|
||||
if ((fFriction > 0) && (dt < 0.5 * fFriction)) // McZapkie-281102:
|
||||
// zabezpieczenie przed
|
||||
// oscylacjami dla dlugich
|
||||
// czasow
|
||||
fValue += dt * (fDesiredValue - fValue) / fFriction;
|
||||
if( ( fFriction > 0 ) && ( dt < 0.5 * fFriction ) ) {
|
||||
// McZapkie-281102: zabezpieczenie przed oscylacjami dla dlugich czasow
|
||||
fValue += dt * ( fDesiredValue - fValue ) / fFriction;
|
||||
}
|
||||
else
|
||||
fValue = fDesiredValue;
|
||||
if (SubModel)
|
||||
{ // warunek na wszelki wypadek, gdyby się submodel nie
|
||||
// podłączył
|
||||
{ // warunek na wszelki wypadek, gdyby się submodel nie podłączył
|
||||
TSubModel *sm;
|
||||
switch (eType)
|
||||
{
|
||||
|
||||
15
Gauge.h
15
Gauge.h
@@ -25,11 +25,11 @@ class TGauge // zmienne "gg"
|
||||
{ // animowany wskaźnik, mogący przyjmować wiele stanów pośrednich
|
||||
private:
|
||||
TGaugeType eType; // typ ruchu
|
||||
double fFriction; // hamowanie przy zliżaniu się do zadanej wartości
|
||||
double fDesiredValue; // wartość docelowa
|
||||
double fValue; // wartość obecna
|
||||
double fOffset; // wartość początkowa ("0")
|
||||
double fScale; // wartość końcowa ("1")
|
||||
double fFriction{ 0.0 }; // hamowanie przy zliżaniu się do zadanej wartości
|
||||
double fDesiredValue{ 0.0 }; // wartość docelowa
|
||||
double fValue{ 0.0 }; // wartość obecna
|
||||
double fOffset{ 0.0 }; // wartość początkowa ("0")
|
||||
double fScale{ 1.0 }; // wartość końcowa ("1")
|
||||
double fStepSize; // nie używane
|
||||
char cDataType; // typ zmiennej parametru: f-float, d-double, i-int
|
||||
union
|
||||
@@ -51,10 +51,7 @@ class TGauge // zmienne "gg"
|
||||
void DecValue(double fNewDesired);
|
||||
void UpdateValue(double fNewDesired);
|
||||
void PutValue(double fNewDesired);
|
||||
float GetValue()
|
||||
{
|
||||
return fValue;
|
||||
};
|
||||
double GetValue() const;
|
||||
void Update();
|
||||
void Render();
|
||||
void AssignFloat(float *fValue);
|
||||
|
||||
@@ -104,6 +104,7 @@ int Global::iHiddenEvents = 1; // czy łączyć eventy z torami poprzez nazwę t
|
||||
|
||||
// parametry użytkowe (jak komu pasuje)
|
||||
int Global::Keys[MaxKeys];
|
||||
bool Global::RealisticControlMode{ false };
|
||||
int Global::iWindowWidth = 800;
|
||||
int Global::iWindowHeight = 600;
|
||||
float Global::fDistanceFactor = Global::ScreenHeight / 768.0; // baza do przeliczania odległości dla LoD
|
||||
@@ -162,6 +163,7 @@ bool Global::bOldSmudge = false; // Używanie starej smugi
|
||||
bool Global::bWireFrame = false;
|
||||
bool Global::bSoundEnabled = true;
|
||||
int Global::iWriteLogEnabled = 3; // maska bitowa: 1-zapis do pliku, 2-okienko, 4-nazwy torów
|
||||
bool Global::MultipleLogs{ false };
|
||||
bool Global::bManageNodes = true;
|
||||
bool Global::bDecompressDDS = false; // czy programowa dekompresja DDS
|
||||
|
||||
@@ -372,7 +374,11 @@ void Global::ConfigParse(cParser &Parser)
|
||||
Global::iWriteLogEnabled = stol_def(token,3);
|
||||
}
|
||||
}
|
||||
else if (token == "adjustscreenfreq")
|
||||
else if( token == "multiplelogs" ) {
|
||||
Parser.getTokens();
|
||||
Parser >> Global::MultipleLogs;
|
||||
}
|
||||
else if( token == "adjustscreenfreq" )
|
||||
{
|
||||
// McZapkie-240403 - czestotliwosc odswiezania ekranu
|
||||
Parser.getTokens();
|
||||
|
||||
@@ -166,6 +166,7 @@ class Global
|
||||
public:
|
||||
// double Global::tSinceStart;
|
||||
static int Keys[MaxKeys];
|
||||
static bool RealisticControlMode; // controls ability to steer the vehicle from outside views
|
||||
static Math3D::vector3 pCameraPosition; // pozycja kamery w świecie
|
||||
static double
|
||||
pCameraRotation; // kierunek bezwzględny kamery w świecie: 0=północ, 90°=zachód (-azymut)
|
||||
@@ -207,13 +208,11 @@ class Global
|
||||
static std::string asHumanCtrlVehicle;
|
||||
static void LoadIniFile(std::string asFileName);
|
||||
static void InitKeys();
|
||||
inline static Math3D::vector3 GetCameraPosition()
|
||||
{
|
||||
return pCameraPosition;
|
||||
};
|
||||
inline static Math3D::vector3 GetCameraPosition() { return pCameraPosition; };
|
||||
static void SetCameraPosition(Math3D::vector3 pNewCameraPosition);
|
||||
static void SetCameraRotation(double Yaw);
|
||||
static int iWriteLogEnabled; // maska bitowa: 1-zapis do pliku, 2-okienko
|
||||
static bool MultipleLogs;
|
||||
// McZapkie-221002: definicja swiatla dziennego
|
||||
static float Background[3];
|
||||
static GLfloat AtmoColor[];
|
||||
|
||||
10
Ground.cpp
10
Ground.cpp
@@ -386,7 +386,7 @@ void TGroundNode::RenderAlphaVBO()
|
||||
if( ( PROBLEND ) ) // sprawdza, czy w nazwie nie ma @ //Q: 13122011 - Szociu: 27012012
|
||||
{
|
||||
glDisable( GL_BLEND );
|
||||
glAlphaFunc( GL_GREATER, 0.45f ); // im mniejsza wartość, tym większa ramka, domyślnie 0.1f
|
||||
glAlphaFunc( GL_GREATER, 0.50f ); // im mniejsza wartość, tym większa ramka, domyślnie 0.1f
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -662,7 +662,7 @@ void TGroundNode::RenderAlphaDL()
|
||||
if ((PROBLEND)) // sprawdza, czy w nazwie nie ma @ //Q: 13122011 - Szociu: 27012012
|
||||
{
|
||||
glDisable(GL_BLEND);
|
||||
glAlphaFunc(GL_GREATER, 0.45f); // im mniejsza wartość, tym większa ramka, domyślnie 0.1f
|
||||
glAlphaFunc(GL_GREATER, 0.50f); // im mniejsza wartość, tym większa ramka, domyślnie 0.1f
|
||||
};
|
||||
#endif
|
||||
if (!DisplayListID) //||Global::bReCompile) //Ra: wymuszenie rekompilacji
|
||||
@@ -2802,7 +2802,7 @@ bool TGround::Init(std::string File)
|
||||
|
||||
cParser timeparser( token );
|
||||
timeparser.getTokens( 2, false, ":" );
|
||||
auto &time = Simulation::Time.data();
|
||||
auto &time = simulation::Time.data();
|
||||
timeparser
|
||||
>> time.wHour
|
||||
>> time.wMinute;
|
||||
@@ -4724,7 +4724,7 @@ TGround::Render( Math3D::vector3 const &Camera ) {
|
||||
bool TGround::RenderDL(vector3 pPosition)
|
||||
{ // renderowanie scenerii z Display List - faza nieprzezroczystych
|
||||
glDisable(GL_BLEND);
|
||||
glAlphaFunc(GL_GREATER, 0.45f); // im mniejsza wartość, tym większa ramka, domyślnie 0.1f
|
||||
glAlphaFunc(GL_GREATER, 0.50f); // im mniejsza wartość, tym większa ramka, domyślnie 0.1f
|
||||
++TGroundRect::iFrameNumber; // zwięszenie licznika ramek (do usuwniania nadanimacji)
|
||||
CameraDirection.x = sin(Global::pCameraRotation); // wektor kierunkowy
|
||||
CameraDirection.z = cos(Global::pCameraRotation);
|
||||
@@ -4814,7 +4814,7 @@ bool TGround::RenderAlphaDL(vector3 pPosition)
|
||||
bool TGround::RenderVBO(vector3 pPosition)
|
||||
{ // renderowanie scenerii z VBO - faza nieprzezroczystych
|
||||
glDisable(GL_BLEND);
|
||||
glAlphaFunc(GL_GREATER, 0.45f); // im mniejsza wartość, tym większa ramka, domyślnie 0.1f
|
||||
glAlphaFunc(GL_GREATER, 0.50f); // im mniejsza wartość, tym większa ramka, domyślnie 0.1f
|
||||
++TGroundRect::iFrameNumber; // zwięszenie licznika ramek
|
||||
CameraDirection.x = sin(Global::pCameraRotation); // wektor kierunkowy
|
||||
CameraDirection.z = cos(Global::pCameraRotation);
|
||||
|
||||
47
Logs.cpp
47
Logs.cpp
@@ -18,6 +18,33 @@ std::ofstream comms; // lista komunikatow "comms.txt", można go wyłączyć
|
||||
|
||||
char endstring[10] = "\n";
|
||||
|
||||
std::string filename_date() {
|
||||
|
||||
::SYSTEMTIME st;
|
||||
::GetLocalTime( &st );
|
||||
char buffer[ 256 ];
|
||||
sprintf( buffer,
|
||||
"%d%02d%02d_%02d%02d",
|
||||
st.wYear,
|
||||
st.wMonth,
|
||||
st.wDay,
|
||||
st.wHour,
|
||||
st.wMinute );
|
||||
|
||||
return std::string( buffer );
|
||||
}
|
||||
|
||||
std::string filename_scenery() {
|
||||
|
||||
auto extension = Global::SceneryFile.rfind( '.' );
|
||||
if( extension != std::string::npos ) {
|
||||
return Global::SceneryFile.substr( 0, extension );
|
||||
}
|
||||
else {
|
||||
return Global::SceneryFile;
|
||||
}
|
||||
}
|
||||
|
||||
void WriteConsoleOnly(const char *str, double value)
|
||||
{
|
||||
char buf[255];
|
||||
@@ -57,8 +84,14 @@ void WriteLog(const char *str, bool newline)
|
||||
{
|
||||
if (Global::iWriteLogEnabled & 1)
|
||||
{
|
||||
if (!output.is_open())
|
||||
output.open("log.txt", std::ios::trunc);
|
||||
if( !output.is_open() ) {
|
||||
|
||||
std::string const filename =
|
||||
( Global::MultipleLogs ?
|
||||
"logs/log (" + filename_scenery() + ") " + filename_date() + ".txt" :
|
||||
"log.txt" );
|
||||
output.open( filename, std::ios::trunc );
|
||||
}
|
||||
output << str;
|
||||
if (newline)
|
||||
output << "\n";
|
||||
@@ -72,9 +105,13 @@ void WriteLog(const char *str, bool newline)
|
||||
|
||||
void ErrorLog(const char *str)
|
||||
{ // Ra: bezwarunkowa rejestracja poważnych błędów
|
||||
if (!errors.is_open())
|
||||
{
|
||||
errors.open("errors.txt", std::ios::trunc);
|
||||
if (!errors.is_open()) {
|
||||
|
||||
std::string const filename =
|
||||
( Global::MultipleLogs ?
|
||||
"logs/errors (" + filename_scenery() + ") " + filename_date() + ".txt" :
|
||||
"errors.txt" );
|
||||
errors.open( filename, std::ios::trunc );
|
||||
errors << "EU07.EXE " + Global::asRelease << "\n";
|
||||
}
|
||||
if (str)
|
||||
|
||||
@@ -416,37 +416,30 @@ struct TPowerParameters
|
||||
struct
|
||||
{
|
||||
_mover__3 RHeater;
|
||||
|
||||
};
|
||||
struct
|
||||
{
|
||||
_mover__2 RPowerCable;
|
||||
|
||||
};
|
||||
struct
|
||||
{
|
||||
TCurrentCollector CollectorParameters;
|
||||
|
||||
};
|
||||
struct
|
||||
{
|
||||
_mover__1 RAccumulator;
|
||||
|
||||
};
|
||||
struct
|
||||
{
|
||||
TEngineTypes GeneratorEngine;
|
||||
|
||||
};
|
||||
struct
|
||||
{
|
||||
double InputVoltage;
|
||||
|
||||
};
|
||||
struct
|
||||
{
|
||||
TPowerType PowerType;
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
@@ -666,15 +659,24 @@ public:
|
||||
double CompressorSpeed = 0.0;
|
||||
/*cisnienie wlaczania, zalaczania sprezarki, wydajnosc sprezarki*/
|
||||
TBrakeDelayTable BrakeDelay; /*opoznienie hamowania/odhamowania t/o*/
|
||||
double AirLeakRate{ 0.01 }; // base rate of air leak from brake system components ( 0.001 = 1 l/sec )
|
||||
int BrakeCtrlPosNo = 0; /*ilosc pozycji hamulca*/
|
||||
/*nastawniki:*/
|
||||
int MainCtrlPosNo = 0; /*ilosc pozycji nastawnika*/
|
||||
int ScndCtrlPosNo = 0;
|
||||
int LightsPosNo = 0; // NOTE: values higher than 0 seem to break the current code for light switches
|
||||
int LightsPosNo = 0;
|
||||
int LightsDefPos = 1;
|
||||
bool LightsWrap = false;
|
||||
int Lights[2][17]; // pozycje świateł, przód - tył, 1 .. 16
|
||||
bool ScndInMain = false; /*zaleznosc bocznika od nastawnika*/
|
||||
enum light {
|
||||
|
||||
headlight_left = 0x01,
|
||||
redmarker_left = 0x02,
|
||||
headlight_upper = 0x04,
|
||||
headlight_right = 0x10,
|
||||
redmarker_right = 0x20,
|
||||
};
|
||||
int ScndInMain{ 0 }; /*zaleznosc bocznika od nastawnika*/
|
||||
bool MBrake = false; /*Czy jest hamulec reczny*/
|
||||
double StopBrakeDecc = 0.0;
|
||||
TSecuritySystem SecuritySystem;
|
||||
@@ -754,7 +756,7 @@ public:
|
||||
double DoorStayOpen = 0.0; /*jak dlugo otwarte w przypadku DoorCloseCtrl=2*/
|
||||
bool DoorClosureWarning = false; /*czy jest ostrzeganie przed zamknieciem*/
|
||||
double DoorOpenSpeed = 1.0; double DoorCloseSpeed = 1.0; /*predkosc otwierania i zamykania w j.u. */
|
||||
double DoorMaxShiftL = 0.5; double DoorMaxShiftR = 0.5; double DoorMaxPlugShift = 0.5;/*szerokosc otwarcia lub kat*/
|
||||
double DoorMaxShiftL = 0.5; double DoorMaxShiftR = 0.5; double DoorMaxPlugShift = 0.1;/*szerokosc otwarcia lub kat*/
|
||||
int DoorOpenMethod = 2; /*sposob otwarcia - 1: przesuwne, 2: obrotowe, 3: trójelementowe*/
|
||||
double PlatformSpeed = 0.25; /*szybkosc stopnia*/
|
||||
double PlatformMaxShift = 0.5; /*wysuniecie stopnia*/
|
||||
@@ -879,6 +881,7 @@ public:
|
||||
bool FuseFlag = false; /*!o bezpiecznik nadmiarowy*/
|
||||
bool ConvOvldFlag = false; /*! nadmiarowy przetwornicy i ogrzewania*/
|
||||
bool StLinFlag = false; /*!o styczniki liniowe*/
|
||||
bool StLinSwitchOff{ false }; // state of the button forcing motor connectors open
|
||||
bool ResistorsFlag = false; /*!o jazda rezystorowa*/
|
||||
double RventRot = 0.0; /*!s obroty wentylatorow rozruchowych*/
|
||||
bool UnBrake = false; /*w EZT - nacisniete odhamowywanie*/
|
||||
@@ -1150,6 +1153,23 @@ private:
|
||||
|
||||
extern double Distance(TLocation Loc1, TLocation Loc2, TDimension Dim1, TDimension Dim2);
|
||||
|
||||
inline
|
||||
std::string
|
||||
extract_value( std::string const &Key, std::string const &Input ) {
|
||||
|
||||
std::string value;
|
||||
auto lookup = Input.find( Key + "=" );
|
||||
if( lookup != std::string::npos ) {
|
||||
value = Input.substr( Input.find_first_not_of( ' ', lookup + Key.size() + 1 ) );
|
||||
lookup = value.find( ' ' );
|
||||
if( lookup != std::string::npos ) {
|
||||
// trim everything past the value
|
||||
value.erase( lookup );
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
template <typename _Type>
|
||||
bool
|
||||
extract_value( _Type &Variable, std::string const &Key, std::string const &Input, std::string const &Default ) {
|
||||
@@ -1169,23 +1189,10 @@ extract_value( _Type &Variable, std::string const &Key, std::string const &Input
|
||||
converter << Default;
|
||||
converter >> Variable;
|
||||
}
|
||||
return false; // supplied the default
|
||||
return false; // couldn't locate the variable in provided input
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
std::string
|
||||
extract_value( std::string const &Key, std::string const &Input ) {
|
||||
|
||||
std::string value;
|
||||
auto lookup = Input.find( Key + "=" );
|
||||
if( lookup != std::string::npos ) {
|
||||
value = Input.substr( Input.find_first_not_of( ' ', lookup + Key.size() + 1 ) );
|
||||
lookup = value.find( ' ' );
|
||||
if( lookup != std::string::npos ) {
|
||||
// trim everything past the value
|
||||
value.erase( lookup );
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
template <>
|
||||
bool
|
||||
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default );
|
||||
|
||||
@@ -129,11 +129,15 @@ double TMoverParameters::current(double n, double U)
|
||||
|
||||
R = RList[MainCtrlActualPos].R * Bn + CircuitRes;
|
||||
|
||||
if ((TrainType != dt_EZT) || (Imin != IminLo) ||
|
||||
(!ScndS)) // yBARC - boczniki na szeregu poprawnie
|
||||
Mn = RList[MainCtrlActualPos].Mn; // to jest wykonywane dla EU07
|
||||
else
|
||||
Mn = RList[MainCtrlActualPos].Mn * RList[MainCtrlActualPos].Bn;
|
||||
if( ( TrainType != dt_EZT )
|
||||
|| ( Imin != IminLo )
|
||||
|| ( false == ScndS ) ) {
|
||||
// yBARC - boczniki na szeregu poprawnie
|
||||
Mn = RList[ MainCtrlActualPos ].Mn; // to jest wykonywane dla EU07
|
||||
}
|
||||
else {
|
||||
Mn = RList[ MainCtrlActualPos ].Mn * RList[ MainCtrlActualPos ].Bn;
|
||||
}
|
||||
|
||||
// writepaslog("#",
|
||||
// "C++-----------------------------------------------------------------------------");
|
||||
@@ -154,21 +158,25 @@ double TMoverParameters::current(double n, double U)
|
||||
if (DynamicBrakeFlag && (!FuseFlag) && (DynamicBrakeType == dbrake_automatic) &&
|
||||
ConverterFlag && Mains) // hamowanie EP09 //TUHEX
|
||||
{
|
||||
// TODO: zrobic bardziej uniwersalne nie tylko dla EP09
|
||||
MotorCurrent =
|
||||
-Max0R(MotorParam[0].fi * (Vadd / (Vadd + MotorParam[0].Isat) - MotorParam[0].fi0), 0) *
|
||||
n * 2.0 / ep09resED; // TODO: zrobic bardziej uniwersalne nie tylko dla EP09
|
||||
-Max0R(MotorParam[0].fi * (Vadd / (Vadd + MotorParam[0].Isat) - MotorParam[0].fi0), 0) * n * 2.0 / ep09resED;
|
||||
}
|
||||
else if( ( RList[ MainCtrlActualPos ].Bn == 0 )
|
||||
|| ( false == StLinFlag ) ) {
|
||||
// wylaczone
|
||||
MotorCurrent = 0;
|
||||
}
|
||||
else if ((RList[MainCtrlActualPos].Bn == 0) || (!StLinFlag))
|
||||
MotorCurrent = 0; // wylaczone
|
||||
else
|
||||
{ // wlaczone...
|
||||
SP = ScndCtrlActualPos;
|
||||
|
||||
if (ScndCtrlActualPos < 255) // tak smiesznie bede wylaczal
|
||||
{
|
||||
if (ScndInMain)
|
||||
if (!(RList[MainCtrlActualPos].ScndAct == 255))
|
||||
SP = RList[MainCtrlActualPos].ScndAct;
|
||||
if( ( ScndInMain )
|
||||
&& ( RList[ MainCtrlActualPos ].ScndAct != 255 ) ) {
|
||||
SP = RList[ MainCtrlActualPos ].ScndAct;
|
||||
}
|
||||
|
||||
Rz = Mn * WindingRes + R;
|
||||
|
||||
@@ -212,10 +220,10 @@ double TMoverParameters::current(double n, double U)
|
||||
{
|
||||
if (U > 0)
|
||||
MotorCurrent =
|
||||
(U1 - Isf * Rz - Mn * MotorParam[SP].fi * n + sqrt(Delta)) / (2.0 * Rz);
|
||||
(U1 - Isf * Rz - Mn * MotorParam[SP].fi * n + std::sqrt(Delta)) / (2.0 * Rz);
|
||||
else
|
||||
MotorCurrent =
|
||||
(U1 - Isf * Rz - Mn * MotorParam[SP].fi * n - sqrt(Delta)) / (2.0 * Rz);
|
||||
(U1 - Isf * Rz - Mn * MotorParam[SP].fi * n - std::sqrt(Delta)) / (2.0 * Rz);
|
||||
}
|
||||
else
|
||||
MotorCurrent = 0;
|
||||
@@ -676,10 +684,23 @@ bool TMoverParameters::CurrentSwitch(int direction)
|
||||
if (TrainType != dt_EZT)
|
||||
return (MinCurrentSwitch(direction != 0));
|
||||
}
|
||||
if (EngineType == DieselEngine) // dla 2Ls150
|
||||
if (ShuntModeAllow)
|
||||
if (ActiveDir == 0) // przed ustawieniem kierunku
|
||||
// TBD, TODO: split off shunt mode toggle into a separate command? It doesn't make much sense to have these two together like that
|
||||
// dla 2Ls150
|
||||
if( ( EngineType == DieselEngine )
|
||||
&& ( true == ShuntModeAllow )
|
||||
&& ( ActiveDir == 0 ) ) {
|
||||
// przed ustawieniem kierunku
|
||||
ShuntMode = ( direction != 0 );
|
||||
return true;
|
||||
}
|
||||
// for SM42/SP42
|
||||
if( ( EngineType == DieselElectric )
|
||||
&& ( true == ShuntModeAllow )
|
||||
&& ( MainCtrlPos == 0 ) ) {
|
||||
ShuntMode = ( direction != 0 );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -1814,8 +1835,9 @@ bool TMoverParameters::IncScndCtrl(int CtrlSpeed)
|
||||
LastRelayTime = 0;
|
||||
|
||||
if ((OK) && (EngineType == ElectricInductionMotor))
|
||||
// NOTE: round() already adds 0.5, are the ones added here as well correct?
|
||||
if ((Vmax < 250))
|
||||
ScndCtrlActualPos = Round(Vel + 0.5f);
|
||||
ScndCtrlActualPos = Round(Vel + 0.5);
|
||||
else
|
||||
ScndCtrlActualPos = Round(Vel * 1.0 / 2 + 0.5);
|
||||
|
||||
@@ -2031,10 +2053,12 @@ void TMoverParameters::SecuritySystemCheck(double dt)
|
||||
(Battery)) // Ra: EZT ma teraz czuwak w rozrządczym
|
||||
{
|
||||
// CA
|
||||
if (Vel >=
|
||||
SecuritySystem
|
||||
.AwareMinSpeed) // domyślnie predkość większa od 10% Vmax, albo podanej jawnie w FIZ
|
||||
{
|
||||
if( ( SecuritySystem.AwareMinSpeed > 0.0 ?
|
||||
( Vel >= SecuritySystem.AwareMinSpeed ) :
|
||||
( ActiveDir != 0 ) ) ) {
|
||||
// domyślnie predkość większa od 10% Vmax, albo podanej jawnie w FIZ
|
||||
// with defined minspeed of 0 the alerter will activate with reverser out of neutral position
|
||||
// this emulates behaviour of engines like SM42
|
||||
SecuritySystem.SystemTimer += dt;
|
||||
if (TestFlag(SecuritySystem.SystemType, 1) &&
|
||||
TestFlag(SecuritySystem.Status, s_aware)) // jeśli świeci albo miga
|
||||
@@ -2819,6 +2843,8 @@ void TMoverParameters::UpdateBrakePressure(double dt)
|
||||
// *************************************************************************************************
|
||||
void TMoverParameters::CompressorCheck(double dt)
|
||||
{
|
||||
CompressedVolume = std::max( 0.0, CompressedVolume - dt * AirLeakRate * 0.1 ); // nieszczelności: 0.001=1l/s
|
||||
|
||||
// if (CompressorSpeed>0.0) then //ten warunek został sprawdzony przy wywołaniu funkcji
|
||||
if (VeselVolume > 0)
|
||||
{
|
||||
@@ -2941,6 +2967,11 @@ void TMoverParameters::CompressorCheck(double dt)
|
||||
// *************************************************************************************************
|
||||
void TMoverParameters::UpdatePipePressure(double dt)
|
||||
{
|
||||
if( PipePress > 1.0 ) {
|
||||
Pipe->Flow( -(PipePress)* AirLeakRate * dt );
|
||||
Pipe->Act();
|
||||
}
|
||||
|
||||
const double LBDelay = 100;
|
||||
const double kL = 0.5;
|
||||
//double dV;
|
||||
@@ -3115,7 +3146,7 @@ void TMoverParameters::UpdatePipePressure(double dt)
|
||||
// temp = (Handle as TFVel6).GetCP
|
||||
temp = Handle->GetCP();
|
||||
else
|
||||
temp = 0;
|
||||
temp = 0.0;
|
||||
Hamulec->SetEPS(temp);
|
||||
SendCtrlToNext("Brake", temp,
|
||||
CabNo); // Ra 2014-11: na tym się wysypuje, ale nie wiem, w jakich warunkach
|
||||
@@ -3124,9 +3155,9 @@ void TMoverParameters::UpdatePipePressure(double dt)
|
||||
Pipe->Act();
|
||||
PipePress = Pipe->P();
|
||||
if ((BrakeStatus & 128) == 128) // jesli hamulec wyłączony
|
||||
temp = 0; // odetnij
|
||||
temp = 0.0; // odetnij
|
||||
else
|
||||
temp = 1; // połącz
|
||||
temp = 1.0; // połącz
|
||||
Pipe->Flow(temp * Hamulec->GetPF(temp * PipePress, dt, Vel) + GetDVc(dt));
|
||||
|
||||
if (ASBType == 128)
|
||||
@@ -3138,17 +3169,17 @@ void TMoverParameters::UpdatePipePressure(double dt)
|
||||
Pipe->Act();
|
||||
PipePress = Pipe->P();
|
||||
|
||||
dpMainValve = dpMainValve / (100 * dt); // normalizacja po czasie do syczenia;
|
||||
dpMainValve = dpMainValve / (100.0 * dt); // normalizacja po czasie do syczenia;
|
||||
|
||||
if (PipePress < -1)
|
||||
if (PipePress < -1.0)
|
||||
{
|
||||
PipePress = -1;
|
||||
Pipe->CreatePress(-1);
|
||||
PipePress = -1.0;
|
||||
Pipe->CreatePress(-1.0);
|
||||
Pipe->Act();
|
||||
}
|
||||
|
||||
if (CompressedVolume < 0)
|
||||
CompressedVolume = 0;
|
||||
if (CompressedVolume < 0.0)
|
||||
CompressedVolume = 0.0;
|
||||
}
|
||||
|
||||
// *************************************************************************************************
|
||||
@@ -3157,6 +3188,11 @@ void TMoverParameters::UpdatePipePressure(double dt)
|
||||
// *************************************************************************************************
|
||||
void TMoverParameters::UpdateScndPipePressure(double dt)
|
||||
{
|
||||
if( ScndPipePress > 1.0 ) {
|
||||
Pipe2->Flow( -(ScndPipePress)* AirLeakRate * dt );
|
||||
Pipe2->Act();
|
||||
}
|
||||
|
||||
const double Spz = 0.5067;
|
||||
TMoverParameters *c;
|
||||
double dv1, dv2, dV;
|
||||
@@ -4087,106 +4123,152 @@ double TMoverParameters::TractionForce(double dt)
|
||||
if ((MainCtrlPos == 0) || (ShuntMode))
|
||||
ScndCtrlPos = 0;
|
||||
|
||||
else if (AutoRelayFlag)
|
||||
switch (RelayType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if ((Im <= (MPTRelay[ScndCtrlPos].Iup * PosRatio)) &&
|
||||
(ScndCtrlPos < ScndCtrlPosNo))
|
||||
else {
|
||||
if( AutoRelayFlag ) {
|
||||
|
||||
switch( RelayType ) {
|
||||
|
||||
case 0: {
|
||||
|
||||
if( ( Im <= ( MPTRelay[ ScndCtrlPos ].Iup * PosRatio ) ) &&
|
||||
( ScndCtrlPos < ScndCtrlPosNo ) )
|
||||
++ScndCtrlPos;
|
||||
if ((Im >= (MPTRelay[ScndCtrlPos].Idown * PosRatio)) && (ScndCtrlPos > 0))
|
||||
if( ( Im >= ( MPTRelay[ ScndCtrlPos ].Idown * PosRatio ) ) && ( ScndCtrlPos > 0 ) )
|
||||
--ScndCtrlPos;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
if ((MPTRelay[ScndCtrlPos].Iup < Vel) && (ScndCtrlPos < ScndCtrlPosNo))
|
||||
case 1: {
|
||||
|
||||
if( ( MPTRelay[ ScndCtrlPos ].Iup < Vel ) && ( ScndCtrlPos < ScndCtrlPosNo ) )
|
||||
++ScndCtrlPos;
|
||||
if ((MPTRelay[ScndCtrlPos].Idown > Vel) && (ScndCtrlPos > 0))
|
||||
if( ( MPTRelay[ ScndCtrlPos ].Idown > Vel ) && ( ScndCtrlPos > 0 ) )
|
||||
--ScndCtrlPos;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if ((MPTRelay[ScndCtrlPos].Iup < Vel) && (ScndCtrlPos < ScndCtrlPosNo) &&
|
||||
(EnginePower < (tmp * 0.99)))
|
||||
case 2: {
|
||||
|
||||
if( ( MPTRelay[ ScndCtrlPos ].Iup < Vel ) && ( ScndCtrlPos < ScndCtrlPosNo ) &&
|
||||
( EnginePower < ( tmp * 0.99 ) ) )
|
||||
++ScndCtrlPos;
|
||||
if ((MPTRelay[ScndCtrlPos].Idown < Im) && (ScndCtrlPos > 0))
|
||||
if( ( MPTRelay[ ScndCtrlPos ].Idown < Im ) && ( ScndCtrlPos > 0 ) )
|
||||
--ScndCtrlPos;
|
||||
break;
|
||||
}
|
||||
case 41:
|
||||
{
|
||||
if ((MainCtrlPos == MainCtrlPosNo) &&
|
||||
(tmpV * 3.6 > MPTRelay[ScndCtrlPos].Iup) && (ScndCtrlPos < ScndCtrlPosNo))
|
||||
{
|
||||
if( ( MainCtrlPos == MainCtrlPosNo )
|
||||
&& ( tmpV * 3.6 > MPTRelay[ ScndCtrlPos ].Iup )
|
||||
&& ( ScndCtrlPos < ScndCtrlPosNo ) ) {
|
||||
++ScndCtrlPos;
|
||||
enrot = enrot * 0.73;
|
||||
}
|
||||
if ((Im > MPTRelay[ScndCtrlPos].Idown) && (ScndCtrlPos > 0))
|
||||
if( ( Im > MPTRelay[ ScndCtrlPos ].Idown )
|
||||
&& ( ScndCtrlPos > 0 ) ) {
|
||||
--ScndCtrlPos;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 45:
|
||||
{
|
||||
if ((MainCtrlPos > 11) && (ScndCtrlPos < ScndCtrlPosNo))
|
||||
if ((ScndCtrlPos == 0))
|
||||
if ((MPTRelay[ScndCtrlPos].Iup > Im))
|
||||
if( ( MainCtrlPos >= 10 ) && ( ScndCtrlPos < ScndCtrlPosNo ) ) {
|
||||
if( ScndCtrlPos == 0 ) {
|
||||
if( Im < MPTRelay[ ScndCtrlPos ].Iup ) {
|
||||
++ScndCtrlPos;
|
||||
else if ((MPTRelay[ScndCtrlPos].Iup < Vel))
|
||||
}
|
||||
}
|
||||
else {
|
||||
if( Vel > MPTRelay[ ScndCtrlPos ].Iup ) {
|
||||
++ScndCtrlPos;
|
||||
|
||||
}
|
||||
// check for cases where the speed drops below threshold for level 2 or 3
|
||||
if( ( ScndCtrlPos > 1 )
|
||||
&& ( Vel < MPTRelay[ ScndCtrlPos - 1 ].Idown ) ){
|
||||
--ScndCtrlPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
// malenie
|
||||
if ((ScndCtrlPos > 0) && (MainCtrlPos < 12))
|
||||
if ((ScndCtrlPos == ScndCtrlPosNo))
|
||||
if ((MPTRelay[ScndCtrlPos].Idown < Im))
|
||||
if( ( ScndCtrlPos > 0 ) && ( MainCtrlPos < 10 ) ) {
|
||||
if( ScndCtrlPos == 1 ) {
|
||||
if( Im > MPTRelay[ ScndCtrlPos - 1 ].Idown ) {
|
||||
--ScndCtrlPos;
|
||||
else if ((MPTRelay[ScndCtrlPos].Idown > Vel))
|
||||
}
|
||||
}
|
||||
else {
|
||||
if( Vel < MPTRelay[ ScndCtrlPos ].Idown ) {
|
||||
--ScndCtrlPos;
|
||||
if ((MainCtrlPos < 11) && (ScndCtrlPos > 2))
|
||||
ScndCtrlPos = 2;
|
||||
if ((MainCtrlPos < 9) && (ScndCtrlPos > 0))
|
||||
}
|
||||
}
|
||||
}
|
||||
// 3rd level drops with master controller at position lower than 10...
|
||||
if( MainCtrlPos < 10 ) {
|
||||
ScndCtrlPos = std::min( 2, ScndCtrlPos );
|
||||
}
|
||||
// ...and below position 7 field shunt drops altogether
|
||||
if( MainCtrlPos < 7 ) {
|
||||
ScndCtrlPos = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 46:
|
||||
{
|
||||
// wzrastanie
|
||||
if ((MainCtrlPos > 9) && (ScndCtrlPos < ScndCtrlPosNo))
|
||||
if ((ScndCtrlPos) % 2 == 0)
|
||||
if ((MPTRelay[ScndCtrlPos].Iup > Im))
|
||||
if( ( MainCtrlPos >= 10 )
|
||||
&& ( ScndCtrlPos < ScndCtrlPosNo ) ) {
|
||||
if( ( ScndCtrlPos ) % 2 == 0 ) {
|
||||
if( ( MPTRelay[ ScndCtrlPos ].Iup > Im ) ) {
|
||||
++ScndCtrlPos;
|
||||
else if ((MPTRelay[ScndCtrlPos - 1].Iup > Im) &&
|
||||
(MPTRelay[ScndCtrlPos].Iup < Vel))
|
||||
}
|
||||
}
|
||||
else {
|
||||
if( ( MPTRelay[ ScndCtrlPos - 1 ].Iup > Im )
|
||||
&& ( MPTRelay[ ScndCtrlPos ].Iup < Vel ) ) {
|
||||
++ScndCtrlPos;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// malenie
|
||||
if ((MainCtrlPos < 10) && (ScndCtrlPos > 0))
|
||||
if ((ScndCtrlPos) % 2 == 0)
|
||||
if ((MPTRelay[ScndCtrlPos].Idown < Im))
|
||||
if( ( MainCtrlPos < 10 )
|
||||
&& ( ScndCtrlPos > 0 ) ) {
|
||||
if( ( ScndCtrlPos ) % 2 == 0 ) {
|
||||
if( ( MPTRelay[ ScndCtrlPos ].Idown < Im ) ) {
|
||||
--ScndCtrlPos;
|
||||
else if ((MPTRelay[ScndCtrlPos + 1].Idown < Im) &&
|
||||
(MPTRelay[ScndCtrlPos].Idown > Vel))
|
||||
}
|
||||
}
|
||||
else {
|
||||
if( ( MPTRelay[ ScndCtrlPos + 1 ].Idown < Im )
|
||||
&& ( MPTRelay[ ScndCtrlPos ].Idown > Vel ) ) {
|
||||
--ScndCtrlPos;
|
||||
if ((MainCtrlPos < 9) && (ScndCtrlPos > 2))
|
||||
ScndCtrlPos = 2;
|
||||
if ((MainCtrlPos < 6) && (ScndCtrlPos > 0))
|
||||
}
|
||||
}
|
||||
}
|
||||
if( MainCtrlPos < 10 ) {
|
||||
ScndCtrlPos = std::min( 2, ScndCtrlPos );
|
||||
}
|
||||
if( MainCtrlPos < 7 ) {
|
||||
ScndCtrlPos = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
} // switch RelayType
|
||||
}
|
||||
}
|
||||
break;
|
||||
} // DieselElectric
|
||||
|
||||
case ElectricInductionMotor:
|
||||
{
|
||||
if ((Mains)) // nie wchodzić w funkcję bez potrzeby
|
||||
if ((abs(Voltage) < EnginePowerSource.CollectorParameters.MinV) ||
|
||||
(abs(Voltage) > EnginePowerSource.CollectorParameters.MaxV + 200))
|
||||
{
|
||||
MainSwitch(false);
|
||||
if( ( Mains ) ) {
|
||||
// nie wchodzić w funkcję bez potrzeby
|
||||
if( ( abs( Voltage ) < EnginePowerSource.CollectorParameters.MinV )
|
||||
|| ( abs( Voltage ) > EnginePowerSource.CollectorParameters.MaxV + 200 ) ) {
|
||||
MainSwitch( false );
|
||||
}
|
||||
tmpV = abs(nrot) * (PI * WheelDiameter) *
|
||||
3.6; //*DirAbsolute*eimc[eimc_s_p]; - do przemyslenia dzialanie pp
|
||||
}
|
||||
tmpV = abs(nrot) * (PI * WheelDiameter) * 3.6; //*DirAbsolute*eimc[eimc_s_p]; - do przemyslenia dzialanie pp
|
||||
if ((Mains))
|
||||
{
|
||||
|
||||
@@ -4833,7 +4915,8 @@ bool TMoverParameters::AutoRelayCheck(void)
|
||||
(MainCtrlActualPos == 0) && (ActiveDir != 0))
|
||||
{ //^^ TODO: sprawdzic BUG, prawdopodobnie w CreateBrakeSys()
|
||||
DelayCtrlFlag = true;
|
||||
if (LastRelayTime >= InitialCtrlDelay)
|
||||
if( (LastRelayTime >= InitialCtrlDelay)
|
||||
&& ( false == StLinSwitchOff ) )
|
||||
{
|
||||
StLinFlag = true; // ybARC - zalaczenie stycznikow liniowych
|
||||
MainCtrlActualPos = 1;
|
||||
@@ -4894,48 +4977,37 @@ bool TMoverParameters::AutoRelayCheck(void)
|
||||
|
||||
// *************************************************************************************************
|
||||
// Q: 20160713
|
||||
// Podnosi / opuszcza przedni pantograf
|
||||
// Podnosi / opuszcza przedni pantograf. Returns: state of the pantograph after the operation
|
||||
// *************************************************************************************************
|
||||
bool TMoverParameters::PantFront(bool State)
|
||||
{
|
||||
double pf1 = 0;
|
||||
bool PF = false;
|
||||
if( ( true == Battery )
|
||||
|| ( true == ConverterFlag ) ) {
|
||||
|
||||
if ((Battery ==
|
||||
true) /* and ((TrainType<>dt_ET40)or ((TrainType=dt_ET40) and (EnginePowerSource.CollectorsNo>1)))*/)
|
||||
{
|
||||
PF = true;
|
||||
if (State == true)
|
||||
pf1 = 1;
|
||||
else
|
||||
pf1 = 0;
|
||||
if (PantFrontUp != State)
|
||||
{
|
||||
if( PantFrontUp != State ) {
|
||||
PantFrontUp = State;
|
||||
if (State == true)
|
||||
{
|
||||
if( State == true ) {
|
||||
PantFrontStart = 0;
|
||||
SendCtrlToNext("PantFront", 1, CabNo);
|
||||
SendCtrlToNext( "PantFront", 1, CabNo );
|
||||
}
|
||||
else
|
||||
{
|
||||
PF = false;
|
||||
else {
|
||||
PantFrontStart = 1;
|
||||
SendCtrlToNext("PantFront", 0, CabNo);
|
||||
//{Ra: nie ma potrzeby opuszczać obydwu na raz, jak mozemy każdy osobno
|
||||
// if (TrainType == dt_EZT) && (ActiveCab == 1)
|
||||
// {
|
||||
// PantRearUp = false;
|
||||
// PantRearStart = 1;
|
||||
// SendCtrlToNext("PantRear", 0, CabNo);
|
||||
// }
|
||||
//}
|
||||
SendCtrlToNext( "PantFront", 0, CabNo );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
SendCtrlToNext("PantFront", pf1, CabNo);
|
||||
else {
|
||||
// no power, drop the pantograph
|
||||
// NOTE: this is a simplification as it should just drop on its own with loss of pressure without resupply from (dead) compressor
|
||||
PantFrontStart = (
|
||||
PantFrontUp ?
|
||||
1 :
|
||||
0 );
|
||||
PantFrontUp = false;
|
||||
SendCtrlToNext( "PantFront", 0, CabNo );
|
||||
}
|
||||
return PF;
|
||||
|
||||
return PantFrontUp;
|
||||
}
|
||||
|
||||
// *************************************************************************************************
|
||||
@@ -4944,35 +5016,33 @@ bool TMoverParameters::PantFront(bool State)
|
||||
// *************************************************************************************************
|
||||
bool TMoverParameters::PantRear(bool State)
|
||||
{
|
||||
double pf1;
|
||||
bool PR = false;
|
||||
if( ( true == Battery )
|
||||
|| ( true == ConverterFlag ) ) {
|
||||
|
||||
if (Battery == true)
|
||||
{
|
||||
PR = true;
|
||||
if (State == true)
|
||||
pf1 = 1;
|
||||
else
|
||||
pf1 = 0;
|
||||
if (PantRearUp != State)
|
||||
{
|
||||
if( PantRearUp != State ) {
|
||||
PantRearUp = State;
|
||||
if (State == true)
|
||||
{
|
||||
if( State == true ) {
|
||||
PantRearStart = 0;
|
||||
SendCtrlToNext("PantRear", 1, CabNo);
|
||||
SendCtrlToNext( "PantRear", 1, CabNo );
|
||||
}
|
||||
else
|
||||
{
|
||||
PR = false;
|
||||
else {
|
||||
PantRearStart = 1;
|
||||
SendCtrlToNext("PantRear", 0, CabNo);
|
||||
SendCtrlToNext( "PantRear", 0, CabNo );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
SendCtrlToNext("PantRear", pf1, CabNo);
|
||||
else {
|
||||
// no power, drop the pantograph
|
||||
// NOTE: this is a simplification as it should just drop on its own with loss of pressure without resupply from (dead) compressor
|
||||
PantRearStart = (
|
||||
PantRearUp ?
|
||||
1 :
|
||||
0 );
|
||||
PantRearUp = false;
|
||||
SendCtrlToNext( "PantRear", 0, CabNo );
|
||||
}
|
||||
return PR;
|
||||
|
||||
return PantRearUp;
|
||||
}
|
||||
|
||||
// *************************************************************************************************
|
||||
@@ -5926,10 +5996,15 @@ bool TMoverParameters::LoadFIZ(std::string chkpath)
|
||||
continue;
|
||||
}
|
||||
|
||||
if( inputline[ 0 ] == ' ' ) {
|
||||
// guard against malformed config files with leading spaces
|
||||
inputline.erase( 0, inputline.find_first_not_of( ' ' ) );
|
||||
}
|
||||
if( inputline.length() == 0 ) {
|
||||
startBPT = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// checking if table parsing should be switched off goes first...
|
||||
if( issection( "END-MPT", inputline ) ) {
|
||||
startBPT = false;
|
||||
@@ -6422,6 +6497,11 @@ void TMoverParameters::LoadFIZ_Brake( std::string const &line ) {
|
||||
lookup->second :
|
||||
1;
|
||||
}
|
||||
|
||||
if( true == extract_value( AirLeakRate, "AirLeakRate", line, "" ) ) {
|
||||
// the parameter is provided in form of a multiplier, where 1.0 means the default rate of 0.001
|
||||
AirLeakRate *= 0.01;
|
||||
}
|
||||
}
|
||||
|
||||
void TMoverParameters::LoadFIZ_Doors( std::string const &line ) {
|
||||
@@ -6633,8 +6713,10 @@ void TMoverParameters::LoadFIZ_Cntrl( std::string const &line ) {
|
||||
}
|
||||
|
||||
// mbpm
|
||||
extract_value( MBPM, "MaxBPMass", line, "" );
|
||||
// MBPM *= 1000;
|
||||
if( true == extract_value( MBPM, "MaxBPMass", line, "" ) ) {
|
||||
// NOTE: only convert the value from tons to kilograms if the entry is present in the config file
|
||||
MBPM *= 1000.0;
|
||||
}
|
||||
|
||||
// asbtype
|
||||
std::string asb;
|
||||
@@ -6891,6 +6973,9 @@ void TMoverParameters::LoadFIZ_Switches( std::string const &Input ) {
|
||||
|
||||
extract_value( PantSwitchType, "Pantograph", Input, "" );
|
||||
extract_value( ConvSwitchType, "Converter", Input, "" );
|
||||
// because people can't make up their minds whether it's "impulse" or "Impulse"...
|
||||
PantSwitchType = ToLower( PantSwitchType );
|
||||
ConvSwitchType = ToLower( ConvSwitchType );
|
||||
}
|
||||
|
||||
void TMoverParameters::LoadFIZ_MotorParamTable( std::string const &Input ) {
|
||||
@@ -7912,3 +7997,22 @@ double TMoverParameters::ShowCurrentP(int AmpN)
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
bool
|
||||
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default ) {
|
||||
|
||||
auto value = extract_value( Key, Input );
|
||||
if( false == value.empty() ) {
|
||||
// set the specified variable to retrieved value
|
||||
Variable = ( ToLower( value ) == "yes" );
|
||||
return true; // located the variable
|
||||
}
|
||||
else {
|
||||
// set the variable to provided default value
|
||||
if( false == Default.empty() ) {
|
||||
Variable = ( ToLower( Default ) == "yes" );
|
||||
}
|
||||
return false; // couldn't locate the variable in provided input
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ static int const bdelay_G = 1; //G
|
||||
static int const bdelay_P = 2; //P
|
||||
static int const bdelay_R = 4; //R
|
||||
static int const bdelay_M = 8; //Mg
|
||||
static int const bdelay_GR = 128; //G-R
|
||||
|
||||
|
||||
/*stan hamulca*/
|
||||
|
||||
@@ -72,23 +72,11 @@ double Min0R(double x1, double x2)
|
||||
// TODO: replace with something sensible
|
||||
std::string Now() {
|
||||
|
||||
std::time_t timenow = std::time( nullptr );
|
||||
std::tm tm = *std::localtime( &timenow );
|
||||
std::stringstream converter;
|
||||
converter << std::put_time( &tm, "%c" );
|
||||
std::time_t timenow = std::time( nullptr );
|
||||
std::tm tm = *std::localtime( &timenow );
|
||||
std::stringstream converter;
|
||||
converter << std::put_time( &tm, "%c" );
|
||||
return converter.str();
|
||||
|
||||
/* char buffer[ 256 ];
|
||||
sprintf( buffer,
|
||||
"%d-%02d-%02d %02d:%02d:%02d.%03d",
|
||||
st.wYear,
|
||||
st.wMonth,
|
||||
st.wDay,
|
||||
st.wHour,
|
||||
st.wMinute,
|
||||
st.wSecond,
|
||||
st.wMilliseconds );
|
||||
*/
|
||||
}
|
||||
|
||||
bool TestFlag(int Flag, int Value)
|
||||
|
||||
@@ -62,7 +62,7 @@ inline double Sign(double x)
|
||||
return x >= 0 ? 1.0 : -1.0;
|
||||
}
|
||||
|
||||
inline long Round(float f)
|
||||
inline long Round(double const f)
|
||||
{
|
||||
return (long)(f + 0.5);
|
||||
//return lround(f);
|
||||
|
||||
45
Model3d.cpp
45
Model3d.cpp
@@ -325,8 +325,13 @@ int TSubModel::Load(cParser &parser, TModel3d *Model, int Pos, bool dynamic)
|
||||
>> discard >> fFarDecayRadius
|
||||
>> discard >> fCosFalloffAngle // kąt liczony dla średnicy, a nie promienia
|
||||
>> discard >> fCosHotspotAngle; // kąt liczony dla średnicy, a nie promienia
|
||||
fCosFalloffAngle = std::cos( DegToRad( 0.5f * fCosFalloffAngle ) );
|
||||
fCosHotspotAngle = std::cos( DegToRad( 0.5f * fCosHotspotAngle ) );
|
||||
// convert conve parameters if specified in degrees
|
||||
if( fCosFalloffAngle > 1.0 ) {
|
||||
fCosFalloffAngle = std::cos( DegToRad( 0.5f * fCosFalloffAngle ) );
|
||||
}
|
||||
if( fCosHotspotAngle > 1.0 ) {
|
||||
fCosHotspotAngle = std::cos( DegToRad( 0.5f * fCosHotspotAngle ) );
|
||||
}
|
||||
iNumVerts = 1;
|
||||
/*
|
||||
iFlags |= 0x4010; // rysowane w cyklu nieprzezroczystych, macierz musi zostać bez zmiany
|
||||
@@ -899,22 +904,22 @@ void TSubModel::RaAnimation(glm::mat4 &m, TAnimType a)
|
||||
m = glm::rotate(m, glm::radians(v_Angles.z), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
break;
|
||||
case at_SecondsJump: // sekundy z przeskokiem
|
||||
m = glm::rotate(m, glm::radians(Simulation::Time.data().wSecond * 6.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
m = glm::rotate(m, glm::radians(simulation::Time.data().wSecond * 6.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
break;
|
||||
case at_MinutesJump: // minuty z przeskokiem
|
||||
m = glm::rotate(m, glm::radians(Simulation::Time.data().wMinute * 6.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
m = glm::rotate(m, glm::radians(simulation::Time.data().wMinute * 6.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
break;
|
||||
case at_HoursJump: // godziny skokowo 12h/360°
|
||||
m = glm::rotate(m, glm::radians(Simulation::Time.data().wHour * 30.0f * 0.5f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
m = glm::rotate(m, glm::radians(simulation::Time.data().wHour * 30.0f * 0.5f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
break;
|
||||
case at_Hours24Jump: // godziny skokowo 24h/360°
|
||||
m = glm::rotate(m, glm::radians(Simulation::Time.data().wHour * 15.0f * 0.25f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
m = glm::rotate(m, glm::radians(simulation::Time.data().wHour * 15.0f * 0.25f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
break;
|
||||
case at_Seconds: // sekundy płynnie
|
||||
m = glm::rotate(m, glm::radians((float)Simulation::Time.second() * 6.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
m = glm::rotate(m, glm::radians((float)simulation::Time.second() * 6.0f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
break;
|
||||
case at_Minutes: // minuty płynnie
|
||||
m = glm::rotate(m, glm::radians(Simulation::Time.data().wMinute * 6.0f + (float)Simulation::Time.second() * 0.1f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
m = glm::rotate(m, glm::radians(simulation::Time.data().wMinute * 6.0f + (float)simulation::Time.second() * 0.1f), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
break;
|
||||
case at_Hours: // godziny płynnie 12h/360°
|
||||
// glRotatef(GlobalTime->hh*30.0+GlobalTime->mm*0.5+GlobalTime->mr/120.0,0.0,1.0,0.0);
|
||||
@@ -943,7 +948,7 @@ void TSubModel::RaAnimation(glm::mat4 &m, TAnimType a)
|
||||
}
|
||||
break;
|
||||
case at_Wind: // ruch pod wpływem wiatru (wiatr będziemy liczyć potem...)
|
||||
m = glm::rotate(m, glm::radians(1.5f * (float)sin(M_PI * Simulation::Time.second() / 6.0)), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
m = glm::rotate(m, glm::radians(1.5f * (float)sin(M_PI * simulation::Time.second() / 6.0)), glm::vec3(0.0f, 1.0f, 0.0f));
|
||||
break;
|
||||
case at_Sky: // animacja nieba
|
||||
m = glm::rotate(m, glm::radians((float)Global::fLatitudeDeg), glm::vec3(0.0f, 1.0f, 0.0f)); // ustawienie osi OY na północ
|
||||
@@ -1526,15 +1531,21 @@ bool TModel3d::LoadFromFile(std::string const &FileName, bool dynamic)
|
||||
LoadFromBinFile(asBinary, dynamic);
|
||||
asBinary = ""; // wyłączenie zapisu
|
||||
Init();
|
||||
}
|
||||
// cache the file name, in case someone wants it later
|
||||
m_filename = name + ".e3d";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (FileExists(name + ".t3d"))
|
||||
{
|
||||
LoadFromTextFile(FileName, dynamic); // wczytanie tekstowego
|
||||
if (!dynamic) // pojazdy dopiero po ustawieniu animacji
|
||||
Init(); // generowanie siatek i zapis E3D
|
||||
}
|
||||
if( !dynamic ) {
|
||||
// pojazdy dopiero po ustawieniu animacji
|
||||
Init(); // generowanie siatek i zapis E3D
|
||||
}
|
||||
// cache the file name, in case someone wants it later
|
||||
m_filename = name + ".t3d";
|
||||
}
|
||||
}
|
||||
bool const result =
|
||||
Root ? (iSubModelsCount > 0) : false; // brak pliku albo problem z wczytaniem
|
||||
@@ -1902,6 +1913,14 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, float8 *v,
|
||||
// so as a workaround we're doing it here manually
|
||||
iFlags |= 0x20;
|
||||
}
|
||||
// intercept and fix hotspot values if specified in degrees and not directly
|
||||
if( fCosFalloffAngle > 1.0 ) {
|
||||
fCosFalloffAngle = std::cos( DegToRad( 0.5f * fCosFalloffAngle ) );
|
||||
}
|
||||
if( fCosHotspotAngle > 1.0 ) {
|
||||
fCosHotspotAngle = std::cos( DegToRad( 0.5f * fCosHotspotAngle ) );
|
||||
}
|
||||
|
||||
iFlags &= ~0x0200; // wczytano z pliku binarnego (nie jest właścicielem tablic)
|
||||
|
||||
iVboPtr = tVboPtr;
|
||||
|
||||
@@ -342,6 +342,7 @@ private:
|
||||
int *iModel; // zawartość pliku binarnego
|
||||
int iSubModelsCount; // Ra: używane do tworzenia binarnych
|
||||
std::string asBinary; // nazwa pod którą zapisać model binarny
|
||||
std::string m_filename;
|
||||
public:
|
||||
inline TSubModel * GetSMRoot()
|
||||
{
|
||||
@@ -382,7 +383,8 @@ public:
|
||||
void Init();
|
||||
std::string NameGet()
|
||||
{
|
||||
return Root ? Root->pName : NULL;
|
||||
// return Root ? Root->pName : NULL;
|
||||
return m_filename;
|
||||
};
|
||||
int TerrainCount();
|
||||
TSubModel * TerrainSquare(int n);
|
||||
|
||||
@@ -48,6 +48,7 @@ class TRealSound
|
||||
int GetStatus();
|
||||
void ResetPosition();
|
||||
// void FreqReset(float f=22050.0) {fFrequency=f;};
|
||||
bool Empty() { return ( pSound == nullptr ); }
|
||||
};
|
||||
|
||||
class TTextSound : public TRealSound
|
||||
|
||||
31
Timer.cpp
31
Timer.cpp
@@ -15,12 +15,12 @@ namespace Timer
|
||||
{
|
||||
|
||||
double DeltaTime, DeltaRenderTime;
|
||||
double fFPS = 0.0f;
|
||||
double fLastTime = 0.0f;
|
||||
DWORD dwFrames = 0L;
|
||||
double fSimulationTime = 0;
|
||||
double fSoundTimer = 0;
|
||||
double fSinceStart = 0;
|
||||
double fFPS{ 0.0f };
|
||||
double fLastTime{ 0.0f };
|
||||
DWORD dwFrames{ 0 };
|
||||
double fSimulationTime{ 0.0 };
|
||||
double fSoundTimer{ 0.0 };
|
||||
double fSinceStart{ 0.0 };
|
||||
|
||||
double GetTime()
|
||||
{
|
||||
@@ -69,15 +69,10 @@ double GetFPS()
|
||||
|
||||
void ResetTimers()
|
||||
{
|
||||
// double CurrentTime=
|
||||
#if _WIN32_WINNT >= _WIN32_WINNT_VISTA
|
||||
::GetTickCount64();
|
||||
#else
|
||||
::GetTickCount();
|
||||
#endif
|
||||
UpdateTimers( Global::iPause != 0 );
|
||||
DeltaTime = 0.1;
|
||||
DeltaRenderTime = 0;
|
||||
fSoundTimer = 0;
|
||||
DeltaRenderTime = 0.0;
|
||||
fSoundTimer = 0.0;
|
||||
};
|
||||
|
||||
LONGLONG fr, count, oldCount;
|
||||
@@ -92,17 +87,17 @@ void UpdateTimers(bool pause)
|
||||
DeltaTime = Global::fTimeSpeed * DeltaRenderTime;
|
||||
fSoundTimer += DeltaTime;
|
||||
if (fSoundTimer > 0.1)
|
||||
fSoundTimer = 0;
|
||||
fSoundTimer = 0.0;
|
||||
/*
|
||||
double CurrentTime= double(count)/double(fr);//GetTickCount();
|
||||
DeltaTime= (CurrentTime-OldTime);
|
||||
OldTime= CurrentTime;
|
||||
*/
|
||||
if (DeltaTime > 1)
|
||||
DeltaTime = 1;
|
||||
if (DeltaTime > 1.0)
|
||||
DeltaTime = 1.0;
|
||||
}
|
||||
else
|
||||
DeltaTime = 0; // wszystko stoi, bo czas nie płynie
|
||||
DeltaTime = 0.0; // wszystko stoi, bo czas nie płynie
|
||||
oldCount = count;
|
||||
|
||||
// Keep track of the time lapse and frame count
|
||||
|
||||
153
Train.h
153
Train.h
@@ -7,39 +7,28 @@ obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#ifndef TrainH
|
||||
#define TrainH
|
||||
#pragma once
|
||||
|
||||
//#include "Track.h"
|
||||
//#include "TrkFoll.h"
|
||||
#include "Button.h"
|
||||
#include <string>
|
||||
#include "DynObj.h"
|
||||
#include "Button.h"
|
||||
#include "Gauge.h"
|
||||
#include "Model3d.h"
|
||||
#include "Spring.h"
|
||||
#include "mtable.h"
|
||||
|
||||
#include "AdvSound.h"
|
||||
#include "FadeSound.h"
|
||||
#include "PyInt.h"
|
||||
#include "RealSound.h"
|
||||
#include "Sound.h"
|
||||
#include <string>
|
||||
#include "command.h"
|
||||
|
||||
// typedef enum {st_Off, st_Starting, st_On, st_ShuttingDown} T4State;
|
||||
|
||||
const int maxcab = 2;
|
||||
|
||||
// const double fCzuwakTime= 90.0f;
|
||||
const double fCzuwakBlink = 0.15;
|
||||
const float fConverterPrzekaznik = 1.5f; // hunter-261211: do przekaznika nadmiarowego przetwornicy
|
||||
// 0.33f
|
||||
// const double fBuzzerTime= 5.0f;
|
||||
const float fHaslerTime = 1.2f;
|
||||
|
||||
// const double fStycznTime= 0.5f;
|
||||
// const double fDblClickTime= 0.2f;
|
||||
|
||||
class TCab
|
||||
{
|
||||
public:
|
||||
@@ -77,52 +66,126 @@ class TTrain
|
||||
bool InitializeCab(int NewCabNo, std::string const &asFileName);
|
||||
TTrain();
|
||||
~TTrain();
|
||||
// bool Init(TTrack *Track);
|
||||
// McZapkie-010302
|
||||
bool Init(TDynamicObject *NewDynamicObject, bool e3d = false);
|
||||
void OnKeyDown(int cKey);
|
||||
void OnKeyUp(int cKey);
|
||||
|
||||
// bool SHP() { fShpTimer= 0; };
|
||||
|
||||
inline vector3 GetDirection()
|
||||
{
|
||||
return DynamicObject->VectorFront();
|
||||
};
|
||||
inline vector3 GetUp()
|
||||
{
|
||||
return DynamicObject->VectorUp();
|
||||
};
|
||||
inline vector3 GetDirection() { return DynamicObject->VectorFront(); };
|
||||
inline vector3 GetUp() { return DynamicObject->VectorUp(); };
|
||||
void UpdateMechPosition(double dt);
|
||||
vector3 GetWorldMechPosition();
|
||||
bool Update( double const Deltatime );
|
||||
bool m_updated = false;
|
||||
void MechStop();
|
||||
void SetLights();
|
||||
// virtual bool RenderAlpha();
|
||||
// McZapkie-310302: ladowanie parametrow z pliku
|
||||
bool LoadMMediaFile(std::string const &asFileName);
|
||||
PyObject *GetTrainState();
|
||||
|
||||
private:
|
||||
// types
|
||||
typedef void( *command_handler )( TTrain *Train, command_data const &Command );
|
||||
typedef std::unordered_map<user_command, command_handler> commandhandler_map;
|
||||
// clears state of all cabin controls
|
||||
void clear_cab_controls();
|
||||
// sets cabin controls based on current state of the vehicle
|
||||
// NOTE: we can get rid of this function once we have per-cab persistent state
|
||||
void set_cab_controls();
|
||||
// initializes a gauge matching provided label. returns: true if the label was found, false
|
||||
// otherwise
|
||||
bool initialize_gauge(cParser &Parser, std::string const &Label, int const Cabindex);
|
||||
// initializes a button matching provided label. returns: true if the label was found, false
|
||||
// otherwise
|
||||
bool initialize_button(cParser &Parser, std::string const &Label, int const Cabindex);
|
||||
// plays specified sound, or fallback sound if the primary sound isn't presend
|
||||
// NOTE: temporary routine until sound system is sorted out and paired with switches
|
||||
void play_sound( PSound Sound, int const Volume = DSBVOLUME_MAX, DWORD const Flags = 0 );
|
||||
void play_sound( PSound Sound, PSound Fallbacksound, int const Volume, DWORD const Flags );
|
||||
// helper, returns true for EMU with oerlikon brake
|
||||
bool is_eztoer() const;
|
||||
// command handlers
|
||||
// NOTE: we're currently using universal handlers and static handler map but it may be beneficial to have these implemented on individual class instance basis
|
||||
// TBD, TODO: consider this approach if we ever want to have customized consist behaviour to received commands, based on the consist/vehicle type or whatever
|
||||
static void OnCommand_mastercontrollerincrease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_mastercontrollerincreasefast( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_mastercontrollerdecrease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_mastercontrollerdecreasefast( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_secondcontrollerincrease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_secondcontrollerincreasefast( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_secondcontrollerdecrease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_secondcontrollerdecreasefast( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_notchingrelaytoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_mucurrentindicatorothersourceactivate( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_independentbrakeincrease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_independentbrakeincreasefast( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_independentbrakedecrease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_independentbrakedecreasefast( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_independentbrakebailoff( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_trainbrakeincrease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_trainbrakedecrease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_trainbrakecharging( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_trainbrakerelease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_trainbrakefirstservice( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_trainbrakeservice( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_trainbrakefullservice( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_trainbrakeemergency( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_wheelspinbrakeactivate( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_sandboxactivate( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_epbrakecontroltoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_brakeactingspeedincrease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_brakeactingspeeddecrease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_mubrakingindicatortoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_reverserincrease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_reverserdecrease( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_alerteracknowledge( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_batterytoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_pantographcompressorvalvetoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_pantographcompressoractivate( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_pantographtogglefront( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_pantographtogglerear( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_pantographlowerall( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_linebreakertoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_convertertoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_converteroverloadrelayreset( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_compressortoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_motorconnectorsopen( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_motordisconnect( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_motoroverloadrelaythresholdtoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_motoroverloadrelayreset( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_heatingtoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_headlighttoggleleft( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_headlighttoggleright( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_headlighttoggleupper( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_redmarkertoggleleft( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_redmarkertoggleright( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_headlighttogglerearleft( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_headlighttogglerearright( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_headlighttogglerearupper( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_redmarkertogglerearleft( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_redmarkertogglerearright( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_headlightsdimtoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_interiorlighttoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_interiorlightdimtoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_instrumentlighttoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_doorlocktoggle( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_doortoggleleft( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_doortoggleright( TTrain *Train, command_data const &Command );
|
||||
static void OnCommand_departureannounce( TTrain *Train, command_data const &Command );
|
||||
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 );
|
||||
|
||||
private: //żeby go nic z zewnątrz nie przestawiało
|
||||
// members
|
||||
TDynamicObject *DynamicObject; // przestawia zmiana pojazdu [F5]
|
||||
private: //żeby go nic z zewnątrz nie przestawiało
|
||||
TMoverParameters *mvControlled; // człon, w którym sterujemy silnikiem
|
||||
TMoverParameters *mvOccupied; // człon, w którym sterujemy hamulcem
|
||||
TMoverParameters *mvSecond; // drugi człon (ET40, ET41, ET42, ukrotnienia)
|
||||
TMoverParameters *mvThird; // trzeci człon (SN61)
|
||||
public: // reszta może by?publiczna
|
||||
// AnsiString asMessage;
|
||||
// helper variable, to prevent immediate switch between closing and opening line breaker circuit
|
||||
int m_linebreakerstate{ 0 }; // -1: freshly open, 0: open, 1: closed, 2: freshly closed (and yes this is awful way to go about it)
|
||||
static const commandhandler_map m_commandhandlers;
|
||||
|
||||
public: // reszta może by?publiczna
|
||||
|
||||
// McZapkie: definicje wskaźników
|
||||
// Ra 2014-08: częsciowo przeniesione do tablicy w TCab
|
||||
@@ -167,8 +230,7 @@ class TTrain
|
||||
TGauge ggSandButton; // guzik piasecznicy
|
||||
TGauge ggAntiSlipButton;
|
||||
TGauge ggFuseButton;
|
||||
TGauge ggConverterFuseButton; // hunter-261211: przycisk odblokowania
|
||||
// nadmiarowego przetwornic i ogrzewania
|
||||
TGauge ggConverterFuseButton; // hunter-261211: przycisk odblokowania nadmiarowego przetwornic i ogrzewania
|
||||
TGauge ggStLinOffButton;
|
||||
TGauge ggRadioButton;
|
||||
TGauge ggUpperLightButton;
|
||||
@@ -194,6 +256,8 @@ class TTrain
|
||||
|
||||
// ABu 090305 - syrena i prad nastepnego czlonu
|
||||
TGauge ggHornButton;
|
||||
TGauge ggHornLowButton;
|
||||
TGauge ggHornHighButton;
|
||||
TGauge ggNextCurrentButton;
|
||||
// ABu 090305 - uniwersalne przyciski
|
||||
TGauge ggUniversal1Button;
|
||||
@@ -215,12 +279,12 @@ class TTrain
|
||||
TGauge ggPantFrontButton;
|
||||
TGauge ggPantRearButton;
|
||||
TGauge ggPantFrontButtonOff; // EZT
|
||||
TGauge ggPantRearButtonOff;
|
||||
TGauge ggPantAllDownButton;
|
||||
// Winger 020304 - wlacznik ogrzewania
|
||||
TGauge ggTrainHeatingButton;
|
||||
TGauge ggSignallingButton;
|
||||
TGauge ggDoorSignallingButton;
|
||||
// TModel3d *mdKabina; McZapkie-030303: to do dynobj
|
||||
// TGauge ggDistCounter; //Ra 2014-07: licznik kilometrów
|
||||
// TGauge ggVelocityDgt; //i od razu prędkościomierz
|
||||
|
||||
@@ -354,8 +418,7 @@ class TTrain
|
||||
// TFadeSound sConverter; //przetwornica
|
||||
// TFadeSound sSmallCompressor; //przetwornica
|
||||
|
||||
int iCabLightFlag; // McZapkie:120503: oswietlenie kabiny (0: wyl, 1:
|
||||
// przyciemnione, 2: pelne)
|
||||
int iCabLightFlag; // McZapkie:120503: oswietlenie kabiny (0: wyl, 1: przyciemnione, 2: pelne)
|
||||
bool bCabLight; // hunter-091012: czy swiatlo jest zapalone?
|
||||
bool bCabLightDim; // hunter-091012: czy przyciemnienie kabiny jest zapalone?
|
||||
|
||||
@@ -422,20 +485,10 @@ class TTrain
|
||||
public:
|
||||
float fPress[20][3]; // cisnienia dla wszystkich czlonow
|
||||
float fEIMParams[9][10]; // parametry dla silnikow asynchronicznych
|
||||
int RadioChannel()
|
||||
{
|
||||
return iRadioChannel;
|
||||
};
|
||||
inline TDynamicObject *Dynamic()
|
||||
{
|
||||
return DynamicObject;
|
||||
};
|
||||
inline TMoverParameters *Controlled()
|
||||
{
|
||||
return mvControlled;
|
||||
};
|
||||
int RadioChannel() { return iRadioChannel; };
|
||||
inline TDynamicObject *Dynamic() { return DynamicObject; };
|
||||
inline TMoverParameters *Controlled() { return mvControlled; };
|
||||
void DynamicSet(TDynamicObject *d);
|
||||
void Silence();
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
#endif
|
||||
|
||||
137
World.cpp
137
World.cpp
@@ -43,7 +43,7 @@ std::shared_ptr<ui_panel> UIHeader = std::make_shared<ui_panel>( 20, 20 ); // he
|
||||
std::shared_ptr<ui_panel> UITable = std::make_shared<ui_panel>( 20, 100 ); // schedule or scan table
|
||||
std::shared_ptr<ui_panel> UITranscripts = std::make_shared<ui_panel>( 85, 600 ); // voice transcripts
|
||||
|
||||
namespace Simulation {
|
||||
namespace simulation {
|
||||
|
||||
simulation_time Time;
|
||||
|
||||
@@ -86,14 +86,13 @@ simulation_time::init() {
|
||||
void
|
||||
simulation_time::update( double const Deltatime ) {
|
||||
|
||||
// use large enough buffer to hold long time skips
|
||||
auto milliseconds = m_time.wMilliseconds + static_cast<size_t>(std::floor( 1000.0 * Deltatime ));
|
||||
while( milliseconds >= 1000.0 ) {
|
||||
m_milliseconds += ( 1000.0 * Deltatime );
|
||||
while( m_milliseconds >= 1000.0 ) {
|
||||
|
||||
++m_time.wSecond;
|
||||
milliseconds -= 1000;
|
||||
m_milliseconds -= 1000.0;
|
||||
}
|
||||
m_time.wMilliseconds = (WORD)milliseconds;
|
||||
m_time.wMilliseconds = std::floor( m_milliseconds );
|
||||
while( m_time.wSecond >= 60 ) {
|
||||
|
||||
++m_time.wMinute;
|
||||
@@ -313,7 +312,7 @@ bool TWorld::Init( GLFWwindow *Window ) {
|
||||
|
||||
glfwSetWindowTitle( window, ( Global::AppName + " (" + Global::SceneryFile + ")" ).c_str() ); // nazwa scenerii
|
||||
|
||||
Simulation::Time.init();
|
||||
simulation::Time.init();
|
||||
|
||||
Environment.init();
|
||||
Camera.Init(Global::FreeCameraInit[0], Global::FreeCameraInitAngle[0]);
|
||||
@@ -506,11 +505,11 @@ void TWorld::OnKeyDown(int cKey)
|
||||
// additional time speedup keys in debug mode
|
||||
if (Global::ctrlState) {
|
||||
// ctrl-f3
|
||||
Simulation::Time.update( 20.0 * 60.0 );
|
||||
simulation::Time.update( 20.0 * 60.0 );
|
||||
}
|
||||
else if (Global::shiftState) {
|
||||
// shift-f3
|
||||
Simulation::Time.update( 5.0 * 60.0 );
|
||||
simulation::Time.update( 5.0 * 60.0 );
|
||||
}
|
||||
}
|
||||
if( (!Global::ctrlState)
|
||||
@@ -608,6 +607,32 @@ void TWorld::OnKeyDown(int cKey)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GLFW_KEY_F7: {
|
||||
// debug mode functions
|
||||
if( DebugModeFlag ) {
|
||||
|
||||
if( Global::ctrlState ) {
|
||||
// ctrl + f7 toggles static daylight
|
||||
ToggleDaylight();
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// f7: wireframe toggle
|
||||
Global::bWireFrame = !Global::bWireFrame;
|
||||
if( true == Global::bWireFrame ) {
|
||||
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
|
||||
}
|
||||
else {
|
||||
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
|
||||
}
|
||||
/*
|
||||
++Global::iReCompile; // odświeżyć siatki
|
||||
// Ra: jeszcze usunąć siatki ze skompilowanych obiektów!
|
||||
*/
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GLFW_KEY_F8: {
|
||||
Global::iTextMode = cKey;
|
||||
// FPS
|
||||
@@ -671,7 +696,17 @@ void TWorld::OnKeyDown(int cKey)
|
||||
// else if (cKey=='3') Global::iWriteLogEnabled^=4; //wypisywanie nazw torów
|
||||
}
|
||||
}
|
||||
else if (Global::ctrlState && cKey == GLFW_KEY_PAUSE) //[Ctrl]+[Break]
|
||||
else if( cKey == GLFW_KEY_ESCAPE ) {
|
||||
// toggle pause
|
||||
if( Global::iPause & 1 ) // jeśli pauza startowa
|
||||
Global::iPause &= ~1; // odpauzowanie, gdy po wczytaniu miało nie startować
|
||||
else if( !( Global::iMultiplayer & 2 ) ) // w multiplayerze pauza nie ma sensu
|
||||
Global::iPause ^= 2; // zmiana stanu zapauzowania
|
||||
if( Global::iPause ) {// jak pauza
|
||||
Global::iTextMode = GLFW_KEY_F1; // to wyświetlić zegar i informację
|
||||
}
|
||||
}
|
||||
else if( Global::ctrlState && cKey == GLFW_KEY_PAUSE ) //[Ctrl]+[Break]
|
||||
{ // hamowanie wszystkich pojazdów w okolicy
|
||||
if (Controlled->MoverParameters->Radio)
|
||||
Ground.RadioStop(Camera.Pos);
|
||||
@@ -793,15 +828,6 @@ void TWorld::OnKeyDown(int cKey)
|
||||
//}
|
||||
}
|
||||
|
||||
void TWorld::OnKeyUp(int cKey)
|
||||
{ // zwolnienie klawisza; (cKey) to kod klawisza, cyfrowe i literowe się zgadzają
|
||||
if (!Global::iPause) // podczas pauzy sterownaie nie działa
|
||||
if (Train)
|
||||
if (Controlled)
|
||||
if ((Controlled->Controller == Humandriver) ? true : DebugModeFlag || (cKey == 'Q'))
|
||||
Train->OnKeyUp(cKey); // przekazanie zwolnienia klawisza do kabiny
|
||||
};
|
||||
|
||||
void TWorld::OnMouseMove(double x, double y)
|
||||
{ // McZapkie:060503-definicja obracania myszy
|
||||
Camera.OnCursorMove(x * Global::fMouseXScale / Global::ZoomFactor, -y * Global::fMouseYScale / Global::ZoomFactor);
|
||||
@@ -946,13 +972,15 @@ bool TWorld::Update()
|
||||
WriteLog("Scenery moved");
|
||||
};
|
||||
#endif
|
||||
|
||||
Timer::UpdateTimers(Global::iPause != 0);
|
||||
|
||||
if( (Global::iPause == false)
|
||||
|| (m_init == false) )
|
||||
{ // jak pauza, to nie ma po co tego przeliczać
|
||||
|| (m_init == false) ) {
|
||||
// jak pauza, to nie ma po co tego przeliczać
|
||||
simulation::Time.update( Timer::GetDeltaTime() );
|
||||
// Ra 2014-07: przeliczenie kąta czasu (do animacji zależnych od czasu)
|
||||
Simulation::Time.update( Timer::GetDeltaTime() );
|
||||
auto const &time = Simulation::Time.data();
|
||||
auto const &time = simulation::Time.data();
|
||||
Global::fTimeAngleDeg = time.wHour * 15.0 + time.wMinute * 0.25 + ( ( time.wSecond + 0.001 * time.wMilliseconds ) / 240.0 );
|
||||
Global::fClockAngleDeg[ 0 ] = 36.0 * ( time.wSecond % 10 ); // jednostki sekund
|
||||
Global::fClockAngleDeg[ 1 ] = 36.0 * ( time.wSecond / 10 ); // dziesiątki sekund
|
||||
@@ -1081,15 +1109,20 @@ bool TWorld::Update()
|
||||
fTime50Hz += dt; // w pauzie też trzeba zliczać czas, bo przy dużym FPS będzie problem z odczytem ramek
|
||||
if( fTime50Hz >= 0.2 ) {
|
||||
Console::Update(); // to i tak trzeba wywoływać
|
||||
fTime50Hz -= 0.2;
|
||||
Update_UI();
|
||||
|
||||
Camera.Velocity *= 0.65;
|
||||
if( std::abs( Camera.Velocity.x ) < 0.01 ) { Camera.Velocity.x = 0.0; }
|
||||
if( std::abs( Camera.Velocity.y ) < 0.01 ) { Camera.Velocity.y = 0.0; }
|
||||
if( std::abs( Camera.Velocity.z ) < 0.01 ) { Camera.Velocity.z = 0.0; }
|
||||
|
||||
fTime50Hz -= 1.0 / 50.0;
|
||||
}
|
||||
|
||||
// variable step render time routines
|
||||
|
||||
Update_Camera( dt );
|
||||
|
||||
Update_UI(); // TBD, TODO: move the ui updates to secondary fixed step routines, to reduce workload?
|
||||
|
||||
GfxRenderer.Update( dt );
|
||||
ResourceSweep();
|
||||
|
||||
@@ -1626,7 +1659,7 @@ TWorld::Update_UI() {
|
||||
|
||||
case( GLFW_KEY_F1 ) : {
|
||||
// f1, default mode: current time and timetable excerpt
|
||||
auto const &time = Simulation::Time.data();
|
||||
auto const &time = simulation::Time.data();
|
||||
uitextline1 =
|
||||
"Time: "
|
||||
+ to_string( time.wHour ) + ":"
|
||||
@@ -1668,16 +1701,21 @@ TWorld::Update_UI() {
|
||||
// timetable
|
||||
TDynamicObject *tmp =
|
||||
( FreeFlyModeFlag ?
|
||||
Ground.DynamicNearest( Camera.Pos ) :
|
||||
Controlled ); // w trybie latania lokalizujemy wg mapy
|
||||
Ground.DynamicNearest( Camera.Pos ) :
|
||||
Controlled ); // w trybie latania lokalizujemy wg mapy
|
||||
|
||||
if( tmp == nullptr ) { break; }
|
||||
if( tmp->Mechanik == nullptr ) { break; }
|
||||
// if the nearest located vehicle doesn't have a direct driver, try to query its owner
|
||||
auto const owner = (
|
||||
tmp->Mechanik != nullptr ?
|
||||
tmp->Mechanik :
|
||||
tmp->ctOwner );
|
||||
if( owner == nullptr ){ break; }
|
||||
|
||||
auto const table = tmp->Mechanik->Timetable();
|
||||
auto const table = owner->Timetable();
|
||||
if( table == nullptr ) { break; }
|
||||
|
||||
auto const &time = Simulation::Time.data();
|
||||
auto const &time = simulation::Time.data();
|
||||
uitextline1 =
|
||||
"Time: "
|
||||
+ to_string( time.wHour ) + ":"
|
||||
@@ -1687,14 +1725,12 @@ TWorld::Update_UI() {
|
||||
uitextline1 += " (paused)";
|
||||
}
|
||||
|
||||
if( Controlled
|
||||
&& Controlled->Mechanik ) {
|
||||
uitextline2 = Global::Bezogonkow( Controlled->Mechanik->Relation(), true ) + " (" + tmp->Mechanik->Timetable()->TrainName + ")";
|
||||
if( !uitextline2.empty() ) {
|
||||
// jeśli jest podana relacja, to dodajemy punkt następnego zatrzymania
|
||||
uitextline3 = " -> " + Global::Bezogonkow( Controlled->Mechanik->NextStop(), true );
|
||||
}
|
||||
}
|
||||
uitextline2 = Global::Bezogonkow( owner->Relation(), true ) + " (" + Global::Bezogonkow( owner->Timetable()->TrainName, true ) + ")";
|
||||
auto const nextstation = Global::Bezogonkow( owner->NextStop(), true );
|
||||
if( !nextstation.empty() ) {
|
||||
// jeśli jest podana relacja, to dodajemy punkt następnego zatrzymania
|
||||
uitextline3 = " -> " + nextstation;
|
||||
}
|
||||
|
||||
if( Global::iScreenMode[ Global::iTextMode - GLFW_KEY_F1 ] == 1 ) {
|
||||
|
||||
@@ -1707,7 +1743,7 @@ TWorld::Update_UI() {
|
||||
UITable->text_lines.emplace_back( "+----------------------------+-------+-------+-----+", Global::UITextColor );
|
||||
|
||||
TMTableLine *tableline;
|
||||
for( int i = tmp->Mechanik->iStationStart; i <= std::min( tmp->Mechanik->iStationStart + 15, table->StationCount ); ++i ) {
|
||||
for( int i = owner->iStationStart; i <= std::min( owner->iStationStart + 15, table->StationCount ); ++i ) {
|
||||
// wyświetlenie pozycji z rozkładu
|
||||
tableline = table->TimeTable + i; // linijka rozkładu
|
||||
|
||||
@@ -1728,7 +1764,7 @@ TWorld::Update_UI() {
|
||||
|
||||
UITable->text_lines.emplace_back(
|
||||
Global::Bezogonkow( "| " + station + " | " + arrival + " | " + departure + " | " + vmax + " | " + tableline->StationWare, true ),
|
||||
( ( tmp->Mechanik->iStationStart < table->StationIndex ) && ( i < table->StationIndex ) ?
|
||||
( ( owner->iStationStart < table->StationIndex ) && ( i < table->StationIndex ) ?
|
||||
float4( 0.0f, 1.0f, 0.0f, 1.0f ) :// czas minął i odjazd był, to nazwa stacji będzie na zielono
|
||||
Global::UITextColor )
|
||||
);
|
||||
@@ -1999,8 +2035,8 @@ TWorld::Update_UI() {
|
||||
to_string( tmp->MoverParameters->RunningShape.R, 1 ) )
|
||||
+ " An=" + to_string( tmp->MoverParameters->AccN, 2 ); // przyspieszenie poprzeczne
|
||||
|
||||
if( tprev != Simulation::Time.data().wSecond ) {
|
||||
tprev = Simulation::Time.data().wSecond;
|
||||
if( tprev != simulation::Time.data().wSecond ) {
|
||||
tprev = simulation::Time.data().wSecond;
|
||||
Acc = ( tmp->MoverParameters->Vel - VelPrev ) / 3.6;
|
||||
VelPrev = tmp->MoverParameters->Vel;
|
||||
}
|
||||
@@ -2159,9 +2195,8 @@ void TWorld::OnCommandGet(DaneRozkaz *pRozkaz)
|
||||
std::string(pRozkaz->cString + 1, (unsigned)(pRozkaz->cString[0])));
|
||||
if (e)
|
||||
if ((e->Type == tp_Multiple) || (e->Type == tp_Lights) ||
|
||||
(e->evJoined != 0)) // tylko jawne albo niejawne Multiple
|
||||
Ground.AddToQuery(e, NULL); // drugi parametr to dynamic wywołujący - tu
|
||||
// brak
|
||||
(e->evJoined != 0)) // tylko jawne albo niejawne Multiple
|
||||
Ground.AddToQuery(e, NULL); // drugi parametr to dynamic wywołujący - tu brak
|
||||
}
|
||||
break;
|
||||
case 3: // rozkaz dla AI
|
||||
@@ -2205,12 +2240,12 @@ void TWorld::OnCommandGet(DaneRozkaz *pRozkaz)
|
||||
if (*pRozkaz->iPar & 1) // ustawienie czasu
|
||||
{
|
||||
double t = pRozkaz->fPar[1];
|
||||
Simulation::Time.data().wDay = std::floor(t); // niby nie powinno być dnia, ale...
|
||||
simulation::Time.data().wDay = std::floor(t); // niby nie powinno być dnia, ale...
|
||||
if (Global::fMoveLight >= 0)
|
||||
Global::fMoveLight = t; // trzeba by deklinację Słońca przeliczyć
|
||||
Simulation::Time.data().wHour = std::floor(24 * t) - 24.0 * Simulation::Time.data().wDay;
|
||||
Simulation::Time.data().wMinute = std::floor(60 * 24 * t) - 60.0 * (24.0 * Simulation::Time.data().wDay + Simulation::Time.data().wHour);
|
||||
Simulation::Time.data().wSecond = std::floor( 60 * 60 * 24 * t ) - 60.0 * ( 60.0 * ( 24.0 * Simulation::Time.data().wDay + Simulation::Time.data().wHour ) + Simulation::Time.data().wMinute );
|
||||
simulation::Time.data().wHour = std::floor(24 * t) - 24.0 * simulation::Time.data().wDay;
|
||||
simulation::Time.data().wMinute = std::floor(60 * 24 * t) - 60.0 * (24.0 * simulation::Time.data().wDay + simulation::Time.data().wHour);
|
||||
simulation::Time.data().wSecond = std::floor( 60 * 60 * 24 * t ) - 60.0 * ( 60.0 * ( 24.0 * simulation::Time.data().wDay + simulation::Time.data().wHour ) + simulation::Time.data().wMinute );
|
||||
}
|
||||
if (*pRozkaz->iPar & 2)
|
||||
{ // ustawienie flag zapauzowania
|
||||
|
||||
4
World.h
4
World.h
@@ -49,11 +49,12 @@ private:
|
||||
daymonth( WORD &Day, WORD &Month, WORD const Year, WORD const Yearday );
|
||||
|
||||
SYSTEMTIME m_time;
|
||||
double m_milliseconds{ 0.0 };
|
||||
int m_yearday;
|
||||
char m_monthdaycounts[ 2 ][ 13 ];
|
||||
};
|
||||
|
||||
namespace Simulation {
|
||||
namespace simulation {
|
||||
|
||||
extern simulation_time Time;
|
||||
|
||||
@@ -100,7 +101,6 @@ TWorld();
|
||||
bool InitPerformed() { return m_init; }
|
||||
GLFWwindow *window;
|
||||
void OnKeyDown(int cKey);
|
||||
void OnKeyUp(int cKey);
|
||||
// void UpdateWindow();
|
||||
void OnMouseMove(double x, double y);
|
||||
void OnCommandGet(DaneRozkaz *pRozkaz);
|
||||
|
||||
216
command.cpp
Normal file
216
command.cpp
Normal file
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
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/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "command.h"
|
||||
|
||||
#include "globals.h"
|
||||
#include "logs.h"
|
||||
#include "timer.h"
|
||||
|
||||
namespace simulation {
|
||||
|
||||
command_queue Commands;
|
||||
commanddescription_sequence Commands_descriptions = {
|
||||
|
||||
{ "mastercontrollerincrease", command_target::vehicle },
|
||||
{ "mastercontrollerincreasefast", command_target::vehicle },
|
||||
{ "mastercontrollerdecrease", command_target::vehicle },
|
||||
{ "mastercontrollerdecreasefast", command_target::vehicle },
|
||||
{ "secondcontrollerincrease", command_target::vehicle },
|
||||
{ "secondcontrollerincreasefast", command_target::vehicle },
|
||||
{ "secondcontrollerdecrease", command_target::vehicle },
|
||||
{ "secondcontrollerdecreasefast", command_target::vehicle },
|
||||
{ "mucurrentindicatorothersourceactivate", command_target::vehicle },
|
||||
{ "independentbrakeincrease", command_target::vehicle },
|
||||
{ "independentbrakeincreasefast", command_target::vehicle },
|
||||
{ "independentbrakedecrease", command_target::vehicle },
|
||||
{ "independentbrakedecreasefast", command_target::vehicle },
|
||||
{ "independentbrakebailoff", command_target::vehicle },
|
||||
{ "trainbrakeincrease", command_target::vehicle },
|
||||
{ "trainbrakedecrease", command_target::vehicle },
|
||||
{ "trainbrakecharging", command_target::vehicle },
|
||||
{ "trainbrakerelease", command_target::vehicle },
|
||||
{ "trainbrakefirstservice", command_target::vehicle },
|
||||
{ "trainbrakeservice", command_target::vehicle },
|
||||
{ "trainbrakefullservice", command_target::vehicle },
|
||||
{ "trainbrakeemergency", command_target::vehicle },
|
||||
{ "wheelspinbrakeactivate", command_target::vehicle },
|
||||
{ "sandboxactivate", command_target::vehicle },
|
||||
{ "reverserincrease", command_target::vehicle },
|
||||
{ "reverserdecrease", command_target::vehicle },
|
||||
{ "linebreakertoggle", command_target::vehicle },
|
||||
{ "convertertoggle", command_target::vehicle },
|
||||
{ "converteroverloadrelayreset", command_target::vehicle },
|
||||
{ "compressortoggle", command_target::vehicle },
|
||||
{ "motoroverloadrelaythresholdtoggle", command_target::vehicle },
|
||||
{ "motoroverloadrelayreset", command_target::vehicle },
|
||||
{ "notchingrelaytoggle", command_target::vehicle },
|
||||
{ "epbrakecontroltoggle", command_target::vehicle },
|
||||
{ "brakeactingspeedincrease", command_target::vehicle },
|
||||
{ "brakeactingspeeddecrease", command_target::vehicle },
|
||||
{ "mubrakingindicatortoggle", command_target::vehicle },
|
||||
{ "alerteracknowledge", command_target::vehicle },
|
||||
{ "hornlowactivate", command_target::vehicle },
|
||||
{ "hornhighactivate", command_target::vehicle },
|
||||
{ "radiotoggle", command_target::vehicle },
|
||||
/*
|
||||
const int k_FailedEngineCutOff = 35;
|
||||
*/
|
||||
{ "viewturn", command_target::entity },
|
||||
{ "movevector", command_target::entity },
|
||||
{ "moveleft", command_target::entity },
|
||||
{ "moveright", command_target::entity },
|
||||
{ "moveforward", command_target::entity },
|
||||
{ "moveback", command_target::entity },
|
||||
{ "moveup", command_target::entity },
|
||||
{ "movedown", command_target::entity },
|
||||
{ "moveleftfast", command_target::entity },
|
||||
{ "moverightfast", command_target::entity },
|
||||
{ "moveforwardfast", command_target::entity },
|
||||
{ "movebackfast", command_target::entity },
|
||||
{ "moveupfast", command_target::entity },
|
||||
{ "movedownfast", command_target::entity },
|
||||
/*
|
||||
const int k_CabForward = 42;
|
||||
const int k_CabBackward = 43;
|
||||
const int k_Couple = 44;
|
||||
const int k_DeCouple = 45;
|
||||
const int k_ProgramQuit = 46;
|
||||
// const int k_ProgramPause= 47;
|
||||
const int k_ProgramHelp = 48;
|
||||
*/
|
||||
{ "doortoggleleft", command_target::vehicle },
|
||||
{ "doortoggleright", command_target::vehicle },
|
||||
{ "departureannounce", command_target::vehicle },
|
||||
{ "doorlocktoggle", command_target::vehicle },
|
||||
{ "pantographcompressorvalvetoggle", command_target::vehicle },
|
||||
{ "pantographcompressoractivate", command_target::vehicle },
|
||||
{ "pantographtogglefront", command_target::vehicle },
|
||||
{ "pantographtogglerear", command_target::vehicle },
|
||||
{ "pantographlowerall", command_target::vehicle },
|
||||
{ "heatingtoggle", command_target::vehicle },
|
||||
/*
|
||||
// const int k_FreeFlyMode= 59;
|
||||
*/
|
||||
{ "headlighttoggleleft", command_target::vehicle },
|
||||
{ "headlighttoggleright", command_target::vehicle },
|
||||
{ "headlighttoggleupper", command_target::vehicle },
|
||||
{ "redmarkertoggleleft", command_target::vehicle },
|
||||
{ "redmarkertoggleright", command_target::vehicle },
|
||||
{ "headlighttogglerearleft", command_target::vehicle },
|
||||
{ "headlighttogglerearright", command_target::vehicle },
|
||||
{ "headlighttogglerearupper", command_target::vehicle },
|
||||
{ "redmarkertogglerearleft", command_target::vehicle },
|
||||
{ "redmarkertogglerearright", command_target::vehicle },
|
||||
{ "headlightsdimtoggle", command_target::vehicle },
|
||||
{ "motorconnectorsopen", command_target::vehicle },
|
||||
{ "motordisconnect", command_target::vehicle },
|
||||
{ "interiorlighttoggle", command_target::vehicle },
|
||||
{ "interiorlightdimtoggle", command_target::vehicle },
|
||||
{ "instrumentlighttoggle", command_target::vehicle },
|
||||
/*
|
||||
const int k_Univ1 = 66;
|
||||
const int k_Univ2 = 67;
|
||||
const int k_Univ3 = 68;
|
||||
const int k_Univ4 = 69;
|
||||
const int k_EndSign = 70;
|
||||
const int k_Active = 71;
|
||||
*/
|
||||
{ "batterytoggle", command_target::vehicle }
|
||||
/*
|
||||
const int k_WalkMode = 73;
|
||||
*/
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// posts specified command for specified recipient
|
||||
void
|
||||
command_queue::push( command_data const &Command, std::size_t const Recipient ) {
|
||||
|
||||
auto lookup = m_commands.emplace( Recipient, commanddata_sequence() );
|
||||
// recipient stack was either located or created, so we can add to it quite safely
|
||||
lookup.first->second.emplace( Command );
|
||||
}
|
||||
|
||||
// retrieves oldest posted command for specified recipient, if any. returns: true on retrieval, false if there's nothing to retrieve
|
||||
bool
|
||||
command_queue::pop( command_data &Command, std::size_t const Recipient ) {
|
||||
|
||||
auto lookup = m_commands.find( Recipient );
|
||||
if( lookup == m_commands.end() ) {
|
||||
// no command stack for this recipient, so no commands
|
||||
return false;
|
||||
}
|
||||
auto &commands = lookup->second;
|
||||
if( true == commands.empty() ) {
|
||||
|
||||
return false;
|
||||
}
|
||||
// we have command stack with command(s) on it, retrieve and pop the first one
|
||||
Command = commands.front();
|
||||
commands.pop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
command_relay::post( user_command const Command, std::uint64_t const Param1, std::uint64_t const Param2, int const Action, std::uint16_t const Recipient ) const {
|
||||
|
||||
auto const &command = simulation::Commands_descriptions[ static_cast<std::size_t>( Command ) ];
|
||||
if( ( command.target == command_target::vehicle )
|
||||
&& ( true == FreeFlyModeFlag )
|
||||
&& ( ( false == DebugModeFlag )
|
||||
&& ( true == Global::RealisticControlMode ) ) ) {
|
||||
// in realistic control mode don't pass vehicle commands if the user isn't in one, unless we're in debug mode
|
||||
return;
|
||||
}
|
||||
|
||||
simulation::Commands.push(
|
||||
command_data{
|
||||
Command,
|
||||
Action,
|
||||
Param1,
|
||||
Param2,
|
||||
Timer::GetDeltaTime() },
|
||||
static_cast<std::size_t>( command.target ) | Recipient );
|
||||
/*
|
||||
#ifdef _DEBUG
|
||||
if( Action != GLFW_RELEASE ) {
|
||||
// key was pressed or is still held
|
||||
if( false == command.name.empty() ) {
|
||||
if( false == (
|
||||
( Command == user_command::moveleft )
|
||||
|| ( Command == user_command::moveleftfast )
|
||||
|| ( Command == user_command::moveright )
|
||||
|| ( Command == user_command::moverightfast )
|
||||
|| ( Command == user_command::moveforward )
|
||||
|| ( Command == user_command::moveforwardfast )
|
||||
|| ( Command == user_command::moveback )
|
||||
|| ( Command == user_command::movebackfast )
|
||||
|| ( Command == user_command::moveup )
|
||||
|| ( Command == user_command::moveupfast )
|
||||
|| ( Command == user_command::movedown )
|
||||
|| ( Command == user_command::movedownfast )
|
||||
|| ( Command == user_command::movevector )
|
||||
|| ( Command == user_command::viewturn ) ) ) {
|
||||
WriteLog( "Command issued: " + command.name );
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// key was released (but we don't log this)
|
||||
WriteLog( "Key released: " + command.name );
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
210
command.h
Normal file
210
command.h
Normal file
@@ -0,0 +1,210 @@
|
||||
/*
|
||||
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 <unordered_map>
|
||||
#include <queue>
|
||||
|
||||
enum class user_command {
|
||||
|
||||
mastercontrollerincrease,
|
||||
mastercontrollerincreasefast,
|
||||
mastercontrollerdecrease,
|
||||
mastercontrollerdecreasefast,
|
||||
secondcontrollerincrease,
|
||||
secondcontrollerincreasefast,
|
||||
secondcontrollerdecrease,
|
||||
secondcontrollerdecreasefast,
|
||||
mucurrentindicatorothersourceactivate,
|
||||
independentbrakeincrease,
|
||||
independentbrakeincreasefast,
|
||||
independentbrakedecrease,
|
||||
independentbrakedecreasefast,
|
||||
independentbrakebailoff,
|
||||
trainbrakeincrease,
|
||||
trainbrakedecrease,
|
||||
trainbrakecharging,
|
||||
trainbrakerelease,
|
||||
trainbrakefirstservice,
|
||||
trainbrakeservice,
|
||||
trainbrakefullservice,
|
||||
trainbrakeemergency,
|
||||
wheelspinbrakeactivate,
|
||||
sandboxactivate,
|
||||
reverserincrease,
|
||||
reverserdecrease,
|
||||
linebreakertoggle,
|
||||
convertertoggle,
|
||||
converteroverloadrelayreset,
|
||||
compressortoggle,
|
||||
motoroverloadrelaythresholdtoggle,
|
||||
motoroverloadrelayreset,
|
||||
notchingrelaytoggle,
|
||||
epbrakecontroltoggle,
|
||||
brakeactingspeedincrease,
|
||||
brakeactingspeeddecrease,
|
||||
mubrakingindicatortoggle,
|
||||
alerteracknowledge,
|
||||
hornlowactivate,
|
||||
hornhighactivate,
|
||||
radiotoggle,
|
||||
/*
|
||||
const int k_FailedEngineCutOff = 35;
|
||||
*/
|
||||
viewturn,
|
||||
movevector,
|
||||
moveleft,
|
||||
moveright,
|
||||
moveforward,
|
||||
moveback,
|
||||
moveup,
|
||||
movedown,
|
||||
moveleftfast,
|
||||
moverightfast,
|
||||
moveforwardfast,
|
||||
movebackfast,
|
||||
moveupfast,
|
||||
movedownfast,
|
||||
/*
|
||||
const int k_CabForward = 42;
|
||||
const int k_CabBackward = 43;
|
||||
const int k_Couple = 44;
|
||||
const int k_DeCouple = 45;
|
||||
const int k_ProgramQuit = 46;
|
||||
// const int k_ProgramPause= 47;
|
||||
const int k_ProgramHelp = 48;
|
||||
*/
|
||||
doortoggleleft,
|
||||
doortoggleright,
|
||||
departureannounce,
|
||||
doorlocktoggle,
|
||||
pantographcompressorvalvetoggle,
|
||||
pantographcompressoractivate,
|
||||
pantographtogglefront,
|
||||
pantographtogglerear,
|
||||
pantographlowerall,
|
||||
heatingtoggle,
|
||||
/*
|
||||
// const int k_FreeFlyMode= 59;
|
||||
*/
|
||||
headlighttoggleleft,
|
||||
headlighttoggleright,
|
||||
headlighttoggleupper,
|
||||
redmarkertoggleleft,
|
||||
redmarkertoggleright,
|
||||
headlighttogglerearleft,
|
||||
headlighttogglerearright,
|
||||
headlighttogglerearupper,
|
||||
redmarkertogglerearleft,
|
||||
redmarkertogglerearright,
|
||||
headlightsdimtoggle,
|
||||
motorconnectorsopen,
|
||||
motordisconnect,
|
||||
interiorlighttoggle,
|
||||
interiorlightdimtoggle,
|
||||
instrumentlighttoggle,
|
||||
/*
|
||||
const int k_Univ1 = 66;
|
||||
const int k_Univ2 = 67;
|
||||
const int k_Univ3 = 68;
|
||||
const int k_Univ4 = 69;
|
||||
const int k_EndSign = 70;
|
||||
const int k_Active = 71;
|
||||
*/
|
||||
batterytoggle
|
||||
/*
|
||||
const int k_WalkMode = 73;
|
||||
*/
|
||||
};
|
||||
|
||||
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
|
||||
consist = 0x4000,
|
||||
unit = 0x8000,
|
||||
*/
|
||||
// values are combined with object id. 0xffff objects of each type should be quite enough ("for everyone")
|
||||
vehicle = 0x10000,
|
||||
signal = 0x20000,
|
||||
entity = 0x40000
|
||||
};
|
||||
|
||||
struct command_description {
|
||||
|
||||
std::string name;
|
||||
command_target target;
|
||||
};
|
||||
|
||||
typedef std::vector<command_description> commanddescription_sequence;
|
||||
|
||||
struct command_data {
|
||||
|
||||
user_command command;
|
||||
int action; // press, repeat or release
|
||||
std::uint64_t param1;
|
||||
std::uint64_t param2;
|
||||
double time_delta;
|
||||
};
|
||||
|
||||
// command_queues: collects and holds commands from input sources, for processing by their intended recipients
|
||||
// NOTE: this won't scale well.
|
||||
// TODO: turn it into a dispatcher and build individual command sequences into the items, where they can be examined without lookups
|
||||
|
||||
class command_queue {
|
||||
|
||||
public:
|
||||
// methods
|
||||
// posts specified command for specified recipient
|
||||
void
|
||||
push( command_data const &Command, std::size_t const Recipient );
|
||||
// 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 );
|
||||
|
||||
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;
|
||||
|
||||
};
|
||||
|
||||
// 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 {
|
||||
|
||||
extern command_queue Commands;
|
||||
// TODO: add name to command map, and wrap these two into helper object
|
||||
extern commanddescription_sequence Commands_descriptions;
|
||||
|
||||
}
|
||||
|
||||
// command_relay: composite class component, passes specified command to appropriate command stack
|
||||
|
||||
class command_relay {
|
||||
|
||||
public:
|
||||
// constructors
|
||||
// methods
|
||||
// posts specified command for the specified recipient
|
||||
// TODO: replace uint16_t with recipient handle, based on item id
|
||||
void
|
||||
post( user_command const Command, std::uint64_t const Param1, std::uint64_t const Param2, int const Action, std::uint16_t const Recipient ) const;
|
||||
private:
|
||||
// types
|
||||
// members
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
353
gamepadinput.cpp
Normal file
353
gamepadinput.cpp
Normal file
@@ -0,0 +1,353 @@
|
||||
/*
|
||||
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/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "gamepadinput.h"
|
||||
#include "logs.h"
|
||||
#include "timer.h"
|
||||
#include "usefull.h"
|
||||
|
||||
glm::vec2 circle_to_square( glm::vec2 const &Point, int const Roundness = 0 ) {
|
||||
|
||||
// Determine the theta angle
|
||||
auto angle = std::atan2( Point.x, Point.y ) + M_PI;
|
||||
|
||||
glm::vec2 squared;
|
||||
// Scale according to which wall we're clamping to
|
||||
// X+ wall
|
||||
if( angle <= M_PI_4 || angle > 7 * M_PI_4 )
|
||||
squared = Point * (float)( 1.0 / std::cos( angle ) );
|
||||
// Y+ wall
|
||||
else if( angle > M_PI_4 && angle <= 3 * M_PI_4 )
|
||||
squared = Point * (float)( 1.0 / std::sin( angle ) );
|
||||
// X- wall
|
||||
else if( angle > 3 * M_PI_4 && angle <= 5 * M_PI_4 )
|
||||
squared = Point * (float)( -1.0 / std::cos( angle ) );
|
||||
// Y- wall
|
||||
else if( angle > 5 * M_PI_4 && angle <= 7 * M_PI_4 )
|
||||
squared = Point * (float)( -1.0 / std::sin( angle ) );
|
||||
|
||||
// Early-out for a perfect square output
|
||||
if( Roundness == 0 )
|
||||
return squared;
|
||||
|
||||
// Find the inner-roundness scaling factor and LERP
|
||||
auto const length = glm::length( Point );
|
||||
auto const factor = std::pow( length, Roundness );
|
||||
return interpolate( Point, squared, factor );
|
||||
}
|
||||
|
||||
gamepad_input::gamepad_input() {
|
||||
|
||||
m_modecommands = {
|
||||
|
||||
{ user_command::mastercontrollerincrease, user_command::mastercontrollerdecrease },
|
||||
{ user_command::trainbrakedecrease, user_command::trainbrakeincrease },
|
||||
{ user_command::secondcontrollerincrease, user_command::secondcontrollerdecrease },
|
||||
{ user_command::independentbrakedecrease, user_command::independentbrakeincrease }
|
||||
};
|
||||
}
|
||||
|
||||
bool
|
||||
gamepad_input::init() {
|
||||
|
||||
// NOTE: we're only checking for joystick_1 and rely for it to stay connected throughout.
|
||||
// not exactly flexible, but for quick hack it'll do
|
||||
auto const name = glfwGetJoystickName( GLFW_JOYSTICK_1 );
|
||||
if( name != nullptr ) {
|
||||
WriteLog( "Connected gamepad: " + std::string( name ) );
|
||||
m_deviceid = GLFW_JOYSTICK_1;
|
||||
}
|
||||
else {
|
||||
// no joystick,
|
||||
WriteLog( "No gamepad detected" );
|
||||
m_axes.clear();
|
||||
m_buttons.clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
int count;
|
||||
|
||||
glfwGetJoystickAxes( m_deviceid, &count );
|
||||
m_axes.resize( count );
|
||||
|
||||
glfwGetJoystickButtons( m_deviceid, &count );
|
||||
m_buttons.resize( count );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// checks state of the controls and sends issued commands
|
||||
void
|
||||
gamepad_input::poll() {
|
||||
|
||||
if( m_deviceid == -1 ) {
|
||||
// if there's no gamepad we can skip the rest
|
||||
return;
|
||||
}
|
||||
|
||||
int count; std::size_t idx = 0;
|
||||
// poll button state
|
||||
auto const buttons = glfwGetJoystickButtons( m_deviceid, &count );
|
||||
if( count ) { // safety check in case joystick gets pulled out
|
||||
for( auto &button : m_buttons ) {
|
||||
|
||||
if( button != buttons[ idx ] ) {
|
||||
// button pressed or released, both are important
|
||||
on_button(
|
||||
static_cast<gamepad_button>( idx ),
|
||||
( buttons[ idx ] == 1 ?
|
||||
GLFW_PRESS :
|
||||
GLFW_RELEASE ) );
|
||||
}
|
||||
else {
|
||||
// otherwise we only pass info about button being held down
|
||||
if( button == 1 ) {
|
||||
|
||||
on_button(
|
||||
static_cast<gamepad_button>( idx ),
|
||||
GLFW_REPEAT );
|
||||
}
|
||||
}
|
||||
button = buttons[ idx ];
|
||||
++idx;
|
||||
}
|
||||
}
|
||||
|
||||
// poll axes state
|
||||
idx = 0;
|
||||
glm::vec2 leftstick, rightstick, triggers;
|
||||
auto const axes = glfwGetJoystickAxes( m_deviceid, &count );
|
||||
if( count ) {
|
||||
// safety check in case joystick gets pulled out
|
||||
if( count >= 2 ) {
|
||||
leftstick = glm::vec2(
|
||||
( std::abs( axes[ gamepad_axes::leftstick_x ] ) > m_deadzone ?
|
||||
axes[ gamepad_axes::leftstick_x ] :
|
||||
0.0f ),
|
||||
( std::abs( axes[ gamepad_axes::leftstick_y ] ) > m_deadzone ?
|
||||
axes[ gamepad_axes::leftstick_y ] :
|
||||
0.0f ) );
|
||||
}
|
||||
if( count >= 4 ) {
|
||||
rightstick = glm::vec2(
|
||||
( std::abs( axes[ gamepad_axes::rightstick_x ] ) > m_deadzone ?
|
||||
axes[ gamepad_axes::rightstick_x ] :
|
||||
0.0f ),
|
||||
( std::abs( axes[ gamepad_axes::rightstick_y ] ) > m_deadzone ?
|
||||
axes[ gamepad_axes::rightstick_y ] :
|
||||
0.0f ) );
|
||||
}
|
||||
if( count >= 6 ) {
|
||||
triggers = glm::vec2(
|
||||
( axes[ gamepad_axes::lefttrigger ] > m_deadzone ?
|
||||
axes[ gamepad_axes::lefttrigger ] :
|
||||
0.0f ),
|
||||
( axes[ gamepad_axes::righttrigger ] > m_deadzone ?
|
||||
axes[ gamepad_axes::righttrigger ] :
|
||||
0.0f ) );
|
||||
}
|
||||
}
|
||||
process_axes( leftstick, rightstick, triggers );
|
||||
}
|
||||
|
||||
void
|
||||
gamepad_input::on_button( gamepad_button const Button, int const Action ) {
|
||||
|
||||
switch( Button ) {
|
||||
// NOTE: this is rigid coupling, down the road we should support more flexible binding of functions with buttons
|
||||
case gamepad_button::a:
|
||||
case gamepad_button::b:
|
||||
case gamepad_button::x:
|
||||
case gamepad_button::y: {
|
||||
|
||||
if( Action == GLFW_RELEASE ) {
|
||||
// TODO: send GLFW_RELEASE for whatever command could be issued by the mode active until now
|
||||
// if the button was released the stick switches to control the movement
|
||||
m_mode = control_mode::entity;
|
||||
// zero the stick and the accumulator so the input won't bleed between modes
|
||||
m_leftstick = glm::vec2();
|
||||
m_modeaccumulator = 0.0f;
|
||||
}
|
||||
else {
|
||||
// otherwise set control mode to match pressed button
|
||||
m_mode = static_cast<control_mode>( Button );
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gamepad_input::process_axes( glm::vec2 Leftstick, glm::vec2 const &Rightstick, glm::vec2 const &Triggers ) {
|
||||
|
||||
// right stick, look around
|
||||
if( ( Rightstick.x != 0.0f ) || ( Rightstick.y != 0.0f ) ) {
|
||||
// TODO: make toggles for the axis flip
|
||||
auto const deltatime = Timer::GetDeltaRenderTime() * 60.0;
|
||||
double const turnx = Rightstick.x * 10.0 * deltatime;
|
||||
double const turny = -Rightstick.y * 10.0 * deltatime;
|
||||
m_relay.post(
|
||||
user_command::viewturn,
|
||||
reinterpret_cast<std::uint64_t const &>( turnx ),
|
||||
reinterpret_cast<std::uint64_t const &>( turny ),
|
||||
GLFW_PRESS,
|
||||
// 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
|
||||
0 );
|
||||
}
|
||||
|
||||
// left stick, either movement or controls, depending on currently active mode
|
||||
if( m_mode == control_mode::entity ) {
|
||||
|
||||
if( ( Leftstick.x != 0.0 || Leftstick.y != 0.0 )
|
||||
|| ( m_leftstick.x != 0.0 || m_leftstick.y != 0.0 ) ) {
|
||||
double const movex = static_cast<double>( Leftstick.x );
|
||||
double const movez = static_cast<double>( Leftstick.y );
|
||||
m_relay.post(
|
||||
user_command::movevector,
|
||||
reinterpret_cast<std::uint64_t const &>( movex ),
|
||||
reinterpret_cast<std::uint64_t const &>( movez ),
|
||||
GLFW_PRESS,
|
||||
0 );
|
||||
}
|
||||
}
|
||||
else {
|
||||
// vehicle control modes
|
||||
process_mode( Leftstick.y, 0 );
|
||||
}
|
||||
|
||||
m_rightstick = Rightstick;
|
||||
m_leftstick = Leftstick;
|
||||
m_triggers = Triggers;
|
||||
}
|
||||
|
||||
void
|
||||
gamepad_input::process_axis( float const Value, float const Previousvalue, float const Multiplier, user_command Command, std::uint16_t const Recipient ) {
|
||||
|
||||
process_axis( Value, Previousvalue, Multiplier, Command, Command, Recipient );
|
||||
}
|
||||
|
||||
void
|
||||
gamepad_input::process_axis( float const Value, float const Previousvalue, float const Multiplier, user_command Command1, user_command Command2, std::uint16_t const Recipient ) {
|
||||
|
||||
user_command command{ Command1 };
|
||||
if( Value * Multiplier > 0.9 ) {
|
||||
command = Command2;
|
||||
}
|
||||
|
||||
if( Value * Multiplier > 0.0f ) {
|
||||
|
||||
m_relay.post(
|
||||
command,
|
||||
0, 0,
|
||||
GLFW_PRESS,
|
||||
Recipient
|
||||
);
|
||||
}
|
||||
else {
|
||||
// if we had movement before but not now, report this as 'button' release
|
||||
if( Previousvalue != 0.0f ) {
|
||||
m_relay.post(
|
||||
command, // doesn't matter which movement 'mode' we report
|
||||
0, 0,
|
||||
GLFW_RELEASE,
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gamepad_input::process_mode( float const Value, std::uint16_t const Recipient ) {
|
||||
|
||||
// TODO: separate multiplier for each mode, to allow different, customizable sensitivity for each control
|
||||
auto const deltatime = Timer::GetDeltaTime() * 15.0;
|
||||
auto const &lookup = m_modecommands.at( static_cast<size_t>( m_mode ) );
|
||||
|
||||
if( Value >= 0.0f ) {
|
||||
if( m_modeaccumulator < 0.0f ) {
|
||||
// reset accumulator if we're going in the other direction i.e. issuing opposite control
|
||||
// this also means we should indicate the previous command no longer applies
|
||||
// (normally it's handled when the stick enters dead zone, but it's possible there's no actual dead zone)
|
||||
m_relay.post(
|
||||
lookup.second,
|
||||
0, 0,
|
||||
GLFW_RELEASE,
|
||||
Recipient );
|
||||
m_modeaccumulator = 0.0f;
|
||||
}
|
||||
if( Value > m_deadzone ) {
|
||||
m_modeaccumulator += ( Value - m_deadzone ) / ( 1.0 - m_deadzone ) * deltatime;
|
||||
// we're making sure there's always a positive charge left in the accumulator,
|
||||
// to more reliably decect when the stick goes from active to dead zone, below
|
||||
while( m_modeaccumulator > 1.0f ) {
|
||||
// send commands if the accumulator(s) was filled
|
||||
m_relay.post(
|
||||
lookup.first,
|
||||
0, 0,
|
||||
GLFW_PRESS,
|
||||
Recipient );
|
||||
m_modeaccumulator -= 1.0f;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if the accumulator isn't empty it's an indicator the stick moved from active to neutral zone
|
||||
// indicate it with proper RELEASE command
|
||||
m_relay.post(
|
||||
lookup.first,
|
||||
0, 0,
|
||||
GLFW_RELEASE,
|
||||
Recipient );
|
||||
m_modeaccumulator = 0.0f;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if( m_modeaccumulator > 0.0f ) {
|
||||
// reset accumulator if we're going in the other direction i.e. issuing opposite control
|
||||
// this also means we should indicate the previous command no longer applies
|
||||
// (normally it's handled when the stick enters dead zone, but it's possible there's no actual dead zone)
|
||||
m_relay.post(
|
||||
lookup.first,
|
||||
0, 0,
|
||||
GLFW_RELEASE,
|
||||
Recipient );
|
||||
m_modeaccumulator = 0.0f;
|
||||
}
|
||||
if( Value < m_deadzone ) {
|
||||
m_modeaccumulator += ( Value + m_deadzone ) / ( 1.0 - m_deadzone ) * deltatime;
|
||||
// we're making sure there's always a negative charge left in the accumulator,
|
||||
// to more reliably decect when the stick goes from active to dead zone, below
|
||||
while( m_modeaccumulator < -1.0f ) {
|
||||
// send commands if the accumulator(s) was filled
|
||||
m_relay.post(
|
||||
lookup.second,
|
||||
0, 0,
|
||||
GLFW_PRESS,
|
||||
Recipient );
|
||||
m_modeaccumulator += 1.0f;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if the accumulator isn't empty it's an indicator the stick moved from active to neutral zone
|
||||
// indicate it with proper RELEASE command
|
||||
m_relay.post(
|
||||
lookup.second,
|
||||
0, 0,
|
||||
GLFW_RELEASE,
|
||||
Recipient );
|
||||
m_modeaccumulator = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
86
gamepadinput.h
Normal file
86
gamepadinput.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
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 <vector>
|
||||
#include "command.h"
|
||||
|
||||
class gamepad_input {
|
||||
|
||||
public:
|
||||
// constructors
|
||||
gamepad_input();
|
||||
|
||||
// methods
|
||||
// checks state of the controls and sends issued commands
|
||||
bool
|
||||
init();
|
||||
void
|
||||
poll();
|
||||
|
||||
private:
|
||||
// types
|
||||
enum gamepad_button {
|
||||
a,
|
||||
b,
|
||||
x,
|
||||
y,
|
||||
left_shoulder,
|
||||
right_shoulder,
|
||||
back,
|
||||
start,
|
||||
left_sticker,
|
||||
right_sticker,
|
||||
dpad_up,
|
||||
dpad_right,
|
||||
dpad_down,
|
||||
dpad_left
|
||||
};
|
||||
enum gamepad_axes {
|
||||
leftstick_x,
|
||||
leftstick_y,
|
||||
rightstick_x,
|
||||
rightstick_y,
|
||||
lefttrigger,
|
||||
righttrigger
|
||||
};
|
||||
enum class control_mode {
|
||||
entity = -1,
|
||||
vehicle_mastercontroller,
|
||||
vehicle_trainbrake,
|
||||
vehicle_secondarycontroller,
|
||||
vehicle_independentbrake
|
||||
};
|
||||
typedef std::vector<float> float_sequence;
|
||||
typedef std::vector<char> char_sequence;
|
||||
typedef std::vector< std::pair< user_command, user_command > > commandpair_sequence;
|
||||
|
||||
// methods
|
||||
void on_button( gamepad_button const Button, int const Action );
|
||||
void process_axes( glm::vec2 Leftstick, glm::vec2 const &Rightstick, glm::vec2 const &Triggers );
|
||||
void process_axis( float const Value, float const Previousvalue, float const Multiplier, user_command Command, std::uint16_t const Recipient );
|
||||
void process_axis( float const Value, float const Previousvalue, float const Multiplier, user_command Command1, user_command Command2, /*user_command Command3,*/ std::uint16_t const Recipient );
|
||||
void process_mode( float const Value, std::uint16_t const Recipient );
|
||||
|
||||
// members
|
||||
command_relay m_relay;
|
||||
float_sequence m_axes;
|
||||
char_sequence m_buttons;
|
||||
int m_deviceid{ -1 };
|
||||
control_mode m_mode{ control_mode::entity };
|
||||
commandpair_sequence m_modecommands; // sets of commands issued depending on the active control mode
|
||||
float m_deadzone{ 0.15f }; // TODO: allow to configure this
|
||||
glm::vec2 m_leftstick;
|
||||
glm::vec2 m_rightstick;
|
||||
glm::vec2 m_triggers;
|
||||
double m_modeaccumulator; // used to throttle command input rate for vehicle controls
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
496
keyboardinput.cpp
Normal file
496
keyboardinput.cpp
Normal file
@@ -0,0 +1,496 @@
|
||||
/*
|
||||
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/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "keyboardinput.h"
|
||||
#include "logs.h"
|
||||
#include "parser.h"
|
||||
|
||||
bool
|
||||
keyboard_input::recall_bindings() {
|
||||
|
||||
// build helper translation tables
|
||||
std::unordered_map<std::string, user_command> nametocommandmap;
|
||||
std::size_t commandid = 0;
|
||||
for( auto const &description : simulation::Commands_descriptions ) {
|
||||
nametocommandmap.emplace(
|
||||
description.name,
|
||||
static_cast<user_command>( commandid ) );
|
||||
++commandid;
|
||||
}
|
||||
std::unordered_map<std::string, int> nametokeymap = {
|
||||
{ "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 },
|
||||
{ "p", GLFW_KEY_P }, { "q", GLFW_KEY_Q }, { "r", GLFW_KEY_R }, { "s", GLFW_KEY_S }, { "t", GLFW_KEY_T },
|
||||
{ "u", GLFW_KEY_U }, { "v", GLFW_KEY_V }, { "w", GLFW_KEY_W }, { "x", GLFW_KEY_X }, { "y", GLFW_KEY_Y }, { "z", GLFW_KEY_Z },
|
||||
{ "-", GLFW_KEY_MINUS }, { "=", GLFW_KEY_EQUAL }, { "backspace", GLFW_KEY_BACKSPACE },
|
||||
{ "[", GLFW_KEY_LEFT_BRACKET }, { "]", GLFW_KEY_RIGHT_BRACKET }, { "\\", GLFW_KEY_BACKSLASH },
|
||||
{ ";", GLFW_KEY_SEMICOLON }, { "'", GLFW_KEY_APOSTROPHE }, { "enter", GLFW_KEY_ENTER },
|
||||
{ ",", GLFW_KEY_COMMA }, { ".", GLFW_KEY_PERIOD }, { "/", GLFW_KEY_SLASH },
|
||||
{ "space", GLFW_KEY_SPACE },
|
||||
// numpad block
|
||||
{ "num_/", GLFW_KEY_KP_DIVIDE }, { "num_*", GLFW_KEY_KP_MULTIPLY }, { "num_-", GLFW_KEY_KP_SUBTRACT },
|
||||
{ "num_7", GLFW_KEY_KP_7 }, { "num_8", GLFW_KEY_KP_8 }, { "num_9", GLFW_KEY_KP_9 }, { "num_+", GLFW_KEY_KP_ADD },
|
||||
{ "num_4", GLFW_KEY_KP_4 }, { "num_5", GLFW_KEY_KP_5 }, { "num_6", GLFW_KEY_KP_6 },
|
||||
{ "num_1", GLFW_KEY_KP_1 }, { "num_2", GLFW_KEY_KP_2 }, { "num_3", GLFW_KEY_KP_3 }, { "num_enter", GLFW_KEY_KP_ENTER },
|
||||
{ "num_0", GLFW_KEY_KP_0 }, { "num_.", GLFW_KEY_KP_DECIMAL }
|
||||
};
|
||||
|
||||
cParser bindingparser( "eu07_input-keyboard.ini", cParser::buffer_FILE );
|
||||
if( false == bindingparser.ok() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while( true == bindingparser.getTokens( 1, true, "\n" ) ) {
|
||||
|
||||
std::string bindingentry;
|
||||
bindingparser >> bindingentry;
|
||||
cParser entryparser( bindingentry );
|
||||
if( true == entryparser.getTokens( 1, true, "\n\r\t " ) ) {
|
||||
|
||||
std::string commandname;
|
||||
entryparser >> commandname;
|
||||
|
||||
auto const lookup = nametocommandmap.find( commandname );
|
||||
if( lookup == nametocommandmap.end() ) {
|
||||
|
||||
WriteLog( "Keyboard binding defined for unknown command, \"" + commandname + "\"" );
|
||||
}
|
||||
else {
|
||||
int binding{ 0 };
|
||||
while( entryparser.getTokens( 1, true, "\n\r\t " ) ) {
|
||||
|
||||
std::string bindingkeyname;
|
||||
entryparser >> bindingkeyname;
|
||||
|
||||
if( bindingkeyname == "shift" ) { binding |= keymodifier::shift; }
|
||||
else if( bindingkeyname == "ctrl" ) { binding |= keymodifier::control; }
|
||||
else {
|
||||
// regular key, convert it to glfw key code
|
||||
auto const keylookup = nametokeymap.find( bindingkeyname );
|
||||
if( keylookup == nametokeymap.end() ) {
|
||||
|
||||
WriteLog( "Keyboard binding included unrecognized key, \"" + bindingkeyname + "\"" );
|
||||
}
|
||||
else {
|
||||
// replace any existing binding, preserve modifiers
|
||||
// (protection from cases where there's more than one key listed in the entry)
|
||||
binding = keylookup->second | ( binding & 0xffff0000 );
|
||||
}
|
||||
}
|
||||
|
||||
if( ( binding & 0xffff ) != 0 ) {
|
||||
m_commands.at( static_cast<std::size_t>( lookup->second ) ).binding = binding;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bind();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
keyboard_input::key( int const Key, int const Action ) {
|
||||
|
||||
bool modifier( false );
|
||||
|
||||
if( ( Key == GLFW_KEY_LEFT_SHIFT ) || ( Key == GLFW_KEY_RIGHT_SHIFT ) ) {
|
||||
// update internal state, but don't bother passing these
|
||||
m_shift =
|
||||
( Action == GLFW_RELEASE ?
|
||||
false :
|
||||
true );
|
||||
modifier = true;
|
||||
// whenever shift key is used it may affect currently pressed movement keys, so check and update these
|
||||
}
|
||||
if( ( Key == GLFW_KEY_LEFT_CONTROL ) || ( Key == GLFW_KEY_RIGHT_CONTROL ) ) {
|
||||
// update internal state, but don't bother passing these
|
||||
m_ctrl =
|
||||
( Action == GLFW_RELEASE ?
|
||||
false :
|
||||
true );
|
||||
modifier = true;
|
||||
}
|
||||
if( ( Key == GLFW_KEY_LEFT_ALT ) || ( Key == GLFW_KEY_RIGHT_ALT ) ) {
|
||||
// currently we have no interest in these whatsoever
|
||||
return false;
|
||||
}
|
||||
|
||||
if( true == update_movement( Key, Action ) ) {
|
||||
// if the received key was one of movement keys, it's been handled and we don't need to bother further
|
||||
return true;
|
||||
}
|
||||
|
||||
// store key state
|
||||
if( Key != -1 ) {
|
||||
m_keys[ Key ] = Action;
|
||||
}
|
||||
|
||||
// include active modifiers for currently pressed key, except if the key is a modifier itself
|
||||
auto const key =
|
||||
Key
|
||||
| ( modifier ? 0 : ( m_shift ? keymodifier::shift : 0 ) )
|
||||
| ( modifier ? 0 : ( m_ctrl ? keymodifier::control : 0 ) );
|
||||
|
||||
auto const lookup = m_bindings.find( key );
|
||||
if( lookup == m_bindings.end() ) {
|
||||
// no binding for this key
|
||||
return false;
|
||||
}
|
||||
// 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( lookup->second, 0, 0, Action, 0 );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
keyboard_input::mouse( double Mousex, double Mousey ) {
|
||||
|
||||
m_relay.post(
|
||||
user_command::viewturn,
|
||||
reinterpret_cast<std::uint64_t const &>( Mousex ),
|
||||
reinterpret_cast<std::uint64_t const &>( Mousey ),
|
||||
GLFW_PRESS,
|
||||
// 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
|
||||
0 );
|
||||
}
|
||||
|
||||
void
|
||||
keyboard_input::default_bindings() {
|
||||
|
||||
m_commands = {
|
||||
// mastercontrollerincrease
|
||||
{ GLFW_KEY_KP_ADD },
|
||||
// mastercontrollerincreasefast
|
||||
{ GLFW_KEY_KP_ADD | keymodifier::shift },
|
||||
// mastercontrollerdecrease
|
||||
{ GLFW_KEY_KP_SUBTRACT },
|
||||
// mastercontrollerdecreasefast
|
||||
{ GLFW_KEY_KP_SUBTRACT | keymodifier::shift },
|
||||
// secondcontrollerincrease
|
||||
{ GLFW_KEY_KP_DIVIDE },
|
||||
// secondcontrollerincreasefast
|
||||
{ GLFW_KEY_KP_DIVIDE | keymodifier::shift },
|
||||
// secondcontrollerdecrease
|
||||
{ GLFW_KEY_KP_MULTIPLY },
|
||||
// secondcontrollerdecreasefast
|
||||
{ GLFW_KEY_KP_MULTIPLY | keymodifier::shift },
|
||||
// mucurrentindicatorothersourceactivate
|
||||
{ GLFW_KEY_Z | keymodifier::shift },
|
||||
// independentbrakeincrease
|
||||
{ GLFW_KEY_KP_1 },
|
||||
// independentbrakeincreasefast
|
||||
{ GLFW_KEY_KP_1 | keymodifier::shift },
|
||||
// independentbrakedecrease
|
||||
{ GLFW_KEY_KP_7 },
|
||||
// independentbrakedecreasefast
|
||||
{ GLFW_KEY_KP_7 | keymodifier::shift },
|
||||
// independentbrakebailoff
|
||||
{ GLFW_KEY_KP_4 },
|
||||
// trainbrakeincrease
|
||||
{ GLFW_KEY_KP_3 },
|
||||
// trainbrakedecrease
|
||||
{ GLFW_KEY_KP_9 },
|
||||
// trainbrakecharging
|
||||
{ GLFW_KEY_KP_DECIMAL },
|
||||
// trainbrakerelease
|
||||
{ GLFW_KEY_KP_6 },
|
||||
// trainbrakefirstservice
|
||||
{ GLFW_KEY_KP_8 },
|
||||
// trainbrakeservice
|
||||
{ GLFW_KEY_KP_5 },
|
||||
// trainbrakefullservice
|
||||
{ GLFW_KEY_KP_2 },
|
||||
// trainbrakeemergency
|
||||
{ GLFW_KEY_KP_0 },
|
||||
// wheelspinbrakeactivate,
|
||||
{ GLFW_KEY_KP_ENTER },
|
||||
// sandboxactivate,
|
||||
{ GLFW_KEY_S },
|
||||
// reverserincrease
|
||||
{ GLFW_KEY_D },
|
||||
// reverserdecrease
|
||||
{ GLFW_KEY_R },
|
||||
// linebreakertoggle
|
||||
{ GLFW_KEY_M },
|
||||
// convertertoggle
|
||||
{ GLFW_KEY_X },
|
||||
// converteroverloadrelayreset
|
||||
{ GLFW_KEY_N | keymodifier::control },
|
||||
// compressortoggle
|
||||
{ GLFW_KEY_C },
|
||||
// motoroverloadrelaythresholdtoggle
|
||||
{ GLFW_KEY_F },
|
||||
// motoroverloadrelayreset
|
||||
{ GLFW_KEY_N },
|
||||
// notchingrelaytoggle
|
||||
{ GLFW_KEY_G },
|
||||
// epbrakecontroltoggle
|
||||
{ GLFW_KEY_Z | keymodifier::control },
|
||||
// brakeactingspeedincrease
|
||||
{ GLFW_KEY_B | keymodifier::shift },
|
||||
// brakeactingspeeddecrease
|
||||
{ GLFW_KEY_B },
|
||||
// mubrakingindicatortoggle
|
||||
{ GLFW_KEY_L | keymodifier::shift },
|
||||
// alerteracknowledge
|
||||
{ GLFW_KEY_SPACE },
|
||||
// hornlowactivate
|
||||
{ GLFW_KEY_A },
|
||||
// hornhighactivate
|
||||
{ GLFW_KEY_A | keymodifier::shift },
|
||||
// radiotoggle
|
||||
{ GLFW_KEY_R | keymodifier::control },
|
||||
// viewturn
|
||||
{ -1 },
|
||||
// movevector
|
||||
{ -1 },
|
||||
// moveleft
|
||||
{ GLFW_KEY_LEFT },
|
||||
// moveright
|
||||
{ GLFW_KEY_RIGHT },
|
||||
// moveforward
|
||||
{ GLFW_KEY_UP },
|
||||
// moveback
|
||||
{ GLFW_KEY_DOWN },
|
||||
// moveup
|
||||
{ GLFW_KEY_PAGE_UP },
|
||||
// movedown
|
||||
{ GLFW_KEY_PAGE_DOWN },
|
||||
// moveleftfast
|
||||
{ -1 },
|
||||
// moverightfast
|
||||
{ -1 },
|
||||
// moveforwardfast
|
||||
{ -1 },
|
||||
// movebackfast
|
||||
{ -1 },
|
||||
// moveupfast
|
||||
{ -1 },
|
||||
// movedownfast
|
||||
{ -1 },
|
||||
/*
|
||||
const int k_CabForward = 42;
|
||||
const int k_CabBackward = 43;
|
||||
const int k_Couple = 44;
|
||||
const int k_DeCouple = 45;
|
||||
const int k_ProgramQuit = 46;
|
||||
// const int k_ProgramPause= 47;
|
||||
const int k_ProgramHelp = 48;
|
||||
*/
|
||||
// doortoggleleft
|
||||
{ GLFW_KEY_COMMA },
|
||||
// doortoggleright
|
||||
{ GLFW_KEY_PERIOD },
|
||||
// departureannounce
|
||||
{ GLFW_KEY_SLASH },
|
||||
// doorlocktoggle
|
||||
{ GLFW_KEY_S | keymodifier::shift },
|
||||
// pantographcompressorvalvetoggle
|
||||
{ GLFW_KEY_V | keymodifier::control },
|
||||
// pantographcompressoractivate
|
||||
{ GLFW_KEY_V | keymodifier::shift },
|
||||
// pantographtogglefront
|
||||
{ GLFW_KEY_P },
|
||||
// pantographtogglerear
|
||||
{ GLFW_KEY_O },
|
||||
// pantographlowerall
|
||||
{ GLFW_KEY_P | keymodifier::control },
|
||||
// heatingtoggle
|
||||
{ GLFW_KEY_H },
|
||||
/*
|
||||
// const int k_FreeFlyMode= 59;
|
||||
*/
|
||||
// headlighttoggleleft
|
||||
{ GLFW_KEY_Y },
|
||||
// headlighttoggleright
|
||||
{ GLFW_KEY_I },
|
||||
// headlighttoggleupper
|
||||
{ GLFW_KEY_U },
|
||||
// redmarkertoggleleft
|
||||
{ GLFW_KEY_Y | keymodifier::shift },
|
||||
// redmarkertoggleright
|
||||
{ GLFW_KEY_I | keymodifier::shift },
|
||||
// headlighttogglerearleft
|
||||
{ GLFW_KEY_Y | keymodifier::control },
|
||||
// headlighttogglerearright
|
||||
{ GLFW_KEY_I | keymodifier::control },
|
||||
// headlighttogglerearupper
|
||||
{ GLFW_KEY_U | keymodifier::control },
|
||||
// redmarkertogglerearleft
|
||||
{ GLFW_KEY_Y | keymodifier::control | keymodifier::shift },
|
||||
// redmarkertogglerearright
|
||||
{ GLFW_KEY_I | keymodifier::control | keymodifier::shift },
|
||||
// headlightsdimtoggle
|
||||
{ GLFW_KEY_L | keymodifier::control },
|
||||
// motorconnectorsopen
|
||||
{ GLFW_KEY_L },
|
||||
// motordisconnect
|
||||
{ GLFW_KEY_E | keymodifier::shift },
|
||||
// interiorlighttoggle
|
||||
{ GLFW_KEY_APOSTROPHE },
|
||||
// interiorlightdimtoggle
|
||||
{ GLFW_KEY_APOSTROPHE | keymodifier::control },
|
||||
// instrumentlighttoggle
|
||||
{ GLFW_KEY_SEMICOLON },
|
||||
/*
|
||||
const int k_Univ1 = 66;
|
||||
const int k_Univ2 = 67;
|
||||
const int k_Univ3 = 68;
|
||||
const int k_Univ4 = 69;
|
||||
const int k_EndSign = 70;
|
||||
const int k_Active = 71;
|
||||
*/
|
||||
// "batterytoggle"
|
||||
{ GLFW_KEY_J }
|
||||
/*
|
||||
const int k_WalkMode = 73;
|
||||
*/
|
||||
};
|
||||
|
||||
bind();
|
||||
}
|
||||
|
||||
void
|
||||
keyboard_input::bind() {
|
||||
|
||||
m_bindings.clear();
|
||||
|
||||
int commandcode{ 0 };
|
||||
for( auto const &command : m_commands ) {
|
||||
|
||||
if( command.binding != -1 ) {
|
||||
m_bindings.emplace(
|
||||
command.binding,
|
||||
static_cast<user_command>( commandcode ) );
|
||||
}
|
||||
++commandcode;
|
||||
}
|
||||
|
||||
// cache movement key bindings, so we can test them faster in the input loop
|
||||
m_bindingscache.forward = m_commands[ static_cast<std::size_t>( user_command::moveforward ) ].binding;
|
||||
m_bindingscache.back = m_commands[ static_cast<std::size_t>( user_command::moveback ) ].binding;
|
||||
m_bindingscache.left = m_commands[ static_cast<std::size_t>( user_command::moveleft ) ].binding;
|
||||
m_bindingscache.right = m_commands[ static_cast<std::size_t>( user_command::moveright ) ].binding;
|
||||
m_bindingscache.up = m_commands[ static_cast<std::size_t>( user_command::moveup ) ].binding;
|
||||
m_bindingscache.down = m_commands[ static_cast<std::size_t>( user_command::movedown ) ].binding;
|
||||
}
|
||||
|
||||
// NOTE: ugliest code ever, gg
|
||||
bool
|
||||
keyboard_input::update_movement( int const Key, int const Action ) {
|
||||
|
||||
bool shift =
|
||||
( ( Key == GLFW_KEY_LEFT_SHIFT )
|
||||
|| ( Key == GLFW_KEY_RIGHT_SHIFT ) );
|
||||
bool movementkey =
|
||||
( ( Key == m_bindingscache.forward )
|
||||
|| ( Key == m_bindingscache.back )
|
||||
|| ( Key == m_bindingscache.left )
|
||||
|| ( Key == m_bindingscache.right )
|
||||
|| ( Key == m_bindingscache.up )
|
||||
|| ( Key == m_bindingscache.down ) );
|
||||
|
||||
if( false == ( shift || movementkey ) ) { return false; }
|
||||
|
||||
if( false == shift ) {
|
||||
// TODO: pass correct entity id once the missing systems are in place
|
||||
if( Key == m_bindingscache.forward ) {
|
||||
m_keys[ Key ] = Action;
|
||||
m_relay.post(
|
||||
( m_shift ?
|
||||
user_command::moveforwardfast :
|
||||
user_command::moveforward ),
|
||||
0, 0,
|
||||
m_keys[ m_bindingscache.forward ],
|
||||
0 );
|
||||
return true;
|
||||
}
|
||||
else if( Key == m_bindingscache.back ) {
|
||||
m_keys[ Key ] = Action;
|
||||
m_relay.post(
|
||||
( m_shift ?
|
||||
user_command::movebackfast :
|
||||
user_command::moveback ),
|
||||
0, 0,
|
||||
m_keys[ m_bindingscache.back ],
|
||||
0 );
|
||||
return true;
|
||||
}
|
||||
else if( Key == m_bindingscache.left ) {
|
||||
m_keys[ Key ] = Action;
|
||||
m_relay.post(
|
||||
( m_shift ?
|
||||
user_command::moveleftfast :
|
||||
user_command::moveleft ),
|
||||
0, 0,
|
||||
m_keys[ m_bindingscache.left ],
|
||||
0 );
|
||||
return true;
|
||||
}
|
||||
else if( Key == m_bindingscache.right ) {
|
||||
m_keys[ Key ] = Action;
|
||||
m_relay.post(
|
||||
( m_shift ?
|
||||
user_command::moverightfast :
|
||||
user_command::moveright ),
|
||||
0, 0,
|
||||
m_keys[ m_bindingscache.right ],
|
||||
0 );
|
||||
return true;
|
||||
}
|
||||
else if( Key == m_bindingscache.up ) {
|
||||
m_keys[ Key ] = Action;
|
||||
m_relay.post(
|
||||
( m_shift ?
|
||||
user_command::moveupfast :
|
||||
user_command::moveup ),
|
||||
0, 0,
|
||||
m_keys[ m_bindingscache.up ],
|
||||
0 );
|
||||
return true;
|
||||
}
|
||||
else if( Key == m_bindingscache.down ) {
|
||||
m_keys[ Key ] = Action;
|
||||
m_relay.post(
|
||||
( m_shift ?
|
||||
user_command::movedownfast :
|
||||
user_command::movedown ),
|
||||
0, 0,
|
||||
m_keys[ m_bindingscache.down ],
|
||||
0 );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// if it's not the movement keys but one of shift keys, we might potentially need to update movement state
|
||||
if( m_keys[ Key ] == Action ) {
|
||||
// but not if it's just repeat
|
||||
return false;
|
||||
}
|
||||
// bit of recursion voodoo here, we fake relevant key presses so we don't have to duplicate the code from above
|
||||
if( m_keys[ m_bindingscache.forward ] != GLFW_RELEASE ) { update_movement( m_bindingscache.forward, m_keys[ m_bindingscache.forward ] ); }
|
||||
if( m_keys[ m_bindingscache.back ] != GLFW_RELEASE ) { update_movement( m_bindingscache.back, m_keys[ m_bindingscache.back ] ); }
|
||||
if( m_keys[ m_bindingscache.left ] != GLFW_RELEASE ) { update_movement( m_bindingscache.left, m_keys[ m_bindingscache.left ] ); }
|
||||
if( m_keys[ m_bindingscache.right ] != GLFW_RELEASE ) { update_movement( m_bindingscache.right, m_keys[ m_bindingscache.right ] ); }
|
||||
if( m_keys[ m_bindingscache.up ] != GLFW_RELEASE ) { update_movement( m_bindingscache.up, m_keys[ m_bindingscache.up ] ); }
|
||||
if( m_keys[ m_bindingscache.down ] != GLFW_RELEASE ) { update_movement( m_bindingscache.down, m_keys[ m_bindingscache.down ] ); }
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
76
keyboardinput.h
Normal file
76
keyboardinput.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
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 <unordered_map>
|
||||
#include <array>
|
||||
#include "command.h"
|
||||
|
||||
class keyboard_input {
|
||||
|
||||
public:
|
||||
// constructors
|
||||
keyboard_input() { default_bindings(); }
|
||||
|
||||
// methods
|
||||
bool
|
||||
init() { return recall_bindings(); }
|
||||
bool
|
||||
recall_bindings();
|
||||
bool
|
||||
key( int const Key, int const Action );
|
||||
void
|
||||
mouse( double const Mousex, double const Mousey );
|
||||
|
||||
private:
|
||||
// types
|
||||
enum keymodifier : int {
|
||||
|
||||
shift = 0x10000,
|
||||
control = 0x20000
|
||||
};
|
||||
|
||||
struct command_setup {
|
||||
|
||||
int binding;
|
||||
};
|
||||
|
||||
typedef std::vector<command_setup> commandsetup_sequence;
|
||||
typedef std::unordered_map<int, user_command> usercommand_map;
|
||||
|
||||
struct bindings_cache {
|
||||
|
||||
int forward{ -1 };
|
||||
int back{ -1 };
|
||||
int left{ -1 };
|
||||
int right{ -1 };
|
||||
int up{ -1 };
|
||||
int down{ -1 };
|
||||
};
|
||||
|
||||
// methods
|
||||
void
|
||||
default_bindings();
|
||||
void
|
||||
bind();
|
||||
bool
|
||||
update_movement( int const Key, int const Action );
|
||||
|
||||
// members
|
||||
commandsetup_sequence m_commands;
|
||||
usercommand_map m_bindings;
|
||||
command_relay m_relay;
|
||||
bool m_shift{ false };
|
||||
bool m_ctrl{ false };
|
||||
bindings_cache m_bindingscache;
|
||||
std::array<char, GLFW_KEY_LAST> m_keys;
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
@@ -57,8 +57,8 @@ light_array::update() {
|
||||
light.direction.z = -light.direction.z;
|
||||
}
|
||||
// determine intensity of this light set
|
||||
if( true == light.owner->MoverParameters->Battery ) {
|
||||
// with battery on, the intensity depends on the state of activated switches
|
||||
if( ( true == light.owner->MoverParameters->Battery ) || ( true == light.owner->MoverParameters->ConverterFlag ) ) {
|
||||
// with power on, the intensity depends on the state of activated switches
|
||||
auto const &lightbits = light.owner->iLights[ light.index ];
|
||||
light.count = 0 +
|
||||
( ( lightbits & 1 ) ? 1 : 0 ) +
|
||||
|
||||
6
moon.cpp
6
moon.cpp
@@ -116,7 +116,7 @@ void cMoon::move() {
|
||||
static double radtodeg = 57.295779513; // converts from radians to degrees
|
||||
static double degtorad = 0.0174532925; // converts from degrees to radians
|
||||
|
||||
SYSTEMTIME localtime = Simulation::Time.data(); // time for the calculation
|
||||
SYSTEMTIME localtime = simulation::Time.data(); // time for the calculation
|
||||
|
||||
if( m_observer.hour >= 0 ) { localtime.wHour = m_observer.hour; }
|
||||
if( m_observer.minute >= 0 ) { localtime.wMinute = m_observer.minute; }
|
||||
@@ -284,7 +284,7 @@ void cMoon::irradiance() {
|
||||
static double radtodeg = 57.295779513; // converts from radians to degrees
|
||||
static double degtorad = 0.0174532925; // converts from degrees to radians
|
||||
|
||||
m_body.dayang = ( Simulation::Time.year_day() - 1 ) * 360.0 / 365.0;
|
||||
m_body.dayang = ( simulation::Time.year_day() - 1 ) * 360.0 / 365.0;
|
||||
double sd = sin( degtorad * m_body.dayang ); // sine of the day angle
|
||||
double cd = cos( degtorad * m_body.dayang ); // cosine of the day angle or delination
|
||||
m_body.erv = 1.000110 + 0.034221*cd + 0.001280*sd;
|
||||
@@ -310,7 +310,7 @@ void
|
||||
cMoon::phase() {
|
||||
|
||||
// calculate moon's age in days from new moon
|
||||
float ip = normalize( ( Simulation::Time.julian_day() - 2451550.1f ) / 29.530588853f );
|
||||
float ip = normalize( ( simulation::Time.julian_day() - 2451550.1f ) / 29.530588853f );
|
||||
m_phase = ip * 29.53f;
|
||||
}
|
||||
|
||||
|
||||
@@ -282,7 +282,7 @@ bool
|
||||
opengl_renderer::Render( TGround *Ground ) {
|
||||
|
||||
glDisable( GL_BLEND );
|
||||
glAlphaFunc( GL_GREATER, 0.45f ); // im mniejsza wartość, tym większa ramka, domyślnie 0.1f
|
||||
glAlphaFunc( GL_GREATER, 0.50f ); // im mniejsza wartość, tym większa ramka, domyślnie 0.1f
|
||||
glEnable( GL_LIGHTING );
|
||||
glColor3f( 1.0f, 1.0f, 1.0f );
|
||||
|
||||
@@ -319,7 +319,7 @@ opengl_renderer::Render( TDynamicObject *Dynamic ) {
|
||||
|
||||
// setup
|
||||
TSubModel::iInstance = ( size_t )this; //żeby nie robić cudzych animacji
|
||||
double squaredistance = SquareMagnitude( Global::pCameraPosition - Dynamic->vPosition ) / Global::ZoomFactor;
|
||||
double squaredistance = SquareMagnitude( ( Global::pCameraPosition - Dynamic->vPosition ) / Global::ZoomFactor );
|
||||
Dynamic->ABuLittleUpdate( squaredistance ); // ustawianie zmiennych submodeli dla wspólnego modelu
|
||||
|
||||
::glPushMatrix();
|
||||
@@ -596,7 +596,7 @@ opengl_renderer::Render_Alpha( TDynamicObject *Dynamic ) {
|
||||
|
||||
// setup
|
||||
TSubModel::iInstance = ( size_t )this; //żeby nie robić cudzych animacji
|
||||
double squaredistance = SquareMagnitude( Global::pCameraPosition - Dynamic->vPosition ) / Global::ZoomFactor;
|
||||
double squaredistance = SquareMagnitude( ( Global::pCameraPosition - Dynamic->vPosition ) / Global::ZoomFactor );
|
||||
Dynamic->ABuLittleUpdate( squaredistance ); // ustawianie zmiennych submodeli dla wspólnego modelu
|
||||
|
||||
::glPushMatrix();
|
||||
|
||||
6
sun.cpp
6
sun.cpp
@@ -115,7 +115,7 @@ void cSun::move() {
|
||||
static double radtodeg = 57.295779513; // converts from radians to degrees
|
||||
static double degtorad = 0.0174532925; // converts from degrees to radians
|
||||
|
||||
SYSTEMTIME localtime = Simulation::Time.data(); // time for the calculation
|
||||
SYSTEMTIME localtime = simulation::Time.data(); // time for the calculation
|
||||
|
||||
if( m_observer.hour >= 0 ) { localtime.wHour = m_observer.hour; }
|
||||
if( m_observer.minute >= 0 ) { localtime.wMinute = m_observer.minute; }
|
||||
@@ -258,9 +258,9 @@ void cSun::irradiance() {
|
||||
static double degrad = 57.295779513; // converts from radians to degrees
|
||||
static double raddeg = 0.0174532925; // converts from degrees to radians
|
||||
|
||||
auto const &localtime = Simulation::Time.data(); // time for the calculation
|
||||
auto const &localtime = simulation::Time.data(); // time for the calculation
|
||||
|
||||
m_body.dayang = ( Simulation::Time.year_day() - 1 ) * 360.0 / 365.0;
|
||||
m_body.dayang = ( simulation::Time.year_day() - 1 ) * 360.0 / 365.0;
|
||||
double sd = sin( raddeg * m_body.dayang ); // sine of the day angle
|
||||
double cd = cos( raddeg * m_body.dayang ); // cosine of the day angle or delination
|
||||
m_body.erv = 1.000110 + 0.034221*cd + 0.001280*sd;
|
||||
|
||||
@@ -18,7 +18,7 @@ LONG CALLBACK unhandled_handler(::EXCEPTION_POINTERS* e)
|
||||
{
|
||||
auto nameEnd = name + ::GetModuleFileNameA(::GetModuleHandleA(0), name, MAX_PATH);
|
||||
::SYSTEMTIME t;
|
||||
::GetSystemTime(&t);
|
||||
::GetLocalTime(&t);
|
||||
wsprintfA(nameEnd - strlen(".exe"),
|
||||
"_crashdump_%4d%02d%02d_%02d%02d%02d.dmp",
|
||||
t.wYear, t.wMonth, t.wDay, t.wHour, t.wMinute, t.wSecond);
|
||||
|
||||
Reference in New Issue
Block a user