From b57ccd7ed510a2141c93f4ae73c77145946c9786 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 31 Mar 2020 20:22:54 +0100 Subject: [PATCH 1/8] Shut up errors on Windows --- src/Backends/Audio/SDL2.cpp | 3 +++ src/Backends/Audio/miniaudio.cpp | 2 ++ src/WindowsWrapper.h | 5 +++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Backends/Audio/SDL2.cpp b/src/Backends/Audio/SDL2.cpp index bbe2dcb3..e03e3069 100644 --- a/src/Backends/Audio/SDL2.cpp +++ b/src/Backends/Audio/SDL2.cpp @@ -1,5 +1,8 @@ #include "../Audio.h" +#include +#include + #include "SDL.h" #include "../../Organya.h" diff --git a/src/Backends/Audio/miniaudio.cpp b/src/Backends/Audio/miniaudio.cpp index 84849a32..ec685da2 100644 --- a/src/Backends/Audio/miniaudio.cpp +++ b/src/Backends/Audio/miniaudio.cpp @@ -1,5 +1,7 @@ #include "../Audio.h" +#include + #define MINIAUDIO_IMPLEMENTATION #define MA_NO_DECODING #define MA_API static diff --git a/src/WindowsWrapper.h b/src/WindowsWrapper.h index abfeca05..58eda2c1 100644 --- a/src/WindowsWrapper.h +++ b/src/WindowsWrapper.h @@ -1,8 +1,9 @@ #pragma once #ifdef _WIN32 -#include -#include +#define WIN32_LEAN_AND_MEAN +#include +#undef FindResource #else #include From 6be5aac70d20bbd752a310b1dc14f44715c3a3f7 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Tue, 31 Mar 2020 20:25:15 +0100 Subject: [PATCH 2/8] Prevent error if Resource table is empty --- src/Resource.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Resource.cpp b/src/Resource.cpp index 3e2ac9a9..3aba8a16 100644 --- a/src/Resource.cpp +++ b/src/Resource.cpp @@ -152,6 +152,7 @@ static const struct {"ORG", "ZONBIE", rZonbie, sizeof(rZonbie)}, {"WAVE", "WAVE100", rWave, sizeof(rWave)}, + {"DUMMY", "DUMMY", NULL, 0} // Just here to prevent errors in the event the array is otherwise empty }; const unsigned char* FindResource(const char *name, const char *type, size_t *size) From 10af7b95f22e006a42fce6734294f59b41ad1db4 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 1 Apr 2020 14:12:17 +0100 Subject: [PATCH 3/8] Update readme with deprecation notices and cleanup --- README.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 13a8e705..a4a1b031 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ Branch | Description [accurate](https://www.github.com/Clownacy/Cave-Story-Engine-2/tree/accurate) | The main decompilation branch. The code intended to be as close to the original as possible, down to all the bugs and platform-dependencies. [portable](https://www.github.com/Clownacy/Cave-Story-Engine-2/tree/portable) | This branch ports the engine to SDL2, and addresses numerous portability issues, allowing it to run on other platforms. [enhanced](https://www.github.com/Clownacy/Cave-Story-Engine-2/tree/enhanced) | Based on the portable branch, this adds several enhancements to the engine, and makes it more accessible to modders. -[emscripten](https://www.github.com/Clownacy/Cave-Story-Engine-2/tree/emscripten) | Modifies the engine to build with Emscripten, [allowing it to run in web browsers](http://sonicresearch.org/clownacy/cave.html). -[wii](https://www.github.com/Clownacy/Cave-Story-Engine-2/tree/wii) | Ports the engine to the Nintendo Wii. +[emscripten](https://www.github.com/Clownacy/Cave-Story-Engine-2/tree/emscripten) | Modifies the engine to build with Emscripten, [allowing it to run in web browsers](http://sonicresearch.org/clownacy/cave.html) (no longer maintained). +[wii](https://www.github.com/Clownacy/Cave-Story-Engine-2/tree/wii) | Ports the engine to the Nintendo Wii (no longer maintained). # Cave Story Engine 2 @@ -42,18 +42,20 @@ Of course, project files for Visual Studio .NET 2003 are available, and can be f As proven by the original `Doukutsu.exe`'s [Rich Header](http://bytepointer.com/articles/the_microsoft_rich_header.htm), Pixel used Visual Studio .NET 2003 to create Cave Story. This means these project files allow us to check the accuracy of the decompilation by comparing the generated assembly code to that of the original executable. The tool for this can be found in the 'devilution' folder. -### Visual Studio 2017 (and later) +### Visual Studio 2017 (and later) \[deprecated - use CMake instead\] Project files for Visual Studio 2017 can be found in the 'vs2017' folder. ### CMake (Visual Studio & MinGW-w64) -In this folder, create another folder called 'build', then switch to the command-line (Visual Studio users should open the [Developer Command Prompt](https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs)) and `cd` into it. After that, generate the files for your build system with: +Switch to the terminal (Visual Studio users should open the [Developer Command Prompt](https://docs.microsoft.com/en-us/dotnet/framework/tools/developer-command-prompt-for-vs)) and `cd` into this folder. After that, generate the files for your build system with: ``` -cmake .. -DCMAKE_BUILD_TYPE=Release +cmake -B build -DCMAKE_BUILD_TYPE=Release ``` +MSYS2 users may want to append `-G"MSYS Makefiles"` to this command, also. + You can also add the following flags: Name | Function @@ -62,21 +64,21 @@ Name | Function `-DFIX_BUGS=ON` | Fix various bugs in the game `-DDEBUG_SAVE=ON` | Re-enable the dummied-out 'Debug Save' option, and the ability to drag-and-drop save files onto the window `-DLTO=ON` | Enable link-time optimisation -`-DMSVC_LINK_STATIC_RUNTIME=ON` | Link the static MSVC runtime library +`-DMSVC_LINK_STATIC_RUNTIME=ON` | Link the static MSVC runtime library (Visual Studio only) You can pass your own compiler flags with `-DCMAKE_C_FLAGS` and `-DCMAKE_CXX_FLAGS`. You can then compile CSE2 with this command: ``` -cmake --build . --config Release +cmake --build build --config Release ``` -If you're a Visual Studio user, you can open the generated `CSE2.sln` file instead. +If you're a Visual Studio user, you can open the generated `CSE2.sln` file instead, which can be found in the `build` folder. Once built, the executable can be found in the `game_english`/`game_japanese` folder, depending on the selected language. -### Makefile (MinGW-w64) +### Makefile (MinGW-w64) \[deprecated - use CMake instead\] Run 'make' in this folder, preferably with some of the following settings: @@ -94,4 +96,4 @@ Once built, the executable can be found in the `game_english`/`game_japanese` fo ## Licensing -Being a decompilation, the majority of the code in this project belongs to Daisuke "Pixel" Amaya - not us. We've yet to agree on a license for our own code. +Being a decompilation, the majority of the code in this project belongs to Daisuke "Pixel" Amaya - not us. We've yet to agree on a licence for our own code. From ca5b0928075a22693d6bf07e7a5dbab41e3ca286 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 1 Apr 2020 20:14:44 +0100 Subject: [PATCH 4/8] Add static-linkage support to CMake file Well, kind of. It uses pkg-config and GCC's `-static' flag. It's very tied the Linux way of doing things. --- CMakeLists.txt | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dbeb2665..5337ff22 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,8 +18,9 @@ option(DEBUG_SAVE "Re-enable the ability to drag-and-drop save files onto the wi set(BACKEND_RENDERER "SDLTexture" CACHE STRING "Which renderer the game should use: 'OpenGL3' for an OpenGL 3.2 renderer, 'OpenGLES2' for an OpenGL ES 2.0 renderer, 'SDLTexture' for SDL2's hardware-accelerated Texture API, 'SDLSurface' for SDL2's software-rendered Surface API, or 'Software' for a handwritten software renderer") set(BACKEND_AUDIO "SDL2" CACHE STRING "Which audio backend the game should use: 'SDL2' or 'miniaudio'") +option(STATIC_LINKAGE "On platforms with pkg-config, static-link the dependencies" OFF) option(LTO "Enable link-time optimisation" OFF) -option(MSVC_LINK_STATIC_RUNTIME "Link the static MSVC runtime library" OFF) +option(MSVC_LINK_STATIC_RUNTIME "Link the static MSVC runtime library (Visual Studio only)" OFF) option(FORCE_LOCAL_LIBS "Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones" OFF) @@ -258,6 +259,10 @@ if(DEBUG_SAVE) target_compile_definitions(CSE2 PRIVATE DEBUG_SAVE) endif() +if(STATIC_LINKAGE) + target_link_options(CSE2 PRIVATE "-static") +endif() + if(LTO) include(CheckIPOSupported) @@ -372,10 +377,29 @@ set_target_properties(CSE2 PROPERTIES ################ if(NOT FORCE_LOCAL_LIBS) - find_package(SDL2) + find_package(PkgConfig QUIET) endif() -if(TARGET SDL2::SDL2) +if(NOT FORCE_LOCAL_LIBS) + find_package(SDL2) + + if (PKG_CONFIG_FOUND) + pkg_check_modules(sdl2 QUIET sdl2) + endif() +endif() + +if(sdl2_FOUND) + # pkg-config + if (STATIC_LINKAGE) + message(STATUS "Using system SDL2 (pkg-config, static)") + target_compile_options(CSE2 PRIVATE ${sdl2_STATIC_CFLAGS}) + target_link_libraries(CSE2 PRIVATE ${sdl2_STATIC_LIBRARIES}) + else() + message(STATUS "Using system SDL2 (pkg-config, dynamic)") + target_compile_options(CSE2 PRIVATE ${sdl2_CFLAGS}) + target_link_libraries(CSE2 PRIVATE ${sdl2_LIBRARIES}) + endif() +elseif(TARGET SDL2::SDL2) # CMake-generated config (Arch, vcpkg, Raspbian) message(STATUS "Using system SDL2 (CMake, dynamic)") target_link_libraries(CSE2 PRIVATE SDL2::SDL2 SDL2::SDL2main) @@ -401,10 +425,25 @@ endif() if(NOT FORCE_LOCAL_LIBS) find_package(Freetype) + + if (PKG_CONFIG_FOUND) + pkg_check_modules(freetype2 QUIET freetype2) + endif() endif() -if(FREETYPE_FOUND) - message(STATUS "Using system FreeType") +if(freetype2_FOUND) + # pkg-config + if (STATIC_LINKAGE) + message(STATUS "Using system FreeType (pkg-config, static)") + target_compile_options(CSE2 PRIVATE ${freetype2_STATIC_CFLAGS}) + target_link_libraries(CSE2 PRIVATE ${freetype2_STATIC_LIBRARIES}) + else() + message(STATUS "Using system FreeType (pkg-config, dynamic)") + target_compile_options(CSE2 PRIVATE ${freetype2_CFLAGS}) + target_link_libraries(CSE2 PRIVATE ${freetype2_LIBRARIES}) + endif() +elseif(FREETYPE_FOUND) + message(STATUS "Using system FreeType (CMake)") target_include_directories(CSE2 PRIVATE ${FREETYPE_INCLUDE_DIRS}) target_link_libraries(CSE2 PRIVATE ${FREETYPE_LIBRARIES}) else() From 883e994949446390b93b7d9fbfc142c6f6d101ba Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 1 Apr 2020 20:17:16 +0100 Subject: [PATCH 5/8] Rename to PKG_CONFIG_STATIC_LIBS --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5337ff22..58ea5117 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ option(DEBUG_SAVE "Re-enable the ability to drag-and-drop save files onto the wi set(BACKEND_RENDERER "SDLTexture" CACHE STRING "Which renderer the game should use: 'OpenGL3' for an OpenGL 3.2 renderer, 'OpenGLES2' for an OpenGL ES 2.0 renderer, 'SDLTexture' for SDL2's hardware-accelerated Texture API, 'SDLSurface' for SDL2's software-rendered Surface API, or 'Software' for a handwritten software renderer") set(BACKEND_AUDIO "SDL2" CACHE STRING "Which audio backend the game should use: 'SDL2' or 'miniaudio'") -option(STATIC_LINKAGE "On platforms with pkg-config, static-link the dependencies" OFF) +option(PKG_CONFIG_STATIC_LIBS "On platforms with pkg-config, static-link the dependencies" OFF) option(LTO "Enable link-time optimisation" OFF) option(MSVC_LINK_STATIC_RUNTIME "Link the static MSVC runtime library (Visual Studio only)" OFF) @@ -259,7 +259,7 @@ if(DEBUG_SAVE) target_compile_definitions(CSE2 PRIVATE DEBUG_SAVE) endif() -if(STATIC_LINKAGE) +if(PKG_CONFIG_STATIC_LIBS) target_link_options(CSE2 PRIVATE "-static") endif() @@ -390,7 +390,7 @@ endif() if(sdl2_FOUND) # pkg-config - if (STATIC_LINKAGE) + if (PKG_CONFIG_STATIC_LIBS) message(STATUS "Using system SDL2 (pkg-config, static)") target_compile_options(CSE2 PRIVATE ${sdl2_STATIC_CFLAGS}) target_link_libraries(CSE2 PRIVATE ${sdl2_STATIC_LIBRARIES}) @@ -433,7 +433,7 @@ endif() if(freetype2_FOUND) # pkg-config - if (STATIC_LINKAGE) + if (PKG_CONFIG_STATIC_LIBS) message(STATUS "Using system FreeType (pkg-config, static)") target_compile_options(CSE2 PRIVATE ${freetype2_STATIC_CFLAGS}) target_link_libraries(CSE2 PRIVATE ${freetype2_STATIC_LIBRARIES}) From a008410b96ab63a2e271d3d69bf38fc2c21ed698 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 1 Apr 2020 20:19:24 +0100 Subject: [PATCH 6/8] List it in the readme --- CMakeLists.txt | 2 +- README.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 58ea5117..b86db83e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ option(DEBUG_SAVE "Re-enable the ability to drag-and-drop save files onto the wi set(BACKEND_RENDERER "SDLTexture" CACHE STRING "Which renderer the game should use: 'OpenGL3' for an OpenGL 3.2 renderer, 'OpenGLES2' for an OpenGL ES 2.0 renderer, 'SDLTexture' for SDL2's hardware-accelerated Texture API, 'SDLSurface' for SDL2's software-rendered Surface API, or 'Software' for a handwritten software renderer") set(BACKEND_AUDIO "SDL2" CACHE STRING "Which audio backend the game should use: 'SDL2' or 'miniaudio'") -option(PKG_CONFIG_STATIC_LIBS "On platforms with pkg-config, static-link the dependencies" OFF) +option(PKG_CONFIG_STATIC_LIBS "On platforms with pkg-config, static-link the dependencies (good for Windows builds, so you don't need to bundle DLL files)" OFF) option(LTO "Enable link-time optimisation" OFF) option(MSVC_LINK_STATIC_RUNTIME "Link the static MSVC runtime library (Visual Studio only)" OFF) diff --git a/README.md b/README.md index 4257e355..ab498814 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ Name | Function `-DBACKEND_AUDIO=SDL2` | Use the SDL2-driven software audio-mixer `-DBACKEND_AUDIO=miniaudio` | Use the miniaudio-driven software audio-mixer `-DLTO=ON` | Enable link-time optimisation +`-DPKG_CONFIG_STATIC_LIBS=ON` | On platforms with pkg-config, static-link the dependencies (good for Windows builds, so you don't need to bundle DLL files) `-DMSVC_LINK_STATIC_RUNTIME=ON` | Link the static MSVC runtime library `-DFORCE_LOCAL_LIBS=ON` | Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones From 03fab974fc3804011adaba7367b28d8f028df0d6 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 1 Apr 2020 20:20:04 +0100 Subject: [PATCH 7/8] Tweaks --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b86db83e..b2d08cf4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,11 +15,12 @@ set(ASSETS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/assets") option(JAPANESE "Enable the Japanese-language build (instead of the unofficial Aeon Genesis English translation)" OFF) option(FIX_BUGS "Fix various bugs in the game" OFF) option(DEBUG_SAVE "Re-enable the ability to drag-and-drop save files onto the window" OFF) + set(BACKEND_RENDERER "SDLTexture" CACHE STRING "Which renderer the game should use: 'OpenGL3' for an OpenGL 3.2 renderer, 'OpenGLES2' for an OpenGL ES 2.0 renderer, 'SDLTexture' for SDL2's hardware-accelerated Texture API, 'SDLSurface' for SDL2's software-rendered Surface API, or 'Software' for a handwritten software renderer") set(BACKEND_AUDIO "SDL2" CACHE STRING "Which audio backend the game should use: 'SDL2' or 'miniaudio'") -option(PKG_CONFIG_STATIC_LIBS "On platforms with pkg-config, static-link the dependencies (good for Windows builds, so you don't need to bundle DLL files)" OFF) option(LTO "Enable link-time optimisation" OFF) +option(PKG_CONFIG_STATIC_LIBS "On platforms with pkg-config, static-link the dependencies (good for Windows builds, so you don't need to bundle DLL files)" OFF) option(MSVC_LINK_STATIC_RUNTIME "Link the static MSVC runtime library (Visual Studio only)" OFF) option(FORCE_LOCAL_LIBS "Compile the built-in versions of SDL2, FreeType, and FLTK instead of using the system-provided ones" OFF) From f4a810be51dcc129ae9e3ec3502a9bb9d6911842 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 1 Apr 2020 20:38:30 +0100 Subject: [PATCH 8/8] Alter pkg-config notice, now that CMake uses it --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 37bfb58b..362b4b7d 100644 --- a/README.md +++ b/README.md @@ -38,12 +38,14 @@ Many months of copypasting and tinkering later, here is the result. ## Dependencies -*Note: with CMake, if these are not found, they will be built locally* - * SDL2 * FreeType * FLTK +In CMake builds, if these are not found, they will be built locally. + +In addition, `pkg-config` is required for Makefile builds, and CMake builds that require static-linkage. + ## Building ### CMake @@ -91,8 +93,6 @@ Once built, the executables can be found in the `game_english`/`game_japanese` f ### Makefile \[deprecated - use CMake instead\] -*Note: this requires pkg-config* - Run 'make' in this folder, preferably with some of the following settings: Name | Function