Overview
Features
Download
Documentation
Community
Add-Ons & Services

Logger and Timer Help

Please post support and help requests here.

Logger and Timer Help

Postby Derjyn » 16 Jan 2009, 06:56

Greetings,

I've just started poking around with POCO, and I must say it's pretty slick. I'm having a couple of problems though. One is surely a simple solution, while the other might be a bit more complex.

I have a class, LogSystem that wraps up some Logger functionality to print to a file as well as a console. What I can't figure out is, how to have the log file cleared each time my app is run. Basically the logger is defaulted to append mode. I've peeked at the docs, and looked around the forums here, couldn't find any relative information.

My other problem, is the timer. Or it's probably a few of the other POCO goodies as well that fit in here. What I'm working on is a game engine, and I'd like to have a nice accurate timer- I was using POCO for my log system, so thought I'd use it for timing as well! The accuracy is quite nice, so it really seems to fit the bill. Not too sure on the performance compared to a "classic" timer (It's a Win32 app at the moment).

I want to be able to get milliseconds, seconds, and fire off X amount of ticks per second. I'm also wanting to tie it into a fixed time-step loop, along the lines of this one. Actually, that one exactly. I'm not very good with programming, so this one is stumping me. I can handle getting the milliseconds and seconds, but I just don't know how to approach building my TimeSystem class so that other classes (namely my SystemsManager class, that has an UpdateSystems function that updates the engine logic, physics, rendering, etc) can listen for a tick to pass and do something each time one does. So say I want to update the engine at 40 ticks per second. What would be the most optimal way of going about this?

Here is my source code- note that I'm starting from "Core", which is basically where initialization, update, and shutdown gets called. Then I work back towards the other classes that get initialized, updated, or shutdown.

Code: Select all
//=========================================================================================
// Core.cpp
//=========================================================================================

#include "Core.h"

//=========================================================================================

namespace Erebus
{

//=========================================================================================

Core::Core()
{
}

Core::~Core()
{
}

//=========================================================================================

void Core::Initialize()
{
   m_StateMgr = new StateManager();
   m_SystemsMgr = new SystemsManager();

   m_SystemsMgr->InitializeSystems();

   m_StateMgr->RequestStateChange( SIMULATION );
}

//=========================================================================================

void Core::Update()
{
   while( m_StateMgr->GetCurrentState() != SHUTDOWN )
   {
      m_SystemsMgr->UpdateSystems();
   }
}

//=========================================================================================

void Core::Shutdown()
{
   m_SystemsMgr->ShutdownSystems();

   delete m_SystemsMgr;
   delete m_StateMgr;
}

//=========================================================================================

} //namespace Erebus

//=========================================================================================
//EOF


Code: Select all
//=========================================================================================
// SystemsManager.cpp
//=========================================================================================

#include "SystemsManager.h"

//=========================================================================================

namespace Erebus
{

//=========================================================================================

SystemsManager::SystemsManager()
{
}

SystemsManager::~SystemsManager()
{
}

//=========================================================================================

void SystemsManager::InitializeSystems()
{
   m_LogSys = new LogSystem();
   m_LogSys->InitLogSystem();
   m_LogSys->LogConsoleInformation("Systems initializing...");
   m_LogSys->LogFileInformation("Systems initializing...");

   m_TimeSys = new TimeSystem();
   m_TimeSys->InitTimeSystem();
}

//=========================================================================================

void SystemsManager::UpdateSystems()
{
   m_TimeSys->UpdateTimeSystem();
}

//=========================================================================================

void SystemsManager::ShutdownSystems()
{
   m_TimeSys->ShutdownTimeSystem();
   m_LogSys->ShutdownLogSystem();

   delete m_TimeSys;
   delete m_LogSys;
}

//=========================================================================================

} //namespace Erebus

//=========================================================================================
//EOF


Code: Select all
//=========================================================================================
// TimeSystem.cpp
//=========================================================================================

#include "TimeSystem.h"

//=========================================================================================

namespace Erebus
{

//=========================================================================================

TimeSystem::TimeSystem()
{
}

TimeSystem::~TimeSystem()
{
}

//=========================================================================================

void TimeSystem::InitTimeSystem()
{
}

//=========================================================================================

void TimeSystem::CycleTimer()
{
}

//=========================================================================================

void TimeSystem::UpdateTimeSystem()
{
}

//=========================================================================================

void TimeSystem::ShutdownTimeSystem()
{
}

//=========================================================================================

} // namespace Erebus

//=========================================================================================
//EOF


You'll notice TimeSystem is in a vanilla state... I didn't realize I whiped it clean before I started this thread; it only contained functions for getting milliseconds/seconds passed since start.

Any help here would be greatly appreciated! As an aside, the Erebus engine is going to be open source. I'll be using Ogre3D for the rendering engine, NxOgre (PhysX wrapper for Ogre), and a few other awesome libraries in it. I recently got access to a beta program for a very slick piece of middleware, though it's not open source sadly. Though I've been talking with the company about being able to use it in the engine still, since I'm making it pluggable I should still be able to utilize it's features. Here is the Google Code page for Erebus. It's nothing fancy at all yet, still in what I call "Phase 0", or the conceptual phase.

Again, thanks for any help/advice.
Derjyn
 
Posts: 1
Joined: 16 Jan 2009, 06:28

Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests

cron