Skip to content

Commit

Permalink
Added tile ordering option for TILESET, TILEMAP and MAP resources + T…
Browse files Browse the repository at this point in the history
…ILESET export option
  • Loading branch information
Stephane-D committed Nov 21, 2024
1 parent 1010efa commit 0619fc5
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 61 deletions.
Binary file modified bin/rescomp.jar
Binary file not shown.
31 changes: 23 additions & 8 deletions bin/rescomp.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ResComp 3.87 (November 2024)
ResComp 3.90 (November 2024)
Copyright Stephane Dallongeville
https://github.com/Stephane-D/SGDK

Expand Down Expand Up @@ -111,7 +111,7 @@ If you use a real 'tileset format' image as input (as a font) then you should se
to avoid removing duplicated tiles (which may exist).

Syntax:
TILESET name file [compression [opt]]
TILESET name file [compression [opt [ordering [export]]]]

name name of the output TileSet structure
file path of the input file (BMP, PNG image file or TSX Tiled file)
Expand All @@ -125,6 +125,12 @@ TILESET name file [compression [opt]]
0 / NONE = no optimisation, each tile is unique
1 / ALL = ignore duplicated and flipped tile (default)
2 / DUPLICATE = ignore duplicated tile only
ordering define the tile process order, accepted values:
ROW = process per row (default)
COLUMN = process per column
export enable the tileset PNG export, accept values:
0 / FALSE = no PNG export (default)
1 / TRUE = optimized tileset is export to PNG format '<file>-tileset-export.png'

Tips:
When using a 8bpp indexed image as input you can use the extra bits of palette to provide extra information for the TILEMAP data but you have to
Expand All @@ -141,7 +147,7 @@ TileMap is used to draw in background plane, it requires a tileset which can be
TILEMAP resource isn't meant to be used to store large background level (eat too much space), use MAP resource for that.

Syntax (image file input):
TILEMAP name img_file tileset_id [compression [map_opt [map_base]]]
TILEMAP name img_file tileset_id [compression [map_opt [map_base [ordering]]]]

name name of the output TileMap structure
img_file path of the input image file (BMP or PNG image file)
Expand All @@ -157,7 +163,10 @@ TILEMAP name img_file tileset_id [compression [map_opt [map_base]]]
1 / ALL = find duplicated and flipped tile (default)
2 / DUPLICATE = find duplicated tile only
map_base define the base tilemap value, useful to set a default priority, palette and base tile index offset.
Using a base tile index offset (static tile allocation) allow to use the faster VDP_setTileMapxxx(..) functions.
using a base tile index offset (static tile allocation) allow to use the faster VDP_setTileMapxxx(..) functions.
ordering define the tilemap process order, accepted values:
ROW = process per row (default)
COLUMN = process per column

Syntax (TMX tiled file input):
TILEMAP name tmx_file layer_id [ts_compression [map_compression [map_base]]]
Expand All @@ -172,7 +181,10 @@ TILEMAP name tmx_file layer_id [ts_compression [map_compression [map_base]]]
2 / FAST / LZ4W = custom lz4 compression (average compression ratio but fast)
map_compression compression type for map (same accepted values than 'ts_compression')
map_base define the base tilemap value, useful to set a default priority, palette and base tile index offset.
Using a base tile index offset (static tile allocation) allow to use the faster VDP_setTileMapxxx(..) functions.
using a base tile index offset (static tile allocation) allow to use the faster VDP_setTileMapxxx(..) functions.
ordering define the tilemap process order, accepted values:
ROW = process per row (default)
COLUMN = process per column

Tips:
When using a 8bpp indexed image as input you can use the extra bits of palette to provide extra information for the TILEMAP data but you have to
Expand Down Expand Up @@ -207,9 +219,9 @@ MAP name img_file tileset_id [compression [map_base]]
1 / APLIB = aplib library (good compression ratio but slow)
2 / FAST / LZ4W = custom lz4 compression (average compression ratio but fast)
map_base define the base tilemap value, useful to set a default priority, palette and base tile index offset.
Using a base tile index offset (static tile allocation) allow to use faster MAP decoding function internally.
using a base tile index offset (static tile allocation) allow to use faster MAP decoding function internally.

MAP name tmx_file layer_id [ts_compression [map_compression [map_base]]]
MAP name tmx_file layer_id [ts_compression [map_compression [map_base [ordering]]]]

