@@ -505,7 +505,7 @@ bool application_class::initialize(int screenWidth, int screenHeight, HWND hwnd,
//ConstructSkyboxWithPlanes();
Skybox * skybox = new Skybox ;
skybox - > Initialize ( direct_3d_ ) ;
skybox_ . push_back ( skybox - > ConstructSkybox ( ) ) ;
skybox_ . push_back ( skybox - > ConstructSkybox ( this ) ) ;
culling_active_ = true ;
culling_thread_ = std : : thread ( & application_class : : culling_thread_function , this ) ;
@@ -765,8 +765,6 @@ void application_class::shutdown()
bool application_class : : frame ( input_class * Input )
{
process_terrain_generation ( ) ;
stats_ - > reset_draw_call_count ( ) ;
int mouseX , mouseY , currentMouseX , currentMouseY ;
@@ -1133,10 +1131,10 @@ bool application_class::render(float rotation, float x, float y, float z, float
// -------------------------------------------------------- //
// set the active camera to the sun camera for rendering the shadow map.
active_camera_ = sun_camera_;
active_camera_- > render ( ) ;
// Render the objects in the render queues. with depth only pass.
active_camera_- > get_view_matrix( viewMatrix) ;
// active_camera_ = sun_camera_;
// active_camera_->render();
// // Render the objects in the render queues. with depth only pass.
// active_camera_-> get_view_matrix( viewMatrix);
result = render_pass ( render_queues_ , diffuseColor , lightPosition , ambientColor , viewMatrix , projectionMatrix ) ;
if ( ! result )
{
@@ -1145,18 +1143,19 @@ bool application_class::render(float rotation, float x, float y, float z, float
}
// Reset the active camera to the main camera.
active_camera_ = camera_;
active_camera_- > render ( ) ;
active_camera_- > get_view_matrix( viewMatrix) ;
// render the objects in the render queues. with standard pass.
result = render_pass( render_queues_, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix) ;
if ( ! result)
{
Logger : : Get ( ) . Log ( " Could not render the model using any shader" , __FILE__, __LINE__, Logger : : LogLevel : : Error ) ;
return false;
}
// active_camera_ = camera_;
// active_camera_->render();
// active_camera_-> get_view_matrix( viewMatrix);
//
// // render the objects in the render queues. with standard pass.
// result = render_pass( render_queues_, diffuseColor, lightPosition, ambientColor, viewMatrix, projectionMatrix);
// if (! result)
// {
// Logger::Get().Log(" Could not render the model using any shader", __FILE__, __LINE__, Logger::LogLevel::Error);
// return false;
// }
stats_ - > update_geometric_stats ( ) ;
// Update the render count text.
result = update_render_count_string ( get_render_count ( ) ) ;
@@ -1329,7 +1328,7 @@ void application_class::generate_terrain()
for ( int j = 0 ; j < gridSizeZ ; j + + )
{
// Cr<43> er un nouvel objet de terrain
object * terrain = new object ( ) ;
object * terrain = new object ( * this ) ;
// Initialiser avec le mod<6F> le et les textures_ pr<70> charg<72> es
if ( ! terrain - > Initialize ( direct_3d_ - > get_device ( ) , direct_3d_ - > get_device_context ( ) , modelFilename , textureContainer ) )
@@ -1362,6 +1361,7 @@ void application_class::generate_terrain()
void application_class : : add_kobject ( std : : wstring & filepath )
{
std : : lock_guard < std : : mutex > lock ( objects_mutex_ ) ;
Logger : : Get ( ) . Log ( " Adding object " , __FILE__ , __LINE__ ) ;
char modelFilename [ 128 ] ;
@@ -1382,7 +1382,7 @@ void application_class::add_kobject(std::wstring& filepath)
L " assets/Texture/BricksGLOSS2K.png "
} ;
object * newObject = new object ( ) ;
object * newObject = new object ( * this ) ;
newObject - > LoadTexturesFromPath ( kobjTexture , KobjectsTextures , direct_3d_ ) ; // Load textures_ from the path
newObject - > Initialize ( direct_3d_ - > get_device ( ) , direct_3d_ - > get_device_context ( ) , modelFilename , KobjectsTextures ) ;
newObject - > SetMass ( 1.0f ) ;
@@ -1404,6 +1404,7 @@ void application_class::add_kobject(std::wstring& filepath)
void application_class : : add_cube ( )
{
std : : lock_guard < std : : mutex > lock ( objects_mutex_ ) ;
Logger : : Get ( ) . Log ( " Adding cube " , __FILE__ , __LINE__ ) ;
char modelFilename [ 128 ] ;
@@ -1418,7 +1419,7 @@ void application_class::add_cube()
static int cubeCount = 0 ;
float position = cubeCount * 2.0f ;
object * newCube = new object ( ) ;
object * newCube = new object ( * this ) ;
newCube - > LoadTexturesFromPath ( cubeTexture , CubeTexture , direct_3d_ ) ; // Load textures_ from the path
newCube - > Initialize ( direct_3d_ - > get_device ( ) , direct_3d_ - > get_device_context ( ) , modelFilename , CubeTexture ) ;
newCube - > SetTranslateMatrix ( XMMatrixTranslation ( position , 0.0f , 0.0f ) ) ;
@@ -1429,6 +1430,7 @@ void application_class::add_cube()
void application_class : : delete_kobject ( int index )
{
std : : lock_guard < std : : mutex > lock ( objects_mutex_ ) ;
Logger : : Get ( ) . Log ( " Deleting object " , __FILE__ , __LINE__ ) ;
if ( index < object_ . size ( ) )
@@ -1439,6 +1441,7 @@ void application_class::delete_kobject(int index)
void application_class : : delete_terrain ( )
{
std : : lock_guard < std : : mutex > lock ( objects_mutex_ ) ;
Logger : : Get ( ) . Log ( " Deleting terrain " , __FILE__ , __LINE__ ) ;
terrain_chunk_ . clear ( ) ;
}
@@ -2151,126 +2154,56 @@ void application_class::physics_thread_function()
}
}
void application_class : : create_big_cube ( int side_count )
bool application_class : : create_big_cube ( int side_count )
{
Logger : : Get ( ) . Log ( " Lancement de la g<> n<EFBFBD> ration du terrain dans un thread s<> par<61> " , __FILE__ , __LINE__ , Logger : : LogLevel : : Info ) ;
// Cr<43> er un thread qui ex<65> cutera la g<> n<EFBFBD> ration du terrain
std : : thread generationThread ( [ this , side_count ] ( ) {
Logger : : Get ( ) . Log ( " Thread de g<> n<EFBFBD> ration de terrain d<> marr<72> " , __FILE__ , __LINE__ , Logger : : LogLevel : : Info ) ;
std : : string modelName = " assets/Model/TXT/cube.txt " ;
std : : shared_ptr < model_class > sharedModel ;
// V<> rifier si le mod<6F> le existe d<> j<EFBFBD>
auto it = g_model_cache . find ( modelName ) ;
if ( it ! = g_model_cache . end ( ) ) {
sharedModel = it - > second ;
} else {
// copy le string en char*
char model_file [ 128 ] ;
size_t convertedChars = 0 ;
( void ) wcstombs_s ( & convertedChars , model_file , sizeof ( model_file ) , std : : wstring ( modelName . begin ( ) , modelName . end ( ) ) . c_str ( ) , _TRUNCATE ) ;
// Stockage temporaire pour les nouveaux objets
std : : vector < object * > newTerrainChunks ;
// Cr<EFBFBD> er et initialiser le mod<6F> le si non trouv<75>
auto newModel = std : : make_shared < model_class > ( ) ;
TextureContainer textures ;
textures . diffusePaths . push_back ( L " assets/Texture/Bricks2K.png " ) ;
textures . normalPaths . push_back ( L " assets/Texture/BricksNRM2K.png " ) ;
textures . specularPaths . push_back ( L " assets/Texture/BricksGLOSS2K.png " ) ;
newModel - > PreloadTextures ( direct_3d_ - > get_device ( ) , direct_3d_ - > get_device_context ( ) , textures ) ;
if ( ! newModel - > Initialize ( direct_3d_ - > get_device ( ) , direct_3d_ - > get_device_context ( ) , model_file , textures ) ) {
Logger : : Get ( ) . Log ( " Impossible d'initialiser le mod<6F> le du gros cube " , __FILE__ , __LINE__ , Logger : : LogLevel : : Error ) ;
return false ;
}
g_model_cache [ modelName ] = newModel ;
sharedModel = newModel ;
}
// Dimensions du terrain
float scaleX = 1.0f ;
float scaleY = 1.0f ;
float scaleZ = 1.0f ;
// Cr<EFBFBD> er temporairement les cubes dans un vecteur local
std : : vector < object * > tempCubes ;
tempCubes . reserve ( side_count * side_count * side_count ) ;
// Pr<EFBFBD> parer les donn<6E> es pour la cr<63> ation des cubes
std : : vector < std : : tuple < float , float , float , std : : string , int > > cubeData ;
int objectId = object_id_ ;
// G<> n<EFBFBD> rer les donn<6E> es des cubes
for ( int i = 0 ; i < side_count ; i + + ) {
for ( int j = 0 ; j < side_count ; j + + ) {
for ( int k = 0 ; k < side_count ; k + + ) {
// V<> rifier si nous devons arr<72> ter le thread
if ( should_quit_ ) {
Logger : : Get ( ) . Log ( " G<EFBFBD> n<EFBFBD> ration de terrain annul<75> e " , __FILE__ , __LINE__ , Logger : : LogLevel : : Info ) ;
return ;
}
// Position et nom du cube
float posX = i * scaleX ;
float posY = k * scaleY ;
float posZ = j * scaleZ ;
std : : string name = " TerrainTile_ " + std : : to_string ( i ) + " _ " + std : : to_string ( j ) + " _ " + std : : to_string ( k ) ;
// Stocker les donn<6E> es du cube
cubeData . push_back ( std : : make_tuple ( posX , posY , posZ , name , objectId + + ) ) ;
}
// G<EFBFBD> n<EFBFBD> rer side_count<6E> cubes
for ( int x = 0 ; x < side_count ; x + + )
{
for ( int y = 0 ; y < side_count ; y + + )
{
for ( int z = 0 ; z < side_count ; z + + )
{
object * cubePart = new object ( * this ) ;
cubePart - > SetModel ( sharedModel ) ;
cubePart - > SetTranslateMatrix ( XMMatrixTranslation ( static_cast < float > ( x ) , static_cast < float > ( y ) , static_cast < float > ( z ) ) ) ;
tempCubes . push_back ( cubePart ) ;
}
}
// Synchroniser avec le thread principal pour cr<63> er les objets
// Cette partie doit <20> tre ex<65> cut<75> e dans le thread principal (via une file d'attente ou autre m<> canisme)
std : : lock_guard < std : : mutex > lock ( terrain_mutex_ ) ;
terrain_generation_data_ = std : : move ( cubeData ) ;
terrain_generation_ready_ = true ;
next_terrain_object_id_ = objectId ;
Logger : : Get ( ) . Log ( " Donn<EFBFBD> es de g<> n<EFBFBD> ration de terrain pr<70> par<61> es ( " + std : : to_string ( terrain_generation_data_ . size ( ) ) + " cubes) " , __FILE__ , __LINE__ , Logger : : LogLevel : : Info ) ;
} ) ;
// D<> tacher le thread pour qu'il s'ex<65> cute en arri<72> re-plan
generationThread . detach ( ) ;
}
void application_class : : process_terrain_generation ( )
{
// V<> rifier si des donn<6E> es de terrain sont pr<70> tes <20> <20> tre trait<69> es
if ( ! terrain_generation_ready_ ) {
return ;
}
// Acqu<71> rir les donn<6E> es g<> n<EFBFBD> r<EFBFBD> es
std : : vector < std : : tuple < float , float , float , std : : string , int > > cubeData ;
{
std : : lock_guard < std : : mutex > lock ( terrain_mutex_ ) ;
cubeData = std : : move ( terrain_generation_data_ ) ;
terrain_generation_data_ . clear ( ) ;
terrain_generation_ready_ = false ;
object_id_ = next_terrain_object_id_ ;
}
Logger : : Get ( ) . Log ( " Cr<EFBFBD> ation des objets terrain <20> partir des donn<6E> es pr<70> par<61> es " , __FILE__ , __LINE__ , Logger : : LogLevel : : Info ) ;
// Transf<73> rer les cubes du vecteur temporaire au vecteur membre
cubes_ = std : : move ( tempCubes ) ;
terrain_chunk_ . clear ( ) ;
// Cr<43> er un conteneur de textures_ partag<61>
TextureContainer textureContainer ;
textureContainer . diffusePaths . push_back ( L " assets/Texture/Bricks2K.png " ) ;
textureContainer . normalPaths . push_back ( L " assets/Texture/BricksNRM2K.png " ) ;
textureContainer . specularPaths . push_back ( L " assets/Texture/BricksGLOSS2K.png " ) ;
// Pr<50> charger les textures_ une seule fois
model_class * sharedModel = new model_class ( ) ;
sharedModel - > PreloadTextures ( direct_3d_ - > get_device ( ) , direct_3d_ - > get_device_context ( ) , textureContainer ) ;
char modelFilename [ 128 ] ;
strcpy_s ( modelFilename , " assets/Model/TXT/cube.txt " ) ;
// Cr<43> er les objets <20> partir des donn<6E> es
for ( const auto & [ posX , posY , posZ , name , id ] : cubeData )
{
// Cr<43> er un nouvel objet de terrain
object * terrain = new object ( ) ;
// Initialiser avec le mod<6F> le et les textures_
if ( ! terrain - > Initialize ( direct_3d_ - > get_device ( ) , direct_3d_ - > get_device_context ( ) , modelFilename , textureContainer ) )
{
Logger : : Get ( ) . Log ( " <EFBFBD> chec de l'initialisation d'une tuile de terrain" , __FILE__ , __LINE__ , Logger : : LogLevel : : Error ) ;
delete terrain ;
continue ;
}
// Configurer l'objet
XMFLOAT3 position ( posX , posY , posZ ) ;
XMFLOAT3 scale ( 1.0f , 1.0f , 1.0f ) ;
terrain - > SetPosition ( XMLoadFloat3 ( & position ) ) ;
terrain - > SetScale ( XMLoadFloat3 ( & scale ) ) ;
terrain - > SetName ( name ) ;
terrain - > SetType ( ObjectType : : Cube ) ;
terrain - > SetActiveShader ( ShaderType : : TEXTURE ) ;
terrain - > SetId ( id ) ;
// Ajouter <20> la liste des chunks de terrain
terrain_chunk_ . push_back ( terrain ) ;
}
delete sharedModel ;
Logger : : Get ( ) . Log ( " G<EFBFBD> n<EFBFBD> ration du terrain termin<69> e avec " + std : : to_string ( terrain_chunk_ . size ( ) ) + " cubes " , __FILE__ , __LINE__ , Logger : : LogLevel : : Info ) ;
return true ;
}