# Khaotic Engine Reborn: enginecustom/src/inc/system/application_class.h Source File

Loading...
Searching...
No Matches
application_class.h
#ifndef _APPLICATIONCLASS_H_
#define _APPLICATIONCLASS_H_
// MY CLASS INCLUDES //
#include "d_3d_class.h"
#include "camera_class.h"
#include "light_class.h"
#include "bitmap_class.h"
#include "sprite_class.h"
#include "timer_class.h"
#include "font_shader_class.h"
#include "font_class.h"
#include "text_class.h"
#include "fps_class.h"
#include "input_class.h"
#include "shader_manager_class.h"
#include "modellistclass.h"
#include "position_class.h"
#include "frustumclass.h"
#include "render_texture_class.h"
#include "display_plane_class.h"
#include "translate_shader_class.h"
#include "reflection_shader_class.h"
#include "physics.h"
#include "frustum.h"
#include "skybox.h"
#include "shadow_map.h"
#include "stats.h"
#include "ecs/components/identity_component.h"
#include "ecs/components/render_component.h"
#include "ecs/components/transform_component.h"
#include "ecs/components/physics_component.h"
#include "ecs/components/shader_component.h"
#include "ecs/systems/render_system.h"
#include "ecs/components/model_path_component.h"
#include <fstream>
#include <WICTextureLoader.h>
#include <comdef.h> // Pour _com_error
#include <chrono>
#include <thread>
#include <map>
#include <algorithm>
#include <DirectXMath.h>
#include <mutex>
#include <memory>
#include <vector>
#include <filesystem>
#include "ecs/entity_manager.h"
// GLOBALS //
constexpr bool full_screen = false;
constexpr float screen_depth = 1000.0f;
constexpr float screen_near = 0.3f;
static std::map<std::string, std::shared_ptr<model_class>> g_model_cache;
struct input
{
bool key_left = false;
bool key_right = false;
bool key_up = false;
bool key_down = false;
};
// Class name: application_class
class application_class
{
public:
application_class();
~application_class();
virtual d_3d_class* get_direct_3d();
void set_direct_3d(d_3d_class* direct_3d) { direct_3d_ = direct_3d; };
render_texture_class* get_scene_texture() const { return scene_texture_; };
render_texture_class* get_render_texture() const { return render_texture_; };
render_texture_class* get_refraction_texture() const { return refraction_texture_; };
render_texture_class* get_reflection_texture() const { return reflection_texture_; };
bool create_big_cube(int side_count);
virtual bool initialize(int screen_width, int screen_height, HWND hwdn, bool is_vulkan);
void shutdown();
virtual bool frame(input_class*);
void physics_thread_function();
int get_physics_tick_rate() const { return physics_tick_rate_; };
void set_physics_tick_rate(int physics_tick_rate) { physics_tick_rate_ = 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 { return speed_; };
void set_speed(const float speed) { this->speed_ = speed; };
void add_cube();
void delete_entity_by_id(int entity_id);
void add_kobject(std::wstring& filepath);
void set_path(WCHAR* path) { path_ = path; };
void set_w_folder(const std::filesystem::path& w_folder) { w_folder_ = w_folder; };
std::filesystem::path get_w_folder() const { return w_folder_; };
int get_terrain_entity_count();
int get_object_id() const { return object_id_; };
void set_object_id(int object_id) { object_id_ = 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 { return lights_; };
light_class* get_sun_light() const { return sun_light_; };
bool get_should_quit() const { return should_quit_; };
void set_should_quit(const bool should_quit) { should_quit_ = should_quit; };
void set_cel_shading(const bool enable) { enable_cel_shading_ = enable; };
void set_vsync(bool vsync) {
vsync_enabled_ = vsync;
if (direct_3d_) {
direct_3d_->set_vsync(vsync);
Logger::Get().Log("Setting Vsync to " + std::to_string(vsync), __FILE__, __LINE__);
}
};
bool get_vsync() const { return vsync_enabled_; };
HWND get_hwnd() const { return hwnd_; };
void set_hwnd(HWND hwnd) { hwnd_ = hwnd; };
bool is_windowed() const { return windowed_; };
void set_windowed(bool windowed) { windowed_ = windowed; };
void set_window_size(const ImVec2 size) { window_size_ = size; };
ImVec2 get_window_size() const { return window_size_; };
float get_aspect_ratio() const { return static_cast<float>(screen_width_) / static_cast<float>(screen_height_); };
physics* get_physics() const { return physics_; };
// ----------------------------------- //
// ------------- Culling ------------- //
// ----------------------------------- //
frustum get_frustum() const { return frustum_culling_; };
void set_frustum(const frustum& frustum) { frustum_culling_ = frustum; };
void construct_frustum();
int get_render_count() const { return render_count_; };
void set_render_count(const int render_count) { render_count_ = render_count; };
float get_frustum_tolerance() const { return frustum_culling_tolerance_; };
void set_frustum_tolerance(const float frustum_tolerance) { frustum_culling_tolerance_ = frustum_tolerance; };
bool get_can_fixed_update() const { return can_fixed_update_; };
void set_can_fixed_update(bool can_fixed_update) { can_fixed_update_ = can_fixed_update; };
ID3D11ShaderResourceView* get_back_buffer_srv() const {return back_buffer_srv_;};
stats* get_stats() const { return stats_; };
fps_class* get_fps() const { return fps_; };
ecs::EntityManager* get_entity_manager() const { return entity_manager_.get(); };
void update_stats_after_modification();
std::map<std::string, std::shared_ptr<model_class>>& get_model_cache() { return g_model_cache; }
private:
bool render(float, float, float, float, float);
bool render_physics(float delta_time);
bool update_mouse_strings(int, int, bool);
bool update_fps();
bool update_render_count_string(int);
bool render_scene_to_texture(float);
bool render_refraction_to_texture();
bool render_reflection_to_texture();
bool render_pass(XMFLOAT4* diffuse, XMFLOAT4* position, XMFLOAT4* ambient, XMMATRIX view, XMMATRIX projection);
void update_skybox_position();
void culling_thread_function();
public :
std::vector<ID3D11ShaderResourceView*> textures;
private :
// Thread de culling
std::thread culling_thread_;
std::atomic<bool> culling_active_;
std::mutex objects_mutex_;
std::mutex terrain_mutex_;
std::vector<std::tuple<float, float, float, std::string, int>> terrain_generation_data_;
bool terrain_generation_ready_;
int next_terrain_object_id_;
// ------------------------------------- //
// ------------- DIRECT3D -------------- //
// ------------------------------------- //
d_3d_class* direct_3d_;
IDXGISwapChain* swap_chain_;
model_class* model_,* ground_model_, * wall_model_, * bath_model_, * water_model_;
ModelListClass* model_list_;
bool vsync_enabled_ = true;
HWND hwnd_;
bool windowed_;
// ------------------------------------- //
// ------------- RENDERING ------------- //
// ------------------------------------- //
XMMATRIX base_view_matrix_;
render_texture_class* render_texture_, * refraction_texture_, * reflection_texture_;
render_texture_class* scene_texture_;
display_plane_class* display_plane_;
int screen_width_, screen_height_;
camera_class* camera_;
camera_class* sun_camera_;
camera_class* active_camera_;
position_class* position_;
shadow_map* shadow_map_;
ID3D11ShaderResourceView* shadow_map_srv_;
// ------------------------------------ //
// ------------- OBJECTS -------------- //
// ------------------------------------ //
std::unique_ptr<ecs::EntityManager> entity_manager_;
object* selected_object_;
float speed_ = 0.1f; // speed for the demo spinning object
std::vector<object*> imported_object_;
int object_id_ = 0;
std::vector<object*> skybox_;
// ----------------------------------- //
// ------------- LIGHTS -------------- //
// ----------------------------------- //
light_class* m_light_;
std::vector<light_class*> lights_;
int num_lights_;
light_class* sun_light_;
XMFLOAT3 true_light_position_;
model_class* light_model_;
// ----------------------------------- //
// ------------- SHADERS ------------- //
// ----------------------------------- //
shader_manager_class* shader_manager_;
font_shader_class* font_shader_;
bitmap_class* bitmap_;
sprite_class* sprite_;
bool enable_cel_shading_;
// ----------------------------------- //
// ------------ VARIABLES ------------ //
// ----------------------------------- //
float water_height_, water_translation_;
wchar_t* path_;
std::filesystem::path w_folder_;
// ------------------------------------------------- //
// ------------- FPS AND INFO ON SCREEN ------------ //
// ------------------------------------------------- //
timer_class* timer_;
text_class* mouse_strings_;
text_class* render_count_string_;
font_class* font_;
fps_class* fps_;
text_class* fps_string_;
int previous_fps_;
// ------------------------------------------------- //
// ------------------- OTHER ----------------------- //
// ------------------------------------------------- //
bool should_quit_;
physics* physics_;
float gravity_;
XMVECTOR previous_position_;
ImVec2 window_size_;
int physics_tick_rate_ = 50;
bool can_fixed_update_ = false;
std::thread physics_thread_;
ID3D11Texture2D* back_buffer_texture_;
ID3D11ShaderResourceView* back_buffer_srv_;
stats* stats_;
// ------------------------------------------------- //
// ------------------- Culling --------------------- //
// ------------------------------------------------- //
frustum frustum_culling_;
int render_count_;
float frustum_culling_tolerance_ = 5.f;
// ------------------------------------------------- //
// -------------------- Input ---------------------- //
// ------------------------------------------------- //
input inputs_;
bool tab_was_pressed_;
};
#endif
ModelListClass
Definition Modellistclass.h:16
application_class
Definition application_class.h:79
application_class::frame
virtual bool frame(input_class *)
Run the main loop of the application. This function will handle the main loop, including rendering an...
Definition application_class.cpp:760
application_class::get_back_buffer_srv
ID3D11ShaderResourceView * get_back_buffer_srv() const
Definition application_class.h:422
application_class::get_physics_tick_rate
int get_physics_tick_rate() const
Definition application_class.h:146
application_class::set_light_position
void set_light_position(int index, XMVECTOR position)
Definition application_class.cpp:1748
application_class::get_aspect_ratio
float get_aspect_ratio() const
Definition application_class.h:355
application_class::set_cel_shading
void set_cel_shading(const bool enable)
Definition application_class.h:297
application_class::set_render_count
void set_render_count(const int render_count)
Definition application_class.h:393
application_class::get_reflection_texture
render_texture_class * get_reflection_texture() const
Definition application_class.h:109
application_class::get_frustum
frustum get_frustum() const
Definition application_class.h:371
application_class::set_frustum_tolerance
void set_frustum_tolerance(const float frustum_tolerance)
Definition application_class.h:405
application_class::get_w_folder
std::filesystem::path get_w_folder() const
Definition application_class.h:216
application_class::get_object_id
int get_object_id() const
Definition application_class.h:227
application_class::initialize
virtual bool initialize(int screen_width, int screen_height, HWND hwdn, bool is_vulkan)
Definition application_class.cpp:70
application_class::get_window_size
ImVec2 get_window_size() const
Definition application_class.h:350
application_class::get_render_texture
render_texture_class * get_render_texture() const
Definition application_class.h:99
application_class::set_hwnd
void set_hwnd(HWND hwnd)
Definition application_class.h:326
application_class::get_screen_height
int get_screen_height() const
Definition application_class.cpp:1288
application_class::set_path
void set_path(WCHAR *path)
Definition application_class.h:207
application_class::get_light_position
XMVECTOR get_light_position(int index)
Definition application_class.cpp:1730
application_class::delete_entity_by_id
void delete_entity_by_id(int entity_id)
Definition application_class.cpp:1526
application_class::set_w_folder
void set_w_folder(const std::filesystem::path &w_folder)
Definition application_class.h:211
application_class::set_vsync
void set_vsync(bool vsync)
Definition application_class.h:303
application_class::get_hwnd
HWND get_hwnd() const
Definition application_class.h:321
application_class::get_scene_texture
render_texture_class * get_scene_texture() const
Definition application_class.h:94
application_class::delete_terrain
void delete_terrain()
Definition application_class.cpp:1548
application_class::get_model_cache
std::map< std::string, std::shared_ptr< model_class > > & get_model_cache()
Definition application_class.h:450
application_class::set_light_color
void set_light_color(int index, XMVECTOR color)
Definition application_class.cpp:1738
application_class::create_big_cube
bool create_big_cube(int side_count)
Create a big cube with a specified number of little cube per sides.
Definition application_class.cpp:2003
application_class::set_speed
void set_speed(const float speed)
Definition application_class.h:187
application_class::construct_frustum
void construct_frustum()
Definition application_class.cpp:1940
application_class::set_windowed
void set_windowed(bool windowed)
Definition application_class.h:337
application_class::get_light_color
XMVECTOR get_light_color(int index)
Definition application_class.cpp:1722
application_class::get_fps
fps_class * get_fps() const
Definition application_class.h:433
application_class::set_physics_tick_rate
void set_physics_tick_rate(int physics_tick_rate)
Definition application_class.h:151
application_class::get_refraction_texture
render_texture_class * get_refraction_texture() const
Definition application_class.h:104
application_class::set_should_quit
void set_should_quit(const bool should_quit)
Definition application_class.h:289
application_class::add_kobject
void add_kobject(std::wstring &filepath)
Definition application_class.cpp:1378
application_class::get_lights
std::vector< light_class * > get_lights() const
Definition application_class.h:271
application_class::set_can_fixed_update
void set_can_fixed_update(bool can_fixed_update)
Definition application_class.h:416
application_class::get_frustum_tolerance
float get_frustum_tolerance() const
Definition application_class.h:399
application_class::update_stats_after_modification
void update_stats_after_modification()
Definition application_class.cpp:2066
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::get_vsync
bool get_vsync() const
Definition application_class.h:315
application_class::add_cube
void add_cube()
Definition application_class.cpp:1464
application_class::is_windowed
bool is_windowed() const
Definition application_class.h:332
application_class::set_window_size
void set_window_size(const ImVec2 size)
Definition application_class.h:344
application_class::get_physics
physics * get_physics() const
Definition application_class.h:361
application_class::application_class
application_class()
Constructor for the application class. Initializes member variables and sets up the application.
Definition application_class.cpp:6
application_class::get_entity_manager
ecs::EntityManager * get_entity_manager() const
Definition application_class.h:439
application_class::set_frustum
void set_frustum(const frustum &frustum)
Definition application_class.h:376
application_class::get_can_fixed_update
bool get_can_fixed_update() const
Definition application_class.h:411
application_class::generate_terrain
void generate_terrain()
Definition application_class.cpp:1293
application_class::set_screen_width
void set_screen_width(int screen_width)
Definition application_class.cpp:1765
application_class::get_render_count
int get_render_count() const
Definition application_class.h:388
application_class::get_speed
float get_speed() const
Definition application_class.h:180
application_class::get_sun_light
light_class * get_sun_light() const
Definition application_class.h:276
application_class::get_stats
stats * get_stats() const
Definition application_class.h:428
application_class::get_screen_width
int get_screen_width() const
Definition application_class.cpp:1283
application_class::set_object_id
void set_object_id(int object_id)
Definition application_class.h:232
application_class::set_screen_height
void set_screen_height(int screen_height)
Definition application_class.cpp:1758
application_class::shutdown
void shutdown()
Definition application_class.cpp:520
application_class::get_terrain_entity_count
int get_terrain_entity_count()
Definition application_class.cpp:2074
application_class::get_should_quit
bool get_should_quit() const
Definition application_class.h:283
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
ecs::EntityManager
Definition entity_manager.h:9
font_class
Definition font_class.h:23
font_shader_class
Definition font_shader_class.h:21
fps_class
Definition fps_class.h:21
frustum
Definition frustum.h:5
input_class
Definition input_class.h:25
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
input
Definition application_class.h:68