[Windows] Development of a game engine

Discussion in 'C++' started by jannikolas.jansen@googlemail.com, Nov 14, 2011.

  1. Guest

    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
    , Nov 14, 2011
    #1
    1. Advertising

  2. Re: Development of a game engine

    On 14 Nov., 01:29, 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.
    >
    > 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.
    Jan Nikolas Jansen, Nov 14, 2011
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. BlackHawke
    Replies:
    12
    Views:
    1,544
    Andrew Thompson
    Jan 26, 2004
  2. judith
    Replies:
    0
    Views:
    1,625
    judith
    Nov 1, 2006
  3. Max Kubierschky
    Replies:
    10
    Views:
    1,821
    pabloreda
    Mar 31, 2007
  4. Advertiser for `2D Games Development Central`

    {Game Development} 2D Game Development Central

    Advertiser for `2D Games Development Central`, May 7, 2008, in forum: Java
    Replies:
    2
    Views:
    399
    RedGrittyBrick
    May 8, 2008
  5. Advertiser for `2D Games Development Central`

    {Game Development} 2D Game Development Central

    Advertiser for `2D Games Development Central`, May 7, 2008, in forum: C++
    Replies:
    0
    Views:
    378
    Advertiser for `2D Games Development Central`
    May 7, 2008
Loading...

Share This Page