Misc GapiDraw Questions
Is it possible to change the frame rate after the app has started?
On the Pocket PC, when full screen, is there a way to get text input from the stylus (block recognizer, transcriber, etc.)?
Alternatively, is it possible to swap in and out of full screen mode on the Pocket PC, say from full screen to half screen (the other half having the text entry areas)?
mlepage wrote:
Is it possible to change the frame rate after the app has started?
the CGapiApplication class has a CGapiTimer object named m_timer. Just doing m_timer.StartTimer (FPS) to set the new framerate works for me
no idea about the other questions, sorry.
Kak
GapiDraw on the pocket pc is a full screen app only. I don't believe you can grab directly from the transcriber and on screen keyboard, but there is another helper library "jojo sip" which is built ontop of GapiDraw you could look up.
Are only four buttons (not counting the d-pad) supported: Start, A, B, and C? My iPAQ has a couple more buttons. I'd like to use them.
For whatever reason, GAPI only offered these 4 for OEMs to provide values for so that's all GapiDraw maps for you.
The rest will be OEM specific key messages. I believe that this page -
http://www.cewindows.net/developer/pocketpcbuttons.htm - has the most complete mapping. What it's missing is consistent layout info (so you know where the buttons are physically located on the device).
OK thanks.
How do I create a new surface that is a copy of an existing surface? (Say, to take a copy of the back buffer.) Can I just use the copy constructor?
Create a new surface the same width and height, and then BltFast.
(I would highly recommend against copy constructors being used for this sort of thing. C++ compilers like to use them in all sorts of places you wouldn't expect, and with a large memory copy you could find performance hits you weren't expecting.)
The documentation says a backbuffer may work one of these two ways:
Pocket PC - Direct Display
The back buffer will point to a memory area managed by GapiDraw. On CGapiSurface::Flip, the contents of this buffer will be copied directly to the display area.
Pocket PC - Buffered Display
The back buffer will point to a memory area managed by GAPI. On CGapiSurface::Flip, the contents of this area will be transfered asynchronously to the display area using GAPI.
How do I know which is the way I am currently using? I have an iPAQ 3970. Is this configurable, or does it depend on my hardware?
Is it possible to change the frame rate after the app has started?
Yes, in GapiDraw 2.05 you can also call ChangeFPS() in GapiApplication...
How do I know which is the way I am currently using?
Yep.. Check the surface flags.. If the flag PRIMARY_SURFACE is set for the m_display surface, you can write directly to the display (i.e. it is a "direct display")
Is vkStart guaranteed to be on all devices? I thought some didn't have the d-pad press in for start. Is it just another button on those devices?
Maybe I'm misunderstanding something.
The documentation for v2.04, CGapiTimer::WaitForNextFrame, says "if one frame takes longer to render than others, the other frames will sleep less."
I run my game at 30fps, and it normally doesn't have a problem keeping up. Occasionally, during heavy screen activity, a frame will take longer than 33ms to render.
I am measuring this using the high performance timer.
What I find, is that once I've developed a lag on that timer of where my app is vs. where it should be, it stays there. That is, GapiDraw's ProcessNextFrame doesn't catch up, even though the screen activity has settled down and there is ample time to catch up.
Am I misunderstanding something about how GapiDraw is supposed to sleep less for subsequent frames to maintain my target 30 fps?
Let's have a concrete example.
Let's say the high performance counter has 3000 ticks per second. Let's say I want to run at 30fps, that's 100 ticks per frame.
Let's say my first frame starts at tick count 10000.
It's simple math to discover that after 1s, or 30 frames, the tick count should be at 13000. Let's say my game is relatively inactive and that's not a problem.
More simple math reveals that after another second (another 30 frames), the tick count should be 16000. Let's say that my game was fairly active, and the 30 frames didn't happen in time. Let's say the tick count was 16050, which means the game is late by half a frame.
Now, let's say this was an isolated incident. That 60th frame took 150 ticks to render, but normally my game only takes 20 ticks.
So now we're rendering the 61st frame. It should be done at 16100 and that's not a problem because the normal frame time is 20 ticks. Frames should continue at 16100, 16200, 16300 and so on.
But instead, everything just continues from 16150, 16250, 16350, and so on. The game is now perpetually late by half a frame, even though it could easily catch up.
I expected the rendering slow-down to smooth over other frames so long as I have slack (which I do). But that doesn't seem to happen.
It appears the ProcessNextFrame timer is not so smart as I thought. Or I'm misunderstanding it.
You don't have to use the CGapiApplication frame timer mechanism; I'd recommend either rolling your own, or instead of using frame ticks switching to absolute times (e.g. your high performance tick counts) to position items in the game world.
Think about this scenario: average frames take 20ms, per-frame time is set at 30ms (so 33.3 frames per second - that makes the other number round). So on average, the timer is going to sleep for 10ms per frame. Now you run into a frame that takes 45ms to render. Now, the timer would have to sleep for -5 seconds to catch up.
Most commercial games that I've seen either just "stutter" when there's an intense frame (e.g. the game slows down when there's lots of activity) or use absolute times (e.g. it takes 5 seconds for a ship to fly across the screen, whether that's 1 frame or 150 frames). In the latter case you probably want to cap the frame rate at some reasonable number so you're not consuming 100% CPU. The CGapiApplication timer seems to be an adequate implementation for both scenarios, but may not be for yours.
I would like my game to run at a fixed real world speed, by fixing the movement per frame and then fixing the frames per real time.
When my frames are too quick, GapiDraw already sleeps to slow the frame rate down to 30fps.
When my frames are too slow, I already drop rendering to speed the frame rate up to 30fps.
The problem is that GapiDraw doesn't in and of itself catch up that lost time, and it doesn't provide an API for me to tell it how to catch up.
GapiDraw provides StartTimer which takes a frame rate as a parameter. I don't want to change the frame rate, I just want to sleep less on the next frame. If GapiDraw provided a way for me to tell its timer exactly when to wake up, I'd be done in one line of code because I already know exactly where my game is in relation to real time.
I could fudge the FPS in that StartTimer method solely for the effect of speeding up the frames to make up for that lost time. But tat's an ugly hack.
InexorableTash wrote:
Think about this scenario: average frames take 20ms, per-frame time is set at 30ms (so 33.3 frames per second - that makes the other number round). So on average, the timer is going to sleep for 10ms per frame. Now you run into a frame that takes 45ms to render. Now, the timer would have to sleep for -5 seconds to catch up.
This is exactly the scenario I have, and here is exactly what I want.
When my game suddenly takes 45ms to render a frame, I don't want GapiDraw to sleep for -8ms to catch up because that's impossible. But I do want it to sleep for as little as possible to catch up. And I will do my part to ensure that the next frame is processed with time to spare, by not rendering it.
So when a game frame takes too long, my game will stop rendering until it catches up. But it can't catch up unless GapiDraw actually catches up, and it seems it doesn't.
If I do my own sleeping, can I turn off GapiDraw's sleeping? It's so limited it's probably best just to disable it.
Here is the core of the problem. Let's say I want to run at 2 frames per second, 500ms per frame.
If my frames process in 400ms, then there is no problem running at 2fps.
Now suddenly a frame takes 550ms to process. Yes everyone is correct that there is no way to go back and reclaim that 50ms that was lost.
But since the next frame only takes 400ms, the game should be back on track after that frame and still have 50ms to spare. I expect the first frame to be processed at 0ms, the second at 550ms, and the third at 1000ms, right on time.
What I am saying is that is not what I see happen. Instead, after 550ms, the next frame processes at 1050ms even though it could have processed as early as 950ms.
So the game caused the second frame to be late, but GapiDraw causes the third and every subsequent frame to be late.
You are correct, if the "allowed" frame time is exceeded once GapiDraw will reset the last tick count and begin as if it was starting out "fresh"...
I guess there were an issue when frame times constantly were exceeded, and the timer had problems "catching up" once frame times were back to normal. What do you suggest? Right now the logic is similar to:
- Code:
WaitForNextFrame()
...
if (dwDeltaTick <= dwWaitForTick)
{
Sleep(dwWaitForTick-dwDeltaTick);
}
else
{
// We are exceeding the target frame rate! Reset last tick count
m_timer.dwFrameIndex = 0;
m_timer.dwTickCount = gdtimer::GetTicksSinceStarted(&m_timer);
return GDERR_FRAMETIMEOVERFLOW;
}
Perhaps it should still reset the last tick count, but after only after a number of "overflow" frames have passed, to allow it to "catch up" if the next or third frame is back to normal?
//Johan
Thanks Johan. Perhaps a little more flexibility on when everything is reset, such as making it configurable how many frames go overtime before resetting (1, 2, etc.).
In v2.04, is it possible to disable GapiDraw's sleeping and just do my own sleeping?
The easiest would be to simply comment out the call to m_timer.WaitForNextFrame() in GapiApplication.h... Then it will never sleep...

