16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-09-01 23:19:21 +02:00

Merge branch 'tmj-dev'

This commit is contained in:
milek7
2018-02-16 15:25:53 +01:00
113 changed files with 4617 additions and 4057 deletions

View File

@@ -84,8 +84,6 @@ extern int ConversionError;
const double Steel2Steel_friction = 0.15; //tarcie statyczne
const double g = 9.81; //przyspieszenie ziemskie
const double SandSpeed = 0.1; //ile kg/s}
const double RVentSpeed = 3.5; //rozpedzanie sie wentylatora obr/s^2}
const double RVentMinI = 50.0; //przy jakim pradzie sie wylaczaja}
const double Pirazy2 = 6.2831853071794f;
#define PI 3.1415926535897f
@@ -210,6 +208,7 @@ enum sound {
//szczególne typy pojazdów (inna obsługa) dla zmiennej TrainType
//zamienione na flagi bitowe, aby szybko wybierać grupę (np. EZT+SZT)
// TODO: convert to enums, they're used as specific checks anyway
static int const dt_Default = 0;
static int const dt_EZT = 1;
static int const dt_ET41 = 2;
@@ -220,6 +219,7 @@ static int const dt_SN61 = 0x20; //nie używane w warunkach, ale ustawiane z CHK
static int const dt_EP05 = 0x40;
static int const dt_ET40 = 0x80;
static int const dt_181 = 0x100;
static int const dt_DMU = 0x200;
//stałe dla asynchronów
static int const eimc_s_dfic = 0;
@@ -739,7 +739,8 @@ public:
double u = 0.0; //wspolczynnik tarcia yB wywalic!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
double CircuitRes = 0.0; /*rezystancje silnika i obwodu*/
int IminLo = 0; int IminHi = 0; /*prady przelacznika automatycznego rozruchu, uzywane tez przez ai_driver*/
int ImaxLo = 0; int ImaxHi = 0; /*maksymalny prad niskiego i wysokiego rozruchu*/
int ImaxLo = 0; // maksymalny prad niskiego rozruchu
int ImaxHi = 0; // maksymalny prad wysokiego rozruchu
double nmax = 0.0; /*maksymalna dop. ilosc obrotow /s*/
double InitialCtrlDelay = 0.0; double CtrlDelay = 0.0; /* -//- -//- miedzy kolejnymi poz.*/
double CtrlDownDelay = 0.0; /* -//- -//- przy schodzeniu z poz.*/ /*hunter-101012*/
@@ -752,6 +753,8 @@ public:
int RVentType = 0; /*0 - brak, 1 - jest, 2 - automatycznie wlaczany*/
double RVentnmax = 1.0; /*maks. obroty wentylatorow oporow rozruchowych*/
double RVentCutOff = 0.0; /*rezystancja wylaczania wentylatorow dla RVentType=2*/
double RVentSpeed { 0.5 }; //rozpedzanie sie wentylatora obr/s^2}
double RVentMinI { 50.0 }; //przy jakim pradzie sie wylaczaja}
int CompressorPower = 1; /*0: bezp. z obwodow silnika, 1: z przetwornicy, reczne, 2: w przetwornicy, stale, 5: z silnikowego*/
int SmallCompressorPower = 0; /*Winger ZROBIC*/
bool Trafo = false; /*pojazd wyposażony w transformator*/

View File

@@ -9,11 +9,11 @@ http://mozilla.org/MPL/2.0/.
#include "stdafx.h"
#include "MOVER.h"
#include "Oerlikon_ESt.h"
#include "utilities.h"
#include "Globals.h"
#include "Logs.h"
#include "Oerlikon_ESt.h"
#include "parser.h"
#include "usefull.h"
// Ra: tu należy przenosić funcje z mover.pas, które nie są z niego wywoływane.
// Jeśli jakieś zmienne nie są używane w mover.pas, też można je przenosić.
@@ -1667,9 +1667,8 @@ bool TMoverParameters::IncMainCtrl(int CtrlSpeed)
// all work is done in the loop header
;
}
// OK:=true ; {takie chamskie, potem poprawie} <-Ra: kto mia³ to
// poprawiæ i po co?
if( ActiveDir == -1 ) {
// OK:=true ; {takie chamskie, potem poprawie} <-Ra: kto mia³ to poprawiæ i po co?
if( ActiveDir < 0 ) {
while( ( RList[ MainCtrlPos ].Bn > 1 )
&& IncMainCtrl( 1 ) ) {
--MainCtrlPos;
@@ -1700,7 +1699,7 @@ bool TMoverParameters::IncMainCtrl(int CtrlSpeed)
}
}
}
if( ActiveDir == -1 ) {
if( ActiveDir < 0 ) {
if( ( TrainType != dt_PseudoDiesel )
&& ( RList[ MainCtrlPos ].Bn > 1 ) ) {
// blokada wejścia na równoległą podczas jazdy do tyłu
@@ -2973,10 +2972,7 @@ bool TMoverParameters::BrakeDelaySwitch(int BDS)
}
else
rBDS = false;
if( true == rBDS ) {
// if setting was changed emit the sound of pneumatic relay
SetFlag( SoundFlag, sound::pneumatic );
}
return rBDS;
}
@@ -3844,6 +3840,9 @@ double TMoverParameters::BrakeForceR(double ratio, double velocity)
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;
if( ( TrainType == dt_DMU ) && ( velocity < 30.0 ) ) {
ratio -= 0.3;
}
}
}
@@ -4251,22 +4250,29 @@ double TMoverParameters::TractionForce(double dt)
RventRot += ( RVentnmax - RventRot ) * RVentSpeed * dt;
}
else {
RventRot = std::max( 0.0, RventRot - RVentSpeed * dt );
RventRot *= std::max( 0.0, 1.0 - RVentSpeed * dt );
}
break;
}
case 2: { // automatic
auto const motorcurrent{ std::min<double>( ImaxHi, std::abs( Im ) ) };
if( ( std::abs( Itot ) > RVentMinI )
&& ( RList[ MainCtrlActualPos ].R > RVentCutOff ) ) {
RventRot += ( RVentnmax * abs( Itot ) / ( ImaxLo * RList[ MainCtrlActualPos ].Bn ) - RventRot ) * RVentSpeed * dt;
RventRot +=
( RVentnmax
* std::min( 1.0, ( ( motorcurrent / NPoweredAxles ) / RVentMinI ) )
* motorcurrent / ImaxLo
- RventRot )
* RVentSpeed * dt;
}
else if( ( DynamicBrakeType == dbrake_automatic )
&& ( true == DynamicBrakeFlag ) ) {
RventRot += ( RVentnmax * Im / ImaxLo - RventRot ) * RVentSpeed * dt;
RventRot += ( RVentnmax * motorcurrent / ImaxLo - RventRot ) * RVentSpeed * dt;
}
else {
RventRot = std::max( 0.0, RventRot - RVentSpeed * dt );
RventRot *= std::max( 0.0, 1.0 - RVentSpeed * dt );
}
break;
}
@@ -4277,14 +4283,15 @@ double TMoverParameters::TractionForce(double dt)
} // rventtype
} // mains
else {
RventRot = std::max( 0.0, RventRot - RVentSpeed * dt );
RventRot *= std::max( 0.0, 1.0 - RVentSpeed * dt );
}
break;
}
case DieselElectric: {
if( true == Mains ) {
// TBD, TODO: currently ignores RVentType, fix this?
RventRot += clamp( DElist[ MainCtrlPos ].RPM - RventRot, -100.0, 50.0 ) * dt;
RventRot += clamp( DElist[ MainCtrlPos ].RPM / 60.0 - RventRot, -100.0, 50.0 ) * dt;
}
else {
RventRot *= std::max( 0.0, 1.0 - RVentSpeed * dt );
@@ -5193,9 +5200,12 @@ bool TMoverParameters::AutoRelayCheck(void)
// Ra 2014-06: dla SN61 nie działa prawidłowo
// rozlaczanie stycznikow liniowych
if ((!Mains) || (FuseFlag) || (MainCtrlPos == 0) ||
((BrakePress > 2.1) && (TrainType != dt_EZT)) ||
(ActiveDir == 0)) // hunter-111211: wylacznik cisnieniowy
if( ( false == Mains )
|| ( true == FuseFlag )
|| ( true == StLinSwitchOff )
|| ( MainCtrlPos == 0 )
|| ( ( TrainType != dt_EZT ) && ( BrakePress > 2.1 ) )
|| ( ActiveDir == 0 ) ) // hunter-111211: wylacznik cisnieniowy
{
StLinFlag = false; // yBARC - rozlaczenie stycznikow liniowych
OK = false;
@@ -5267,34 +5277,46 @@ bool TMoverParameters::AutoRelayCheck(void)
&& ( MainCtrlPos > 0 )
&& ( MainCtrlPos != MainCtrlPosNo )
&& ( FastSerialCircuit == 1 ) ) {
// szybkie wchodzenie na bezoporowa (303E)
// MainCtrlActualPos:=MainCtrlPos; //hunter-111012:
++MainCtrlActualPos;
// MainCtrlActualPos:=MainCtrlPos; //hunter-111012:
// szybkie wchodzenie na bezoporowa (303E)
OK = true;
SetFlag(SoundFlag, sound::parallel | sound::loud);
if( MainCtrlPos - MainCtrlActualPos == 1 ) {
// HACK: ensure we play only single sound of basic relays for entire trasition; return false
// for all but last step despite configuration change, to prevent playback of the basic relay sound
// TBD, TODO: move the basic sound event here and enable it with call parameter
OK = true;
}
if( RList[ MainCtrlActualPos ].R == 0 ) {
SetFlag( SoundFlag, sound::parallel | sound::loud );
OK = true;
}
}
else if ((LastRelayTime > CtrlDelay) && (ARFASI))
{
// WriteLog("LRT = " + FloatToStr(LastRelayTime) + ", " +
// FloatToStr(CtrlDelay));
if ((TrainType == dt_ET22) && (MainCtrlPos > 1) &&
((RList[MainCtrlActualPos].Bn < RList[MainCtrlActualPos + 1].Bn) ||
(DelayCtrlFlag))) // et22 z walem grupowym
if (!DelayCtrlFlag) // najpierw przejscie
if( ( TrainType == dt_ET22 )
&& ( MainCtrlPos > 1 )
&& ( ( RList[ MainCtrlActualPos ].Bn < RList[ MainCtrlActualPos + 1 ].Bn )
|| ( DelayCtrlFlag ) ) ) {
// et22 z walem grupowym
if( !DelayCtrlFlag ) // najpierw przejscie
{
++MainCtrlActualPos;
DelayCtrlFlag = true; // tryb przejscia
OK = true;
}
else if (LastRelayTime > 4 * CtrlDelay) // przejscie
else if( LastRelayTime > 4 * CtrlDelay ) // przejscie
{
DelayCtrlFlag = false;
OK = true;
}
/*
else
;
*/
}
else // nie ET22 z wałem grupowym
{
++MainCtrlActualPos;
@@ -5302,30 +5324,33 @@ bool TMoverParameters::AutoRelayCheck(void)
}
//---------
// hunter-111211: poprawki
if (MainCtrlActualPos > 0)
if ((RList[MainCtrlActualPos].R == 0) &&
(!(MainCtrlActualPos == MainCtrlPosNo))) // wejscie na bezoporowa
{
SetFlag(SoundFlag, sound::parallel | sound::loud);
if( MainCtrlActualPos > 0 ) {
if( ( RList[ MainCtrlActualPos ].R == 0 )
&& ( MainCtrlActualPos != MainCtrlPosNo ) ) {
// wejscie na bezoporowa
SetFlag( SoundFlag, sound::parallel | sound::loud );
}
else if ((RList[MainCtrlActualPos].R > 0) &&
(RList[MainCtrlActualPos - 1].R ==
0)) // wejscie na drugi uklad
{
SetFlag(SoundFlag, sound::parallel);
else if( ( RList[ MainCtrlActualPos ].R > 0 )
&& ( RList[ MainCtrlActualPos - 1 ].R == 0 ) ) {
// wejscie na drugi uklad
SetFlag( SoundFlag, sound::parallel );
}
}
}
}
else if (RList[MainCtrlActualPos].Relay > MainCtrlPos)
{
if ((RList[MainCtrlPos].R == 0) && (MainCtrlPos > 0) &&
(!(MainCtrlPos == MainCtrlPosNo)) && (FastSerialCircuit == 1))
{
if( ( RList[ MainCtrlPos ].R == 0 )
&& ( MainCtrlPos > 0 )
&& ( !( MainCtrlPos == MainCtrlPosNo ) )
&& ( FastSerialCircuit == 1 ) ) {
// szybkie wchodzenie na bezoporowa (303E)
// MainCtrlActualPos:=MainCtrlPos; //hunter-111012:
--MainCtrlActualPos;
// MainCtrlActualPos:=MainCtrlPos; //hunter-111012:
// szybkie wchodzenie na bezoporowa (303E)
OK = true;
SetFlag(SoundFlag, sound::parallel);
if( RList[ MainCtrlActualPos ].R == 0 ) {
SetFlag( SoundFlag, sound::parallel );
}
}
else if (LastRelayTime > CtrlDownDelay)
{
@@ -6095,52 +6120,55 @@ bool TMoverParameters::ChangeOffsetH(double DeltaOffset)
// *************************************************************************************************
std::string TMoverParameters::EngineDescription(int what)
{
std::string outstr;
outstr = "";
switch (what)
{
case 0:
{
if (DamageFlag == 255)
std::string outstr { "OK" };
switch (what) {
case 0: {
if( DamageFlag == 255 ) {
outstr = "WRECKED";
else
{
if (TestFlag(DamageFlag, dtrain_thinwheel))
if (Power > 0.1)
}
else {
if( TestFlag( DamageFlag, dtrain_thinwheel ) ) {
if( Power > 0.1 )
outstr = "Thin wheel";
else
outstr = "Load shifted";
if (TestFlag(DamageFlag, dtrain_wheelwear))
}
if( ( WheelFlat > 5.0 )
|| ( TestFlag( DamageFlag, dtrain_wheelwear ) ) ) {
outstr = "Wheel wear";
if (TestFlag(DamageFlag, dtrain_bearing))
}
if( TestFlag( DamageFlag, dtrain_bearing ) ) {
outstr = "Bearing damaged";
if (TestFlag(DamageFlag, dtrain_coupling))
}
if( TestFlag( DamageFlag, dtrain_coupling ) ) {
outstr = "Coupler broken";
if (TestFlag(DamageFlag, dtrain_loaddamage))
if (Power > 0.1)
}
if( TestFlag( DamageFlag, dtrain_loaddamage ) ) {
if( Power > 0.1 )
outstr = "Ventilator damaged";
else
outstr = "Load damaged";
if (TestFlag(DamageFlag, dtrain_loaddestroyed))
if (Power > 0.1)
}
if( TestFlag( DamageFlag, dtrain_loaddestroyed ) ) {
if( Power > 0.1 )
outstr = "Engine damaged";
else
outstr = "LOAD DESTROYED";
if (TestFlag(DamageFlag, dtrain_axle))
}
if( TestFlag( DamageFlag, dtrain_axle ) ) {
outstr = "Axle broken";
if (TestFlag(DamageFlag, dtrain_out))
}
if( TestFlag( DamageFlag, dtrain_out ) ) {
outstr = "DERAILED";
if (outstr == "")
outstr = "OK";
}
}
break;
}
default:
default: {
outstr = "Invalid qualifier";
break;
}
}
return outstr;
}
@@ -6969,6 +6997,7 @@ void TMoverParameters::LoadFIZ_Param( std::string const &line ) {
std::map<std::string, int> types{
{ "pseudodiesel", dt_PseudoDiesel },
{ "ezt", dt_EZT },
{ "dmu", dt_DMU },
{ "sn61", dt_SN61 },
{ "et22", dt_ET22 },
{ "et40", dt_ET40 },
@@ -7739,6 +7768,8 @@ void TMoverParameters::LoadFIZ_RList( std::string const &Input ) {
RVentnmax /= 60.0;
extract_value( RVentCutOff, "RVentCutOff", Input, "" );
}
extract_value( RVentMinI, "RVentMinI", Input, "" );
extract_value( RVentSpeed, "RVentSpeed", Input, "" );
}
void TMoverParameters::LoadFIZ_DList( std::string const &Input ) {
@@ -8093,7 +8124,10 @@ bool TMoverParameters::CheckLocomotiveParameters(bool ReadyFlag, int Dir)
{
WriteLog( "Ready to depart" );
CompressedVolume = VeselVolume * MinCompressor * ( 9.8 ) / 10.0;
ScndPipePress = CompressedVolume / VeselVolume;
ScndPipePress = (
VeselVolume > 0.0 ?
CompressedVolume / VeselVolume :
0.0 );
PipePress = CntrlPipePress;
BrakePress = 0.0;
LocalBrakePos = 0;
@@ -8598,8 +8632,6 @@ bool TMoverParameters::RunCommand( std::string Command, double CValue1, double C
if( true == Hamulec->SetBDF( brakesetting ) ) {
BrakeDelayFlag = brakesetting;
OK = true;
// if setting was changed emit the sound of pneumatic relay
SetFlag( SoundFlag, sound::pneumatic );
}
else {
OK = false;

View File

@@ -20,7 +20,6 @@ http://mozilla.org/MPL/2.0/.
#include <memory>
#include "hamulce.h" // Pascal unit
#include "friction.h" // Pascal unit
#include "mctools.h" // Pascal unit
/*
(C) youBy

View File

@@ -16,7 +16,7 @@ Copyright (C) 2007-2014 Maciej Cierniak
#include "hamulce.h"
#include <typeinfo>
#include "MOVER.h"
#include "usefull.h"
#include "utilities.h"
//---FUNKCJE OGOLNE---

View File

@@ -35,7 +35,6 @@ Knorr/West EP - żeby był
#pragma once
#include "friction.h" // Pascal unit
#include "mctools.h" // Pascal unit
static int const LocalBrakePosNo = 10; /*ilosc nastaw hamulca recznego lub pomocniczego*/
static int const MainBrakeMaxPos = 10; /*max. ilosc nastaw hamulca zasadniczego*/
@@ -514,7 +513,7 @@ class TDriverHandle {
virtual double GetPos(int i);
virtual double GetEP(double pos);
inline TDriverHandle() { memset(Sounds, 0, sizeof(Sounds)); }
inline TDriverHandle() { memset( Sounds, 0, sizeof( Sounds ) ); }
};
class TFV4a : public TDriverHandle {

View File

@@ -1,306 +0,0 @@
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
/*
MaSzyna EU07 - SPKS
Brakes.
Copyright (C) 2007-2014 Maciej Cierniak
*/
#include "stdafx.h"
#include "mctools.h"
#include <sys/types.h>
#include <sys/stat.h>
#ifndef WIN32
#include <unistd.h>
#endif
#ifdef WIN32
#define stat _stat
#endif
#include "Globals.h"
/*================================================*/
bool DebugModeFlag = false;
bool FreeFlyModeFlag = false;
bool EditorModeFlag = true;
bool DebugCameraFlag = false;
double Max0R(double x1, double x2)
{
if (x1 > x2)
return x1;
else
return x2;
}
double Min0R(double x1, double x2)
{
if (x1 < x2)
return x1;
else
return x2;
}
// shitty replacement for Borland timestamp function
// TODO: replace with something sensible
std::string Now() {
std::time_t timenow = std::time( nullptr );
std::tm tm = *std::localtime( &timenow );
std::stringstream converter;
converter << std::put_time( &tm, "%c" );
return converter.str();
}
bool SetFlag( int &Flag, int const Value ) {
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 jest ujemne, czyli zerowanie flagi
return ClearFlag( Flag, -Value );
}
return false;
}
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)
{
std::uniform_real_distribution<> dis(a, b);
return dis(Global::random_engine);
}
bool FuzzyLogic(double Test, double Threshold, double Probability)
{
if ((Test > Threshold) && (!DebugModeFlag))
return
(Random() < Probability * Threshold * 1.0 / Test) /*im wiekszy Test tym wieksza szansa*/;
else
return false;
}
bool FuzzyLogicAI(double Test, double Threshold, double Probability)
{
if ((Test > Threshold))
return
(Random() < Probability * Threshold * 1.0 / Test) /*im wiekszy Test tym wieksza szansa*/;
else
return false;
}
std::string DUE(std::string s) /*Delete Before Equal sign*/
{
//DUE = Copy(s, Pos("=", s) + 1, length(s));
return s.substr(s.find("=") + 1, s.length());
}
std::string DWE(std::string s) /*Delete After Equal sign*/
{
size_t ep = s.find("=");
if (ep != std::string::npos)
//DWE = Copy(s, 1, ep - 1);
return s.substr(0, ep);
else
return s;
}
std::string ExchangeCharInString( std::string const &Source, char const From, char const To )
{
std::string replacement; replacement.reserve( Source.size() );
std::for_each(
std::begin( Source ), std::end( Source ),
[&](char const idx) {
if( idx != From ) { replacement += idx; }
else { replacement += To; } } );
return replacement;
}
std::vector<std::string> &Split(const std::string &s, char delim, std::vector<std::string> &elems)
{ // dzieli tekst na wektor tekstow
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim))
{
elems.push_back(item);
}
return elems;
}
std::vector<std::string> Split(const std::string &s, char delim)
{ // dzieli tekst na wektor tekstow
std::vector<std::string> elems;
Split(s, delim, elems);
return elems;
}
std::vector<std::string> Split(const std::string &s)
{ // dzieli tekst na wektor tekstow po białych znakach
std::vector<std::string> elems;
std::stringstream ss(s);
std::string item;
while (ss >> item)
{
elems.push_back(item);
}
return elems;
}
std::string to_string(int _Val)
{
std::ostringstream o;
o << _Val;
return o.str();
};
std::string to_string(unsigned int _Val)
{
std::ostringstream o;
o << _Val;
return o.str();
};
std::string to_string(double _Val)
{
std::ostringstream o;
o << _Val;
return o.str();
};
std::string to_string(int _Val, int precision)
{
std::ostringstream o;
o << std::fixed << std::setprecision(precision);
o << _Val;
return o.str();
};
std::string to_string(double _Val, int precision)
{
std::ostringstream o;
o << std::fixed << std::setprecision(precision);
o << _Val;
return o.str();
};
std::string to_string(int _Val, int precision, int width)
{
std::ostringstream o;
o.width(width);
o << std::fixed << std::setprecision(precision);
o << _Val;
return o.str();
};
std::string to_string(double const Value, int const Precision, int const Width)
{
std::ostringstream converter;
converter << std::setw( Width ) << std::fixed << std::setprecision(Precision) << Value;
return converter.str();
};
std::string to_hex_str( int const Value, int const Width )
{
std::ostringstream converter;
converter << "0x" << std::uppercase << std::setfill( '0' ) << std::setw( Width ) << std::hex << Value;
return converter.str();
};
int stol_def(const std::string &str, const int &DefaultValue) {
int result { DefaultValue };
std::stringstream converter;
converter << str;
converter >> result;
return result;
}
std::string ToLower(std::string const &text)
{
std::string lowercase( text );
std::transform(text.begin(), text.end(), lowercase.begin(), ::tolower);
return lowercase;
}
std::string ToUpper(std::string const &text)
{
std::string uppercase( text );
std::transform(text.begin(), text.end(), uppercase.begin(), ::toupper);
return uppercase;
}
// replaces polish letters with basic ascii
void
win1250_to_ascii( std::string &Input ) {
std::unordered_map<char, char> charmap{
{ 165, 'A' }, { 198, 'C' }, { 202, 'E' }, { 163, 'L' }, { 209, 'N' }, { 211, 'O' }, { 140, 'S' }, { 143, 'Z' }, { 175, 'Z' },
{ 185, 'a' }, { 230, 'c' }, { 234, 'e' }, { 179, 'l' }, { 241, 'n' }, { 243, 'o' }, { 156, 's' }, { 159, 'z' }, { 191, 'z' }
};
std::unordered_map<char, char>::const_iterator lookup;
for( auto &input : Input ) {
if( ( lookup = charmap.find( input ) ) != charmap.end() )
input = lookup->second;
}
}
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
}
}
bool FileExists( std::string const &Filename ) {
std::string fn = Filename;
std::replace(fn.begin(), fn.end(), '\\', '/');
std::ifstream file( fn );
return( true == file.is_open() );
}
// returns time of last modification for specified file
std::time_t
last_modified( std::string const &Filename ) {
std::string fn = Filename;
std::replace(fn.begin(), fn.end(), '\\', '/');
struct stat filestat;
if( ::stat( fn.c_str(), &filestat ) == 0 )
return filestat.st_mtime;
else
return 0;
}

View File

@@ -1,164 +0,0 @@
#pragma once
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
/*rozne takie duperele do operacji na stringach w paszczalu, pewnie w delfi sa lepsze*/
/*konwersja zmiennych na stringi, funkcje matematyczne, logiczne, lancuchowe, I/O etc*/
#include <string>
#include <fstream>
#include <ctime>
#include <vector>
#include <sstream>
extern bool DebugModeFlag;
extern bool FreeFlyModeFlag;
extern bool EditorModeFlag;
extern bool DebugCameraFlag;
/*funkcje matematyczne*/
double Max0R(double x1, double x2);
double Min0R(double x1, double x2);
inline double Sign(double x)
{
return x >= 0 ? 1.0 : -1.0;
}
inline long Round(double const f)
{
return (long)(f + 0.5);
//return lround(f);
}
extern double Random(double a, double b);
inline double Random()
{
return Random(0.0,1.0);
}
inline double Random(double b)
{
return Random(0.0, b);
}
inline double BorlandTime()
{
auto timesinceepoch = std::time( nullptr );
return timesinceepoch / (24.0 * 60 * 60);
/*
// std alternative
auto timesinceepoch = std::chrono::system_clock::now().time_since_epoch();
return std::chrono::duration_cast<std::chrono::seconds>( timesinceepoch ).count() / (24.0 * 60 * 60);
*/
}
std::string Now();
/*funkcje logiczne*/
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*/
bool FuzzyLogicAI(double Test, double Threshold, double Probability);
/*to samo ale zawsze niezaleznie od DebugFlag*/
/*operacje na stringach*/
std::string DUE(std::string s); /*Delete Until Equal sign*/
std::string DWE(std::string s); /*Delete While Equal sign*/
std::string ExchangeCharInString( std::string const &Source, char const From, char const To ); // zamienia jeden znak na drugi
std::vector<std::string> &Split(const std::string &s, char delim, std::vector<std::string> &elems);
std::vector<std::string> Split(const std::string &s, char delim);
//std::vector<std::string> Split(const std::string &s);
std::string to_string(int _Val);
std::string to_string(unsigned int _Val);
std::string to_string(int _Val, int precision);
std::string to_string(int _Val, int precision, int width);
std::string to_string(double _Val);
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) {
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);
std::string ToUpper(std::string const &text);
// replaces polish letters with basic ascii
void win1250_to_ascii( std::string &Input );
inline
std::string
extract_value( std::string const &Key, std::string const &Input ) {
// NOTE, HACK: the leading space allows to uniformly look for " variable=" substring
std::string const input { " " + 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() + 2 ) );
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 );
// returns time of last modification for specified file
std::time_t last_modified( std::string const &Filename );