This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Dynamic calculation of resource IDs


Dynamic calculation of resource IDs

Postby fzammetti » Jan 27, 2005 @ 7:09pm

Hello all...

I frequently run into the situation where I have a series of resources, cells of animation for instance, that I need to load into an array. The resources might be named:

GFX_PLAYER_CELL_1
GFX_PLAYER_CELL_2

...and so on. I usually wind up writing code like this (this is for GapiDraw, but ignore that fact, it's still a generic question)...

pPlayer[0]->CreateSurface(NULL, hInst, GFX_PLAYER_CELL_1, TEXT("GRAPHICS"));
pPlayer[1]->CreateSurface(NULL, hInst, GFX_PLAYER_CELL_2, TEXT("GRAPHICS"));

...and so on for all the cells of animation. Here's my question... is there any way to dynamically get the resourceID (GFX_PLAYER_CELL_x) instead of hardcoding it?

I know I could find the resourceID of the first cell and just add one for each subsequent cell, but that will only work if the resources are numbered sequentially, which they might usually be, but I can't assume VC++ will do that, and I don't want to be renumbering them myself each time I add or change something.

Any ideas? Sure, they could be external files, then I could construct the filename dynamically no problem, and I may in fact do that later on, but for development it's usually easier if they are resources, then there's just one file to toss from desktop to PPC to test.

Thanks all!
...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby dan.p » Jan 27, 2005 @ 10:14pm

NOTE: I love discussing game design (especially if it's something within the realm of my understanding), and I ended up rambling on a little bit. Sorry. :)

I don't think there's a dynamic way of doing it. Maybe if you could somehow get access to all of the resources available, then go through them one by one (must like you would if they were files stored in a folder). However, you'd still have to know which cells go with which object. How else would you determine which cell goes with which object if you don't have a hardcoded ID? I personally prefer the hardcoded ID because I have a GraphicManager which keeps track of which graphics are being referenced, which ones need to be created, and which ones need to be destroyed. All graphics I need are retrieved via GraphicManager::Reference(Resource ID);

In any case.. the only "dynamic" solution I can think of would be to try and store the resource.h file as a resource itself, then parse it for #define GFX_* values.

It sounds like you have all of your animation frames (or cells as you call them) as seperate graphics. If this is the case, perhaps you could store the entire animation as a single graphic, then dynamically create the cells when it's loaded. This would at the very least dramatically cut down on your code that needs to be hardcoded. I have a Graphic and Animation class that does just that. Now instead of having to load 32 individual cells for a single animation, you only have to create a single graphic, then have an animation class handle all of the animation stuff for you.

Personally, I have all of the animations for an object stored in a single graphic image (walking, running, jumping, etc.). I then have a Graphic class which breaks it down into an array of cells. After that, I have individual Animation objects which encapsulate Graphic objects and control animations (there are several Animation objects per Graphic object). All of my Graphics are kept track of in a GraphicManager, and Animations are created via AnimationFactory.
dan.p
pm Member
 
Posts: 89
Joined: Jan 6, 2005 @ 6:49am


Postby fzammetti » Jan 27, 2005 @ 10:19pm

Yep, that's one decent approach, the single "sheet" of images for all the cells.

I havne't done that in the past, at least not early on in development, just because it makes it a little harder to make changes and tweak the animation sequences, and that tends to happen a lot early on. That being said, I think I might go that route anyway, it's the best solution I can see.

Don't worry about rambling on by the way... I'm not exactly known for my brevity around here ;)
...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby Andy » Jan 27, 2005 @ 10:39pm

Andy
<font color=red size=3>Troll++</font>
 
Posts: 1288
Joined: Nov 1, 2003 @ 7:36am


Postby fzammetti » Jan 27, 2005 @ 10:47pm

...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby j.edwards » Jan 28, 2005 @ 10:02pm

User avatar
j.edwards
pm Member
 
Posts: 240
Joined: Oct 29, 2003 @ 11:09am
Location: Australia


Postby fzammetti » Jan 28, 2005 @ 10:12pm

...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby rcp » Jan 28, 2005 @ 10:33pm

User avatar
rcp
pm Member
 
Posts: 184
Joined: Jul 18, 2003 @ 2:12am
Location: Duluth, GA. (Southeast US)


Postby fzammetti » Jan 28, 2005 @ 10:59pm

...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby dan.p » Jan 28, 2005 @ 11:12pm

dan.p
pm Member
 
Posts: 89
Joined: Jan 6, 2005 @ 6:49am


Postby fzammetti » Jan 28, 2005 @ 11:24pm

...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby Dan East » Jan 29, 2005 @ 2:00am

You should make your compound image a tall, single-frame width image, which makes each frame a contiguous piece of memory. If the images are side by side in columns then there is a cache miss each scanline.

Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Postby fzammetti » Jan 29, 2005 @ 4:45am

Thanks Dan, I wouldn't have realized that. When I change the code tomorrow to do the "blit with rects" I'll do that too.
...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Postby dan.p » Jan 30, 2005 @ 11:52pm

dan.p
pm Member
 
Posts: 89
Joined: Jan 6, 2005 @ 6:49am


Postby fzammetti » Jan 31, 2005 @ 5:25am

I looked at it for a little while, but I decided against it, for much the same reason I originally had all the animation cells independant: easier to tweak things, especially during development. With something like VFS, I'd need to "rebuild" it when I made a change, and that's just extra work in my eyes. Especially since I have no plans to develop for anything but Win32 and PocketPC. I'm not saying it's a bad suggestion by any means, just pointing ut that I had considered it and ultimately rejected it.

In the interest of not having anyone expending more cycles on this debate than they have to, I want to say that I am actually rather happy with how things are being done now. I'm not by any stretch claiming it's the best way or anything, but it is working for me, and in fact better than before as a result of this discussion. I just didn't want anyone thinking I still had a problem here to be addressed, I no longer do :)

(Of course, feel free to continue to debate in a general kind of way all you like! Discussion is rarely a bad thing!)
...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"
User avatar
fzammetti
pm Insider
 
Posts: 1496
Joined: Jun 4, 2002 @ 6:21pm
Location: Omnytex Technologies


Next

Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum