Merge remote-tracking branch 'origin/master' into ResolutionChange

This commit is contained in:
Tleety
2016-02-19 13:17:31 +01:00
28 changed files with 639 additions and 69 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ project(TacticalZ-Engine)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(GLFW REQUIRED)
find_package(Boost REQUIRED COMPONENTS system filesystem thread chrono program_options)
find_package(Boost REQUIRED COMPONENTS system filesystem thread chrono timer program_options)
find_package(assimp REQUIRED)
find_package(ZLIB REQUIRED)
find_package(PNG REQUIRED)
+52 -6
View File
@@ -366,7 +366,8 @@ bool AABBvsTriangle(const AABB& box,
float verticalStepHeight,
bool& isOnGround,
glm::vec3& boxVelocity,
glm::vec3& outResolution)
glm::vec3& outResolution,
bool resolveCollision)
{
//Check so we don't have a zero area triangle when calculating the normal.
//Also, don't check a triangle facing away from the player.
@@ -426,7 +427,7 @@ bool AABBvsTriangle(const AABB& box,
//if projections don't overlap, return false.
if (!rectangleVsTriangle(boxMin, boxMax, t2D, resolutionVector, resolutionDist, pushedFromTriangleLine)) {
return false;
} else {
} else if (resolveCollision) {
//Overwrite the smallest resolution if this is smaller.
if (resolutionDist < resolveShortest.DistanceSq) {
resolveShortest.Vector = glm::vec3(0.f);
@@ -463,6 +464,11 @@ bool AABBvsTriangle(const AABB& box,
if (glm::abs(t) > 1) {
return false;
}
if (!resolveCollision) {
return true;
}
glm::vec3 cornerResolution = (1+t) * diagonal;
//Overwrite the smallest resolution if cornerResolution is smaller.
float lenSq = glm::length2(cornerResolution);
@@ -537,7 +543,8 @@ bool AABBvsTriangles(const AABB& box,
glm::vec3& boxVelocity,
float verticalStepHeight,
bool& isOnGround,
glm::vec3& outResolutionVector)
glm::vec3& outResolutionVector,
bool resolveCollision)
{
bool hit = false;
@@ -553,7 +560,7 @@ bool AABBvsTriangles(const AABB& box,
};
glm::vec3 outVec;
bool collideWithGround = isOnGround;
if (AABBvsTriangle(newBox, triVertices, originalBoxVelocity, verticalStepHeight, collideWithGround, boxVelocity, outVec)) {
if (AABBvsTriangle(newBox, triVertices, originalBoxVelocity, verticalStepHeight, collideWithGround, boxVelocity, outVec, resolveCollision)) {
hit = true;
outResolutionVector += outVec;
newBox = AABB::FromOriginSize(newBox.Origin() + outVec, newBox.Size());
@@ -569,6 +576,44 @@ bool AABBvsTriangles(const AABB& box,
return hit;
}
bool AABBvsTriangles(const AABB& box,
const RawModel::Vertex* modelVertices,
const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix,
glm::vec3& boxVelocity,
float verticalStepHeight,
bool& isOnGround,
glm::vec3& outResolutionVector)
{
return AABBvsTriangles(box,
modelVertices,
modelIndices,
modelMatrix,
boxVelocity,
verticalStepHeight,
isOnGround,
outResolutionVector,
true);
}
bool AABBvsTriangles(const AABB& box,
const RawModel::Vertex* modelVertices,
const std::vector<unsigned int>& modelIndices,
const glm::mat4& modelMatrix)
{
glm::vec3 vel, outres;
bool g;
return AABBvsTriangles(box,
modelVertices,
modelIndices,
modelMatrix,
vel,
0.f,
g,
outres,
false);
}
boost::optional<EntityAABB> EntityAbsoluteAABB(EntityWrapper& entity, bool takeModelBox)
{
AABB modelSpaceBox;
@@ -648,8 +693,9 @@ boost::optional<EntityAABB> EntityFirstHitByRay(const Ray& ray, std::vector<Enti
if (!entityBox.Entity.HasComponent("Model")) {
continue;
}
std::string res = entityBox.Entity["Model"]["Resource"];
if (res.empty()) {
auto& cModel = entityBox.Entity["Model"];
std::string res = cModel["Resource"];
if (res.empty() || (bool)cModel["Transparent"] || !((bool)cModel["Visible"])) {
continue;
}
Model* model;
+76
View File
@@ -0,0 +1,76 @@
#include "Core/PerformanceTimer.h"
#include <ctime>
#include <fstream>
cpu_timer PerformanceTimer::m_Timer;
std::map<std::string, cpu_timer> PerformanceTimer::timers;
std::string PerformanceTimer::currentTimerRunning = "";
void PerformanceTimer::StartTimer(std::string nameOfTimer)
{
timers[nameOfTimer].stop();
timers[nameOfTimer].start();
currentTimerRunning = nameOfTimer;
}
void PerformanceTimer::StartTimerAndStopPrevious(std::string nameOfTimer)
{
//stop the current timer and start some other - useful to not have to stop timers all the time
if (currentTimerRunning != "") {
timers[currentTimerRunning].stop();
}
timers[nameOfTimer].stop();
timers[nameOfTimer].start();
currentTimerRunning = nameOfTimer;
}
void PerformanceTimer::StopTimer(std::string nameOfTimer)
{
timers[nameOfTimer].stop();
currentTimerRunning = nameOfTimer;
}
void PerformanceTimer::SetFrameNumber(int frameNumber)
{
}
void PerformanceTimer::ResetAllTimers()
{
//stop all timers
for (auto aTimer : timers)
{
aTimer.second.stop();
}
currentTimerRunning = "";
timers.clear();
}
void PerformanceTimer::CreateExcelData()
{
//get time
std::time_t t = std::time(NULL);
char tStr[16];
std::strftime(tStr, 32, " %a %H-%M-%S", std::localtime(&t));
std::string time(tStr);
std::string path("TacticalZ");
path += time + ".csv";
std::ofstream someFileStream;
someFileStream.open(path, std::ofstream::out);
someFileStream << "classname" << ',' << "walltime" << ',' << "userTime" << ',' << "systemTime" << '\n';
//write all timers to file
for (auto aTimer : timers)
{
//remove the "class" name in front of the string
auto className = aTimer.first;
if (className.find("class ") != std::string::npos) {
className.replace(0, 6, "");
}
auto wallTime = (double)aTimer.second.elapsed().wall*1e-3;
auto userTime = (double)aTimer.second.elapsed().user*1e-3;
auto systemTime = (double)aTimer.second.elapsed().system*1e-3;
someFileStream << className << "," << wallTime << ',' << userTime << ',' << systemTime << '\n';
}
someFileStream.close();
}
+6
View File
@@ -225,6 +225,12 @@ bool EditorSystem::OnInputCommand(const Events::InputCommand& e)
Enable();
}
}
if (e.Command == "PerformanceTimingResetAllTimers" && e.Value > 0) {
PerformanceTimer::ResetAllTimers();
}
if (e.Command == "PerformanceTimingCreateExcelData" && e.Value > 0) {
PerformanceTimer::CreateExcelData();
}
return true;
}
+9 -3
View File
@@ -38,6 +38,7 @@ bool ButtonSystem::OnMousePress(const Events::MousePress& e)
//You have clicked on a button entity, send pressed event.
Events::ButtonPressed ePressed;
ePressed.Entity = m_PickEntity;
ePressed.EntityName = m_PickEntity.Name();
m_EventBroker->Publish(ePressed);
}
@@ -50,15 +51,20 @@ bool ButtonSystem::OnMouseRelease(const Events::MouseRelease& e)
{
if(!m_MouseIsLocked) {
//Mouse is not locked, send release event.
Events::ButtonReleased eReleased;
m_EventBroker->Publish(eReleased);
m_PickData = m_Renderer->Pick(glm::vec2(e.X, e.Y));
if(m_PickData.Entity != EntityID_Invalid && m_PickData.World == m_World) {
EntityWrapper ent = EntityWrapper(m_World, m_PickData.Entity);
Events::ButtonReleased eReleased;
eReleased.EntityName = m_PickEntity.Name();
eReleased.Entity = m_PickEntity;
m_EventBroker->Publish(eReleased);
if(m_World->HasComponent(m_PickData.Entity, "Button")) {
EntityWrapper ent = EntityWrapper(m_World, m_PickData.Entity);
if (ent == m_PickEntity) {
//The entity you released the mouse button on is the same as you pressed it on. "Clicked"
Events::ButtonClicked eClicked;
eClicked.Entity = m_PickEntity;
eClicked.EntityName = m_PickEntity.Name();
m_EventBroker->Publish(eClicked);
}
+2 -2
View File
@@ -757,7 +757,7 @@ void DrawFinalPass::BindExplosionUniforms(GLuint shaderHandle, std::shared_ptr<E
GLERROR("Bind 19 uniform");
glUniform4fv(glGetUniformLocation(shaderHandle, "AmbientColor"), 1, glm::value_ptr(scene.AmbientColor));
GLERROR("Bind 20 uniform");
glUniform1f(glGetUniformLocation(shaderHandle, "GlowIntensity"), job->GlowIntencity);
glUniform1f(glGetUniformLocation(shaderHandle, "GlowIntensity"), job->GlowIntensity);
GLERROR("END");
}
@@ -796,7 +796,7 @@ void DrawFinalPass::BindModelUniforms(GLuint shaderHandle, std::shared_ptr<Model
GLERROR("Bind 10 uniform");
GLint Location_GlowIntensity = glGetUniformLocation(shaderHandle, "GlowIntensity");
glUniform1f(Location_GlowIntensity, job->GlowIntencity);
glUniform1f(Location_GlowIntensity, job->GlowIntensity);
GLERROR("END");
}
+18 -1
View File
@@ -114,34 +114,48 @@ void Renderer::Draw(RenderFrame& frame)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//Clear other buffers
PerformanceTimer::StartTimer("Renderer-ClearBuffers");
m_PickingPass->ClearPicking();
m_DrawFinalPass->ClearBuffer();
m_DrawBloomPass->ClearBuffer();
PerformanceTimer::StopTimer("Renderer-ClearBuffers");
for (auto scene : frame.RenderScenes){
PerformanceTimer::StartTimer("Renderer-Depth");
SortRenderJobsByDepth(*scene);
GLERROR("SortByDepth");
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Drawing PickingPass");
m_PickingPass->Draw(*scene);
GLERROR("Drawing pickingpass");
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Generate Frustrums");
m_LightCullingPass->GenerateNewFrustum(*scene);
GLERROR("Generate frustums");
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Filling Light List");
m_LightCullingPass->FillLightList(*scene);
GLERROR("Filling light list");
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Light Culling");
m_LightCullingPass->CullLights(*scene);
GLERROR("LightCulling");
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Geometry+Light");
m_DrawFinalPass->Draw(*scene);
GLERROR("Draw Geometry+Light");
//m_DrawScenePass->Draw(*scene);
PerformanceTimer::StartTimerAndStopPrevious("Renderer-Draw Text");
m_TextPass->Draw(*scene, *m_DrawFinalPass->FinalPassFrameBuffer());
GLERROR("Draw Text");
PerformanceTimer::StopTimer("Renderer-Draw Text");
}
PerformanceTimer::StartTimer("Renderer-Draw Bloom");
m_DrawBloomPass->Draw(m_DrawFinalPass->BloomTexture());
PerformanceTimer::StopTimer("Renderer-Draw Bloom");
if (m_DebugTextureToDraw == 0) {
PerformanceTimer::StartTimer("Renderer-Color Correction Pass");
m_DrawColorCorrectionPass->Draw(m_DrawFinalPass->SceneTexture(), m_DrawBloomPass->GaussianTexture(), m_DrawFinalPass->SceneTextureLowRes(), m_DrawFinalPass->BloomTextureLowRes(), frame.Gamma, frame.Exposure);
PerformanceTimer::StopTimer("Renderer-Color Correction Pass");
}
PerformanceTimer::StartTimer("Renderer-Misc Debug Draws");
if (m_DebugTextureToDraw == 1) {
m_DrawScreenQuadPass->Draw(m_DrawFinalPass->SceneTexture());
}
@@ -160,10 +174,13 @@ void Renderer::Draw(RenderFrame& frame)
if (m_DebugTextureToDraw == 6) {
m_DrawScreenQuadPass->Draw(m_PickingPass->PickingTexture());
}
PerformanceTimer::StopTimer("Renderer-Misc Debug Draws");
PerformanceTimer::StartTimer("Renderer-ImGuiRenderPass");
m_ImGuiRenderPass->Draw();
GLERROR("Imgui draw");
glfwSwapBuffers(m_Window);
PerformanceTimer::StopTimer("Renderer-ImGuiRenderPass");
}
PickData Renderer::Pick(glm::vec2 screenCoord)