diff --git a/BUILDING.md b/BUILDING.md index 4e2f35616..08ea20b35 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -48,7 +48,7 @@ make -j $(nproc) OPTFLAGS=-O2 DEBUG=0 ## macOS -1. Requires `gcc@12, sdl2, libpng, glew, dylibbundler` (can be installed via brew, etc) +1. Requires Xcode (or xcode-tools) && `sdl2, libpng, glew, dylibbundler` (can be installed via brew, etc) ```bash # Clone the repo git clone https://github.com/HarbourMasters/Shipwright.git @@ -59,9 +59,9 @@ cp OTRExporter cd soh # Extract the assets/Compile the exporter/Run the exporter # -jX defines number of cores to use for compilation - lower or remove entirely if having issues -make setup -j8 DEBUG=0 CC=gcc-12 CXX=g++-12 +make setup -j8 DEBUG=0 # Compile the code (watch the -j parameter as above) -make -j8 DEBUG=0 CC=gcc-12 CXX=g++-12 +make -j8 DEBUG=0 # Create macOS app bundle make filledappbundle ``` diff --git a/Jenkinsfile b/Jenkinsfile index 74e33c1b1..8ea6317a4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -137,8 +137,8 @@ pipeline { sh ''' cp ../../ZELOOTD.z64 OTRExporter/baserom_non_mq.z64 cd soh - make setup -j4 DEBUG=0 OPTFLAGS=-O2 CC=gcc-12 CXX=g++-12 - make -j4 DEBUG=0 OPTFLAGS=-O2 CC=gcc-12 CXX=g++-12 + export CC="clang -arch arm64 -arch x86_64"; export CXX="clang++ -arch arm64 -arch x86_64"; make setup -j4 OPTFLAGS=-O2 DEBUG=0 LD="ld" + export CC="clang -arch arm64 -arch x86_64"; export CXX="clang++ -arch arm64 -arch x86_64"; make -j4 DEBUG=0 OPTFLAGS=-O2 LD="ld" make -j4 appbundle mv ../README.md readme.txt 7z a soh-mac.7z soh.app readme.txt diff --git a/OTRExporter/OTRExporter/DisplayListExporter.cpp b/OTRExporter/OTRExporter/DisplayListExporter.cpp index ed4694397..f233f2d78 100644 --- a/OTRExporter/OTRExporter/DisplayListExporter.cpp +++ b/OTRExporter/OTRExporter/DisplayListExporter.cpp @@ -96,14 +96,14 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina { case G_NOOP: { - Gfx value = gsDPNoOp(); + Gfx value = {gsDPNoOp()}; word0 = value.words.w0; word1 = value.words.w1; } break; case G_ENDDL: { - Gfx value = gsSPEndDisplayList(); + Gfx value = {gsSPEndDisplayList()}; word0 = value.words.w0; word1 = value.words.w1; } @@ -114,7 +114,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t nnnn = (data & 0x0000FFFF00000000ULL) >> 32; int32_t vvvvvvvv = (data & 0x00000000FFFFFFFFULL); - Gfx value = gsSPModifyVertex(nnnn / 2, ww, vvvvvvvv); + Gfx value = {gsSPModifyVertex(nnnn / 2, ww, vvvvvvvv)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -131,35 +131,35 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t cccccc = (data & 0x00FFFFFF00000000) >> 32; int32_t ssssssss = (data & 0xFFFFFFFF); - Gfx value = gsSPGeometryMode(~cccccc, ssssssss); + Gfx value = {gsSPGeometryMode(~cccccc, ssssssss)}; word0 = value.words.w0; word1 = value.words.w1; } break; case G_RDPPIPESYNC: { - Gfx value = gsDPPipeSync(); + Gfx value = {gsDPPipeSync()}; word0 = value.words.w0; word1 = value.words.w1; } break; case G_RDPLOADSYNC: { - Gfx value = gsDPLoadSync(); + Gfx value = {gsDPLoadSync()}; word0 = value.words.w0; word1 = value.words.w1; } break; case G_RDPTILESYNC: { - Gfx value = gsDPTileSync(); + Gfx value = {gsDPTileSync()}; word0 = value.words.w0; word1 = value.words.w1; } break; case G_RDPFULLSYNC: { - Gfx value = gsDPFullSync(); + Gfx value = {gsDPFullSync()}; word0 = value.words.w0; word1 = value.words.w1; } @@ -169,14 +169,14 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t hhhhhh = (data & 0x00FFFFFF00000000) >> 32; int32_t llllllll = (data & 0x00000000FFFFFFFF); - Gfx value = gsDPSetOtherMode(hhhhhh, llllllll); + Gfx value = {gsDPSetOtherMode(hhhhhh, llllllll)}; word0 = value.words.w0; word1 = value.words.w1; } break; case G_POPMTX: { - Gfx value = gsSPPopMatrix(data); + Gfx value = {gsSPPopMatrix(data)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -188,7 +188,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina uint8_t b = (uint8_t)((data & 0xFF00FF00) >> 8); uint8_t a = (uint8_t)((data & 0x000000FF) >> 0); - Gfx value = gsDPSetEnvColor(r, g, b, a); + Gfx value = {gsDPSetEnvColor(r, g, b, a)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -204,7 +204,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina mm = (mm & 0x0FFFFFFF) + 1; - Gfx value = gsSPMatrix(mm, pp); + Gfx value = {gsSPMatrix(mm, pp)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -214,7 +214,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina uint32_t mm = (data & 0x00000000FFFFFFFF); pp ^= G_MTX_PUSH; - Gfx value = gsSPMatrix(mm, pp); + Gfx value = {gsSPMatrix(mm, pp)}; word0 = value.words.w0; word1 = value.words.w1; @@ -253,7 +253,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t xxx = (data & 0x0000000000FFF000) >> 12; int32_t ddd = (data & 0x0000000000000FFF); - Gfx value = gsDPLoadBlock(i, sss, ttt, xxx, ddd); + Gfx value = {gsDPLoadBlock(i, sss, ttt, xxx, ddd)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -263,7 +263,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t vvvv = (data & 0xFFFF00000000) >> 32; int32_t wwww = (data & 0x0000FFFF); - Gfx value = gsSPCullDisplayList(vvvv / 2, wwww / 2); + Gfx value = {gsSPCullDisplayList(vvvv / 2, wwww / 2)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -279,7 +279,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina uint32_t z = (data & 0x00000000FFFFFFFF) >> 0; uint32_t h = (data & 0xFFFFFFFF); - Gfx value = gsSPBranchLessZraw3(h & 0x00FFFFFF); + Gfx value = {gsSPBranchLessZraw3(h & 0x00FFFFFF)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -292,7 +292,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina break; case G_RDPHALF_2: { - Gfx value = gsDPWordLo(data & 0xFFFFFFFF); + Gfx value = {gsDPWordLo(data & 0xFFFFFFFF)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -305,7 +305,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t XXX = (data & 0x0000000000FFF000) >> 12; int32_t YYY = (data & 0x0000000000000FFF); - Gfx value = gsSPTextureRectangle2(XXX, YYY, xxx, yyy, i); + Gfx value = {gsSPTextureRectangle2(XXX, YYY, xxx, yyy, i)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -324,7 +324,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int bp = 0; - Gfx value = gsSPBranchLessZraw2(0xDEADABCD, (a / 5) | (b / 2), z); + Gfx value = {gsSPBranchLessZraw2(0xDEADABCD, (a / 5) | (b / 2), z)}; word0 = (value.words.w0 & 0x00FFFFFF) + (G_BRANCH_Z_OTR << 24); word1 = value.words.w1; @@ -389,9 +389,9 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina u32 dListVal = (data & 0x0FFFFFFF) + 1; if (pp != 0) - value = gsSPBranchList(dListVal); + value = {gsSPBranchList(dListVal)}; else - value = gsSPDisplayList(dListVal); + value = {gsSPDisplayList(dListVal)}; word0 = value.words.w0; word1 = value.words.w1; @@ -469,7 +469,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t ddd = (____ & 0x700) >> 8; int32_t nnnnnnn = (____ & 0xFE) >> 1; - Gfx value = gsSPTexture(ssss, tttt, lll, ddd, nnnnnnn); + Gfx value = {gsSPTexture(ssss, tttt, lll, ddd, nnnnnnn)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -480,7 +480,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t bb = ((data & 0x0000FF0000000000ULL) >> 40) / 2; int32_t cc = ((data & 0x000000FF00000000ULL) >> 32) / 2; - Gfx test = gsSP1Triangle(aa, bb, cc, 0); + Gfx test = {gsSP1Triangle(aa, bb, cc, 0)}; word0 = test.words.w0; word1 = test.words.w1; } @@ -494,7 +494,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t ee = ((data & 0x0000000000FF00ULL) >> 8) / 2; int32_t ff = ((data & 0x000000000000FFULL) >> 0) / 2; - Gfx test = gsSP2Triangles(aa, bb, cc, 0, dd, ee, ff, 0); + Gfx test = {gsSP2Triangles(aa, bb, cc, 0, dd, ee, ff, 0)}; word0 = test.words.w0; word1 = test.words.w1; } @@ -506,7 +506,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t cc = ((data & 0x000000FF00000000ULL) >> 32) / 2; int32_t dd = ((data & 0x000000000000FFULL)) / 2; - Gfx test = gsSP1Quadrangle(aa, bb, cc, dd, 0); + Gfx test = {gsSP1Quadrangle(aa, bb, cc, dd, 0)}; word0 = test.words.w0; word1 = test.words.w1; } @@ -520,7 +520,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t bb = (data & 0x000000000000FF00) >> 8; int32_t aa = (data & 0x00000000000000FF) >> 0; - Gfx value = gsDPSetPrimColor(mm, ff, rr, gg, bb, aa); + Gfx value = {gsDPSetPrimColor(mm, ff, rr, gg, bb, aa)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -534,7 +534,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina // TODO: Output the correct render modes in data - Gfx value = gsSPSetOtherMode(0xE2, sft, len, dd); + Gfx value = {gsSPSetOtherMode(0xE2, sft, len, dd)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -552,11 +552,11 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina if (sft == 14) // G_MDSFT_TEXTLUT { const char* types[] = { "G_TT_NONE", "G_TT_NONE", "G_TT_RGBA16", "G_TT_IA16" }; - value = gsDPSetTextureLUT(dd >> 14); + value = {gsDPSetTextureLUT(dd >> 14)}; } else { - value = gsSPSetOtherMode(0xE3, sft, nn + 1, dd); + value = {gsSPSetOtherMode(0xE3, sft, nn + 1, dd)}; } word0 = value.words.w0; @@ -583,7 +583,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t bbbb = (data & 0b0000000000000000000000000000000000000000000000000000000011110000) >> 4; int32_t uuuu = (data & 0b0000000000000000000000000000000000000000000000000000000000001111); - Gfx value = gsDPSetTile(fff, ii, nnnnnnnnn, mmmmmmmmm, ttt, pppp, cc, aaaa, ssss, dd, bbbb, uuuu); + Gfx value = {gsDPSetTile(fff, ii, nnnnnnnnn, mmmmmmmmm, ttt, pppp, cc, aaaa, ssss, dd, bbbb, uuuu)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -607,7 +607,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t ab1 = (data & 0b00000000000000000000000000000000000000000000000000000000111000) >> 3; int32_t ad1 = (data & 0b00000000000000000000000000000000000000000000000000000000000111) >> 0; - Gfx value = gsDPSetCombineLERP2(a0, b0, c0, d0, aa0, ab0, ac0, ad0, a1, b1, c1, d1, aa1, ab1, ac1, ad1); + Gfx value = {gsDPSetCombineLERP2(a0, b0, c0, d0, aa0, ab0, ac0, ad0, a1, b1, c1, d1, aa1, ab1, ac1, ad1)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -620,7 +620,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t vvv = (data & 0x0000000000000FFF); int32_t i = (data & 0x000000000F000000) >> 24; - Gfx value = gsDPSetTileSize(i, sss, ttt, uuu, vvv); + Gfx value = {gsDPSetTileSize(i, sss, ttt, uuu, vvv)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -630,7 +630,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t t = (data & 0x0000000007000000) >> 24; int32_t ccc = (data & 0x00000000003FF000) >> 14; - Gfx value = gsDPLoadTLUTCmd(t, ccc); + Gfx value = {gsDPLoadTLUTCmd(t, ccc)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -643,7 +643,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int uuu = (data & 0x0000000000FFF000) >> 12; int vvv= (data & 0x0000000000000FFF); - Gfx value = gsDPLoadTile(i, sss, ttt, uuu, vvv); + Gfx value = {gsDPLoadTile(i, sss, ttt, uuu, vvv)}; word0 = value.words.w0; word1 = value.words.w1; } @@ -661,7 +661,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina uint32_t fmt = (__ & 0xE0) >> 5; uint32_t siz = (__ & 0x18) >> 3; - Gfx value = gsDPSetTextureImage(fmt, siz, www + 1, (seg & 0x0FFFFFFF) + 1); + Gfx value = {gsDPSetTextureImage(fmt, siz, www + 1, (seg & 0x0FFFFFFF) + 1)}; word0 = value.words.w0; word1 = value.words.w1; @@ -679,7 +679,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina uint32_t fmt = (__ & 0xE0) >> 5; uint32_t siz = (__ & 0x18) >> 3; - Gfx value = gsDPSetTextureImage(fmt, siz, www + 1, __); + Gfx value = {gsDPSetTextureImage(fmt, siz, www + 1, __)}; word0 = value.words.w0 & 0x00FFFFFF; word0 += (G_SETTIMG_OTR << 24); //word1 = value.words.w1; @@ -722,7 +722,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina int32_t aa = (data & 0x000000FF00000000ULL) >> 32; int32_t nn = (data & 0x000FF00000000000ULL) >> 44; - Gfx value = gsSPVertex(data & 0xFFFFFFFF, nn, ((aa >> 1) - nn)); + Gfx value = {gsSPVertex(data & 0xFFFFFFFF, nn, ((aa >> 1) - nn))}; word0 = value.words.w0; word1 = value.words.w1 | 1; @@ -745,7 +745,7 @@ void OTRExporter_DisplayList::Save(ZResource* res, const fs::path& outPath, Bina { uint32_t diff = segOffset - vtxDecl->address; - Gfx value = gsSPVertex(diff, nn, ((aa >> 1) - nn)); + Gfx value = {gsSPVertex(diff, nn, ((aa >> 1) - nn))}; word0 = value.words.w0; word0 &= 0x00FFFFFF; @@ -893,4 +893,4 @@ std::string OTRExporter_DisplayList::GetPrefix(ZResource* res) prefix = "code"; return prefix; -} \ No newline at end of file +} diff --git a/OTRExporter/OTRExporter/VersionInfo.cpp b/OTRExporter/OTRExporter/VersionInfo.cpp index 0a2004673..ba0146d41 100644 --- a/OTRExporter/OTRExporter/VersionInfo.cpp +++ b/OTRExporter/OTRExporter/VersionInfo.cpp @@ -5,7 +5,7 @@ std::map resourceVersions; void InitVersionInfo() { - resourceVersions = { + resourceVersions = std::map { { Ship::ResourceType::Animation, 0 }, { Ship::ResourceType::Model, 0 }, { Ship::ResourceType::Texture, 0 }, @@ -24,4 +24,4 @@ void InitVersionInfo() { Ship::ResourceType::Text, 0 }, { Ship::ResourceType::Blob, 0 }, }; -} \ No newline at end of file +} diff --git a/ZAPDTR/Makefile b/ZAPDTR/Makefile index 2e871b32f..d9a85b6db 100644 --- a/ZAPDTR/Makefile +++ b/ZAPDTR/Makefile @@ -124,7 +124,7 @@ lib/libgfxd/libgfxd.a: .PHONY: StormLib StormLib: LDFLAGS="" cmake -B ../StormLib/build -S ../StormLib - LDFLAGS="" cmake --build ../StormLib/build + $(MAKE) -C ../StormLib/build .PHONY: ExporterTest ExporterTest: diff --git a/ZAPDTR/ZAPD/ZAudioDecode.cpp b/ZAPDTR/ZAPD/ZAudioDecode.cpp index b8b066474..90ecfe35c 100644 --- a/ZAPDTR/ZAPD/ZAudioDecode.cpp +++ b/ZAPDTR/ZAPD/ZAudioDecode.cpp @@ -461,8 +461,8 @@ char* OldMain(char* infilename) else { char comprType[5] = { - CommChunk.compressionTypeH >> 8, CommChunk.compressionTypeH & 0xFF, - CommChunk.compressionTypeL >> 8, CommChunk.compressionTypeL & 0xFF, 0}; + static_cast(CommChunk.compressionTypeH >> 8), static_cast(CommChunk.compressionTypeH & 0xFF), + static_cast(CommChunk.compressionTypeL >> 8), static_cast(CommChunk.compressionTypeL & 0xFF), 0}; fail_parse("file is of the wrong compression type [got %s (%08x)]", &comprType, cType); } @@ -603,8 +603,8 @@ char* OldMain(char* infilename) { s32 startPos = aloops[0].start, endPos = aloops[0].end; const char* markerNames[2] = {"start", "end"}; - Marker markers[2] = {{1, startPos >> 16, startPos & 0xffff}, - {2, endPos >> 16, endPos & 0xffff}}; + Marker markers[2] = {{1, static_cast(startPos >> 16), static_cast(startPos & 0xffff)}, + {2, static_cast(endPos >> 16), static_cast(endPos & 0xffff)}}; write_header(ofile, "MARK", 2 + 2 * sizeof(Marker) + 1 + 5 + 1 + 3); s16 numMarkers = bswap16(2); fwrite(&numMarkers, sizeof(s16), 1, ofile); @@ -666,4 +666,4 @@ char* OldMain(char* infilename) fclose(ifile); fclose(ofile); return 0; -} \ No newline at end of file +} diff --git a/ZAPDTR/ZAPD/ZFile.cpp b/ZAPDTR/ZAPD/ZFile.cpp index 9ff7a6823..1ea5cd553 100644 --- a/ZAPDTR/ZAPD/ZFile.cpp +++ b/ZAPDTR/ZAPD/ZFile.cpp @@ -800,9 +800,11 @@ void ZFile::GenerateSourceHeaderFiles() { OutputFormatter formatter; + formatter.Write("#pragma once\n"); + std::set nameSet; for (ZResource* res : resources) { - std::string resSrc = res->GetSourceOutputHeader(""); + std::string resSrc = res->GetSourceOutputHeader("", &nameSet); formatter.Write(resSrc); if (resSrc != "") @@ -811,7 +813,7 @@ void ZFile::GenerateSourceHeaderFiles() for (auto& sym : symbolResources) { - formatter.Write(sym.second->GetSourceOutputHeader("")); + formatter.Write(sym.second->GetSourceOutputHeader("", &nameSet)); } formatter.Write(ProcessExterns()); diff --git a/ZAPDTR/ZAPD/ZResource.cpp b/ZAPDTR/ZAPD/ZResource.cpp index 550031ab4..89238d9a0 100644 --- a/ZAPDTR/ZAPD/ZResource.cpp +++ b/ZAPDTR/ZAPD/ZResource.cpp @@ -7,6 +7,7 @@ #include "WarningHandler.h" #include "ZFile.h" #include +#include #include #include @@ -304,7 +305,7 @@ void ZResource::GetSourceOutputCode([[maybe_unused]] const std::string& prefix) } } -std::string ZResource::GetSourceOutputHeader([[maybe_unused]] const std::string& prefix) +std::string ZResource::GetSourceOutputHeader([[maybe_unused]] const std::string& prefix, std::set *nameSet) { if (Globals::Instance->otrMode && genOTRDef) { @@ -342,9 +343,20 @@ std::string ZResource::GetSourceOutputHeader([[maybe_unused]] const std::string& prefix = "text"; if (prefix != "") - str += StringHelper::Sprintf("#define %s \"__OTR__%s/%s/%s\"", name.c_str(), prefix.c_str(), outName.c_str(), nameStr.c_str()); + str += StringHelper::Sprintf("#define d%s \"__OTR__%s/%s/%s\"", name.c_str(), prefix.c_str(), outName.c_str(), nameStr.c_str()); else - str += StringHelper::Sprintf("#define %s \"__OTR__%s/%s\"", name.c_str(), outName.c_str(), nameStr.c_str()); + str += StringHelper::Sprintf("#define d%s \"__OTR__%s/%s\"", name.c_str(), outName.c_str(), nameStr.c_str()); + + if (nameSet && nameSet->find(name) == nameSet->end()) { +#ifdef _WIN32 + str += StringHelper::Sprintf("\nstatic const __declspec(align(2)) char %s[] = d%s;", name.c_str(), name.c_str()); +#else + str += StringHelper::Sprintf("\nstatic const char %s[] __attribute__((aligned (2))) = d%s;", name.c_str(), name.c_str()); +#endif + if (nameSet) { + nameSet->insert(name); + } + } return str; } diff --git a/ZAPDTR/ZAPD/ZResource.h b/ZAPDTR/ZAPD/ZResource.h index 8b1055a4b..be272cf6b 100644 --- a/ZAPDTR/ZAPD/ZResource.h +++ b/ZAPDTR/ZAPD/ZResource.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -116,7 +117,7 @@ public: [[nodiscard]] virtual std::string GetDefaultName(const std::string& prefix) const; virtual void GetSourceOutputCode(const std::string& prefix); - virtual std::string GetSourceOutputHeader(const std::string& prefix); + virtual std::string GetSourceOutputHeader(const std::string& prefix, std::set *nameSet); virtual void CalcHash(); /** * Exports the resource to binary format diff --git a/ZAPDTR/ZAPD/ZString.cpp b/ZAPDTR/ZAPD/ZString.cpp index 965d4d636..2a0c1eaf8 100644 --- a/ZAPDTR/ZAPD/ZString.cpp +++ b/ZAPDTR/ZAPD/ZString.cpp @@ -48,7 +48,7 @@ std::string ZString::GetBodySourceCode() const return StringHelper::Sprintf("\t\"%s\"", strData.data()); } -std::string ZString::GetSourceOutputHeader([[maybe_unused]] const std::string& prefix) +std::string ZString::GetSourceOutputHeader([[maybe_unused]] const std::string& prefix, std::set *nameSet) { return StringHelper::Sprintf("#define %s_macro \"%s\"", name.c_str(), strData.data()); } diff --git a/ZAPDTR/ZAPD/ZString.h b/ZAPDTR/ZAPD/ZString.h index 6c58ebdcb..19f615a90 100644 --- a/ZAPDTR/ZAPD/ZString.h +++ b/ZAPDTR/ZAPD/ZString.h @@ -13,7 +13,7 @@ public: Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr) override; std::string GetBodySourceCode() const override; - std::string GetSourceOutputHeader(const std::string& prefix) override; + std::string GetSourceOutputHeader(const std::string& prefix, std::set *nameSet) override; std::string GetSourceTypeName() const override; ZResourceType GetResourceType() const override; diff --git a/ZAPDTR/ZAPD/ZSymbol.cpp b/ZAPDTR/ZAPD/ZSymbol.cpp index eabfc2faa..b5df68669 100644 --- a/ZAPDTR/ZAPD/ZSymbol.cpp +++ b/ZAPDTR/ZAPD/ZSymbol.cpp @@ -74,7 +74,7 @@ size_t ZSymbol::GetRawDataSize() const return typeSize; } -std::string ZSymbol::GetSourceOutputHeader([[maybe_unused]] const std::string& prefix) +std::string ZSymbol::GetSourceOutputHeader([[maybe_unused]] const std::string& prefix, std::set *nameSet) { if (isArray) { diff --git a/ZAPDTR/ZAPD/ZSymbol.h b/ZAPDTR/ZAPD/ZSymbol.h index 7cb14aa9b..e00f14c6b 100644 --- a/ZAPDTR/ZAPD/ZSymbol.h +++ b/ZAPDTR/ZAPD/ZSymbol.h @@ -18,7 +18,7 @@ public: Declaration* DeclareVar(const std::string& prefix, const std::string& bodyStr) override; - std::string GetSourceOutputHeader(const std::string& prefix) override; + std::string GetSourceOutputHeader(const std::string& prefix, std::set *nameSet) override; std::string GetSourceTypeName() const override; ZResourceType GetResourceType() const override; diff --git a/libultraship/Makefile b/libultraship/Makefile index 2d0b1b606..b3b7d2836 100644 --- a/libultraship/Makefile +++ b/libultraship/Makefile @@ -17,12 +17,23 @@ WARN := -Wall -Wextra -Werror \ -Wno-unused-function \ -Wno-parentheses \ -Wno-narrowing \ - -Wno-error=stringop-overflow \ -Wno-missing-field-initializers \ - -Wno-error=multichar + -Wno-error=multichar \ + -Wno-unused-command-line-argument \ + -Wno-delete-non-abstract-non-virtual-dtor \ + -Wno-unused-private-field \ + -Wno-deprecated-copy-with-user-provided-copy \ + -Wno-deprecated-declarations \ + -Wno-unknown-warning-option CWARN := -CXXWARN := -Wno-deprecated-enum-enum-conversion -Wno-error=maybe-uninitialized +CXXWARN := -Wno-deprecated-enum-enum-conversion -Wno-deprecated-copy + +COMPILER_VERSION := $(shell $(CXX) --version) +ifneq '' '$(findstring g++,$(COMPILER_VERSION))' + WARN += -Wno-error=stringop-overflow + CXXWARN += -Wno-error=maybe-uninitialized +endif CXXFLAGS := $(WARN) $(CXXWARN) -std=c++20 -D_GNU_SOURCE -DENABLE_OPENGL -DSPDLOG_ACTIVE_LEVEL=0 CFLAGS := $(WARN) $(CWARN) -std=c99 -D_GNU_SOURCE -DENABLE_OPENGL -DSPDLOG_ACTIVE_LEVEL=0 @@ -32,6 +43,10 @@ ifeq ($(UNAME), Darwin) #APPLE CPPFLAGS += $(shell pkg-config --cflags sdl2 glew) -framework OpenGL endif +ifeq ($(UNAME), Linux) + WARN += -Wno-error=stringop-overflow # This is required with clang on Linux. +endif + ifneq ($(DEBUG),0) CXXFLAGS += -g -D_DEBUG CFLAGS += -g -D_DEBUG diff --git a/libultraship/libultraship/Console.cpp b/libultraship/libultraship/Console.cpp index 6708f1bfb..da61e4056 100644 --- a/libultraship/libultraship/Console.cpp +++ b/libultraship/libultraship/Console.cpp @@ -28,7 +28,7 @@ static bool ClearCommand(const std::vector&) { std::string toLowerCase(std::string in) { std::string cpy(in); - std::ranges::transform(cpy, cpy.begin(), [](unsigned char c) { return std::tolower(c); }); + std::transform(cpy.begin(), cpy.end(), cpy.begin(), ::tolower); return cpy; } @@ -204,11 +204,11 @@ void Console::Draw() { for (int i = 0; i < static_cast(channel.size()); i++) { ConsoleLine line = channel[i]; if(!this->filter.empty() && line.text.find(this->filter) == std::string::npos) continue; - if(this->level_filter != NULLSTR && line.priority != (std::ranges::find(priority_filters, this->level_filter) - priority_filters.begin()) - 1) continue; + if(this->level_filter != NULLSTR && line.priority != (std::find(priority_filters.begin(), priority_filters.end(), this->level_filter) - priority_filters.begin()) - 1) continue; std::string id = line.text + "##" + std::to_string(i); ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); - const bool is_selected = (this->selectedId == i) || std::ranges::find(this->selectedEntries, i) != this->selectedEntries.end(); + const bool is_selected = (this->selectedId == i) || std::find(this->selectedEntries.begin(), this->selectedEntries.end(), i) != this->selectedEntries.end(); ImGui::PushStyleColor(ImGuiCol_Text, this->priority_colors[line.priority]); if (ImGui::Selectable(id.c_str(), is_selected)) { if (ImGui::IsKeyDown(ImGui::GetKeyIndex(ImGuiKey_LeftCtrl)) && !is_selected) diff --git a/libultraship/libultraship/ImGuiImpl.cpp b/libultraship/libultraship/ImGuiImpl.cpp index 1886823c7..7b1d905e7 100644 --- a/libultraship/libultraship/ImGuiImpl.cpp +++ b/libultraship/libultraship/ImGuiImpl.cpp @@ -1246,7 +1246,7 @@ namespace SohImGui { if (ImGui::BeginMenu(category.first.c_str())) { for (const std::string& name : category.second) { std::string varName(name); - varName.erase(std::ranges::remove_if(varName, isspace).begin(), varName.end()); + varName.erase(std::remove_if(varName.begin(), varName.end(), [](unsigned char x) { return std::isspace(x); }), varName.end()); std::string toggleName = "g" + varName + "Enabled"; EnhancementCheckbox(name.c_str(), toggleName.c_str()); diff --git a/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp b/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp index b53c2550f..91e63227e 100644 --- a/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp +++ b/libultraship/libultraship/Lib/Fast3D/gfx_pc.cpp @@ -566,7 +566,7 @@ static bool gfx_texture_cache_lookup(int i, int tile) { static void gfx_texture_cache_delete(const uint8_t* orig_addr) { while (gfx_texture_cache.map.bucket_count() > 0) { - TextureCacheKey key = { orig_addr, 0, 0, 0 }; // bucket index only depends on the address + TextureCacheKey key = { orig_addr, {0}, 0, 0 }; // bucket index only depends on the address size_t bucket = gfx_texture_cache.map.bucket(key); bool again = false; for (auto it = gfx_texture_cache.map.begin(bucket); it != gfx_texture_cache.map.end(bucket); ++it) { diff --git a/libultraship/libultraship/mixer.c b/libultraship/libultraship/mixer.c index 1e66dc8a1..2e80ffb16 100644 --- a/libultraship/libultraship/mixer.c +++ b/libultraship/libultraship/mixer.c @@ -4,7 +4,9 @@ #include "mixer.h" +#ifndef __clang__ #pragma GCC optimize ("unroll-loops") +#endif #define ROUND_UP_64(v) (((v) + 63) & ~63) #define ROUND_UP_32(v) (((v) + 31) & ~31) @@ -449,10 +451,14 @@ void aFilterImpl(uint8_t flags, uint16_t count_or_buf, int16_t *state_or_filter) int16_t *buf = BUF_S16(count_or_buf); if (flags == A_INIT) { +#ifndef __clang__ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wmemset-elt-size" +#endif memset(tmp, 0, 8 * sizeof(int16_t)); +#ifndef __clang__ #pragma GCC diagnostic pop +#endif memset(tmp2, 0, 8 * sizeof(int16_t)); } else { memcpy(tmp, state_or_filter, 8 * sizeof(int16_t)); diff --git a/soh/Makefile b/soh/Makefile index 43140dc95..14bb46827 100644 --- a/soh/Makefile +++ b/soh/Makefile @@ -18,8 +18,11 @@ LTO ?= 0 WARN := \ -Wno-return-type \ + -Wno-unused-command-line-argument \ + -Wno-implicit-function-declaration \ + -Wno-c++11-narrowing \ -funsigned-char \ - -fno-stack-protector -fno-common -fno-zero-initialized-in-bss -fno-strict-aliasing -fno-inline-functions -fno-inline-small-functions -fno-toplevel-reorder -ffreestanding -fwrapv \ + -fno-stack-protector -fno-common -fno-zero-initialized-in-bss -fno-strict-aliasing -fno-inline-functions -fno-inline-small-functions -ffreestanding -fwrapv \ CXXFLAGS := $(WARN) -std=c++20 -D_GNU_SOURCE -fpermissive -no-pie -nostdlib CFLAGS := $(WARN) -std=c99 -D_GNU_SOURCE -no-pie -nostdlib @@ -99,7 +102,6 @@ LDLIBS := \ bz2 \ z \ pthread \ - atomic \ ultraship \ ) @@ -116,7 +118,7 @@ endif ifeq ($(UNAME), Darwin) #APPLE LDLIBS += \ - $(addprefix -framework, \ + $(addprefix -framework , \ OpenGL \ ) \ $(shell sdl2-config --libs) $(shell pkg-config --libs glew) @@ -208,7 +210,7 @@ build/%.o: %.c $(TARGET): $(LIBULTRASHIP) $(TARGET): $(O_FILES) - $(CXX) $^ -o $@ $(LDFLAGS) -fuse-ld=$(LD) $(LDDIRS) $(LDLIBS) + $(CXX) $^ -o $@ $(LDFLAGS) $(LDDIRS) $(LDLIBS) -include $(D_FILES) diff --git a/soh/soh/Enhancements/bootcommands.c b/soh/soh/Enhancements/bootcommands.c index 90f3ae7a2..0b789b445 100644 --- a/soh/soh/Enhancements/bootcommands.c +++ b/soh/soh/Enhancements/bootcommands.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/soh/soh/Enhancements/debugconsole.cpp b/soh/soh/Enhancements/debugconsole.cpp index e96942893..445134f2a 100644 --- a/soh/soh/Enhancements/debugconsole.cpp +++ b/soh/soh/Enhancements/debugconsole.cpp @@ -509,7 +509,7 @@ void DebugConsole_LoadCVars() if (cfg.size() < 2) continue; if (cfg[1].find("\"") != std::string::npos) { std::string value(cfg[1]); - value.erase(std::ranges::remove(value, '\"').begin(), value.end()); + value.erase(std::remove(value.begin(), value.end(), '\"'), value.end()); CVar_SetString(cfg[0].c_str(), ImStrdup(value.c_str())); } if (is_number(cfg[1])) { diff --git a/soh/soh/Enhancements/debugger/colViewer.cpp b/soh/soh/Enhancements/debugger/colViewer.cpp index 366e228ae..1cab6ef64 100644 --- a/soh/soh/Enhancements/debugger/colViewer.cpp +++ b/soh/soh/Enhancements/debugger/colViewer.cpp @@ -194,9 +194,9 @@ void CreateSphereFace(std::vector>& faces, in // Create 3 new verticies at the midpoints Vec3f vs[3] = { - Vec3f((v0.n.ob[0] + v1.n.ob[0]) / 2.0f, (v0.n.ob[1] + v1.n.ob[1]) / 2.0f, (v0.n.ob[2] + v1.n.ob[2]) / 2.0f), - Vec3f((v1.n.ob[0] + v2.n.ob[0]) / 2.0f, (v1.n.ob[1] + v2.n.ob[1]) / 2.0f, (v1.n.ob[2] + v2.n.ob[2]) / 2.0f), - Vec3f((v2.n.ob[0] + v0.n.ob[0]) / 2.0f, (v2.n.ob[1] + v0.n.ob[1]) / 2.0f, (v2.n.ob[2] + v0.n.ob[2]) / 2.0f) + Vec3f{(v0.n.ob[0] + v1.n.ob[0]) / 2.0f, (v0.n.ob[1] + v1.n.ob[1]) / 2.0f, (v0.n.ob[2] + v1.n.ob[2]) / 2.0f}, + Vec3f{(v1.n.ob[0] + v2.n.ob[0]) / 2.0f, (v1.n.ob[1] + v2.n.ob[1]) / 2.0f, (v1.n.ob[2] + v2.n.ob[2]) / 2.0f}, + Vec3f{(v2.n.ob[0] + v0.n.ob[0]) / 2.0f, (v2.n.ob[1] + v0.n.ob[1]) / 2.0f, (v2.n.ob[2] + v0.n.ob[2]) / 2.0f} }; // Normalize vertex positions so they are on the sphere @@ -221,20 +221,20 @@ void CreateSphereData() { float d = (1.0f + sqrtf(5.0f)) / 2.0f; // Create the 12 starting verticies, 4 on each rectangle - base.emplace_back(-1, d, 0); - base.emplace_back(1, d, 0); - base.emplace_back(-1, -d, 0); - base.emplace_back(1, -d, 0); + base.emplace_back(Vec3f({-1, d, 0})); + base.emplace_back(Vec3f({1, d, 0})); + base.emplace_back(Vec3f({-1, -d, 0})); + base.emplace_back(Vec3f({1, -d, 0})); - base.emplace_back(0, -1, d); - base.emplace_back(0, 1, d); - base.emplace_back(0, -1, -d); - base.emplace_back(0, 1, -d); + base.emplace_back(Vec3f({0, -1, d})); + base.emplace_back(Vec3f({0, 1, d})); + base.emplace_back(Vec3f({0, -1, -d})); + base.emplace_back(Vec3f({0, 1, -d})); - base.emplace_back(d, 0, -1); - base.emplace_back(d, 0, 1); - base.emplace_back(-d, 0, -1); - base.emplace_back(-d, 0, 1); + base.emplace_back(Vec3f({d, 0, -1})); + base.emplace_back(Vec3f({d, 0, 1})); + base.emplace_back(Vec3f({-d, 0, -1})); + base.emplace_back(Vec3f({-d, 0, 1})); // Normalize verticies so they are on the unit sphere for (Vec3f& v : base) { diff --git a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp index 8ccd10ba5..0c9d0f25b 100644 --- a/soh/soh/Enhancements/debugger/debugSaveEditor.cpp +++ b/soh/soh/Enhancements/debugger/debugSaveEditor.cpp @@ -185,17 +185,17 @@ typedef struct { // Maps quest items ids to info for use in ImGui std::map questMapping = { - QUEST_MAP_ENTRY(QUEST_MEDALLION_FOREST, gForestMedallionIconTex), - QUEST_MAP_ENTRY(QUEST_MEDALLION_FIRE, gFireMedallionIconTex), - QUEST_MAP_ENTRY(QUEST_MEDALLION_WATER, gWaterMedallionIconTex), - QUEST_MAP_ENTRY(QUEST_MEDALLION_SPIRIT, gSpiritMedallionIconTex), - QUEST_MAP_ENTRY(QUEST_MEDALLION_SHADOW, gShadowMedallionIconTex), - QUEST_MAP_ENTRY(QUEST_MEDALLION_LIGHT, gLightMedallionIconTex), - QUEST_MAP_ENTRY(QUEST_KOKIRI_EMERALD, gKokiriEmeraldIconTex), - QUEST_MAP_ENTRY(QUEST_GORON_RUBY, gGoronRubyIconTex), - QUEST_MAP_ENTRY(QUEST_ZORA_SAPPHIRE, gZoraSapphireIconTex), - QUEST_MAP_ENTRY(QUEST_STONE_OF_AGONY, gStoneOfAgonyIconTex), - QUEST_MAP_ENTRY(QUEST_GERUDO_CARD, gGerudosCardIconTex), + QUEST_MAP_ENTRY(QUEST_MEDALLION_FOREST, dgForestMedallionIconTex), + QUEST_MAP_ENTRY(QUEST_MEDALLION_FIRE, dgFireMedallionIconTex), + QUEST_MAP_ENTRY(QUEST_MEDALLION_WATER, dgWaterMedallionIconTex), + QUEST_MAP_ENTRY(QUEST_MEDALLION_SPIRIT, dgSpiritMedallionIconTex), + QUEST_MAP_ENTRY(QUEST_MEDALLION_SHADOW, dgShadowMedallionIconTex), + QUEST_MAP_ENTRY(QUEST_MEDALLION_LIGHT, dgLightMedallionIconTex), + QUEST_MAP_ENTRY(QUEST_KOKIRI_EMERALD, dgKokiriEmeraldIconTex), + QUEST_MAP_ENTRY(QUEST_GORON_RUBY, dgGoronRubyIconTex), + QUEST_MAP_ENTRY(QUEST_ZORA_SAPPHIRE, dgZoraSapphireIconTex), + QUEST_MAP_ENTRY(QUEST_STONE_OF_AGONY, dgStoneOfAgonyIconTex), + QUEST_MAP_ENTRY(QUEST_GERUDO_CARD, dgGerudosCardIconTex), }; typedef struct { diff --git a/soh/soh/OTRGlobals.cpp b/soh/soh/OTRGlobals.cpp index 9bb5da000..ff8755006 100644 --- a/soh/soh/OTRGlobals.cpp +++ b/soh/soh/OTRGlobals.cpp @@ -1330,17 +1330,17 @@ extern "C" int16_t OTRGetRectDimensionFromRightEdge(float v) { } extern "C" void bswapSoundFontSound(SoundFontSound* swappable) { - swappable->sample = (SoundFontSample*)BOMSWAP32((u32)swappable->sample); - swappable->tuningAsU32 = BOMSWAP32((u32)swappable->tuningAsU32); + swappable->sample = (SoundFontSample*)BOMSWAP32((u32)(uintptr_t(swappable->sample))); + swappable->tuningAsU32 = BOMSWAP32((u32)(swappable->tuningAsU32 & 0xFFFFFFFF)); } extern "C" void bswapDrum(Drum* swappable) { bswapSoundFontSound(&swappable->sound); - swappable->envelope = (AdsrEnvelope*)BOMSWAP32((u32)swappable->envelope); + swappable->envelope = (AdsrEnvelope*)BOMSWAP32((u32)uintptr_t(swappable->envelope)); } extern "C" void bswapInstrument(Instrument* swappable) { - swappable->envelope = (AdsrEnvelope*)BOMSWAP32((u32)swappable->envelope); + swappable->envelope = (AdsrEnvelope*)BOMSWAP32((u32)uintptr_t(swappable->envelope)); bswapSoundFontSound(&swappable->lowNotesSound); bswapSoundFontSound(&swappable->normalNotesSound); bswapSoundFontSound(&swappable->highNotesSound); @@ -1355,9 +1355,9 @@ extern "C" void bswapSoundFontSample(SoundFontSample* swappable) { swappable->unk_bit25 = (origBitfield >> 21) & 0x01; swappable->size = (origBitfield) & 0x00FFFFFF; - swappable->sampleAddr = (u8*)BOMSWAP32((u32)swappable->sampleAddr); - swappable->loop = (AdpcmLoop*)BOMSWAP32((u32)swappable->loop); - swappable->book = (AdpcmBook*)BOMSWAP32((u32)swappable->book); + swappable->sampleAddr = (u8*)BOMSWAP32((u32)uintptr_t(swappable->sampleAddr)); + swappable->loop = (AdpcmLoop*)BOMSWAP32((u32)uintptr_t(swappable->loop)); + swappable->book = (AdpcmBook*)BOMSWAP32((u32)uintptr_t(swappable->book)); } extern "C" void bswapAdpcmLoop(AdpcmLoop* swappable) { diff --git a/soh/soh/gu_pc.c b/soh/soh/gu_pc.c index 7bdcded98..be1954a5d 100644 --- a/soh/soh/gu_pc.c +++ b/soh/soh/gu_pc.c @@ -1,3 +1,4 @@ +#include #include "z64.h" void guMtxF2L(float mf[4][4], Mtx* m) { @@ -84,4 +85,4 @@ void guNormalize(f32* x, f32* y, f32* z) { *x = *x * tmp; *y = *y * tmp; *z = *z * tmp; -} \ No newline at end of file +} diff --git a/soh/src/code/game.c b/soh/src/code/game.c index 306b292bc..9e0cfb50b 100644 --- a/soh/src/code/game.c +++ b/soh/src/code/game.c @@ -1,3 +1,4 @@ +#include #include "global.h" #include "vt.h" @@ -9,6 +10,9 @@ ViMode sViMode; FaultClient sGameFaultClient; u16 sLastButtonPressed; +// Forward declared, because this in a C++ header. +int gfx_create_framebuffer(uint32_t width, uint32_t height); + void GameState_FaultPrint(void) { static char sBtnChars[] = "ABZSuldr*+LRudlr"; s32 i; diff --git a/soh/src/overlays/gamestates/ovl_title/z_title.c b/soh/src/overlays/gamestates/ovl_title/z_title.c index 065059a32..0ab8e699e 100644 --- a/soh/src/overlays/gamestates/ovl_title/z_title.c +++ b/soh/src/overlays/gamestates/ovl_title/z_title.c @@ -33,6 +33,8 @@ void Title_PrintBuildInfo(Gfx** gfxp) { #ifdef _MSC_VER GfxPrint_Printf(&printer, "MSVC SHIP"); +#elif __clang__ + GfxPrint_Printf(&printer, "CLANG SHIP"); #else GfxPrint_Printf(&printer, "GCC SHIP"); #endif