Clean Up CMake Build System

This commit is contained in:
TheBrokenRail 2023-10-10 15:25:03 -04:00
parent 4ff68d1f87
commit bba3099b71
16 changed files with 156 additions and 92 deletions

View file

@ -14,8 +14,8 @@ cd emsdk
# Update Emscripten SDK
git pull
./emsdk install 3.1.42 # https://github.com/emscripten-core/emscripten/issues/19921
./emsdk activate 3.1.42 > /dev/null
./emsdk install latest
./emsdk activate latest > /dev/null
# Use Emscripten SDK
export EMSDK_QUIET=1
@ -38,5 +38,5 @@ cmake --build .
# Bundle
cp reminecraftpe.* ../dist
cp ../../platforms/sdl/wasm_shell.html ../dist/reminecraftpe.html
cp ../../platforms/sdl/emscripten/wasm_shell.html ../dist/reminecraftpe.html
cp ../../thirdparty/coi-serviceworker/coi-serviceworker.min.js ../dist

View file

@ -0,0 +1,21 @@
cmake_minimum_required(VERSION 3.16.0)
project(reminecraftpe-openal)
# Build
add_library(reminecraftpe-openal STATIC
SoundSystemAL.cpp
)
# Core
target_link_libraries(reminecraftpe-openal PUBLIC reminecraftpe-core)
# OpenAL
if(EMSCRIPTEN)
target_link_libraries(reminecraftpe-openal PUBLIC openal)
else()
find_library(OPENAL_LIBRARY NAMES openal REQUIRED)
target_link_libraries(reminecraftpe-openal PUBLIC "${OPENAL_LIBRARY}")
endif()
# Headers
target_include_directories(reminecraftpe-openal PUBLIC .)

View file

@ -1,13 +0,0 @@
#pragma once
#include <string>
#include "../sdl/AppPlatform_sdl.hpp"
class AppPlatform_emscripten : public AppPlatform_sdlbase
{
public:
AppPlatform_emscripten(std::string storageDir, SDL_Window *window);
Texture loadTexture(const std::string& path, bool b = false) override;
};

View file

