Understanding oamSet() parameter palette_alpha
Posted: Fri Aug 20, 2010 8:39 pm
Hello everyone, I've been working in C/C++ with libnds for a short while, and I've been making a C++ wrapper class for accessing Sprite attributes. In order to make it low-footprint, it only stores the sprite index and a boolean for which engine (main or sub) it's on until you modify it, at which point it makes a structure containing the arguments for oamSet() from the information stored in OAM at that index, and uses that information until you call update(), which feeds the information back in via oamSet(). I know this is a pretty bad design, and I'm not personally comfortable with it, but I am doing it this way in the hopes of not breaking the underlying sprite representation by writing information back using any means other than oamSet() calls. My intent is to have working code similar to this example:
The problem is, I don't quite understand where the palette_alpha information goes during an oamSet() call, so I can't rightfully read out the previously-set, existing value, while maintaining a low memory footprint AND ensuring similar information access for different instances of Sprite with the same index. Could anyone help me out with this?
Code: Select all
// Get the main OAM state.
OAMState oam(OAMState::MAIN);
// Initialize it to the sprite mapping and extended palette info, and enable it.
oam.init(SpriteMapping_Whatever, false);
oam.enable();
// Grab a handle to sprite 0.
Sprite* pSprite = oam.createSprite(0);
// Set the sprite's X and Y coordinates and graphics data, and update the OAM entry.
pSprite->setX(0);
pSprite->setY(0);
pSprite->setSize(SpriteSize_Whatever);
pSprite->setFormat(SpriteColorFormat_Whatever);
// I'm still deciding upon a format for moving around graphics data using C++, so for now I'm using the old-fashioned way of passing a uint16* around and dmaCopying memory.
uint16* gfx = oam.allocateGraphics(SpriteSize_Whatever, SpriteColorFormat_Whatever);
dmaCopy(someGfxDataPtr, gfx, pSprite->getByteSize());
pSprite->setGraphics(gfx);
pSprite->update();
// Grab the sprite's palette alpha value (as passed to oamSet()), then release the handle.
int alpha = pSprite->getPaletteAlpha(); // <--- How do I get the existing palette alpha value? Where is it located?
delete pSprite;
// Grab a handle to sprite 1.
Sprite* pOther = oam.createSprite(1);
// Set the sprite's palette alpha value to match sprite 0's alpha value, then update it and release the handle.
pOther->setPaletteAlpha(alpha);
pOther->update();
delete pOther;