On 11/13/2011 5:14 PM, Jan Nikolas Jansen wrote:
> 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.
>
sounds like misinterpretation and premature optimization...
> 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.
>
are you sure the issue is not related to using double-buffering (vs
triple-buffering), or using vsync, or similar?...
are you sure it actually matters?...
FWIW, there may be little practical merit in having the max framerate
being something much higher than the user can actually see (since the
monitor may only update, say, at 60Hz, and even then the typical user
generally can't really perceive all that much above 40-60Hz anyways).
much better IMO, is to delay optimization until one actually has a real
performance issue.