From c7e3639663643855f130ec64a219ef0cb44eb2ad Mon Sep 17 00:00:00 2001 From: Robert Jordan Date: Wed, 20 May 2015 11:52:40 -0400 Subject: [PATCH 1/3] Sprite build command build uses ../../data/g2.dat and all numbered images in ../../resources/g2/. No other parameters needed. Also changed speed button hyper arrows to support game speeds inbetween 4 and 8. --- data/g2.dat | Bin 20774 -> 20666 bytes resources/g2/4.png | Bin 246 -> 229 bytes src/cmdline_sprite.c | 69 ++++++++++++++++++++++++++++++++++++++ src/sprites.h | 2 +- src/windows/top_toolbar.c | 7 ++-- 5 files changed, 75 insertions(+), 3 deletions(-) diff --git a/data/g2.dat b/data/g2.dat index ce7d217b48656c328464e8872ed8150f21b63b4f..697d7bbdf80047027fafa70dcc65cd62a409d7b3 100644 GIT binary patch delta 143 zcmZ3sh;i3KMpjk^28N`GtnQ4Q8+|?e8LK8w^WRv^(8>^(nwk>V0;E#nni=9!;u;y_ zgcu|k6c{uaj2LVg+!*{B!WkGD;~H7w+8E+8;((|fNT-8PJ7ZjW8VI#B#igZykUaxX U3}_S(0aZa5Ky4{;Km;)a0AoNY-~a#s delta 252 zcmZXOu?YfE5JYFhk0J;n*nyc1*nuX;bufth`)3PAa;T}GAIw!SzeunMYjQ(b;VsJ! z!_K^KeBK!XfX_KBIBAPzN#twU?q)}*s-h0IqV`Z!Lya-T90k_c;)DlYAjPiO69?i@ n%}5t$BS$u^_GGF~p4?H2N-LWm&^NR7aM)X?*lGDuj{lZlh6_*L diff --git a/resources/g2/4.png b/resources/g2/4.png index 29118138d8c658dfb0fb77eb27194a10f6fe8a63..24395cc1b733bb3d547ebfb03c6c3d859e5ca747 100644 GIT binary patch delta 176 zcmeyy_>@txGr-TCmrII^fq{Y7)59eQNOOWP2OE%lFp*7QqMkI@AqED%LyV#tUJVn2 z)hm)cT^vI+f|D5->#E!SC$I@9Y<|d~vg1eX|9XMmGi_eZ3_go~*BQnL_V9)>F)A=l zaQXMMV1tU0^ePr62POs1?_Xafc&3=eIDVi8li>SscWUgd8}) a!0^#De!EDoGr-TCmrII^fq{Y7)59eQNQ(k7CkGplyvv+k2Ba8^gWR1M)}51iIZ;uX z>o5ZY-(kk%`72T;x~bQsd%8G=XapxSFxFMK{ZC*M2sqTnJmJBk?|=V0nyBWiC=_6r z{9<1`Pq>Sobe0NB1B-*u&*z5^PMWe|p_>zf2ZPGPeQ~lno}AKo318}}cPOal+>+p6 rQsDEMAY^vMg2h2>NeeF{4-Z4d5y96Ra?9=lox|Yi>gTe~DWM4f;6OfS diff --git a/src/cmdline_sprite.c b/src/cmdline_sprite.c index d98fb2eb1b..56f6e7835e 100644 --- a/src/cmdline_sprite.c +++ b/src/cmdline_sprite.c @@ -412,6 +412,75 @@ int cmdline_for_sprite(const char **argv, int argc) return -1; return 1; + } + else if (_strcmpi(argv[0], "build") == 0) { + /*if (argc < 3) { + fprintf(stderr, "usage: sprite build [spritefile] [resources]\n"); + return -1; + }*/ + + const char *spriteFilePath = "../../data/g2.dat"; + const char *resourcePath = "../../resources/g2/"; + char imagePath[256], number[8]; + + bool fileExists = true; + FILE *file; + + spriteFileHeader.num_entries = 0; + spriteFileHeader.total_size = 0; + sprite_file_save(spriteFilePath); + + //sprite_file_close(); + + printf("Building: %s\n", spriteFilePath); + for (int i = 0; fileExists; i++) { + itoa(i, number, 10); + strcpy(imagePath, resourcePath); + strcat(imagePath, number); + strcat(imagePath, ".png"); + if (file = fopen(imagePath, "r")) { + fclose(file); + rct_g1_element spriteElement; + uint8 *buffer; + int bufferLength; + if (!sprite_file_import(imagePath, &spriteElement, &buffer, &bufferLength)) { + fprintf(stderr, "Could not import image file: %s\nCanceling\n", imagePath); + printf("Could not import image file: %s\nCanceling\n", imagePath); + return -1; + } + + if (!sprite_file_open(spriteFilePath)) { + fprintf(stderr, "Unable to open sprite file: %s\nCanceling\n", spriteFilePath); + printf("Unable to open sprite file: %s\nCanceling\n", spriteFilePath); + return -1; + } + + spriteFileHeader.num_entries++; + spriteFileHeader.total_size += bufferLength; + spriteFileEntries = realloc(spriteFileEntries, spriteFileHeader.num_entries * sizeof(rct_g1_element)); + spriteFileData = realloc(spriteFileData, spriteFileHeader.total_size); + spriteFileEntries[spriteFileHeader.num_entries - 1] = spriteElement; + memcpy(spriteFileData + (spriteFileHeader.total_size - bufferLength), buffer, bufferLength); + spriteFileEntries[spriteFileHeader.num_entries - 1].offset = spriteFileData + (spriteFileHeader.total_size - bufferLength); + + free(buffer); + + if (!sprite_file_save(spriteFilePath)) { + printf("Could not save sprite file: %s\nCanceling\n", imagePath); + return -1; + } + printf("Added: %s\n", imagePath); + } + else { + + printf("Could not find file: %s\n", imagePath); + fileExists = false; + } + } + + + printf("Finished\n", imagePath); + return 1; } else { fprintf(stderr, "Unknown sprite command."); return -1; diff --git a/src/sprites.h b/src/sprites.h index 6b30a0f6fb..cb48b5c5ce 100644 --- a/src/sprites.h +++ b/src/sprites.h @@ -351,7 +351,7 @@ enum { SPR_G2_TITLE = SPR_G2_BEGIN + 1, SPR_G2_FASTFORWARD = SPR_G2_BEGIN + 2, SPR_G2_SPEED_ARROW = SPR_G2_BEGIN + 3, - SPR_G2_HYPER_ARROWS = SPR_G2_BEGIN + 4 + SPR_G2_HYPER_ARROW = SPR_G2_BEGIN + 4 }; #endif diff --git a/src/windows/top_toolbar.c b/src/windows/top_toolbar.c index 7ad7199397..e2984ac975 100644 --- a/src/windows/top_toolbar.c +++ b/src/windows/top_toolbar.c @@ -647,9 +647,12 @@ static void window_top_toolbar_paint() for (int i = 0; i < gGameSpeed && gGameSpeed <= 4; i++) { gfx_draw_sprite(dpi, SPR_G2_SPEED_ARROW, x + 5 + i * 5, y + 15, 0); } - if (gGameSpeed == 8) { - gfx_draw_sprite(dpi, SPR_G2_HYPER_ARROWS, x + 5, y + 15, 0); + for (int i = 0; i < 3 && i < gGameSpeed - 4 && gGameSpeed >= 5; i++) { + gfx_draw_sprite(dpi, SPR_G2_HYPER_ARROW, x + 5 + i * 6, y + 15, 0); } + /*if (gGameSpeed >= 8) { + gfx_draw_sprite(dpi, SPR_G2_HYPER_ARROWS, x + 5, y + 15, 0); + }*/ } // Draw cheats button From 0a3d2b949c18059b853438be1648079c39a7096c Mon Sep 17 00:00:00 2001 From: Robert Jordan Date: Wed, 20 May 2015 13:17:08 -0400 Subject: [PATCH 2/3] sprite build now uses parameters Added batch file to build g2.dat --- build_g2.bat | 2 ++ src/cmdline_sprite.c | 29 +++++++++++++++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 build_g2.bat diff --git a/build_g2.bat b/build_g2.bat new file mode 100644 index 0000000000..3cdef7917c --- /dev/null +++ b/build_g2.bat @@ -0,0 +1,2 @@ +.\build\release\openrct2.exe sprite build "data/g2.dat" "resources/g2/" +pause \ No newline at end of file diff --git a/src/cmdline_sprite.c b/src/cmdline_sprite.c index 56f6e7835e..5b4197a484 100644 --- a/src/cmdline_sprite.c +++ b/src/cmdline_sprite.c @@ -414,15 +414,17 @@ int cmdline_for_sprite(const char **argv, int argc) return 1; } else if (_strcmpi(argv[0], "build") == 0) { - /*if (argc < 3) { - fprintf(stderr, "usage: sprite build [spritefile] [resources]\n"); + if (argc < 3) { + fprintf(stderr, "usage: sprite build [-s]\n"); return -1; - }*/ + } - const char *spriteFilePath = "../../data/g2.dat"; - const char *resourcePath = "../../resources/g2/"; + const char *spriteFilePath = argv[1]; + const char *resourcePath = argv[2]; char imagePath[256], number[8]; + int resourceLength = strlen(resourcePath); + bool silent = (argc >= 4 && strcmp(argv[3], "-s") == 0); bool fileExists = true; FILE *file; @@ -430,12 +432,12 @@ int cmdline_for_sprite(const char **argv, int argc) spriteFileHeader.total_size = 0; sprite_file_save(spriteFilePath); - //sprite_file_close(); - - printf("Building: %s\n", spriteFilePath); + fprintf(stderr, "Building: %s\n", spriteFilePath); for (int i = 0; fileExists; i++) { itoa(i, number, 10); strcpy(imagePath, resourcePath); + if (resourceLength == 0 || resourcePath[resourceLength - 1] != '/') + strcat(imagePath, "/"); strcat(imagePath, number); strcat(imagePath, ".png"); if (file = fopen(imagePath, "r")) { @@ -445,13 +447,11 @@ int cmdline_for_sprite(const char **argv, int argc) int bufferLength; if (!sprite_file_import(imagePath, &spriteElement, &buffer, &bufferLength)) { fprintf(stderr, "Could not import image file: %s\nCanceling\n", imagePath); - printf("Could not import image file: %s\nCanceling\n", imagePath); return -1; } if (!sprite_file_open(spriteFilePath)) { fprintf(stderr, "Unable to open sprite file: %s\nCanceling\n", spriteFilePath); - printf("Unable to open sprite file: %s\nCanceling\n", spriteFilePath); return -1; } @@ -466,20 +466,21 @@ int cmdline_for_sprite(const char **argv, int argc) free(buffer); if (!sprite_file_save(spriteFilePath)) { - printf("Could not save sprite file: %s\nCanceling\n", imagePath); + fprintf(stderr, "Could not save sprite file: %s\nCanceling\n", imagePath); return -1; } - printf("Added: %s\n", imagePath); + if (!silent) + fprintf(stderr, "Added: %s\n", imagePath); } else { - printf("Could not find file: %s\n", imagePath); + fprintf(stderr, "Could not find file: %s\n", imagePath); fileExists = false; } } - printf("Finished\n", imagePath); + fprintf(stderr, "Finished\n", imagePath); return 1; } else { fprintf(stderr, "Unknown sprite command."); From ac17b52139d4369dfa2cbeea900569a66557b5bd Mon Sep 17 00:00:00 2001 From: Robert Jordan Date: Wed, 20 May 2015 14:20:24 -0400 Subject: [PATCH 3/3] g2.dat is now updated every build. data/g2.dat is now ignored. --- .gitignore | 1 + projects/openrct2.vcxproj | 14 +++++++++++++- projects/openrct2.vcxproj.filters | 1 - src/cmdline_sprite.c | 8 ++++---- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 6486216ed8..c34bf9e3e5 100644 --- a/.gitignore +++ b/.gitignore @@ -231,3 +231,4 @@ pip-log.txt openrct2.id* openrct2.nam openrct2.til +data/g2.dat diff --git a/projects/openrct2.vcxproj b/projects/openrct2.vcxproj index 0e3320b342..02c1ab98ec 100644 --- a/projects/openrct2.vcxproj +++ b/projects/openrct2.vcxproj @@ -264,6 +264,8 @@ $(SolutionDir)..\lib\sdl\lib\x86;$(LibraryPath) $(SolutionDir)..\build\$(Configuration)\ $(SolutionDir)..\obj\$(ProjectName)\$(Configuration)\ + + @@ -304,8 +306,18 @@ winmm.lib;sdl2.lib;Dsound.lib;%(AdditionalDependencies) - xcopy /Y "$(SolutionDir)\..\Data\*.*" "$(TargetDir)\Data\" + "$(TargetDir)\openrct2.exe" sprite build "$(SolutionDir)\..\Data\g2.dat" "$(SolutionDir)\..\Resources\g2\" +xcopy /Y "$(SolutionDir)\..\Data\*.*" "$(TargetDir)\Data\" + Build g2.dat and copy the Data directory. + + + + + + + + diff --git a/projects/openrct2.vcxproj.filters b/projects/openrct2.vcxproj.filters index c39a466b58..eb0498021c 100644 --- a/projects/openrct2.vcxproj.filters +++ b/projects/openrct2.vcxproj.filters @@ -378,7 +378,6 @@ Source\Windows - Source\Localisation diff --git a/src/cmdline_sprite.c b/src/cmdline_sprite.c index 5b4197a484..83c2d1b536 100644 --- a/src/cmdline_sprite.c +++ b/src/cmdline_sprite.c @@ -415,7 +415,7 @@ int cmdline_for_sprite(const char **argv, int argc) } else if (_strcmpi(argv[0], "build") == 0) { if (argc < 3) { - fprintf(stderr, "usage: sprite build [-s]\n"); + fprintf(stderr, "usage: sprite build [silent]\n"); return -1; } @@ -424,7 +424,7 @@ int cmdline_for_sprite(const char **argv, int argc) char imagePath[256], number[8]; int resourceLength = strlen(resourcePath); - bool silent = (argc >= 4 && strcmp(argv[3], "-s") == 0); + bool silent = (argc >= 4 && strcmp(argv[3], "silent") == 0); bool fileExists = true; FILE *file; @@ -436,7 +436,7 @@ int cmdline_for_sprite(const char **argv, int argc) for (int i = 0; fileExists; i++) { itoa(i, number, 10); strcpy(imagePath, resourcePath); - if (resourceLength == 0 || resourcePath[resourceLength - 1] != '/') + if (resourceLength == 0 || (resourcePath[resourceLength - 1] != '/' && resourcePath[resourceLength - 1] != '\\')) strcat(imagePath, "/"); strcat(imagePath, number); strcat(imagePath, ".png"); @@ -484,7 +484,7 @@ int cmdline_for_sprite(const char **argv, int argc) return 1; } else { fprintf(stderr, "Unknown sprite command."); - return -1; + return 1; } }