Ha ha ha. My game plays absurdly fast on the PC when I do that.
Sleep only takes milliseconds as a parameter. Is there anything more accurate?
I have my frame sleeping and skipping working properly (after disabling GapiDraw's implementation), but I'd like to make it more accurate if I can.
"Seep only takes milliseconds as a parameter. Is there anything more accurate?""
No on PocketPC.
If I were you I wouldn't even bother with trying to "catch" up with the frame rate. I would simply store all movement in terms of framerate and then simply update these values on each pass.
This way you will run at the fixed rate regardless of the current framerate (within sane limits of course.)
My game is a puzzle game and doesn't have sprites moving at speeds, so that method is inferior (in my opinion). If I had sprites, I'd tie things to time.
But you have to understand that I am, in a way, tied to time. I have defined all my speeds in terms of frames, so by defining my game to run at 30fps, I am dealing in time in 1/30s, guaranteed.
I already have my frame rate locked at 30fps, catching up beautifully. It just drops frame rendering if it finds itself behind. The effect is as good as I had hoped it would be.
So far, on my device, I find it drops about every other frame during my big block fade effect. So instead of seeing 8 frames of fade, you see every second one. The effect isn't as smooth as on the PC, but it's definitely locked in with the time as it should be.
I expect more powerful devices wouldn't drop frames during the heavy activity at all. And I expect less powerful devices might drop frames even during normal light activity. But that's not as bad as it sounds. If a falling shape moves and eats up 3 frames of time, it will skip 2 frames of rendering, but it wasn't going to move during those next two frames anyways (it only moves every so many frames), so the loss is visually unnoticeable.
Actually, the question I came here to ask, is whether there is a way to tell CGapiApplication NOT to blit the backbuffer on a particular frame? I'm assuming there isn't, but I'm also assuming it won't be difficult to edit CGapiApplication's source to add this for myself. Is that correct Johan?
Actually, the question I came here to ask, is whether there is a way to tell CGapiApplication NOT to blit the backbuffer on a particular frame? I'm assuming there isn't, but I'm also assuming it won't be difficult to edit CGapiApplication's source to add this for myself. Is that correct Johan?
You would have to add this yourself. Just add a member variable BOOL m_bDoNotRenderNextFrame and set it to FALSE as default. Set it to TRUE in ProcessNextFrame if you don't want to render next frame, and check if the variable is set and skip Flip() and reset it to FALSE in the main loop in GapiApplication.cpp.
Thanks Johan, that's about as simple as I expected it would be, I just wanted to make sure there wasn't any gotcha to it.
I'll also note that technique could be extended to do a partial flip. (Where flip is a copy and not an actual hardware flip.)
Hey, I think this can improve my game's performance too.

Thanks for the tip Johan!
This could be another potential GapiDraw future feature creature.