# Khaotic Engine Reborn: application_class Class Reference

Loading...
Searching...
No Matches
application_class Class Reference

## Public Member Functions

| application_class ()
| Constructor for the application class. Initializes member variables and sets up the application.
virtual d_3d_class * | get_direct_3d ()
void | set_direct_3d (d_3d_class *direct_3d)
render_texture_class * | get_scene_texture () const
render_texture_class * | get_render_texture () const
render_texture_class * | get_refraction_texture () const
render_texture_class * | get_reflection_texture () const
bool | create_big_cube (int side_count)
| Create a big cube with a specified number of little cube per sides.
virtual bool | initialize (int screen_width, int screen_height, HWND hwdn, bool is_vulkan)
void | shutdown ()
virtual bool | frame (input_class *)
| Run the main loop of the application. This function will handle the main loop, including rendering and updating the application.
void | physics_thread_function ()
| Thread function for handling physics updates. this function will run in a separate thread to handle physics updates at a fixed rate (50 fps by default).
int | get_physics_tick_rate () const
void | set_physics_tick_rate (int physics_tick_rate)
int | get_screen_width () const
void | set_screen_width (int screen_width)
int | get_screen_height () const
void | set_screen_height (int screen_height)
float | get_speed () const
void | set_speed (const float speed)
void | add_cube ()
void | delete_entity_by_id (int entity_id)
void | add_kobject (std::wstring &filepath)
void | set_path (WCHAR *path)
void | set_w_folder (const std::filesystem::path &w_folder)
std::filesystem::path | get_w_folder () const
int | get_terrain_entity_count ()
int | get_object_id () const
void | set_object_id (int object_id)
void | generate_terrain ()
void | delete_terrain ()
XMVECTOR | get_light_position (int index)
XMVECTOR | get_light_color (int index)
void | set_light_position (int index, XMVECTOR position)
void | set_light_color (int index, XMVECTOR color)
std::vector< light_class * > | get_lights () const
light_class * | get_sun_light () const
bool | get_should_quit () const
void | set_should_quit (const bool should_quit)
void | set_cel_shading (const bool enable)
void | set_vsync (bool vsync)
bool | get_vsync () const
HWND | get_hwnd () const
void | set_hwnd (HWND hwnd)
bool | is_windowed () const
void | set_windowed (bool windowed)
void | set_window_size (const ImVec2 size)
ImVec2 | get_window_size () const
float | get_aspect_ratio () const
physics * | get_physics () const
frustum | get_frustum () const
void | set_frustum (const frustum &frustum)
void | construct_frustum ()
int | get_render_count () const
void | set_render_count (const int render_count)
float | get_frustum_tolerance () const
void | set_frustum_tolerance (const float frustum_tolerance)
bool | get_can_fixed_update () const
void | set_can_fixed_update (bool can_fixed_update)
ID3D11ShaderResourceView * | get_back_buffer_srv () const
stats * | get_stats () const
fps_class * | get_fps () const
ecs::EntityManager * | get_entity_manager () const
void | update_stats_after_modification ()
std::map< std::string, std::shared_ptr< model_class > > & | get_model_cache ()

## Public Attributes

std::vector< ID3D11ShaderResourceView * > | textures

## Detailed Description

Definition at line 78 of file application_class.h.

## Constructor & Destructor Documentation

## application_class()

application_class::application_class | ( |  | ) |

Constructor for the application class. Initializes member variables and sets up the application.

Definition at line 6 of file application_class.cpp.

: should_quit_(false)
{
direct_3d_ = nullptr;
camera_ = nullptr;
model_ = nullptr;
bitmap_ = nullptr;
sprite_ = nullptr;
timer_ = nullptr;
mouse_strings_ = nullptr;
font_shader_ = nullptr;
font_ = nullptr;
fps_ = nullptr;
fps_string_ = nullptr;
shader_manager_ = nullptr;
render_count_string_ = nullptr;
model_list_ = nullptr;
position_ = nullptr;
display_plane_ = nullptr;
bath_model_ = nullptr;
water_model_ = nullptr;
m_light_ = nullptr;
refraction_texture_ = nullptr;
reflection_texture_ = nullptr;
scene_texture_ = nullptr;
physics_ = nullptr;
skybox_.clear();
lights_.clear();
sun_light_ = nullptr;
swap_chain_ = nullptr;
ground_model_ = nullptr;
wall_model_ = nullptr;
hwnd_ = nullptr;
base_view_matrix_ = XMMatrixIdentity();
render_texture_ = nullptr;
screen_width_ = 0;
screen_height_ = 0;
num_lights_ = 0;
water_height_ = 0.0f;
water_translation_ = 0.0f;
true_light_position_ = XMFLOAT3(0.0f, 0.0f, 0.0f);
light_model_ = nullptr;
render_count_ = 0;
tab_was_pressed_ = false;
}

## ~application_class()

application_class::~application_class | ( |  | ) |

Definition at line 51 of file application_class.cpp.

{
should_quit_ = true;
culling_active_ = false;
// Joindre les threads pour s'assurer qu'ils se terminent correctement
if (physics_thread_.joinable())
{
physics_thread_.join();
}
if (culling_thread_.joinable())
{
culling_thread_.join();
}
}

## Member Function Documentation

## add_cube()

void application_class::add_cube | ( |  | ) |

Add a basic cube to the scene.

Definition at line 1464 of file application_class.cpp.

{
std::lock_guard<std::mutex> lock(objects_mutex_);
Logger::Get().Log("Adding cube", __FILE__, __LINE__);
std::string model_name = "assets/Model/TXT/cube.txt";
std::shared_ptr<model_class> sharedModel;
auto it = g_model_cache.find(model_name);
if (it != g_model_cache.end())
{
Logger::Get().Log("Using cached model: " + model_name, __FILE__, __LINE__);
sharedModel = it->second;
}
else
{
TextureContainer cube_textures;
cube_textures.diffusePaths.push_back(L"assets/Texture/Bricks2K.png");
cube_textures.normalPaths.push_back(L"assets/Texture/BricksNRM2K.png");
cube_textures.specularPaths.push_back(L"assets/Texture/BricksGLOSS2K.png");
char model_filename[128];
strcpy_s(model_filename, model_name.c_str());
auto newModel = std::make_shared<model_class>();
newModel->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), cube_textures);
if (!newModel->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), model_filename, cube_textures)) {
Logger::Get().Log("Failed to initialize cube model", __FILE__, __LINE__, Logger::LogLevel::Error);
return;
}
g_model_cache[model_name] = newModel;
sharedModel = newModel;
Logger::Get().Log("Added cube model to cache: " + model_name, __FILE__, __LINE__);
if (entity_manager_)
{
auto entity = entity_manager_->CreateEntity();
auto identity = entity->AddComponent<ecs::IdentityComponent>(object_id_++);
identity->SetName("Cube");
identity->SetType(ecs::ObjectType::Cube);
auto transform = entity->AddComponent<ecs::TransformComponent>();
transform->SetPosition(XMVectorSet(0.0f, 10.0f, 0.0f, 0.0f));
transform->SetScale(XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f));
transform->UpdateWorldMatrix();
auto render = entity->AddComponent<ecs::RenderComponent>();
render->InitializeWithModel(sharedModel);
auto shader = entity->AddComponent<ecs::ShaderComponent>();
shader->SetActiveShader(ecs::ShaderType::TEXTURE);
}
}
update_stats_after_modification();
Logger::Get().Log("Cube added successfully", __FILE__, __LINE__, Logger::LogLevel::Info);
}
application_class::update_stats_after_modification
void update_stats_after_modification()
Definition application_class.cpp:2066
ecs::IdentityComponent
Definition identity_component.h:18
ecs::IdentityComponent::SetName
void SetName(const std::string &name)
Definition identity_component.h:56
ecs::RenderComponent
Definition render_component.h:29
ecs::ShaderComponent
Definition shader_component.h:24
ecs::ShaderComponent::SetActiveShader
void SetActiveShader(ShaderType shader)
Definition shader_component.h:47
ecs::TransformComponent
Definition transform_component.h:9
ecs::TransformComponent::SetPosition
void SetPosition(XMVECTOR position)
Definition transform_component.h:29
TextureContainer
Definition model_class.h:34

