October 17, 2017, 09:05:00 PM*

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
Advanced search  
Pages: [1]
Print
Author Topic: Sprite Routine  (Read 12334 times)
0 Members and 1 Guest are viewing this topic.
Flash
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 13149



« on: January 20, 2009, 08:27:19 AM »

This is how we are going to have to address the sprites internally, then using a sub to convert the data to sprite display on the relevent screens with the modified coords. On a sprite between 2 screens - 2 sprites will be used to display the sprite as it passes between the 2 screens.



* Sprite coords.png (12.34 KB, 320x448 - viewed 515 times.)
« Last Edit: January 21, 2009, 10:41:48 AM by Flash » Logged

Coding for the love of it!
Flash
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 13149



« Reply #1 on: January 20, 2009, 02:04:55 PM »

Further to the last post, I have worked out the code to do the sprite possitioning on the 2 screens.
The demo posted here (though basic) uses a single sprite to fall through the two screens using the coords shown above. In No$gba, this works as intended, but in Dualis and iDeaS - there is a 2 pixel overlap between the screens. I believe this is a fault with the emus and not the code!  Undecided
When the sprite hits the base of screen 1, 2 sprites are used - one on each screen, until the overlap has passed and then the sprite is moved to the base screen.
The code also handles off side sprites without recourse to negative numbers - makes things a lot easier.
I will pehaps offset the Y pos further, so to add coords above the top screen to handle the mapping of oncoming enemies. This would also make the attack waves a BREEZE to coordinate. The entire wave could be set up off screen and then jusr "let go!".

Ok, for those who look at code - this is a basic first draft and has a lot of expansion to be done to it!
Ie. This will only work with sprites with a maximum of 32 pixels high. Not much use for the far larger bosses! This is easily modified though Wink

PS. Was really trying to put this off... It was a lot easier than i expected! A bit like writing a multiplexor on the c64!

* SpriteTest.rar (50.46 KB - downloaded 271 times.)
* SpriteTest.nds (6.01 KB - downloaded 309 times.)
« Last Edit: January 21, 2009, 10:50:07 AM by Flash » Logged

Coding for the love of it!
BaDToaD
Proterian
Dragon 32
*****
Offline Offline

Gender: Male
Posts: 76



« Reply #2 on: January 20, 2009, 04:03:52 PM »

I love how you can bang the metal and call it easy. You always did freak me out you weirdo Wink

I still remember going to bed with you programming away in your room only to get up in the morning and find you still at it... LOL
Logged
Flash
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 13149



« Reply #3 on: January 20, 2009, 04:38:44 PM »

That was because I am slow!!! Cheesy  Cheesy  Cheesy

It is nice to code in ASM and not have to rely on C to transcode the program to IT'S interpretation. In ASM you write your own code to do a routine rather than someone else library!

Got to love it!!! Smiley
Logged

Coding for the love of it!
Flash
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 13149



« Reply #4 on: January 20, 2009, 07:36:08 PM »

Had another thought about the sprite coord system,If I can work this, then all attack waves can be pre-placed in whitespace and then set in motion!This would be a much easier way of doing it!


* Sprite_coords_=_Revised.png (22.68 KB, 384x799 - viewed 542 times.)
« Last Edit: January 21, 2009, 10:32:46 AM by Flash » Logged

Coding for the love of it!
Flash
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 13149



« Reply #5 on: January 21, 2009, 10:58:38 AM »

