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

Conflicts:
	Escape-the-Dawn/Escape-the-Dawn.vcxproj.filters
This commit is contained in:
Adam
2014-03-09 22:42:49 +01:00
15 changed files with 308 additions and 13 deletions
+37
View File
@@ -0,0 +1,37 @@
#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);
}
+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__