diff --git a/CMakeLists.txt b/CMakeLists.txt index df64bf909786302634207b8eddb8a93a1f06920b..a190c9c9a7ef268665456beac13e7a700ceb546a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,14 +2,16 @@ cmake_minimum_required(VERSION 3.12) project(DEngine) set(CMAKE_CXX_STANDARD 17) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/") if(WIN32) - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/build") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build") endif() -file(GLOB_RECURSE SOURCE_FILES "${CMAKE_SOURCE_DIR}/src/*.cpp" "${CMAKE_SOURCE_DIR}/src/*.hpp" "${CMAKE_SOURCE_DIR}/src/*.inl") +file(GLOB_RECURSE SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/*.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/*.inl") add_executable(${PROJECT_NAME} ${SOURCE_FILES}) +target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include") + add_subdirectory(external) target_link_libraries(${PROJECT_NAME} external::external) diff --git a/CMakeSettings.json b/CMakeSettings.json deleted file mode 100644 index 01191edd6e86ba6d11e98cc0654d9248c7efb34a..0000000000000000000000000000000000000000 --- a/CMakeSettings.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "configurations": [ - { - "name": "x64-Release", - "generator": "Ninja", - "configurationType": "RelWithDebInfo", - "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", - "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", - "cmakeCommandArgs": "", - "buildCommandArgs": "-v", - "ctestCommandArgs": "", - "inheritEnvironments": [ "msvc_x64_x64" ], - "variables": [] - }, - { - "name": "x64-Debug", - "generator": "Ninja", - "configurationType": "Debug", - "buildRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\build\\${name}", - "installRoot": "${env.USERPROFILE}\\CMakeBuilds\\${workspaceHash}\\install\\${name}", - "cmakeCommandArgs": "", - "buildCommandArgs": "-v", - "ctestCommandArgs": "", - "inheritEnvironments": [ "msvc_x64_x64" ], - "variables": [] - } - ] -} \ No newline at end of file diff --git a/Data/Textures/test.ktx b/Data/DRenderer/Textures/01.ktx similarity index 100% rename from Data/Textures/test.ktx rename to Data/DRenderer/Textures/01.ktx diff --git a/Data/DRenderer/Textures/02.KTX b/Data/DRenderer/Textures/02.KTX new file mode 100644 index 0000000000000000000000000000000000000000..63f35a58ddce8caf9d9a29e6fa03576173c9e78e Binary files /dev/null and b/Data/DRenderer/Textures/02.KTX differ diff --git a/Data/DRenderer/Textures/Test file description.txt b/Data/DRenderer/Textures/Test file description.txt new file mode 100644 index 0000000000000000000000000000000000000000..ec5cb76d5daf3ca6acacdabfa1f70c3060cfdb46 --- /dev/null +++ b/Data/DRenderer/Textures/Test file description.txt @@ -0,0 +1,2 @@ +01 - Uncompressed 2D image, no mips, no layers, no cubemap +02 - BC7 RGBA compressed 2D image, mips, no layers, no cubemap \ No newline at end of file diff --git a/Data/Textures/defaultTexture.psd b/Data/DRenderer/Textures/defaultTexture.psd similarity index 100% rename from Data/Textures/defaultTexture.psd rename to Data/DRenderer/Textures/defaultTexture.psd diff --git a/Data/Textures/test2.KTX b/Data/Textures/test2.KTX deleted file mode 100644 index 01b38d5c0cc5bfca8facac67dc4e2f43f252b0aa..0000000000000000000000000000000000000000 Binary files a/Data/Textures/test2.KTX and /dev/null differ diff --git a/Data/Textures/test3.ktx b/Data/Textures/test3.ktx deleted file mode 100644 index ac7933ea6b3c3a99b310b5bbaac13524868a9ff4..0000000000000000000000000000000000000000 Binary files a/Data/Textures/test3.ktx and /dev/null differ diff --git a/external/DMath b/external/DMath index a86909a7b37084c09c867efefa59faec47686128..5c97c86c9e4b8f0a033a694c236da505478a4806 160000 --- a/external/DMath +++ b/external/DMath @@ -1 +1 @@ -Subproject commit a86909a7b37084c09c867efefa59faec47686128 +Subproject commit 5c97c86c9e4b8f0a033a694c236da505478a4806 diff --git a/external/DTex b/external/DTex index 9a0b7e18d9d774e85c8a15a7204b4da7815ba082..0cd6cbee1b47224a3b734b27f6e6197da213f5b6 160000 --- a/external/DTex +++ b/external/DTex @@ -1 +1 @@ -Subproject commit 9a0b7e18d9d774e85c8a15a7204b4da7815ba082 +Subproject commit 0cd6cbee1b47224a3b734b27f6e6197da213f5b6 diff --git a/src/Engine/AssetManager/AssetManager.hpp b/include/DEngine/AssetManager/AssetManager.hpp similarity index 92% rename from src/Engine/AssetManager/AssetManager.hpp rename to include/DEngine/AssetManager/AssetManager.hpp index bdf33bac024f8bd5eaab8249e392a9ad84c3841d..4327c222b7cafc39bb5dcb25ab2db1d3f8d1137f 100644 --- a/src/Engine/AssetManager/AssetManager.hpp +++ b/include/DEngine/AssetManager/AssetManager.hpp @@ -7,7 +7,7 @@ #include <string_view> #include <optional> -#include "../Renderer/MeshDocument.hpp" +#include "DRenderer/MeshDocument.hpp" namespace Engine { diff --git a/src/Engine/AssetManager/MeshDocument.hpp b/include/DEngine/AssetManager/MeshDocument.hpp similarity index 100% rename from src/Engine/AssetManager/MeshDocument.hpp rename to include/DEngine/AssetManager/MeshDocument.hpp diff --git a/src/Engine/AssetManager/Typedefs.hpp b/include/DEngine/AssetManager/Typedefs.hpp similarity index 100% rename from src/Engine/AssetManager/Typedefs.hpp rename to include/DEngine/AssetManager/Typedefs.hpp diff --git a/src/Engine/ComponentReference.hpp b/include/DEngine/ComponentReference.hpp similarity index 100% rename from src/Engine/ComponentReference.hpp rename to include/DEngine/ComponentReference.hpp diff --git a/src/Engine/Components/BoxCollider2D.hpp b/include/DEngine/Components/BoxCollider2D.hpp similarity index 77% rename from src/Engine/Components/BoxCollider2D.hpp rename to include/DEngine/Components/BoxCollider2D.hpp index a1df5d949e0e867657471ad817d6722f584bff92..240b6d6ba4fae7faf456255147cfd5cfdc866a8f 100644 --- a/src/Engine/Components/BoxCollider2D.hpp +++ b/include/DEngine/Components/BoxCollider2D.hpp @@ -1,7 +1,7 @@ #pragma once -#include "Components.hpp" -#include "../Enum.hpp" +#include "DEngine/Components/Components.hpp" +#include "DEngine/Enum.hpp" #include "DMath/Vector/Vector.hpp" #include "DMath/Matrix/Matrix.hpp" @@ -23,9 +23,9 @@ namespace Engine Math::Matrix2x2 GetRotationModel2D(Space space) const; Math::Matrix3x3 GetRotationModel2D_Homo(Space space) const; - Math::Vector2D position; - float rotation; - Math::Vector2D size; + Math::Vector2D position{}; + float rotation{}; + Math::Vector2D size{ 1, 1 }; }; } } \ No newline at end of file diff --git a/src/Engine/Components/Camera.hpp b/include/DEngine/Components/Camera.hpp similarity index 52% rename from src/Engine/Components/Camera.hpp rename to include/DEngine/Components/Camera.hpp index de12d6b4b7eb7aa2648ed07dceec5a5f3acc7014..f9d7d482d737073f5495096b90e01ad2fc3af0b6 100644 --- a/src/Engine/Components/Camera.hpp +++ b/include/DEngine/Components/Camera.hpp @@ -1,11 +1,11 @@ #pragma once -#include "Components.hpp" -#include "../Enum.hpp" +#include "DEngine/Components/Components.hpp" +#include "DEngine/Enum.hpp" #include "DMath/Vector/Vector.hpp" - -#include "../Renderer/Renderer.hpp" +#include "DMath/Matrix/Matrix.hpp" +#include "DMath/UnitQuaternion.hpp" namespace Engine { @@ -31,20 +31,19 @@ namespace Engine explicit Camera(SceneObject& owningObject); ~Camera(); - Math::Vector3D positionOffset; - Math::Vector3D forward; - Math::Vector3D up; - - float fov; - float orthographicWidth; - float zNear; - float zFar; - ProjectionMode projectionMode; + Math::Vector3D positionOffset{}; + Math::UnitQuaternion<> rotation{}; + float fov = defaultFovY; + float orthographicWidth = defaultOrtographicWidth; + float zNear = defaultZNear; + float zFar = defaultZFar; + ProjectionMode projectionMode = ProjectionMode::Perspective; - void LookAt(const Math::Vector3D& newTarget); + void LookAt(const Math::Vector3D& newTarget, Space space); [[nodiscard]] Math::Matrix<4, 3, float> GetModel_Reduced(Space space) const; - Renderer::CameraInfo GetRendererCameraInfo() const; + [[nodiscard]] Math::Matrix<4, 4, float> GetModel(Space space) const; + [[nodiscard]] Math::Matrix<4, 4, float> GetViewModel(Space space) const; }; } } \ No newline at end of file diff --git a/src/Engine/Components/CircleCollider.hpp b/include/DEngine/Components/CircleCollider.hpp similarity index 84% rename from src/Engine/Components/CircleCollider.hpp rename to include/DEngine/Components/CircleCollider.hpp index d2aa45e3088c4c6047f87b51b73341ccce835561..f9186cfa8e931f0463c63d49681f94bc616dcc51 100644 --- a/src/Engine/Components/CircleCollider.hpp +++ b/include/DEngine/Components/CircleCollider.hpp @@ -1,7 +1,7 @@ #pragma once -#include "Components.hpp" -#include "../Enum.hpp" +#include "DEngine/Components/Components.hpp" +#include "DEngine/Enum.hpp" #include "DMath/Vector/Vector.hpp" diff --git a/src/Engine/Components/CircleCollider2D.hpp b/include/DEngine/Components/CircleCollider2D.hpp similarity index 72% rename from src/Engine/Components/CircleCollider2D.hpp rename to include/DEngine/Components/CircleCollider2D.hpp index 05f33e616559d35ed05dbfb0d980102287b7b633..00facdaea5a859a9b63fc86db6398ea8f032c157 100644 --- a/src/Engine/Components/CircleCollider2D.hpp +++ b/include/DEngine/Components/CircleCollider2D.hpp @@ -1,7 +1,7 @@ #pragma once -#include "Components.hpp" -#include "../Enum.hpp" +#include "DEngine/Components/Components.hpp" +#include "DEngine/Enum.hpp" #include "DMath/Vector/Vector.hpp" @@ -19,8 +19,8 @@ namespace Engine Math::Matrix<3, 2> GetModel2D_Reduced(Space space) const; - Math::Vector2D positionOffset; - float radius; + Math::Vector2D positionOffset{}; + float radius{ 0.5 }; }; } } \ No newline at end of file diff --git a/src/Engine/Components/Components.hpp b/include/DEngine/Components/Components.hpp similarity index 100% rename from src/Engine/Components/Components.hpp rename to include/DEngine/Components/Components.hpp diff --git a/include/DEngine/Components/FreeLook.hpp b/include/DEngine/Components/FreeLook.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c142acb8ec5738b74cb7c5fb5a58fa2faa3bc4a1 --- /dev/null +++ b/include/DEngine/Components/FreeLook.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "DEngine/Components/ScriptBase.hpp" + +namespace Engine +{ + namespace Components + { + class FreeLook : public ScriptBase + { + public: + using ParentType = ScriptBase; + + explicit FreeLook(SceneObject& owningObject); + + protected: + void SceneStart() override; + + void Tick() override; + }; + } +} \ No newline at end of file diff --git a/src/Engine/Components/MeshRenderer.hpp b/include/DEngine/Components/MeshRenderer.hpp similarity index 85% rename from src/Engine/Components/MeshRenderer.hpp rename to include/DEngine/Components/MeshRenderer.hpp index c920a15c92051e92c4cf8b2648242f9d0b9cff56..4a699281e4682d3045e83bc7f6cd51acc94bafe1 100644 --- a/src/Engine/Components/MeshRenderer.hpp +++ b/include/DEngine/Components/MeshRenderer.hpp @@ -1,10 +1,10 @@ #pragma once -#include "Components.hpp" +#include "DEngine/Components/Components.hpp" -#include "../AssetManager/AssetManager.hpp" +#include "DEngine/AssetManager/AssetManager.hpp" -#include "../Enum.hpp" +#include "DEngine/Enum.hpp" #include "DMath/Vector/Vector.hpp" #include "DMath/UnitQuaternion.hpp" diff --git a/src/Engine/Components/PointLight.hpp b/include/DEngine/Components/PointLight.hpp similarity index 68% rename from src/Engine/Components/PointLight.hpp rename to include/DEngine/Components/PointLight.hpp index edf60781c9e4d616eb704caf3d3e96da3ecec42e..4495e75f7616046ae0fce8542f9733f89377ede1 100644 --- a/src/Engine/Components/PointLight.hpp +++ b/include/DEngine/Components/PointLight.hpp @@ -1,12 +1,12 @@ #pragma once -#include "Components.hpp" -#include "../Enum.hpp" +#include "DEngine/Components/Components.hpp" +#include "DEngine/Enum.hpp" #include "DMath/Vector/Vector.hpp" #include "DMath/Matrix/Matrix.hpp" -#include "../Utility/Color.hpp" +#include "Utility/Color.hpp" namespace Engine { @@ -20,9 +20,9 @@ namespace Engine explicit PointLight(SceneObject& owningObject); ~PointLight(); - float intensity; - Math::Vector3D color; - Math::Vector3D positionOffset; + float intensity{ 1 }; + Math::Vector3D color{ 1, 1, 1 }; + Math::Vector3D positionOffset{}; [[nodiscard]] Math::Matrix<4, 3> GetModel_Reduced(Space space) const; [[nodiscard]] Math::Matrix4x4 GetModel(Space space) const; diff --git a/src/Engine/Components/RigidBody2D.hpp b/include/DEngine/Components/RigidBody2D.hpp similarity index 76% rename from src/Engine/Components/RigidBody2D.hpp rename to include/DEngine/Components/RigidBody2D.hpp index fc93d02248898512a03b3459c78ccd68318e1ed7..de6e8bc095f73991a8f8b6204ffa0f9e93c67102 100644 --- a/src/Engine/Components/RigidBody2D.hpp +++ b/include/DEngine/Components/RigidBody2D.hpp @@ -1,6 +1,6 @@ #pragma once -#include "Components.hpp" +#include "DEngine/Components/Components.hpp" #include "DMath/Vector/Vector.hpp" @@ -19,9 +19,9 @@ namespace Engine explicit RigidBody2D(SceneObject& owningObject); ~RigidBody2D(); - Math::Vector2D position; - Math::Vector2D velocity; - float torque; + Math::Vector2D position{}; + Math::Vector2D velocity{}; + float torque{}; float GetMass() const; void SetMass(float newMass); @@ -29,7 +29,7 @@ namespace Engine void SetInverseMass(float newInverseMass); private: - float inverseMass; + float inverseMass{ 1.f }; }; } diff --git a/src/Engine/Components/ScriptBase.hpp b/include/DEngine/Components/ScriptBase.hpp similarity index 100% rename from src/Engine/Components/ScriptBase.hpp rename to include/DEngine/Components/ScriptBase.hpp diff --git a/src/Engine/Components/SpriteRenderer.hpp b/include/DEngine/Components/SpriteRenderer.hpp similarity index 67% rename from src/Engine/Components/SpriteRenderer.hpp rename to include/DEngine/Components/SpriteRenderer.hpp index 8018258280275ccb6d300aee176324ee7c260803..5308ed222e5d8b6e58d7b1c98a35df551405bace 100644 --- a/src/Engine/Components/SpriteRenderer.hpp +++ b/include/DEngine/Components/SpriteRenderer.hpp @@ -1,13 +1,13 @@ #pragma once -#include "Components.hpp" +#include "DEngine/Components/Components.hpp" -#include "../AssetManager/AssetManager.hpp" +#include "DEngine/AssetManager/AssetManager.hpp" #include "DMath/Vector/Vector.hpp" #include "DMath/Matrix/Matrix.hpp" -#include "../Enum.hpp" +#include "DEngine/Enum.hpp" namespace Engine { @@ -27,12 +27,12 @@ namespace Engine Math::Matrix<3, 2> GetModel2D_Reduced(Space space) const; Math::Matrix4x4 GetModel(Space space) const; - Math::Vector2D positionOffset; - float rotation; - Math::Vector2D scale; + Math::Vector2D positionOffset{}; + float rotation{}; + Math::Vector2D scale{ 1, 1 }; private: - AssMan::Sprite sprite; + AssMan::Sprite sprite = AssMan::Sprite::None; }; } diff --git a/src/Engine/Enum.hpp b/include/DEngine/Enum.hpp similarity index 100% rename from src/Engine/Enum.hpp rename to include/DEngine/Enum.hpp diff --git a/src/Engine/Input/InputRaw.hpp b/include/DEngine/Input/InputRaw.hpp similarity index 75% rename from src/Engine/Input/InputRaw.hpp rename to include/DEngine/Input/InputRaw.hpp index f2ad433ed0805491f5d78d18a3f868bffe99779b..47cb0ae064b2c5881e2449e024f531c07241a1dd 100644 --- a/src/Engine/Input/InputRaw.hpp +++ b/include/DEngine/Input/InputRaw.hpp @@ -1,8 +1,7 @@ #pragma once -#include "DMath/Vector/Vector.hpp" - #include <cstdint> +#include <array> namespace Engine { @@ -18,13 +17,13 @@ namespace Engine EventType GetEventType(Button input); - Math::Vector<2, int16_t> GetMouseDelta(); + std::array<int16_t, 2> GetMouseDelta(); } namespace Core { - void UpdateSingle(bool buttonValue, Input::Raw::Button button); - void UpdateMouseInfo(int16_t posX, int16_t posY, int16_t moveX, int16_t moveY); + void UpdateKey(bool buttonValue, Input::Raw::Button button); + void UpdateMouseInfo(uint16_t posX, uint16_t posY); void Initialize(); void Terminate(); void ClearValues(); diff --git a/src/Engine/Physics2D.hpp b/include/DEngine/Physics2D.hpp similarity index 100% rename from src/Engine/Physics2D.hpp rename to include/DEngine/Physics2D.hpp diff --git a/src/Engine/Scene.hpp b/include/DEngine/Scene.hpp similarity index 97% rename from src/Engine/Scene.hpp rename to include/DEngine/Scene.hpp index e534fcc8ff7fa01d558040068d5627a4fe1d21c1..1ae1bc9d7d2f306162e6f63af44b5c0f632fa3fc 100644 --- a/src/Engine/Scene.hpp +++ b/include/DEngine/Scene.hpp @@ -55,6 +55,8 @@ namespace Engine [[nodiscard]] size_t GetIndexInEngine() const; + const Time::SceneData& GetTimeData() const; + void Clear(); private: @@ -75,7 +77,7 @@ namespace Engine void Scripts_SceneStart(); void ScriptTick(); - Time::SceneData &GetTimeData(); + Time::SceneData& GetTimeData(); void RemoveSceneObject(SceneObject &owningObject); diff --git a/src/Engine/SceneObject.hpp b/include/DEngine/SceneObject.hpp similarity index 65% rename from src/Engine/SceneObject.hpp rename to include/DEngine/SceneObject.hpp index 2ac0bb67aa36288901c49023b3fcba40f23f7996..b02983d864eb5ae62eea210258ee5b0829871fe6 100644 --- a/src/Engine/SceneObject.hpp +++ b/include/DEngine/SceneObject.hpp @@ -11,9 +11,9 @@ namespace Engine } #include "Scene.hpp" -#include "Transform.hpp" #include "ComponentReference.hpp" #include "Components/Components.hpp" +#include "Enum.hpp" #include <vector> #include <functional> @@ -21,6 +21,10 @@ namespace Engine #include <typeindex> #include <type_traits> +#include "DMath/Vector/Vector.hpp" +#include "DMath/Matrix/Matrix.hpp" +#include "DMath/UnitQuaternion.hpp" + namespace Engine { void Destroy(SceneObject& sceneObject); @@ -43,11 +47,30 @@ namespace Engine template<typename T> decltype(auto) AddComponent(); - Transform transform; + template<typename T> + auto GetComponents(); + template<typename T> + auto GetComponents() const; + Math::Vector3D localPosition{}; + Math::UnitQuaternion<> localRotation{}; + Math::Vector3D localScale{ 1, 1, 1 }; + + Math::Vector3D GetPosition(Space space) const; + + Math::Matrix<4, 3> GetModel_Reduced(Space space) const; + Math::Matrix<3, 2> GetModel2D_Reduced(Space space) const; + + Math::Matrix2x2 GetRotationModel2D(Space space) const; + Math::Matrix<3, 3, float> GetRotationModel(Space space) const; + + Math::Vector<3, float> GetForwardVector(Space space) const; + Math::Vector<3, float> GetUpVector(Space space) const; + Math::Vector<3, float> GetRightVector(Space space) const; + private: std::reference_wrapper<Scene> sceneRef; - SceneObject* parent; + SceneObject* parent = nullptr; std::vector<SceneObject*> children; std::unordered_map<std::type_index, std::vector<size_t>> components; std::unordered_map<std::type_index, size_t> singletonComponents; @@ -67,7 +90,7 @@ namespace Engine } else { - using ReturnType = std::pair<std::reference_wrapper<T>, CompRef<T>>; + using ReturnType = std::pair<CompRef<T>, std::reference_wrapper<T>>; auto iterator = components.find(typeid(T)); if (iterator == components.end()) @@ -85,7 +108,7 @@ namespace Engine auto guidRefPair = scene.AddComponent<T>(*this); vector.emplace_back(guidRefPair.first); - return ReturnType{ guidRefPair.second, CompRef<T>(scene, guidRefPair.first) }; + return ReturnType{ CompRef<T>(scene, guidRefPair.first), guidRefPair.second }; } } diff --git a/src/Engine/Time/Time.hpp b/include/DEngine/Time/Time.hpp similarity index 63% rename from src/Engine/Time/Time.hpp rename to include/DEngine/Time/Time.hpp index ac75dfd85e49e0175d2a2b2f676a22e3975cf3d8..45cacc98cd1e2ccbd384ef6f80c8c0600756dc3c 100644 --- a/src/Engine/Time/Time.hpp +++ b/include/DEngine/Time/Time.hpp @@ -30,15 +30,15 @@ namespace Engine uint16_t GetFPS() const; private: - size_t tickCount; - size_t fixedTickCount; - std::chrono::high_resolution_clock::time_point startTime; - std::chrono::high_resolution_clock::time_point previousFrameEndTime; - float deltaTime; - - std::array<std::chrono::high_resolution_clock::duration, 2> fixedTickInterval; - uint8_t fixedTickIntervalBufferIndex; - bool fixedTickIntervalChanged; + size_t tickCount{}; + size_t fixedTickCount{}; + std::chrono::high_resolution_clock::time_point startTime{}; + std::chrono::high_resolution_clock::time_point previousFrameEndTime{}; + float deltaTime{}; + + std::array<std::chrono::high_resolution_clock::duration, 2> fixedTickInterval{}; + uint8_t fixedTickIntervalBufferIndex{}; + bool fixedTickIntervalChanged{}; friend Time::Core; }; diff --git a/src/Engine/Renderer/MeshDocument.hpp b/include/DRenderer/MeshDocument.hpp similarity index 100% rename from src/Engine/Renderer/MeshDocument.hpp rename to include/DRenderer/MeshDocument.hpp diff --git a/src/Engine/Renderer/OpenGL.hpp b/include/DRenderer/OpenGL.hpp similarity index 100% rename from src/Engine/Renderer/OpenGL.hpp rename to include/DRenderer/OpenGL.hpp diff --git a/src/Engine/Renderer/OpenGLCreateInfo.hpp b/include/DRenderer/OpenGLCreateInfo.hpp similarity index 100% rename from src/Engine/Renderer/OpenGLCreateInfo.hpp rename to include/DRenderer/OpenGLCreateInfo.hpp diff --git a/src/Engine/Renderer/Renderer.hpp b/include/DRenderer/Renderer.hpp similarity index 93% rename from src/Engine/Renderer/Renderer.hpp rename to include/DRenderer/Renderer.hpp index 38bdacde2a291ef9b10f601500565c9b777443ae..544927104340f3dff99002dd2ca7487388095035 100644 --- a/src/Engine/Renderer/Renderer.hpp +++ b/include/DRenderer/Renderer.hpp @@ -4,11 +4,13 @@ #include "Typedefs.hpp" #include "OpenGLCreateInfo.hpp" -#include "../Utility/ImgDim.hpp" +#include "Utility/ImgDim.hpp" #include "DMath/Vector/Vector.hpp" #include "DMath/Matrix/Matrix.hpp" +#include "DTex/DTex.hpp" + #include <memory> #include <vector> #include <map> @@ -64,7 +66,7 @@ namespace Engine { using MeshLoaderPFN = std::optional<MeshDocument>(*)(size_t); MeshLoaderPFN meshLoader = nullptr; - using TextureLoaderPFN = std::optional<TextureDocument>(*)(size_t); + using TextureLoaderPFN = std::optional<DTex::TexDoc>(*)(size_t); TextureLoaderPFN textureLoader = nullptr; }; @@ -85,14 +87,15 @@ namespace Engine std::vector<SpriteID> sprites; std::vector<MeshID> meshes; + std::vector<Math::Vector<3, float>> pointLightIntensities; Math::Vector3D ambientLight; - std::vector<Math::Vector<3, float>> pointLights; }; struct Renderer::RenderGraphTransform { std::vector<Math::Matrix<4, 4, float>> sprites; std::vector<Math::Matrix<4, 4, float>> meshes; + std::vector<Math::Vector<3, float>> pointLights; }; diff --git a/src/Engine/Renderer/RendererData.hpp b/include/DRenderer/RendererData.hpp similarity index 100% rename from src/Engine/Renderer/RendererData.hpp rename to include/DRenderer/RendererData.hpp diff --git a/src/Engine/Renderer/Setup.hpp b/include/DRenderer/Setup.hpp similarity index 77% rename from src/Engine/Renderer/Setup.hpp rename to include/DRenderer/Setup.hpp index a065681f2afa850fcfd0b8fbae4805416a925d0a..b0bd60eeec51b7b17e0ec95bdea69db092266886 100644 --- a/src/Engine/Renderer/Setup.hpp +++ b/include/DRenderer/Setup.hpp @@ -14,7 +14,7 @@ namespace Engine constexpr bool enableDebugging = true; - constexpr std::string_view assetPath = "Data/DRenderer"; + constexpr std::string_view assetPath = "Data"; } } } diff --git a/src/Engine/Renderer/Typedefs.hpp b/include/DRenderer/Typedefs.hpp similarity index 95% rename from src/Engine/Renderer/Typedefs.hpp rename to include/DRenderer/Typedefs.hpp index fd71484ef7d9889a4abc5023c185edb77941b8e2..72e113807706cf3deb7f1c106433cfa48d9a4bde 100644 --- a/src/Engine/Renderer/Typedefs.hpp +++ b/include/DRenderer/Typedefs.hpp @@ -23,8 +23,6 @@ namespace Engine struct InitInfo; class MeshDocument; - class TextureDocument; - enum class API; class Viewport; diff --git a/src/Engine/Utility/Color.hpp b/include/Utility/Color.hpp similarity index 100% rename from src/Engine/Utility/Color.hpp rename to include/Utility/Color.hpp diff --git a/src/Engine/Utility/ImgDim.hpp b/include/Utility/ImgDim.hpp similarity index 100% rename from src/Engine/Utility/ImgDim.hpp rename to include/Utility/ImgDim.hpp diff --git a/src/Engine/Utility/ObjectList.hpp b/include/Utility/ObjectList.hpp similarity index 100% rename from src/Engine/Utility/ObjectList.hpp rename to include/Utility/ObjectList.hpp diff --git a/src/Engine/Utility/Random.hpp b/include/Utility/Random.hpp similarity index 100% rename from src/Engine/Utility/Random.hpp rename to include/Utility/Random.hpp diff --git a/src/Engine/Application.cpp b/src/Engine/Application.cpp index 13507ac3afc1a0034070cc91531c3fe2565813e4..c5441bcb9f5cc7eb9884765d77a01dc62209e9c2 100644 --- a/src/Engine/Application.cpp +++ b/src/Engine/Application.cpp @@ -1,6 +1,6 @@ #include "Application.hpp" -#include "Input/InputRaw.hpp" +#include "DEngine/Input/InputRaw.hpp" #include "GLFW/glfw3.h" @@ -30,7 +30,9 @@ namespace Engine Input::Raw::Button APIKeyToButton(int32_t apiKey); - void GLFW_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); + void KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); + void MousePosCallback(GLFWwindow* window, double x, double y); + void MouseButtonCallback(GLFWwindow* window, int button, int action, int modifierBits); } } } @@ -71,7 +73,9 @@ namespace Engine glfwMakeContextCurrent(window); glfwSwapInterval(1); - glfwSetKeyCallback(window, GLFW_KeyCallback); + glfwSetKeyCallback(window, &KeyCallback); + glfwSetCursorPosCallback(window, &MousePosCallback); + glfwSetMouseButtonCallback(window, &MouseButtonCallback); data->windowHandle = window; data->windowSize = defaultWindowSize; @@ -120,13 +124,36 @@ void Engine::Application::Core::Terminate() glfwTerminate(); } -void Engine::Application::Core::GLFW_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) +void Engine::Application::Core::KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) { Input::Raw::Button button = APIKeyToButton(key); if (action == GLFW_PRESS) - Input::Core::UpdateSingle(true, button); + Input::Core::UpdateKey(true, button); else if (action == GLFW_RELEASE) - Input::Core::UpdateSingle(false, button); + Input::Core::UpdateKey(false, button); +} + +void Engine::Application::Core::MousePosCallback(GLFWwindow* window, double x, double y) +{ + Input::Core::UpdateMouseInfo(uint16_t(x), uint16_t(y)); +} + +void Engine::Application::Core::MouseButtonCallback(GLFWwindow* window, int button, int action, int modifierBits) +{ + if (button == GLFW_MOUSE_BUTTON_1) + { + if (action == GLFW_PRESS) + Input::Core::UpdateKey(true, Input::Raw::Button::LeftMouse); + else if (action == GLFW_RELEASE) + Input::Core::UpdateKey(false, Input::Raw::Button::LeftMouse); + } + else if (button == GLFW_MOUSE_BUTTON_2) + { + if (action == GLFW_PRESS) + Input::Core::UpdateKey(true, Input::Raw::Button::RightMouse); + else if (action == GLFW_RELEASE) + Input::Core::UpdateKey(false, Input::Raw::Button::RightMouse); + } } Engine::Input::Raw::Button Engine::Application::Core::APIKeyToButton(int32_t apiKey) diff --git a/src/Engine/AssManRendererConnect.cpp b/src/Engine/AssManRendererConnect.cpp index a01e693b16367a0844f4109cfac29e7f591535b5..e6ebeeb34eac12b49629d8d37e1bfff749a6d6aa 100644 --- a/src/Engine/AssManRendererConnect.cpp +++ b/src/Engine/AssManRendererConnect.cpp @@ -1,9 +1,37 @@ #include "AssManRendererConnect.hpp" -#include "AssetManager/AssetManager.hpp" +#include "DEngine/AssetManager/AssetManager.hpp" + +#include <cassert> namespace Engine { + Renderer::CameraInfo GetRendererCameraInfo(const Components::Camera& in) + { + Renderer::CameraInfo cameraInfo{}; + + cameraInfo.fovY = in.fov; + cameraInfo.orthoWidth = in.orthographicWidth; + cameraInfo.zNear = in.zNear; + cameraInfo.zFar = in.zFar; + + cameraInfo.transform = in.GetViewModel(Space::World); + + switch (in.projectionMode) + { + case Components::Camera::ProjectionMode::Perspective: + cameraInfo.projectMode = Renderer::CameraInfo::ProjectionMode::Perspective; + break; + case Components::Camera::ProjectionMode::Orthgraphic: + cameraInfo.projectMode = Renderer::CameraInfo::ProjectionMode::Orthographic; + break; + default: + assert(false && "Invalid Camera Projection Mode."); + } + + return cameraInfo; + } + std::optional<Renderer::MeshDocument> LoadMesh(size_t i) { auto path = AssMan::GetMeshPath(i); @@ -30,4 +58,17 @@ namespace Engine return std::optional<Renderer::MeshDocument>{ Renderer::MeshDocument(std::move(newInfo)) }; } + + std::optional<DTex::TexDoc> LoadTexture(size_t i) + { + auto path = AssMan::GetTexturePath(i); + if (path == "") + return {}; + + auto loadResult = DTex::LoadFromFile(path); + if (loadResult.GetResultInfo() != DTex::ResultInfo::Success) + return {}; + + return std::optional<DTex::TexDoc>{ std::move(loadResult.GetValue()) }; + } } diff --git a/src/Engine/AssManRendererConnect.hpp b/src/Engine/AssManRendererConnect.hpp index c7060cd9fdca918f8c79162f52143663f94dfe30..ffb4998867193b6db7dc51899c5fa5b6a7de4aa0 100644 --- a/src/Engine/AssManRendererConnect.hpp +++ b/src/Engine/AssManRendererConnect.hpp @@ -1,10 +1,19 @@ #pragma once -#include "AssetManager/MeshDocument.hpp" +#include "DEngine/Components/Camera.hpp" -#include "Renderer/MeshDocument.hpp" +#include "DEngine/AssetManager/MeshDocument.hpp" + +#include "DRenderer/MeshDocument.hpp" +#include "DRenderer/Renderer.hpp" + +#include "DTex/DTex.hpp" namespace Engine { + Renderer::CameraInfo GetRendererCameraInfo(const Components::Camera& in); + std::optional<Renderer::MeshDocument> LoadMesh(size_t i); + + std::optional<DTex::TexDoc> LoadTexture(size_t i); } \ No newline at end of file diff --git a/src/Engine/AssetManager/AssetManager.cpp b/src/Engine/AssetManager/AssetManager.cpp index 3795ea6ecffd2ef3a90513249b76608ff8412178..d41c5172432b993eebeb24ba66a326ba22a411f4 100644 --- a/src/Engine/AssetManager/AssetManager.cpp +++ b/src/Engine/AssetManager/AssetManager.cpp @@ -1,5 +1,5 @@ -#include "AssetManager.hpp" -#include "MeshDocument.hpp" +#include "DEngine/AssetManager/AssetManager.hpp" +#include "DEngine/AssetManager/MeshDocument.hpp" #include <cassert> #include <map> diff --git a/src/Engine/AssetManager/MeshDocument.inl b/src/Engine/AssetManager/MeshDocument.inl index 215b01406108b7d6441d6d8ec5333839c3f7934c..cc93668378afc287d5a0d99b2cb2bbef601290f1 100644 --- a/src/Engine/AssetManager/MeshDocument.inl +++ b/src/Engine/AssetManager/MeshDocument.inl @@ -1,5 +1,5 @@ #pragma once -#include "MeshDocument.hpp" +#include "DRenderer/MeshDocument.hpp" #include "fx/gltf.h" diff --git a/src/Engine/Components/BoxCollider2D.cpp b/src/Engine/Components/BoxCollider2D.cpp index 6db6eddd3e37dae717d01888bf8caf2e810a5188..4136a99b02159164e8da897bc92a35f3ee090cd8 100644 --- a/src/Engine/Components/BoxCollider2D.cpp +++ b/src/Engine/Components/BoxCollider2D.cpp @@ -1,7 +1,7 @@ -#include "BoxCollider2D.hpp" +#include "DEngine/Components/BoxCollider2D.hpp" #include "DMath/LinearTransform2D.hpp" -#include "../SceneObject.hpp" +#include "DEngine/SceneObject.hpp" #include <cassert> #include <iostream> @@ -11,10 +11,7 @@ namespace Engine namespace Components { BoxCollider2D::BoxCollider2D(SceneObject& owningObject) : - ParentType(owningObject), - size{ 1.f, 1.f }, - position{ 0, 0 }, - rotation{ 0 } + ParentType(owningObject) { } @@ -38,27 +35,25 @@ namespace Engine { const auto& scaleModel = Math::LinTran2D::Scale_Reduced(size); const auto& rotateModel = Math::LinTran2D::Rotate_Reduced<Math::AngleUnit::Degrees>(rotation); - auto localModel = Math::LinTran2D::Multiply(scaleModel, rotateModel); + auto localModel = Math::LinTran2D::Multiply_Reduced(scaleModel, rotateModel); Math::LinTran2D::AddTranslation(localModel, position); if (space == Space::Local) return localModel; else { - const auto& parentModel = GetSceneObject().transform.GetModel2D_Reduced(space); - return Math::LinTran2D::Multiply(parentModel, localModel); + const auto& parentModel = GetSceneObject().GetModel2D_Reduced(space); + return Math::LinTran2D::Multiply_Reduced(parentModel, localModel); } } Math::Matrix2x2 BoxCollider2D::GetRotationModel2D(Space space) const { - assert(space != Space::Local); - auto localModel = Math::LinTran2D::Rotate(rotation); if (space == Space::Local) return localModel; else - return GetSceneObject().transform.GetRotationModel2D(Space::World) * localModel; + return GetSceneObject().GetRotationModel2D(Space::World) * localModel; } Math::Matrix3x3 BoxCollider2D::GetRotationModel2D_Homo(Space space) const diff --git a/src/Engine/Components/Camera.cpp b/src/Engine/Components/Camera.cpp index af2e0128dac5c2f85e62782b025a8da2c38353bf..35b67b8605decbd3c7034fb1c8b44dd5d7d0d8d2 100644 --- a/src/Engine/Components/Camera.cpp +++ b/src/Engine/Components/Camera.cpp @@ -1,67 +1,84 @@ -#include "Camera.hpp" +#include "DEngine/Components/Camera.hpp" -#include "../SceneObject.hpp" +#include "DEngine/SceneObject.hpp" #include "DMath/LinearTransform3D.hpp" -#include "../Renderer/Renderer.hpp" +#include "DRenderer/Renderer.hpp" + +#include <assert.h> + +#include <iostream> namespace Engine { namespace Components { Camera::Camera(SceneObject& owningObject) : - ParentType(owningObject), - positionOffset(), - fov(defaultFovY), - forward(Math::Vector3D::Back()), - up(Math::Vector3D::Up()), - zNear(defaultZNear), - zFar(defaultZFar), - projectionMode(ProjectionMode::Perspective), - orthographicWidth(defaultOrtographicWidth) + ParentType(owningObject) { + //rotation = Math::UnitQuaternion<float>(Math::Vector3D{ 0, 1, 0 }, 180.f); } Camera::~Camera() { } - void Camera::LookAt(const Math::Vector3D& newTarget) + void Camera::LookAt(const Math::Vector3D& newTarget, Space space) { - forward = (newTarget - positionOffset).GetNormalized(); + } Math::Matrix<4, 3, float> Camera::GetModel_Reduced(Space space) const { using namespace Math::LinTran3D; - const auto& localModel = Translate_Reduced(positionOffset); + auto localModel = Rotate_Reduced(rotation); + AddTranslation(localModel, positionOffset); if (space == Space::Local) return localModel; else - return Multiply(GetSceneObject().transform.GetModel_Reduced(Space::World), localModel); + return Multiply_Reduced(GetSceneObject().GetModel_Reduced(Space::World), localModel); } - Renderer::CameraInfo Camera::GetRendererCameraInfo() const + Math::Matrix<4, 4, float> Camera::GetModel(Space space) const { - Renderer::CameraInfo cameraInfo; + return Math::LinTran3D::AsMat4(GetModel_Reduced(space)); + } + + Math::Matrix<4, 4, float> Camera::GetViewModel(Space space) const + { + using namespace Math::LinTran3D; + + auto model = Rotate_Reduced(rotation); + AddTranslation(model, positionOffset); + + // Switch invert Z and X axis + Math::Matrix<4, 3, float> testReduced{}; + for (size_t i = 0; i < 3; i++) + testReduced.At(i, i) = 1; + testReduced.At(2, 2) = -testReduced.At(2, 2); + testReduced.At(0, 0) = -testReduced.At(0, 0); + model = Multiply_Reduced(testReduced, model); + + if (space == Space::World) + model = Multiply_Reduced(GetSceneObject().GetModel_Reduced(Space::World), model); - cameraInfo.fovY = fov; - cameraInfo.orthoWidth = orthographicWidth; - cameraInfo.zNear = zNear; - cameraInfo.zFar = zFar; + auto modelMat4 = AsMat4(model); - if (projectionMode == ProjectionMode::Perspective) - cameraInfo.projectMode = Renderer::CameraInfo::ProjectionMode::Perspective; - else if (projectionMode == ProjectionMode::Orthgraphic) - cameraInfo.projectMode = Renderer::CameraInfo::ProjectionMode::Orthographic; + /* + Math::Matrix<4, 4, float> test{}; + for (size_t i = 0; i < 4; i++) + test.At(i, i) = 1; + test.At(2, 2) = -1; + modelMat4 = test * modelMat4; + */ - cameraInfo.transform = Math::LinTran3D::LookAt_RH(positionOffset, positionOffset + forward, up); - auto test = GetModel_Reduced(Space::World); - cameraInfo.worldSpacePos = Math::LinTran3D::GetTranslation(test); + auto inverseOpt = modelMat4.GetInverse(); + assert(inverseOpt.has_value() && "Error. Couldn't find inverse matrix of camera."); + auto inverse = inverseOpt.value(); - return cameraInfo; + return inverse; } } } diff --git a/src/Engine/Components/CircleCollider.cpp b/src/Engine/Components/CircleCollider.cpp index ec4a4e64b95bd8f7741febc8e0066a45effd1bac..5943bd76b0af3b728f357ef505e03f3fef2224cd 100644 --- a/src/Engine/Components/CircleCollider.cpp +++ b/src/Engine/Components/CircleCollider.cpp @@ -1,4 +1,4 @@ -#include "CircleCollider.hpp" +#include "DEngine/Components/CircleCollider.hpp" namespace Engine { diff --git a/src/Engine/Components/CircleCollider2D.cpp b/src/Engine/Components/CircleCollider2D.cpp index bf71334dbf9a55e58853696ae5d571e41908289d..5dc0a90a8ed3a0431a7a5ca9379454ab18a2ef2a 100644 --- a/src/Engine/Components/CircleCollider2D.cpp +++ b/src/Engine/Components/CircleCollider2D.cpp @@ -1,18 +1,16 @@ -#include "CircleCollider2D.hpp" +#include "DEngine/Components/CircleCollider2D.hpp" #include "DMath/LinearTransform2D.hpp" -#include "../Scene.hpp" -#include "../SceneObject.hpp" +#include "DEngine/Scene.hpp" +#include "DEngine/SceneObject.hpp" namespace Engine { namespace Components { CircleCollider2D::CircleCollider2D(SceneObject& owningObject) : - ParentType(owningObject), - radius(0.5f), - positionOffset{ 0, 0 } + ParentType(owningObject) { } @@ -27,8 +25,8 @@ namespace Engine return localModel; else { - const auto& worldSpaceModel = GetSceneObject().transform.GetModel2D_Reduced(Space::World); - return Math::LinTran2D::Multiply(worldSpaceModel, localModel); + const auto& worldSpaceModel = GetSceneObject().GetModel2D_Reduced(Space::World); + return Math::LinTran2D::Multiply_Reduced(worldSpaceModel, localModel); } } } diff --git a/src/Engine/Components/Components.cpp b/src/Engine/Components/Components.cpp index 6cb09010b3b0e49dc1d4e0ef7380b28c44e6cd87..a923776eace190830ab23549fbfd093c019e8b04 100644 --- a/src/Engine/Components/Components.cpp +++ b/src/Engine/Components/Components.cpp @@ -1,4 +1,4 @@ -#include "Components.hpp" +#include "DEngine/Components/Components.hpp" namespace Engine { diff --git a/src/Engine/Components/FreeLook.cpp b/src/Engine/Components/FreeLook.cpp new file mode 100644 index 0000000000000000000000000000000000000000..13cbb103a849c9343b108a58a658a0562a60cd92 --- /dev/null +++ b/src/Engine/Components/FreeLook.cpp @@ -0,0 +1,85 @@ +#include "DEngine/Components/FreeLook.hpp" + +#include "DMath/Vector/Vector.hpp" + +#include "DEngine/Input/InputRaw.hpp" + +#include "DEngine/SceneObject.hpp" +#include "DEngine/Scene.hpp" + +#include <iostream> + +namespace Engine +{ + namespace Components + { + FreeLook::FreeLook(SceneObject& owningObject) : + ParentType(owningObject) + { + + } + + void FreeLook::SceneStart() + { + ParentType::SceneStart(); + } + + void FreeLook::Tick() + { + ParentType::Tick(); + + SceneObject& obj = GetSceneObject(); + const Scene& scene = obj.GetScene(); + float deltaTime = scene.GetTimeData().GetDeltaTime(); + + if (Input::Raw::GetValue(Input::Raw::Button::RightMouse)) + { + float sensitivity = 15; + + float amountX = Input::Raw::GetMouseDelta()[0]; + + obj.localRotation = Math::UnitQuaternion<float>(Math::Vector3D{ 0, -sensitivity * deltaTime * amountX, 0 }) * obj.localRotation; + + auto amountY = -Input::Raw::GetMouseDelta()[1]; + + Math::Vector3D forward = GetSceneObject().GetForwardVector(Space::Local); + float dot = Math::Vector3D::Dot(forward, Math::Vector3D::Up()); + if (dot <= -0.99f) + amountY = Math::Max(0, amountY); + else if (dot >= 0.99f) + amountY = Math::Min(0, amountY); + + Math::Vector3D right = GetSceneObject().GetRightVector(Space::Local); + + obj.localRotation = Math::UnitQuaternion<float>(right, sensitivity * deltaTime * -amountY) * obj.localRotation; + } + + auto mat = GetSceneObject().GetRotationModel(Space::Local); + + Math::Vector3D right{ mat[0][0], mat[0][1], mat[0][2] }; + Math::Vector3D up{ mat[1][0], mat[1][1], mat[1][2] }; + Math::Vector3D forward{ mat[2][0], mat[2][1], mat[2][2] }; + + + + + + + // Handles origin movement for camera + constexpr float speed = 5.f; + + if (Input::Raw::GetValue(Input::Raw::Button::A)) + obj.localPosition += right * speed * deltaTime; + if (Input::Raw::GetValue(Input::Raw::Button::D)) + obj.localPosition -= right * speed * deltaTime; + if (Input::Raw::GetValue(Input::Raw::Button::W)) + obj.localPosition += forward * speed * deltaTime; + if (Input::Raw::GetValue(Input::Raw::Button::S)) + obj.localPosition -= forward * speed * deltaTime; + if (Input::Raw::GetValue(Input::Raw::Button::Space)) + obj.localPosition += Math::Vector3D::Up() * speed * deltaTime; + if (Input::Raw::GetValue(Input::Raw::Button::LeftCtrl)) + obj.localPosition += Math::Vector3D::Down() * speed * deltaTime; + } + } +} \ No newline at end of file diff --git a/src/Engine/Components/MeshRenderer.cpp b/src/Engine/Components/MeshRenderer.cpp index 30b6cbd23cfcb00dad11ea4a5bb96a78be573ec6..2429645748f97456a1d999af7adde88c677fcb2c 100644 --- a/src/Engine/Components/MeshRenderer.cpp +++ b/src/Engine/Components/MeshRenderer.cpp @@ -1,15 +1,15 @@ -#include "MeshRenderer.hpp" +#include "DEngine/Components/MeshRenderer.hpp" #include <vector> #include <string> #include <cassert> -#include "../Renderer/Renderer.hpp" +#include "DRenderer/Renderer.hpp" #include "DMath/LinearTransform3D.hpp" -#include "../Scene.hpp" -#include "../SceneObject.hpp" +#include "DEngine/Scene.hpp" +#include "DEngine/SceneObject.hpp" namespace Engine { @@ -43,13 +43,13 @@ namespace Engine Math::Matrix<4, 3> MeshRenderer::GetModel_Reduced(Space space) const { using namespace Math::LinTran3D; - Math::Matrix<4, 3> localModel = Multiply(Scale_Reduced(scale), Rotate_Reduced(rotation)); + Math::Matrix<4, 3> localModel = Multiply_Reduced(Scale_Reduced(scale), Rotate_Reduced(rotation)); AddTranslation(localModel, positionOffset); if (space == Space::Local) return localModel; else - return Multiply(GetSceneObject().transform.GetModel_Reduced(Space::World), localModel); + return Multiply_Reduced(GetSceneObject().GetModel_Reduced(Space::World), localModel); } Math::Matrix4x4 MeshRenderer::GetModel(Space space) const diff --git a/src/Engine/Components/PointLight.cpp b/src/Engine/Components/PointLight.cpp index 9f420038dc9897fbc96ee3cb1286a55ebc3a9fde..31630598d6a7979ed3ff64abb5a07965ad235174 100644 --- a/src/Engine/Components/PointLight.cpp +++ b/src/Engine/Components/PointLight.cpp @@ -1,6 +1,6 @@ -#include "PointLight.hpp" +#include "DEngine/Components/PointLight.hpp" -#include "../SceneObject.hpp" +#include "DEngine/SceneObject.hpp" #include "DMath/LinearTransform3D.hpp" @@ -9,10 +9,7 @@ namespace Engine namespace Components { PointLight::PointLight(SceneObject& owningObject) : - ParentType(owningObject), - positionOffset(), - intensity(1), - color{1.f, 1.f, 1.f} + ParentType(owningObject) { } @@ -28,7 +25,7 @@ namespace Engine if (space == Space::Local) return localModel; else - return Multiply(GetSceneObject().transform.GetModel_Reduced(Space::World), localModel); + return Multiply_Reduced(GetSceneObject().GetModel_Reduced(Space::World), localModel); } Math::Matrix4x4 PointLight::GetModel(Space space) const diff --git a/src/Engine/Components/RigidBody2D.cpp b/src/Engine/Components/RigidBody2D.cpp index da0919bea6882a9683615a3df539b15184cc8307..23b05fd2cd23b50e77b34ebcbd93e3b8031d4c59 100644 --- a/src/Engine/Components/RigidBody2D.cpp +++ b/src/Engine/Components/RigidBody2D.cpp @@ -1,19 +1,15 @@ -#include "RigidBody2D.hpp" +#include "DEngine/Components/RigidBody2D.hpp" -#include "../Scene.hpp" -#include "../SceneObject.hpp" +#include "DEngine/SceneObject.hpp" namespace Engine { namespace Components { RigidBody2D::RigidBody2D(SceneObject& owningObject) : - ParentType(owningObject), - velocity(), - inverseMass(1.f), - torque() + ParentType(owningObject) { - position = owningObject.transform.GetPosition(Space::World).AsVec2(); + position = owningObject.GetPosition(Space::World).AsVec2(); } RigidBody2D::~RigidBody2D() diff --git a/src/Engine/Components/ScriptBase.cpp b/src/Engine/Components/ScriptBase.cpp index caefdc9e36b57f449823ce040aa2d24bd7e5788f..9134c582d42de45bf16a963af39cfea27af8805e 100644 --- a/src/Engine/Components/ScriptBase.cpp +++ b/src/Engine/Components/ScriptBase.cpp @@ -1,4 +1,4 @@ -#include "ScriptBase.hpp" +#include "DEngine/Components/ScriptBase.hpp" namespace Engine { diff --git a/src/Engine/Components/SpriteRenderer.cpp b/src/Engine/Components/SpriteRenderer.cpp index e13eb3c6aa629a08b33cfb829c0cd3fc96f2193f..ef423767b6a96c4472693993242832a62a2473bf 100644 --- a/src/Engine/Components/SpriteRenderer.cpp +++ b/src/Engine/Components/SpriteRenderer.cpp @@ -1,10 +1,10 @@ -#include "SpriteRenderer.hpp" +#include "DEngine/Components/SpriteRenderer.hpp" #include <array> #include <cassert> -#include "../Scene.hpp" -#include "../SceneObject.hpp" +#include "DEngine/Scene.hpp" +#include "DEngine/SceneObject.hpp" #include "DMath/LinearTransform2D.hpp" @@ -13,11 +13,7 @@ namespace Engine namespace Components { SpriteRenderer::SpriteRenderer(SceneObject& owningObject) : - ParentType(owningObject), - sprite(AssMan::Sprite::None), - positionOffset{ 0, 0 }, - rotation(0), - scale{ 1, 1 } + ParentType(owningObject) { } @@ -41,15 +37,15 @@ namespace Engine const auto& scaleModel = Scale_Reduced(scale); const auto& rotateModel = Rotate_Reduced(rotation); - auto localModel = Multiply(scaleModel, rotateModel); + auto localModel = Multiply_Reduced(scaleModel, rotateModel); AddTranslation(localModel, positionOffset); if (space == Space::Local) return localModel; else { - auto parentModel = GetSceneObject().transform.GetModel2D_Reduced(space); - return Multiply(parentModel, localModel); + auto parentModel = GetSceneObject().GetModel2D_Reduced(space); + return Multiply_Reduced(parentModel, localModel); } } diff --git a/src/Engine/Engine.cpp b/src/Engine/Engine.cpp index d613028c63212708726193c0037e1d69ead83fbb..cd9897ffd6731b293805949ef635588953cdd175 100644 --- a/src/Engine/Engine.cpp +++ b/src/Engine/Engine.cpp @@ -1,16 +1,18 @@ #include "Engine.hpp" #include "Application.hpp" -#include "Renderer/Renderer.hpp" -#include "Components/SpriteRenderer.hpp" -#include "Components/MeshRenderer.hpp" -#include "Components/PointLight.hpp" -#include "Time/Time.hpp" -#include "Input/InputRaw.hpp" -#include "Scene.hpp" -#include "SceneObject.hpp" +#include "DEngine/Time/Time.hpp" +#include "DEngine/Input/InputRaw.hpp" +#include "DRenderer/Renderer.hpp" -#include "Components/Camera.hpp" +#include "DEngine/Scene.hpp" +#include "DEngine/SceneObject.hpp" + +#include "DEngine/Components/Camera.hpp" +#include "DEngine/Components/FreeLook.hpp" +#include "DEngine/Components/SpriteRenderer.hpp" +#include "DEngine/Components/MeshRenderer.hpp" +#include "DEngine/Components/PointLight.hpp" #include "Systems/RenderSystem.hpp" @@ -42,7 +44,7 @@ namespace Engine rendererInitInfo.surfaceHandle = Application::Core::GetMainWindowHandle(); rendererInitInfo.assetLoadCreateInfo.meshLoader = &LoadMesh; - //rendererInitInfo.assetLoadCreateInfo.textureLoader = &LoadTexture; + rendererInitInfo.assetLoadCreateInfo.textureLoader = &LoadTexture; rendererInitInfo.openGLInitInfo.glSwapBuffers = &Application::Core::GL_SwapWindow; Renderer::Core::Initialize(rendererInitInfo); @@ -54,7 +56,6 @@ void Engine::Core::Run() Application::Core::Initialize(Application::API3D::OpenGL); Time::Core::Initialize(); Input::Core::Initialize(); - Physics2D::Core::Initialize(); InitializeRenderer(); @@ -64,36 +65,37 @@ void Engine::Core::Run() Renderer::GetViewport(0).SetSceneRef(&scene1); - + auto& objCamera = scene1.NewSceneObject(); + objCamera.localPosition.z = -5.f; + auto& camera = objCamera.AddComponent<Components::Camera>().second.get(); + objCamera.AddComponent<Components::FreeLook>(); auto& sceneObject1 = scene1.NewSceneObject(); - auto& mesh1 = sceneObject1.AddComponent<Components::MeshRenderer>().first.get(); + auto& mesh1 = sceneObject1.AddComponent<Components::MeshRenderer>().second.get(); mesh1.SetMesh(AssMan::Mesh::Helmet); - auto& meshTest = sceneObject1.AddComponent<Components::MeshRenderer>().first.get(); + auto& meshTest = sceneObject1.AddComponent<Components::MeshRenderer>().second.get(); meshTest.SetMesh(AssMan::Mesh::Helmet); meshTest.positionOffset.x = -3.f; - auto& mesh2 = sceneObject1.AddComponent<Components::MeshRenderer>().first.get(); + auto& mesh2 = sceneObject1.AddComponent<Components::MeshRenderer>().second.get(); mesh2.SetMesh(AssMan::Mesh::Cube); mesh2.positionOffset.x = 2.f; - auto& objCamera = scene1.NewSceneObject(); - auto& camera = objCamera.AddComponent<Components::Camera>().first.get(); - camera.positionOffset.z = 5.f; + auto& lightObj = scene1.NewSceneObject(); - lightObj.transform.localPosition = { 2.5f, 2.5f, 2.5f }; - Components::PointLight& light1 = lightObj.AddComponent<Components::PointLight>().first.get(); + lightObj.localPosition = { 2.5f, 2.5f, 2.5f }; + Components::PointLight& light1 = lightObj.AddComponent<Components::PointLight>().second.get(); light1.color = { 1.f, 1.f, 1.f }; - auto& mesh3 = lightObj.AddComponent<Components::MeshRenderer>().first.get(); + auto& mesh3 = lightObj.AddComponent<Components::MeshRenderer>().second.get(); mesh3.SetMesh(AssMan::Mesh::Cube); mesh3.scale = { 0.1f, 0.1f, 0.1f }; auto& obj4 = scene1.NewSceneObject(); - obj4.transform.localPosition = { 0.f, -7.5f, -10.f }; - Components::PointLight& light3 = obj4.AddComponent<Components::PointLight>().first.get(); - auto& mesh4 = obj4.AddComponent<Components::MeshRenderer>().first.get(); + obj4.localPosition = { 0.f, -7.5f, -10.f }; + Components::PointLight& light3 = obj4.AddComponent<Components::PointLight>().second.get(); + auto& mesh4 = obj4.AddComponent<Components::MeshRenderer>().second.get(); mesh4.SetMesh(AssMan::Mesh::Cube); mesh4.scale = { 0.1f, 0.1f, 0.1f }; @@ -105,52 +107,20 @@ void Engine::Core::Run() scene1.Scripts_SceneStart(); while (Application::Core::UpdateEvents(), Application::IsRunning()) { - // Handles origin movement for camera - const float speed = 5.f; - auto cross = Math::Vector3D::Cross(camera.forward, camera.up); - if (Input::Raw::GetValue(Input::Raw::Button::A)) - camera.positionOffset -= cross * speed * scene1.GetTimeData().GetDeltaTime(); - if (Input::Raw::GetValue(Input::Raw::Button::D)) - camera.positionOffset += cross * speed * scene1.GetTimeData().GetDeltaTime(); - if (Input::Raw::GetValue(Input::Raw::Button::W)) - camera.positionOffset += camera.forward * speed * scene1.GetTimeData().GetDeltaTime(); - if (Input::Raw::GetValue(Input::Raw::Button::S)) - camera.positionOffset -= camera.forward * speed * scene1.GetTimeData().GetDeltaTime(); - if (Input::Raw::GetValue(Input::Raw::Button::Space)) - camera.positionOffset += Math::Vector3D::Up() * speed * scene1.GetTimeData().GetDeltaTime(); - if (Input::Raw::GetValue(Input::Raw::Button::LeftCtrl)) - camera.positionOffset += Math::Vector3D::Down() * speed * scene1.GetTimeData().GetDeltaTime(); - camera.LookAt({ -1.f, 0, 0 }); - - if (Input::Raw::GetValue(Input::Raw::Button::Up)) - lightObj.transform.localPosition.z -= speed * scene1.GetTimeData().GetDeltaTime(); - if (Input::Raw::GetValue(Input::Raw::Button::Down)) - lightObj.transform.localPosition.z += speed * scene1.GetTimeData().GetDeltaTime(); - if (Input::Raw::GetValue(Input::Raw::Button::Left)) - lightObj.transform.localPosition.x -= speed * scene1.GetTimeData().GetDeltaTime(); - if (Input::Raw::GetValue(Input::Raw::Button::Right)) - lightObj.transform.localPosition.x += speed * scene1.GetTimeData().GetDeltaTime(); - - if (Input::Raw::GetEventType(Input::Raw::Button::C) == Input::EventType::Pressed) - { - scene1.Clear(); - } - - scene1.ScriptTick(); RenderSystem::BuildRenderGraph(scene1, graph); Renderer::Core::PrepareRenderingEarly(graph); - Renderer::Core::SetCameraInfo(camera.GetRendererCameraInfo()); + Renderer::Core::SetCameraInfo(GetRendererCameraInfo(camera)); RenderSystem::BuildRenderGraphTransform(scene1, graphTransform); Renderer::Core::PrepareRenderingLate(graphTransform); Renderer::Core::Draw(); - + Input::Core::ClearValues(); Time::Core::TickEnd(scene1.GetTimeData()); } diff --git a/src/Engine/Input/InputRaw.cpp b/src/Engine/Input/InputRaw.cpp index 42350f66fc42dca3585f00ccdf41d1eb7684186b..ca31c8f4d472f5dc32db2a5dc1b8e2bcaaa65fba 100644 --- a/src/Engine/Input/InputRaw.cpp +++ b/src/Engine/Input/InputRaw.cpp @@ -1,6 +1,5 @@ #define INPUT_BUTTON_COUNT -#include "InputRaw.hpp" -#include "DMath/Vector/Vector.hpp" +#include "DEngine/Input/InputRaw.hpp" #include <array> #include <memory> @@ -13,11 +12,11 @@ namespace Engine { struct Data { - std::array<bool, static_cast<size_t>(Input::Raw::Button::COUNT)> buttonValues; - std::array<Input::EventType, static_cast<size_t>(Input::Raw::Button::COUNT)> eventTypes; + std::array<bool, static_cast<size_t>(Input::Raw::Button::COUNT)> buttonValues{}; + std::array<Input::EventType, static_cast<size_t>(Input::Raw::Button::COUNT)> eventTypes{}; - Math::Vector<2, int16_t> mousePosition; - Math::Vector<2, int16_t> mouseDelta; + std::array<uint16_t, 2> mousePosition{}; + std::array<int16_t, 2> mouseDelta{}; }; static std::unique_ptr<Data> data; @@ -33,19 +32,19 @@ bool Engine::Input::Raw::GetValue(Button input) { return Core::data->buttonValue Engine::Input::EventType Engine::Input::Raw::GetEventType(Button input) { return Core::data->eventTypes[static_cast<size_t>(input)]; } -Math::Vector<2, int16_t> Engine::Input::Raw::GetMouseDelta() { return Core::data->mouseDelta; } +std::array<int16_t, 2> Engine::Input::Raw::GetMouseDelta() { return Core::data->mouseDelta; } -void Engine::Input::Core::UpdateSingle(bool buttonValue, Raw::Button button) +void Engine::Input::Core::UpdateKey(bool buttonValue, Raw::Button button) { - size_t index = static_cast<size_t>(button); + size_t index = size_t(button); data->buttonValues[index] = buttonValue; data->eventTypes[index] = ToEventType(buttonValue); } -void Engine::Input::Core::UpdateMouseInfo(int16_t posX, int16_t posY, int16_t moveX, int16_t moveY) +void Engine::Input::Core::UpdateMouseInfo(uint16_t posX, uint16_t posY) { + data->mouseDelta = { int16_t(posX) - int16_t(data->mousePosition[0]), int16_t(posY) - int16_t(data->mousePosition[1]) }; data->mousePosition = { posX, posY }; - data->mouseDelta = { moveX, moveY }; } void Engine::Input::Core::Initialize() diff --git a/src/Engine/Physics2D.cpp b/src/Engine/Physics2D.cpp index 3189c4144896bb088fa28ea2123e00468aeab527..ab67bf795c211a308a92b4038bc61bef58cd68cc 100644 --- a/src/Engine/Physics2D.cpp +++ b/src/Engine/Physics2D.cpp @@ -1,11 +1,11 @@ -#include "Physics2D.hpp" - -#include "Scene.hpp" -#include "SceneObject.hpp" -#include "Components/CircleCollider2D.hpp" -#include "Components/BoxCollider2D.hpp" -#include "Components/RigidBody2D.hpp" -#include "Time/Time.hpp" +#include "DEngine/Physics2D.hpp" + +#include "DEngine/Scene.hpp" +#include "DEngine/SceneObject.hpp" +#include "DEngine/Components/CircleCollider2D.hpp" +#include "DEngine/Components/BoxCollider2D.hpp" +#include "DEngine/Components/RigidBody2D.hpp" +#include "DEngine/Time/Time.hpp" #include "DMath/LinearTransform2D.hpp" diff --git a/src/Engine/Renderer/MeshDocument.inl b/src/Engine/Renderer/MeshDocument.inl index 8e49aa2f217b060c59a7ff486ae44201e39a8b01..5e7f8009fa10b22275a405be54b3914a1bf3213f 100644 --- a/src/Engine/Renderer/MeshDocument.inl +++ b/src/Engine/Renderer/MeshDocument.inl @@ -1,6 +1,6 @@ #pragma once -#include "MeshDocument.hpp" +#include "DRenderer/MeshDocument.hpp" namespace Engine { diff --git a/src/Engine/Renderer/OpenGL.cpp b/src/Engine/Renderer/OpenGL.cpp index 945f90bd46d9c896655bf3339dfbc0f484a90fa0..0553534aa825667fc0edb04bc1b9f4839168eb7f 100644 --- a/src/Engine/Renderer/OpenGL.cpp +++ b/src/Engine/Renderer/OpenGL.cpp @@ -1,13 +1,12 @@ -#include "Renderer.hpp" -#include "RendererData.hpp" -#include "MeshDocument.hpp" -#include "OpenGL.hpp" - -#define DTEX_IMPLEMENTATION -#include "DTex/DTex.hpp" +#include "DRenderer/Renderer.hpp" +#include "DRenderer/RendererData.hpp" +#include "DRenderer/MeshDocument.hpp" +#include "DRenderer/OpenGL.hpp" #include "GL/glew.h" +#include "DTex/DTex.hpp" + #include <cassert> #include <memory> #include <unordered_map> @@ -34,7 +33,7 @@ namespace Engine void UpdateVBODatabase(Data& data, const std::vector<MeshID>& loadQueue); void UpdateIBODatabase(Data& data, const std::vector<SpriteID>& loadQueue); std::optional<VBO> GetVBOFromID(size_t id); - std::optional<IBO> GetIBOFromID(size_t id); + std::optional<IBO> GetIBOFromTexDoc(const DTex::TexDoc& input); Data& GetAPIData(); @@ -317,7 +316,10 @@ namespace Engine //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - data.testIBO = GetIBOFromID(2).value(); + // Load default texture + auto loadResult = DTex::LoadFromFile(std::string{ Setup::assetPath } +"/DRenderer/Textures/02.ktx"); + assert(loadResult.GetResultInfo() == DTex::ResultInfo::Success && "Couldn't load the default texture for DRenderer."); + data.testIBO = GetIBOFromTexDoc(loadResult.GetValue()).value(); //LoadSpriteShader(data); @@ -356,15 +358,15 @@ namespace Engine glNamedBufferSubData(data.lightDataUBO, ambientLightOffset, sizeof(renderGraph.ambientLight), renderGraph.ambientLight.Data()); // Update light count - auto pointLightCount = static_cast<uint32_t>(renderGraph.pointLights.size()); + auto pointLightCount = static_cast<uint32_t>(renderGraph.pointLightIntensities.size()); constexpr GLintptr pointLightCountDataOffset = offsetof(LightDataUBO, LightDataUBO::pointLightCount); glNamedBufferSubData(data.lightDataUBO, pointLightCountDataOffset, sizeof(pointLightCount), &pointLightCount); // Update intensities - const size_t elements = Math::Min(10, renderGraph.pointLights.size()); + const size_t elements = Math::Min(10, renderGraph.pointLightIntensities.size()); std::array<Math::Vector4D, 10> intensityData; for (size_t i = 0; i < elements; i++) - intensityData[i] = renderGraph.pointLights[i].AsVec4(); + intensityData[i] = renderGraph.pointLightIntensities[i].AsVec4(); size_t byteLength = sizeof(Math::Vector4D) * elements; constexpr GLintptr pointLightIntensityOffset = offsetof(LightDataUBO, LightDataUBO::pointLightIntensity); glNamedBufferSubData(data.lightDataUBO, pointLightIntensityOffset, byteLength, intensityData.data()); @@ -489,51 +491,59 @@ namespace Engine void Renderer::OpenGL::UpdateIBODatabase(Data& data, const std::vector<SpriteID>& loadQueue) { - glActiveTexture(GL_TEXTURE0); + //glActiveTexture(GL_TEXTURE0); + for (const auto& id : loadQueue) { - auto iboOpt = GetIBOFromID(static_cast<size_t>(id)); - assert(iboOpt.has_value()); + auto texDocOpt = Core::GetData().assetLoadData.textureLoader(size_t(id)); + if (!texDocOpt.has_value()) + continue; + + auto& texDoc = texDocOpt.value(); + + auto iboOpt = GetIBOFromTexDoc(texDoc); + if (!iboOpt.has_value()) + continue; data.iboDatabase.insert({ id, iboOpt.value() }); } } - std::optional<Renderer::OpenGL::IBO> Renderer::OpenGL::GetIBOFromID(size_t id) + std::optional<Renderer::OpenGL::IBO> Renderer::OpenGL::GetIBOFromTexDoc(const DTex::TexDoc& input) { - //auto texDocumentOpt = Core::GetData().assetLoadData.textureLoader(id); - //assert(texDocumentOpt.has_value()); - - auto texDocOpt = DTex::LoadFromFile("Data/Textures/test.ktx"); - auto& texDoc = texDocOpt.value(); - IBO ibo; - glGenTextures(1, &ibo.texture); + GLenum target = DTex::ToGLTarget(input.GetTextureType()); + GLint format = DTex::ToGLFormat(input.GetPixelFormat()); + GLenum type = DTex::ToGLType(input.GetPixelFormat()); + if (target == 0 || format == 0) + { + LogDebugMessage("Error. Texture can not be used in OpenGL."); + return {}; + } - GLenum target = texDoc.GetGLTarget(); + glGenTextures(1, &ibo.texture); glBindTexture(target, ibo.texture); - - GLint format = texDoc.GetGLFormat(); - GLenum type = texDoc.GetGLType(); - - for (size_t level = 0; level < texDoc.GetMipLevels(); level++) + for (GLint level = 0; level < GLint(input.GetMipLevels()); level++) { - GLsizei width = texDoc.GetDimensions(level)[0]; - GLsizei height = texDoc.GetDimensions(level)[1]; - auto data = texDoc.GetData(level); - GLsizei dataLength = texDoc.GetByteLength(level); + GLsizei width = GLsizei(input.GetDimensions(level).width); + GLsizei height = GLsizei(input.GetDimensions(level).height); + auto data = input.GetData(level); + GLsizei dataLength = input.GetDataSize(level); - if (texDoc.IsCompressed()) + if (input.IsCompressed()) glCompressedTexImage2D(target, level, format, width, height, 0, dataLength, data); else glTexImage2D(target, level, format, width, height, 0, format, type, data); } - glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0); - glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, texDoc.GetMipLevels() - 1); + if (input.GetMipLevels() > 1) + { + glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, input.GetMipLevels() - 1); + } return ibo; } diff --git a/src/Engine/Renderer/Renderer.cpp b/src/Engine/Renderer/Renderer.cpp index 849109634254744d36b8f2c514a0fe88097f45f3..1869b15d2c50274c60bdaf86da0295f5d2012663 100644 --- a/src/Engine/Renderer/Renderer.cpp +++ b/src/Engine/Renderer/Renderer.cpp @@ -1,7 +1,7 @@ -#include "Renderer.hpp" -#include "RendererData.hpp" +#include "DRenderer/Renderer.hpp" +#include "DRenderer/RendererData.hpp" -#include "OpenGL.hpp" +#include "DRenderer/OpenGL.hpp" #include "DMath/LinearTransform3D.hpp" @@ -48,6 +48,13 @@ namespace Engine return false; } + // Asset load stuff + if (createInfo.assetLoadCreateInfo.textureLoader == nullptr) + { + DebugMessage("Error. TextureLoader pointer in initialization cannot be nullptr."); + return false; + } + // Debug stuff if (createInfo.debugInitInfo.useDebugging == true) { @@ -270,7 +277,7 @@ namespace Engine if (renderGraph.meshes.size() != transforms.meshes.size()) return false; - if (renderGraph.pointLights.size() != transforms.pointLights.size()) + if (renderGraph.pointLightIntensities.size() != transforms.pointLights.size()) return false; return true; diff --git a/src/Engine/Rotation.hpp b/src/Engine/Rotation.hpp deleted file mode 100644 index 1a30bc4a95daf8c640dc77131c5081fba0605deb..0000000000000000000000000000000000000000 --- a/src/Engine/Rotation.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "Math/Vector/Vector.hpp" - -class Rotation -{ -public: - Math::Vector3D GetEulerAngles() const { return rotation; } - -private: - Math::Vector3D rotation; -}; \ No newline at end of file diff --git a/src/Engine/Scene.cpp b/src/Engine/Scene.cpp index 3c783dd0908f13523638cadf7c3597fdf02f3a06..64bc8a6d1c066a324f234c6856d7e32bd778497b 100644 --- a/src/Engine/Scene.cpp +++ b/src/Engine/Scene.cpp @@ -1,9 +1,9 @@ -#include "Scene.hpp" +#include "DEngine/Scene.hpp" #include <algorithm> #include <cassert> -#include "SceneObject.hpp" +#include "DEngine/SceneObject.hpp" namespace Engine { @@ -27,6 +27,8 @@ namespace Engine size_t Scene::GetIndexInEngine() const { return indexInEngine; } + const Time::SceneData& Scene::GetTimeData() const { return timeData; } + Time::SceneData& Scene::GetTimeData() { return timeData; } void Scene::RemoveSceneObject(SceneObject& owningObject) diff --git a/src/Engine/SceneObject.cpp b/src/Engine/SceneObject.cpp index 44a7d6bb825226b8b9a475b61d3f084431d1bd04..f8fb6ad6737b52580cd8aa916a86eb2c94c05306 100644 --- a/src/Engine/SceneObject.cpp +++ b/src/Engine/SceneObject.cpp @@ -1,14 +1,11 @@ -#include "SceneObject.hpp" +#include "DEngine/SceneObject.hpp" #include "Engine.hpp" -#include "Scene.hpp" - #include "DMath/LinearTransform2D.hpp" +#include "DMath/LinearTransform3D.hpp" Engine::SceneObject::SceneObject(Scene& owningScene, size_t indexInScene) : - transform(*this), - parent(nullptr), sceneRef(owningScene) { } @@ -25,7 +22,111 @@ Engine::Scene& Engine::SceneObject::GetScene() Engine::SceneObject* Engine::SceneObject::GetParent() const { return parent; } +Math::Vector3D Engine::SceneObject::GetPosition(Space space) const +{ + if (space == Space::Local) + return localPosition; + else + { + if (parent == nullptr) + return localPosition; + else + { + assert(false); + return {}; + } + } +} + +Math::Matrix<4, 3> Engine::SceneObject::GetModel_Reduced(Space space) const +{ + const auto& scaleModel = Math::LinTran3D::Scale_Reduced(localScale); + const auto& rotateModel = Math::LinTran3D::Rotate_Reduced(localRotation); + auto localModel = Math::LinTran3D::Multiply_Reduced(scaleModel, rotateModel); + Math::LinTran3D::AddTranslation(localModel, localPosition); + return localModel; +} + +Math::Matrix<3, 2> Engine::SceneObject::GetModel2D_Reduced(Space space) const +{ + const auto& scaleModel = Math::LinTran2D::Scale_Reduced(localScale.x, localScale.y); + const auto& rotate = Math::LinTran2D::Rotate_Reduced(localRotation); + auto localModel = Math::LinTran2D::Multiply_Reduced(scaleModel, rotate); + Math::LinTran2D::AddTranslation(localModel, localPosition.x, localPosition.y); + return localModel; +} + +Math::Matrix2x2 Engine::SceneObject::GetRotationModel2D(Space space) const +{ + return Math::Matrix2x2(); +} + +Math::Matrix<3, 3, float> Engine::SceneObject::GetRotationModel(Space space) const +{ + using namespace Math::LinearTransform3D; + + auto localModel = Rotate(localRotation); + if (space == Space::Local || parent == nullptr) + return localModel; + else + return parent->GetRotationModel(space) * localModel; +} + +Math::Vector<3, float> Engine::SceneObject::GetForwardVector(Space space) const +{ + Math::UnitQuaternion<float> quat = localRotation; + + const auto & s = quat.GetS(); + const auto & x = quat.GetX(); + const auto & y = quat.GetY(); + const auto & z = quat.GetZ(); + + return + Math::Vector<3, float> + { + 2 * x* z + 2 * y * s, + 2 * y* z - 2 * x * s, + 1 - 2 * Math::Sqrd(x) - 2 * Math::Sqrd(y) + }; +} + +Math::Vector<3, float> Engine::SceneObject::GetUpVector(Space space) const +{ + Math::UnitQuaternion<float> quat = localRotation; + + const auto & s = quat.GetS(); + const auto & x = quat.GetX(); + const auto & y = quat.GetY(); + const auto & z = quat.GetZ(); + + return + Math::Vector<3, float> + { + 2 * x* y - 2 * z * s, + 1 - 2 * Math::Sqrd(x) - 2 * Math::Sqrd(z), + 2 * y* z + 2 * x * s + }; +} + +Math::Vector<3, float> Engine::SceneObject::GetRightVector(Space space) const +{ + Math::UnitQuaternion<float> quat = localRotation; + + const auto& s = quat.GetS(); + const auto& x = quat.GetX(); + const auto& y = quat.GetY(); + const auto& z = quat.GetZ(); + + return + Math::Vector<3, float> + { + 1 - 2 * Math::Sqrd(y) - 2 * Math::Sqrd(z), + 2 * x * y + 2 * z * s, + 2 * x * z - 2 * y * s + }; +} + void Engine::Destroy(SceneObject& sceneObject) { Core::Destroy(sceneObject); -} +} \ No newline at end of file diff --git a/src/Engine/Systems/RenderSystem.cpp b/src/Engine/Systems/RenderSystem.cpp index 3bbc39b939c27c63ec19e55984641b6f95c61488..ed118943962e4afd509c4e0467e3240c34023abf 100644 --- a/src/Engine/Systems/RenderSystem.cpp +++ b/src/Engine/Systems/RenderSystem.cpp @@ -1,10 +1,10 @@ #include "RenderSystem.hpp" -#include "../Renderer/Renderer.hpp" +#include "DRenderer/Renderer.hpp" -#include "../Components/SpriteRenderer.hpp" -#include "../Components/MeshRenderer.hpp" -#include "../Components/PointLight.hpp" +#include "DEngine/Components/SpriteRenderer.hpp" +#include "DEngine/Components/MeshRenderer.hpp" +#include "DEngine/Components/PointLight.hpp" #include "DMath/LinearTransform3D.hpp" @@ -36,17 +36,17 @@ namespace Engine auto pointLightComponentsPtr = scene.GetAllComponents<Components::PointLight>(); if (pointLightComponentsPtr == nullptr) - graph.pointLights.clear(); + graph.pointLightIntensities.clear(); else { const auto& pointLightComponents = *pointLightComponentsPtr; - graph.pointLights.resize(pointLightComponents.size()); + graph.pointLightIntensities.resize(pointLightComponents.size()); for (size_t i = 0; i < pointLightComponents.size(); i++) { Math::Vector3D color = pointLightComponents[i].color; for (auto& element : color) element = Math::Clamp(element, 0.f, 1.f) * pointLightComponents[i].intensity; - graph.pointLights[i] = color; + graph.pointLightIntensities[i] = color; } } } diff --git a/src/Engine/Systems/RenderSystem.hpp b/src/Engine/Systems/RenderSystem.hpp index e80c7fc3c639684c7f83aaea608ec8d04c33518b..df5774b19a86bacb19b116c9bda5348b322f053e 100644 --- a/src/Engine/Systems/RenderSystem.hpp +++ b/src/Engine/Systems/RenderSystem.hpp @@ -2,9 +2,9 @@ #include "System.hpp" -#include "../Renderer/Typedefs.hpp" +#include "DRenderer/Typedefs.hpp" -#include "../Scene.hpp" +#include "DEngine/Scene.hpp" // Forward declarations namespace Engine diff --git a/src/Engine/Time/Time.cpp b/src/Engine/Time/Time.cpp index cf490e2e73730440d4c323b5fee5c37c1b0c703c..a34276120305f2978d60983d5358abaa08332ee0 100644 --- a/src/Engine/Time/Time.cpp +++ b/src/Engine/Time/Time.cpp @@ -1,4 +1,4 @@ -#include "Time.hpp" +#include "DEngine/Time/Time.hpp" #include <chrono> #include <memory> @@ -48,11 +48,7 @@ void Engine::Time::Core::TickEnd(SceneData& scene) scene.previousFrameEndTime = now; } -Engine::Time::SceneData::SceneData() : - tickCount(0), - fixedTickInterval(), - fixedTickIntervalChanged(false), - fixedTickIntervalBufferIndex(0) +Engine::Time::SceneData::SceneData() { auto now = std::chrono::high_resolution_clock::now(); diff --git a/src/Engine/Transform.cpp b/src/Engine/Transform.cpp deleted file mode 100644 index e96720b96afb5e0c92992838a5b97c9095432431..0000000000000000000000000000000000000000 --- a/src/Engine/Transform.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "Transform.hpp" - -#include "DMath/LinearTransform3D.hpp" -#include "DMath/LinearTransform2D.hpp" - -#include "Scene.hpp" -#include "SceneObject.hpp" - -Engine::Transform::Transform(SceneObject& owningSceneObject) : - sceneObject(owningSceneObject), - localPosition(), - localRotation(), - scale(Math::Vector3D::One()) -{ -} - -Engine::SceneObject& Engine::Transform::GetSceneObject() const { return sceneObject; } - -Math::Vector3D Engine::Transform::GetPosition(Space space) const -{ - if (space == Space::Local) - return localPosition; - else - { - if (GetSceneObject().GetParent() == nullptr) - return localPosition; - else - { - assert(false); - return {}; - } - } -} - -Math::Matrix<4, 3> Engine::Transform::GetModel_Reduced(Space space) const -{ - const auto& scaleModel = Math::LinTran3D::Scale_Reduced(scale); - const auto& rotateModel = Math::LinTran3D::Rotate_Reduced(localRotation); - auto localModel = Math::LinTran3D::Multiply(scaleModel, rotateModel); - Math::LinTran3D::AddTranslation(localModel, localPosition); - return localModel; -} - -Math::Matrix<3, 2> Engine::Transform::GetModel2D_Reduced(Space space) const -{ - const auto& scaleModel = Math::LinTran2D::Scale_Reduced(scale.x, scale.y); - const auto& rotate = Math::LinTran2D::Rotate_Reduced(localRotation); - auto localModel = Math::LinTran2D::Multiply(scaleModel, rotate); - Math::LinTran2D::AddTranslation(localModel, localPosition.x, localPosition.y); - return localModel; -} - -Math::Matrix2x2 Engine::Transform::GetRotationModel2D(Engine::Space space) const -{ - return Math::Matrix2x2(); -} diff --git a/src/Engine/Transform.hpp b/src/Engine/Transform.hpp deleted file mode 100644 index da161771024edb9c0f5c262116af225c18a3f7da..0000000000000000000000000000000000000000 --- a/src/Engine/Transform.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "DMath/Vector/Vector.hpp" -#include "DMath/Matrix/Matrix.hpp" -#include "DMath/UnitQuaternion.hpp" - -#include "Enum.hpp" - -namespace Engine -{ - class SceneObject; - - class Transform - { - public: - Math::Vector3D localPosition; - Math::UnitQuaternion<> localRotation; - Math::Vector3D scale; - - SceneObject& GetSceneObject() const; - - Math::Vector3D GetPosition(Space space) const; - - Math::Matrix<4, 3> GetModel_Reduced(Space space) const; - Math::Matrix<3, 2> GetModel2D_Reduced(Space space) const; - - Math::Matrix2x2 GetRotationModel2D(Space space) const; - - private: - Transform(SceneObject& owningSceneObject); - - SceneObject& sceneObject; - - friend class SceneObject; - }; -} diff --git a/src/main.cpp b/src/main.cpp index 32fcb46f8b26d77cd03213dd2fa5b368daf539f5..eaa1f1fc1b0f54592e7b232d48ea68c120849e6d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,8 @@ #include "Engine/Engine.hpp" +#include "DTex/DTex.hpp" + int main(int argc, char* argv[]) { Engine::Core::Run();