diff --git a/CMakeLists.txt b/CMakeLists.txt index 69b1f778..7ac0e9ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -261,6 +261,72 @@ include_directories( ${GLEW_INCLUDE_DIRS} ) +if (CMAKE_SYSTEM_NAME STREQUAL "Windows") + if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + target_compile_definitions(${PROJECT_NAME} PRIVATE + "$<$:" + "_DEBUG;" + "_CRT_SECURE_NO_WARNINGS;" + "ENABLE_DX11;" + ">" + "$<$:" + "NDEBUG" + ">" + "INCLUDE_GAME_PRINTF;" + "UNICODE;" + "_UNICODE" + STORMLIB_NO_AUTO_LINK + "_CRT_SECURE_NO_WARNINGS;" + ) + elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") + target_compile_definitions(${PROJECT_NAME} PRIVATE + "$<$:" + "NOINCLUDE_GAME_PRINTF;" + "_DEBUG;" + "_CRT_SECURE_NO_WARNINGS;" + "ENABLE_OPENGL" + ">" + "$<$:" + "NDEBUG;" + ">" + "INCLUDE_GAME_PRINTF;" + "WIN32;" + "UNICODE;" + "_UNICODE" + STORMLIB_NO_AUTO_LINK + ) + endif() +elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") + target_compile_definitions(${PROJECT_NAME} PRIVATE + "$<$:" + "_DEBUG" + ">" + "$<$:" + "NDEBUG" + ">" + "SPDLOG_ACTIVE_LEVEL=3;" + "SPDLOG_NO_THREAD_ID;" + "SPDLOG_NO_TLS;" + "STBI_NO_THREAD_LOCALS;" + ) +elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU|Clang|AppleClang") + target_compile_definitions(${PROJECT_NAME} PRIVATE + "$<$:" + "_DEBUG" + ">" + "$<$:" + "NDEBUG" + ">" + "$<$:ENABLE_CROWD_CONTROL>" + "SPDLOG_ACTIVE_LEVEL=0;" + "_CONSOLE;" + "_CRT_SECURE_NO_WARNINGS;" + "ENABLE_OPENGL;" + "UNICODE;" + "_UNICODE" + ) +endif() + add_subdirectory(libultraship ${CMAKE_CURRENT_SOURCE_DIR}/libultraship) add_dependencies(${PROJECT_NAME} libultraship) @@ -271,6 +337,183 @@ if(APPLE) target_link_libraries(${PROJECT_NAME} PRIVATE SDL2::SDL2) endif() +################################################################################ +# Compile and link options +################################################################################ +if(MSVC) + if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + target_compile_options(${PROJECT_NAME} PRIVATE + $<$: + /w; + /Od + > + $<$: + /Oi; + /Gy; + /W3 + > + /sdl-; + /permissive-; + /MP; + ${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT}; + ${DEFAULT_CXX_EXCEPTION_HANDLING} + ) + target_compile_options(${PROJECT_NAME} PRIVATE $<$:/ZI;>) + elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") + target_compile_options(${PROJECT_NAME} PRIVATE + $<$: + /RTCs + > + $<$: + /O2; + /Oi; + /Gy + > + /permissive-; + /MP; + /sdl-; + /w; + ${DEFAULT_CXX_DEBUG_INFORMATION_FORMAT}; + ${DEFAULT_CXX_EXCEPTION_HANDLING} + ) + endif() + if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64") + target_link_options(${PROJECT_NAME} PRIVATE + $<$: + /INCREMENTAL + > + $<$: + /OPT:REF; + /OPT:ICF; + /INCREMENTAL:NO; + /FORCE:MULTIPLE + > + /MANIFEST:NO; + /DEBUG; + /SUBSYSTEM:WINDOWS + ) + elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32") + target_link_options(${PROJECT_NAME} PRIVATE + $<$: + /STACK:8777216 + > + $<$: + /OPT:REF; + /OPT:ICF; + /INCREMENTAL:NO; + /FORCE:MULTIPLE + > + /MANIFEST:NO; + /DEBUG; + /SUBSYSTEM:WINDOWS + ) + endif() +endif() + +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang") + if (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + target_compile_options(${PROJECT_NAME} PRIVATE + -Wall -Wextra -Wno-error + -Wno-return-type + -Wno-unused-parameter + -Wno-unused-function + -Wno-unused-variable + -Wno-missing-field-initializers + -Wno-parentheses + -Wno-narrowing + -Wno-missing-braces + $<$: + -Werror-implicit-function-declaration + -Wno-incompatible-pointer-types + > + $<$:-fpermissive> + $<$: + -Wno-c++11-narrowing + -Wno-deprecated-enum-enum-conversion + > + -pthread + ) + + target_link_options(${PROJECT_NAME} PRIVATE + -pthread + ) + elseif (CMAKE_SYSTEM_NAME STREQUAL "NintendoSwitch") + target_compile_options(${PROJECT_NAME} PRIVATE + -Wall -Wextra -Wno-error + -Wno-return-type + -Wno-unused-parameter + -Wno-unused-function + -Wno-unused-variable + -Wno-missing-field-initializers + -Wno-parentheses + -Wno-narrowing + -Wno-missing-braces + $<$: + -Werror-implicit-function-declaration + -Wno-incompatible-pointer-types + > + $<$:-fpermissive> + $<$: + -Wno-c++11-narrowing + -Wno-deprecated-enum-enum-conversion + > + -pthread + ) + + target_link_options(${PROJECT_NAME} PRIVATE + -pthread + ) + elseif (CMAKE_SYSTEM_NAME STREQUAL "CafeOS") + target_compile_options(${PROJECT_NAME} PRIVATE + -O2 + + # disable some warnings to not clutter output + -Wno-multichar + -Wno-return-type + -Wno-narrowing + -Wno-switch-outside-range + $<$: + -Werror-implicit-function-declaration + -Wno-incompatible-pointer-types + -Wno-discarded-array-qualifiers + -Wno-discarded-qualifiers + -Wno-int-conversion + -Wno-builtin-declaration-mismatch + -Wno-switch-unreachable + -Wno-stringop-overflow + > + ) + else() + if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") + set(CPU_OPTION -msse2 -mfpmath=sse) + endif() + + target_compile_options(${PROJECT_NAME} PRIVATE + -Wall -Wextra -Wno-error + -Wno-unused-parameter + -Wno-unused-function + -Wno-unused-variable + -Wno-missing-field-initializers + -Wno-parentheses + -Wno-narrowing + -Wno-missing-braces + $<$: + -Werror-implicit-function-declaration + -Wno-incompatible-pointer-types + > + $<$:-fpermissive> + $<$:-Wno-deprecated-enum-enum-conversion> + -pthread + ${CPU_OPTION} + ) + + target_link_options(${PROJECT_NAME} PRIVATE + -pthread + -Wl,-export-dynamic + ) + endif() +endif() + #==============================================================================# # Sound File Generation # #==============================================================================# diff --git a/include/platform_info.h b/include/platform_info.h index 3222bc7a..d7b6de63 100644 --- a/include/platform_info.h +++ b/include/platform_info.h @@ -3,8 +3,9 @@ #include #define IS_64_BIT (UINTPTR_MAX == 0xFFFFFFFFFFFFFFFFU) -#define IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) - +#if (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)) || defined(__BIG_ENDIAN__) +#define IS_BIG_ENDIAN +#endif #define DOUBLE_SIZE_ON_64_BIT(size) ((size) * (sizeof(void *) / 4)) #endif // PLATFORM_INFO_H diff --git a/include/sm64.h b/include/sm64.h index ce451edc..da808907 100644 --- a/include/sm64.h +++ b/include/sm64.h @@ -18,6 +18,11 @@ #include #include +#ifdef _WIN32 +#define bzero(b,len) (memset((b), '\0', (len)), (void) 0) +#define bcopy(b1, b2, len) (memmove((b2), (b1), (len)), (void) 0) +#endif + // Crash handler enhancement #ifdef CRASH_SCREEN_INCLUDED #define DEBUG_ASSERT(exp) do { if (!(exp)) _n64_assert(__FILE__, __LINE__, #exp, 1); } while (0) diff --git a/src/audio/internal.h b/src/audio/internal.h index ef7d63d4..2dd2f54b 100644 --- a/src/audio/internal.h +++ b/src/audio/internal.h @@ -93,7 +93,8 @@ #endif #ifdef _WIN32 -typedef size_t ssize_t; +#include +typedef SSIZE_T ssize_t; #endif struct NotePool; diff --git a/src/engine/math_util.c b/src/engine/math_util.c index 1598f97a..a14f3ad2 100644 --- a/src/engine/math_util.c +++ b/src/engine/math_util.c @@ -734,12 +734,14 @@ s16 atan2s(f32 y, f32 x) { return ret; } +#ifndef _WIN32 /** * Compute the atan2 in radians by calling atan2s and converting the result. */ f32 atan2f(f32 y, f32 x) { return (f32) atan2s(y, x) * M_PI / 0x8000; } +#endif #define CURVE_BEGIN_1 1 #define CURVE_BEGIN_2 2 diff --git a/src/game/game_init.c b/src/game/game_init.c index 1224ef2c..a90cf0ff 100644 --- a/src/game/game_init.c +++ b/src/game/game_init.c @@ -624,9 +624,9 @@ void setup_game_memory(void) { * Main game loop thread. Runs forever as long as the game continues. */ -struct LevelCommand *addr; +static struct LevelCommand *addr; -void thread5_game_loop() { +void thread5_game_loop(void) { setup_game_memory(); #if ENABLE_RUMBLE diff --git a/src/game/game_init.h b/src/game/game_init.h index f954fe68..0c1af35f 100644 --- a/src/game/game_init.h +++ b/src/game/game_init.h @@ -50,7 +50,7 @@ extern u16 sRenderingFramebuffer; extern u32 gGlobalTimer; void setup_game_memory(void); -void thread5_game_loop(); +void thread5_game_loop(void); void clear_framebuffer(s32 color); void clear_viewport(Vp *viewport, s32 color); void make_viewport_clip_rect(Vp *viewport); diff --git a/src/port/Game.cpp b/src/port/Game.cpp index 155b54bd..d732746c 100644 --- a/src/port/Game.cpp +++ b/src/port/Game.cpp @@ -8,7 +8,7 @@ extern "C" { #include "game/game_init.h" } -bool sAudioEnabled = false; +bool sAudioEnabled = true; void alloc_pool() { static u64 pool[1024 * 1024 * 4]; @@ -38,7 +38,11 @@ void push_frame() { } } +#ifdef _WIN32 +int SDL_main(int argc, char **argv) { +#else int main(){ +#endif GameEngine::Create(); alloc_pool(); audio_init(); diff --git a/src/port/Variables.cpp b/src/port/Variables.cpp index 98bc69f3..ffce12a3 100644 --- a/src/port/Variables.cpp +++ b/src/port/Variables.cpp @@ -15,7 +15,7 @@ u64 osClockRate = 62500000; s8 gShowProfiler = FALSE; s8 gShowDebugText = FALSE; -s8 gDebugLevelSelect = TRUE; +s8 gDebugLevelSelect = FALSE; OSIoMesg gDmaIoMesg; OSMesg gMainReceivedMesg;