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

merge, with tmj renderer

This commit is contained in:
milek7
2017-08-18 00:56:05 +02:00
85 changed files with 6815 additions and 3770 deletions

View File

@@ -78,7 +78,8 @@ zwiekszenie nacisku przy duzych predkosciach w hamulcach Oerlikona
*/
#include "dumb3d.h"
using namespace Math3D;
extern int ConversionError;
const double Steel2Steel_friction = 0.15; //tarcie statyczne
const double g = 9.81; //przyspieszenie ziemskie
@@ -623,14 +624,14 @@ public:
bool Signalling = false; /*Czy jest zalaczona sygnalizacja hamowania ostatniego wagonu*/
bool DoorSignalling = false; /*Czy jest zalaczona sygnalizacja blokady drzwi*/
bool Radio = true; /*Czy jest zalaczony radiotelefon*/
double NominalBatteryVoltage = 0.0; /*Winger - baterie w elektrykach*/
float NominalBatteryVoltage = 0.f; /*Winger - baterie w elektrykach*/
TDimension Dim; /*wymiary*/
double Cx = 0.0; /*wsp. op. aerodyn.*/
double Floor = 0.96; //poziom podłogi dla ładunków
double WheelDiameter = 1.0; /*srednica kol napednych*/
double WheelDiameterL = 0.9; //Ra: srednica kol tocznych przednich
double WheelDiameterT = 0.9; //Ra: srednica kol tocznych tylnych
double TrackW = 1.435; /*nominalna szerokosc toru [m]*/
float Floor = 0.96f; //poziom podłogi dla ładunków
float WheelDiameter = 1.f; /*srednica kol napednych*/
float WheelDiameterL = 0.9f; //Ra: srednica kol tocznych przednich
float WheelDiameterT = 0.9f; //Ra: srednica kol tocznych tylnych
float TrackW = 1.435f; /*nominalna szerokosc toru [m]*/
double AxleInertialMoment = 0.0; /*moment bezwladnosci zestawu kolowego*/
std::string AxleArangement; /*uklad osi np. Bo'Bo' albo 1'C*/
int NPoweredAxles = 0; /*ilosc osi napednych liczona z powyzszego*/
@@ -996,8 +997,8 @@ public:
double FrictConst2d= 0.0;
double TotalMassxg = 0.0; /*TotalMass*g*/
vector3 vCoulpler[2]; // powtórzenie współrzędnych sprzęgów z DynObj :/
vector3 DimHalf; // połowy rozmiarów do obliczeń geometrycznych
Math3D::vector3 vCoulpler[2]; // powtórzenie współrzędnych sprzęgów z DynObj :/
Math3D::vector3 DimHalf; // połowy rozmiarów do obliczeń geometrycznych
// int WarningSignal; //0: nie trabi, 1,2: trabi syreną o podanym numerze
int WarningSignal = 0; // tymczasowo 8bit, ze względu na funkcje w MTools
double fBrakeCtrlPos = -2.0; // płynna nastawa hamulca zespolonego
@@ -1023,7 +1024,7 @@ public:
bool IncBrakeLevel(); // wersja na użytek AI
bool DecBrakeLevel();
bool ChangeCab(int direction);
bool CurrentSwitch(int direction);
bool CurrentSwitch(bool const State);
void UpdateBatteryVoltage(double dt);
double ComputeMovement(double dt, double dt1, const TTrackShape &Shape, TTrackParam &Track, TTractionParam &ElectricTraction, const TLocation &NewLoc, TRotation &NewRot); //oblicza przesuniecie pojazdu
double FastComputeMovement(double dt, const TTrackShape &Shape, TTrackParam &Track, const TLocation &NewLoc, TRotation &NewRot); //oblicza przesuniecie pojazdu - wersja zoptymalizowana
@@ -1108,6 +1109,8 @@ public:
double Adhesive(double staticfriction);
double TractionForce(double dt);
double FrictionForce(double R, int TDamage);
double BrakeForceR(double ratio, double velocity);
double BrakeForceP(double press, double velocity);
double BrakeForce(const TTrackParam &Track);
double CouplerForce(int CouplerN, double dt);
void CollisionDetect(int CouplerN, double dt);
@@ -1210,47 +1213,3 @@ 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 ) {
auto value = extract_value( Key, Input );
if( false == value.empty() ) {
// set the specified variable to retrieved value
std::stringstream converter;
converter << value;
converter >> Variable;
return true; // located the variable
}
else {
// set the variable to provided default value
if( false == Default.empty() ) {
std::stringstream converter;
converter << Default;
converter >> Variable;
}
return false; // couldn't locate the variable in provided input
}
}
template <>
bool
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default );