name name of the output Map structure
tmx_file path of the input TMX file (TMX Tiled file with CSV encoded map data)
Expand All @@ -221,7 +233,10 @@ MAP name tmx_file layer_id [ts_compression [map_compression [map_base]]]
2 / FAST / LZ4W = custom lz4 compression (average compression ratio but fast)
map_compression compression type for map (same accepted values than 'ts_compression')
map_base define the base tilemap value, useful to set a default priority, palette and base tile index offset.
Using a base tile index offset (static tile allocation) allow to use faster MAP decoding function internally.
using a base tile index offset (static tile allocation) allow to use faster MAP decoding function internally.
ordering define the map process order, accepted values:
ROW = process per row (default)
COLUMN = process per column

Tips:
When using a 8bpp indexed image as input you can use the extra bits of palette to provide extra information for the TILEMAP data but you have to
Expand Down
2 changes: 1 addition & 1 deletion tools/rescomp/src/sgdk/rescomp/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ else if (dep && depTarget == null)
depTarget = param;
}

System.out.println("ResComp 3.87 - SGDK Resource Compiler - Copyright 2024 (Stephane Dallongeville)");
System.out.println("ResComp 3.90 - SGDK Resource Compiler - Copyright 2024 (Stephane Dallongeville)");

if (fileName == null)
{
Expand Down
20 changes: 14 additions & 6 deletions tools/rescomp/src/sgdk/rescomp/processor/MapProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sgdk.rescomp.resource.Tileset;
import sgdk.rescomp.tool.Util;
import sgdk.rescomp.type.Basics.Compression;
import sgdk.rescomp.type.Basics.TileOrdering;
import sgdk.rescomp.type.TMX.TMXMap;
import sgdk.tool.FileUtil;
import sgdk.tool.StringUtil;
Expand Down Expand Up @@ -37,10 +38,9 @@ public Resource execute(String[] fields) throws Exception
System.out.println(" 1 / APLIB = aplib library (good compression ratio but slow)");
System.out.println(" 2 / FAST / LZ4W = custom lz4 compression (average compression ratio but fast)");
System.out.println(" map_base define the base tilemap value, useful to set a default priority, palette and base tile index offset");
System.out.println(
" Using a base tile index offset (static tile allocation) allow to use faster MAP decoding function internally.");
System.out.println(" using a base tile index offset (static tile allocation) allow to use faster MAP decoding function internally.");
System.out.println();
System.out.println("MAP name \"tmx_file\" \"layer_id\" [ts_compression [map_compression [map_base]]]");
System.out.println("MAP name \"tmx_file\" \"layer_id\" [ts_compression [map_compression [map_base [ordering]]]]");
System.out.println(" name Map variable name");
System.out.println(" tmx_file path of the input TMX file (TMX Tiled file)");
System.out.println(" layer_id layer name we want to extract map data from.");
Expand All @@ -51,6 +51,10 @@ public Resource execute(String[] fields) throws Exception
System.out.println(" 2 / FAST / LZ4W = custom lz4 compression (average compression ratio but fast)");
System.out.println(" map_compression compression type for map (same accepted values then 'ts_compression')");
System.out.println(" map_base define the base tilemap value, useful to set a default priority, palette and base tile index offset");
System.out.println(" using a base tile index offset (static tile allocation) allow to use faster MAP decoding function internally.");
System.out.println(" ordering define the map process order, accepted values:");
System.out.println(" ROW = process per row (default)");
System.out.println(" COLUMN = process per column");

return null;
}
Expand Down Expand Up @@ -79,14 +83,18 @@ public Resource execute(String[] fields) throws Exception
int mapBase = 0;
if (fields.length >= 7)
mapBase = StringUtil.parseInt(fields[6], 0);
// get tile ordering value
TileOrdering order = TileOrdering.ROW;
if (fields.length >= 8)
order = Util.getTileOrdering(fields[7]);

// build TMX map
final TMXMap tmxMap = new TMXMap(fileIn, layerName);
// then build MAP from TMX Map
return new Map(id, tmxMap.getMapImage(), tmxMap.w * tmxMap.tileSize, tmxMap.h * tmxMap.tileSize, mapBase, 2, tmxMap.getTilesets(id, tileSetCompression, false),
mapCompression, true);
return new Map(id, tmxMap.getMapImage(), tmxMap.w * tmxMap.tileSize, tmxMap.h * tmxMap.tileSize, mapBase, 2,
tmxMap.getTilesets(id, tileSetCompression, false, order), mapCompression, true);
}
else

// image file
{
// get tileset
Expand Down
27 changes: 21 additions & 6 deletions tools/rescomp/src/sgdk/rescomp/processor/TilemapProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sgdk.rescomp.tool.Util;
import sgdk.rescomp.type.Basics.Compression;
import sgdk.rescomp.type.Basics.TileOptimization;
import sgdk.rescomp.type.Basics.TileOrdering;
import sgdk.rescomp.type.TMX.TMXMap;
import sgdk.tool.FileUtil;
import sgdk.tool.StringUtil;
Expand All @@ -29,7 +30,7 @@ public Resource execute(String[] fields) throws Exception
if (fields.length < 3)
{
System.out.println("Wrong TILEMAP definition");
System.out.println("TILEMAP name \"img_file\" tileset_id [compression [map_opt [map_base]]]");
System.out.println("TILEMAP name \"img_file\" tileset_id [compression [map_opt [map_base [ordering]]]]");
System.out.println(" name Tilemap variable name");
System.out.println(" file path of the input image file (BMP or PNG image file)");
System.out.println(" tileset_id base tileset resource to use (allow to share tileset along several maps)");
Expand All @@ -43,8 +44,11 @@ public Resource execute(String[] fields) throws Exception
System.out.println(" 1 / ALL = find duplicate and flipped tile (default)");
System.out.println(" 2 / DUPLICATE = find duplicate tile only");
System.out.println(" map_base define the base tilemap value, useful to set a default priority, palette and base tile index offset");
System.out.println(" ordering define the tilemap process order, accepted values:");
System.out.println(" ROW = process per row (default)");
System.out.println(" COLUMN = process per column");
System.out.println();
System.out.println("TILEMAP name \"tmx_file\" \"layer_id\" [ts_compression [map_compression [map_base]]]");
System.out.println("TILEMAP name \"tmx_file\" \"layer_id\" [ts_compression [map_compression [map_base [ordering]]]]");
System.out.println(" name Tilemap variable name");
System.out.println(" tmx_file path of the input TMX file (TMX Tiled file)");
System.out.println(" layer_id layer name we want to extract map data from.");
Expand All @@ -55,6 +59,9 @@ public Resource execute(String[] fields) throws Exception
System.out.println(" 2 / FAST / LZ4W = custom lz4 compression (average compression ratio but fast)");
System.out.println(" map_compression compression type for map (same accepted values then 'ts_compression')");
System.out.println(" map_base define the base tilemap value, useful to set a default priority, palette and base tile index offset.");
System.out.println(" ordering define the tilemap process order, accepted values:");
System.out.println(" ROW = process per row (default)");
System.out.println(" COLUMN = process per column");

return null;
}
Expand Down Expand Up @@ -83,17 +90,21 @@ public Resource execute(String[] fields) throws Exception
int mapBase = 0;
if (fields.length >= 7)
mapBase = StringUtil.parseInt(fields[6], 0);
// get tile ordering value
TileOrdering order = TileOrdering.ROW;
if (fields.length >= 8)
order = Util.getTileOrdering(fields[7]);

// build TMX map
final TMXMap tmxMap = new TMXMap(fileIn, layerName);
// get tilesets for this TMX map
final List<Tileset> tilesets = tmxMap.getTilesets(id, tileSetCompression, false);
final List<Tileset> tilesets = tmxMap.getTilesets(id, tileSetCompression, false, order);

// then build TileMap from TMX Map
return Tilemap.getTilemap(id, new Tileset(tilesets), mapBase, tmxMap.getMapImage(), (tmxMap.w * tmxMap.tileSize) / 8,
(tmxMap.h * tmxMap.tileSize) / 8, TileOptimization.ALL, mapCompression);
(tmxMap.h * tmxMap.tileSize) / 8, TileOptimization.ALL, mapCompression, order);
}
else

// image file
{
// get packed value
Expand All @@ -108,14 +119,18 @@ public Resource execute(String[] fields) throws Exception
int mapBase = 0;
if (fields.length >= 7)
mapBase = StringUtil.parseInt(fields[6], 0);
// get tile ordering value
TileOrdering order = TileOrdering.ROW;
if (fields.length >= 8)
order = Util.getTileOrdering(fields[7]);

// get tileset
final Tileset tileset = (Tileset) Compiler.getResourceById(fields[3]);
// check tileset correctly found
if (tileset == null)
throw new InvalidParameterException("TILEMAP resource definition error: Tileset '" + fields[3] + "' not found !");

return Tilemap.getTilemap(id, tileset, mapBase, fileIn, tileOpt, compression);
return Tilemap.getTilemap(id, tileset, mapBase, fileIn, tileOpt, compression, order);
}
}
}
20 changes: 18 additions & 2 deletions tools/rescomp/src/sgdk/rescomp/processor/TilesetProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import sgdk.rescomp.tool.Util;
import sgdk.rescomp.type.Basics.Compression;
import sgdk.rescomp.type.Basics.TileOptimization;
import sgdk.rescomp.type.Basics.TileOrdering;
import sgdk.rescomp.type.TSX;
import sgdk.tool.FileUtil;
import sgdk.tool.StringUtil;

