diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a67598..aa81883 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,22 +6,45 @@ include(cmake/CPM.cmake) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) set(CMAKE_POLICY_VERSION_MINIMUM 3.10) + if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") set(CMAKE_CXX_FLAGS "-Wno-c++11-narrowing -Wno-narrowing -Wno-invalid-source-encoding -Wno-reserved-user-defined-literal") endif() +# ## Config options ### +include(CMakeDependentOption) +include(cmake/EnumOption.cmake) + +if(EMSCRIPTEN) + # When configuring web builds with "emcmake cmake -B build -S .", set PLATFORM to Web by default + set(PLATFORM Web CACHE STRING "Platform to build for.") +endif() + +enum_option(PLATFORM "Desktop;Web" "Platform to build for.") + find_package(Threads REQUIRED) find_package(OpenSSL) -if(EMSCRIPTEN) - set(AL_LIBTYPE "STATIC") -else() - set(AL_LIBTYPE "SHARED") +if (${PLATFORM} STREQUAL "Desktop") + set(PLATFORM_CPP "PLATFORM_DESKTOP") + + if (WIN32) + add_definitions(-D_CRT_SECURE_NO_WARNINGS) + set(EXTRA_LIBS ws2_32) + elseif(UNIX) + find_library(pthread NAMES pthread) + set(EXTRA_LIBS pthread m) + endif() + +elseif (${PLATFORM} STREQUAL "Web") + set(PLATFORM_CPP "PLATFORM_WEB") + set(EXTRA_LIBS "idbfs.js") endif() # I totally shocked -if(EMSCRIPTEN) +if(${PLATFORM} MATCHES "Web") set(PNG_LIB png) + set(AL_LIBTYPE "STATIC") add_library(zlib INTERFACE IMPORTED) set_target_properties(zlib PROPERTIES @@ -39,6 +62,7 @@ if(EMSCRIPTEN) ) else() set(PNG_LIB png_shared) + set(AL_LIBTYPE "SHARED") CPMAddPackage( NAME "zlib" @@ -259,49 +283,32 @@ file(GLOB CLIENT_SOURCES "src/SharedConstants.cpp" "src/main.cpp" "src/NinecraftApp.cpp" + + "src/AppPlatform_glfw.cpp" + "src/main.cpp" ) -if(NOT DEFINED PLATFORM) - set(PLATFORM "PLATFORM_GLFW") -endif() - - -if(PLATFORM STREQUAL "PLATFORM_WIN32") - list(APPEND CLIENT_SOURCES "src/AppPlatform_win32.cpp" "glad/src/glad.c") -endif() - -if(PLATFORM STREQUAL "PLATFORM_GLFW") - list(APPEND CLIENT_SOURCES "src/AppPlatform_glfw.cpp" "glad/src/glad.c") -endif() - -if(EMSCRIPTEN) - list(APPEND CLIENT_SOURCES "glad/src/glad.c") +if (${PLATFORM} STREQUAL "Desktop") + list(APPEND CLIENT_SOURCES glad/src/glad.c) endif() # Server if(UNIX) -add_executable("${PROJECT_NAME}-server" ${SERVER_SOURCES}) + add_executable("${PROJECT_NAME}-server" ${SERVER_SOURCES}) -target_compile_definitions("${PROJECT_NAME}-server" PUBLIC "STANDALONE_SERVER" "SERVER_PROFILER") + target_compile_definitions("${PROJECT_NAME}-server" PUBLIC "STANDALONE_SERVER" "SERVER_PROFILER") -target_include_directories("${PROJECT_NAME}-server" PUBLIC - "${CMAKE_SOURCE_DIR}/src/" - "project/lib_projects/raknet/jni/RaknetSources" -) + target_include_directories("${PROJECT_NAME}-server" PUBLIC + "${CMAKE_SOURCE_DIR}/src/" + "project/lib_projects/raknet/jni/RaknetSources" + ) -target_link_libraries("${PROJECT_NAME}-server" ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries("${PROJECT_NAME}-server" ${CMAKE_THREAD_LIBS_INIT}) endif() add_executable(${PROJECT_NAME} ${CLIENT_SOURCES}) -if(WIN32) - set(EXTRA_LIBS "ws2_32") - target_compile_definitions(${PROJECT_NAME} PUBLIC "_CRT_SECURE_NO_WARNINGS") -endif() - -if(PLATFORM STREQUAL "PLATFORM_WIN32" OR PLATFORM STREQUAL "PLATFORM_GLFW") - target_compile_definitions(${PROJECT_NAME} PUBLIC "PLATFORM_DESKTOP") -endif() +target_compile_definitions(${PROJECT_NAME} PUBLIC ${PLATFORM_CPP}) target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/glad/include/" @@ -311,7 +318,7 @@ target_include_directories(${PROJECT_NAME} PUBLIC "lib/include" ) -if(EMSCRIPTEN) +if(${PLATFORM} MATCHES "Web") set(CMAKE_CXX_STANDARD 11) # uuuh i hate it set(EM_FLAGS "-pthread -sUSE_PTHREADS=1 -sSHARED_MEMORY=1") @@ -352,7 +359,6 @@ if(EMSCRIPTEN) endif() target_compile_definitions(${PROJECT_NAME} PUBLIC "__EMSCRIPTEN__" "NO_SOUND" "NO_NETWORK") - set(EXTRA_LIBS "idbfs.js") endif() # Client @@ -373,7 +379,7 @@ if (NOT UNIX) ) endif() -if(NOT EMSCRIPTEN) +if(NOT ${PLATFORM} MATCHES "Web") add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD @@ -385,4 +391,7 @@ else() POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_SOURCE_DIR}/misc/web/index.html" $ ) -endif() \ No newline at end of file +endif() + +message(STATUS "Compiling with the flags:") +message(STATUS " PLATFORM=" ${PLATFORM_CPP}) \ No newline at end of file diff --git a/src/client/MouseHandler.cpp b/src/client/MouseHandler.cpp index 7855e41..d122950 100755 --- a/src/client/MouseHandler.cpp +++ b/src/client/MouseHandler.cpp @@ -5,7 +5,7 @@ #include #endif -#ifdef PLATFORM_GLFW +#ifdef PLATFORM_DESKTOP #include #endif @@ -34,7 +34,7 @@ void MouseHandler::grab() { SDL_ShowCursor(0); #endif -#ifdef PLATFORM_GLFW +#ifdef PLATFORM_DESKTOP glfwSetInputMode(glfwGetCurrentContext(), GLFW_CURSOR, GLFW_CURSOR_DISABLED); #endif } @@ -46,7 +46,7 @@ void MouseHandler::release() { SDL_ShowCursor(1); #endif -#ifdef PLATFORM_GLFW +#ifdef PLATFORM_DESKTOP glfwSetInputMode(glfwGetCurrentContext(), GLFW_CURSOR, GLFW_CURSOR_NORMAL); #endif } diff --git a/src/main.cpp b/src/main.cpp index de00f66..d2e9138 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,12 +22,12 @@ #include "NinecraftApp.h" #define MAIN_CLASS NinecraftApp -#ifdef PLATFORM_WINDOWS - #include "main_win32.h" -#endif +// #ifdef PLATFORM_WINDOWS +// #include "main_win32.h" +// #endif -#ifdef PLATFORM_GLFW +#ifdef PLATFORM_DESKTOP #include "main_glfw.h" #endif diff --git a/src/world/level/storage/ExternalFileLevelStorage.cpp b/src/world/level/storage/ExternalFileLevelStorage.cpp index 2291302..91bcf45 100755 --- a/src/world/level/storage/ExternalFileLevelStorage.cpp +++ b/src/world/level/storage/ExternalFileLevelStorage.cpp @@ -7,6 +7,7 @@ #include "../chunk/LevelChunk.h" #include "../Level.h" #include "../LevelConstants.h" +#include "platform/log.h" #include "../tile/TreeTile.h" #include "../../entity/EntityFactory.h" #include "../../../nbt/NbtIo.h" @@ -289,8 +290,9 @@ bool ExternalFileLevelStorage::readPlayerData(const std::string& filename, Level void ExternalFileLevelStorage::tick() { tickCount++; - if ((tickCount % 50) == 0 && level) - { + if ((tickCount % 1000) == 0 && level) { + LOGI("Saving level...\n"); + // look for chunks that needs to be saved for (int z = 0; z < CHUNK_CACHE_WIDTH; z++) {