Optimizations
This commit is contained in:
@@ -17,4 +17,7 @@ Global
|
|||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
GlobalSection(Performance) = preSolution
|
||||||
|
HasPerformanceSessions = true
|
||||||
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ namespace Components
|
|||||||
|
|
||||||
struct Collision : Component
|
struct Collision : Component
|
||||||
{
|
{
|
||||||
|
Collision() : Phantom(false), Interested(false) { }
|
||||||
|
|
||||||
bool Phantom;
|
bool Phantom;
|
||||||
|
bool Interested;
|
||||||
std::vector<EntityID> CollidingEntities;
|
std::vector<EntityID> CollidingEntities;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
<OutDir>$(SolutionDir)bin\</OutDir>
|
<OutDir>$(SolutionDir)bin\</OutDir>
|
||||||
<IntDir>$(SolutionDir)obj\$(ProjectName)\</IntDir>
|
<IntDir>$(SolutionDir)obj\$(ProjectName)\</IntDir>
|
||||||
<TargetName>$(ProjectName)-$(Configuration)</TargetName>
|
<TargetName>$(ProjectName)-$(Configuration)</TargetName>
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
@@ -87,7 +88,6 @@
|
|||||||
<DebugInformationFormat>None</DebugInformationFormat>
|
<DebugInformationFormat>None</DebugInformationFormat>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ void GameWorld::Initialize()
|
|||||||
AddComponent<Components::Input>(m_Player, "Input");
|
AddComponent<Components::Input>(m_Player, "Input");
|
||||||
collision = AddComponent<Components::Collision>(m_Player, "Collision");
|
collision = AddComponent<Components::Collision>(m_Player, "Collision");
|
||||||
collision->Phantom = false;
|
collision->Phantom = false;
|
||||||
|
collision->Interested = true;
|
||||||
bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
|
bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
|
||||||
bounds->Origin = glm::vec3(transform->Position.x, transform->Position.y - 4, transform->Position.z + 3);
|
bounds->Origin = glm::vec3(transform->Position.x, transform->Position.y - 4, transform->Position.z + 3);
|
||||||
bounds->VolumeVector = glm::vec3(4.f,0.7f,4);
|
bounds->VolumeVector = glm::vec3(4.f,0.7f,4);
|
||||||
|
|||||||
@@ -233,12 +233,13 @@ void Renderer::DrawShadowMap()
|
|||||||
|
|
||||||
m_ShaderProgramShadows.Bind();
|
m_ShaderProgramShadows.Bind();
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
for (int i = 0; i < ModelsToRender.size(); i++)
|
for (auto tuple : ModelsToRender)
|
||||||
{
|
{
|
||||||
ModelData* modelData = ModelsToRender.at(i);
|
Model* model;
|
||||||
auto model = modelData->model;
|
glm::mat4 modelMatrix;
|
||||||
|
std::tie(model, modelMatrix) = tuple;
|
||||||
|
|
||||||
MVP = depthCamera * modelData->ModelMatrix;
|
MVP = depthCamera * modelMatrix;
|
||||||
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramShadows.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
glUniformMatrix4fv(glGetUniformLocation(m_ShaderProgramShadows.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
|
|
||||||
glBindVertexArray(model->VAO);
|
glBindVertexArray(model->VAO);
|
||||||
@@ -268,14 +269,15 @@ void Renderer::DrawModels(ShaderProgram &shader)
|
|||||||
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
|
||||||
|
|
||||||
glm::mat4 MVP;
|
glm::mat4 MVP;
|
||||||
for (int i = 0; i < ModelsToRender.size(); i++)
|
for (auto tuple : ModelsToRender)
|
||||||
{
|
{
|
||||||
ModelData* modelData = ModelsToRender.at(i);
|
Model* model;
|
||||||
auto model = modelData->model;
|
glm::mat4 modelMatrix;
|
||||||
|
std::tie(model, modelMatrix) = tuple;
|
||||||
|
|
||||||
MVP = cameraMatrix * modelData->ModelMatrix;
|
MVP = cameraMatrix * modelMatrix;
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "MVP"), 1, GL_FALSE, glm::value_ptr(MVP));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelData->ModelMatrix));
|
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "model"), 1, GL_FALSE, glm::value_ptr(modelMatrix));
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
glUniformMatrix4fv(glGetUniformLocation(shader.GetHandle(), "view"), 1, GL_FALSE, glm::value_ptr(m_Camera->ViewMatrix()));
|
||||||
glBindVertexArray(model->VAO);
|
glBindVertexArray(model->VAO);
|
||||||
for (auto texGroup : model->TextureGroups) {
|
for (auto texGroup : model->TextureGroups) {
|
||||||
@@ -298,9 +300,9 @@ void Renderer::AddTextToDraw()
|
|||||||
|
|
||||||
void Renderer::AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale)
|
void Renderer::AddModelToDraw(std::shared_ptr<Model> model, glm::vec3 position, glm::quat orientation, glm::vec3 scale)
|
||||||
{
|
{
|
||||||
glm::mat4 ModelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
glm::mat4 modelMatrix = glm::translate(glm::mat4(), position) * glm::toMat4(orientation) * glm::scale(scale);
|
||||||
// You can now use ModelMatrix to build the MVP matrix
|
// You can now use ModelMatrix to build the MVP matrix
|
||||||
ModelsToRender.push_back(new ModelData(model, ModelMatrix));
|
ModelsToRender.push_back(std::make_tuple(model.get(), modelMatrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::AddPointLightToDraw(
|
void Renderer::AddPointLightToDraw(
|
||||||
|
|||||||
@@ -30,15 +30,7 @@ public:
|
|||||||
|
|
||||||
int HEIGHT, WIDTH;
|
int HEIGHT, WIDTH;
|
||||||
|
|
||||||
struct ModelData
|
std::list<std::tuple<Model*, glm::mat4>> ModelsToRender;
|
||||||
{
|
|
||||||
std::shared_ptr<Model> model;
|
|
||||||
glm::mat4 ModelMatrix;
|
|
||||||
ModelData(std::shared_ptr<Model> _model, glm::mat4 _modelMatrix)
|
|
||||||
: model(_model), ModelMatrix(_modelMatrix) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::vector<ModelData*> ModelsToRender;
|
|
||||||
int Lights;
|
int Lights;
|
||||||
std::vector<float> Light_position;
|
std::vector<float> Light_position;
|
||||||
std::vector<float> Light_specular;
|
std::vector<float> Light_specular;
|
||||||
@@ -47,7 +39,7 @@ public:
|
|||||||
std::vector<float> Light_linearAttenuation;
|
std::vector<float> Light_linearAttenuation;
|
||||||
std::vector<float> Light_quadraticAttenuation;
|
std::vector<float> Light_quadraticAttenuation;
|
||||||
std::vector<float> Light_spotExponent;
|
std::vector<float> Light_spotExponent;
|
||||||
std::vector<std::tuple<glm::mat4, bool>> AABBsToRender;
|
std::list<std::tuple<glm::mat4, bool>> AABBsToRender;
|
||||||
|
|
||||||
Renderer();
|
Renderer();
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|||||||
// Clear old collisions
|
// Clear old collisions
|
||||||
collisionComponent->CollidingEntities.clear();
|
collisionComponent->CollidingEntities.clear();
|
||||||
|
|
||||||
|
// Quit out if we're not interested in collision events
|
||||||
|
if (!collisionComponent->Interested)
|
||||||
|
return;
|
||||||
|
|
||||||
auto entities = m_World->GetEntities();
|
auto entities = m_World->GetEntities();
|
||||||
|
|
||||||
for (auto pair : *entities) {
|
for (auto pair : *entities) {
|
||||||
@@ -43,7 +47,8 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID
|
|||||||
|
|
||||||
//pair.first, pair.second;
|
//pair.first, pair.second;
|
||||||
if(entity == entity2)
|
if(entity == entity2)
|
||||||
break;
|
continue;
|
||||||
|
|
||||||
Intersects(entity, entity2);
|
Intersects(entity, entity2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ Systems::LevelGenerationSystem::LevelGenerationSystem( World* world )
|
|||||||
|
|
||||||
void Systems::LevelGenerationSystem::SpawnObstacle()
|
void Systems::LevelGenerationSystem::SpawnObstacle()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typeRandom = 0 + (rand() % 3);
|
typeRandom = 0 + (rand() % 3);
|
||||||
|
|
||||||
|
|
||||||
@@ -75,7 +72,7 @@ void Systems::LevelGenerationSystem::Update( double dt )
|
|||||||
elapsedtime = 0;
|
elapsedtime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<EntityID> removethis;
|
std::list<EntityID> removethis;
|
||||||
|
|
||||||
for(auto ent : obstacles)
|
for(auto ent : obstacles)
|
||||||
{
|
{
|
||||||
@@ -85,7 +82,6 @@ void Systems::LevelGenerationSystem::Update( double dt )
|
|||||||
if(transformComponent->Position.z > 100)
|
if(transformComponent->Position.z > 100)
|
||||||
{
|
{
|
||||||
removethis.push_back(ent);
|
removethis.push_back(ent);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
|
|||||||
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity, "SoundEmitter");
|
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity, "SoundEmitter");
|
||||||
if(soundEmitter != nullptr)
|
if(soundEmitter != nullptr)
|
||||||
{
|
{
|
||||||
ALuint source = m_Source[soundEmitter.get()];
|
ALuint source = m_Source[soundEmitter];
|
||||||
alSourcei(source, AL_GAIN, soundEmitter->Gain);
|
alSourcei(source, AL_GAIN, soundEmitter->Gain);
|
||||||
alSourcei(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance);
|
alSourcei(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance);
|
||||||
alSourcei(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance);
|
alSourcei(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public:
|
|||||||
std::shared_ptr<T> AddComponent(EntityID entity, std::string componentType);
|
std::shared_ptr<T> AddComponent(EntityID entity, std::string componentType);
|
||||||
std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType);
|
std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType);
|
||||||
template <class T>
|
template <class T>
|
||||||
std::shared_ptr<T> GetComponent(EntityID entity, std::string componentType);
|
T* GetComponent(EntityID entity, std::string componentType);
|
||||||
|
|
||||||
/*std::vector<EntityID> GetEntityChildren(EntityID entity);*/
|
/*std::vector<EntityID> GetEntityChildren(EntityID entity);*/
|
||||||
|
|
||||||
@@ -117,9 +117,9 @@ std::shared_ptr<T> World::AddComponent(EntityID entity, std::string componentTyp
|
|||||||
|
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
std::shared_ptr<T> World::GetComponent(EntityID entity, std::string componentType)
|
T* World::GetComponent(EntityID entity, std::string componentType)
|
||||||
{
|
{
|
||||||
return std::static_pointer_cast<T>(m_EntityComponents[entity][componentType]);
|
return (T*)m_EntityComponents[entity][componentType].get();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // World_h__
|
#endif // World_h__
|
||||||
Reference in New Issue
Block a user