Theorical question about the sprites

SGDK only sub forum

Moderator: Stef

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Theorical question about the sprites

Post by dub » Wed Nov 04, 2015 9:24 am

Always doesn't working. I don't understand why ? Only the sprite 0 is drawing on screen.

One with setSetprite :

Code: Select all

#include "genesis.h"
#include "gfx.h"

int main()
{
    u16 wmt = tile_sprite.w; 
	u16 hmt = tile_sprite.h; 

	VDP_setPalette(PAL2, tile_sprite.palette->data); 
	VDP_loadBMPTileData((u32*) tile_sprite.image,  2, wmt / 8, hmt / 8, wmt / 8 ); 
		
	VDP_resetSprites(); 
	
	VDP_setSprite  ( 0, 0, 160,    SPRITE_SIZE(2, 2),    TILE_ATTR_FULL(PAL2, 0, 0, 0, 2), 0 ) ;
	VDP_setSprite  ( 1, 60, 160,    SPRITE_SIZE(2, 2),    TILE_ATTR_FULL(PAL2, 0, 0, 0, 9), 0 ) ;
	
	VDP_updateSprites(); 

	
    while(1)
    {
	VDP_updateSprites();		
        VDP_waitVSync();
    }
	return (0);
}
And one with setSpriteDirect :

Code: Select all

#include "genesis.h"
#include "gfx.h"

int main()
{
    u16 wmt = tile_sprite.w; 
	u16 hmt = tile_sprite.h; 

	VDP_setPalette(PAL2, tile_sprite.palette->data); 
	VDP_loadBMPTileData((u32*) tile_sprite.image,  2, wmt / 8, hmt / 8, wmt / 8 ); 
	
	VDP_setSpriteDirect  ( 0, 0, 160,    SPRITE_SIZE(2, 1),    TILE_ATTR_FULL(PAL2, 0, 0, 0, 2), 0 ) ;
	VDP_setSpriteDirect  ( 1, 60, 160,    SPRITE_SIZE(2, 1),    TILE_ATTR_FULL(PAL2, 0, 0, 0, 9), 0 ) ;

	
    while(1)
    {
        VDP_waitVSync();
    }
	return (0);
}
my gfx.res : BITMAP tile_sprite "data\sprite.png" 0

Everything seems good in VDP part:
Image

I add the src / build file https://www.dropbox.com/s/vtz5pl4wwm3s8 ... 4_test.zip

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Theorical question about the sprites

Post by Stef » Wed Nov 04, 2015 9:28 am

The megadrive VDP sprite system work as a chained list. The link field in the sprite structure give you the information of the next sprite to draw and 0 mean end of the list, I guess that is your problem.

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Theorical question about the sprites

Post by dub » Wed Nov 04, 2015 10:07 am

Thanks. I was thinking that the link was for the metasprite :oops:

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Theorical question about the sprites

Post by Stef » Wed Nov 04, 2015 1:52 pm

Meta sprite is only a software concept (does not exist in the MD VDP) and 'link' is definitely something inside hardware. Very practical to quickly change priority of sprites (Y/Z ordering) and just to hide some of them.

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Theorical question about the sprites

Post by dub » Wed Nov 04, 2015 4:37 pm

Fine. :D
Thanks for the informations.

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Theorical question about the sprites

Post by dub » Wed Nov 11, 2015 10:32 am

It's great. I added my sprite function and it's working well.

2 scrolls with Big Sprite and 80 sprites at full 60 Hz without tearing.

Image

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Theorical question about the sprites

Post by dub » Sun Nov 15, 2015 10:51 am

Another question :

I have
Image

Want this
Image

I have my yellow tile plane in Plan_B with multiscrolling and my HUD in Plan_A with no scrolling and transparent tiles in the low part.

I want to change the lower tiles of my Plan_A with new tiles to hide (not entirely) the background when the game is in pause.

For drawing all my tiles in the beginning I use something like that :

