git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit d8f3c6258c5fa69509973b7dfba750c871edab1e
parent 3778e11683e2282bef51c0bf50c09af30ade4b94
Author: Toxa <untoxa@mail.ru>
Date:   Wed, 18 Aug 2021 14:19:35 +0300

png2mtspr.cpp ability to disable tile flipping

Diffstat:
Mgbdk-lib/examples/gg/metasprites/Makefile2+-
Mgbdk-lib/examples/gg/metasprites/metasprites.c9++++++++-
Mgbdk-lib/examples/sms/metasprites/Makefile2+-
Mgbdk-lib/examples/sms/metasprites/metasprites.c9++++++++-
Mgbdk-support/png2mtspr/png2mtspr.cpp24++++++++++++++++--------
5 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/gbdk-lib/examples/gg/metasprites/Makefile b/gbdk-lib/examples/gg/metasprites/Makefile @@ -25,7 +25,7 @@ compile.bat: Makefile # -spr8x16 : Use 8x16 hardware sprites # -c ... : Set C output file %.c: %.png - $(PNG2MTSPR) $< -sh 48 -spr8x16 -plat sms -c $@ + $(PNG2MTSPR) $< -sh 48 -spr8x16 -noflip -plat sms -c $@ # Compile all C sources, including converted png metasprites $(BINS): $(CSOURCES) $(PNG_CSOURCES) diff --git a/gbdk-lib/examples/gg/metasprites/metasprites.c b/gbdk-lib/examples/gg/metasprites/metasprites.c @@ -27,7 +27,14 @@ uint8_t idx, rot; // main funxction void main(void) { - // Fill the screen background with a single tile pattern + // Set compatible palette + for (uint8_t i = 0; i != 2; i++) { + set_palette_entry(i, 0, RGB8(255, 255, 255)); + set_palette_entry(i, 1, RGB8(128, 128, 128)); + set_palette_entry(i, 2, RGB8( 64, 64, 64)); + set_palette_entry(i, 3, RGB8( 0, 0, 0)); + } + // Fill the screen background with a single tile pattern // fill_bkg_rect(0, 0, 20, 18, 0); set_bkg_2bpp_data(0, 1, pattern); diff --git a/gbdk-lib/examples/sms/metasprites/Makefile b/gbdk-lib/examples/sms/metasprites/Makefile @@ -25,7 +25,7 @@ compile.bat: Makefile # -spr8x16 : Use 8x16 hardware sprites # -c ... : Set C output file %.c: %.png - $(PNG2MTSPR) $< -sh 48 -spr8x16 -plat sms -c $@ + $(PNG2MTSPR) $< -sh 48 -spr8x16 -noflip -plat sms -c $@ # Compile all C sources, including converted png metasprites $(BINS): $(CSOURCES) $(PNG_CSOURCES) diff --git a/gbdk-lib/examples/sms/metasprites/metasprites.c b/gbdk-lib/examples/sms/metasprites/metasprites.c @@ -27,7 +27,14 @@ uint8_t idx, rot; // main funxction void main(void) { - // Fill the screen background with a single tile pattern + // Set compatible palette + for (uint8_t i = 0; i != 2; i++) { + set_palette_entry(i, 0, RGB8(255, 255, 255)); + set_palette_entry(i, 1, RGB8(128, 128, 128)); + set_palette_entry(i, 2, RGB8( 64, 64, 64)); + set_palette_entry(i, 3, RGB8( 0, 0, 0)); + } + // Fill the screen background with a single tile pattern // fill_bkg_rect(0, 0, 20, 18, 0); set_bkg_2bpp_data(0, 1, pattern); diff --git a/gbdk-support/png2mtspr/png2mtspr.cpp b/gbdk-support/png2mtspr/png2mtspr.cpp @@ -105,7 +105,7 @@ Tile FlipV(const Tile& tile) return ret; } -bool FindTile(const Tile& t, unsigned char& idx, unsigned char& props) +bool FindTile(const Tile& t, unsigned char& idx, unsigned char& props, bool tryflip) { vector< Tile >::iterator it; it = find(tiles.begin(), tiles.end(), t); @@ -116,6 +116,8 @@ bool FindTile(const Tile& t, unsigned char& idx, unsigned char& props) return true; } + if (!tryflip) return false; + Tile tile = FlipV(t); it = find(tiles.begin(), tiles.end(), tile); if(it != tiles.end()) @@ -146,7 +148,7 @@ bool FindTile(const Tile& t, unsigned char& idx, unsigned char& props) return false; } -void GetMetaSprite(int _x, int _y, int _w, int _h, int pivot_x, int pivot_y) +void GetMetaSprite(int _x, int _y, int _w, int _h, int pivot_x, int pivot_y, bool tryflip) { int last_x = _x + pivot_x; int last_y = _y + pivot_y; @@ -162,7 +164,7 @@ void GetMetaSprite(int _x, int _y, int _w, int _h, int pivot_x, int pivot_y) { unsigned char idx; unsigned char props; - if(!FindTile(tile, idx, props)) + if(!FindTile(tile, idx, props, tryflip)) { tiles.push_back(tile); idx = (unsigned char)tiles.size() - 1; @@ -202,6 +204,7 @@ int main(int argc, char *argv[]) printf("-spr8x16 use SPRITES_8x16 (default: SPRITES_8x16)\n"); printf("-b <bank> bank (default 0)\n"); printf("-plat <plat> platform (default gb)\n"); + printf("-noflip disable flipping"); return 0; } @@ -215,6 +218,7 @@ int main(int argc, char *argv[]) string plat = "gb"; output_filename = output_filename.substr(0, output_filename.size() - 4) + ".c"; int bank = 0; + bool tryflip = true; //Parse argv for(int i = 2; i < argc; ++i) @@ -259,6 +263,10 @@ int main(int argc, char *argv[]) { plat = argv[++ i]; } + else if(!strcmp(argv[i], "-noflip")) + { + tryflip = false; + } } int slash_pos = (int)output_filename.find_last_of('/'); @@ -275,10 +283,10 @@ int main(int argc, char *argv[]) printf("data_name:%s", data_name.c_str()); printf("\n"); // End of output - //load and decode png - vector<unsigned char> buffer; - loadFile(buffer, argv[1]); - if(decodePNG(image.data, image.w, image.h, buffer.empty() ? 0 : &buffer[0], (unsigned long)buffer.size()) != 0) + //load and decode png + vector<unsigned char> buffer; + loadFile(buffer, argv[1]); + if(decodePNG(image.data, image.w, image.h, buffer.empty() ? 0 : &buffer[0], (unsigned long)buffer.size()) != 0) { printf("Error decoding PNG"); return 0; @@ -294,7 +302,7 @@ int main(int argc, char *argv[]) { for(int x = 0; x < (int)image.w; x += sprite_w) { - GetMetaSprite(x, y, sprite_w, sprite_h, pivot_x, pivot_y); + GetMetaSprite(x, y, sprite_w, sprite_h, pivot_x, pivot_y, tryflip); } }

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.