mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
stl-based names class replacement, re-enabled cab camera shake, enhanced parser comment support, minor bug fixes.
This commit is contained in:
@@ -36,7 +36,9 @@ class TMtableTime; // czas dla danego posterunku
|
||||
};
|
||||
|
||||
class TController; // obiekt sterujący pociągiem (AI)
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
class TNames; // obiekt sortujący nazwy
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{ // binarne odpowiedniki komend w komórce pamięci
|
||||
|
||||
108
Ground.cpp
108
Ground.cpp
@@ -1308,8 +1308,9 @@ TGround::TGround()
|
||||
for( int i = 0; i < TP_LAST; ++i ) {
|
||||
nRootOfType[ i ] = nullptr; // zerowanie tablic wyszukiwania
|
||||
}
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
sTracks = new TNames(); // nazwy torów - na razie tak
|
||||
|
||||
#endif
|
||||
::SecureZeroMemory( TempConnectionType, sizeof( TempConnectionType ) );
|
||||
::SecureZeroMemory( pRendered, sizeof( pRendered ) );
|
||||
}
|
||||
@@ -1348,7 +1349,9 @@ void TGround::Free()
|
||||
iNumNodes = 0;
|
||||
// RootNode=NULL;
|
||||
nRootDynamic = NULL;
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
delete sTracks;
|
||||
#endif
|
||||
}
|
||||
|
||||
TGroundNode * TGround::DynamicFindAny(std::string asNameToFind)
|
||||
@@ -1381,7 +1384,38 @@ TGroundNode * TGround::FindGroundNode(std::string asNameToFind, TGroundNodeType
|
||||
{ // wyszukiwanie obiektu o podanej nazwie i konkretnym typie
|
||||
if ((iNodeType == TP_TRACK) || (iNodeType == TP_MEMCELL) || (iNodeType == TP_MODEL))
|
||||
{ // wyszukiwanie w drzewie binarnym
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
return (TGroundNode *)sTracks->Find(iNodeType, asNameToFind.c_str());
|
||||
#else
|
||||
/*
|
||||
switch( iNodeType ) {
|
||||
|
||||
case TP_TRACK: {
|
||||
auto const lookup = m_trackmap.find( asNameToFind );
|
||||
return
|
||||
lookup != m_trackmap.end() ?
|
||||
lookup->second :
|
||||
nullptr;
|
||||
}
|
||||
case TP_MODEL: {
|
||||
auto const lookup = m_modelmap.find( asNameToFind );
|
||||
return
|
||||
lookup != m_modelmap.end() ?
|
||||
lookup->second :
|
||||
nullptr;
|
||||
}
|
||||
case TP_MEMCELL: {
|
||||
auto const lookup = m_memcellmap.find( asNameToFind );
|
||||
return
|
||||
lookup != m_memcellmap.end() ?
|
||||
lookup->second :
|
||||
nullptr;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
*/
|
||||
return m_trackmap.Find( iNodeType, asNameToFind );
|
||||
#endif
|
||||
}
|
||||
// standardowe wyszukiwanie liniowe
|
||||
TGroundNode *Current;
|
||||
@@ -1705,6 +1739,7 @@ TGroundNode * TGround::AddGroundNode(cParser *parser)
|
||||
tmp->MemCell->Load(parser);
|
||||
if (!tmp->asName.empty()) // jest pusta gdy "none"
|
||||
{ // dodanie do wyszukiwarki
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
if (sTracks->Update(TP_MEMCELL, tmp->asName.c_str(),
|
||||
tmp)) // najpierw sprawdzić, czy już jest
|
||||
{ // przy zdublowaniu wskaźnik zostanie podmieniony w drzewku na późniejszy (zgodność
|
||||
@@ -1713,6 +1748,12 @@ TGroundNode * TGround::AddGroundNode(cParser *parser)
|
||||
}
|
||||
else
|
||||
sTracks->Add(TP_MEMCELL, tmp->asName.c_str(), tmp); // nazwa jest unikalna
|
||||
#else
|
||||
if( false == m_trackmap.Add( TP_MEMCELL, tmp->asName, tmp ) ) {
|
||||
// przy zdublowaniu wskaźnik zostanie podmieniony w drzewku na późniejszy (zgodność wsteczna)
|
||||
ErrorLog( "Duplicated memcell: " + tmp->asName ); // to zgłaszać duplikat
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case TP_EVLAUNCH:
|
||||
@@ -1732,6 +1773,7 @@ TGroundNode * TGround::AddGroundNode(cParser *parser)
|
||||
tmp->asName); // w nazwie może być nazwa odcinka izolowanego
|
||||
if (!tmp->asName.empty()) // jest pusta gdy "none"
|
||||
{ // dodanie do wyszukiwarki
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
if (sTracks->Update(TP_TRACK, tmp->asName.c_str(),
|
||||
tmp)) // najpierw sprawdzić, czy już jest
|
||||
{ // przy zdublowaniu wskaźnik zostanie podmieniony w drzewku na późniejszy (zgodność
|
||||
@@ -1741,6 +1783,12 @@ TGroundNode * TGround::AddGroundNode(cParser *parser)
|
||||
}
|
||||
else
|
||||
sTracks->Add(TP_TRACK, tmp->asName.c_str(), tmp); // nazwa jest unikalna
|
||||
#else
|
||||
if( false == m_trackmap.Add( TP_TRACK, tmp->asName, tmp ) ) {
|
||||
// przy zdublowaniu wskaźnik zostanie podmieniony w drzewku na późniejszy (zgodność wsteczna)
|
||||
ErrorLog( "Duplicated track: " + tmp->asName ); // to zgłaszać duplikat
|
||||
}
|
||||
#endif
|
||||
}
|
||||
tmp->pCenter = (tmp->pTrack->CurrentSegment()->FastGetPoint_0() +
|
||||
tmp->pTrack->CurrentSegment()->FastGetPoint(0.5) +
|
||||
@@ -1981,6 +2029,7 @@ TGroundNode * TGround::AddGroundNode(cParser *parser)
|
||||
}
|
||||
else if (!tmp->asName.empty()) // jest pusta gdy "none"
|
||||
{ // dodanie do wyszukiwarki
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
if (sTracks->Update(TP_MODEL, tmp->asName.c_str(),
|
||||
tmp)) // najpierw sprawdzić, czy już jest
|
||||
{ // przy zdublowaniu wskaźnik zostanie podmieniony w drzewku na późniejszy (zgodność
|
||||
@@ -1989,6 +2038,12 @@ TGroundNode * TGround::AddGroundNode(cParser *parser)
|
||||
}
|
||||
else
|
||||
sTracks->Add(TP_MODEL, tmp->asName.c_str(), tmp); // nazwa jest unikalna
|
||||
#else
|
||||
if( false == m_trackmap.Add( TP_MODEL, tmp->asName, tmp ) ) {
|
||||
// przy zdublowaniu wskaźnik zostanie podmieniony w drzewku na późniejszy (zgodność wsteczna)
|
||||
ErrorLog( "Duplicated model: " + tmp->asName ); // to zgłaszać duplikat
|
||||
}
|
||||
#endif
|
||||
}
|
||||
// str=Parser->GetNextSymbol().LowerCase();
|
||||
break;
|
||||
@@ -2268,7 +2323,15 @@ TSubRect * TGround::GetSubRect(int iCol, int iRow)
|
||||
|
||||
TEvent * TGround::FindEvent(const string &asEventName)
|
||||
{
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
return (TEvent *)sTracks->Find(0, asEventName.c_str()); // wyszukiwanie w drzewie
|
||||
#else
|
||||
auto const lookup = m_eventmap.find( asEventName );
|
||||
return
|
||||
lookup != m_eventmap.end() ?
|
||||
lookup->second :
|
||||
nullptr;
|
||||
#endif
|
||||
/* //powolna wyszukiwarka
|
||||
for (TEvent *Current=RootEvent;Current;Current=Current->Next2)
|
||||
{
|
||||
@@ -2281,13 +2344,25 @@ TEvent * TGround::FindEvent(const string &asEventName)
|
||||
|
||||
TEvent * TGround::FindEventScan(const string &asEventName)
|
||||
{ // wyszukanie eventu z opcją utworzenia niejawnego dla komórek skanowanych
|
||||
TEvent *e = (TEvent *)sTracks->Find(0, asEventName.c_str()); // wyszukiwanie w drzewie eventów
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
TEvent *e = (TEvent *)sTracks->Find( 0, asEventName.c_str() ); // wyszukiwanie w drzewie eventów
|
||||
#else
|
||||
auto const lookup = m_eventmap.find( asEventName );
|
||||
auto e =
|
||||
lookup != m_eventmap.end() ?
|
||||
lookup->second :
|
||||
nullptr;
|
||||
#endif
|
||||
if (e)
|
||||
return e; // jak istnieje, to w porządku
|
||||
if (asEventName.rfind(":scan") != std::string::npos) // jeszcze może być event niejawny
|
||||
{ // no to szukamy komórki pamięci o nazwie zawartej w evencie
|
||||
string n = asEventName.substr(0, asEventName.length() - 5); // do dwukropka
|
||||
if (sTracks->Find(TP_MEMCELL, n.c_str())) // jeśli jest takowa komórka pamięci
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
if( sTracks->Find( TP_MEMCELL, n.c_str() ) ) // jeśli jest takowa komórka pamięci
|
||||
#else
|
||||
if( m_trackmap.Find( TP_MEMCELL, n ) != nullptr ) // jeśli jest takowa komórka pamięci
|
||||
#endif
|
||||
e = new TEvent(n); // utworzenie niejawnego eventu jej odczytu
|
||||
}
|
||||
return e; // utworzony albo się nie udało
|
||||
@@ -2626,7 +2701,11 @@ bool TGround::Init(std::string asFile, HDC hDC)
|
||||
if (RootEvent->asName.find(
|
||||
"onstart") != string::npos) // event uruchamiany automatycznie po starcie
|
||||
AddToQuery(RootEvent, NULL); // dodanie do kolejki
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
sTracks->Add(0, tmp->asName.c_str(), tmp); // dodanie do wyszukiwarki
|
||||
#else
|
||||
m_eventmap.emplace( tmp->asName, tmp ); // dodanie do wyszukiwarki
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2905,10 +2984,12 @@ bool TGround::Init(std::string asFile, HDC hDC)
|
||||
parser >> token;
|
||||
}
|
||||
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
sTracks->Sort(TP_TRACK); // finalne sortowanie drzewa torów
|
||||
sTracks->Sort(TP_MEMCELL); // finalne sortowanie drzewa komórek pamięci
|
||||
sTracks->Sort(TP_MODEL); // finalne sortowanie drzewa modeli
|
||||
sTracks->Sort(0); // finalne sortowanie drzewa eventów
|
||||
#endif
|
||||
if (!bInitDone)
|
||||
FirstInit(); // jeśli nie było w scenerii
|
||||
if (Global::pTerrainCompact)
|
||||
@@ -3375,7 +3456,11 @@ void TGround::InitTracks()
|
||||
Current = new TGroundNode(); // to nie musi mieć nazwy, nazwa w wyszukiwarce wystarczy
|
||||
// Current->asName=p->asName; //mazwa identyczna, jak nazwa odcinka izolowanego
|
||||
Current->MemCell = new TMemCell(NULL); // nowa komórka
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
sTracks->Add(TP_MEMCELL, p->asName.c_str(), Current); // dodanie do wyszukiwarki
|
||||
#else
|
||||
m_trackmap.Add( TP_MEMCELL, p->asName, Current );
|
||||
#endif
|
||||
Current->nNext =
|
||||
nRootOfType[TP_MEMCELL]; // to nie powinno tutaj być, bo robi się śmietnik
|
||||
nRootOfType[TP_MEMCELL] = Current;
|
||||
@@ -4038,15 +4123,16 @@ bool TGround::CheckQuery()
|
||||
}
|
||||
#endif
|
||||
//if (DebugModeFlag)
|
||||
WriteLog("Type: UpdateValues & Track command - " +
|
||||
std::string(tmpEvent->Params[0].asText) + " " +
|
||||
std::to_string(tmpEvent->Params[1].asdouble) + " " +
|
||||
std::to_string(tmpEvent->Params[2].asdouble));
|
||||
WriteLog("Type: UpdateValues & Track command - " +
|
||||
tmpEvent->Params[5].asMemCell->Text() + " " +
|
||||
std::to_string( tmpEvent->Params[ 5 ].asMemCell->Value1() ) + " " +
|
||||
std::to_string( tmpEvent->Params[ 5 ].asMemCell->Value2() ) );
|
||||
}
|
||||
else //if (DebugModeFlag)
|
||||
WriteLog("Type: UpdateValues - " + std::string( tmpEvent->Params[0].asText ) +
|
||||
" " + std::to_string(tmpEvent->Params[1].asdouble) + " " +
|
||||
std::to_string(tmpEvent->Params[2].asdouble));
|
||||
else //if (DebugModeFlag)
|
||||
WriteLog("Type: UpdateValues - " +
|
||||
tmpEvent->Params[5].asMemCell->Text() + " " +
|
||||
std::to_string( tmpEvent->Params[ 5 ].asMemCell->Value1() ) + " " +
|
||||
std::to_string( tmpEvent->Params[ 5 ].asMemCell->Value2() ) );
|
||||
}
|
||||
break;
|
||||
case tp_GetValues:
|
||||
|
||||
9
Ground.h
9
Ground.h
@@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "Classes.h"
|
||||
#include "ResourceManager.h"
|
||||
#include "dumb3d.h"
|
||||
#include "Names.h"
|
||||
|
||||
using namespace Math3D;
|
||||
|
||||
@@ -297,7 +298,15 @@ class TGround
|
||||
ssh = 0,
|
||||
ssm = 0; // ustawienia czasu
|
||||
// int tracks,tracksfar; //liczniki torów
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
TNames *sTracks = nullptr; // posortowane nazwy torów i eventów
|
||||
#else
|
||||
typedef std::unordered_map<std::string, TEvent *> event_map;
|
||||
// typedef std::unordered_map<std::string, TGroundNode *> groundnode_map;
|
||||
event_map m_eventmap;
|
||||
// groundnode_map m_memcellmap, m_modelmap, m_trackmap;
|
||||
TNames<TGroundNode *> m_trackmap;
|
||||
#endif
|
||||
private: // metody prywatne
|
||||
bool EventConditon(TEvent *e);
|
||||
|
||||
|
||||
61
Names.h
61
Names.h
@@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
@@ -7,8 +8,64 @@ obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#ifndef NamesH
|
||||
#define NamesH
|
||||
#include <unordered_map>
|
||||
#include <string>
|
||||
|
||||
template <typename _Pointer>
|
||||
class TNames {
|
||||
|
||||
public:
|
||||
// types:
|
||||
|
||||
// constructors:
|
||||
TNames() = default;
|
||||
|
||||
// destructor:
|
||||
|
||||
// methods:
|
||||
// dodanie obiektu z wskaźnikiem. updates data field if the object already exists. returns true for insertion, false for update
|
||||
bool
|
||||
Add( int const Type, std::string const &Name, _Pointer Data ) {
|
||||
|
||||
auto lookup = find_map( Type ).emplace( Name, Data );
|
||||
if( lookup.second == false ) {
|
||||
// record already exists, update it
|
||||
lookup.first->second = Data;
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
// new record inserted, bail out
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// returns pointer associated with provided label, or nullptr if there's no match
|
||||
_Pointer
|
||||
Find( int const Type, std::string const &Name ) {
|
||||
|
||||
auto const &map = find_map( Type );
|
||||
auto const lookup = map.find( Name );
|
||||
if( lookup != map.end() ) { return lookup->second; }
|
||||
else { return nullptr; }
|
||||
}
|
||||
|
||||
private:
|
||||
// types:
|
||||
typedef std::unordered_map<std::string, _Pointer> pointer_map;
|
||||
typedef std::unordered_map<int, pointer_map> pointermap_map;
|
||||
|
||||
// methods:
|
||||
// returns database stored with specified type key; creates new database if needed.
|
||||
pointer_map &
|
||||
find_map( int const Type ) {
|
||||
|
||||
return m_maps.emplace( Type, pointer_map() ).first->second;
|
||||
}
|
||||
|
||||
// members:
|
||||
pointermap_map m_maps; // list of pointer maps of types specified so far
|
||||
};
|
||||
|
||||
#ifdef EU07_USE_OLD_TNAMES_CLASS
|
||||
//---------------------------------------------------------------------------
|
||||
class ItemRecord
|
||||
{ // rekord opisujący obiekt; raz utworzony nie przemieszcza się
|
||||
|
||||
40
Spring.cpp
40
Spring.cpp
@@ -29,7 +29,7 @@ void TSpring::Init(double nrestLen, double nKs, double nKd)
|
||||
restLen = nrestLen;
|
||||
}
|
||||
|
||||
bool TSpring::ComputateForces(vector3 pPosition1, vector3 pPosition2)
|
||||
Math3D::vector3 TSpring::ComputateForces(vector3 const &pPosition1, vector3 const &pPosition2)
|
||||
{
|
||||
|
||||
double dist, Hterm, Dterm;
|
||||
@@ -41,31 +41,29 @@ bool TSpring::ComputateForces(vector3 pPosition1, vector3 pPosition2)
|
||||
// dist = VectorLength(&deltaP); // Magnitude of
|
||||
// deltaP
|
||||
dist = deltaP.Length();
|
||||
if (dist == 0)
|
||||
{
|
||||
vForce1 = vForce2 = vector3(0, 0, 0);
|
||||
return false;
|
||||
if (dist != 0.0 ) {
|
||||
|
||||
// Hterm = (dist - spring->restLen) * spring->Ks; // Ks * (dist - rest)
|
||||
Hterm = ( dist - restLen ) * Ks; // Ks * (dist - rest)
|
||||
|
||||
// VectorDifference(&p1->v,&p2->v,&deltaV); // Delta Velocity Vector
|
||||
deltaV = pPosition1 - pPosition2;
|
||||
|
||||
// Dterm = (DotProduct(&deltaV,&deltaP) * spring->Kd) / dist; // Damping Term
|
||||
// Dterm = (DotProduct(deltaV,deltaP) * Kd) / dist;
|
||||
Dterm = 0;
|
||||
|
||||
// ScaleVector(&deltaP,1.0f / dist, &springForce); // Normalize Distance Vector
|
||||
// ScaleVector(&springForce,-(Hterm + Dterm),&springForce); // Calc Force
|
||||
springForce = deltaP / dist * ( -( Hterm + Dterm ) );
|
||||
// VectorSum(&p1->f,&springForce,&p1->f); // Apply to Particle 1
|
||||
// VectorDifference(&p2->f,&springForce,&p2->f); // - Force on Particle 2
|
||||
}
|
||||
|
||||
// Hterm = (dist - spring->restLen) * spring->Ks; // Ks * (dist - rest)
|
||||
Hterm = (dist - restLen) * Ks; // Ks * (dist - rest)
|
||||
|
||||
// VectorDifference(&p1->v,&p2->v,&deltaV); // Delta Velocity Vector
|
||||
deltaV = pPosition1 - pPosition2;
|
||||
|
||||
// Dterm = (DotProduct(&deltaV,&deltaP) * spring->Kd) / dist; // Damping Term
|
||||
// Dterm = (DotProduct(deltaV,deltaP) * Kd) / dist;
|
||||
Dterm = 0;
|
||||
|
||||
// ScaleVector(&deltaP,1.0f / dist, &springForce); // Normalize Distance Vector
|
||||
// ScaleVector(&springForce,-(Hterm + Dterm),&springForce); // Calc Force
|
||||
springForce = deltaP / dist * (-(Hterm + Dterm));
|
||||
// VectorSum(&p1->f,&springForce,&p1->f); // Apply to Particle 1
|
||||
// VectorDifference(&p2->f,&springForce,&p2->f); // - Force on Particle 2
|
||||
vForce1 = springForce;
|
||||
vForce2 = springForce;
|
||||
|
||||
return true;
|
||||
return springForce;
|
||||
}
|
||||
|
||||
void TSpring::Render()
|
||||
|
||||
2
Spring.h
2
Spring.h
@@ -31,7 +31,7 @@ class TSpring
|
||||
// void Init(TParticnp1, TParticle *np2, double nKs= 0.5f, double nKd= 0.002f,
|
||||
// double nrestLen= -1.0f);
|
||||
void Init(double nrestLen, double nKs = 0.5f, double nKd = 0.002f);
|
||||
bool ComputateForces(vector3 pPosition1, vector3 pPosition2);
|
||||
Math3D::vector3 ComputateForces(vector3 const &pPosition1, vector3 const &pPosition2);
|
||||
void Render();
|
||||
vector3 vForce1, vForce2;
|
||||
double restLen; // LENGTH OF SPRING AT REST
|
||||
|
||||
65
Train.cpp
65
Train.cpp
@@ -217,13 +217,13 @@ bool TTrain::Init(TDynamicObject *NewDynamicObject, bool e3d)
|
||||
}
|
||||
}
|
||||
*/
|
||||
MechSpring.Init(0, 500);
|
||||
MechSpring.Init(0.015, 250);
|
||||
vMechVelocity = vector3(0, 0, 0);
|
||||
pMechOffset = vector3(-0.4, 3.3, 5.5);
|
||||
fMechCroach = 0.5;
|
||||
fMechSpringX = 1;
|
||||
fMechSpringY = 0.1;
|
||||
fMechSpringZ = 0.1;
|
||||
fMechSpringY = 0.5;
|
||||
fMechSpringZ = 0.5;
|
||||
fMechMaxSpring = 0.15;
|
||||
fMechRoll = 0.05;
|
||||
fMechPitch = 0.1;
|
||||
@@ -2545,36 +2545,41 @@ void TTrain::UpdateMechPosition(double dt)
|
||||
// - przy szybkiej jeździe kabina prosto, horyzont pochylony
|
||||
|
||||
vector3 pNewMechPosition;
|
||||
Math3D::vector3 shake;
|
||||
// McZapkie: najpierw policzę pozycję w/m kabiny
|
||||
|
||||
// ABu: rzucamy kabina tylko przy duzym FPS!
|
||||
// Mala histereza, zeby bez przerwy nie przelaczalo przy FPS~17
|
||||
// Granice mozna ustalic doswiadczalnie. Ja proponuje 14:20
|
||||
double r1, r2, r3;
|
||||
int iVel = DynamicObject->GetVelocity();
|
||||
if (iVel > 150)
|
||||
iVel = 150;
|
||||
double iVel = DynamicObject->GetVelocity();
|
||||
if (iVel > 150.0)
|
||||
iVel = 150.0;
|
||||
if (!Global::iSlowMotion // musi być pełna prędkość
|
||||
&& (pMechOffset.y < 4.0)) // Ra 15-01: przy oglądaniu pantografu bujanie przeszkadza
|
||||
{
|
||||
if (!(Random((GetFPS() + 1) / 15) > 0))
|
||||
{
|
||||
if ((iVel > 0) && (Random(155 - iVel) < 16))
|
||||
{
|
||||
r1 = (double(Random(iVel * 2) - iVel) / ((iVel * 2) * 4)) * fMechSpringX;
|
||||
r2 = (double(Random(iVel * 2) - iVel) / ((iVel * 2) * 4)) * fMechSpringY;
|
||||
r3 = (double(Random(iVel * 2) - iVel) / ((iVel * 2) * 4)) * fMechSpringZ;
|
||||
MechSpring.ComputateForces(vector3(r1, r2, r3), pMechShake);
|
||||
// MechSpring.ComputateForces(vector3(double(random(200)-100)/200,double(random(200)-100)/200,double(random(200)-100)/500),pMechShake);
|
||||
if( iVel > 0.0 ) {
|
||||
// acceleration-driven base shake
|
||||
shake += 1.5 * MechSpring.ComputateForces(
|
||||
vector3(
|
||||
-mvControlled->AccN * dt * 7.5, // highlight side sway
|
||||
mvControlled->AccV * dt * 15,
|
||||
-mvControlled->AccS * dt ),
|
||||
pMechShake );
|
||||
|
||||
if( Random( iVel ) > 30.0 ) {
|
||||
// extra shake at increased velocity
|
||||
shake += MechSpring.ComputateForces(
|
||||
vector3(
|
||||
( Random( iVel * 2 ) - iVel ) / ( ( iVel * 2 ) * 4 ) * fMechSpringX,
|
||||
( Random( iVel * 2 ) - iVel ) / ( ( iVel * 2 ) * 4 ) * fMechSpringY,
|
||||
( Random( iVel * 2 ) - iVel ) / ( ( iVel * 2 ) * 4 ) * fMechSpringZ ),
|
||||
pMechShake );
|
||||
// * (( 200 - DynamicObject->MyTrack->iQualityFlag ) * 0.0075 ); // scale to 75-150% based on track quality
|
||||
}
|
||||
else
|
||||
MechSpring.ComputateForces(vector3(-mvControlled->AccN * dt,
|
||||
mvControlled->AccV * dt * 10,
|
||||
-mvControlled->AccS * dt),
|
||||
pMechShake);
|
||||
shake *= 1.35;
|
||||
}
|
||||
vMechVelocity -= (MechSpring.vForce2 + vMechVelocity * 100) *
|
||||
(fMechSpringX + fMechSpringY + fMechSpringZ) / (200);
|
||||
vMechVelocity -= (shake + vMechVelocity * 100) * (fMechSpringX + fMechSpringY + fMechSpringZ) / (200);
|
||||
// shake *= 0.95 * dt; // shake damping
|
||||
|
||||
// McZapkie:
|
||||
pMechShake += vMechVelocity * dt;
|
||||
@@ -2583,14 +2588,12 @@ void TTrain::UpdateMechPosition(double dt)
|
||||
if ((pMechShake.y > fMechMaxSpring) || (pMechShake.y < -fMechMaxSpring))
|
||||
vMechVelocity.y = -vMechVelocity.y;
|
||||
// ABu011104: 5*pMechShake.y, zeby ladnie pudlem rzucalo :)
|
||||
pNewMechPosition = pMechOffset + vector3(pMechShake.x, 5 * pMechShake.y, pMechShake.z);
|
||||
pNewMechPosition = pMechOffset + vector3(1.5 * pMechShake.x, 2.0 * pMechShake.y, 1.5 * pMechShake.z);
|
||||
vMechMovement = 0.5 * vMechMovement;
|
||||
}
|
||||
else
|
||||
{ // hamowanie rzucania przy spadku FPS
|
||||
pMechShake -= pMechShake * Min0R(dt, 1); // po tym chyba potrafią zostać
|
||||
// jakieś ułamki, które powodują
|
||||
// zjazd
|
||||
pMechShake -= pMechShake * std::min(dt, 1.0); // po tym chyba potrafią zostać jakieś ułamki, które powodują zjazd
|
||||
pMechOffset += vMechMovement * dt;
|
||||
vMechVelocity.y = 0.5 * vMechVelocity.y;
|
||||
pNewMechPosition = pMechOffset + vector3(pMechShake.x, 5 * pMechShake.y, pMechShake.z);
|
||||
@@ -5067,6 +5070,8 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName)
|
||||
{
|
||||
double dSDist;
|
||||
cParser parser(asFileName, cParser::buffer_FILE);
|
||||
// NOTE: yaml-style comments are disabled until conflict in use of # is resolved
|
||||
// parser.addCommentStyle( "#", "\n" );
|
||||
//Wartości domyślne by nie wysypywało przy wybrakowanych mmd @240816 Stele
|
||||
dsbPneumaticSwitch = TSoundsManager::GetFromName("silence1.wav", true);
|
||||
dsbBufferClamp = TSoundsManager::GetFromName("en57_bufferclamp.wav", true);
|
||||
@@ -5312,7 +5317,7 @@ bool TTrain::LoadMMediaFile(std::string const &asFileName)
|
||||
double ks, kd;
|
||||
parser.getTokens(2, false);
|
||||
parser >> ks >> kd;
|
||||
MechSpring.Init(0, ks, kd);
|
||||
MechSpring.Init(MechSpring.restLen, ks, kd);
|
||||
parser.getTokens(6, false);
|
||||
parser >> fMechSpringX >> fMechSpringY >> fMechSpringZ >> fMechMaxSpring >>
|
||||
fMechRoll >> fMechPitch;
|
||||
@@ -5388,6 +5393,8 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
|
||||
std::string cabstr("cab" + std::to_string(cabindex) + "definition:");
|
||||
|
||||
std::shared_ptr<cParser> parser = std::make_shared<cParser>(asFileName, cParser::buffer_FILE);
|
||||
// NOTE: yaml-style comments are disabled until conflict in use of # is resolved
|
||||
// parser.addCommentStyle( "#", "\n" );
|
||||
std::string token;
|
||||
do
|
||||
{
|
||||
@@ -5404,6 +5411,8 @@ bool TTrain::InitializeCab(int NewCabNo, std::string const &asFileName)
|
||||
cabstr = "cab1definition:";
|
||||
// crude way to start parsing from beginning
|
||||
parser = std::make_shared<cParser>(asFileName, cParser::buffer_FILE);
|
||||
// NOTE: yaml-style comments are disabled until conflict in use of # is resolved
|
||||
// parser.addCommentStyle( "#", "\n" );
|
||||
do
|
||||
{
|
||||
token = "";
|
||||
|
||||
@@ -114,7 +114,6 @@
|
||||
<ClCompile Include="MemCell.cpp" />
|
||||
<ClCompile Include="Model3d.cpp" />
|
||||
<ClCompile Include="mtable.cpp" />
|
||||
<ClCompile Include="Names.cpp" />
|
||||
<ClCompile Include="opengl\ARB_Multisample.cpp" />
|
||||
<ClCompile Include="parser.cpp" />
|
||||
<ClCompile Include="PyInt.cpp" />
|
||||
|
||||
@@ -99,9 +99,6 @@
|
||||
<ClCompile Include="mtable.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Names.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="parser.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
|
||||
@@ -21,9 +21,9 @@ http://mozilla.org/MPL/2.0/.
|
||||
// cParser -- generic class for parsing text data.
|
||||
|
||||
// constructors
|
||||
cParser::cParser(std::string const Stream, buffertype Type, std::string Path, bool tr)
|
||||
cParser::cParser( std::string const &Stream, buffertype const Type, std::string Path, bool const Loadtraction )
|
||||
{
|
||||
LoadTraction = tr;
|
||||
LoadTraction = Loadtraction;
|
||||
// build comments map
|
||||
mComments.insert(commentmap::value_type("/*", "*/"));
|
||||
mComments.insert(commentmap::value_type("//", "\n"));
|
||||
@@ -236,3 +236,8 @@ int cParser::getProgress() const
|
||||
{
|
||||
return static_cast<int>( mStream->rdbuf()->pubseekoff(0, std::ios_base::cur) * 100 / mSize );
|
||||
}
|
||||
|
||||
void cParser::addCommentStyle( std::string const &Commentstart, std::string const &Commentend ) {
|
||||
|
||||
mComments.insert( commentmap::value_type(Commentstart, Commentend) );
|
||||
}
|
||||
|
||||
11
parser.h
11
parser.h
@@ -28,8 +28,7 @@ class cParser //: public std::stringstream
|
||||
buffer_TEXT
|
||||
};
|
||||
// constructors:
|
||||
cParser(std::string Stream, buffertype Type = buffer_TEXT, std::string Path = "",
|
||||
bool tr = true);
|
||||
cParser(std::string const &Stream, buffertype const Type = buffer_TEXT, std::string Path = "", bool const Loadtraction = true );
|
||||
// destructor:
|
||||
virtual ~cParser();
|
||||
// methods:
|
||||
@@ -79,9 +78,10 @@ class cParser //: public std::stringstream
|
||||
return !mStream->fail();
|
||||
};
|
||||
bool getTokens(int Count = 1, bool ToLower = true, const char *Break = "\n\t ;");
|
||||
int getProgress() const; // percentage of file processed.
|
||||
// load traction?
|
||||
bool LoadTraction;
|
||||
// returns percentage of file processed so far
|
||||
int getProgress() const;
|
||||
// add custom definition of text which should be ignored when retrieving tokens
|
||||
void addCommentStyle( std::string const &Commentstart, std::string const &Commentend );
|
||||
|
||||
private:
|
||||
// methods:
|
||||
@@ -92,6 +92,7 @@ class cParser //: public std::stringstream
|
||||
bool findQuotes( std::string &String );
|
||||
bool trimComments( std::string &String );
|
||||
// members:
|
||||
bool LoadTraction; // load traction?
|
||||
std::istream *mStream; // relevant kind of buffer is attached on creation.
|
||||
std::string mPath; // path to open stream, for relative path lookups.
|
||||
std::streamoff mSize; // size of open stream, for progress report.
|
||||
|
||||
Reference in New Issue
Block a user