SYS_disableInts();
VDP_setEnable(0);

...

u8 i,j;
for(i=0;i<6;i++)
{
for(j=0;j<40;j++)
{
VDP_setTileMapXY(VDP_PLAN_A, TILE_ATTR_FULL(PAL1, 0, 0, 0, mine[j+(i*40)] ), j, i);
}
}

for(i=6;i<30;i++)
{
for(j=0;j<40;j++)
{
VDP_setTileMapXY(VDP_PLAN_A, TILE_ATTR_FULL(PAL1, 0, 0, 0, 75 ), j, i);
}
}

VDP_fillTileMapRect(VDP_PLAN_B, TILE_ATTR_FULL(PAL0, 0, 0, 0, 79), 0, 0, 512 / 8, 512 / 8);


VDP_setEnable(1);
SYS_enableInts();
But, using VDP_setEnable(0);, I have a black screen while the tiles are drawing.

So if I want to change the lower part of my Plan_A in game, I can't use vdp_setenable(0) and I see the tiles drawing on screen, line per line. It's fast but not enough to fill all the empty tiles. I use :
for(i=6;i<30;i++)
{
for(j=0;j<40;j++)
{
VDP_setTileMapXY(VDP_PLAN_A, TILE_ATTR_FULL(PAL1, 0, 0, 0, 78 ), j, i);
}
}
How can I make to draw all the tiles on screen without seeing the drawing ?
Do we need to stop some interrupts, lik vertical or horizontal ?

Thanks.

mikejmoffitt
Very interested
Posts: 86
Joined: Fri Sep 25, 2015 4:16 pm

Re: Theorical question about the sprites

Post by mikejmoffitt » Fri Nov 20, 2015 11:02 pm

You should put your HUD in the Window plane, as it's made for this. Anywhere the Window plane is being revealed it will replace Plane A. It is hard to explain without a visual example. This will let you use Plane A and B for your game.

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Theorical question about the sprites

Post by dub » Sat Nov 21, 2015 1:12 pm

Thanks, I'll try this.

I've always thinking you can use only Plan A or Window plane. But not the two on the same frame. I'll make an attempt.

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Theorical question about the sprites

Post by dub » Fri Dec 11, 2015 12:26 pm

I have a new error and it's come from my C langage variable.

I have an array like :

Code: Select all

static const u16 lev0B[16800] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0 ...};
I use a function to create my map :

Code: Select all

void SCR_screenDraw(u16 plan, const Bitmap nTiles, u16 nIndex, u8 nSizeH, u8 nSizeV, const u16 nPal, u8 nPlanSizeH, u8 nPlanSizeV, const char str[])
It's a simple generic function to draw tiles in layer. But I have a error on the last variable. This is the variable for making a link to my array. "const char str[]".
SCR_screenDraw(.. , .. , .. , .. , .. , .. , .. , .. , lev0B);

The output message is "warning: passing arg 9 of `SCR_screenDraw' from incompatible pointer type".

I have no error when I change the u16 to u8, but I have 300 different tiles values in my array

Code: Select all

static const u8 lev0B[16800] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0 ...};
Or maybe I can change value to hexa ?

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Theorical question about the sprites

Post by dub » Fri Dec 11, 2015 2:13 pm

Once again, I've found the answer after losing my time. :mrgreen:

u8 = char and I forgot the pointer of the array.
I change my array to static const u16 and use "const u16 * str" in my function with the pointeur.

mikejmoffitt
Very interested
Posts: 86
Joined: Fri Sep 25, 2015 4:16 pm

Re: Theorical question about the sprites

Post by mikejmoffitt » Fri Dec 11, 2015 4:57 pm

EDIT: Whoops, I replied without reading through most of the thread (just the first few posts). This may not help you that much in the end but I've left it here just in case.

If you'd like to try it, you can use my sprite support code:

https://github.com/Mikejmoffitt/LICS/bl ... /sprites.c

