diff --git a/.gitignore b/.gitignore index 51c6aa3..6e43dc0 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ Debug/ Release/ MinSizeRel/ CMakeSettings.json +CMakeUserPresets.json compile_commands.json runme diff --git a/CMakeLists.txt b/CMakeLists.txt index 4db7068..32de854 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) # options option(ENGINE_BUILD_TEST "Compile the test program" ON) -SET(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo") +set(CMAKE_CONFIGURATION_TYPES "Debug;Release;RelWithDebInfo") # enable link time code generation for all targets in the solution set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE) @@ -19,7 +19,11 @@ set(SRC_FILES "src/application.cpp" "src/application_component.cpp" "src/ecs.cpp" + "src/file_dialog.cpp" + "src/files.cpp" + "src/gen_tangents.cpp" "src/gfx_device_vulkan.cpp" + "src/gltf_loader.cpp" "src/input_manager.cpp" "src/renderer.cpp" "src/resource_font.cpp" @@ -33,15 +37,11 @@ set(SRC_FILES "src/system_custom_behaviour.cpp" "src/system_mesh_render.cpp" "src/system_transform.cpp" - "src/files.cpp" - "src/gen_tangents.cpp" - "src/gltf_loader.cpp" - "src/vulkan_device.cpp" "src/vulkan_allocator.cpp" + "src/vulkan_device.cpp" "src/vulkan_instance.cpp" "src/vulkan_swapchain.cpp" "src/window.cpp" - "src/file_dialog.cpp" ) set(INCLUDE_FILES @@ -51,22 +51,24 @@ set(INCLUDE_FILES "include/component_custom.h" "include/component_mesh.h" "include/component_transform.h" + "include/debug_line.h" "include/ecs.h" - "include/vulkan_allocator.h" - "include/vulkan_device.h" - "include/vulkan_instance.h" - "include/vulkan_swapchain.h" + "include/entity.h" "include/event_system.h" + "include/file_dialog.h" + "include/files.h" + "include/gen_tangents.h" "include/gfx.h" "include/gfx_device.h" - "include/input_manager.h" + "include/gltf_loader.h" "include/input_keys.h" + "include/input_manager.h" "include/input_mouse.h" "include/log.h" "include/logger.h" "include/renderer.h" - "include/resource_manager.h" "include/resource_font.h" + "include/resource_manager.h" "include/resource_material.h" "include/resource_mesh.h" "include/resource_shader.h" @@ -78,36 +80,34 @@ set(INCLUDE_FILES "include/system_mesh_render.h" "include/system_transform.h" "include/util.h" - "include/files.h" - "include/gen_tangents.h" - "include/gltf_loader.h" + "include/vulkan_allocator.h" + "include/vulkan_device.h" + "include/vulkan_instance.h" + "include/vulkan_swapchain.h" "include/window.h" - "include/file_dialog.h" ) - -file(GLOB_RECURSE RES_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/res/engine/*") - add_library(${PROJECT_NAME} STATIC ${SRC_FILES} ${INCLUDE_FILES} ${RES_FILES} ) +# show game engine resources in VS generated solution explorer +file(GLOB_RECURSE RES_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/res/engine/*") + +# Organise files in VS generated solution explorer source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/src" PREFIX "Source" FILES ${SRC_FILES}) source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/include" PREFIX "Include" FILES ${INCLUDE_FILES}) source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/res/engine" PREFIX "Resources" FILES ${RES_FILES}) # compiling options: -target_compile_definitions(${PROJECT_NAME} PRIVATE DEFINITIONS "ENGINE_EXPORTS") - if (WIN32) target_compile_definitions(${PROJECT_NAME} PRIVATE DEFINITIONS "NOMINMAX") # stop windows.h conflicting with 'std::max' endif() -set_property(TARGET ${PROJECT_NAME} PROPERTY WINDOWS_EXPORT_ALL_SYMBOLS ON) - +# This project uses C++20 and C11 set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_EXTENSIONS OFF) @@ -133,7 +133,9 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) # Build the test if (ENGINE_BUILD_TEST) add_subdirectory(test) + # Copy DLLs to the enginetest.exe folder (I think that's what this does?) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY $) + # Set enginetest.exe as the default startup project in VS set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT enginetest) endif() @@ -151,7 +153,8 @@ add_subdirectory(vendor/volk) target_link_libraries(${PROJECT_NAME} PUBLIC volk::volk) # Vulkan Memory Allocator -target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC vendor/VulkanMemoryAllocator/include) +add_subdirectory(vendor/VulkanMemoryAllocator) +target_link_libraries(${PROJECT_NAME} PUBLIC VulkanMemoryAllocator) # shaderc if (MSVC) @@ -169,22 +172,20 @@ set(SDL_STATIC OFF CACHE INTERNAL "" FORCE) set(SDL_TEST OFF CACHE INTERNAL "" FORCE) set(BUILD_SHARED_LIBS ON) add_subdirectory(vendor/SDL) -target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC vendor/SDL/include) # TODO maybe delete this line? target_link_libraries(${PROJECT_NAME} PUBLIC SDL2::SDL2) target_link_libraries(${PROJECT_NAME} PUBLIC SDL2::SDL2main) # GLM: set(BUILD_SHARED_LIBS OFF) add_subdirectory(vendor/glm) -target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC vendor/glm) -target_compile_definitions(${PROJECT_NAME} PUBLIC GLM_ENABLE_EXPERIMENTAL) +target_link_libraries(${PROJECT_NAME} PUBLIC glm::glm) # spdlog -set(SPDLOG_BUILD_SHARED OFF CACHE INTERNAL "" FORCE) -set(SPDLOG_SYSTEM_INCLUDES ON CACHE INTERNAL "" FORCE) +set(SPDLOG_BUILD_SHARED OFF) +set(SPDLOG_SYSTEM_INCLUDES ON) set(BUILD_SHARED_LIBS OFF) -add_subdirectory(vendor/spdlog) # automatically calls target_include_directories -target_link_libraries(${PROJECT_NAME} PUBLIC spdlog) +add_subdirectory(vendor/spdlog) +target_link_libraries(${PROJECT_NAME} PUBLIC spdlog::spdlog) # stb add_subdirectory(vendor/stb) diff --git a/include/application.h b/include/application.h index 40d0c33..a98df72 100644 --- a/include/application.h +++ b/include/application.h @@ -5,15 +5,17 @@ #include #include +#include "debug_line.h" #include "gfx.h" -#include "input_manager.h" -#include "renderer.h" #include "resource_manager.h" -#include "scene_manager.h" -#include "window.h" namespace engine { +class Window; // forward-dec +class InputManager; // forward-dec +class Renderer; // forward-dec +class SceneManager; // forward-dec + struct AppConfiguration { bool enable_frame_limiter; }; @@ -23,14 +25,15 @@ private: std::unique_ptr m_window; std::unique_ptr m_input_manager; std::unique_ptr m_renderer; + std::unique_ptr m_scene_manager; std::unordered_map> m_resource_managers{}; std::filesystem::path m_resources_path; - std::unique_ptr m_scene_manager; AppConfiguration m_configuration; + public: const char* const app_name; const char* const app_version; - std::vector debug_lines{}; + std::vector debug_lines{}; public: Application(const char* app_name, const char* app_version, gfx::GraphicsSettings graphics_settings, AppConfiguration configuration); @@ -48,10 +51,10 @@ public: std::shared_ptr getResource(const std::string& name); void gameLoop(); void setFrameLimiter(bool on) { m_configuration.enable_frame_limiter = on; } - Window* window() { return m_window.get(); } - InputManager* input_manager() { return m_input_manager.get(); } - SceneManager* scene_manager() { return m_scene_manager.get(); } - Renderer* renderer() { return m_renderer.get(); } + Window* getWindow() { return m_window.get(); } + InputManager* getInputManager() { return m_input_manager.get(); } + SceneManager* getSceneManager() { return m_scene_manager.get(); } + Renderer* getRenderer() { return m_renderer.get(); } std::string getResourcePath(const std::string relative_path) const { return (m_resources_path / relative_path).string(); } private: diff --git a/include/application_component.h b/include/application_component.h index 0818708..de878e5 100644 --- a/include/application_component.h +++ b/include/application_component.h @@ -8,23 +8,26 @@ namespace engine { class Application; // forward-dec +// a class that extends many classes in the engine to expose 'global' functionality class ApplicationComponent { - // a class that extends many classes in the engine to expose 'global' functionality to lower-tier classes +private: + Application& m_app; - // if multithreading is ever implemented, this class must do synchronization as its instantiations may run concurrently - private: - Application& app_; - - protected: - ApplicationComponent(Application& app) : app_(app) {} - - std::string GetResourcePath(const std::string& relative_path) const; - SDL_Window* GetWindowHandle() const; - const char* GetAppName() const; - const char* GetAppVersion() const; - - public: +public: ApplicationComponent() = delete; + ApplicationComponent(const ApplicationComponent&) = delete; + + ~ApplicationComponent() = default; + + ApplicationComponent& operator=(const ApplicationComponent&) = delete; + +protected: + ApplicationComponent(Application& app) : m_app(app) {} + + std::string getResourcePath(const std::string& relative_path) const; + SDL_Window* getWindowHandle() const; + const char* getAppName() const; + const char* getAppVersion() const; }; } // namespace engine \ No newline at end of file diff --git a/include/component_mesh.h b/include/component_mesh.h index da83e95..5c301d9 100644 --- a/include/component_mesh.h +++ b/include/component_mesh.h @@ -2,11 +2,11 @@ #include -#include "resource_material.h" -#include "resource_mesh.h" - namespace engine { +class Mesh; // forward-dec +class Material; // forward-dec + struct MeshRenderableComponent { std::shared_ptr mesh; std::shared_ptr material; diff --git a/include/debug_line.h b/include/debug_line.h new file mode 100644 index 0000000..bdb2e23 --- /dev/null +++ b/include/debug_line.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace engine { + +struct DebugLine { + glm::vec3 pos1; + glm::vec3 pos2; + glm::vec3 color; +}; + +} // namespace engine \ No newline at end of file diff --git a/include/ecs.h b/include/ecs.h index 890f544..0760fae 100644 --- a/include/ecs.h +++ b/include/ecs.h @@ -1,71 +1,71 @@ #pragma once -#include #include #include #include + +#include #include -#include #include +#include + +#include "entity.h" namespace engine { -class Scene; +class Scene; // forward-dec -using Entity = uint32_t; // ECS entity - -constexpr size_t kMaxComponents = 10; +constexpr size_t MAX_COMPONENTS = 10; class IComponentArray { - public: +public: virtual ~IComponentArray() = default; }; template class ComponentArray : public IComponentArray { - public: - void InsertData(Entity entity, const T& component) +private: + std::vector m_component_array{}; + +public: + void insertData(Entity entity, const T& component) { - if (component_array_.size() < entity + 1) { - component_array_.resize(entity + 1); + if (m_component_array.size() < entity + 1) { + m_component_array.resize(entity + 1); } // bounds checking here as not performance critical - component_array_.at(entity) = component; + m_component_array.at(entity) = component; } - void DeleteData(Entity entity) + void removeData(Entity entity) { (void)entity; // TODO } - T* GetData(Entity entity) + T* getData(Entity entity) { - assert(entity < component_array_.size()); - return &component_array_[entity]; + assert(entity < m_component_array.size()); + return &m_component_array[entity]; } - - private: - std::vector component_array_{}; }; class System { - public: +public: + Scene* const m_scene; + std::bitset m_signature; + std::set m_entities{}; // entities that contain the needed components + +public: System(Scene* scene, std::set required_component_hashes); - virtual ~System() {} System(const System&) = delete; + + virtual ~System() {}; + System& operator=(const System&) = delete; - virtual void OnUpdate(float ts) = 0; - - virtual void OnComponentInsert(Entity) {} - virtual void OnComponentRemove(Entity) {} - - Scene* const scene_; - - std::bitset signature_; - - // entities that contain the needed components - std::set entities_{}; + virtual void onUpdate(float ts) = 0; + virtual void onComponentInsert(Entity) {} + virtual void onComponentRemove(Entity) {} }; } // namespace engine \ No newline at end of file diff --git a/include/entity.h b/include/entity.h new file mode 100644 index 0000000..471173e --- /dev/null +++ b/include/entity.h @@ -0,0 +1,9 @@ +#pragma once + +#include + +namespace engine { + +using Entity = uint32_t; + +} \ No newline at end of file diff --git a/include/renderer.h b/include/renderer.h index d5fd082..2a33dd6 100644 --- a/include/renderer.h +++ b/include/renderer.h @@ -9,6 +9,7 @@ #include "application_component.h" #include "gfx_device.h" #include "system_mesh_render.h" +#include "debug_line.h" namespace engine { @@ -23,12 +24,6 @@ struct UniformDescriptor { gfx::UniformBuffer* uniform_buffer; }; -struct Line { - glm::vec3 pos1; - glm::vec3 pos2; - glm::vec3 color; -}; - class Renderer : private ApplicationComponent { public: Renderer(Application& app, gfx::GraphicsSettings settings); @@ -36,7 +31,7 @@ class Renderer : private ApplicationComponent { ~Renderer(); // staticList can be nullptr to render nothing - void Render(bool window_is_resized, glm::mat4 camera_transform, const RenderList* static_list, const RenderList* dynamic_list, const std::vector& debug_lines); + void Render(bool window_is_resized, glm::mat4 camera_transform, const RenderList* static_list, const RenderList* dynamic_list, const std::vector& debug_lines); // getters diff --git a/include/scene.h b/include/scene.h index 6b81b7c..a49f847 100644 --- a/include/scene.h +++ b/include/scene.h @@ -48,7 +48,7 @@ class Scene { size_t signature_position = next_signature_position_; ++next_signature_position_; - assert(signature_position < kMaxComponents && "Registering too many components!"); + assert(signature_position < MAX_COMPONENTS && "Registering too many components!"); assert(component_signature_positions_.contains(hash) == false); component_signature_positions_.emplace(hash, signature_position); } @@ -65,7 +65,7 @@ class Scene { } auto array = GetComponentArray(); - return array->GetData(entity); + return array->getData(entity); } // because GetComponent(); - array->InsertData(entity, comp); // errors if entity already exists in array + array->insertData(entity, comp); // errors if entity already exists in array // set the component bit for this entity size_t signature_position = component_signature_positions_.at(hash); @@ -91,14 +91,14 @@ class Scene { signature_ref.set(signature_position); for (auto& [system_hash, system] : ecs_systems_) { - if (system->entities_.contains(entity)) continue; - if ((system->signature_ & signature_ref) == system->signature_) { - system->entities_.insert(entity); - system->OnComponentInsert(entity); + if (system->m_entities.contains(entity)) continue; + if ((system->m_signature & signature_ref) == system->m_signature) { + system->m_entities.insert(entity); + system->onComponentInsert(entity); } } - return array->GetData(entity); + return array->getData(entity); } template @@ -148,7 +148,7 @@ class Scene { // maps component hashes to signature positions std::unordered_map component_signature_positions_{}; // maps entity ids to their signatures - std::unordered_map> signatures_{}; + std::unordered_map> signatures_{}; // maps component hashes to their arrays std::unordered_map> component_arrays_{}; diff --git a/include/system_collisions.h b/include/system_collisions.h index 047e4cb..767f85a 100644 --- a/include/system_collisions.h +++ b/include/system_collisions.h @@ -29,9 +29,9 @@ class CollisionSystem : public System { public: CollisionSystem(Scene* scene); - void OnComponentInsert(Entity entity) override; + void onComponentInsert(Entity entity) override; - void OnUpdate(float ts) override; + void onUpdate(float ts) override; Raycast GetRaycast(Ray ray); diff --git a/include/system_custom_behaviour.h b/include/system_custom_behaviour.h index 4bc045a..44cbbe1 100644 --- a/include/system_custom_behaviour.h +++ b/include/system_custom_behaviour.h @@ -14,8 +14,8 @@ class CustomBehaviourSystem : public System { CustomBehaviourSystem(Scene* scene); ~CustomBehaviourSystem(); - void OnUpdate(float ts) override; - void OnComponentInsert(Entity entity) override; + void onUpdate(float ts) override; + void onComponentInsert(Entity entity) override; private: std::unordered_map entity_is_initialised_{}; diff --git a/include/system_mesh_render.h b/include/system_mesh_render.h index f86bc0f..c358664 100644 --- a/include/system_mesh_render.h +++ b/include/system_mesh_render.h @@ -28,8 +28,8 @@ class MeshRenderSystem : public System { const RenderList* GetStaticRenderList() const { return &static_render_list_; } const RenderList* GetDynamicRenderList() const { return &dynamic_render_list_; } - void OnComponentInsert(Entity entity) override; - void OnUpdate(float ts) override; + void onComponentInsert(Entity entity) override; + void onUpdate(float ts) override; private: RenderList static_render_list_; diff --git a/include/system_transform.h b/include/system_transform.h index 328710a..9ce38e7 100644 --- a/include/system_transform.h +++ b/include/system_transform.h @@ -9,7 +9,7 @@ class TransformSystem : public System { public: TransformSystem(Scene* scene); - void OnUpdate(float ts) override; + void onUpdate(float ts) override; /* * Linear-searches for an entity that matches the arguments' criteria. diff --git a/src/application.cpp b/src/application.cpp index 3e01087..fb88ad9 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -24,6 +24,8 @@ #include "resource_mesh.h" #include "resource_shader.h" #include "resource_texture.h" +#include "renderer.h" +#include "debug_line.h" #include "scene.h" #include "scene_manager.h" #include "system_collisions.h" @@ -95,7 +97,7 @@ Application::Application(const char* appName, const char* appVersion, gfx::Graph shaderSettings.write_z = true; shaderSettings.render_order = 0; auto fancyShader = - std::make_unique(renderer(), getResourcePath("engine/shaders/fancy.vert"), getResourcePath("engine/shaders/fancy.frag"), shaderSettings); + std::make_unique(getRenderer(), getResourcePath("engine/shaders/fancy.vert"), getResourcePath("engine/shaders/fancy.frag"), shaderSettings); getResourceManager()->AddPersistent("builtin.fancy", std::move(fancyShader)); } @@ -107,7 +109,7 @@ Application::Application(const char* appName, const char* appVersion, gfx::Graph samplerInfo.magnify = gfx::Filter::kNearest; samplerInfo.mipmap = gfx::Filter::kNearest; samplerInfo.anisotropic_filtering = false; - auto whiteTexture = std::make_unique(renderer(), pixel, 1, 1, samplerInfo, true); + auto whiteTexture = std::make_unique(getRenderer(), pixel, 1, 1, samplerInfo, true); getResourceManager()->AddPersistent("builtin.white", std::move(whiteTexture)); } { @@ -117,7 +119,7 @@ Application::Application(const char* appName, const char* appVersion, gfx::Graph samplerInfo.magnify = gfx::Filter::kNearest; samplerInfo.mipmap = gfx::Filter::kNearest; samplerInfo.anisotropic_filtering = false; - auto blackTexture = std::make_unique(renderer(), pixel, 1, 1, samplerInfo, true); + auto blackTexture = std::make_unique(getRenderer(), pixel, 1, 1, samplerInfo, true); getResourceManager()->AddPersistent("builtin.black", std::move(blackTexture)); } { @@ -127,7 +129,7 @@ Application::Application(const char* appName, const char* appVersion, gfx::Graph samplerInfo.magnify = gfx::Filter::kNearest; samplerInfo.mipmap = gfx::Filter::kNearest; samplerInfo.anisotropic_filtering = false; - auto normalTexture = std::make_unique(renderer(), pixel, 1, 1, samplerInfo, false); + auto normalTexture = std::make_unique(getRenderer(), pixel, 1, 1, samplerInfo, false); getResourceManager()->AddPersistent("builtin.normal", std::move(normalTexture)); } { @@ -137,13 +139,13 @@ Application::Application(const char* appName, const char* appVersion, gfx::Graph samplerInfo.magnify = gfx::Filter::kNearest; samplerInfo.mipmap = gfx::Filter::kNearest; samplerInfo.anisotropic_filtering = false; - auto mrTexture = std::make_unique(renderer(), pixel, 1, 1, samplerInfo, false); + auto mrTexture = std::make_unique(getRenderer(), pixel, 1, 1, samplerInfo, false); getResourceManager()->AddPersistent("builtin.mr", std::move(mrTexture)); } /* default materials */ { - auto defaultMaterial = std::make_unique(renderer(), getResource("builtin.fancy")); + auto defaultMaterial = std::make_unique(getRenderer(), getResource("builtin.fancy")); defaultMaterial->setAlbedoTexture(getResource("builtin.white")); defaultMaterial->setNormalTexture(getResource("builtin.normal")); defaultMaterial->setOcclusionRoughnessMetallicTexture(getResource("builtin.mr")); @@ -205,7 +207,7 @@ void Application::gameLoop() if (now - lastTick >= 1000000000LL * 5LL) [[unlikely]] { lastTick = now; LOG_DEBUG("fps: {}", std::lroundf(avg_fps)); - renderer()->GetDevice()->LogPerformanceInfo(); + getRenderer()->GetDevice()->LogPerformanceInfo(); m_window->ResetAvgFPS(); } @@ -227,7 +229,7 @@ void Application::gameLoop() ImGui_ImplSDL2_NewFrame(); ImGui::NewFrame(); - //ImGui::ShowDemoWindow(); + // ImGui::ShowDemoWindow(); // Stop mouse from moving the camera when the settings menu is open m_input_manager->SetDeviceActive(InputDevice::kMouse, !debug_menu_state.menu_active); @@ -274,7 +276,7 @@ void Application::gameLoop() if (!scene) ImGui::BeginDisabled(); // load gltf file dialog if (ImGui::Button("Load glTF")) { - std::filesystem::path path = util::OpenFileDialog({ "glb" }); + std::filesystem::path path = util::OpenFileDialog({"glb"}); if (path.empty() == false) { util::LoadGLTF(*scene, path.string(), false); } @@ -327,85 +329,85 @@ void Application::gameLoop() if (node.type1 == CollisionSystem::BiTreeNode::Type::Entity) { const glm::vec3 col = (node.type1 == CollisionSystem::BiTreeNode::Type::BoundingVolume) ? glm::vec3{1.0f, 0.0f, 0.0f} : glm::vec3{0.0f, 1.0f, 0.0f}; - Line line1{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.min.z}, - glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.min.z}, col}; + DebugLine line1{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.min.z}, + glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.min.z}, col}; debug_lines.push_back(line1); - Line line2{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.min.z}, - glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.min.z}, col}; + DebugLine line2{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.min.z}, + glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.min.z}, col}; debug_lines.push_back(line2); - Line line3{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.min.z}, - glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.min.z}, col}; + DebugLine line3{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.min.z}, + glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.min.z}, col}; debug_lines.push_back(line3); - Line line4{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.min.z}, - glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.min.z}, col}; + DebugLine line4{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.min.z}, + glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.min.z}, col}; debug_lines.push_back(line4); - Line line5{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.min.z}, - glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.max.z}, col}; + DebugLine line5{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.min.z}, + glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.max.z}, col}; debug_lines.push_back(line5); - Line line6{glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.min.z}, - glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.max.z}, col}; + DebugLine line6{glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.min.z}, + glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.max.z}, col}; debug_lines.push_back(line6); - Line line7{glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.min.z}, - glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.max.z}, col}; + DebugLine line7{glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.min.z}, + glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.max.z}, col}; debug_lines.push_back(line7); - Line line8{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.min.z}, - glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.max.z}, col}; + DebugLine line8{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.min.z}, + glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.max.z}, col}; debug_lines.push_back(line8); - Line line9{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.max.z}, - glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.max.z}, col}; + DebugLine line9{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.max.z}, + glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.max.z}, col}; debug_lines.push_back(line9); - Line line10{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.max.z}, - glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.max.z}, col}; + DebugLine line10{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.max.z}, + glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.max.z}, col}; debug_lines.push_back(line10); - Line line11{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.max.z}, - glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.max.z}, col}; + DebugLine line11{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.max.z}, + glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.max.z}, col}; debug_lines.push_back(line11); - Line line12{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.max.z}, - glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.max.z}, col}; + DebugLine line12{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.max.z}, + glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.max.z}, col}; debug_lines.push_back(line12); } if (node.type2 == CollisionSystem::BiTreeNode::Type::Entity) { const glm::vec3 col = (node.type2 == CollisionSystem::BiTreeNode::Type::BoundingVolume) ? glm::vec3{1.0f, 0.0f, 0.0f} : glm::vec3{0.0f, 1.0f, 0.0f}; - Line line1{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.min.z}, - glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.min.z}, col}; + DebugLine line1{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.min.z}, + glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.min.z}, col}; debug_lines.push_back(line1); - Line line2{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.min.z}, - glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.min.z}, col}; + DebugLine line2{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.min.z}, + glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.min.z}, col}; debug_lines.push_back(line2); - Line line3{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.min.z}, - glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.min.z}, col}; + DebugLine line3{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.min.z}, + glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.min.z}, col}; debug_lines.push_back(line3); - Line line4{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.min.z}, - glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.min.z}, col}; + DebugLine line4{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.min.z}, + glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.min.z}, col}; debug_lines.push_back(line4); - Line line5{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.min.z}, - glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.max.z}, col}; + DebugLine line5{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.min.z}, + glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.max.z}, col}; debug_lines.push_back(line5); - Line line6{glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.min.z}, - glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.max.z}, col}; + DebugLine line6{glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.min.z}, + glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.max.z}, col}; debug_lines.push_back(line6); - Line line7{glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.min.z}, - glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.max.z}, col}; + DebugLine line7{glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.min.z}, + glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.max.z}, col}; debug_lines.push_back(line7); - Line line8{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.min.z}, - glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.max.z}, col}; + DebugLine line8{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.min.z}, + glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.max.z}, col}; debug_lines.push_back(line8); - Line line9{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.max.z}, - glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.max.z}, col}; + DebugLine line9{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.max.z}, + glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.max.z}, col}; debug_lines.push_back(line9); - Line line10{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.max.z}, - glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.max.z}, col}; + DebugLine line10{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.max.z}, + glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.max.z}, col}; debug_lines.push_back(line10); - Line line11{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.max.z}, - glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.max.z}, col}; + DebugLine line11{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.max.z}, + glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.max.z}, col}; debug_lines.push_back(line11); - Line line12{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.max.z}, - glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.max.z}, col}; + DebugLine line12{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.max.z}, + glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.max.z}, col}; debug_lines.push_back(line12); } } @@ -417,85 +419,85 @@ void Application::gameLoop() if (node.type1 == CollisionSystem::BiTreeNode::Type::BoundingVolume) { const glm::vec3 col = (node.type1 == CollisionSystem::BiTreeNode::Type::BoundingVolume) ? glm::vec3{1.0f, 0.0f, 0.0f} : glm::vec3{0.0f, 1.0f, 0.0f}; - Line line1{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.min.z}, - glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.min.z}, col}; + DebugLine line1{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.min.z}, + glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.min.z}, col}; debug_lines.push_back(line1); - Line line2{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.min.z}, - glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.min.z}, col}; + DebugLine line2{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.min.z}, + glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.min.z}, col}; debug_lines.push_back(line2); - Line line3{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.min.z}, - glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.min.z}, col}; + DebugLine line3{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.min.z}, + glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.min.z}, col}; debug_lines.push_back(line3); - Line line4{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.min.z}, - glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.min.z}, col}; + DebugLine line4{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.min.z}, + glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.min.z}, col}; debug_lines.push_back(line4); - Line line5{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.min.z}, - glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.max.z}, col}; + DebugLine line5{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.min.z}, + glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.max.z}, col}; debug_lines.push_back(line5); - Line line6{glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.min.z}, - glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.max.z}, col}; + DebugLine line6{glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.min.z}, + glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.max.z}, col}; debug_lines.push_back(line6); - Line line7{glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.min.z}, - glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.max.z}, col}; + DebugLine line7{glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.min.z}, + glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.max.z}, col}; debug_lines.push_back(line7); - Line line8{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.min.z}, - glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.max.z}, col}; + DebugLine line8{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.min.z}, + glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.max.z}, col}; debug_lines.push_back(line8); - Line line9{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.max.z}, - glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.max.z}, col}; + DebugLine line9{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.max.z}, + glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.max.z}, col}; debug_lines.push_back(line9); - Line line10{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.max.z}, - glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.max.z}, col}; + DebugLine line10{glm::vec3{node.box1.min.x, node.box1.min.y, node.box1.max.z}, + glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.max.z}, col}; debug_lines.push_back(line10); - Line line11{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.max.z}, - glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.max.z}, col}; + DebugLine line11{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.max.z}, + glm::vec3{node.box1.max.x, node.box1.min.y, node.box1.max.z}, col}; debug_lines.push_back(line11); - Line line12{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.max.z}, - glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.max.z}, col}; + DebugLine line12{glm::vec3{node.box1.max.x, node.box1.max.y, node.box1.max.z}, + glm::vec3{node.box1.min.x, node.box1.max.y, node.box1.max.z}, col}; debug_lines.push_back(line12); } if (node.type2 == CollisionSystem::BiTreeNode::Type::BoundingVolume) { const glm::vec3 col = (node.type2 == CollisionSystem::BiTreeNode::Type::BoundingVolume) ? glm::vec3{1.0f, 0.0f, 0.0f} : glm::vec3{0.0f, 1.0f, 0.0f}; - Line line1{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.min.z}, - glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.min.z}, col}; + DebugLine line1{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.min.z}, + glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.min.z}, col}; debug_lines.push_back(line1); - Line line2{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.min.z}, - glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.min.z}, col}; + DebugLine line2{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.min.z}, + glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.min.z}, col}; debug_lines.push_back(line2); - Line line3{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.min.z}, - glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.min.z}, col}; + DebugLine line3{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.min.z}, + glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.min.z}, col}; debug_lines.push_back(line3); - Line line4{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.min.z}, - glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.min.z}, col}; + DebugLine line4{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.min.z}, + glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.min.z}, col}; debug_lines.push_back(line4); - Line line5{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.min.z}, - glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.max.z}, col}; + DebugLine line5{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.min.z}, + glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.max.z}, col}; debug_lines.push_back(line5); - Line line6{glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.min.z}, - glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.max.z}, col}; + DebugLine line6{glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.min.z}, + glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.max.z}, col}; debug_lines.push_back(line6); - Line line7{glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.min.z}, - glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.max.z}, col}; + DebugLine line7{glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.min.z}, + glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.max.z}, col}; debug_lines.push_back(line7); - Line line8{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.min.z}, - glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.max.z}, col}; + DebugLine line8{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.min.z}, + glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.max.z}, col}; debug_lines.push_back(line8); - Line line9{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.max.z}, - glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.max.z}, col}; + DebugLine line9{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.max.z}, + glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.max.z}, col}; debug_lines.push_back(line9); - Line line10{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.max.z}, - glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.max.z}, col}; + DebugLine line10{glm::vec3{node.box2.min.x, node.box2.min.y, node.box2.max.z}, + glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.max.z}, col}; debug_lines.push_back(line10); - Line line11{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.max.z}, - glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.max.z}, col}; + DebugLine line11{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.max.z}, + glm::vec3{node.box2.max.x, node.box2.min.y, node.box2.max.z}, col}; debug_lines.push_back(line11); - Line line12{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.max.z}, - glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.max.z}, col}; + DebugLine line12{glm::vec3{node.box2.max.x, node.box2.max.y, node.box2.max.z}, + glm::vec3{node.box2.min.x, node.box2.max.y, node.box2.max.z}, col}; debug_lines.push_back(line12); } } @@ -506,7 +508,7 @@ void Application::gameLoop() static_list = mesh_render_system->GetStaticRenderList(); dynamic_list = mesh_render_system->GetDynamicRenderList(); } - m_renderer->Render(window()->GetWindowResized(), camera_transform, static_list, dynamic_list, debug_lines); + m_renderer->Render(getWindow()->GetWindowResized(), camera_transform, static_list, dynamic_list, debug_lines); debug_lines.clear(); // gets remade every frame :0 /* poll events */ diff --git a/src/application_component.cpp b/src/application_component.cpp index 36b2c4c..90b654d 100644 --- a/src/application_component.cpp +++ b/src/application_component.cpp @@ -7,17 +7,17 @@ namespace engine { -std::string ApplicationComponent::GetResourcePath(const std::string& relative_path) const { return app_.getResourcePath(relative_path); } +std::string ApplicationComponent::getResourcePath(const std::string& relative_path) const { return m_app.getResourcePath(relative_path); } -SDL_Window* ApplicationComponent::GetWindowHandle() const { - return app_.window()->GetHandle(); +SDL_Window* ApplicationComponent::getWindowHandle() const { + return m_app.getWindow()->GetHandle(); } -const char* ApplicationComponent::GetAppName() const { - return app_.app_name; +const char* ApplicationComponent::getAppName() const { + return m_app.app_name; } -const char* ApplicationComponent::GetAppVersion() const { - return app_.app_version; +const char* ApplicationComponent::getAppVersion() const { + return m_app.app_version; } } // namespace engine \ No newline at end of file diff --git a/src/ecs.cpp b/src/ecs.cpp index c31e3c6..0823126 100644 --- a/src/ecs.cpp +++ b/src/ecs.cpp @@ -5,11 +5,11 @@ namespace engine { System::System(Scene* scene, std::set requiredComponentHashes) - : scene_(scene) + : m_scene(scene) { for (size_t componentHash : requiredComponentHashes) { - size_t componentSignaturePosition = scene_->GetComponentSignaturePosition(componentHash); - signature_.set(componentSignaturePosition); + size_t componentSignaturePosition = m_scene->GetComponentSignaturePosition(componentHash); + m_signature.set(componentSignaturePosition); } } diff --git a/src/gltf_loader.cpp b/src/gltf_loader.cpp index c02ed25..73cabb6 100644 --- a/src/gltf_loader.cpp +++ b/src/gltf_loader.cpp @@ -1,15 +1,17 @@ #include "gltf_loader.h" -#include "log.h" -#include "files.h" - #include -#include #include +#include +#include "component_collider.h" #include "component_mesh.h" #include "component_transform.h" -#include "component_collider.h" +#include "files.h" +#include "log.h" +#include "renderer.h" +#include "resource_material.h" +#include "resource_texture.h" struct Color { uint8_t r, g, b, a; @@ -203,7 +205,7 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic) const tg::Image& image = model.images.at(texture.source); if (image.as_is == false && image.bits == 8 && image.component == 4 && image.pixel_type == TINYGLTF_COMPONENT_TYPE_UNSIGNED_BYTE) { // create texture on GPU - textures.back() = std::make_shared(scene.app()->renderer(), image.image.data(), image.width, image.height, samplerInfo, + textures.back() = std::make_shared(scene.app()->getRenderer(), image.image.data(), image.width, image.height, samplerInfo, tex_index_is_base_color[texture_idx]); } else { @@ -245,7 +247,7 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic) } } - materials.emplace_back(std::make_shared(scene.app()->renderer(), scene.app()->getResource("builtin.fancy"))); + materials.emplace_back(std::make_shared(scene.app()->getRenderer(), scene.app()->getResource("builtin.fancy"))); // base color materials.back()->setAlbedoTexture(scene.app()->getResource("builtin.white")); @@ -267,7 +269,7 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic) samplerInfo.magnify = gfx::Filter::kNearest; samplerInfo.mipmap = gfx::Filter::kNearest; samplerInfo.anisotropic_filtering = false; - colour_textures.emplace(std::make_pair(c, std::make_shared(scene.app()->renderer(), pixel, 1, 1, samplerInfo, true))); + colour_textures.emplace(std::make_pair(c, std::make_shared(scene.app()->getRenderer(), pixel, 1, 1, samplerInfo, true))); } materials.back()->setAlbedoTexture(colour_textures.at(c)); } @@ -296,7 +298,7 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic) samplerInfo.magnify = gfx::Filter::kNearest; samplerInfo.mipmap = gfx::Filter::kNearest; samplerInfo.anisotropic_filtering = false; - metal_rough_textures.emplace(std::make_pair(mr, std::make_shared(scene.app()->renderer(), pixel, 1, 1, samplerInfo, false))); + metal_rough_textures.emplace(std::make_pair(mr, std::make_shared(scene.app()->getRenderer(), pixel, 1, 1, samplerInfo, false))); } materials.back()->setOcclusionRoughnessMetallicTexture(metal_rough_textures.at(mr)); } @@ -550,7 +552,7 @@ engine::Entity LoadGLTF(Scene& scene, const std::string& path, bool isStatic) } // generate mesh on GPU - std::shared_ptr engine_mesh = std::make_shared(scene.app()->renderer()->GetDevice(), vertices, indices); + std::shared_ptr engine_mesh = std::make_shared(scene.app()->getRenderer()->GetDevice(), vertices, indices); // get material std::shared_ptr engine_material = nullptr; diff --git a/src/renderer.cpp b/src/renderer.cpp index 591989c..4b83876 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -16,7 +16,7 @@ namespace engine { Renderer::Renderer(Application& app, gfx::GraphicsSettings settings) : ApplicationComponent(app) { - device_ = std::make_unique(GetAppName(), GetAppVersion(), GetWindowHandle(), settings); + device_ = std::make_unique(getAppName(), getAppVersion(), getWindowHandle(), settings); // sort out descriptor set layouts: std::vector globalSetBindings; @@ -75,8 +75,8 @@ Renderer::Renderer(Application& app, gfx::GraphicsSettings settings) : Applicati { gfx::PipelineInfo debug_pipeline_info{}; - debug_pipeline_info.vert_shader_path = GetResourcePath("engine/shaders/debug.vert"); - debug_pipeline_info.frag_shader_path = GetResourcePath("engine/shaders/debug.frag"); + debug_pipeline_info.vert_shader_path = getResourcePath("engine/shaders/debug.vert"); + debug_pipeline_info.frag_shader_path = getResourcePath("engine/shaders/debug.frag"); debug_pipeline_info.vertex_format = debug_vertex_format; debug_pipeline_info.alpha_blending = false; debug_pipeline_info.face_cull_mode = gfx::CullMode::kCullNone; // probably ignored for line rendering @@ -97,7 +97,7 @@ Renderer::Renderer(Application& app, gfx::GraphicsSettings settings) : Applicati for (int face = 0; face < 6; ++face) { std::string path = std::string("engine/textures/skybox") + std::to_string(face) + std::string(".jpg"); - face_unq_ptrs[face] = ReadImageFile(GetResourcePath(path), w, h); + face_unq_ptrs[face] = ReadImageFile(getResourcePath(path), w, h); if (cubemap_w != w || cubemap_h != h) throw std::runtime_error("Skybox textures must be 512x512!"); face_unsafe_ptrs[face] = face_unq_ptrs[face]->data(); } @@ -119,12 +119,12 @@ Renderer::Renderer(Application& app, gfx::GraphicsSettings settings) : Applicati // create skybox shader { gfx::VertexFormat vertex_format{}; - vertex_format.attribute_descriptions.emplace_back(0, gfx::VertexAttribFormat::kFloat3, 0); + vertex_format.attribute_descriptions.emplace_back(0u, gfx::VertexAttribFormat::kFloat3, 0u); vertex_format.stride = 3 * sizeof(float); gfx::PipelineInfo pipeline_info{}; - pipeline_info.vert_shader_path = GetResourcePath("engine/shaders/skybox.vert"); - pipeline_info.frag_shader_path = GetResourcePath("engine/shaders/skybox.frag"); + pipeline_info.vert_shader_path = getResourcePath("engine/shaders/skybox.vert"); + pipeline_info.frag_shader_path = getResourcePath("engine/shaders/skybox.frag"); pipeline_info.vertex_format = vertex_format; pipeline_info.alpha_blending = false; pipeline_info.face_cull_mode = gfx::CullMode::kCullBack; @@ -195,11 +195,11 @@ Renderer::Renderer(Application& app, gfx::GraphicsSettings settings) : Applicati // shadow map pipeline gfx::VertexFormat shadowVertexFormat{}; shadowVertexFormat.stride = sizeof(float) * 12; // using the full meshes so a lot of data is skipped - shadowVertexFormat.attribute_descriptions.emplace_back(0, gfx::VertexAttribFormat::kFloat3, 0); // position - shadowVertexFormat.attribute_descriptions.emplace_back(1, gfx::VertexAttribFormat::kFloat2, sizeof(float) * 10); // uv + shadowVertexFormat.attribute_descriptions.emplace_back(0u, gfx::VertexAttribFormat::kFloat3, 0u); // position + shadowVertexFormat.attribute_descriptions.emplace_back(1u, gfx::VertexAttribFormat::kFloat2, static_cast(sizeof(float)) * 10u); // uv gfx::PipelineInfo shadowPipelineInfo{}; - shadowPipelineInfo.vert_shader_path = GetResourcePath("engine/shaders/shadow.vert"); - shadowPipelineInfo.frag_shader_path = GetResourcePath("engine/shaders/shadow.frag"); + shadowPipelineInfo.vert_shader_path = getResourcePath("engine/shaders/shadow.vert"); + shadowPipelineInfo.frag_shader_path = getResourcePath("engine/shaders/shadow.frag"); shadowPipelineInfo.vertex_format = shadowVertexFormat; shadowPipelineInfo.face_cull_mode = gfx::CullMode::kCullFront; // shadows care about back faces shadowPipelineInfo.alpha_blending = false; @@ -250,7 +250,7 @@ Renderer::~Renderer() device_->DestroyDescriptorSetLayout(global_uniform.layout); } -void Renderer::Render(bool window_is_resized, glm::mat4 camera_transform, const RenderList* static_list, const RenderList* dynamic_list, const std::vector& debug_lines) +void Renderer::Render(bool window_is_resized, glm::mat4 camera_transform, const RenderList* static_list, const RenderList* dynamic_list, const std::vector& debug_lines) { if (window_is_resized) { @@ -321,7 +321,7 @@ void Renderer::Render(bool window_is_resized, glm::mat4 camera_transform, const // draw debug shit here device_->CmdBindPipeline(draw_buffer, debug_rendering_things_.pipeline); DebugPush push{}; - for (const Line& l : debug_lines) { + for (const DebugLine& l : debug_lines) { push.pos1 = global_uniform.uniform_buffer_data.data.proj * frame_uniform.uniform_buffer_data.data * glm::vec4(l.pos1, 1.0f); push.pos2 = global_uniform.uniform_buffer_data.data.proj * frame_uniform.uniform_buffer_data.data * glm::vec4(l.pos2, 1.0f); push.color = l.color; diff --git a/src/resource_material.cpp b/src/resource_material.cpp index 1d830dc..752812b 100644 --- a/src/resource_material.cpp +++ b/src/resource_material.cpp @@ -1,5 +1,6 @@ #include "resource_material.h" +#include "renderer.h" #include "resource_shader.h" namespace engine { diff --git a/src/resource_shader.cpp b/src/resource_shader.cpp index 36a60f2..4de80c6 100644 --- a/src/resource_shader.cpp +++ b/src/resource_shader.cpp @@ -3,6 +3,7 @@ #include "application.h" #include "gfx_device.h" #include "log.h" +#include "renderer.h" #include diff --git a/src/resource_texture.cpp b/src/resource_texture.cpp index d287c5e..c89791e 100644 --- a/src/resource_texture.cpp +++ b/src/resource_texture.cpp @@ -3,6 +3,7 @@ #include "application.h" #include "files.h" #include "log.h" +#include "renderer.h" #include diff --git a/src/scene.cpp b/src/scene.cpp index 11eebcb..2444d2f 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -36,7 +36,7 @@ Entity Scene::CreateEntity(const std::string& tag, Entity parent, const glm::vec3& scl) { Entity id = next_entity_id_++; - signatures_.emplace(id, std::bitset{}); + signatures_.emplace(id, std::bitset{}); auto t = AddComponent(id); @@ -61,7 +61,7 @@ size_t Scene::GetComponentSignaturePosition(size_t hash) { void Scene::Update(float ts) { for (auto& [name, system] : ecs_systems_) { - system->OnUpdate(ts); + system->onUpdate(ts); } event_system_->DespatchEvents(); // clears event queue diff --git a/src/system_collisions.cpp b/src/system_collisions.cpp index d808825..2effeb6 100644 --- a/src/system_collisions.cpp +++ b/src/system_collisions.cpp @@ -74,19 +74,19 @@ static std::pair RayBoxIntersection(const Ray& ray, const AABB& box CollisionSystem::CollisionSystem(Scene* scene) : System(scene, {typeid(TransformComponent).hash_code(), typeid(ColliderComponent).hash_code()}) {} -void CollisionSystem::OnComponentInsert(Entity entity) { ++colliders_size_now_; } +void CollisionSystem::onComponentInsert(Entity entity) { ++colliders_size_now_; } -void CollisionSystem::OnUpdate(float ts) +void CollisionSystem::onUpdate(float ts) { (void)ts; if (colliders_size_last_update_ != colliders_size_now_) { std::vector prims{}; - prims.reserve(entities_.size()); - for (Entity entity : entities_) { - const auto t = scene_->GetComponent(entity); - const auto c = scene_->GetComponent(entity); + prims.reserve(m_entities.size()); + for (Entity entity : m_entities) { + const auto t = m_scene->GetComponent(entity); + const auto c = m_scene->GetComponent(entity); AABB transformed_box{}; transformed_box.min = t->world_matrix * glm::vec4(c->aabb.min, 1.0f); @@ -107,7 +107,7 @@ void CollisionSystem::OnUpdate(float ts) } bvh_.clear(); - bvh_.reserve(entities_.size() * 3 / 2); // from testing, bvh is usually 20% larger than number of objects + bvh_.reserve(m_entities.size() * 3 / 2); // from testing, bvh is usually 20% larger than number of objects BuildNode(prims, bvh_); // check AABB mins and maxes are the correct order @@ -297,7 +297,7 @@ int CollisionSystem::BuildNode(std::vector& prims, std::vector(prims.size()) - (i + 1))); if (combined_surface_area < sah) { sah = combined_surface_area; optimal_box1 = box1; diff --git a/src/system_custom_behaviour.cpp b/src/system_custom_behaviour.cpp index 0ac607b..71c3ca8 100644 --- a/src/system_custom_behaviour.cpp +++ b/src/system_custom_behaviour.cpp @@ -16,9 +16,9 @@ CustomBehaviourSystem::CustomBehaviourSystem(Scene* scene) CustomBehaviourSystem::~CustomBehaviourSystem() {} -void CustomBehaviourSystem::OnUpdate(float ts) { - for (Entity entity : entities_) { - auto c = scene_->GetComponent(entity); +void CustomBehaviourSystem::onUpdate(float ts) { + for (Entity entity : m_entities) { + auto c = m_scene->GetComponent(entity); assert(c != nullptr); bool& entity_initialised = entity_is_initialised_.at(entity); if (entity_initialised == false) { @@ -31,7 +31,7 @@ void CustomBehaviourSystem::OnUpdate(float ts) { } } -void CustomBehaviourSystem::OnComponentInsert(Entity entity) +void CustomBehaviourSystem::onComponentInsert(Entity entity) { entity_is_initialised_.emplace(entity, false); } diff --git a/src/system_mesh_render.cpp b/src/system_mesh_render.cpp index b006433..9abb692 100644 --- a/src/system_mesh_render.cpp +++ b/src/system_mesh_render.cpp @@ -2,9 +2,10 @@ #include -#include "component_transform.h" #include "component_mesh.h" +#include "component_transform.h" #include "log.h" +#include "resource_material.h" namespace engine { @@ -18,13 +19,13 @@ void MeshRenderSystem::RebuildStaticRenderList() list_needs_rebuild_ = false; } -void MeshRenderSystem::OnComponentInsert(Entity entity) +void MeshRenderSystem::onComponentInsert(Entity entity) { (void)entity; list_needs_rebuild_ = true; } -void MeshRenderSystem::OnUpdate(float ts) +void MeshRenderSystem::onUpdate(float ts) { // do stuff (void)ts; @@ -39,16 +40,16 @@ void MeshRenderSystem::OnUpdate(float ts) void MeshRenderSystem::BuildRenderList(RenderList& render_list, bool with_static_entities) { render_list.clear(); - render_list.reserve(entities_.size()); + render_list.reserve(m_entities.size()); std::unordered_map render_orders; - for (Entity entity : entities_) { - auto transform = scene_->GetComponent(entity); + for (Entity entity : m_entities) { + auto transform = m_scene->GetComponent(entity); if (transform->is_static != with_static_entities) continue; - auto renderable = scene_->GetComponent(entity); + auto renderable = m_scene->GetComponent(entity); if (renderable->visible == false) continue; diff --git a/src/system_transform.cpp b/src/system_transform.cpp index 9a93928..2eff919 100644 --- a/src/system_transform.cpp +++ b/src/system_transform.cpp @@ -9,12 +9,12 @@ namespace engine { TransformSystem::TransformSystem(Scene* scene) : System(scene, {typeid(TransformComponent).hash_code()}) {} -void TransformSystem::OnUpdate(float ts) +void TransformSystem::onUpdate(float ts) { (void)ts; - for (Entity entity : entities_) { - auto t = scene_->GetComponent(entity); + for (Entity entity : m_entities) { + auto t = m_scene->GetComponent(entity); glm::mat4 transform; @@ -26,7 +26,7 @@ void TransformSystem::OnUpdate(float ts) transform = glm::scale(transform, t->scale); if (t->parent != 0) { - auto parent_t = scene_->GetComponent(t->parent); + auto parent_t = m_scene->GetComponent(t->parent); transform = parent_t->world_matrix * transform; // (debug builds only) ensure static objects have static parents @@ -39,8 +39,8 @@ void TransformSystem::OnUpdate(float ts) Entity TransformSystem::GetChildEntity(Entity parent, const std::string& tag) { - for (Entity entity : entities_) { - auto t = scene_->GetComponent(entity); + for (Entity entity : m_entities) { + auto t = m_scene->GetComponent(entity); if (t->parent == parent) { if (t->tag == tag) { return entity; diff --git a/test/src/camera_controller.cpp b/test/src/camera_controller.cpp index 7e9adc0..afe9314 100644 --- a/test/src/camera_controller.cpp +++ b/test/src/camera_controller.cpp @@ -1,32 +1,34 @@ #include "camera_controller.hpp" +#define GLM_ENABLE_EXPERIMENTAL #include #include #include #include #include "application.h" +#include "component_mesh.h" #include "component_transform.h" #include "ecs.h" #include "input_manager.h" #include "log.h" #include "scene.h" #include "scene_manager.h" -#include "window.h" #include "system_collisions.h" -#include "component_mesh.h" +#include "system_mesh_render.h" +#include "window.h" CameraControllerSystem::CameraControllerSystem(engine::Scene* scene) : System(scene, {typeid(engine::TransformComponent).hash_code(), typeid(CameraControllerComponent).hash_code()}) { } -void CameraControllerSystem::OnUpdate(float ts) +void CameraControllerSystem::onUpdate(float ts) { if (t == nullptr || c == nullptr) { - for (engine::Entity entity : entities_) { - t = scene_->GetComponent(entity); - c = scene_->GetComponent(entity); + for (engine::Entity entity : m_entities) { + t = m_scene->GetComponent(entity); + c = m_scene->GetComponent(entity); break; } if (t == nullptr) return; @@ -35,21 +37,21 @@ void CameraControllerSystem::OnUpdate(float ts) const float dt = ts; - float dx = scene_->app()->input_manager()->GetAxis("movex") * CameraControllerComponent::kSpeedStrafe; - float dy = scene_->app()->input_manager()->GetAxis("movey") * CameraControllerComponent::kSpeedForwardBack; + float dx = m_scene->app()->getInputManager()->GetAxis("movex") * CameraControllerComponent::kSpeedStrafe; + float dy = m_scene->app()->getInputManager()->GetAxis("movey") * CameraControllerComponent::kSpeedForwardBack; - if (scene_->app()->input_manager()->GetButton("sprint")) { + if (m_scene->app()->getInputManager()->GetButton("sprint")) { dy *= CameraControllerComponent::kSprintMultiplier; } // calculate new pitch and yaw - float d_pitch = scene_->app()->input_manager()->GetAxis("looky") * -1.0f * CameraControllerComponent::kCameraSensitivity; + float d_pitch = m_scene->app()->getInputManager()->GetAxis("looky") * -1.0f * CameraControllerComponent::kCameraSensitivity; c->pitch += d_pitch; if (c->pitch <= CameraControllerComponent::kMinPitch || c->pitch >= CameraControllerComponent::kMaxPitch) { c->pitch -= d_pitch; } - c->yaw += scene_->app()->input_manager()->GetAxis("lookx") * -1.0f * CameraControllerComponent::kCameraSensitivity; + c->yaw += m_scene->app()->getInputManager()->GetAxis("lookx") * -1.0f * CameraControllerComponent::kCameraSensitivity; // update position relative to camera direction in xz plane const glm::vec3 d2x_rotated = glm::rotateZ(glm::vec3{dx, 0.0f, 0.0f}, c->yaw); @@ -63,7 +65,7 @@ void CameraControllerSystem::OnUpdate(float ts) c->vel.z += CameraControllerComponent::kGravAccel * dt; // jumping - if (scene_->app()->input_manager()->GetButtonPress("jump") && (c->grounded || c->noclip)) { + if (m_scene->app()->getInputManager()->GetButtonPress("jump") && (c->grounded || c->noclip)) { c->vel.z += CameraControllerComponent::kJumpVelocity; // m/s } @@ -86,7 +88,7 @@ void CameraControllerSystem::OnUpdate(float ts) ray.direction.x = c->vel.x; ray.direction.y = c->vel.y; // this is normalized by GetRayCast() ray.direction.z = 0.0f; - raycasts[i] = scene_->GetSystem()->GetRaycast(ray); + raycasts[i] = m_scene->GetSystem()->GetRaycast(ray); if (raycasts[i].hit && raycasts[i].distance < smallest_distance) { smallest_distance = raycasts[i].distance; @@ -119,7 +121,7 @@ void CameraControllerSystem::OnUpdate(float ts) fall_ray.origin = t->position; fall_ray.origin.z += CameraControllerComponent::kMaxStairHeight - CameraControllerComponent::kPlayerHeight; fall_ray.direction = { 0.0f, 0.0f, -1.0f }; // down - const engine::Raycast fall_raycast = scene_->GetSystem()->GetRaycast(fall_ray); + const engine::Raycast fall_raycast = m_scene->GetSystem()->GetRaycast(fall_ray); if (fall_raycast.hit) { // there is ground below player // find how far the player will move (downwards) if velocity is applied without collision const float mag_dz = fabsf(c->vel.z * dt); @@ -144,7 +146,7 @@ void CameraControllerSystem::OnUpdate(float ts) engine::Ray jump_ray{}; jump_ray.origin = t->position; jump_ray.direction = { 0.0f, 0.0f, 1.0f }; - const engine::Raycast jump_raycast = scene_->GetSystem()->GetRaycast(jump_ray); + const engine::Raycast jump_raycast = m_scene->GetSystem()->GetRaycast(jump_ray); if (jump_raycast.hit) { // find how far the player will move (upwards) if velocity is applied without collision const float mag_dz = fabsf(c->vel.z * dt); @@ -183,47 +185,47 @@ void CameraControllerSystem::OnUpdate(float ts) /* user interface inputs */ - if (scene_->app()->window()->GetKeyPress(engine::inputs::Key::K_R) || glm::length(t->position) > CameraControllerComponent::kMaxDistanceFromOrigin) { + if (m_scene->app()->getWindow()->GetKeyPress(engine::inputs::Key::K_R) || glm::length(t->position) > CameraControllerComponent::kMaxDistanceFromOrigin) { t->position = {0.0f, 0.0f, 10.0f}; c->vel = {0.0f, 0.0f, 0.0f}; c->pitch = glm::half_pi(); c->yaw = 0.0f; } - if (scene_->app()->input_manager()->GetButtonPress("fullscreen")) { - scene_->app()->window()->ToggleFullscreen(); + if (m_scene->app()->getInputManager()->GetButtonPress("fullscreen")) { + m_scene->app()->getWindow()->ToggleFullscreen(); } - if (scene_->app()->input_manager()->GetButtonPress("exit")) { - scene_->app()->window()->SetCloseFlag(); + if (m_scene->app()->getInputManager()->GetButtonPress("exit")) { + m_scene->app()->getWindow()->SetCloseFlag(); } - if (scene_->app()->window()->GetKeyPress(engine::inputs::Key::K_F)) { - scene_->app()->scene_manager()->SetActiveScene(next_scene_); + if (m_scene->app()->getWindow()->GetKeyPress(engine::inputs::Key::K_F)) { + m_scene->app()->getSceneManager()->SetActiveScene(next_scene_); } - if (scene_->app()->window()->GetKeyPress(engine::inputs::Key::K_Q)) { + if (m_scene->app()->getWindow()->GetKeyPress(engine::inputs::Key::K_Q)) { c->noclip ^= true; } - if (scene_->app()->window()->GetButtonPress(engine::inputs::MouseButton::M_LEFT)) { + if (m_scene->app()->getWindow()->GetButtonPress(engine::inputs::MouseButton::M_LEFT)) { engine::Ray ray{}; ray.origin = t->position; ray.direction = glm::vec3(glm::mat4_cast(t->rotation) * glm::vec4{0.0f, 0.0f, -1.0f, 1.0f}); - engine::Raycast cast = scene_->GetSystem()->GetRaycast(ray); + engine::Raycast cast = m_scene->GetSystem()->GetRaycast(ray); if (cast.hit) { LOG_TRACE("Distance: {} m", cast.distance); LOG_TRACE("Location: {} {} {}", cast.location.x, cast.location.y, cast.location.z); LOG_TRACE("Normal: {} {} {}", cast.normal.x, cast.normal.y, cast.normal.z); LOG_TRACE("Ray direction: {} {} {}", ray.direction.x, ray.direction.y, ray.direction.z); - LOG_TRACE("Hit Entity: {}", scene_->GetComponent(cast.hit_entity)->tag); + LOG_TRACE("Hit Entity: {}", m_scene->GetComponent(cast.hit_entity)->tag); c->perm_lines.clear(); c->perm_lines.emplace_back(ray.origin, cast.location, glm::vec3{0.0f, 0.0f, 1.0f}); - scene_->GetComponent(cast.hit_entity)->visible ^= true; - scene_->GetSystem()->RebuildStaticRenderList(); + m_scene->GetComponent(cast.hit_entity)->visible ^= true; + m_scene->GetSystem()->RebuildStaticRenderList(); } } - scene_->app()->debug_lines.insert(scene_->app()->debug_lines.end(), c->perm_lines.begin(), c->perm_lines.end()); + m_scene->app()->debug_lines.insert(m_scene->app()->debug_lines.end(), c->perm_lines.begin(), c->perm_lines.end()); } diff --git a/test/src/camera_controller.hpp b/test/src/camera_controller.hpp index de9dedc..5258ac1 100644 --- a/test/src/camera_controller.hpp +++ b/test/src/camera_controller.hpp @@ -2,8 +2,9 @@ #include -#include "component_transform.h" #include "application.h" +#include "component_transform.h" +#include "debug_line.h" #include "ecs.h" struct CameraControllerComponent { @@ -36,7 +37,7 @@ struct CameraControllerComponent { glm::vec3 vel{0.0f, 0.0f, 0.0f}; bool grounded = false; - std::vector perm_lines{}; // raycasting lines + std::vector perm_lines{}; // raycasting lines }; class CameraControllerSystem : public engine::System { @@ -44,7 +45,7 @@ class CameraControllerSystem : public engine::System { CameraControllerSystem(engine::Scene* scene); // engine::System overrides - void OnUpdate(float ts) override; + void onUpdate(float ts) override; engine::TransformComponent* t = nullptr; CameraControllerComponent* c = nullptr; diff --git a/test/src/game.cpp b/test/src/game.cpp index fa8a208..af7fc8f 100644 --- a/test/src/game.cpp +++ b/test/src/game.cpp @@ -6,8 +6,11 @@ #include "component_custom.h" #include "component_mesh.h" #include "component_transform.h" +#include "gltf_loader.h" #include "input_manager.h" +#include "log.h" #include "meshgen.hpp" +#include "renderer.h" #include "resource_font.h" #include "resource_material.h" #include "resource_texture.h" @@ -15,8 +18,6 @@ #include "scene_manager.h" #include "system_mesh_render.h" #include "system_transform.h" -#include "gltf_loader.h" -#include "log.h" #include "window.h" #include "config.h" @@ -54,10 +55,10 @@ void PlayGame(GameSettings settings) configuration.enable_frame_limiter = settings.enable_frame_limiter; engine::Application app(PROJECT_NAME, PROJECT_VERSION, graphics_settings, configuration); - app.window()->SetRelativeMouseMode(true); - ConfigureInputs(*app.input_manager()); + app.getWindow()->SetRelativeMouseMode(true); + ConfigureInputs(*app.getInputManager()); - engine::Scene* start_scene = app.scene_manager()->CreateEmptyScene(); + engine::Scene* start_scene = app.getSceneManager()->CreateEmptyScene(); { /* create camera */ engine::Entity camera = start_scene->CreateEntity("camera"); @@ -73,7 +74,7 @@ void PlayGame(GameSettings settings) start_scene->GetPosition(camera).z += 10.0f; } - engine::Scene* main_scene = app.scene_manager()->CreateEmptyScene(); + engine::Scene* main_scene = app.getSceneManager()->CreateEmptyScene(); { /* create camera */ engine::Entity camera = main_scene->CreateEntity("camera"); @@ -82,7 +83,7 @@ void PlayGame(GameSettings settings) main_scene->GetTransform(camera_child)->is_static = false; auto camren = main_scene->AddComponent(camera_child); camren->visible = false; - camren->mesh = GenSphereMesh(app.renderer()->GetDevice(), 1.0f, /*16*/32); + camren->mesh = GenSphereMesh(app.getRenderer()->GetDevice(), 1.0f, /*16*/32); camren->material = app.getResource("builtin.default"); /* as of right now, the entity with tag 'camera' is used to build the view @@ -136,7 +137,7 @@ void PlayGame(GameSettings settings) main_scene->GetTransform(cube)->is_static = false; auto cube_ren = main_scene->AddComponent(cube); cube_ren->material = app.getResource("builtin.default"); - cube_ren->mesh = GenCuboidMesh(app.renderer()->GetDevice(), 1.0f, 1.0f, 1.0f); + cube_ren->mesh = GenCuboidMesh(app.getRenderer()->GetDevice(), 1.0f, 1.0f, 1.0f); cube_ren->visible = true; auto cubeCustom = main_scene->AddComponent(cube); cubeCustom->on_init = [] {}; @@ -166,6 +167,6 @@ void PlayGame(GameSettings settings) start_scene->GetSystem()->next_scene_ = main_scene; main_scene->GetSystem()->next_scene_ = start_scene; - app.scene_manager()->SetActiveScene(main_scene); + app.getSceneManager()->SetActiveScene(main_scene); app.gameLoop(); }