diff --git a/AGE/src/Age/Renderer/Renderer2D.cpp b/AGE/src/Age/Renderer/Renderer2D.cpp index b482af7..07594fe 100644 --- a/AGE/src/Age/Renderer/Renderer2D.cpp +++ b/AGE/src/Age/Renderer/Renderer2D.cpp @@ -34,7 +34,7 @@ namespace AGE { uint32_t QuadIndexCount = 0; - std::array, MaxTextureSlots> TextureSlots; + std::array, MaxTextureSlots> TextureSlots{UnitTexture}; uint32_t TextureSlotIndex = 1; //0 - Unit Texture; glm::vec4 QuadVertexPositions[4]; @@ -320,7 +320,7 @@ namespace AGE { } int Renderer2D::FindTextureIndex(const Ref& texture) { - int textureIndex = 0; + int textureIndex = -1; if (texture != nullptr) { for (int i{0}; i < s_Data.TextureSlotIndex; i++) { @@ -330,7 +330,7 @@ namespace AGE { } } - if (textureIndex == 0) { + if (textureIndex == -1) { textureIndex = (int)s_Data.TextureSlotIndex; s_Data.TextureSlots[textureIndex] = texture; s_Data.TextureSlotIndex++; diff --git a/AGE/src/Age/Renderer/Texture.h b/AGE/src/Age/Renderer/Texture.h index 9218b35..40a15b9 100644 --- a/AGE/src/Age/Renderer/Texture.h +++ b/AGE/src/Age/Renderer/Texture.h @@ -31,7 +31,7 @@ namespace AGE { static Ref Create(const uint32_t width, const uint32_t height); static Ref ErrorTexture(); - virtual bool operator==(const Texture2D& other) const = 0; + virtual bool operator==(const Texture2D& other) const { return ID() == other.ID(); }; }; } diff --git a/Sandbox/src/Sandbox2DLayer.cpp b/Sandbox/src/Sandbox2DLayer.cpp index 3e5ec06..bd948a8 100644 --- a/Sandbox/src/Sandbox2DLayer.cpp +++ b/Sandbox/src/Sandbox2DLayer.cpp @@ -24,7 +24,7 @@ static const char* s_MapTiles = "WWWWWWWWDDDDDDDDDWWWWWWW" "WWWWWWWWWWWWWWWWWWWWWWWW"; -Sandbox2DLayer::Sandbox2DLayer() : m_CameraController(1280.0f / 720.0f) { +Sandbox2DLayer::Sandbox2DLayer() : m_CameraController(1280.0f / 720.0f), m_Particles(5000) { AGE_PROFILE_FUNCTION(); m_SpriteSheet = AGE::Texture2D::Create("assets/textures/tilemap.png"); @@ -50,13 +50,50 @@ void Sandbox2DLayer::OnUpdate(AGE::Timestep ts) { for(uint32_t x{0}; x < mapWidth; x++) { float normX = (float)x - ((float)mapWidth / 2.0f); if(m_TileMap.find(s_MapTiles[y * mapWidth + x]) == m_TileMap.end()) { - AGE::Renderer2D::DrawQuad({normX, normY}, {1.0f, 1.0f}, AGE::Texture2D::ErrorTexture()); + AGE::Renderer2D::DrawQuad({normX, normY, -0.1f}, {1.0f, 1.0f}, AGE::Texture2D::ErrorTexture()); continue; } - AGE::Renderer2D::DrawQuad({normX, normY}, {1.0f, 1.0f}, m_TileMap[s_MapTiles[y * mapWidth + x]]); + AGE::Renderer2D::DrawQuad({normX, normY, -0.1f}, {1.0f, 1.0f}, m_TileMap[s_MapTiles[y * mapWidth + x]]); } } + static float lastParticleSpawn{0.0f}; + + static ParticleProps props{glm::vec2{0.0f}, + glm::vec2{0}, + 1.5f, + 45.0f, + 90.0f, + glm::vec4{2.5f, 2.0f, 1.0f, 1.0f}, + glm::vec4{0.6f, 0.0f, 0.0f, 0.3f}, + 0.05f, + 0.1f, + 0.05f, + 0.01, + 1.0f, + 0.0f}; + + lastParticleSpawn += ts; + + if(AGE::Input::IsMousePressed(AGE::Mouse::ButtonLeft)) { + auto [x,y] = AGE::Input::MousePos(); + auto windowWidth = AGE::Application::Instance()->Window()->Width(); + auto windowHeight = AGE::Application::Instance()->Window()->Height(); + + auto bounds = m_CameraController.Bounds(); + auto cameraPos = m_CameraController.GetCamera().Position(); + x = ((float)x/(float)windowWidth) * bounds.Width() - bounds.Width() * 0.5f; + y = bounds.Height() * 0.5f - ((float)y/(float)windowHeight) * bounds.Height(); + + props.Position = {x,y}; + for(int i{0}; i < 10; i++) { + m_Particles.Emit(props); + } + } + + m_Particles.OnUpdate(ts); + m_Particles.Render(); + AGE::Renderer2D::EndScene(); } diff --git a/Sandbox/src/Sandbox2DLayer.h b/Sandbox/src/Sandbox2DLayer.h index b953ac2..6c0d42e 100644 --- a/Sandbox/src/Sandbox2DLayer.h +++ b/Sandbox/src/Sandbox2DLayer.h @@ -23,6 +23,8 @@ class Sandbox2DLayer : public AGE::Layer { std::unordered_map> m_TileMap; friend class Sandbox2DUI; + + ParticleSystem m_Particles; }; class Sandbox2DUI : public AGE::ImGuiLayer {