RenderSystem
This commit is contained in:
@@ -11,7 +11,7 @@ namespace Components
|
|||||||
|
|
||||||
struct Model : Component
|
struct Model : Component
|
||||||
{
|
{
|
||||||
std::string ModelFile;
|
const char* ModelFile;
|
||||||
Color Color;
|
Color Color;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
#include "RenderSystem.h"
|
||||||
|
#include "World.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Systems::RenderSystem::OnComponentCreated( std::string type, std:: shared_ptr<Component> component )
|
||||||
|
{
|
||||||
|
if(type == "Model")
|
||||||
|
{
|
||||||
|
auto modelComponent = std::static_pointer_cast<Components::Model>(component);
|
||||||
|
|
||||||
|
if (m_CachedModels.find(modelComponent->ModelFile) != m_CachedModels.end()) {
|
||||||
|
m_CachedModels[modelComponent->ModelFile] = new Model(modelComponent->ModelFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::RenderSystem::UpdateEntity( double dt, EntityID entity, EntityID parent )
|
||||||
|
{
|
||||||
|
auto modelComponent = m_World->GetComponent<Components::Model>(entity, "Model");
|
||||||
|
if (modelComponent == nullptr)
|
||||||
|
return;
|
||||||
|
auto transformComponent = m_World->GetComponent<Components::Transform>(entity, "Transform");
|
||||||
|
if (transformComponent == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Model* model = m_CachedModels[modelComponent->ModelFile];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
m_Renderer->AddModelToDraw(model, transformComponent->Position, transformComponent->Orientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Systems::RenderSystem::Update( double dt )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
#ifndef RenderSystem_h__
|
||||||
|
#define RenderSystem_h__
|
||||||
|
|
||||||
|
#include "System.h"
|
||||||
|
#include "Model.h"
|
||||||
|
#include "Texture.h"
|
||||||
|
#include "Components/Model.h"
|
||||||
|
#include "Components/Transform.h"
|
||||||
|
#include "Renderer.h"
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
|
namespace Systems
|
||||||
|
{
|
||||||
|
|
||||||
|
class RenderSystem : public System
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RenderSystem(World* world, std::shared_ptr<Renderer> renderer)
|
||||||
|
: System(world), m_Renderer(renderer) {}
|
||||||
|
|
||||||
|
|
||||||
|
std::unordered_map<std::string, Model*> m_CachedModels;
|
||||||
|
|
||||||
|
|
||||||
|
void AddModelToDraw();
|
||||||
|
void OnComponentCreated(std::string type, std:: shared_ptr<Component> component) override;
|
||||||
|
void UpdateEntity(double dt, EntityID entity, EntityID parent) override;
|
||||||
|
void Update(double dt) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::shared_ptr<Renderer> m_Renderer;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif //RenderSystem_h__
|
||||||
Reference in New Issue
Block a user