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

build 170914. fix for car braking, sound and event updates refactored out of gfx renderer

This commit is contained in:
tmj-fstate
2017-09-15 04:14:12 +02:00
parent f6fa8ee09b
commit 6c69a5b8f1
7 changed files with 104 additions and 56 deletions

View File

@@ -1422,11 +1422,15 @@ void TController::TablePurger()
iLast = sSpeedTable.size() - 1;
};
void TController::TableSort()
{
void TController::TableSort() {
if( sSpeedTable.size() < 3 ) {
// we skip last slot and no point in checking if there's only one other entry
return;
}
TSpeedPos sp_temp = TSpeedPos(); // uzywany do przenoszenia
for (std::size_t i = 0; i < (iLast - 1) && iLast > 0; ++i)
{ // pętla tylko do dwóch pozycji od końca bo ostatniej nie modyfikujemy
for( std::size_t i = 0; i < ( iLast - 1 ); ++i ) {
// pętla tylko do dwóch pozycji od końca bo ostatniej nie modyfikujemy
if (sSpeedTable[i].fDist > sSpeedTable[i + 1].fDist)
{ // jesli pozycja wcześniejsza jest dalej to źle
sp_temp = sSpeedTable[i + 1];
@@ -4568,24 +4572,52 @@ TController::UpdateSituation(double dt) {
}
// koniec predkosci nastepnej
if( vel > VelDesired ) {
// jesli jedzie za szybko do AKTUALNEGO
if( VelDesired == 0.0 ) {
// jesli stoj, to hamuj, ale i tak juz za pozno :)
AccDesired = std::min( AccDesired, -0.85 ); // hamuj solidnie
}
else {
// try to estimate increase of current velocity before engaged brakes start working
// if it looks like we'll exceed maximum allowed speed start thinking about slight slowing down
if( ( vel + vel * ( 1.0 - fBrake_a0[ 0 ] ) * AbsAccS ) > ( VelDesired + fVelPlus ) ) {
// hamuj tak średnio
AccDesired = std::min( AccDesired, -0.25 );
// decisions based on current speed
if( mvOccupied->CategoryFlag == 1 ) {
// try to estimate increase of current velocity before engaged brakes start working
auto const speedestimate = vel + vel * ( 1.0 - fBrake_a0[ 0 ] ) * AbsAccS;
if( speedestimate > VelDesired ) {
// jesli jedzie za szybko do AKTUALNEGO
if( VelDesired == 0.0 ) {
// jesli stoj, to hamuj, ale i tak juz za pozno :)
AccDesired = std::min( AccDesired, -0.85 ); // hamuj solidnie
}
else {
// o 5 km/h to olej (zacznij luzować)
AccDesired = std::min(
AccDesired, // but don't override decceleration for VelNext
std::max( 0.0, AccPreferred ) );
if( speedestimate > ( VelDesired + fVelPlus ) ) {
// if it looks like we'll exceed maximum allowed speed start thinking about slight slowing down
AccDesired = std::min( AccDesired, -0.25 );
}
else {
// close enough to target to stop accelerating
AccDesired = std::min(
AccDesired, // but don't override decceleration for VelNext
interpolate( // ease off as you close to the target velocity
-0.06, AccPreferred,
clamp( speedestimate - vel, 0.0, fVelPlus ) / fVelPlus ) );
}
}
}
}
else {
// for cars the older version works better
if( vel > VelDesired ) {
// jesli jedzie za szybko do AKTUALNEGO
if( VelDesired == 0.0 ) {
// jesli stoj, to hamuj, ale i tak juz za pozno :)
AccDesired = std::min( AccDesired, -0.9 ); // hamuj solidnie
}
else {
// slow down, not full stop
if( vel > ( VelDesired + fVelPlus ) ) {
// hamuj tak średnio
AccDesired = std::min( AccDesired, -fBrake_a0[ 0 ] * 0.5 );
}
else {
// o 5 km/h to olej (zacznij luzować)
AccDesired = std::min(
AccDesired, // but don't override decceleration for VelNext
std::max( 0.0, AccPreferred ) );
}
}
}
}
@@ -4593,8 +4625,10 @@ TController::UpdateSituation(double dt) {
// last step sanity check, until the whole calculation is straightened out
AccDesired = std::min( AccDesired, AccPreferred );
// also take into account impact of gravity
AccDesired = clamp( AccDesired - fAccGravity, -0.9, 0.9 );
if( mvOccupied->CategoryFlag == 1 ) {
// also take into account impact of gravity
AccDesired = clamp( AccDesired - fAccGravity, -0.9, 0.9 );
}

View File

@@ -171,8 +171,8 @@ extern bool WriteLogFlag; // logowanie parametrów fizycznych
static const int BrakeAccTableSize = 20;
//----------------------------------------------------------------------------
class TController
{
class TController {
private: // obsługa tabelki prędkości (musi mieć możliwość odhaczania stacji w rozkładzie)
int iLast{ 0 }; // ostatnia wypełniona pozycja w tabeli <iFirst (modulo iSpeedTableSize)
int iTableDirection{ 0 }; // kierunek zapełnienia tabelki względem pojazdu z AI
@@ -183,7 +183,7 @@ class TController
std::size_t SemNextIndex{ std::size_t(-1) };
std::size_t SemNextStopIndex{ std::size_t( -1 ) };
double dMoveLen = 0.0; // odległość przejechana od ostatniego sprawdzenia tabelki
private: // parametry aktualnego składu
// parametry aktualnego składu
double fLength = 0.0; // długość składu (do wyciągania z ograniczeń)
double fMass = 0.0; // całkowita masa do liczenia stycznej składowej grawitacji
public:
@@ -191,11 +191,11 @@ public:
TEvent *eSignNext = nullptr; // sygnał zmieniający prędkość, do pokazania na [F2]
std::string asNextStop; // nazwa następnego punktu zatrzymania wg rozkładu
int iStationStart = 0; // numer pierwszej stacji pokazywanej na podglądzie rozkładu
private: // parametry sterowania pojazdem (stan, hamowanie)
// parametry sterowania pojazdem (stan, hamowanie)
private:
double fShuntVelocity = 40.0; // maksymalna prędkość manewrowania, zależy m.in. od składu // domyślna prędkość manewrowa
int iVehicles = 0; // ilość pojazdów w składzie
int iEngineActive = 0; // ABu: Czy silnik byl juz zalaczony; Ra: postęp w załączaniu
// vector3 vMechLoc; //pozycja pojazdu do liczenia odległości od semafora (?)
bool Psyche = false;
int iDrivigFlags = // flagi bitowe ruchu
moveStopPoint | // podjedź do W4 możliwie blisko

View File

@@ -3581,6 +3581,45 @@ TGround::Update_Lights() {
m_lights.update();
}
void
TGround::Update_Hidden() {
// rednerowanie globalnych (nie za często?)
for( TGroundNode *node = srGlobal.nRenderHidden; node; node = node->nNext3 ) {
node->RenderHidden();
}
// render events and sounds from sectors near enough to the viewer
auto const range = 2750.0; // audible range of 100 db sound
int const camerax = static_cast<int>( std::floor( Global::pCameraPosition.x / 1000.0 ) + iNumRects / 2 );
int const cameraz = static_cast<int>( std::floor( Global::pCameraPosition.z / 1000.0 ) + iNumRects / 2 );
int const segmentcount = 2 * static_cast<int>( std::ceil( range / 1000.0 ) );
int const originx = std::max( 0, camerax - segmentcount / 2 );
int const originz = std::max( 0, cameraz - segmentcount / 2 );
for( int column = originx; column <= originx + segmentcount; ++column ) {
for( int row = originz; row <= originz + segmentcount; ++row ) {
auto &cell = Rects[ column ][ row ];
for( int subcellcolumn = 0; subcellcolumn < iNumSubRects; ++subcellcolumn ) {
for( int subcellrow = 0; subcellrow < iNumSubRects; ++subcellrow ) {
auto subcell = cell.FastGetSubRect( subcellcolumn, subcellrow );
if( subcell == nullptr ) { continue; }
// renderowanie obiektów aktywnych a niewidocznych
for( auto node = subcell->nRenderHidden; node; node = node->nNext3 ) {
node->RenderHidden();
}
// jeszcze dźwięki pojazdów by się przydały, również niewidocznych
// TODO: move to sound renderer
subcell->RenderSounds();
}
}
}
}
}
// Winger 170204 - szukanie trakcji nad pantografami
bool TGround::GetTraction(TDynamicObject *model)
{ // aktualizacja drutu zasilającego dla każdego pantografu, żeby odczytać napięcie

View File

@@ -227,7 +227,7 @@ public:
return pSubRects + iRow * iNumSubRects + iCol; // zwrócenie właściwego
};
// pobranie wskaźnika do małego kwadratu, bez tworzenia jeśli nie ma
TSubRect * FastGetSubRect(int iCol, int iRow) {
TSubRect *FastGetSubRect(int iCol, int iRow) const {
return (
pSubRects ?
pSubRects + iRow * iNumSubRects + iCol :
@@ -287,6 +287,7 @@ class TGround
void UpdatePhys(double dt, int iter); // aktualizacja fizyki stałym krokiem
bool Update(double dt, int iter); // aktualizacja przesunięć zgodna z FPS
void Update_Lights(); // updates scene lights array
void Update_Hidden(); // updates invisible elements of the scene
bool AddToQuery(TEvent *Event, TDynamicObject *Node);
bool GetTraction(TDynamicObject *model);
bool CheckQuery();

View File

@@ -1047,6 +1047,7 @@ bool TWorld::Update()
Ground.CheckQuery();
Ground.Update_Hidden();
Ground.Update_Lights();
// render time routines follow:

View File

@@ -1344,19 +1344,6 @@ opengl_renderer::Render( TGround *Ground ) {
m_drawqueue.clear();
switch( m_renderpass.draw_mode ) {
case rendermode::color: {
// rednerowanie globalnych (nie za często?)
for( TGroundNode *node = Ground->srGlobal.nRenderHidden; node; node = node->nNext3 ) {
node->RenderHidden();
}
break;
}
default: {
break;
}
}
glm::vec3 const cameraposition { m_renderpass.camera.position() };
int const camerax = static_cast<int>( std::floor( cameraposition.x / 1000.0f ) + iNumRects / 2 );
int const cameraz = static_cast<int>( std::floor( cameraposition.z / 1000.0f ) + iNumRects / 2 );
@@ -1373,20 +1360,6 @@ opengl_renderer::Render( TGround *Ground ) {
for( int row = originz; row <= originz + segmentcount; ++row ) {
auto *cell = &Ground->Rects[ column ][ row ];
for( int subcellcolumn = 0; subcellcolumn < iNumSubRects; ++subcellcolumn ) {
for( int subcellrow = 0; subcellrow < iNumSubRects; ++subcellrow ) {
auto subcell = cell->FastGetSubRect( subcellcolumn, subcellrow );
if( subcell == nullptr ) { continue; }
// renderowanie obiektów aktywnych a niewidocznych
for( auto node = subcell->nRenderHidden; node; node = node->nNext3 ) {
node->RenderHidden();
}
// jeszcze dźwięki pojazdów by się przydały, również niewidocznych
subcell->RenderSounds();
}
}
if( m_renderpass.camera.visible( cell->m_area ) ) {
Render( cell );
}

View File

@@ -1,5 +1,5 @@
#pragma once
#define VERSION_MAJOR 17
#define VERSION_MINOR 913
#define VERSION_MINOR 914
#define VERSION_REVISION 0