Shared tiles and palettes

mtheall
Posts: 211
Joined: Thu Feb 03, 2011 10:47 pm

Re: Shared tiles and palettes

Post by mtheall » Mon Aug 29, 2011 1:41 am

Code: Select all

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

DIRS := $(patsubst %/,%,$(dir $(wildcard */*.grit)))
TARGETS := $(foreach d,$(DIRS),$d.s)

all: $(TARGETS)

$(TARGETS) : %.s :
  grit $*/*.png -o $@ -ff $*/tiles.grit

clean:
  rm -f $(TARGETS) $(patsubst %.s,%.h,$(TARGETS))
This treats each directory as its own exclusive shared set. Yours will pull everything from every directory and treat it as a single set.

mtheall
Posts: 211
Joined: Thu Feb 03, 2011 10:47 pm

Re: Shared tiles and palettes

Post by mtheall » Mon Aug 29, 2011 1:59 am

Sorry, my edit time expired, but I was going to add this info:

You will end up with dir1.s dir1.h, dir2.s dir2.h dir3.s dir3.h etc... More practically you'd want each directory to be something like TitleScreen, MainMenu, Level1, etc... Yours will pull everything from every directory and treat it as a single set, so you wouldn't be able to separate unrelated graphics, i.e. your title screen, main menu, and level 1 graphics would all use the same tileset. This might be okay for a small game, but it breaks once you try to expand or scale. Any one tileset can only have 1024 tiles (256 tiles for affine backgrounds), and of course you will be limited with number of colors. Really, it ends up being only 1023 because grit always inserts a blank tile at the beginning of the tileset (at least for shared graphics).

headkaze
Posts: 13
Joined: Wed Oct 21, 2009 5:57 pm

Re: Shared tiles and palettes

Post by headkaze » Mon Aug 29, 2011 2:55 am

Actually the Makefile I posted works on a single directory.

I do like the method you posted but is it possbile to have directories of shared graphics as well as directories of unrelated graphics? It looks as though it will share all the graphics in each folder. ie. Can you have a "misc" folder where each png has their own individual .grit file and a "shared" folder with a single .grit file and all png's share the same tileset?

mtheall
Posts: 211
Joined: Thu Feb 03, 2011 10:47 pm

Re: Shared tiles and palettes

Post by mtheall » Mon Aug 29, 2011 4:20 am

That's easy enough. You just need to filter out or filter in new rules.

Code: Select all

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

# list what you want to use shared graphics
SHARED := shared1 shared2
SHPNGS := $(addsuffix .s,$(SHARED))

# filter out what you don't want to use shared graphics
UNSHARED := $(filter-out $(SHARED),$(patsubst %/,%,$(dir $(wildcard */*.grit))))
PNGS := $(sort $(patsubst %.png,%.s,$(foreach d,$(UNSHARED),$(wildcard $d/*.png))))

all: $(SHPNGS) $(PNGS)

# shared graphics -- the resulting .s and .h appear in the current directory
$(SHPNGS) : %.s : %/tiles.grit
  grit $*/*.png -o $@ -ff $*/tiles.grit

# individual pngs -- the resulting .s and .h appear in the image's directory
$(PNGS): %.s : %.png %.grit
  grit $*.png -o $@ -ff $*.grit

headkaze
Posts: 13
Joined: Wed Oct 21, 2009 5:57 pm

Re: Shared tiles and palettes

Post by headkaze » Mon Aug 29, 2011 6:17 am

Makefiles make me want to poke my eyes out.

Anyway thanks again for your help!

mtheall
Posts: 211
Joined: Thu Feb 03, 2011 10:47 pm

Re: Shared tiles and palettes

Post by mtheall » Mon Aug 29, 2011 6:22 am

They're not so bad once you figure out how to do more advanced things. In the long run, a well-made makefile can save tons of time, especially if you design it to be reusable.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 18 guests