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

partial replacement of char arrays with std::string; minor updates, fixes and cleanup of mctools

This commit is contained in:
tmj-fstate
2017-01-29 18:12:18 +01:00
parent c3d79e29e2
commit 3c0edb3ec3
10 changed files with 211 additions and 132 deletions

View File

@@ -319,7 +319,7 @@ std::string TSpeedPos::TableText()
if (iFlags & spEnabled) if (iFlags & spEnabled)
{ // o ile pozycja istotna { // o ile pozycja istotna
return "Flags=" + to_hex_str(iFlags, 6) + ", Dist=" + to_string(fDist, 1, 7) + return "Flags=" + to_hex_str(iFlags, 6) + ", Dist=" + to_string(fDist, 1, 7) +
", Vel=" + to_string(fVelNext, 1, 5) + ", Name=" + GetName(); ", Vel=" + (fVelNext == -1.0 ? " * " : to_string(fVelNext, 1, 5)) + ", Name=" + GetName();
//if (iFlags & spTrack) // jeśli tor //if (iFlags & spTrack) // jeśli tor
// return "Flags=#" + IntToHex(iFlags, 8) + ", Dist=" + FloatToStrF(fDist, ffFixed, 7, 1) + // return "Flags=#" + IntToHex(iFlags, 8) + ", Dist=" + FloatToStrF(fDist, ffFixed, 7, 1) +
// ", Vel=" + AnsiString(fVelNext) + ", Track=" + trTrack->NameGet(); // ", Vel=" + AnsiString(fVelNext) + ", Track=" + trTrack->NameGet();

View File

@@ -36,19 +36,21 @@ TEventLauncher::TEventLauncher()
DeltaTime = -1; DeltaTime = -1;
UpdatedTime = 0; UpdatedTime = 0;
fVal1 = fVal2 = 0; fVal1 = fVal2 = 0;
#ifdef EU07_USE_OLD_TEVENTLAUNCHER_TEXT_ARRAY
szText = NULL; szText = NULL;
#endif
iHour = iMinute = -1; // takiego czasu nigdy nie będzie iHour = iMinute = -1; // takiego czasu nigdy nie będzie
dRadius = 0; dRadius = 0;
Event1 = Event2 = NULL; Event1 = Event2 = NULL;
MemCell = NULL; MemCell = NULL;
iCheckMask = 0; iCheckMask = 0;
} }
#ifdef EU07_USE_OLD_TEVENTLAUNCHER_TEXT_ARRAY
TEventLauncher::~TEventLauncher() TEventLauncher::~TEventLauncher()
{ {
SafeDeleteArray(szText); SafeDeleteArray(szText);
} }
#endif
void TEventLauncher::Init() void TEventLauncher::Init()
{ {
} }
@@ -105,17 +107,20 @@ bool TEventLauncher::Load(cParser *parser)
asMemCellName = token; asMemCellName = token;
parser->getTokens(); parser->getTokens();
*parser >> token; *parser >> token;
#ifdef EU07_USE_OLD_TEVENTLAUNCHER_TEXT_ARRAY
SafeDeleteArray(szText); SafeDeleteArray(szText);
szText = new char[256]; szText = new char[256];
strcpy(szText, token.c_str()); strcpy(szText, token.c_str());
if (token.compare("*") != 0) //*=nie brać command pod uwagę #else
szText = token;
#endif
if (token != "*") //*=nie brać command pod uwagę
iCheckMask |= conditional_memstring; iCheckMask |= conditional_memstring;
parser->getTokens(); parser->getTokens();
*parser >> token; *parser >> token;
if (token.compare("*") != 0) //*=nie brać wartości 1. pod uwagę if (token != "*") //*=nie brać wartości 1. pod uwagę
{ {
iCheckMask |= conditional_memval1; iCheckMask |= conditional_memval1;
//str = AnsiString(token.c_str());
fVal1 = atof(token.c_str()); fVal1 = atof(token.c_str());
} }
else else
@@ -125,7 +130,6 @@ bool TEventLauncher::Load(cParser *parser)
if (token.compare("*") != 0) //*=nie brać wartości 2. pod uwagę if (token.compare("*") != 0) //*=nie brać wartości 2. pod uwagę
{ {
iCheckMask |= conditional_memval2; iCheckMask |= conditional_memval2;
//str = AnsiString(token.c_str());
fVal2 = atof(token.c_str()); fVal2 = atof(token.c_str());
} }
else else

