Riyyi
4 years ago
5 changed files with 88 additions and 11 deletions
@ -0,0 +1,37 @@
|
||||
#include <glm/ext/matrix_transform.hpp> // glm::translate, glm::rotate, glm::scale, glm::radians |
||||
|
||||
#include "inferno/assertions.h" |
||||
#include "inferno/log.h" |
||||
#include "inferno/render/renderer.h" |
||||
#include "inferno/scene/components.h" |
||||
#include "inferno/scene/entity.h" |
||||
#include "inferno/systems/render.h" |
||||
|
||||
namespace Inferno { |
||||
|
||||
RenderSystem* RenderSystem::s_instance = nullptr; |
||||
|
||||
void RenderSystem::initialize() |
||||
{ |
||||
ASSERT(!s_instance, "RenderSystem already exists!"); |
||||
s_instance = this; |
||||
|
||||
dbg(Log::Info) << "RenderSystem initialized"; |
||||
} |
||||
|
||||
void RenderSystem::render() |
||||
{ |
||||
auto group = m_registry->group<TransformComponent, SpriteComponent>(); |
||||
|
||||
for(auto&& [entity, transform, sprite] : group.each()) { |
||||
Renderer2D::the().drawQuad(transform, sprite.color, sprite.texture); |
||||
} |
||||
} |
||||
|
||||
void RenderSystem::destroy() |
||||
{ |
||||
delete s_instance; |
||||
s_instance = nullptr; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,30 @@
|
||||
#ifndef RENDER_SYSTEM_H |
||||
#define RENDER_SYSTEM_H |
||||
|
||||
#include <memory> //std::shared_ptr |
||||
|
||||
#include "entt/entity/registry.hpp" // entt::entity, entt::registry |
||||
|
||||
#include "inferno/render/renderer.h" |
||||
|
||||
namespace Inferno { |
||||
|
||||
class RenderSystem { |
||||
public: |
||||
void initialize(); |
||||
void render(); |
||||
void destroy(); |
||||
|
||||
void setRegistry(const std::shared_ptr<entt::registry>& registry) { m_registry = registry; }; |
||||
|
||||
static inline RenderSystem& the() { return *s_instance; } |
||||
|
||||
private: |
||||
std::shared_ptr<entt::registry> m_registry; |
||||
|
||||
static RenderSystem* s_instance; |
||||
}; |
||||
|
||||
} |
||||
|
||||
#endif // RENDER_SYSTEM_H
|
Loading…
Reference in new issue