Future PF features
It sounds like we can be expecting the first PHAL-based PF version any day now (or I guess any WEEKEND now, right Thierry

), so I was just thinking that maybe a thread dedicated to what new features we'd all like to see in PF down the road might be useful.
There is an alterior motive to this... Thierry has always said that he wanted more help with PF, and with all the apparent negativity towards other libraries at the moment, my guess is that more people would now be willing to put some work into PF for everyone's benefit. Thierry could even have the option of not dealing with PF if he didn't want to and just concentrate on PHAL entirely. I haven't discussed this with him, so I don't know where his thinking is on this. Maybe he could just serve as the final integrater of all the changes without actually doing any work on his own, but that presumes everyone else pitches in of course.
I know I have about another 1-2 months of work on my current project, and I need to keep my focus there if it's going to get done at all... but when it's done, my intention is to put some time into PF and see if I can add some things myself.
On the top of my list is bitmap font support, including a tool like the one for GD. I'm not sure I'm going to use the exact same format as GD does, but something close I think makes sense. I'd like the tool to have the ability to do a couple of new things, including anti-aliasing, gradient coloring, pattern fills and outlining of any font (not that I'm sure how to do that at the moment and get decent results all the time). More or less I'm going to look at what can be done with Paint Shop Pro or Photoshop and duplicate as much of it as I can. I'd also like the drawing function to have some extra capabilities, including linebreak support, leading, colorization and scaling. Some of this really may just require some built-in shaders (colorization most probably), but I think it would be a worth-wild effort.
The other thing on my list is a basic GUI interface subsystem. I'm thinking the ability to open a window over whatever is on the screen at the time with either a solid 3-D shadowed look or an alpha-blended look, or even a combination (which I use in my current project) and then to put some basic interface components on that window, things like checkboxes, drop-downs, textboxes, etc., deal with the events and return to exactly where the application left off. I've done much of this in my current project, and the model has worked fairly well. For instance, I have a doPopup() method. When you call it, you pass some parameters naturally, one of which is a callback method that handles events any way you want. When your all done, you call finishPopup(), and control resumes where it left off (at the next iteration of ProcessNextFrame()... remember, my current project is GD-based, but this would work in PF just the same). Now, my popups don't have all the controls I want to have, and there's no notion of "designing a form", meaning my popups all look and work the same way, but I don't see any real problem with creating a defintion language to define the window and it's contents, then just pass a reference to the definition of a given window to the doPopup() method, and go from there. Mind you, much of this is up in the air, I can solidify it a lot once my current project is done, but you get an idea what I'm thinking here.
So, anyone else have any ideas, and more importantly, anyone want to VOLUNTEER for anything, once the new PF version is out?
Walk before you run. Get basic functionality working before you go for a zillion text options, full GUI, etc. Just my two cents.
I wrote a basic line breaking function here:
http://www.pocketmatrix.com/forums/view ... hp?t=14735
You might be able to build off of it, it's mostly standard C++.
Do you mean basic PF functionality? If so, I have complete faith in Thiery's ability to get PF running on top of PHAL in short order. PF itself was ALREADY quite solid, so just a matter of PHAL getting in there.
If you meant basic bitmap font functionality, I was just stating what my goals were. Hell, half of it could fall by the wayside because it winds up being beyond my abilities, but what I wrote is what my plans are.
The GUI stuff I've already done to a large extent. The basic event model works quite well in my current project, just needs some tweaking to make it more general-purpose. GD is close enough to PF in most respects that I know that transition isn't going to cause any major headaches. I've also written a couple of GUI widgets over the years, so it's not as big a deal as it might otherwise be. Ironically, the GUI stuff might wind up being easier than the bitmap font stuff! But, the GUI stuff, obviously, will make more sense using the bitmap font functionality, so that's first up.
Yes, I saw that post by the way... don't be surprised if your code winds up in PF almost exactly as posted

