gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Is it a good idea to have a variable declared in a...

#19204 - mr_schmoe - Wed Apr 14, 2004 1:36 am

Ok, basically it's like this. I have an include file sprites.h and the definitions in a cpp file sprites.cpp. The idea is have a sprite class for each sprite in the game. But to copy the attribute data to the OAM it's generally a good idea to have the OAM variable in one long array (i.e. OAMentry sprites[128]; ) so's you can copy it to the actual OAM memory right quickly like. So, what I was thinking is have the OAM variable declared and defined in the sprite.cpp and the sprite class just have a pointer to it's particular sprite number in the OAM. I don't want to start an argument on the way I want to handle the sprites, that was just to give you an idea what I was talking about.

#19205 - sgeos - Wed Apr 14, 2004 1:47 am

If I understand what you are trying to do, it sounds like a good idea to me.

You are talking about doing something like this, right? (In C because I don't do the C++ thing.)
Code:
struct oam oam[128];

struct sprite happy_rabbit = {&oam[HAPPY_RABBIT], ...};
struct sprite evil_fluffy = {&oam[EVIL_FLUFFY], ...};
struct sprite icecream_of_doom = {&oam[ICECREAM_OF_DOOM], ...};
...


-Brendan

#19207 - sajiimori - Wed Apr 14, 2004 2:13 am

Quote:

I don't want to start an argument on the way I want to handle the sprites, that was just to give you an idea what I was talking about.

You want to know if it's a good idea, but you don't want to discuss alternatives? So what are you doing, fishing for compliments?

#19210 - yaustar - Wed Apr 14, 2004 2:39 am

Just so I got this right:

Insted of
Code:
sprites[1].attribute etc

you do
Code:
sprites[pacman.spriteNo].attribute etc


No problem with that, keeps things organised, I think it was reccomended in gbajunkie's tutorials...
_________________
[Blog] [Portfolio]

#19212 - poslundc - Wed Apr 14, 2004 3:02 am

My experience: the system you start out with to handle the OAM entries for any application is rarely the one you'll end up with.

So just a pick a method and go with it; you can always revise it later on.

Dan.