mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-22 09:19:18 +02:00
build 190809. load weights data file
This commit is contained in:
@@ -1616,6 +1616,7 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
|
|||||||
}
|
}
|
||||||
// load the cargo now that we know whether the vehicle will allow it
|
// load the cargo now that we know whether the vehicle will allow it
|
||||||
MoverParameters->AssignLoad( LoadType, Load );
|
MoverParameters->AssignLoad( LoadType, Load );
|
||||||
|
MoverParameters->ComputeMass();
|
||||||
|
|
||||||
bool driveractive = (fVel != 0.0); // jeśli prędkość niezerowa, to aktywujemy ruch
|
bool driveractive = (fVel != 0.0); // jeśli prędkość niezerowa, to aktywujemy ruch
|
||||||
if (!MoverParameters->CheckLocomotiveParameters(
|
if (!MoverParameters->CheckLocomotiveParameters(
|
||||||
@@ -2431,6 +2432,7 @@ void TDynamicObject::update_exchange( double const Deltatime ) {
|
|||||||
m_exchange.unload_count -= exchangesize;
|
m_exchange.unload_count -= exchangesize;
|
||||||
MoverParameters->LoadStatus = 1;
|
MoverParameters->LoadStatus = 1;
|
||||||
MoverParameters->LoadAmount = std::max( 0.f, MoverParameters->LoadAmount - exchangesize );
|
MoverParameters->LoadAmount = std::max( 0.f, MoverParameters->LoadAmount - exchangesize );
|
||||||
|
MoverParameters->ComputeMass();
|
||||||
update_load_visibility();
|
update_load_visibility();
|
||||||
}
|
}
|
||||||
if( m_exchange.unload_count < 0.01 ) {
|
if( m_exchange.unload_count < 0.01 ) {
|
||||||
@@ -2445,6 +2447,7 @@ void TDynamicObject::update_exchange( double const Deltatime ) {
|
|||||||
m_exchange.load_count -= exchangesize;
|
m_exchange.load_count -= exchangesize;
|
||||||
MoverParameters->LoadStatus = 2;
|
MoverParameters->LoadStatus = 2;
|
||||||
MoverParameters->LoadAmount = std::min( MoverParameters->MaxLoad, MoverParameters->LoadAmount + exchangesize ); // std::max not strictly needed but, eh
|
MoverParameters->LoadAmount = std::min( MoverParameters->MaxLoad, MoverParameters->LoadAmount + exchangesize ); // std::max not strictly needed but, eh
|
||||||
|
MoverParameters->ComputeMass();
|
||||||
update_load_visibility();
|
update_load_visibility();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1497,7 +1497,7 @@ public:
|
|||||||
|
|
||||||
/*funkcje obliczajace sily*/
|
/*funkcje obliczajace sily*/
|
||||||
void ComputeConstans(void);//ABu: wczesniejsze wyznaczenie stalych dla liczenia sil
|
void ComputeConstans(void);//ABu: wczesniejsze wyznaczenie stalych dla liczenia sil
|
||||||
double ComputeMass(void);
|
void ComputeMass(void);
|
||||||
void ComputeTotalForce(double dt);
|
void ComputeTotalForce(double dt);
|
||||||
double Adhesive(double staticfriction) const;
|
double Adhesive(double staticfriction) const;
|
||||||
double TractionForce(double dt);
|
double TractionForce(double dt);
|
||||||
@@ -1645,3 +1645,11 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
//double Distance(TLocation Loc1, TLocation Loc2, TDimension Dim1, TDimension Dim2);
|
//double Distance(TLocation Loc1, TLocation Loc2, TDimension Dim1, TDimension Dim2);
|
||||||
|
|
||||||
|
namespace simulation {
|
||||||
|
|
||||||
|
using weights_table = std::unordered_map<std::string, float>;
|
||||||
|
|
||||||
|
extern weights_table Weights;
|
||||||
|
|
||||||
|
} // simulation
|
||||||
|
|||||||
@@ -4010,7 +4010,6 @@ void TMoverParameters::ComputeConstans(void)
|
|||||||
double BearingF, RollF, HideModifier;
|
double BearingF, RollF, HideModifier;
|
||||||
double Curvature; // Ra 2014-07: odwrotność promienia
|
double Curvature; // Ra 2014-07: odwrotność promienia
|
||||||
|
|
||||||
TotalMass = ComputeMass();
|
|
||||||
TotalMassxg = TotalMass * g; // TotalMass*g
|
TotalMassxg = TotalMass * g; // TotalMass*g
|
||||||
BearingF = 2.0 * (DamageFlag && dtrain_bearing);
|
BearingF = 2.0 * (DamageFlag && dtrain_bearing);
|
||||||
|
|
||||||
@@ -4061,29 +4060,28 @@ void TMoverParameters::ComputeConstans(void)
|
|||||||
// Q: 20160713
|
// Q: 20160713
|
||||||
// Oblicza masę ładunku
|
// Oblicza masę ładunku
|
||||||
// *************************************************************************************************
|
// *************************************************************************************************
|
||||||
double TMoverParameters::ComputeMass(void)
|
void TMoverParameters::ComputeMass()
|
||||||
{
|
{
|
||||||
double M { 0.0 };
|
|
||||||
// TODO: unit weight table, pulled from external data file
|
|
||||||
if( LoadAmount > 0 ) {
|
|
||||||
|
|
||||||
if (ToLower(LoadQuantity) == "tonns")
|
|
||||||
M = LoadAmount * 1000;
|
|
||||||
else if (LoadType.name == "passengers")
|
|
||||||
M = LoadAmount * 80;
|
|
||||||
else if (LoadType.name == "luggage")
|
|
||||||
M = LoadAmount * 100;
|
|
||||||
else if (LoadType.name == "cars")
|
|
||||||
M = LoadAmount * 1200; // 800 kilo to miał maluch
|
|
||||||
else if (LoadType.name == "containers")
|
|
||||||
M = LoadAmount * 8000;
|
|
||||||
else if (LoadType.name == "transformers")
|
|
||||||
M = LoadAmount * 50000;
|
|
||||||
else
|
|
||||||
M = LoadAmount * 1000;
|
|
||||||
}
|
|
||||||
// Ra: na razie tak, ale nie wszędzie masy wirujące się wliczają
|
// Ra: na razie tak, ale nie wszędzie masy wirujące się wliczają
|
||||||
return Mass + M + Mred;
|
TotalMass = Mass + Mred;
|
||||||
|
|
||||||
|
if( LoadAmount == 0 ) { return; }
|
||||||
|
|
||||||
|
// include weight of carried load
|
||||||
|
auto loadtypeunitweight { 0.f };
|
||||||
|
|
||||||
|
if( ToLower( LoadQuantity ) == "tonns" ) {
|
||||||
|
loadtypeunitweight = 1000;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
auto const lookup { simulation::Weights.find( LoadType.name ) };
|
||||||
|
loadtypeunitweight = (
|
||||||
|
lookup != simulation::Weights.end() ?
|
||||||
|
lookup->second :
|
||||||
|
1000.f ); // legacy default unit weight value
|
||||||
|
}
|
||||||
|
|
||||||
|
TotalMass += LoadAmount * loadtypeunitweight;
|
||||||
}
|
}
|
||||||
|
|
||||||
// *************************************************************************************************
|
// *************************************************************************************************
|
||||||
@@ -7069,6 +7067,7 @@ TMoverParameters::AssignLoad( std::string const &Name, float const Amount ) {
|
|||||||
if( Name == loadattributes.name ) {
|
if( Name == loadattributes.name ) {
|
||||||
LoadType = loadattributes;
|
LoadType = loadattributes;
|
||||||
LoadAmount = clamp( Amount, 0.f, MaxLoad ) ;
|
LoadAmount = clamp( Amount, 0.f, MaxLoad ) ;
|
||||||
|
ComputeMass();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7088,7 +7087,7 @@ bool TMoverParameters::LoadingDone(double const LSpeed, std::string const &Loadn
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( Loadname.empty() ) { return ( LoadStatus >= 4 ); }
|
if( Loadname.empty() ) { return ( LoadStatus >= 4 ); }
|
||||||
if( Loadname != LoadType.name ) { return ( LoadStatus >= 4 ); }
|
if( Loadname != LoadType.name ) { return ( LoadStatus >= 4 ); }
|
||||||
|
|
||||||
// test zakończenia załadunku/rozładunku
|
// test zakończenia załadunku/rozładunku
|
||||||
@@ -7111,6 +7110,7 @@ bool TMoverParameters::LoadingDone(double const LSpeed, std::string const &Loadn
|
|||||||
if( LoadAmount == 0.f ) {
|
if( LoadAmount == 0.f ) {
|
||||||
AssignLoad(""); // jak nic nie ma, to nie ma też nazwy
|
AssignLoad(""); // jak nic nie ma, to nie ma też nazwy
|
||||||
}
|
}
|
||||||
|
ComputeMass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if( LSpeed > 0 ) {
|
else if( LSpeed > 0 ) {
|
||||||
@@ -7125,6 +7125,7 @@ bool TMoverParameters::LoadingDone(double const LSpeed, std::string const &Loadn
|
|||||||
LoadStatus = 4; // skończony załadunek
|
LoadStatus = 4; // skończony załadunek
|
||||||
LoadAmount = std::min<float>( MaxLoad * ( 1.0 + OverLoadFactor ), LoadAmount );
|
LoadAmount = std::min<float>( MaxLoad * ( 1.0 + OverLoadFactor ), LoadAmount );
|
||||||
}
|
}
|
||||||
|
ComputeMass();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -10666,3 +10667,9 @@ double TMoverParameters::ShowCurrentP(int AmpN) const
|
|||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace simulation {
|
||||||
|
|
||||||
|
weights_table Weights;
|
||||||
|
|
||||||
|
} // simulation
|
||||||
@@ -16,6 +16,7 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "simulation.h"
|
#include "simulation.h"
|
||||||
#include "Train.h"
|
#include "Train.h"
|
||||||
|
#include "dictionary.h"
|
||||||
#include "sceneeditor.h"
|
#include "sceneeditor.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "uilayer.h"
|
#include "uilayer.h"
|
||||||
@@ -128,6 +129,9 @@ eu07_application::init( int Argc, char *Argv[] ) {
|
|||||||
if( ( result = init_audio() ) != 0 ) {
|
if( ( result = init_audio() ) != 0 ) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
if( ( result = init_data() ) != 0 ) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
m_taskqueue.init();
|
m_taskqueue.init();
|
||||||
if( ( result = init_modes() ) != 0 ) {
|
if( ( result = init_modes() ) != 0 ) {
|
||||||
return result;
|
return result;
|
||||||
@@ -523,6 +527,23 @@ eu07_application::init_audio() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
eu07_application::init_data() {
|
||||||
|
|
||||||
|
// HACK: grab content of the first {} block in load_unit_weights using temporary parser, then parse it normally. on any error our weight list will be empty string
|
||||||
|
auto loadweights { cParser( cParser( "data/load_weights.txt", cParser::buffer_FILE ).getToken<std::string>( true, "{}" ), cParser::buffer_TEXT ) };
|
||||||
|
while( true == loadweights.getTokens( 2 ) ) {
|
||||||
|
std::pair<std::string, float> weightpair;
|
||||||
|
loadweights
|
||||||
|
>> weightpair.first
|
||||||
|
>> weightpair.second;
|
||||||
|
weightpair.first.erase( weightpair.first.end() - 1 ); // trim trailing ':' from the key
|
||||||
|
simulation::Weights.emplace( weightpair.first, weightpair.second );
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
eu07_application::init_modes() {
|
eu07_application::init_modes() {
|
||||||
|
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ private:
|
|||||||
void init_callbacks();
|
void init_callbacks();
|
||||||
int init_gfx();
|
int init_gfx();
|
||||||
int init_audio();
|
int init_audio();
|
||||||
|
int init_data();
|
||||||
int init_modes();
|
int init_modes();
|
||||||
// members
|
// members
|
||||||
modeptr_array m_modes { nullptr }; // collection of available application behaviour modes
|
modeptr_array m_modes { nullptr }; // collection of available application behaviour modes
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ basic_station::update_load( TDynamicObject *First, Mtable::TTrainParameters &Sch
|
|||||||
// (try to) set the cargo type for empty cars
|
// (try to) set the cargo type for empty cars
|
||||||
parameters.LoadAmount = 0.f; // safety measure against edge cases
|
parameters.LoadAmount = 0.f; // safety measure against edge cases
|
||||||
parameters.AssignLoad( "passengers" );
|
parameters.AssignLoad( "passengers" );
|
||||||
|
parameters.ComputeMass();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( parameters.LoadType.name == "passengers" ) {
|
if( parameters.LoadType.name == "passengers" ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user