Merge branch 'multiisolated' into sim

This commit is contained in:
milek7
2022-06-23 22:36:11 +02:00
6 changed files with 47 additions and 20 deletions

View File

@@ -853,7 +853,7 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin)
{ // obwód izolowany, do którego tor należy
parser->getTokens();
*parser >> token;
pIsolated = TIsolated::Find(token);
Isolated.push_back(TIsolated::Find(token));
}
else if (str == "angle1")
{ // kąt ścięcia końca od strony 1
@@ -922,13 +922,11 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin)
str = token;
}
// alternatywny zapis nazwy odcinka izolowanego - po znaku "@" w nazwie toru
if (!pIsolated)
if ((i = m_name.find("@")) != std::string::npos)
if (i < m_name.length()) // nie może być puste
{
pIsolated = TIsolated::Find(m_name.substr(i + 1, m_name.length()));
m_name = m_name.substr(0, i - 1); // usunięcie z nazwy
}
if ((i = m_name.find("@")) != std::string::npos && i < m_name.length())
{
Isolated.push_back(TIsolated::Find(m_name.substr(i + 1, m_name.length())));
m_name = m_name.substr(0, i - 1); // usunięcie z nazwy
}
// calculate path location
location( (
@@ -1010,11 +1008,11 @@ void TTrack::QueueEvents( event_sequence const &Events, TDynamicObject const *Ow
}
}
std::string TTrack::IsolatedName()
std::string TTrack::RemoteIsolatedName()
{ // podaje nazwę odcinka izolowanego, jesli nie ma on jeszcze przypisanych zdarzeń
if (pIsolated)
if (!pIsolated->evBusy && !pIsolated->evFree)
return pIsolated->asName;
for (const TIsolated *iso : Isolated)
if (!iso->evBusy && !iso->evFree)
return iso->asName;
return "";
};
@@ -2333,8 +2331,8 @@ TTrack::export_as_text_( std::ostream &Output ) const {
Output << "velocity " << fVelocity << ' ';
}
}
if( pIsolated ) {
Output << "isolated " << pIsolated->asName << ' ';
for( const TIsolated *iso : Isolated ) {
Output << "isolated " << iso->asName << ' ';
}
if( fOverhead != -1.0 ) {
Output << "overhead " << fOverhead << ' ';

11
Track.h
View File

@@ -153,7 +153,7 @@ class TTrack : public scene::basic_node
friend itemproperties_panel;
private:
TIsolated * pIsolated = nullptr; // obwód izolowany obsługujący zajęcia/zwolnienia grupy torów
std::vector<TIsolated*> Isolated; // obwód izolowany obsługujący zajęcia/zwolnienia grupy torów
std::shared_ptr<TSwitchExtension> SwitchExtension; // dodatkowe dane do toru, który jest zwrotnicą
std::shared_ptr<TSegment> Segment;
TTrack * trNext = nullptr; // odcinek od strony punktu 2 - to powinno być w segmencie
@@ -300,9 +300,12 @@ public:
void RadioStop();
void AxleCounter(int i, TDynamicObject *o) {
if (pIsolated)
pIsolated->Modify(i, o); }; // dodanie lub odjęcie osi
std::string IsolatedName();
for (TIsolated *iso : Isolated)
iso->Modify(i, o); }; // dodanie lub odjęcie osi
std::string RemoteIsolatedName();
void AddIsolated(TIsolated *iso) {
Isolated.push_back(iso);
}
double WidthTotal();
bool IsGroupable();
int TestPoint( Math3D::vector3 *Point);

View File

@@ -109,9 +109,17 @@ itemproperties_panel::update( scene::basic_node const *Node ) {
else if( typeid( *node ) == typeid( TTrack ) ) {
auto const *subnode = static_cast<TTrack const *>( node );
std::string isolatedlist;
for (const TIsolated *iso : subnode->Isolated) {
if (!isolatedlist.empty())
isolatedlist += ", ";
isolatedlist += iso->asName;
}
// basic attributes
textline =
"isolated: " + ( ( subnode->pIsolated != nullptr ) ? Bezogonkow( subnode->pIsolated->asName ) : "(none)" )
"isolated: " + ( !isolatedlist.empty() ? isolatedlist : "(none)" )
+ "\nvelocity: " + to_string( subnode->SwitchExtension ? subnode->SwitchExtension->fVelocity : subnode->fVelocity )
+ "\nwidth: " + to_string( subnode->fTrackWidth ) + " m"
+ "\nfriction: " + to_string( subnode->fFriction, 2 )

View File

@@ -371,7 +371,7 @@ WyslijObsadzone()
r.fPar[ 16 * i + 5 ] = vehicle->GetPosition().y;
r.fPar[ 16 * i + 6 ] = vehicle->GetPosition().z;
r.iPar[ 16 * i + 7 ] = static_cast<int>( vehicle->Mechanik->action() );
strcpy( r.cString + 64 * i + 32, vehicle->GetTrack()->IsolatedName().c_str() );
strcpy( r.cString + 64 * i + 32, vehicle->GetTrack()->RemoteIsolatedName().c_str() );
strcpy( r.cString + 64 * i + 48, vehicle->Mechanik->TrainName().c_str() );
i++;
if( i > 30 ) break;

View File

@@ -68,6 +68,7 @@ state_serializer::deserialize_begin( std::string const &Scenariofile ) {
std::string,
deserializefunction> > functionlist = {
{ "area", &state_serializer::deserialize_area },
{ "isolated", &state_serializer::deserialize_isolated },
{ "assignment", &state_serializer::deserialize_assignment },
{ "atmo", &state_serializer::deserialize_atmo },
{ "camera", &state_serializer::deserialize_camera },
@@ -149,6 +150,22 @@ state_serializer::deserialize_continue(std::shared_ptr<deserializer_state> state
return false;
}
void
state_serializer::deserialize_isolated( cParser &Input, scene::scratch_data &Scratchpad ) {
// first parameter specifies name of parent piece...
auto token { Input.getToken<std::string>() };
auto *groupowner { TIsolated::Find( token ) };
// ...followed by list of its tracks
while( ( false == ( token = Input.getToken<std::string>() ).empty() )
&& ( token != "endisolated" ) ) {
auto *track { simulation::Paths.find( token ) };
if( track != nullptr )
track->AddIsolated( groupowner );
else
ErrorLog( "Bad scenario: track \"" + token + "\" not found" );
}
}
void
state_serializer::deserialize_area( cParser &Input, scene::scratch_data &Scratchpad ) {
// first parameter specifies name of parent piece...

View File

@@ -50,6 +50,7 @@ private:
// methods
// restores class data from provided stream
void deserialize_area( cParser &Input, scene::scratch_data &Scratchpad );
void deserialize_isolated( cParser &Input, scene::scratch_data &Scratchpad );
void deserialize_assignment( cParser &Input, scene::scratch_data &Scratchpad );
void deserialize_atmo( cParser &Input, scene::scratch_data &Scratchpad );
void deserialize_camera( cParser &Input, scene::scratch_data &Scratchpad );