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

merge tmj

This commit is contained in:
VB
2017-02-14 19:26:51 +01:00
25 changed files with 1053 additions and 1179 deletions

View File

@@ -449,12 +449,16 @@ bool TAnimModel::Init(std::string const &asName, std::string const &asReplacable
asText = asReplacableTexture.substr(1, asReplacableTexture.length() - 1); // zapamiętanie tekstu
else if (asReplacableTexture != "none")
ReplacableSkinId[1] =
TTexturesManager::GetTextureID(NULL, NULL, asReplacableTexture.c_str());
if (TTexturesManager::GetAlpha(ReplacableSkinId[1]))
iTexAlpha =
0x31310031; // tekstura z kanałem alfa - nie renderować w cyklu nieprzezroczystych
else
iTexAlpha = 0x30300030; // tekstura nieprzezroczysta - nie renderować w cyklu
TextureManager.GetTextureId( asReplacableTexture, "" );
if( ( ReplacableSkinId[ 1 ] != 0 )
&& ( TextureManager.Texture( ReplacableSkinId[ 1 ] ).has_alpha ) ) {
// tekstura z kanałem alfa - nie renderować w cyklu nieprzezroczystych
iTexAlpha = 0x31310031;
}
else{
// tekstura nieprzezroczysta - nie renderować w cyklu
iTexAlpha = 0x30300030;
}
// przezroczystych
return (Init(TModelsManager::GetModel(asName.c_str())));
}

View File

@@ -16,6 +16,7 @@ http://mozilla.org/MPL/2.0/.
#define AnimModelH
#include "Model3d.h"
#include "Texture.h"
const int iMaxNumLights = 8;
@@ -148,7 +149,7 @@ class TAnimModel
void RaAnimate(); // przeliczenie animacji egzemplarza
void RaPrepare(); // ustawienie animacji egzemplarza na wzorcu
public:
GLuint ReplacableSkinId[5]; // McZapkie-020802: zmienialne skory
texture_manager::size_type ReplacableSkinId[5]; // McZapkie-020802: zmienialne skory
static TAnimContainer *acAnimList; // lista animacji z eventem, które muszą być przeliczane
// również bez wyświetlania
TAnimModel();

View File

@@ -3984,25 +3984,32 @@ void TDynamicObject::RenderSounds()
else
rsSilnik.Stop();
}
enginevolume = (enginevolume + vol) / 2;
if (enginevolume < 0.01)
enginevolume = (enginevolume + vol) * 0.5;
if( enginevolume < 0.01 ) {
rsSilnik.Stop();
if ((MoverParameters->EngineType == ElectricSeriesMotor) ||
(MoverParameters->EngineType == ElectricInductionMotor) && rsWentylator.AM != 0)
}
if ( ( MoverParameters->EngineType == ElectricSeriesMotor )
|| ( MoverParameters->EngineType == ElectricInductionMotor )
&& ( rsWentylator.AM != 0 ) )
{
if (MoverParameters->RventRot > 0.1)
{
if (MoverParameters->RventRot > 0.1) {
// play ventilator sound if the ventilators are rotating fast enough...
freq = rsWentylator.FM * MoverParameters->RventRot + rsWentylator.FA;
rsWentylator.AdjFreq(freq, dt);
if (MoverParameters->EngineType == ElectricInductionMotor)
vol =
rsWentylator.AM * sqrt(fabs(MoverParameters->dizel_fill)) + rsWentylator.AA;
else
if( MoverParameters->EngineType == ElectricInductionMotor ) {
vol = rsWentylator.AM * std::sqrt( std::fabs( MoverParameters->dizel_fill ) ) + rsWentylator.AA;
}
else {
vol = rsWentylator.AM * MoverParameters->RventRot + rsWentylator.AA;
}
rsWentylator.Play(vol, DSBPLAY_LOOPING, MechInside, GetPosition());
}
else
else {
// ...otherwise shut down the sound
rsWentylator.Stop();
}
}
if (MoverParameters->TrainType == dt_ET40)
{
@@ -4415,7 +4422,7 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
Global::asCurrentTexturePath + ReplacableSkin; // skory tez z dynamic/...
std::string x = TextureTest(Global::asCurrentTexturePath + "nowhere"); // na razie prymitywnie
if (!x.empty())
ReplacableSkinID[4] = TTexturesManager::GetTextureID(NULL, NULL, Global::asCurrentTexturePath + "nowhere", 9);
ReplacableSkinID[4] = TextureManager.GetTextureId( Global::asCurrentTexturePath + "nowhere", "", 9);
/*
if ((i = ReplacableSkin.Pos("|")) > 0) // replacable dzielone
{
@@ -4478,24 +4485,22 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
*/
if (iMultiTex > 0)
{ // jeśli model ma 4 tekstury
ReplacableSkinID[1] = TTexturesManager::GetTextureID(
NULL, NULL, ReplacableSkin + ",1", Global::iDynamicFiltering);
ReplacableSkinID[1] = TextureManager.GetTextureId(
ReplacableSkin + ",1", "", Global::iDynamicFiltering);
if (ReplacableSkinID[1])
{ // pierwsza z zestawu znaleziona
ReplacableSkinID[2] = TTexturesManager::GetTextureID(
NULL, NULL, ReplacableSkin + ",2", Global::iDynamicFiltering);
ReplacableSkinID[2] = TextureManager.GetTextureId(
ReplacableSkin + ",2", "", Global::iDynamicFiltering);
if (ReplacableSkinID[2])
{
iMultiTex = 2; // już są dwie
ReplacableSkinID[3] = TTexturesManager::GetTextureID(
NULL, NULL, ReplacableSkin + ",3",
Global::iDynamicFiltering);
ReplacableSkinID[3] = TextureManager.GetTextureId(
ReplacableSkin + ",3", "", Global::iDynamicFiltering);
if (ReplacableSkinID[3])
{
iMultiTex = 3; // a teraz nawet trzy
ReplacableSkinID[4] = TTexturesManager::GetTextureID(
NULL, NULL, ReplacableSkin + ",4",
Global::iDynamicFiltering);
ReplacableSkinID[4] = TextureManager.GetTextureId(
ReplacableSkin + ",4", "", Global::iDynamicFiltering);
if (ReplacableSkinID[4])
iMultiTex = 4; // jak są cztery, to blokujemy podmianę tekstury
// rozkładem
@@ -4505,14 +4510,14 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
else
{ // zestaw nie zadziałał, próbujemy normanie
iMultiTex = 0;
ReplacableSkinID[1] = TTexturesManager::GetTextureID(
NULL, NULL, ReplacableSkin, Global::iDynamicFiltering);
ReplacableSkinID[1] = TextureManager.GetTextureId(
ReplacableSkin, "", Global::iDynamicFiltering);
}
}
else
ReplacableSkinID[1] = TTexturesManager::GetTextureID(
NULL, NULL, ReplacableSkin, Global::iDynamicFiltering);
if (TTexturesManager::GetAlpha(ReplacableSkinID[1]))
ReplacableSkinID[1] = TextureManager.GetTextureId(
ReplacableSkin, "", Global::iDynamicFiltering);
if (TextureManager.Texture(ReplacableSkinID[1]).has_alpha)
iAlpha = 0x31310031; // tekstura -1 z kanałem alfa - nie renderować w cyklu
// nieprzezroczystych
else
@@ -4520,21 +4525,22 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
// renderować w
// cyklu przezroczystych
if (ReplacableSkinID[2])
if (TTexturesManager::GetAlpha(ReplacableSkinID[2]))
if (TextureManager.Texture(ReplacableSkinID[2]).has_alpha)
iAlpha |= 0x02020002; // tekstura -2 z kanałem alfa - nie renderować
// w cyklu
// nieprzezroczystych
if (ReplacableSkinID[3])
if (TTexturesManager::GetAlpha(ReplacableSkinID[3]))
if (TextureManager.Texture(ReplacableSkinID[3]).has_alpha)
iAlpha |= 0x04040004; // tekstura -3 z kanałem alfa - nie renderować
// w cyklu
// nieprzezroczystych
if (ReplacableSkinID[4])
if (TTexturesManager::GetAlpha(ReplacableSkinID[4]))
if (TextureManager.Texture(ReplacableSkinID[4]).has_alpha)
iAlpha |= 0x08080008; // tekstura -4 z kanałem alfa - nie renderować
// w cyklu
// nieprzezroczystych
}
/*
// Winger 040304 - ladowanie przedsionkow dla EZT
if (MoverParameters->TrainType == dt_EZT)
{
@@ -4542,6 +4548,7 @@ void TDynamicObject::LoadMMediaFile(std::string BaseDir, std::string TypeName,
asModel = BaseDir + asModel;
mdPrzedsionek = TModelsManager::GetModel(asModel, true);
}
*/
if (!MoverParameters->LoadAccepted.empty())
// if (MoverParameters->LoadAccepted!=AnsiString("")); // &&
// MoverParameters->LoadType!=AnsiString("passengers"))
@@ -5848,13 +5855,13 @@ void TDynamicObject::DestinationSet(std::string to, std::string numer)
std::string x = TextureTest(asBaseDir + numer + "@" + MoverParameters->TypeName);
if (!x.empty())
{
ReplacableSkinID[4] = TTexturesManager::GetTextureID( NULL, NULL, x, 9); // rozmywania 0,1,4,5 nie nadają się
ReplacableSkinID[4] = TextureManager.GetTextureId( x, "", 9); // rozmywania 0,1,4,5 nie nadają się
return;
}
x = TextureTest(asBaseDir + numer );
if (!x.empty())
{
ReplacableSkinID[4] = TTexturesManager::GetTextureID( NULL, NULL, x, 9); // rozmywania 0,1,4,5 nie nadają się
ReplacableSkinID[4] = TextureManager.GetTextureId( x, "", 9); // rozmywania 0,1,4,5 nie nadają się
return;
}
if (to.empty())
@@ -5862,17 +5869,17 @@ void TDynamicObject::DestinationSet(std::string to, std::string numer)
x = TextureTest(asBaseDir + to + "@" + MoverParameters->TypeName); // w pierwszej kolejności z nazwą FIZ/MMD
if (!x.empty())
{
ReplacableSkinID[4] = TTexturesManager::GetTextureID( NULL, NULL, x, 9); // rozmywania 0,1,4,5 nie nadają się
ReplacableSkinID[4] = TextureManager.GetTextureId( x, "", 9); // rozmywania 0,1,4,5 nie nadają się
return;
}
x = TextureTest(asBaseDir + to); // na razie prymitywnie
if (!x.empty())
ReplacableSkinID[4] = TTexturesManager::GetTextureID( NULL, NULL, x, 9); // rozmywania 0,1,4,5 nie nadają się
ReplacableSkinID[4] = TextureManager.GetTextureId( x, "", 9); // rozmywania 0,1,4,5 nie nadają się
else
{
x = TextureTest(asBaseDir + "nowhere"); // jak nie znalazł dedykowanej, to niech daje nowhere
if (!x.empty())
ReplacableSkinID[4] = TTexturesManager::GetTextureID(NULL, NULL, x, 9);
ReplacableSkinID[4] = TextureManager.GetTextureId( x, "", 9);
}
// Ra 2015-01: żeby zalogować błąd, trzeba by mieć pewność, że model używa
// tekstury nr 4

View File

@@ -395,7 +395,7 @@ private:
int iCabs; // maski bitowe modeli kabin
TTrack *MyTrack; // McZapkie-030303: tor na ktorym stoi, ABu
std::string asBaseDir;
GLuint ReplacableSkinID[5]; // McZapkie:zmienialne nadwozie
texture_manager::size_type ReplacableSkinID[5]; // McZapkie:zmienialne nadwozie
int iAlpha; // maska przezroczystości tekstur
int iMultiTex; //<0 tekstury wskazane wpisem, >0 tekstury z przecinkami, =0 jedna
int iOverheadMask; // maska przydzielana przez AI pojazdom posiadającym pantograf, aby wymuszały

View File

@@ -63,8 +63,8 @@ int Global::iScreenMode[12] = {0, 0, 0, 0, 0, 0,
double Global::fSunDeclination = 0.0; // deklinacja Słońca
double Global::fTimeAngleDeg = 0.0; // godzina w postaci kąta
float Global::fClockAngleDeg[6]; // kąty obrotu cylindrów dla zegara cyfrowego
char *Global::szTexturesTGA[4] = {"tga", "dds", "tex", "bmp"}; // lista tekstur od TGA
char *Global::szTexturesDDS[4] = {"dds", "tga", "tex", "bmp"}; // lista tekstur od DDS
std::string Global::szTexturesTGA = ".tga"; // lista tekstur od TGA
std::string Global::szTexturesDDS = ".dds"; // lista tekstur od DDS
int Global::iKeyLast = 0; // ostatnio naciśnięty klawisz w celu logowania
GLuint Global::iTextureId = 0; // ostatnio użyta tekstura 2D
int Global::iPause = 0x10; // globalna pauza ruchu
@@ -137,7 +137,7 @@ int Global::iDynamicFiltering = 5; // domyślne rozmywanie tekstur pojazdów
bool Global::bUseVBO = false; // czy jest VBO w karcie graficznej (czy użyć)
GLint Global::iMaxTextureSize = 16384; // maksymalny rozmiar tekstury
bool Global::bSmoothTraction = false; // wygładzanie drutów starym sposobem
char **Global::szDefaultExt = Global::szTexturesDDS; // domyślnie od DDS
std::string Global::szDefaultExt = Global::szTexturesDDS; // domyślnie od DDS
int Global::iMultisampling = 2; // tryb antyaliasingu: 0=brak,1=2px,2=4px,3=8px,4=16px
bool Global::bGlutFont = false; // czy tekst generowany przez GLUT32.DLL
int Global::iConvertModels = 7; // tworzenie plików binarnych, +2-optymalizacja transformów
@@ -424,6 +424,12 @@ void Global::ConfigParse(cParser &Parser)
// domyślnie od TGA
Global::szDefaultExt = Global::szTexturesTGA;
}
else {
Global::szDefaultExt =
( token[ 0 ] == '.' ?
token :
"." + token );
}
}
else if (token == "newaircouplers")
{

View File

@@ -185,7 +185,7 @@ class Global
static double fFogStart;
static double fFogEnd;
static TGround *pGround;
static char **szDefaultExt;
static std::string szDefaultExt;
static std::string SceneryFile;
static char CreatorName1[20];
static char CreatorName2[20];
@@ -261,8 +261,8 @@ class Global
static double fTimeAngleDeg; // godzina w postaci kąta
static float fClockAngleDeg[6]; // kąty obrotu cylindrów dla zegara cyfrowego
static double fLatitudeDeg; // szerokość geograficzna
static char *szTexturesTGA[4]; // lista tekstur od TGA
static char *szTexturesDDS[4]; // lista tekstur od DDS
static std::string szTexturesTGA; // lista tekstur od TGA
static std::string szTexturesDDS; // lista tekstur od DDS
static int iMultisampling; // tryb antyaliasingu: 0=brak,1=2px,2=4px,3=8px,4=16px
static bool bGlutFont; // tekst generowany przez GLUT
static int iKeyLast; // ostatnio naciśnięty klawisz w celu logowania

View File

@@ -275,7 +275,7 @@ void TGroundNode::RaRenderVBO()
{ // renderowanie z domyslnego bufora VBO
glColor3ub(Diffuse[0], Diffuse[1], Diffuse[2]);
if (TextureID)
glBindTexture(GL_TEXTURE_2D, TextureID); // Ustaw aktywną teksturę
TextureManager.Bind(TextureID); // Ustaw aktywną teksturę
glDrawArrays(iType, iVboPtr, iNumVerts); // Narysuj naraz wszystkie trójkąty
}
@@ -442,7 +442,7 @@ void TGroundNode::Compile(bool many)
#ifdef USE_VERTEX_ARRAYS
glVertexPointer(3, GL_DOUBLE, sizeof(vector3), &Points[0].x);
#endif
glBindTexture(GL_TEXTURE_2D, 0);
TextureManager.Bind(0);
#ifdef USE_VERTEX_ARRAYS
glDrawArrays(iType, 0, iNumPts);
#else
@@ -463,7 +463,7 @@ void TGroundNode::Compile(bool many)
glTexCoordPointer(2, GL_FLOAT, sizeof(TGroundVertex), &tri->Vertices[0].tu);
#endif
glColor3ub(tri->Diffuse[0], tri->Diffuse[1], tri->Diffuse[2]);
glBindTexture(GL_TEXTURE_2D, Global::bWireFrame ? 0 : tri->TextureID);
TextureManager.Bind(Global::bWireFrame ? 0 : tri->TextureID);
#ifdef USE_VERTEX_ARRAYS
glDrawArrays(Global::bWireFrame ? GL_LINE_LOOP : tri->iType, 0, tri->iNumVerts);
#else
@@ -491,7 +491,7 @@ void TGroundNode::Compile(bool many)
else if (iType == TP_MESH)
{ // grupa ze wspólną teksturą - wrzucanie do wspólnego Display List
if (TextureID)
glBindTexture(GL_TEXTURE_2D, TextureID); // Ustaw aktywną teksturę
TextureManager.Bind(TextureID); // Ustaw aktywną teksturę
TGroundNode *n = nNode;
while (n ? n->TextureID == TextureID : false)
{ // wszystkie obiekty o tej samej testurze
@@ -2096,14 +2096,14 @@ TGroundNode * TGround::AddGroundNode(cParser *parser)
// PROBLEND Q: 13122011 - Szociu: 27012012
PROBLEND = true; // domyslnie uruchomione nowe wyświetlanie
tmp->PROBLEND = true; // odwolanie do tgroundnode, bo rendering jest w tej klasie
if (str.find("@") != string::npos) // sprawdza, czy w nazwie tekstury jest znak "@"
if (str.find('@') != string::npos) // sprawdza, czy w nazwie tekstury jest znak "@"
{
PROBLEND = false; // jeśli jest, wyswietla po staremu
tmp->PROBLEND = false;
}
#endif
tmp->TextureID = TTexturesManager::GetTextureID(szTexturePath, szSceneryPath, str.c_str());
tmp->iFlags = TTexturesManager::GetAlpha(tmp->TextureID) ? 0x220 : 0x210; // z usuwaniem
tmp->TextureID = TextureManager.GetTextureId( str, szTexturePath );
tmp->iFlags = TextureManager.Texture(tmp->TextureID).has_alpha ? 0x220 : 0x210; // z usuwaniem
if (((tmp->iType == GL_TRIANGLES) && (tmp->iFlags & 0x10)) ?
Global::pTerrainCompact->TerrainLoaded() :
false)

View File

@@ -14,6 +14,7 @@ http://mozilla.org/MPL/2.0/.
#include "VBO.h"
#include "Classes.h"
#include "ResourceManager.h"
#include "Texture.h"
#include "dumb3d.h"
#include "Names.h"
@@ -141,7 +142,7 @@ class TGroundNode : public Resource
GLuint DisplayListID; // numer siatki DisplayLists
bool PROBLEND;
int iVboPtr; // indeks w buforze VBO
GLuint TextureID; // główna (jedna) tekstura obiektu
texture_manager::size_type TextureID; // główna (jedna) tekstura obiektu
int iFlags; // tryb przezroczystości: 0x10-nieprz.,0x20-przezroczysty,0x30-mieszany
int Ambient[4], Diffuse[4], Specular[4]; // oświetlenie
bool bVisible;

View File

@@ -3819,7 +3819,7 @@ double TMoverParameters::TractionForce(double dt)
{
case 1:
{
if (ActiveDir != 0 && RList[MainCtrlActualPos].R > RVentCutOff)
if ((ActiveDir != 0) && (RList[MainCtrlActualPos].R > RVentCutOff))
RventRot += (RVentnmax - RventRot) * RVentSpeed * dt;
else
RventRot *= (1.0 - RVentSpeed * dt);
@@ -3835,7 +3835,7 @@ double TMoverParameters::TractionForce(double dt)
RventRot += (RVentnmax * Im / ImaxLo - RventRot) * RVentSpeed * dt;
else
{
RventRot = RventRot * (1.0 - RVentSpeed * dt);
RventRot *= (1.0 - RVentSpeed * dt);
if (RventRot < 0.1)
RventRot = 0;
}
@@ -4213,7 +4213,7 @@ double TMoverParameters::TractionForce(double dt)
}
else
{
PosRatio = (MainCtrlPos / MainCtrlPosNo);
PosRatio = static_cast<double>( MainCtrlPos ) / static_cast<double>( MainCtrlPosNo );
eimv[eimv_Fzad] = PosRatio;
if ((Flat) && (eimc[eimc_p_F0] * eimv[eimv_Fful] > 0))
PosRatio = Min0R(PosRatio * eimc[eimc_p_F0] / eimv[eimv_Fful], 1);
@@ -4288,12 +4288,12 @@ double TMoverParameters::TractionForce(double dt)
Transmision.Ratio * NPoweredAxles * 2.0 / WheelDiameter;
if ((dizel_fill < 0))
{
eimv[eimv_Fful] = Min0R(eimc[eimc_p_Ph] * 3.6 / Vel,
Min0R(eimc[eimc_p_Fh], eimv[eimv_FMAXMAX]));
eimv[eimv_Fful] = std::min(eimc[eimc_p_Ph] * 3.6 / (Vel != 0.0 ? Vel : 0.001),
std::min(eimc[eimc_p_Fh], eimv[eimv_FMAXMAX]));
eimv[eimv_Fmax] =
-Sign(V) * (DirAbsolute)*Min0R(
eimc[eimc_p_Ph] * 3.6 / Vel,
Min0R(-eimc[eimc_p_Fh] * dizel_fill, eimv[eimv_FMAXMAX]));
-Sign(V) * (DirAbsolute)*std::min(
eimc[eimc_p_Ph] * 3.6 / (Vel != 0.0 ? Vel : 0.001),
std::min(-eimc[eimc_p_Fh] * dizel_fill, eimv[eimv_FMAXMAX]));
//*Min0R(1,(Vel-eimc[eimc_p_Vh0])/(eimc[eimc_p_Vh1]-eimc[eimc_p_Vh0]))
}
else
@@ -6406,7 +6406,7 @@ void TMoverParameters::LoadFIZ_Brake( std::string const &line ) {
CompressorPower =
lookup != compressorpowers.end() ?
lookup->second :
0;
1;
}
}
@@ -6925,7 +6925,7 @@ void TMoverParameters::LoadFIZ_RList( std::string const &Input ) {
if( RVentType > 0 ) {
extract_value( RVentnmax, "RVentmax", Input, "" );
extract_value( RVentnmax, "RVentnmax", Input, "" );
RVentnmax /= 60.0;
extract_value( RVentCutOff, "RVentCutOff", Input, "" );
}

View File

@@ -28,7 +28,7 @@ using namespace Mtable;
double TSubModel::fSquareDist = 0;
size_t TSubModel::iInstance; // numer renderowanego egzemplarza obiektu
GLuint *TSubModel::ReplacableSkinId = NULL;
texture_manager::size_type *TSubModel::ReplacableSkinId = NULL;
int TSubModel::iAlpha = 0x30300030; // maska do testowania flag tekstur wymiennych
TModel3d *TSubModel::pRoot; // Ra: tymczasowo wskaźnik na model widoczny z submodelu
std::string *TSubModel::pasText;
@@ -411,13 +411,12 @@ int TSubModel::Load(cParser &parser, TModel3d *Model, int Pos, bool dynamic)
TextureNameSet(texture.c_str());
if (texture.find_first_of("/\\") == texture.npos)
texture.insert(0, Global::asCurrentTexturePath.c_str());
TextureID = TTexturesManager::GetTextureID(
szTexturePath, const_cast<char *>(Global::asCurrentTexturePath.c_str()), texture);
TextureID = TextureManager.GetTextureId( texture, szTexturePath );
// TexAlpha=TTexturesManager::GetAlpha(TextureID);
// iFlags|=TexAlpha?0x20:0x10; //0x10-nieprzezroczysta, 0x20-przezroczysta
if (Opacity < 1.0) // przezroczystość z tekstury brana tylko dla Opacity
// 0!
iFlags |= TTexturesManager::GetAlpha(TextureID) ?
iFlags |= TextureManager.Texture(TextureID).has_alpha ?
0x20 :
0x10; // 0x10-nieprzezroczysta, 0x20-przezroczysta
else
@@ -616,7 +615,7 @@ int TSubModel::Load(cParser &parser, TModel3d *Model, int Pos, bool dynamic)
return iNumVerts; // do określenia wielkości VBO
};
int TSubModel::TriangleAdd(TModel3d *m, int tex, int tri)
int TSubModel::TriangleAdd(TModel3d *m, texture_manager::size_type tex, int tri)
{ // dodanie trójkątów do submodelu, używane
// przy tworzeniu E3D terenu
TSubModel *s = this;
@@ -637,7 +636,7 @@ int TSubModel::TriangleAdd(TModel3d *m, int tex, int tri)
m->AddTo(this, s);
}
// s->asTexture=AnsiString(TTexturesManager::GetName(tex).c_str());
s->TextureNameSet(TTexturesManager::GetName(tex).c_str());
s->TextureNameSet(TextureManager.Texture(tex).name.c_str());
s->TextureID = tex;
s->eType = GL_TRIANGLES;
// iAnimOwner=0; //roboczy wskaźnik na wierzchołek
@@ -715,7 +714,7 @@ void TSubModel::DisplayLists()
{
uiDisplayList = glGenLists(1);
glNewList(uiDisplayList, GL_COMPILE);
glBindTexture(GL_TEXTURE_2D, 0);
TextureManager.Bind(0);
// if (eType==smt_FreeSpotLight)
// {
// if (iFarAttenDecay==0)
@@ -738,7 +737,7 @@ void TSubModel::DisplayLists()
{ // punkty świecące dookólnie
uiDisplayList = glGenLists(1);
glNewList(uiDisplayList, GL_COMPILE);
glBindTexture(GL_TEXTURE_2D, 0); // tekstury nie ma
TextureManager.Bind(0); // tekstury nie ma
glColorMaterial(GL_FRONT, GL_EMISSION);
glDisable(GL_LIGHTING); // Tolaris-030603: bo mu punkty swiecace sie blendowaly
glBegin(GL_POINTS);
@@ -1101,11 +1100,11 @@ void TSubModel::RenderDL()
{
if (TextureID < 0) // && (ReplacableSkinId!=0))
{ // zmienialne skóry
glBindTexture(GL_TEXTURE_2D, ReplacableSkinId[-TextureID]);
TextureManager.Bind(ReplacableSkinId[-TextureID]);
// TexAlpha=!(iAlpha&1); //zmiana tylko w przypadku wymienej tekstury
}
else
glBindTexture(GL_TEXTURE_2D, TextureID); // również 0
TextureManager.Bind(TextureID); // również 0
if (Global::fLuminance < fLight)
{
glMaterialfv(GL_FRONT, GL_EMISSION, f4Diffuse); // zeby swiecilo na kolorowo
@@ -1198,11 +1197,11 @@ void TSubModel::RenderAlphaDL()
{
if (TextureID < 0) // && (ReplacableSkinId!=0))
{ // zmienialne skóry
glBindTexture(GL_TEXTURE_2D, ReplacableSkinId[-TextureID]);
TextureManager.Bind(ReplacableSkinId[-TextureID]);
// TexAlpha=iAlpha&1; //zmiana tylko w przypadku wymienej tekstury
}
else
glBindTexture(GL_TEXTURE_2D, TextureID); // również 0
TextureManager.Bind(TextureID); // również 0
if (Global::fLuminance < fLight)
{
glMaterialfv(GL_FRONT, GL_EMISSION, f4Diffuse); // zeby swiecilo na kolorowo
@@ -1278,11 +1277,11 @@ void TSubModel::RenderVBO()
{
if (TextureID < 0) // && (ReplacableSkinId!=0))
{ // zmienialne skóry
glBindTexture(GL_TEXTURE_2D, ReplacableSkinId[-TextureID]);
TextureManager.Bind(ReplacableSkinId[-TextureID]);
// TexAlpha=!(iAlpha&1); //zmiana tylko w przypadku wymienej tekstury
}
else
glBindTexture(GL_TEXTURE_2D, TextureID); // również 0
TextureManager.Bind(TextureID); // również 0
glColor3fv(f4Diffuse); // McZapkie-240702: zamiast ub
// glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,f4Diffuse); //to samo,
// co glColor
@@ -1349,7 +1348,7 @@ void TSubModel::RenderVBO()
Distdimm=1;
*/
glBindTexture(GL_TEXTURE_2D, 0); // nie teksturować
TextureManager.Bind(0); // nie teksturować
// glColor3f(f4Diffuse[0],f4Diffuse[1],f4Diffuse[2]);
// glColorMaterial(GL_FRONT,GL_EMISSION);
float color[4] = {(float)(f4Diffuse[0] * Distdimm), (float)(f4Diffuse[1] * Distdimm),
@@ -1378,7 +1377,7 @@ void TSubModel::RenderVBO()
if (pRoot->StartColorVBO())
{ // wyświetlanie kolorowych punktów zamiast
// trójkątów
glBindTexture(GL_TEXTURE_2D, 0); // tekstury nie ma
TextureManager.Bind(0); // tekstury nie ma
glColorMaterial(GL_FRONT, GL_EMISSION);
glDisable(GL_LIGHTING); // Tolaris-030603: bo mu punkty swiecace sie
// blendowaly
@@ -1452,11 +1451,11 @@ void TSubModel::RenderAlphaVBO()
{
if (TextureID < 0) // && (ReplacableSkinId!=0))
{ // zmienialne skory
glBindTexture(GL_TEXTURE_2D, ReplacableSkinId[-TextureID]);
TextureManager.Bind(ReplacableSkinId[-TextureID]);
// TexAlpha=iAlpha&1; //zmiana tylko w przypadku wymienej tekstury
}
else
glBindTexture(GL_TEXTURE_2D, TextureID); // również 0
TextureManager.Bind(TextureID); // również 0
if (Global::fLuminance < fLight)
{
glMaterialfv(GL_FRONT, GL_EMISSION, f4Diffuse); // zeby swiecilo na kolorowo
@@ -1624,15 +1623,14 @@ void TSubModel::BinInit(TSubModel *s, float4x4 *m, float8 *v, TStringPack *t, TS
std::string tex = pTexture;
if (tex.find_last_of("/\\") == std::string::npos)
tex.insert(0, Global::asCurrentTexturePath);
TextureID = TTexturesManager::GetTextureID(
szTexturePath, const_cast<char *>(Global::asCurrentTexturePath.c_str()), tex);
TextureID = TextureManager.GetTextureId( tex, szTexturePath );
// TexAlpha=TTexturesManager::GetAlpha(TextureID); //zmienna robocza
// ustawienie cyklu przezroczyste/nieprzezroczyste zależnie od własności
// stałej tekstury
// iFlags=(iFlags&~0x30)|(TTexturesManager::GetAlpha(TextureID)?0x20:0x10);
// //0x10-nieprzezroczysta, 0x20-przezroczysta
if (Opacity < 1.0) // przezroczystość z tekstury brana tylko dla Opacity 0!
iFlags |= TTexturesManager::GetAlpha(TextureID) ?
iFlags |= TextureManager.Texture(TextureID).has_alpha ?
0x20 :
0x10; // 0x10-nieprzezroczysta, 0x20-przezroczysta
else
@@ -2188,7 +2186,7 @@ ReplacableSkinId,int iAlpha)
};
*/
void TModel3d::Render(double fSquareDistance, GLuint *ReplacableSkinId, int iAlpha)
void TModel3d::Render(double fSquareDistance, texture_manager::size_type *ReplacableSkinId, int iAlpha)
{
iAlpha ^= 0x0F0F000F; // odwrócenie flag tekstur, aby wyłapać nieprzezroczyste
if (iAlpha & iFlags & 0x1F1F001F) // czy w ogóle jest co robić w tym cyklu?
@@ -2199,7 +2197,7 @@ void TModel3d::Render(double fSquareDistance, GLuint *ReplacableSkinId, int iAlp
}
};
void TModel3d::RenderAlpha(double fSquareDistance, GLuint *ReplacableSkinId, int iAlpha)
void TModel3d::RenderAlpha(double fSquareDistance, texture_manager::size_type *ReplacableSkinId, int iAlpha)
{
if (iAlpha & iFlags & 0x2F2F002F)
{
@@ -2243,7 +2241,7 @@ globalna!
};
*/
void TModel3d::RaRender(double fSquareDistance, GLuint *ReplacableSkinId, int iAlpha)
void TModel3d::RaRender( double fSquareDistance, texture_manager::size_type *ReplacableSkinId, int iAlpha )
{ // renderowanie specjalne, np. kabiny
iAlpha ^= 0x0F0F000F; // odwrócenie flag tekstur, aby wyłapać nieprzezroczyste
if (iAlpha & iFlags & 0x1F1F001F) // czy w ogóle jest co robić w tym cyklu?
@@ -2259,7 +2257,7 @@ void TModel3d::RaRender(double fSquareDistance, GLuint *ReplacableSkinId, int iA
}
};
void TModel3d::RaRenderAlpha(double fSquareDistance, GLuint *ReplacableSkinId, int iAlpha)
void TModel3d::RaRenderAlpha(double fSquareDistance, texture_manager::size_type *ReplacableSkinId, int iAlpha)
{ // renderowanie specjalne, np. kabiny
if (iAlpha & iFlags & 0x2F2F002F) // czy w ogóle jest co robić w tym cyklu?
{
@@ -2297,7 +2295,7 @@ globalna!
// 2011-03-16 cztery nowe funkcje renderowania z możliwością pochylania obiektów
//-----------------------------------------------------------------------------
void TModel3d::Render(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId, int iAlpha)
void TModel3d::Render(vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId, int iAlpha)
{ // nieprzezroczyste, Display List
glPushMatrix();
glTranslated(vPosition->x, vPosition->y, vPosition->z);
@@ -2314,7 +2312,7 @@ void TModel3d::Render(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSki
Root->RenderDL();
glPopMatrix();
};
void TModel3d::RenderAlpha(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId,
void TModel3d::RenderAlpha(vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId,
int iAlpha)
{ // przezroczyste, Display List
glPushMatrix();
@@ -2331,7 +2329,7 @@ void TModel3d::RenderAlpha(vector3 *vPosition, vector3 *vAngle, GLuint *Replacab
Root->RenderAlphaDL();
glPopMatrix();
};
void TModel3d::RaRender(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId, int iAlpha)
void TModel3d::RaRender( vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId, int iAlpha )
{ // nieprzezroczyste, VBO
glPushMatrix();
glTranslated(vPosition->x, vPosition->y, vPosition->z);
@@ -2351,7 +2349,7 @@ void TModel3d::RaRender(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableS
}
glPopMatrix();
};
void TModel3d::RaRenderAlpha(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId,
void TModel3d::RaRenderAlpha(vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId,
int iAlpha)
{ // przezroczyste, VBO
glPushMatrix();

View File

@@ -15,6 +15,7 @@ http://mozilla.org/MPL/2.0/.
#include "dumb3d.h"
#include "Float3d.h"
#include "VBO.h"
#include "Texture.h"
using namespace Math3D;
@@ -215,7 +216,7 @@ class TSubModel
// światła
float fCosViewAngle; // cos kata pod jakim sie teraz patrzy
// Ra: dalej są zmienne robocze, można je przestawiać z zachowaniem rozmiaru klasy
int TextureID; // numer tekstury, -1 wymienna, 0 brak
texture_manager::size_type TextureID; // numer tekstury, -1 wymienna, 0 brak
bool bWire; // nie używane, ale wczytywane
// short TexAlpha; //Ra: nie używane już
GLuint uiDisplayList; // roboczy numer listy wyświetlania
@@ -254,7 +255,7 @@ class TSubModel
public:
static size_t iInstance; // identyfikator egzemplarza, który aktualnie renderuje model
static GLuint *ReplacableSkinId;
static texture_manager::size_type *ReplacableSkinId;
static int iAlpha; // maska bitowa dla danego przebiegu
static double fSquareDist;
static TModel3d *pRoot;
@@ -273,7 +274,7 @@ class TSubModel
{
return Child;
};
int TriangleAdd(TModel3d *m, int tex, int tri);
int TriangleAdd(TModel3d *m, texture_manager::size_type tex, int tri);
float8 * TrianglePtr(int tex, int pos, int *la, int *ld, int *ls);
// float8* TrianglePtr(const char *tex,int tri);
// void SetRotate(vector3 vNewRotateAxis,float fNewAngle);
@@ -313,7 +314,7 @@ class TSubModel
void InfoSet(TSubModelInfo *info);
void BinInit(TSubModel *s, float4x4 *m, float8 *v, TStringPack *t, TStringPack *n = NULL,
bool dynamic = false);
void ReplacableSet(GLuint *r, int a)
void ReplacableSet(texture_manager::size_type *r, int a)
{
ReplacableSkinId = r;
iAlpha = a;
@@ -412,29 +413,29 @@ class TModel3d : public CMesh
void SaveToBinFile(char const *FileName);
void BreakHierarhy();
// renderowanie specjalne
void Render(double fSquareDistance, GLuint *ReplacableSkinId = NULL, int iAlpha = 0x30300030);
void RenderAlpha(double fSquareDistance, GLuint *ReplacableSkinId = NULL,
void Render(double fSquareDistance, texture_manager::size_type *ReplacableSkinId = NULL, int iAlpha = 0x30300030);
void RenderAlpha(double fSquareDistance, texture_manager::size_type *ReplacableSkinId = NULL,
int iAlpha = 0x30300030);
void RaRender(double fSquareDistance, GLuint *ReplacableSkinId = NULL, int iAlpha = 0x30300030);
void RaRenderAlpha(double fSquareDistance, GLuint *ReplacableSkinId = NULL,
void RaRender(double fSquareDistance, texture_manager::size_type *ReplacableSkinId = NULL, int iAlpha = 0x30300030);
void RaRenderAlpha(double fSquareDistance, texture_manager::size_type *ReplacableSkinId = NULL,
int iAlpha = 0x30300030);
// jeden kąt obrotu
void Render(vector3 pPosition, double fAngle = 0, GLuint *ReplacableSkinId = NULL,
void Render(vector3 pPosition, double fAngle = 0, texture_manager::size_type *ReplacableSkinId = NULL,
int iAlpha = 0x30300030);
void RenderAlpha(vector3 pPosition, double fAngle = 0, GLuint *ReplacableSkinId = NULL,
void RenderAlpha(vector3 pPosition, double fAngle = 0, texture_manager::size_type *ReplacableSkinId = NULL,
int iAlpha = 0x30300030);
void RaRender(vector3 pPosition, double fAngle = 0, GLuint *ReplacableSkinId = NULL,
void RaRender(vector3 pPosition, double fAngle = 0, texture_manager::size_type *ReplacableSkinId = NULL,
int iAlpha = 0x30300030);
void RaRenderAlpha(vector3 pPosition, double fAngle = 0, GLuint *ReplacableSkinId = NULL,
void RaRenderAlpha(vector3 pPosition, double fAngle = 0, texture_manager::size_type *ReplacableSkinId = NULL,
int iAlpha = 0x30300030);
// trzy kąty obrotu
void Render(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId = NULL,
void Render( vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId = NULL,
int iAlpha = 0x30300030);
void RenderAlpha(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId = NULL,
void RenderAlpha( vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId = NULL,
int iAlpha = 0x30300030);
void RaRender(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId = NULL,
void RaRender( vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId = NULL,
int iAlpha = 0x30300030);
void RaRenderAlpha(vector3 *vPosition, vector3 *vAngle, GLuint *ReplacableSkinId = NULL,
void RaRenderAlpha( vector3 *vPosition, vector3 *vAngle, texture_manager::size_type *ReplacableSkinId = NULL,
int iAlpha = 0x30300030);
// inline int GetSubModelsCount() { return (SubModelsCount); };
int Flags()

View File

@@ -289,10 +289,22 @@ void TPythonScreenRenderer::updateTexture()
#endif // _PY_INT_MORE_LOG
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindTexture(GL_TEXTURE_2D, _textureId);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE,
textureData);
// setup texture parameters
if( GLEW_VERSION_1_4 ) {
glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
glTexEnvf( GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -1.0 );
}
else {
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
}
// build texture
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, textureData);
#ifdef _PY_INT_MORE_LOG
GLenum status = glGetError();
switch (status)
@@ -407,7 +419,7 @@ void TPythonScreens::reset(void *train)
_terminationFlag = true;
if (_thread != NULL)
{
WriteLog("Awaiting python thread to end");
// WriteLog("Awaiting python thread to end");
WaitForSingleObject(_thread, INFINITE);
_thread = NULL;
}
@@ -428,61 +440,43 @@ void TPythonScreens::reset(void *train)
void TPythonScreens::init(cParser &parser, TModel3d *model, std::string const &name, int const cab)
{
char buff[255];
std::string asSubModelName, asPyClassName;
parser.getTokens( 2, false );
parser
>> asSubModelName
>> asPyClassName;
char *subModelName = (char *)calloc(asSubModelName.length() + 1, sizeof(char));
strcpy(subModelName, ToLower( asSubModelName).c_str());
char *pyClassName = (char *)calloc(asPyClassName.length() + 1, sizeof(char));
strcpy(pyClassName, ToLower( asPyClassName ).c_str());
TSubModel *subModel = model->GetFromName(subModelName);
std::string subModelName = ToLower( asSubModelName );
std::string pyClassName = ToLower( asPyClassName );
TSubModel *subModel = model->GetFromName(subModelName.c_str());
if (subModel == NULL)
{
sprintf(buff, "Python Screen: submodel %s not found - Ignoring screen", subModelName);
WriteLog(buff);
free(subModelName);
free(pyClassName);
WriteLog( "Python Screen: submodel " + subModelName + " not found - Ignoring screen" );
return; // nie ma takiego sub modelu w danej kabinie pomijamy
}
int textureId = subModel->GetTextureId();
int textureId = TextureManager.Texture(subModel->GetTextureId()).id;
if (textureId <= 0)
{
sprintf(buff, "Python Screen: invalid texture id %d - Ignoring screen", textureId);
WriteLog(buff);
free(subModelName);
free(pyClassName);
WriteLog( "Python Screen: invalid texture id " + std::to_string(textureId) + " - Ignoring screen" );
return; // sub model nie posiada tekstury lub tekstura wymienna - nie obslugiwana
}
TPythonInterpreter *python = TPythonInterpreter::getInstance();
python->loadClassFile(_lookupPath, pyClassName);
PyObject *args = Py_BuildValue("(ssi)", _lookupPath, name.c_str(), cab);
PyObject *args = Py_BuildValue("(ssi)", _lookupPath.c_str(), name.c_str(), cab);
if (args == NULL)
{
WriteLog("Python Screen: cannot create __init__ arguments");
free(subModelName);
free(pyClassName);
return;
}
PyObject *pyRenderer = python->newClass(pyClassName, args);
Py_CLEAR(args);
if (pyRenderer == NULL)
{
sprintf(buff, "Python Screen: null renderer for %s - Ignoring screen", pyClassName);
WriteLog(buff);
free(subModelName);
free(pyClassName);
WriteLog( "Python Screen: null renderer for " + pyClassName + " - Ignoring screen" );
return; // nie mozna utworzyc obiektu Pythonowego
}
TPythonScreenRenderer *renderer = new TPythonScreenRenderer(textureId, pyRenderer);
_screens.push_back(renderer);
sprintf(buff, "Created python screen %s on submodel %s (%d)", pyClassName, subModelName,
textureId);
WriteLog(buff);
free(subModelName);
free(pyClassName);
WriteLog( "Created python screen " + pyClassName + " on submodel " + subModelName + " (" + std::to_string(textureId) + ")" );
}
void TPythonScreens::update()

View File

@@ -36,7 +36,7 @@ class TPythonInterpreter
TPythonInterpreter();
~TPythonInterpreter() {}
static TPythonInterpreter *_instance;
int _screenRendererPriority;
int _screenRendererPriority = 0;
// std::set<const char *, ltstr> _classes;
std::set<std::string> _classes;
PyObject *_main;

View File

@@ -641,7 +641,7 @@ void TSegment::RenderSwitchRail(const vector6 *ShapePoints1, const vector6 *Shap
void TSegment::Render()
{
vector3 pt;
glBindTexture(GL_TEXTURE_2D, 0);
TextureManager.Bind(0);
if (bCurve)
{
glColor3f(0, 0, 1.0f);

File diff suppressed because it is too large Load Diff

127
Texture.h
View File

@@ -12,49 +12,90 @@ http://mozilla.org/MPL/2.0/.
#include <string>
#include "GL/glew.h"
enum class resource_state {
none,
loading,
good,
failed
};
struct opengl_texture {
// methods
void load();
void create();
// members
GLuint id{ -1 }; // associated GL resource
bool has_alpha{ false }; // indicates the texture has alpha channel
bool is_ready{ false }; // indicates the texture was processed and is ready for use
std::string traits; // requested texture attributes: wrapping modes etc
std::string name; // name of the texture source file
private:
// methods
void load_BMP();
void load_DDS();
void load_TEX();
void load_TGA();
void set_filtering();
// members
std::vector<char> data; // texture data
resource_state data_state{ resource_state::none }; // current state of texture data
int data_width{ 0 },
data_height{ 0 },
data_mapcount{ 0 };
GLuint data_format{ 0 },
data_components{ 0 };
/*
//Ra: miejsce umieszczenia tego jest deczko bezsensowne
void glDebug()
{//logowanie błędów OpenGL
GLenum err;
if (Global::iErorrCounter==326) //tu wpisz o 1 mniej niz wartość, przy której się wyłożyło
Global::iErorrCounter=Global::iErorrCounter+0; //do zastawiania pułapki przed błędnym kodem
while ((err=glGetError())!=GL_NO_ERROR) //dalej jest pułapka po wykonaniu błędnego kodu
WriteLog("OpenGL error found: "+AnsiString(err)+", step:"+AnsiString(Global::iErorrCounter));
++Global::iErorrCounter;
};
std::atomic<bool> is_loaded{ false }; // indicates the texture data was loaded and can be processed
std::atomic<bool> is_good{ false }; // indicates the texture data was retrieved without errors
*/
class TTexturesManager
{
public:
static void Init();
static void Free();
static GLuint GetTextureID(char *dir, char *where, std::string name, int filter = -1);
static bool GetAlpha(GLuint ID); // McZapkie-141203: czy tekstura ma polprzeroczystosc
static std::string GetName(GLuint id);
private:
typedef std::pair<GLuint, bool> AlphaValue;
typedef std::map<std::string, GLuint> Names;
typedef std::map<GLuint, bool> Alphas;
static Names::iterator LoadFromFile(std::string name, int filter = -1);
static AlphaValue LoadBMP(std::string const &fileName);
static AlphaValue LoadTEX(std::string fileName);
static AlphaValue LoadTGA(std::string fileName, int filter = -1);
static AlphaValue LoadDDS(std::string fileName, int filter = -1);
static void SetFiltering(int filter);
static void SetFiltering(bool alpha, bool hash);
static GLuint CreateTexture(GLubyte *buff, GLint bpp, int width, int height, bool bHasAlpha,
bool bHash, bool bDollar = true, int filter = -1);
static Names _names;
static Alphas _alphas;
// std::list<TTexture> Textures;
};
//---------------------------------------------------------------------------
class texture_manager {
private:
typedef std::vector<opengl_texture> opengltexture_array;
public:
// typedef opengltexture_array::size_type size_type;
typedef int size_type;
texture_manager();
~texture_manager() { Free(); }
size_type GetTextureId( std::string Filename, std::string const &Dir, int const Filter = -1, bool const Loadnow = true );
void Bind( size_type const Id );
opengl_texture &Texture( size_type const Id ) { return m_textures.at( Id ); }
void Init();
void Free();
private:
typedef std::unordered_map<std::string, size_type> index_map;
/*
opengltexture_array::size_type LoadFromFile(std::string name, int filter = -1);
*/
/*
bool LoadBMP( std::string const &fileName);
bool LoadTEX( std::string fileName );
bool LoadTGA( std::string fileName, int filter = -1 );
bool LoadDDS( std::string fileName, int filter = -1 );
*/
// checks whether specified texture is in the texture bank. returns texture id, or npos.
size_type find_in_databank( std::string const &Texturename );
// checks whether specified file exists. returns name of the located file, or empty string.
std::string find_on_disk( std::string const &Texturename );
/*
void SetFiltering(int filter);
void SetFiltering(bool alpha, bool hash);
GLuint CreateTexture(GLubyte *buff, GLint bpp, int width, int height, bool bHasAlpha,
bool bHash, bool bDollar = true, int filter = -1);
*/
static const size_type npos{ 0 }; // should be -1, but the rest of the code uses -1 for something else
opengltexture_array m_textures;
index_map m_texturemappings;
size_type m_activetexture{ 0 }; // last i.e. currently bound texture
};
extern texture_manager TextureManager;

View File

@@ -507,8 +507,8 @@ void TTrack::Load(cParser *parser, vector3 pOrigin, std::string name)
parser->getTokens();
*parser >> token;
str = token; // railtex
TextureID1 = (str == "none" ? 0 : TTexturesManager::GetTextureID(
szTexturePath, szSceneryPath, str,
TextureID1 = (str == "none" ? 0 : TextureManager.GetTextureId(
str, szTexturePath,
(iCategoryFlag & 1) ? Global::iRailProFiltering :
Global::iBallastFiltering));
parser->getTokens();
@@ -518,8 +518,8 @@ void TTrack::Load(cParser *parser, vector3 pOrigin, std::string name)
parser->getTokens();
*parser >> token;
str = token; // sub || railtex
TextureID2 = (str == "none" ? 0 : TTexturesManager::GetTextureID(
szTexturePath, szSceneryPath, str,
TextureID2 = (str == "none" ? 0 : TextureManager.GetTextureId(
str, szTexturePath,
(eType == tt_Normal) ? Global::iBallastFiltering :
Global::iRailProFiltering));
parser->getTokens(3);
@@ -578,12 +578,12 @@ void TTrack::Load(cParser *parser, vector3 pOrigin, std::string name)
if (TextureID1 && fTexLength)
{ // dla drogi trzeba ustalić proporcje boków nawierzchni
float w, h;
glBindTexture(GL_TEXTURE_2D, TextureID1);
TextureManager.Bind(TextureID1);
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
if (h != 0.0)
fTexRatio1 = w / h; // proporcja boków
glBindTexture(GL_TEXTURE_2D, TextureID2);
TextureManager.Bind(TextureID2);
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
glGetTexLevelParameterfv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h);
if (h != 0.0)
@@ -1298,14 +1298,14 @@ void TTrack::Compile(GLuint tex)
}
}
if (!tex)
glBindTexture(GL_TEXTURE_2D, TextureID2);
TextureManager.Bind( TextureID2 );
Segment->RenderLoft(bpts1, iTrapezoid ? -4 : 4, fTexLength);
}
if (TextureID1)
if (tex ? TextureID1 == tex : true) // jeśli pasuje do grupy (tex)
{ // szyny
if (!tex)
glBindTexture(GL_TEXTURE_2D, TextureID1);
TextureManager.Bind( TextureID1 );
Segment->RenderLoft(rpts1, iTrapezoid ? -nnumPts : nnumPts, fTexLength);
Segment->RenderLoft(rpts2, iTrapezoid ? -nnumPts : nnumPts, fTexLength);
}
@@ -1344,7 +1344,7 @@ void TTrack::Compile(GLuint tex)
// McZapkie-130302 - poprawione rysowanie szyn
if (SwitchExtension->RightSwitch)
{ // zwrotnica prawa
glBindTexture(GL_TEXTURE_2D, TextureID1);
TextureManager.Bind( TextureID1 );
SwitchExtension->Segments[0]->RenderLoft(rpts1, nnumPts, fTexLength,
2); // prawa szyna za iglicą
SwitchExtension->Segments[0]->RenderSwitchRail(
@@ -1353,7 +1353,7 @@ void TTrack::Compile(GLuint tex)
SwitchExtension->Segments[0]->RenderLoft(
rpts2, nnumPts, fTexLength); // lewa szyna normalnie cała
if (TextureID2 != TextureID1) // nie wiadomo, czy OpenGL to optymalizuje
glBindTexture(GL_TEXTURE_2D, TextureID2);
TextureManager.Bind( TextureID2 );
SwitchExtension->Segments[1]->RenderLoft(
rpts1, nnumPts, fTexLength); // prawa szyna normalna cała
SwitchExtension->Segments[1]->RenderLoft(rpts2, nnumPts, fTexLength,
@@ -1364,7 +1364,7 @@ void TTrack::Compile(GLuint tex)
}
else
{ // lewa kiedyś działała lepiej niż prawa
glBindTexture(GL_TEXTURE_2D, TextureID1);
TextureManager.Bind( TextureID1 );
SwitchExtension->Segments[0]->RenderLoft(
rpts1, nnumPts, fTexLength); // prawa szyna normalna cała
SwitchExtension->Segments[0]->RenderLoft(rpts2, nnumPts, fTexLength,
@@ -1373,7 +1373,7 @@ void TTrack::Compile(GLuint tex)
rpts2, rpts4, nnumPts, fTexLength, 2,
-SwitchExtension->fOffset2); // lewa iglica
if (TextureID2 != TextureID1) // nie wiadomo, czy OpenGL to optymalizuje
glBindTexture(GL_TEXTURE_2D, TextureID2);
TextureManager.Bind( TextureID2 );
SwitchExtension->Segments[1]->RenderLoft(rpts1, nnumPts, fTexLength,
2); // prawa szyna za iglicą
SwitchExtension->Segments[1]->RenderSwitchRail(
@@ -1421,7 +1421,7 @@ void TTrack::Compile(GLuint tex)
if (tex ? TextureID1 == tex : true) // jeśli pasuje do grupy (tex)
{ // tworzenie trójkątów nawierzchni szosy
if (!tex)
glBindTexture(GL_TEXTURE_2D, TextureID1);
TextureManager.Bind( TextureID1 );
Segment->RenderLoft(bpts1, iTrapezoid ? -2 : 2, fTexLength);
}
if (TextureID2)
@@ -1429,7 +1429,7 @@ void TTrack::Compile(GLuint tex)
{ // pobocze drogi - poziome przy przechyłce (a może krawężnik i chodnik zrobić jak
// w Midtown Madness 2?)
if (!tex)
glBindTexture(GL_TEXTURE_2D, TextureID2);
TextureManager.Bind( TextureID2 );
vector6 rpts1[6],
rpts2[6]; // współrzędne przekroju i mapowania dla prawej i lewej strony
if (fTexHeight1 >= 0.0)
@@ -1609,7 +1609,7 @@ void TTrack::Compile(GLuint tex)
// Midtown Madness 2?)
if (TextureID2)
if (!tex)
glBindTexture(GL_TEXTURE_2D, TextureID2);
TextureManager.Bind( TextureID2 );
vector6 rpts1[6],
rpts2[6]; // współrzędne przekroju i mapowania dla prawej i lewej strony
// Ra 2014-07: trzeba to przerobić na pętlę i pobierać profile (przynajmniej 2..4) z
@@ -1754,7 +1754,7 @@ void TTrack::Compile(GLuint tex)
if (tex ? TextureID1 == tex : true) // jeśli pasuje do grupy (tex)
{
if (!tex)
glBindTexture(GL_TEXTURE_2D, TextureID1);
TextureManager.Bind( TextureID1 );
glBegin(GL_TRIANGLE_FAN); // takie kółeczko będzie
glNormal3f(0, 1, 0);
glTexCoord2f(0.5, 0.5); //środek tekstury na środku skrzyżowania
@@ -1786,7 +1786,7 @@ void TTrack::Compile(GLuint tex)
if (tex ? TextureID1 == tex : true) // jeśli pasuje do grupy (tex)
{
if (!tex)
glBindTexture(GL_TEXTURE_2D, TextureID1);
TextureManager.Bind( TextureID1 );
Segment->RenderLoft(bpts1, numPts, fTexLength);
}
if (TextureID2)
@@ -1798,7 +1798,7 @@ void TTrack::Compile(GLuint tex)
vector6 rpts2[3] = {vector6(-fHTW, 0.0, 1.0), vector6(-fHTW - side, 0.0, 0.5),
vector6(-rozp, -fTexHeight1, 0.0)}; // Ra: po kiego 0.1?
if (!tex)
glBindTexture(GL_TEXTURE_2D, TextureID2); // brzeg rzeki
TextureManager.Bind( TextureID2 ); // brzeg rzeki
Segment->RenderLoft(rpts1, 3, fTexLength);
Segment->RenderLoft(rpts2, 3, fTexLength);
}
@@ -2472,7 +2472,7 @@ void TTrack::RaRenderVBO(int iPtr)
if (TextureID1)
if ((seg = SwitchExtension->Segments[0]->RaSegCount()) > 0)
{
glBindTexture(GL_TEXTURE_2D, TextureID1); // szyny +
TextureManager.Bind( TextureID1 ); // szyny +
for (i = 0; i < seg; ++i)
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 24 * i, 24);
iPtr += 24 * seg; // pominięcie lewej szyny
@@ -2483,7 +2483,7 @@ void TTrack::RaRenderVBO(int iPtr)
if (TextureID2)
if ((seg = SwitchExtension->Segments[1]->RaSegCount()) > 0)
{
glBindTexture(GL_TEXTURE_2D, TextureID2); // szyny -
TextureManager.Bind( TextureID2 ); // szyny -
for (i = 0; i < seg; ++i)
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 24 * i, 24);
iPtr += 24 * seg; // pominięcie lewej szyny
@@ -2497,14 +2497,14 @@ void TTrack::RaRenderVBO(int iPtr)
{
if (TextureID2)
{
glBindTexture(GL_TEXTURE_2D, TextureID2); // podsypka
TextureManager.Bind( TextureID2 ); // podsypka
for (i = 0; i < seg; ++i)
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 8 * i, 8);
iPtr += 8 * seg; // pominięcie podsypki
}
if (TextureID1)
{
glBindTexture(GL_TEXTURE_2D, TextureID1); // szyny
TextureManager.Bind( TextureID1 ); // szyny
for (i = 0; i < seg; ++i)
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 24 * i, 24);
iPtr += 24 * seg; // pominięcie lewej szyny
@@ -2519,7 +2519,7 @@ void TTrack::RaRenderVBO(int iPtr)
{
if (TextureID1)
{
glBindTexture(GL_TEXTURE_2D, TextureID1); // nawierzchnia
TextureManager.Bind( TextureID1 ); // nawierzchnia
for (i = 0; i < seg; ++i)
{
glDrawArrays(GL_TRIANGLE_STRIP, iPtr, 4);
@@ -2528,7 +2528,7 @@ void TTrack::RaRenderVBO(int iPtr)
}
if (TextureID2)
{
glBindTexture(GL_TEXTURE_2D, TextureID2); // pobocze
TextureManager.Bind( TextureID2 ); // pobocze
if (fTexHeight1 >= 0.0)
{ // normalna droga z poboczem
for (i = 0; i < seg; ++i)
@@ -2557,7 +2557,7 @@ void TTrack::RaRenderVBO(int iPtr)
{
if (TextureID1)
{
glBindTexture(GL_TEXTURE_2D, TextureID1); // nawierzchnia
TextureManager.Bind( TextureID1 ); // nawierzchnia
for (i = 0; i < seg; ++i)
{
glDrawArrays(GL_TRIANGLE_STRIP, iPtr, 4);
@@ -2566,7 +2566,7 @@ void TTrack::RaRenderVBO(int iPtr)
}
if (TextureID2)
{
glBindTexture(GL_TEXTURE_2D, TextureID2); // pobocze
TextureManager.Bind( TextureID2 ); // pobocze
for (i = 0; i < seg; ++i)
glDrawArrays(GL_TRIANGLE_STRIP, iPtr + 6 * i, 6);
iPtr += 6 * seg; // pominięcie lewego pobocza

View File

@@ -13,6 +13,7 @@ http://mozilla.org/MPL/2.0/.
#include "GL/glew.h"
#include "ResourceManager.h"
#include "Segment.h"
#include "Texture.h"
class TEvent;
@@ -136,8 +137,8 @@ class TTrack : public Resource
TTrack *trNext = nullptr; // odcinek od strony punktu 2 - to powinno być w segmencie
TTrack *trPrev = nullptr; // odcinek od strony punktu 1
// McZapkie-070402: dodalem zmienne opisujace rozmiary tekstur
GLuint TextureID1 = 0; // tekstura szyn albo nawierzchni
GLuint TextureID2 = 0; // tekstura automatycznej podsypki albo pobocza
texture_manager::size_type TextureID1 = 0; // tekstura szyn albo nawierzchni
texture_manager::size_type TextureID2 = 0; // tekstura automatycznej podsypki albo pobocza
float fTexLength = 4.0f; // długość powtarzania tekstury w metrach
float fTexRatio1 = 1.0f; // proporcja boków tekstury nawierzchni (żeby zaoszczędzić na rozmiarach tekstur...)
float fTexRatio2 = 1.0f; // proporcja boków tekstury chodnika (żeby zaoszczędzić na rozmiarach tekstur...)

View File

@@ -18,6 +18,7 @@ http://mozilla.org/MPL/2.0/.
#include "logs.h"
#include "mctools.h"
#include "TractionPower.h"
#include "Texture.h"
//---------------------------------------------------------------------------
/*
@@ -115,7 +116,7 @@ void TTraction::Optimize()
uiDisplayList = glGenLists(1);
glNewList(uiDisplayList, GL_COMPILE);
glBindTexture(GL_TEXTURE_2D, 0);
TextureManager.Bind(0);
// glColor3ub(0,0,0); McZapkie: to do render
// glPushMatrix();
@@ -462,7 +463,7 @@ void TTraction::RenderVBO(float mgn, int iPtr)
{ // renderowanie z użyciem VBO
if (Wires != 0 && !TestFlag(DamageFlag, 128)) // rysuj jesli sa druty i nie zerwana
{
glBindTexture(GL_TEXTURE_2D, 0);
TextureManager.Bind(0);
glDisable(GL_LIGHTING); // aby nie używało wektorów normalnych do kolorowania
glColor4f(0, 0, 0, 1); // jak nieznany kolor to czarne nieprzezroczyste
if (!Global::bSmoothTraction)

224
Train.cpp
View File

@@ -186,6 +186,27 @@ TTrain::TTrain()
dsbBufferClamp = NULL;
iRadioChannel = 0;
fTachoTimer = 0.0; // włączenie skoków wskazań prędkościomierza
//
for( int i = 0; i < 8; i++ ) {
bMains[ i ] = false;
fCntVol[ i ] = 0.0f;
bPants[ i ][ 0 ] = false;
bPants[ i ][ 1 ] = false;
bFuse[ i ] = false;
bBatt[ i ] = false;
bConv[ i ] = false;
bComp[ i ][ 0 ] = false;
bComp[ i ][ 1 ] = false;
bHeat[ i ] = false;
}
for( int i = 0; i < 9; ++i )
for( int j = 0; j < 10; ++j )
fEIMParams[ i ][ j ] = 0.0;
for( int i = 0; i < 20; ++i )
for( int j = 0; j < 3; ++j )
fPress[ i ][ j ] = 0.0;
}
TTrain::~TTrain()
@@ -267,139 +288,98 @@ bool TTrain::Init(TDynamicObject *NewDynamicObject, bool e3d)
return true;
}
PyObject *TTrain::GetTrainState()
{
PyObject *TTrain::GetTrainState() {
PyObject *dict = PyDict_New();
if (dict == NULL)
{
if( dict == NULL ) {
return NULL;
}
PyDict_SetItemString(dict, "direction", PyGetInt(DynamicObject->MoverParameters->ActiveDir));
PyDict_SetItemString(dict, "cab", PyGetInt(DynamicObject->MoverParameters->ActiveCab));
PyDict_SetItemString(dict, "slipping_wheels",
PyGetBool(DynamicObject->MoverParameters->SlippingWheels));
PyDict_SetItemString(dict, "converter",
PyGetBool(DynamicObject->MoverParameters->ConverterFlag));
PyDict_SetItemString(dict, "main_ctrl_actual_pos",
PyGetInt(DynamicObject->MoverParameters->MainCtrlActualPos));
PyDict_SetItemString(dict, "scnd_ctrl_actual_pos",
PyGetInt(DynamicObject->MoverParameters->ScndCtrlActualPos));
PyDict_SetItemString(dict, "fuse", PyGetBool(DynamicObject->MoverParameters->FuseFlag));
PyDict_SetItemString(dict, "converter_overload",
PyGetBool(DynamicObject->MoverParameters->ConvOvldFlag));
PyDict_SetItemString(dict, "voltage", PyGetFloat(DynamicObject->MoverParameters->Voltage));
PyDict_SetItemString(dict, "velocity", PyGetFloat(DynamicObject->MoverParameters->Vel));
PyDict_SetItemString(dict, "im", PyGetFloat(DynamicObject->MoverParameters->Im));
PyDict_SetItemString(dict, "compress",
PyGetBool(DynamicObject->MoverParameters->CompressorFlag));
PyDict_SetItemString(dict, "hours", PyGetInt(GlobalTime->hh));
PyDict_SetItemString(dict, "minutes", PyGetInt(GlobalTime->mm));
PyDict_SetItemString(dict, "seconds", PyGetInt(GlobalTime->mr));
PyDict_SetItemString(dict, "velocity_desired", PyGetFloat(DynamicObject->Mechanik->VelDesired));
char *TXTT[10] = {"fd", "fdt", "fdb", "pd", "pdt", "pdb", "itothv", "1", "2", "3"};
char *TXTC[10] = {"fr", "frt", "frb", "pr", "prt", "prb", "im", "vm", "ihv", "uhv"};
char *TXTP[3] = {"bc", "bp", "sp"};
for (int j = 0; j < 10; j++)
{
PyDict_SetItemString(dict, std::string("eimp_t_" + std::string(TXTT[j])).c_str(),
PyGetFloatS(fEIMParams[0][j]));
PyDict_SetItemString( dict, "direction", PyGetInt( DynamicObject->MoverParameters->ActiveDir ) );
PyDict_SetItemString( dict, "cab", PyGetInt( DynamicObject->MoverParameters->ActiveCab ) );
PyDict_SetItemString( dict, "slipping_wheels",
PyGetBool( DynamicObject->MoverParameters->SlippingWheels ) );
PyDict_SetItemString( dict, "converter",
PyGetBool( DynamicObject->MoverParameters->ConverterFlag ) );
PyDict_SetItemString( dict, "main_ctrl_actual_pos",
PyGetInt( DynamicObject->MoverParameters->MainCtrlActualPos ) );
PyDict_SetItemString( dict, "scnd_ctrl_actual_pos",
PyGetInt( DynamicObject->MoverParameters->ScndCtrlActualPos ) );
PyDict_SetItemString( dict, "fuse", PyGetBool( DynamicObject->MoverParameters->FuseFlag ) );
PyDict_SetItemString( dict, "converter_overload",
PyGetBool( DynamicObject->MoverParameters->ConvOvldFlag ) );
PyDict_SetItemString( dict, "voltage", PyGetFloat( DynamicObject->MoverParameters->Voltage ) );
PyDict_SetItemString( dict, "velocity", PyGetFloat( DynamicObject->MoverParameters->Vel ) );
PyDict_SetItemString( dict, "im", PyGetFloat( DynamicObject->MoverParameters->Im ) );
PyDict_SetItemString( dict, "compress",
PyGetBool( DynamicObject->MoverParameters->CompressorFlag ) );
PyDict_SetItemString( dict, "hours", PyGetInt( GlobalTime->hh ) );
PyDict_SetItemString( dict, "minutes", PyGetInt( GlobalTime->mm ) );
PyDict_SetItemString( dict, "seconds", PyGetInt( GlobalTime->mr ) );
PyDict_SetItemString( dict, "velocity_desired", PyGetFloat( DynamicObject->Mechanik->VelDesired ) );
char* TXTT[ 10 ] = { "fd", "fdt", "fdb", "pd", "pdt", "pdb", "itothv", "1", "2", "3" };
char* TXTC[ 10 ] = { "fr", "frt", "frb", "pr", "prt", "prb", "im", "vm", "ihv", "uhv" };
char* TXTP[ 3 ] = { "bc", "bp", "sp" };
for( int j = 0; j<10; j++ )
PyDict_SetItemString( dict, ( std::string( "eimp_t_" ) + std::string( TXTT[ j ] ) ).c_str(), PyGetFloatS( fEIMParams[ 0 ][ j ] ) );
for( int i = 0; i<8; i++ ) {
for( int j = 0; j<10; j++ )
PyDict_SetItemString( dict, ( std::string( "eimp_c" ) + std::to_string( i + 1 ) + std::string( "_" ) + std::string( TXTC[ j ] ) ).c_str(), PyGetFloatS( fEIMParams[ i + 1 ][ j ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_c" ) + std::to_string( i + 1 ) + std::string( "_ms" ) ).c_str(), PyGetBool( bMains[ i ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_c" ) + std::to_string( i + 1 ) + std::string( "_cv" ) ).c_str(), PyGetFloatS( fCntVol[ i ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_u" ) + std::to_string( i + 1 ) + std::string( "_pf" ) ).c_str(), PyGetBool( bPants[ i ][ 0 ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_u" ) + std::to_string( i + 1 ) + std::string( "_pr" ) ).c_str(), PyGetBool( bPants[ i ][ 1 ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_c" ) + std::to_string( i + 1 ) + std::string( "_fuse" ) ).c_str(), PyGetBool( bFuse[ i ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_c" ) + std::to_string( i + 1 ) + std::string( "_batt" ) ).c_str(), PyGetBool( bBatt[ i ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_c" ) + std::to_string( i + 1 ) + std::string( "_conv" ) ).c_str(), PyGetBool( bConv[ i ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_u" ) + std::to_string( i + 1 ) + std::string( "_comp_a" ) ).c_str(), PyGetBool( bComp[ i ][ 0 ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_u" ) + std::to_string( i + 1 ) + std::string( "_comp_w" ) ).c_str(), PyGetBool( bComp[ i ][ 1 ] ) );
PyDict_SetItemString( dict, ( std::string( "eimp_c" ) + std::to_string( i + 1 ) + std::string( "_heat" ) ).c_str(), PyGetBool( bHeat[ i ] ) );
}
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 10; j++)
{
PyDict_SetItemString(
dict,
(std::string("eimp_c") + std::to_string(i + 1) + "_" + std::string(TXTC[j]))
.c_str(),
PyGetFloatS(fEIMParams[i + 1][j]));
}
PyDict_SetItemString(dict, (std::string("eimp_c") + std::to_string(i + 1) + "_ms").c_str(),
PyGetBool(bMains[i]));
PyDict_SetItemString(dict, (std::string("eimp_c") + std::to_string(i + 1) + "_cv").c_str(),
PyGetFloatS(fCntVol[i]));
PyDict_SetItemString(dict, (std::string("eimp_u") + std::to_string(i + 1) + "_pf").c_str(),
PyGetBool(bPants[i][0]));
PyDict_SetItemString(dict, (std::string("eimp_u") + std::to_string(i + 1) + "_pr").c_str(),
PyGetBool(bPants[i][1]));
PyDict_SetItemString(dict,
(std::string("eimp_c") + std::to_string(i + 1) + "_fuse").c_str(),
PyGetBool(bFuse[i]));
PyDict_SetItemString(dict,
(std::string("eimp_c") + std::to_string(i + 1) + "_batt").c_str(),
PyGetBool(bBatt[i]));
PyDict_SetItemString(dict,
(std::string("eimp_c") + std::to_string(i + 1) + "_conv").c_str(),
PyGetBool(bConv[i]));
PyDict_SetItemString(dict,
(std::string("eimp_u") + std::to_string(i + 1) + "_comp_a").c_str(),
PyGetBool(bComp[i][0]));
PyDict_SetItemString(dict,
(std::string("eimp_u") + std::to_string(i + 1) + "_comp_w").c_str(),
PyGetBool(bComp[i][1]));
PyDict_SetItemString(dict,
(std::string("eimp_c") + std::to_string(i + 1) + "_heat").c_str(),
PyGetBool(bHeat[i]));
}
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 3; j++)
PyDict_SetItemString(
dict,
(std::string("eimp_pn") + std::to_string(i + 1) + "_" + std::string(TXTP[j]))
.c_str(),
PyGetFloatS(fPress[i][j]));
for( int i = 0; i<20; i++ ) {
for( int j = 0; j<3; j++ )
PyDict_SetItemString( dict, ( std::string( "eimp_pn" ) + std::to_string( i + 1 ) + std::string( "_" ) + std::string( TXTP[ j ] ) ).c_str(),
PyGetFloatS( fPress[ i ][ j ] ) );
}
bool bEP, bPN;
bEP = ( mvControlled->LocHandle->GetCP() > 0.2 ) || ( fEIMParams[0][2] > 0.01 );
PyDict_SetItemString(dict, "dir_brake", PyGetBool(bEP));
if (typeid(mvControlled->Hamulec) == typeid(TLSt) ||
typeid(mvControlled->Hamulec) == typeid(TEStED))
{
bEP = ( mvControlled->LocHandle->GetCP()>0.2 ) || ( fEIMParams[ 0 ][ 2 ]>0.01 );
PyDict_SetItemString( dict, "dir_brake", PyGetBool( bEP ) );
if( ( typeid( *mvControlled->Hamulec ) == typeid( TLSt ) )
|| ( typeid( *mvControlled->Hamulec ) == typeid( TEStED ) ) ) {
TBrake* temp_ham = mvControlled->Hamulec.get();
// TLSt* temp_ham2 = temp_ham;
bPN = ( static_cast<TLSt *>( mvControlled->Hamulec.get() )->GetEDBCP() > 0.2 );
bPN = ( static_cast<TLSt*>( temp_ham )->GetEDBCP()>0.2 );
}
else
bPN = false;
PyDict_SetItemString(dict, "indir_brake", PyGetBool(bPN));
for (int i = 0; i < 20; i++)
{
PyDict_SetItemString(dict, (std::string("doors_") + std::to_string(i + 1)).c_str(),
PyGetFloatS(bDoors[i][0]));
PyDict_SetItemString(dict, (std::string("doors_r_") + std::to_string(i + 1)).c_str(),
PyGetFloatS(bDoors[i][1]));
PyDict_SetItemString(dict, (std::string("doors_l_") + std::to_string(i + 1)).c_str(),
PyGetFloatS(bDoors[i][2]));
PyDict_SetItemString(dict, (std::string("doors_no_") + std::to_string(i + 1)).c_str(),
PyGetInt(iDoorNo[i]));
PyDict_SetItemString(
dict, (std::string("code_") + std::to_string(i + 1)).c_str(),
PyGetString(std::string(std::to_string(iUnits[i]) + cCode[i]).c_str()));
PyDict_SetItemString(dict, (std::string("car_name") + std::to_string(i + 1)).c_str(),
PyGetString(asCarName[i].c_str()));
PyDict_SetItemString( dict, "indir_brake", PyGetBool( bPN ) );
for( int i = 0; i<20; i++ ) {
PyDict_SetItemString( dict, ( std::string( "doors_" ) + std::to_string( i + 1 ) ).c_str(), PyGetFloatS( bDoors[ i ][ 0 ] ) );
PyDict_SetItemString( dict, ( std::string( "doors_r_" ) + std::to_string( i + 1 ) ).c_str(), PyGetFloatS( bDoors[ i ][ 1 ] ) );
PyDict_SetItemString( dict, ( std::string( "doors_l_" ) + std::to_string( i + 1 ) ).c_str(), PyGetFloatS( bDoors[ i ][ 2 ] ) );
PyDict_SetItemString( dict, ( std::string( "doors_no_" ) + std::to_string( i + 1 ) ).c_str(), PyGetInt( iDoorNo[ i ] ) );
PyDict_SetItemString( dict, ( std::string( "code_" ) + std::to_string( i + 1 ) ).c_str(), PyGetString( std::string( std::to_string( iUnits[ i ] ) +
cCode[ i ] ).c_str() ) );
PyDict_SetItemString( dict, ( std::string( "car_name" ) + std::to_string( i + 1 ) ).c_str(), PyGetString( asCarName[ i ].c_str() ) );
}
PyDict_SetItemString(dict, "car_no", PyGetInt(iCarNo));
PyDict_SetItemString(dict, "power_no", PyGetInt(iPowerNo));
PyDict_SetItemString(dict, "unit_no", PyGetInt(iUnitNo));
PyDict_SetItemString(dict, "universal3", PyGetBool(LampkaUniversal3_st));
PyDict_SetItemString(dict, "ca",
PyGetBool(TestFlag(mvOccupied->SecuritySystem.Status, s_aware)));
PyDict_SetItemString(dict, "shp",
PyGetBool(TestFlag(mvOccupied->SecuritySystem.Status, s_active)));
PyDict_SetItemString(dict, "manual_brake", PyGetBool(mvOccupied->ManualBrakePos > 0));
PyDict_SetItemString(dict, "pantpress", PyGetFloat(mvControlled->PantPress));
PyDict_SetItemString(dict, "trainnumber",
PyGetString(DynamicObject->Mechanik->TrainName().c_str()));
PyDict_SetItemString(dict, "velnext", PyGetFloat(DynamicObject->Mechanik->VelNext));
PyDict_SetItemString(dict, "actualproximitydist",
PyGetFloat(DynamicObject->Mechanik->ActualProximityDist));
PyDict_SetItemString(dict, "velsignallast", PyGetFloat(DynamicObject->Mechanik->VelSignalLast));
PyDict_SetItemString(dict, "vellimitlast", PyGetFloat(DynamicObject->Mechanik->VelLimitLast));
PyDict_SetItemString(dict, "velroad", PyGetFloat(DynamicObject->Mechanik->VelRoad));
PyDict_SetItemString(dict, "velsignalnext", PyGetFloat(DynamicObject->Mechanik->VelSignalNext));
PyDict_SetItemString(dict, "battery", PyGetBool(mvControlled->Battery));
PyDict_SetItemString(dict, "tractionforce", PyGetFloat(DynamicObject->MoverParameters->Ft));
PyDict_SetItemString( dict, "car_no", PyGetInt( iCarNo ) );
PyDict_SetItemString( dict, "power_no", PyGetInt( iPowerNo ) );
PyDict_SetItemString( dict, "unit_no", PyGetInt( iUnitNo ) );
PyDict_SetItemString( dict, "universal3", PyGetBool( LampkaUniversal3_st ) );
PyDict_SetItemString( dict, "ca", PyGetBool( TestFlag( mvOccupied->SecuritySystem.Status, s_aware ) ) );
PyDict_SetItemString( dict, "shp", PyGetBool( TestFlag( mvOccupied->SecuritySystem.Status, s_active ) ) );
PyDict_SetItemString( dict, "manual_brake", PyGetBool( mvOccupied->ManualBrakePos > 0 ) );
PyDict_SetItemString( dict, "pantpress", PyGetFloat( mvControlled->PantPress ) );
PyDict_SetItemString( dict, "trainnumber", PyGetString( DynamicObject->Mechanik->TrainName().c_str() ) );
PyDict_SetItemString( dict, "velnext", PyGetFloat( DynamicObject->Mechanik->VelNext ) );
PyDict_SetItemString( dict, "actualproximitydist", PyGetFloat( DynamicObject->Mechanik->ActualProximityDist ) );
PyDict_SetItemString( dict, "velsignallast", PyGetFloat( DynamicObject->Mechanik->VelSignalLast ) );
PyDict_SetItemString( dict, "vellimitlast", PyGetFloat( DynamicObject->Mechanik->VelLimitLast ) );
PyDict_SetItemString( dict, "velroad", PyGetFloat( DynamicObject->Mechanik->VelRoad ) );
PyDict_SetItemString( dict, "velsignalnext", PyGetFloat( DynamicObject->Mechanik->VelSignalNext ) );
PyDict_SetItemString( dict, "battery", PyGetBool( mvControlled->Battery ) );
PyDict_SetItemString( dict, "tractionforce", PyGetFloat( DynamicObject->MoverParameters->Ft ) );
return dict;
}
@@ -5028,6 +5008,8 @@ bool TTrain::Update( double const Deltatime )
// wyprowadzenie sygnałów dla haslera na PoKeys (zaznaczanie na taśmie)
btHaslerBrakes.Turn(DynamicObject->MoverParameters->BrakePress > 0.4); // ciśnienie w cylindrach
btHaslerCurrent.Turn(DynamicObject->MoverParameters->Im != 0.0); // prąd na silnikach
m_updated = true;
return true; //(DynamicObject->Update(dt));
} // koniec update

View File

@@ -95,6 +95,7 @@ class TTrain
};
void UpdateMechPosition(double dt);
bool Update( double const Deltatime );
bool m_updated = false;
void MechStop();
void SetLights();
// virtual bool RenderAlpha();

View File

@@ -73,7 +73,6 @@ TWorld::~TWorld()
// Ground.Free(); //Ra: usunięcie obiektów przed usunięciem dźwięków - sypie się
TSoundsManager::Free();
TModelsManager::Free();
TTexturesManager::Free();
glDeleteLists(base, 96);
}
@@ -474,9 +473,8 @@ bool TWorld::Init(GLFWwindow *w)
glDisable(GL_DEPTH_TEST); // Disables depth testing
glColor3f(3.0f, 3.0f, 3.0f);
GLuint logo;
logo = TTexturesManager::GetTextureID(szTexturePath, szSceneryPath, "logo", 6);
glBindTexture(GL_TEXTURE_2D, logo); // Select our texture
auto logo = TextureManager.GetTextureId( "logo", szTexturePath, 6 );
TextureManager.Bind(logo); // Select our texture
glBegin(GL_QUADS); // Drawing using triangles
glTexCoord2f(0.0f, 0.0f);
@@ -525,7 +523,6 @@ bool TWorld::Init(GLFWwindow *w)
}
glfwSwapBuffers(window);
TTexturesManager::Init();
WriteLog("Textures init OK");
if (Global::detonatoryOK)
{
@@ -660,9 +657,9 @@ bool TWorld::Init(GLFWwindow *w)
// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); //{Texture blends with object
// background}
if (Global::bOldSmudge == true)
light = TTexturesManager::GetTextureID(szTexturePath, szSceneryPath, "smuga.tga");
light = TextureManager.GetTextureId( "smuga.tga", szTexturePath );
else
light = TTexturesManager::GetTextureID(szTexturePath, szSceneryPath, "smuga2.tga");
light = TextureManager.GetTextureId( "smuga2.tga", szTexturePath );
// Camera.Reset();
Timer::ResetTimers();
WriteLog( "Load time: " +
@@ -1204,11 +1201,15 @@ bool TWorld::Update()
// przy 0.25 smuga gaśnie o 6:37 w Quarku, a mogłaby już 5:40
// Ra 2014-12: przy 0.15 się skarżyli, że nie widać smug => zmieniłem na 0.25
// changed light activation threshold to 0.5, paired with strength reduction in daylight
if (Train) // jeśli nie usunięty
Global::bSmudge =
FreeFlyModeFlag ? false : ((Train->Dynamic()->fShade <= 0.0) ?
(Global::fLuminance <= 0.25) :
(Train->Dynamic()->fShade * Global::fLuminance <= 0.25));
( FreeFlyModeFlag ?
false :
( Train->Dynamic()->fShade <= 0.0 ?
(Global::fLuminance <= 0.5) :
(Train->Dynamic()->fShade * Global::fLuminance <= 0.5) ) );
if (!Render())
return false;
@@ -1446,6 +1447,7 @@ bool TWorld::Render()
glColor3ub(255, 255, 255);
// glColor3b(255, 0, 255);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDepthFunc( GL_LEQUAL );
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity();
Camera.SetMatrix(); // ustawienie macierzy kamery względem początku scenerii
@@ -1525,20 +1527,36 @@ TWorld::Render_Cab() {
// 1. warunek na smugę wyznaczyc wcześniej
// 2. jeśli smuga włączona, nie renderować pojazdu użytkownika w DynObj
// 3. jeśli smuga właczona, wyrenderować pojazd użytkownia po dodaniu smugi do sceny
if( Train->Controlled()->Battery ) { // trochę na skróty z tą baterią
auto const &frontlights = Train->Controlled()->iLights[ 0 ];
float frontlightstrength = 0.f +
( ( frontlights & 1 ) ? 0.3f : 0.f ) +
( ( frontlights & 4 ) ? 0.3f : 0.f ) +
( ( frontlights & 16 ) ? 0.3f : 0.f );
frontlightstrength = std::max( frontlightstrength - Global::fLuminance, 0.0 );
auto const &rearlights = Train->Controlled()->iLights[ 1 ];
float rearlightstrength = 0.f +
( ( rearlights & 1 ) ? 0.3f : 0.f ) +
( ( rearlights & 4 ) ? 0.3f : 0.f ) +
( ( rearlights & 16 ) ? 0.3f : 0.f );
rearlightstrength = std::max( rearlightstrength - Global::fLuminance, 0.0 );
if( ( Train->Controlled()->Battery ) // trochę na skróty z tą baterią
&& ( ( frontlightstrength > 0.f )
|| ( rearlightstrength > 0.f ) ) ) {
if( Global::bOldSmudge == true ) {
glBlendFunc( GL_ONE_MINUS_SRC_ALPHA, GL_ONE );
glBlendFunc( GL_SRC_ALPHA, GL_ONE );
// glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_DST_COLOR);
// glBlendFunc(GL_SRC_ALPHA_SATURATE,GL_ONE);
glDisable( GL_DEPTH_TEST );
glDisable( GL_LIGHTING );
glDisable( GL_FOG );
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
glBindTexture( GL_TEXTURE_2D, light ); // Select our texture
TextureManager.Bind( light ); // Select our texture
glBegin( GL_QUADS );
float fSmudge =
dynamic->MoverParameters->DimHalf.y + 7; // gdzie zaczynać smugę
if( Train->Controlled()->iLights[ 0 ] & 21 ) { // wystarczy jeden zapalony z przodu
if( frontlightstrength > 0.f ) { // wystarczy jeden zapalony z przodu
glColor4f( 1.0f, 1.0f, 1.0f, 0.5f * frontlightstrength );
glTexCoord2f( 0, 0 );
glVertex3f( 15.0, 0.0, +fSmudge ); // rysowanie względem położenia modelu
glTexCoord2f( 1, 0 );
@@ -1548,7 +1566,8 @@ TWorld::Render_Cab() {
glTexCoord2f( 0, 1 );
glVertex3f( 15.0, 2.5, 250.0 );
}
if( Train->Controlled()->iLights[ 1 ] & 21 ) { // wystarczy jeden zapalony z tyłu
if( rearlightstrength > 0.f ) { // wystarczy jeden zapalony z tyłu
glColor4f( 1.0f, 1.0f, 1.0f, 0.5f * rearlightstrength );
glTexCoord2f( 0, 0 );
glVertex3f( -15.0, 0.0, -fSmudge );
glTexCoord2f( 1, 0 );
@@ -1566,6 +1585,7 @@ TWorld::Render_Cab() {
glEnable( GL_FOG );
}
else {
glBlendFunc( GL_DST_COLOR, GL_ONE );
glDepthFunc( GL_GEQUAL );
glAlphaFunc( GL_GREATER, 0.004f );
@@ -1573,27 +1593,28 @@ TWorld::Render_Cab() {
glDisable( GL_LIGHTING );
glDisable( GL_FOG );
//glColor4f(0.15f, 0.15f, 0.15f, 0.25f);
glBindTexture( GL_TEXTURE_2D, light ); // Select our texture
TextureManager.Bind( light ); // Select our texture
//float ddl = (0.15*Global::diffuseDayLight[0]+0.295*Global::diffuseDayLight[1]+0.055*Global::diffuseDayLight[2]); //0.24:0
glBegin( GL_QUADS );
float fSmudge = dynamic->MoverParameters->DimHalf.y + 7; // gdzie zaczynać smugę
if( Train->Controlled()->iLights[ 0 ] & 21 ) { // wystarczy jeden zapalony z przodu
if( frontlightstrength > 0.f ) { // wystarczy jeden zapalony z przodu
for( int i = 15; i <= 35; i++ ) {
float z = i * i * i * 0.01f;//25/4;
//float C = (36 - i*0.5)*0.005*(1.5 - sqrt(ddl));
float C = ( 36 - i*0.5 )*0.005*sqrt( ( 1 / sqrt( Global::fLuminance + 0.015 ) ) - 1 );
glColor4f( C, C, C, 0.25f );
float C = ( 36 - i*0.5 )*0.005*sqrt( ( 1 / sqrt( Global::fLuminance + 0.015 ) ) - 1 ) * frontlightstrength;
glColor4f( C, C, C, 0.35f );// *frontlightstrength );
glTexCoord2f( 0, 0 ); glVertex3f( -10 / 2 - 2 * i / 4, 6.0 + 0.3*z, 13 + 1.7*z / 3 );
glTexCoord2f( 1, 0 ); glVertex3f( 10 / 2 + 2 * i / 4, 6.0 + 0.3*z, 13 + 1.7*z / 3 );
glTexCoord2f( 1, 1 ); glVertex3f( 10 / 2 + 2 * i / 4, -5.0 - 0.5*z, 13 + 1.7*z / 3 );
glTexCoord2f( 0, 1 ); glVertex3f( -10 / 2 - 2 * i / 4, -5.0 - 0.5*z, 13 + 1.7*z / 3 );
}
}
if( Train->Controlled()->iLights[ 1 ] & 21 ) { // wystarczy jeden zapalony z tyłu
if( rearlightstrength > 0.f ) { // wystarczy jeden zapalony z tyłu
for( int i = 15; i <= 35; i++ ) {
float z = i * i * i * 0.01f;//25/4;
float C = ( 36 - i*0.5 )*0.005*sqrt( ( 1 / sqrt( Global::fLuminance + 0.015 ) ) - 1 );
glColor4f( C, C, C, 0.25f );
float C = ( 36 - i*0.5 )*0.005*sqrt( ( 1 / sqrt( Global::fLuminance + 0.015 ) ) - 1 ) * rearlightstrength;
glColor4f( C, C, C, 0.35f );// *rearlightstrength );
glTexCoord2f( 0, 0 ); glVertex3f( 10 / 2 + 2 * i / 4, 6.0 + 0.3*z, -13 - 1.7*z / 3 );
glTexCoord2f( 1, 0 ); glVertex3f( -10 / 2 - 2 * i / 4, 6.0 + 0.3*z, -13 - 1.7*z / 3 );
glTexCoord2f( 1, 1 ); glVertex3f( -10 / 2 - 2 * i / 4, -5.0 - 0.5*z, -13 - 1.7*z / 3 );
@@ -1867,12 +1888,13 @@ TWorld::Render_UI() {
Global::changeDynObj = NULL;
}
glDepthFunc( GL_ALWAYS );
glDisable( GL_LIGHTING );
glfwSetWindowTitle(window, ("EU07++NG: " + Controlled->MoverParameters->Name).c_str());
glfwSetWindowTitle(window, ("EU07++NG: " + Global::SceneryFile).c_str());
glBindTexture( GL_TEXTURE_2D, 0 );
TextureManager.Bind(0);
glColor4f( 1.0f, 0.0f, 0.0f, 1.0f );
glLoadIdentity();
glTranslatef( 0.0f, 0.0f, -0.50f );

View File

@@ -52,7 +52,7 @@ class TWorld
TDynamicObject *pDynamicNearest;
bool Paused;
GLuint base; // numer DL dla znaków w napisach
GLuint light; // numer tekstury dla smugi
texture_manager::size_type light; // numer tekstury dla smugi
TSky Clouds;
TEvent *KeyEvents[10]; // eventy wyzwalane z klawiaury
TMoverParameters *mvControlled; // wskaźnik na człon silnikowy, do wyświetlania jego parametrów

View File

@@ -77,7 +77,7 @@ class cParser //: public std::stringstream
{
return !mStream->fail();
};
bool getTokens(unsigned int Count = 1, bool ToLower = true, const char *Break = "\n\t ;");
bool getTokens(unsigned int Count = 1, bool ToLower = true, const char *Break = "\n\r\t ;");
// returns percentage of file processed so far
int getProgress() const;
// add custom definition of text which should be ignored when retrieving tokens
@@ -85,9 +85,9 @@ class cParser //: public std::stringstream
private:
// methods:
std::string readToken(bool ToLower = true, const char *Break = "\n\t ;");
std::string readToken(bool ToLower = true, const char *Break = "\n\r\t ;");
std::string readQuotes( char const Quote = '\"' );
std::string readComment( std::string const &Break = "\n\t ;" );
std::string readComment( std::string const &Break = "\n\r\t ;" );
// std::string trtest;
bool findQuotes( std::string &String );
bool trimComments( std::string &String );

View File

@@ -53,6 +53,7 @@
#include <limits>
#include <memory>
#include <thread>
#include <atomic>
#include <mutex>
#include <condition_variable>
#include <typeinfo>