[Windows] Development of a game engine

J

jannikolas.jansen

Hello,

I am trying to develop a simple game engine in C++ for Windows using
the DirectX SDK 2010 (June). However, when running an application
using my game engine that does nothing but display a text (the actual
framerate), I get maximum framerates of around 70. If I use other game
engines, such as Allegro, or IndieLib I usually get framerates around
300 on my system. Obviously, my approach here is completely
unefficient and I am looking for a way to speed things up.

My current approach is as naive as possible: I initialize stuff,
create a window, and start a timer that calls my main loop. In this
main loop I calculate what's necessary and then render everything to
screen.

To give you an impression of what it looks like in C++ source code:

SetTimer( hWnd, IDT_MAINLOOP, 0, MainLoop ); // this is how I set my
timer up

// this is pretty much what my timerproc function looks like
void WINAPI CALLBACK MainLoop( HWND hWnd, UINT uiMessage, UINT
uiTimerId, DWORD dwTime ) {
static DWORD dwActualFramerate = 0;
static DWORD dwTimeOfLastCall = 0;

if( uiTimerId == IDT_MAINLOOP ) { // if the main loop timer called
// calculate actual framerate
if( dwTimeOfLastCall > 0 )
dwActualFramerate = 1000 / (dwTime - dwTimeOfLastCall);
dwTimeOfLastCall = dwTime;
// do what i actually want to do
think(); // calculate everything
render(); // render everything
}
}

I would really appreciate if someone experienced in this matter could
push me in the right direction of how to improve this design.

Thanks in advance,
Jan Nikolas Jansen
 
J

Jan Nikolas Jansen

Hello,

I am trying to develop a simple game engine in C++ for Windows using
the DirectX SDK 2010 (June). However, when running an application
using my game engine that does nothing but display a text (the actual
framerate), I get maximum framerates of around 70. If I use other game
engines, such as Allegro, or IndieLib I usually get framerates around
300 on my system. Obviously, my approach here is completely
unefficient and I am looking for a way to speed things up.

My current approach is as naive as possible: I initialize stuff,
create a window, and start a timer that calls my main loop. In this
main loop I calculate what's necessary and then render everything to
screen.

To give you an impression of what it looks like in C++ source code:

SetTimer( hWnd, IDT_MAINLOOP, 0, MainLoop ); // this is how I set my
timer up

// this is pretty much what my timerproc function looks like
void WINAPI CALLBACK MainLoop( HWND hWnd, UINT uiMessage, UINT
uiTimerId, DWORD dwTime ) {
   static DWORD dwActualFramerate = 0;
   static DWORD dwTimeOfLastCall = 0;

   if( uiTimerId == IDT_MAINLOOP ) { // if the main loop timer called
       // calculate actual framerate
       if( dwTimeOfLastCall > 0 )
           dwActualFramerate = 1000 / (dwTime - dwTimeOfLastCall);
       dwTimeOfLastCall = dwTime;
       // do what i actually want to do
       think(); // calculate everything
       render(); // render everything
   }

}

I would really appreciate if someone experienced in this matter could
push me in the right direction of how to improve this design.

Thanks in advance,
Jan Nikolas Jansen

I found a way to solve this problem by using a thread for my MainLoop
instead of a timer callback function. The thread will measure the time
using GetTicks. Additionally, the time that drawing takes will be
measured, and if the game happens to get behind the desired framerate,
it will skip drawing frames until a certain maximum value for skipping
frames is reached.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top