mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
Merge branch 'master' into gfx-work
This commit is contained in:
125
Track.cpp
125
Track.cpp
@@ -17,6 +17,11 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "Track.h"
|
||||
#include "simulation.h"
|
||||
#include "Globals.h"
|
||||
#include "Event.h"
|
||||
#include "messaging.h"
|
||||
#include "DynObj.h"
|
||||
#include "AnimModel.h"
|
||||
#include "Track.h"
|
||||
#include "Timer.h"
|
||||
#include "Logs.h"
|
||||
#include "renderer.h"
|
||||
@@ -63,12 +68,12 @@ TSwitchExtension::TSwitchExtension(TTrack *owner, int const what)
|
||||
TSwitchExtension::~TSwitchExtension()
|
||||
{ // nie ma nic do usuwania
|
||||
}
|
||||
|
||||
/*
|
||||
TIsolated::TIsolated()
|
||||
{ // utworznie pustego
|
||||
TIsolated("none", NULL);
|
||||
};
|
||||
|
||||
*/
|
||||
TIsolated::TIsolated(std::string const &n, TIsolated *i) :
|
||||
asName( n ), pNext( i )
|
||||
{
|
||||
@@ -84,7 +89,7 @@ void TIsolated::DeleteAll() {
|
||||
}
|
||||
}
|
||||
|
||||
TIsolated * TIsolated::Find(std::string const &n, bool create)
|
||||
TIsolated * TIsolated::Find(std::string const &n)
|
||||
{ // znalezienie obiektu albo utworzenie nowego
|
||||
TIsolated *p = pRoot;
|
||||
while (p)
|
||||
@@ -93,12 +98,19 @@ TIsolated * TIsolated::Find(std::string const &n, bool create)
|
||||
return p;
|
||||
p = p->pNext;
|
||||
}
|
||||
if (!create)
|
||||
return nullptr;
|
||||
pRoot = new TIsolated(n, pRoot); // BUG: source of a memory leak
|
||||
return pRoot;
|
||||
};
|
||||
|
||||
bool
|
||||
TIsolated::AssignEvents() {
|
||||
|
||||
evBusy = simulation::Events.FindEvent( asName + ":busy" );
|
||||
evFree = simulation::Events.FindEvent( asName + ":free" );
|
||||
|
||||
return ( evBusy != nullptr ) && ( evFree != nullptr );
|
||||
}
|
||||
|
||||
void TIsolated::Modify(int i, TDynamicObject *o)
|
||||
{ // dodanie lub odjęcie osi
|
||||
if (iAxles)
|
||||
@@ -128,6 +140,10 @@ void TIsolated::Modify(int i, TDynamicObject *o)
|
||||
pMemCell->UpdateValues( "", 0, int( pMemCell->Value2() ) | 1, update_memval2 ); // zmieniamy ostatnią wartość na nieparzystą
|
||||
}
|
||||
}
|
||||
// pass the event to the parent
|
||||
if( pParent != nullptr ) {
|
||||
pParent->Modify( i, o );
|
||||
}
|
||||
};
|
||||
|
||||
// tworzenie nowego odcinka ruchu
|
||||
@@ -854,6 +870,12 @@ void TTrack::Load(cParser *parser, glm::dvec3 const &pOrigin)
|
||||
iAction |= 0x40; // flaga opuszczenia pantografu (tor uwzględniany w skanowaniu jako
|
||||
// ograniczenie dla pantografujących)
|
||||
}
|
||||
else if( str == "vradius" ) {
|
||||
// y-axis track radius
|
||||
// NOTE: not used/implemented
|
||||
parser->getTokens();
|
||||
*parser >> fVerticalRadius;
|
||||
}
|
||||
else
|
||||
ErrorLog("Unknown property: \"" + str + "\" in track \"" + m_name + "\"");
|
||||
parser->getTokens();
|
||||
@@ -957,19 +979,6 @@ std::string TTrack::IsolatedName()
|
||||
return "";
|
||||
};
|
||||
|
||||
bool TTrack::IsolatedEventsAssign(TEvent *busy, TEvent *free)
|
||||
{ // ustawia zdarzenia dla odcinka izolowanego
|
||||
if (pIsolated)
|
||||
{
|
||||
if (busy)
|
||||
pIsolated->evBusy = busy;
|
||||
if (free)
|
||||
pIsolated->evFree = free;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
// ABu: przeniesione z Path.h i poprawione!!!
|
||||
bool TTrack::AddDynamicObject(TDynamicObject *Dynamic)
|
||||
{ // dodanie pojazdu do trajektorii
|
||||
@@ -1421,7 +1430,10 @@ void TTrack::create_geometry( gfx::geometrybank_handle const &Bank ) {
|
||||
case tt_Switch: // dla zwrotnicy dwa razy szyny
|
||||
if( m_material1 || m_material2 ) {
|
||||
// iglice liczone tylko dla zwrotnic
|
||||
gfx::basic_vertex rpts3[24], rpts4[24];
|
||||
gfx::basic_vertex
|
||||
rpts3[24],
|
||||
rpts4[24];
|
||||
glm::vec3 const flipxvalue { -1, 1, 1 };
|
||||
for( int i = 0; i < 12; ++i ) {
|
||||
|
||||
rpts3[ i ] = {
|
||||
@@ -1440,17 +1452,17 @@ void TTrack::create_geometry( gfx::geometrybank_handle const &Bank ) {
|
||||
{ ( -fHTW - iglica[ i ].position.x ) * cos1 + iglica[ i ].position.y * sin1,
|
||||
-( -fHTW - iglica[ i ].position.x ) * sin1 + iglica[ i ].position.y * cos1,
|
||||
0.f},
|
||||
{iglica[ i ].normal},
|
||||
{iglica[ i ].normal * flipxvalue},
|
||||
{iglica[ i ].texture.x, 0.f} };
|
||||
rpts4[ 23 - i ] = {
|
||||
{ ( -fHTW2 - szyna[ i ].position.x ) * cos2 + szyna[ i ].position.y * sin2,
|
||||
-( -fHTW2 - szyna[ i ].position.x ) * sin2 + iglica[ i ].position.y * cos2,
|
||||
0.f},
|
||||
{szyna[ i ].normal},
|
||||
{szyna[ i ].normal * flipxvalue},
|
||||
{szyna[ i ].texture.x, 0.f} };
|
||||
}
|
||||
// TODO, TBD: change all track geometry to triangles, to allow packing data in less, larger buffers
|
||||
auto const bladelength { 2 * Global.SplineFidelity };
|
||||
auto const bladelength { static_cast<int>( std::ceil( SwitchExtension->Segments[ 0 ]->RaSegCount() * 0.65 ) ) };
|
||||
if (SwitchExtension->RightSwitch)
|
||||
{ // nowa wersja z SPKS, ale odwrotnie lewa/prawa
|
||||
gfx::vertex_array vertices;
|
||||
@@ -2384,18 +2396,18 @@ int TTrack::CrossSegment(int from, int into)
|
||||
switch (into)
|
||||
{
|
||||
case 0: // stop
|
||||
// WriteLog( "Stopping in P" + to_string( from + 1 ) + " on " + pMyNode->asName );
|
||||
// WriteLog( "Stopping in P" + to_string( from + 1 ) + " on " + name() );
|
||||
break;
|
||||
case 1: // left
|
||||
// WriteLog( "Turning left from P" + to_string( from + 1 ) + " on " + pMyNode->asName );
|
||||
// WriteLog( "Turning left from P" + to_string( from + 1 ) + " on " + name() );
|
||||
i = (SwitchExtension->iRoads == 4) ? iLewo4[from] : iLewo3[from];
|
||||
break;
|
||||
case 2: // right
|
||||
// WriteLog( "Turning right from P" + to_string( from + 1 ) + " on " + pMyNode->asName );
|
||||
// WriteLog( "Turning right from P" + to_string( from + 1 ) + " on " + name() );
|
||||
i = (SwitchExtension->iRoads == 4) ? iPrawo4[from] : iPrawo3[from];
|
||||
break;
|
||||
case 3: // stright
|
||||
// WriteLog( "Going straight from P" + to_string( from + 1 ) + " on " + pMyNode->asName );
|
||||
// WriteLog( "Going straight from P" + to_string( from + 1 ) + " on " + name() );
|
||||
i = (SwitchExtension->iRoads == 4) ? iProsto4[from] : iProsto3[from];
|
||||
break;
|
||||
}
|
||||
@@ -2476,6 +2488,7 @@ TTrack * TTrack::RaAnimate()
|
||||
gfx::basic_vertex
|
||||
rpts3[ 24 ],
|
||||
rpts4[ 24 ];
|
||||
glm::vec3 const flipxvalue { -1, 1, 1 };
|
||||
for (int i = 0; i < 12; ++i) {
|
||||
|
||||
rpts3[ i ] = {
|
||||
@@ -2494,19 +2507,18 @@ TTrack * TTrack::RaAnimate()
|
||||
{+( -fHTW - iglica[ i ].position.x ) * cos1 + iglica[ i ].position.y * sin1,
|
||||
-( -fHTW - iglica[ i ].position.x ) * sin1 + iglica[ i ].position.y * cos1,
|
||||
0.f},
|
||||
{iglica[ i ].normal},
|
||||
{iglica[ i ].normal * flipxvalue},
|
||||
{iglica[ i ].texture.x, 0.f} };
|
||||
rpts4[ 23 - i ] = {
|
||||
{ ( -fHTW2 - szyna[ i ].position.x ) * cos2 + szyna[ i ].position.y * sin2,
|
||||
-( -fHTW2 - szyna[ i ].position.x ) * sin2 + iglica[ i ].position.y * cos2,
|
||||
0.f},
|
||||
{szyna[ i ].normal},
|
||||
{szyna[ i ].normal * flipxvalue},
|
||||
{szyna[ i ].texture.x, 0.f} };
|
||||
}
|
||||
|
||||
gfx::vertex_array vertices;
|
||||
|
||||
auto const bladelength { 2 * Global.SplineFidelity };
|
||||
auto const bladelength { static_cast<int>( std::ceil( SwitchExtension->Segments[ 0 ]->RaSegCount() * 0.65 ) ) };
|
||||
if (SwitchExtension->RightSwitch)
|
||||
{ // nowa wersja z SPKS, ale odwrotnie lewa/prawa
|
||||
if( m_material1 ) {
|
||||
@@ -2773,7 +2785,7 @@ TTrack::export_as_text_( std::ostream &Output ) const {
|
||||
eEnvironment == e_canyon ? "canyon" :
|
||||
eEnvironment == e_mountains ? "mountains" :
|
||||
"none" )
|
||||
<< ' ';
|
||||
<< ' ';
|
||||
// visibility
|
||||
// NOTE: 'invis' would be less wrong than 'unvis', but potentially incompatible with old 3rd party tools
|
||||
Output << ( m_visible ? "vis" : "unvis" ) << ' ';
|
||||
@@ -2781,8 +2793,8 @@ TTrack::export_as_text_( std::ostream &Output ) const {
|
||||
// texture parameters are supplied only if the path is set as visible
|
||||
auto texturefile { (
|
||||
m_material1 != null_handle ?
|
||||
GfxRenderer.Material( m_material1 ).name :
|
||||
"none" ) };
|
||||
GfxRenderer.Material( m_material1 ).name :
|
||||
"none" ) };
|
||||
if( texturefile.find( szTexturePath ) == 0 ) {
|
||||
// don't include 'textures/' in the path
|
||||
texturefile.erase( 0, std::string{ szTexturePath }.size() );
|
||||
@@ -2793,8 +2805,8 @@ TTrack::export_as_text_( std::ostream &Output ) const {
|
||||
|
||||
texturefile = (
|
||||
m_material2 != null_handle ?
|
||||
GfxRenderer.Material( m_material2 ).name :
|
||||
"none" );
|
||||
GfxRenderer.Material( m_material2 ).name :
|
||||
"none" );
|
||||
if( texturefile.find( szTexturePath ) == 0 ) {
|
||||
// don't include 'textures/' in the path
|
||||
texturefile.erase( 0, std::string{ szTexturePath }.size() );
|
||||
@@ -2837,11 +2849,14 @@ TTrack::export_as_text_( std::ostream &Output ) const {
|
||||
|
||||
for( auto &eventsequence : eventsequences ) {
|
||||
for( auto &event : *( eventsequence.second ) ) {
|
||||
if( false == event.first.empty() ) {
|
||||
Output
|
||||
<< eventsequence.first << ' '
|
||||
<< event.first << ' ';
|
||||
}
|
||||
// NOTE: actual event name can be potentially different from its cached name, if it was renamed in the editor
|
||||
// therefore on export we pull the name from the event itself, if the binding isn't broken
|
||||
Output
|
||||
<< eventsequence.first << ' '
|
||||
<< ( event.second != nullptr ?
|
||||
event.second->asName :
|
||||
event.first )
|
||||
<< ' ';
|
||||
}
|
||||
}
|
||||
if( ( SwitchExtension )
|
||||
@@ -2859,6 +2874,9 @@ TTrack::export_as_text_( std::ostream &Output ) const {
|
||||
if( fOverhead != -1.0 ) {
|
||||
Output << "overhead " << fOverhead << ' ';
|
||||
}
|
||||
if( fVerticalRadius != 0.f ) {
|
||||
Output << "vradius " << fVerticalRadius << ' ';
|
||||
}
|
||||
// footer
|
||||
Output
|
||||
<< "endtrack"
|
||||
@@ -3100,15 +3118,6 @@ path_table::InitTracks() {
|
||||
}
|
||||
} // switch
|
||||
|
||||
// pobranie nazwy odcinka izolowanego
|
||||
auto const isolatedname { track->IsolatedName() };
|
||||
if( false == isolatedname.empty() ) {
|
||||
// jeśli została zwrócona nazwa
|
||||
track->IsolatedEventsAssign(
|
||||
simulation::Events.FindEvent( isolatedname + ":busy" ),
|
||||
simulation::Events.FindEvent( isolatedname + ":free" ) );
|
||||
}
|
||||
|
||||
if( ( trackname[ 0 ] == '*' )
|
||||
&& ( !track->CurrentPrev() && track->CurrentNext() ) ) {
|
||||
// możliwy portal, jeśli nie podłączony od strony 1
|
||||
@@ -3117,25 +3126,25 @@ path_table::InitTracks() {
|
||||
}
|
||||
}
|
||||
|
||||
TIsolated *isolated = TIsolated::Root();
|
||||
auto *isolated = TIsolated::Root();
|
||||
while( isolated ) {
|
||||
// jeśli się znajdzie, to podać wskaźnik
|
||||
|
||||
isolated->AssignEvents();
|
||||
|
||||
auto *memorycell = simulation::Memory.find( isolated->asName ); // czy jest komóka o odpowiedniej nazwie
|
||||
if( memorycell != nullptr ) {
|
||||
// przypisanie powiązanej komórki
|
||||
isolated->pMemCell = memorycell;
|
||||
}
|
||||
else {
|
||||
if( memorycell == nullptr ) {
|
||||
// utworzenie automatycznej komórki
|
||||
// TODO: determine suitable location for this one, create and add world reference node
|
||||
scene::node_data nodedata;
|
||||
nodedata.name = isolated->asName;
|
||||
auto *memorycell = new TMemCell( nodedata ); // to nie musi mieć nazwy, nazwa w wyszukiwarce wystarczy
|
||||
memorycell = new TMemCell( nodedata ); // to nie musi mieć nazwy, nazwa w wyszukiwarce wystarczy
|
||||
// NOTE: autogenerated cells aren't exported; they'll be autogenerated anew when exported file is loaded
|
||||
memorycell->is_exportable = false;
|
||||
simulation::Memory.insert( memorycell );
|
||||
isolated->pMemCell = memorycell; // wskaźnik komóki przekazany do odcinka izolowanego
|
||||
}
|
||||
// przypisanie powiązanej komórki
|
||||
isolated->pMemCell = memorycell;
|
||||
|
||||
isolated = isolated->Next();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user