Skip to content

Commit

Permalink
Linux/GCC Support (HarbourMasters#28)
Browse files Browse the repository at this point in the history
* Initial Linux/GCC support commit

* Add instructins for linux in the README

* apply suggestions by @Erotemic and @Emill

* Fix python 3.10 symlink line

* Fix func_80041E80 type mismatch (HarbourMasters#3)

Type mismatch functions.h:664

* Makefile: clean OTRExporter/libultraship/ZAPDTR with distclean and fix CXX_FILES

* Makefile: find C/CXX_FILES automatically

* Makefile: remove ugly conditions in find commands

* cleanup _MSC_VER usage

* fix Windows build

* cleanup extraction scripts

* fix Windows build

* Fix Windows path separator issue

* fix rumble support for linux

* use glew-cmake in dockerfile

* add pulseaudio backend

* fix ZAPDTR linkage

* Check for "soh.elf" in directory (HarbourMasters#6)

hide second button if `soh.exe` or `soh.elf` is present

* Fix hardcoded segment addresses (HarbourMasters#5)

* fix condition

* hack lus -> soh dep for ZAPDTR

Co-authored-by: sholdee <102821812+sholdee@users.noreply.github.com>
Co-authored-by: qurious-pixel <62252937+qurious-pixel@users.noreply.github.com>
Co-authored-by: GaryOderNichts <12049776+GaryOderNichts@users.noreply.github.com>
  • Loading branch information
4 people authored and Kenix3 committed Oct 18, 2022
1 parent 537455a commit dfe5e73
Show file tree
Hide file tree
Showing 44 changed files with 585 additions and 270 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,6 @@ MigrationBackup/
.ionide/

!libultraship/Lib/**
libultraship/DebugObj/*
libultraship/DebugObj/*
build/
libultraship.a
84 changes: 76 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,96 @@
# Only used for standalone compilation, usually inherits these from the main makefile
CXXFLAGS ?= -Wall -Wextra -O2 -g -std=c++17

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

ASAN ?= 0
DEBUG ?= 1
OPTFLAGS ?= -O0
LTO ?= 0

WARN := -Wall -Wextra -Werror \
-Wno-unused-variable \
-Wno-unused-parameter \
-Wno-unused-function \
-Wno-parentheses \
-Wno-narrowing \
-Wno-missing-field-initializers

CXXFLAGS := $(WARN) -std=c++20 -D_GNU_SOURCE -DENABLE_OPENGL -DSPDLOG_ACTIVE_LEVEL=0 -m32
CFLAGS := $(WARN) -std=c99 -D_GNU_SOURCE -DENABLE_OPENGL -DSPDLOG_ACTIVE_LEVEL=0 -m32
CPPFLAGS := -MMD

ifneq ($(DEBUG),0)
CXXFLAGS += -g -D_DEBUG
CFLAGS += -g -D_DEBUG
endif

ifneq ($(ASAN),0)
CXXFLAGS += -fsanitize=address
CFLAGS += -fsanitize=address
endif

ifneq ($(LTO),0)
CXXFLAGS += -flto
CFLAGS += -flto
endif

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))

O_FILES := $(foreach f,$(CPP_FILES:.cpp=.o),build/$f)
LIB := otrlib.a
CXX_FILES := \
$(shell find libultraship/Factories -name *.cpp) \
$(shell find libultraship/Lib/Fast3D -name *.cpp) \
$(shell find libultraship -maxdepth 1 -name *.cpp) \
$(shell find libultraship/Lib/ImGui -maxdepth 1 -name *.cpp) \
libultraship/Lib/ImGui/backends/imgui_impl_opengl3.cpp \
libultraship/Lib/ImGui/backends/imgui_impl_sdl.cpp \
libultraship/Lib/StrHash64.cpp \
libultraship/Lib/tinyxml2/tinyxml2.cpp

C_FILES := \
libultraship/mixer.c \
libultraship/Lib/stb/stb_impl.c

FMT_FILES := $(shell find libultraship/ -type f \( -name *.cpp -o -name *.h \) -a -not -path "libultraship/Lib/*")

O_FILES := \
$(CXX_FILES:%.cpp=build/%.o) \
$(C_FILES:%.c=build/%.o)

D_FILES := $(O_FILES:%.o=%.d)

LIB := libultraship.a

INC_DIRS := $(addprefix -I, \
../ZAPDTR/ZAPDUtils \
libultraship/Lib/Fast3D/U64 \
libultraship/Lib/spdlog \
libultraship/Lib/spdlog/include \
libultraship \
)

# create build directories
$(shell mkdir -p $(foreach dir,$(SRC_DIRS),build/$(dir)))
$(shell mkdir -p $(SRC_DIRS:%=build/%))

all: $(LIB)

clean:
rm -rf build $(LIB)

format:
clang-format-11 -i $(CPP_FILES) $(H_FILES)
$(FORMAT) -i $(FMT_FILES)

.PHONY: all clean format

build/%.o: %.cpp
$(CXX) $(CXXFLAGS) $(OPTFLAGS) -I ./ -I ../ZAPD/ZAPD -I ../ZAPD/ZAPDUtils -I ../../ZAPD/lib/tinyxml2 -I otrlib/Lib/spdlog/include -c $(OUTPUT_OPTION) $<
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPTFLAGS) $(INC_DIRS) -c $< -o $@

build/%.o: %.c
$(CC) $(CFLAGS) $(CPPFLAGS) $(OPTFLAGS) $(INC_DIRS) -c $< -o $@

$(LIB): $(O_FILES)
$(AR) rcs $@ $^

-include $(D_FILES)
2 changes: 1 addition & 1 deletion libultraship/Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void Ship::AnimationV0::ParseFileBinary(BinaryReader* reader, Resource* res)

uint32_t rotIndCnt = reader->ReadUInt32();
anim->rotationIndices.reserve(rotIndCnt);
for (int i = 0; i < rotIndCnt; i++)
for (size_t i = 0; i < rotIndCnt; i++)
{
uint16_t x = reader->ReadUInt16();
uint16_t y = reader->ReadUInt16();
Expand Down
50 changes: 35 additions & 15 deletions libultraship/Archive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <filesystem>

namespace Ship {
Archive::Archive(const std::string& MainPath, bool enableWriting) : Archive(MainPath, "", enableWriting)
Archive::Archive(const std::string& MainPath, bool enableWriting) : Archive(MainPath, "", enableWriting)
{
mainMPQ = nullptr;
}
Expand All @@ -28,7 +28,7 @@ namespace Ship {

std::shared_ptr<Archive> Archive::CreateArchive(const std::string& archivePath, int fileCapacity)
{
Archive* archive = new Archive(archivePath, true);
auto archive = std::make_shared<Archive>(archivePath, true);

TCHAR* t_filename = new TCHAR[archivePath.size() + 1];
t_filename[archivePath.size()] = 0;
Expand All @@ -37,10 +37,15 @@ namespace Ship {
bool success = SFileCreateArchive(t_filename, MPQ_CREATE_LISTFILE | MPQ_CREATE_ATTRIBUTES | MPQ_CREATE_ARCHIVE_V2, fileCapacity, &archive->mainMPQ);
int error = GetLastError();

if (success) {
delete[] t_filename;

if (success)
{
archive->mpqHandles[archivePath] = archive->mainMPQ;
return std::make_shared<Archive>(*archive);
} else {
return archive;
}
else
{
SPDLOG_ERROR("({}) We tried to create an archive, but it has fallen and cannot get up.");
return nullptr;
}
Expand Down Expand Up @@ -139,13 +144,16 @@ namespace Ship {

bool Archive::AddFile(const std::string& path, uintptr_t fileData, DWORD dwFileSize) {
HANDLE hFile;

#ifdef _WIN32
SYSTEMTIME sysTime;
GetSystemTime(&sysTime);
FILETIME t;
SystemTimeToFileTime(&sysTime, &t);
ULONGLONG stupidHack = static_cast<uint64_t>(t.dwHighDateTime) << (sizeof(t.dwHighDateTime) * 8) | t.dwLowDateTime;

#else
time_t stupidHack;
time(&stupidHack);
#endif
if (!SFileCreateFile(mainMPQ, path.c_str(), stupidHack, dwFileSize, 0, MPQ_FILE_COMPRESS, &hFile)) {
SPDLOG_ERROR("({}) Failed to create file of {} bytes {} in archive {}", GetLastError(), dwFileSize, path.c_str(), MainPath.c_str());
return false;
Expand Down Expand Up @@ -181,7 +189,7 @@ namespace Ship {
SPDLOG_ERROR("({}) Failed to remove file {} in archive {}", GetLastError(), path.c_str(), MainPath.c_str());
return false;
}

return true;
}

Expand All @@ -201,7 +209,7 @@ namespace Ship {
SFILE_FIND_DATA findContext;
HANDLE hFind;


hFind = SFileFindFirstFile(mainMPQ, searchMask.c_str(), &findContext, nullptr);
//if (hFind && GetLastError() != ERROR_NO_MORE_FILES) {
if (hFind != nullptr) {
Expand Down Expand Up @@ -245,7 +253,7 @@ namespace Ship {
auto start = std::chrono::steady_clock::now();

auto lst = ListFiles(filename);

for (const auto& item : lst) {
if (item.cFileName == filename) {
result = true;
Expand All @@ -267,7 +275,7 @@ namespace Ship {
return LoadMainMPQ(enableWriting, genCRCMap) && LoadPatchMPQs();
}

bool Archive::Unload()
bool Archive::Unload()
{
bool success = true;
for (const auto& mpqHandle : mpqHandles) {
Expand Down Expand Up @@ -302,11 +310,16 @@ namespace Ship {

bool Archive::LoadMainMPQ(bool enableWriting, bool genCRCMap) {
HANDLE mpqHandle = NULL;
#ifdef _WIN32
std::wstring wfullPath = std::filesystem::absolute(MainPath).wstring();
#endif
std::string fullPath = std::filesystem::absolute(MainPath).string();

std::wstring wFileName = std::filesystem::absolute(MainPath).wstring();

if (!SFileOpenArchive(wFileName.c_str(), 0, enableWriting ? 0 : MPQ_OPEN_READ_ONLY, &mpqHandle)) {
#ifdef _WIN32
if (!SFileOpenArchive(wfullPath.c_str(), 0, enableWriting ? 0 : MPQ_OPEN_READ_ONLY, &mpqHandle)) {
#else
if (!SFileOpenArchive(fullPath.c_str(), 0, enableWriting ? 0 : MPQ_OPEN_READ_ONLY, &mpqHandle)) {
#endif
SPDLOG_ERROR("({}) Failed to open main mpq file {}.", GetLastError(), fullPath.c_str());
return false;
}
Expand Down Expand Up @@ -340,12 +353,19 @@ namespace Ship {

std::wstring wPath = std::filesystem::absolute(path).wstring();

#ifdef _WIN32
if (!SFileOpenArchive(wPath.c_str(), 0, MPQ_OPEN_READ_ONLY, &patchHandle)) {
#else
if (!SFileOpenArchive(fullPath.c_str(), 0, MPQ_OPEN_READ_ONLY, &patchHandle)) {
#endif
SPDLOG_ERROR("({}) Failed to open patch mpq file {} while applying to {}.", GetLastError(), path.c_str(), MainPath.c_str());
return false;
}

#ifdef _WIN32
if (!SFileOpenPatchArchive(mainMPQ, wPath.c_str(), "", 0)) {
#else
if (!SFileOpenPatchArchive(mainMPQ, fullPath.c_str(), "", 0)) {
#endif
SPDLOG_ERROR("({}) Failed to apply patch mpq file {} to main mpq {}.", GetLastError(), path.c_str(), MainPath.c_str());
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions libultraship/Array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ namespace Ship
data.u16 = reader->ReadUInt16();
break;
// OTRTODO: IMPLEMENT OTHER TYPES!
default:
break;
}

arr->scalars.push_back(data);
Expand Down
2 changes: 1 addition & 1 deletion libultraship/ConfigFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ namespace Ship {
bool CreateDefaultConfig();

private:
mINI::INIFile File;
mINI::INIStructure Val;
std::weak_ptr<GlobalCtx2> Context;
std::string Path;
mINI::INIFile File;
};
}
2 changes: 1 addition & 1 deletion libultraship/Cvar.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "cvar.h"
#include "Cvar.h"
#include <map>
#include <string>
#include <PR/ultra64/gbi.h>
Expand Down
71 changes: 0 additions & 71 deletions libultraship/Factories/OTRResourceLoader.cpp

This file was deleted.

3 changes: 2 additions & 1 deletion libultraship/GameSettings.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#include "GameSettings.h"

// Audio
#include <cstddef>
#include <PR/ultra64/types.h>
#include <PR/ultra64/sptask.h>
#include <PR/ultra64/pi.h>
#include <PR/ultra64/message.h>
#include <PR/ultra64/types.h>

#include "ConfigFile.h"
#include "Cvar.h"
Expand Down
6 changes: 5 additions & 1 deletion libultraship/GlobalCtx2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Ship {
}

GlobalCtx2::GlobalCtx2(const std::string& Name) : Name(Name), MainPath(""), PatchesPath("") {

}

GlobalCtx2::~GlobalCtx2() {
Expand All @@ -54,7 +54,11 @@ namespace Ship {

if (!ResMan->DidLoadSuccessfully())
{
#ifdef _WIN32
MessageBox(NULL, L"Main OTR file not found!", L"Uh oh", MB_OK);
#else
SPDLOG_ERROR("Main OTR file not found!");
#endif
exit(1);
}
INSTANCE = new ModManager(ResMan);
Expand Down
Loading

0 comments on commit dfe5e73

Please sign in to comment.