From 769bbd426169ff79d55975524197abb9519a4774c04df0a8a92c4135f0e70eb4 Mon Sep 17 00:00:00 2001 From: Mexpert_PRO Date: Sat, 21 Feb 2026 13:52:07 +0100 Subject: [PATCH] made a lot of changes, to get the render pipeline working --- TSE_Base/src/IdGenerator.cpp | 16 +- TSE_Base/src/IdGenerator.hpp | 1 + TSE_Core/src/BehaviourScripts/Camera.cpp | 6 + TSE_Core/src/BehaviourScripts/Camera.hpp | 11 +- TSE_Core/src/BehaviourScripts/TileMap.cpp | 281 ++++++++++-------- TSE_Core/src/BehaviourScripts/TileMap.hpp | 19 +- TSE_Core/src/elements/Layer.cpp | 12 + TSE_Core/src/elements/Layer.hpp | 6 +- TSE_Core/src/elements/Material.cpp | 2 + TSE_Core/src/elements/Scene.cpp | 15 + TSE_Core/src/interfaces/IIdentifyable.hpp | 13 + TSE_Core/src/interfaces/IObservable.hpp | 35 +++ TSE_Core/src/interfaces/IObserver.hpp | 10 + TSE_Core/src/interfaces/IWindow.cpp | 1 + TSE_Core/src/interfaces/IWindow.hpp | 1 + TSE_Editor/src/EditorSubsystem.cpp | 1 + TSE_Editor/src/UI/ElementDrawer.cpp | 8 + TSE_GlfwImpl/src/WindowGlfw.cpp | 10 + TSE_GlfwImpl/src/WindowGlfw.hpp | 1 + .../src/DefaultRendererOpenGL.cpp | 3 + TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.cpp | 2 + TSE_GlfwOpenGlImpl/src/shader/Shader.cpp | 5 + TSE_GlfwOpenGlImpl/src/shader/Shader.hpp | 2 + .../src/shader/basicTileMapShader.cpp | 12 +- TSE_Math/src/Vector2i.cpp | 138 +++++++++ TSE_Math/src/Vector2i.hpp | 85 ++++++ 26 files changed, 546 insertions(+), 150 deletions(-) create mode 100644 TSE_Core/src/interfaces/IIdentifyable.hpp create mode 100644 TSE_Core/src/interfaces/IObservable.hpp create mode 100644 TSE_Core/src/interfaces/IObserver.hpp create mode 100644 TSE_Math/src/Vector2i.cpp create mode 100644 TSE_Math/src/Vector2i.hpp diff --git a/TSE_Base/src/IdGenerator.cpp b/TSE_Base/src/IdGenerator.cpp index a730631..dbf98f6 100644 --- a/TSE_Base/src/IdGenerator.cpp +++ b/TSE_Base/src/IdGenerator.cpp @@ -1,9 +1,21 @@ #include "IdGenerator.hpp" -std::mt19937 rnd = std::mt19937(); +bool init = false; +std::mt19937 rnd; auto gen = uuids::uuid_random_generator(rnd); uuids::uuid TSE::GenerateRandomUUID() { + if(!init) + { + InitRandomIDs(); + init = true; + } return gen(); -} \ No newline at end of file +} + +void TSE::InitRandomIDs() +{ + rnd = std::mt19937(); + gen = uuids::uuid_random_generator(rnd); +} diff --git a/TSE_Base/src/IdGenerator.hpp b/TSE_Base/src/IdGenerator.hpp index 4e3ce8a..3d64b5b 100644 --- a/TSE_Base/src/IdGenerator.hpp +++ b/TSE_Base/src/IdGenerator.hpp @@ -5,4 +5,5 @@ namespace TSE { uuids::uuid GenerateRandomUUID(); + void InitRandomIDs(); } // namespace TSE diff --git a/TSE_Core/src/BehaviourScripts/Camera.cpp b/TSE_Core/src/BehaviourScripts/Camera.cpp index 6734ef6..20d0094 100644 --- a/TSE_Core/src/BehaviourScripts/Camera.cpp +++ b/TSE_Core/src/BehaviourScripts/Camera.cpp @@ -1,6 +1,7 @@ #include "Camera.hpp" #include "elements/Transformable.hpp" #include "interfaces/IRenderer.hpp" +#include "uuid.h" TSE::Camera* TSE::Camera::mainCamera = nullptr; TSE::ICameraHelper* TSE::Camera::helper = nullptr; @@ -30,6 +31,11 @@ float TSE::Camera::GetFov() const return fov; } +const TSE::Vector2 &TSE::Camera::GetRenderTargetSize() const +{ + return lastRtSize; +} + TSE::Vector3 TSE::Camera::SceenPositionToGamePosition(Vector2 screenPos) { float x = 2.0f * screenPos.x / lastRtSize.x -1.0f; diff --git a/TSE_Core/src/BehaviourScripts/Camera.hpp b/TSE_Core/src/BehaviourScripts/Camera.hpp index 0ee91c9..8a6dde4 100644 --- a/TSE_Core/src/BehaviourScripts/Camera.hpp +++ b/TSE_Core/src/BehaviourScripts/Camera.hpp @@ -8,6 +8,7 @@ #include "Vector3.hpp" #include "interfaces/IRenderTarget.hpp" #include "elements/BehaviourScript.hpp" +#include "uuid.h" namespace TSE { @@ -31,16 +32,17 @@ namespace TSE ProjectionType projection = ProjectionType::Orthographic; Matrix4x4* projectionMatrix = nullptr; Matrix4x4 viewMatrix; - + float nearClippingPlane = 0; float farClippingPlane = 100; - + //perspective float fov = 60; - + Vector2 lastRtSize = {0, 0}; - + public: + std::vector layersNotToRender; static ICameraHelper* helper; static Camera* mainCamera; @@ -50,6 +52,7 @@ namespace TSE float GetNearClippingPlane() const; float GetFarClippingPlane() const; float GetFov() const; + const Vector2& GetRenderTargetSize() const; // Setter Vector3 SceenPositionToGamePosition(Vector2 screenPos); diff --git a/TSE_Core/src/BehaviourScripts/TileMap.cpp b/TSE_Core/src/BehaviourScripts/TileMap.cpp index e59f697..6d0e2f1 100644 --- a/TSE_Core/src/BehaviourScripts/TileMap.cpp +++ b/TSE_Core/src/BehaviourScripts/TileMap.cpp @@ -7,9 +7,14 @@ TSE::TileMapChunk::TileMapChunk(int _chunksize, const Vector2 &_pos, SortingOrde order = _order; } -void TSE::TileMapChunk::SetTile(const Vector2& p, const Vector2& Spriteindex, TileSet* set) +void TSE::TileMapChunk::SetTile(const Vector2& p, const Vector2& Spriteindex, const Vector2& Normalindex, TileSet* set) { - sprites[p] = set->GetSpriteIdAt(Spriteindex.x, Spriteindex.y); + int normalid = -1; + if(Normalindex != Vector2(-1,-1)) + normalid = set->GetSpriteIdAt(Normalindex.x, Normalindex.y); + sprites[p] = {set->GetSpriteIdAt(Spriteindex.x, Spriteindex.y), normalid}; + dirtyPositions = true; + dirtySpriteIds = true; } void TSE::TileMapChunk::RemoveTile(Vector2 p) @@ -22,118 +27,130 @@ void TSE::TileMapChunk::SetOrdering(SortingOrder _order) order = _order; } -void TSE::TileMapChunk::GetOrderedPositions(Vector2 *array) +const std::vector* TSE::TileMapChunk::GetOrderedPositions() { - switch (order) + if(dirtyPositions) { - case TopLeft: - for (int y = 0; y < chunksize; y++) + orderedPositions.clear(); + switch (order) { - Vector2 offset = nextLine * y; - for (int x = 0; x < chunksize; x++) + case TopLeft: + for (int y = 0; y < chunksize; y++) { - Vector2 p(x,y); - auto v = sprites.find(p); - if(v != sprites.end()) - *array++ = v->first - offset; + Vector2 offset = nextLine * y; + for (int x = 0; x < chunksize; x++) + { + Vector2 p(x,y); + auto v = sprites.find(p); + if(v != sprites.end()) + orderedPositions.push_back(v->first - offset); + } } - } - break; - case TopRight: - for (int y = 0; y < chunksize; y++) - { - Vector2 offset = nextLine * y; - for (int x = chunksize - 1; x >= 0; x--) + break; + case TopRight: + for (int y = 0; y < chunksize; y++) { - Vector2 p(x,y); - auto v = sprites.find(p); - if(v != sprites.end()) - *array++ = v->first - offset; + Vector2 offset = nextLine * y; + for (int x = chunksize - 1; x >= 0; x--) + { + Vector2 p(x,y); + auto v = sprites.find(p); + if(v != sprites.end()) + orderedPositions.push_back(v->first - offset); + } } - } - break; - case BottomLeft: - for (int y = chunksize - 1; y >= 0; y--) - { - Vector2 offset = nextLine * y; - for (int x = 0; x < chunksize; x++) + break; + case BottomLeft: + for (int y = chunksize - 1; y >= 0; y--) { - Vector2 p(x,y); - auto v = sprites.find(p); - if(v != sprites.end()) - *array++ = v->first - offset; + Vector2 offset = nextLine * y; + for (int x = 0; x < chunksize; x++) + { + Vector2 p(x,y); + auto v = sprites.find(p); + if(v != sprites.end()) + orderedPositions.push_back(v->first - offset); + } } - } - break; - case BottomRight: - for (int y = chunksize - 1; y >= 0; y--) - { - Vector2 offset = nextLine * y; - for (int x = chunksize - 1; x >= 0; x--) + break; + case BottomRight: + for (int y = chunksize - 1; y >= 0; y--) { - Vector2 p(x,y); - auto v = sprites.find(p); - if(v != sprites.end()) - *array++ = v->first - offset; + Vector2 offset = nextLine * y; + for (int x = chunksize - 1; x >= 0; x--) + { + Vector2 p(x,y); + auto v = sprites.find(p); + if(v != sprites.end()) + orderedPositions.push_back(v->first - offset); + } } + break; } - break; + dirtyPositions = false; } + return &orderedPositions; } -void TSE::TileMapChunk::GetOrderedSpriteIds(int *array) +const std::vector* TSE::TileMapChunk::GetOrderedSpriteIds() { - switch (order) + if(dirtySpriteIds) { - case TopLeft: - for (int y = 0; y < chunksize; y++) + orderedSpriteIDs.clear(); + switch (order) { - for (int x = 0; x < chunksize; x++) + case TopLeft: + for (int y = 0; y < chunksize; y++) { - Vector2 p(x,y); - auto v = sprites.find(p); - if(v != sprites.end()) - *array++ = v->second; + for (int x = 0; x < chunksize; x++) + { + Vector2 p(x,y); + auto v = sprites.find(p); + if(v != sprites.end()) + orderedSpriteIDs.push_back(v->second); + } } - } - break; - case TopRight: - for (int y = 0; y < chunksize; y++) - { - for (int x = chunksize - 1; x >= 0; x--) + break; + case TopRight: + for (int y = 0; y < chunksize; y++) { - Vector2 p(x,y); - auto v = sprites.find(p); - if(v != sprites.end()) - *array++ = v->second; + for (int x = chunksize - 1; x >= 0; x--) + { + Vector2 p(x,y); + auto v = sprites.find(p); + if(v != sprites.end()) + orderedSpriteIDs.push_back(v->second); + } } - } - break; - case BottomLeft: - for (int y = chunksize - 1; y >= 0; y--) - { - for (int x = 0; x < chunksize; x++) + break; + case BottomLeft: + for (int y = chunksize - 1; y >= 0; y--) { - Vector2 p(x,y); - auto v = sprites.find(p); - if(v != sprites.end()) - *array++ = v->second; + for (int x = 0; x < chunksize; x++) + { + Vector2 p(x,y); + auto v = sprites.find(p); + if(v != sprites.end()) + orderedSpriteIDs.push_back(v->second); + } } - } - break; - case BottomRight: - for (int y = chunksize - 1; y >= 0; y--) - { - for (int x = chunksize - 1; x >= 0; x--) + break; + case BottomRight: + for (int y = chunksize - 1; y >= 0; y--) { - Vector2 p(x,y); - auto v = sprites.find(p); - if(v != sprites.end()) - *array++ = v->second; + for (int x = chunksize - 1; x >= 0; x--) + { + Vector2 p(x,y); + auto v = sprites.find(p); + if(v != sprites.end()) + orderedSpriteIDs.push_back(v->second); + } } + break; } - break; + dirtySpriteIds = false; } + return &orderedSpriteIDs; } int TSE::TileMapChunk::GetChunksize() @@ -154,17 +171,18 @@ void TSE::TileMap::RemoveTile(Vector2 p) chunks[chunkIndex].RemoveTile(chunkInnerPos); } -void TSE::TileMap::SetTile(Vector2 p, Vector2 Spriteindex) +void TSE::TileMap::SetTile(Vector2 p, Vector2 Spriteindex, Vector2 Normalindex) { Vector2 chunkInnerPos = LocalToChunkPos(p); Vector2 chunkIndex = p - chunkInnerPos; if(!chunks.contains(chunkIndex)) { + dirty = true; chunks[chunkIndex] = TileMapChunk(chunkSize, chunkIndex, order); chunks[chunkIndex].nextLine = nextLine; CheckBounds(chunkIndex); } - chunks[chunkIndex].SetTile(chunkInnerPos, Spriteindex, set); + chunks[chunkIndex].SetTile(chunkInnerPos, Spriteindex, Normalindex, set); } TSE::TileMapChunk* TSE::TileMap::GetChunk(const Vector2 &pos) @@ -175,60 +193,65 @@ TSE::TileMapChunk* TSE::TileMap::GetChunk(const Vector2 &pos) return &chunks[pos]; } -void TSE::TileMap::GetChunkPositionsInOrder(Vector2 *arr) +const std::vector* TSE::TileMap::GetChunkPositionsInOrder() { - - switch (order) + if(dirty) { - case TopLeft: - for (int y = bounds.p1.y; y < bounds.p2.y + 1; y++) + orderedChunks.clear(); + switch (order) { - for (int x = bounds.p1.x; x < bounds.p2.x + 1; x++) + case TopLeft: + for (int y = bounds.p1.y; y < bounds.p2.y + 1; y++) { - Vector2 p(x,y); - auto v = chunks.find(p); - if(v != chunks.end()) - *arr++ = v->first; + for (int x = bounds.p1.x; x < bounds.p2.x + 1; x++) + { + Vector2 p(x,y); + auto v = chunks.find(p); + if(v != chunks.end()) + orderedChunks.push_back(v->first); + } } - } - break; - case TopRight: - for (int y = bounds.p1.y; y < bounds.p2.y + 1; y++) - { - for (int x = bounds.p2.x; x > bounds.p1.x - 1; x--) + break; + case TopRight: + for (int y = bounds.p1.y; y < bounds.p2.y + 1; y++) { - Vector2 p(x,y); - auto v = chunks.find(p); - if(v != chunks.end()) - *arr++ = v->first; + for (int x = bounds.p2.x; x > bounds.p1.x - 1; x--) + { + Vector2 p(x,y); + auto v = chunks.find(p); + if(v != chunks.end()) + orderedChunks.push_back(v->first); + } } - } - break; - case BottomLeft: - for (int y = bounds.p2.y; y > bounds.p1.y - 1; y--) - { - for (int x = bounds.p1.x; x < bounds.p2.x + 1; x++) + break; + case BottomLeft: + for (int y = bounds.p2.y; y > bounds.p1.y - 1; y--) { - Vector2 p(x,y); - auto v = chunks.find(p); - if(v != chunks.end()) - *arr++ = v->first; + for (int x = bounds.p1.x; x < bounds.p2.x + 1; x++) + { + Vector2 p(x,y); + auto v = chunks.find(p); + if(v != chunks.end()) + orderedChunks.push_back(v->first); + } } - } - break; - case BottomRight: - for (int y = bounds.p2.y; y > bounds.p1.y - 1; y--) - { - for (int x = bounds.p2.x; x > bounds.p1.x - 1; x--) + break; + case BottomRight: + for (int y = bounds.p2.y; y > bounds.p1.y - 1; y--) { - Vector2 p(x,y); - auto v = chunks.find(p); - if(v != chunks.end()) - *arr++ = v->first; + for (int x = bounds.p2.x; x > bounds.p1.x - 1; x--) + { + Vector2 p(x,y); + auto v = chunks.find(p); + if(v != chunks.end()) + orderedChunks.push_back(v->first); + } } + break; } - break; + dirty = false; } + return &orderedChunks; } int TSE::TileMap::GetChunkCount() diff --git a/TSE_Core/src/BehaviourScripts/TileMap.hpp b/TSE_Core/src/BehaviourScripts/TileMap.hpp index a5471f7..1ca0ae9 100644 --- a/TSE_Core/src/BehaviourScripts/TileMap.hpp +++ b/TSE_Core/src/BehaviourScripts/TileMap.hpp @@ -5,6 +5,7 @@ #include #include "elements/BehaviourScript.hpp" #include "Vector2.hpp" +#include "Vector2i.hpp" #include "elements/Sprite.hpp" #include "elements/TileSet.hpp" @@ -21,19 +22,23 @@ namespace TSE struct TileMapChunk { private: + bool dirtyPositions = true; + bool dirtySpriteIds = true; + std::vector orderedPositions; + std::vector orderedSpriteIDs; SortingOrder order; int chunksize; - std::unordered_map sprites; + std::unordered_map sprites; public: Vector2 nextLine; Vector2 pos; TileMapChunk(int _chunksize = 16, const Vector2& _pos = {0,0}, SortingOrder _order = TopRight); - void SetTile(const Vector2& p, const Vector2& Spriteindex, TileSet* set); + void SetTile(const Vector2& p, const Vector2& Spriteindex, const Vector2& Normalindex, TileSet* set); void RemoveTile(Vector2 p); void SetOrdering(SortingOrder _order); - void GetOrderedPositions(Vector2* array); - void GetOrderedSpriteIds(int* array); + const std::vector* GetOrderedPositions(); + const std::vector* GetOrderedSpriteIds(); int GetChunksize(); int GetSpriteCount(); @@ -42,6 +47,8 @@ namespace TSE class TileMap : public BehaviourScript { private: + bool dirty = true; + std::vector orderedChunks; Rect bounds = Rect(0,0,0,0); Vector2 nextLine = Vector2(-0.5f, 1.25f); public: @@ -52,9 +59,9 @@ namespace TSE std::unordered_map chunks; void RemoveTile(Vector2 p); - void SetTile(Vector2 p, Vector2 Spriteindex); + void SetTile(Vector2 p, Vector2 Spriteindex, Vector2 Normalindex = {-1,-1}); TileMapChunk* GetChunk(const Vector2& pos); - void GetChunkPositionsInOrder(Vector2* arr); + const std::vector* GetChunkPositionsInOrder(); int GetChunkCount(); TileSet* GetTileSet(); const Rect& GetBounds() const { return bounds; } diff --git a/TSE_Core/src/elements/Layer.cpp b/TSE_Core/src/elements/Layer.cpp index 58f8660..39e62dc 100644 --- a/TSE_Core/src/elements/Layer.cpp +++ b/TSE_Core/src/elements/Layer.cpp @@ -1,6 +1,7 @@ #include "Layer.hpp" #include "BehaviourScripts/Renderable.hpp" #include "elements/BehaviourScript.hpp" +#include "IdGenerator.hpp" void HandleObject(TSE::Transformable* trans, TSE::TransformationStack& stack, TSE::IRenderer& rnd) { @@ -24,6 +25,7 @@ void HandleObject(TSE::Transformable* trans, TSE::TransformationStack& stack, TS TSE::Layer::Layer(const string &n) { + ID = GenerateRandomUUID(); name = n; } @@ -94,3 +96,13 @@ void TSE::Layer::Update() trans->Update(); } } + +void TSE::Layer::SetNonVisual(bool v) +{ + nonVisual = v; +} + +bool TSE::Layer::IsVisual() +{ + return !nonVisual; +} diff --git a/TSE_Core/src/elements/Layer.hpp b/TSE_Core/src/elements/Layer.hpp index 7b59159..332bfb3 100644 --- a/TSE_Core/src/elements/Layer.hpp +++ b/TSE_Core/src/elements/Layer.hpp @@ -4,14 +4,16 @@ #include "Types.hpp" #include "interfaces/IRenderer.hpp" #include +#include "interfaces/IIdentifyable.hpp" namespace TSE { - class Layer + class Layer : public IIdentifyable { private: string name; std::vector objectsToRender; + bool nonVisual = false; public: Layer(const string& name); @@ -27,5 +29,7 @@ namespace TSE void SetName(const string& name); std::vector& GetAllObjects(); void Update(); + void SetNonVisual(bool v); + bool IsVisual(); }; } // namespace TSE diff --git a/TSE_Core/src/elements/Material.cpp b/TSE_Core/src/elements/Material.cpp index 32d02a1..5f3d86d 100644 --- a/TSE_Core/src/elements/Material.cpp +++ b/TSE_Core/src/elements/Material.cpp @@ -60,6 +60,7 @@ namespace TSE } template void Material::SetValue(const string&, const int&); + template void Material::SetValue(const string&, const uint&); template void Material::SetValue(const string&, const float&); template void Material::SetValue(const string&, const Vector2&); template void Material::SetValue(const string&, const Vector3&); @@ -70,6 +71,7 @@ namespace TSE template void Material::SetValue(const string&, const ITexture*); template int Material::GetValue(const string&) const; + template uint Material::GetValue(const string&) const; template float Material::GetValue(const string&) const; template Vector2 Material::GetValue(const string&) const; template Vector3 Material::GetValue(const string&) const; diff --git a/TSE_Core/src/elements/Scene.cpp b/TSE_Core/src/elements/Scene.cpp index 6c9e1fd..1a0afee 100644 --- a/TSE_Core/src/elements/Scene.cpp +++ b/TSE_Core/src/elements/Scene.cpp @@ -1,10 +1,25 @@ #include "Scene.hpp" +#include "BehaviourScripts/Camera.hpp" +#include +#include "Debug.hpp" void TSE::Scene::Render(IRenderer &rnd, const IWindow &wnd) { + auto camerasBackup = std::vector(IRenderer::camerasToRenderWith); int counter = 1; for(auto l : layers) { + IRenderer::camerasToRenderWith.clear(); + if(!l.second->IsVisual()) continue; + for(auto camera : camerasBackup) + { + auto it = std::find(camera->layersNotToRender.begin(), camera->layersNotToRender.end(), l.second->GetID()); + if(it == camera->layersNotToRender.end()) + { + IRenderer::camerasToRenderWith.push_back(camera); + } + } + l.second->Render(rnd); if(counter++ != layers.size()) { diff --git a/TSE_Core/src/interfaces/IIdentifyable.hpp b/TSE_Core/src/interfaces/IIdentifyable.hpp new file mode 100644 index 0000000..f708aea --- /dev/null +++ b/TSE_Core/src/interfaces/IIdentifyable.hpp @@ -0,0 +1,13 @@ +#pragma once +#include "uuid.h" + +namespace TSE +{ + class IIdentifyable + { + protected: + uuids::uuid ID; + public: + inline const uuids::uuid& GetID() { return ID;}; + }; +} // namespace TSE diff --git a/TSE_Core/src/interfaces/IObservable.hpp b/TSE_Core/src/interfaces/IObservable.hpp new file mode 100644 index 0000000..54491bd --- /dev/null +++ b/TSE_Core/src/interfaces/IObservable.hpp @@ -0,0 +1,35 @@ +#pragma once + +#include "IObserver.hpp" +#include +#include + +namespace TSE +{ + class IObservable + { + private: + std::vector objectsToNotify; + + public: + inline void Observe(IObserver* observer) + { + objectsToNotify.push_back(observer); + }; + inline void StopObserve(IObserver* observer) + { + auto it = std::find(objectsToNotify.begin(), objectsToNotify.end(), observer); + if(it != objectsToNotify.end()) + objectsToNotify.erase(it); + }; + + protected: + inline void TriggerObserver(void* data) + { + for (auto &&observer : objectsToNotify) + { + observer->OnObserved(data); + } + }; + }; +} // namespace TSE diff --git a/TSE_Core/src/interfaces/IObserver.hpp b/TSE_Core/src/interfaces/IObserver.hpp new file mode 100644 index 0000000..c3b047e --- /dev/null +++ b/TSE_Core/src/interfaces/IObserver.hpp @@ -0,0 +1,10 @@ +#pragma once + +namespace TSE +{ + class IObserver + { + public: + virtual void OnObserved(void* data) = 0; + }; +} // namespace TSE diff --git a/TSE_Core/src/interfaces/IWindow.cpp b/TSE_Core/src/interfaces/IWindow.cpp index c2e0961..6b19b1b 100644 --- a/TSE_Core/src/interfaces/IWindow.cpp +++ b/TSE_Core/src/interfaces/IWindow.cpp @@ -5,6 +5,7 @@ #include "version.h" #include "IInputManager.hpp" #include "elements/AudioEngine.hpp" +#include "IdGenerator.hpp" #define FREEIMAGE_LIB #include "FI/FreeImage.h" diff --git a/TSE_Core/src/interfaces/IWindow.hpp b/TSE_Core/src/interfaces/IWindow.hpp index c8c8e4f..c410edb 100644 --- a/TSE_Core/src/interfaces/IWindow.hpp +++ b/TSE_Core/src/interfaces/IWindow.hpp @@ -18,6 +18,7 @@ namespace TSE virtual void Clear() const = 0; virtual void ClearDepthBuffer() const = 0; virtual bool ShouldClose() const = 0; + virtual void DoneSetup() = 0; bool BaseInit() const; void BaseUpdate() const; diff --git a/TSE_Editor/src/EditorSubsystem.cpp b/TSE_Editor/src/EditorSubsystem.cpp index 5adf717..22c6144 100644 --- a/TSE_Editor/src/EditorSubsystem.cpp +++ b/TSE_Editor/src/EditorSubsystem.cpp @@ -40,6 +40,7 @@ TSE::EDITOR::EditorSubsystem::EditorSubsystem() : sv(nullptr), editorLayer("") editorLayer = Layer(".editor"); editorLayer.AddTransformable(editorCamera); + editorLayer.SetNonVisual(true); #pragma endregion } \ No newline at end of file diff --git a/TSE_Editor/src/UI/ElementDrawer.cpp b/TSE_Editor/src/UI/ElementDrawer.cpp index 2769552..d8b0b05 100644 --- a/TSE_Editor/src/UI/ElementDrawer.cpp +++ b/TSE_Editor/src/UI/ElementDrawer.cpp @@ -439,6 +439,14 @@ namespace TSE::EDITOR Texture* value = element->GetValue(name); Draw(value, debug, name , true); } + if (type == typeid(uint).name()) + { + int value = element->GetValue(name); + if(ImGui::InputInt(name.c_str(), &value)) + { + element->SetValue(name, value); + } + } else { ImGui::TextDisabled(("Not Implemented: " + type).c_str()); diff --git a/TSE_GlfwImpl/src/WindowGlfw.cpp b/TSE_GlfwImpl/src/WindowGlfw.cpp index 9850ac3..10d757b 100644 --- a/TSE_GlfwImpl/src/WindowGlfw.cpp +++ b/TSE_GlfwImpl/src/WindowGlfw.cpp @@ -149,3 +149,13 @@ bool TSE::GLFW::WindowGlfw::ShouldClose() const { return glfwWindowShouldClose(window); } + +void TSE::GLFW::WindowGlfw::DoneSetup() +{ + renderingBackend->onResize(width, height); + + for (auto const& i : objectsToResize) + { + i->OnResize(width, height, this); + } +} diff --git a/TSE_GlfwImpl/src/WindowGlfw.hpp b/TSE_GlfwImpl/src/WindowGlfw.hpp index af06d24..487344f 100644 --- a/TSE_GlfwImpl/src/WindowGlfw.hpp +++ b/TSE_GlfwImpl/src/WindowGlfw.hpp @@ -36,5 +36,6 @@ namespace TSE::GLFW bool ShouldClose() const override; inline void Bind() override { }; inline void Unbind() override { }; + void DoneSetup() override; }; } // namespace TSE::GLFW diff --git a/TSE_GlfwOpenGlImpl/src/DefaultRendererOpenGL.cpp b/TSE_GlfwOpenGlImpl/src/DefaultRendererOpenGL.cpp index 7bfef24..fb6f761 100644 --- a/TSE_GlfwOpenGlImpl/src/DefaultRendererOpenGL.cpp +++ b/TSE_GlfwOpenGlImpl/src/DefaultRendererOpenGL.cpp @@ -1,6 +1,7 @@ #include "DefaultRendererOpenGL.hpp" #include "BehaviourScripts/Camera.hpp" #include "BehaviourScripts/Renderable.hpp" +#include "Debug.hpp" #define RENDERER_MAX_SPRITES 20000 #define RENDERER_MAX_INDECIES 60000 @@ -77,6 +78,8 @@ void TSE::GLFW::DefaultRendererOpenGL::Flush() camerasToRenderWith[i]->PostDraw(); } + + lastShader->PostDraw(); if(ibobound) { diff --git a/TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.cpp b/TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.cpp index b20005b..b312286 100644 --- a/TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.cpp +++ b/TSE_GlfwOpenGlImpl/src/buffer/FrameBuffer.cpp @@ -96,6 +96,8 @@ void TSE::GLFW::FrameBuffer::LoadFBTexture() glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); glBindRenderbuffer(GL_RENDERBUFFER, depthRboID); glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height); diff --git a/TSE_GlfwOpenGlImpl/src/shader/Shader.cpp b/TSE_GlfwOpenGlImpl/src/shader/Shader.cpp index aed5028..ffbf204 100644 --- a/TSE_GlfwOpenGlImpl/src/shader/Shader.cpp +++ b/TSE_GlfwOpenGlImpl/src/shader/Shader.cpp @@ -39,6 +39,11 @@ void TSE::GLFW::Shader::DrawCall(int indexCount) OnDrawCall(indexCount); } +void TSE::GLFW::Shader::PostDraw() +{ + OnPostDraw(); +} + void TSE::GLFW::Shader::Submit(const Transformable &t, float *&target, TransformationStack &stack, void (*restartDrawcall)(IRenderer &), IRenderer &rnd) { OnSubmit(t, target, stack, restartDrawcall, rnd); diff --git a/TSE_GlfwOpenGlImpl/src/shader/Shader.hpp b/TSE_GlfwOpenGlImpl/src/shader/Shader.hpp index 4039cf4..bd76e1e 100644 --- a/TSE_GlfwOpenGlImpl/src/shader/Shader.hpp +++ b/TSE_GlfwOpenGlImpl/src/shader/Shader.hpp @@ -24,6 +24,7 @@ namespace TSE::GLFW virtual void OnDisable() const {}; virtual void OnFlush() {}; virtual void OnDrawCall(int indexCount) {}; + virtual void OnPostDraw() {}; virtual void OnSubmit(const Transformable& t, float*& target, TransformationStack& stack, void (*restartDrawcall)(IRenderer&), IRenderer& rnd) {}; public: @@ -33,6 +34,7 @@ namespace TSE::GLFW void Disable(bool notify = false) const; void Flush(); void DrawCall(int indexCount); + void PostDraw(); void Submit(const Transformable& t, float*& target, TransformationStack& stack, void (*restartDrawcall)(IRenderer&), IRenderer& rnd); bool IsEnabled() const; int packageSize(); diff --git a/TSE_GlfwOpenGlImpl/src/shader/basicTileMapShader.cpp b/TSE_GlfwOpenGlImpl/src/shader/basicTileMapShader.cpp index 3d07428..38c1070 100644 --- a/TSE_GlfwOpenGlImpl/src/shader/basicTileMapShader.cpp +++ b/TSE_GlfwOpenGlImpl/src/shader/basicTileMapShader.cpp @@ -171,9 +171,7 @@ void TSE::GLFW::BasicTileMapShader::OnSubmit(const Transformable &t, float *&tar SpriteCount = tileSet->GetCount(); SpriteScale = tm->SpriteScale; - const int chunkcount = tm->GetChunkCount(); - Vector2 orderedChunks[chunkcount]; - tm->GetChunkPositionsInOrder(orderedChunks); + const std::vector orderedChunks = *tm->GetChunkPositionsInOrder(); Matrix4x4 matr = t.GetLocalMatrix(); @@ -183,10 +181,8 @@ void TSE::GLFW::BasicTileMapShader::OnSubmit(const Transformable &t, float *&tar { auto chunk = tm->GetChunk(chunkPos); const int spriteCount = chunk->GetSpriteCount(); - Vector2 spritePositions[spriteCount]; - int spriteIds[spriteCount]; - chunk->GetOrderedPositions(spritePositions); - chunk->GetOrderedSpriteIds(spriteIds); + const std::vector spritePositions = *chunk->GetOrderedPositions(); + const std::vector spriteIds = *chunk->GetOrderedSpriteIds(); int chunkSize = chunk->GetChunksize(); for (int i = 0; i < spriteCount; i++) @@ -198,7 +194,7 @@ void TSE::GLFW::BasicTileMapShader::OnSubmit(const Transformable &t, float *&tar *target++ = pos.x; *target++ = pos.y; *target++ = pos.z; - *target++ = spriteIds[i]; + *target++ = spriteIds[i].x; ++instanceCount; stack.Pop(); diff --git a/TSE_Math/src/Vector2i.cpp b/TSE_Math/src/Vector2i.cpp new file mode 100644 index 0000000..478054d --- /dev/null +++ b/TSE_Math/src/Vector2i.cpp @@ -0,0 +1,138 @@ +#include "Vector2i.hpp" +#include "Vector2.hpp" +#include "Vector3.hpp" +#include "Vector4.hpp" +#include + +TSE::Vector2i::Vector2i() { } + +TSE::Vector2i::Vector2i(int _x, int _y) +{ + x = _x; + y = _y; +} + +TSE::Vector2i::Vector2i(const Vector2i &other) +{ + x = other.x; + y = other.y; +} + +TSE::Vector2i::Vector2i(const Vector2 &other) +{ + x = other.x; + y = other.y; +} + +TSE::Vector2i::Vector2i(const Vector3 &other) +{ + x = other.x; + y = other.y; +} + +TSE::Vector2i::Vector2i(const Vector4 &other) +{ + x = other.x; + y = other.y; +} + +bool TSE::Vector2i::IsValid() const +{ + return !std::isnan(x) && !std::isnan(y); +} + +TSE::string TSE::Vector2i::ToString() const +{ + return "(" + std::to_string(x) + "|" + std::to_string(y) + ")"; +} + +TSE::Vector2 TSE::Vector2i::ToVector2() const +{ + return Vector2(); +} + +TSE::Vector3 TSE::Vector2i::ToVector3() const +{ + return Vector3(x,y,0); +} + +TSE::Vector4 TSE::Vector2i::ToVector4() const +{ + return Vector4(x,y,0,0); +} + +TSE::Vector2i TSE::Vector2i::operator+(const Vector2i &other) const +{ + return Vector2i(x + other.x, y + other.y); +} + +TSE::Vector2i TSE::Vector2i::operator+=(const Vector2i &other) +{ + *this = *this + other; + return *this; +} + +TSE::Vector2i TSE::Vector2i::operator-(const Vector2i &other) const +{ + return Vector2i(x - other.x, y - other.y); +} + +TSE::Vector2i TSE::Vector2i::operator-=(const Vector2i &other) +{ + *this = *this - other; + return *this; +} + +TSE::Vector2i TSE::Vector2i::operator*(const Vector2i &other) const +{ + return Vector2i(x * other.x, y * other.y); +} + +TSE::Vector2i TSE::Vector2i::operator*=(const Vector2i &other) +{ + *this = *this * other; + return *this; +} + +TSE::Vector2i TSE::Vector2i::operator/(const Vector2i &other) const +{ + return Vector2i(x / other.x, y / other.y); +} + +TSE::Vector2i TSE::Vector2i::operator/=(const Vector2i &other) +{ + *this = *this / other; + return *this; +} + +TSE::Vector2i TSE::Vector2i::operator*(const float other) const +{ + return Vector2i(x * other, y * other); +} + +TSE::Vector2i TSE::Vector2i::operator*=(const float other) +{ + *this = *this * other; + return *this; +} + +TSE::Vector2i TSE::Vector2i::operator/(const float other) const +{ + return Vector2i(x / other, y / other); +} + +TSE::Vector2i TSE::Vector2i::operator/=(const float other) +{ + *this = *this / other; + return *this; +} + +bool TSE::Vector2i::operator==(const Vector2i &other) const +{ + return x == other.x && y == other.y; +} + +bool TSE::Vector2i::operator!=(const Vector2i &other) const +{ + return !(*this == other); +} \ No newline at end of file diff --git a/TSE_Math/src/Vector2i.hpp b/TSE_Math/src/Vector2i.hpp new file mode 100644 index 0000000..e21eda1 --- /dev/null +++ b/TSE_Math/src/Vector2i.hpp @@ -0,0 +1,85 @@ +#pragma once + +#include "Types.hpp" +#include "MathF.hpp" +#include + +namespace TSE +{ + class Vector2; + class Vector3; + class Vector4; + + class Vector2i + { + public: + #pragma region members + int x = 0, y = 0; + #pragma endregion members + + #pragma region consts + static const Vector2i left; + static const Vector2i right; + static const Vector2i up; + static const Vector2i down; + static const Vector2i one; + static const Vector2i zero; + #pragma endregion + + #pragma region ctor + /// @brief enpty constructor defined as (0,0) + Vector2i(); + /// @brief constructs a Vector2i with custom values + /// @param _x the x component + /// @param _y the y component + Vector2i(int _x, int _y); + /// @brief copy constructor + /// @param other the Vector2i to be copied from + Vector2i(const Vector2i& other); + /// @brief copy constructor + /// @param other the Vector2i to be copied from + Vector2i(const Vector2& other); + /// @brief converter constructor. it converts a Vector3 to a Vector2i without encointing for the z component + /// @param other the Vector3 to convert + Vector2i(const Vector3& other); + /// @brief converter constructor. it converts a Vector4 to a Vector2i without encointing for the z, and w component + /// @param other the Vector4 to convert + Vector2i(const Vector4& other); + #pragma endregion ctor + + #pragma region methods + /// @brief checks if the individual components have valid values aka are not nan + /// @return are the values valid + bool IsValid() const; + /// @brief gives you the Vector2i as a string representation. mostly for debugging + /// @return the Vector2i in a format like (x|y) + string ToString() const; + /// @brief creates a Vector3 with the same values as the Vector2i, the y component gets the value 0 + /// @return the Vector2i as a Vector3 + Vector2 ToVector2() const; + /// @brief creates a Vector3 with the same values as the Vector2i, the y component gets the value 0 + /// @return the Vector2i as a Vector3 + Vector3 ToVector3() const; + /// @brief creates a Vector4 with the same values as the Vector2i, the y and w components get the value 0 + /// @return the Vector2i as a Vector4 + Vector4 ToVector4() const; + + #pragma region operators + Vector2i operator+(const Vector2i& other) const; + Vector2i operator+=(const Vector2i& other); + Vector2i operator-(const Vector2i& other) const; + Vector2i operator-=(const Vector2i& other); + Vector2i operator*(const Vector2i& other) const; + Vector2i operator*=(const Vector2i& other); + Vector2i operator/(const Vector2i& other) const; + Vector2i operator/=(const Vector2i& other); + Vector2i operator*(const float other) const; + Vector2i operator*=(const float other); + Vector2i operator/(const float other) const; + Vector2i operator/=(const float other); + bool operator==(const Vector2i& other) const; + bool operator!=(const Vector2i& other) const; + #pragma endregion operators + #pragma endregion methods + }; +} // namespace TSE \ No newline at end of file