Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Big CMake + MinGW + Sound PR #127

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y build-essential cmake ninja-build libopenal-dev libsdl2-dev zlib1g-dev
sudo apt-get install --no-install-recommends -y \
build-essential \
cmake ninja-build \
libopenal-dev \
libsdl2-dev zlib1g-dev
- name: Build
run: |
cd platforms/sdl
mkdir build
cd build
cmake -GNinja ${{ matrix.flags }} ..
Expand All @@ -37,7 +40,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Install Dependencies
Expand All @@ -51,7 +54,7 @@ jobs:
runs-on: macos-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Install MacPorts
Expand All @@ -62,6 +65,7 @@ jobs:
sudo port install libpng +universal
- name: Build macOS Archive
run: |
ln -s sound/openal platforms/openal # Please someone fix this properly later.
cd platforms/macos/projects/Minecraft
xcodebuild -scheme "MinecraftClient.SDL2" \
-archivePath $RUNNER_TEMP/GitHubActions_MacOS_SDL2.xcarchive \
Expand Down Expand Up @@ -103,11 +107,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
- name: Setup JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
Expand All @@ -116,3 +120,32 @@ jobs:
run: |
cd ${{ matrix.directory }}
./gradlew build
mingw:
strategy:
fail-fast: false
matrix:
include:
- name: Win32
flags: "-DREMCPE_PLATFORM=windows"
- name: SDL
flags: "-DREMCPE_PLATFORM=sdl"
name: MinGW-w64 (${{ matrix.name }})
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
submodules: true
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y \
build-essential \
cmake ninja-build \
mingw-w64
- name: Build
run: |
mkdir build
cd build
cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw-w64-toolchain.cmake ${{ matrix.flags }} ..
cmake --build .
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ xcuserdata/
/sound_data

# Ignore linux/mingw build artifacts.
/build
/build*
/minecraftcpp
/minecraftcpp.exe

Expand Down Expand Up @@ -207,3 +207,12 @@ xcuserdata/
/game/assets/gui/feedback_outer.png
/game/assets/snow.png
/game/assets/mob/pig.png

# CLion
/.idea
/cmake-build-*

# Sound
/tools/__pycache__
/tools/venv
/game/assets/sound
61 changes: 61 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
cmake_minimum_required(VERSION 3.16.0)
project(reminecraftpe)

# Store Output In Top-Level Build Directory
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}")

# WASM
if(EMSCRIPTEN)
function(add_compile_and_link_options)
add_compile_options(${ARGV})
add_link_options(${ARGV})
endfunction()
set(CMAKE_EXECUTABLE_SUFFIX ".js")
add_link_options("$<$<CONFIG:DEBUG>:-gsource-map>")
add_link_options(-Wno-pthreads-mem-growth -sALLOW_MEMORY_GROWTH=1)
endif()

# Clang
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Wno-inconsistent-missing-override -Wno-enum-compare-switch -Wno-register)
endif()

# Windows Linking
if(WIN32)
add_link_options(
-static-libgcc
-static-libstdc++
)
endif()

# HaikuOS Network Library
if(HAIKU)
link_libraries(network)
endif()

# Threading
if(EMSCRIPTEN)
add_compile_and_link_options(-pthread)
else()
find_package(Threads)
link_libraries(Threads::Threads)
endif()

# Android Logging
if(ANDROID)
link_libraries(log)
endif()

# Load Common Code
add_subdirectory(source)

# Load Platform-Specific Code
add_subdirectory(platforms)

