Wrote a simple passive timer for debugging

This commit is contained in:
Kayne Ruse
2014-07-30 20:53:32 +10:00
parent b6e8b13d1b
commit 3b1841f6b7
6 changed files with 138 additions and 1 deletions
+14
View File
@@ -21,6 +21,8 @@
*/ */
#include "application.hpp" #include "application.hpp"
#include "timer.hpp"
#include <stdexcept> #include <stdexcept>
#include <chrono> #include <chrono>
#include <iostream> #include <iostream>
@@ -118,6 +120,8 @@ void Application::Proc() {
//update the current time //update the current time
realTime = Clock::now(); realTime = Clock::now();
Timer runTimer("run");
//simulate game time //simulate game time
while (simTime < realTime) { while (simTime < realTime) {
//call each user defined function //call each user defined function
@@ -125,8 +129,18 @@ void Application::Proc() {
simTime += delta; simTime += delta;
} }
runTimer.Stop();
Timer renderTimer("render");
//draw the game to the screen //draw the game to the screen
activeScene->RenderFrame(); activeScene->RenderFrame();
renderTimer.Stop();
//debugging output
// std::cout << runTimer << std::endl;
// std::cout << renderTimer << std::endl;
} }
UnloadScene(); UnloadScene();
+37
View File
@@ -0,0 +1,37 @@
#config
INCLUDES+=.
LIBS+=
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
#source
CXXSRC=$(wildcard *.cpp)
#objects
OBJDIR=obj
OBJ+=$(addprefix $(OBJDIR)/,$(CXXSRC:.cpp=.o))
#output
OUTDIR=..
OUT=$(addprefix $(OUTDIR)/,libcommon.a)
#targets
all: $(OBJ) $(OUT)
ar -crs $(OUT) $(OBJ)
$(OBJ): | $(OBJDIR)
$(OUT): | $(OUTDIR)
$(OBJDIR):
mkdir $(OBJDIR)
$(OUTDIR):
mkdir $(OUTDIR)
$(OBJDIR)/%.o: %.cpp
$(CXX) $(CXXFLAGS) -c -o $@ $<
clean:
$(RM) *.o *.a *.exe
rebuild: clean all
+29
View File
@@ -0,0 +1,29 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#include "timer.hpp"
std::ostream& operator<<(std::ostream& os, Timer& t) {
os << t.GetName() << ": ";
os << std::chrono::duration_cast<std::chrono::nanoseconds>(t.GetTime()).count();
os << "ns";
return os;
}
+54
View File
@@ -0,0 +1,54 @@
/* Copyright: (c) Kayne Ruse 2014
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
*
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
*
* 3. This notice may not be removed or altered from any source
* distribution.
*/
#ifndef TIMER_HPP_
#define TIMER_HPP_
#include <chrono>
#include <string>
#include <ostream>
class Timer {
public:
typedef std::chrono::high_resolution_clock Clock;
Timer() = default;
Timer(std::string s) : name(s), start(Clock::now()) {};
~Timer() = default;
inline void Start() { start = Clock::now(); }
inline void Stop() { time = Clock::now() - start; }
//accessors and mutators
Clock::duration GetTime() { return time; }
std::string SetName(std::string s) { return name = s; }
std::string GetName() { return name; }
private:
std::string name;
Clock::time_point start;
Clock::duration time;
};
std::ostream& operator<<(std::ostream& os, Timer& t);
#endif
+2
View File
@@ -21,6 +21,8 @@
*/ */
#include "in_world.hpp" #include "in_world.hpp"
#include "timer.hpp"
#include "utility.hpp" #include "utility.hpp"
#include "region_pager_api.hpp" #include "region_pager_api.hpp"
+2 -1
View File
@@ -1,5 +1,5 @@
#config #config
INCLUDES+=. graphics map ui utilities INCLUDES+=. debugging graphics map ui utilities
LIBS+=libcommon.a -lmingw32 -lSDLmain -lSDL -llua LIBS+=libcommon.a -lmingw32 -lSDLmain -lSDL -llua
CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES))
@@ -16,6 +16,7 @@ OUT=$(addprefix $(OUTDIR)/,jam)
#targets #targets
all: $(OBJ) $(OUT) all: $(OBJ) $(OUT)
$(MAKE) -C debugging
$(MAKE) -C graphics $(MAKE) -C graphics
$(MAKE) -C map $(MAKE) -C map
$(MAKE) -C ui $(MAKE) -C ui