## add_kobject()

void application_class::add_kobject | ( | std::wstring & | filepath | ) |

Create a new entity with the specified model path.

Parameters

  filepath |

Definition at line 1378 of file application_class.cpp.

{
std::lock_guard<std::mutex> lock(objects_mutex_);
Logger::Get().Log("Adding object", __FILE__, __LINE__);
char modelFilename[128];
TextureContainer KobjectsTextures;
filesystem::path p(filepath);
string filename = p.stem().string();
size_t convertedChars = 0;
(void)wcstombs_s(&convertedChars, modelFilename, sizeof(modelFilename), filepath.c_str(), _TRUNCATE);
filesystem::current_path(w_folder_);
// Liste des fichiers de texture
std::vector<std::wstring> kobjTexture = {
L"assets/Texture/Bricks2K.png",
L"assets/Texture/BricksNRM2K.png",
L"assets/Texture/BricksGLOSS2K.png"
};
// Configurer les chemins des textures dans le conteneur
KobjectsTextures.diffusePaths.push_back(kobjTexture[0]);
if (kobjTexture.size() > 1) KobjectsTextures.normalPaths.push_back(kobjTexture[1]);
if (kobjTexture.size() > 2) KobjectsTextures.specularPaths.push_back(kobjTexture[2]);
// Vérifier si le modèle existe déjà dans le cache
std::string modelKey = std::string(modelFilename);
std::shared_ptr<model_class> sharedModel;
auto it = g_model_cache.find(modelKey);
if (it != g_model_cache.end()) {
// Utiliser le modèle existant du cache
Logger::Get().Log("Using cached model for " + modelKey, __FILE__, __LINE__);
sharedModel = it->second;
}
else {
// Créer un nouveau modèle
sharedModel = std::make_shared<model_class>();
// Précharger les textures
sharedModel->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), KobjectsTextures);
// Initialiser le modèle
if (!sharedModel->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, KobjectsTextures)) {
Logger::Get().Log("Failed to initialize model for object: " + modelKey, __FILE__, __LINE__, Logger::LogLevel::Error);
return;
}
// Ajouter le modèle au cache
g_model_cache[modelKey] = sharedModel;
Logger::Get().Log("Added model to cache: " + modelKey, __FILE__, __LINE__);
}
// Créer une nouvelle entité
auto entity = entity_manager_->CreateEntity();
// Ajouter un composant d'identité
auto identity = entity->AddComponent<ecs::IdentityComponent>(object_id_++);
identity->SetName(filename);
identity->SetType(ecs::ObjectType::Unknown);
// Ajouter un composant de transformation
auto transform = entity->AddComponent<ecs::TransformComponent>();
transform->SetPosition(XMVectorSet(0.0f, 50.0f, 0.0f, 0.0f));
transform->SetScale(XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f));
transform->UpdateWorldMatrix();
// Ajouter un composant de rendu avec le modèle partagé
auto render = entity->AddComponent<ecs::RenderComponent>();
render->InitializeWithModel(sharedModel);
// Ajouter un composant de shader
auto shader = entity->AddComponent<ecs::ShaderComponent>();
shader->SetActiveShader(ecs::ShaderType::LIGHTING);
// Stocker le chemin du modèle
auto modelPath = entity->AddComponent<ecs::ModelPathComponent>();
modelPath->SetPath(filepath);
Logger::Get().Log("ECS entity created with ID: " + std::to_string(identity->GetId()), __FILE__, __LINE__);
update_stats_after_modification();
}
ecs::ModelPathComponent
Definition model_path_component.h:7
ecs::ModelPathComponent::SetPath
void SetPath(const std::wstring &path)
Definition model_path_component.h:25

## construct_frustum()

void application_class::construct_frustum | ( |  | ) |

Construct the frustum for culling. This function will calculate the frustum based on the current camera view and projection matrices.

Definition at line 1940 of file application_class.cpp.

{
XMMATRIX projectionMatrix = direct_3d_->get_projection_matrix();
XMMATRIX viewMatrix;
active_camera_->get_view_matrix(viewMatrix);
frustum_culling_.ConstructFrustum(screen_depth, projectionMatrix, viewMatrix);
}

## create_big_cube()

bool application_class::create_big_cube | ( | int | side_count | ) |

Create a big cube with a specified number of little cube per sides.

Parameters

  side_count | The number of cubes per sides for the big cube.

Returns
  True if the cube was created successfully, false otherwise.

Definition at line 2003 of file application_class.cpp.

{
std::string modelName = "assets/Model/TXT/cube.txt";
std::shared_ptr<model_class> sharedModel;
// Vérifier si le modèle existe déjà
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);
// Créer et initialiser le modèle si non trouvé
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èle du gros cube", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
g_model_cache[modelName] = newModel;
sharedModel = newModel;
}
for (int x = 0; x < side_count; x++) {
for (int y = 0; y < side_count; y++) {
for (int z = 0; z < side_count; z++) {
// Créer une entité
auto entity = entity_manager_->CreateEntity();
// Ajouter un composant d'identité
auto identity = entity->AddComponent<ecs::IdentityComponent>(object_id_++);
identity->SetName("CubePart_" + std::to_string(x) + "_" + std::to_string(y) + "_" + std::to_string(z));
identity->SetType(ecs::ObjectType::Terrain);
// Ajouter un composant de transformation
auto transform = entity->AddComponent<ecs::TransformComponent>();
transform->SetPosition(XMVectorSet(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), 0.0f));
transform->SetScale(XMVectorSet(1.0f, 1.0f, 1.0f, 0.0f));
transform->UpdateWorldMatrix();
// Ajouter un composant de rendu
auto render = entity->AddComponent<ecs::RenderComponent>();
render->InitializeWithModel(sharedModel);
// Ajouter un composant de shader
auto shader = entity->AddComponent<ecs::ShaderComponent>();
shader->SetActiveShader(ecs::ShaderType::LIGHTING);
}
}
}
update_stats_after_modification();
return true;
}

## delete_entity_by_id()

void application_class::delete_entity_by_id | ( | int | entity_id | ) |

Delete an entity by its ID.

Parameters

  entity_id | The ID of the entity to delete.

Definition at line 1526 of file application_class.cpp.

{
std::lock_guard<std::mutex> lock(objects_mutex_);
Logger::Get().Log("Deleting entity with ID: " + std::to_string(entity_id), __FILE__, __LINE__, Logger::LogLevel::Info);
if (entity_manager_) {
// Rechercher l'entité avec l'ID spécifié via le composant IdentityComponent
auto entities_with_identity = entity_manager_->GetEntitiesWithComponent<ecs::IdentityComponent>();
for (auto& entity : entities_with_identity) {
auto identity = entity->GetComponent<ecs::IdentityComponent>();
if (identity && identity->GetId() == entity_id) {
// Supprimer l'entité
entity_manager_->DestroyEntity(entity->GetID());
Logger::Get().Log("Entity with ID " + std::to_string(entity_id) + " successfully deleted", __FILE__, __LINE__, Logger::LogLevel::Info);
break;
}
}
}
update_stats_after_modification();
}

## delete_terrain()

void application_class::delete_terrain | ( |  | ) |

Delete the flat terrain/Big Cubes from the scene.

