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

basic scenery data export in legacy text format

This commit is contained in:
tmj-fstate
2018-06-13 16:51:57 +02:00
parent e3f7ea33b3
commit 457de678c3
27 changed files with 1383 additions and 309 deletions

244
Event.cpp
View File

@@ -304,9 +304,9 @@ void TEvent::Load(cParser *parser, Math3D::vector3 const &org)
if (token.find('#') != std::string::npos)
token.erase(token.find('#')); // obcięcie unikatowości
win1250_to_ascii( token ); // get rid of non-ascii chars
bEnabled = false; // nie do kolejki (dla SetVelocity też, ale jak jest do toru
// dowiązany)
Params[6].asCommand = cm_PassengerStopPoint;
// nie do kolejki (dla SetVelocity też, ale jak jest do toru dowiązany)
bEnabled = false;
}
else if (token == "SetVelocity")
{
@@ -328,11 +328,6 @@ void TEvent::Load(cParser *parser, Math3D::vector3 const &org)
bEnabled = false;
Params[6].asCommand = cm_ShuntVelocity;
}
//else if (str == "SetProximityVelocity")
//{
// bEnabled = false;
// Params[6].asCommand = cm_SetProximityVelocity;
//}
else if (token == "OutsideStation")
{
bEnabled = false; // ma być skanowny, aby AI nie przekraczało W5
@@ -391,6 +386,11 @@ void TEvent::Load(cParser *parser, Math3D::vector3 const &org)
}
}
} while( token.compare( "endevent" ) != 0 );
while( paramidx < 8 ) {
// HACK: mark unspecified lights with magic value
Params[ paramidx ].asdouble = -2.0;
++paramidx;
}
break;
}
case tp_Visible: // zmiana wyświetlania obiektu
@@ -403,7 +403,7 @@ void TEvent::Load(cParser *parser, Math3D::vector3 const &org)
case tp_Velocity:
parser->getTokens();
*parser >> token;
Params[0].asdouble = atof(token.c_str()) * 0.28;
Params[0].asdouble = atof(token.c_str()) * ( 1000.0 / 3600.0 );
parser->getTokens();
*parser >> token;
break;
@@ -420,7 +420,6 @@ void TEvent::Load(cParser *parser, Math3D::vector3 const &org)
*parser >> token;
break;
case tp_Exit:
asNodeName = ExchangeCharInString( asNodeName, '_', ' ' );
parser->getTokens();
*parser >> token;
break;
@@ -605,6 +604,191 @@ void TEvent::Load(cParser *parser, Math3D::vector3 const &org)
}
};
// sends basic content of the class in legacy (text) format to provided stream
void
TEvent::export_as_text( std::ostream &Output ) const {
if( Type == tp_Unknown ) { return; }
// header
Output << "event ";
// name
Output << asName << ' ';
// type
std::vector<std::string> const types {
"unknown", "sound", "exit", "disable", "velocity", "animation", "lights",
"updatevalues", "getvalues", "putvalues", "switch", "dynvel", "trackvel",
"multiple", "addvalues", "copyvalues", "whois", "logvalues", "visible",
"voltage", "message", "friction" };
Output << types[ Type ] << ' ';
// delay
Output << fDelay << ' ';
// associated node
Output << ( asNodeName.empty() ? "none" : asNodeName ) << ' ';
// type-specific attributes
switch( Type ) {
case tp_AddValues:
case tp_UpdateValues: {
Output
<< ( ( iFlags & update_memstring ) == 0 ? "*" : Params[ 0 ].asText ) << ' '
<< ( ( iFlags & update_memval1 ) == 0 ? "*" : to_string( Params[ 1 ].asdouble ) ) << ' '
<< ( ( iFlags & update_memval2 ) == 0 ? "*" : to_string( Params[ 2 ].asdouble ) ) << ' ';
break;
}
case tp_CopyValues: {
// NOTE: there's no way to get the original parameter value if it doesn't point to existing memcell
Output
<< ( Params[ 9 ].asMemCell == nullptr ? "none" : Params[ 9 ].asMemCell->name() ) << ' '
<< ( iFlags & ( update_memstring | update_memval1 | update_memval2 ) ) << ' ';
break;
}
case tp_PutValues: {
Output
// location
<< Params[ 3 ].asdouble << ' '
<< Params[ 4 ].asdouble << ' '
<< Params[ 5 ].asdouble << ' '
// command
<< Params[ 0 ].asText << ' '
<< Params[ 1 ].asdouble << ' '
<< Params[ 2 ].asdouble << ' ';
break;
}
case tp_Multiple: {
// NOTE: conditional_anyelse won't work when event cap is removed
bool hasconditionalelse { false };
for( auto eventidx = 0; eventidx < 8; ++eventidx ) {
if( Params[ eventidx ].asEvent == nullptr ) { continue; }
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
if( true == hasconditionalelse ) {
Output << "else ";
for( auto eventidx = 0; eventidx < 8; ++eventidx ) {
if( Params[ eventidx ].asEvent == nullptr ) { continue; }
if( ( iFlags & ( conditional_else << eventidx ) ) != 0 ) {
Output << Params[ eventidx ].asEvent->asName << ' ';
}
}
}
break;
}
case tp_Visible: {
Output << Params[ 0 ].asInt << ' ';
break;
}
case tp_Switch: {
Output << Params[ 0 ].asInt << ' ';
if( ( Params[ 1 ].asdouble != -1.0 )
|| ( Params[ 2 ].asdouble != -1.0 ) ) {
Output << Params[ 1 ].asdouble << ' ';
}
if( Params[ 2 ].asdouble != -1.0 ) {
Output << Params[ 2 ].asdouble << ' ';
}
break;
}
case tp_Lights: {
auto lightidx { 0 };
while( ( lightidx < iMaxNumLights )
&& ( Params[ lightidx ].asdouble > -2.0 ) ) {
Output << Params[ lightidx ].asdouble << ' ';
++lightidx;
}
break;
}
case tp_Animation: {
// animation type
Output << (
Params[ 0 ].asInt == 1 ? "rotate" :
Params[ 0 ].asInt == 2 ? "translate" :
// NOTE: .vmd animation doesn't preserve file name, can't be exported. TODO: fix this
Params[ 0 ].asInt == 8 ? "digital" :
"none" )
<< ' ';
// submodel
Output << (
Params[ 9 ].asAnimContainer != nullptr ?
Params[ 9 ].asAnimContainer->NameGet() :
"none" ) << ' ';
// animation parameters
Output
<< Params[ 1 ].asdouble << ' '
<< Params[ 2 ].asdouble << ' '
<< Params[ 3 ].asdouble << ' '
<< Params[ 4 ].asdouble << ' ';
break;
}
case tp_Sound: {
// playback mode
Output << Params[ 0 ].asInt << ' ';
// optional radio channel
if( Params[ 1 ].asdouble > 0.0 ) {
Output << Params[ 1 ].asdouble << ' ';
}
break;
}
case tp_DynVel:
case tp_TrackVel:
case tp_Voltage:
case tp_Friction: {
Output << Params[ 0 ].asdouble << ' ';
break;
}
case tp_Velocity: {
Output << Params[ 0 ].asdouble * ( 3600.0 / 1000.0 ) << ' ';
break;
}
case tp_WhoIs: {
Output
<< ( iFlags & ( update_memstring | update_memval1 | update_memval2 ) ) << ' ';
break;
}
default: {
break;
}
}
// optional conditions
// NOTE: for flexibility condition check and export is performed for all event types rather than only for these which support it currently
auto const isconditional { ( conditional_trackoccupied | conditional_trackfree | conditional_propability | conditional_memcompare ) };
if( ( ( iFlags & isconditional ) != 0 ) ) {
Output << "condition ";
if( ( iFlags & conditional_trackoccupied ) != 0 ) {
Output << "trackoccupied ";
}
else if( ( iFlags & conditional_trackfree ) != 0 ) {
Output << "trackfree ";
}
else if( ( iFlags & conditional_propability ) != 0 ) {
Output
<< "propability "
<< Params[ 10 ].asdouble << ' ';
}
else if( ( iFlags & conditional_memcompare ) != 0 ) {
Output
<< "memcompare "
<< ( ( iFlags & conditional_memstring ) == 0 ? "*" : Params[ 10 ].asText ) << ' '
<< ( ( iFlags & conditional_memval1 ) == 0 ? "*" : to_string( Params[ 11 ].asdouble ) ) << ' '
<< ( ( iFlags & conditional_memval2 ) == 0 ? "*" : to_string( Params[ 12 ].asdouble ) ) << ' ';
}
}
if( fRandomDelay != 0.0 ) {
Output
<< "randomdelay "
<< fRandomDelay << ' ';
}
// footer
Output
<< "endevent"
<< "\n";
}
void TEvent::AddToQuery( TEvent *Event, TEvent *&Start ) {
TEvent *target( Start );
@@ -1002,6 +1186,10 @@ event_manager::CheckQuery() {
case tp_Lights: {
if( m_workevent->Params[ 9 ].asModel ) {
for( i = 0; i < iMaxNumLights; ++i ) {
if( m_workevent->Params[ i ].asdouble == -2.0 ) {
// processed all supplied values, bail out
break;
}
if( m_workevent->Params[ i ].asdouble >= 0 ) {
// -1 zostawia bez zmiany
m_workevent->Params[ 9 ].asModel->LightSet(
@@ -1013,8 +1201,8 @@ event_manager::CheckQuery() {
break;
}
case tp_Visible: {
if( m_workevent->Params[ 9 ].asEditorNode )
m_workevent->Params[ 9 ].asEditorNode->visible( m_workevent->Params[ 0 ].asInt > 0 );
if( m_workevent->Params[ 9 ].asSceneNode )
m_workevent->Params[ 9 ].asSceneNode->visible( m_workevent->Params[ 0 ].asInt > 0 );
break;
}
case tp_Velocity: {
@@ -1022,8 +1210,12 @@ event_manager::CheckQuery() {
break;
}
case tp_Exit: {
MessageBox( 0, m_workevent->asNodeName.c_str(), " THE END ", MB_OK );
Global.iTextMode = -1; // wyłączenie takie samo jak sekwencja F10 -> Y
// wyłączenie takie samo jak sekwencja F10 -> Y
MessageBox(
0,
ExchangeCharInString( m_workevent->asNodeName, '_', ' ' ).c_str(),
" THE END ",
MB_OK );
return false;
}
case tp_Sound: {
@@ -1404,7 +1596,6 @@ event_manager::InitEvents() {
else {
ErrorLog( "Bad event: animation event \"" + event->asName + "\" cannot find model instance \"" + event->asNodeName + "\"" );
}
event->asNodeName = "";
break;
}
case tp_Lights: {
@@ -1414,12 +1605,11 @@ event_manager::InitEvents() {
event->Params[ 9 ].asModel = instance;
else
ErrorLog( "Bad event: lights event \"" + event->asName + "\" cannot find model instance \"" + event->asNodeName + "\"" );
event->asNodeName = "";
break;
}
case tp_Visible: {
// ukrycie albo przywrócenie obiektu
editor::basic_node *node = simulation::Instances.find( event->asNodeName ); // najpierw model
scene::basic_node *node = simulation::Instances.find( event->asNodeName ); // najpierw model
if( node == nullptr ) {
// albo tory?
node = simulation::Paths.find( event->asNodeName );
@@ -1429,12 +1619,11 @@ event_manager::InitEvents() {
node = simulation::Traction.find( event->asNodeName );
}
if( node != nullptr )
event->Params[ 9 ].asEditorNode = node;
event->Params[ 9 ].asSceneNode = node;
else {
event->m_ignored = true;
ErrorLog( "Bad event: visibility event \"" + event->asName + "\" cannot find item \"" + event->asNodeName + "\"" );
}
event->asNodeName = "";
break;
}
case tp_Switch: {
@@ -1460,7 +1649,6 @@ event_manager::InitEvents() {
else {
ErrorLog( "Bad event: switch event \"" + event->asName + "\" cannot find track \"" + event->asNodeName + "\"" );
}
event->asNodeName = "";
break;
}
case tp_Sound: {
@@ -1470,7 +1658,6 @@ event_manager::InitEvents() {
event->Params[ 9 ].tsTextSound = sound;
else
ErrorLog( "Bad event: sound event \"" + event->asName + "\" cannot find static sound \"" + event->asNodeName + "\"" );
event->asNodeName = "";
break;
}
case tp_TrackVel: {
@@ -1486,7 +1673,6 @@ event_manager::InitEvents() {
ErrorLog( "Bad event: track velocity event \"" + event->asName + "\" cannot find track \"" + event->asNodeName + "\"" );
}
}
event->asNodeName = "";
break;
}
case tp_DynVel: {
@@ -1500,7 +1686,6 @@ event_manager::InitEvents() {
else
ErrorLog( "Bad event: vehicle velocity event \"" + event->asName + "\" cannot find vehicle \"" + event->asNodeName + "\"" );
}
event->asNodeName = "";
break;
}
case tp_Multiple: {
@@ -1548,7 +1733,6 @@ event_manager::InitEvents() {
else
ErrorLog( "Bad event: voltage event \"" + event->asName + "\" cannot find power source \"" + event->asNodeName + "\"" );
}
event->asNodeName = "";
break;
}
case tp_Message: {
@@ -1597,6 +1781,20 @@ event_manager::InitLaunchers() {
}
}
// sends basic content of the class in legacy (text) format to provided stream
void
event_manager::export_as_text( std::ostream &Output ) const {
Output << "// events\n";
for( auto const *event : m_events ) {
event->export_as_text( Output );
}
Output << "// event launchers\n";
for( auto const *launcher : m_launchers.sequence() ) {
launcher->export_as_text( Output );
}
}
// legacy method, verifies condition for specified event
bool
event_manager::EventConditon( TEvent *Event ) {