mirror of
https://github.com/celisej567/mcpe.git
synced 2026-09-11 20:11:18 +03:00
* Visual Studio Project Overhaul + Cleanup * SDL2 project for Windows * Re-added game client icon to SDL2 code * Renamed "AppPlatform_windows" to "AppPlatform_win32" (this is the name of the Windows API and is not representative of the architecture type) * Renamed "LoggerWindows" to "LoggerWin32" * Renamed "SoundSystemWindows to "SoundSystemDS" (DirectSound). This may be used for the 360, so it wouldn't really be Windows-specific then. * Moved "ClientSideNetworkHandler" from "network" to "client/network". We don't need it being compiled for the server if the client's the only thing that needs it. * I wonder if this still works on macOS... * Bugfixes & Fixed for macOS * Options::savePropertiesToFile Logging Bugfix * Silence Winsock Deprecation Warnings in RakNet * VS Project Improvements - Replaced 50 billion relative paths with $(MC_ROOT) - Added $(RAKNET_PATH) variable to override RakNet location - Re-added gitignore for .vcxproj.user files - Added debugging config to Directory.Builds.props - Slimmed down project configurations for SDL2 * VS Project Config Bugfixes - Fixed RakNet header path for additional includes * RakNet Target for XCode * XCode Project Config Fixes * Packet logging * Network VS Project Filter Fix * Fix RakNet Packet ID Length We previously didn't have consistency between old and new C++ regarding PacketType enum length. Now we do. This is required or else it completely breaks networking between the versions. * Additional RakNet Error Handling * Disable packet logging * * Fix CMakeLists.txt This reflects the relocation of ClientSideNetworkHandler.cpp. * * Also add renderer/GL/GL.cpp to the CMakeLists.txt * * Replace libpng with stb_image * * Fix buggy water behavior. * * Put the CMakeLists of the SDL project in debug mode * Visual Studio 2010 Support * * Change the SdlIoCallbacks from an array to a single member. This fixes compilation of the sdl2 target on VS. * * Fix missing _error label. * Revert "* Fix missing _error label." This reverts commit 99a057fc84049a16c864bd840fb439a008af5c74. * Revert "* Replace libpng with stb_image" * info_updateGame Tiles --------- Co-authored-by: Brent Da Mage <BrentDaMage@users.noreply.github.com> Co-authored-by: iProgramInCpp <iprogramincpp@gmail.com>
241 lines
5.6 KiB
C++
241 lines
5.6 KiB
C++
/********************************************************************
|
|
Minecraft: Pocket Edition - Decompilation Project
|
|
Copyright (C) 2023 iProgramInCpp
|
|
|
|
The following code is licensed under the BSD 1 clause license.
|
|
SPDX-License-Identifier: BSD-1-Clause
|
|
********************************************************************/
|
|
|
|
#include <cstdarg>
|
|
#include <WindowsX.h>
|
|
|
|
#include "thirdparty/GL/GL.hpp"
|
|
#include "compat/KeyCodes.hpp"
|
|
|
|
#include "client/app/App.hpp"
|
|
#include "client/app/NinecraftApp.hpp"
|
|
|
|
#include "AppPlatform_win32.hpp"
|
|
|
|
LPCTSTR g_WindowClassName = TEXT("MCPEClass");
|
|
|
|
AppPlatform_win32 g_AppPlatform;
|
|
NinecraftApp* g_pApp;
|
|
|
|
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
switch (iMsg)
|
|
{
|
|
default:
|
|
return DefWindowProc(hWnd, iMsg, wParam, lParam);
|
|
|
|
case WM_SETFOCUS:
|
|
case WM_KILLFOCUS:
|
|
{
|
|
g_AppPlatform.updateFocused(iMsg == WM_SETFOCUS);
|
|
break;
|
|
}
|
|
|
|
case WM_LBUTTONUP:
|
|
case WM_LBUTTONDOWN:
|
|
case WM_RBUTTONUP:
|
|
case WM_RBUTTONDOWN:
|
|
case WM_MBUTTONUP:
|
|
case WM_MBUTTONDOWN:
|
|
case WM_MOUSEMOVE:
|
|
case WM_MOUSEWHEEL:
|
|
{
|
|
Mouse::ButtonType buttonType = AppPlatform_win32::GetMouseButtonType(iMsg);
|
|
Mouse::ButtonState buttonState = AppPlatform_win32::GetMouseButtonState(iMsg, wParam);
|
|
int posX, posY;
|
|
if (iMsg == WM_MOUSEMOVE)
|
|
{
|
|
posX = GET_X_LPARAM(lParam);
|
|
posY = GET_Y_LPARAM(lParam);
|
|
}
|
|
else
|
|
{
|
|
posX = Mouse::getX();
|
|
posY = Mouse::getY();
|
|
}
|
|
Mouse::feed(buttonType, buttonState, posX, posY);
|
|
break;
|
|
}
|
|
|
|
case WM_SIZE:
|
|
{
|
|
UINT width = LOWORD(lParam);
|
|
UINT height = HIWORD(lParam);
|
|
|
|
Minecraft::width = width;
|
|
Minecraft::height = height;
|
|
Minecraft::setGuiScaleMultiplier(1.0f); // assume no meddling with the DPI stuff
|
|
|
|
g_AppPlatform.setScreenSize(width, height);
|
|
|
|
if (g_pApp)
|
|
g_pApp->sizeUpdate(width, height);
|
|
|
|
break;
|
|
}
|
|
|
|
|
|
case WM_KEYUP:
|
|
case WM_KEYDOWN:
|
|
{
|
|
Keyboard::KeyState state = AppPlatform_win32::GetKeyState(iMsg);
|
|
Keyboard::feed(state, int(wParam));
|
|
|
|
if (wParam == VK_SHIFT)
|
|
g_AppPlatform.setShiftPressed(state == Keyboard::KeyState::DOWN);
|
|
|
|
break;
|
|
}
|
|
|
|
case WM_CHAR:
|
|
{
|
|
if (lParam & (1 << 31))
|
|
break;
|
|
|
|
if (wParam >= '~' && wParam < ' ')
|
|
break;
|
|
|
|
g_pApp->handleCharInput(char(wParam));
|
|
break;
|
|
}
|
|
|
|
case WM_DESTROY:
|
|
PostQuitMessage(0);
|
|
return 0;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
extern bool g_bIsMenuBackgroundAvailable; // client/gui/Screen.cpp
|
|
extern bool g_bAreCloudsAvailable; // client/renderer/LevelRenderer.cpp
|
|
|
|
void CheckOptionalTextureAvailability()
|
|
{
|
|
// TODO: These should be inside of an initialized "Minecraft" instance rather than the global namespace
|
|
// Optional features that you really should be able to get away with not including.
|
|
g_bIsMenuBackgroundAvailable = XPL_ACCESS("assets/gui/background/panorama_0.png", 0) == 0;
|
|
g_bAreCloudsAvailable = XPL_ACCESS("assets/environment/clouds.png", 0) == 0;
|
|
}
|
|
|
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
|
|
{
|
|
#if defined(_DEBUG) && defined(MOD_POPOUT_CONSOLE)
|
|
AllocConsole();
|
|
FILE* ostream;
|
|
FILE* istream;
|
|
freopen_s(&ostream, "CONOUT$", "w", stdout);
|
|
freopen_s(&istream, "CONIN$", "r", stdin);
|
|
SetConsoleTitle("ReMinecraftPE Debug Console");
|
|
#endif
|
|
|
|
SetInstance(hInstance);
|
|
|
|
// register the window class:
|
|
WNDCLASS wc;
|
|
wc.style = CS_OWNDC;
|
|
wc.lpfnWndProc = WndProc;
|
|
wc.cbClsExtra = 0;
|
|
wc.cbWndExtra = 0;
|
|
wc.hInstance = hInstance;
|
|
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
|
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
|
wc.lpszMenuName = NULL;
|
|
wc.lpszClassName = g_WindowClassName;
|
|
|
|
CheckOptionalTextureAvailability();
|
|
|
|
RECT wr = { 0,0, g_AppPlatform.getScreenWidth(), g_AppPlatform.getScreenHeight() };
|
|
AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, false);
|
|
int w = wr.right - wr.left;
|
|
int h = wr.bottom - wr.top;
|
|
|
|
const char* windowTitle = g_AppPlatform.getWindowTitle();
|
|
// Dumb Unicode bullshit
|
|
//LPTSTR windowTitle;
|
|
//mbstowcs(&windowTitle, windowTitleStr, 255);
|
|
|
|
if (!RegisterClass(&wc))
|
|
{
|
|
MessageBox(NULL, TEXT("Could not register Minecraft class"), windowTitle, MB_ICONERROR | MB_OK);
|
|
return 1;
|
|
}
|
|
|
|
HWND hWnd = CreateWindowEx(0, g_WindowClassName, windowTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, w, h, NULL, NULL, hInstance, g_pApp);
|
|
|
|
CenterWindow(hWnd);
|
|
ShowWindow(hWnd, nCmdShow);
|
|
SetHWND(hWnd);
|
|
|
|
HDC hDC; HGLRC hRC;
|
|
// enable OpenGL for the window
|
|
EnableOpenGL(hWnd, &hDC, &hRC);
|
|
|
|
xglInit();
|
|
|
|
if (!xglInitted())
|
|
{
|
|
const char* const GL_ERROR_MSG = "Error initializing GL extensions. OpenGL 2.0 or later is required. Update your graphics drivers!";
|
|
LOG_E(GL_ERROR_MSG);
|
|
MessageBoxA(GetHWND(), GL_ERROR_MSG, "OpenGL Error", MB_OK);
|
|
|
|
goto _cleanup;
|
|
}
|
|
|
|
xglSwapIntervalEXT(1);
|
|
|
|
g_pApp = new NinecraftApp;
|
|
g_pApp->m_pPlatform = &g_AppPlatform;
|
|
g_pApp->m_externalStorageDir = ".";
|
|
|
|
// initialize the app
|
|
g_pApp->init();
|
|
g_pApp->sizeUpdate(Minecraft::width, Minecraft::height);
|
|
|
|
while (!g_pApp->wantToQuit())
|
|
{
|
|
MSG sMsg;
|
|
if (PeekMessage(&sMsg, NULL, 0, 0, PM_REMOVE))
|
|
{
|
|
if (sMsg.message == WM_QUIT)
|
|
{
|
|
g_pApp->quit();
|
|
}
|
|
else
|
|
{
|
|
TranslateMessage(&sMsg);
|
|
DispatchMessage(&sMsg);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// update our stuff here:
|
|
g_pApp->update();
|
|
|
|
// note: NinecraftApp would have done this with eglSwapBuffers, but I'd rather do it here:
|
|
SwapBuffers(hDC);
|
|
}
|
|
}
|
|
|
|
_cleanup:
|
|
g_pApp->saveOptions();
|
|
|
|
// disable OpenGL for the window
|
|
DisableOpenGL(hWnd, hDC, hRC);
|
|
|
|
// destroy the window explicitly, since we ignored the WM_QUIT message
|
|
DestroyWindow(hWnd);
|
|
|
|
hWnd = NULL;
|
|
SetHWND(NULL);
|
|
|
|
delete g_pApp;
|
|
|
|
return 0;
|
|
}
|