Definition at line 1548 of file application_class.cpp.

{
std::lock_guard<std::mutex> lock(objects_mutex_);
Logger::Get().Log("Deleting terrain", __FILE__, __LINE__, Logger::LogLevel::Info);
// Get all entities with the Terrain type
auto entities_with_terrain = entity_manager_->GetEntitiesWithComponent<ecs::IdentityComponent>();
for (auto& entity : entities_with_terrain) {
auto identity = entity->GetComponent<ecs::IdentityComponent>();
if (identity && identity->GetType() == ecs::ObjectType::Terrain) {
// Destroy the entity
entity_manager_->DestroyEntity(entity->GetID());
Logger::Get().Log("Terrain entity with ID " + std::to_string(identity->GetId()) + " successfully deleted", __FILE__, __LINE__, Logger::LogLevel::Info);
}
}
update_stats_after_modification();
}

## frame()

bool application_class::frame | ( | input_class * | Input | ) |

virtual

Run the main loop of the application. This function will handle the main loop, including rendering and updating the application.

Returns
  True if the application should continue running, false if it should quit.

Definition at line 760 of file application_class.cpp.

{
stats_->reset_draw_call_count();
int mouseX, mouseY, currentMouseX, currentMouseY;
bool result, leftMouseDown, rightMouseDown, buttonQ, buttonD, buttonZ, buttonS, buttonA, buttonE, scrollUp, scrollDown;
float rotationY, rotationX, positionX, positionY, positionZ;
static float textureTranslation = 0.0f;
float frameTime;
static int lastMouseX = 0, lastMouseY = 0;
static float rotation = 360.0f;
static float x = 0.0f;
static float y = 3.0f;
static float z = 0.0f;
// Update the system stats.
timer_->Frame();
// Get the current frame time.
frameTime = timer_->GetTime();
// Check if the user pressed escape and wants to exit the application.
if (Input->IsEscapePressed())
{
Logger::Get().Log("User pressed escape, exiting application", __FILE__, __LINE__, Logger::LogLevel::Input);
should_quit_ = true;
}
// Get the location of the mouse from the input object,
Input->GetMouseLocation(mouseX, mouseY);
// Check if the mouse has been pressed.
leftMouseDown = Input->IsLeftMousePressed();
rightMouseDown = Input->IsRightMousePressed();
currentMouseX = mouseX;
int deltaX = currentMouseX - lastMouseX; // Calculate the mouse movement.
lastMouseX = currentMouseX; // Update the last mouse position for the next frame
currentMouseY = mouseY;
int deltaY = currentMouseY - lastMouseY; // Calculate the mouse movement.
lastMouseY = currentMouseY; // Update the last mouse position for the next frame
// Set the frame time for calculating the updated position.
position_->SetFrameTime(timer_->GetTime());
position_->TurnMouse((float)deltaX, (float)deltaY, 0.1f, rightMouseDown);
// Get the current view point rotation.
position_->GetRotation(rotationY, rotationX);
scrollUp = Input->IsScrollUp();
scrollDown = Input->IsScrollDown();
// Check if the a(q), d, w(z), s, q(a), e have been pressed, if so move the camera accordingly.
buttonQ = Input->IsAPressed();
buttonD = Input->IsDPressed();
buttonZ = Input->IsWPressed();
buttonS = Input->IsSPressed();
buttonA = Input->IsQPressed();
buttonE = Input->IsEPressed();
position_->MoveCamera(buttonZ, buttonS, buttonQ, buttonD, buttonE, buttonA, scrollUp, scrollDown, rightMouseDown);
position_->GetPosition(positionX, positionY, positionZ);
XMFLOAT3 dir = sun_light_->GetDirection();
float pitch = asinf(-dir.y) * (180.0f / XM_PI); // en degrés
float yaw = atan2f(dir.x, dir.z) * (180.0f / XM_PI); // en degrés
float roll = 0.0f;
if (Input->is_key_pressed(DIK_TAB)) {
if (!tab_was_pressed_) {
// Alterner la caméra active
if (active_camera_ == camera_)
active_camera_ = sun_camera_;
else
active_camera_ = camera_;
tab_was_pressed_ = true;
}
} else {
tab_was_pressed_ = false;
}
if (active_camera_ == camera_) {
// Update the camera position and rotation based on the position class.
camera_->set_position(positionX, positionY, positionZ);
camera_->set_rotation(rotationX, rotationY, 0.0f);
} else {
// Update the sun camera position and rotation based on the light position.
sun_camera_->set_position(sun_light_->GetPosition().x, sun_light_->GetPosition().y, sun_light_->GetPosition().z);
sun_camera_->set_rotation(pitch, yaw, roll);
// sun_camera_->set_position(positionX, positionY, positionZ);
// sun_camera_->set_rotation(rotationX, rotationY, 0.0f);
}
active_camera_->render();
// render the static graphics scene.
result = render(rotation, x, y, z, textureTranslation);
if (!result)
{
Logger::Get().Log("Could not render the graphics scene", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Update the frames per second each frame.
result = update_fps();
if (!result)
{
Logger::Get().Log("Could not update the frames per second", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Update the rotation variable each frame.
rotation -= 0.0174532925f * speed_;
if (rotation < 0.0f)
{
rotation += 360.0f;
}
// Update the position of the water to simulate motion.
water_translation_ += 0.001f;
if (water_translation_ > 1.0f)
{
water_translation_ -= 1.0f;
}
// render the refraction of the scene to a texture.
result = render_refraction_to_texture();
if (!result)
{
return false;
}
// render the reflection of the scene to a texture.
result = render_reflection_to_texture();
if (!result)
{
return false;
}
inputs_.key_left = Input->IsLeftArrowPressed();
inputs_.key_right = Input->IsRightArrowPressed();
inputs_.key_up = Input->IsUpArrowPressed();
inputs_.key_down = Input->IsDownArrowPressed();
// render the scene to a render texture.
result = render_scene_to_texture(rotation);
if (!result)
{
Logger::Get().Log("Could not render the scene to the render texture", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Update the mouse strings each frame.
result = update_mouse_strings(mouseX, mouseY, leftMouseDown);
if (!result)
{
Logger::Get().Log("Could not update the mouse strings", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Update the sprite object using the frame time.
sprite_->Update(frameTime);
// Increment the texture translation.
textureTranslation += 0.01f;
if (textureTranslation > 1.0f)
{
textureTranslation -= 1.0f;
}
return true;
}

## generate_terrain()

void application_class::generate_terrain | ( |  | ) |

Generate a flat terrain for test purposes using plane entities.

Definition at line 1293 of file application_class.cpp.

{
Logger::Get().Log("Génération du terrain avec ECS", __FILE__, __LINE__, Logger::LogLevel::Info);
// delete previous terrain if it exists
delete_terrain();
// Dimensions du terrain
float scaleX = 10.0f;
float scaleY = 1.0f;
float scaleZ = 10.0f;
int gridSizeX = 20;
int gridSizeZ = 20;
// Vérifier si le modèle existe déjà dans le cache
std::string modelName = "assets/Model/OBJ/plane.obj";
std::shared_ptr<model_class> sharedModel;
auto it = g_model_cache.find(modelName);
if (it != g_model_cache.end()) {
// Utiliser le modèle existant du cache
Logger::Get().Log("Using cached model for terrain: " + modelName, __FILE__, __LINE__);
sharedModel = it->second;
}
else {
// Créer un conteneur de textures partagé
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");
// Créer et initialiser le modèle si non trouvé
char modelFilename[128];
strcpy_s(modelFilename, modelName.c_str());
auto newModel = std::make_shared<model_class>();
newModel->PreloadTextures(direct_3d_->get_device(), direct_3d_->get_device_context(), textureContainer);
if (!newModel->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, textureContainer)) {
Logger::Get().Log("Impossible d'initialiser le modèle du terrain", __FILE__, __LINE__, Logger::LogLevel::Error);
return;
}
// Ajouter le modèle au cache
g_model_cache[modelName] = newModel;
sharedModel = newModel;
Logger::Get().Log("Added terrain model to cache: " + modelName, __FILE__, __LINE__);
}
// Vérifier si l'entity manager est disponible
if (entity_manager_) {
// Générer les tuiles de terrain avec le système ECS
for (int i = 0; i < gridSizeX; i++) {
for (int j = 0; j < gridSizeZ; j++) {
// Créer une entité
auto entity = entity_manager_->CreateEntity();
// Ajouter un composant d'identité
auto identity = entity->AddComponent<ecs::IdentityComponent>(object_id_++);
identity->SetName("TerrainTile_" + std::to_string(i) + "_" + std::to_string(j));
identity->SetType(ecs::ObjectType::Terrain);
// Ajouter un composant de transformation
auto transform = entity->AddComponent<ecs::TransformComponent>();
transform->SetPosition(XMVectorSet(i * scaleX, -12.0f, j * scaleZ, 0.0f));
transform->SetScale(XMVectorSet(scaleX, scaleY, scaleZ, 0.0f));
transform->UpdateWorldMatrix();
// Ajouter un composant de rendu
auto render = entity->AddComponent<ecs::RenderComponent>();
render->InitializeWithModel(sharedModel);
// Ajouter un composant de shader
auto shader = entity->AddComponent<ecs::ShaderComponent>();
shader->SetActiveShader(ecs::ShaderType::SUNLIGHT);
}
}
}
update_stats_after_modification();
int totalTiles = gridSizeX * gridSizeZ;
Logger::Get().Log("Terrain généré avec " + std::to_string(totalTiles) + " tuiles", __FILE__, __LINE__, Logger::LogLevel::Info);
}
application_class::delete_terrain
void delete_terrain()
Definition application_class.cpp:1548

## get_aspect_ratio()

float application_class::get_aspect_ratio | ( |  | ) | const

inline

Get the aspect ratio of the screen.

Returns
  The aspect ratio as a float.

Definition at line 355 of file application_class.h.

{ return static_cast<float>(screen_width_) / static_cast<float>(screen_height_); };

## get_back_buffer_srv()

ID3D11ShaderResourceView * application_class::get_back_buffer_srv | ( |  | ) | const

inline

Get the Direct3D back buffer texture.

Returns
  Pointer to the Direct3D back buffer texture.

Definition at line 422 of file application_class.h.

{return back_buffer_srv_;};

## get_can_fixed_update()

bool application_class::get_can_fixed_update | ( |  | ) | const

inline

Get the flag indicating whether the application can perform fixed updates.

Returns
  True if fixed updates are allowed, false otherwise.

Definition at line 411 of file application_class.h.

{ return can_fixed_update_; };

## get_direct_3d()

d_3d_class * application_class::get_direct_3d | ( |  | ) |

virtual

Definition at line 1278 of file application_class.cpp.

{
return direct_3d_;
}

## get_entity_manager()

ecs::EntityManager * application_class::get_entity_manager | ( |  | ) | const

inline

Get the entity manager instance.

Returns
  Pointer to the entity manager instance.

Definition at line 439 of file application_class.h.

{ return entity_manager_.get(); };

## get_fps()

fps_class * application_class::get_fps | ( |  | ) | const

inline

Get the FPS manager instance.

Returns
  Pointer to the FPS manager instance.

Definition at line 433 of file application_class.h.

{ return fps_; };

## get_frustum()

frustum application_class::get_frustum | ( |  | ) | const

inline

Get the frustum used for culling.

Returns
  The frustum used for culling as a frustum object.

Definition at line 371 of file application_class.h.

{ return frustum_culling_; };

## get_frustum_tolerance()

float application_class::get_frustum_tolerance | ( |  | ) | const

inline

Get the frustum culling tolerance. This value is used to determine how much an object must be outside the frustum to be culled.

Returns
  The frustum culling tolerance as a float.

Definition at line 399 of file application_class.h.

{ return frustum_culling_tolerance_; };

## get_hwnd()

HWND application_class::get_hwnd | ( |  | ) | const

inline

Get the handle to the window.

Returns
  The handle to the window as an HWND.

Definition at line 321 of file application_class.h.

{ return hwnd_; };

## get_light_color()

XMVECTOR application_class::get_light_color | ( | int | index | ) |

Get the color for a specific light index.

Parameters

  index |

Returns
  The color of the light as an XMVECTOR.

Definition at line 1722 of file application_class.cpp.

{
//convert to XMVECTOR
XMVECTOR lightColor = XMVectorSet(lights_[index]->GetDiffuseColor().x, lights_[index]->GetDiffuseColor().y, lights_[index]->GetDiffuseColor().z, 1.0f);
return lightColor;
}

## get_light_position()

XMVECTOR application_class::get_light_position | ( | int | index | ) |

Get the position for a specific light index.

Parameters

  index |

Returns
  The position of the light as an XMVECTOR.

Definition at line 1730 of file application_class.cpp.

{
//convert to XMVECTOR
XMVECTOR lightPosition = XMVectorSet(lights_[index]->GetPosition().x, lights_[index]->GetPosition().y, lights_[index]->GetPosition().z, 1.0f);
return lightPosition;
}

## get_lights()

std::vector< light_class * > application_class::get_lights | ( |  | ) | const

inline

Get all the lights in the scene.

Returns
  A vector of pointers to light_class objects representing the lights in the scene.

Definition at line 271 of file application_class.h.

{ return lights_; };

## get_model_cache()

std::map< std::string, std::shared_ptr< model_class > > & application_class::get_model_cache | ( |  | ) |

inline

Get the global model cache. The model cache is a static map that stores shared pointers to model_class objects. This cache is used to avoid loading the same model multiple times.

Returns
  A reference to the global model cache as a map of strings to shared pointers of model_class.

Definition at line 450 of file application_class.h.

{ return g_model_cache; }

## get_object_id()

int application_class::get_object_id | ( |  | ) | const

inline

Get the object ID.

Returns
  The object ID as an integer.

Definition at line 227 of file application_class.h.

{ return object_id_; };

## get_physics()

physics * application_class::get_physics | ( |  | ) | const

inline

Get the physics engine instance.

Returns
  Pointer to the physics engine instance.

Definition at line 361 of file application_class.h.

{ return physics_; };

## get_physics_tick_rate()

int application_class::get_physics_tick_rate | ( |  | ) | const

inline

Get the physics tick rate.

Returns
  The physics tick rate in frames per second as an integer.

Definition at line 146 of file application_class.h.

{ return physics_tick_rate_; };

## get_reflection_texture()

render_texture_class * application_class::get_reflection_texture | ( |  | ) | const

inline

Get the reflection texture used for rendering reflections.

Returns
  Pointer to the reflection texture.

Definition at line 109 of file application_class.h.

{ return reflection_texture_; };

## get_refraction_texture()

render_texture_class * application_class::get_refraction_texture | ( |  | ) | const

inline

Get the refraction texture used for rendering water effects.

Returns
  Pointer to the refraction texture.

Definition at line 104 of file application_class.h.

{ return refraction_texture_; };

## get_render_count()

int application_class::get_render_count | ( |  | ) | const

inline

Get the number of objects rendered in the current frame.

Returns

Definition at line 388 of file application_class.h.

{ return render_count_; };

## get_render_texture()

render_texture_class * application_class::get_render_texture | ( |  | ) | const

inline

Get the display plane used for rendering.

Returns
  Pointer to the display plane.

Definition at line 99 of file application_class.h.

{ return render_texture_; };

## get_scene_texture()

render_texture_class * application_class::get_scene_texture | ( |  | ) | const

inline

Get the scene texture, which is used for rendering the scene.

Returns
  Pointer to the scene texture.

Definition at line 94 of file application_class.h.

{ return scene_texture_; };

## get_screen_height()

int application_class::get_screen_height | ( |  | ) | const

Get the screen height.

Returns
  The height of the screen in pixels as an integer.

Definition at line 1288 of file application_class.cpp.

{
return GetSystemMetrics(SM_CYSCREEN);
}

## get_screen_width()

int application_class::get_screen_width | ( |  | ) | const

Get the screen width.

Returns
  The width of the screen in pixels as an integer.

Definition at line 1283 of file application_class.cpp.

{
return GetSystemMetrics(SM_CXSCREEN);
}

## get_should_quit()

bool application_class::get_should_quit | ( |  | ) | const

inline

Get the should_quit flag. This flag indicates whether the application should quit.

Returns
  The should_quit flag as a boolean.

Definition at line 283 of file application_class.h.

{ return should_quit_; };

## get_speed()

float application_class::get_speed | ( |  | ) | const

inline

Get the speed value. An old value used for the demo spinning object. This value is not used in the current implementation.

Returns
  The speed value as a float.

Definition at line 180 of file application_class.h.

{ return speed_; };

## get_stats()

stats * application_class::get_stats | ( |  | ) | const

inline

Get the Stats manager instance.

Returns
  Pointer to the Stats manager instance.

Definition at line 428 of file application_class.h.

{ return stats_; };

## get_sun_light()

light_class * application_class::get_sun_light | ( |  | ) | const

inline

Get the sun light in the scene.

Returns
  The sun light as a pointer to a light_class object.

Definition at line 276 of file application_class.h.

{ return sun_light_; };

## get_terrain_entity_count()

int application_class::get_terrain_entity_count | ( |  | ) |

Get the number of entities with the ObjectType set as Terrain in the scene.

Returns
  The count of terrain entities as an integer.

Definition at line 2074 of file application_class.cpp.

{
std::lock_guard<std::mutex> lock(objects_mutex_);
int terrainCount = 0;
// Get all entities with the Terrain type
auto entities_with_terrain = entity_manager_->GetEntitiesWithComponent<ecs::IdentityComponent>();
for (auto& entity : entities_with_terrain) {
auto identity = entity->GetComponent<ecs::IdentityComponent>();
if (identity && identity->GetType() == ecs::ObjectType::Terrain) {
terrainCount++;
}
}
return terrainCount;
}

## get_vsync()

bool application_class::get_vsync | ( |  | ) | const

inline

Get the V-sync state.

Returns
  The V-sync state as a boolean.

Definition at line 315 of file application_class.h.

{ return vsync_enabled_; };

## get_w_folder()

std::filesystem::path application_class::get_w_folder | ( |  | ) | const

inline

Get the working folder of the engine.

Returns
  The working folder as a std::filesystem::path.

Definition at line 216 of file application_class.h.

{ return w_folder_; };

## get_window_size()

ImVec2 application_class::get_window_size | ( |  | ) | const

inline

Get the window size for an ImGui window. This isn't used in the current implementation.

Returns
  The window size as an ImVec2.

Definition at line 350 of file application_class.h.

{ return window_size_; };

## initialize()

bool application_class::initialize | ( | int | screen_width,
|  | int | screen_height,
|  | HWND | hwdn,
|  | bool | is_vulkan )

virtual

initialize the application with the given parameters.

Parameters

  screen_width | The width of the screen.
  screen_height | The height of the screen.
  hwdn | The handle to the window.
  is_vulkan | Whether to use Vulkan for rendering.

Returns
  True if the initialization was successful, false otherwise.

Definition at line 70 of file application_class.cpp.

{
Logger::Get().Log("Initializing application class", __FILE__, __LINE__, Logger::LogLevel::Initialize);
try
{
char mouseString1[32], mouseString2[32], mouseString3[32];
char modelFilename[128], renderString[32];
char bitmapFilename[128];
char spriteFilename[128];
char fpsString[32];
bool result;
HRESULT Hresult;
// create entity manager
entity_manager_ = std::make_unique<ecs::EntityManager>();
screen_width_ = screenWidth;
screen_height_ = screenHeight;
set_hwnd(hwnd);
set_windowed(full_screen);
set_screen_height(screenHeight);
set_screen_width(screenWidth);
// Create the Direct3D object.
direct_3d_ = new d_3d_class;
if (!direct_3d_)
{
Logger::Get().Log("Could not create the Direct3D object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
result = direct_3d_->initialize(screen_width_, screen_height_, vsync_enabled_, hwnd, full_screen, screen_depth, screen_near);
if (!result)
{
Logger::Get().Log("Could not initialize Direct3D", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create the camera object.
camera_ = new camera_class;
if (!camera_)
{
Logger::Get().Log("Could not create the camera object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
sun_camera_ = new camera_class;
if (!sun_camera_)
{
Logger::Get().Log("Could not create the sun camera object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
sun_camera_->set_position(0.0f,0.0f,0.0f);
sun_camera_->set_rotation(0.0f, 0.0f, 0.0f);
sun_camera_->render();
sun_camera_->get_view_matrix(base_view_matrix_);
// Set the initial position of the camera.
camera_->set_position(0.0f, 0.0f, -12.0f);
camera_->set_rotation(0.0f, 0.0f, 0.0f);
camera_->render();
camera_->get_view_matrix(base_view_matrix_);
active_camera_ = camera_;
// Create and initialize the font shader object.
font_shader_ = new font_shader_class;
result = font_shader_->initialize(direct_3d_->get_device(), hwnd);
if (!result)
{
Logger::Get().Log("Could not initialize the font shader object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the font object.
font_ = new font_class;
result = font_->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), 0);
if (!result)
{
Logger::Get().Log("Could not initialize the font object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the render to texture object.
render_texture_ = new render_texture_class;
result = render_texture_->Initialize(direct_3d_->get_device(), 256, 256, screen_depth, screen_near, 1);
if (!result)
{
Logger::Get().Log("Could not initialize the render texture object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
//ImVec2 availableSize = ImGui::GetContentRegionAvail();
// Create and initialize the scene render to texture object.
scene_texture_ = new render_texture_class();
result = scene_texture_->Initialize(direct_3d_->get_device(), 256, 256, screen_depth, screen_near, 1);
if (!result)
{
Logger::Get().Log("Could not initialize the render texture object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the display plane object.
display_plane_ = new display_plane_class;
result = display_plane_->Initialize(direct_3d_->get_device(), 1.0f, 1.0f);
if (!result)
{
Logger::Get().Log("Could not initialize the display plane object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the sprite info file we will be using.
//
strcpy_s(spriteFilename, "sprite_data_01.txt");
// Create and initialize the sprite object.
sprite_ = new sprite_class;
result = sprite_->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), screenWidth, screenHeight, spriteFilename, 50, 50);
if (!result)
{
Logger::Get().Log("Could not initialize the sprite object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the initial mouse strings.
strcpy_s(mouseString1, "Mouse X: 0");
strcpy_s(mouseString2, "Mouse Y: 0");
strcpy_s(mouseString3, "Mouse Button: No");
// Create and initialize the text objects for the mouse strings.
mouse_strings_ = new text_class[3];
for (int i = 0; i < 3; i++)
{
int y = 10 + (i * 25);
result = mouse_strings_[i].Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), screenWidth, screenHeight, 32, font_, mouseString1, 10, y, 1.0f, 1.0f, 1.0f);
if (!result)
{
Logger::Get().Log("Could not initialize the mouse strings", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
}
// Set the file name of the bitmap file.
strcpy_s(bitmapFilename, "assets/Texture/stone01.tga");
// Create and initialize the bitmap object.
bitmap_ = new bitmap_class;
result = bitmap_->initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), screenWidth, screenHeight, bitmapFilename, 50, 50);
if (!result)
{
Logger::Get().Log("Could not initialize the bitmap object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the file name of the model.
strcpy_s(modelFilename, "assets/Model/TXT/cube.txt");
// Charger les textures_
std::vector<std::wstring> textureFilenames = {
L"assets/Texture/stone01.png"
};
TextureContainer CubeTextures;
for (const auto& textureFilename : textureFilenames)
{
ID3D11ShaderResourceView* texture = nullptr;
Hresult = DirectX::CreateWICTextureFromFile(direct_3d_->get_device(), direct_3d_->get_device_context(), textureFilename.c_str(), nullptr, &texture);
if (FAILED(Hresult))
{
Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
CubeTextures.diffuse.push_back(texture);
}
// Create and initialize the model object.
model_ = new model_class;
result = model_->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, CubeTextures);
if (!result)
{
Logger::Get().Log("Could not initialize the model object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the light object.
m_light_ = new light_class;
m_light_->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
m_light_->SetDirection(0.0f, 0.0f, -1.0f);
m_light_->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
m_light_->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
m_light_->SetSpecularPower(16.0f);
// Set the number of lights we will use.
num_lights_ = 4;
// Create and initialize the light objects array.
lights_.resize(num_lights_);
lights_[0] = new light_class;
lights_[0]->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); // White
lights_[0]->SetDirection(0.0f, 0.0f, -1.0f);
lights_[0]->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
lights_[0]->SetSpecularColor(1.0f, 1.0f, 1.0f, 1.0f);
lights_[0]->SetSpecularPower(16.0f);
lights_[0]->SetPosition(10.0f, 7.0f, -5.0f);
lights_[1] = new light_class;
lights_[1]->SetDiffuseColor(1.0f, 0.0f, 0.0f, 1.0f); // Red
lights_[1]->SetDirection(0.0f, 0.0f, -1.0f);
lights_[1]->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
lights_[1]->SetSpecularColor(1.0f, 0.0f, 0.0f, 1.0f);
lights_[1]->SetSpecularPower(16.0f);
lights_[1]->SetPosition(-10.0f, 7.0f, -5.0f);
lights_[2] = new light_class;
lights_[2]->SetDiffuseColor(0.0f, 1.0f, 0.0f, 1.0f); // Green
lights_[2]->SetDirection(0.0f, 0.0f, -1.0f);
lights_[2]->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
lights_[2]->SetSpecularColor(0.0f, 1.0f, 0.0f, 1.0f);
lights_[2]->SetSpecularPower(16.0f);
lights_[2]->SetPosition(10.0f, 7.0f, 5.0f);
lights_[3] = new light_class;
lights_[3]->SetDiffuseColor(0.0f, 0.0f, 1.0f, 1.0f); // Blue
lights_[3]->SetDirection(0.0f, 0.0f, -1.0f);
lights_[3]->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
lights_[3]->SetSpecularColor(0.0f, 0.0f, 1.0f, 1.0f);
lights_[3]->SetSpecularPower(16.0f);
lights_[3]->SetPosition(-10.0f, 7.0f, 5.0f);
// ------------------------------------------------------------- //
// ----------------------- || THE SUN || ----------------------- //
// ------------------------------------------------------------- //
sun_light_ = new light_class;
sun_light_->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f); // White
sun_light_->SetDirection(0.0f, -1.0f, 0.0f);
sun_light_->SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);
sun_light_->SetPosition(0.0f, 100.0f, 0.0f);
sun_light_->SetIntensity(1.0f);
sun_camera_->set_position(sun_light_->GetPosition().x, sun_light_->GetPosition().y, sun_light_->GetPosition().z);
sun_camera_->set_rotation(0.0f, 0.0f, 0.0f);
sun_camera_->render();
// Create and initialize the normal map shader object.
shader_manager_ = new shader_manager_class;
result = shader_manager_->initialize(direct_3d_->get_device(), hwnd);
if (!result)
{
Logger::Get().Log("Could not initialize the shader manager object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Set the initial render count string.
strcpy_s(renderString, "render Count: 0");
// Create and initialize the text object for the render count string.
render_count_string_ = new text_class;
result = render_count_string_->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), screenWidth, screenHeight, 32, font_, renderString, 10, 10, 1.0f, 1.0f, 1.0f);
if (!result)
{
Logger::Get().Log("Could not initialize the render count string", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create and initialize the model list object.
model_list_ = new ModelListClass;
model_list_->Initialize(25);
// Charger les textures_ initiales pour bath_model_
std::vector<std::wstring> bathTextures = {
L"assets/Texture/marble01.png"
};
TextureContainer BathTextures;
textures.clear();
for (const auto& textureFilename : bathTextures)
{
ID3D11ShaderResourceView* texture = nullptr;
Hresult = DirectX::CreateWICTextureFromFile(direct_3d_->get_device(), direct_3d_->get_device_context(), textureFilename.c_str(), nullptr, &texture);
if (FAILED(Hresult))
{
Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
BathTextures.diffuse.push_back(texture);
}
// Set the file name of the bath model.
strcpy_s(modelFilename, "assets/Model/TXT/bath.txt");
// Create and initialize the bath model object.
bath_model_ = new model_class;
result = bath_model_->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, BathTextures);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the bath model object.", L"Error", MB_OK);
return false;
}
// Set the file names of the water model.
strcpy_s(modelFilename, "assets/Model/TXT/water.txt");
// replace first element with the new filename
std::vector<std::wstring> waterTextures = {
L"assets/Texture/water01.png"
};
TextureContainer WaterTextures;
textures.clear();
for (const auto& textureFilename : waterTextures)
{
ID3D11ShaderResourceView* texture = nullptr;
Hresult = DirectX::CreateWICTextureFromFile(direct_3d_->get_device(), direct_3d_->get_device_context(), textureFilename.c_str(), nullptr, &texture);
if (FAILED(Hresult))
{
Logger::Get().Log("Failed to load texture: " + std::string(textureFilename.begin(), textureFilename.end()), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
WaterTextures.diffuse.push_back(texture);
}
// Create and initialize the water model object.
water_model_ = new model_class;
result = water_model_->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), modelFilename, WaterTextures);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the water model object.", L"Error", MB_OK);
return false;
}
// Create and initialize the refraction render to texture object.
refraction_texture_ = new render_texture_class;
result = refraction_texture_->Initialize(direct_3d_->get_device(), screenWidth, screenHeight, screen_depth, screen_near, 1);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the refraction render texture object.", L"Error", MB_OK);
return false;
}
// Create and initialize the reflection render to texture object.
reflection_texture_ = new render_texture_class;
result = reflection_texture_->Initialize(direct_3d_->get_device(), screenWidth, screenHeight, screen_depth, screen_near, 1);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the reflection render texture object.", L"Error", MB_OK);
return false;
}
// Set the height of the water.
water_height_ = -9.25f;
// initialize the position of the water.
water_translation_ = 100.0f;
// Create and initialize the timer object.
timer_ = new timer_class;
result = timer_->Initialize();
if (!result)
{
Logger::Get().Log("Could not initialize the timer object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
// Create the position class object.
position_ = new position_class;
// Create and initialize the fps object.
fps_ = new fps_class();
fps_->Initialize();
// Set the initial fps and fps string.
previous_fps_ = -1;
strcpy_s(fpsString, "Fps: 0");
// Create and initialize the text object for the fps string.
fps_string_ = new text_class;
result = fps_string_->Initialize(direct_3d_->get_device(), direct_3d_->get_device_context(), screenWidth, screenHeight, 32, font_, fpsString, 10, 10, 0.0f, 1.0f, 0.0f);
if (!result)
{
Logger::Get().Log("Could not initialize the fps string", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
shadow_map_ = new shadow_map();
if (!shadow_map_->initialize(direct_3d_->get_device(), 2048, 2048))
{
Logger::Get().Log("Could not initialize the shadow map object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
stats_ = new stats();
if (!stats_->initialize(this))
{
Logger::Get().Log("Could not initialize the stats object", __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
physics_ = new physics;
physics_thread_ = std::thread(&application_class::physics_thread_function, this);
//ConstructSkyboxWithPlanes();
Skybox* skybox = new Skybox;
skybox->Initialize(direct_3d_);
skybox_.push_back(skybox->ConstructSkybox(this));
culling_active_ = true;
culling_thread_ = std::thread(&application_class::culling_thread_function, this);
}
catch (const std::exception& e)
{
Logger::Get().Log(std::string("Exception caught during initialization: ") + e.what(), __FILE__, __LINE__, Logger::LogLevel::Error);
return false;
}
Logger::Get().Log("Application class initialized", __FILE__, __LINE__, Logger::LogLevel::Initialize);
return true;
}
ModelListClass
Definition Modellistclass.h:16
Skybox
Definition Skybox.h:8
application_class::set_hwnd
void set_hwnd(HWND hwnd)
Definition application_class.h:326
application_class::set_windowed
void set_windowed(bool windowed)
Definition application_class.h:337
application_class::physics_thread_function
void physics_thread_function()
Thread function for handling physics updates. this function will run in a separate thread to handle p...
Definition application_class.cpp:1978
application_class::set_screen_width
void set_screen_width(int screen_width)
Definition application_class.cpp:1765
application_class::set_screen_height
void set_screen_height(int screen_height)
Definition application_class.cpp:1758
bitmap_class
Definition bitmap_class.h:22
camera_class
Definition camera_class.h:19
d_3d_class
Definition d_3d_class.h:31
display_plane_class
Definition display_plane_class.h:15
font_class
Definition font_class.h:23
font_shader_class
Definition font_shader_class.h:21
fps_class
Definition fps_class.h:21
light_class
Definition light_class.h:20
model_class
Definition model_class.h:151
physics
Definition physics.h:8
position_class
Definition position_class.h:15
render_texture_class
Definition render_texture_class.h:21
shader_manager_class
Definition shader_manager_class.h:28
shadow_map
Definition shadow_map.h:5
sprite_class
Definition sprite_class.h:23
stats
Definition stats.h:13
text_class
Definition text_class.h:13
timer_class
Definition timer_class.h:16

## is_windowed()

bool application_class::is_windowed | ( |  | ) | const

inline

Check if the application is running in windowed mode.

Returns
  True if the application is in windowed mode, false otherwise.

Definition at line 332 of file application_class.h.

{ return windowed_; };

## physics_thread_function()

void application_class::physics_thread_function | ( |  | ) |

Thread function for handling physics updates. this function will run in a separate thread to handle physics updates at a fixed rate (50 fps by default).

Definition at line 1978 of file application_class.cpp.

{
auto fixedUpdateInterval = std::chrono::milliseconds(1000 / physics_tick_rate_);
auto lastTime = std::chrono::steady_clock::now();
while (!should_quit_)
{
auto now = std::chrono::steady_clock::now();
if (now - lastTime >= fixedUpdateInterval)
{
lastTime = now;
float deltaTime = 1.0f / static_cast<float>(physics_tick_rate_);
bool result = render_physics(deltaTime);
if (!result)
{
Logger::Get().Log("Could not render the physics scene", __FILE__, __LINE__, Logger::LogLevel::Error);
return;
}
}
// Attendre un peu pour éviter de surcharger le CPU
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
}

## set_can_fixed_update()

void application_class::set_can_fixed_update | ( | bool | can_fixed_update | ) |

inline

Set the flag indicating whether the application can perform fixed updates.

Parameters

  can_fixed_update | True to allow fixed updates, false to disallow them.

Definition at line 416 of file application_class.h.

{ can_fixed_update_ = can_fixed_update; };

## set_cel_shading()

void application_class::set_cel_shading | ( | const bool | enable | ) |

inline

Set the cel shading mode. This function isn't used in the current implementation. It's an old function that was used for cel shading effects before the complete implementation of the cel shading shader.

Parameters

  enable |

Definition at line 297 of file application_class.h.

{ enable_cel_shading_ = enable; };

## set_direct_3d()

void application_class::set_direct_3d | ( | d_3d_class * | direct_3d | ) |

inline

Definition at line 88 of file application_class.h.

{ direct_3d_ = direct_3d; };

## set_frustum()

void application_class::set_frustum | ( | const frustum & | frustum | ) |

inline

Set the frustum used for culling.

Parameters

  frustum | The new frustum to set for culling.

Definition at line 376 of file application_class.h.

{ frustum_culling_ = frustum; };
frustum
Definition frustum.h:5

## set_frustum_tolerance()

void application_class::set_frustum_tolerance | ( | const float | frustum_tolerance | ) |

inline

Set the frustum culling tolerance. This value is used to determine how much an object must be outside the frustum to be culled.

Parameters

  frustum_tolerance | The new frustum culling tolerance as a float.

Definition at line 405 of file application_class.h.

{ frustum_culling_tolerance_ = frustum_tolerance; };

## set_hwnd()

void application_class::set_hwnd | ( | HWND | hwnd | ) |

inline

Set the handle to the window.

Parameters

  hwnd | The new handle to the window as an HWND.

Definition at line 326 of file application_class.h.

{ hwnd_ = hwnd; };

## set_light_color()

void application_class::set_light_color | ( | int | index,
|  | XMVECTOR | color )

Set the color for a specific light index.

Parameters

  index | The index of the light to set the color for.
  color | The new color as an XMVECTOR.

Definition at line 1738 of file application_class.cpp.

{
//convert to XMFLOAT4
XMFLOAT4 lightColor;
XMStoreFloat4(&lightColor, color);
//set the color
lights_[index]->SetDiffuseColor(lightColor.x, lightColor.y, lightColor.z, 1.0f);
}

## set_light_position()

void application_class::set_light_position | ( | int | index,
|  | XMVECTOR | position )

Set the position for a specific light index.

Parameters

  index | The index of the light to set the position for.
  position | The new position as an XMVECTOR.

Definition at line 1748 of file application_class.cpp.

{
//convert to XMFLOAT4
XMFLOAT4 lightPosition;
XMStoreFloat4(&lightPosition, position);
//set the position
lights_[index]->SetPosition(lightPosition.x, lightPosition.y, lightPosition.z);
}

## set_object_id()

void application_class::set_object_id | ( | int | object_id | ) |

inline

Set the object ID.

Parameters

  object_id | The new object ID as an integer.

Definition at line 232 of file application_class.h.

{ object_id_ = object_id; };

## set_path()

void application_class::set_path | ( | WCHAR * | path | ) |

inline

Set the executable path of the engine.

Parameters

  path |

Definition at line 207 of file application_class.h.

{ path_ = path; };

## set_physics_tick_rate()

void application_class::set_physics_tick_rate | ( | int | physics_tick_rate | ) |

inline

Set the physics tick rate.

Parameters

  physics_tick_rate | The new physics tick rate in frames per second.

Definition at line 151 of file application_class.h.

{ physics_tick_rate_ = physics_tick_rate; };

## set_render_count()

void application_class::set_render_count | ( | const int | render_count | ) |

inline

Set the number of objects rendered in the current frame.

Parameters

  render_count | The new render count as an integer.

Definition at line 393 of file application_class.h.

{ render_count_ = render_count; };

## set_screen_height()

void application_class::set_screen_height | ( | int | screen_height | ) |

Set the screen height.

Parameters

  screen_height | The new height of the screen in pixels as an integer.

Definition at line 1758 of file application_class.cpp.

{
// log the new screen height
Logger::Get().Log("Setting screen height to " + std::to_string(height), __FILE__, __LINE__);
screen_height_ = height;
}

## set_screen_width()

void application_class::set_screen_width | ( | int | screen_width | ) |

Set the screen width.

Parameters

  screen_width | The new width of the screen in pixels as an integer.

Definition at line 1765 of file application_class.cpp.

{
// log the new screen width
Logger::Get().Log("Setting screen width to " + std::to_string(width), __FILE__, __LINE__);
screen_width_ = width;
}

## set_should_quit()

void application_class::set_should_quit | ( | const bool | should_quit | ) |

inline

Set the should_quit flag. This flag indicates whether the application should quit.

Parameters

  should_quit | The new value for the should_quit flag as a boolean.

Definition at line 289 of file application_class.h.

{ should_quit_ = should_quit; };

## set_speed()

void application_class::set_speed | ( | const float | speed | ) |

inline

Set the speed value. An old value used for the demo spinning object. This value is not used in the current implementation.

Parameters

  speed | The new speed value as a float.

Definition at line 187 of file application_class.h.

{ this->speed_ = speed; };

## set_vsync()

void application_class::set_vsync | ( | bool | vsync | ) |

inline

Set the V-sync state.

Parameters

  vsync |

Definition at line 303 of file application_class.h.

{
vsync_enabled_ = vsync;
if (direct_3d_) {
direct_3d_->set_vsync(vsync);
Logger::Get().Log("Setting Vsync to " + std::to_string(vsync), __FILE__, __LINE__);
}
};

## set_w_folder()

void application_class::set_w_folder | ( | const std::filesystem::path & | w_folder | ) |

inline

Set the working folder of the engine.

Definition at line 211 of file application_class.h.

{ w_folder_ = w_folder; };

## set_window_size()

void application_class::set_window_size | ( | const ImVec2 | size | ) |

inline

Set the window size for an ImGui window. This isn't used in the current implementation.

Parameters

  size |

Definition at line 344 of file application_class.h.

{ window_size_ = size; };

## set_windowed()

void application_class::set_windowed | ( | bool | windowed | ) |

inline

Set the windowed mode state.

Parameters

  windowed | True to set the application in windowed mode, false for full screen.

Definition at line 337 of file application_class.h.

{ windowed_ = windowed; };

## shutdown()

void application_class::shutdown | ( |  | ) |

Shutdown the application and release resources.

Definition at line 520 of file application_class.cpp.

{
Logger::Get().Log("Shutting down application class", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
// Release the shader manager object.
if (shader_manager_)
{
Logger::Get().Log("Releasing the shader manager object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
shader_manager_->shutdown();
delete shader_manager_;
shader_manager_ = 0;
Logger::Get().Log("Shader manager object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the reflection render texture object.
if (reflection_texture_)
{
reflection_texture_->Shutdown();
delete reflection_texture_;
reflection_texture_ = 0;
}
// Release the refraction render texture object.
if (refraction_texture_)
{
refraction_texture_->Shutdown();
delete refraction_texture_;
refraction_texture_ = 0;
}
// Release the water model object.
if (water_model_)
{
water_model_->Shutdown();
delete water_model_;
water_model_ = 0;
}
// Release the bath model object.
if (bath_model_)
{
bath_model_->Shutdown();
delete bath_model_;
bath_model_ = 0;
}
// Release the physics object.
if (physics_)
{
delete physics_;
physics_ = 0;
}
// Release the display plane object.
if (display_plane_)
{
Logger::Get().Log("Releasing the display plane object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
display_plane_->Shutdown();
delete display_plane_;
display_plane_ = 0;
Logger::Get().Log("Display plane object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the position object.
if (position_)
{
Logger::Get().Log("Releasing the position object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
delete position_;
position_ = 0;
Logger::Get().Log("Position object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the model list object.
if (model_list_)
{
Logger::Get().Log("Releasing the model list object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
model_list_->Shutdown();
delete model_list_;
model_list_ = 0;
Logger::Get().Log("Model list object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the text objects for the render count string.
if (render_count_string_)
{
Logger::Get().Log("Releasing the render count string object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
render_count_string_->Shutdown();
delete render_count_string_;
render_count_string_ = 0;
Logger::Get().Log("render count string object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the text objects for the mouse strings.
if (mouse_strings_)
{
Logger::Get().Log("Releasing the mouse strings", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
mouse_strings_[0].Shutdown();
mouse_strings_[1].Shutdown();
mouse_strings_[2].Shutdown();
delete[] mouse_strings_;
mouse_strings_ = 0;
Logger::Get().Log("Mouse strings released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the text object for the fps string.
if (fps_string_)
{
Logger::Get().Log("Releasing the fps string object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
fps_string_->Shutdown();
delete fps_string_;
fps_string_ = 0;
Logger::Get().Log("Fps string object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the fps object.
if (fps_)
{
Logger::Get().Log("Releasing the fps object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
delete fps_;
fps_ = 0;
Logger::Get().Log("Fps object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the font object.
if (font_)
{
Logger::Get().Log("Releasing the font object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
font_->Shutdown();
delete font_;
font_ = 0;
Logger::Get().Log("Font object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the font shader object.
if (font_shader_)
{
Logger::Get().Log("Releasing the font shader object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
font_shader_->shutdown();
delete font_shader_;
font_shader_ = 0;
Logger::Get().Log("Font shader object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the timer object.
if (timer_)
{
Logger::Get().Log("Releasing the timer object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
delete timer_;
timer_ = 0;
Logger::Get().Log("Timer object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the sprite object.
if (sprite_)
{
Logger::Get().Log("Releasing the sprite object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
sprite_->Shutdown();
delete sprite_;
sprite_ = 0;
Logger::Get().Log("Sprite object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
for (auto light : lights_)
{
Logger::Get().Log("Releasing the light object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
if (light)
{
delete light;
light = 0;
}
Logger::Get().Log("Light object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the light object.
if (m_light_)
{
Logger::Get().Log("Releasing the light object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
delete m_light_;
m_light_ = 0;
Logger::Get().Log("Light object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
// Release the model object.
if (model_)
{
Logger::Get().Log("Releasing the model object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
model_->Shutdown();
delete model_;
model_ = 0;
Logger::Get().Log("Model object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
if (scene_texture_)
{
scene_texture_->Shutdown();
delete scene_texture_;
scene_texture_ = nullptr;
}
if (sun_camera_)
{
Logger::Get().Log("Releasing the sun camera object", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
delete sun_camera_;
sun_camera_ = nullptr;
Logger::Get().Log("Sun camera object released", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}
if (shadow_map_) {
shadow_map_->shutdown();
delete shadow_map_;
shadow_map_ = nullptr;
}
Logger::Get().Log("Application class shut down", __FILE__, __LINE__, Logger::LogLevel::Shutdown);
}

## update_stats_after_modification()

void application_class::update_stats_after_modification | ( |  | ) |

Update the stats after an update in the scene.

Definition at line 2066 of file application_class.cpp.

{
if (stats_)
{
stats_ -> update_geometric_stats();
}
}

## Member Data Documentation

## textures

std::vector<ID3D11ShaderResourceView*> application_class::textures

Definition at line 533 of file application_class.h.

The documentation for this class was generated from the following files:

- enginecustom/src/inc/system/application_class.h
- enginecustom/src/src/system/application_class.cpp