oamSet modifying sprite ids

Post Reply
awesomejuice
Posts: 3
Joined: Thu Mar 05, 2009 12:39 pm

oamSet modifying sprite ids

Post by awesomejuice » Sun Mar 08, 2009 4:00 am

We've written a Sprite class to handle sprites behind a layer of abstraction. In another class, we create a few sprites sequentially using our Sprite::Sprite() constructor and the new keyword:

Sprite::Sprite()

Code: Select all

Sprite::Sprite ( string name, u8 screen, SpriteSize size, u8 prior, u16 xPos, u16 yPos, u8 width, u8 height )
{
   this->screen = screen;
   setupSprite(name);
   assignId();
   sprite = &oamMain.oamMemory[spriteId]; //sprite is a spriteEntry pointer, oamMemory is a pointer to 
   assignPalette();
   sprite->x = xPos;
   sprite->y = yPos;
   sprite->palette = palId;
   this->size = size;
   this->height = height;
   this->width = width;
   this->priority = prior;

   //oamAllocateGfx returns a u16 pointer gfxindex is just a u16 need to make conversion
   if(screen == 0)
   {
      gfxPtr = oamAllocateGfx ( &oamMain, size, SpriteColorFormat_256Color );
   }
   else
   {
      gfxPtr = oamAllocateGfx ( &oamSub, size, SpriteColorFormat_256Color );
   }

   oamSet(&oamMain, spriteId, sprite->x, sprite->y, 0, palId, size, SpriteColorFormat_256Color, gfxPtr, -1, false, false, false, false, false);
   dmaCopy(spriteTiles, gfxPtr, width*height);
   
}
If we print out the member Sprite::spriteId (a u8), they look fine until after the third one is made. It seems like oamSet, the only thing that should interact with spriteId, is changing that Id somehow.

Inside of our second class "Inventory"

Code: Select all

   spriteR1C1 = new Sprite("invR1C1", 0, SpriteSize_64x64, 0, 0, 100, 64, 64);
   spriteR1C2 = new Sprite("invR1C2", 0, SpriteSize_64x64, 0, 64, 100, 64, 64) ;
   spriteR1C3 = new Sprite("invR1C3", 0, SpriteSize_64x64, 0, 128, 100, 64, 64);

   // Breaks here after the third sprite is created

   spriteR1C4 = new Sprite("invR1C4", 0, SpriteSize_64x64, 0, 192, 100, 64, 64);
   spriteR2C4 = new Sprite("invR2C4", 0, SpriteSize_64x64, 0, 192, 164, 64, 64);
If we write a iprintf statement after each sprite is created, their IDs show up fine up till the third is created. Here is what it looks like:

Code: Select all

s1 s2 s3 s4 s5
0
0  1
0  1  2
0  3  2  3
0  4  2  4  4
- Each number represents a sprite id. Each line has a one more than the previous because we're printing out new lines after another sprite is created.

Our Questions and concerns:
- What does oamSet() do, and can we have the code for it? We would like to see what it does so we can possibly know what we can do differently.
- We are confused as to how the spriteIDs are being changed. This is causing us difficulty because our collision algorithm is being affected by it implicitly. We are testing the wrong sprites because due to the ID changing, our SpriteEntry* pointers are being altered in a strange way.

Oddly enough, the sprites do appear on the screen correctly...

Any help and input is greatly appreciated.

Sylus101
Posts: 179
Joined: Wed Dec 24, 2008 5:08 am

Re: oamSet modifying sprite ids

Post by Sylus101 » Sun Mar 08, 2009 6:27 am

I don't follow C++, but I think I can answer the question on oamSet.

It took me a bit at first to understand it, but all oamSet does is assign values for a particular entry in the hardware's OAM supplied by the second parameter. In short, you're not assigning an Id, but telling oamSet which already existing spot (0-127) in the OAM to update information for.
-Sylus "Not Stylus..." McFrederickson

Come visit my web site.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest