From d1de430d14c4d7e3486041ba51c90da8e895104f Mon Sep 17 00:00:00 2001 From: iProgramInCpp Date: Fri, 11 Aug 2023 00:13:06 +0300 Subject: [PATCH] * Add optional 3d panorama background --- .gitignore | 8 ++ platforms/sdl/main.cpp | 6 +- platforms/windows/main.cpp | 4 + source/Minecraft.cpp | 6 + source/Minecraft.hpp | 3 + source/client/gui/Screen.cpp | 112 +++++++++++++++++- source/client/gui/Screen.hpp | 3 + source/client/gui/screens/OptionsScreen.cpp | 5 +- source/client/gui/screens/StartMenuScreen.cpp | 4 +- .../network/ServerSideNetworkHandler.cpp | 16 +++ source/client/renderer/Textures.hpp | 12 ++ 11 files changed, 172 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index f3f606f..bf3de2f 100644 --- a/.gitignore +++ b/.gitignore @@ -401,6 +401,14 @@ FodyWeavers.xsd /game/assets/particles.png /game/assets/terrain.png +# Ignore the panorama textures. +/game/assets/gui/background/panorama_0.png +/game/assets/gui/background/panorama_1.png +/game/assets/gui/background/panorama_2.png +/game/assets/gui/background/panorama_3.png +/game/assets/gui/background/panorama_4.png +/game/assets/gui/background/panorama_5.png + # Avoid including Minecraft Classic assets from Mojang, for now. /game/assets/patches/*.png /game/assets/patches/classic/*.png diff --git a/platforms/sdl/main.cpp b/platforms/sdl/main.cpp index 74dde7b..ba09ebf 100644 --- a/platforms/sdl/main.cpp +++ b/platforms/sdl/main.cpp @@ -134,7 +134,7 @@ static void handle_events() } // GUI Scale -static void calulate_gui_scale() +static void calculate_gui_scale() { int width = Minecraft::width; @@ -207,6 +207,8 @@ static EM_BOOL main_loop(double time, void *user_data) } } +extern bool g_bIsMenuBackgroundAvailable; // client/gui/Screen.cpp + // Main int main(int argc, char *argv[]) { @@ -235,6 +237,8 @@ int main(int argc, char *argv[]) Minecraft::height = std::stoi(argv[2]); #endif + g_bIsMenuBackgroundAvailable = XPL_ACCESS("assets/gui/background/panorama_0.png", 0) == 0; + // Create Window window = SDL_CreateWindow("ReMinecraftPE", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, Minecraft::width, Minecraft::height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); if (!window) diff --git a/platforms/windows/main.cpp b/platforms/windows/main.cpp index a4e76c9..bb7f78c 100644 --- a/platforms/windows/main.cpp +++ b/platforms/windows/main.cpp @@ -70,6 +70,8 @@ void UpdateMouse() Mouse::_y = g_MousePosY; } +extern bool g_bIsMenuBackgroundAvailable; + LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { switch (iMsg) @@ -218,6 +220,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLin wc.lpszMenuName = NULL; wc.lpszClassName = g_WindowClassName; + g_bIsMenuBackgroundAvailable = XPL_ACCESS("assets/gui/background/panorama_0.png", 0) == 0; + RECT wr = { 0,0, g_AppPlatform.getScreenWidth(), g_AppPlatform.getScreenHeight() }; AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, false); int w = wr.right - wr.left; diff --git a/source/Minecraft.cpp b/source/Minecraft.cpp index 64bf3f6..b9837ee 100644 --- a/source/Minecraft.cpp +++ b/source/Minecraft.cpp @@ -84,6 +84,8 @@ Minecraft::Minecraft() : m_gui(this) m_bHasQueuedScreen = false; m_pQueuedScreen = nullptr; m_licenseID = -2; + m_fLastUpdated = 0; + m_fDeltaTime = 0; #ifndef ORIGINAL_CODE m_pTurnInput = new MouseTurnInput(this); @@ -665,6 +667,10 @@ void Minecraft::update() #endif m_pGameRenderer->render(m_timer.field_18); + + double time = double(getTimeS()); + m_fDeltaTime = time - m_fLastUpdated; + m_fLastUpdated = time; } void Minecraft::init() diff --git a/source/Minecraft.hpp b/source/Minecraft.hpp index 2b066ad..8ae0b69 100644 --- a/source/Minecraft.hpp +++ b/source/Minecraft.hpp @@ -127,5 +127,8 @@ public: Screen* m_pQueuedScreen; int m_licenseID; ItemInstance m_CurrItemInstance; + + // in 0.8. Offset 3368 + double m_fDeltaTime, m_fLastUpdated; }; diff --git a/source/client/gui/Screen.cpp b/source/client/gui/Screen.cpp index 0dbe047..98f37b0 100644 --- a/source/client/gui/Screen.cpp +++ b/source/client/gui/Screen.cpp @@ -115,6 +115,109 @@ void Screen::charInput(char chr) textInput->charPressed(chr); } +static const char* g_panoramaList[] = +{ + "gui/background/panorama_0.png", + "gui/background/panorama_1.png", + "gui/background/panorama_2.png", + "gui/background/panorama_3.png", + "gui/background/panorama_4.png", + "gui/background/panorama_5.png", +}; + +static float g_panoramaAngle = 0.0f; +bool g_bIsMenuBackgroundAvailable = false; + +void Screen::renderMenuBackground(float f) +{ + if (!g_bIsMenuBackgroundAvailable) + { + renderDirtBackground(0); + return; + } + + g_panoramaAngle += float(30.0 * m_pMinecraft->m_fDeltaTime); + + // not in 0.8 + glDisable(GL_BLEND); + glDisable(GL_CULL_FACE); + glDisable(GL_DEPTH_TEST); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + gluPerspective(120.0f, 1.0f, 0.05f, 10.0f); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + glRotatef(180.0f, 1.0f, 0.0f, 0.0f); + glRotatef(Mth::sin((f + g_panoramaAngle) / 400.0f) * 25.0f + 20.0f, 1.0f, 0.0f, 0.0f); + glRotatef(-0.1f * (f + g_panoramaAngle), 0.0f, 1.0f, 0.0f); + + for (int i = 0; i < 6; i++) + { + glPushMatrix(); + + float xm = 0.0f, ym = 0.0f, ang = 0.0f; + switch (i) + { + case 1: + ang = 90.0f; + xm = 0.0f; + ym = 1.0f; + break; + case 2: + ang = 180.0f; + xm = 0.0f; + ym = 1.0f; + break; + case 3: + ang = -90.0f; + xm = 0.0f; + ym = 1.0f; + break; + case 4: + ang = 90.0f; + ym = 0.0f; + xm = 1.0f; + break; + case 5: + ang = -90.0f; + ym = 0.0f; + xm = 1.0f; + break; + } + + glRotatef(ang, xm, ym, 0.0f); + + m_pMinecraft->m_pTextures->setSmoothing(true); + m_pMinecraft->m_pTextures->setClampToEdge(true); + m_pMinecraft->m_pTextures->loadAndBindTexture(std::string(g_panoramaList[i])); + m_pMinecraft->m_pTextures->setSmoothing(false); + m_pMinecraft->m_pTextures->setClampToEdge(false); + + Tesselator& t = Tesselator::instance; + t.begin(); + t.vertexUV(-1.0f, -1.0f, 1.0f, 0.0f, 0.0f); + t.vertexUV(+1.0f, -1.0f, 1.0f, 1.0f, 0.0f); + t.vertexUV(+1.0f, +1.0f, 1.0f, 1.0f, 1.0f); + t.vertexUV(-1.0f, +1.0f, 1.0f, 0.0f, 1.0f); + t.draw(); + + glPopMatrix(); + } + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glEnable(GL_BLEND); + glEnable(GL_CULL_FACE); + glEnable(GL_DEPTH_TEST); + + fillGradient(0, 0, m_width, m_height, 0x89000000, 0x89FFFFFF); +} + void Screen::mouseClicked(int xPos, int yPos, int d) // d = clicked? { if (!d) return; @@ -167,6 +270,7 @@ void Screen::render(int xPos, int yPos, float unused) void Screen::tick() { + g_panoramaAngle++; } void Screen::removed() @@ -255,10 +359,10 @@ void Screen::renderDirtBackground(int unk) Tesselator& t = Tesselator::instance; t.begin(); t.color(0x404040); - t.vertexUV(0.0f, float(m_height), 0, 0, float(unk) + float(m_height) / 32.0f); - t.vertexUV(float(m_width), float(m_height), 0, float(unk) + float(m_width) / 32.0f, float(unk) + float(m_height) / 32.0f); - t.vertexUV(float(m_width), 0, 0, float(unk) + float(m_width) / 32.0f, 0); - t.vertexUV(0.0f, 0, 0, 0, 0); + t.vertexUV(0.0f, float(m_height), 0, 0, float(unk) + float(m_height) / 32.0f); + t.vertexUV(float(m_width), float(m_height), 0, float(m_width) / 32.0f, float(unk) + float(m_height) / 32.0f); + t.vertexUV(float(m_width), 0, 0, float(m_width) / 32.0f, float(unk) + 0.0f); + t.vertexUV(0.0f, 0, 0, 0, float(unk) + 0.0f); t.draw(); } diff --git a/source/client/gui/Screen.hpp b/source/client/gui/Screen.hpp index 7af0453..2b9967f 100644 --- a/source/client/gui/Screen.hpp +++ b/source/client/gui/Screen.hpp @@ -46,6 +46,9 @@ public: virtual void keyPressed(int); virtual void charInput(char); + // ported from 0.8 + virtual void renderMenuBackground(float f); + public: int m_width; int m_height; diff --git a/source/client/gui/screens/OptionsScreen.cpp b/source/client/gui/screens/OptionsScreen.cpp index 26f9994..8092dda 100644 --- a/source/client/gui/screens/OptionsScreen.cpp +++ b/source/client/gui/screens/OptionsScreen.cpp @@ -140,7 +140,10 @@ void OptionsScreen::init() void OptionsScreen::render(int a, int b, float c) { - renderBackground(); + if (!m_pMinecraft->isLevelGenerated()) + renderMenuBackground(c); + + fillGradient(0, 0, m_width, m_height, 0xC0101010, 0xD0101010); if (m_pMinecraft->m_pPlatform->getUserInputStatus() >= 0) { diff --git a/source/client/gui/screens/StartMenuScreen.cpp b/source/client/gui/screens/StartMenuScreen.cpp index ea4905b..7c4f7a7 100644 --- a/source/client/gui/screens/StartMenuScreen.cpp +++ b/source/client/gui/screens/StartMenuScreen.cpp @@ -455,7 +455,8 @@ bool StartMenuScreen::isInGameScreen() void StartMenuScreen::render(int a, int b, float c) { - renderBackground(); + //renderBackground(); + renderMenuBackground(c); Textures* tx = m_pMinecraft->m_pTextures; @@ -521,6 +522,7 @@ void StartMenuScreen::render(int a, int b, float c) void StartMenuScreen::tick() { + Screen::tick(); _updateLicense(); } diff --git a/source/client/network/ServerSideNetworkHandler.cpp b/source/client/network/ServerSideNetworkHandler.cpp index b1f628f..a15d7b4 100644 --- a/source/client/network/ServerSideNetworkHandler.cpp +++ b/source/client/network/ServerSideNetworkHandler.cpp @@ -419,9 +419,25 @@ void ServerSideNetworkHandler::commandTime(OnlinePlayer* player, const std::vect if (!m_pLevel) return; + if (!parms.empty()) + { + int t = 0; + if (!sscanf(parms[0].c_str(), "%d", &t)) + { + sendMessage(player, "Usage: /time [new time value]"); + return; + } + + m_pLevel->setTime(t); + sendMessage(player, "Time has been set to " + parms[0]); + + return; + } + std::stringstream ss; ss << "In-game time: "; ss << m_pLevel->getTime(); + ss << ". Day " << m_pLevel->getTime() / 24000; sendMessage(player, ss.str()); } diff --git a/source/client/renderer/Textures.hpp b/source/client/renderer/Textures.hpp index 4a238a3..14ed7ee 100644 --- a/source/client/renderer/Textures.hpp +++ b/source/client/renderer/Textures.hpp @@ -42,6 +42,18 @@ public: void addDynamicTexture(DynamicTexture* pTexture); Texture* getTemporaryTextureData(GLuint id); + // set smoothing for next texture to be loaded + void setSmoothing(bool b) + { + field_39 = b; + } + + // set smoothing for next texture to be loaded + void setClampToEdge(bool b) + { + field_38 = b; + } + Textures(Options*, AppPlatform*); ~Textures();