Ok, got the code working as intended! Phew! We now have a really nice 384x384 offscreen area in which to construct our attack waves. Once the sprites are placed there, we can move them as if they where active and they will apear on either screen when they reach the screen areas! The code was fairly easy, though at the moment it will only work with sprites of X by32. So, the Y res can only be 32. This is not very good when we want to have 8 pixel bullets and 128x128 pixel motherships. The code can easily be modified to enable any size X and Y though!
Code:
ldr r0,=OBJ_ATTRIBUTE0(0)
ldr r2, =(ATTR0_COLOR_16 | ATTR0_SQUARE)
ldr r3,=576-32
sub r1,r3
cmp r1,#32
addmi r1,#256
sub r1,#32
and r1,#0xff @ Y is only 0-255
orr r2,r1
strh r2,[r0]
@ Draw X
adrl r0,[spriteX] @ get X coord mem space
ldr r1,[r0] @ add ,rX for offsets
cmp r1,#64 @ if less than 64, this is off left of screen
addmi r1,#512 @ convert coord for offscreen (64 each side)
sub r1,#64 @ Take 64 off our X
ldr r3,=0x1ff @ Make sure 0-512 only as higher would affect attributes
ldr r0,=OBJ_ATTRIBUTE1(0)
ldr r2, =(ATTR1_SIZE_32)
and r1,r3
orr r2,r1
strh r2,[r0]

If that makes any sense?

In the code I have used 32 directly rather than muddling it in with the calculations so it is easy to change to a variable for sprite Y size.
« Last Edit: January 21, 2009, 11:01:26 AM by Flash » Logged

Coding for the love of it!
Flash
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 13149



« Reply #6 on: January 21, 2009, 03:33:38 PM »

Ok, sprite code works with the new coord system and also allows for varied sprites and numbers.
So, you can position 128 sprites and have a different image in each and put them anywhere!

Doesn't look very exciting, but it does pretty much underpin a shootem up!

PS. Just realised that I have instinctively put 8 sprites on the screen  Grin

PS2. The code is writing all the sprite data to BUF_xxxx registers. At the moment these are indexed to the real registers, but will be switched to a buffer later. This is so the real registers can be bulk updated in the correct place so that they update correctly on a real DS. You cannot update during Vblank (or the other way round). This is why our sprites stay at 0,0 on a real DS - the coords cannot be updated. This is called - forward thinking... I try to do that now and again Wink

* SpriteTest.rar (85.83 KB - downloaded 272 times.)
* SpriteTest.nds (25.01 KB - downloaded 306 times.)

* Untitled-1.png (5.16 KB, 256x384 - viewed 524 times.)
« Last Edit: January 21, 2009, 06:20:57 PM by Flash » Logged

Coding for the love of it!
headkaze
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 7805



« Reply #7 on: January 21, 2009, 07:52:41 PM »

Great demos Flash, just been checking them out. I feel like I'm falling behind a bit but there is still plenty to do.

Are you sure you can only update sprites during vblank? Sound a little strange. In libnds they have an area for OAM data that is updated all at once as well, so your probably right there.

Looking good Smiley

PS. I find myself working in power of two's all the time, and it makes sense to think like that when your coding Wink
Logged
Flash
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 13149



« Reply #8 on: January 21, 2009, 07:57:37 PM »

Glad you like the code! It is getting there!
It is only a fairly small step to move this into the main code and add firing, then from there (trickier) background collisions. Then attack waves....
So, I am trying to think ahead with everything so that all routines can coordinate to create the whole.

I am sure I read some where that you can only update it in the vblank (or out of it?). Take this example - no vblank. Main game has, and it is not updated!

Logged

Coding for the love of it!
Flash
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 13149



« Reply #9 on: January 26, 2009, 11:55:36 AM »

What would be really great is:-

To take the sprite rotate code, make it flexible and integrate it into the spriteDraw routine.

We could have another line of 128 bytes for Angle. This could be read by the draw code and the attribute applied.

Bet ya $5au you can't/can work it out (delete whichever results in me winning)  Grin
Logged

Coding for the love of it!
headkaze
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 7805



« Reply #10 on: January 26, 2009, 01:44:58 PM »

It would be easy to do IMHO. The sprite and sprite_rs demos are very similar. The only difference is to set a few extra bits, some extra initialization and maintaining special areas of OAM for the rotation. I've already made a set of macro's to make accessing this all pretty easy.

Do we really want sprite rotation in Warhawk? If we need it I'll implement it no problem.
Logged
Flash
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 13149



« Reply #11 on: January 26, 2009, 03:09:32 PM »

I think it is worth adding to the warhawk drawsprite code. It is the code that draws the sprites on top/bottom or both depending on position. If in the middle of the 2 screens, both sprites needs updating.