# Assets
if(EMSCRIPTEN)
target_link_options(reminecraftpe PRIVATE --use-preload-plugins --preload-file "${CMAKE_CURRENT_SOURCE_DIR}/game@/")
else()
file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/game/assets" "${CMAKE_CURRENT_BINARY_DIR}/assets" SYMBOLIC)
endif()
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ based on Minecraft PE v0.1.3.
* To keep the source code layout similar to the original Minecraft PE (reconstructed from clues hidden within
certain versions of the game, such as the 0.1.0 touch prototype/debug build)
* To port the game to more platforms, such as Windows (including older versions), Xbox 360, Wii, and more.
Currently there are ports for:
Currently, there are ports for:
* Windows XP-11
* Android (thanks to [Stom](https://github.com/Stommm) for the help)
* Linux
* WebGL
* Mac OS (port by [BrentDaMage](https://github.com/BrentDaMage))
* macOS (port by [BrentDaMage](https://github.com/BrentDaMage))
* iOS (3.0 and above; port by [BrentDaMage](https://github.com/BrentDaMage))
* HaikuOS (thanks to [SanyaSho](https://github.com/SanyaSho))
* Xbox 360 (work in progress; port by [BrentDaMage](https://github.com/BrentDaMage))
Expand All @@ -36,7 +36,7 @@ Note: While the original Minecraft PE v0.1.3 may not work on newer devices, ReMi

## License information

This project is licensed under the [BSD 1 clause license](LICENSE.md). However, it contains third party
This project is licensed under the [BSD 1 clause license](LICENSE.txt). However, it contains third party
software with different but compatible licenses:

- [RakNet](https://github.com/facebookarchive/RakNet): [Licensed under the BSD 2 clause license](thirdparty/raknet/LICENSE)
Expand Down Expand Up @@ -142,7 +142,6 @@ This project uses CMake on Linux. Just like WebAssembly, the game assets must be
#### How To Build

```sh
cd platforms/sdl
mkdir build && cd build
cmake -GNinja ..
cmake --build .
Expand Down
2 changes: 1 addition & 1 deletion build-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mkdir -p build
cd build

# Configure Build
emcmake cmake -GNinja "$@" ../../platforms/sdl
emcmake cmake -GNinja "$@" ../../

# Build
cmake --build .
Expand Down
11 changes: 11 additions & 0 deletions cmake/mingw-w64-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://gist.github.com/peterspackman/8cf73f7f12ba270aa8192d6911972fe8
set(CMAKE_SYSTEM_NAME Windows)
set(TOOLCHAIN_PREFIX x86_64-w64-mingw32)
set(CMAKE_C_COMPILER "${TOOLCHAIN_PREFIX}-gcc")
set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PREFIX}-g++")
set(CMAKE_Fortran_COMPILER "${TOOLCHAIN_PREFIX}-gfortran")
set(CMAKE_RC_COMPILER "${TOOLCHAIN_PREFIX}-windres")
set(CMAKE_FIND_ROOT_PATH "/usr/${TOOLCHAIN_PREFIX}")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
2 changes: 1 addition & 1 deletion compat/KeyCodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ enum eSDLVirtualKeys

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <windows.h>
#elif __APPLE__
// https://i.stack.imgur.com/LD8pT.png
#define AKEYCODE_FORWARD_DEL 0x75
Expand Down
12 changes: 12 additions & 0 deletions platforms/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
project(reminecraftpe-platforms)

# Select & Build
set(DEFAULT_PLATFORM "sdl")
if(WIN32)
set(DEFAULT_PLATFORM "windows")
endif()
set(REMCPE_PLATFORM "${DEFAULT_PLATFORM}" CACHE STRING "ReMCPE Platform (Check <root>/platforms)")
add_subdirectory("${REMCPE_PLATFORM}")

# Load Sound
add_subdirectory(sound)
23 changes: 21 additions & 2 deletions platforms/android/AppPlatform_android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <sstream>

#include "AppPlatform_android.hpp"
#include "SoundSystemSL.hpp"
#include "CustomSoundSystem.hpp"
#include "client/player/input/Mouse.hpp"

#include "stb_image.h"
Expand Down Expand Up @@ -174,7 +174,7 @@ SoundSystem* const AppPlatform_android::getSoundSystem() const
void AppPlatform_android::initSoundSystem()
{
if (!m_pSoundSystem)
m_pSoundSystem = new SoundSystemSL();
m_pSoundSystem = new SOUND_SYSTEM();
else
LOG_E("Trying to initialize SoundSystem more than once!");
}
Expand Down Expand Up @@ -357,3 +357,22 @@ int AppPlatform_android::getKeyboardUpOffset()
// For now we'll just return 1/2 of the screen height. That ought to cover most cases.
return m_ScreenHeight / 2;
}

AssetFile AppPlatform_android::readAssetFile(const std::string& str) const
{
std::string realPath = str;
if (realPath.size() && realPath[0] == '/')
// trim it off
realPath = realPath.substr(1);

AAsset* asset = AAssetManager_open(m_app->activity->assetManager, str.c_str(), AASSET_MODE_BUFFER);
if (!asset) {
LOG_E("File %s couldn't be opened", realPath.c_str());
return AssetFile();
}
size_t cnt = AAsset_getLength(asset);
unsigned char* buffer = new unsigned char[cnt];
AAsset_read(asset, (void*)buffer, cnt);
AAsset_close(asset);
return AssetFile(ssize_t(cnt), buffer);
}
2 changes: 2 additions & 0 deletions platforms/android/AppPlatform_android.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class AppPlatform_android : public AppPlatform
void initAndroidApp(android_app* ptr);
void setExternalStoragePath(const std::string& path);

AssetFile readAssetFile(const std::string&) const override;

private:
void changeKeyboardVisibility(bool bShown);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
cmake_minimum_required(VERSION 3.16.0)
project(reminecraftpe-android)

# Project Root
set(MC_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../..")

# Native Android Build
add_compile_definitions(USE_NATIVE_ANDROID)
set(USE_NATIVE_ANDROID TRUE)
target_compile_definitions(reminecraftpe-core PUBLIC USE_NATIVE_ANDROID)

# Build
add_library(reminecraftpe SHARED
"${MC_ROOT}/platforms/android/android_native_app_glue.c"
"${MC_ROOT}/platforms/android/AppPlatform_android.cpp"
"${MC_ROOT}/platforms/android/SoundSystemSL.cpp"
"${MC_ROOT}/platforms/android/main.cpp"
android_native_app_glue.c
AppPlatform_android.cpp
main.cpp
)

# Core
add_subdirectory("${MC_ROOT}/source" source)
target_link_libraries(reminecraftpe reminecraftpe-core)

# OpenGL
target_link_libraries(reminecraftpe-core PUBLIC EGL GLESv1_CM)

# stb_image
add_subdirectory("${MC_ROOT}/thirdparty/stb_image" stb_image)
add_subdirectory(../../thirdparty/stb_image stb_image)
target_link_libraries(reminecraftpe stb_image)

# Extra Dependencies
target_link_libraries(reminecraftpe android OpenSLES)
target_link_libraries(reminecraftpe android)

# Check for the presence of some optional asset based features.
if(EXISTS "${MC_ROOT}/game/assets/gui/background/panorama_0.png")
Expand Down
4 changes: 2 additions & 2 deletions platforms/android/project/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ android {
// testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments '-DANDROID_PLATFORM=android-21', '-DANDROID_STL=c++_static'
arguments '-DANDROID_PLATFORM=android-21', '-DANDROID_STL=c++_static', '-DREMCPE_PLATFORM=android', '-DREMCPE_SOUND_PLATFORM=opensl'
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}
}
Expand All @@ -47,7 +47,7 @@ android {
}
externalNativeBuild {
cmake {
path file('src/main/cpp/CMakeLists.txt')
path '../../../../CMakeLists.txt'
version '3.22.1'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,7 @@
84EAE8E12AF1EAB5000894E8 /* GLKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLKit.framework; path = System/Library/Frameworks/GLKit.framework; sourceTree = SDKROOT; };
84EAE8E32AF1EABE000894E8 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
84EAE8E62AF1EAFA000894E8 /* SoundSystemAL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SoundSystemAL.cpp; sourceTree = "<group>"; };
84EAE8E72AF1EAFA000894E8 /* SoundSystemAL.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = SoundSystemAL.hpp; sourceTree = "<group>"; };
84EAE8E72AF1EAFA000894E8 /* CustomSoundSystem.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = CustomSoundSystem.hpp; sourceTree = "<group>"; };
84EAE8F02AF1EAFA000894E8 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
84EAE8F12AF1EAFA000894E8 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = "<group>"; };
84ED99D42AFF12D1003B6AF0 /* minecraftpe.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = minecraftpe.entitlements; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3566,7 +3566,7 @@
isa = PBXGroup;
children = (
84EAE8E62AF1EAFA000894E8 /* SoundSystemAL.cpp */,
84EAE8E72AF1EAFA000894E8 /* SoundSystemAL.hpp */,
84EAE8E72AF1EAFA000894E8 /* CustomSoundSystem.hpp */,
);
path = openal;
sourceTree = "<group>";
Expand Down
Loading