public class TilesetProcessor implements Processor
{
Expand All @@ -24,7 +26,7 @@ public Resource execute(String[] fields) throws Exception
if (fields.length < 3)
{
System.out.println("Wrong TILESET definition");
System.out.println("TILESET name \"file\" [compression [opt]]");
System.out.println("TILESET name \"file\" [compression [opt [ordering [export]]]]");
System.out.println(" name Tileset variable name");
System.out.println(" file path of the input file (BMP, PNG image file or TSX Tiled file)");
System.out.println(" compression compression type, accepted values:");
Expand All @@ -36,6 +38,12 @@ public Resource execute(String[] fields) throws Exception
System.out.println(" 0 / NONE = no optimisation, each tile is unique (default for TSX file)");
System.out.println(" 1 / ALL = ignore duplicated and flipped tile (default for image file)");
System.out.println(" 2 / DUPLICATE = ignore duplicated tile only");
System.out.println(" ordering define the tile process order, accepted values:");
System.out.println(" ROW = process per row (default)");
System.out.println(" COLUMN = process per column");
System.out.println(" export enable the tileset PNG export, accept values:");
System.out.println(" 0 / FALSE = no PNG export (default)");
System.out.println(" 1 / TRUE = optimized tileset is export to PNG format '<file>-tileset-export.png'");

return null;
}
Expand All @@ -57,10 +65,18 @@ public Resource execute(String[] fields) throws Exception
// force ALL for TSX format
if (!tsx && (fields.length >= 5))
opt = Util.getTileOpt(fields[4]);
// get tile ordering value
TileOrdering order = TileOrdering.ROW;
if (fields.length >= 6)
order = Util.getTileOrdering(fields[5]);
// PNG export
boolean export = false;
if (fields.length >= 7)
export = StringUtil.parseBoolean(fields[6], false);

// add resource file (used for deps generation)
Compiler.addResourceFile(fileIn);

return Tileset.getTileset(id, tsx ? TSX.getTSXTilesetPath(fileIn) : fileIn, compression, opt, tsx, false);
return Tileset.getTileset(id, tsx ? TSX.getTSXTilesetPath(fileIn) : fileIn, compression, opt, tsx, false, order, export);
}
}
7 changes: 3 additions & 4 deletions tools/rescomp/src/sgdk/rescomp/resource/Image.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package sgdk.rescomp.resource;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import sgdk.rescomp.Resource;
import sgdk.rescomp.tool.Util;
import sgdk.rescomp.type.Basics.Compression;
import sgdk.rescomp.type.Basics.TileOptimization;
import sgdk.rescomp.type.Basics.TileOrdering;
import sgdk.tool.ImageUtil;
import sgdk.tool.ImageUtil.BasicImageInfo;

Expand Down Expand Up @@ -54,9 +53,9 @@ public Image(String id, String imgFile, Compression compression, TileOptimizatio
final int ht = h / 8;

// build TILESET with wanted compression
tileset = (Tileset) addInternalResource(new Tileset(id + "_tileset", image, w, h, 0, 0, wt, ht, tileOpt, compression, false, false));
tileset = (Tileset) addInternalResource(new Tileset(id + "_tileset", image, w, h, 0, 0, wt, ht, tileOpt, compression, false, false, TileOrdering.ROW));
// build TILEMAP with wanted compression
tilemap = (Tilemap) addInternalResource(Tilemap.getTilemap(id + "_tilemap", tileset, mapBase, image, wt, ht, tileOpt, compression));
tilemap = (Tilemap) addInternalResource(Tilemap.getTilemap(id + "_tilemap", tileset, mapBase, image, wt, ht, tileOpt, compression, TileOrdering.ROW));
// build PALETTE
palette = (Palette) addInternalResource(new Palette(id + "_palette", imgFile, 64, true));

Expand Down
Loading

0 comments on commit 0619fc5

Please sign in to comment.