some cleanup
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
#include "../Core/ComponentWrapper.h"
|
#include "../Core/ComponentWrapper.h"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include "Model.h"
|
#include "Model.h"
|
||||||
|
|
||||||
#include "RenderJob.h"
|
#include "RenderJob.h"
|
||||||
#include "../Core/ResourceManager.h"
|
#include "../Core/ResourceManager.h"
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
@@ -30,7 +29,6 @@ struct ModelJob : RenderJob
|
|||||||
Entity = modelComponent.EntityID;
|
Entity = modelComponent.EntityID;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
unsigned int TextureID;
|
unsigned int TextureID;
|
||||||
unsigned int ShaderID;
|
unsigned int ShaderID;
|
||||||
|
|
||||||
@@ -45,13 +43,10 @@ struct ModelJob : RenderJob
|
|||||||
unsigned int StartIndex = 0;
|
unsigned int StartIndex = 0;
|
||||||
unsigned int EndIndex = 0;
|
unsigned int EndIndex = 0;
|
||||||
|
|
||||||
|
|
||||||
void CalculateHash() override
|
void CalculateHash() override
|
||||||
{
|
{
|
||||||
Hash = TextureID;
|
Hash = TextureID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -15,39 +15,6 @@
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
|
|
||||||
struct TransparentModelJob : RenderJob
|
|
||||||
{
|
|
||||||
unsigned int ShaderID = 0;
|
|
||||||
unsigned int TextureID = 0;
|
|
||||||
|
|
||||||
//TODO: RENDERER: Not sure if the best solution for pickingColor to entity link is this
|
|
||||||
EntityID Entity;
|
|
||||||
|
|
||||||
glm::mat4 Matrix;
|
|
||||||
const Texture* DiffuseTexture;
|
|
||||||
const Texture* NormalTexture;
|
|
||||||
const Texture* SpecularTexture;
|
|
||||||
float Shininess = 0.f;
|
|
||||||
glm::vec4 Color;
|
|
||||||
const Model* Model = nullptr;
|
|
||||||
unsigned int StartIndex = 0;
|
|
||||||
unsigned int EndIndex = 0;
|
|
||||||
|
|
||||||
// Animation
|
|
||||||
Skeleton* Skeleton = nullptr;
|
|
||||||
bool NoRootMotion = true;
|
|
||||||
std::string AnimationName;
|
|
||||||
double AnimationTime = 0;
|
|
||||||
|
|
||||||
void CalculateHash() override
|
|
||||||
{
|
|
||||||
Hash = TextureID;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct SpriteJob : RenderJob
|
struct SpriteJob : RenderJob
|
||||||
{
|
{
|
||||||
unsigned int ShaderID = 0;
|
unsigned int ShaderID = 0;
|
||||||
|
|||||||
@@ -42,16 +42,16 @@ private:
|
|||||||
bool OnSetCamera(const Events::SetCamera &event);
|
bool OnSetCamera(const Events::SetCamera &event);
|
||||||
EntityID m_CurrentCamera = -1;
|
EntityID m_CurrentCamera = -1;
|
||||||
|
|
||||||
void SwitchCamera(EntityID entity);
|
void switchCamera(EntityID entity);
|
||||||
|
|
||||||
void Initialize();
|
void initialize();
|
||||||
void UpdateCamera(World* world, double dt);
|
void updateCamera(World* world, double dt);
|
||||||
void UpdateProjectionMatrix(ComponentWrapper& cameraComponent);
|
void updateProjectionMatrix(ComponentWrapper& cameraComponent);
|
||||||
glm::mat4 m_ViewMatrix;
|
glm::mat4 m_ViewMatrix;
|
||||||
glm::mat4 m_ProjectionMatrix;
|
glm::mat4 m_ProjectionMatrix;
|
||||||
|
|
||||||
glm::mat4 ModelMatrix(EntityID entity);
|
glm::mat4 ModelMatrix(EntityID entity);
|
||||||
void FillModels(std::list<std::shared_ptr<RenderJob>>& jobs);
|
void fillModels(std::list<std::shared_ptr<RenderJob>>& jobs);
|
||||||
|
|
||||||
EventRelay<RenderSystem, Events::InputCommand> m_EInputCommand;
|
EventRelay<RenderSystem, Events::InputCommand> m_EInputCommand;
|
||||||
bool OnInputCommand(const Events::InputCommand& e);
|
bool OnInputCommand(const Events::InputCommand& e);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ RenderSystem::RenderSystem(EventBroker* eventBrokerer, const IRenderer* renderer
|
|||||||
{
|
{
|
||||||
m_Renderer = renderer;
|
m_Renderer = renderer;
|
||||||
m_RenderFrame = renderFrame;
|
m_RenderFrame = renderFrame;
|
||||||
Initialize();
|
initialize();
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &RenderSystem::OnSetCamera);
|
EVENT_SUBSCRIBE_MEMBER(m_ESetCamera, &RenderSystem::OnSetCamera);
|
||||||
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &RenderSystem::OnInputCommand);
|
EVENT_SUBSCRIBE_MEMBER(m_EInputCommand, &RenderSystem::OnInputCommand);
|
||||||
|
|
||||||
@@ -16,7 +16,6 @@ RenderSystem::RenderSystem(EventBroker* eventBrokerer, const IRenderer* renderer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool RenderSystem::OnSetCamera(const Events::SetCamera &event)
|
bool RenderSystem::OnSetCamera(const Events::SetCamera &event)
|
||||||
{
|
{
|
||||||
auto cameras = m_World->GetComponents("Camera");
|
auto cameras = m_World->GetComponents("Camera");
|
||||||
@@ -24,14 +23,14 @@ bool RenderSystem::OnSetCamera(const Events::SetCamera &event)
|
|||||||
if (cameras != nullptr) {
|
if (cameras != nullptr) {
|
||||||
for (auto it = cameras->begin(); it != cameras->end(); it++) {
|
for (auto it = cameras->begin(); it != cameras->end(); it++) {
|
||||||
if ((std::string)(*it)["Name"] == event.Name) {
|
if ((std::string)(*it)["Name"] == event.Name) {
|
||||||
SwitchCamera((*it).EntityID);
|
switchCamera((*it).EntityID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderSystem::SwitchCamera(EntityID entity)
|
void RenderSystem::switchCamera(EntityID entity)
|
||||||
{
|
{
|
||||||
if(m_World->HasComponent(entity, "Camera")) {
|
if(m_World->HasComponent(entity, "Camera")) {
|
||||||
if (m_World->HasComponent(m_CurrentCamera, "Model")) {
|
if (m_World->HasComponent(m_CurrentCamera, "Model")) {
|
||||||
@@ -50,12 +49,12 @@ void RenderSystem::SwitchCamera(EntityID entity)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderSystem::Initialize()
|
void RenderSystem::initialize()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderSystem::UpdateProjectionMatrix(ComponentWrapper& cameraComponent)
|
void RenderSystem::updateProjectionMatrix(ComponentWrapper& cameraComponent)
|
||||||
{
|
{
|
||||||
double fov = cameraComponent["FOV"];
|
double fov = cameraComponent["FOV"];
|
||||||
double aspectRatio = m_Renderer->Resolution().Width / m_Renderer->Resolution().Height;
|
double aspectRatio = m_Renderer->Resolution().Width / m_Renderer->Resolution().Height;
|
||||||
@@ -126,7 +125,7 @@ glm::mat4 RenderSystem::ModelMatrix(EntityID entity)
|
|||||||
return modelMatrix;
|
return modelMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderSystem::FillModels(std::list<std::shared_ptr<RenderJob>>& jobs)
|
void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs)
|
||||||
{
|
{
|
||||||
auto models = m_World->GetComponents("Model");
|
auto models = m_World->GetComponents("Model");
|
||||||
if (models == nullptr) {
|
if (models == nullptr) {
|
||||||
@@ -173,18 +172,19 @@ void RenderSystem::Update(World* world, double dt)
|
|||||||
m_World = world;
|
m_World = world;
|
||||||
m_EventBroker->Process<RenderSystem>();
|
m_EventBroker->Process<RenderSystem>();
|
||||||
|
|
||||||
UpdateCamera(world, dt);
|
updateCamera(world, dt);
|
||||||
|
|
||||||
|
//Only supports opaque geometry atm
|
||||||
m_RenderFrame->Clear();
|
m_RenderFrame->Clear();
|
||||||
RenderScene* rs = new RenderScene();
|
RenderScene* rs = new RenderScene();
|
||||||
rs->Camera = m_Camera;
|
rs->Camera = m_Camera;
|
||||||
rs->ViewPort = Rectangle(1280, 720);
|
rs->ViewPort = Rectangle(1280, 720);
|
||||||
FillModels(rs->ForwardJobs);
|
fillModels(rs->ForwardJobs);
|
||||||
m_RenderFrame->Add(*rs);
|
m_RenderFrame->Add(*rs);
|
||||||
delete rs;
|
delete rs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderSystem::UpdateCamera(World* world, double dt)
|
void RenderSystem::updateCamera(World* world, double dt)
|
||||||
{
|
{
|
||||||
static DebugCameraInputController<RenderSystem> firstPersonInputController(m_EventBroker, -1);
|
static DebugCameraInputController<RenderSystem> firstPersonInputController(m_EventBroker, -1);
|
||||||
|
|
||||||
@@ -196,9 +196,9 @@ void RenderSystem::UpdateCamera(World* world, double dt)
|
|||||||
if ((*it).EntityID == m_CurrentCamera) {
|
if ((*it).EntityID == m_CurrentCamera) {
|
||||||
it++;
|
it++;
|
||||||
if (it != cameras->end()) {
|
if (it != cameras->end()) {
|
||||||
SwitchCamera((*it).EntityID);
|
switchCamera((*it).EntityID);
|
||||||
} else {
|
} else {
|
||||||
SwitchCamera((*cameras->begin()).EntityID);
|
switchCamera((*cameras->begin()).EntityID);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -227,7 +227,7 @@ void RenderSystem::UpdateCamera(World* world, double dt)
|
|||||||
m_Camera->SetPosition(position);
|
m_Camera->SetPosition(position);
|
||||||
m_Camera->SetOrientation(orientation);
|
m_Camera->SetOrientation(orientation);
|
||||||
|
|
||||||
UpdateProjectionMatrix(cameraComponent);
|
updateProjectionMatrix(cameraComponent);
|
||||||
m_Camera->UpdateViewMatrix();
|
m_Camera->UpdateViewMatrix();
|
||||||
} else {
|
} else {
|
||||||
m_Camera = m_DefaultCamera;
|
m_Camera = m_DefaultCamera;
|
||||||
@@ -235,7 +235,7 @@ void RenderSystem::UpdateCamera(World* world, double dt)
|
|||||||
auto cameras = world->GetComponents("Camera");
|
auto cameras = world->GetComponents("Camera");
|
||||||
if (cameras != nullptr) {
|
if (cameras != nullptr) {
|
||||||
ComponentWrapper& cameraC = *cameras->begin();
|
ComponentWrapper& cameraC = *cameras->begin();
|
||||||
SwitchCamera(cameraC.EntityID);
|
switchCamera(cameraC.EntityID);
|
||||||
world->GetComponent(m_CurrentCamera, "Model")["Visible"] = false;
|
world->GetComponent(m_CurrentCamera, "Model")["Visible"] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user