View File

@@ -21,7 +21,11 @@ class TEventLauncher
double UpdatedTime; double UpdatedTime;
double fVal1; double fVal1;
double fVal2; double fVal2;
char *szText; #ifdef EU07_USE_OLD_TEVENTLAUNCHER_TEXT_ARRAY
char * szText;
#else
std::string szText;
#endif
int iHour, iMinute; // minuta uruchomienia int iHour, iMinute; // minuta uruchomienia
public: public:
double dRadius; double dRadius;
@@ -33,7 +37,9 @@ class TEventLauncher
TMemCell *MemCell; TMemCell *MemCell;
int iCheckMask; int iCheckMask;
TEventLauncher(); TEventLauncher();
#ifdef EU07_USE_OLD_TEVENTLAUNCHER_TEXT_ARRAY
~TEventLauncher(); ~TEventLauncher();
#endif
void Init(); void Init();
bool Load(cParser *parser); bool Load(cParser *parser);
bool Render(); bool Render();

View File

@@ -3998,7 +3998,8 @@ bool TGround::CheckQuery()
{ {
case tp_CopyValues: // skopiowanie wartości z innej komórki case tp_CopyValues: // skopiowanie wartości z innej komórki
tmpEvent->Params[5].asMemCell->UpdateValues( tmpEvent->Params[5].asMemCell->UpdateValues(
tmpEvent->Params[9].asMemCell->Text(), tmpEvent->Params[9].asMemCell->Value1(), tmpEvent->Params[9].asMemCell->Text(),
tmpEvent->Params[9].asMemCell->Value1(),
tmpEvent->Params[9].asMemCell->Value2(), tmpEvent->Params[9].asMemCell->Value2(),
tmpEvent->iFlags // flagi określają, co ma być skopiowane tmpEvent->iFlags // flagi określają, co ma być skopiowane
); );
@@ -4009,8 +4010,10 @@ bool TGround::CheckQuery()
{ // teraz mogą być warunki do tych eventów { // teraz mogą być warunki do tych eventów
if (tmpEvent->Type != tp_CopyValues) // dla CopyValues zrobiło się wcześniej if (tmpEvent->Type != tp_CopyValues) // dla CopyValues zrobiło się wcześniej
tmpEvent->Params[5].asMemCell->UpdateValues( tmpEvent->Params[5].asMemCell->UpdateValues(
tmpEvent->Params[0].asText, tmpEvent->Params[1].asdouble, tmpEvent->Params[0].asText,
tmpEvent->Params[2].asdouble, tmpEvent->iFlags); tmpEvent->Params[1].asdouble,
tmpEvent->Params[2].asdouble,
tmpEvent->iFlags);
if (tmpEvent->Params[6].asTrack) if (tmpEvent->Params[6].asTrack)
{ // McZapkie-100302 - updatevalues oprocz zmiany wartosci robi putcommand dla { // McZapkie-100302 - updatevalues oprocz zmiany wartosci robi putcommand dla
// wszystkich 'dynamic' na danym torze // wszystkich 'dynamic' na danym torze
@@ -4198,14 +4201,24 @@ bool TGround::CheckQuery()
if (tmpEvent->iFlags & update_load) if (tmpEvent->iFlags & update_load)
{ // jeśli pytanie o ładunek { // jeśli pytanie o ładunek
if (tmpEvent->iFlags & update_memadd) // jeśli typ pojazdu if (tmpEvent->iFlags & update_memadd) // jeśli typ pojazdu
tmpEvent->Params[9].asMemCell->UpdateValues( #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
strdup(tmpEvent->Activator->MoverParameters->TypeName.c_str()), // typ pojazdu strdup(tmpEvent->Activator->MoverParameters->TypeName.c_str()), // typ pojazdu
0, // na razie nic 0, // na razie nic
0, // na razie nic 0, // na razie nic
tmpEvent->iFlags & tmpEvent->iFlags &
(update_memstring | update_memval1 | update_memval2)); (update_memstring | update_memval1 | update_memval2));
#else
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
tmpEvent->Activator->MoverParameters->TypeName, // typ pojazdu
0, // na razie nic
0, // na razie nic
tmpEvent->iFlags &
(update_memstring | update_memval1 | update_memval2));
#endif
else // jeśli parametry ładunku else // jeśli parametry ładunku
tmpEvent->Params[9].asMemCell->UpdateValues( #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
tmpEvent->Activator->MoverParameters->LoadType != "" ? tmpEvent->Activator->MoverParameters->LoadType != "" ?
strdup(tmpEvent->Activator->MoverParameters->LoadType.c_str()) : strdup(tmpEvent->Activator->MoverParameters->LoadType.c_str()) :
(char*)"none", // nazwa ładunku (char*)"none", // nazwa ładunku
@@ -4213,21 +4226,38 @@ bool TGround::CheckQuery()
tmpEvent->Activator->MoverParameters->MaxLoad, // maksymalna ilość tmpEvent->Activator->MoverParameters->MaxLoad, // maksymalna ilość
tmpEvent->iFlags & tmpEvent->iFlags &
(update_memstring | update_memval1 | update_memval2)); (update_memstring | update_memval1 | update_memval2));
#else
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
tmpEvent->Activator->MoverParameters->LoadType, // nazwa ładunku
tmpEvent->Activator->MoverParameters->Load, // aktualna ilość
tmpEvent->Activator->MoverParameters->MaxLoad, // maksymalna ilość
tmpEvent->iFlags &
(update_memstring | update_memval1 | update_memval2));
#endif
} }
else if (tmpEvent->iFlags & update_memadd) else if (tmpEvent->iFlags & update_memadd)
{ // jeśli miejsce docelowe pojazdu { // jeśli miejsce docelowe pojazdu
tmpEvent->Params[9].asMemCell->UpdateValues( #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
strdup(tmpEvent->Activator->asDestination.c_str()), // adres docelowy strdup(tmpEvent->Activator->asDestination.c_str()), // adres docelowy
tmpEvent->Activator->DirectionGet(), // kierunek pojazdu względem czoła tmpEvent->Activator->DirectionGet(), // kierunek pojazdu względem czoła
// składu (1=zgodny,-1=przeciwny) // składu (1=zgodny,-1=przeciwny)
tmpEvent->Activator->MoverParameters tmpEvent->Activator->MoverParameters
->Power, // moc pojazdu silnikowego: 0 dla wagonu ->Power, // moc pojazdu silnikowego: 0 dla wagonu
tmpEvent->iFlags & (update_memstring | update_memval1 | update_memval2)); tmpEvent->iFlags & (update_memstring | update_memval1 | update_memval2));
#else
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
tmpEvent->Activator->asDestination, // adres docelowy
tmpEvent->Activator->DirectionGet(), // kierunek pojazdu względem czoła składu (1=zgodny,-1=przeciwny)
tmpEvent->Activator->MoverParameters ->Power, // moc pojazdu silnikowego: 0 dla wagonu
tmpEvent->iFlags & (update_memstring | update_memval1 | update_memval2));
#endif
} }
else if (tmpEvent->Activator->Mechanik) else if (tmpEvent->Activator->Mechanik)
if (tmpEvent->Activator->Mechanik->Primary()) if (tmpEvent->Activator->Mechanik->Primary())
{ // tylko jeśli ktoś tam siedzi - nie powinno dotyczyć pasażera! { // tylko jeśli ktoś tam siedzi - nie powinno dotyczyć pasażera!
tmpEvent->Params[9].asMemCell->UpdateValues( #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
const_cast<char *>(tmpEvent->Activator->Mechanik->TrainName().c_str()), const_cast<char *>(tmpEvent->Activator->Mechanik->TrainName().c_str()),
tmpEvent->Activator->Mechanik->StationCount() - tmpEvent->Activator->Mechanik->StationCount() -
tmpEvent->Activator->Mechanik tmpEvent->Activator->Mechanik
@@ -4235,6 +4265,16 @@ bool TGround::CheckQuery()
tmpEvent->Activator->Mechanik->IsStop() ? 1 : tmpEvent->Activator->Mechanik->IsStop() ? 1 :
0, // 1, gdy ma tu zatrzymanie 0, // 1, gdy ma tu zatrzymanie
tmpEvent->iFlags); tmpEvent->iFlags);
#else
tmpEvent->Params[ 9 ].asMemCell->UpdateValues(
tmpEvent->Activator->Mechanik->TrainName(),
tmpEvent->Activator->Mechanik->StationCount() -
tmpEvent->Activator->Mechanik
->StationIndex(), // ile przystanków do końca
tmpEvent->Activator->Mechanik->IsStop() ? 1 :
0, // 1, gdy ma tu zatrzymanie
tmpEvent->iFlags);
#endif
WriteLog("Train detected: " + tmpEvent->Activator->Mechanik->TrainName()); WriteLog("Train detected: " + tmpEvent->Activator->Mechanik->TrainName());
} }
break; break;

