mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-07-18 00:49:19 +02:00
replaced basic array in the model manager with stl containers
This commit is contained in:
@@ -223,7 +223,7 @@ void TEvent::Load(cParser *parser, vector3 *org)
|
|||||||
parser->getTokens(1, false); // case sensitive
|
parser->getTokens(1, false); // case sensitive
|
||||||
*parser >> token;
|
*parser >> token;
|
||||||
// str = AnsiString(token.c_str());
|
// str = AnsiString(token.c_str());
|
||||||
Params[0].asText = new char[token.length() + 1];
|
Params[0].asText = new char[token.length() + 1]; // BUG: source of memory leak
|
||||||
strcpy(Params[0].asText, token.c_str());
|
strcpy(Params[0].asText, token.c_str());
|
||||||
if (token != "*") // czy ma zostać bez zmian?
|
if (token != "*") // czy ma zostać bez zmian?
|
||||||
iFlags |= update_memstring;
|
iFlags |= update_memstring;
|
||||||
|
|||||||
180
MdlMngr.cpp
180
MdlMngr.cpp
@@ -17,64 +17,45 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#include "MdlMngr.h"
|
#include "MdlMngr.h"
|
||||||
|
|
||||||
#include "Globals.h"
|
#include "Globals.h"
|
||||||
#include "Logs.h"
|
|
||||||
#include "McZapkie/mctools.h"
|
#include "McZapkie/mctools.h"
|
||||||
|
|
||||||
//#define SeekFiles std::string("*.t3d")
|
// wczytanie modelu do kontenerka
|
||||||
|
TModel3d *
|
||||||
|
TMdlContainer::LoadModel(std::string const &Name, bool const Dynamic) {
|
||||||
|
|
||||||
TModel3d * TMdlContainer::LoadModel(std::string const &NewName, bool dynamic)
|
Model = std::make_shared<TModel3d>();
|
||||||
{ // wczytanie modelu do kontenerka
|
if( true == Model->LoadFromFile( Name, Dynamic ) ) {
|
||||||
SafeDelete(Model);
|
m_name = Name;
|
||||||
Name = NewName;
|
return Model.get();
|
||||||
Model = new TModel3d();
|
}
|
||||||
if (!Model->LoadFromFile(Name, dynamic)) // np. "models\\pkp/head1-y.t3d"
|
else {
|
||||||
SafeDelete(Model);
|
m_name.clear();
|
||||||
return Model;
|
Model = nullptr;
|
||||||
};
|
return nullptr;
|
||||||
|
}
|
||||||
TMdlContainer *TModelsManager::Models;
|
};
|
||||||
int TModelsManager::Count;
|
|
||||||
int const MAX_MODELS = 1000;
|
TModelsManager::modelcontainer_sequence TModelsManager::m_models;
|
||||||
|
TModelsManager::stringmodelcontainerindex_map TModelsManager::m_modelsmap;
|
||||||
void TModelsManager::Init()
|
|
||||||
{
|
// wczytanie modelu do tablicy
|
||||||
Models = new TMdlContainer[MAX_MODELS];
|
TModel3d *
|
||||||
Count = 0;
|
TModelsManager::LoadModel(std::string const &Name, bool dynamic) {
|
||||||
}
|
|
||||||
/*
|
m_models.emplace_back();
|
||||||
TModelsManager::TModelsManager()
|
auto model = m_models.back().LoadModel( Name, dynamic );
|
||||||
{
|
if( model != nullptr ) {
|
||||||
// Models= NULL;
|
m_modelsmap.emplace( Name, m_models.size() - 1 );
|
||||||
Models= new TMdlContainer[MAX_MODELS];
|
return model;
|
||||||
Count= 0;
|
}
|
||||||
};
|
else {
|
||||||
|
m_models.pop_back();
|
||||||
TModelsManager::~TModelsManager()
|
return nullptr;
|
||||||
{
|
|
||||||
Free();
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
void TModelsManager::Free()
|
|
||||||
{
|
|
||||||
delete[] Models;
|
|
||||||
Models = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
TModel3d * TModelsManager::LoadModel(std::string const &Name, bool dynamic)
|
|
||||||
{ // wczytanie modelu do tablicy
|
|
||||||
TModel3d *mdl = NULL;
|
|
||||||
if (Count >= MAX_MODELS)
|
|
||||||
Error("FIXME: Too many models, program will now crash :)");
|
|
||||||
else
|
|
||||||
{
|
|
||||||
mdl = Models[Count].LoadModel(Name, dynamic);
|
|
||||||
if (mdl)
|
|
||||||
Count++; // jeśli błąd wczytania modelu, to go nie wliczamy
|
|
||||||
}
|
}
|
||||||
return mdl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TModel3d * TModelsManager::GetModel(std::string const &Name, bool dynamic)
|
TModel3d *
|
||||||
|
TModelsManager::GetModel(std::string const &Name, bool const Dynamic)
|
||||||
{ // model może być we wpisie "node...model" albo "node...dynamic", a także być dodatkowym w dynamic
|
{ // model może być we wpisie "node...model" albo "node...dynamic", a także być dodatkowym w dynamic
|
||||||
// (kabina, wnętrze, ładunek)
|
// (kabina, wnętrze, ładunek)
|
||||||
// dla "node...dynamic" mamy podaną ścieżkę w "\dynamic\" i musi być co najmniej 1 poziom, zwkle
|
// dla "node...dynamic" mamy podaną ścieżkę w "\dynamic\" i musi być co najmniej 1 poziom, zwkle
|
||||||
@@ -97,53 +78,10 @@ TModel3d * TModelsManager::GetModel(std::string const &Name, bool dynamic)
|
|||||||
// - niebo animowane, ścieżka brana ze wpisu, tekstury nieokreślone
|
// - niebo animowane, ścieżka brana ze wpisu, tekstury nieokreślone
|
||||||
// - wczytanie modelu animowanego - Init() - sprawdzić
|
// - wczytanie modelu animowanego - Init() - sprawdzić
|
||||||
std::string buf;
|
std::string buf;
|
||||||
std::string buftp = Global::asCurrentTexturePath; // zapamiętanie aktualnej ścieżki do tekstur,
|
std::string const buftp = Global::asCurrentTexturePath; // zapamiętanie aktualnej ścieżki do tekstur,
|
||||||
// bo będzie tyczmasowo zmieniana
|
|
||||||
/*
|
|
||||||
// Ra: niby tak jest lepiej, ale działa gorzej, więc przywrócone jest oryginalne
|
|
||||||
//nawet jeśli model będzie pobrany z tablicy, to trzeba ustalić ścieżkę dla tekstur
|
|
||||||
if (dynamic) //na razie tak, bo nie wiadomo, jaki może mieć wpływ na pozostałe modele
|
|
||||||
{//dla pojazdów podana jest zawsze pełna ścieżka do modelu
|
|
||||||
strcpy(buf,Name);
|
|
||||||
if (strchr(Name,'/')!=NULL)
|
|
||||||
{//pobieranie tekstur z katalogu, w którym jest model
|
|
||||||
Global::asCurrentTexturePath=Global::asCurrentTexturePath+AnsiString(Name);
|
|
||||||
Global::asCurrentTexturePath.Delete(Global::asCurrentTexturePath.Pos("/")+1,Global::asCurrentTexturePath.Length());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{//dla modeli scenerii trzeba ustalić ścieżkę
|
|
||||||
if (strchr(Name,'\\')==NULL)
|
|
||||||
{//jeśli nie ma lewego ukośnika w ścieżce, a jest prawy, to zmienić ścieżkę dla tekstur na tę
|
|
||||||
z modelem
|
|
||||||
strcpy(buf,"models\\"); //Ra: było by lepiej katalog dodać w parserze
|
|
||||||
//strcpy(buf,"scenery\\"); //Ra: było by lepiej katalog dodać w parserze
|
|
||||||
strcat(buf,Name);
|
|
||||||
if (strchr(Name,'/')!=NULL)
|
|
||||||
{//jeszcze musi być prawy ukośnik
|
|
||||||
Global::asCurrentTexturePath=Global::asCurrentTexturePath+AnsiString(Name);
|
|
||||||
Global::asCurrentTexturePath.Delete(Global::asCurrentTexturePath.Pos("/")+1,Global::asCurrentTexturePath.Length());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{//jeśli jest lewy ukośnik, to ścieżkę do tekstur zmienić tylko dla pojazdów
|
|
||||||
strcpy(buf,Name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
StrLower(buf);
|
|
||||||
for (int i=0;i<Count;i++)
|
|
||||||
{//bezsensowne przeszukanie tabeli na okoliczność wystąpienia modelu
|
|
||||||
if (strcmp(buf,Models[i].Name)==0)
|
|
||||||
{
|
|
||||||
Global::asCurrentTexturePath=buftp; //odtworzenie ścieżki do tekstur
|
|
||||||
return (Models[i].Model); //model znaleziony
|
|
||||||
}
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
if( Name.find('\\') == std::string::npos )
|
if( Name.find('\\') == std::string::npos )
|
||||||
{
|
{
|
||||||
buf = "models\\"; // Ra: było by lepiej katalog dodać w parserze
|
buf = "models\\" + Name; // Ra: było by lepiej katalog dodać w parserze
|
||||||
buf.append( Name );
|
|
||||||
if( Name.find( '/') != std::string::npos)
|
if( Name.find( '/') != std::string::npos)
|
||||||
{
|
{
|
||||||
Global::asCurrentTexturePath = Global::asCurrentTexturePath + Name;
|
Global::asCurrentTexturePath = Global::asCurrentTexturePath + Name;
|
||||||
@@ -154,43 +92,27 @@ TModel3d * TModelsManager::GetModel(std::string const &Name, bool dynamic)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
buf = Name;
|
buf = Name;
|
||||||
if (dynamic) // na razie tak, bo nie wiadomo, jaki może mieć wpływ na pozostałe modele
|
if( Dynamic ) {
|
||||||
if (Name.find( '/') != std::string::npos)
|
// na razie tak, bo nie wiadomo, jaki może mieć wpływ na pozostałe modele
|
||||||
{ // pobieranie tekstur z katalogu, w którym jest model
|
if( Name.find( '/' ) != std::string::npos ) { // pobieranie tekstur z katalogu, w którym jest model
|
||||||
Global::asCurrentTexturePath = Global::asCurrentTexturePath + Name;
|
Global::asCurrentTexturePath = Global::asCurrentTexturePath + Name;
|
||||||
Global::asCurrentTexturePath.erase(Global::asCurrentTexturePath.find("/") + 1,
|
Global::asCurrentTexturePath.erase(
|
||||||
Global::asCurrentTexturePath.length() - 1);
|
Global::asCurrentTexturePath.find( "/" ) + 1,
|
||||||
|
Global::asCurrentTexturePath.length() - 1 );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
buf = ToLower( buf );
|
buf = ToLower( buf );
|
||||||
for (int i = 0; i < Count; ++i)
|
|
||||||
{
|
auto const lookup = m_modelsmap.find( buf );
|
||||||
if ( buf == Models[i].Name )
|
if( lookup != m_modelsmap.end() ) {
|
||||||
{
|
Global::asCurrentTexturePath = buftp;
|
||||||
Global::asCurrentTexturePath = buftp;
|
return ( m_models[ lookup->second ].Model.get() );
|
||||||
return (Models[i].Model);
|
}
|
||||||
}
|
|
||||||
};
|
auto model = LoadModel(buf, Dynamic); // model nie znaleziony, to wczytać
|
||||||
TModel3d *tmpModel = LoadModel(buf, dynamic); // model nie znaleziony, to wczytać
|
|
||||||
Global::asCurrentTexturePath = buftp; // odtworzenie ścieżki do tekstur
|
Global::asCurrentTexturePath = buftp; // odtworzenie ścieżki do tekstur
|
||||||
return (tmpModel); // NULL jeśli błąd
|
return model; // NULL jeśli błąd
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
TModel3d TModelsManager::GetModel(char *Name, AnsiString asReplacableTexture)
|
|
||||||
{
|
|
||||||
GLuint ReplacableTextureID= 0;
|
|
||||||
TModel3d NewModel;
|
|
||||||
|
|
||||||
NewModel= *GetNextModel(Name);
|
|
||||||
|
|
||||||
if (asReplacableTexture!=AnsiString("none"))
|
|
||||||
ReplacableTextureID= TTexturesManager::GetTextureID(asReplacableTexture.c_str());
|
|
||||||
|
|
||||||
NewModel.ReplacableSkinID=ReplacableTextureID;
|
|
||||||
|
|
||||||
return NewModel;
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|||||||
41
MdlMngr.h
41
MdlMngr.h
@@ -9,33 +9,28 @@ http://mozilla.org/MPL/2.0/.
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Model3d.h"
|
#include "Model3d.h"
|
||||||
#include "usefull.h"
|
|
||||||
|
|
||||||
class TMdlContainer
|
class TMdlContainer {
|
||||||
{
|
|
||||||
friend class TModelsManager;
|
friend class TModelsManager;
|
||||||
~TMdlContainer()
|
private:
|
||||||
{
|
TModel3d *LoadModel( std::string const &Name, bool const Dynamic );
|
||||||
delete Model;
|
std::shared_ptr<TModel3d> Model { nullptr };
|
||||||
};
|
std::string m_name;
|
||||||
TModel3d * LoadModel(std::string const &NewName, bool dynamic);
|
|
||||||
TModel3d *Model{ nullptr };
|
|
||||||
std::string Name;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class TModelsManager
|
// klasa statyczna, nie ma obiektu
|
||||||
{ // klasa statyczna, nie ma obiektu
|
class TModelsManager {
|
||||||
private:
|
// types:
|
||||||
static TMdlContainer *Models;
|
typedef std::deque<TMdlContainer> modelcontainer_sequence;
|
||||||
static int Count;
|
typedef std::unordered_map<std::string, modelcontainer_sequence::size_type> stringmodelcontainerindex_map;
|
||||||
static TModel3d * LoadModel(std::string const &Name, bool dynamic);
|
// members:
|
||||||
|
static modelcontainer_sequence m_models;
|
||||||
public:
|
static stringmodelcontainerindex_map m_modelsmap;
|
||||||
// TModelsManager();
|
// methods:
|
||||||
// ~TModelsManager();
|
static TModel3d *LoadModel( std::string const &Name, bool const Dynamic );
|
||||||
static void Init();
|
public:
|
||||||
static void Free();
|
|
||||||
// McZapkie: dodalem sciezke, notabene Path!=Patch :)
|
// McZapkie: dodalem sciezke, notabene Path!=Patch :)
|
||||||
static TModel3d * GetModel(std::string const &Name, bool dynamic = false);
|
static TModel3d *GetModel( std::string const &Name, bool dynamic = false );
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -909,7 +909,7 @@ texture_manager::info() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
"Textures: "
|
"; textures: "
|
||||||
#ifdef EU07_DEFERRED_TEXTURE_UPLOAD
|
#ifdef EU07_DEFERRED_TEXTURE_UPLOAD
|
||||||
+ std::to_string( readytexturecount )
|
+ std::to_string( readytexturecount )
|
||||||
+ " ("
|
+ " ("
|
||||||
|
|||||||
@@ -203,7 +203,6 @@ TWorld::~TWorld()
|
|||||||
TrainDelete();
|
TrainDelete();
|
||||||
// Ground.Free(); //Ra: usunięcie obiektów przed usunięciem dźwięków - sypie się
|
// Ground.Free(); //Ra: usunięcie obiektów przed usunięciem dźwięków - sypie się
|
||||||
TSoundsManager::Free();
|
TSoundsManager::Free();
|
||||||
TModelsManager::Free();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TWorld::TrainDelete(TDynamicObject *d)
|
void TWorld::TrainDelete(TDynamicObject *d)
|
||||||
@@ -291,8 +290,6 @@ bool TWorld::Init( GLFWwindow *Window ) {
|
|||||||
|
|
||||||
TSoundsManager::Init( glfwGetWin32Window( window ) );
|
TSoundsManager::Init( glfwGetWin32Window( window ) );
|
||||||
WriteLog("Sound Init OK");
|
WriteLog("Sound Init OK");
|
||||||
TModelsManager::Init();
|
|
||||||
WriteLog("Models init OK");
|
|
||||||
|
|
||||||
glfwSetWindowTitle( window, ( Global::AppName + " (" + Global::SceneryFile + ")" ).c_str() ); // nazwa scenerii
|
glfwSetWindowTitle( window, ( Global::AppName + " (" + Global::SceneryFile + ")" ).c_str() ); // nazwa scenerii
|
||||||
UILayer.set_progress(0.01);
|
UILayer.set_progress(0.01);
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ struct basic_vertex {
|
|||||||
glm::vec2 texture; // uv space
|
glm::vec2 texture; // uv space
|
||||||
|
|
||||||
basic_vertex() = default;
|
basic_vertex() = default;
|
||||||
basic_vertex( glm::vec3 const&Position, glm::vec3 const &Normal, glm::vec2 const &Texture ) :
|
basic_vertex( glm::vec3 const &Position, glm::vec3 const &Normal, glm::vec2 const &Texture ) :
|
||||||
position( Position ), normal( Normal ), texture( Texture )
|
position( Position ), normal( Normal ), texture( Texture )
|
||||||
{}
|
{}
|
||||||
void serialize( std::ostream& ) const;
|
void serialize( std::ostream& ) const;
|
||||||
void deserialize( std::istream& );
|
void deserialize( std::istream& );
|
||||||
|
|||||||
12
renderer.cpp
12
renderer.cpp
@@ -408,7 +408,7 @@ opengl_renderer::Render_pass( rendermode const Mode ) {
|
|||||||
::glEnable( GL_SCISSOR_TEST );
|
::glEnable( GL_SCISSOR_TEST );
|
||||||
setup_matrices();
|
setup_matrices();
|
||||||
::glEnable( GL_POLYGON_OFFSET_FILL ); // alleviate depth-fighting
|
::glEnable( GL_POLYGON_OFFSET_FILL ); // alleviate depth-fighting
|
||||||
::glPolygonOffset( 4.f, 8.f );
|
::glPolygonOffset( 2.f, 2.f );
|
||||||
// render
|
// render
|
||||||
// opaque parts...
|
// opaque parts...
|
||||||
setup_drawing( false );
|
setup_drawing( false );
|
||||||
@@ -560,6 +560,11 @@ opengl_renderer::setup_pass( renderpass_config &Config, rendermode const Mode, f
|
|||||||
bounding_box( frustumchunkmin, frustumchunkmax, std::begin( frustumchunkshapepoints ), std::end( frustumchunkshapepoints ) );
|
bounding_box( frustumchunkmin, frustumchunkmax, std::begin( frustumchunkshapepoints ), std::end( frustumchunkshapepoints ) );
|
||||||
// ...use the dimensions to set up light projection boundaries
|
// ...use the dimensions to set up light projection boundaries
|
||||||
// NOTE: since we only have one cascade map stage, we extend the chunk forward/back to catch areas normally covered by other stages
|
// NOTE: since we only have one cascade map stage, we extend the chunk forward/back to catch areas normally covered by other stages
|
||||||
|
auto const quantizationstep = ( Global::shadowtune.depth + 1000.f ) / m_shadowbuffersize;
|
||||||
|
frustumchunkmin.x -= std::remainder( frustumchunkmin.x, quantizationstep );
|
||||||
|
frustumchunkmin.y -= std::remainder( frustumchunkmin.y, quantizationstep );
|
||||||
|
frustumchunkmax.x -= std::remainder( frustumchunkmax.x, quantizationstep );
|
||||||
|
frustumchunkmax.y -= std::remainder( frustumchunkmax.y, quantizationstep );
|
||||||
camera.projection() *=
|
camera.projection() *=
|
||||||
glm::ortho(
|
glm::ortho(
|
||||||
frustumchunkmin.x, frustumchunkmax.x,
|
frustumchunkmin.x, frustumchunkmax.x,
|
||||||
@@ -2708,10 +2713,7 @@ opengl_renderer::Update( double const Deltatime ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( true == DebugModeFlag ) {
|
if( true == DebugModeFlag ) {
|
||||||
m_debuginfo = m_textures.info();
|
m_debuginfo += m_textures.info();
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_debuginfo.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ( true == Global::ControlPicking )
|
if( ( true == Global::ControlPicking )
|
||||||
|
|||||||
Reference in New Issue
Block a user