the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 1698 lines 69 kB view raw
1// Minecraft.cpp : Defines the entry point for the application. 2// 3 4#include "stdafx.h" 5 6#include <assert.h> 7#include <system_service.h> 8#include <codecvt> 9#include "GameConfig\Minecraft.spa.h" 10#include "..\MinecraftServer.h" 11#include "..\LocalPlayer.h" 12#include "..\..\Minecraft.World\ItemInstance.h" 13#include "..\..\Minecraft.World\MapItem.h" 14#include "..\..\Minecraft.World\Recipes.h" 15#include "..\..\Minecraft.World\Recipy.h" 16#include "..\..\Minecraft.World\Language.h" 17#include "..\..\Minecraft.World\StringHelpers.h" 18#include "..\..\Minecraft.World\AABB.h" 19#include "..\..\Minecraft.World\Vec3.h" 20#include "..\..\Minecraft.World\Level.h" 21#include "..\..\Minecraft.World\net.minecraft.world.level.tile.h" 22 23#include "..\ClientConnection.h" 24#include "..\User.h" 25#include "..\..\Minecraft.World\Socket.h" 26#include "..\..\Minecraft.World\ThreadName.h" 27#include "..\..\Minecraft.Client\StatsCounter.h" 28#include "..\ConnectScreen.h" 29//#include "Social\SocialManager.h" 30//#include "Leaderboards\LeaderboardManager.h" 31//#include "XUI\XUI_Scene_Container.h" 32//#include "NetworkManager.h" 33#include "..\..\Minecraft.Client\Tesselator.h" 34#include "..\..\Minecraft.Client\Options.h" 35#include "Sentient\SentientManager.h" 36#include "..\..\Minecraft.World\IntCache.h" 37#include "..\Textures.h" 38#include "..\..\Minecraft.World\compression.h" 39#include "..\..\Minecraft.World\OldChunkStorage.h" 40#include "Leaderboards\OrbisLeaderboardManager.h" 41 42#include "Network/Orbis_NPToolkit.h" 43#include "Orbis\Network\SonyVoiceChat_Orbis.h" 44 45#define THEME_NAME "584111F70AAAAAAA" 46#define THEME_FILESIZE 2797568 47 48//#define THREE_MB 3145728 // minimum save size (checking for this on a selected device) 49//#define FIVE_MB 5242880 // minimum save size (checking for this on a selected device) 50//#define FIFTY_TWO_MB (1024*1024*52) // Maximum TCR space required for a save (checking for this on a selected device) 51#define FIFTY_ONE_MB (1000000*51) // Maximum TCR space required for a save is 52MB (checking for this on a selected device) 52 53//#define PROFILE_VERSION 3 // new version for the interim bug fix 166 TU 54#define NUM_PROFILE_VALUES 5 55#define NUM_PROFILE_SETTINGS 4 56DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]= 57{ 58#ifdef _XBOX 59 XPROFILE_OPTION_CONTROLLER_VIBRATION, 60 XPROFILE_GAMER_YAXIS_INVERSION, 61 XPROFILE_GAMER_CONTROL_SENSITIVITY, 62 XPROFILE_GAMER_ACTION_MOVEMENT_CONTROL, 63 XPROFILE_TITLE_SPECIFIC1, 64#else 65 0,0,0,0,0 66#endif 67}; 68 69//------------------------------------------------------------------------------------- 70// Time Since fAppTime is a float, we need to keep the quadword app time 71// as a LARGE_INTEGER so that we don't lose precision after running 72// for a long time. 73//------------------------------------------------------------------------------------- 74 75// functions for storing and converting rich presence strings from wchar to utf8 76uint8_t * AddRichPresenceString(int iID); 77void FreeRichPresenceStrings(); 78 79BOOL g_bWidescreen = TRUE; 80 81 82void DefineActions(void) 83{ 84 // The app needs to define the actions required, and the possible mappings for these 85 86 // Split into Menu actions, and in-game actions 87 88 if(InputManager.IsCircleCrossSwapped()) 89 { 90 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_A, _PS4_JOY_BUTTON_O); 91 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OK, _PS4_JOY_BUTTON_O); 92 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_B, _PS4_JOY_BUTTON_X); 93 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_CANCEL, _PS4_JOY_BUTTON_X); 94 } 95 else 96 { 97 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_A, _PS4_JOY_BUTTON_X); 98 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OK, _PS4_JOY_BUTTON_X); 99 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_B, _PS4_JOY_BUTTON_O); 100 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_CANCEL, _PS4_JOY_BUTTON_O); 101 } 102 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_X, _PS4_JOY_BUTTON_SQUARE); 103 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_Y, _PS4_JOY_BUTTON_TRIANGLE); 104 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_UP, _PS4_JOY_BUTTON_DPAD_UP | _PS4_JOY_BUTTON_LSTICK_UP); 105 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_DOWN, _PS4_JOY_BUTTON_DPAD_DOWN | _PS4_JOY_BUTTON_LSTICK_DOWN); 106 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_LEFT, _PS4_JOY_BUTTON_DPAD_LEFT | _PS4_JOY_BUTTON_LSTICK_LEFT); 107 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_RIGHT, _PS4_JOY_BUTTON_DPAD_RIGHT | _PS4_JOY_BUTTON_LSTICK_RIGHT); 108 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAGEUP, _PS4_JOY_BUTTON_L2); 109 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAGEDOWN, _PS4_JOY_BUTTON_R2); 110 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_RIGHT_SCROLL, _PS4_JOY_BUTTON_R1); 111 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_LEFT_SCROLL, _PS4_JOY_BUTTON_L1); 112 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAUSEMENU, _PS4_JOY_BUTTON_OPTIONS); 113 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_STICK_PRESS, _PS4_JOY_BUTTON_L3); 114 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_PRESS, _PS4_JOY_BUTTON_R3); 115 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_UP, _PS4_JOY_BUTTON_RSTICK_UP); 116 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_DOWN, _PS4_JOY_BUTTON_RSTICK_DOWN); 117 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_LEFT, _PS4_JOY_BUTTON_RSTICK_LEFT); 118 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_RIGHT, _PS4_JOY_BUTTON_RSTICK_RIGHT); 119 120 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_JUMP, _PS4_JOY_BUTTON_X); 121 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_FORWARD, _PS4_JOY_BUTTON_LSTICK_UP); 122 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_BACKWARD, _PS4_JOY_BUTTON_LSTICK_DOWN); 123 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LEFT, _PS4_JOY_BUTTON_LSTICK_LEFT); 124 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RIGHT, _PS4_JOY_BUTTON_LSTICK_RIGHT); 125 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_LEFT, _PS4_JOY_BUTTON_RSTICK_LEFT); 126 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_RIGHT, _PS4_JOY_BUTTON_RSTICK_RIGHT); 127 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_UP, _PS4_JOY_BUTTON_RSTICK_UP); 128 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_DOWN, _PS4_JOY_BUTTON_RSTICK_DOWN); 129 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_USE, _PS4_JOY_BUTTON_L2); 130 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_ACTION, _PS4_JOY_BUTTON_R2); 131 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RIGHT_SCROLL, _PS4_JOY_BUTTON_R1); 132 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LEFT_SCROLL, _PS4_JOY_BUTTON_L1); 133 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_INVENTORY, _PS4_JOY_BUTTON_TRIANGLE); 134 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_PAUSEMENU, _PS4_JOY_BUTTON_OPTIONS); 135 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DROP, _PS4_JOY_BUTTON_O); 136 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_SNEAK_TOGGLE, _PS4_JOY_BUTTON_R3); 137 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_CRAFTING, _PS4_JOY_BUTTON_SQUARE); 138 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _PS4_JOY_BUTTON_L3); 139 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_GAME_INFO, _PS4_JOY_BUTTON_TOUCHPAD); 140 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_LEFT, _PS4_JOY_BUTTON_DPAD_LEFT); 141 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_RIGHT, _PS4_JOY_BUTTON_DPAD_RIGHT); 142 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_UP, _PS4_JOY_BUTTON_DPAD_UP); 143 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_DOWN, _PS4_JOY_BUTTON_DPAD_DOWN); 144 145 if(InputManager.IsCircleCrossSwapped()) 146 { 147 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_A, _PS4_JOY_BUTTON_O); 148 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OK, _PS4_JOY_BUTTON_O); 149 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_B, _PS4_JOY_BUTTON_X); 150 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_CANCEL, _PS4_JOY_BUTTON_X); 151 } 152 else 153 { 154 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_A, _PS4_JOY_BUTTON_X); 155 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OK, _PS4_JOY_BUTTON_X); 156 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_B, _PS4_JOY_BUTTON_O); 157 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_CANCEL, _PS4_JOY_BUTTON_O); 158 } 159 160 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_X, _PS4_JOY_BUTTON_SQUARE); 161 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_Y, _PS4_JOY_BUTTON_TRIANGLE); 162 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_UP, _PS4_JOY_BUTTON_DPAD_UP | _PS4_JOY_BUTTON_LSTICK_UP); 163 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_DOWN, _PS4_JOY_BUTTON_DPAD_DOWN | _PS4_JOY_BUTTON_LSTICK_DOWN); 164 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_LEFT, _PS4_JOY_BUTTON_DPAD_LEFT | _PS4_JOY_BUTTON_LSTICK_LEFT); 165 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_RIGHT, _PS4_JOY_BUTTON_DPAD_RIGHT | _PS4_JOY_BUTTON_LSTICK_RIGHT); 166 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAGEUP, _PS4_JOY_BUTTON_L1); 167 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAGEDOWN, _PS4_JOY_BUTTON_R2); 168 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_RIGHT_SCROLL, _PS4_JOY_BUTTON_R1); 169 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_LEFT_SCROLL, _PS4_JOY_BUTTON_L1); 170 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAUSEMENU, _PS4_JOY_BUTTON_TOUCHPAD); 171 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_STICK_PRESS, _PS4_JOY_BUTTON_L3); 172 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_PRESS, _PS4_JOY_BUTTON_R3); 173 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_UP, _PS4_JOY_BUTTON_RSTICK_UP); 174 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_DOWN, _PS4_JOY_BUTTON_RSTICK_DOWN); 175 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_LEFT, _PS4_JOY_BUTTON_RSTICK_LEFT); 176 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_RIGHT, _PS4_JOY_BUTTON_RSTICK_RIGHT); 177 178 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_JUMP, _PS4_JOY_BUTTON_R1); 179 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_FORWARD, _PS4_JOY_BUTTON_LSTICK_UP); 180 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_BACKWARD, _PS4_JOY_BUTTON_LSTICK_DOWN); 181 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LEFT, _PS4_JOY_BUTTON_LSTICK_LEFT); 182 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RIGHT, _PS4_JOY_BUTTON_LSTICK_RIGHT); 183 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_LEFT, _PS4_JOY_BUTTON_RSTICK_LEFT); 184 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_RIGHT, _PS4_JOY_BUTTON_RSTICK_RIGHT); 185 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_UP, _PS4_JOY_BUTTON_RSTICK_UP); 186 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_DOWN, _PS4_JOY_BUTTON_RSTICK_DOWN); 187 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_USE, _PS4_JOY_BUTTON_R2); 188 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_ACTION, _PS4_JOY_BUTTON_L2); 189 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RIGHT_SCROLL, _PS4_JOY_BUTTON_DPAD_RIGHT); 190 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LEFT_SCROLL, _PS4_JOY_BUTTON_DPAD_LEFT); 191 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_INVENTORY, _PS4_JOY_BUTTON_TRIANGLE); 192 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_PAUSEMENU, _PS4_JOY_BUTTON_OPTIONS); 193 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DROP, _PS4_JOY_BUTTON_O); 194 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_SNEAK_TOGGLE, _PS4_JOY_BUTTON_L3); 195 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_CRAFTING, _PS4_JOY_BUTTON_SQUARE); 196 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _PS4_JOY_BUTTON_R3); 197 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_GAME_INFO, _PS4_JOY_BUTTON_TOUCHPAD); 198 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_LEFT, _PS4_JOY_BUTTON_DPAD_LEFT); 199 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_RIGHT, _PS4_JOY_BUTTON_DPAD_RIGHT); 200 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_UP, _PS4_JOY_BUTTON_DPAD_UP); 201 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_DOWN, _PS4_JOY_BUTTON_DPAD_DOWN); 202 203 if(InputManager.IsCircleCrossSwapped()) 204 { 205 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_A, _PS4_JOY_BUTTON_O); 206 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OK, _PS4_JOY_BUTTON_O); 207 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_B, _PS4_JOY_BUTTON_X); 208 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_CANCEL, _PS4_JOY_BUTTON_X); 209 } 210 else 211 { 212 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_A, _PS4_JOY_BUTTON_X); 213 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OK, _PS4_JOY_BUTTON_X); 214 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_B, _PS4_JOY_BUTTON_O); 215 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_CANCEL, _PS4_JOY_BUTTON_O); 216 } 217 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_X, _PS4_JOY_BUTTON_SQUARE); 218 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_Y, _PS4_JOY_BUTTON_TRIANGLE); 219 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_UP, _PS4_JOY_BUTTON_DPAD_UP | _PS4_JOY_BUTTON_LSTICK_UP); 220 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_DOWN, _PS4_JOY_BUTTON_DPAD_DOWN | _PS4_JOY_BUTTON_LSTICK_DOWN); 221 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_LEFT, _PS4_JOY_BUTTON_DPAD_LEFT | _PS4_JOY_BUTTON_LSTICK_LEFT); 222 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_RIGHT, _PS4_JOY_BUTTON_DPAD_RIGHT | _PS4_JOY_BUTTON_LSTICK_RIGHT); 223 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAGEUP, _PS4_JOY_BUTTON_DPAD_UP | _PS4_JOY_BUTTON_L1); 224 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAGEDOWN, _PS4_JOY_BUTTON_R2); 225 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_RIGHT_SCROLL, _PS4_JOY_BUTTON_R1); 226 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_LEFT_SCROLL, _PS4_JOY_BUTTON_L1); 227 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAUSEMENU, _PS4_JOY_BUTTON_OPTIONS); 228 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_STICK_PRESS, _PS4_JOY_BUTTON_L3); 229 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_PRESS, _PS4_JOY_BUTTON_R3); 230 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_UP, _PS4_JOY_BUTTON_RSTICK_UP); 231 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_DOWN, _PS4_JOY_BUTTON_RSTICK_DOWN); 232 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_LEFT, _PS4_JOY_BUTTON_RSTICK_LEFT); 233 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_RIGHT, _PS4_JOY_BUTTON_RSTICK_RIGHT); 234 235 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_JUMP, _PS4_JOY_BUTTON_L2); 236 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_FORWARD, _PS4_JOY_BUTTON_LSTICK_UP); 237 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_BACKWARD, _PS4_JOY_BUTTON_LSTICK_DOWN); 238 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LEFT, _PS4_JOY_BUTTON_LSTICK_LEFT); 239 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RIGHT, _PS4_JOY_BUTTON_LSTICK_RIGHT); 240 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_LEFT, _PS4_JOY_BUTTON_RSTICK_LEFT); 241 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_RIGHT, _PS4_JOY_BUTTON_RSTICK_RIGHT); 242 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_UP, _PS4_JOY_BUTTON_RSTICK_UP); 243 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_DOWN, _PS4_JOY_BUTTON_RSTICK_DOWN); 244 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_USE, _PS4_JOY_BUTTON_R2); 245 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_ACTION, _PS4_JOY_BUTTON_X); 246 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RIGHT_SCROLL, _PS4_JOY_BUTTON_DPAD_RIGHT); 247 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LEFT_SCROLL, _PS4_JOY_BUTTON_DPAD_LEFT); 248 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_INVENTORY, _PS4_JOY_BUTTON_TRIANGLE); 249 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_PAUSEMENU, _PS4_JOY_BUTTON_OPTIONS); 250 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DROP, _PS4_JOY_BUTTON_O); 251 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_SNEAK_TOGGLE, _PS4_JOY_BUTTON_L1); 252 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_CRAFTING, _PS4_JOY_BUTTON_SQUARE); 253 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _PS4_JOY_BUTTON_L3); 254 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_GAME_INFO, _PS4_JOY_BUTTON_TOUCHPAD); 255 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_LEFT, _PS4_JOY_BUTTON_DPAD_LEFT); 256 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_RIGHT, _PS4_JOY_BUTTON_DPAD_RIGHT); 257 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_UP, _PS4_JOY_BUTTON_DPAD_UP); 258 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_DOWN, _PS4_JOY_BUTTON_DPAD_DOWN); 259 260 // Vita remote play map 261 if(InputManager.IsCircleCrossSwapped()) 262 { 263 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_A, _PS4_JOY_BUTTON_O); 264 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_OK, _PS4_JOY_BUTTON_O); 265 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_B, _PS4_JOY_BUTTON_X); 266 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_CANCEL, _PS4_JOY_BUTTON_X); 267 } 268 else 269 { 270 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_A, _PS4_JOY_BUTTON_X); 271 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_OK, _PS4_JOY_BUTTON_X); 272 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_B, _PS4_JOY_BUTTON_O); 273 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_CANCEL, _PS4_JOY_BUTTON_O); 274 } 275 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_X, _PS4_JOY_BUTTON_SQUARE); 276 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_Y, _PS4_JOY_BUTTON_TRIANGLE); 277 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_UP, _PS4_JOY_BUTTON_DPAD_UP | _PS4_JOY_BUTTON_LSTICK_UP); 278 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_DOWN, _PS4_JOY_BUTTON_DPAD_DOWN | _PS4_JOY_BUTTON_LSTICK_DOWN); 279 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_LEFT, _PS4_JOY_BUTTON_DPAD_LEFT | _PS4_JOY_BUTTON_LSTICK_LEFT); 280 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_RIGHT, _PS4_JOY_BUTTON_DPAD_RIGHT | _PS4_JOY_BUTTON_LSTICK_RIGHT); 281 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_PAUSEMENU, _PS4_JOY_BUTTON_OPTIONS); 282 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_OTHER_STICK_UP, _PS4_JOY_BUTTON_RSTICK_UP); 283 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_OTHER_STICK_DOWN, _PS4_JOY_BUTTON_RSTICK_DOWN); 284 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_OTHER_STICK_LEFT, _PS4_JOY_BUTTON_RSTICK_LEFT); 285 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_OTHER_STICK_RIGHT, _PS4_JOY_BUTTON_RSTICK_RIGHT); 286 287 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_PAGEUP, _PS4_JOY_BUTTON_L2); 288 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_PAGEDOWN, _PS4_JOY_BUTTON_R2); 289 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_RIGHT_SCROLL, _PS4_JOY_BUTTON_R1); 290 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_LEFT_SCROLL, _PS4_JOY_BUTTON_L1); 291 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_STICK_PRESS, _PS4_JOY_BUTTON_L3); 292 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_OTHER_STICK_PRESS, _PS4_JOY_BUTTON_R3); 293 294 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_JUMP, _PS4_JOY_BUTTON_X); 295 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_FORWARD, _PS4_JOY_BUTTON_LSTICK_UP); 296 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_BACKWARD, _PS4_JOY_BUTTON_LSTICK_DOWN); 297 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_LEFT, _PS4_JOY_BUTTON_LSTICK_LEFT); 298 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_RIGHT, _PS4_JOY_BUTTON_LSTICK_RIGHT); 299 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_LOOK_LEFT, _PS4_JOY_BUTTON_RSTICK_LEFT); 300 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_LOOK_RIGHT, _PS4_JOY_BUTTON_RSTICK_RIGHT); 301 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_LOOK_UP, _PS4_JOY_BUTTON_RSTICK_UP); 302 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_LOOK_DOWN, _PS4_JOY_BUTTON_RSTICK_DOWN); 303 304 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_INVENTORY, _PS4_JOY_BUTTON_TRIANGLE); 305 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_PAUSEMENU, _PS4_JOY_BUTTON_OPTIONS); 306 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_DROP, _PS4_JOY_BUTTON_O); 307 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_CRAFTING, _PS4_JOY_BUTTON_SQUARE); 308 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_GAME_INFO, _PS4_JOY_BUTTON_TOUCHPAD); 309 310 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_USE, _PS4_JOY_BUTTON_L1); 311 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_ACTION, _PS4_JOY_BUTTON_R1); 312 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_RIGHT_SCROLL, _PS4_JOY_BUTTON_R2 | _PS4_JOY_BUTTON_DPAD_RIGHT); 313 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_LEFT_SCROLL, _PS4_JOY_BUTTON_L2 | _PS4_JOY_BUTTON_DPAD_LEFT); 314 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _PS4_JOY_BUTTON_L3 | _PS4_JOY_BUTTON_DPAD_UP); 315 InputManager.SetGameJoypadMaps(MAP_STYLE_3,MINECRAFT_ACTION_SNEAK_TOGGLE, _PS4_JOY_BUTTON_R3 | _PS4_JOY_BUTTON_DPAD_DOWN); 316 317 // Touchpad mapping 318 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_TOUCHPAD_PRESS, _PS4_JOY_BUTTON_TOUCHPAD); 319 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_TOUCHPAD_PRESS, _PS4_JOY_BUTTON_TOUCHPAD); 320 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_TOUCHPAD_PRESS, _PS4_JOY_BUTTON_TOUCHPAD); 321 InputManager.SetGameJoypadMaps(MAP_STYLE_3,ACTION_MENU_TOUCHPAD_PRESS, _PS4_JOY_BUTTON_TOUCHPAD); 322 323 // Partial mapping for Vita TV (applied over other mappings) 324 325 InputManager.SetGameJoypadMaps(PARTIAL_MAP_1, MINECRAFT_ACTION_GAME_INFO, _PS4_JOY_BUTTON_DPAD_UP); 326} 327 328#if 0 329HRESULT InitD3D( IDirect3DDevice9 **ppDevice, 330 D3DPRESENT_PARAMETERS *pd3dPP ) 331{ 332 IDirect3D9 *pD3D; 333 334 pD3D = Direct3DCreate9( D3D_SDK_VERSION ); 335 336 // Set up the structure used to create the D3DDevice 337 // Using a permanent 1280x720 backbuffer now no matter what the actual video resolution.right Have also disabled letterboxing, 338 // which would letterbox a 1280x720 output if it detected a 4:3 video source - we're doing an anamorphic squash in this 339 // mode so don't need this functionality. 340 341 ZeroMemory( pd3dPP, sizeof(D3DPRESENT_PARAMETERS) ); 342 XVIDEO_MODE VideoMode; 343 XGetVideoMode( &VideoMode ); 344 g_bWidescreen = VideoMode.fIsWideScreen; 345 pd3dPP->BackBufferWidth = 1280; 346 pd3dPP->BackBufferHeight = 720; 347 pd3dPP->BackBufferFormat = D3DFMT_A8R8G8B8; 348 pd3dPP->BackBufferCount = 1; 349 pd3dPP->EnableAutoDepthStencil = TRUE; 350 pd3dPP->AutoDepthStencilFormat = D3DFMT_D24S8; 351 pd3dPP->SwapEffect = D3DSWAPEFFECT_DISCARD; 352 pd3dPP->PresentationInterval = D3DPRESENT_INTERVAL_ONE; 353 //pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX; 354 //ERR[D3D]: Can't set D3DPRESENTFLAG_NO_LETTERBOX when wide-screen is enabled 355 // in the launcher/dashboard. 356 if(g_bWidescreen) 357 pd3dPP->Flags=0; 358 else 359 pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX; 360 361 // Create the device. 362 return pD3D->CreateDevice( 363 0, 364 D3DDEVTYPE_HAL, 365 NULL, 366 D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_BUFFER_2_FRAMES, 367 pd3dPP, 368 ppDevice ); 369} 370#endif 371//#define MEMORY_TRACKING 372 373#ifdef MEMORY_TRACKING 374void ResetMem(); 375void DumpMem(); 376void MemPixStuff(); 377#else 378void MemSect(int sect) 379{ 380} 381#endif 382 383#ifndef __ORBIS__ 384HINSTANCE g_hInst = NULL; 385HWND g_hWnd = NULL; 386D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL; 387D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0; 388ID3D11Device* g_pd3dDevice = NULL; 389ID3D11DeviceContext* g_pImmediateContext = NULL; 390IDXGISwapChain* g_pSwapChain = NULL; 391ID3D11RenderTargetView* g_pRenderTargetView = NULL; 392ID3D11DepthStencilView* g_pDepthStencilView = NULL; 393ID3D11Texture2D* g_pDepthStencilBuffer = NULL; 394 395// 396// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) 397// 398// PURPOSE: Processes messages for the main window. 399// 400// WM_COMMAND - process the application menu 401// WM_PAINT - Paint the main window 402// WM_DESTROY - post a quit message and return 403// 404// 405LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 406{ 407 int wmId, wmEvent; 408 PAINTSTRUCT ps; 409 HDC hdc; 410 411 switch (message) 412 { 413 case WM_COMMAND: 414 wmId = LOWORD(wParam); 415 wmEvent = HIWORD(wParam); 416 // Parse the menu selections: 417 switch (wmId) 418 { 419 case IDM_EXIT: 420 DestroyWindow(hWnd); 421 break; 422 default: 423 return DefWindowProc(hWnd, message, wParam, lParam); 424 } 425 break; 426 case WM_PAINT: 427 hdc = BeginPaint(hWnd, &ps); 428 // TODO: Add any drawing code here... 429 EndPaint(hWnd, &ps); 430 break; 431 case WM_DESTROY: 432 PostQuitMessage(0); 433 break; 434 default: 435 return DefWindowProc(hWnd, message, wParam, lParam); 436 } 437 return 0; 438} 439 440 441// 442// FUNCTION: MyRegisterClass() 443// 444// PURPOSE: Registers the window class. 445// 446ATOM MyRegisterClass(HINSTANCE hInstance) 447{ 448 WNDCLASSEX wcex; 449 450 wcex.cbSize = sizeof(WNDCLASSEX); 451 452 wcex.style = CS_HREDRAW | CS_VREDRAW; 453 wcex.lpfnWndProc = WndProc; 454 wcex.cbClsExtra = 0; 455 wcex.cbWndExtra = 0; 456 wcex.hInstance = hInstance; 457 wcex.hIcon = LoadIcon(hInstance, "Minecraft"); 458 wcex.hCursor = LoadCursor(NULL, IDC_ARROW); 459 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 460 wcex.lpszMenuName = "Minecraft"; 461 wcex.lpszClassName = "MinecraftClass"; 462 wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); 463 464 return RegisterClassEx(&wcex); 465} 466 467// 468// FUNCTION: InitInstance(HINSTANCE, int) 469// 470// PURPOSE: Saves instance handle and creates main window 471// 472// COMMENTS: 473// 474// In this function, we save the instance handle in a global variable and 475// create and display the main program window. 476// 477BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) 478{ 479 g_hInst = hInstance; // Store instance handle in our global variable 480 481 g_hWnd = CreateWindow("MinecraftClass", "Minecraft", WS_OVERLAPPEDWINDOW, 482 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); 483 484 if (!g_hWnd) 485 { 486 return FALSE; 487 } 488 489 ShowWindow(g_hWnd, nCmdShow); 490 UpdateWindow(g_hWnd); 491 492 return TRUE; 493} 494 495 496//-------------------------------------------------------------------------------------- 497// Create Direct3D device and swap chain 498//-------------------------------------------------------------------------------------- 499HRESULT InitDevice() 500{ 501 HRESULT hr = S_OK; 502 503 RECT rc; 504 GetClientRect( g_hWnd, &rc ); 505 UINT width = rc.right - rc.left; 506 UINT height = rc.bottom - rc.top; 507 508 UINT createDeviceFlags = 0; 509#ifdef _DEBUG 510 createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; 511#endif 512 513 D3D_DRIVER_TYPE driverTypes[] = 514 { 515 D3D_DRIVER_TYPE_HARDWARE, 516 D3D_DRIVER_TYPE_WARP, 517 D3D_DRIVER_TYPE_REFERENCE, 518 }; 519 UINT numDriverTypes = ARRAYSIZE( driverTypes ); 520 521 D3D_FEATURE_LEVEL featureLevels[] = 522 { 523 D3D_FEATURE_LEVEL_11_0, 524 D3D_FEATURE_LEVEL_10_1, 525 D3D_FEATURE_LEVEL_10_0, 526 }; 527 UINT numFeatureLevels = ARRAYSIZE( featureLevels ); 528 529 DXGI_SWAP_CHAIN_DESC sd; 530 ZeroMemory( &sd, sizeof( sd ) ); 531 sd.BufferCount = 1; 532 sd.BufferDesc.Width = width; 533 sd.BufferDesc.Height = height; 534 sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 535 sd.BufferDesc.RefreshRate.Numerator = 60; 536 sd.BufferDesc.RefreshRate.Denominator = 1; 537 sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; 538 sd.OutputWindow = g_hWnd; 539 sd.SampleDesc.Count = 1; 540 sd.SampleDesc.Quality = 0; 541 sd.Windowed = TRUE; 542 543 for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ ) 544 { 545 g_driverType = driverTypes[driverTypeIndex]; 546 hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels, 547 D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext ); 548 if( HRESULT_SUCCEEDED( hr ) ) 549 break; 550 } 551 if( FAILED( hr ) ) 552 return hr; 553 554 // Create a render target view 555 ID3D11Texture2D* pBackBuffer = NULL; 556 hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer ); 557 if( FAILED( hr ) ) 558 return hr; 559 560 // Create a depth stencil buffer 561 D3D11_TEXTURE2D_DESC descDepth; 562 563 descDepth.Width = width; 564 descDepth.Height = height; 565 descDepth.MipLevels = 1; 566 descDepth.ArraySize = 1; 567 descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; 568 descDepth.SampleDesc.Count = 1; 569 descDepth.SampleDesc.Quality = 0; 570 descDepth.Usage = D3D11_USAGE_DEFAULT; 571 descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL; 572 descDepth.CPUAccessFlags = 0; 573 descDepth.MiscFlags = 0; 574 hr = g_pd3dDevice->CreateTexture2D(&descDepth, NULL, &g_pDepthStencilBuffer); 575 576 D3D11_DEPTH_STENCIL_VIEW_DESC descDSView; 577 descDSView.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; 578 descDSView.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; 579 descDSView.Texture2D.MipSlice = 0; 580 581 hr = g_pd3dDevice->CreateDepthStencilView(g_pDepthStencilBuffer, &descDSView, &g_pDepthStencilView); 582 583 hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView ); 584 pBackBuffer->Release(); 585 if( FAILED( hr ) ) 586 return hr; 587 588 g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, g_pDepthStencilView ); 589 590 // Setup the viewport 591 D3D11_VIEWPORT vp; 592 vp.Width = (FLOAT)width; 593 vp.Height = (FLOAT)height; 594 vp.MinDepth = 0.0f; 595 vp.MaxDepth = 1.0f; 596 vp.TopLeftX = 0; 597 vp.TopLeftY = 0; 598 g_pImmediateContext->RSSetViewports( 1, &vp ); 599 600 RenderManager.Initialise(g_pd3dDevice, g_pSwapChain); 601 602 return S_OK; 603} 604 605 606//-------------------------------------------------------------------------------------- 607// Render the frame 608//-------------------------------------------------------------------------------------- 609void Render() 610{ 611 // Just clear the backbuffer 612 float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; //red,green,blue,alpha 613 614 g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetView, ClearColor ); 615 g_pSwapChain->Present( 0, 0 ); 616} 617 618 619//-------------------------------------------------------------------------------------- 620// Clean up the objects we've created 621//-------------------------------------------------------------------------------------- 622void CleanupDevice() 623{ 624 if( g_pImmediateContext ) g_pImmediateContext->ClearState(); 625 626 if( g_pRenderTargetView ) g_pRenderTargetView->Release(); 627 if( g_pSwapChain ) g_pSwapChain->Release(); 628 if( g_pImmediateContext ) g_pImmediateContext->Release(); 629 if( g_pd3dDevice ) g_pd3dDevice->Release(); 630} 631#endif 632 633 634void RegisterAwardsWithProfileManager() 635{ 636 // register the awards 637 ProfileManager.RegisterAward(eAward_TakingInventory, ACHIEVEMENT_01, eAwardType_Achievement); 638 ProfileManager.RegisterAward(eAward_GettingWood, ACHIEVEMENT_02, eAwardType_Achievement); 639 ProfileManager.RegisterAward(eAward_Benchmarking, ACHIEVEMENT_03, eAwardType_Achievement); 640 ProfileManager.RegisterAward(eAward_TimeToMine, ACHIEVEMENT_04, eAwardType_Achievement); 641 ProfileManager.RegisterAward(eAward_HotTopic, ACHIEVEMENT_05, eAwardType_Achievement); 642 ProfileManager.RegisterAward(eAward_AquireHardware, ACHIEVEMENT_06, eAwardType_Achievement); 643 ProfileManager.RegisterAward(eAward_TimeToFarm, ACHIEVEMENT_07, eAwardType_Achievement); 644 ProfileManager.RegisterAward(eAward_BakeBread, ACHIEVEMENT_08, eAwardType_Achievement); 645 ProfileManager.RegisterAward(eAward_TheLie, ACHIEVEMENT_09, eAwardType_Achievement); 646 ProfileManager.RegisterAward(eAward_GettingAnUpgrade, ACHIEVEMENT_10, eAwardType_Achievement); 647 ProfileManager.RegisterAward(eAward_DeliciousFish, ACHIEVEMENT_11, eAwardType_Achievement); 648 ProfileManager.RegisterAward(eAward_OnARail, ACHIEVEMENT_12, eAwardType_Achievement); 649 ProfileManager.RegisterAward(eAward_TimeToStrike, ACHIEVEMENT_13, eAwardType_Achievement); 650 ProfileManager.RegisterAward(eAward_MonsterHunter, ACHIEVEMENT_14, eAwardType_Achievement); 651 ProfileManager.RegisterAward(eAward_CowTipper, ACHIEVEMENT_15, eAwardType_Achievement); 652 ProfileManager.RegisterAward(eAward_WhenPigsFly, ACHIEVEMENT_16, eAwardType_Achievement); 653 ProfileManager.RegisterAward(eAward_LeaderOfThePack, ACHIEVEMENT_17, eAwardType_Achievement); 654 ProfileManager.RegisterAward(eAward_MOARTools, ACHIEVEMENT_18, eAwardType_Achievement); 655 ProfileManager.RegisterAward(eAward_DispenseWithThis, ACHIEVEMENT_19, eAwardType_Achievement); 656 ProfileManager.RegisterAward(eAward_InToTheNether, ACHIEVEMENT_20, eAwardType_Achievement); 657 658 ProfileManager.RegisterAward(eAward_snipeSkeleton, ACHIEVEMENT_21, eAwardType_Achievement); // 'Sniper Duel' 659 ProfileManager.RegisterAward(eAward_diamonds, ACHIEVEMENT_22, eAwardType_Achievement); // 'DIAMONDS!' 660 ProfileManager.RegisterAward(eAward_ghast, ACHIEVEMENT_23, eAwardType_Achievement); // 'Return To Sender' 661 ProfileManager.RegisterAward(eAward_blazeRod, ACHIEVEMENT_24, eAwardType_Achievement); // 'Into Fire' 662 ProfileManager.RegisterAward(eAward_potion, ACHIEVEMENT_25, eAwardType_Achievement); // 'Local Brewery' 663 ProfileManager.RegisterAward(eAward_theEnd, ACHIEVEMENT_26, eAwardType_Achievement); // 'The End?' 664 ProfileManager.RegisterAward(eAward_winGame, ACHIEVEMENT_27, eAwardType_Achievement); // 'The End.' 665 ProfileManager.RegisterAward(eAward_enchantments, ACHIEVEMENT_28, eAwardType_Achievement); // 'Enchanter' 666 667#ifdef _EXTENDED_ACHIEVEMENTS 668 ProfileManager.RegisterAward(eAward_overkill, ACHIEVEMENT_29, eAwardType_Achievement); 669 ProfileManager.RegisterAward(eAward_bookcase, ACHIEVEMENT_30, eAwardType_Achievement); 670 ProfileManager.RegisterAward(eAward_adventuringTime, ACHIEVEMENT_31, eAwardType_Achievement); 671 ProfileManager.RegisterAward(eAward_repopulation, ACHIEVEMENT_32, eAwardType_Achievement); 672 ProfileManager.RegisterAward(eAward_diamondsToYou, ACHIEVEMENT_33, eAwardType_Achievement); 673 ProfileManager.RegisterAward(eAward_eatPorkChop, ACHIEVEMENT_34, eAwardType_Achievement); 674 ProfileManager.RegisterAward(eAward_play100Days, ACHIEVEMENT_35, eAwardType_Achievement); 675 ProfileManager.RegisterAward(eAward_arrowKillCreeper, ACHIEVEMENT_36, eAwardType_Achievement); 676 ProfileManager.RegisterAward(eAward_theHaggler, ACHIEVEMENT_37, eAwardType_Achievement); 677 ProfileManager.RegisterAward(eAward_potPlanter, ACHIEVEMENT_38, eAwardType_Achievement); 678 ProfileManager.RegisterAward(eAward_itsASign, ACHIEVEMENT_39, eAwardType_Achievement); 679 ProfileManager.RegisterAward(eAward_ironBelly, ACHIEVEMENT_40, eAwardType_Achievement); 680 ProfileManager.RegisterAward(eAward_haveAShearfulDay, ACHIEVEMENT_41, eAwardType_Achievement); 681 ProfileManager.RegisterAward(eAward_rainbowCollection, ACHIEVEMENT_42, eAwardType_Achievement); 682 ProfileManager.RegisterAward(eAward_stayinFrosty, ACHIEVEMENT_43, eAwardType_Achievement); 683 ProfileManager.RegisterAward(eAward_chestfulOfCobblestone, ACHIEVEMENT_44, eAwardType_Achievement); 684 ProfileManager.RegisterAward(eAward_renewableEnergy, ACHIEVEMENT_45, eAwardType_Achievement); 685 ProfileManager.RegisterAward(eAward_musicToMyEars, ACHIEVEMENT_46, eAwardType_Achievement); 686 ProfileManager.RegisterAward(eAward_bodyGuard, ACHIEVEMENT_47, eAwardType_Achievement); 687 ProfileManager.RegisterAward(eAward_ironMan, ACHIEVEMENT_48, eAwardType_Achievement); 688 ProfileManager.RegisterAward(eAward_zombieDoctor, ACHIEVEMENT_49, eAwardType_Achievement); 689 ProfileManager.RegisterAward(eAward_lionTamer, ACHIEVEMENT_50, eAwardType_Achievement); 690#endif 691 692#if 0 693 ProfileManager.RegisterAward(eAward_mine100Blocks, GAMER_PICTURE_GAMERPIC1, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC1,IDS_CONFIRM_OK); 694 ProfileManager.RegisterAward(eAward_kill10Creepers, GAMER_PICTURE_GAMERPIC2, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC2,IDS_CONFIRM_OK); 695 696 ProfileManager.RegisterAward(eAward_eatPorkChop, AVATARASSETAWARD_PORKCHOP_TSHIRT, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR1,IDS_CONFIRM_OK); 697 ProfileManager.RegisterAward(eAward_play100Days, AVATARASSETAWARD_WATCH, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR2,IDS_CONFIRM_OK); 698 ProfileManager.RegisterAward(eAward_arrowKillCreeper, AVATARASSETAWARD_CAP, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR3,IDS_CONFIRM_OK); 699 700 ProfileManager.RegisterAward(eAward_socialPost, 0, eAwardType_Theme,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_THEME,IDS_CONFIRM_OK,THEME_NAME,THEME_FILESIZE); 701#endif 702 // Rich Presence init - number of presences, number of contexts 703 //printf("Rich presence strings are hard coded on PS3 for now, must change this!\n"); 704 ProfileManager.RichPresenceInit(4,1); 705 ProfileManager.SetRichPresenceSettingFn(SQRNetworkManager_Orbis::SetRichPresence); 706 char *pchRichPresenceString; 707 708 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCE_GAMESTATE); 709 ProfileManager.RichPresenceRegisterContext(CONTEXT_GAME_STATE, pchRichPresenceString); 710 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCE_IDLE); 711 ProfileManager.RichPresenceRegisterPresenceString(CONTEXT_PRESENCE_IDLE, pchRichPresenceString); 712 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCE_MENUS); 713 ProfileManager.RichPresenceRegisterPresenceString(CONTEXT_PRESENCE_MENUS, pchRichPresenceString); 714 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCE_MULTIPLAYER); 715 ProfileManager.RichPresenceRegisterPresenceString(CONTEXT_PRESENCE_MULTIPLAYER, pchRichPresenceString); 716 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCE_MULTIPLAYEROFFLINE); 717 ProfileManager.RichPresenceRegisterPresenceString(CONTEXT_PRESENCE_MULTIPLAYEROFFLINE, pchRichPresenceString); 718 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCE_MULTIPLAYER_1P); 719 ProfileManager.RichPresenceRegisterPresenceString(CONTEXT_PRESENCE_MULTIPLAYER_1P, pchRichPresenceString); 720 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCE_MULTIPLAYER_1POFFLINE); 721 ProfileManager.RichPresenceRegisterPresenceString(CONTEXT_PRESENCE_MULTIPLAYER_1POFFLINE, pchRichPresenceString); 722 723 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCESTATE_BLANK); 724 ProfileManager.RichPresenceRegisterContextString(CONTEXT_GAME_STATE, CONTEXT_GAME_STATE_BLANK, pchRichPresenceString); 725 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCESTATE_RIDING_PIG); 726 ProfileManager.RichPresenceRegisterContextString(CONTEXT_GAME_STATE, CONTEXT_GAME_STATE_RIDING_PIG, pchRichPresenceString); 727 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCESTATE_RIDING_MINECART); 728 ProfileManager.RichPresenceRegisterContextString(CONTEXT_GAME_STATE, CONTEXT_GAME_STATE_RIDING_MINECART, pchRichPresenceString); 729 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCESTATE_BOATING); 730 ProfileManager.RichPresenceRegisterContextString(CONTEXT_GAME_STATE, CONTEXT_GAME_STATE_BOATING, pchRichPresenceString); 731 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCESTATE_FISHING); 732 ProfileManager.RichPresenceRegisterContextString(CONTEXT_GAME_STATE, CONTEXT_GAME_STATE_FISHING, pchRichPresenceString); 733 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCESTATE_CRAFTING); 734 ProfileManager.RichPresenceRegisterContextString(CONTEXT_GAME_STATE, CONTEXT_GAME_STATE_CRAFTING, pchRichPresenceString); 735 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCESTATE_FORGING); 736 ProfileManager.RichPresenceRegisterContextString(CONTEXT_GAME_STATE, CONTEXT_GAME_STATE_FORGING, pchRichPresenceString); 737 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCESTATE_NETHER); 738 ProfileManager.RichPresenceRegisterContextString(CONTEXT_GAME_STATE, CONTEXT_GAME_STATE_NETHER, pchRichPresenceString); 739 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCESTATE_CD); 740 ProfileManager.RichPresenceRegisterContextString(CONTEXT_GAME_STATE, CONTEXT_GAME_STATE_CD, pchRichPresenceString); 741 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCESTATE_MAP); 742 ProfileManager.RichPresenceRegisterContextString(CONTEXT_GAME_STATE, CONTEXT_GAME_STATE_MAP, pchRichPresenceString); 743 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCESTATE_ENCHANTING); 744 ProfileManager.RichPresenceRegisterContextString(CONTEXT_GAME_STATE, CONTEXT_GAME_STATE_ENCHANTING, pchRichPresenceString); 745 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCESTATE_BREWING); 746 ProfileManager.RichPresenceRegisterContextString(CONTEXT_GAME_STATE, CONTEXT_GAME_STATE_BREWING, pchRichPresenceString); 747 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCESTATE_ANVIL); 748 ProfileManager.RichPresenceRegisterContextString(CONTEXT_GAME_STATE, CONTEXT_GAME_STATE_ANVIL, pchRichPresenceString); 749 pchRichPresenceString=(char *)AddRichPresenceString(IDS_RICHPRESENCESTATE_TRADING); 750 ProfileManager.RichPresenceRegisterContextString(CONTEXT_GAME_STATE, CONTEXT_GAME_STATE_TRADING, pchRichPresenceString); 751 752} 753 754int StartMinecraftThreadProc( void* lpParameter ) 755{ 756 Vec3::UseDefaultThreadStorage(); 757 AABB::UseDefaultThreadStorage(); 758 Tesselator::CreateNewThreadStorage(1024*1024); 759 RenderManager.InitialiseContext(); 760 Minecraft::start(wstring(),wstring()); 761 delete Tesselator::getInstance(); 762 return 0; 763} 764 765int main(int argc, const char *argv[] ) 766{ 767 app.DebugPrintf("---main()\n"); 768 OrbisInit(); 769 770 771#if 0 772 // Main message loop 773 MSG msg = {0}; 774 while( WM_QUIT != msg.message ) 775 { 776 if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) 777 { 778 TranslateMessage( &msg ); 779 DispatchMessage( &msg ); 780 } 781 else 782 { 783 Render(); 784 } 785 } 786 787 return (int) msg.wParam; 788#endif 789 790 static bool bTrialTimerDisplayed=true; 791 792#ifdef MEMORY_TRACKING 793 ResetMem(); 794 MEMORYSTATUS memStat; 795 GlobalMemoryStatus(&memStat); 796 printf("RESETMEM start: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); 797#endif 798 799#if 0 800 // Initialize D3D 801 hr = InitD3D( &pDevice, &d3dpp ); 802 g_pD3DDevice = pDevice; 803 if( FAILED(hr) ) 804 { 805 app.DebugPrintf 806 ( "Failed initializing D3D.\n" ); 807 return -1; 808 } 809 810 // Initialize the application, assuming sharing of the d3d interface. 811 hr = app.InitShared( pDevice, &d3dpp, 812 XuiPNGTextureLoader ); 813 814 if ( FAILED(hr) ) 815 { 816 app.DebugPrintf 817 ( "Failed initializing application.\n" ); 818 819 return -1; 820 } 821 822#endif 823 824 825 826 827 828 char *usrdirPath= getUsrDirPath(); 829 830 strcpy(usrdirPath,"/app0"); 831 832 RenderManager.Initialise(); 833 834 // Read the file containing the product codes 835 app.DebugPrintf("---ReadProductCodes()\n"); 836 if(app.ReadProductCodes()==FALSE) 837 { 838 // can't continue 839 app.FatalLoadError(); 840 } 841 842// StorageManager.SetDLCProductCode(app.GetProductCode()); 843// StorageManager.SetProductUpgradeKey(app.GetUpgradeKey()); 844 // ProfileManager.SetServiceID(app.GetCommerceCategory()); 845 846 SceNpContentRestriction param; 847 memset(&param, 0x0, sizeof(param)); 848 param.size = sizeof(param); 849 850 SceNpAgeRestriction ageRestriction[5]; 851 memset(ageRestriction, 0x0, sizeof(ageRestriction)); 852 853 bool bCircleCrossSwapped = false; 854 switch(app.GetProductSKU()) 855 { 856 case e_sku_SCEA: 857 // ESRB EVERYONE 10+ 858 param.defaultAgeRestriction = 10; 859 break; 860 case e_sku_SCEJ: 861 bCircleCrossSwapped = true; 862 // 4J Stu - Intentional fall-through 863 case e_sku_SCEE: 864 // PEGI 7+ 865 param.defaultAgeRestriction = 7; 866 867 868 869 // USK 6+ 870 strncpy(ageRestriction[0].countryCode.data, "de" , 2); 871 ageRestriction[0].age = 6; 872 873 // PG rating has no age, but for some reason the testers are saying it's 8 874 strncpy(ageRestriction[1].countryCode.data, "au" , 2); 875 ageRestriction[1].age = 8; 876 877 strncpy(ageRestriction[2].countryCode.data, "ru" , 2); 878 ageRestriction[2].age = 6; 879 880 strncpy(ageRestriction[3].countryCode.data, "jp" , 2); 881 ageRestriction[3].age = 0; 882 883 strncpy(ageRestriction[4].countryCode.data, "kr" , 2); 884 ageRestriction[4].age = 0; 885 886 param.ageRestrictionCount = 5; 887 param.ageRestriction = ageRestriction; 888 break; 889 } 890 891 InputManager.SetCircleCrossSwapped(bCircleCrossSwapped); 892 893 int err = sceNpSetContentRestriction(&param); 894 if (err < 0){ 895 /* Error handling */ 896 app.DebugPrintf("sceNpSetContentRestriction failed with error %08x\n", err); 897 } 898 899 err = sceGameLiveStreamingInitialize(SCE_GAME_LIVE_STREAMING_HEAP_SIZE); 900 901 if(err < 0) 902 { 903 app.DebugPrintf("Failed to init sceGameLiveStreamingInitialize. %08x\n", err); 904 } 905 906 err = sceGameLiveStreamingSetStandbyScreenResource("standy_screen"); 907 908 if(err < 0) 909 { 910 app.DebugPrintf("Failed to set special standby screen resource. %08x\n", err); 911 } 912 913 914 app.loadMediaArchive(); 915 app.loadStringTable(); 916 ui.init(1920,1080); 917 918 // storage manager is needed for the trial key check 919 StorageManager.Init(0,app.GetString(IDS_DEFAULT_SAVENAME),"savegame.dat",FIFTY_ONE_MB,&CConsoleMinecraftApp::DisplaySavingMessage,(LPVOID)&app,""); 920 StorageManager.SetSaveTitleExtraFileSuffix(app.GetString(IDS_SAVE_SUBTITLE_SUFFIX)); 921 StorageManager.SetDLCInfoMap(app.GetSonyDLCMap()); 922 app.CommerceInit(); // MGH - moved this here so GetCommerce isn't NULL 923 // 4J-PB - Kick of the check for trial or full version - requires ui to be initialised 924 app.GetCommerce()->CheckForTrialUpgradeKey(); 925 926 //////////////// 927 // Initialise // 928 //////////////// 929 930#if 0 931 // 4J Stu - XACT was creating these automatically, but we need them for QNet. The setup params 932 // are just copied from a sample app and may need changed for our purposes 933 // Start XAudio2 934 hr = XAudio2Create( &g_pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR ); 935 if( FAILED( hr ) ) 936 { 937 app.DebugPrintf( "Initializing XAudio2 failed (err = 0x%08x)!\n", hr ); 938 app.FatalLoadError(); 939 } 940 941 // Create an XAudio2 mastering voice (utilized by XHV2 when voice data is mixed to main speakers) 942 hr = g_pXAudio2->CreateMasteringVoice(&g_pXAudio2MasteringVoice, XAUDIO2_DEFAULT_CHANNELS, XAUDIO2_DEFAULT_SAMPLERATE, 0, 0, NULL); 943 if ( FAILED( hr ) ) 944 { 945 app.DebugPrintf( "Creating XAudio2 mastering voice failed (err = 0x%08x)!\n", hr ); 946 app.FatalLoadError(); 947 } 948 949 950#endif 951 app.InitTime(); 952 NPToolkit.init(); 953 954 // Set the number of possible joypad layouts that the user can switch between, and the number of actions 955 InputManager.Initialise(1,5,MINECRAFT_ACTION_MAX, ACTION_MAX_MENU); 956 957 // Set the default joypad action mappings for Minecraft 958 DefineActions(); 959 InputManager.SetJoypadMapVal(0,0); 960 InputManager.SetKeyRepeatRate(0.3f,0.2f); 961 962 // looks like the PS4 controller is a good bit more sensitive than PS3. Defaults in the lib are 10000 for deadzone and 32767 for movement range 963 InputManager.SetDeadzoneAndMovementRange(10000,20000,32767); 964 965 // Initialise the profile manager with the game Title ID, Offer ID, a profile version number, and the number of profile values and settings 966 967 SceNpCommunicationId commsId; 968 SceNpCommunicationSignature commsSig; 969 970 ProfileManager.Initialise( &commsId, //SQRNetworkManager::GetSceNpCommsId(), 971 &commsSig, //SQRNetworkManager::GetSceNpCommsSig(), 972 PROFILE_VERSION_BUILD_JUNE14, 973 NUM_PROFILE_VALUES, 974 NUM_PROFILE_SETTINGS, 975 dwProfileSettingsA, 976 app.GAME_DEFINED_PROFILE_DATA_BYTES*XUSER_MAX_COUNT, 977 &app.uiGameDefinedDataChangedBitmask); 978 979 // register the awards 980 RegisterAwardsWithProfileManager(); 981 982 // register the get string function with the profile lib, so it can be called within the lib 983 984 ProfileManager.SetGetStringFunc(&CConsoleMinecraftApp::GetString); 985 ProfileManager.SetPlayerListTitleID(IDS_PLAYER_LIST_TITLE); 986 987 988 989 990 StorageManager.SetGameSaveFolderTitle((WCHAR *)app.GetString(IDS_GAMENAME)); 991 StorageManager.SetSaveCacheFolderTitle((WCHAR *)app.GetString(IDS_SAVECACHEFILE)); 992 StorageManager.SetOptionsFolderTitle((WCHAR *)app.GetString(IDS_OPTIONSFILE)); 993 StorageManager.SetCorruptSaveName((WCHAR *)app.GetString(IDS_CORRUPTSAVE_TITLE)); 994#if (defined _FINAL_BUILD) || (defined _ART_BUILD) 995 StorageManager.SetGameSaveFolderPrefix(app.GetSaveFolderPrefix()); 996#else 997 // Use debug directory to prevent debug saves being loaded/edited in package build (since debug can't edit package save games this causes various problems) 998 StorageManager.SetGameSaveFolderPrefix("DEBUG01899"); 999#endif 1000 StorageManager.SetMaxSaves(99); 1001 1002 byteArray baOptionsIcon = app.getArchiveFile(L"DefaultOptionsImage228x128.png"); 1003 byteArray baSaveThumbnail = app.getArchiveFile(L"DefaultSaveThumbnail64x64.png"); 1004 byteArray baSaveImage = app.getArchiveFile(L"DefaultSaveImage228x128.png"); 1005 1006 StorageManager.InitialiseProfileData(PROFILE_VERSION_BUILD_JUNE14, 1007 NUM_PROFILE_VALUES, 1008 NUM_PROFILE_SETTINGS, 1009 dwProfileSettingsA, 1010 app.GAME_DEFINED_PROFILE_DATA_BYTES*XUSER_MAX_COUNT, 1011 &app.uiGameDefinedDataChangedBitmask); 1012 1013 StorageManager.SetDefaultImages((PBYTE)baOptionsIcon.data, baOptionsIcon.length,(PBYTE)baSaveImage.data, baSaveImage.length,(PBYTE)baSaveThumbnail.data, baSaveThumbnail.length); 1014 1015 // Set function to be called if a save game operation can't complete due to running out of storage space etc. 1016 StorageManager.SetIncompleteSaveCallback(CConsoleMinecraftApp::Callback_SaveGameIncomplete, (LPVOID)&app); 1017 1018 // Temporary - set a single user for quadrant 0 for the storage manager. Will need to do more to link this aspect of the storage manager is once we have proper profile management. 1019 1020 SceUserServiceUserId aUserIds[4]; 1021 memset(aUserIds, 0, sizeof(aUserIds)); 1022 int ret = sceUserServiceGetInitialUser(&aUserIds[0]); 1023 assert(ret == SCE_OK); 1024 StorageManager.SetQuadrantUserIds(aUserIds); 1025 1026#if 0 1027 // Set up the global title storage path 1028 StorageManager.StoreTMSPathName(); 1029 1030 1031 // set a function to be called when the ethernet is disconnected, so we can back out if required 1032 ProfileManager.SetNotificationsCallback(&CConsoleMinecraftApp::NotificationsCallback,(LPVOID)&app); 1033 1034#endif 1035 // 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 1036 ProfileManager.SetSignInChangeCallback(&CConsoleMinecraftApp::SignInChangeCallback,(LPVOID)&app); 1037 1038 1039 // Set a callback for the default player options to be set - when there is no profile data for the player 1040 StorageManager.SetDefaultOptionsCallback(&CConsoleMinecraftApp::DefaultOptionsCallback,(LPVOID)&app); 1041 StorageManager.SetOptionsDataCallback(&CConsoleMinecraftApp::OptionsDataCallback,(LPVOID)&app); 1042 1043 // Set a callback to deal with old profile versions needing updated to new versions 1044 StorageManager.SetOldProfileVersionCallback(&CConsoleMinecraftApp::OldProfileVersionCallback,(LPVOID)&app); 1045 1046 // Set a callback for when there is a read error on profile data 1047 //StorageManager.SetProfileReadErrorCallback(&CConsoleMinecraftApp::ProfileReadErrorCallback,(LPVOID)&app); 1048 1049 1050 // QNet needs to be setup after profile manager, as we do not want its Notify listener to handle 1051 // XN_SYS_SIGNINCHANGED notifications. This does mean that we need to have a callback in the 1052 // ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet. 1053 1054 g_NetworkManager.Initialise(); 1055 1056 // debug switch to trial version 1057 ProfileManager.SetDebugFullOverride(true); 1058#if 0 1059 1060 //ProfileManager.AddDLC(2); 1061 StorageManager.SetDLCPackageRoot("DLCDrive"); 1062 StorageManager.RegisterMarketplaceCountsCallback(&CConsoleMinecraftApp::MarketplaceCountsCallback,(LPVOID)&app); 1063 // Kinect ! 1064 1065 if(XNuiGetHardwareStatus()!=0) 1066 { 1067 // If the Kinect Sensor is not physically connected, this function returns 0. 1068 NuiInitialize(NUI_INITIALIZE_FLAG_USES_HIGH_QUALITY_COLOR | NUI_INITIALIZE_FLAG_USES_DEPTH | 1069 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 ); 1070 } 1071 1072 // Sentient ! 1073 hr = TelemetryManager->Init(); 1074 1075 1076#endif 1077 // Initialise TLS for tesselator, for this main thread 1078 Tesselator::CreateNewThreadStorage(1024*1024); 1079 // Initialise TLS for AABB and Vec3 pools, for this main thread 1080 AABB::CreateNewThreadStorage(); 1081 Vec3::CreateNewThreadStorage(); 1082 IntCache::CreateNewThreadStorage(); 1083 Compression::CreateNewThreadStorage(); 1084 OldChunkStorage::CreateNewThreadStorage(); 1085 Level::enableLightingCache(); 1086 Tile::CreateNewThreadStorage(); 1087 1088 Minecraft::main(); 1089 1090 // Minecraft::main () used to call Minecraft::Start, but this takes ~2.5 seconds, so now running this in another thread 1091 // 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 1092 C4JThread *minecraftThread = new C4JThread(&StartMinecraftThreadProc, NULL, "Running minecraft start"); 1093 minecraftThread->Run(); 1094 do 1095 { 1096 RenderManager.StartFrame(); 1097 Sleep(20); 1098 RenderManager.Present(); 1099 } while (minecraftThread->isRunning()); 1100 delete minecraftThread; 1101 1102 Minecraft *pMinecraft=Minecraft::GetInstance(); 1103 1104 app.InitGameSettings(); 1105 // read the options here for controller 0 1106 StorageManager.ReadFromProfile(0); 1107 1108 // 4J-PB - have to hide the auto splashscreen, or we never see our game 1109 sceSystemServiceHideSplashScreen(); 1110 1111 1112#if 0 1113 //bool bDisplayPauseMenu=false; 1114 1115 // set the default gamma level 1116 float fVal=50.0f*327.68f; 1117 RenderManager.UpdateGamma((unsigned short)fVal); 1118 1119 // load any skins 1120 //app.AddSkinsToMemoryTextureFiles(); 1121#endif 1122 // set the default profile values 1123 for(int i=0;i<XUSER_MAX_COUNT;i++) 1124 { 1125 app.SetDefaultOptions(StorageManager.GetDashboardProfileSettings(i),i); 1126 } 1127#if 0 1128 1129 // set the achievement text for a trial achievement, now we have the string table loaded 1130 ProfileManager.SetTrialTextStringTable(app.GetStringTable(),IDS_CONFIRM_OK, IDS_CONFIRM_CANCEL); 1131 ProfileManager.SetTrialAwardText(eAwardType_Achievement,IDS_UNLOCK_TITLE,IDS_UNLOCK_ACHIEVEMENT_TEXT); 1132 ProfileManager.SetTrialAwardText(eAwardType_GamerPic,IDS_UNLOCK_TITLE,IDS_UNLOCK_GAMERPIC_TEXT); 1133 ProfileManager.SetTrialAwardText(eAwardType_AvatarItem,IDS_UNLOCK_TITLE,IDS_UNLOCK_AVATAR_TEXT); 1134 ProfileManager.SetTrialAwardText(eAwardType_Theme,IDS_UNLOCK_TITLE,IDS_UNLOCK_THEME_TEXT); 1135 ProfileManager.SetUpsellCallback(&app.UpsellReturnedCallback,&app); 1136 1137 // Set up a debug character press sequence 1138#ifndef _FINAL_BUILD 1139 app.SetDebugSequence("LRLRYYY"); 1140#endif 1141 1142 // Initialise the social networking manager. 1143 CSocialManager::Instance()->Initialise(); 1144 1145 // Update the base scene quick selects now that the minecraft class exists 1146 //CXuiSceneBase::UpdateScreenSettings(0); 1147#endif 1148 app.InitialiseTips(); 1149#if 0 1150 1151 DWORD initData=0; 1152 1153 1154 1155#ifndef _FINAL_BUILD 1156#ifndef _DEBUG 1157 #pragma message(__LOC__"Need to define the _FINAL_BUILD before submission") 1158#endif 1159#endif 1160 1161 // Set the default sound levels 1162 pMinecraft->options->set(Options::Option::MUSIC,1.0f); 1163 pMinecraft->options->set(Options::Option::SOUND,1.0f); 1164 1165 app.NavigateToScene(XUSER_INDEX_ANY,eUIScene_Intro,&initData); 1166#endif 1167 //app.TemporaryCreateGameStart(); 1168 1169 //Sleep(10000); 1170#if 0 1171 // Intro loop ? 1172 while(app.IntroRunning()) 1173 { 1174 ProfileManager.Tick(); 1175 // Tick XUI 1176 app.RunFrame(); 1177 1178 // 4J : WESTY : Added to ensure we always have clear background for intro. 1179 RenderManager.SetClearColour(D3DCOLOR_RGBA(0,0,0,255)); 1180 RenderManager.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1181 1182 // Render XUI 1183 hr = app.Render(); 1184 1185 // Present the frame. 1186 RenderManager.Present(); 1187 1188 // Update XUI Timers 1189 hr = XuiTimersRun(); 1190 } 1191#endif 1192 1193 // 4J-PB - Moved here because it crashed when the network init was called if left where it was before. 1194 // We should track down why though... 1195 app.DebugPrintf("---init sound engine()\n"); 1196 1197 pMinecraft->soundEngine->init(NULL); 1198 1199 while (TRUE) 1200 { 1201 SonyVoiceChat_Orbis::tick(); 1202 RenderManager.StartFrame(); 1203#if 0 1204 if(pMinecraft->soundEngine->isStreamingWavebankReady() && 1205 !pMinecraft->soundEngine->isPlayingStreamingGameMusic() && 1206 !pMinecraft->soundEngine->isPlayingStreamingCDMusic() ) 1207 { 1208 // play some music in the menus 1209 pMinecraft->soundEngine->playStreaming(L"", 0, 0, 0, 0, 0, false); 1210 } 1211#endif 1212 app.UpdateTime(); 1213 PIXBeginNamedEvent(0,"Input manager tick"); 1214 InputManager.Tick(); 1215 PIXEndNamedEvent(); 1216 PIXBeginNamedEvent(0,"Profile manager tick"); 1217 ProfileManager.Tick(); 1218 PIXEndNamedEvent(); 1219 PIXBeginNamedEvent(0,"Storage manager tick"); 1220 StorageManager.Tick(); 1221 PIXEndNamedEvent(); 1222 PIXBeginNamedEvent(0,"Render manager tick"); 1223 RenderManager.Tick(); 1224 PIXEndNamedEvent(); 1225 1226 // Tick the social networking manager. 1227 PIXBeginNamedEvent(0,"Social network manager tick"); 1228// CSocialManager::Instance()->Tick(); 1229 PIXEndNamedEvent(); 1230 1231 // Tick sentient. 1232 PIXBeginNamedEvent(0,"Sentient tick"); 1233 MemSect(37); 1234// SentientManager.Tick(); 1235 MemSect(0); 1236 PIXEndNamedEvent(); 1237 1238 PIXBeginNamedEvent(0,"Network manager do work #1"); 1239 g_NetworkManager.DoWork(); 1240 PIXEndNamedEvent(); 1241 1242 LeaderboardManager::Instance()->Tick(); 1243 // Render game graphics. 1244 if(app.GetGameStarted()) 1245 { 1246 pMinecraft->run_middle(); 1247 app.SetAppPaused( g_NetworkManager.IsLocalGame() && g_NetworkManager.GetPlayerCount() == 1 && ui.IsPauseMenuDisplayed(ProfileManager.GetPrimaryPad()) ); 1248 } 1249 else 1250 { 1251 MemSect(28); 1252 pMinecraft->soundEngine->tick(NULL, 0.0f); 1253 MemSect(0); 1254 pMinecraft->textures->tick(true,false); 1255 IntCache::Reset(); 1256 if( app.GetReallyChangingSessionType() ) 1257 { 1258 pMinecraft->tickAllConnections(); // Added to stop timing out when we are waiting after converting to an offline game 1259 } 1260 } 1261 pMinecraft->soundEngine->playMusicTick(); 1262 1263 static bool bInitnet=false; 1264 1265 if(bInitnet) 1266 { 1267 g_NetworkManager.Initialise(); 1268 } 1269 1270#ifdef MEMORY_TRACKING 1271 static bool bResetMemTrack = false; 1272 static bool bDumpMemTrack = false; 1273 1274 MemPixStuff(); 1275 1276 if( bResetMemTrack ) 1277 { 1278 ResetMem(); 1279 MEMORYSTATUS memStat; 1280 GlobalMemoryStatus(&memStat); 1281 printf("RESETMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); 1282 bResetMemTrack = false; 1283 } 1284 1285 if( bDumpMemTrack ) 1286 { 1287 DumpMem(); 1288 bDumpMemTrack = false; 1289 MEMORYSTATUS memStat; 1290 GlobalMemoryStatus(&memStat); 1291 printf("DUMPMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); 1292 printf("Renderer used: %d\n",RenderManager.CBuffSize(-1)); 1293 } 1294#endif 1295#if 0 1296 static bool bDumpTextureUsage = false; 1297 if( bDumpTextureUsage ) 1298 { 1299 RenderManager.TextureGetStats(); 1300 bDumpTextureUsage = false; 1301 } 1302#endif 1303 ui.tick(); 1304 ui.render(); 1305#if 0 1306 app.HandleButtonPresses(); 1307 1308 // store the minecraft renderstates, and re-set them after the xui render 1309 GetRenderAndSamplerStates(pDevice,RenderStateA,SamplerStateA); 1310 1311 // Tick XUI 1312 PIXBeginNamedEvent(0,"Xui running"); 1313 app.RunFrame(); 1314 PIXEndNamedEvent(); 1315 1316 // Render XUI 1317 1318 PIXBeginNamedEvent(0,"XUI render"); 1319 MemSect(7); 1320 hr = app.Render(); 1321 MemSect(0); 1322 GetRenderAndSamplerStates(pDevice,RenderStateA2,SamplerStateA2); 1323 PIXEndNamedEvent(); 1324 1325 for(int i=0;i<8;i++) 1326 { 1327 if(RenderStateA2[i]!=RenderStateA[i]) 1328 { 1329 //printf("Reseting RenderStateA[%d] after a XUI render\n",i); 1330 pDevice->SetRenderState(RenderStateModes[i],RenderStateA[i]); 1331 } 1332 } 1333 for(int i=0;i<5;i++) 1334 { 1335 if(SamplerStateA2[i]!=SamplerStateA[i]) 1336 { 1337 //printf("Reseting SamplerStateA[%d] after a XUI render\n",i); 1338 pDevice->SetSamplerState(0,SamplerStateModes[i],SamplerStateA[i]); 1339 } 1340 } 1341 1342 RenderManager.Set_matrixDirty(); 1343#endif 1344 // Present the frame. 1345 RenderManager.Present(); 1346 1347 ui.CheckMenuDisplayed(); 1348 PIXBeginNamedEvent(0,"Profile load check"); 1349 // has the game defined profile data been changed (by a profile load) 1350 if(app.uiGameDefinedDataChangedBitmask!=0) 1351 { 1352 void *pData; 1353 for(int i=0;i<XUSER_MAX_COUNT;i++) 1354 { 1355 if(app.uiGameDefinedDataChangedBitmask&(1<<i)) 1356 { 1357 // It has - game needs to update its values with the data from the profile 1358 pData=StorageManager.GetGameDefinedProfileData(i); 1359 // reset the changed flag 1360 app.ClearGameSettingsChangedFlag(i); 1361 app.DebugPrintf("*** - APPLYING GAME SETTINGS CHANGE for pad %d\n",i); 1362 app.ApplyGameSettingsChanged(i); 1363 1364#ifdef _DEBUG_MENUS_ENABLED 1365 if(app.DebugSettingsOn()) 1366 { 1367 app.ActionDebugMask(i); 1368 } 1369 else 1370 { 1371 // force debug mask off 1372 app.ActionDebugMask(i,true); 1373 } 1374#endif 1375 // clear the stats first - there could have beena signout and sign back in in the menus 1376 // need to clear the player stats - can't assume it'll be done in setlevel - we may not be in the game 1377 pMinecraft->stats[ i ]->clear(); 1378 pMinecraft->stats[i]->parse(pData); 1379 } 1380 1381 } 1382 1383 // clear the flag 1384 app.uiGameDefinedDataChangedBitmask=0; 1385 } 1386 PIXEndNamedEvent(); 1387 1388 // 4J-PB - Monitor the options save for a space issue 1389 bool bOptionsNoSpace=false; 1390 for(int i=0;i<XUSER_MAX_COUNT;i++) 1391 { 1392 if(bOptionsNoSpace==false) 1393 { 1394 if(app.GetOptionsCallbackStatus(i)==C4JStorage::eOptions_Callback_Write_Fail_NoSpace) 1395 { 1396 // get the game to bring up the save space handling 1397 bOptionsNoSpace=true; 1398 app.SetOptionsCallbackStatus(i,C4JStorage::eOptions_Callback_Idle); 1399 app.SetAction(i,eAppAction_OptionsSaveNoSpace); 1400 } 1401 } 1402 } 1403 1404 1405 PIXBeginNamedEvent(0,"Network manager do work #2"); 1406 g_NetworkManager.DoWork(); 1407 PIXEndNamedEvent(); 1408 1409#if 0 1410 PIXBeginNamedEvent(0,"Misc extra xui"); 1411 // Update XUI Timers 1412 hr = XuiTimersRun(); 1413 1414#endif 1415 // Any threading type things to deal with from the xui side? 1416 app.HandleXuiActions(); 1417#if 0 1418 PIXEndNamedEvent(); 1419#endif 1420 1421 // 4J-PB - Update the trial timer display if we are in the trial version 1422 if(!ProfileManager.IsFullVersion()) 1423 { 1424 // display the trial timer 1425 if(app.GetGameStarted()) 1426 { 1427 // 4J-PB - if the game is paused, add the elapsed time to the trial timer count so it doesn't tick down 1428 if(app.IsAppPaused()) 1429 { 1430 app.UpdateTrialPausedTimer(); 1431 } 1432 ui.UpdateTrialTimer(ProfileManager.GetPrimaryPad()); 1433 } 1434 } 1435 else 1436 { 1437 // need to turn off the trial timer if it was on , and we've unlocked the full version 1438 if(bTrialTimerDisplayed) 1439 { 1440 ui.ShowTrialTimer(false); 1441 bTrialTimerDisplayed=false; 1442 } 1443 } 1444 1445 // PS4 DLC 1446 app.CommerceTick(); 1447 app.SystemServiceTick(); 1448 1449 app.SaveDataDialogTick(); 1450 app.PatchAvailableDialogTick(); 1451 1452 // Fix for #7318 - Title crashes after short soak in the leaderboards menu 1453 // A memory leak was caused because the icon renderer kept creating new Vec3's because the pool wasn't reset 1454 Vec3::resetPool(); 1455 } 1456 1457 // Free resources, unregister custom classes, and exit. 1458// app.Uninit(); 1459// g_pd3dDevice->Release(); 1460} 1461 1462 1463vector<uint8_t *> vRichPresenceStrings; 1464 1465// convert wstring to UTF-8 string 1466std::string wstring_to_utf8 (const std::wstring& str) 1467{ 1468 std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv; 1469 return myconv.to_bytes(str); 1470} 1471 1472uint8_t *mallocAndCreateUTF8ArrayFromString(int iID) 1473{ 1474 int result; 1475 LPCWSTR wchString=app.GetString(iID); 1476 1477 std::wstring srcString = wchString; 1478 std::string dstString = wstring_to_utf8(srcString); 1479 1480 int dst_len = dstString.size()+1; 1481 uint8_t *strUtf8=(uint8_t *)malloc(dst_len); 1482 memcpy(strUtf8, dstString.c_str(), dst_len); 1483 1484 return strUtf8; 1485} 1486 1487uint8_t * AddRichPresenceString(int iID) 1488{ 1489 uint8_t *strUtf8 = mallocAndCreateUTF8ArrayFromString(iID); 1490 if( strUtf8 != NULL ) 1491 { 1492 vRichPresenceStrings.push_back(strUtf8); 1493 } 1494 return strUtf8; 1495} 1496 1497void FreeRichPresenceStrings() 1498{ 1499 uint8_t *strUtf8; 1500 for(int i=0;i<vRichPresenceStrings.size();i++) 1501 { 1502 strUtf8=vRichPresenceStrings.at(i); 1503 free(strUtf8); 1504 } 1505 vRichPresenceStrings.clear(); 1506} 1507 1508 1509#ifdef MEMORY_TRACKING 1510 1511int totalAllocGen = 0; 1512unordered_map<int,int> allocCounts; 1513bool trackEnable = false; 1514bool trackStarted = false; 1515volatile size_t sizeCheckMin = 1160; 1516volatile size_t sizeCheckMax = 1160; 1517volatile int sectCheck = 48; 1518CRITICAL_SECTION memCS; 1519DWORD tlsIdx; 1520 1521LPVOID XMemAlloc(SIZE_T dwSize, DWORD dwAllocAttributes) 1522{ 1523 if( !trackStarted ) 1524 { 1525 void *p = XMemAllocDefault(dwSize,dwAllocAttributes); 1526 size_t realSize = XMemSizeDefault(p, dwAllocAttributes); 1527 totalAllocGen += realSize; 1528 return p; 1529 } 1530 1531 EnterCriticalSection(&memCS); 1532 1533 void *p=XMemAllocDefault(dwSize + 16,dwAllocAttributes); 1534 size_t realSize = XMemSizeDefault(p,dwAllocAttributes) - 16; 1535 1536 if( trackEnable ) 1537 { 1538#if 1 1539 int sect = ((int) TlsGetValue(tlsIdx)) & 0x3f; 1540 *(((unsigned char *)p)+realSize) = sect; 1541 1542 if( ( realSize >= sizeCheckMin ) && ( realSize <= sizeCheckMax ) && ( ( sect == sectCheck ) || ( sectCheck == -1 ) ) ) 1543 { 1544 app.DebugPrintf("Found one\n"); 1545 } 1546#endif 1547 1548 if( p ) 1549 { 1550 totalAllocGen += realSize; 1551 trackEnable = false; 1552 int key = ( sect << 26 ) | realSize; 1553 int oldCount = allocCounts[key]; 1554 allocCounts[key] = oldCount + 1; 1555 1556 trackEnable = true; 1557 } 1558 } 1559 1560 LeaveCriticalSection(&memCS); 1561 1562 return p; 1563} 1564 1565void* operator new (size_t size) 1566{ 1567 return (unsigned char *)XMemAlloc(size,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); 1568} 1569 1570void operator delete (void *p) 1571{ 1572 XMemFree(p,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); 1573} 1574 1575void WINAPI XMemFree(PVOID pAddress, DWORD dwAllocAttributes) 1576{ 1577 bool special = false; 1578 if( dwAllocAttributes == 0 ) 1579 { 1580 dwAllocAttributes = MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP); 1581 special = true; 1582 } 1583 if(!trackStarted ) 1584 { 1585 size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes); 1586 XMemFreeDefault(pAddress, dwAllocAttributes); 1587 totalAllocGen -= realSize; 1588 return; 1589 } 1590 EnterCriticalSection(&memCS); 1591 if( pAddress ) 1592 { 1593 size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes) - 16; 1594 1595 if(trackEnable) 1596 { 1597 int sect = *(((unsigned char *)pAddress)+realSize); 1598 totalAllocGen -= realSize; 1599 trackEnable = false; 1600 int key = ( sect << 26 ) | realSize; 1601 int oldCount = allocCounts[key]; 1602 allocCounts[key] = oldCount - 1; 1603 trackEnable = true; 1604 1605 } 1606 XMemFreeDefault(pAddress, dwAllocAttributes); 1607 } 1608 LeaveCriticalSection(&memCS); 1609} 1610 1611SIZE_T WINAPI XMemSize( 1612 PVOID pAddress, 1613 DWORD dwAllocAttributes 1614) 1615{ 1616 if( trackStarted ) 1617 { 1618 return XMemSizeDefault(pAddress, dwAllocAttributes) - 16; 1619 } 1620 else 1621 { 1622 return XMemSizeDefault(pAddress, dwAllocAttributes); 1623 } 1624} 1625 1626 1627void DumpMem() 1628{ 1629 int totalLeak = 0; 1630 for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ ) 1631 { 1632 if(it->second > 0 ) 1633 { 1634 app.DebugPrintf("%d %d %d %d\n",( it->first >> 26 ) & 0x3f,it->first & 0x03ffffff, it->second, (it->first & 0x03ffffff) * it->second); 1635 totalLeak += ( it->first & 0x03ffffff ) * it->second; 1636 } 1637 } 1638 app.DebugPrintf("Total %d\n",totalLeak); 1639} 1640 1641void ResetMem() 1642{ 1643 if( !trackStarted ) 1644 { 1645 trackEnable = true; 1646 trackStarted = true; 1647 totalAllocGen = 0; 1648 InitializeCriticalSection(&memCS); 1649 tlsIdx = TlsAlloc(); 1650 } 1651 EnterCriticalSection(&memCS); 1652 trackEnable = false; 1653 allocCounts.clear(); 1654 trackEnable = true; 1655 LeaveCriticalSection(&memCS); 1656} 1657 1658void MemSect(int section) 1659{ 1660 unsigned int value = (unsigned int)TlsGetValue(tlsIdx); 1661 if( section == 0 ) // pop 1662 { 1663 value = (value >> 6) & 0x03ffffff; 1664 } 1665 else 1666 { 1667 value = (value << 6) | section; 1668 } 1669 TlsSetValue(tlsIdx, (LPVOID)value); 1670} 1671 1672void MemPixStuff() 1673{ 1674 const int MAX_SECT = 46; 1675 1676 int totals[MAX_SECT] = {0}; 1677 1678 for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ ) 1679 { 1680 if(it->second > 0 ) 1681 { 1682 int sect = ( it->first >> 26 ) & 0x3f; 1683 int bytes = it->first & 0x03ffffff; 1684 totals[sect] += bytes * it->second; 1685 } 1686 } 1687 1688 unsigned int allSectsTotal = 0; 1689 for( int i = 0; i < MAX_SECT; i++ ) 1690 { 1691 allSectsTotal += totals[i]; 1692 PIXAddNamedCounter(((float)totals[i])/1024.0f,"MemSect%d",i); 1693 } 1694 1695 PIXAddNamedCounter(((float)allSectsTotal)/(4096.0f),"MemSect total pages"); 1696} 1697 1698#endif