Frank,
For the bitmapped font class for now I just grabbed the one on your site from Jason Chong, and changed it a little bit so it will return string lengths, and works right with the current GD/MetalShard type fonts (they grab the column on either side of the mask line on top for spacing, etc...).
I wanted to get my current project ported over fast and this worked pretty well, and the tool is then already written, as Im guessing MetalShard might be coming this way too... As long as that doesnt cause any problems with GD?!?!? I would think it would be good if we are all working with the same font types(easier port back to GD in the future)....
Thanks birdiestyle, I was not aware of that (I haven't looked at my own site in some time!). I'll talk to Jason as well as Metalshard and see how they feel about using their work. Maybe Metalshard would even update the tool themselves to add some of the features I was talking about, and then I can just work on the actual render code (heck, maybe Jason might even want to continue on with it himself, in which case I can move right into the GUI stuff - Jason, are you reading this by any chance?!?).
Here is what I changed from the original file:
I changed this line:
- Code:
// chardata[ascii[ch]].offset=i;
chardata[ascii[ch]].offset= i - 1; //on system font border it is taking one in front and behind
and this line
- Code:
// chardata[ascii[ch]].length=klength;
chardata[ascii[ch]].length= klength + 2;//on system font border it is taking one in front and behind, for spacing
and added the function:
- Code:
int Font::GetStringWidth(TCHAR *str)
{
int iLength = 0;
for (int i = 0; i < _tcslen(str); i++)
{
iLength += chardata[str[i]].length;
}
return iLength;
}
fzammetti wrote:
So, anyone else have any ideas, and more importantly, anyone want to VOLUNTEER for anything, once the new PF version is out?
This is all somewhat premature of course...
I might be able to provide some basic tutorials and documentation.
In addition to the font support, I'd like to have hekkus or another sound library integrated. And a nice, generic sprite library wouldn't hurt either
Pam
I think the sprite library is a good idea, but I've always felt that Hekkus, or any sound library really, is better left separate. Especially when they are going to continue to develop separately, I like the ability to just drop a new version o Hekkus in completely independant of the version of PF.
However, I think a really good, concise FAQ on how to integrate it would be a good idea. PF 0.7.0 shipped with a Hekkus sample that I put together, but having a document to explain how to do it from scratch would be nice (it would only be 3-4 steps I'd guess, it's pretty darned easy).
Documentation is one of the areas I've heard complaints about PF, so I think anything that anyone can do in that area would be a big plus. Pam, your Oxygen-generated reference you did a while back I think would be a fantastic starting point. If you or someone could fill out the details, when the time comes naturally, I could see that being a big plus for PF.
I will be probably be adding sprites to PF very soon (after the port to PHAL) as I need them myself. I was thinking about this:
1) One surface can contain multiple sprites. In effect, the surface would be reference-counted by the Sprite class.
2) Support for RLE sprites (without stretching/rotation)
Not sure where to fit animated sprites... There is so many different ways to animate a sprite that I find it hard to come up with a generic and efficient method.
I can certainly understand the difficulty. That being said, in my mind a sprite class really HAS to have animation support, otherwise I don't see much point to it. Perhaps we should have a whole new thread just for this and see what ideas everyone can contribute?
fzammetti wrote:I can certainly understand the difficulty. That being said, in my mind a sprite class really HAS to have animation support, otherwise I don't see much point to it. Perhaps we should have a whole new thread just for this and see what ideas everyone can contribute?
I disagree.
Sprite animation is too high level for a sprite engine.
You just need a way to easily get the animations of the main sprite by adding an offstet.
in uEngine sprites are not referenced by pointers but by index, and when uEngine load a tga containing several sprites, their index are incremented sequentially.
It's simple and efficient, and quite flexible.
I have a class that I've been using for all of my 2D games (I just port it to whatever library I'm using, but no doubt you could make it generic by using templates, I just haven't bothered doing that yet). It inherits from the Surface class, and offers the following additional functionality;
Note: This is the class declaration for what I use in GapiDraw - I have not used PF yet so *shrug* sorry, but I think you get the idea;
- Code:
#ifndef __SPRITE_H__
#define __SPRITE_H__
#include "GapiDraw.h"
class Sprite
: public CGapiSurface
{
public:
Sprite();
void Display(CGapiSurface* pBuffer, POINT p, DWORD index) const;
RECT GetFrameArea(DWORD index) const;
DWORD GetFrameCount() const;
DWORD GetFramesPerRow() const;
DWORD GetFramesPerCol() const;
void SetFrameSize(DWORD width, DWORD height);
DWORD GetFrameWidth() const;
DWORD GetFrameHeight() const;
private:
DWORD m_frameCount;
DWORD m_framesPerCol;
DWORD m_framesPerRow;
DWORD m_frameWidth;
DWORD m_frameHeight;
};
#endif // __SPRITE_H__
As you can see, it basically breaks the surface up into frames. ie; SetFrameSize(32, 32) will break a surface into 32x32 rectangles, and then I can simply draw my "frames" by doing a simple call to display; Display(pBackBuffer, location, 0). I leave it up to the sprite owner to define the animation. A character class for example will draw the appropriate frame based off of the direction its facing and what animation step its currently on.
No idea if you'd call this a "sprite" class, but it's what I call it. It defines the basic functionality needed for animating and drawing a sprite.
Anyway, just thought I'd share.
Alpha-masks would be great... I've implemented them myself for the moment, but it's not too neat. Even better would be loading the alpha channel from a PNG...
The font stuff sounds excellent - I've stolen the Font class from PFPlus, and added masking to give an anti-aliased look in one project at the moment, but again - built-in support for these sorts of things are always appreciated.
We've reached the level of understanding of our beloved devices that these features are no longer 'impossible' or 'infeasible' - we can do this stuff now, easily and efficiently because the framework is there. It's a fantastic achievement by Thierry!
Of cause, all improvement is great. Better font support and alpha channels would be my favourites though

