Ver código fonte

Add a stats logger entity.

legacy
Sam Hocevar sam 14 anos atrás
pai
commit
6e4ad90a9f
4 arquivos alterados com 95 adições e 1 exclusões
  1. +1
    -1
      src/Makefile.am
  2. +59
    -0
      src/debugstats.cpp
  3. +33
    -0
      src/debugstats.h
  4. +2
    -0
      src/test-map.cpp

+ 1
- 1
src/Makefile.am Ver arquivo

@@ -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


+ 59
- 0
src/debugstats.cpp Ver arquivo

@@ -0,0 +1,59 @@
//
// Deus Hax (working title)
// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
//

#if defined HAVE_CONFIG_H
# include "config.h"
#endif

#include <cstdio>

#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;
}


+ 33
- 0
src/debugstats.h Ver arquivo

@@ -0,0 +1,33 @@
//
// Deus Hax (working title)
// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
//

//
// 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__


+ 2
- 0
src/test-map.cpp Ver arquivo

@@ -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())
{


Carregando…
Cancelar
Salvar