Skip to content

Commit

Permalink
Add Support for macOS (HarbourMasters#441)
Browse files Browse the repository at this point in the history
* Fixed soh filters

* add more makefile changes

* almost ready

* more updates

* update

* update

* Update Makefiles to handle both platforms

* Allow for overriding the CXX and CC executables

* Restore original structure while supporting custom CXX flags

* Remove some platform specific libs

* Dynamic target name

* Make X11 paths package-agnostic

* Remove changes to `gfx_opengl.cpp`

* Use OpenGL2 on MacOS instead of OpenGL3

* make it actually render something

* render at least the first texture, still need to figure out the second
one

* Let’s use OpenGL 3 again

* maybe this works to get the right texture? link's eyes still look off a bit

* did this work?

* set the platform to macos

* actual numbers are right, but logic is ugly XXX/TODO, i know

* add zlib to ldflags for ZAPDUtils

* A bit of cleanup

* Revert unneeded changes

* Remove GL_CHECK

* Fix issues with z64 branch

* use an std::map instead of a giant array

* three point filter fix (#2)

* Fix mac compilation

* fix audio for 64 bit

* revert audio heap size, keep bigger pools

* Add more Apple specific checks to our modifications

* Add building instructions for macOS

* Remove unecessary step from building instructions

* Add missing SDL2 & GLEW to Linux LDLIBS

* Update BUILDING.md

Co-authored-by: BountyChocolate123456 <101743444+BountyChocolate123456@users.noreply.github.com>

* Update soh/.gitignore to include other arch binaries

Co-authored-by: BountyChocolate123456 <101743444+BountyChocolate123456@users.noreply.github.com>

* Use right platform name for debugging window

Co-authored-by: BountyChocolate123456 <101743444+BountyChocolate123456@users.noreply.github.com>

* Fix stormlib on macos (arm64)

* Simplify some of the ifdef checks

* Revert an older no longer necessary fix

* Remove remaining unecessary deviations

* Update building instructions after StormLib changes

* Feature: Use OpenGL 4.1 (#1)

* Further tweak the BUILDING

* Tidy up

* reword -j message

* Add Jenkins CI Support (#2)

* Fix type issues

* add target <appbundle> and <filledappbundle>

add makefile targets to create an .app
`filledappbundle` creates the target with the .otr included

this should perhaps be moved to Application Support though

* pull gcc's rpath from otool output

* move make target to the end so it's not default

* Add Jenkins and make exe in par with other platforms

* Actually save build artefacts

* Fix artefact path

* Remove x11 mentions and linking (not used)

* Update building instructions for generating app

* use appsupport directory

* Add new app icon

* Update target to match macOS types

* Update more audio types

* fix null deref in Audio_PlayFanfare

* Remove old import from z64

* address final nit with apple ifdefs

Co-authored-by: KiritoDev <36680385+KiritoDv@users.noreply.github.com>
Co-authored-by: Jeffrey Crowell <github@crowell.biz>
Co-authored-by: BountyChocolate123456 <101743444+BountyChocolate123456@users.noreply.github.com>
  • Loading branch information
4 people authored Jun 22, 2022
1 parent 77e7080 commit e42b18c
Show file tree
Hide file tree
Showing 32 changed files with 441 additions and 69 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,9 @@ ZAPDUtils/build/
ZAPD/BuildInfo.h

DebugObj/*
ReleaseObj/*
ReleaseObj/*
.tags
tags
oot.otr
oot_save.sav
shipofharkinian.ini
21 changes: 21 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ make setup -j$(nproc) OPTFLAGS=-O2 DEBUG=0
make -j $(nproc) OPTFLAGS=-O2 DEBUG=0
```

## macOS

1. Requires `gcc@12, sdl2, libpng, glew, dylibbundler` (can be installed via brew, etc)
```bash
# Clone the repo
git clone https://github.com/HarbourMasters/Shipwright.git
cd ShipWright
# Copy the baserom to the OTRExporter folder
cp <path to your ROM> 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
# Compile the code (watch the -j parameter as above)
make -j8 DEBUG=0 CC=gcc-12 CXX=g++-12
# Create macOS app bundle
make filledappbundle
```
9. Launch soh app in the soh folder!

# Compatible Roms
```
OOT_PAL_GC checksum 0x09465AC3
Expand Down
34 changes: 34 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,39 @@ pipeline {
}
}
}
stage ('Build macOS') {
agent {
label "SoH-Mac-Builders"
}
steps {
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: scm.extensions,
userRemoteConfigs: scm.userRemoteConfigs
])
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
sh '''
cp ../../ZELOOTD.z64 OTRExporter/baserom_non_mq.z64
cd soh
make setup -j4 DEBUG=0 CC=gcc-12 CXX=g++-12
make -j4 DEBUG=0 CC=gcc-12 CXX=g++-12
make -j4 appbundle
mv ../README.md readme.txt
7z a soh-mac.7z soh.app readme.txt
'''
}
archiveArtifacts artifacts: 'soh/soh-mac.7z', followSymlinks: false, onlyIfSuccessful: true
}
post {
always {
step([$class: 'WsCleanup']) // Clean workspace
}
}
}
}
}
6 changes: 3 additions & 3 deletions OTRExporter/OTRExporter/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Only used for standalone compilation, usually inherits these from the main makefile

CXX := g++
CXX ?= g++
AR := ar
FORMAT := clang-format-11

Expand Down Expand Up @@ -31,7 +31,7 @@ ifneq ($(LTO),0)
CXXFLAGS += -flto
endif

SRC_DIRS := $(shell find -type d -not -path "*build*")
SRC_DIRS := $(shell find . -type d -not -path "*build*")
CXX_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
H_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.h))

Expand Down Expand Up @@ -69,4 +69,4 @@ build/%.o: %.cpp
$(LIB): $(O_FILES)
$(AR) rcs $@ $^

-include $(D_FILES)
-include $(D_FILES)
2 changes: 1 addition & 1 deletion StormLib/src/SFileAddFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static int FillWritableHandle(
pFileEntry->dwFlags = dwFlags | MPQ_FILE_EXISTS;

// Initialize the file time, CRC32 and MD5
assert(sizeof(hf->hctx) >= sizeof(hash_state));
//assert(sizeof(hf->hctx) >= sizeof(hash_state));
memset(pFileEntry->md5, 0, MD5_DIGEST_SIZE);
md5_init((hash_state *)hf->hctx);
pFileEntry->dwCrc32 = crc32(0, Z_NULL, 0);
Expand Down
25 changes: 12 additions & 13 deletions ZAPDTR/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ DEBUG ?= 0
COPYCHECK_ARGS ?=
LLD ?= 0
WERROR ?= 0
UNAME := $(shell uname)

# Use clang++ if available, else use g++
ifeq ($(shell command -v clang++ >/dev/null 2>&1; echo $$?),0)
CXX := clang++
CXX ?= clang++
else
CXX := g++
CXX ?= g++
endif

INC := -I ZAPD -I lib/elfio -I lib/libgfxd -I lib/tinyxml2 -I ZAPDUtils
Expand Down Expand Up @@ -44,8 +45,15 @@ ifneq ($(DEPRECATION_ON),0)
endif
# CXXFLAGS += -DTEXTURE_DEBUG

LDFLAGS := -lm -ldl -lpng \
-L../StormLib/build -L../libultraship -lz -lbz2 -pthread -lpulse -lultraship -lstorm -lSDL2 -lGLEW -lGL -lX11
LDFLAGS := -lm -ldl \
-L../StormLib/build -L../libultraship -lbz2 -pthread -lultraship -lstorm

ifeq ($(UNAME), Darwin)
LDFLAGS += $(shell pkg-config --libs glew libpng zlib) $(shell sdl2-config --libs) -framework OpenGL
INC += $(shell pkg-config --cflags libpng)
else
LDFLAGS += -lpng -lGL -lGLEW -lX11 -lz -lSDL2 -lpulse
endif

# Use LLD if available. Set LLD=0 to not use it
ifeq ($(shell command -v ld.lld >/dev/null 2>&1; echo $$?),0)
Expand All @@ -56,21 +64,12 @@ ifneq ($(LLD),0)
LDFLAGS += -fuse-ld=lld
endif

UNAME := $(shell uname)
UNAMEM := $(shell uname -m)
ifneq ($(UNAME), Darwin)
LDFLAGS += -Wl,-export-dynamic -lstdc++fs
EXPORTERS := -Wl,--whole-archive ../OTRExporter/OTRExporter/OTRExporter.a -Wl,--no-whole-archive
else
EXPORTERS := -Wl,-force_load ../OTRExporter/OTRExporter/OTRExporter.a
ifeq ($(UNAMEM),arm64)
ifeq ($(shell brew list libpng > /dev/null 2>&1; echo $$?),0)
LDFLAGS += -L $(shell brew --prefix)/lib
INC += -I $(shell brew --prefix)/include
else
$(error Please install libpng via Homebrew)
endif
endif
endif


Expand Down
6 changes: 5 additions & 1 deletion ZAPDTR/ZAPD/ZRom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "Utils/Directory.h"
#include "yaz0/yaz0.h"

#ifndef _MSC_VER
#ifdef __linux__
#include <byteswap.h>
#endif
#include <Globals.h>
Expand All @@ -17,6 +17,10 @@ namespace fs = std::filesystem;
#define __bswap_32 _byteswap_ulong
#define bswap_32 _byteswap_ulong
#endif
#if defined __APPLE__
#define __bswap32 __builtin_bswap32
#define bswap32 __builtin_bswap32
#endif

// ROM DMA Table Start
#define OOT_OFF_NTSC_10_RC 0x7430
Expand Down
3 changes: 2 additions & 1 deletion ZAPDTR/ZAPDUtils/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Only used for standalone compilation, usually inherits these from the main makefile
CXX ?= g++
CXXFLAGS ?= -Wall -Wextra -O2 -g -std=c++17

SRC_DIRS := $(shell find -type d -not -path "*build*")
SRC_DIRS := $(shell find . -type d -not -path "*build*")
CPP_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
H_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.h))

Expand Down
1 change: 1 addition & 0 deletions ZAPDTR/lib/libgfxd/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CC ?= gcc
CFLAGS = -Wall -O2 -g
UC_OBJ = uc_f3d.o uc_f3db.o uc_f3dex.o uc_f3dexb.o uc_f3dex2.o
OBJ = gfxd.o $(UC_OBJ)
Expand Down
17 changes: 12 additions & 5 deletions libultraship/Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Only used for standalone compilation, usually inherits these from the main makefile

CXX := g++
CC := gcc
CXX ?= g++
CC ?= gcc
AR := ar
FORMAT := clang-format-11
UNAME := $(shell uname)

ASAN ?= 0
DEBUG ?= 1
Expand All @@ -16,7 +17,8 @@ WARN := -Wall -Wextra -Werror \
-Wno-unused-function \
-Wno-parentheses \
-Wno-narrowing \
-Wno-missing-field-initializers
-Wno-missing-field-initializers \
-Wno-error=multichar

CWARN :=
CXXWARN := -Wno-deprecated-enum-enum-conversion
Expand All @@ -25,6 +27,10 @@ CXXFLAGS := $(WARN) $(CXXWARN) -std=c++20 -D_GNU_SOURCE -DENABLE_OPENGL -DSPDLOG
CFLAGS := $(WARN) $(CWARN) -std=c99 -D_GNU_SOURCE -DENABLE_OPENGL -DSPDLOG_ACTIVE_LEVEL=0
CPPFLAGS := -MMD

ifeq ($(UNAME), Darwin) #APPLE
CPPFLAGS += $(shell pkg-config --cflags sdl2 glew) -framework OpenGL
endif

ifneq ($(DEBUG),0)
CXXFLAGS += -g -D_DEBUG
CFLAGS += -g -D_DEBUG
Expand All @@ -40,7 +46,7 @@ ifneq ($(LTO),0)
CFLAGS += -flto
endif

SRC_DIRS := $(shell find -type d -not -path "*build*")
SRC_DIRS := $(shell find . -type d -not -path "*build*")

CXX_FILES := \
$(shell find libultraship/Factories -name "*.cpp") \
Expand Down Expand Up @@ -71,6 +77,7 @@ INC_DIRS := $(addprefix -I, \
libultraship/Lib/Fast3D/U64 \
libultraship/Lib/spdlog \
libultraship/Lib/spdlog/include \
libultraship/Lib/ImGui \
libultraship \
../StormLib/src \
)
Expand All @@ -97,4 +104,4 @@ build/%.o: %.c
$(LIB): $(O_FILES)
$(AR) rcs $@ $^

-include $(D_FILES)
-include $(D_FILES)
36 changes: 18 additions & 18 deletions libultraship/libultraship/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ namespace Ship

ResourceFile::ParseFileBinary(reader, res);

int seqDataSize = reader->ReadInt32();
uint32_t seqDataSize = reader->ReadInt32();

seq->seqData.reserve(seqDataSize);

for (int i = 0; i < seqDataSize; i++)
for (uint32_t i = 0; i < seqDataSize; i++)
seq->seqData.push_back(reader->ReadUByte());

seq->seqNumber = reader->ReadUByte();
seq->medium = reader->ReadUByte();
seq->cachePolicy = reader->ReadUByte();

int numFonts = reader->ReadInt32();
uint32_t numFonts = reader->ReadInt32();

for (int i = 0; i < numFonts; i++)
for (uint32_t i = 0; i < numFonts; i++)
seq->fonts.push_back(reader->ReadUByte());
}

Expand All @@ -36,26 +36,26 @@ namespace Ship
entry->unk_bit26 = reader->ReadByte();
entry->unk_bit25 = reader->ReadByte();

int dataSize = reader->ReadInt32();
uint32_t dataSize = reader->ReadInt32();

for (int i = 0; i < dataSize; i++)
for (uint32_t i = 0; i < dataSize; i++)
entry->data.push_back(reader->ReadUByte());

entry->loop.start = reader->ReadUInt32();
entry->loop.end = reader->ReadUInt32();
entry->loop.count = reader->ReadUInt32();

int loopStateCnt = reader->ReadUInt32();
uint32_t loopStateCnt = reader->ReadUInt32();

for (int i = 0; i < loopStateCnt; i++)
for (uint32_t i = 0; i < loopStateCnt; i++)
entry->loop.states.push_back(reader->ReadInt16());

entry->book.order = reader->ReadInt32();
entry->book.npredictors = reader->ReadInt32();

int bookSize = reader->ReadInt32();
uint32_t bookSize = reader->ReadInt32();

for (int i = 0; i < bookSize; i++)
for (uint32_t i = 0; i < bookSize; i++)
entry->book.books.push_back(reader->ReadInt16());
}

Expand All @@ -72,11 +72,11 @@ namespace Ship
soundFont->data2 = reader->ReadInt16();
soundFont->data3 = reader->ReadInt16();

int drumCnt = reader->ReadInt32();
int instrumentCnt = reader->ReadInt32();
int sfxCnt = reader->ReadInt32();
uint32_t drumCnt = reader->ReadInt32();
uint32_t instrumentCnt = reader->ReadInt32();
uint32_t sfxCnt = reader->ReadInt32();

for (int i = 0; i < drumCnt; i++)
for (uint32_t i = 0; i < drumCnt; i++)
{
DrumEntry drum;
drum.releaseRate = reader->ReadUByte();
Expand All @@ -92,7 +92,7 @@ namespace Ship
soundFont->drums.push_back(drum);
}

for (int i = 0; i < instrumentCnt; i++)
for (uint32_t i = 0; i < instrumentCnt; i++)
{
InstrumentEntry entry;

Expand Down Expand Up @@ -143,7 +143,7 @@ namespace Ship
soundFont->instruments.push_back(entry);
}

for (int i = 0; i < sfxCnt; i++)
for (uint32_t i = 0; i < sfxCnt; i++)
{
SoundFontEntry* entry = new SoundFontEntry();

Expand All @@ -164,9 +164,9 @@ namespace Ship
{
std::vector<AdsrEnvelope*> envelopes;

int envelopeCnt = reader->ReadInt32();
uint32_t envelopeCnt = reader->ReadInt32();

for (int i = 0; i < envelopeCnt; i++)
for (uint32_t i = 0; i < envelopeCnt; i++)
{
AdsrEnvelope* env = new AdsrEnvelope();
env->delay = reader->ReadInt16();
Expand Down
4 changes: 2 additions & 2 deletions libultraship/libultraship/Audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace Ship

struct AdpcmBook
{
/* 0x00 */ int32_t order;
/* 0x04 */ int32_t npredictors;
/* 0x00 */ uint32_t order;
/* 0x04 */ uint32_t npredictors;
/* 0x08 */ std::vector<int16_t> books; // size 8 * order * npredictors. 8-byte aligned
};

Expand Down
Loading

0 comments on commit e42b18c

Please sign in to comment.