Optimizations

This commit is contained in:
2014-03-13 14:01:15 +01:00
parent f8f9203141
commit b34d2d3dd0
10 changed files with 34 additions and 32 deletions
+3
View File
@@ -17,4 +17,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal
+3
View File
@@ -10,7 +10,10 @@ namespace Components
struct Collision : Component
{
Collision() : Phantom(false), Interested(false) { }
bool Phantom;
bool Interested;
std::vector<EntityID> CollidingEntities;
};
+1 -1
View File
@@ -54,6 +54,7 @@
<OutDir>$(SolutionDir)bin\</OutDir>
<IntDir>$(SolutionDir)obj\$(ProjectName)\</IntDir>
<TargetName>$(ProjectName)-$(Configuration)</TargetName>
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@@ -87,7 +88,6 @@
<DebugInformationFormat>None</DebugInformationFormat>
</ClCompile>
<Link>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>OpenAL32.lib;opengl32.lib;glu32.lib;SOIL.lib;glew32s.lib;glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
+1
View File
@@ -100,6 +100,7 @@ void GameWorld::Initialize()
AddComponent<Components::Input>(m_Player, "Input");
collision = AddComponent<Components::Collision>(m_Player, "Collision");
collision->Phantom = false;
collision->Interested = true;
bounds = AddComponent<Components::Bounds>(m_Player, "Bounds");
bounds->Origin = glm::vec3(transform->Position.x, transform->Position.y - 4, transform->Position.z + 3);
bounds->VolumeVector = glm::vec3(4.f,0.7f,4);
+13 -11
View File
@@ -233,12 +233,13 @@ void Renderer::DrawShadowMap()
m_ShaderProgramShadows.Bind();
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
for (int i = 0; i < ModelsToRender.size(); i++)
for (auto tuple : ModelsToRender)
{
ModelData* modelData = ModelsToRender.at(i);
auto model = modelData->model;
Model* 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));
glBindVertexArray(model->VAO);
@@ -268,14 +269,15 @@ void Renderer::DrawModels(ShaderProgram &shader)
glm::mat4 cameraMatrix = m_Camera->ProjectionMatrix() * m_Camera->ViewMatrix();
glm::mat4 MVP;
for (int i = 0; i < ModelsToRender.size(); i++)
for (auto tuple : ModelsToRender)
{
ModelData* modelData = ModelsToRender.at(i);
auto model = modelData->model;
Model* 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(), "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()));
glBindVertexArray(model->VAO);
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)
{
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
ModelsToRender.push_back(new ModelData(model, ModelMatrix));
ModelsToRender.push_back(std::make_tuple(model.get(), modelMatrix));
}
void Renderer::AddPointLightToDraw(
+2 -10
View File
@@ -30,15 +30,7 @@ public:
int HEIGHT, WIDTH;
struct ModelData
{
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;
std::list<std::tuple<Model*, glm::mat4>> ModelsToRender;
int Lights;
std::vector<float> Light_position;
std::vector<float> Light_specular;
@@ -47,7 +39,7 @@ public:
std::vector<float> Light_linearAttenuation;
std::vector<float> Light_quadraticAttenuation;
std::vector<float> Light_spotExponent;
std::vector<std::tuple<glm::mat4, bool>> AABBsToRender;
std::list<std::tuple<glm::mat4, bool>> AABBsToRender;
Renderer();
+6 -1
View File
@@ -20,6 +20,10 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID
// Clear old collisions
collisionComponent->CollidingEntities.clear();
// Quit out if we're not interested in collision events
if (!collisionComponent->Interested)
return;
auto entities = m_World->GetEntities();
for (auto pair : *entities) {
@@ -43,7 +47,8 @@ void Systems::CollisionSystem::UpdateEntity(double dt, EntityID entity, EntityID
//pair.first, pair.second;
if(entity == entity2)
break;
continue;
Intersects(entity, entity2);
}
}
@@ -9,9 +9,6 @@ Systems::LevelGenerationSystem::LevelGenerationSystem( World* world )
void Systems::LevelGenerationSystem::SpawnObstacle()
{
typeRandom = 0 + (rand() % 3);
@@ -75,7 +72,7 @@ void Systems::LevelGenerationSystem::Update( double dt )
elapsedtime = 0;
}
std::vector<EntityID> removethis;
std::list<EntityID> removethis;
for(auto ent : obstacles)
{
@@ -85,7 +82,6 @@ void Systems::LevelGenerationSystem::Update( double dt )
if(transformComponent->Position.z > 100)
{
removethis.push_back(ent);
}
}
+1 -1
View File
@@ -54,7 +54,7 @@ void Systems::SoundSystem::UpdateEntity(double dt, EntityID entity, EntityID par
auto soundEmitter = m_World->GetComponent<Components::SoundEmitter>(entity, "SoundEmitter");
if(soundEmitter != nullptr)
{
ALuint source = m_Source[soundEmitter.get()];
ALuint source = m_Source[soundEmitter];
alSourcei(source, AL_GAIN, soundEmitter->Gain);
alSourcei(source, AL_MAX_DISTANCE, soundEmitter->MaxDistance);
alSourcei(source, AL_REFERENCE_DISTANCE, soundEmitter->ReferenceDistance);
+3 -3
View File
@@ -60,7 +60,7 @@ public:
std::shared_ptr<T> AddComponent(EntityID entity, std::string componentType);
std::shared_ptr<Component> AddComponent(EntityID entity, std::string componentType);
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);*/
@@ -117,9 +117,9 @@ std::shared_ptr<T> World::AddComponent(EntityID entity, std::string componentTyp
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__