View File

@@ -5836,7 +5836,7 @@ bool TMoverParameters::readDList( std::string const &line ) {
++DLISTLINE; ++DLISTLINE;
int idx = 0; int idx = 0;
parser >> idx; parser >> idx;
if( idx >= sizeof( DElist ) ) { if( idx >= sizeof( RList ) ) {
WriteLog( "Read DList: number of entries exceeded capacity of the data table" ); WriteLog( "Read DList: number of entries exceeded capacity of the data table" );
return false; return false;
} }

View File

@@ -158,7 +158,7 @@ bool FuzzyLogicAI(double Test, double Threshold, double Probability)
return false; return false;
} }
std::string ReadWord(std::ifstream& infile) std::string ReadWord(std::ifstream &infile)
{ {
std::string s = ""; std::string s = "";
char c; char c;
@@ -176,7 +176,7 @@ std::string ReadWord(std::ifstream& infile)
return s; return s;
} }
std::string TrimSpace(std::string &s, int Just) std::string TrimSpace(std::string &s)
{ {
/*int ii; /*int ii;
@@ -266,41 +266,6 @@ std::string DWE(std::string s) /*Delete After Equal sign*/
return s; return s;
} }
std::string Ld2Sp(std::string const &s) /*Low dash to Space sign*/
{
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;
}
std::string Tab2Sp(std::string const &s) /*Tab to Space sign*/
{
std::string s2 = "";
char tmp = (char)9;
for (std::size_t b = 0; b < s.length(); ++b)
//{
// if (s[b] == tmp[0])
// s[b] = tmp[1];
//}
//return s;
{
if (s[b] == tmp)
s2 = s2 + " ";
else
s2 = s2 + s[b];
}
return s2;
}
std::string ExchangeCharInString( std::string const &Source, char const &From, char const &To ) std::string ExchangeCharInString( std::string const &Source, char const &From, char const &To )
{ {
std::string replacement; replacement.reserve( Source.size() ); std::string replacement; replacement.reserve( Source.size() );
@@ -311,22 +276,6 @@ std::string ExchangeCharInString( std::string const &Source, char const &From, c
} ); } );
return replacement; return replacement;
/*
int const length = Source.size();
std::string replacement; replacement.reserve( length );
for( int idx = 0; idx < length; ++idx ) {
if( Source[ idx ] != From ) {
replacement += Source[ idx ];
}
else {
if( To != NULL ) {
replacement += To;
}
}
}
return replacement;
*/
} }
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> &elems)
@@ -422,9 +371,12 @@ std::string to_hex_str( int const Value, int const Width )
int stol_def(const std::string &str, const int &DefaultValue) int stol_def(const std::string &str, const int &DefaultValue)
{ {
// NOTE: there's good chance this function is bugged, it produced wrong result on at least one occasion int result { DefaultValue };
// TODO: rewrite into something more reliable std::stringstream converter;
converter << str;
converter >> result;
return result;
/*
// this function was developed iteratively on Codereview.stackexchange // this function was developed iteratively on Codereview.stackexchange
// with the assistance of @Corbin // with the assistance of @Corbin
std::size_t len = str.size(); std::size_t len = str.size();
@@ -443,6 +395,7 @@ int stol_def(const std::string &str, const int &DefaultValue)
return DefaultValue; return DefaultValue;
} }
return result; return result;
*/
} }
std::string ToLower(std::string const &text) std::string ToLower(std::string const &text)