View File

@@ -22,6 +22,8 @@ http://mozilla.org/MPL/2.0/.
const double dEpsilon = 0.01; // 1cm (zależy od typu sprzęgu...)
const double CouplerTune = 0.1; // skalowanie tlumiennosci
int ConversionError = 0;
std::vector<std::string> const TMoverParameters::eimc_labels = {
"dfic: ", "dfmax:", "p: ", "scfu: ", "cim: ", "icif: ", "Uzmax:", "Uzh: ", "DU: ", "I0: ",
"fcfu: ", "F0: ", "a1: ", "Pmax: ", "Fh: ", "Ph: ", "Vh0: ", "Vh1: ", "Imax: ", "abed: ",
@@ -689,13 +691,13 @@ bool TMoverParameters::ChangeCab(int direction)
return false;
};
bool TMoverParameters::CurrentSwitch(int direction)
{ // rozruch wysoki (true) albo niski (false)
// rozruch wysoki (true) albo niski (false)
bool
TMoverParameters::CurrentSwitch(bool const State) {
// Ra: przeniosłem z Train.cpp, nie wiem czy ma to sens
if (MaxCurrentSwitch(direction != 0))
{
if (MaxCurrentSwitch(State)) {
if (TrainType != dt_EZT)
return (MinCurrentSwitch(direction != 0));
return (MinCurrentSwitch(State));
}
// 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
@@ -703,14 +705,14 @@ bool TMoverParameters::CurrentSwitch(int direction)
&& ( true == ShuntModeAllow )
&& ( ActiveDir == 0 ) ) {
// przed ustawieniem kierunku
ShuntMode = ( direction != 0 );
ShuntMode = State;
return true;
}
// for SM42/SP42
if( ( EngineType == DieselElectric )
&& ( true == ShuntModeAllow )
&& ( MainCtrlPos == 0 ) ) {
ShuntMode = ( direction != 0 );
ShuntMode = State;
return true;
}
@@ -814,9 +816,11 @@ void TMoverParameters::UpdateBatteryVoltage(double dt)
sn3 = 0.0,
sn4 = 0.0,
sn5 = 0.0; // Ra: zrobić z tego amperomierz NN
if ((BatteryVoltage > 0) && (EngineType != DieselEngine) && (EngineType != WheelsDriven) &&
(NominalBatteryVoltage > 0))
{
if( ( BatteryVoltage > 0 )
&& ( EngineType != DieselEngine )
&& ( EngineType != WheelsDriven )
&& ( NominalBatteryVoltage > 0 ) ) {
if ((NominalBatteryVoltage / BatteryVoltage < 1.22) && Battery)
{ // 110V
if (!ConverterFlag)
@@ -884,10 +888,10 @@ void TMoverParameters::UpdateBatteryVoltage(double dt)
if (BatteryVoltage < 0.01)
BatteryVoltage = 0.01;
}
else if (NominalBatteryVoltage == 0)
BatteryVoltage = 0;
else
BatteryVoltage = 90;
else {
// TODO: check and implement proper way to handle this for diesel engines
BatteryVoltage = NominalBatteryVoltage;
}
};
/* Ukrotnienie EN57:
@@ -1542,7 +1546,7 @@ double TMoverParameters::ShowEngineRotation(int VehN)
switch (VehN)
{ // numer obrotomierza
case 1:
return fabs(enrot);
return std::abs(enrot);
case 2:
for (b = 0; b <= 1; ++b)
if (TestFlag(Couplers[b].CouplingFlag, ctrain_controll))
@@ -2021,6 +2025,7 @@ bool TMoverParameters::CabActivisation(void)
{
CabNo = ActiveCab; // sterowanie jest z kabiny z obsadą
DirAbsolute = ActiveDir * CabNo;
SecuritySystem.Status |= s_waiting; // activate the alerter TODO: make it part of control based cab selection
SendCtrlToNext("CabActivisation", 1, CabNo);
}
return OK;
@@ -2040,6 +2045,8 @@ bool TMoverParameters::CabDeactivisation(void)
CabNo = 0;
DirAbsolute = ActiveDir * CabNo;
DepartureSignal = false; // nie buczeć z nieaktywnej kabiny
SecuritySystem.Status = 0; // deactivate alerter TODO: make it part of control based cab selection
SendCtrlToNext("CabActivisation", 0, ActiveCab); // CabNo==0!
}
return OK;
@@ -3043,6 +3050,11 @@ void TMoverParameters::CompressorCheck(double dt)
}
else
{
if( ( EngineType == DieselEngine )
&& ( CompressorPower == 0 ) ) {
// experimental: make sure compressor coupled with diesel engine is always ready for work
CompressorAllow = true;
}
if (CompressorFlag) // jeśli sprężarka załączona
{ // sprawdzić możliwe warunki wyłączenia sprężarki
if (CompressorPower == 5) // jeśli zasilanie z sąsiedniego członu
@@ -3170,29 +3182,38 @@ void TMoverParameters::CompressorCheck(double dt)
}
}
if (CompressorFlag)
if ((EngineType == DieselElectric) && (CompressorPower > 0))
CompressedVolume += dt * CompressorSpeed * (2.0 * MaxCompressor - Compressor) /
MaxCompressor *
(DElist[MainCtrlPos].RPM / DElist[MainCtrlPosNo].RPM);
else
{
if( CompressorFlag ) {
if( ( EngineType == DieselElectric ) && ( CompressorPower > 0 ) ) {
CompressedVolume +=
dt * CompressorSpeed * (2.0 * MaxCompressor - Compressor) / MaxCompressor;
if ((CompressorPower == 5) && (Couplers[1].Connected != NULL))
Couplers[1].Connected->TotalCurrent +=
0.0015 * Couplers[1].Connected->Voltage; // tymczasowo tylko obciążenie
// sprężarki, tak z 5A na
// sprężarkę
else if ((CompressorPower == 4) && (Couplers[0].Connected != NULL))
Couplers[0].Connected->TotalCurrent +=
0.0015 * Couplers[0].Connected->Voltage; // tymczasowo tylko obciążenie
// sprężarki, tak z 5A na
// sprężarkę
dt * CompressorSpeed
* ( 2.0 * MaxCompressor - Compressor ) / MaxCompressor
* ( DElist[ MainCtrlPos ].RPM / DElist[ MainCtrlPosNo ].RPM );
}
else if( ( EngineType == DieselEngine ) && ( CompressorPower == 0 ) ) {
// experimental: compressor coupled with diesel engine, output scaled by current engine rotational speed
CompressedVolume +=
dt * CompressorSpeed
* ( 2.0 * MaxCompressor - Compressor ) / MaxCompressor
* ( std::abs( enrot ) / nmax );
}
else {
CompressedVolume +=
dt * CompressorSpeed * ( 2.0 * MaxCompressor - Compressor ) / MaxCompressor;
if( ( CompressorPower == 5 ) && ( Couplers[ 1 ].Connected != NULL ) )
Couplers[ 1 ].Connected->TotalCurrent +=
0.0015 * Couplers[ 1 ].Connected->Voltage; // tymczasowo tylko obciążenie
// sprężarki, tak z 5A na
// sprężarkę
else if( ( CompressorPower == 4 ) && ( Couplers[ 0 ].Connected != NULL ) )
Couplers[ 0 ].Connected->TotalCurrent +=
0.0015 * Couplers[ 0 ].Connected->Voltage; // tymczasowo tylko obciążenie
// sprężarki, tak z 5A na
// sprężarkę
else
TotalCurrent += 0.0015 *
Voltage; // tymczasowo tylko obciążenie sprężarki, tak z 5A na sprężarkę
Voltage; // tymczasowo tylko obciążenie sprężarki, tak z 5A na sprężarkę
}
}
}
}
}
@@ -3744,6 +3765,41 @@ void TMoverParameters::ComputeTotalForce(double dt, double dt1, bool FullVer)
//};
}
double TMoverParameters::BrakeForceR(double ratio, double velocity)
{
double press = 0;
if (MBPM>2)
{
press = MaxBrakePress[1] + (MaxBrakePress[3] - MaxBrakePress[1]) * std::min(1.0, (TotalMass - Mass) / (MBPM - Mass));
}
else
{
if (MaxBrakePress[1] > 0.1)
{
press = MaxBrakePress[LoadFlag];
}
else
{
press = MaxBrakePress[3];
if (DynamicBrakeType == dbrake_automatic)
ratio = ratio + (1.5 - ratio)*std::min(1.0, Vel*0.02);
if ((BrakeDelayFlag&bdelay_R) && (BrakeMethod%128 != bp_Cosid) && (BrakeMethod % 128 != bp_D1) && (BrakeMethod % 128 != bp_D2) && (Power<1) && (velocity<40))
ratio = ratio / 2;
}
}
return BrakeForceP(press*ratio, velocity);
}
double TMoverParameters::BrakeForceP(double press, double velocity)
{
double BFP = 0;
double K = (((press * P2FTrans) - BrakeCylSpring) * BrakeCylMult[0] - BrakeSlckAdj) * BrakeRigEff;
K *= static_cast<double>(BrakeCylNo) / (NAxles * std::max(1, NBpA));
BFP = Hamulec->GetFC(velocity, K)*K*(NAxles * std::max(1, NBpA)) * 1000;
return BFP;
}
// *************************************************************************************************
// Q: 20160713
// oblicza siłę na styku koła i szyny
@@ -3787,7 +3843,7 @@ double TMoverParameters::BrakeForce(const TTrackParam &Track)
Ntotal = u * BrakeRigEff;
else
{
u = (BrakePress * P2FTrans) * BrakeCylMult[0] - BrakeSlckAdj;
u = ((BrakePress * P2FTrans) - BrakeCylSpring) * BrakeCylMult[0] - BrakeSlckAdj;
if (u * (2.0 - BrakeRigEff) < Ntotal) // histereza na nacisku klockow
Ntotal = u * (2.0 - BrakeRigEff);
}
@@ -3841,6 +3897,9 @@ double TMoverParameters::FrictionForce(double R, int TDamage)
return FF;
}
// *************************************************************************************************
// Q: 20160713
// Oblicza przyczepność
@@ -4590,36 +4649,26 @@ double TMoverParameters::TractionForce(double dt)
else
tmp = 4; // szybkie malenie, powolne wzrastanie
}
// if SlippingWheels then begin PosRatio:=0; tmp:=10; SandDoseOn;
// end;//przeciwposlizg
// if(Flat)then //PRZECIWPOŚLIZG
dmoment = eimv[eimv_Fful];
// else
// dmoment:=eimc[eimc_p_F0]*0.99;
// NOTE: the commands to operate the sandbox are likely to conflict with other similar ai decisions
// TODO: gather these in single place so they can be resolved together
if ((abs((PosRatio + 9.66 * dizel_fill) * dmoment * 100) >
0.95 * Adhesive(RunningTrack.friction) * TotalMassxg))
{
if( ( std::abs( ( PosRatio + 9.66 * dizel_fill ) * dmoment * 100 ) > 0.95 * Adhesive( RunningTrack.friction ) * TotalMassxg ) ) {
PosRatio = 0;
tmp = 4;
Sandbox( true, range::local );
} // przeciwposlizg
if ((abs((PosRatio + 9.80 * dizel_fill) * dmoment * 100) >
0.95 * Adhesive(RunningTrack.friction) * TotalMassxg))
{
if( ( std::abs( ( PosRatio + 9.80 * dizel_fill ) * dmoment * 100 ) > 0.95 * Adhesive( RunningTrack.friction ) * TotalMassxg ) ) {
PosRatio = 0;
tmp = 9;
} // przeciwposlizg
if( ( SlippingWheels ) ) {
PosRatio = 0;
tmp = 9;
Sandbox( true, range::local );
} // przeciwposlizg
if ((SlippingWheels))
{
// PosRatio = -PosRatio * 0; // serio -0 ???
PosRatio = 0;
tmp = 9;
Sandbox( true, range::local );
} // przeciwposlizg
else {
// switch sandbox off
Sandbox( false, range::local );
}
dizel_fill += Max0R(Min0R(PosRatio - dizel_fill, 0.1), -0.1) * 2 *
(tmp /*2{+4*byte(PosRatio<dizel_fill)*/) *
@@ -5078,14 +5127,17 @@ bool TMoverParameters::AutoRelayCheck(void)
// IminLo
}
// main bez samoczynnego rozruchu
if( ( MainCtrlActualPos < ( sizeof( RList ) / sizeof( TScheme ) - 1 ) ) // crude guard against running out of current fixed table
&& ( ( RList[ MainCtrlActualPos ].Relay < MainCtrlPos )
|| ( RList[ MainCtrlActualPos + 1 ].Relay == MainCtrlPos )
|| ( ( TrainType == dt_ET22 )
&& ( DelayCtrlFlag ) ) ) ) {
if( ( RList[MainCtrlPos].R == 0 )
&& ( MainCtrlPos > 0 )
&& ( MainCtrlPos != MainCtrlPosNo )
&& ( FastSerialCircuit == 1 ) ) {
if ((RList[MainCtrlActualPos].Relay < MainCtrlPos) ||
(RList[MainCtrlActualPos + 1].Relay == MainCtrlPos) ||
((TrainType == dt_ET22) && (DelayCtrlFlag)))
{
if ((RList[MainCtrlPos].R == 0) && (MainCtrlPos > 0) &&
(!(MainCtrlPos == MainCtrlPosNo)) && (FastSerialCircuit == 1))
{
MainCtrlActualPos++;
// MainCtrlActualPos:=MainCtrlPos; //hunter-111012:
// szybkie wchodzenie na bezoporowa (303E)
@@ -5784,28 +5836,28 @@ std::string TMoverParameters::EngineDescription(int what)
{
if (TestFlag(DamageFlag, dtrain_thinwheel))
if (Power > 0.1)
outstr = "Thin wheel,";
outstr = "Thin wheel";
else
outstr = "Load shifted,";
outstr = "Load shifted";
if (TestFlag(DamageFlag, dtrain_wheelwear))
outstr = "Wheel wear,";
outstr = "Wheel wear";
if (TestFlag(DamageFlag, dtrain_bearing))
outstr = "Bearing damaged,";
outstr = "Bearing damaged";
if (TestFlag(DamageFlag, dtrain_coupling))
outstr = "Coupler broken,";
outstr = "Coupler broken";
if (TestFlag(DamageFlag, dtrain_loaddamage))
if (Power > 0.1)
outstr = "Ventilator damaged,";
outstr = "Ventilator damaged";
else
outstr = "Load damaged,";
outstr = "Load damaged";
if (TestFlag(DamageFlag, dtrain_loaddestroyed))
if (Power > 0.1)
outstr = "Engine damaged,";
outstr = "Engine damaged";
else
outstr = "LOAD DESTROYED,";
outstr = "LOAD DESTROYED";
if (TestFlag(DamageFlag, dtrain_axle))
outstr = "Axle broken,";
outstr = "Axle broken";
if (TestFlag(DamageFlag, dtrain_out))
outstr = "DERAILED";
if (outstr == "")
@@ -6086,7 +6138,7 @@ bool TMoverParameters::readRList( std::string const &Input ) {
return false;
}
auto idx = LISTLINE++;
if( idx >= sizeof( RList ) ) {
if( idx >= sizeof( RList ) / sizeof( TScheme ) ) {
WriteLog( "Read RList: number of entries exceeded capacity of the data table" );
return false;
}
@@ -6108,7 +6160,7 @@ bool TMoverParameters::readDList( std::string const &line ) {
cParser parser( line );
parser.getTokens( 3, false );
auto idx = LISTLINE++;
if( idx >= sizeof( RList ) ) {
if( idx >= sizeof( RList ) / sizeof( TScheme ) ) {
WriteLog( "Read DList: number of entries exceeded capacity of the data table" );
return false;
}
@@ -6128,7 +6180,7 @@ bool TMoverParameters::readFFList( std::string const &line ) {
return false;
}
int idx = LISTLINE++;
if( idx >= sizeof( DElist ) ) {
if( idx >= sizeof( DElist ) / sizeof( TDEScheme ) ) {
WriteLog( "Read FList: number of entries exceeded capacity of the data table" );
return false;
}
@@ -6148,7 +6200,7 @@ bool TMoverParameters::readWWList( std::string const &line ) {
return false;
}
int idx = LISTLINE++;
if( idx >= sizeof( DElist ) ) {
if( idx >= sizeof( DElist ) / sizeof( TDEScheme ) ) {
WriteLog( "Read WWList: number of entries exceeded capacity of the data table" );
return false;
}
@@ -7235,9 +7287,10 @@ void TMoverParameters::LoadFIZ_Engine( std::string const &Input ) {
extract_value( dizel_nmin, "nmin", Input, "" );
dizel_nmin /= 60.0;
extract_value( dizel_nmax, "nmax", Input, "" );
dizel_nmax /= 60.0;
nmax = dizel_nmax; // not sure if this is needed, but just in case
// TODO: unify naming scheme and sort out which diesel engine params are used where and how
extract_value( nmax, "nmax", Input, "" );
nmax /= 60.0;
// nmax = dizel_nmax; // not sure if this is needed, but just in case
extract_value( dizel_nmax_cutoff, "nmax_cutoff", Input, "0.0" );
dizel_nmax_cutoff /= 60.0;
extract_value( dizel_AIM, "AIM", Input, "1.0" );
@@ -8153,7 +8206,7 @@ bool TMoverParameters::RunCommand( std::string Command, double CValue1, double C
else if (Command == "PantRear") /*Winger 160204, ABu 310105 i 030305*/
{ // Ra: uwzględnić trzeba jeszcze zgodność sprzęgów
if ((TrainType == dt_EZT))
{ /*'ezt'*/
{ //'ezt'
if ((CValue1 == 1))
{
PantRearUp = true;
@@ -8166,9 +8219,9 @@ bool TMoverParameters::RunCommand( std::string Command, double CValue1, double C
}
}
else
{ /*nie 'ezt'*/
{ //nie 'ezt'
if ((CValue1 == 1))
/*if ostatni polaczony sprz. sterowania*/
//if ostatni polaczony sprz. sterowania
if ((TestFlag(Couplers[1].CouplingFlag, ctrain_controll) && (CValue2 == 1)) ||
(TestFlag(Couplers[0].CouplingFlag, ctrain_controll) && (CValue2 == -1)))
{
@@ -8345,22 +8398,3 @@ 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
}
}

View File

@@ -2372,6 +2372,11 @@ double TFV4aM::GetPos(int i)
return pos_table[i];
}
double TFV4aM::GetCP()
{
return TP;
}
double TFV4aM::LPP_RP(double pos) // cisnienie z zaokraglonej pozycji;
{
int const i_pos = 2 + std::floor( pos ); // zaokraglone w dol

View File

@@ -551,7 +551,7 @@ class TFV4aM : public TDriverHandle {
void SetReductor(double nAdj)/*override*/;
double GetSound(int i)/*override*/;
double GetPos(int i)/*override*/;
double GetCP();
inline TFV4aM() :
TDriverHandle()
{}

View File

@@ -17,40 +17,9 @@ Copyright (C) 2007-2014 Maciej Cierniak
/*================================================*/
int ConversionError = 0;
int LineCount = 0;
bool DebugModeFlag = false;
bool FreeFlyModeFlag = false;
//std::string Ups(std::string s)
//{
// int jatka;
// std::string swy;
//
// swy = "";
// {
// long jatka_end = s.length() + 1;
// for (jatka = 0; jatka < jatka_end; jatka++)
// swy = swy + UpCase(s[jatka]);
// }
// return swy;
//} /*=Ups=*/
int Max0(int x1, int x2)
{
if (x1 > x2)
return x1;
else
return x2;
}
int Min0(int x1, int x2)
{
if (x1 < x2)
return x1;
else
return x2;
}
bool DebugCameraFlag = false;
double Max0R(double x1, double x2)
{
@@ -79,45 +48,30 @@ std::string Now() {
return converter.str();
}
bool TestFlag(int Flag, int Value)
{
if ((Flag & Value) == Value)
return true;
else
return false;
}
bool SetFlag( int &Flag, int const Value ) {
bool SetFlag(int &Flag, int Value)
{
return iSetFlag(Flag, Value);
}
bool iSetFlag(int &Flag, int Value)
{
if (Value > 0)
{
if ((Flag & Value) == 0)
{
if( Value > 0 ) {
if( false == TestFlag( Flag, Value ) ) {
Flag |= Value;
return true; // true, gdy było wcześniej 0 i zostało ustawione
}
}
else if (Value < 0)
{
Value = abs(Value);
if ((Flag & Value) == Value)
{
Flag &= ~Value; // Value jest ujemne, czyli zerowanie flagi
return true; // true, gdy było wcześniej 1 i zostało wyzerowane
}
else if( Value < 0 ) {
// Value jest ujemne, czyli zerowanie flagi
return ClearFlag( Flag, -Value );
}
return false;
return false;
}
bool UnSetFlag(int &Flag, int Value)
{
Flag &= ~Value;
return true;
bool ClearFlag( int &Flag, int const Value ) {
if( true == TestFlag( Flag, Value ) ) {
Flag &= ~Value;
return true;
}
else {
return false;
}
}
double Random(double a, double b)
@@ -164,9 +118,8 @@ std::string ExchangeCharInString( std::string const &Source, char const &From, c
{
std::string replacement; replacement.reserve( Source.size() );
std::for_each(Source.cbegin(), Source.cend(), [&](char const idx) {
if( idx != From ) { replacement += idx; }
else {
if( To != 0 ) { replacement += To; } }
if( idx != From ) { replacement += idx; }
else { replacement += To; }
} );
return replacement;
@@ -263,33 +216,13 @@ std::string to_hex_str( int const Value, int const Width )
return converter.str();
};
int stol_def(const std::string &str, const int &DefaultValue)
{
int stol_def(const std::string &str, const int &DefaultValue) {
int result { DefaultValue };
std::stringstream converter;
converter << str;
converter >> result;
return result;
/*
// this function was developed iteratively on Codereview.stackexchange
// with the assistance of @Corbin
std::size_t len = str.size();
while (std::isspace(str[len - 1]))
len--;
if (len == 0)
return DefaultValue;
errno = 0;
char *s = new char[len + 1];
std::strncpy(s, str.c_str(), len);
char *p;
int result = strtol(s, &p, 0);
delete[] s;
if( ( *p != '\0' ) || ( errno != 0 ) )
{
return DefaultValue;
}
return result;
*/
}
std::string ToLower(std::string const &text)
@@ -321,61 +254,23 @@ win1250_to_ascii( std::string &Input ) {
}
}
void ComputeArc(double X0, double Y0, double Xn, double Yn, double R, double L, double dL,
double &phi, double &Xout, double &Yout)
/*wylicza polozenie Xout Yout i orientacje phi punktu na elemencie dL luku*/
{
double dX;
double dY;
double Xc;
double Yc;
double gamma;
double alfa;
double AbsR;
template <>
bool
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default ) {
if ((R != 0) && (L != 0))
{
AbsR = abs(R);
dX = Xn - X0;
dY = Yn - Y0;
if (dX != 0)
gamma = atan(dY * 1.0 / dX);
else if (dY > 0)
gamma = M_PI * 1.0 / 2;
else
gamma = 3 * M_PI * 1.0 / 2;
alfa = L * 1.0 / R;
phi = gamma - (alfa + M_PI * Round(R * 1.0 / AbsR)) * 1.0 / 2;
Xc = X0 - AbsR * cos(phi);
Yc = Y0 - AbsR * sin(phi);
phi = phi + alfa * dL * 1.0 / L;
Xout = AbsR * cos(phi) + Xc;
Yout = AbsR * sin(phi) + Yc;
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
}
}
void ComputeALine(double X0, double Y0, double Xn, double Yn, double L, double R, double &Xout,
double &Yout)
{
double dX;
double dY;
double gamma;
double alfa;
/* pX,pY : real;*/
alfa = 0; // ABu: bo nie bylo zainicjowane
dX = Xn - X0;
dY = Yn - Y0;
if (dX != 0)
gamma = atan(dY * 1.0 / dX);
else if (dY > 0)
gamma = M_PI * 1.0 / 2;
else
gamma = 3 * M_PI * 1.0 / 2;
if (R != 0)
alfa = L * 1.0 / R;
Xout = X0 + L * cos(alfa * 1.0 / 2 - gamma);
Yout = Y0 + L * sin(alfa * 1.0 / 2 - gamma);
}
bool FileExists( std::string const &Filename ) {
@@ -384,52 +279,3 @@ bool FileExists( std::string const &Filename ) {
std::ifstream file( fn );
return( true == file.is_open() );
}
/*
//graficzne:
double Xhor(double h)
{
return h * Hstep + Xmin;
}
double Yver(double v)
{
return (Vsize - v) * Vstep + Ymin;
}
long Horiz(double x)
{
x = (x - Xmin) * 1.0 / Hstep;
if (x > -INT_MAX)
if (x < INT_MAX)
return Round(x);
else
return INT_MAX;
else
return -INT_MAX;
}
long Vert(double Y)
{
Y = (Y - Ymin) * 1.0 / Vstep;
if (Y > -INT_MAX)
if (Y < INT_MAX)
return Vsize - Round(Y);
else
return INT_MAX;
else
return -INT_MAX;
}
*/
// NOTE: this now does nothing.
void ClearPendingExceptions()
// resetuje błędy FPU, wymagane dla Trunc()
{
; /*?*/ /* ASM
FNCLEX
ASM END */
}
// END

View File

@@ -15,48 +15,17 @@ http://mozilla.org/MPL/2.0/.
#include <string>
#include <fstream>
#include <ctime>
#include <sys/stat.h>
#include <vector>
#include <sstream>
/*Ra: te stałe nie są używane...
_FileName = ['a'..'z','A'..'Z',':','\','.','*','?','0'..'9','_','-'];
_RealNum = ['0'..'9','-','+','.','E','e'];
_Integer = ['0'..'9','-']; //Ra: to się gryzie z STLport w Builder 6
_Plus_Int = ['0'..'9'];
_All = [' '..'ţ'];
_Delimiter= [',',';']+_EOL;
_Delimiter_Space=_Delimiter+[' '];
*/
static char _EOL[2] = { (char)13, (char)10 };
static char _Spacesigns[4] = { (char)' ', (char)9, (char)13, (char)10 };
static std::string _spacesigns = " \x09\x0D\x0A";
static int const CutLeft = -1;
static int const CutRight = 1;
static int const CutBoth = 0; /*Cut_Space*/
extern int ConversionError;
extern int LineCount;
extern bool DebugModeFlag;
extern bool FreeFlyModeFlag;
typedef unsigned long/*?*//*set of: char */ TableChar; /*MCTUTIL*/
/*konwersje*/
extern bool DebugCameraFlag;
/*funkcje matematyczne*/
int Max0(int x1, int x2);
int Min0(int x1, int x2);
double Max0R(double x1, double x2);
double Min0R(double x1, double x2);
inline int Sign(int x)
{
return x >= 0 ? 1 : -1;
}
inline double Sign(double x)
{
return x >= 0 ? 1.0 : -1.0;
@@ -94,10 +63,9 @@ inline double BorlandTime()
std::string Now();
/*funkcje logiczne*/
extern bool TestFlag(int Flag, int Value);
extern bool SetFlag( int & Flag, int Value);
extern bool iSetFlag( int & Flag, int Value);
extern bool UnSetFlag(int &Flag, int Value);
inline bool TestFlag( int const Flag, int const Value ) { return ( ( Flag & Value ) == Value ); }
bool SetFlag( int &Flag, int const Value);
bool ClearFlag(int &Flag, int const Value);
bool FuzzyLogic(double Test, double Threshold, double Probability);
/*jesli Test>Threshold to losowanie*/
@@ -121,11 +89,21 @@ std::string to_string(double _Val, int precision);
std::string to_string(double _Val, int precision, int width);
std::string to_hex_str( int const _Val, int const width = 4 );
inline std::string to_string(bool _Val)
{
inline std::string to_string(bool _Val) {
return _Val == true ? "true" : "false";
}
template <typename Type_, glm::precision Precision_ = glm::defaultp>
std::string to_string( glm::tvec3<Type_, Precision_> const &Value ) {
return to_string( Value.x, 2 ) + ", " + to_string( Value.y, 2 ) + ", " + to_string( Value.z, 2 );
}
template <typename Type_, glm::precision Precision_ = glm::defaultp>
std::string to_string( glm::tvec4<Type_, Precision_> const &Value, int const Width = 2 ) {
return to_string( Value.x, Width ) + ", " + to_string( Value.y, Width ) + ", " + to_string( Value.z, Width ) + ", " + to_string( Value.w, Width );
}
int stol_def(const std::string & str, const int & DefaultValue);
std::string ToLower(std::string const &text);
@@ -134,40 +112,48 @@ std::string ToUpper(std::string const &text);
// replaces polish letters with basic ascii
void win1250_to_ascii( std::string &Input );
/*procedury, zmienne i funkcje graficzne*/
void ComputeArc(double X0, double Y0, double Xn, double Yn, double R, double L, double dL, double & phi, double & Xout, double & Yout);
/*wylicza polozenie Xout Yout i orientacje phi punktu na elemencie dL luku*/
void ComputeALine(double X0, double Y0, double Xn, double Yn, double L, double R, double & Xout, double & Yout);
/*
inline bool fileExists(const std::string &name)
{
struct stat buffer;
return (stat(name.c_str(), &buffer) == 0);
}*/
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 ) {
auto value = extract_value( Key, Input );
if( false == value.empty() ) {
// set the specified variable to retrieved value
std::stringstream converter;
converter << value;
converter >> Variable;
return true; // located the variable
}
else {
// set the variable to provided default value
if( false == Default.empty() ) {
std::stringstream converter;
converter << Default;
converter >> Variable;
}
return false; // couldn't locate the variable in provided input
}
}
template <>
bool
extract_value( bool &Variable, std::string const &Key, std::string const &Input, std::string const &Default );
bool FileExists( std::string const &Filename );
/*
extern double Xmin;
extern double Ymin;
extern double Xmax;
extern double Ymax;
extern double Xaspect;
extern double Yaspect;
extern double Hstep;
extern double Vstep;
extern int Vsize;
extern int Hsize;
// Converts horizontal screen coordinate into real X-coordinate.
double Xhor( double h );
// Converts vertical screen coordinate into real Y-coordinate.
double Yver( double v );
long Horiz(double x);
long Vert(double Y);
*/
void ClearPendingExceptions();