dealing with matrices (arrays)

SGDK only sub forum

Moderator: Stef

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

Re: dealing with matrices (arrays)

Post by Stef » Thu Nov 22, 2018 12:25 pm

Better to do it in this way:

Code: Select all

VDP_setWindowAddress(0xB000);
VDP_setSpriteListAddress(0xBC00);
VDP_setHScrollTableAddress(0xB800);
VDP_setBPlanAddress(0xC000);
VDP_setAPlanAddress(0xE000);

VDP_setPlanSize(64, 64);
Normally having the sprite table at 0xBC00 should be alright so i guess the problem is somewhere else ;)

nemezes
Very interested
Posts: 69
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Fri Nov 23, 2018 2:12 am

Stef wrote:
Thu Nov 22, 2018 12:25 pm
Better to do it in this way:

Code: Select all

VDP_setWindowAddress(0xB000);
VDP_setSpriteListAddress(0xBC00);
VDP_setHScrollTableAddress(0xB800);
VDP_setBPlanAddress(0xC000);
VDP_setAPlanAddress(0xE000);

VDP_setPlanSize(64, 64);
Normally having the sprite table at 0xBC00 should be alright so i guess the problem is somewhere else ;)
Yes, you are right! the problem was another one.

I start using " VDP_setScrollingMode(HSCROLL_TILE,VSCROLL_PLANE); " and so as I set plansize to 64x64, I thought I would need to scroll 64 tile lines.

then I start to test, and test, and test :lol: erasing lines and realize that I have to move the normal resolution screen 28 tile lines.

also, thats why I was getting trouble with the same comand that uses pixel lines, I was trying to move 514 lines, and should use 224.

I was using something like this:

Code: Select all

/* ---- WRONG CODE --- */

u8 i;
velScroll3 -= 1;

for (i = 0; i <= 63; i++)
{
      hscroll3[i] = velScroll3>>3;
}

VDP_setHorizontalScrollTile(PLAN_B, 0, hscroll2,64,0);
but when I set to

Code: Select all

/* ---- CORRECT CODE --- */

u8 i;
velScroll3 -= 1;

for (i = 0; i <= 27; i++)
{
      hscroll3[i] = velScroll3>>3;
}

VDP_setHorizontalScrollTile(PLAN_B, 0, hscroll2,28,0);
everything worked fine. :D Thanks!!

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

Re: dealing with matrices (arrays)

Post by Stef » Mon Nov 26, 2018 9:47 am

Haha, really glad you were able to fix all that, well done :)

nemezes
Very interested
Posts: 69
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Wed Dec 19, 2018 6:17 pm

Another small question. I wanna use about 70 sprites on screen, but I can only show 64.

Is there a way to use more than 64? All the sprites are 16x16 pixels.

I read some old doc of sgdk saying that only PAL can go to 80 sprites. I think 70 or 75 sprites will fit in the game. Is there a problem using this amount of sprites?

One thing I noticed is that I setup more than 64 sprites, but the 65 will only show when I hide one of the first 64.

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

Re: dealing with matrices (arrays)

Post by Stef » Thu Dec 20, 2018 9:30 am

You are limited to 64 in H32 mode (256 px wide screen), H40 mode (320 px wide screen) allows 80 sprites.
You're probably using H32 mode then ?

nemezes
Very interested
Posts: 69
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Thu Dec 20, 2018 1:42 pm

my bad, I was using VDP_init() after setting VDP_setScreenWidth320(), so VDP_setScreenWidth320() was taking no effect. :roll:

EDIT: sorry, I thought, I corrected the problem, but still there. some sprites didnt show. I thought I corrected because it was sprites at bottom that did not show, but then it was sprites at top, so I was looking down and thought I corrected it. my bad again. :roll:

I will take a look again and see what I am doing wrong.

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

Re: dealing with matrices (arrays)

Post by Stef » Fri Dec 21, 2018 8:25 am

no worries.. i hope you will be able to sort that out.
Just for your information, when you call VDP_init(), by default it use the H40 mode (so 320 px wide mode) :)