@ -1,7 +1,5 @@
cmake_minimum_required(VERSION 3.16.0)
project(reminecraftpe)
set(CMAKE_BUILD_TYPE Debug)
project(reminecraftpe-sdl)
# SDL Build
add_compile_definitions(USE_SDL USE_OPENAL HANDLE_CHARS_SEPARATELY)
@ -29,31 +27,22 @@ else()
endif()
# Build
if(EMSCRIPTEN)
add_executable(reminecraftpe
main.cpp
AppPlatform_sdlbase.cpp
AppPlatform_emscripten.cpp
../openal/SoundSystemAL.cpp
)
else()
add_executable(reminecraftpe
main.cpp
AppPlatform_sdlbase.cpp
AppPlatform_sdl.cpp
../openal/SoundSystemAL.cpp
)
endif()
# Core
add_subdirectory(../../source source)
target_link_libraries(reminecraftpe reminecraftpe-core)
# LibPNG
if(NOT EMSCRIPTEN)
find_package(PNG REQUIRED)
target_link_libraries(reminecraftpe PNG::PNG)
# SDL Base And Platform
add_subdirectory(base)
if(EMSCRIPTEN)
add_subdirectory(emscripten)
else()
add_subdirectory(desktop)
endif()
target_link_libraries(reminecraftpe reminecraftpe-sdl-platform)
# SDL
if(TARGET SDL2::SDL2main)
@ -72,5 +61,5 @@ endif()
if(EMSCRIPTEN)
target_link_options(reminecraftpe PRIVATE --use-preload-plugins --preload-file "${CMAKE_CURRENT_SOURCE_DIR}/../../game/assets@/assets")
elseif(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/assets")
file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/assets" "${CMAKE_CURRENT_BINARY_DIR}/assets" SYMBOLIC)
file(CREATE_LINK "${CMAKE_CURRENT_SOURCE_DIR}/../../game/assets" "${CMAKE_CURRENT_BINARY_DIR}/assets" SYMBOLIC)
endif()

View file

@ -1,4 +1,4 @@
#include "AppPlatform_sdlbase.hpp"
#include "AppPlatform_sdl_base.hpp"
#include <sstream>
#include <fstream>
@ -12,9 +12,9 @@
#include "common/Utils.hpp"
#include "platforms/openal/SoundSystemAL.hpp"
#include "SoundSystemAL.hpp"
void AppPlatform_sdlbase::_init(std::string storageDir, SDL_Window *window)
void AppPlatform_sdl_base::_init(std::string storageDir, SDL_Window *window)
{
_storageDir = storageDir;
_window = window;
@ -31,7 +31,7 @@ void AppPlatform_sdlbase::_init(std::string storageDir, SDL_Window *window)
m_pSoundSystem = nullptr;
}
void AppPlatform_sdlbase::initSoundSystem()
void AppPlatform_sdl_base::initSoundSystem()
{
if (!m_pSoundSystem)
{
@ -44,7 +44,7 @@ void AppPlatform_sdlbase::initSoundSystem()
}
}
void AppPlatform_sdlbase::setIcon(const Texture& icon)
void AppPlatform_sdl_base::setIcon(const Texture& icon)
{
if (!icon.m_pixels)
return;
@ -59,7 +59,7 @@ void AppPlatform_sdlbase::setIcon(const Texture& icon)
SDL_SetWindowIcon(_window, _icon);
}
AppPlatform_sdlbase::~AppPlatform_sdlbase()
AppPlatform_sdl_base::~AppPlatform_sdl_base()
{
if (_icon) SDL_FreeSurface(_icon);
SAFE_DELETE(_iconTexture);
@ -70,7 +70,7 @@ AppPlatform_sdlbase::~AppPlatform_sdlbase()
SAFE_DELETE(m_pLogger);
}
SDL_Surface* AppPlatform_sdlbase::getSurfaceForTexture(const Texture* const texture)
SDL_Surface* AppPlatform_sdl_base::getSurfaceForTexture(const Texture* const texture)
{
if (!texture) return nullptr;
@ -90,71 +90,71 @@ SDL_Surface* AppPlatform_sdlbase::getSurfaceForTexture(const Texture* const text
return surface;
}
int AppPlatform_sdlbase::checkLicense()
int AppPlatform_sdl_base::checkLicense()
{
// we own the game!!
return 1;
}
const char* const AppPlatform_sdlbase::getWindowTitle() const
const char* const AppPlatform_sdl_base::getWindowTitle() const
{
return SDL_GetWindowTitle(_window);
}
int AppPlatform_sdlbase::getScreenWidth() const
int AppPlatform_sdl_base::getScreenWidth() const
{
int width;
SDL_GL_GetDrawableSize(_window, &width, nullptr);
return width;
}
int AppPlatform_sdlbase::getScreenHeight() const
int AppPlatform_sdl_base::getScreenHeight() const
{
int height;
SDL_GL_GetDrawableSize(_window, nullptr, &height);
return height;
}
void AppPlatform_sdlbase::setMouseGrabbed(bool b)
void AppPlatform_sdl_base::setMouseGrabbed(bool b)
{
SDL_SetWindowGrab(_window, b ? SDL_TRUE : SDL_FALSE);
SDL_SetRelativeMouseMode(b ? SDL_TRUE : SDL_FALSE);
}
void AppPlatform_sdlbase::setMouseDiff(int x, int y)
void AppPlatform_sdl_base::setMouseDiff(int x, int y)
{
xrel = x;
yrel = y;
}
void AppPlatform_sdlbase::getMouseDiff(int& x, int& y)
void AppPlatform_sdl_base::getMouseDiff(int& x, int& y)
{
x = xrel;
y = yrel;
}
void AppPlatform_sdlbase::clearDiff()
void AppPlatform_sdl_base::clearDiff()
{
xrel = 0;
yrel = 0;
}
bool AppPlatform_sdlbase::shiftPressed()
bool AppPlatform_sdl_base::shiftPressed()
{
return m_bShiftPressed[0] || m_bShiftPressed[1];
}
void AppPlatform_sdlbase::setShiftPressed(bool b, bool isLeft)
void AppPlatform_sdl_base::setShiftPressed(bool b, bool isLeft)
{
m_bShiftPressed[isLeft ? 0 : 1] = b;
}
int AppPlatform_sdlbase::getUserInputStatus()
int AppPlatform_sdl_base::getUserInputStatus()
{
return -1;
}
MouseButtonType AppPlatform_sdlbase::GetMouseButtonType(SDL_Event event)
MouseButtonType AppPlatform_sdl_base::GetMouseButtonType(SDL_Event event)
{
switch (event.button.button)
{
@ -169,7 +169,7 @@ MouseButtonType AppPlatform_sdlbase::GetMouseButtonType(SDL_Event event)
}
}
bool AppPlatform_sdlbase::GetMouseButtonState(SDL_Event event)
bool AppPlatform_sdl_base::GetMouseButtonState(SDL_Event event)
{
bool result;
@ -200,7 +200,7 @@ bool AppPlatform_sdlbase::GetMouseButtonState(SDL_Event event)
return result;
}
Keyboard::KeyState AppPlatform_sdlbase::GetKeyState(SDL_Event event)
Keyboard::KeyState AppPlatform_sdl_base::GetKeyState(SDL_Event event)
{
switch (event.key.state)
{

View file

@ -9,15 +9,15 @@
#include "client/player/input/Keyboard.hpp"
#include "common/Logger.hpp"
class AppPlatform_sdlbase : public AppPlatform
class AppPlatform_sdl_base : public AppPlatform
{
public:
void _init(std::string storageDir, SDL_Window *window);
AppPlatform_sdlbase(std::string storageDir, SDL_Window *window)
AppPlatform_sdl_base(std::string storageDir, SDL_Window *window)
{
_init(storageDir, window);
}
~AppPlatform_sdlbase();
~AppPlatform_sdl_base();
void initSoundSystem() override;

View file

@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.16.0)
project(reminecraftpe-sdl-base)
# Build
add_library(reminecraftpe-sdl-base STATIC
AppPlatform_sdl_base.cpp
)
# Core
target_link_libraries(reminecraftpe-sdl-base reminecraftpe-core)
# Headers
target_include_directories(reminecraftpe-sdl-base PUBLIC .)
# OpenAL
add_subdirectory(../../openal openal)
target_link_libraries(reminecraftpe-sdl-base reminecraftpe-openal)

View file

@ -1,4 +1,4 @@
#include "AppPlatform_sdl.hpp"
#include "AppPlatform_sdl_desktop.hpp"
#include <fstream>
#include <sstream>
@ -11,8 +11,8 @@
#include "common/Utils.hpp"
AppPlatform_sdl::AppPlatform_sdl(std::string storageDir, SDL_Window *window)
: AppPlatform_sdlbase(storageDir, window)
AppPlatform_sdl_desktop::AppPlatform_sdl_desktop(std::string storageDir, SDL_Window *window)
: AppPlatform_sdl_base(storageDir, window)
{
setIcon(loadTexture("icon.png"));
}
@ -97,7 +97,7 @@ ret:
}
// Ensure Screenshots Folder Exists
void AppPlatform_sdl::ensureDirectoryExists(const char* path)
void AppPlatform_sdl_desktop::ensureDirectoryExists(const char* path)
{
// Check Screenshots Folder
struct stat obj;
@ -118,7 +118,7 @@ void AppPlatform_sdl::ensureDirectoryExists(const char* path)
}
}
void AppPlatform_sdl::saveScreenshot(const std::string& filename, int glWidth, int glHeight)
void AppPlatform_sdl_desktop::saveScreenshot(const std::string& filename, int glWidth, int glHeight)
{
// Get Directory
std::string screenshots = _storageDir + "/screenshots";
@ -206,7 +206,7 @@ static void nop_png_warning(png_structp png_ptr, png_const_charp warning_message
// Do Nothing
}
Texture AppPlatform_sdl::loadTexture(const std::string& path, bool b)
Texture AppPlatform_sdl_desktop::loadTexture(const std::string& path, bool b)
{
Texture out;
out.field_C = 1;
@ -295,7 +295,7 @@ Texture AppPlatform_sdl::loadTexture(const std::string& path, bool b)
return out;
}
bool AppPlatform_sdl::hasFileSystemAccess()
bool AppPlatform_sdl_desktop::hasFileSystemAccess()
{
return true;
}

View file

@ -2,12 +2,12 @@
#include <string>
#include "AppPlatform_sdlbase.hpp"
#include "AppPlatform_sdl_base.hpp"
class AppPlatform_sdl : public AppPlatform_sdlbase
class AppPlatform_sdl_desktop : public AppPlatform_sdl_base
{
public:
AppPlatform_sdl(std::string storageDir, SDL_Window *window);
AppPlatform_sdl_desktop(std::string storageDir, SDL_Window *window);
void saveScreenshot(const std::string& fileName, int width, int height) override;
Texture loadTexture(const std::string& path, bool b = false) override;

View file

@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.16.0)
project(reminecraftpe-sdl-desktop)
# Build
add_library(reminecraftpe-sdl-platform STATIC
AppPlatform_sdl_desktop.cpp
)
# Core
target_link_libraries(reminecraftpe-sdl-platform reminecraftpe-core)
# SDL Base
target_link_libraries(reminecraftpe-sdl-platform reminecraftpe-sdl-base)
# Headers
target_include_directories(reminecraftpe-sdl-platform PUBLIC .)
# LibPNG
find_package(PNG REQUIRED)
target_link_libraries(reminecraftpe-sdl-platform PNG::PNG)
# Assets
file(CREATE_LINK "${CMAKE_SOURCE_DIR}/../../game/assets" "${CMAKE_BINARY_DIR}/assets" SYMBOLIC)

View file

@ -1,15 +1,15 @@
#include "AppPlatform_emscripten.hpp"
#include "AppPlatform_sdl_emscripten.hpp"
#include <emscripten.h>
#include "common/Utils.hpp"
AppPlatform_emscripten::AppPlatform_emscripten(std::string storageDir, SDL_Window *window)
: AppPlatform_sdlbase(storageDir, window)
AppPlatform_sdl_emscripten::AppPlatform_sdl_emscripten(std::string storageDir, SDL_Window *window)
: AppPlatform_sdl_base(storageDir, window)
{
}
Texture AppPlatform_emscripten::loadTexture(const std::string& path, bool b)
Texture AppPlatform_sdl_emscripten::loadTexture(const std::string& path, bool b)
{
Texture out;
out.field_C = 1;

View file

@ -0,0 +1,13 @@
#pragma once
#include <string>
#include "AppPlatform_sdl_base.hpp"
class AppPlatform_sdl_emscripten : public AppPlatform_sdl_base
{
public:
AppPlatform_sdl_emscripten(std::string storageDir, SDL_Window *window);
Texture loadTexture(const std::string& path, bool b = false) override;
};

View file

@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 3.16.0)
project(reminecraftpe-sdl-emscripten)
# Build
add_library(reminecraftpe-sdl-platform STATIC
AppPlatform_sdl_emscripten.cpp
)
# Core
target_link_libraries(reminecraftpe-sdl-platform reminecraftpe-core)
# SDL Base
target_link_libraries(reminecraftpe-sdl-platform reminecraftpe-sdl-base)
# Headers
target_include_directories(reminecraftpe-sdl-platform PUBLIC .)
# WASM
target_link_options(reminecraftpe-sdl-platform PUBLIC -Wno-pthreads-mem-growth)
target_link_options(reminecraftpe-sdl-platform PUBLIC -sALLOW_MEMORY_GROWTH=1)
# Export Resize Function
target_link_options(reminecraftpe-sdl-platform PUBLIC -sEXPORTED_FUNCTIONS=_main,_resize_from_js -sEXPORTED_RUNTIME_METHODS=ccall)
# Assets
target_link_options(reminecraftpe-sdl-platform PUBLIC --use-preload-plugins --preload-file "${CMAKE_SOURCE_DIR}/../../game/assets@/assets")

View file

@ -10,6 +10,7 @@
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
canvas {
display: block;

View file

@ -5,12 +5,12 @@
#include "thirdparty/GL/GL.hpp"
#include "client/app/App.hpp"
#if defined(__EMSCRIPTEN__)
#include "AppPlatform_emscripten.hpp"
typedef AppPlatform_emscripten UsedAppPlatform;
#if defined(__EMSCRIPTEN__)
#include "AppPlatform_sdl_emscripten.hpp"
typedef AppPlatform_sdl_emscripten UsedAppPlatform;
#else
#include "AppPlatform_sdl.hpp"
typedef AppPlatform_sdl UsedAppPlatform;
#include "AppPlatform_sdl_desktop.hpp"
typedef AppPlatform_sdl_desktop UsedAppPlatform;
#endif
#include "client/app/NinecraftApp.hpp"
@ -24,8 +24,6 @@ typedef AppPlatform_sdl UsedAppPlatform;
#define EM_FALSE false
#endif
#undef main
static float g_fPointToPixelScale = 1.0f;
UsedAppPlatform *g_pAppPlatform;
@ -88,7 +86,7 @@ static void handle_events()
}
*/
Keyboard::feed(AppPlatform_sdlbase::GetKeyState(event), TranslateSDLKeyCodeToVirtual(event.key.keysym.sym));
Keyboard::feed(AppPlatform_sdl_base::GetKeyState(event), TranslateSDLKeyCodeToVirtual(event.key.keysym.sym));
if (event.key.keysym.sym == SDLK_LSHIFT || event.key.keysym.sym == SDLK_RSHIFT)
{
g_pAppPlatform->setShiftPressed(event.key.state == SDL_PRESSED, event.key.keysym.sym == SDLK_LSHIFT);
@ -99,7 +97,7 @@ static void handle_events()
case SDL_MOUSEBUTTONUP:
{
const float scale = g_fPointToPixelScale;
Mouse::feed(AppPlatform_sdlbase::GetMouseButtonType(event), AppPlatform_sdlbase::GetMouseButtonState(event), event.button.x * scale, event.button.y * scale);
Mouse::feed(AppPlatform_sdl_base::GetMouseButtonType(event), AppPlatform_sdl_base::GetMouseButtonState(event), event.button.x * scale, event.button.y * scale);
break;
}
case SDL_MOUSEMOTION:
@ -113,7 +111,7 @@ static void handle_events()
}
case SDL_MOUSEWHEEL:
{
Mouse::feed(BUTTON_SCROLLWHEEL, AppPlatform_sdlbase::GetMouseButtonState(event), Mouse::getX(), Mouse::getY());
Mouse::feed(BUTTON_SCROLLWHEEL, AppPlatform_sdl_base::GetMouseButtonState(event), Mouse::getX(), Mouse::getY());
break;
}
case SDL_TEXTINPUT:

View file

@ -274,11 +274,3 @@ else()
find_package(OpenGL REQUIRED)
target_link_libraries(reminecraftpe-core PUBLIC OpenGL::OpenGL OpenGL::GLU)
endif()
# OpenAL
if(EMSCRIPTEN)
target_link_libraries(reminecraftpe-core PUBLIC openal)
else()
find_library(OPENAL_LIBRARY NAMES openal REQUIRED)
target_link_libraries(reminecraftpe-core PUBLIC "${OPENAL_LIBRARY}")
endif()