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 >> token;
|
||||
// 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());
|
||||
if (token != "*") // czy ma zostać bez zmian?
|
||||
iFlags |= update_memstring;
|
||||
|
||||
180
MdlMngr.cpp
180
MdlMngr.cpp
@@ -17,64 +17,45 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include "MdlMngr.h"
|
||||
|
||||
#include "Globals.h"
|
||||
#include "Logs.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)
|
||||
{ // wczytanie modelu do kontenerka
|
||||
SafeDelete(Model);
|
||||
Name = NewName;
|
||||
Model = new TModel3d();
|
||||
if (!Model->LoadFromFile(Name, dynamic)) // np. "models\\pkp/head1-y.t3d"
|
||||
SafeDelete(Model);
|
||||
return Model;
|
||||
};
|
||||
|
||||
TMdlContainer *TModelsManager::Models;
|
||||
int TModelsManager::Count;
|
||||
int const MAX_MODELS = 1000;
|
||||
|
||||
void TModelsManager::Init()
|
||||
{
|
||||
Models = new TMdlContainer[MAX_MODELS];
|
||||
Count = 0;
|
||||
}
|
||||
/*
|
||||
TModelsManager::TModelsManager()
|
||||
{
|
||||
// Models= NULL;
|
||||
Models= new TMdlContainer[MAX_MODELS];
|
||||
Count= 0;
|
||||
};
|
||||
|
||||
TModelsManager::~TModelsManager()
|
||||
{
|
||||
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
|
||||
Model = std::make_shared<TModel3d>();
|
||||
if( true == Model->LoadFromFile( Name, Dynamic ) ) {
|
||||
m_name = Name;
|
||||
return Model.get();
|
||||
}
|
||||
else {
|
||||
m_name.clear();
|
||||
Model = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
TModelsManager::modelcontainer_sequence TModelsManager::m_models;
|
||||
TModelsManager::stringmodelcontainerindex_map TModelsManager::m_modelsmap;
|
||||
|
||||
// wczytanie modelu do tablicy
|
||||
TModel3d *
|
||||
TModelsManager::LoadModel(std::string const &Name, bool dynamic) {
|
||||
|
||||
m_models.emplace_back();
|
||||
auto model = m_models.back().LoadModel( Name, dynamic );
|
||||
if( model != nullptr ) {
|
||||
m_modelsmap.emplace( Name, m_models.size() - 1 );
|
||||
return model;
|
||||
}
|
||||
else {
|
||||
m_models.pop_back();
|
||||
return nullptr;
|
||||
}
|
||||
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
|
||||
// (kabina, wnętrze, ładunek)
|
||||
// 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
|
||||
// - wczytanie modelu animowanego - Init() - sprawdzić
|
||||
std::string buf;
|
||||
std::string 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
|
||||
}
|
||||
};
|
||||
*/
|
||||
std::string const buftp = Global::asCurrentTexturePath; // zapamiętanie aktualnej ścieżki do tekstur,
|
||||
if( Name.find('\\') == std::string::npos )
|
||||
{
|
||||
buf = "models\\"; // Ra: było by lepiej katalog dodać w parserze
|
||||
buf.append( Name );
|
||||
buf = "models\\" + Name; // Ra: było by lepiej katalog dodać w parserze
|
||||
if( Name.find( '/') != std::string::npos)
|
||||
{
|
||||
Global::asCurrentTexturePath = Global::asCurrentTexturePath + Name;
|
||||
@@ -154,43 +92,27 @@ TModel3d * TModelsManager::GetModel(std::string const &Name, bool dynamic)
|
||||
else
|
||||
{
|
||||
buf = Name;
|
||||
if (dynamic) // na razie tak, bo nie wiadomo, jaki może mieć wpływ na pozostałe modele
|
||||
if (Name.find( '/') != std::string::npos)
|
||||
{ // pobieranie tekstur z katalogu, w którym jest model
|
||||
if( Dynamic ) {
|
||||
// na razie tak, bo nie wiadomo, jaki może mieć wpływ na pozostałe modele
|
||||
if( Name.find( '/' ) != std::string::npos ) { // pobieranie tekstur z katalogu, w którym jest model
|
||||
Global::asCurrentTexturePath = Global::asCurrentTexturePath + Name;
|
||||
Global::asCurrentTexturePath.erase(Global::asCurrentTexturePath.find("/") + 1,
|
||||
Global::asCurrentTexturePath.length() - 1);
|
||||
Global::asCurrentTexturePath.erase(
|
||||
Global::asCurrentTexturePath.find( "/" ) + 1,
|
||||
Global::asCurrentTexturePath.length() - 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
buf = ToLower( buf );
|
||||
for (int i = 0; i < Count; ++i)
|
||||
{
|
||||
if ( buf == Models[i].Name )
|
||||
{
|
||||
Global::asCurrentTexturePath = buftp;
|
||||
return (Models[i].Model);
|
||||
}
|
||||
};
|
||||
TModel3d *tmpModel = LoadModel(buf, dynamic); // model nie znaleziony, to wczytać
|
||||
|
||||
auto const lookup = m_modelsmap.find( buf );
|
||||
if( lookup != m_modelsmap.end() ) {
|
||||
Global::asCurrentTexturePath = buftp;
|
||||
return ( m_models[ lookup->second ].Model.get() );
|
||||
}
|
||||
|
||||
auto model = LoadModel(buf, Dynamic); // model nie znaleziony, to wczytać
|
||||
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
|
||||
|
||||
#include "Model3d.h"
|
||||
#include "usefull.h"
|
||||
|
||||
class TMdlContainer
|
||||
{
|
||||
class TMdlContainer {
|
||||
friend class TModelsManager;
|
||||
~TMdlContainer()
|
||||
{
|
||||
delete Model;
|
||||
};
|
||||
TModel3d * LoadModel(std::string const &NewName, bool dynamic);
|
||||
TModel3d *Model{ nullptr };
|
||||
std::string Name;
|
||||
private:
|
||||
TModel3d *LoadModel( std::string const &Name, bool const Dynamic );
|
||||
std::shared_ptr<TModel3d> Model { nullptr };
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
class TModelsManager
|
||||
{ // klasa statyczna, nie ma obiektu
|
||||
private:
|
||||
static TMdlContainer *Models;
|
||||
static int Count;
|
||||
static TModel3d * LoadModel(std::string const &Name, bool dynamic);
|
||||
|
||||
public:
|
||||
// TModelsManager();
|
||||
// ~TModelsManager();
|
||||
static void Init();
|
||||
static void Free();
|
||||
// klasa statyczna, nie ma obiektu
|
||||
class TModelsManager {
|
||||
// types:
|
||||
typedef std::deque<TMdlContainer> modelcontainer_sequence;
|
||||
typedef std::unordered_map<std::string, modelcontainer_sequence::size_type> stringmodelcontainerindex_map;
|
||||
// members:
|
||||
static modelcontainer_sequence m_models;
|
||||
static stringmodelcontainerindex_map m_modelsmap;
|
||||
// methods:
|
||||
static TModel3d *LoadModel( std::string const &Name, bool const Dynamic );
|
||||
public:
|
||||
// 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
|
||||
"Textures: "
|
||||
"; textures: "
|
||||
#ifdef EU07_DEFERRED_TEXTURE_UPLOAD
|
||||
+ std::to_string( readytexturecount )
|
||||
+ " ("
|
||||
|
||||
@@ -203,7 +203,6 @@ TWorld::~TWorld()
|
||||
TrainDelete();
|
||||
// Ground.Free(); //Ra: usunięcie obiektów przed usunięciem dźwięków - sypie się
|
||||
TSoundsManager::Free();
|
||||
TModelsManager::Free();
|
||||
}
|
||||
|
||||
void TWorld::TrainDelete(TDynamicObject *d)
|
||||
@@ -291,8 +290,6 @@ bool TWorld::Init( GLFWwindow *Window ) {
|
||||
|
||||
TSoundsManager::Init( glfwGetWin32Window( window ) );
|
||||
WriteLog("Sound Init OK");
|
||||
TModelsManager::Init();
|
||||
WriteLog("Models init OK");
|
||||
|
||||
glfwSetWindowTitle( window, ( Global::AppName + " (" + Global::SceneryFile + ")" ).c_str() ); // nazwa scenerii
|
||||
UILayer.set_progress(0.01);
|
||||
|
||||
@@ -25,8 +25,8 @@ struct basic_vertex {
|
||||
glm::vec2 texture; // uv space
|
||||
|
||||
basic_vertex() = default;
|
||||
basic_vertex( glm::vec3 const&Position, glm::vec3 const &Normal, glm::vec2 const &Texture ) :
|
||||
position( Position ), normal( Normal ), texture( Texture )
|
||||
basic_vertex( glm::vec3 const &Position, glm::vec3 const &Normal, glm::vec2 const &Texture ) :
|
||||
position( Position ), normal( Normal ), texture( Texture )
|
||||
{}
|
||||
void serialize( std::ostream& ) const;
|
||||
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 );
|
||||
setup_matrices();
|
||||
::glEnable( GL_POLYGON_OFFSET_FILL ); // alleviate depth-fighting
|
||||
::glPolygonOffset( 4.f, 8.f );
|
||||
::glPolygonOffset( 2.f, 2.f );
|
||||
// render
|
||||
// opaque parts...
|
||||
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 ) );
|
||||
// ...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
|
||||
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() *=
|
||||
glm::ortho(
|
||||
frustumchunkmin.x, frustumchunkmax.x,
|
||||
@@ -2708,10 +2713,7 @@ opengl_renderer::Update( double const Deltatime ) {
|
||||
}
|
||||
|
||||
if( true == DebugModeFlag ) {
|
||||
m_debuginfo = m_textures.info();
|
||||
}
|
||||
else {
|
||||
m_debuginfo.clear();
|
||||
m_debuginfo += m_textures.info();
|
||||
}
|
||||
|
||||
if( ( true == Global::ControlPicking )
|
||||
|
||||
Reference in New Issue
Block a user