Skip to content

Commit

Permalink
Remove unused RLE format and refactor other formats
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 committed Sep 7, 2019
1 parent 94ff25d commit 3023775
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 88 deletions.
13 changes: 6 additions & 7 deletions res/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ <h1>)" PROGRAM_NAME R"(</h1>
</ul>
<p>Be sure to set the right format (via the Format toolbar dropdown, or the Options&nbsp;→&nbsp;Format menu) before opening a tilemap. The available formats are:</p>
<ul>
<li><b>Plain:</b> Each byte is a tile ID, top to bottom, left to right. A byte goes from $00 (0) to $FF (255), so there are 256 possible tiles.</li>
<li><b>Run-length encoded (RLE):</b> Each pair of bytes encodes a tile ID and a length to repeat that tile. For example, $F0 $0D encodes a sequence of 13 tiles with ID $F0. (A length of 0 is valid but would do nothing.)</li>
<li><b>GSC Town Map ($FF end):</b> A sequence of tile IDs ended by an $FF byte (so $FF is not a valid tile ID). Meant for the Town Map tilemaps in pokecrystal: gfx)" DIR_SEP "pokegear" DIR_SEP R"(johto.bin and kanto.bin.</li>
<li><b>Pok&eacute;gear card (RLE + $FF end):</b> A sequence of tile IDs and run lengths, ended by an $FF byte (so $FF is not a valid tile ID). Meant for the Pok&eacute;gear card tilemaps in pokecrystal: gfx)" DIR_SEP "pokegear" DIR_SEP R"(*.tilemap.rle.</li>
<li><b>RBY Town Map (RLE nybbles + $00 end):</b> A sequence of bytes that each encode a tile ID in their high nybble and a run length in their low nybble, ended by a $00 byte. For example, $42 encodes a sequence of two tiles with ID $04. Only 16 tile IDs can be represented, $00 to $0F. Meant for the Town Map tilemap in pokered: gfx)" DIR_SEP R"(town_map.rle.</li>
<li><b>PC Town Map (X/Y flip):</b> A sequence of bytes that each encode a tile ID in their low six bits and X/Y flip attributes in their high two bits, ended by an $FF byte. Only 64 tile IDs can be represented, $00 to $3F. Meant for the Town Map tilemaps in <a href="https://github.com/Rangi42/polishedcrystal">Polished Crystal</a>: gfx)" DIR_SEP "town_map" DIR_SEP R"(*.bin.</li>
<li><b>SGB border (tile + attribute):</b> Each pair of bytes encodes a tile ID and an attribute byte. The only supported attribute bits are X/Y flip and four colors. Meant for the SGB borders in pokered: gfx)" DIR_SEP "red" DIR_SEP "sgbborder.map and gfx" DIR_SEP "blue" DIR_SEP R"(sgbborder.map.</li>
<li><b>Plain tiles:</b> Each byte is a tile ID, top to bottom, left to right. A byte goes from $00 (0) to $FF (255), so there are 256 possible tiles.</li>
<li><b>Tiles + attributes:</b> Each pair of bytes encodes a tile ID and an attribute byte. The only supported attribute bits are X/Y flip and four colors. Meant for the SGB borders in pokered: gfx)" DIR_SEP "red" DIR_SEP "sgbborder.map and gfx" DIR_SEP "blue" DIR_SEP R"(sgbborder.map. Also applies to some other tilemaps in pokecrystal.</li>
<li><b>RBY Town Map:</b> A sequence of bytes that each encode a tile ID in their high nybble and a run length in their low nybble, ended by a $00 byte. For example, $46 encodes a sequence of six tiles with ID $04. Only 16 tile IDs can be represented, $00 to $0F. Meant for the Town Map tilemap in pokered: gfx)" DIR_SEP R"(town_map.rle.</li>
<li><b>GSC Town Map:</b> A sequence of tile IDs ended by an $FF byte (so $FF is not a valid tile ID). Meant for the Town Map tilemaps in pokecrystal: gfx)" DIR_SEP "pokegear" DIR_SEP R"(johto.bin and kanto.bin.</li>
<li><b>PC Town Map:</b> A sequence of bytes that each encode a tile ID in their low six bits and X/Y flip attributes in their high two bits, ended by an $FF byte. Only 64 tile IDs can be represented, $00 to $3F. Meant for the Town Map tilemaps in <a href="https://github.com/Rangi42/polishedcrystal">Polished Crystal</a>: gfx)" DIR_SEP "town_map" DIR_SEP R"(*.bin.</li>
<li><b>Pok&eacute;gear card:</b> A sequence of tile IDs and run lengths, ended by an $FF byte (so $FF is not a valid tile ID). For example, $F0 $0D encodes a sequence of 13 tiles with ID $F0. Meant for the Pok&eacute;gear card tilemaps in pokecrystal: gfx)" DIR_SEP "pokegear" DIR_SEP R"(*.tilemap.rle.</li>
</ul>
<hr>
<p>Most functions are available via the menu bar, the toolbars, or shortcut keys.</p>
Expand Down
Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 37 additions & 41 deletions src/main-window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ Main_Window::Main_Window(int x, int y, int w, int h, const char *) : Fl_Double_W
wh -= _status_bar->h();
_tilemap_dimensions = new Status_Bar_Field(0, 0, text_width("Tilemap: 999 x 999", 8), 21, "");
new Spacer(0, 0, 2, 21);
_tilemap_format = new Status_Bar_Field(0, 0, text_width("Run-length encoded", 8), 21, "");
int wgt_w = 0;
for (int i = 0; i < NUM_FORMATS; i++) {
const char *l = format_name((Tilemap_Format)i);
int lw = text_width(l, 8);
if (lw > wgt_w) { wgt_w = lw; }
}
_tilemap_format = new Status_Bar_Field(0, 0, wgt_w, 21, "");
new Spacer(0, 0, 2, 21);
_hover_id = new Status_Bar_Field(0, 0, text_width("ID: $99", 8), 21, "");
new Spacer(0, 0, 2, 21);
Expand All @@ -92,7 +98,7 @@ Main_Window::Main_Window(int x, int y, int w, int h, const char *) : Fl_Double_W
int gx = _left_group->x(), gy = _left_group->y(), gw = _left_group->w(), gh = _left_group->h();
_left_top_bar = new Fl_Group(gx, gy, gw, wgt_h);
int bx = _left_top_bar->x(), by = _left_top_bar->y(), bw = _left_top_bar->w(), bh = _left_top_bar->h();
int wgt_w = text_width("Tilemap:", 4);
wgt_w = text_width("Tilemap:", 4);
Label *tilemap_heading = new Label(bx, by, wgt_w, bh, "Tilemap:");
bx += tilemap_heading->w(); bw -= tilemap_heading->w();
_new_tb = new Toolbar_Button(bx, by, wgt_h, wgt_h);
Expand Down Expand Up @@ -332,20 +338,18 @@ Main_Window::Main_Window(int x, int y, int w, int h, const char *) : Fl_Double_W
{},
OS_SUBMENU("&Options"),
OS_MENU_ITEM("&Format", 0, NULL, NULL, FL_SUBMENU),
OS_MENU_ITEM("&Plain", FL_COMMAND + '1', (Fl_Callback *)plain_format_cb, this,
OS_MENU_ITEM("Plain &tiles", FL_COMMAND + '1', (Fl_Callback *)plain_format_cb, this,
FL_MENU_RADIO | (Config::format() == Tilemap_Format::PLAIN ? FL_MENU_VALUE : 0)),
OS_MENU_ITEM("&Run-length encoded (RLE)", FL_COMMAND + '2', (Fl_Callback *)rle_format_cb, this,
FL_MENU_RADIO | (Config::format() == Tilemap_Format::RLE ? FL_MENU_VALUE : 0)),
OS_MENU_ITEM("GSC &Town Map ($FF end)", FL_COMMAND + '3', (Fl_Callback *)gsc_town_map_format_cb, this,
FL_MENU_RADIO | (Config::format() == Tilemap_Format::FF_END ? FL_MENU_VALUE : 0)),
OS_MENU_ITEM("Pok\xc3\xa9gear &card (RLE + $FF end)", FL_COMMAND + '4', (Fl_Callback *)pokegear_card_format_cb, this,
FL_MENU_RADIO | (Config::format() == Tilemap_Format::RLE_FF_END ? FL_MENU_VALUE : 0)),
OS_MENU_ITEM("RBY Town Map (RLE &nybbles + $00 end)", FL_COMMAND + '5', (Fl_Callback *)rby_town_map_format_cb, this,
OS_MENU_ITEM("Tiles + &attributes", FL_COMMAND + '2', (Fl_Callback *)sgb_border_format_cb, this,
FL_MENU_RADIO | (Config::format() == Tilemap_Format::TILE_ATTR ? FL_MENU_VALUE : 0)),
OS_MENU_ITEM("&RBY Town Map", FL_COMMAND + '3', (Fl_Callback *)rby_town_map_format_cb, this,
FL_MENU_RADIO | (Config::format() == Tilemap_Format::RLE_NYBBLES ? FL_MENU_VALUE : 0)),
OS_MENU_ITEM("PC Town Map (&X\x2fY flip)", FL_COMMAND + '6', (Fl_Callback *)pc_town_map_format_cb, this,
OS_MENU_ITEM("&GSC Town Map", FL_COMMAND + '4', (Fl_Callback *)gsc_town_map_format_cb, this,
FL_MENU_RADIO | (Config::format() == Tilemap_Format::FF_END ? FL_MENU_VALUE : 0)),
OS_MENU_ITEM("&PC Town Map", FL_COMMAND + '5', (Fl_Callback *)pc_town_map_format_cb, this,
FL_MENU_RADIO | (Config::format() == Tilemap_Format::XY_FLIP ? FL_MENU_VALUE : 0)),
OS_MENU_ITEM("&SGB border (tile + attribute)", FL_COMMAND + '7', (Fl_Callback *)sgb_border_format_cb, this,
FL_MENU_RADIO | (Config::format() == Tilemap_Format::TILE_ATTR ? FL_MENU_VALUE : 0)),
OS_MENU_ITEM("Pok\xc3\xa9gear &card", FL_COMMAND + '6', (Fl_Callback *)pokegear_card_format_cb, this,
FL_MENU_RADIO | (Config::format() == Tilemap_Format::RLE_FF_END ? FL_MENU_VALUE : 0)),
{},
OS_MENU_ITEM("Show SGB &Colors", FL_COMMAND + 'G', (Fl_Callback *)show_attributes_cb, this,
FL_MENU_TOGGLE | (Config::attributes() ? FL_MENU_VALUE : 0)),
Expand Down Expand Up @@ -377,12 +381,11 @@ Main_Window::Main_Window(int x, int y, int w, int h, const char *) : Fl_Double_W
_rose_gold_theme_mi = PM_FIND_MENU_ITEM_CB(rose_gold_theme_cb);
_dark_theme_mi = PM_FIND_MENU_ITEM_CB(dark_theme_cb);
_plain_format_mi = PM_FIND_MENU_ITEM_CB(plain_format_cb);
_rle_format_mi = PM_FIND_MENU_ITEM_CB(rle_format_cb);
_gsc_town_map_format_mi = PM_FIND_MENU_ITEM_CB(gsc_town_map_format_cb);
_pokegear_card_format_mi = PM_FIND_MENU_ITEM_CB(pokegear_card_format_cb);
_sgb_border_format_mi = PM_FIND_MENU_ITEM_CB(sgb_border_format_cb);
_rby_town_map_format_mi = PM_FIND_MENU_ITEM_CB(rby_town_map_format_cb);
_gsc_town_map_format_mi = PM_FIND_MENU_ITEM_CB(gsc_town_map_format_cb);
_pc_town_map_format_mi = PM_FIND_MENU_ITEM_CB(pc_town_map_format_cb);
_sgb_border_format_mi = PM_FIND_MENU_ITEM_CB(sgb_border_format_cb);
_pokegear_card_format_mi = PM_FIND_MENU_ITEM_CB(pokegear_card_format_cb);
_grid_mi = PM_FIND_MENU_ITEM_CB(grid_cb);
_rainbow_tiles_mi = PM_FIND_MENU_ITEM_CB(rainbow_tiles_cb);
_show_attributes_mi = PM_FIND_MENU_ITEM_CB(show_attributes_cb);
Expand Down Expand Up @@ -420,13 +423,9 @@ Main_Window::Main_Window(int x, int y, int w, int h, const char *) : Fl_Double_W
_print_tb->image(PRINT_ICON);
_print_tb->deimage(PRINT_DISABLED_ICON);

_format->add("Plain"); // PLAIN
_format->add("Run-length encoded (RLE)"); // RLE
_format->add("GSC Town Map ($FF end)"); // FF_END
_format->add("Pok\xc3\xa9gear card (RLE + $FF end)"); // RLE_FF_END
_format->add("RBY Town Map (RLE nybbles + $00 end)"); // RLE_NYBBLES
_format->add("PC Town Map (X\\/Y flip)"); // XY_FLIP
_format->add("SGB border (tile + attribute)"); // TILE_ATTR
for (int i = 0; i < NUM_FORMATS; i++) {
_format->add(format_name((Tilemap_Format)i));
}
_format->value(Config::format());
_format->callback((Fl_Callback *)format_tb_cb, this);

Expand Down Expand Up @@ -1630,29 +1629,22 @@ void Main_Window::plain_format_cb(Fl_Menu_ *, Main_Window *mw) {
mw->redraw();
}

void Main_Window::rle_format_cb(Fl_Menu_ *, Main_Window *mw) {
Config::format(Tilemap_Format::RLE);
mw->_format->value(Config::format());
mw->update_active_controls();
mw->redraw();
}

void Main_Window::gsc_town_map_format_cb(Fl_Menu_ *, Main_Window *mw) {
Config::format(Tilemap_Format::FF_END);
void Main_Window::sgb_border_format_cb(Fl_Menu_ *, Main_Window *mw) {
Config::format(Tilemap_Format::TILE_ATTR);
mw->_format->value(Config::format());
mw->update_active_controls();
mw->redraw();
}

void Main_Window::pokegear_card_format_cb(Fl_Menu_ *, Main_Window *mw) {
Config::format(Tilemap_Format::RLE_FF_END);
void Main_Window::rby_town_map_format_cb(Fl_Menu_ *, Main_Window *mw) {
Config::format(Tilemap_Format::RLE_NYBBLES);
mw->_format->value(Config::format());
mw->update_active_controls();
mw->redraw();
}

void Main_Window::rby_town_map_format_cb(Fl_Menu_ *, Main_Window *mw) {
Config::format(Tilemap_Format::RLE_NYBBLES);
void Main_Window::gsc_town_map_format_cb(Fl_Menu_ *, Main_Window *mw) {
Config::format(Tilemap_Format::FF_END);
mw->_format->value(Config::format());
mw->update_active_controls();
mw->redraw();
Expand All @@ -1665,8 +1657,8 @@ void Main_Window::pc_town_map_format_cb(Fl_Menu_ *, Main_Window *mw) {
mw->redraw();
}

void Main_Window::sgb_border_format_cb(Fl_Menu_ *, Main_Window *mw) {
Config::format(Tilemap_Format::TILE_ATTR);
void Main_Window::pokegear_card_format_cb(Fl_Menu_ *, Main_Window *mw) {
Config::format(Tilemap_Format::RLE_FF_END);
mw->_format->value(Config::format());
mw->update_active_controls();
mw->redraw();
Expand All @@ -1689,8 +1681,12 @@ void Main_Window::about_cb(Fl_Widget *, Main_Window *mw) {
void Main_Window::format_tb_cb(Dropdown *, Main_Window *mw) {
Config::format((Tilemap_Format)mw->_format->value());
Fl_Menu_Item *menu_items[NUM_FORMATS] = {
mw->_plain_format_mi, mw->_rle_format_mi, mw->_gsc_town_map_format_mi, mw->_pokegear_card_format_mi,
mw->_rby_town_map_format_mi, mw->_pc_town_map_format_mi, mw->_sgb_border_format_mi
mw->_plain_format_mi, // PLAIN
mw->_sgb_border_format_mi, // TILE_ATTR
mw->_rby_town_map_format_mi, // RLE_NYBBLES
mw->_gsc_town_map_format_mi, // FF_END
mw->_pokegear_card_format_mi, // XY_FLIP
mw->_pc_town_map_format_mi // RLE_FF_END
};
menu_items[Config::format()]->setonly();
mw->update_active_controls();
Expand Down
11 changes: 5 additions & 6 deletions src/main-window.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class Main_Window : public Fl_Double_Window {
Fl_Menu_Item *_classic_theme_mi = NULL, *_aero_theme_mi = NULL, *_metro_theme_mi = NULL, *_aqua_theme_mi = NULL,
*_greybird_theme_mi = NULL, *_metal_theme_mi = NULL, *_blue_theme_mi = NULL, *_olive_theme_mi = NULL,
*_rose_gold_theme_mi = NULL, *_dark_theme_mi = NULL;
Fl_Menu_Item *_plain_format_mi = NULL, *_rle_format_mi = NULL, *_gsc_town_map_format_mi = NULL, *_pokegear_card_format_mi = NULL,
*_rby_town_map_format_mi = NULL, *_pc_town_map_format_mi = NULL, *_sgb_border_format_mi = NULL;
Fl_Menu_Item *_plain_format_mi = NULL, *_sgb_border_format_mi = NULL, *_rby_town_map_format_mi = NULL,
*_gsc_town_map_format_mi = NULL, *_pc_town_map_format_mi = NULL, *_pokegear_card_format_mi = NULL;
Fl_Menu_Item *_grid_mi, *_rainbow_tiles_mi = NULL, *_show_attributes_mi = NULL;
Toolbar_Button *_new_tb, *_open_tb, *_save_tb, *_print_tb;
Dropdown *_format;
Expand Down Expand Up @@ -161,12 +161,11 @@ class Main_Window : public Fl_Double_Window {
static void image_to_tiles_cb(Fl_Widget *w, Main_Window *mw);
// Options menu
static void plain_format_cb(Fl_Menu_ *m, Main_Window *mw);
static void rle_format_cb(Fl_Menu_ *m, Main_Window *mw);
static void gsc_town_map_format_cb(Fl_Menu_ *m, Main_Window *mw);
static void pokegear_card_format_cb(Fl_Menu_ *m, Main_Window *mw);
static void sgb_border_format_cb(Fl_Menu_ *m, Main_Window *mw);
static void rby_town_map_format_cb(Fl_Menu_ *m, Main_Window *mw);
static void gsc_town_map_format_cb(Fl_Menu_ *m, Main_Window *mw);
static void pc_town_map_format_cb(Fl_Menu_ *m, Main_Window *mw);
static void sgb_border_format_cb(Fl_Menu_ *m, Main_Window *mw);
static void pokegear_card_format_cb(Fl_Menu_ *m, Main_Window *mw);
static void show_attributes_cb(Fl_Menu_ *m, Main_Window *mw);
// Help menu
static void help_cb(Fl_Widget *w, Main_Window *mw);
Expand Down
10 changes: 3 additions & 7 deletions src/option-dialogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,9 @@ void Image_To_Tiles_Dialog::initialize_content() {
_image_name->callback((Fl_Callback *)image_cb, this);
_tilemap_name->callback((Fl_Callback *)tilemap_cb, this);
_tileset_name->callback((Fl_Callback *)tileset_cb, this);
_format->add("Plain"); // PLAIN
_format->add("Run-length encoded (RLE)"); // RLE
_format->add("GSC Town Map ($FF end)"); // FF_END
_format->add("Pok\xc3\xa9gear card (RLE + $FF end)"); // RLE_FF_END
_format->add("RBY Town Map (RLE nybbles + $00 end)"); // RLE_NYBBLES
_format->add("PC Town Map (X\\/Y flip)"); // XY_FLIP
_format->add("SGB border (tile + attribute)"); // TILE_ATTR
for (int i = 0; i < NUM_FORMATS; i++) {
_format->add(format_name((Tilemap_Format)i));
}
_start_id->default_value(0x00);
_image_chooser->title("Read Image");
_image_chooser->filter("Image Files\t*.{png,bmp}\n");
Expand Down
17 changes: 7 additions & 10 deletions src/tilemap-format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ int format_tileset_size(Tilemap_Format fmt) {
const char *format_name(Tilemap_Format fmt) {
switch (fmt) {
case Tilemap_Format::PLAIN:
return "Plain";
case Tilemap_Format::RLE:
return "Run-length encoded";
case Tilemap_Format::FF_END:
return "GSC Town Map";
case Tilemap_Format::RLE_FF_END:
return "Pok\xc3\xa9gear card";
return "Plain tiles";
case Tilemap_Format::TILE_ATTR:
return "Tiles + attributes";
case Tilemap_Format::RLE_NYBBLES:
return "RBY Town Map";
case Tilemap_Format::FF_END:
return "GSC Town Map";
case Tilemap_Format::XY_FLIP:
return "PC Town Map";
case Tilemap_Format::TILE_ATTR:
return "SGB border";
case Tilemap_Format::RLE_FF_END:
return "Pok\xc3\xa9gear card";
default:
return "Any";
}
Expand All @@ -43,7 +41,6 @@ const char *format_extension(Tilemap_Format fmt) {
case Tilemap_Format::PLAIN:
default:
return ".tilemap"; // e.g. pokecrystal/gfx/card_flip/card_flip.tilemap
case Tilemap_Format::RLE:
case Tilemap_Format::RLE_NYBBLES:
return ".rle"; // e.g. pokered/gfx/town_map.rle
case Tilemap_Format::FF_END:
Expand Down
4 changes: 2 additions & 2 deletions src/tilemap-format.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef TILEMAP_FORMAT_H
#define TILEMAP_FORMAT_H

#define NUM_FORMATS 7
#define NUM_FORMATS 6

enum Tilemap_Format { PLAIN, RLE, FF_END, RLE_FF_END, RLE_NYBBLES, XY_FLIP, TILE_ATTR };
enum Tilemap_Format { PLAIN, TILE_ATTR, RLE_NYBBLES, FF_END, XY_FLIP, RLE_FF_END };

int format_tileset_size(Tilemap_Format fmt);
const char *format_name(Tilemap_Format fmt);
Expand Down
16 changes: 1 addition & 15 deletions src/tilemap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,20 +184,6 @@ Tilemap::Result Tilemap::read_tiles(const char *f) {
}
}

else if (fmt == Tilemap_Format::RLE) {
if (c % 2) {
fclose(file);
return (_result = TILEMAP_TOO_SHORT_FF);
}
for (long i = 0; i < c; i += 2) {
int v = fgetc(file);
int r = fgetc(file);
for (int j = 0; j < r; j++) {
tiles.emplace_back(new Tile_Tessera(0, 0, 0, 0, (uint8_t)v));
}
}
}

else if (fmt == Tilemap_Format::FF_END) {
for (long i = 0; i < c - 1; i++) {
int b = fgetc(file);
Expand Down Expand Up @@ -340,7 +326,7 @@ bool Tilemap::write_tiles(const char *f, std::vector<Tile_Tessera *> &tiles, Til
fputc(v, file);
}
}
else if (fmt == Tilemap_Format::RLE || fmt == Tilemap_Format::RLE_FF_END) {
else if (fmt == Tilemap_Format::RLE_FF_END) {
size_t n = tiles.size();
for (size_t i = 0; i < n;) {
Tile_Tessera *tt = tiles[i++];
Expand Down

0 comments on commit 3023775

Please sign in to comment.