We could add spriteRotate with 128 bytes and set the relevent sprite to the angle we want for each. It may be used for ship death (sprin it round and crash with explosion) and also end of level bosses could rotate (perhaps)

still it will be a nice adition to our sprite code that may well get used on other things..
Logged

Coding for the love of it!
Flash
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 13149



« Reply #12 on: May 06, 2009, 09:35:28 PM »

I have a feeling this topic is a bit dead?

Is it worth removing it or is the data on the drawsprite code still valid?
Logged

Coding for the love of it!
sverx
RBP Member
IBM PC
*****
Offline Offline

Gender: Male
Posts: 462


"Ow!!! What's that ?!?!"


WWW
« Reply #13 on: August 26, 2009, 06:26:40 AM »

Very interesting topic! Even if it's abandoned, I would like to add a detail: yes, sprites can be rotated (and even scaled!) on a DS, but that can't be done in a 'per sprite' base. Instead, there are 32 classes: each class has its rotation/scaling matrix (4 halfwords) and a sprite which has the ATTR0_ROTSCALE attribute bits should also have a class specified thru ATTR1_ROTDATA(n)  (0 <= n < 32).
So a little bit more of trickery is needed Smiley

Bye!

Logged
Flash
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 13149



« Reply #14 on: August 26, 2009, 06:33:45 AM »

It is a shame that all 128 sprites cannot have individual rotation values.

One way round that is to use 3d. Have a flat texture (spaceship picture) mapped to a single plane and rotated that. Then everything could be rotated.
Logged

Coding for the love of it!
sverx
RBP Member
IBM PC
*****
Offline Offline

Gender: Male
Posts: 462


"Ow!!! What's that ?!?!"


WWW
« Reply #15 on: August 26, 2009, 06:42:13 AM »

Well, indeed is a shame that there's no individual rotation, btw -if you don't need scaling- it's possible to define the classes with values that would split the 360° in 32 parts (will be 11,25° each) or even in 24 parts only (so it's 15° each) and use the class as a 'rotation' value with some degrees resolution.
I bet it won't be bad, sprites are quite small after all Wink

Bye!
Logged
Flash
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 13149



« Reply #16 on: October 01, 2009, 10:05:51 PM »

What would be really nice is to be able to use hardware to rotate a sprite to a buffer and grab rotated data and dump that to an active sprite. Sadly, the rotated data is not stored to be read. Sad

Would be nice to find a way to adress all 128 with rotation rather than the limited 32. Real shame.. Though I am sure there is a way round the limitation somewhere in the hardware.
« Last Edit: October 01, 2009, 10:07:13 PM by Flash » Logged

Coding for the love of it!
sverx
RBP Member
IBM PC
*****
Offline Offline

Gender: Male
Posts: 462


"Ow!!! What's that ?!?!"


WWW
« Reply #17 on: October 02, 2009, 06:06:54 AM »

What would be really nice is to be able to use hardware to rotate a sprite to a buffer and grab rotated data and dump that to an active sprite.

So that you can check per-pixel collisions on a rotated sprite?

Would be nice to find a way to adress all 128 with rotation rather than the limited 32. Real shame.. Though I am sure there is a way round the limitation somewhere in the hardware.

All 128 sprites can be rotated, it's just that there are only 32 possible affine matrix (rotations) at a given moment. But it shouldn't be so hard implement a system that counts all the 128 wanted sprite rotations degrees and -if they are more than 32- assigns to some sprites the closest rotation possibile... if it's well done you won't even notice that approximation.

Logged
Flash
Administrator
Blue Gene Super Computer
**********
Offline Offline

Gender: Male
Posts: 13149



« Reply #18 on: October 02, 2009, 06:56:20 AM »

With rotation, I meant it would be nice if each sprite could have an idividual rotation value. On larger sprites the 32 limit would be much more noticeable.

Not that I can think of a reason to use rotation at the moment, though we nearly did in Warhawk.
Logged

Coding for the love of it!
Pages: [1]
Print
Jump to: