diff --git a/src/application.cpp b/src/application.cpp index cffc3f5..b9d1114 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -21,6 +21,8 @@ */ #include "application.hpp" +#include "timer.hpp" + #include #include #include @@ -118,6 +120,8 @@ void Application::Proc() { //update the current time realTime = Clock::now(); + Timer runTimer("run"); + //simulate game time while (simTime < realTime) { //call each user defined function @@ -125,8 +129,18 @@ void Application::Proc() { simTime += delta; } + runTimer.Stop(); + + Timer renderTimer("render"); + //draw the game to the screen activeScene->RenderFrame(); + + renderTimer.Stop(); + + //debugging output +// std::cout << runTimer << std::endl; +// std::cout << renderTimer << std::endl; } UnloadScene(); diff --git a/src/debugging/makefile b/src/debugging/makefile new file mode 100644 index 0000000..a4efd0c --- /dev/null +++ b/src/debugging/makefile @@ -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 diff --git a/src/debugging/timer.cpp b/src/debugging/timer.cpp new file mode 100644 index 0000000..be3636a --- /dev/null +++ b/src/debugging/timer.cpp @@ -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(t.GetTime()).count(); + os << "ns"; + return os; +} diff --git a/src/debugging/timer.hpp b/src/debugging/timer.hpp new file mode 100644 index 0000000..7f8f38b --- /dev/null +++ b/src/debugging/timer.hpp @@ -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 +#include +#include + +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 diff --git a/src/in_world.cpp b/src/in_world.cpp index 3e3c4a7..b9a4903 100644 --- a/src/in_world.cpp +++ b/src/in_world.cpp @@ -21,6 +21,8 @@ */ #include "in_world.hpp" +#include "timer.hpp" + #include "utility.hpp" #include "region_pager_api.hpp" diff --git a/src/makefile b/src/makefile index ac5fdd9..2b86498 100644 --- a/src/makefile +++ b/src/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. graphics map ui utilities +INCLUDES+=. debugging graphics map ui utilities LIBS+=libcommon.a -lmingw32 -lSDLmain -lSDL -llua CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) @@ -16,6 +16,7 @@ OUT=$(addprefix $(OUTDIR)/,jam) #targets all: $(OBJ) $(OUT) + $(MAKE) -C debugging $(MAKE) -C graphics $(MAKE) -C map $(MAKE) -C ui