Page 1 of 2

Shared tiles and palettes

Posted: Fri Aug 26, 2011 9:09 pm
by headkaze
I cannot seems to get this feature to work in a makefile. The only information I can find is in the readme
Special: batch bitmap->tilemap conversions. This is an example
makefile rule for mapping and converting many bitmaps into a
file with tilemaps and a shared tileset.
The following converts files a1.bmp a2.bmp and a3.bmp to regular 8bpp
tilemaps. The maps are stored into tilemap.s, WITHOUT the palette or
tiles. The -fx option gathers the tileset into tiles.bmp, which is
converted into a palette and tileset by the second command in the
rule.

Code: Select all

GIT      := grit.exe
BMPS   := a1.bmp a2.bmp a3.bmp
TILESET   := tiles.bmp

tilemap.s : $(BMPS)
   $(GIT) $^ -o $@ -fa -fx $(TILESET) -p! -g! -mR8
   $(GIT) $(TILESET) -o tileset.s
I've tried to follow the example but cannot get anything to output. Is there an actual working example or can someone post a working makefile?

Re: Shared tiles and palettes

Posted: Sat Aug 27, 2011 12:33 am
by mtheall
In my experience, shared gfx will only work if the first image processed has all the colors of the remaining images in its palette. This can be fairly easily achieved by using usenti to build up your palette.

Re: Shared tiles and palettes

Posted: Sat Aug 27, 2011 12:46 am
by mtheall
Actually, I have some more notes. It's not enough to simply put all the other file's colors into the first image's palette. Those colors have to actually appear in the first image. What I've found useful is to just combine all the images into one master image, and then use usenti's built-in "Reduce Tiles" to get an image that is in the format grit expects for an existing master tileset. So in your example, I'd combine a1.bmp a2.bmp a3.bmp a4.bmp into a single image file, "Reduce Tiles", save it as tiles.bmp, and then change the makefile to something like this:

Code: Select all

GIT      := grit.exe
BMPS   := a1.bmp a2.bmp a3.bmp
TILESET   := tiles.bmp

tilemap.s : $(BMPS)
   $(GIT) $^ -o $@ -fa -fx $(TILESET) -p! -g! -mR8
   $(GIT) $(TILESET) -o tileset.s

Re: Shared tiles and palettes

Posted: Sat Aug 27, 2011 9:47 am
by headkaze
Palettes are not the issue I'm having. All the graphics I need to convert share the same palette already. I can run grit from the command line and generate the tiles.png. I just can't seem to get it to work in a makefile. So I'm really just looking for a working example that will take a directory of png's and generate a single palette along with a tiles.png and header file which will have all the shared tiles and a map file for each individual image. Any help with this would be appreciated.

Re: Shared tiles and palettes

Posted: Sun Aug 28, 2011 4:18 am
by headkaze
Okay forget the makefile for a moment, I can't even get grit to do what I want from command line. Here is my batch file

Code: Select all

@ECHO OFF
SET PATH=C:\devkitPro\devkitARM\bin
grit.exe graphics\*.png -o *.o -fa -fx tileset.png -gt -mRtf -m -gB8 -mLs -gS -pS
grit.exe tileset.png -o tileset.s
This creates a tileset.png along with tileset.s and tileset.h but I can't seem to get the map files for each shared png. When I change "-o *.o" to "-o *.s" it crashes grit.

Re: Shared tiles and palettes

Posted: Sun Aug 28, 2011 6:10 am
by mtheall
Here is a major problem:

grit.exe graphics\*.png -o *.o -fa -fx tileset.png -gt -mRtf -m -gB8 -mLs -gS -pS

Maybe you don't realize this will expand to become:

grit.exe graphics\*.png -o a1.o a2.o a3.o a4.o -fa -fx tileset.png -gt -mRtf -m -gB8 -mLs -gS -pS

Basically this is going to cause grit to try to use a2.o a3.o and a4.o as input image files (or a2.s a3.s a4.s). Maybe grit does something special with '.s' files and that's why it ends up crashing. It could be a number of things.

I've got shared graphics working before; I still need to go back and look at how I did it. When I do, I'll get back to you.

Re: Shared tiles and palettes

Posted: Sun Aug 28, 2011 7:41 pm
by mtheall
Okay I have played around a bit and the resultant "shared image" is always garbage. However, that doesn't mean the exported .h and .s files are garbage! Here is my Makefile:

Code: Select all

PATH:=$(DEVKITARM)/bin:$(PATH)

all: tilemap.s

BMPS   := a1.bmp a2.bmp a3.bmp a4.bmp

tilemap.s : $(BMPS)
  grit $^ -o $@ -ff tiles.grit
This is tiles.grit:

Code: Select all

# include graphics, tiled, 8bpp, shared, array is u8[], transparent color magenta
-g -gt -gB8 -gS -gu8 -gT FF00FF

# include palette, shared, array is u16[]
-p -pS -pu16

# include map, tile and flip reduction, organized in screen blocks
-m -mR8 -mLs

# shared name is tileset, append data (build up shared set)
-S tileset
-fa
Of course, you can put all those rules inline in the Makefile, but I prefer to have separate grit rule files (makes for easy editing). Now you will end up with tilemap.s and tilemap.h. You just need to include tilemap.h and then you will have several things available:
  • a1Map (and a1MapLen #define)
  • a2Map (and a2MapLen #define)
  • a3Map (and a3MapLen #define)
  • a4Map (and a4MapLen #define)
  • tilesetTiles (and tilesetTilesLen #define)
  • tilesetPal (and tilesetPalLen)
tilesetTiles and tilesetPal are the shared graphics and palette, while all the original images retain their own maps. With this setup, you will not get an exported image (it would be garbage anyways, I guess that's a bug with exporting the palette, since the image data actually looks right). The advantage of doing it this way is that there is only one run of grit instead of two, plus everything gets put in one header file, so you don't have to include separate ones for the same shared data.

I hope this helps.

Re: Shared tiles and palettes

Posted: Sun Aug 28, 2011 9:22 pm
by mtheall
Oh yeah, I forgot to mention, this method won't require that all the colors appear in the first image.

Re: Shared tiles and palettes

Posted: Mon Aug 29, 2011 12:49 am
by headkaze
Thanks. This is just about right for my needs. What I need is to change $(BMPS) so it's a directory of png's. I can't seem to get it to work without listing each file manually. I think this is the problem I've been having all along. As soon as I try and change it to be a directory it will include the maps and exclude the tile data or include the tile data and exclude the maps.

Re: Shared tiles and palettes

Posted: Mon Aug 29, 2011 1:37 am
by headkaze
Okay here is the only solution I've found thus far. If anyone knows of a way to do this without the shell call I'm all ears. Anyway it works and I'm happy!

Code: Select all

PATH			:=	$(DEVKITARM)/bin:$(PATH)

GRAPHICS		:=	graphics

PNGS			:=	$(shell find $(GRAPHICS) -name "*.png" | tr "\n" " ")

all: tilemap.s

tilemap.s : $(PNGS)
	grit $^ -o $@ -ff $(GRAPHICS)/tiles.grit