View File

@@ -82,16 +82,13 @@ inline double Random(double b)
inline double BorlandTime() inline double BorlandTime()
{ {
std::tm epoch; auto timesinceepoch = std::time( nullptr );
epoch.tm_sec = 0; return timesinceepoch / (24.0 * 60 * 60);
epoch.tm_min = 0; /*
epoch.tm_hour = 0; // std alternative
epoch.tm_mday = 1; auto timesinceepoch = std::chrono::system_clock::now().time_since_epoch();
epoch.tm_mon = 0; return std::chrono::duration_cast<std::chrono::seconds>( timesinceepoch ).count() / (24.0 * 60 * 60);
epoch.tm_year = 0; */
time_t basetime = mktime(&epoch);
time_t raw_t = time(NULL);
return (difftime(raw_t, basetime) / 24) + 2;
} }
std::string Now(); std::string Now();
@@ -110,13 +107,11 @@ bool FuzzyLogicAI(double Test, double Threshold, double Probability);
/*operacje na stringach*/ /*operacje na stringach*/
std::string ReadWord( std::ifstream& infile); /*czyta slowo z wiersza pliku tekstowego*/ std::string ReadWord( std::ifstream& infile); /*czyta slowo z wiersza pliku tekstowego*/
//std::string Ups(std::string s); //std::string Ups(std::string s);
std::string TrimSpace(std::string &s, int Just = CutBoth); std::string TrimSpace(std::string &s);
char* TrimAndReduceSpaces(const char* s); char* TrimAndReduceSpaces(const char* s);
std::string ExtractKeyWord(std::string InS, std::string KeyWord); /*wyciaga slowo kluczowe i lancuch do pierwszej spacji*/ 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 DUE(std::string s); /*Delete Until Equal sign*/
std::string DWE(std::string s); /*Delete While Equal sign*/ std::string DWE(std::string s); /*Delete While Equal sign*/
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 const &s, const char &aim, const char &target); // zamienia jeden znak na drugi std::string ExchangeCharInString(std::string const &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> &elems);
std::vector<std::string> Split(const std::string &s, char delim); std::vector<std::string> Split(const std::string &s, char delim);

View File

@@ -28,29 +28,37 @@ http://mozilla.org/MPL/2.0/.
TMemCell::TMemCell(vector3 *p) TMemCell::TMemCell(vector3 *p)
{ {
fValue1 = fValue2 = 0; fValue1 = fValue2 = 0;
szText = new char[256]; // musi być dla automatycznie tworzonych komórek dla odcinków #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
// izolowanych szText = new char[256]; // musi być dla automatycznie tworzonych komórek dla odcinków izolowanych
#endif
vPosition = vPosition =
p ? *p : vector3(0, 0, 0); // ustawienie współrzędnych, bo do TGroundNode nie ma dostępu p ? *p : vector3(0, 0, 0); // ustawienie współrzędnych, bo do TGroundNode nie ma dostępu
bCommand = false; // komenda wysłana bCommand = false; // komenda wysłana
OnSent = NULL; OnSent = NULL;
} }
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
TMemCell::~TMemCell() TMemCell::~TMemCell()
{ {
SafeDeleteArray(szText); SafeDeleteArray(szText);
} }
#endif
void TMemCell::Init() void TMemCell::Init()
{ {
} }
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
void TMemCell::UpdateValues(char *szNewText, double fNewValue1, double fNewValue2, int CheckMask) void TMemCell::UpdateValues(char const *szNewText, double const fNewValue1, double const fNewValue2, int const CheckMask)
#else
void TMemCell::UpdateValues( std::string const &szNewText, double const fNewValue1, double const fNewValue2, int const CheckMask )
#endif
{ {
if (CheckMask & update_memadd) if (CheckMask & update_memadd)
{ // dodawanie wartości { // dodawanie wartości
if (TestFlag(CheckMask, update_memstring)) if( TestFlag( CheckMask, update_memstring ) )
strcat(szText, szNewText); #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
strcat( szText, szNewText );
#else
szText += szNewText;
#endif
if (TestFlag(CheckMask, update_memval1)) if (TestFlag(CheckMask, update_memval1))
fValue1 += fNewValue1; fValue1 += fNewValue1;
if (TestFlag(CheckMask, update_memval2)) if (TestFlag(CheckMask, update_memval2))
@@ -58,8 +66,12 @@ void TMemCell::UpdateValues(char *szNewText, double fNewValue1, double fNewValue
} }
else else
{ {
if (TestFlag(CheckMask, update_memstring)) if( TestFlag( CheckMask, update_memstring ) )
strcpy(szText, szNewText); #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
strcpy( szText, szNewText );
#else
szText = szNewText;
#endif
if (TestFlag(CheckMask, update_memval1)) if (TestFlag(CheckMask, update_memval1))
fValue1 = fNewValue1; fValue1 = fNewValue1;
if (TestFlag(CheckMask, update_memval2)) if (TestFlag(CheckMask, update_memval2))
@@ -71,32 +83,56 @@ void TMemCell::UpdateValues(char *szNewText, double fNewValue1, double fNewValue
TCommandType TMemCell::CommandCheck() TCommandType TMemCell::CommandCheck()
{ // rozpoznanie komendy { // rozpoznanie komendy
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
if (strcmp(szText, "SetVelocity") == 0) // najpopularniejsze if (strcmp(szText, "SetVelocity") == 0) // najpopularniejsze
#else
if( szText == "SetVelocity" ) // najpopularniejsze
#endif
{ {
eCommand = cm_SetVelocity; eCommand = cm_SetVelocity;
bCommand = false; // ta komenda nie jest wysyłana bCommand = false; // ta komenda nie jest wysyłana
} }
else if (strcmp(szText, "ShuntVelocity") == 0) // w tarczach manewrowych #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
else if( strcmp( szText, "ShuntVelocity" ) == 0 ) // w tarczach manewrowych
#else
else if( szText == "ShuntVelocity" ) // w tarczach manewrowych
#endif
{ {
eCommand = cm_ShuntVelocity; eCommand = cm_ShuntVelocity;
bCommand = false; // ta komenda nie jest wysyłana bCommand = false; // ta komenda nie jest wysyłana
} }
else if (strcmp(szText, "Change_direction") == 0) // zdarza się #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
else if( strcmp( szText, "Change_direction" ) == 0 ) // zdarza się
#else
else if( szText == "Change_direction" ) // zdarza się
#endif
{ {
eCommand = cm_ChangeDirection; eCommand = cm_ChangeDirection;
bCommand = true; // do wysłania bCommand = true; // do wysłania
} }
else if (strcmp(szText, "OutsideStation") == 0) // zdarza się #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
else if( strcmp( szText, "OutsideStation" ) == 0 ) // zdarza się
#else
else if( szText == "OutsideStation" ) // zdarza się
#endif
{ {
eCommand = cm_OutsideStation; eCommand = cm_OutsideStation;
bCommand = false; // tego nie powinno być w komórce bCommand = false; // tego nie powinno być w komórce
} }
else if (strncmp(szText, "PassengerStopPoint:", 19) == 0) // porównanie początków #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
else if( strncmp( szText, "PassengerStopPoint:", 19 ) == 0 ) // porównanie początków
#else
else if( szText.compare( 0, 19, "PassengerStopPoint:" ) == 0 ) // porównanie początków
#endif
{ {
eCommand = cm_PassengerStopPoint; eCommand = cm_PassengerStopPoint;
bCommand = false; // tego nie powinno być w komórce bCommand = false; // tego nie powinno być w komórce
} }
else if (strcmp(szText, "SetProximityVelocity") == 0) // nie powinno tego być #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
else if( strcmp( szText, "SetProximityVelocity" ) == 0 ) // nie powinno tego być
#else
else if( szText == "SetProximityVelocity" ) // nie powinno tego być
#endif
{ {
eCommand = cm_SetProximityVelocity; eCommand = cm_SetProximityVelocity;
bCommand = false; // ta komenda nie jest wysyłana bCommand = false; // ta komenda nie jest wysyłana
@@ -113,21 +149,25 @@ bool TMemCell::Load(cParser *parser)
{ {
std::string token; std::string token;
parser->getTokens(1, false); // case sensitive parser->getTokens(1, false); // case sensitive
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
*parser >> token; *parser >> token;
SafeDeleteArray(szText); SafeDeleteArray(szText);
szText = new char[256]; // musi być bufor do łączenia tekstów szText = new char[256]; // musi być bufor do łączenia tekstów
strcpy(szText, token.c_str()); strcpy(szText, token.c_str());
parser->getTokens(); #else
*parser >> fValue1; *parser >> szText;
parser->getTokens(); #endif
*parser >> fValue2; parser->getTokens( 2, false );
*parser
>> fValue1
>> fValue2;
parser->getTokens(); parser->getTokens();
*parser >> token; *parser >> token;
if (token.compare("none") != 0) // gdy różne od "none" if (token != "none") // gdy różne od "none"
asTrackName = token; // sprawdzane przez IsEmpty() asTrackName = token; // sprawdzane przez IsEmpty()
parser->getTokens(); parser->getTokens();
*parser >> token; *parser >> token;
if (token.compare("endmemcell") != 0) if (token != "endmemcell")
Error("endmemcell statement missing"); Error("endmemcell statement missing");
CommandCheck(); CommandCheck();
return true; return true;
@@ -139,35 +179,22 @@ void TMemCell::PutCommand(TController *Mech, vector3 *Loc)
Mech->PutCommand(szText, fValue1, fValue2, Loc); Mech->PutCommand(szText, fValue1, fValue2, Loc);
} }
bool TMemCell::Compare(char *szTestText, double fTestValue1, double fTestValue2, int CheckMask) bool TMemCell::Compare(char const *szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask)
{ // porównanie zawartości komórki pamięci z podanymi wartościami { // porównanie zawartości komórki pamięci z podanymi wartościami
if (TestFlag(CheckMask, conditional_memstring)) if (TestFlag(CheckMask, conditional_memstring))
{ // porównać teksty { // porównać teksty
/* char *pos = std::strstr(szTestText, "*"); // zwraca wskaźnik na pozycję albo NULL std::string
if( nullptr != pos ) { // porównanie fragmentu łańcucha
int i = pos - szTestText; // ilość porównywanych znaków
if( i ) { // jeśli nie jest pierwszym znakiem
if( std::string( szTestText ).substr( 0, i ) != std::string( szText ).substr( 0, i ) ) {
return false; // początki o długości (i) są różne
}
}
}
else if( std::string( szTestText ) != std::string( szText ) ) {
return false; //łąńcuchy są różne
}
*/ std::string
source( szText ),
match( szTestText ); match( szTestText );
auto range = match.find( '*' ); auto range = match.find( '*' );
if( range != std::string::npos ) { if( range != std::string::npos ) {
// compare string parts // compare string parts
if( 0 != source.compare( 0, range, match, 0, range ) ) { if( 0 != szText.compare( 0, range, match, 0, range ) ) {
return false; return false;
} }
} }
else { else {
// compare full strings // compare full strings
if( source != match ) { if( szText != match ) {
return false; return false;
} }
} }
@@ -177,6 +204,31 @@ bool TMemCell::Compare(char *szTestText, double fTestValue1, double fTestValue2,
(!TestFlag(CheckMask, conditional_memval2) || (fValue2 == fTestValue2))); (!TestFlag(CheckMask, conditional_memval2) || (fValue2 == fTestValue2)));
}; };
#ifndef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
bool TMemCell::Compare( std::string const &szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask ) {
// porównanie zawartości komórki pamięci z podanymi wartościami
if( TestFlag( CheckMask, conditional_memstring ) ) {
// porównać teksty
auto range = szTestText.find( '*' );
if( range != std::string::npos ) {
// compare string parts
if( 0 != szText.compare( 0, range, szTestText, 0, range ) ) {
return false;
}
}
else {
// compare full strings
if( szText != szTestText ) {
return false;
}
}
}
// tekst zgodny, porównać resztę
return ( ( !TestFlag( CheckMask, conditional_memval1 ) || ( fValue1 == fTestValue1 ) ) &&
( !TestFlag( CheckMask, conditional_memval2 ) || ( fValue2 == fTestValue2 ) ) );
};
#endif
bool TMemCell::Render() bool TMemCell::Render()
{ {
return true; return true;

View File

@@ -19,7 +19,11 @@ class TMemCell
{ {
private: private:
vector3 vPosition; vector3 vPosition;
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
char *szText; char *szText;
#else
std::string szText;
#endif
double fValue1; double fValue1;
double fValue2; double fValue2;
TCommandType eCommand; TCommandType eCommand;
@@ -29,17 +33,30 @@ class TMemCell
string string
asTrackName; // McZapkie-100302 - zeby nazwe toru na ktory jest Putcommand wysylane pamietac asTrackName; // McZapkie-100302 - zeby nazwe toru na ktory jest Putcommand wysylane pamietac
TMemCell(vector3 *p); TMemCell(vector3 *p);
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
~TMemCell(); ~TMemCell();
#endif
void Init(); void Init();
void UpdateValues(char *szNewText, double fNewValue1, double fNewValue2, int CheckMask); #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
void UpdateValues( char const *szNewText, double const fNewValue1, double const fNewValue2, int const CheckMask );
#else
void UpdateValues( std::string const &szNewText, double const fNewValue1, double const fNewValue2, int const CheckMask );
#endif
bool Load(cParser *parser); bool Load(cParser *parser);
void PutCommand(TController *Mech, vector3 *Loc); void PutCommand(TController *Mech, vector3 *Loc);
bool Compare(char *szTestText, double fTestValue1, double fTestValue2, int CheckMask); bool Compare( char const *szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask );
#ifndef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
bool Compare( std::string const &szTestText, double const fTestValue1, double const fTestValue2, int const CheckMask );
#endif
bool Render(); bool Render();
#ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
inline char * Text() inline char * Text()
{ {
return szText; return szText;
}; };
#else
inline std::string const &Text() { return szText; }
#endif
inline double Value1() inline double Value1()
{ {
return fValue1; return fValue1;

View File

@@ -121,8 +121,13 @@ void TIsolated::Modify(int i, TDynamicObject *o)
if (Global::iMultiplayer) // jeśli multiplayer if (Global::iMultiplayer) // jeśli multiplayer
Global::pGround->WyslijString(asName, 10); // wysłanie pakietu o zwolnieniu Global::pGround->WyslijString(asName, 10); // wysłanie pakietu o zwolnieniu
if (pMemCell) // w powiązanej komórce if (pMemCell) // w powiązanej komórce
pMemCell->UpdateValues(NULL, 0, int(pMemCell->Value2()) & ~0xFF, #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
pMemCell->UpdateValues( NULL, 0, int( pMemCell->Value2() ) & ~0xFF,
update_memval2); //"zerujemy" ostatnią wartość update_memval2); //"zerujemy" ostatnią wartość
#else
pMemCell->UpdateValues( "", 0, int( pMemCell->Value2() ) & ~0xFF,
update_memval2 ); //"zerujemy" ostatnią wartość
#endif
} }
} }
else else
@@ -135,8 +140,12 @@ void TIsolated::Modify(int i, TDynamicObject *o)
if (Global::iMultiplayer) // jeśli multiplayer if (Global::iMultiplayer) // jeśli multiplayer
Global::pGround->WyslijString(asName, 11); // wysłanie pakietu o zajęciu Global::pGround->WyslijString(asName, 11); // wysłanie pakietu o zajęciu
if (pMemCell) // w powiązanej komórce if (pMemCell) // w powiązanej komórce
pMemCell->UpdateValues(NULL, 0, int(pMemCell->Value2()) | 1, #ifdef EU07_USE_OLD_TMEMCELL_TEXT_ARRAY
pMemCell->UpdateValues( NULL, 0, int( pMemCell->Value2() ) | 1,
update_memval2); // zmieniamy ostatnią wartość na nieparzystą update_memval2); // zmieniamy ostatnią wartość na nieparzystą
#else
pMemCell->UpdateValues( "", 0, int( pMemCell->Value2() ) | 1, update_memval2 ); // zmieniamy ostatnią wartość na nieparzystą
#endif
} }
} }
}; };
@@ -1893,7 +1902,7 @@ bool TTrack::RemoveDynamicObject(TDynamicObject *Dynamic)
#else #else
bool result = false; bool result = false;
if( *Dynamics.begin() == Dynamic ) { if( *Dynamics.begin() == Dynamic ) {
// most likely the object getting removed it's at the front... // most likely the object getting removed is at the front...
Dynamics.pop_front(); Dynamics.pop_front();
result = true; result = true;
} }
@@ -1903,12 +1912,15 @@ bool TTrack::RemoveDynamicObject(TDynamicObject *Dynamic)
result = true; result = true;
} }
else { else {
// ... if these fail, check all objects one by one, just in case // ... if these fail, check all objects one by one
// TODO: check if this is ever needed, remove if it isn't. for( auto idx = Dynamics.begin(); idx != Dynamics.end(); /*iterator advancement is inside the loop*/ ) {
for( auto idx = Dynamics.begin(); idx != Dynamics.end(); ++idx ) {
if( *idx == Dynamic ) { if( *idx == Dynamic ) {
Dynamics.erase( idx ); idx = Dynamics.erase( idx );
result = true; result = true;
break; // object are unique, so we can bail out here.
}
else {
++idx;
} }
} }
} }