Add some time usage statistics and minor cleanup and formatting
This commit is contained in:
parent
b29537273b
commit
5d07aba7c4
|
@ -6,14 +6,18 @@
|
||||||
// glm::translate, glm::rotate, glm::scale, glm::perspective
|
// glm::translate, glm::rotate, glm::scale, glm::perspective
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
#include <SFML/Audio.hpp>
|
#include <SFML/Audio.hpp>
|
||||||
#include <SFML/System/Time.hpp>
|
#include <SFML/System/Time.hpp>
|
||||||
#include <utilities/shapes.h>
|
#include <utilities/shapes.h>
|
||||||
#include <utilities/glutils.h>
|
#include <utilities/glutils.h>
|
||||||
#include <utilities/shader.hpp>
|
#include <utilities/shader.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
#include <utilities/timeutils.h>
|
#include <utilities/timeutils.hpp>
|
||||||
|
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
|
using std::setprecision;
|
||||||
|
|
||||||
void runProgram(GLFWwindow* window, CommandLineOptions options)
|
void runProgram(GLFWwindow* window, CommandLineOptions options)
|
||||||
{
|
{
|
||||||
|
@ -31,23 +35,28 @@ void runProgram(GLFWwindow* window, CommandLineOptions options)
|
||||||
// Set default colour after clearing the colour buffer
|
// Set default colour after clearing the colour buffer
|
||||||
glClearColor(0.3f, 0.5f, 0.8f, 1.0f);
|
glClearColor(0.3f, 0.5f, 0.8f, 1.0f);
|
||||||
|
|
||||||
initRenderer(window, options);
|
int w, h;
|
||||||
|
glfwGetWindowSize(window, &w, &h);
|
||||||
|
|
||||||
|
initRenderer(window, w, h);
|
||||||
init_scene(options);
|
init_scene(options);
|
||||||
getTimeDeltaSeconds();
|
Clock c, prof;
|
||||||
|
|
||||||
// Rendering Loop
|
// Rendering Loop
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
// Clear colour and depth buffers
|
// Clear colour and depth buffers
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
int w, h;
|
|
||||||
glfwGetWindowSize(window, &w, &h);
|
glfwGetWindowSize(window, &w, &h);
|
||||||
|
|
||||||
step_scene(getTimeDeltaSeconds());
|
double td = c.getTimeDeltaSeconds();
|
||||||
|
step_scene(td);
|
||||||
|
|
||||||
|
prof.getTimeDeltaSeconds();
|
||||||
updateFrame(window, w, h);
|
updateFrame(window, w, h);
|
||||||
|
cout << "uf: " << setprecision(4) << prof.getTimeDeltaSeconds() / td * 100 << "\t";
|
||||||
renderFrame(window, w, h);
|
renderFrame(window, w, h);
|
||||||
|
cout << "rf: " << setprecision(4) << prof.getTimeDeltaSeconds() / td * 100 << endl << endl;
|
||||||
|
|
||||||
|
|
||||||
// Handle other events
|
// Handle other events
|
||||||
|
|
|
@ -13,9 +13,14 @@
|
||||||
#include <utilities/glfont.h>
|
#include <utilities/glfont.h>
|
||||||
#include <utilities/shader.hpp>
|
#include <utilities/shader.hpp>
|
||||||
|
|
||||||
|
#include <utilities/timeutils.hpp>
|
||||||
|
|
||||||
|
|
||||||
using glm::vec3;
|
using glm::vec3;
|
||||||
using glm::vec4;
|
using glm::vec4;
|
||||||
using glm::mat4;
|
using glm::mat4;
|
||||||
|
using std::cout;
|
||||||
|
using std::endl;
|
||||||
typedef unsigned int uint;
|
typedef unsigned int uint;
|
||||||
|
|
||||||
sf::Sound* sound;
|
sf::Sound* sound;
|
||||||
|
@ -233,9 +238,8 @@ void renderNode(SceneNode* node, Gloom::Shader* parent_shader, vector<NodeDistSh
|
||||||
#undef cache
|
#undef cache
|
||||||
|
|
||||||
if (do_recursive)
|
if (do_recursive)
|
||||||
for(SceneNode* child : node->children) {
|
for(SceneNode* child : node->children)
|
||||||
renderNode(child, node_shader, transparent_nodes, true);
|
renderNode(child, node_shader, transparent_nodes, true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw
|
// draw
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include <utilities/mesh.h>
|
#include <utilities/mesh.h>
|
||||||
#include <utilities/shader.hpp>
|
#include <utilities/shader.hpp>
|
||||||
#include <utilities/shapes.h>
|
#include <utilities/shapes.h>
|
||||||
#include <utilities/timeutils.h>
|
#include <utilities/timeutils.hpp>
|
||||||
#include <utilities/glfont.h>
|
#include <utilities/glfont.h>
|
||||||
#include <utilities/glmhelpers.hpp>
|
#include <utilities/glmhelpers.hpp>
|
||||||
|
|
||||||
|
@ -45,7 +45,6 @@ vector<SceneNode*> movingNodes;
|
||||||
|
|
||||||
Gloom::Shader* default_shader;
|
Gloom::Shader* default_shader;
|
||||||
//Gloom::Shader* plain_shader;
|
//Gloom::Shader* plain_shader;
|
||||||
//Gloom::Shader* post_shader;
|
|
||||||
|
|
||||||
// todo: const the following:
|
// todo: const the following:
|
||||||
|
|
||||||
|
@ -181,7 +180,7 @@ void init_scene(CommandLineOptions options) {
|
||||||
|
|
||||||
lightNode[0]->position = {-600, 1400, 800};
|
lightNode[0]->position = {-600, 1400, 800};
|
||||||
lightNode[0]->position = {-600, 0, 800};
|
lightNode[0]->position = {-600, 0, 800};
|
||||||
lightNode[0]->attenuation = vec3(1.8, 0.0, 0.0);
|
lightNode[0]->attenuation = vec3(1.8, 0.0, 0.0); // the color of the first light affects the emissive component aswell
|
||||||
//lightNode[0]->light_color = vec3(0.3, 0.3, 0.9);
|
//lightNode[0]->light_color = vec3(0.3, 0.3, 0.9);
|
||||||
lightNode[0]->light_color = vec3(0.5, 0.5, 1.0);
|
lightNode[0]->light_color = vec3(0.5, 0.5, 1.0);
|
||||||
rootNode->children.push_back(lightNode[0]);
|
rootNode->children.push_back(lightNode[0]);
|
||||||
|
@ -265,9 +264,9 @@ void step_scene(double timeDelta) {
|
||||||
float brh = DISPLACEMENT * (t_perlin.at_bilinear(br.x*3/1000, br.y*3/1000).x * 2 - 1);
|
float brh = DISPLACEMENT * (t_perlin.at_bilinear(br.x*3/1000, br.y*3/1000).x * 2 - 1);
|
||||||
float blh = DISPLACEMENT * (t_perlin.at_bilinear(bl.x*3/1000, bl.y*3/1000).x * 2 - 1);
|
float blh = DISPLACEMENT * (t_perlin.at_bilinear(bl.x*3/1000, bl.y*3/1000).x * 2 - 1);
|
||||||
|
|
||||||
cout << o.x << " " << o.y << endl;
|
//cout << o.x << " " << o.y << endl;
|
||||||
cout << frh << "\t" << flh << "\t" << blh << "\t" << brh << endl;
|
//cout << frh << "\t" << flh << "\t" << blh << "\t" << brh << endl;
|
||||||
cout << ((frh+flh)-(brh+blh))/2 / 100 << endl;
|
//cout << ((frh+flh)-(brh+blh))/2 / 100 << endl;
|
||||||
|
|
||||||
carNode->rotation.x = -glm::asin(((frh+flh)-(brh+blh)) / 2 / 100);
|
carNode->rotation.x = -glm::asin(((frh+flh)-(brh+blh)) / 2 / 100);
|
||||||
carNode->rotation.y = glm::asin(((frh+brh)-(flh+blh)) / 2 / 60);
|
carNode->rotation.y = glm::asin(((frh+brh)-(flh+blh)) / 2 / 60);
|
||||||
|
|
|
@ -1,12 +1,10 @@
|
||||||
#include <chrono>
|
#include "timeutils.hpp"
|
||||||
#include "timeutils.h"
|
|
||||||
|
|
||||||
|
Clock::Clock() {
|
||||||
|
_prev = std::chrono::steady_clock::now();
|
||||||
|
}
|
||||||
|
|
||||||
// Calculates the elapsed time since the previous time this function was called.
|
double Clock::getTimeDeltaSeconds() {
|
||||||
double getTimeDeltaSeconds() {
|
|
||||||
static std::chrono::steady_clock::time_point _prev
|
|
||||||
= std::chrono::steady_clock::now();
|
|
||||||
|
|
||||||
std::chrono::steady_clock::time_point now
|
std::chrono::steady_clock::time_point now
|
||||||
= std::chrono::steady_clock::now();
|
= std::chrono::steady_clock::now();
|
||||||
|
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
double getTimeDeltaSeconds();
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
#pragma once
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
class Clock {
|
||||||
|
private:
|
||||||
|
std::chrono::steady_clock::time_point _prev;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Clock();
|
||||||
|
|
||||||
|
// Calculates the elapsed time since the previous time this function was called.
|
||||||
|
double getTimeDeltaSeconds();
|
||||||
|
};
|
Loading…
Reference in New Issue