diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 939e04509..0e582f64d 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -324,7 +324,7 @@ void Minecraft::init() { // if (options.languageCode != null) { // Language.getInstance().loadLanguage(options.languageCode); // // - //font.setEnforceUnicodeSheet("true".equalsIgnoreCase(I18n.get("language.enforceUnicode"))); + // font.setEnforceUnicodeSheet("true".equalsIgnoreCase(I18n.get("language.enforceUnicode"))); // font.setEnforceUnicodeSheet(Language.getInstance().isSelectedLanguageIsUnicode()); // font.setBidirectional(Language.isBidirectional(options.languageCode)); // } @@ -507,7 +507,7 @@ File Minecraft::getWorkingDirectory(const std::wstring& applicationName) { } // #elif defined(_MACOS) // workingDirectory = new File(userHome, "Library/Application -//Support/" + applicationName); +// Support/" + applicationName); #else workingDirectory = new File(userHome, applicationName + L'/'); #endif @@ -1079,7 +1079,7 @@ std::shared_ptr Minecraft::createExtraLocalPlayer( // loaded "Mass Effect World". Move this check to // ClientConnection::handleMovePlayer // // 4J-PB - can't call this when this function is called - //from the qnet thread (GetGameStarted will be false) + // from the qnet thread (GetGameStarted will be false) // if(app.GetGameStarted()) // { // ui.CloseUIScenes(idx); @@ -1839,16 +1839,16 @@ void Minecraft::run_middle() { timer->advanceTime(); } - //__int64 beforeTickTime = System::nanoTime(); - for (int i = 0; i < timer->ticks; i++) - { - bool bLastTimerTick = ( i == ( timer->ticks - 1 ) ); - // 4J-PB - the tick here can run more than once, and this is a problem for our input, which would see the a key press twice with the same time - let's tick the inputmanager again - if(i!=0) - { - InputManager.Tick(); - app.HandleButtonPresses(); - } + //__int64 beforeTickTime = System::nanoTime(); + for (int i = 0; i < timer->ticks; i++) { + bool bLastTimerTick = (i == (timer->ticks - 1)); + // 4J-PB - the tick here can run more than once, and this is a + // problem for our input, which would see the a key press twice + // with the same time - let's tick the inputmanager again + if (i != 0) { + InputManager.Tick(); + app.HandleButtonPresses(); + } ticks++; // try { // 4J - try/catch removed @@ -1913,19 +1913,20 @@ void Minecraft::run_middle() { } } - // } catch (LevelConflictException e) { - // this.level = null; - // setLevel(null); - // setScreen(new LevelConflictScreen()); - // } -// SparseLightStorage::tick(); // 4J added -// CompressedTileStorage::tick(); // 4J added -// SparseDataStorage::tick(); // 4J added - } - //__int64 tickDuraction = System::nanoTime() - beforeTickTime; - MemSect(31); - checkGlError(L"Pre render"); - MemSect(0); + // } catch (LevelConflictException e) { + // this.level = null; + // setLevel(null); + // setScreen(new LevelConflictScreen()); + // } + // SparseLightStorage::tick(); + // // 4J added CompressedTileStorage::tick(); // 4J added + // SparseDataStorage::tick(); + // // 4J added + } + //__int64 tickDuraction = System::nanoTime() - beforeTickTime; + MemSect(31); + checkGlError(L"Pre render"); + MemSect(0); TileRenderer::fancy = options->fancyGraphics; @@ -1951,20 +1952,17 @@ void Minecraft::run_middle() { if (player != NULL && player->isInWall()) player->SetThirdPersonView(0); - if (!noRender) - { - bool bFirst = true; - int iPrimaryPad=ProfileManager.GetPrimaryPad(); - for( int i = 0; i < XUSER_MAX_COUNT; i++ ) - { - - if( setLocalPlayerIdx(i) ) - { - PIXBeginNamedEvent(0,"Game render player idx %d",i); - RenderManager.StateSetViewport((C4JRender::eViewportType)player->m_iScreenSection); - gameRenderer->render(timer->a, bFirst); - bFirst = false; - PIXEndNamedEvent(); + if (!noRender) { + bool bFirst = true; + int iPrimaryPad = ProfileManager.GetPrimaryPad(); + for (int i = 0; i < XUSER_MAX_COUNT; i++) { + if (setLocalPlayerIdx(i)) { + PIXBeginNamedEvent(0, "Game render player idx %d", i); + RenderManager.StateSetViewport( + (C4JRender::eViewportType)player->m_iScreenSection); + gameRenderer->render(timer->a, bFirst); + bFirst = false; + PIXEndNamedEvent(); if (i == iPrimaryPad) { #ifdef __ORBIS__ @@ -1974,39 +1972,42 @@ void Minecraft::run_middle() { // point in the frame to do it. RenderManager.InternalScreenCapture(); #endif - // check to see if we need to capture a screenshot for the save game thumbnail - switch(app.GetXuiAction(i)) - { - case eAppAction_ExitWorldCapturedThumbnail: - case eAppAction_SaveGameCapturedThumbnail: - case eAppAction_AutosaveSaveGameCapturedThumbnail: - // capture the save thumbnail - app.CaptureSaveThumbnail(); - break; - } - } - } - } + // check to see if we need to capture a screenshot + // for the save game thumbnail + switch (app.GetXuiAction(i)) { + case eAppAction_ExitWorldCapturedThumbnail: + case eAppAction_SaveGameCapturedThumbnail: + case eAppAction_AutosaveSaveGameCapturedThumbnail: + // capture the save thumbnail + app.CaptureSaveThumbnail(); + break; + } + } + } + } -// #ifdef __linux__ -// // On Linux, Iggy Flash UI is not available. If no players were rendered -// // (menu / title-screen state), call GameRenderer directly so mc->screen draws. -// if (bFirst) -// { -// localPlayerIdx = 0; -// RenderManager.StateSetViewport(C4JRender::VIEWPORT_TYPE_FULLSCREEN); -// gameRenderer->render(timer->a, true); -// } -// #endif +#ifdef _ENABLEIGGY + // On Linux, Iggy Flash UI is not available. If no players were + // rendered (menu / title-screen state), call GameRenderer + // directly so mc->screen draws. + if (bFirst) { + localPlayerIdx = 0; + RenderManager.StateSetViewport( + C4JRender::VIEWPORT_TYPE_FULLSCREEN); + gameRenderer->render(timer->a, true); + } +#endif - - // If there's an unoccupied quadrant, then clear that to black - if( unoccupiedQuadrant > -1 ) - { - // render a logo - RenderManager.StateSetViewport((C4JRender::eViewportType)(C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_LEFT + unoccupiedQuadrant)); - glClearColor(0, 0, 0, 0); - glClear(GL_COLOR_BUFFER_BIT); + // If there's an unoccupied quadrant, then clear that to black + if (unoccupiedQuadrant > -1) { + // render a logo + RenderManager.StateSetViewport(( + C4JRender:: + eViewportType)(C4JRender:: + VIEWPORT_TYPE_QUADRANT_TOP_LEFT + + unoccupiedQuadrant)); + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT); ui.SetEmptyQuadrantLogo( C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_LEFT + @@ -2025,19 +2026,19 @@ void Minecraft::run_middle() { } } #endif - } - glFlush(); + } + glFlush(); - /* 4J - removed - if (!Display::isActive()) - { - if (fullscreen) - { - this->toggleFullScreen(); - } - Sleep(10); - } - */ + /* 4J - removed + if (!Display::isActive()) + { + if (fullscreen) + { + this->toggleFullScreen(); + } + Sleep(10); + } + */ /* 4J - removed if (!Display::isActive()) @@ -2140,11 +2141,7 @@ void Minecraft::run_middle() { LeaveCriticalSection(&m_setLevelCS); } - -void Minecraft::run_end() -{ - destroy(); -} +void Minecraft::run_end() { destroy(); } void Minecraft::renderFpsMeter(__int64 tickTime) { int nsPer60Fps = 1000000000l / 60; @@ -4602,8 +4599,8 @@ void Minecraft::main() { // if(Item::items[i] != NULL) // { // wprintf(L"%ls\n", - //i, app.GetString( Item::items[i]->getDescriptionId() )); + // value=\"%d\">%ls\n", + // i, app.GetString( Item::items[i]->getDescriptionId() )); // } //} @@ -4614,8 +4611,8 @@ void Minecraft::main() { // if(Tile::tiles[i] != NULL) // { // wprintf(L"%ls\n", - //i, app.GetString( Tile::tiles[i]->getDescriptionId() )); + // value=\"%d\">%ls\n", + // i, app.GetString( Tile::tiles[i]->getDescriptionId() )); // } // } //__debugbreak(); @@ -4710,9 +4707,10 @@ int Minecraft::maxSupportedTextureSize() { // for (int texSize = 16384; texSize > 0; texSize >>= 1) { // GL11.glTexImage2D(GL11.GL_PROXY_TEXTURE_2D, 0, GL11.GL_RGBA, texSize, - //texSize, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); final - //int width = GL11.glGetTexLevelParameteri(GL11.GL_PROXY_TEXTURE_2D, 0, - //GL11.GL_TEXTURE_WIDTH); if (width != 0) { return texSize; + // texSize, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, (ByteBuffer) null); + // final int width = GL11.glGetTexLevelParameteri(GL11.GL_PROXY_TEXTURE_2D, + // 0, GL11.GL_TEXTURE_WIDTH); if (width != 0) { return + // texSize; // } // } // return -1; @@ -4722,7 +4720,7 @@ void Minecraft::delayTextureReload() { reloadTextures = true; } __int64 Minecraft::currentTimeMillis() { return System::currentTimeMillis(); //(Sys.getTime() * 1000) / - //Sys.getTimerResolution(); + // Sys.getTimerResolution(); } /*void Minecraft::handleMouseDown(int button, bool down) diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_Intro.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_Intro.cpp index cd516ad6f..ce3b01c1a 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_Intro.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_Intro.cpp @@ -2,12 +2,19 @@ #include "UI.h" #include "UIScene_Intro.h" +#ifndef _ENABLEIGGY +static int s_introTickCount = 0; +#endif + UIScene_Intro::UIScene_Intro(int iPad, void *initData, UILayer *parentLayer) : UIScene(iPad, parentLayer) { // Setup all the Iggy references we need for this scene initialiseMovie(); m_bIgnoreNavigate = false; m_bAnimationEnded = false; +#ifndef _ENABLEIGGY + s_introTickCount = 0; +#endif bool bSkipESRB = false; #if defined(__PS3__) || defined(__ORBIS__) || defined(__PSVITA__) @@ -163,3 +170,22 @@ void UIScene_Intro::handleGainFocus(bool navBack) ui.NavigateToScene(0,eUIScene_MainMenu); } } + +#ifndef _ENABLEIGGY +void UIScene_Intro::tick() +{ + // Call base tick first (processes Iggy ticking) + UIScene::tick(); + + // Auto-skip the intro after 60 ticks (~2 seconds at 30fps) + // since we have no SWF renderer to play the intro animation + s_introTickCount++; + if(s_introTickCount == 60 && !m_bIgnoreNavigate) + { + fprintf(stderr, "[Linux] Auto-skipping intro -> MainMenu after %d ticks\n", s_introTickCount); + m_bIgnoreNavigate = true; + // Skip straight to MainMenu, bypassing SaveMessage (no SWF interaction possible) + ui.NavigateToScene(0, eUIScene_MainMenu); + } +} +#endif \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_Intro.h b/Minecraft.Client/Platform/Common/UI/UIScene_Intro.h index e1c492a8a..45da2ed2d 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_Intro.h +++ b/Minecraft.Client/Platform/Common/UI/UIScene_Intro.h @@ -49,4 +49,7 @@ public: virtual void handleTouchInput(unsigned int iPad, S32 x, S32 y, int iId, bool bPressed, bool bRepeat, bool bReleased); #endif +#ifndef _ENABLEIGGY + virtual void tick(); +#endif }; diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_MainMenu.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_MainMenu.cpp index 18f7af101..092ff90fb 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_MainMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_MainMenu.cpp @@ -1806,6 +1806,20 @@ void UIScene_MainMenu::tick() { UIScene::tick(); +#ifndef _ENABLEIGGY + { + static int s_mainMenuTickCount = 0; + s_mainMenuTickCount++; + if(s_mainMenuTickCount % 60 == 1) { fprintf(stderr, "[MM] tick %d\n", s_mainMenuTickCount); fflush(stderr); } + if(s_mainMenuTickCount == 90) // ~3 seconds at 30fps + { + fprintf(stderr, "[Linux] Auto-starting trial world from MainMenu after %d ticks\n", s_mainMenuTickCount); + LoadTrial(); + return; + } + } +#endif + #if defined(__PS3__) || defined (__ORBIS__) || defined(__PSVITA__) if(m_bLaunchFullVersionPurchase) { diff --git a/Minecraft.Client/Platform/Linux/Linux_Minecraft.cpp b/Minecraft.Client/Platform/Linux/Linux_Minecraft.cpp index c25f86e45..7d16d9af0 100644 --- a/Minecraft.Client/Platform/Linux/Linux_Minecraft.cpp +++ b/Minecraft.Client/Platform/Linux/Linux_Minecraft.cpp @@ -4,7 +4,7 @@ #include "../../../Minecraft.World/Platform/stdafx.h" #include -//#include +// #include #include #if defined(__linux__) && defined(__GLIBC__) #include @@ -12,20 +12,29 @@ #include static void sigsegv_handler(int sig) { const char msg[] = "\n=== SIGNAL CAUGHT: "; - write(STDERR_FILENO, msg, sizeof(msg)-1); + write(STDERR_FILENO, msg, sizeof(msg) - 1); char signum[8]; int len = 0; int s = sig; - if (s == 0) { signum[len++] = '0'; } - else { char tmp[8]; int tl = 0; while(s > 0) { tmp[tl++] = '0' + (s%10); s /= 10; } for(int i = tl-1; i >= 0; i--) signum[len++] = tmp[i]; } + if (s == 0) { + signum[len++] = '0'; + } else { + char tmp[8]; + int tl = 0; + while (s > 0) { + tmp[tl++] = '0' + (s % 10); + s /= 10; + } + for (int i = tl - 1; i >= 0; i--) signum[len++] = tmp[i]; + } write(STDERR_FILENO, signum, len); const char msg1b[] = " ===\n"; - write(STDERR_FILENO, msg1b, sizeof(msg1b)-1); - void *array[64]; + write(STDERR_FILENO, msg1b, sizeof(msg1b) - 1); + void* array[64]; int size = backtrace(array, 64); backtrace_symbols_fd(array, size, STDERR_FILENO); const char msg2[] = "=== END BACKTRACE ===\n"; - write(STDERR_FILENO, msg2, sizeof(msg2)-1); + write(STDERR_FILENO, msg2, sizeof(msg2) - 1); _exit(139); } #endif @@ -49,10 +58,10 @@ static void sigsegv_handler(int sig) { #include "../../../Minecraft.World/Util/ThreadName.h" #include "../../GameState/StatsCounter.h" #include "../../UI/Screens/ConnectScreen.h" -//#include "../Durango/Social/SocialManager.h" -//#include "../Common/Leaderboards/LeaderboardManager.h" -//#include "../Common/XUI/XUI_Scene_Container.h" -//#include "NetworkManager.h" +// #include "../Durango/Social/SocialManager.h" +// #include "../Common/Leaderboards/LeaderboardManager.h" +// #include "../Common/XUI/XUI_Scene_Container.h" +// #include "NetworkManager.h" #include "../../Rendering/Tesselator.h" #include "../../GameState/Options.h" #include "../Orbis/Sentient/SentientManager.h" @@ -65,195 +74,348 @@ static void sigsegv_handler(int sig) { // #include "../Orbis/Network/Orbis_NPToolkit.h" // #include "../Orbis/Network/SonyVoiceChat_Orbis.h" -#define THEME_NAME "584111F70AAAAAAA" -#define THEME_FILESIZE 2797568 +#define THEME_NAME "584111F70AAAAAAA" +#define THEME_FILESIZE 2797568 -//#define THREE_MB 3145728 // minimum save size (checking for this on a selected device) -//#define FIVE_MB 5242880 // minimum save size (checking for this on a selected device) -//#define FIFTY_TWO_MB (1024*1024*52) // Maximum TCR space required for a save (checking for this on a selected device) -#define FIFTY_ONE_MB (1000000*51) // Maximum TCR space required for a save is 52MB (checking for this on a selected device) +// #define THREE_MB 3145728 // minimum save size (checking for this on a +// selected device) #define FIVE_MB 5242880 // minimum save size (checking for +// this on a selected device) #define FIFTY_TWO_MB (1024*1024*52) // Maximum TCR +// space required for a save (checking for this on a selected device) +#define FIFTY_ONE_MB \ + (1000000 * 51) // Maximum TCR space required for a save is 52MB (checking + // for this on a selected device) -//#define PROFILE_VERSION 3 // new version for the interim bug fix 166 TU -#define NUM_PROFILE_VALUES 5 +// #define PROFILE_VERSION 3 // new version for the interim bug fix 166 TU +#define NUM_PROFILE_VALUES 5 #define NUM_PROFILE_SETTINGS 4 -DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]= -{ - #ifdef _XBOX +DWORD dwProfileSettingsA[NUM_PROFILE_VALUES] = { +#ifdef _XBOX XPROFILE_OPTION_CONTROLLER_VIBRATION, XPROFILE_GAMER_YAXIS_INVERSION, XPROFILE_GAMER_CONTROL_SENSITIVITY, XPROFILE_GAMER_ACTION_MOVEMENT_CONTROL, XPROFILE_TITLE_SPECIFIC1, - #else - 0,0,0,0,0 - #endif +#else + 0, 0, 0, 0, 0 +#endif }; //------------------------------------------------------------------------------------- -// Time Since fAppTime is a float, we need to keep the quadword app time -// as a LARGE_INTEGER so that we don't lose precision after running -// for a long time. +// Time Since fAppTime is a float, we need to keep the quadword app +// time +// as a LARGE_INTEGER so that we don't lose precision after +// running for a long time. //------------------------------------------------------------------------------------- // functions for storing and converting rich presence strings from wchar to utf8 -uint8_t * AddRichPresenceString(int iID); +uint8_t* AddRichPresenceString(int iID); void FreeRichPresenceStrings(); BOOL g_bWidescreen = TRUE; - -void DefineActions(void) -{ - // The app needs to define the actions required, and the possible mappings for these +void DefineActions(void) { + // The app needs to define the actions required, and the possible mappings + // for these // Split into Menu actions, and in-game actions - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_A, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_B, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_X, _360_JOY_BUTTON_X); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_Y, _360_JOY_BUTTON_Y); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OK, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_LT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_A, + _360_JOY_BUTTON_A); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_B, + _360_JOY_BUTTON_B); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_X, + _360_JOY_BUTTON_X); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_Y, + _360_JOY_BUTTON_Y); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_OK, + _360_JOY_BUTTON_A); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_CANCEL, + _360_JOY_BUTTON_B); + InputManager.SetGameJoypadMaps( + MAP_STYLE_0, ACTION_MENU_UP, + _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP); + InputManager.SetGameJoypadMaps( + MAP_STYLE_0, ACTION_MENU_DOWN, + _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN); + InputManager.SetGameJoypadMaps( + MAP_STYLE_0, ACTION_MENU_LEFT, + _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT); + InputManager.SetGameJoypadMaps( + MAP_STYLE_0, ACTION_MENU_RIGHT, + _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_PAGEUP, + _360_JOY_BUTTON_LT); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_PAGEDOWN, + _360_JOY_BUTTON_RT); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_RIGHT_SCROLL, + _360_JOY_BUTTON_RB); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_LEFT_SCROLL, + _360_JOY_BUTTON_LB); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_PAUSEMENU, + _360_JOY_BUTTON_START); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_STICK_PRESS, + _360_JOY_BUTTON_LTHUMB); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_OTHER_STICK_PRESS, + _360_JOY_BUTTON_RTHUMB); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_OTHER_STICK_UP, + _360_JOY_BUTTON_RSTICK_UP); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_OTHER_STICK_DOWN, + _360_JOY_BUTTON_RSTICK_DOWN); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_OTHER_STICK_LEFT, + _360_JOY_BUTTON_RSTICK_LEFT); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, ACTION_MENU_OTHER_STICK_RIGHT, + _360_JOY_BUTTON_RSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_LT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_RT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_RB); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_LB); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_RTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_LTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_JUMP, + _360_JOY_BUTTON_A); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_FORWARD, + _360_JOY_BUTTON_LSTICK_UP); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_BACKWARD, + _360_JOY_BUTTON_LSTICK_DOWN); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_LEFT, + _360_JOY_BUTTON_LSTICK_LEFT); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_RIGHT, + _360_JOY_BUTTON_LSTICK_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_LOOK_LEFT, + _360_JOY_BUTTON_RSTICK_LEFT); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_LOOK_RIGHT, + _360_JOY_BUTTON_RSTICK_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_LOOK_UP, + _360_JOY_BUTTON_RSTICK_UP); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_LOOK_DOWN, + _360_JOY_BUTTON_RSTICK_DOWN); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_USE, + _360_JOY_BUTTON_LT); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_ACTION, + _360_JOY_BUTTON_RT); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_RIGHT_SCROLL, + _360_JOY_BUTTON_RB); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_LEFT_SCROLL, + _360_JOY_BUTTON_LB); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_INVENTORY, + _360_JOY_BUTTON_Y); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_PAUSEMENU, + _360_JOY_BUTTON_START); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_DROP, + _360_JOY_BUTTON_B); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_SNEAK_TOGGLE, + _360_JOY_BUTTON_RTHUMB); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_CRAFTING, + _360_JOY_BUTTON_X); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, + MINECRAFT_ACTION_RENDER_THIRD_PERSON, + _360_JOY_BUTTON_LTHUMB); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_GAME_INFO, + _360_JOY_BUTTON_BACK); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_DPAD_LEFT, + _360_JOY_BUTTON_DPAD_LEFT); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_DPAD_RIGHT, + _360_JOY_BUTTON_DPAD_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_DPAD_UP, + _360_JOY_BUTTON_DPAD_UP); + InputManager.SetGameJoypadMaps(MAP_STYLE_0, MINECRAFT_ACTION_DPAD_DOWN, + _360_JOY_BUTTON_DPAD_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_A, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_B, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_X, _360_JOY_BUTTON_X); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_Y, _360_JOY_BUTTON_Y); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OK, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_LB); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_A, + _360_JOY_BUTTON_A); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_B, + _360_JOY_BUTTON_B); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_X, + _360_JOY_BUTTON_X); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_Y, + _360_JOY_BUTTON_Y); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_OK, + _360_JOY_BUTTON_A); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_CANCEL, + _360_JOY_BUTTON_B); + InputManager.SetGameJoypadMaps( + MAP_STYLE_1, ACTION_MENU_UP, + _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP); + InputManager.SetGameJoypadMaps( + MAP_STYLE_1, ACTION_MENU_DOWN, + _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN); + InputManager.SetGameJoypadMaps( + MAP_STYLE_1, ACTION_MENU_LEFT, + _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT); + InputManager.SetGameJoypadMaps( + MAP_STYLE_1, ACTION_MENU_RIGHT, + _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_PAGEUP, + _360_JOY_BUTTON_LB); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_PAGEDOWN, + _360_JOY_BUTTON_RT); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_RIGHT_SCROLL, + _360_JOY_BUTTON_RB); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_LEFT_SCROLL, + _360_JOY_BUTTON_LB); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_PAUSEMENU, + _360_JOY_BUTTON_START); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_STICK_PRESS, + _360_JOY_BUTTON_LTHUMB); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_OTHER_STICK_PRESS, + _360_JOY_BUTTON_RTHUMB); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_OTHER_STICK_UP, + _360_JOY_BUTTON_RSTICK_UP); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_OTHER_STICK_DOWN, + _360_JOY_BUTTON_RSTICK_DOWN); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_OTHER_STICK_LEFT, + _360_JOY_BUTTON_RSTICK_LEFT); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, ACTION_MENU_OTHER_STICK_RIGHT, + _360_JOY_BUTTON_RSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_RB); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_RT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_LT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_DPAD_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_DPAD_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_LTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_RTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_JUMP, + _360_JOY_BUTTON_RB); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_FORWARD, + _360_JOY_BUTTON_LSTICK_UP); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_BACKWARD, + _360_JOY_BUTTON_LSTICK_DOWN); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_LEFT, + _360_JOY_BUTTON_LSTICK_LEFT); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_RIGHT, + _360_JOY_BUTTON_LSTICK_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_LOOK_LEFT, + _360_JOY_BUTTON_RSTICK_LEFT); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_LOOK_RIGHT, + _360_JOY_BUTTON_RSTICK_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_LOOK_UP, + _360_JOY_BUTTON_RSTICK_UP); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_LOOK_DOWN, + _360_JOY_BUTTON_RSTICK_DOWN); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_USE, + _360_JOY_BUTTON_RT); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_ACTION, + _360_JOY_BUTTON_LT); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_RIGHT_SCROLL, + _360_JOY_BUTTON_DPAD_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_LEFT_SCROLL, + _360_JOY_BUTTON_DPAD_LEFT); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_INVENTORY, + _360_JOY_BUTTON_Y); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_PAUSEMENU, + _360_JOY_BUTTON_START); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_DROP, + _360_JOY_BUTTON_B); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_SNEAK_TOGGLE, + _360_JOY_BUTTON_LTHUMB); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_CRAFTING, + _360_JOY_BUTTON_X); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, + MINECRAFT_ACTION_RENDER_THIRD_PERSON, + _360_JOY_BUTTON_RTHUMB); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_GAME_INFO, + _360_JOY_BUTTON_BACK); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_DPAD_LEFT, + _360_JOY_BUTTON_DPAD_LEFT); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_DPAD_RIGHT, + _360_JOY_BUTTON_DPAD_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_DPAD_UP, + _360_JOY_BUTTON_DPAD_UP); + InputManager.SetGameJoypadMaps(MAP_STYLE_1, MINECRAFT_ACTION_DPAD_DOWN, + _360_JOY_BUTTON_DPAD_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_A, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_B, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_X, _360_JOY_BUTTON_X); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_Y, _360_JOY_BUTTON_Y); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OK, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LB); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_A, + _360_JOY_BUTTON_A); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_B, + _360_JOY_BUTTON_B); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_X, + _360_JOY_BUTTON_X); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_Y, + _360_JOY_BUTTON_Y); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_OK, + _360_JOY_BUTTON_A); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_CANCEL, + _360_JOY_BUTTON_B); + InputManager.SetGameJoypadMaps( + MAP_STYLE_2, ACTION_MENU_UP, + _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP); + InputManager.SetGameJoypadMaps( + MAP_STYLE_2, ACTION_MENU_DOWN, + _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN); + InputManager.SetGameJoypadMaps( + MAP_STYLE_2, ACTION_MENU_LEFT, + _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT); + InputManager.SetGameJoypadMaps( + MAP_STYLE_2, ACTION_MENU_RIGHT, + _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT); + InputManager.SetGameJoypadMaps( + MAP_STYLE_2, ACTION_MENU_PAGEUP, + _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LB); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_PAGEDOWN, + _360_JOY_BUTTON_RT); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_RIGHT_SCROLL, + _360_JOY_BUTTON_RB); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_LEFT_SCROLL, + _360_JOY_BUTTON_LB); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_LT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_RT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_DPAD_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_DPAD_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_LB); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_LTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_JUMP, + _360_JOY_BUTTON_LT); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_FORWARD, + _360_JOY_BUTTON_LSTICK_UP); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_BACKWARD, + _360_JOY_BUTTON_LSTICK_DOWN); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_LEFT, + _360_JOY_BUTTON_LSTICK_LEFT); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_RIGHT, + _360_JOY_BUTTON_LSTICK_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_LOOK_LEFT, + _360_JOY_BUTTON_RSTICK_LEFT); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_LOOK_RIGHT, + _360_JOY_BUTTON_RSTICK_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_LOOK_UP, + _360_JOY_BUTTON_RSTICK_UP); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_LOOK_DOWN, + _360_JOY_BUTTON_RSTICK_DOWN); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_USE, + _360_JOY_BUTTON_RT); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_ACTION, + _360_JOY_BUTTON_A); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_RIGHT_SCROLL, + _360_JOY_BUTTON_DPAD_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_LEFT_SCROLL, + _360_JOY_BUTTON_DPAD_LEFT); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_INVENTORY, + _360_JOY_BUTTON_Y); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_PAUSEMENU, + _360_JOY_BUTTON_START); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_DROP, + _360_JOY_BUTTON_B); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_SNEAK_TOGGLE, + _360_JOY_BUTTON_LB); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_CRAFTING, + _360_JOY_BUTTON_X); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, + MINECRAFT_ACTION_RENDER_THIRD_PERSON, + _360_JOY_BUTTON_LTHUMB); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_GAME_INFO, + _360_JOY_BUTTON_BACK); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_PAUSEMENU, + _360_JOY_BUTTON_START); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_STICK_PRESS, + _360_JOY_BUTTON_LTHUMB); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_OTHER_STICK_PRESS, + _360_JOY_BUTTON_RTHUMB); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_OTHER_STICK_UP, + _360_JOY_BUTTON_RSTICK_UP); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_OTHER_STICK_DOWN, + _360_JOY_BUTTON_RSTICK_DOWN); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_OTHER_STICK_LEFT, + _360_JOY_BUTTON_RSTICK_LEFT); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, ACTION_MENU_OTHER_STICK_RIGHT, + _360_JOY_BUTTON_RSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_DPAD_LEFT, + _360_JOY_BUTTON_DPAD_LEFT); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_DPAD_RIGHT, + _360_JOY_BUTTON_DPAD_RIGHT); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_DPAD_UP, + _360_JOY_BUTTON_DPAD_UP); + InputManager.SetGameJoypadMaps(MAP_STYLE_2, MINECRAFT_ACTION_DPAD_DOWN, + _360_JOY_BUTTON_DPAD_DOWN); } #if 0 @@ -299,29 +461,27 @@ pd3dPP, ppDevice ); } #endif -//#define MEMORY_TRACKING +// #define MEMORY_TRACKING #ifdef MEMORY_TRACKING void ResetMem(); void DumpMem(); void MemPixStuff(); #else -void MemSect(int sect) -{ -} +void MemSect(int sect) {} #endif #ifndef __linux__ -HINSTANCE g_hInst = NULL; -HWND g_hWnd = NULL; -D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL; -D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0; -ID3D11Device* g_pd3dDevice = NULL; -ID3D11DeviceContext* g_pImmediateContext = NULL; -IDXGISwapChain* g_pSwapChain = NULL; +HINSTANCE g_hInst = NULL; +HWND g_hWnd = NULL; +D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL; +D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0; +ID3D11Device* g_pd3dDevice = NULL; +ID3D11DeviceContext* g_pImmediateContext = NULL; +IDXGISwapChain* g_pSwapChain = NULL; ID3D11RenderTargetView* g_pRenderTargetView = NULL; ID3D11DepthStencilView* g_pDepthStencilView = NULL; -ID3D11Texture2D* g_pDepthStencilBuffer = NULL; +ID3D11Texture2D* g_pDepthStencilBuffer = NULL; // // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) @@ -333,20 +493,18 @@ ID3D11Texture2D* g_pDepthStencilBuffer = NULL; // WM_DESTROY - post a quit message and return // // -LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ +LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, + LPARAM lParam) { int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; - switch (message) - { + switch (message) { case WM_COMMAND: - wmId = LOWORD(wParam); + wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: - switch (wmId) - { + switch (wmId) { case IDM_EXIT: DestroyWindow(hWnd); break; @@ -354,43 +512,41 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) return DefWindowProc(hWnd, message, wParam, lParam); } break; - case WM_PAINT: - hdc = BeginPaint(hWnd, &ps); - // TODO: Add any drawing code here... - EndPaint(hWnd, &ps); - break; - case WM_DESTROY: - PostQuitMessage(0); - break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); + case WM_PAINT: + hdc = BeginPaint(hWnd, &ps); + // TODO: Add any drawing code here... + EndPaint(hWnd, &ps); + break; + case WM_DESTROY: + PostQuitMessage(0); + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); } return 0; } - // // FUNCTION: MyRegisterClass() // // PURPOSE: Registers the window class. // -ATOM MyRegisterClass(HINSTANCE hInstance) -{ +ATOM MyRegisterClass(HINSTANCE hInstance) { WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = WndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = hInstance; - wcex.hIcon = LoadIcon(hInstance, "Minecraft"); - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wcex.lpszMenuName = "Minecraft"; - wcex.lpszClassName = "MinecraftClass"; - wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); + wcex.style = CS_HREDRAW | CS_VREDRAW; + wcex.lpfnWndProc = WndProc; + wcex.cbClsExtra = 0; + wcex.cbWndExtra = 0; + wcex.hInstance = hInstance; + wcex.hIcon = LoadIcon(hInstance, "Minecraft"); + wcex.hCursor = LoadCursor(NULL, IDC_ARROW); + wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wcex.lpszMenuName = "Minecraft"; + wcex.lpszClassName = "MinecraftClass"; + wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); return RegisterClassEx(&wcex); } @@ -405,15 +561,14 @@ ATOM MyRegisterClass(HINSTANCE hInstance) // In this function, we save the instance handle in a global variable and // create and display the main program window. // -BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) -{ - g_hInst = hInstance; // Store instance handle in our global variable +BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { + g_hInst = hInstance; // Store instance handle in our global variable g_hWnd = CreateWindow("MinecraftClass", "Minecraft", WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); + CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, + hInstance, NULL); - if (!g_hWnd) - { + if (!g_hWnd) { return FALSE; } @@ -423,42 +578,38 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) return TRUE; } - //-------------------------------------------------------------------------------------- // Create Direct3D device and swap chain //-------------------------------------------------------------------------------------- -HRESULT InitDevice() -{ +HRESULT InitDevice() { HRESULT hr = S_OK; RECT rc; - GetClientRect( g_hWnd, &rc ); + GetClientRect(g_hWnd, &rc); UINT width = rc.right - rc.left; UINT height = rc.bottom - rc.top; UINT createDeviceFlags = 0; - #ifdef _DEBUG +#ifdef _DEBUG createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; - #endif +#endif - D3D_DRIVER_TYPE driverTypes[] = - { + D3D_DRIVER_TYPE driverTypes[] = { D3D_DRIVER_TYPE_HARDWARE, D3D_DRIVER_TYPE_WARP, D3D_DRIVER_TYPE_REFERENCE, }; - UINT numDriverTypes = ARRAYSIZE( driverTypes ); + UINT numDriverTypes = ARRAYSIZE(driverTypes); - D3D_FEATURE_LEVEL featureLevels[] = - { + D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, }; - UINT numFeatureLevels = ARRAYSIZE( featureLevels ); + UINT numFeatureLevels = ARRAYSIZE(featureLevels); DXGI_SWAP_CHAIN_DESC sd; - ZeroMemory( &sd, sizeof( sd ) ); + ZeroMemory(&sd, sizeof(sd)); sd.BufferCount = 1; sd.BufferDesc.Width = width; sd.BufferDesc.Height = height; @@ -471,22 +622,22 @@ HRESULT InitDevice() sd.SampleDesc.Quality = 0; sd.Windowed = TRUE; - for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ ) - { + for (UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; + driverTypeIndex++) { g_driverType = driverTypes[driverTypeIndex]; - hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels, - D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext ); - if( HRESULT_SUCCEEDED( hr ) ) - break; + hr = D3D11CreateDeviceAndSwapChain( + NULL, g_driverType, NULL, createDeviceFlags, featureLevels, + numFeatureLevels, D3D11_SDK_VERSION, &sd, &g_pSwapChain, + &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext); + if (HRESULT_SUCCEEDED(hr)) break; } - if( FAILED( hr ) ) - return hr; + if (FAILED(hr)) return hr; // Create a render target view ID3D11Texture2D* pBackBuffer = NULL; - hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer ); - if( FAILED( hr ) ) - return hr; + hr = g_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), + (LPVOID*)&pBackBuffer); + if (FAILED(hr)) return hr; // Create a depth stencil buffer D3D11_TEXTURE2D_DESC descDepth; @@ -502,21 +653,24 @@ HRESULT InitDevice() descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL; descDepth.CPUAccessFlags = 0; descDepth.MiscFlags = 0; - hr = g_pd3dDevice->CreateTexture2D(&descDepth, NULL, &g_pDepthStencilBuffer); + hr = + g_pd3dDevice->CreateTexture2D(&descDepth, NULL, &g_pDepthStencilBuffer); D3D11_DEPTH_STENCIL_VIEW_DESC descDSView; descDSView.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; descDSView.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; descDSView.Texture2D.MipSlice = 0; - hr = g_pd3dDevice->CreateDepthStencilView(g_pDepthStencilBuffer, &descDSView, &g_pDepthStencilView); + hr = g_pd3dDevice->CreateDepthStencilView( + g_pDepthStencilBuffer, &descDSView, &g_pDepthStencilView); - hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView ); + hr = g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, + &g_pRenderTargetView); pBackBuffer->Release(); - if( FAILED( hr ) ) - return hr; + if (FAILED(hr)) return hr; - g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, g_pDepthStencilView ); + g_pImmediateContext->OMSetRenderTargets(1, &g_pRenderTargetView, + g_pDepthStencilView); // Setup the viewport D3D11_VIEWPORT vp; @@ -526,54 +680,48 @@ HRESULT InitDevice() vp.MaxDepth = 1.0f; vp.TopLeftX = 0; vp.TopLeftY = 0; - g_pImmediateContext->RSSetViewports( 1, &vp ); + g_pImmediateContext->RSSetViewports(1, &vp); RenderManager.Initialise(g_pd3dDevice, g_pSwapChain); return S_OK; } - //-------------------------------------------------------------------------------------- // Render the frame //-------------------------------------------------------------------------------------- -void Render() -{ +void Render() { // Just clear the backbuffer - float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; //red,green,blue,alpha + float ClearColor[4] = {0.0f, 0.125f, 0.3f, 1.0f}; // red,green,blue,alpha - g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetView, ClearColor ); - g_pSwapChain->Present( 0, 0 ); + g_pImmediateContext->ClearRenderTargetView(g_pRenderTargetView, ClearColor); + g_pSwapChain->Present(0, 0); } - //-------------------------------------------------------------------------------------- // Clean up the objects we've created //-------------------------------------------------------------------------------------- -void CleanupDevice() -{ - if( g_pImmediateContext ) g_pImmediateContext->ClearState(); +void CleanupDevice() { + if (g_pImmediateContext) g_pImmediateContext->ClearState(); - if( g_pRenderTargetView ) g_pRenderTargetView->Release(); - if( g_pSwapChain ) g_pSwapChain->Release(); - if( g_pImmediateContext ) g_pImmediateContext->Release(); - if( g_pd3dDevice ) g_pd3dDevice->Release(); + if (g_pRenderTargetView) g_pRenderTargetView->Release(); + if (g_pSwapChain) g_pSwapChain->Release(); + if (g_pImmediateContext) g_pImmediateContext->Release(); + if (g_pd3dDevice) g_pd3dDevice->Release(); } #endif -int StartMinecraftThreadProc( void* lpParameter ) -{ +int StartMinecraftThreadProc(void* lpParameter) { Vec3::UseDefaultThreadStorage(); AABB::UseDefaultThreadStorage(); - Tesselator::CreateNewThreadStorage(1024*1024); + Tesselator::CreateNewThreadStorage(1024 * 1024); RenderManager.InitialiseContext(); - Minecraft::start(std::wstring(),std::wstring()); + Minecraft::start(std::wstring(), std::wstring()); delete Tesselator::getInstance(); return 0; } -int main(int argc, const char *argv[] ) -{ +int main(int argc, const char* argv[]) { #if defined(__linux__) && defined(__GLIBC__) struct sigaction sa; sa.sa_handler = sigsegv_handler; @@ -602,13 +750,11 @@ int main(int argc, const char *argv[] ) reqH = atoi(argv[++i]); } } - if (reqW > 0 && reqH > 0) - RenderManager.SetWindowSize(reqW, reqH); - if (fs) - RenderManager.SetFullscreen(true); + if (reqW > 0 && reqH > 0) RenderManager.SetWindowSize(reqW, reqH); + if (fs) RenderManager.SetFullscreen(true); } - #if 0 +#if 0 // Main message loop MSG msg = {0}; while( WM_QUIT != msg.message ) @@ -627,13 +773,14 @@ Render(); return (int) msg.wParam; #endif -static bool bTrialTimerDisplayed=true; + static bool bTrialTimerDisplayed = true; #ifdef MEMORY_TRACKING -ResetMem(); -MEMORYSTATUS memStat; -GlobalMemoryStatus(&memStat); -printf("RESETMEM start: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); + ResetMem(); + MEMORYSTATUS memStat; + GlobalMemoryStatus(&memStat); + printf("RESETMEM start: Avail. phys %d\n", + memStat.dwAvailPhys / (1024 * 1024)); #endif #if 0 @@ -661,178 +808,185 @@ return -1; #endif -RenderManager.Initialise(); + RenderManager.Initialise(); -// Read the file containing the product codes -app.DebugPrintf("---ReadProductCodes()\n"); + // Read the file containing the product codes + app.DebugPrintf("---ReadProductCodes()\n"); -app.loadMediaArchive(); -app.loadStringTable(); + app.loadMediaArchive(); + app.loadStringTable(); // fuck you ui.init(1920, 1080); -// storage manager is needed for the trial key check -StorageManager.Init(0,app.GetString(IDS_DEFAULT_SAVENAME),(char*)"savegame.dat",FIFTY_ONE_MB,&CConsoleMinecraftApp::DisplaySavingMessage,(LPVOID)&app,(char*)""); + // storage manager is needed for the trial key check + StorageManager.Init(0, app.GetString(IDS_DEFAULT_SAVENAME), + (char*)"savegame.dat", FIFTY_ONE_MB, + &CConsoleMinecraftApp::DisplaySavingMessage, + (LPVOID)&app, (char*)""); -//////////////// -// Initialise // -//////////////// + //////////////// + // Initialise // + //////////////// -app.InitTime(); + app.InitTime(); -// Set the number of possible joypad layouts that the user can switch between, and the number of actions -InputManager.Initialise(1,5,MINECRAFT_ACTION_MAX, ACTION_MAX_MENU); + // Set the number of possible joypad layouts that the user can switch + // between, and the number of actions + InputManager.Initialise(1, 5, MINECRAFT_ACTION_MAX, ACTION_MAX_MENU); -// Set the default joypad action mappings for Minecraft -DefineActions(); -InputManager.SetJoypadMapVal(0,0); -InputManager.SetKeyRepeatRate(0.3f,0.2f); + // Set the default joypad action mappings for Minecraft + DefineActions(); + InputManager.SetJoypadMapVal(0, 0); + InputManager.SetKeyRepeatRate(0.3f, 0.2f); -// Initialise the profile manager with the game Title ID, Offer ID, a profile version number, and the number of profile values and settings + // Initialise the profile manager with the game Title ID, Offer ID, a + // profile version number, and the number of profile values and settings -ProfileManager.Initialise(TITLEID_MINECRAFT, - app.m_dwOfferID, - PROFILE_VERSION_10, - NUM_PROFILE_VALUES, - NUM_PROFILE_SETTINGS, - dwProfileSettingsA, - app.GAME_DEFINED_PROFILE_DATA_BYTES*XUSER_MAX_COUNT, - &app.uiGameDefinedDataChangedBitmask -); + ProfileManager.Initialise( + TITLEID_MINECRAFT, app.m_dwOfferID, PROFILE_VERSION_10, + NUM_PROFILE_VALUES, NUM_PROFILE_SETTINGS, dwProfileSettingsA, + app.GAME_DEFINED_PROFILE_DATA_BYTES * XUSER_MAX_COUNT, + &app.uiGameDefinedDataChangedBitmask); -// set a function to be called when there's a sign in change, so we can exit a level if the primary player signs out -ProfileManager.SetSignInChangeCallback(&CConsoleMinecraftApp::SignInChangeCallback, &app); + // set a function to be called when there's a sign in change, so we can exit + // a level if the primary player signs out + ProfileManager.SetSignInChangeCallback( + &CConsoleMinecraftApp::SignInChangeCallback, &app); -// Set a callback for when there is a read error on profile data -//StorageManager.SetProfileReadErrorCallback(&CConsoleMinecraftApp::ProfileReadErrorCallback, &app); + // Set a callback for when there is a read error on profile data + // StorageManager.SetProfileReadErrorCallback(&CConsoleMinecraftApp::ProfileReadErrorCallback, + // &app); + // QNet needs to be setup after profile manager, as we do not want its + // Notify listener to handle XN_SYS_SIGNINCHANGED notifications. This does + // mean that we need to have a callback in the ProfileManager for + // XN_LIVE_INVITE_ACCEPTED for QNet. -// QNet needs to be setup after profile manager, as we do not want its Notify listener to handle -// XN_SYS_SIGNINCHANGED notifications. This does mean that we need to have a callback in the -// ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet. - -g_NetworkManager.Initialise(); - -// debug switch to trial version -ProfileManager.SetDebugFullOverride(true); -// Initialise TLS for tesselator, for this main thread -Tesselator::CreateNewThreadStorage(1024*1024); -// Initialise TLS for AABB and Vec3 pools, for this main thread -AABB::CreateNewThreadStorage(); -Vec3::CreateNewThreadStorage(); -IntCache::CreateNewThreadStorage(); -Compression::CreateNewThreadStorage(); -OldChunkStorage::CreateNewThreadStorage(); -Level::enableLightingCache(); -Tile::CreateNewThreadStorage(); - -Minecraft::main(); - -// Minecraft::main () used to call Minecraft::Start, but this takes ~2.5 seconds, so now running this in another thread -// so we can do some basic renderer calls whilst it is happening. This is at attempt to stop getting TRC failure on SubmitDone taking > 5 seconds on boot -C4JThread *minecraftThread = new C4JThread(&StartMinecraftThreadProc, NULL, "Running minecraft start"); -minecraftThread->Run(); -do -{ - RenderManager.StartFrame(); - Sleep(20); - RenderManager.Present(); -} while (minecraftThread->isRunning()); -delete minecraftThread; - -// Re-acquire the GL context in the main thread. -// StartMinecraftThreadProc calls InitialiseContext() which moves the context -// to the init thread for texture loading; we must reclaim it here before -// any further OpenGL calls in the main render loop. -RenderManager.InitialiseContext(); - -Minecraft *pMinecraft=Minecraft::GetInstance(); - -app.InitGameSettings(); - -app.InitialiseTips(); -while (!RenderManager.ShouldClose()) { -RenderManager.StartFrame(); -app.UpdateTime(); -PIXBeginNamedEvent(0,"Input manager tick"); -InputManager.Tick(); -PIXEndNamedEvent(); -PIXBeginNamedEvent(0,"Profile manager tick"); -ProfileManager.Tick(); -PIXEndNamedEvent(); -PIXBeginNamedEvent(0,"Storage manager tick"); -StorageManager.Tick(); -PIXEndNamedEvent(); -PIXBeginNamedEvent(0,"Render manager tick"); -RenderManager.Tick(); -PIXEndNamedEvent(); - -// Tick the social networking manager. -PIXBeginNamedEvent(0,"Social network manager tick"); -// CSocialManager::Instance()->Tick(); -PIXEndNamedEvent(); - -// Tick sentient. -PIXBeginNamedEvent(0,"Sentient tick"); -MemSect(37); -// SentientManager.Tick(); -MemSect(0); -PIXEndNamedEvent(); - -PIXBeginNamedEvent(0,"Network manager do work #1"); -g_NetworkManager.DoWork(); -PIXEndNamedEvent(); - -// Render game graphics. -if(app.GetGameStarted()) -{ - pMinecraft->run_middle(); - app.SetAppPaused( g_NetworkManager.IsLocalGame() && g_NetworkManager.GetPlayerCount() == 1 && ui.IsPauseMenuDisplayed(ProfileManager.GetPrimaryPad()) ); -} -else -{ - MemSect(28); - pMinecraft->soundEngine->tick(NULL, 0.0f); - MemSect(0); - pMinecraft->textures->tick(true,false); - IntCache::Reset(); - if( app.GetReallyChangingSessionType() ) - { - pMinecraft->tickAllConnections(); // Added to stop timing out when we are waiting after converting to an offline game - } -} -pMinecraft->soundEngine->playMusicTick(); - -static bool bInitnet=false; - -if(bInitnet) -{ g_NetworkManager.Initialise(); -} + + // debug switch to trial version + ProfileManager.SetDebugFullOverride(true); + // Initialise TLS for tesselator, for this main thread + Tesselator::CreateNewThreadStorage(1024 * 1024); + // Initialise TLS for AABB and Vec3 pools, for this main thread + AABB::CreateNewThreadStorage(); + Vec3::CreateNewThreadStorage(); + IntCache::CreateNewThreadStorage(); + Compression::CreateNewThreadStorage(); + OldChunkStorage::CreateNewThreadStorage(); + Level::enableLightingCache(); + Tile::CreateNewThreadStorage(); + + Minecraft::main(); + + // Minecraft::main () used to call Minecraft::Start, but this takes ~2.5 + // seconds, so now running this in another thread so we can do some basic + // renderer calls whilst it is happening. This is at attempt to stop getting + // TRC failure on SubmitDone taking > 5 seconds on boot + C4JThread* minecraftThread = new C4JThread(&StartMinecraftThreadProc, NULL, + "Running minecraft start"); + minecraftThread->Run(); + do { + RenderManager.StartFrame(); + Sleep(20); + RenderManager.Present(); + } while (minecraftThread->isRunning()); + delete minecraftThread; + + // Re-acquire the GL context in the main thread. + // StartMinecraftThreadProc calls InitialiseContext() which moves the + // context to the init thread for texture loading; we must reclaim it here + // before any further OpenGL calls in the main render loop. + RenderManager.InitialiseContext(); + + Minecraft* pMinecraft = Minecraft::GetInstance(); + + app.InitGameSettings(); + + app.InitialiseTips(); + while (!RenderManager.ShouldClose()) { + RenderManager.StartFrame(); + app.UpdateTime(); + PIXBeginNamedEvent(0, "Input manager tick"); + InputManager.Tick(); + PIXEndNamedEvent(); + PIXBeginNamedEvent(0, "Profile manager tick"); + ProfileManager.Tick(); + PIXEndNamedEvent(); + PIXBeginNamedEvent(0, "Storage manager tick"); + StorageManager.Tick(); + PIXEndNamedEvent(); + PIXBeginNamedEvent(0, "Render manager tick"); + RenderManager.Tick(); + PIXEndNamedEvent(); + + // Tick the social networking manager. + PIXBeginNamedEvent(0, "Social network manager tick"); + // CSocialManager::Instance()->Tick(); + PIXEndNamedEvent(); + + // Tick sentient. + PIXBeginNamedEvent(0, "Sentient tick"); + MemSect(37); + // SentientManager.Tick(); + MemSect(0); + PIXEndNamedEvent(); + + PIXBeginNamedEvent(0, "Network manager do work #1"); + g_NetworkManager.DoWork(); + PIXEndNamedEvent(); + + // Render game graphics. + if (app.GetGameStarted()) { + pMinecraft->run_middle(); + app.SetAppPaused( + g_NetworkManager.IsLocalGame() && + g_NetworkManager.GetPlayerCount() == 1 && + ui.IsPauseMenuDisplayed(ProfileManager.GetPrimaryPad())); + } else { + MemSect(28); + pMinecraft->soundEngine->tick(NULL, 0.0f); + MemSect(0); + pMinecraft->textures->tick(true, false); + IntCache::Reset(); + if (app.GetReallyChangingSessionType()) { + pMinecraft + ->tickAllConnections(); // Added to stop timing out when we + // are waiting after converting to + // an offline game + } + } + pMinecraft->soundEngine->playMusicTick(); + + static bool bInitnet = false; + + if (bInitnet) { + g_NetworkManager.Initialise(); + } #ifdef MEMORY_TRACKING -static bool bResetMemTrack = false; -static bool bDumpMemTrack = false; + static bool bResetMemTrack = false; + static bool bDumpMemTrack = false; -MemPixStuff(); + MemPixStuff(); -if( bResetMemTrack ) -{ - ResetMem(); - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("RESETMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); - bResetMemTrack = false; -} + if (bResetMemTrack) { + ResetMem(); + MEMORYSTATUS memStat; + GlobalMemoryStatus(&memStat); + printf("RESETMEM: Avail. phys %d\n", + memStat.dwAvailPhys / (1024 * 1024)); + bResetMemTrack = false; + } -if( bDumpMemTrack ) -{ - DumpMem(); - bDumpMemTrack = false; - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("DUMPMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); - printf("Renderer used: %d\n",RenderManager.CBuffSize(-1)); -} + if (bDumpMemTrack) { + DumpMem(); + bDumpMemTrack = false; + MEMORYSTATUS memStat; + GlobalMemoryStatus(&memStat); + printf("DUMPMEM: Avail. phys %d\n", + memStat.dwAvailPhys / (1024 * 1024)); + printf("Renderer used: %d\n", RenderManager.CBuffSize(-1)); + } #endif #if 0 static bool bDumpTextureUsage = false; @@ -842,8 +996,8 @@ RenderManager.TextureGetStats(); bDumpTextureUsage = false; } #endif -ui.tick(); -ui.render(); + ui.tick(); + ui.render(); #if 0 app.HandleButtonPresses(); @@ -884,51 +1038,47 @@ pDevice->SetSamplerState(0,SamplerStateModes[i],SamplerStateA[i]); RenderManager.Set_matrixDirty(); #endif -// Present the frame. -RenderManager.Present(); + // Present the frame. + RenderManager.Present(); -ui.CheckMenuDisplayed(); -PIXBeginNamedEvent(0,"Profile load check"); -// has the game defined profile data been changed (by a profile load) -if(app.uiGameDefinedDataChangedBitmask!=0) -{ - void *pData; - for(int i=0;istats[i]->clear(); + pMinecraft->stats[i]->parse(pData); + } } - else - { - // force debug mask off - app.ActionDebugMask(i,true); - } - #endif - // clear the stats first - there could have beena signout and sign back in in the menus - // need to clear the player stats - can't assume it'll be done in setlevel - we may not be in the game - pMinecraft->stats[ i ]->clear(); - pMinecraft->stats[i]->parse(pData); + + // clear the flag + app.uiGameDefinedDataChangedBitmask = 0; } + PIXEndNamedEvent(); - } - - // clear the flag - app.uiGameDefinedDataChangedBitmask=0; -} -PIXEndNamedEvent(); - -PIXBeginNamedEvent(0,"Network manager do work #2"); -g_NetworkManager.DoWork(); -PIXEndNamedEvent(); + PIXBeginNamedEvent(0, "Network manager do work #2"); + g_NetworkManager.DoWork(); + PIXEndNamedEvent(); #if 0 PIXBeginNamedEvent(0,"Misc extra xui"); @@ -936,143 +1086,136 @@ PIXBeginNamedEvent(0,"Misc extra xui"); hr = XuiTimersRun(); #endif -// Any threading type things to deal with from the xui side? -app.HandleXuiActions(); + // Any threading type things to deal with from the xui side? + app.HandleXuiActions(); #if 0 PIXEndNamedEvent(); #endif -// 4J-PB - Update the trial timer display if we are in the trial version -if(!ProfileManager.IsFullVersion()) -{ - // display the trial timer - if(app.GetGameStarted()) - { - // 4J-PB - if the game is paused, add the elapsed time to the trial timer count so it doesn't tick down - if(app.IsAppPaused()) - { - app.UpdateTrialPausedTimer(); + // 4J-PB - Update the trial timer display if we are in the trial version + if (!ProfileManager.IsFullVersion()) { + // display the trial timer + if (app.GetGameStarted()) { + // 4J-PB - if the game is paused, add the elapsed time to the + // trial timer count so it doesn't tick down + if (app.IsAppPaused()) { + app.UpdateTrialPausedTimer(); + } + ui.UpdateTrialTimer(ProfileManager.GetPrimaryPad()); + } + } else { + // need to turn off the trial timer if it was on , and we've + // unlocked the full version + if (bTrialTimerDisplayed) { + ui.ShowTrialTimer(false); + bTrialTimerDisplayed = false; + } } - ui.UpdateTrialTimer(ProfileManager.GetPrimaryPad()); - } -} -else -{ - // need to turn off the trial timer if it was on , and we've unlocked the full version - if(bTrialTimerDisplayed) - { - ui.ShowTrialTimer(false); - bTrialTimerDisplayed=false; - } -} -// Fix for #7318 - Title crashes after short soak in the leaderboards menu -// A memory leak was caused because the icon renderer kept creating new Vec3's because the pool wasn't reset -Vec3::resetPool(); -} // end game loop + // Fix for #7318 - Title crashes after short soak in the leaderboards + // menu A memory leak was caused because the icon renderer kept creating + // new Vec3's because the pool wasn't reset + Vec3::resetPool(); + } // end game loop - // Graceful shutdown: destroy GL context and GLFW before any C++ dtors run. - // Without this, static/global destructors that touch GL objects cause SIGSEGV. - RenderManager.Shutdown(); - _exit(0); -} // end main + // Graceful shutdown: destroy GL context and GLFW before any C++ dtors run. + // Without this, static/global destructors that touch GL objects cause + // SIGSEGV. + RenderManager.Shutdown(); + _exit(0); +} // end main // Free resources, unregister custom classes, and exit. // app.Uninit(); // g_pd3dDevice->Release(); - -std::vector vRichPresenceStrings; +std::vector vRichPresenceStrings; // convert std::wstring to UTF-8 string // wchar_t is 32bit on all Linux systems, and interpreted as UTF-32 -// the code base stores all strings internally as UCS-2 (16bit, subset of UTF-16), -// which, scince it only stores BMP code points, is trivially convertable -// to UTF-32 as well as UTF-16. hence this parser simply parses UTF-32 +// the code base stores all strings internally as UCS-2 (16bit, subset of +// UTF-16), which, scince it only stores BMP code points, is trivially +// convertable to UTF-32 as well as UTF-16. hence this parser simply parses +// UTF-32 // all implementations of libc (including glibc, musl, uClibc...) implement -// wchar_t as 4byte/32bit (scince around 1999), it would break the libc ABI, +// wchar_t as 4byte/32bit (scince around 1999), it would break the libc ABI, // if this ever will get changed, hence this assert -static_assert( sizeof(wchar_t) == 4, "Linux with non 32bit wchar_t"); +static_assert(sizeof(wchar_t) == 4, "Linux with non 32bit wchar_t"); -std::string wstring_to_utf8 (const std::wstring& str) -{ - std::string result; - // preallocation, so it will never need to resize. - // same allocation size as for the 4byte wstring representation. - // it well get destructed instantly, in the function that it gets called from - result.reserve(str.size() * 4); +std::string wstring_to_utf8(const std::wstring& str) { + std::string result; + // preallocation, so it will never need to resize. + // same allocation size as for the 4byte wstring representation. + // it well get destructed instantly, in the function that it gets called + // from + result.reserve(str.size() * 4); - for (size_t i = 0; i < str.size(); ++i) { - uint32_t cp = static_cast(str[i]); + for (size_t i = 0; i < str.size(); ++i) { + uint32_t cp = static_cast(str[i]); - // outside of valid unicode range or preserved UTF-16 surrogate pairs (just in case) - if (cp > 0x10FFFF || (cp >= 0xD800 && cp <= 0xDFFF)) { - cp = 0xFFFD; // unicode replacement character - } + // outside of valid unicode range or preserved UTF-16 surrogate pairs + // (just in case) + if (cp > 0x10FFFF || (cp >= 0xD800 && cp <= 0xDFFF)) { + cp = 0xFFFD; // unicode replacement character + } - if (cp < 0x80) { - // ASCII - result += static_cast(cp); - // extract multibyte unicode into multiple bytes of UTF-8 - } else if (cp < 0x800) { - result += static_cast(0xC0 | (cp >> 6)); - result += static_cast(0x80 | (cp & 0x3F)); - } else if (cp < 0x10000) { - result += static_cast(0xE0 | (cp >> 12)); - result += static_cast(0x80 | ((cp >> 6) & 0x3F)); - result += static_cast(0x80 | (cp & 0x3F)); - } else { - result += static_cast(0xF0 | (cp >> 18)); - result += static_cast(0x80 | ((cp >> 12) & 0x3F)); - result += static_cast(0x80 | ((cp >> 6) & 0x3F)); - result += static_cast(0x80 | (cp & 0x3F)); - } - } + if (cp < 0x80) { + // ASCII + result += static_cast(cp); + // extract multibyte unicode into multiple bytes of UTF-8 + } else if (cp < 0x800) { + result += static_cast(0xC0 | (cp >> 6)); + result += static_cast(0x80 | (cp & 0x3F)); + } else if (cp < 0x10000) { + result += static_cast(0xE0 | (cp >> 12)); + result += static_cast(0x80 | ((cp >> 6) & 0x3F)); + result += static_cast(0x80 | (cp & 0x3F)); + } else { + result += static_cast(0xF0 | (cp >> 18)); + result += static_cast(0x80 | ((cp >> 12) & 0x3F)); + result += static_cast(0x80 | ((cp >> 6) & 0x3F)); + result += static_cast(0x80 | (cp & 0x3F)); + } + } - return result; + return result; } -uint8_t *mallocAndCreateUTF8ArrayFromString(int iID) -{ - LPCWSTR wchString=app.GetString(iID); +uint8_t* mallocAndCreateUTF8ArrayFromString(int iID) { + LPCWSTR wchString = app.GetString(iID); std::wstring srcString = wchString; std::string dstString = wstring_to_utf8(srcString); - int dst_len = dstString.size()+1; - uint8_t *strUtf8=(uint8_t *)malloc(dst_len); + int dst_len = dstString.size() + 1; + uint8_t* strUtf8 = (uint8_t*)malloc(dst_len); memcpy(strUtf8, dstString.c_str(), dst_len); return strUtf8; } -uint8_t * AddRichPresenceString(int iID) -{ - uint8_t *strUtf8 = mallocAndCreateUTF8ArrayFromString(iID); - if( strUtf8 != NULL ) - { +uint8_t* AddRichPresenceString(int iID) { + uint8_t* strUtf8 = mallocAndCreateUTF8ArrayFromString(iID); + if (strUtf8 != NULL) { vRichPresenceStrings.push_back(strUtf8); } return strUtf8; } -void FreeRichPresenceStrings() -{ - uint8_t *strUtf8; - for(int i=0;i allocCounts; +std::unordered_map allocCounts; bool trackEnable = false; bool trackStarted = false; volatile size_t sizeCheckMin = 1160; @@ -1081,11 +1224,9 @@ volatile int sectCheck = 48; CRITICAL_SECTION memCS; DWORD tlsIdx; -LPVOID XMemAlloc(SIZE_T dwSize, DWORD dwAllocAttributes) -{ - if( !trackStarted ) - { - void *p = XMemAllocDefault(dwSize,dwAllocAttributes); +LPVOID XMemAlloc(SIZE_T dwSize, DWORD dwAllocAttributes) { + if (!trackStarted) { + void* p = XMemAllocDefault(dwSize, dwAllocAttributes); size_t realSize = XMemSizeDefault(p, dwAllocAttributes); totalAllocGen += realSize; return p; @@ -1093,26 +1234,24 @@ LPVOID XMemAlloc(SIZE_T dwSize, DWORD dwAllocAttributes) EnterCriticalSection(&memCS); - void *p=XMemAllocDefault(dwSize + 16,dwAllocAttributes); - size_t realSize = XMemSizeDefault(p,dwAllocAttributes) - 16; + void* p = XMemAllocDefault(dwSize + 16, dwAllocAttributes); + size_t realSize = XMemSizeDefault(p, dwAllocAttributes) - 16; - if( trackEnable ) - { - #if 1 - int sect = ((int) TlsGetValue(tlsIdx)) & 0x3f; - *(((unsigned char *)p)+realSize) = sect; + if (trackEnable) { +#if 1 + int sect = ((int)TlsGetValue(tlsIdx)) & 0x3f; + *(((unsigned char*)p) + realSize) = sect; - if( ( realSize >= sizeCheckMin ) && ( realSize <= sizeCheckMax ) && ( ( sect == sectCheck ) || ( sectCheck == -1 ) ) ) - { + if ((realSize >= sizeCheckMin) && (realSize <= sizeCheckMax) && + ((sect == sectCheck) || (sectCheck == -1))) { app.DebugPrintf("Found one\n"); } - #endif +#endif - if( p ) - { + if (p) { totalAllocGen += realSize; trackEnable = false; - int key = ( sect << 26 ) | realSize; + int key = (sect << 26) | realSize; int oldCount = allocCounts[key]; allocCounts[key] = oldCount + 1; @@ -1125,86 +1264,74 @@ LPVOID XMemAlloc(SIZE_T dwSize, DWORD dwAllocAttributes) return p; } -void* operator new (size_t size) -{ - return (unsigned char *)XMemAlloc(size,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); +void* operator new(size_t size) { + return (unsigned char*)XMemAlloc( + size, MAKE_XALLOC_ATTRIBUTES( + 0, FALSE, TRUE, FALSE, 0, XALLOC_PHYSICAL_ALIGNMENT_DEFAULT, + XALLOC_MEMPROTECT_READWRITE, FALSE, XALLOC_MEMTYPE_HEAP)); } -void operator delete (void *p) -{ - XMemFree(p,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); +void operator delete(void* p) { + XMemFree(p, MAKE_XALLOC_ATTRIBUTES( + 0, FALSE, TRUE, FALSE, 0, XALLOC_PHYSICAL_ALIGNMENT_DEFAULT, + XALLOC_MEMPROTECT_READWRITE, FALSE, XALLOC_MEMTYPE_HEAP)); } -void WINAPI XMemFree(PVOID pAddress, DWORD dwAllocAttributes) -{ +void WINAPI XMemFree(PVOID pAddress, DWORD dwAllocAttributes) { bool special = false; - if( dwAllocAttributes == 0 ) - { - dwAllocAttributes = MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP); + if (dwAllocAttributes == 0) { + dwAllocAttributes = MAKE_XALLOC_ATTRIBUTES( + 0, FALSE, TRUE, FALSE, 0, XALLOC_PHYSICAL_ALIGNMENT_DEFAULT, + XALLOC_MEMPROTECT_READWRITE, FALSE, XALLOC_MEMTYPE_HEAP); special = true; } - if(!trackStarted ) - { + if (!trackStarted) { size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes); XMemFreeDefault(pAddress, dwAllocAttributes); totalAllocGen -= realSize; return; } EnterCriticalSection(&memCS); - if( pAddress ) - { + if (pAddress) { size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes) - 16; - if(trackEnable) - { - int sect = *(((unsigned char *)pAddress)+realSize); + if (trackEnable) { + int sect = *(((unsigned char*)pAddress) + realSize); totalAllocGen -= realSize; trackEnable = false; - int key = ( sect << 26 ) | realSize; + int key = (sect << 26) | realSize; int oldCount = allocCounts[key]; allocCounts[key] = oldCount - 1; trackEnable = true; - } XMemFreeDefault(pAddress, dwAllocAttributes); } LeaveCriticalSection(&memCS); } -SIZE_T WINAPI XMemSize( - PVOID pAddress, - DWORD dwAllocAttributes -) -{ - if( trackStarted ) - { +SIZE_T WINAPI XMemSize(PVOID pAddress, DWORD dwAllocAttributes) { + if (trackStarted) { return XMemSizeDefault(pAddress, dwAllocAttributes) - 16; - } - else - { + } else { return XMemSizeDefault(pAddress, dwAllocAttributes); } } - -void DumpMem() -{ +void DumpMem() { int totalLeak = 0; - for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ ) - { - if(it->second > 0 ) - { - app.DebugPrintf("%d %d %d %d\n",( it->first >> 26 ) & 0x3f,it->first & 0x03ffffff, it->second, (it->first & 0x03ffffff) * it->second); - totalLeak += ( it->first & 0x03ffffff ) * it->second; + for (AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++) { + if (it->second > 0) { + app.DebugPrintf("%d %d %d %d\n", (it->first >> 26) & 0x3f, + it->first & 0x03ffffff, it->second, + (it->first & 0x03ffffff) * it->second); + totalLeak += (it->first & 0x03ffffff) * it->second; } } - app.DebugPrintf("Total %d\n",totalLeak); + app.DebugPrintf("Total %d\n", totalLeak); } -void ResetMem() -{ - if( !trackStarted ) - { +void ResetMem() { + if (!trackStarted) { trackEnable = true; trackStarted = true; totalAllocGen = 0; @@ -1218,44 +1345,38 @@ void ResetMem() LeaveCriticalSection(&memCS); } -void MemSect(int section) -{ +void MemSect(int section) { unsigned int value = (unsigned int)TlsGetValue(tlsIdx); - if( section == 0 ) // pop + if (section == 0) // pop { value = (value >> 6) & 0x03ffffff; - } - else - { + } else { value = (value << 6) | section; } TlsSetValue(tlsIdx, (LPVOID)value); } -void MemPixStuff() -{ +void MemPixStuff() { const int MAX_SECT = 46; int totals[MAX_SECT] = {0}; - for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ ) - { - if(it->second > 0 ) - { - int sect = ( it->first >> 26 ) & 0x3f; + for (AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++) { + if (it->second > 0) { + int sect = (it->first >> 26) & 0x3f; int bytes = it->first & 0x03ffffff; totals[sect] += bytes * it->second; } } unsigned int allSectsTotal = 0; - for( int i = 0; i < MAX_SECT; i++ ) - { + for (int i = 0; i < MAX_SECT; i++) { allSectsTotal += totals[i]; - PIXAddNamedCounter(((float)totals[i])/1024.0f,"MemSect%d",i); + PIXAddNamedCounter(((float)totals[i]) / 1024.0f, "MemSect%d", i); } - PIXAddNamedCounter(((float)allSectsTotal)/(4096.0f),"MemSect total pages"); + PIXAddNamedCounter(((float)allSectsTotal) / (4096.0f), + "MemSect total pages"); } #endif