the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 1077 lines 42 kB view raw
1// Minecraft.cpp : Defines the entry point for the application. 2// 3 4#include "stdafx.h" 5#include <xbdm.h> 6#include <assert.h> 7#include "GameConfig\Minecraft.spa.h" 8#include "..\MinecraftServer.h" 9#include "..\LocalPlayer.h" 10#include "..\..\Minecraft.World\ItemInstance.h" 11#include "..\..\Minecraft.World\MapItem.h" 12#include "..\..\Minecraft.World\Recipes.h" 13#include "..\..\Minecraft.World\Recipy.h" 14#include "..\..\Minecraft.World\Language.h" 15#include "..\..\Minecraft.World\StringHelpers.h" 16#include "..\..\Minecraft.World\AABB.h" 17#include "..\..\Minecraft.World\Vec3.h" 18#include "..\..\Minecraft.World\Level.h" 19#include "..\..\Minecraft.World\net.minecraft.world.level.tile.h" 20#include "..\ClientConnection.h" 21#include "..\User.h" 22#include "..\..\Minecraft.World\Socket.h" 23#include "..\..\Minecraft.World\ThreadName.h" 24#include "..\..\Minecraft.Client\StatsCounter.h" 25#include "..\ConnectScreen.h" 26#include "Social\SocialManager.h" 27#include "Leaderboards\XboxLeaderboardManager.h" 28#include "..\Common\XUI\XUI_Scene_Container.h" 29#include "..\..\Minecraft.Client\Tesselator.h" 30#include "..\..\Minecraft.Client\Options.h" 31#include "Sentient\SentientManager.h" 32#include "..\..\Minecraft.World\IntCache.h" 33#include "..\Textures.h" 34#include "..\..\Minecraft.World\compression.h" 35#include "..\..\Minecraft.World\OldChunkStorage.h" 36//#include "..\..\Minecraft.Client\SoundEngine.h" 37 38#include <NuiApi.h> 39 40void GetRenderAndSamplerStates(IDirect3DDevice9 *pDevice,DWORD *RenderStateA,DWORD *SamplerStateA); 41void SetRenderAndSamplerStates(IDirect3DDevice9 *pDevice,DWORD *RenderStateA,DWORD *SamplerStateA); 42 43// 4J-PB - Done - #pragma message(__LOC__"Theme should be GREEN SIGNED before _FINAL_BUILD") 44 45#define THEME_NAME "584111F70AAAAAAA" 46#define THEME_FILESIZE 2797568 47//#define THREE_MB 3145728 // minimum save size (checking for this on a selected device) 48//#define FIVE_MB 5242880 // minimum save size (checking for this on a selected device) 49//#define FIFTY_TWO_MB (1024*1024*52) // Maximum TCR space required for a save (checking for this on a selected device) 50#define FIFTY_ONE_MB (1000000*51) // Maximum TCR space required for a save is 52MB (checking for this on a selected device) 51 52//#define PROFILE_VERSION 3 // new version for the interim bug fix 166 TU 53#define NUM_PROFILE_VALUES 5 54#define NUM_PROFILE_SETTINGS 4 55DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]= 56{ 57 XPROFILE_OPTION_CONTROLLER_VIBRATION, 58 XPROFILE_GAMER_YAXIS_INVERSION, 59 XPROFILE_GAMER_CONTROL_SENSITIVITY, 60 XPROFILE_GAMER_ACTION_MOVEMENT_CONTROL, 61 XPROFILE_TITLE_SPECIFIC1, 62}; 63 64D3DRENDERSTATETYPE RenderStateModes[]= 65{ 66 D3DRS_FILLMODE, 67 D3DRS_CULLMODE, 68 D3DRS_ALPHABLENDENABLE, 69 D3DRS_VIEWPORTENABLE, 70 D3DRS_BLENDOP, 71 D3DRS_SRCBLEND, 72 D3DRS_DESTBLEND, 73 D3DRS_COLORWRITEENABLE 74}; 75 76D3DSAMPLERSTATETYPE SamplerStateModes[]= 77{ 78 D3DSAMP_MINFILTER, 79 D3DSAMP_MAGFILTER, 80 D3DSAMP_MIPFILTER, 81 D3DSAMP_ADDRESSU, 82 D3DSAMP_ADDRESSV 83}; 84 85//------------------------------------------------------------------------------------- 86// Time Since fAppTime is a float, we need to keep the quadword app time 87// as a LARGE_INTEGER so that we don't lose precision after running 88// for a long time. 89//------------------------------------------------------------------------------------- 90 91 92BOOL g_bWidescreen = TRUE; 93 94 95void DefineActions(void) 96{ 97 // The app needs to define the actions required, and the possible mappings for these 98 99 // Split into Menu actions, and in-game actions 100 101 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_A, _360_JOY_BUTTON_A); 102 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_B, _360_JOY_BUTTON_B); 103 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_X, _360_JOY_BUTTON_X); 104 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_Y, _360_JOY_BUTTON_Y); 105 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OK, _360_JOY_BUTTON_A); 106 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B); 107 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP); 108 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN); 109 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT); 110 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT); 111 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_LT); 112 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT); 113 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB); 114 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB); 115 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START); 116 117 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB); 118 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB); 119 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP); 120 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); 121 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); 122 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); 123 124 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_A); 125 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP); 126 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN); 127 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT); 128 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT); 129 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); 130 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); 131 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP); 132 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); 133 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_LT); 134 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_RT); 135 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_RB); 136 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_LB); 137 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y); 138 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START); 139 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B); 140 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_RTHUMB); 141 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X); 142 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_LTHUMB); 143 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK); 144 145 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT); 146 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT); 147 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP); 148 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN); 149 150 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_A, _360_JOY_BUTTON_A); 151 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_B, _360_JOY_BUTTON_B); 152 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_X, _360_JOY_BUTTON_X); 153 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_Y, _360_JOY_BUTTON_Y); 154 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OK, _360_JOY_BUTTON_A); 155 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B); 156 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP); 157 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN); 158 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT); 159 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT); 160 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_LB); 161 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT); 162 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB); 163 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB); 164 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START); 165 166 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB); 167 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB); 168 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP); 169 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); 170 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); 171 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); 172 173 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_RB); 174 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP); 175 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN); 176 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT); 177 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT); 178 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); 179 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); 180 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP); 181 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); 182 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_RT); 183 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_LT); 184 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_DPAD_RIGHT); 185 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_DPAD_LEFT); 186 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y); 187 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START); 188 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B); 189 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_LTHUMB); 190 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X); 191 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_RTHUMB); 192 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK); 193 194 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT); 195 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT); 196 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP); 197 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN); 198 199 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_A, _360_JOY_BUTTON_A); 200 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_B, _360_JOY_BUTTON_B); 201 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_X, _360_JOY_BUTTON_X); 202 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_Y, _360_JOY_BUTTON_Y); 203 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OK, _360_JOY_BUTTON_A); 204 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B); 205 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP); 206 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN); 207 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT); 208 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT); 209 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LB); 210 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT); 211 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB); 212 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB); 213 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START); 214 215 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB); 216 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB); 217 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP); 218 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); 219 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); 220 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); 221 222 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_LT); 223 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP); 224 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN); 225 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT); 226 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT); 227 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); 228 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); 229 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP); 230 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); 231 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_RT); 232 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_A); 233 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_DPAD_RIGHT); 234 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_DPAD_LEFT); 235 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y); 236 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START); 237 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B); 238 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_LB); 239 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X); 240 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_LTHUMB); 241 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK); 242 243 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT); 244 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT); 245 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP); 246 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN); 247} 248 249 250 251 252HRESULT InitD3D( IDirect3DDevice9 **ppDevice, 253 D3DPRESENT_PARAMETERS *pd3dPP ) 254{ 255 IDirect3D9 *pD3D; 256 257 pD3D = Direct3DCreate9( D3D_SDK_VERSION ); 258 259 // Set up the structure used to create the D3DDevice 260 // Using a permanent 1280x720 backbuffer now no matter what the actual video resolution.right Have also disabled letterboxing, 261 // which would letterbox a 1280x720 output if it detected a 4:3 video source - we're doing an anamorphic squash in this 262 // mode so don't need this functionality. 263 264 ZeroMemory( pd3dPP, sizeof(D3DPRESENT_PARAMETERS) ); 265 XVIDEO_MODE VideoMode; 266 XGetVideoMode( &VideoMode ); 267 g_bWidescreen = VideoMode.fIsWideScreen; 268 pd3dPP->BackBufferWidth = 1280; 269 pd3dPP->BackBufferHeight = 720; 270 pd3dPP->BackBufferFormat = D3DFMT_A8R8G8B8; 271 pd3dPP->BackBufferCount = 1; 272 pd3dPP->EnableAutoDepthStencil = TRUE; 273 pd3dPP->AutoDepthStencilFormat = D3DFMT_D24S8; 274 pd3dPP->SwapEffect = D3DSWAPEFFECT_DISCARD; 275 pd3dPP->PresentationInterval = D3DPRESENT_INTERVAL_ONE; 276 //pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX; 277 //ERR[D3D]: Can't set D3DPRESENTFLAG_NO_LETTERBOX when wide-screen is enabled 278 // in the launcher/dashboard. 279 if(g_bWidescreen) 280 pd3dPP->Flags=0; 281 else 282 pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX; 283 284 // Create the device. 285 return pD3D->CreateDevice( 286 0, 287 D3DDEVTYPE_HAL, 288 NULL, 289 D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_BUFFER_2_FRAMES, 290 pd3dPP, 291 ppDevice ); 292} 293//#define MEMORY_TRACKING 294 295#ifdef MEMORY_TRACKING 296void ResetMem(); 297void DumpMem(); 298void MemPixStuff(); 299#else 300void MemSect(int sect) 301{ 302} 303#endif 304 305IDirect3DDevice9 *g_pD3DDevice; 306 307//------------------------------------------------------------------------------------- 308// Name: main() 309// Desc: The application's entry point 310//------------------------------------------------------------------------------------- 311int __cdecl main() 312{ 313 IDirect3DDevice9 *pDevice; 314 D3DPRESENT_PARAMETERS d3dpp; 315 HRESULT hr; 316 static bool bTrialTimerDisplayed=true; 317 318 //__debugbreak(); 319 320#ifdef MEMORY_TRACKING 321 ResetMem(); 322 MEMORYSTATUS memStat; 323 GlobalMemoryStatus(&memStat); 324 printf("RESETMEM start: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); 325#endif 326 // capture the launch data if there is any 327 app.StoreLaunchData(); 328 329#ifdef _DEBUG 330 // Output more verbose errors for sessions 331 XDebugSetSystemOutputLevel( HXAMAPP_XGI, 3 ); 332#endif 333 334// DumpMem(); 335 336 // Declare an instance of the XUI framework. 337 338 // XUI render can change the following renderstates, so store then before and re-set them after the xui render 339 /* The following D3DRENDERSTATETYPE D3D render states. 340 341 D3DRS_FILLMODE 342 343 D3DRS_CULLMODE 344 345 D3DRS_ALPHABLENDENABLE 346 347 D3DRS_VIEWPORTENABLE 348 349 D3DRS_BLENDOP 350 351 D3DRS_SRCBLEND 352 353 D3DRS_DESTBLEND 354 355 D3DRS_COLORWRITEENABLE 356 */ 357 358 DWORD RenderStateA[8]; 359 DWORD SamplerStateA[5]; 360 DWORD RenderStateA2[8]; 361 DWORD SamplerStateA2[5]; 362 363 // Initialize D3D 364 hr = InitD3D( &pDevice, &d3dpp ); 365 g_pD3DDevice = pDevice; 366 if( FAILED(hr) ) 367 { 368 app.DebugPrintf 369 ( "Failed initializing D3D.\n" ); 370 return -1; 371 } 372 373 // Initialize the application, assuming sharing of the d3d interface. 374 hr = app.InitShared( pDevice, &d3dpp, 375 XuiPNGTextureLoader ); 376 377 if ( FAILED(hr) ) 378 { 379 app.DebugPrintf 380 ( "Failed initializing application.\n" ); 381 382 return -1; 383 } 384 385 RenderManager.Initialise(pDevice); 386 387 //////////////// 388 // Initialise // 389 //////////////// 390 391 // 4J Stu - XACT was creating these automatically, but we need them for QNet. The setup params 392 // are just copied from a sample app and may need changed for our purposes 393 // Start XAudio2 394 hr = XAudio2Create( &g_pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR ); 395 if( FAILED( hr ) ) 396 { 397 app.DebugPrintf( "Initializing XAudio2 failed (err = 0x%08x)!\n", hr ); 398 app.FatalLoadError(); 399 } 400 401 // Create an XAudio2 mastering voice (utilized by XHV2 when voice data is mixed to main speakers) 402 hr = g_pXAudio2->CreateMasteringVoice(&g_pXAudio2MasteringVoice, XAUDIO2_DEFAULT_CHANNELS, XAUDIO2_DEFAULT_SAMPLERATE, 0, 0, NULL); 403 if ( FAILED( hr ) ) 404 { 405 app.DebugPrintf( "Creating XAudio2 mastering voice failed (err = 0x%08x)!\n", hr ); 406 app.FatalLoadError(); 407 } 408 409 app.InitTime(); 410 411 // Set the number of possible joypad layouts that the user can switch between, and the number of actions 412 InputManager.Initialise(1,3,MINECRAFT_ACTION_MAX, ACTION_MAX_MENU); 413 414 // Set the default joypad action mappings for Minecraft 415 DefineActions(); 416 InputManager.SetJoypadMapVal(0,0); 417 InputManager.SetKeyRepeatRate(0.3f,0.2f); 418 419 420 // Initialise the profile manager with the game Title ID, Offer ID, a profile version number, and the number of profile values and settings 421 ProfileManager.Initialise(TITLEID_MINECRAFT, 422 app.m_dwOfferID, 423 PROFILE_VERSION_10, 424 NUM_PROFILE_VALUES, 425 NUM_PROFILE_SETTINGS, 426 dwProfileSettingsA, 427 app.GAME_DEFINED_PROFILE_DATA_BYTES*XUSER_MAX_COUNT, 428 &app.uiGameDefinedDataChangedBitmask 429 ); 430 431 // register the awards 432 ProfileManager.RegisterAward(eAward_TakingInventory, ACHIEVEMENT_01, eAwardType_Achievement); 433 ProfileManager.RegisterAward(eAward_GettingWood, ACHIEVEMENT_02, eAwardType_Achievement); 434 ProfileManager.RegisterAward(eAward_Benchmarking, ACHIEVEMENT_03, eAwardType_Achievement); 435 ProfileManager.RegisterAward(eAward_TimeToMine, ACHIEVEMENT_04, eAwardType_Achievement); 436 ProfileManager.RegisterAward(eAward_HotTopic, ACHIEVEMENT_05, eAwardType_Achievement); 437 ProfileManager.RegisterAward(eAward_AquireHardware, ACHIEVEMENT_06, eAwardType_Achievement); 438 ProfileManager.RegisterAward(eAward_TimeToFarm, ACHIEVEMENT_07, eAwardType_Achievement); 439 ProfileManager.RegisterAward(eAward_BakeBread, ACHIEVEMENT_08, eAwardType_Achievement); 440 ProfileManager.RegisterAward(eAward_TheLie, ACHIEVEMENT_09, eAwardType_Achievement); 441 ProfileManager.RegisterAward(eAward_GettingAnUpgrade, ACHIEVEMENT_10, eAwardType_Achievement); 442 ProfileManager.RegisterAward(eAward_DeliciousFish, ACHIEVEMENT_11, eAwardType_Achievement); 443 ProfileManager.RegisterAward(eAward_OnARail, ACHIEVEMENT_12, eAwardType_Achievement); 444 ProfileManager.RegisterAward(eAward_TimeToStrike, ACHIEVEMENT_13, eAwardType_Achievement); 445 ProfileManager.RegisterAward(eAward_MonsterHunter, ACHIEVEMENT_14, eAwardType_Achievement); 446 ProfileManager.RegisterAward(eAward_CowTipper, ACHIEVEMENT_15, eAwardType_Achievement); 447 ProfileManager.RegisterAward(eAward_WhenPigsFly, ACHIEVEMENT_16, eAwardType_Achievement); 448 ProfileManager.RegisterAward(eAward_LeaderOfThePack, ACHIEVEMENT_17, eAwardType_Achievement); 449 ProfileManager.RegisterAward(eAward_MOARTools, ACHIEVEMENT_18, eAwardType_Achievement); 450 ProfileManager.RegisterAward(eAward_DispenseWithThis, ACHIEVEMENT_19, eAwardType_Achievement); 451 ProfileManager.RegisterAward(eAward_InToTheNether, ACHIEVEMENT_20, eAwardType_Achievement); 452 453 ProfileManager.RegisterAward(eAward_mine100Blocks, GAMER_PICTURE_GAMERPIC1, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC1,IDS_CONFIRM_OK); 454 ProfileManager.RegisterAward(eAward_kill10Creepers, GAMER_PICTURE_GAMERPIC2, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC2,IDS_CONFIRM_OK); 455 456 ProfileManager.RegisterAward(eAward_eatPorkChop, AVATARASSETAWARD_PORKCHOP_TSHIRT, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR1,IDS_CONFIRM_OK); 457 ProfileManager.RegisterAward(eAward_play100Days, AVATARASSETAWARD_WATCH, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR2,IDS_CONFIRM_OK); 458 ProfileManager.RegisterAward(eAward_arrowKillCreeper, AVATARASSETAWARD_CAP, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR3,IDS_CONFIRM_OK); 459 460 ProfileManager.RegisterAward(eAward_socialPost, 0, eAwardType_Theme,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_THEME,IDS_CONFIRM_OK,THEME_NAME,THEME_FILESIZE); 461 462 // Rich Presence init - number of presences, number of contexts 463 ProfileManager.RichPresenceInit(4,1); 464 ProfileManager.RegisterRichPresenceContext(CONTEXT_GAME_STATE); 465 466 app.LoadXuiResources(); 467 468 // initialise the storage manager with a default save display name, a Minimum save size, and a callback for displaying the saving message 469 StorageManager.Init(app.GetString(IDS_DEFAULT_SAVENAME),"savegame.dat",FIFTY_ONE_MB,&CConsoleMinecraftApp::DisplaySavingMessage,(LPVOID)&app,GROUP_ID); 470 // Set up the global title storage path 471 StorageManager.StoreTMSPathName(); 472 473 // 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 474 ProfileManager.SetSignInChangeCallback(&CConsoleMinecraftApp::SignInChangeCallback,(LPVOID)&app); 475 476 // set a function to be called when the ethernet is disconnected, so we can back out if required 477 ProfileManager.SetNotificationsCallback(&CConsoleMinecraftApp::NotificationsCallback,(LPVOID)&app); 478 479 // Set a callback for the default player options to be set - when there is no profile data for the player 480 ProfileManager.SetDefaultOptionsCallback(&CConsoleMinecraftApp::DefaultOptionsCallback,(LPVOID)&app); 481 // Set a callback to deal with old profile versions needing updated to new versions 482 ProfileManager.SetOldProfileVersionCallback(&CConsoleMinecraftApp::OldProfileVersionCallback,(LPVOID)&app); 483 484 // Set a callback for when there is a read error on profile data 485 ProfileManager.SetProfileReadErrorCallback(&CConsoleMinecraftApp::ProfileReadErrorCallback,(LPVOID)&app); 486 487 488 // QNet needs to be setup after profile manager, as we do not want its Notify listener to handle 489 // XN_SYS_SIGNINCHANGED notifications. This does mean that we need to have a callback in the 490 // ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet. 491 g_NetworkManager.Initialise(); 492 493 app.InitGameSettings(); 494 495 // debug switch to trial version 496 ProfileManager.SetDebugFullOverride(true); 497 498 //ProfileManager.AddDLC(2); 499 StorageManager.SetDLCPackageRoot("DLCDrive"); 500 StorageManager.RegisterMarketplaceCountsCallback(&CConsoleMinecraftApp::MarketplaceCountsCallback,(LPVOID)&app); 501 // Kinect ! 502 503// if(XNuiGetHardwareStatus()!=0) 504// { 505// // If the Kinect Sensor is not physically connected, this function returns 0. 506// NuiInitialize(NUI_INITIALIZE_FLAG_USES_HIGH_QUALITY_COLOR | NUI_INITIALIZE_FLAG_USES_DEPTH | 507// NUI_INITIALIZE_FLAG_EXTRAPOLATE_FLOOR_PLANE | NUI_INITIALIZE_FLAG_USES_FITNESS | NUI_INITIALIZE_FLAG_NUI_GUIDE_DISABLED | NUI_INITIALIZE_FLAG_SUPPRESS_AUTOMATIC_UI,NUI_INITIALIZE_DEFAULT_HARDWARE_THREAD ); 508// } 509 510 // Sentient ! 511 hr = TelemetryManager->Init(); 512 513 // Initialise TLS for tesselator, for this main thread 514 Tesselator::CreateNewThreadStorage(1024*1024); 515 // Initialise TLS for AABB and Vec3 pools, for this main thread 516 AABB::CreateNewThreadStorage(); 517 Vec3::CreateNewThreadStorage(); 518 IntCache::CreateNewThreadStorage(); 519 Compression::CreateNewThreadStorage(); 520 OldChunkStorage::CreateNewThreadStorage(); 521 Level::enableLightingCache(); 522 Tile::CreateNewThreadStorage(); 523 524 Minecraft::main(); 525 Minecraft *pMinecraft=Minecraft::GetInstance(); 526 //bool bDisplayPauseMenu=false; 527 528 // set the default gamma level 529 float fVal=50.0f*327.68f; 530 RenderManager.UpdateGamma((unsigned short)fVal); 531 532 // load any skins 533 //app.AddSkinsToMemoryTextureFiles(); 534 535 // set the achievement text for a trial achievement, now we have the string table loaded 536 ProfileManager.SetTrialTextStringTable(app.GetStringTable(),IDS_CONFIRM_OK, IDS_CONFIRM_CANCEL); 537 ProfileManager.SetTrialAwardText(eAwardType_Achievement,IDS_UNLOCK_TITLE,IDS_UNLOCK_ACHIEVEMENT_TEXT); 538 ProfileManager.SetTrialAwardText(eAwardType_GamerPic,IDS_UNLOCK_TITLE,IDS_UNLOCK_GAMERPIC_TEXT); 539 ProfileManager.SetTrialAwardText(eAwardType_AvatarItem,IDS_UNLOCK_TITLE,IDS_UNLOCK_AVATAR_TEXT); 540 ProfileManager.SetTrialAwardText(eAwardType_Theme,IDS_UNLOCK_TITLE,IDS_UNLOCK_THEME_TEXT); 541 ProfileManager.SetUpsellCallback(&app.UpsellReturnedCallback,&app); 542 543 // Set up a debug character press sequence 544#ifndef _FINAL_BUILD 545 app.SetDebugSequence("LRLRYYY"); 546#endif 547 548 // Initialise the social networking manager. 549 CSocialManager::Instance()->Initialise(); 550 551 // Update the base scene quick selects now that the minecraft class exists 552 //CXuiSceneBase::UpdateScreenSettings(0); 553 554 app.InitialiseTips(); 555 556 DWORD initData=0; 557 558 559 560#ifndef _FINAL_BUILD 561#ifndef _DEBUG 562 #pragma message(__LOC__"Need to define the _FINAL_BUILD before submission") 563#endif 564#endif 565 566 // 4J-PB - Having to add in code to stop people being able to play a build from Partnernet unless they know the code 567#ifdef _CONTENT_PACKAGE 568#ifndef _FINAL_BUILD 569// app.SetPartnernetPasswordRunning(true); 570// 571// app.NavigateToScene(XUSER_INDEX_ANY,eUIScene_PartnernetPassword,&initData); 572// 573// while(app.PartnernetPasswordRunning()) 574// { 575// ProfileManager.Tick(); 576// InputManager.Tick(); // need to ruin this for the edit box 577// 578// // Tick XUI 579// app.RunFrame(); 580// 581// // 4J : WESTY : Added to ensure we always have clear background for intro. 582// RenderManager.SetClearColour(D3DCOLOR_RGBA(0,0,0,255)); 583// RenderManager.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 584// 585// // Render XUI 586// hr = app.Render(); 587// 588// // Present the frame. 589// RenderManager.Present(); 590// 591// // Update XUI Timers 592// hr = XuiTimersRun(); 593// } 594#endif 595#endif 596 // Set the default sound levels 597 pMinecraft->options->set(Options::Option::MUSIC,1.0f); 598 pMinecraft->options->set(Options::Option::SOUND,1.0f); 599 600 app.NavigateToScene(XUSER_INDEX_ANY,eUIScene_Intro,&initData); 601 602 //Sleep(10000); 603 604 // Intro loop ? 605 while(app.IntroRunning()) 606 { 607 ProfileManager.Tick(); 608 // Tick XUI 609 app.RunFrame(); 610 611 // 4J : WESTY : Added to ensure we always have clear background for intro. 612 RenderManager.SetClearColour(D3DCOLOR_RGBA(0,0,0,255)); 613 RenderManager.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 614 615 // Render XUI 616 hr = app.Render(); 617 618 // Present the frame. 619 RenderManager.Present(); 620 621 // Update XUI Timers 622 hr = XuiTimersRun(); 623 } 624 625 while( TRUE ) 626 { 627 if(pMinecraft->soundEngine->isStreamingWavebankReady() && 628 !pMinecraft->soundEngine->GetIsPlayingStreamingGameMusic() && 629 !pMinecraft->soundEngine->GetIsPlayingStreamingCDMusic() ) 630 { 631 // play some music in the menus 632 pMinecraft->soundEngine->playStreaming(L"", 0, 0, 0, 0, 0, false); 633 } 634 app.UpdateTime(); 635 PIXBeginNamedEvent(0,"Input manager tick"); 636 InputManager.Tick(); 637 PIXEndNamedEvent(); 638 PIXBeginNamedEvent(0,"Profile manager tick"); 639 ProfileManager.Tick(); 640 PIXEndNamedEvent(); 641 PIXBeginNamedEvent(0,"Storage manager tick"); 642 StorageManager.Tick(); 643 PIXEndNamedEvent(); 644 PIXBeginNamedEvent(0,"Render manager tick"); 645 RenderManager.Tick(); 646 PIXEndNamedEvent(); 647 648 // Tick the social networking manager. 649 PIXBeginNamedEvent(0,"Social network manager tick"); 650 CSocialManager::Instance()->Tick(); 651 PIXEndNamedEvent(); 652 653 // Tick sentient. 654 PIXBeginNamedEvent(0,"Sentient tick"); 655 MemSect(37); 656 TelemetryManager->Tick(); 657 MemSect(0); 658 PIXEndNamedEvent(); 659 660 PIXBeginNamedEvent(0,"Network manager do work #1"); 661 g_NetworkManager.DoWork(); 662 PIXEndNamedEvent(); 663 664 LeaderboardManager::Instance()->Tick(); 665 // Render game graphics. 666 if(app.GetGameStarted()) 667 { 668 pMinecraft->run_middle(); 669 app.SetAppPaused( g_NetworkManager.IsLocalGame() && g_NetworkManager.GetPlayerCount() == 1 && app.IsPauseMenuDisplayed(ProfileManager.GetPrimaryPad()) ); 670 } 671 else 672 { 673 MemSect(28); 674 pMinecraft->soundEngine->tick(NULL, 0.0f); 675 MemSect(0); 676 pMinecraft->textures->tick(true,false); 677 IntCache::Reset(); 678 if( app.GetReallyChangingSessionType() ) 679 { 680 pMinecraft->tickAllConnections(); // Added to stop timing out when we are waiting after converting to an offline game 681 } 682 } 683 684 pMinecraft->soundEngine->playMusicTick(); 685 686 687#ifdef MEMORY_TRACKING 688 static bool bResetMemTrack = false; 689 static bool bDumpMemTrack = false; 690 691 MemPixStuff(); 692 693 if( bResetMemTrack ) 694 { 695 ResetMem(); 696 MEMORYSTATUS memStat; 697 GlobalMemoryStatus(&memStat); 698 printf("RESETMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); 699 bResetMemTrack = false; 700 } 701 702 if( bDumpMemTrack ) 703 { 704 DumpMem(); 705 bDumpMemTrack = false; 706 MEMORYSTATUS memStat; 707 GlobalMemoryStatus(&memStat); 708 printf("DUMPMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); 709 printf("Renderer used: %d\n",RenderManager.CBuffSize(-1)); 710 } 711#endif 712#if 0 713 static bool bDumpTextureUsage = false; 714 if( bDumpTextureUsage ) 715 { 716 RenderManager.TextureGetStats(); 717 bDumpTextureUsage = false; 718 } 719#endif 720 721 app.HandleButtonPresses(); 722 723 // store the minecraft renderstates, and re-set them after the xui render 724 GetRenderAndSamplerStates(pDevice,RenderStateA,SamplerStateA); 725 726 // Tick XUI 727 PIXBeginNamedEvent(0,"Xui running"); 728 app.RunFrame(); 729 PIXEndNamedEvent(); 730 731 // Render XUI 732 733 PIXBeginNamedEvent(0,"XUI render"); 734 MemSect(7); 735 hr = app.Render(); 736 MemSect(0); 737 GetRenderAndSamplerStates(pDevice,RenderStateA2,SamplerStateA2); 738 PIXEndNamedEvent(); 739 740 for(int i=0;i<8;i++) 741 { 742 if(RenderStateA2[i]!=RenderStateA[i]) 743 { 744 //printf("Reseting RenderStateA[%d] after a XUI render\n",i); 745 pDevice->SetRenderState(RenderStateModes[i],RenderStateA[i]); 746 } 747 } 748 for(int i=0;i<5;i++) 749 { 750 if(SamplerStateA2[i]!=SamplerStateA[i]) 751 { 752 //printf("Reseting SamplerStateA[%d] after a XUI render\n",i); 753 pDevice->SetSamplerState(0,SamplerStateModes[i],SamplerStateA[i]); 754 } 755 } 756 757 RenderManager.Set_matrixDirty(); 758 // Present the frame. 759 PIXBeginNamedEvent(0,"Frame present"); 760 RenderManager.Present(); 761 PIXEndNamedEvent(); 762 763 app.CheckMenuDisplayed(); 764 PIXBeginNamedEvent(0,"Profile load check"); 765 // has the game defined profile data been changed (by a profile load) 766 if(app.uiGameDefinedDataChangedBitmask!=0) 767 { 768 void *pData; 769 for(int i=0;i<XUSER_MAX_COUNT;i++) 770 { 771 if(app.uiGameDefinedDataChangedBitmask&(1<<i)) 772 { 773 // It has - game needs to update its values with the data from the profile 774 pData=ProfileManager.GetGameDefinedProfileData(i); 775 // reset the changed flag 776 app.ClearGameSettingsChangedFlag(i); 777 app.DebugPrintf("*** - APPLYING GAME SETTINGS CHANGE for pad %d\n",i); 778 app.ApplyGameSettingsChanged(i); 779 780#ifdef _DEBUG_MENUS_ENABLED 781 if(app.DebugSettingsOn()) 782 { 783 app.ActionDebugMask(i); 784 } 785 else 786 { 787 // force debug mask off 788 app.ActionDebugMask(i,true); 789 } 790#endif 791 // clear the stats first - there could have beena signout and sign back in in the menus 792 // need to clear the player stats - can't assume it'll be done in setlevel - we may not be in the game 793 pMinecraft->stats[ i ]->clear(); 794 pMinecraft->stats[i]->parse(pData); 795 796 // Update the selected item position based on the user's UI setting 797 CXuiSceneBase::UpdateSelectedItemPos(i); 798 } 799 } 800 801 // Check to see if we can post to social networks. 802 CSocialManager::Instance()->RefreshPostingCapability(); 803 804 // clear the flag 805 app.uiGameDefinedDataChangedBitmask=0; 806 807 // Check if any profile write are needed 808 app.CheckGameSettingsChanged(); 809 810 } 811 PIXEndNamedEvent(); 812 app.TickDLCOffersRetrieved(); 813 app.TickTMSPPFilesRetrieved(); 814 815 PIXBeginNamedEvent(0,"Network manager do work #2"); 816 g_NetworkManager.DoWork(); 817 PIXEndNamedEvent(); 818 819 PIXBeginNamedEvent(0,"Misc extra xui"); 820 // Update XUI Timers 821 hr = XuiTimersRun(); 822 823 // Any threading type things to deal with from the xui side? 824 app.HandleXuiActions(); 825 PIXEndNamedEvent(); 826 827 // 4J-PB - Update the trial timer display if we are in the trial version 828 if(!ProfileManager.IsFullVersion()) 829 { 830 // display the trial timer 831 if(app.GetGameStarted()) 832 { 833 // 4J-PB - if the game is paused, add the elapsed time to the trial timer count so it doesn't tick down 834 if(app.IsAppPaused()) 835 { 836 app.UpdateTrialPausedTimer(); 837 } 838 CXuiSceneBase::UpdateTrialTimer(ProfileManager.GetPrimaryPad()); 839 } 840 } 841 else 842 { 843 // need to turn off the trial timer if it was on , and we've unlocked the full version 844 if(bTrialTimerDisplayed) 845 { 846 CXuiSceneBase::ShowTrialTimer(FALSE); 847 bTrialTimerDisplayed=false; 848 } 849 } 850 851 // Fix for #7318 - Title crashes after short soak in the leaderboards menu 852 // A memory leak was caused because the icon renderer kept creating new Vec3's because the pool wasn't reset 853 Vec3::resetPool(); 854 } 855 856 // Free resources, unregister custom classes, and exit. 857 app.Uninit(); 858 pDevice->Release(); 859} 860 861 862void GetRenderAndSamplerStates(IDirect3DDevice9 *pDevice,DWORD *RenderStateA,DWORD *SamplerStateA) 863{ 864 for(int i=0;i<8;i++) 865 { 866 pDevice->GetRenderState(RenderStateModes[i],&RenderStateA[i]); 867 } 868 869 for(int i=0;i<5;i++) 870 { 871 pDevice->GetSamplerState(0,SamplerStateModes[i],&SamplerStateA[i]); 872 } 873} 874 875void SetRenderAndSamplerStates(IDirect3DDevice9 *pDevice,DWORD *RenderStateA,DWORD *SamplerStateA) 876{ 877 for(int i=0;i<8;i++) 878 { 879 pDevice->SetRenderState(RenderStateModes[i],RenderStateA[i]); 880 } 881 882 for(int i=0;i<5;i++) 883 { 884 pDevice->SetSamplerState(0,SamplerStateModes[i],SamplerStateA[i]); 885 } 886} 887 888#ifdef MEMORY_TRACKING 889 890int totalAllocGen = 0; 891unordered_map<int,int> allocCounts; 892bool trackEnable = false; 893bool trackStarted = false; 894volatile size_t sizeCheckMin = 1160; 895volatile size_t sizeCheckMax = 1160; 896volatile int sectCheck = 48; 897CRITICAL_SECTION memCS; 898DWORD tlsIdx; 899 900LPVOID XMemAlloc(SIZE_T dwSize, DWORD dwAllocAttributes) 901{ 902 if( !trackStarted ) 903 { 904 void *p = XMemAllocDefault(dwSize,dwAllocAttributes); 905 size_t realSize = XMemSizeDefault(p, dwAllocAttributes); 906 totalAllocGen += realSize; 907 return p; 908 } 909 910 EnterCriticalSection(&memCS); 911 912 void *p=XMemAllocDefault(dwSize + 16,dwAllocAttributes); 913 size_t realSize = XMemSizeDefault(p,dwAllocAttributes) - 16; 914 915 if( trackEnable ) 916 { 917#if 1 918 int sect = ((int) TlsGetValue(tlsIdx)) & 0x3f; 919 *(((unsigned char *)p)+realSize) = sect; 920 921 if( ( realSize >= sizeCheckMin ) && ( realSize <= sizeCheckMax ) && ( ( sect == sectCheck ) || ( sectCheck == -1 ) ) ) 922 { 923 app.DebugPrintf("Found one\n"); 924 } 925#endif 926 927 if( p ) 928 { 929 totalAllocGen += realSize; 930 trackEnable = false; 931 int key = ( sect << 26 ) | realSize; 932 int oldCount = allocCounts[key]; 933 allocCounts[key] = oldCount + 1; 934 935 trackEnable = true; 936 } 937 } 938 939 LeaveCriticalSection(&memCS); 940 941 return p; 942} 943 944void* operator new (size_t size) 945{ 946 return (unsigned char *)XMemAlloc(size,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); 947} 948 949void operator delete (void *p) 950{ 951 XMemFree(p,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); 952} 953 954void WINAPI XMemFree(PVOID pAddress, DWORD dwAllocAttributes) 955{ 956 bool special = false; 957 if( dwAllocAttributes == 0 ) 958 { 959 dwAllocAttributes = MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP); 960 special = true; 961 } 962 if(!trackStarted ) 963 { 964 size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes); 965 XMemFreeDefault(pAddress, dwAllocAttributes); 966 totalAllocGen -= realSize; 967 return; 968 } 969 EnterCriticalSection(&memCS); 970 if( pAddress ) 971 { 972 size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes) - 16; 973 974 if(trackEnable) 975 { 976 int sect = *(((unsigned char *)pAddress)+realSize); 977 totalAllocGen -= realSize; 978 trackEnable = false; 979 int key = ( sect << 26 ) | realSize; 980 int oldCount = allocCounts[key]; 981 allocCounts[key] = oldCount - 1; 982 trackEnable = true; 983 984 } 985 XMemFreeDefault(pAddress, dwAllocAttributes); 986 } 987 LeaveCriticalSection(&memCS); 988} 989 990SIZE_T WINAPI XMemSize( 991 PVOID pAddress, 992 DWORD dwAllocAttributes 993) 994{ 995 if( trackStarted ) 996 { 997 return XMemSizeDefault(pAddress, dwAllocAttributes) - 16; 998 } 999 else 1000 { 1001 return XMemSizeDefault(pAddress, dwAllocAttributes); 1002 } 1003} 1004 1005 1006void DumpMem() 1007{ 1008 int totalLeak = 0; 1009 for(auto it = allocCounts.begin(); it != allocCounts.end(); it++ ) 1010 { 1011 if(it->second > 0 ) 1012 { 1013 app.DebugPrintf("%d %d %d %d\n",( it->first >> 26 ) & 0x3f,it->first & 0x03ffffff, it->second, (it->first & 0x03ffffff) * it->second); 1014 totalLeak += ( it->first & 0x03ffffff ) * it->second; 1015 } 1016 } 1017 app.DebugPrintf("Total %d\n",totalLeak); 1018} 1019 1020void ResetMem() 1021{ 1022 if( !trackStarted ) 1023 { 1024 trackEnable = true; 1025 trackStarted = true; 1026 totalAllocGen = 0; 1027 InitializeCriticalSection(&memCS); 1028 tlsIdx = TlsAlloc(); 1029 } 1030 EnterCriticalSection(&memCS); 1031 trackEnable = false; 1032 allocCounts.clear(); 1033 trackEnable = true; 1034 LeaveCriticalSection(&memCS); 1035} 1036 1037void MemSect(int section) 1038{ 1039 unsigned int value = (unsigned int)TlsGetValue(tlsIdx); 1040 if( section == 0 ) // pop 1041 { 1042 value = (value >> 6) & 0x03ffffff; 1043 } 1044 else 1045 { 1046 value = (value << 6) | section; 1047 } 1048 TlsSetValue(tlsIdx, (LPVOID)value); 1049} 1050 1051void MemPixStuff() 1052{ 1053 const int MAX_SECT = 56; 1054 1055 int totals[MAX_SECT] = {0}; 1056 1057 for(auto it = allocCounts.begin(); it != allocCounts.end(); it++ ) 1058 { 1059 if(it->second > 0 ) 1060 { 1061 int sect = ( it->first >> 26 ) & 0x3f; 1062 int bytes = it->first & 0x03ffffff; 1063 totals[sect] += bytes * it->second; 1064 } 1065 } 1066 1067 unsigned int allSectsTotal = 0; 1068 for( int i = 0; i < MAX_SECT; i++ ) 1069 { 1070 allSectsTotal += totals[i]; 1071 PIXAddNamedCounter(((float)totals[i])/1024.0f,"MemSect%d",i); 1072 } 1073 1074 PIXAddNamedCounter(((float)allSectsTotal)/(4096.0f),"MemSect total pages"); 1075} 1076 1077#endif