Merge branch 'master' of github.com:sippeangelo/Escape-the-Dawn

This commit is contained in:
Tobias Dahl
2014-03-09 21:15:51 +01:00
3 changed files with 85 additions and 1 deletions
+1 -1
View File
@@ -11,7 +11,7 @@ namespace Components
struct Model : Component
{
std::string ModelFile;
const char* ModelFile;
Color Color;
};
+43
View File
@@ -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 )
{
}
+41
View File
@@ -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__