From 6e4ad90a9fa65bc84d59b1d81298ac3d23a464e5 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 2 Sep 2010 04:39:20 +0000 Subject: [PATCH] Add a stats logger entity. --- src/Makefile.am | 2 +- src/debugstats.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++ src/debugstats.h | 33 ++++++++++++++++++++++++++ src/test-map.cpp | 2 ++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/debugstats.cpp create mode 100644 src/debugstats.h diff --git a/src/Makefile.am b/src/Makefile.am index 7de118b8..b612de3d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,7 +10,7 @@ libcommon_a_SOURCES = \ forge.cpp forge.h video.cpp video.h timer.cpp timer.h bitfield.h \ profiler.cpp profiler.h input.h input.cpp world.cpp world.h \ debugfps.cpp debugfps.h debugsprite.cpp debugsprite.h \ - debugrecord.cpp debugrecord.h + debugrecord.cpp debugrecord.h debugstats.cpp debugstats.h libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image` test_map_SOURCES = test-map.cpp sdlinput.cpp sdlinput.h diff --git a/src/debugstats.cpp b/src/debugstats.cpp new file mode 100644 index 00000000..25b566e3 --- /dev/null +++ b/src/debugstats.cpp @@ -0,0 +1,59 @@ +// +// Deus Hax (working title) +// Copyright (c) 2010 Sam Hocevar +// + +#if defined HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#include "core.h" +#include "debugstats.h" + +/* + * DebugStats implementation class + */ + +class DebugStatsData +{ + friend class DebugStats; + +private: + FILE *fp; +}; + +/* + * Public DebugStats class + */ + +DebugStats::DebugStats(char const *path) +{ + data = new DebugStatsData(); + data->fp = fopen(path, "w+"); +} + +Entity::Group DebugStats::GetGroup() +{ + return GROUP_AFTER; +} + +void DebugStats::TickGame(float deltams) +{ + Entity::TickGame(deltams); + + fprintf(data->fp, "%i %f %f %f %f\n", + Ticker::GetFrameNum(), + Profiler::GetAvg(Profiler::STAT_TICK_GAME), + Profiler::GetAvg(Profiler::STAT_TICK_DRAW), + Profiler::GetAvg(Profiler::STAT_TICK_BLIT), + Profiler::GetAvg(Profiler::STAT_TICK_FRAME)); +} + +DebugStats::~DebugStats() +{ + fclose(data->fp); + delete data; +} + diff --git a/src/debugstats.h b/src/debugstats.h new file mode 100644 index 00000000..71cfce51 --- /dev/null +++ b/src/debugstats.h @@ -0,0 +1,33 @@ +// +// Deus Hax (working title) +// Copyright (c) 2010 Sam Hocevar +// + +// +// The DebugStats class +// -------------------- +// + +#if !defined __DH_DEBUGSTATS_H__ +#define __DH_DEBUGSTATS_H__ + +#include "entity.h" + +class DebugStatsData; + +class DebugStats : public Entity +{ +public: + DebugStats(char const *path); + virtual ~DebugStats(); + +protected: + virtual Group GetGroup(); + virtual void TickGame(float deltams); + +private: + DebugStatsData *data; +}; + +#endif // __DH_DEBUGSTATS_H__ + diff --git a/src/test-map.cpp b/src/test-map.cpp index b54f155e..26b1cde6 100644 --- a/src/test-map.cpp +++ b/src/test-map.cpp @@ -17,6 +17,7 @@ #include "debugfps.h" #include "debugsprite.h" #include "debugrecord.h" +#include "debugstats.h" static float const FPS = 30.0f; @@ -52,6 +53,7 @@ int main(int argc, char **argv) new DebugFps(); new DebugSprite(game); //new DebugRecord("lolengine.ogg"); + new DebugStats("stats.txt"); while (!Ticker::Finished()) {