Page 1 of 1

Accessing the data from a tileset

Posted: Sun Nov 25, 2018 9:24 am
by darkjoy2k2
i have set up a tile-scrolling effect to create some water effects like in Neutopia 2 and i didnt wanted to use scrolling or sprites for that.

So i set up 2 Images:

Code: Select all

const u32 movtile[2][8] =
{{
		0x81111111,
		0x18111111,
		0x11811111,
		0x81181111,
		0x81118118,
		0x11111811,
		0x11111181,
		0x11111118
},

{
		0x11111118,
		0x11111181,
		0x11111811,
		0x81118111,
		0x81181118,
		0x11811111,
		0x18111111,
		0x81111111
}};

...

for (x = 0; x<8;x++)
{
    movtile_A[x] = movtile[0][x];
    movtile_B[x] = movtile[1][x];
    // movtile_C[] is just a cache
}
And do some circular bitshift to the Variables:

Code: Select all

            
        for (x = 0; x<8;x++)
            {
                movtile_C[x] = movtile_A[x];
                movtile_A[x] = movtile_A[x] << 4 | movtile_B[x] >> 28;
                movtile_B[x] = movtile_B[x] << 4 | movtile_C[x] >> 28;
            }
            VDP_loadTileData( (const u32 *)movtile_A, 3, 1, 0);
            VDP_loadTileData( (const u32 *)movtile_B, 4, 1, 0);
            VDP_loadTileData( (const u32 *)movtile_B, 43, 1, 0);
            VDP_loadTileData( (const u32 *)movtile_A, 44, 1, 0);
Works well and does a nice left shift over every tile have been placed on that number,

Only problem now is instead of defining every tile i like to shift by hand in a field of arrays i´d like to access the tileset i imported with rescomp.

Code: Select all

// gfx.res
TILESET tiles_image "gfx/tiles.png" 0

// main.c
VDP_loadTileSet( &tiles_image, TILE1, 0); //ts_1 is a tileset
tried something like

Code: Select all

for (x = 0; x<8;x++)
{
    movtile_A[x] = tiles_image.tiles[1][x];
    movtile_B[x] = tiles_image.tiles[2][x];
    // movtile_C[] is just a cache
}
Resulting error
src\main.c|243|error: subscripted value is neither array nor pointer nor vector|

Re: Accessing the data from a tileset

Posted: Sun Nov 25, 2018 6:19 pm
by cero
tiles_image.tiles[32/4 * num]

Each tile is 32 bytes. The pointer is 32-bit, so divide by four.

Re: Accessing the data from a tileset

Posted: Sun Nov 25, 2018 9:15 pm
by darkjoy2k2
Thanks! I will try that tomorrow.

In the meantime i made myself a Windows-Aplication to turn an indexed image to a set of values that can be directly in the code... Like to share it if someone is interested because i did not find any Programs with this feature.
https://drive.google.com/open?id=1dW3_F ... ZBm7rLi_-7

Re: Accessing the data from a tileset

Posted: Mon Nov 26, 2018 9:19 am
by cero
Save your image as XPM and open it in a text editor ;) Gimp also has direct "export as C".

Re: Accessing the data from a tileset

Posted: Mon Nov 26, 2018 9:44 am
by darkjoy2k2
Good to know!

i work most with photoshop or Pro Motion NG and
they dont have that feature/module/plugin.

Sometimes DIY works best and gives you most control =)

Re: Accessing the data from a tileset

Posted: Mon Nov 26, 2018 5:30 pm
by darkjoy2k2
cero wrote: Sun Nov 25, 2018 6:19 pm tiles_image.tiles[32/4 * num]

Each tile is 32 bytes. The pointer is 32-bit, so divide by four.
So it really works! Thx!!!

My code is

Code: Select all

        
for (x = 0;x < 8; x++)
{
    movtile_A[x] = tiles_image.tiles[8 * 80 + x];
}
Can i access the tiles stored with VDP_Loadtiledata() too? Or is it a one way ticket?