From a86d333478697d036513397d582625ff332391c3 Mon Sep 17 00:00:00 2001 From: Kolyah35 Date: Mon, 2 Mar 2026 23:17:13 +0300 Subject: [PATCH] some improvements --- .gitignore | 1 + CMakeLists.txt | 40 ++++++++++++++----- src/client/Minecraft.cpp | 22 +++++----- src/client/Options.cpp | 2 +- src/client/gui/Gui.cpp | 4 +- src/client/gui/screens/SelectWorldScreen.cpp | 2 +- .../screens/touch/TouchSelectWorldScreen.cpp | 2 +- src/client/player/input/KeyboardInput.cpp | 2 +- src/client/renderer/Textures.cpp | 1 + src/client/renderer/Textures.h | 2 +- src/client/renderer/gles.h | 2 +- 11 files changed, 49 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 4684bf0..e213499 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build/ linux-build/ +.cache/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index d87c831..a8a48c5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,10 @@ project(MinecraftPE) include(cmake/CPM.cmake) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED TRUE) +set(CMAKE_CXX_FLAGS "-Wno-c++11-narrowing -Wno-invalid-source-encoding") + CPMAddPackage("gh:madler/zlib@1.3.2") CPMAddPackage( NAME "libpng" @@ -116,15 +120,33 @@ file(GLOB SOURCES "src/NinecraftApp.cpp" ) +if(NOT DEFINED PLATFORM) + set(PLATFORM "PLATFORM_GLFW") +endif() + + +if(PLATFORM STREQUAL "PLATFORM_WIN32") + list(APPEND SOURCES "src/AppPlatform_win32.cpp") +endif() + +if(PLATFORM STREQUAL "PLATFORM_GLFW") + list(APPEND SOURCES "src/AppPlatform_glfw.cpp") +endif() + add_executable(${PROJECT_NAME} ${SOURCES} - - #TODO: if PLATFORM=PLATFORM_GLFW - "src/AppPlatform_glfw.cpp" - "glad/src/glad.c" ) +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_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_SOURCE_DIR}/glad/include/" "${CMAKE_SOURCE_DIR}/src" @@ -133,14 +155,10 @@ target_include_directories(${PROJECT_NAME} PUBLIC "lib/include" ) -target_compile_definitions(${PROJECT_NAME} PUBLIC "OPENGL_ES" "NO_EGL" "_CRT_SECURE_NO_WARNINGS" "PLATFORM_GLFW") +target_compile_definitions(${PROJECT_NAME} PUBLIC "OPENGL_ES" "NO_EGL" ${PLATFORM}) +target_link_libraries(${PROJECT_NAME} zlib png_shared alsoft.common OpenAL::OpenAL glfw ${EXTRA_LIBS}) -# TODO: add ws2_32 lib if windows -# TODO: fix openal linking for windows - -target_link_libraries(${PROJECT_NAME} zlib png_shared alsoft.common OpenAL glfw) - -if (NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Linux") +if (NOT UNIX) add_custom_command( TARGET ${PROJECT_NAME} POST_BUILD diff --git a/src/client/Minecraft.cpp b/src/client/Minecraft.cpp index 44b15ce..613d5b2 100755 --- a/src/client/Minecraft.cpp +++ b/src/client/Minecraft.cpp @@ -4,7 +4,7 @@ #define NO_NETWORK #endif -#if defined(RPI) +#ifdef PLATFORM_DESKTOP #define CREATORMODE #endif @@ -574,7 +574,7 @@ void Minecraft::tick(int nTick, int maxTick) { #ifndef STANDALONE_SERVER textures->loadAndBindTexture("terrain.png"); if (!pause && !(screen && !screen->renderGameBehind())) { - #if !defined(RPI) + #ifndef PLATFORM_DESKTOP #ifdef __APPLE__ if (isSuperFast()) #endif @@ -691,7 +691,7 @@ void Minecraft::tickInput() { if (isPressed) { gui.handleKeyPressed(key); - #if defined(WIN32) || defined(RPI)//|| defined(_DEBUG) || defined(DEBUG) + #ifdef PLATFORM_DESKTOP //|| defined(_DEBUG) || defined(DEBUG) if (key >= '0' && key <= '9') { int digit = key - '0'; int slot = digit - 1; @@ -714,16 +714,14 @@ void Minecraft::tickInput() { } #endif } - #endif - #if defined(RPI) + if (key == Keyboard::KEY_E) { screenChooser.setScreen(SCREEN_BLOCKSELECTION); } if (!screen && key == Keyboard::KEY_O || key == 250) { releaseMouse(); } - #endif - #if defined(WIN32) + if (key == Keyboard::KEY_F) { options.isFlying = !options.isFlying; player->noPhysics = options.isFlying; @@ -831,7 +829,7 @@ void Minecraft::tickInput() { } #endif - #if !defined(RPI) && !defined(PLATFORM_GLFW) + #ifndef PLATFORM_DESKTOP if (key == 82) pauseGame(false); #else @@ -848,7 +846,7 @@ void Minecraft::tickInput() { } #endif } - #ifdef WIN32 + #ifdef PLATFORM_DESKTOP if (key == Keyboard::KEY_M) { for (int i = 0; i < 5 * SharedConstants::TicksPerSecond; ++i) level->tick(); @@ -892,7 +890,7 @@ void Minecraft::tickInput() { || (buildHandled && bai.isRemove()); TIMER_POP_PUSH("handlemouse"); -#if defined(RPI) || defined(PLATFORM_GLFW) +#ifdef PLATFORM_DESKTOP handleMouseDown(MouseAction::ACTION_LEFT, isTryingToDestroyBlock); handleMouseClick(buildHandled && bai.isInteract() || options.useMouseForDigging && Mouse::isButtonDown(MouseAction::ACTION_RIGHT)); @@ -1123,7 +1121,7 @@ void Minecraft::releaseMouse() } bool Minecraft::useTouchscreen() { -#if defined(RPI) || defined(PLATFORM_GLFW) +#ifdef PLATFORM_DESKTOP return false; #endif return options.useTouchScreen || !_supportsNonTouchscreen; @@ -1366,7 +1364,7 @@ void Minecraft::_levelGenerated() netCallback->levelGenerated(level); } -#if defined(WIN32) || defined(RPI) +#ifdef PLATFORM_DESKTOP if (_commandServer) { delete _commandServer; } diff --git a/src/client/Options.cpp b/src/client/Options.cpp index cde2f5b..dde5f1f 100755 --- a/src/client/Options.cpp +++ b/src/client/Options.cpp @@ -54,7 +54,7 @@ void Options::initDefaultValues() { keyJump = KeyMapping("key.jump", Keyboard::KEY_SPACE); keyBuild = KeyMapping("key.inventory", Keyboard::KEY_E); keySneak = KeyMapping("key.sneak", Keyboard::KEY_LSHIFT); -#if defined(RPI) || defined(PLATFORM_GLFW) +#ifdef PLATFORM_DESKTOP keyCraft = KeyMapping("key.crafting", Keyboard::KEY_Q); keyDrop = KeyMapping("key.drop", Keyboard::KEY_Q); keyChat = KeyMapping("key.chat", Keyboard::KEY_T); diff --git a/src/client/gui/Gui.cpp b/src/client/gui/Gui.cpp index 93a3c0c..c87da8c 100755 --- a/src/client/gui/Gui.cpp +++ b/src/client/gui/Gui.cpp @@ -112,10 +112,10 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) { unsigned int max = 10; bool isChatting = false; renderChatMessages(screenHeight, max, isChatting, font); -#if !defined(RPI) +#ifndef PLATFORM_DESKTOP renderOnSelectItemNameText(screenWidth, font, ySlot); #endif -#if defined(RPI) +#ifdef PLATFORM_DESKTOP renderDebugInfo(); #endif diff --git a/src/client/gui/screens/SelectWorldScreen.cpp b/src/client/gui/screens/SelectWorldScreen.cpp index dd3ebbb..2f7d09f 100755 --- a/src/client/gui/screens/SelectWorldScreen.cpp +++ b/src/client/gui/screens/SelectWorldScreen.cpp @@ -295,7 +295,7 @@ static char ILLEGAL_FILE_CHARACTERS[] = { void SelectWorldScreen::tick() { if (_state == _STATE_CREATEWORLD) { - #if defined(RPI) + #if defined(PLATFORM_DESKTOP) std::string levelId = getUniqueLevelName("world"); LevelSettings settings(getEpochTimeS(), GameType::Creative); minecraft->selectLevel(levelId, levelId, settings); diff --git a/src/client/gui/screens/touch/TouchSelectWorldScreen.cpp b/src/client/gui/screens/touch/TouchSelectWorldScreen.cpp index bc0d977..83b79d0 100755 --- a/src/client/gui/screens/touch/TouchSelectWorldScreen.cpp +++ b/src/client/gui/screens/touch/TouchSelectWorldScreen.cpp @@ -393,7 +393,7 @@ static char ILLEGAL_FILE_CHARACTERS[] = { void SelectWorldScreen::tick() { if (_state == _STATE_CREATEWORLD) { - #if defined(RPI) + #ifdef PLATFORM_DESKTOP std::string levelId = getUniqueLevelName("perf"); //int seed = Util::hashCode("/r/Minecraft"); LevelSettings settings(getEpochTimeS(), GameType::Creative); diff --git a/src/client/player/input/KeyboardInput.cpp b/src/client/player/input/KeyboardInput.cpp index 30a5a55..916bab2 100755 --- a/src/client/player/input/KeyboardInput.cpp +++ b/src/client/player/input/KeyboardInput.cpp @@ -52,7 +52,7 @@ void KeyboardInput::tick( Player* player ) ya *= 0.3f; } - #if defined(RPI) || defined(PLATFORM_GLFW) + #ifdef PLATFORM_DESKTOP wantUp = jumping; wantDown = sneaking; #endif diff --git a/src/client/renderer/Textures.cpp b/src/client/renderer/Textures.cpp index a64644a..50c6502 100755 --- a/src/client/renderer/Textures.cpp +++ b/src/client/renderer/Textures.cpp @@ -8,6 +8,7 @@ /*static*/ int Textures::textureChanges = 0; /*static*/ bool Textures::MIPMAP = false; +const TextureId Textures::InvalidId = -1; Textures::Textures( Options* options_, AppPlatform* platform_ ) : clamp(false), diff --git a/src/client/renderer/Textures.h b/src/client/renderer/Textures.h index faa5d1f..f5e2113 100755 --- a/src/client/renderer/Textures.h +++ b/src/client/renderer/Textures.h @@ -58,7 +58,7 @@ private: public: static bool MIPMAP; static int textureChanges; - static const TextureId InvalidId = -1; + static const TextureId InvalidId; private: TextureMap idMap; diff --git a/src/client/renderer/gles.h b/src/client/renderer/gles.h index 7e13d42..2c0c850 100755 --- a/src/client/renderer/gles.h +++ b/src/client/renderer/gles.h @@ -5,7 +5,7 @@ #include "../Options.h" // Android should always run OPENGL_ES -#if defined(ANDROID) || defined(__APPLE__) || defined(RPI) +#if defined(ANDROID) || defined(__APPLE__) || defined(PLATFORM_DESKTOP) #define OPENGL_ES #endif