Fixed compilation

This commit is contained in:
KiritoDv 2025-03-07 17:39:58 -06:00 committed by Lywx
parent 629125110d
commit 5f8550790a
6 changed files with 97 additions and 25 deletions

8
.gitignore vendored
View File

@ -119,4 +119,10 @@ imgui.ini
spaghettify.cfg.json
# modding
*.wasm
*.wasm
cmake-build-*/
.idea/
.vs
build*/
.DS_Store

View File

@ -15,12 +15,17 @@ set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15" CACHE STRING "Minimum OS X deployment ve
set(CMAKE_CXX_STANDARD 20 CACHE STRING "The C++ standard to use")
set(CMAKE_C_STANDARD 11 CACHE STRING "The C standard to use")
set_property(DIRECTORY ${CMAKE_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT Spaghettify)
set(PROJECT_TEAM "MegaMech")
set(PROJECT_VERSION_MAJOR 1)
set(PROJECT_VERSION_MINOR 0)
set(PROJECT_VERSION_PATCH 0)
#add_compile_options(-fsanitize=address)
#add_link_options(-fsanitize=address)
# Add a custom module path to locate additional CMake modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
include(FindFontconfig)
set(YAML_CPP_STATIC_DEFINE ON)
add_compile_definitions(YAML_CPP_STATIC_DEFINE)
include(cmake/lus-cvars.cmake)
if (WIN32)
@ -70,6 +75,20 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
endif()
endif()
################################################################################
# Global configuration types
################################################################################
if (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
set(CMAKE_C_FLAGS_DEBUG "-g -ffast-math -DDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-g -ffast-math -DDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-O3 -ffast-math -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -ffast-math -DNDEBUG")
else()
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_OBJCXX_FLAGS_RELEASE "-O2 -DNDEBUG")
endif()
# Set game compilation version
set(VERSION us)
set(USE_NETWORKING ON)
@ -80,7 +99,7 @@ set(GFX_DEBUG_DISASSEMBLER ON)
add_compile_definitions(
VERSION_US=1
ENABLE_RUMBLE=1
# F3DEX_GBI=1
F3DEX_GBI=1
_LANGUAGE_C
_USE_MATH_DEFINES
CIMGUI_DEFINE_ENUMS_AND_STRUCTS
@ -243,7 +262,7 @@ FetchContent_Declare(
FetchContent_MakeAvailable(dr_libs)
#==============================================================================#
# Libultraship Integration #
# Libultraship Integration #
#==============================================================================#
include_directories(
@ -347,8 +366,10 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
"Vorbis::vorbisfile"
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
find_package(SDL2)
set(ADDITIONAL_LIBRARY_DEPENDENCIES
-lglad
SDL2::SDL2
)
elseif(CMAKE_SYSTEM_NAME STREQUAL "CafeOS")
set(ADDITIONAL_LIBRARY_DEPENDENCIES
@ -376,8 +397,12 @@ if(USE_NETWORKING)
endif()
find_package(SDL2_net REQUIRED)
include_directories(${SDL2_NET_INCLUDE_DIRS})
# target_link_libraries(${PROJECT_NAME} PRIVATE SDL2_net::SDL2_net)
# target_compile_definitions(${PROJECT_NAME} PRIVATE USE_NETWORKING)
target_compile_definitions(${PROJECT_NAME} PRIVATE USE_NETWORKING)
if(CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2_net)
else()
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2_net::SDL2_net)
endif()
endif()
option(USE_STANDALONE "Build as a standalone executable" OFF)
@ -408,11 +433,6 @@ endif()
################################################################################
# Compile and link options
################################################################################
set(GBI_UCODE F3DEX_GBI)
target_compile_definitions(${PROJECT_NAME} PRIVATE F3DEX_GBI=1)
if(MSVC)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
target_compile_options(${PROJECT_NAME} PRIVATE
@ -603,6 +623,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
endif()
endif()
if(NOT CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch")
include(ExternalProject)
ExternalProject_Add(TorchExternal
PREFIX TorchExternal
@ -616,7 +637,6 @@ if (MSVC)
else()
set(TORCH_EXECUTABLE ${install_dir}/src/TorchExternal-build/torch)
endif()
message(STATUS "Torch executable path: ${TORCH_EXECUTABLE}")
add_custom_target(
ExtractAssets
@ -661,6 +681,7 @@ endif()
set_property(TARGET ${PROJECT_NAME} PROPERTY APPIMAGE_DESKTOP_FILE_TERMINAL YES)
set_property(TARGET ${PROJECT_NAME} PROPERTY APPIMAGE_DESKTOP_FILE "${CMAKE_SOURCE_DIR}/SpaghettiKart.desktop")
set_property(TARGET ${PROJECT_NAME} PROPERTY APPIMAGE_ICON_FILE "${CMAKE_SOURCE_DIR}/logo.png")
endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
set(CPACK_GENERATOR "External")
@ -671,4 +692,4 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
endif()
set(CPACK_PROJECT_CONFIG_FILE ${CMAKE_SOURCE_DIR}/cmake/configure-packaging.cmake)
include(cmake/packaging.cmake)
include(cmake/packaging.cmake)

View File

@ -29,6 +29,10 @@
#include <utility>
#ifdef __SWITCH__
#include <port/switch/SwitchImpl.h>
#endif
extern "C" {
bool prevAltAssets = false;
float gInterpolationStep = 0.0f;
@ -46,6 +50,10 @@ float gInterpolationStep = 0.0f;
GameEngine* GameEngine::Instance;
GameEngine::GameEngine() {
#ifdef __SWITCH__
Ship::Switch::Init(Ship::PreInitPhase);
Ship::Switch::Init(Ship::PostInitPhase);
#endif
std::vector<std::string> archiveFiles;
const std::string main_path = Ship::Context::GetPathRelativeToAppDirectory("spaghetti.o2r");
@ -102,10 +110,11 @@ GameEngine::GameEngine() {
this->context->Init(archiveFiles, {}, 3, { 26800, 512, 1100 }, wnd, controlDeck);
// this->context = Ship::Context::CreateInstance("Spaghettify", "skart64", "spaghettify.cfg.json", OTRFiles, {}, 3,
// { 26800, 512, 1100 });
#ifndef __SWITCH__
Ship::Context::GetInstance()->GetLogger()->set_level(
(spdlog::level::level_enum) CVarGetInteger("gDeveloperTools.LogLevel", 1));
Ship::Context::GetInstance()->GetLogger()->set_pattern("[%H:%M:%S.%e] [%s:%#] [%l] %v");
#endif
wnd->SetRendererUCode(ucode_f3dex);
this->context->InitGfxDebugger();
@ -193,18 +202,21 @@ bool GameEngine::GenAssetFile() {
}
void GameEngine::ShowMessage(const char* title, const char* message, SDL_MessageBoxFlags type) {
#if defined(__SWITCH__)
SPDLOG_ERROR(message);
#else
SDL_ShowSimpleMessageBox(type, title, message, nullptr);
SPDLOG_ERROR(message);
#endif
#if defined(__SWITCH__)
SPDLOG_ERROR(message);
#else
SDL_ShowSimpleMessageBox(type, title, message, nullptr);
SPDLOG_ERROR(message);
#endif
}
int GameEngine::ShowYesNoBox(const char* title, const char* box) {
int ret;
#ifdef _WIN32
ret = MessageBoxA(nullptr, box, title, MB_YESNO | MB_ICONQUESTION);
#elif defined(__SWITCH__)
SPDLOG_ERROR(box);
return IDYES;
#else
SDL_MessageBoxData boxData = { 0 };
SDL_MessageBoxButtonData buttons[2] = { { 0 } };
@ -236,6 +248,9 @@ void GameEngine::Create() {
void GameEngine::Destroy() {
AudioExit();
#ifdef __SWITCH__
Ship::Switch::Exit();
#endif
}
bool ShouldClearTextureCacheAtEndOfFrame = false;

View File

@ -5,15 +5,18 @@
#include "Context.h"
#include "spdlog/spdlog.h"
#include "portable-file-dialogs.h"
#include <port/Engine.h>
#if !defined(__IOS__) && !defined(__ANDROID__) && !defined(__SWITCH__)
#include "portable-file-dialogs.h"
#endif
std::unordered_map<std::string, std::string> mGameList = {
{ "579c48e211ae952530ffc8738709f078d5dd215e", "Mario Kart 64 (US)" },
};
bool GameExtractor::SelectGameFromUI() {
#if !defined(__IOS__) || !defined(__ANDROID__) || !defined(__SWITCH__)
#if !defined(__IOS__) && !defined(__ANDROID__) && !defined(__SWITCH__)
auto selection = pfd::open_file("Select a file", ".", { "N64 Roms", "*.z64" }).result();
if (selection.empty()) {

View File

@ -10,6 +10,10 @@
#include <tuple>
#include "ResolutionEditor.h"
#ifdef __SWITCH__
#include <port/switch/SwitchImpl.h>
#endif
extern "C" {
extern s32 gGamestateNext;
extern s32 gMenuSelection;
@ -362,10 +366,31 @@ void PortMenu::AddEnhancements() {
.Tooltip("When Disable Wall Collision are enable what is the minimal height you can get."));
}
#ifdef __SWITCH__
static const std::unordered_map<int32_t, const char*> switchCPUProfiles = {
{ Ship::SwitchProfiles::MAXIMUM, "Maximum Performance" },
{ Ship::SwitchProfiles::HIGH, "High Performance" },
{ Ship::SwitchProfiles::BOOST, "Boost Performance" },
{ Ship::SwitchProfiles::STOCK, "Stock Performance" },
{ Ship::SwitchProfiles::POWERSAVINGM1, "Powersaving Mode 1" },
{ Ship::SwitchProfiles::POWERSAVINGM2, "Powersaving Mode 2" },
{ Ship::SwitchProfiles::POWERSAVINGM3, "Powersaving Mode 3" }
};
#endif
void PortMenu::AddDevTools() {
AddMenuEntry("Developer", "gSettings.Menu.DevToolsSidebarSection");
AddSidebarEntry("Developer", "General", 3);
WidgetPath path = { "Developer", "General", SECTION_COLUMN_1 };
#ifdef __SWITCH__
AddWidget(path, "Switch CPU Profile", WIDGET_CVAR_COMBOBOX)
.CVar("gSwitchPerfMode")
.Options(ComboboxOptions()
.Tooltip("Switches the CPU profile to a different one")
.ComboMap(switchCPUProfiles)
.DefaultIndex(Ship::SwitchProfiles::STOCK))
.Callback([](WidgetInfo& info) { Ship::Switch::ApplyOverclock(); });
#endif
AddWidget(path, "Popout Menu", WIDGET_CVAR_CHECKBOX)
.CVar("gSettings.Menu.Popout")
.Options(CheckboxOptions().Tooltip("Changes the menu display from overlay to windowed."));

View File

@ -96,8 +96,10 @@ s32 osPfsAllocateFile(OSPfs* pfs, u16 company_code, u32 game_code, u8* game_name
return PFS_NO_ERROR;
}
#ifndef __SWITCH__
void osSetTime(OSTime time) {
}
#endif
s32 osPfsIsPlug(OSMesgQueue* queue, u8* pattern) {
}