nemezes
Very interested
Posts: 69
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Mon Feb 18, 2019 8:53 pm

I use a lot the "sprite" example that came with SGDK to make my games, but now I figured out that using the functions

Code: Select all

JOY_setEventHandler(joyEvent);

static void joyEvent(u16 joy, u16 changed, u16 state)
{
 etc
}
it works for any controller. so if I have a one player game, but use those functions, if I press A, B, C or START on controller 2, everything will work.

is there a easy way to use those functions just for controller 1 or 2?

I am trying to make a 2 players game, but if I use these functions in this way, everything I press for controller 1 or 2 will affect both players.

wanna know if I can make a joyEvent1 and joyEvent2 then use

Code: Select all

JOY_setEventHandler(joyEvent1);

JOY_setEventHandler(joyEvent2);
is it possible?

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: dealing with matrices (arrays)

Post by Chilly Willy » Mon Feb 18, 2019 9:31 pm

Not directly. The joyEventCB is universal for all controllers, but passes the index as a parameter. You can make your own jump table and fill it in and then do something like

Code: Select all

void setJoyEventCBEntry(u16 joy, eventCBEntry cb)
{
    eventJT[joy] = cb;
}

void myJoyEventCB(u16 joy, u16 changed, u16 state)
{
    if (eventJT[joy])
        (eventJT[joy])(changed, state);
}

nemezes
Very interested
Posts: 69
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Tue Feb 19, 2019 1:31 am

Chilly Willy wrote:
Mon Feb 18, 2019 9:31 pm
Not directly. The joyEventCB is universal for all controllers, but passes the index as a parameter. You can make your own jump table and fill it in and then do something like

Code: Select all

void setJoyEventCBEntry(u16 joy, eventCBEntry cb)
{
    eventJT[joy] = cb;
}

void myJoyEventCB(u16 joy, u16 changed, u16 state)
{
    if (eventJT[joy])
        (eventJT[joy])(changed, state);
}
Thanks! I will try it. :)

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

Re: dealing with matrices (arrays)

Post by Stef » Tue Feb 19, 2019 9:01 am

Why just not doing this ?

Code: Select all

static void joyEvent(u16 joy, u16 changed, u16 state)
{
    if (joy == JOY_1) joy1Event(changed, state);
    else if (joy == JOY_2) joy2Event(changed, state);
}

static void joy1Event(u16 changed, u16 state)
{
    // player 1 stuff
    ...
}

static void joy2Event(u16 changed, u16 state)
{
    // player 2 stuff
    ...
}
You don't even need the if (joy == JOY_2) test if you don't use multiplayer.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: dealing with matrices (arrays)

Post by Chilly Willy » Tue Feb 19, 2019 2:07 pm

That would be the easier way to handle it. If you did use more than two controllers, the function jump table would be faster than a bunch of compares.

nemezes
Very interested
Posts: 69
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Fri Apr 05, 2019 5:59 pm

the 2 players mode that I want to implement is working fine.

here is a video preview of the game (just one player): http://www.youtube.com/watch?v=1juF43JWcIU

the game is called Irmãos Aratu (aratu brothers).

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Re: dealing with matrices (arrays)

Post by Chilly Willy » Sat Apr 06, 2019 1:48 pm

Game looks pretty cool. The purple colored skin is a bit odd, but Sega is chock-full of odd characters. :lol:

nemezes
Very interested
Posts: 69
Joined: Sat Mar 31, 2018 1:09 pm

Re: dealing with matrices (arrays)

Post by nemezes » Wed Apr 17, 2019 11:34 pm

could happen a problem if I install a new version of java in my computer?

I was using an old version of java, then I needed to install a new one, when I did it, the background of my game get really weird. it is not displaying the image as it is. I get only some vertical bars on screen.

I was reading the documentation and the forum and I find that if I use the option FAST for background images it uses java in rescomp. now I change everything to NONE and the game is working again (phew! I was afraid to lost all the work), also the ROM shrinks size.

is there a major difference between those compressions?

Post Reply