16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 15:09:19 +02:00

removed dependencies on the old parser. The code can now be compiled outside of Borland C++

This commit is contained in:
tmj-fstate
2017-01-15 15:04:17 +01:00
parent 7df7c8b76e
commit 15cf3d73a8
87 changed files with 3395 additions and 3232 deletions

View File

@@ -7,16 +7,11 @@ obtain one at
http://mozilla.org/MPL/2.0/.
*/
#ifndef MoverH
#define MoverH
#pragma once
//---------------------------------------------------------------------------
//#include "Mover.hpp" //Q: 20160805 - odlaczenie pliku fizyki .pas od kompilacji
#include "Oerlikon_ESt.h"
#include "hamulce.h"
#include <string>
#include "mctools.h"
//Q: 20160805 - odlaczenie pliku fizyki .pas od kompilacji
#include <map>
#include "hamulce.h"
/*
MaSzyna EU07 locomotive simulator
Copyright (C) 2001-2004 Maciej Czapkiewicz and others
@@ -247,60 +242,43 @@ enum TProblem // lista problem
};
/*ogolne*/
/*lokacja*/
struct TLocation
{
double X;
double Y;
double Z; /*lokacja*/
inline TLocation() {
X, Y, Z = 0.0;
}
double X = 0.0;
double Y = 0.0;
double Z = 0.0;
};
/*rotacja*/
struct TRotation
{
double Rx;
double Ry;
double Rz; /*rotacja*/
inline TRotation() {
Rx, Ry, Rz = 0.0;
}
double Rx = 0.0;
double Ry = 0.0;
double Rz = 0.0;
};
/*wymiary*/
struct TDimension
{
double W;
double L;
double H; /*wymiary*/
inline TDimension()
{
W = 0.0;
L = 0.0;
H = 0.0;
}
double W = 0.0;
double L = 0.0;
double H = 0.0;
};
struct TCommand
{
std::string Command; /*komenda*/
double Value1;
double Value2; /*argumenty komendy*/
double Value1 = 0.0; /*argumenty komendy*/
double Value2 = 0.0;
TLocation Location;
inline TCommand() {
Command = "";
Value1, Value2 = 0.0;
Location = TLocation();
}
};
/*tory*/
struct TTrackShape
{/*ksztalt odcinka - promien, dlugosc, nachylenie, przechylka*/
double R;
double Len;
double dHtrack;
double dHrail;
inline TTrackShape() {
R, Len, dHrail, dHtrack = 0.0;
}
{/*ksztalt odcinka*/
double R = 0.0; // promien
double Len = 0.0; // dlugosc
double dHtrack = 0.0; // nachylenie
double dHrail = 0.0; // przechylka
};
struct TTrackParam
@@ -977,8 +955,8 @@ public:
TMoverParameters(double VelInitial, std::string TypeNameInit, std::string NameInit, int LoadInitial, std::string LoadTypeInitial, int Cab);
// obsługa sprzęgów
double Distance(const TLocation &Loc1, const TLocation &Loc2, const TDimension &Dim1, const TDimension &Dim2);
double Distance(const vector3 &Loc1, const vector3 &Loc2, const vector3 &Dim1, const vector3 &Dim2);
//bool AttachA(int ConnectNo, int ConnectToNr, TMoverParameters *ConnectTo, int CouplingType, bool Forced = false);
/* double Distance(const vector3 &Loc1, const vector3 &Loc2, const vector3 &Dim1, const vector3 &Dim2);
*/ //bool AttachA(int ConnectNo, int ConnectToNr, TMoverParameters *ConnectTo, int CouplingType, bool Forced = false);
bool Attach(int ConnectNo, int ConnectToNr, TMoverParameters *ConnectTo, int CouplingType, bool Forced = false);
int DettachStatus(int ConnectNo);
bool Dettach(int ConnectNo);
@@ -1146,5 +1124,3 @@ public:
};
extern double Distance(TLocation Loc1, TLocation Loc2, TDimension Dim1, TDimension Dim2);
#endif

View File