and

https://github.com/Mikejmoffitt/LICS/bl ... /sprites.h

At the start of your program, initialize the sprite support code:

Code: Select all

sprites_init()
After that, all you have to do is call

Code: Select all

void sprite_put(s16 x, s16 y, u8 size, u16 attr);

// Example:
// Place a 32x32 sprite in the center of the screen
sprite_put(144, 96, SPRITE_SIZE(4, 4), TILE_ATTR_FULL(0, 0, 0, 0, 4));
to place a sprite. Coordinates are normalized to on-screen coordinates. When VBlank starts, just call

Code: Select all

sprites_dma_simple()
to DMA the necessary sprite table changes.

This uses a cached sprite table which is transferred to VRAM via one DMA per frame, rather than using a loop. Only relevant entries are transferred so it doesn't copy all 80 entries at once if it doesn't need to.

If you want to statically set one sprite, rather than queue them with sprite_put, you can use sprite_set instead:

Code: Select all

void sprite_set(u8 num, s16 x, s16 y, u8 size, u16 attr, u8 link);
// Example:
// Set sprite 0 to be in the middle of the screen (32x32), and link to sprite #1
sprite_set(0, 144, 96, SPRITE_SIZE(4,4), TILE_ATTR_FULL(0, 0, 0, 0, 4), 1);
If you do that, you must then call sprites_dma(u16 spr_num) to tell it how much of the table to transfer.

mikejmoffitt
Very interested
Posts: 86
Joined: Fri Sep 25, 2015 4:16 pm

Re: Theorical question about the sprites

Post by mikejmoffitt » Fri Dec 11, 2015 5:05 pm

dub wrote:I have a new error and it's come from my C langage variable.

I have an array like :

Code: Select all

static const u16 lev0B[16800] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0 ...};
I use a function to create my map :

Code: Select all

void SCR_screenDraw(u16 plan, const Bitmap nTiles, u16 nIndex, u8 nSizeH, u8 nSizeV, const u16 nPal, u8 nPlanSizeH, u8 nPlanSizeV, const char str[])
It's a simple generic function to draw tiles in layer. But I have a error on the last variable. This is the variable for making a link to my array. "const char str[]".
SCR_screenDraw(.. , .. , .. , .. , .. , .. , .. , .. , lev0B);

The output message is "warning: passing arg 9 of `SCR_screenDraw' from incompatible pointer type".

I have no error when I change the u16 to u8, but I have 300 different tiles values in my array

Code: Select all

static const u8 lev0B[16800] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0 ...};
Or maybe I can change value to hexa ?
If you are giving the array data, you can remove the indicator of array size [16800]. The compiler will determine this based on the number of elements in the array.

The problem is that const char str[] is really an array of s8, since s8 is just a typedef to signed char. An unsigned char is compatible as well. In this case, casting to (const u16 *) is fine, like this:

Code: Select all

SCR_screenDraw(..,..,..,..,..,..,..,..,(const u16 *)lev0B);
You will want to use a DMA to do large copies of data, rather than a large loop or nested loops.

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Theorical question about the sprites

Post by dub » Fri Dec 11, 2015 5:47 pm

Thanks for all the infos. I'll read your source code.

And you're right, I always forget the cast :mrgreen:

dub
Very interested
Posts: 101
Joined: Thu Mar 19, 2015 1:26 pm

Re: Theorical question about the sprites

Post by dub » Wed Dec 16, 2015 8:45 am

mikejmoffitt wrote: If you'd like to try it, you can use my sprite support code:

https://github.com/Mikejmoffitt/LICS/bl ... /sprites.c

and

https://github.com/Mikejmoffitt/LICS/bl ... /sprites.h
I try your code but I have a problem with the (VDP_doVRamDMA((u32)sprite_table,sprite_addr,spr_num << 2);)
I need to make a .bin file to use it, right ?

Post Reply