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

build 180614. relaxed children count limit for multi-events, minor scene code cleanup

This commit is contained in:
tmj-fstate
2018-06-14 17:38:45 +02:00
parent 0fe653cab9
commit e54468f831
5 changed files with 82 additions and 106 deletions

View File

@@ -4023,9 +4023,9 @@ TController::UpdateSituation(double dt) {
// podłączanie do składu // podłączanie do składu
if (iDrivigFlags & moveConnect) { if (iDrivigFlags & moveConnect) {
// jeśli stanął już blisko, unikając zderzenia i można próbować podłączyć // jeśli stanął już blisko, unikając zderzenia i można próbować podłączyć
fMinProximityDist = -0.5; fMinProximityDist = -1.0;
fMaxProximityDist = 0.0; //[m] dojechać maksymalnie fMaxProximityDist = 0.0; //[m] dojechać maksymalnie
fVelPlus = 0.5; // dopuszczalne przekroczenie prędkości na ograniczeniu bez hamowania fVelPlus = 1.0; // dopuszczalne przekroczenie prędkości na ograniczeniu bez hamowania
fVelMinus = 0.5; // margines prędkości powodujący załączenie napędu fVelMinus = 0.5; // margines prędkości powodujący załączenie napędu
if (AIControllFlag) if (AIControllFlag)
{ // to robi tylko AI, wersję dla człowieka trzeba dopiero zrobić { // to robi tylko AI, wersję dla człowieka trzeba dopiero zrobić
@@ -4033,21 +4033,17 @@ TController::UpdateSituation(double dt) {
bool ok; // true gdy się podłączy (uzyskany sprzęg będzie zgodny z żądanym) bool ok; // true gdy się podłączy (uzyskany sprzęg będzie zgodny z żądanym)
if (pVehicles[0]->DirectionGet() > 0) // jeśli sprzęg 0 if (pVehicles[0]->DirectionGet() > 0) // jeśli sprzęg 0
{ // sprzęg 0 - próba podczepienia { // sprzęg 0 - próba podczepienia
if (pVehicles[0]->MoverParameters->Couplers[0].Connected) // jeśli jest coś if( pVehicles[ 0 ]->MoverParameters->Couplers[ 0 ].Connected ) {
// wykryte (a // jeśli jest coś wykryte (a chyba jest, nie?)
// chyba jest, if( pVehicles[ 0 ]->MoverParameters->Attach(
// nie?) 0, 2, pVehicles[ 0 ]->MoverParameters->Couplers[ 0 ].Connected,
if (pVehicles[0]->MoverParameters->Attach( iCoupler ) ) {
0, 2, pVehicles[0]->MoverParameters->Couplers[0].Connected, // pVehicles[0]->dsbCouplerAttach->SetVolume(DSBVOLUME_MAX);
iCoupler)) // pVehicles[0]->dsbCouplerAttach->Play(0,0,0);
{
// pVehicles[0]->dsbCouplerAttach->SetVolume(DSBVOLUME_MAX);
// pVehicles[0]->dsbCouplerAttach->Play(0,0,0);
} }
// WriteLog("CoupleDist[0]="+AnsiString(pVehicles[0]->MoverParameters->Couplers[0].CoupleDist)+", }
// Connected[0]="+AnsiString(pVehicles[0]->MoverParameters->Couplers[0].CouplingFlag)); // udało się? (mogło częściowo)
ok = (pVehicles[0]->MoverParameters->Couplers[0].CouplingFlag == ok = (pVehicles[0]->MoverParameters->Couplers[0].CouplingFlag == iCoupler);
iCoupler); // udało się? (mogło częściowo)
} }
else // if (pVehicles[0]->MoverParameters->DirAbsolute<0) //jeśli sprzęg 1 else // if (pVehicles[0]->MoverParameters->DirAbsolute<0) //jeśli sprzęg 1
{ // sprzęg 1 - próba podczepienia { // sprzęg 1 - próba podczepienia
@@ -4060,10 +4056,8 @@ TController::UpdateSituation(double dt) {
// pVehicles[0]->dsbCouplerAttach->Play(0,0,0); // pVehicles[0]->dsbCouplerAttach->Play(0,0,0);
} }
} }
// WriteLog("CoupleDist[1]="+AnsiString(Controlling->Couplers[1].CoupleDist)+", // udało się? (mogło częściowo)
// Connected[0]="+AnsiString(Controlling->Couplers[1].CouplingFlag)); ok = (pVehicles[0]->MoverParameters->Couplers[1].CouplingFlag == iCoupler);
ok = (pVehicles[0]->MoverParameters->Couplers[1].CouplingFlag ==
iCoupler); // udało się? (mogło częściowo)
} }
if (ok) if (ok)
{ // jeżeli został podłączony { // jeżeli został podłączony

View File

@@ -536,8 +536,7 @@ void TEvent::Load(cParser *parser, Math3D::vector3 const &org)
*parser >> token; *parser >> token;
break; break;
case tp_Multiple: { case tp_Multiple: {
int paramidx { 0 }; bool conditionalelse { false }; // flaga dla else
bool ti { false }; // flaga dla else
parser->getTokens(); parser->getTokens();
*parser >> token; *parser >> token;
@@ -548,18 +547,7 @@ void TEvent::Load(cParser *parser, Math3D::vector3 const &org)
if( token != "else" ) { if( token != "else" ) {
if( token.substr( 0, 5 ) != "none_" ) { if( token.substr( 0, 5 ) != "none_" ) {
// eventy rozpoczynające się od "none_" są ignorowane // eventy rozpoczynające się od "none_" są ignorowane
if( paramidx < 8 ) { m_children.emplace_back( token, nullptr, ( conditionalelse == false ) );
Params[ paramidx ].asText = new char[ token.size() + 1 ];
strcpy( Params[ paramidx ].asText, token.c_str() );
if( ti ) {
// oflagowanie dla eventów "else"
iFlags |= conditional_else << paramidx;
}
++paramidx;
}
else {
ErrorLog( "Bad event: multi-event \"" + asName + "\" with more than 8 events; discarding link to event \"" + token + "\"" );
}
} }
else { else {
WriteLog( "Multi-event \"" + asName + "\" ignored link to event \"" + token + "\"" ); WriteLog( "Multi-event \"" + asName + "\" ignored link to event \"" + token + "\"" );
@@ -567,7 +555,8 @@ void TEvent::Load(cParser *parser, Math3D::vector3 const &org)
} }
else { else {
// zmiana flagi dla słowa "else" // zmiana flagi dla słowa "else"
ti = !ti; conditionalelse = !conditionalelse;
m_conditionalelse = true;
} }
parser->getTokens(); parser->getTokens();
*parser >> token; *parser >> token;
@@ -655,25 +644,19 @@ TEvent::export_as_text( std::ostream &Output ) const {
break; break;
} }
case tp_Multiple: { case tp_Multiple: {
// NOTE: conditional_anyelse won't work when event cap is removed for( auto const &childevent : m_children ) {
bool hasconditionalelse { false }; if( std::get<TEvent *>( childevent ) == nullptr ) { continue; }
for( auto eventidx = 0; eventidx < 8; ++eventidx ) { if( true == std::get<bool>( childevent ) ) {
if( Params[ eventidx ].asEvent == nullptr ) { continue; } Output << std::get<std::string>( childevent ) << ' ';
if( ( iFlags & ( conditional_else << eventidx ) ) == 0 ) {
Output << Params[ eventidx ].asEvent->asName << ' ';
}
else {
// this event is executed as part of the 'else' block
hasconditionalelse = true;
} }
} }
// optional 'else' block // optional 'else' block
if( true == hasconditionalelse ) { if( true == m_conditionalelse ) {
Output << "else "; Output << "else ";
for( auto eventidx = 0; eventidx < 8; ++eventidx ) { for( auto const &childevent : m_children ) {
if( Params[ eventidx ].asEvent == nullptr ) { continue; } if( std::get<TEvent *>( childevent ) == nullptr ) { continue; }
if( ( iFlags & ( conditional_else << eventidx ) ) != 0 ) { if( false == std::get<bool>( childevent ) ) {
Output << Params[ eventidx ].asEvent->asName << ' '; Output << std::get<std::string>( childevent ) << ' ';
} }
} }
} }
@@ -1317,29 +1300,30 @@ event_manager::CheckQuery() {
Error("Event \"DynVel\" is obsolete"); Error("Event \"DynVel\" is obsolete");
break; break;
case tp_Multiple: { case tp_Multiple: {
auto const bCondition = EventConditon(m_workevent); auto const condition { EventConditon( m_workevent ) };
if( ( bCondition ) if( ( true == condition )
|| ( m_workevent->iFlags & conditional_anyelse ) ) { || ( true == m_workevent->m_conditionalelse ) ) {
// warunek spelniony albo było użyte else // warunek spelniony albo było użyte else
WriteLog("Type: Multi-event"); WriteLog("Type: Multi-event");
for (i = 0; i < 8; ++i) { for( auto &childevent : m_workevent->m_children ) {
// dodawane do kolejki w kolejności zapisania auto *childeventdata { std::get<TEvent*>( childevent ) };
if( m_workevent->Params[ i ].asEvent ) { if( childeventdata == nullptr ) { continue; }
if( bCondition != ( ( ( m_workevent->iFlags & ( conditional_else << i ) ) != 0 ) ) ) { if( std::get<bool>( childevent ) != condition ) { continue; }
if( m_workevent->Params[ i ].asEvent != m_workevent )
AddToQuery( m_workevent->Params[ i ].asEvent, m_workevent->Activator ); // normalnie dodać if( childeventdata != m_workevent ) {
else { // normalnie dodać
// jeśli ma być rekurencja to musi mieć sensowny okres powtarzania AddToQuery( childeventdata, m_workevent->Activator );
if( m_workevent->fDelay >= 5.0 ) { }
AddToQuery( m_workevent, m_workevent->Activator ); else {
} // jeśli ma być rekurencja to musi mieć sensowny okres powtarzania
} if( m_workevent->fDelay >= 5.0 ) {
AddToQuery( m_workevent, m_workevent->Activator );
} }
} }
} }
if( Global.iMultiplayer ) { if( Global.iMultiplayer ) {
// dajemy znać do serwera o wykonaniu // dajemy znać do serwera o wykonaniu
if( ( m_workevent->iFlags & conditional_anyelse ) == 0 ) { if( false == m_workevent->m_conditionalelse ) {
// jednoznaczne tylko, gdy nie było else // jednoznaczne tylko, gdy nie było else
if( m_workevent->Activator ) { if( m_workevent->Activator ) {
multiplayer::WyslijEvent( m_workevent->asName, m_workevent->Activator->name() ); multiplayer::WyslijEvent( m_workevent->asName, m_workevent->Activator->name() );
@@ -1711,15 +1695,10 @@ event_manager::InitEvents() {
event->iFlags &= ~( conditional_memstring | conditional_memval1 | conditional_memval2 ); event->iFlags &= ~( conditional_memstring | conditional_memval1 | conditional_memval2 );
} }
} }
for( int i = 0; i < 8; ++i ) { for( auto &childevent : event->m_children ) {
if( event->Params[ i ].asText != nullptr ) { std::get<TEvent *>( childevent ) = FindEvent( std::get<std::string>( childevent ) );
cellastext = event->Params[ i ].asText; if( std::get<TEvent *>( childevent ) == nullptr ) {
SafeDeleteArray( event->Params[ i ].asText ); ErrorLog( "Bad event: multi-event \"" + event->asName + "\" cannot find event \"" + std::get<std::string>( childevent ) + "\"" );
event->Params[ i ].asEvent = FindEvent( cellastext );
if( event->Params[ i ].asEvent == nullptr ) {
// Ra: tylko w logu informacja o braku
ErrorLog( "Bad event: multi-event \"" + event->asName + "\" cannot find event \"" + cellastext + "\"" );
}
} }
} }
break; break;

49
Event.h
View File

@@ -48,8 +48,6 @@ const int update_only = 0x00000FF; // wartość graniczna
const int conditional_memstring = 0x0000100; // porównanie tekstu const int conditional_memstring = 0x0000100; // porównanie tekstu
const int conditional_memval1 = 0x0000200; // porównanie pierwszej wartości liczbowej const int conditional_memval1 = 0x0000200; // porównanie pierwszej wartości liczbowej
const int conditional_memval2 = 0x0000400; // porównanie drugiej wartości const int conditional_memval2 = 0x0000400; // porównanie drugiej wartości
const int conditional_else = 0x0010000; // flaga odwrócenia warunku (przesuwana bitowo)
const int conditional_anyelse = 0x0FF0000; // do sprawdzania, czy są odwrócone warunki
const int conditional_trackoccupied = 0x1000000; // jeśli tor zajęty const int conditional_trackoccupied = 0x1000000; // jeśli tor zajęty
const int conditional_trackfree = 0x2000000; // jeśli tor wolny const int conditional_trackfree = 0x2000000; // jeśli tor wolny
const int conditional_propability = 0x4000000; // zależnie od generatora lizcb losowych const int conditional_propability = 0x4000000; // zależnie od generatora lizcb losowych
@@ -67,7 +65,6 @@ union TParam
TTrain *asTrain; TTrain *asTrain;
TDynamicObject *asDynamic; TDynamicObject *asDynamic;
TEvent *asEvent; TEvent *asEvent;
bool asBool;
double asdouble; double asdouble;
int asInt; int asInt;
sound_source *tsTextSound; sound_source *tsTextSound;
@@ -78,10 +75,27 @@ union TParam
class TEvent // zmienne: ev* class TEvent // zmienne: ev*
{ // zdarzenie { // zdarzenie
private: public:
void Conditions(cParser *parser, std::string s); // types
// wrapper for binding between editor-supplied name, event, and execution conditional flag
public: using conditional_event = std::tuple<std::string, TEvent *, bool>;
// constructors
TEvent(std::string const &m = "");
~TEvent();
// metody
void Load(cParser *parser, Math3D::vector3 const &org);
// sends basic content of the class in legacy (text) format to provided stream
void
export_as_text( std::ostream &Output ) const;
static void AddToQuery( TEvent *Event, TEvent *&Start );
std::string CommandGet();
TCommandType Command();
double ValueGet(int n);
glm::dvec3 PositionGet() const;
bool StopCommand();
void StopCommandSent();
void Append(TEvent *e);
// members
std::string asName; std::string asName;
bool m_ignored { false }; // replacement for tp_ignored bool m_ignored { false }; // replacement for tp_ignored
bool bEnabled = false; // false gdy ma nie być dodawany do kolejki (skanowanie sygnałów) bool bEnabled = false; // false gdy ma nie być dodawany do kolejki (skanowanie sygnałów)
@@ -96,22 +110,11 @@ class TEvent // zmienne: ev*
std::string asNodeName; // McZapkie-100302 - dodalem zeby zapamietac nazwe toru std::string asNodeName; // McZapkie-100302 - dodalem zeby zapamietac nazwe toru
TEvent *evJoined = nullptr; // kolejny event z tą samą nazwą - od wersji 378 TEvent *evJoined = nullptr; // kolejny event z tą samą nazwą - od wersji 378
double fRandomDelay = 0.0; // zakres dodatkowego opóźnienia // standardowo nie będzie dodatkowego losowego opóźnienia double fRandomDelay = 0.0; // zakres dodatkowego opóźnienia // standardowo nie będzie dodatkowego losowego opóźnienia
public: std::vector<conditional_event> m_children; // events which are placed in the query when this event is executed
// metody bool m_conditionalelse { false }; // TODO: make a part of condition struct
TEvent(std::string const &m = "");
~TEvent(); private:
void Load(cParser *parser, Math3D::vector3 const &org); void Conditions( cParser *parser, std::string s );
// sends basic content of the class in legacy (text) format to provided stream
void
export_as_text( std::ostream &Output ) const;
static void AddToQuery( TEvent *Event, TEvent *&Start );
std::string CommandGet();
TCommandType Command();
double ValueGet(int n);
glm::dvec3 PositionGet() const;
bool StopCommand();
void StopCommandSent();
void Append(TEvent *e);
}; };
class event_manager { class event_manager {

View File

@@ -432,7 +432,7 @@ basic_cell::find( glm::dvec3 const &Point, float const Radius, bool const Onlyco
std::tie( vehiclenearest, leastdistance ) = std::tie( vehicle, distance ); std::tie( vehiclenearest, leastdistance ) = std::tie( vehicle, distance );
} }
} }
return std::tie( vehiclenearest, leastdistance ); return { vehiclenearest, leastdistance };
} }
// finds a path with one of its ends located in specified point. returns: located path and id of the matching endpoint // finds a path with one of its ends located in specified point. returns: located path and id of the matching endpoint
@@ -449,7 +449,7 @@ basic_cell::find( glm::dvec3 const &Point, TTrack const *Exclude ) const {
endpointid = path->TestPoint( &point ); endpointid = path->TestPoint( &point );
if( endpointid >= 0 ) { if( endpointid >= 0 ) {
return std::tie( path, endpointid ); return { path, endpointid };
} }
} }
return { nullptr, -1 }; return { nullptr, -1 };
@@ -468,7 +468,7 @@ basic_cell::find( glm::dvec3 const &Point, TTraction const *Exclude ) const {
endpointid = traction->TestPoint( Point ); endpointid = traction->TestPoint( Point );
if( endpointid >= 0 ) { if( endpointid >= 0 ) {
return std::tie( traction, endpointid ); return { traction, endpointid };
} }
} }
return { nullptr, -1 }; return { nullptr, -1 };
@@ -729,7 +729,7 @@ basic_section::find( glm::dvec3 const &Point, float const Radius, bool const Onl
std::tie( vehiclenearest, distancenearest ) = std::tie( vehiclefound, distancefound ); std::tie( vehiclenearest, distancenearest ) = std::tie( vehiclefound, distancefound );
} }
} }
return std::tie( vehiclenearest, distancenearest ); return { vehiclenearest, distancenearest };
} }
// finds a path with one of its ends located in specified point. returns: located path and id of the matching endpoint // finds a path with one of its ends located in specified point. returns: located path and id of the matching endpoint
@@ -1245,7 +1245,7 @@ basic_region::find_vehicle( glm::dvec3 const &Point, float const Radius, bool co
std::tie( nearestvehicle, nearestdistance ) = std::tie( foundvehicle, founddistance ); std::tie( nearestvehicle, nearestdistance ) = std::tie( foundvehicle, founddistance );
} }
} }
return std::tie( nearestvehicle, nearestdistance ); return { nearestvehicle, nearestdistance };
} }
// finds a path with one of its ends located in specified point. returns: located path and id of the matching endpoint // finds a path with one of its ends located in specified point. returns: located path and id of the matching endpoint
@@ -1258,7 +1258,7 @@ basic_region::find_path( glm::dvec3 const &Point, TTrack const *Exclude ) {
return section( Point ).find( Point, Exclude ); return section( Point ).find( Point, Exclude );
} }
return std::make_tuple<TTrack *, int>( nullptr, -1 ); return { nullptr, -1 };
} }
// finds a traction piece with one of its ends located in specified point. returns: located traction piece and id of the matching endpoint // finds a traction piece with one of its ends located in specified point. returns: located traction piece and id of the matching endpoint
@@ -1271,7 +1271,7 @@ basic_region::find_traction( glm::dvec3 const &Point, TTraction const *Exclude )
return section( Point ).find( Point, Exclude ); return section( Point ).find( Point, Exclude );
} }
return std::make_tuple<TTraction *, int>( nullptr, -1 ); return { nullptr, -1 };
} }
// finds a traction piece located nearest to specified point, sharing section with specified other piece and powered in specified direction. returns: located traction piece // finds a traction piece located nearest to specified point, sharing section with specified other piece and powered in specified direction. returns: located traction piece

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#define VERSION_MAJOR 18 #define VERSION_MAJOR 18
#define VERSION_MINOR 609 #define VERSION_MINOR 614
#define VERSION_REVISION 0 #define VERSION_REVISION 0