@@ -7,28 +7,12 @@ obtain one at
http://mozilla.org/MPL/2.0/.
*/
#include <MATH.H>
#include <FLOAT.H>
#include <typeinfo>
#include <fstream> // std::ifstream
#include <sstream>
#include <istream>
#include <iostream>
#include <stdio.h> // sprintf()
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <stdio.h>
#include "stdafx.h"
#include "Mover.h"
#include "../globals.h"
//#include "../qutils.h"
#include "mctools.h"
#include "../logs.h"
#include "hamulce.h"
#include "Oerlikon_ESt.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
// 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ć.
@@ -753,13 +737,13 @@ double TMoverParameters::Distance(const TLocation &Loc1, const TLocation &Loc2,
{ // zwraca odległość pomiędzy pojazdami (Loc1) i (Loc2) z uwzględnieneim ich długości (kule!)
return hypot(Loc2.X - Loc1.X, Loc1.Y - Loc2.Y) - 0.5 * (Dim2.L + Dim1.L);
};
/*
double TMoverParameters::Distance(const vector3 &s1, const vector3 &s2, const vector3 &d1,
const vector3 &d2){
// obliczenie odległości prostopadłościanów o środkach (s1) i (s2) i wymiarach (d1) i (d2)
// return 0.0; //będzie zgłaszać warning - funkcja do usunięcia, chyba że się przyda...
};
*/
double TMoverParameters::CouplerDist(int Coupler)
{ // obliczenie odległości pomiędzy sprzęgami (kula!)
return Couplers[Coupler].CoupleDist =
@@ -1417,7 +1401,6 @@ double TMoverParameters::ComputeMovement(double dt, double dt1, const TTrackShap
HVCouplers[0][0] = 0;
HVCouplers[1][0] = 0;
}
ClearPendingExceptions(); // ma byc
if (!TestFlag(DamageFlag, dtrain_out))
{ // Ra: to przepisywanie tu jest bez sensu
@@ -1620,8 +1603,6 @@ double TMoverParameters::FastComputeMovement(double dt, const TTrackShape &Shape
int b;
// T_MoverParameters::FastComputeMovement(dt, Shape, Track, NewLoc, NewRot);
ClearPendingExceptions(); // nie bylo
Loc = NewLoc;
Rot = NewRot;
NewRot.Rx = 0.0;
@@ -5237,7 +5218,7 @@ bool TMoverParameters::PantFront(bool State)
bool TMoverParameters::PantRear(bool State)
{
double pf1;
bool PR;
bool PR = false;
if (Battery == true)
{
@@ -5854,7 +5835,7 @@ std::string tS(std::string val)
int Pos(std::string str_find, std::string in)
{
size_t pos = in.find(str_find);
return (pos != string::npos ? pos+1 : 0);
return (pos != std::string::npos ? pos+1 : 0);
}
// *************************************************************************************************
@@ -5863,7 +5844,7 @@ int Pos(std::string str_find, std::string in)
bool issection(std::string name)
{
sectionname = name;
if (xline.find(name) != string::npos)
if (xline.find(name) != std::string::npos)
{
lastsectionname = name;
return true;
@@ -5890,7 +5871,7 @@ std::string getkeyval(int rettype, std::string key)
int klen = key.length();
int kpos = Pos(key, xline) - 1;
temp.erase(0, kpos + klen);
if (temp.find(" ") != string::npos)
if (temp.find(" ") != std::string::npos)
to = temp.find(" ");
else
to = 255;
@@ -5919,7 +5900,7 @@ int MARKERROR(int code, std::string type, std::string msg)
return code;
}
int s2NPW(string s)
int s2NPW(std::string s)
{ // wylicza ilosc osi napednych z opisu ukladu osi
const char A = 64;
int k;
@@ -5932,7 +5913,7 @@ int s2NPW(string s)
return NPW;
}
int s2NNW(string s)
int s2NNW(std::string s)
{ // wylicza ilosc osi nienapedzanych z opisu ukladu osi
const char Zero = 48;
int k;
@@ -5995,7 +5976,7 @@ bool TMoverParameters::readMPT(int ln, std::string line)
// parsowanie RList
bool TMoverParameters::readRLIST(int ln, std::string line)
{
char *xxx;
char *xxx = nullptr;
startRLIST = true;
if (ln > 0) // 0 to nazwa sekcji - RList:
@@ -6046,7 +6027,7 @@ bool TMoverParameters::readRLIST(int ln, std::string line)
// parsowanie Brake Param Table
bool TMoverParameters::readBPT(int ln, std::string line)
{
char *xxx;
char *xxx = nullptr;
startBPT = true;
int k;
@@ -6342,7 +6323,7 @@ bool TMoverParameters::LoadFIZ(std::string chkpath)
int b, OKFlag;
std::string lines, s, appdir;
std::string APPDIR, filetocheck, line, node, key, file, CERR;
string wers;
std::string wers;
bool noexist = false;
bool OK;
@@ -6362,7 +6343,7 @@ bool TMoverParameters::LoadFIZ(std::string chkpath)
// appdir = ExtractFilePath(ParamStr(0));
ifstream in(file.c_str());
std::ifstream in(file.c_str());
if (!in.is_open())
{
WriteLog("E8 - FIZ FILE NOT EXIST.");
@@ -6385,7 +6366,7 @@ bool TMoverParameters::LoadFIZ(std::string chkpath)
xline = wers.c_str();
ishash = xline.find("#");
// if ((ishash == 1)) WriteLog("zakomentowane " + xline);
if ((ishash == string::npos))
if ((ishash == std::string::npos))
{
if (xline.length() == 0)
@@ -7685,7 +7666,6 @@ bool TMoverParameters::RunCommand(std::string Command, double CValue1, double CV
bool OK;
std::string testload;
OK = false;
ClearPendingExceptions();
if (Command == "MainCtrl")
{

View File

@@ -12,8 +12,8 @@ Brakes. Oerlikon ESt.
Copyright (C) 2007-2014 Maciej Cierniak
*/
#include "stdafx.h"
#include "Oerlikon_ESt.h"
#include <typeinfo>
double d2A(double d)
{

View File

@@ -12,8 +12,8 @@ Friction coefficient.
Copyright (C) 2007-2013 Maciej Cierniak
*/
#include "stdafx.h"
#include "friction.h"
#include <math.h>
double TFricMat::GetFC(double N, double Vel)
{

View File

@@ -12,10 +12,10 @@ Brakes. Oerlikon ESt.
Copyright (C) 2007-2014 Maciej Cierniak
*/
#include "stdafx.h"
#include "hamulce.h"
#include "Mover.h"
#include <cmath>
#include <typeinfo>
#include "Mover.h"
//---FUNKCJE OGOLNE---
@@ -82,11 +82,6 @@ double PF1(double P1, double P2, double S)
return FM;
}
long lround(double value)
{
return floorl(value + 0.5);
}
double PFVa(double PH, double PL, double S, double LIM,
double DP) // zawor napelniajacy z PH do PL, PL do LIM
{
@@ -252,7 +247,7 @@ TBrake::TBrake(double i_mbp, double i_bcr, double i_bcd, double i_brc, int i_bcn
MaxBP = i_mbp;
BCN = i_bcn;
BCM = 1;
BCA = i_bcn * i_bcr * i_bcr * pi;
BCA = i_bcn * i_bcr * i_bcr * M_PI;
BA = i_ba;
NBpA = i_nbpa;
BrakeDelays = i_BD;

View File

@@ -835,8 +835,6 @@ Knorr/West EP -
extern double PFVa(double PH, double PL, double S, double LIM, double DP = 0.1); //zawor napelniajacy z PH do PL, PL do LIM
extern double PFVd(double PH, double PL, double S, double LIM, double DP = 0.1); //zawor wypuszczajacy z PH do PL, PH do LIM
extern long lround(double value); //zastepuje funkcje nieobecna w C++99
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
#endif
#endif//INCLUDED_HAMULCE_H

View File

@@ -11,15 +11,9 @@ MaSzyna EU07 - SPKS
Brakes.
Copyright (C) 2007-2014 Maciej Cierniak
*/
#include "stdafx.h"
#include "mctools.h"
#include <cmath>
#include <fstream>
#include <cctype>
#include <ostream>
#include <iomanip>
#include <algorithm>
using namespace std;
/*================================================*/
int ConversionError = 0;
@@ -73,6 +67,31 @@ double Min0R(double x1, double x2)
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;
std::string output;
converter << std::put_time( &tm, "%c" );
converter >> output;
return output;
/* char buffer[ 256 ];
sprintf( buffer,
"%d-%02d-%02d %02d:%02d:%02d.%03d",
st.wYear,
st.wMonth,
st.wDay,
st.wHour,
st.wMinute,
st.wSecond,
st.wMilliseconds );
*/
}
bool TestFlag(int Flag, int Value)
{
if ((Flag & Value) == Value)
@@ -141,10 +160,10 @@ std::string ReadWord(std::ifstream& infile)
while ((!infile.eof()) && (!nextword))
{
infile.get(c);
if (_spacesigns.find(c) != string::npos)
if (_spacesigns.find(c) != std::string::npos)
if (s != "")
nextword = true;
if (_spacesigns.find(c) == string::npos)
if (_spacesigns.find(c) == std::string::npos)
s += c;
}
return s;
@@ -181,7 +200,7 @@ std::string TrimSpace(std::string &s, int Just)
if (s.empty())
return "";
size_t first = s.find_first_not_of(' ');
if (first == string::npos)
if (first == std::string::npos)
return "";
size_t last = s.find_last_not_of(' ');
return s.substr(first, (last - first + 1));
@@ -193,7 +212,7 @@ char* TrimAndReduceSpaces(const char* s)
if (s)
{
tmp = strdup(s);
tmp = _strdup(s);
char* from = tmp + strspn(tmp, " ");
char* to = tmp;
@@ -212,7 +231,7 @@ std::string ExtractKeyWord(std::string InS, std::string KeyWord)
std::string s;
InS = InS + " ";
std::size_t kwp = InS.find(KeyWord);
if (kwp != string::npos)
if (kwp != std::string::npos)
{
s = InS.substr(kwp, InS.length());
//s = Copy(InS, kwp, length(InS));
@@ -233,30 +252,30 @@ std::string DUE(std::string s) /*Delete Before Equal sign*/
std::string DWE(std::string s) /*Delete After Equal sign*/
{
size_t ep = s.find("=");
if (ep != string::npos)
if (ep != std::string::npos)
//DWE = Copy(s, 1, ep - 1);
return s.substr(0, ep);
else
return s;
}
std::string Ld2Sp(std::string s) /*Low dash to Space sign*/
std::string Ld2Sp(std::string const &s) /*Low dash to Space sign*/
{
//std::string s2 = "";
char tmp[] = { (char)"_", (char)" " };
for (int b = 0; b < s.length(); ++b)
if (s[b] == tmp[0])
s[b] = tmp[1];
std::string s2( s );
char tmp[] = { '_', ' ' };
for (int b = 0; b < s2.length(); ++b)
if (s2[b] == tmp[0])
s2[b] = tmp[1];
//{
// if (s[b] == tmp[0])
// s2 = s2 + " ";
// else
// s2 = s2 + s[b];
//}
// return s2;
return s2;
}
std::string Tab2Sp(std::string s) /*Tab to Space sign*/
std::string Tab2Sp(std::string const &s) /*Tab to Space sign*/
{
std::string s2 = "";
char tmp = (char)9;
@@ -275,7 +294,7 @@ std::string Tab2Sp(std::string s) /*Tab to Space sign*/
return s2;
}
std::string ExchangeCharInString(string s, const char &aim, const char &target)
std::string ExchangeCharInString(std::string s, const char &aim, const char &target)
{
char *tmp = new char[s.length()];
for (int b = 0; b < s.length(); ++b)
@@ -288,7 +307,7 @@ std::string ExchangeCharInString(string s, const char &aim, const char &target)
else
tmp[b] = s[b];
}
return string(tmp);
return std::string(tmp);
}
std::vector<std::string> &Split(const std::string &s, char delim, std::vector<std::string> &elems)
@@ -411,16 +430,18 @@ int stol_def(const std::string &str, const int &DefaultValue)
return result;
}
std::string ToLower(std::string text)
std::string ToLower(std::string const &text)
{
std::transform(text.begin(), text.end(), text.begin(), ::tolower);
return text;
std::string lowercase( text );
std::transform(text.begin(), text.end(), lowercase.begin(), ::tolower);
return lowercase;
}
std::string ToUpper(std::string text)
std::string ToUpper(std::string const &text)
{
std::transform(text.begin(), text.end(), text.begin(), ::toupper);
return text;
std::string uppercase( text );
std::transform(text.begin(), text.end(), uppercase.begin(), ::toupper);
return uppercase;
}
void ComputeArc(double X0, double Y0, double Xn, double Yn, double R, double L, double dL,
@@ -443,11 +464,11 @@ void ComputeArc(double X0, double Y0, double Xn, double Yn, double R, double L,
if (dX != 0)
gamma = atan(dY * 1.0 / dX);
else if (dY > 0)
gamma = pi * 1.0 / 2;
gamma = M_PI * 1.0 / 2;
else
gamma = 3 * pi * 1.0 / 2;
gamma = 3 * M_PI * 1.0 / 2;
alfa = L * 1.0 / R;
phi = gamma - (alfa + pi * Round(R * 1.0 / AbsR)) * 1.0 / 2;
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;
@@ -471,16 +492,24 @@ void ComputeALine(double X0, double Y0, double Xn, double Yn, double L, double R
if (dX != 0)
gamma = atan(dY * 1.0 / dX);
else if (dY > 0)
gamma = pi * 1.0 / 2;
gamma = M_PI * 1.0 / 2;
else
gamma = 3 * pi * 1.0 / 2;
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);
}
/*graficzne:*/
bool FileExists( std::string const &Filename ) {
std::ifstream file( Filename );
if( file.is_open() == false ) { return false; }
else { return true; }
}
/*
//graficzne:
double Xhor(double h)
{
@@ -515,7 +544,9 @@ long Vert(double Y)
else
return -INT_MAX;
}
*/
// NOTE: this now does nothing.
void ClearPendingExceptions()
// resetuje b³êdy FPU, wymagane dla Trunc()
{
@@ -525,4 +556,3 @@ void ClearPendingExceptions()
}
// END

View File

@@ -1,7 +1,4 @@
#pragma once
#ifndef INCLUDED_MCTOOLS_H
#define INCLUDED_MCTOOLS_H
/*
This Source Code Form is subject to the
@@ -17,13 +14,11 @@ http://mozilla.org/MPL/2.0/.
#include <string>
#include <fstream>
#include <time.h>
#include <ctime>
#include <sys/stat.h>
#include <vector>
#include <sstream>
using namespace std;
/*Ra: te sta³e nie s¹ u¿ywane...
_FileName = ['a'..'z','A'..'Z',':','\','.','*','?','0'..'9','_','-'];
_RealNum = ['0'..'9','-','+','.','E','e'];
@@ -34,13 +29,11 @@ using namespace std;
_Delimiter_Space=_Delimiter+[' '];
*/
static char _EOL[2] = { (char)13, (char)10 };
//static char const _SPACE = " ";
static char _Spacesigns[4] = { (char)" ",(char)9, (char)13, (char)10};
static string _spacesigns = " " + (char)9 + (char)13 + (char)10;
static char _Spacesigns[4] = { (char)' ', (char)9, (char)13, (char)10 };
static std::string _spacesigns = " " + (char)9 + (char)13 + (char)10;
static int const CutLeft = -1;
static int const CutRight = 1;
static int const CutBoth = 0; /*Cut_Space*/
static double const pi = 3.141592653589793;
extern int ConversionError;
extern int LineCount;
@@ -77,14 +70,14 @@ inline long Round(float f)
inline int Random()
{
srand(time(NULL));
return rand();
std::srand(std::time(NULL));
return std::rand();
}
inline double Random(double a, double b)
{
srand(time(NULL));
return a + rand() / (float)RAND_MAX * (b - a);
std::srand(std::time(NULL));
return a + std::rand() / (float)RAND_MAX * (b - a);
}
inline double Random(double b)
@@ -92,16 +85,6 @@ inline double Random(double b)
return Random(0.0, b);
}
inline double abs(double _val)
{
return _val < 0 ? -_val : _val;
}
inline long abs(long _val)
{
return _val < 0 ? -_val : _val;
}
inline double BorlandTime()
{
std::tm epoch;
@@ -116,6 +99,8 @@ inline double BorlandTime()
return (difftime(raw_t, basetime) / 24) + 2;
}
std::string Now();
/*funkcje logiczne*/
extern bool TestFlag(int Flag, int Value);
extern bool SetFlag( int & Flag, int Value);
@@ -135,9 +120,9 @@ char* TrimAndReduceSpaces(const char* s);
std::string ExtractKeyWord(std::string InS, std::string KeyWord); /*wyciaga slowo kluczowe i lancuch do pierwszej spacji*/
std::string DUE(std::string s); /*Delete Until Equal sign*/
std::string DWE(std::string s); /*Delete While Equal sign*/
std::string Ld2Sp(std::string s); /*Low dash to Space sign*/
std::string Tab2Sp(std::string s); /*Tab to Space sign*/
std::string ExchangeCharInString(string s, const char &aim, const char &target); // zamienia jeden znak na drugi
std::string Ld2Sp(std::string const &s); /*Low dash to Space sign*/
std::string Tab2Sp(std::string const &s); /*Tab to Space sign*/
std::string ExchangeCharInString(std::string s, const char &aim, const char &target); // 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);
@@ -152,25 +137,26 @@ std::string to_string(double _Val, int precision, int width);
std::string to_hex_str(double _Val, int precision = 0, int width = 0);
inline std::string to_string(bool _Val)
{
return to_string((int)_Val);
return _Val == true ? "true" : "false";
}
int stol_def(const std::string & str, const int & DefaultValue);
std::string ToLower(std::string text);
std::string ToUpper(std::string text);
std::string ToLower(std::string const &text);
std::string ToUpper(std::string const &text);
/*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);
}
}*/
bool FileExists( std::string const &Filename );
/*
extern double Xmin;
extern double Ymin;
extern double Xmax;
@@ -182,20 +168,17 @@ extern double Vstep;
extern int Vsize;
extern int Hsize;
double Xhor( double h);
/* Converts horizontal screen coordinate into real X-coordinate. */
double Yver( double v);
/* Converts vertical screen coordinate into real Y-coordinate. */
// 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();
/*------------------------------------------------*/
#endif//INCLUDED_MCTOOLS_H
//END