fzammetti wrote:I can certainly understand the difficulty. That being said, in my mind a sprite class really HAS to have animation support, otherwise I don't see much point to it. Perhaps we should have a whole new thread just for this and see what ideas everyone can contribute?
Animation depends on the game, so I don't see how you could define a generic animation sequence to cover all types of sprites in each and every game engine. An RPG could have a chess represented by a sprite, a character, a magic spell animation, and on so. A space combat game on the other hand would have ships that rotate 360 degrees, missiles, effects as well, and so on.
No doubt a simple "effect" class could be provided, since effects just play through their animation once and then that's it. But as for the rest, there's just no possible way. It has to be left to the game engine to determine how the sprites are displayed for individual game objects.
Well, let me put it this way... In my current project I do this way too much:
int player_frame = 0
int player_frame_delay = 0;
// Then, later on in the main game loop...
blt(player[player_frame]);
player_frame_delay++;
if (player_frame_delay > 5) {
player_frame_delay = 0;
player_frame++;
if (player_frame == 10) { player_frame = 0; }
}
Now, you can obviously ask why I didn't write a class to deal with that, and my simple answer would be that by the time I realized it would have been a good idea, I was so far along that I just said f**k it.
But, my point here is that in my mind, that's a big part of what a sprite class should do. Now, whether it's taking a surface and dividing it into blocks and calling them frames, or taking in an array of pointers to images that are frames, or something else entirely, the abillity to encapsulate code like what you see above is what I would consider a sprite class to be for.
Now, the point that animation is game-specific is valid, but I don't think that means you can't come up with a sprite class that handles a lot of cases, maybe even most cases. I'm not saying I can enumerate all the details here, I'd have to think about it a great deal, but something generic I definitely think is possible.
Like I said before, it's impossible to do what you ask in a generic way. The only thing you can possibly do generically is setting up the frames for the sprite itself (which my class does).
Let me see if I can explain further. In my game I have 4 directions in which you can face;
enum DIRECTIONS { UP, DOWN, LEFT, RIGHT };
In the character graphic, each direction is on a row itself, with 2 frames per walking animation;
U0, U1
D0, D1
L0, L1
R0, R1
So what the heck am I getting at? To calculate which frame to draw for my walking character, I have to combine the direction and the current walking frame.
Obviously, that's not the way you're doing it.
My animation code looks something like this (note; example is simplified from actual game code);
- Code:
m_animFrame += g_Timer.GetTime() * this->AnimationPerSecond;
if ((int) m_animFrame > m_sprite->FramesPerCol()) m_animFrame = 0;
DWORD frame = m_direction * m_sprite->FramesPerRow() + (int) m_animFrame;
m_sprite->Display(pBuffer, m_point, frame);
EDIT:
Everyone just does animation and graphics in their own way. Heck, I even noticed that I use a timer to insure that my animation loops at the same speed, regardless of the games actual frames per second, while you do not (which means your animations are looping at the actual frames per second of the game, in which case each device may be playing your game faster or slower than another).
wyrd wrote:
EDIT:
Everyone just does animation and graphics in their own way. Heck, I even noticed that I use a timer to insure that my animation loops at the same speed, regardless of the games actual frames per second, while you do not (which means your animations are looping at the actual frames per second of the game, in which case each device may be playing your game faster or slower than another).
Depends on how your frame limiting system works.
mlepage wrote:Walk before you run. Get basic functionality working before you go for a zillion text options, full GUI, etc. Just my two cents.
that´s exactly how I feel.
basic functionality is not simple, it may include a lot of blendings, effects, etc, so we should concentrate on that for now.
How about including some sort of Timer/Time correction functions... I've got my own, but I've seen plenty of games that needed it... Plus GD has the thing where you specify the framerate of the game(I think) - whereas pfrog runs as fast as it can.
What I did in my game is a class that you call each time you call display->update(). You set the target framerate in milliseconds, then fetch a value each frame that is the ratio of the actual framerate vs. the desired one. Or you can get the delta milliseconds between frames as well.
The class uses static variables, so each instance is tied back to that one update in your main code (if that makes any sense).
I can post code if anyone is interested (but beware, it's probably could be written a lot better).
As for the sprite thing... The only thing I could see doing is handling the loading of all the images (and destruction) and fetching the right image given an index... Of course, you could then set up your own class and inherit the loader, etc, and add your own smarts to the animation itself.
Jason
HTK wrote:Depends on how your frame limiting system works.
Why would you want to limit your frame rate in the first place...
Animations and movement should be based on time, not frames. That's a typical mistake.
fast_rx wrote:How about including some sort of Timer/Time correction functions... I've got my own, but I've seen plenty of games that needed it... Plus GD has the thing where you specify the framerate of the game(I think) - whereas pfrog runs as fast as it can.
That's actually a feature. Why limit the frame rate in the first place?
Concerning animation of sprites, I agree with StephC, Wyrm and a few others. There is simply no way to make a generic system, everyone has it's own needs. That's why I never added it to PF.
At Relic, our animation system is based on multiple variables (direction, speed, time, health and so on). The animator can even define his own variables and update them using scripting. This is obviously overkill for PF.
I think that having some functionality to access sub-images in a surface would be nice and useful to a lot of people... But anything more will simply add overhead to the majority of users.
Here's an article on how to correctly use a timer in your game.
http://www.gamedev.net/reference/articl ... cle753.asp
Thierry":2g65l9i5]
adjusting animation according to the framerate may have some undesirable effects, like the giant jump on quake3 for people with ultra fast systems, thats why carmack is using a 60fps fixed system on doom3.
I think its cool to adjust movement based on time, but sometimes ( small projects for example ) its easier/simpler/faster to base it on fps
adjusting animation according to the framerate may have some undesirable effects, like the giant jump on quake3 for people with ultra fast systems, thats why carmack is using a 60fps fixed system on doom3.
The fixed fps fixes the HUGE jumps for those with uber systems that can play the game at 100+ fps, but he's still using time based animation and movement. There's simply no way around it when you're making a game that can run at 30 fps on one machine, and 60 fps on another. You must have a game that plays at the same speed, regardless of machine.
I think its cool to adjust movement based on time, but sometimes ( small projects for example ) its easier/simpler/faster to base it on
Just because something is easier, simpler, or faster, doesn't mean it should be a practiced or used technique.
Exactly HTK. For my current project, there's no need for a high frame rate. In fact, 24FPS is more than sufficient. So, I've hard-coded everything to run at that speed. Even the worst devices out there can keep up without much trouble, so it works fine, and the code is considerably less complex. I'm certainly not saying that's the approach to take in every case, but it's not automatically a bad idea all the time.
... and the code is considerably less complex.
*scratches head*
Your animation step;
m_animFrame++;
Mine;
m_animFrame += g_Timer->GetTime() * this->UnitsPerSecond;
Not much of a difference if you ask me. Each is only a single line of code of varying length. The only difference is that in my case (aside from the 0.000001 seconds longer it took me to type out), I can have each sprite animating at totally different speeds with the flick of a variable. With your solution, you'd either have to add some extra counter or skip frames. In such a case, your life would be more difficult than if you implemented a simple timer solution to begin with.
In fact, 24FPS is more than sufficient.
All devices run your game at this speed? None run it at say, 20 fps? Time based movement and animation isn't just for faster devices, it's also for slower devices.
What do you mean "not much of a difference"? You mean that you consider two pointer references, one of which is a method call, a multiplication and an addition to be as simplistic as a variable increment? Are you serious?!?
Look, you may be so good that to you one is just as easy as the other, and if that's the case, more power to you. But arguing that your line of code isn't much different than mine is pretty nuts in my opinion.
I too can have my animations run at different speeds with the flick of a variable. I can make them all scale by the same factor, if I chose to do so. Alright, I'll be fair and say that your method will yield better results in that case, but still, it can be done otherwise.
As for your question, the answer is yes, FASTER devices are still limited to 24FPS. GD has a frame limiting function, and I simply set it to 24. Any device that can achieve 24FPS will run it at that constant speed, presuming of course that my game loop doesn't take longer than that speed dictates. As for slower devices, it is definitely true that the potential exists that they won't be able to achieve that frame rate. However, I've choosen that rate because it is achieve on both my Casio E-125 running at stock 150MHz, as well as my stock Axim X5. It is a fair assumption that any device will be equal or better than either of these (the E-125 is of course slower than any modern device, and the Axim has the lousy video chip slowing it down).
Also, one added benefit of this method is that the smoothness of the game is constant across all devices. With a time-based method, a faster device would appear smoother than a slower device. This is generally viewed as a good thing, but I'm not so sure I agree in principal. It's of course important that the game run the same SPEED on all devices, but I personally find it just as important that it run at the same SMOOTHNESS on all devices. A time-based method doesn't do that. Assuming that the baseline speed and performance is acceptable, which I find it to be absolutely, then I find this approach better overall.
I guess we just have different opinions.
What do you mean "not much of a difference"? You mean that you consider two pointer references, one of which is a method call, a multiplication and an addition to be as simplistic as a variable increment? Are you serious?!?
My line of code is fairly simple, yes. It's easy to understand, read, and debug. What more can you ask for? What it's actually doing is totally irrelevent unless you want to get into a discussion about optimization and how multiplication is slower than addition. In that case, we're on a totally different subject.
With a time-based method, a faster device would appear smoother than a slower device.
Yup, you're right, and that's how it should be. Why should all devices appear to be choppy when those with faster models could have a smoother experience? By limiting all devices to 24 fps (as you're doing), you're forcing all devices to act as if they were of a lesser model. And in fact, I don't believe 24 fps is all that smooth, so why give everyone that experience? IMO, 30 fps is the breaking point.
HTK wrote:
adjusting animation according to the framerate may have some undesirable effects, like the giant jump on quake3 for people with ultra fast systems, thats why carmack is using a 60fps fixed system on doom3.
I think its cool to adjust movement based on time, but sometimes ( small projects for example ) its easier/simpler/faster to base it on fps
well, carmack never explained why that happened, and I see no reason
why it should happen unless it's an obvious design flaw. I have opengl
code from years ago (it run at 5 fps by that time) which runs at
500 fps now and it works the same than before (ultrasmooth, of course),
and there's no problem with people/cars jumping too much due to
high framerate.
anyway I wouldn't take carmack as a reference in game design... he's
a great 3d engine designer but that's all. He's been doing the same
game again and again for 15 years and he's still having problems with
ultra fast systems ;)
The only good reason to limit framerate that I see is that you will reduce cpu usage. For a Pocket PC this might lead to less power consumption (correct me if I am wrong) and on a PC your fans might not need to go in full speed making lots of noice.
I don't see any reason why you would need more than 60 fps so I will probably limit my game somewhere around there.
Basing your game speed on framrate means that if your game is based on fast reaction time it will be possible to cheat.
You can just create a program that sets a high priority and then runs a loop that does a Sleep after lets say 100000 iterations and run that program before starting the game.
I might also add that it is preferable to use a performance counter instead of GetTickCount(), especially on a PC.
Another thing is that on a PC Sleep is not as accurate as on Windows CE (>=3.0).
I think it should be pointed out that the limitation to 60fps for Doom is intended to limit how often the game state is updated. Typically, Quake would update the game state (eg, move objects with regards to velocity, poll inputs) at the same rate as the renderer (ie, each time a new frame needs to be drawn). This meant that running it at 10fps would demonstrate small differences when compared to running it at 60fps, due to the increased resolution of updates.
Due to the nature of movement, this also led to some maneouvres being possible when running at 60fps, but not 10fps, and vice versa. One example Carmack describes are certain jumps that cover a slightly larger distance due to the resolution - quite an inconsistent model!
This could be solved by more math in the engine, but IMO Carmack made the correct decision to limit the FPS (both of the game and the renderer) instead.
So, since Doom updates at a rate 60Hz, the renderer is also (I believe) capped at 60fps, to avoid rendering almost duplicate frames.
Wyrd, just a quick question. I like the idea of time-based animation but I'm a bit afraid of debugging it. What happens when you debug your code line by line and obviously the internal timer is still ticking while you're examining the code? For instance you've got a problem with frame animation. Can you debug it frame by frame when using time-based animation? I doubt it. FZametti's frame-limiter solution looks easier to debug however it has its own limitations. Sorry if I missed something. Can you shed light on this pls.
My only other comment on all this would be to argue that 24FPS isn't as choppy as you might expect in some cases, and as supporting evidence of this I would say to wait for the release of my game

See how that runs, and then decide whether I made a horrible decision or not. I think you will be surprised.
That being said, I think it's reasonable to say that the type of game needs to be considered in all this too. For instance, I would NEVER say that Halo should be limited to 24FPS! But then again, I don't think Pac-Man needs 60FPS either. My game is much closer to Pac-Man than Halo. A FPS needs all the speed it can get, but for a 2-D side-scroller, or something like River Raid for instance, FPS doesn't matter nearly as much, and in those cases I would still contend that the benefit of (a) simpler code, even if only marginally so, and (b) the same smoothness in addition to constant speed on all devices is worth more than those extra FPS.
Your right though, we have different opinions (unless you agree with what I just said, in which case we're close than you might have thought

), and different opinions are great.
It is possible to run the game at exactly the same speed on all devices, and it's possible at 60FPS.
To do that you have to separate the Game Logic and the Frame Display.
1 / game logic
2/ frame display
3/ flip screen
on fast devices :
123 123 123 (60fps display, 60fps logic)
on slower devices
12 13 12 13 (30fps display, 60fps logic)
In my tests, users almost don't noticed the difference between the two, because the game was still reacting at 60FPS...
Given the fact thar your game logic (and then animation system) is running at a constant speed, I don't see why you need to base animation on time. (you may need floats to do that properly, and this is slooow)
StephC wrote:
on slower devices
12 13 12 13 (30fps display, 60fps logic)
this is frameskipping, same technique as video game emulators use to make the game run at full speed on systems that can´t afford the full fps.
that´s what i´ll use on my next game, but you don´t need the "2" where the "3" is not present, at least in the way I understood your explanation.
StephC wrote:
(you may need floats to do that properly, and this is slooow)
you sure need floats, unless one wants to simulate the floats with fixed point arithmetic, but this just adds to the complexity
StephC is correct. This is what I'm doing in my current game.
It runs at 30fps, period. That's 33ms per frame. On my device, game logic and rendering takes about half that time, but it doesn't run at 60fps because it is limited to 30fps.
However, if things get busy and it does take longer than 33ms, the game starts dropping the rendering of frames (but not the game logic). The game logic still runs at 30fps.
Everything in my game is animated based on frames, but that's not a problem because I'm guaranteed that 30 frames occur in one second. So it is both frame-based and time-based, if you will.
I'm using GapiDraw 2.04, however, and I am experiencing a problem which I posted about but nobody has commented on yet. I find that GD204 does not recover the lost time when a frame takes too long to render, it just continues at 30fps after the slowdown instead of running quicker to make up for lost time. Yes there is slack time after, my game usually only slows for a few frames when it does.
I thought it was supposed to, since the documentation says it will sleep less if a frame takes longer, but maybe that's only if it takes longer but still less than FRAMEOVERTIME. The documentation is unclear and I don't have an answer yet.
If GD simply doesn't do that, I'm going to have to screw around with the frame rate (in fps) to compenstate, and that's a can of worms I really don't want to open (and shouldn't have to).
HTK":294gk4i8]
Yes, frameskipping, and this is efficient with devices that have a slow flipscreen (MediaQ etc), and this is what we call "slow devices" in the PocketPC world.
You need the 2 when the 3 is not present.
It's interlacing of frame display and flipscreen, at half the frame rate.
StephC:
Yes, timed animation and movement requires float precision. There's no other way to achieve it.
Sparkie:
I've never had a problem debugging with timed movement and animation.
wyrd wrote:StephC:
Yes, timed animation and movement requires float precision. There's no other way to achieve it.
Don't you heard that ARM CPU don't have any FPU unit ?
No FPU mean calling a (slow) function for each floating point operation.
In fact division and modulos (hidden division) are also prohibited in my "pocket pc games design rules".
fixed point calculations is good enough
I usually use 16 simulation ticks / second and interpolate the position of the sprites between them to maximize the frame rate available on the device. Hell 8 sim ticks/sec is often enough.
I use a power of 2 so that interpolation is quickly done using fixed point maths.
Doesn't Quake (1 and 2 at least) use a 10fps resolution for the network traffic, with position limited to 1/8 of a unit? So your client may run faster and with greater position, but the communication to the server is slower and with less precision. Something like that anyway.
Hmm, interesting. I guess this would be one of those cases where PC programming doesn't translate too well.
I guess I'll have to find another approach to time based animation.

Perhaps Thierry could enlighten us about this, since he seems to be using time based animation and movement as well (I'll admit that I'm not a performance freak in terms of squeezing out every ounce of power, nor do I even know how to in most cases, so I'll leave that discussion for someone who actually knows about it).
EDIT:
Nevermind, he already did.
StephC wrote:
You need the 2 when the 3 is not present.
It's interlacing of frame display and flipscreen, at half the frame rate.
oh ok, I thought you said 12 123 12 123
my mistake
Mine is more like 123 123 1 123 123 1 123 1, because it normally keeps up to 30fps, and just drops drawing altogether if it is not keeping up, since that's usually only for a few frames. It has the effect that it will drop every other frame or so if bogged down. I may tweak this later, though, I'm still working on frameskipping and hit a bit of a snag.
Ok, another suggestion for PF features...
How about adding something to the main window (or whatever you want to call it) framework so that it will only allow 1 instance of the application. I have code that will do this, but it seems like most people would want this.
Of course, I expect someone to say that the PF app shouldn't be minimized, but I have had cases where a battery warning pops up or other things that caused the user to loose focus on the app. Then they start another copy...
It's a simple check if you know the window title (which is being set by the m_config.szWindowName in the game class constructor).
Another suggestion...
It is my understanding that some devices send a "phantom" keyDown and keyUp message before sending the real value... Most of the time I guess this doesn't bother anyone because we check for values that are a member of a keylist structure, so we are in essence just ignoring those "phantom" values.
My suggestion is this... just like in electronics where you have to add a debounce piece to a circuit to stop mechanical switches from bouncing, it might be nice if PF did the same thing and "ate' those phantom values and only send the valid ones. I of course assume it doesn't already?!?
Here's why I'm thinking of this...
In my current game I want to include a key mapper. Now, this is easy enough if you do something like this:
- Code:
// In keyUp handler...
if (we_are_mapping_the_up_button) {
if (keyPressed == keylist.vkA) { myUp = keylist.vkA; }
if (keyPressed == keylist.vkB) { myUp = keylist.vkB; }
// ... and so on through the members of the keylist struct
}
}
Then, in all the actual game code button handlers I just compare what is sent in to the variable myUp. Easy. It even, I think, does away with that phantom value, since it's just ignored (that presumes the value doesn't match one of the values in the keylist of course, otherwise this doesn't work right).
But, it would be nice to be able to do this instead:
- Code:
// In keyUp handler...
if (we_are_mapping_the_up_button) {
myUp = keyPressed;
}
That would even allow you to map buttons that don't have values in the keylist.
I'm not sure that's possible, and I'm even less sure I fully understand the problem, but I'm making the suggestion none the less on the off chance that I DO get it

I've brought up the non-standard values for keys a few times before... Usually the solution is just "provide a keymapper".
I'll use the wonderful Axims as an example. [/sarcasm]
On the Axim X5, GetKeyList returns as default:
vkA - Leftmost Key
vkB - MidLeft Key
vkC - MidRight Key
vkStart - Rightmost Key
On the Axim X3, it returns as default:
vkA - MidLeft Key
vkB - MidRight Key
vkC - Rightmost Key
vkStart - Leftmost Key
On the h1910, GetKeyList returns as default:
vkStart - button in the center of the d-pad
It's all pretty nuts. Even the same manufacturer returns different values. Of course, with the different button configurations coming out (like buttons wrapped around the d-pad), you can't rely on button placement.
So anyway, if you're going to use the buttons, you really have no choice but to include a keymapper. The only alternative would be to intercept the value, compare it to a master device/keycode list, and send an alternative value to ButtonDown() and ButtonUp() (like BUTTON_A, BUTTON_B, etc). But nobody's going to build a master list and do that, because it would be obsolete when the next device came out.
-John
Frank,
Your second thought, about mapping values to any button, is definitely possible. (I do it in Dr. Pocket.) But, you have to ignore the dummy (ghost) values in your keymapper for it to work:
91 - for the buttons
132 - for the D-Pad
If there are other dummy values, I don't know what they are.
-John
Yes, that was my concern... I've heard a couple of people say that there are in fact other ghost values, it's not consistent. That's why my current key mapper code only looks for values in the keylist (which of course means you can't map any of the "non-standard' buttons), because that's the only way I could see to deal with those ghost values consistently. I can live with the limitation that puts on what buttons can be mapped, but if the underlying library had a list of the ghost values, your right, it could be done and would make life a lot easier on the app developer, and open up those other buttons. I just don't know how big that list would wind up being.
The right way to do it is simply to compare the key code with what values are in the keylist. There is simply no other way. Why do you have a problem with that?
I have a problem with that because if a value isn't in the keylist, then effectively you can never map to it. I mean, as an example, what about the record button on my Axim? Is there a value in keylist for it? If not, I can never use it. What about new devices that come out with more buttons? Same deal.
The simple solution would be to take the value that is passed to the key event handler and assign that to my variable corresponding to some action I want mapped, as in my example (i.e., map my variable vkUp to whatever is passed in and then I can use my vkUp variable to determine when up was pressed, even if up is mapped to the record button for example). The problem is that I can either (a) check the passed value against keylist, as I'm now doing, which gets back to the unmappable button issue, or (b) just take the value passed in and use that, which leaves the possibility it's actually a phantom value.
It's quite possible I don't understand something here, so feel free to correct me if I'm wrong on something here. I think the same issue exists in GD by the way, in fact that's what I have in my head right now thinking this through, so maybe it doesn't even apply to PHAL?
PHAL will return you all the keys, not only the one that GapiDraw can return. So it shouldn't be an issue.
Here is a nice reference for key codes:
http://www.cewindows.net/developer/pocketpcbuttons.htm
You will notice that all PPCs use VK_UP, VK_DOWN, VK_LEFT and VK_RIGHT for the arrow keys. You will also notice that most DPads can be pressed and VK_RETURN (0x0D) will be the key code. This code is often misinterpreted as a so-called "ghost key" on the DPad when it fact it is not.
Then the hardware buttons usually are in the C0-CF range.
I don't know if there is any exceptions (I think my E-125 has 0x86 for one of the keys), but it seems you can deal with this without even having a key list returned by PHAL, GD or anyone else.
Another suggestion... it would be very nice if PF contained functions to retrieve the total amount of memory used by an app. It might be even nicer if it could give me total app memory as well as total memory used by surfaces, fonts, etc.
PHAL will return you all the keys, not only the one that GapiDraw can return. So it shouldn't be an issue.
? GapiDraw forwards all key codes to the application, not only vkA, vkB, vkC, etc. GapiDraw also translates vkUp, vkDown, vkLeft, vkRight to the current display rotation. Did you mean "GAPI"?

Johan wrote: GapiDraw forwards all key codes to the application, not only vkA, vkB, vkC, etc. GapiDraw also translates vkUp, vkDown, vkLeft, vkRight to the current display rotation. Did you mean "GAPI"? ;)
GapiDraw's documentation describe the GDKeyList as follow:
- Code:
typedef struct _GDKEYLIST
{
DWORD vkUp;
DWORD vkDown;
DWORD vkLeft;
DWORD vkRight;
DWORD vkStart;
DWORD vkA;
DWORD vkB;
DWORD vkC;
} GDKEYLIST;
Which is exactly the same key codes returned by GAPI. If you are returning more keys then this, then my apologies. PHAL does return up to 8 more key codes (aux1,aux2,...)
Aha, ok. Well, GapiDraw forwards all key presses to the application. The key list is primary to simplify for translating the key presses to the display rotation, and checking against the values in the key list. While many games rely on vkA, vkB, and vkC (and aux etc as you have labeled some button codes in PHAL), I believe that key lists should merely be used for arrow keys for simplification, and that the user should be able to define what keys do what in the game...
The key list is the only known way (around these parts) to handle the "shadow keys" issue. Since PHAL returns all the hardware key codes, there isn't a need to handle these "shadow keys" anymore.
I just ran across an issue with intentionally minimizing a pocketfrog app...
It sucks up a lot of processor time even though it's suspended.
I seem to have fixed it with the following in game.cpp
- Code:
// Main loop
for(;;)
{
MSG msg;
if (::PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
{
if (msg.message == WM_QUIT)
break;
::TranslateMessage( &msg );
::DispatchMessage( &msg );
}
else
{
if (!m_bSuspended)
GameLoop();
else // <--- added by JLE
Sleep(200); // <--- added by JLE
}
}
This shouldn't hurt performance at all for apps that stay full screen, right? And paired with the 'one instance' mod, it will allow a pocketfrog app to be minimized and restored well.
Jason
fast_rx wrote:I just ran across an issue with intentionally minimizing a pocketfrog app...
I think you can also use a MsgWaitForMultipleObjects instead of sleep, which sleeps a certain amount of time (or infinite time) and wakes up when receives a certain stimulus.
i.e. MsgWaitForMultipleObjects (0, NULL, FALSE, INFINITE, QS_ALLINPUT);
will wait forever, until any input (includes window messages) arrives.
anyway Sleep (200) should be good enough. :)
MsgWaitForMultipleObjects is definately better because if a broadcast message are sent you risk that the system (or process sending the message) will hang for 200 ms.
So instead of Sleep do:
MsgWaitForMultipleObjects(0, NULL, FALSE, 200, QS_ALLINPUT);
Another approach would be not to run the game(/application) loop at all when the app is minimized but it depends on what your game(/application) must do when it is minimized.