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
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <SFML/Audio.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
#include <utilities/shapes.h>
|
||||
#include <utilities/glutils.h>
|
||||
#include <utilities/shader.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)
|
||||
{
|
||||
|
@ -31,23 +35,28 @@ void runProgram(GLFWwindow* window, CommandLineOptions options)
|
|||
// Set default colour after clearing the colour buffer
|
||||
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);
|
||||
getTimeDeltaSeconds();
|
||||
Clock c, prof;
|
||||
|
||||
// Rendering Loop
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
// Clear colour and depth buffers
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
int w, h;
|
||||
glfwGetWindowSize(window, &w, &h);
|
||||
|
||||
step_scene(getTimeDeltaSeconds());
|
||||
double td = c.getTimeDeltaSeconds();
|
||||
step_scene(td);
|
||||
|
||||
prof.getTimeDeltaSeconds();
|
||||
updateFrame(window, w, h);
|
||||
cout << "uf: " << setprecision(4) << prof.getTimeDeltaSeconds() / td * 100 << "\t";
|
||||
renderFrame(window, w, h);
|
||||
cout << "rf: " << setprecision(4) << prof.getTimeDeltaSeconds() / td * 100 << endl << endl;
|
||||
|
||||
|
||||
// Handle other events
|
||||
|
|
|
@ -13,9 +13,14 @@
|
|||
#include <utilities/glfont.h>
|
||||
#include <utilities/shader.hpp>
|
||||
|
||||
#include <utilities/timeutils.hpp>
|
||||
|
||||
|
||||
using glm::vec3;
|
||||
using glm::vec4;
|
||||
using glm::mat4;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
typedef unsigned int uint;
|
||||
|
||||
sf::Sound* sound;
|
||||
|
@ -233,10 +238,9 @@ void renderNode(SceneNode* node, Gloom::Shader* parent_shader, vector<NodeDistSh
|
|||
#undef cache
|
||||
|
||||
if (do_recursive)
|
||||
for(SceneNode* child : node->children) {
|
||||
for(SceneNode* child : node->children)
|
||||
renderNode(child, node_shader, transparent_nodes, true);
|
||||
}
|
||||
}
|
||||
|
||||
// draw
|
||||
void renderFrame(GLFWwindow* window, int windowWidth, int windowHeight) {
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include <utilities/mesh.h>
|
||||
#include <utilities/shader.hpp>
|
||||
#include <utilities/shapes.h>
|
||||
#include <utilities/timeutils.h>
|
||||
#include <utilities/timeutils.hpp>
|
||||
#include <utilities/glfont.h>
|
||||
#include <utilities/glmhelpers.hpp>
|
||||
|
||||
|
@ -45,7 +45,6 @@ vector<SceneNode*> movingNodes;
|
|||
|
||||
Gloom::Shader* default_shader;
|
||||
//Gloom::Shader* plain_shader;
|
||||
//Gloom::Shader* post_shader;
|
||||
|
||||
// todo: const the following:
|
||||
|
||||
|
@ -181,7 +180,7 @@ void init_scene(CommandLineOptions options) {
|
|||
|
||||
lightNode[0]->position = {-600, 1400, 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.5, 0.5, 1.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 blh = DISPLACEMENT * (t_perlin.at_bilinear(bl.x*3/1000, bl.y*3/1000).x * 2 - 1);
|
||||
|
||||
cout << o.x << " " << o.y << endl;
|
||||
cout << frh << "\t" << flh << "\t" << blh << "\t" << brh << endl;
|
||||
cout << ((frh+flh)-(brh+blh))/2 / 100 << endl;
|
||||
//cout << o.x << " " << o.y << endl;
|
||||
//cout << frh << "\t" << flh << "\t" << blh << "\t" << brh << endl;
|
||||
//cout << ((frh+flh)-(brh+blh))/2 / 100 << endl;
|
||||
|
||||
carNode->rotation.x = -glm::asin(((frh+flh)-(brh+blh)) / 2 / 100);
|
||||
carNode->rotation.y = glm::asin(((frh+brh)-(flh+blh)) / 2 / 60);
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#include <chrono>
|
||||
#include "timeutils.h"
|
||||
#include "timeutils.hpp"
|
||||
|
||||
Clock::Clock() {
|
||||
_prev = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
// Calculates the elapsed time since the previous time this function was called.
|
||||
double getTimeDeltaSeconds() {
|
||||
static std::chrono::steady_clock::time_point _prev
|
||||
= std::chrono::steady_clock::now();
|
||||
|
||||
double Clock::getTimeDeltaSeconds() {
|
||||
std::chrono::steady_clock::time_point 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