16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-19 12:19:18 +02:00

merge (with bugs)

This commit is contained in:
VB
2017-04-24 20:52:21 +02:00
40 changed files with 5449 additions and 2493 deletions

137
World.cpp
View File

@@ -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