the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1// Minecraft.cpp : Defines the entry point for the application.
2//
3
4#include "stdafx.h"
5
6#include <assert.h>
7#include "..\MinecraftServer.h"
8#include "..\LocalPlayer.h"
9#include "..\..\Minecraft.World\ItemInstance.h"
10#include "..\..\Minecraft.World\MapItem.h"
11#include "..\..\Minecraft.World\Recipes.h"
12#include "..\..\Minecraft.World\Recipy.h"
13#include "..\..\Minecraft.World\Language.h"
14#include "..\..\Minecraft.World\StringHelpers.h"
15#include "..\..\Minecraft.World\AABB.h"
16#include "..\..\Minecraft.World\Vec3.h"
17#include "..\..\Minecraft.World\Level.h"
18#include "..\..\Minecraft.World\net.minecraft.world.level.tile.h"
19
20#include "Leaderboards\GameProgress.h"
21#include "..\ClientConnection.h"
22#include "..\User.h"
23#include "..\..\Minecraft.World\Socket.h"
24#include "..\..\Minecraft.World\ThreadName.h"
25#include "..\..\Minecraft.Client\StatsCounter.h"
26#include "..\ConnectScreen.h"
27#include "Leaderboards\DurangoLeaderboardManager.h"
28#include "..\..\Minecraft.Client\Tesselator.h"
29#include "..\..\Minecraft.Client\Options.h"
30#include "Sentient\SentientManager.h"
31#include "..\..\Minecraft.World\IntCache.h"
32#include "..\Textures.h"
33#include "Resource.h"
34#include "..\..\Minecraft.World\compression.h"
35#include "..\..\Minecraft.World\OldChunkStorage.h"
36#include <agile.h>
37
38//using namespace Windows::Xbox::Input;
39using namespace Windows::Foundation::Collections;
40
41#define THEME_NAME "584111F70AAAAAAA"
42#define THEME_FILESIZE 2797568
43
44//#define THREE_MB 3145728 // minimum save size (checking for this on a selected device)
45//#define FIVE_MB 5242880 // minimum save size (checking for this on a selected device)
46//#define FIFTY_TWO_MB (1024*1024*52) // Maximum TCR space required for a save (checking for this on a selected device)
47#define FIFTY_ONE_MB (1000000*51) // Maximum TCR space required for a save is 52MB (checking for this on a selected device)
48
49//#define PROFILE_VERSION 3 // new version for the interim bug fix 166 TU
50#define NUM_PROFILE_VALUES 5
51#define NUM_PROFILE_SETTINGS 4
52DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]=
53{
54#ifdef _XBOX
55 XPROFILE_OPTION_CONTROLLER_VIBRATION,
56 XPROFILE_GAMER_YAXIS_INVERSION,
57 XPROFILE_GAMER_CONTROL_SENSITIVITY,
58 XPROFILE_GAMER_ACTION_MOVEMENT_CONTROL,
59 XPROFILE_TITLE_SPECIFIC1,
60#else
61 0,0,0,0,0
62#endif
63};
64
65//-------------------------------------------------------------------------------------
66// Time Since fAppTime is a float, we need to keep the quadword app time
67// as a LARGE_INTEGER so that we don't lose precision after running
68// for a long time.
69//-------------------------------------------------------------------------------------
70
71
72BOOL g_bWidescreen = TRUE;
73
74
75void DefineActions(void)
76{
77 // The app needs to define the actions required, and the possible mappings for these
78
79 // Split into Menu actions, and in-game actions
80
81 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_A, _360_JOY_BUTTON_A);
82 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_B, _360_JOY_BUTTON_B | _360_GTC_BACK);
83 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_X, _360_JOY_BUTTON_X);
84 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_Y, _360_JOY_BUTTON_Y);
85 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OK, _360_JOY_BUTTON_A);
86 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B | _360_GTC_BACK);
87 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP);
88 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN);
89 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT);
90 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT);
91 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_LT);
92 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT);
93 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB);
94 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB);
95 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START | _360_GTC_MENU);
96
97 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_GTC_PAUSE, _360_GTC_PAUSE);
98 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_GTC_RESUME, _360_GTC_PLAY);
99
100 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB);
101 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB);
102 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP);
103 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
104 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
105 InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
106
107 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_A);
108 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP);
109 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN);
110 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT);
111 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT);
112 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
113 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
114 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP);
115 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
116 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_LT);
117 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_RT);
118 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_RB);
119 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_LB);
120 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y);
121 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START | _360_GTC_MENU);
122 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B);
123 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_RTHUMB);
124 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X);
125 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_LTHUMB);
126 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK | _360_GTC_VIEW);
127
128 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT);
129 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT);
130 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP);
131 InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN);
132
133 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_A, _360_JOY_BUTTON_A);
134 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_B, _360_JOY_BUTTON_B | _360_GTC_BACK);
135 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_X, _360_JOY_BUTTON_X);
136 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_Y, _360_JOY_BUTTON_Y);
137 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OK, _360_JOY_BUTTON_A);
138 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B | _360_GTC_BACK);
139 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP);
140 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN);
141 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT);
142 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT);
143 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_LB);
144 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT);
145 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB);
146 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB);
147 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START | _360_GTC_MENU);
148
149 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_GTC_PAUSE, _360_GTC_PAUSE);
150 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_GTC_RESUME, _360_GTC_PLAY);
151
152 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB);
153 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB);
154 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP);
155 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
156 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
157 InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
158
159 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_RB);
160 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP);
161 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN);
162 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT);
163 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT);
164 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
165 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
166 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP);
167 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
168 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_RT);
169 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_LT);
170 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_DPAD_RIGHT);
171 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_DPAD_LEFT);
172 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y);
173 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START | _360_GTC_MENU);
174 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B);
175 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_LTHUMB);
176 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X);
177 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_RTHUMB);
178 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK | _360_GTC_VIEW);
179
180 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT);
181 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT);
182 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP);
183 InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN);
184
185 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_A, _360_JOY_BUTTON_A);
186 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_B, _360_JOY_BUTTON_B | _360_GTC_BACK);
187 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_X, _360_JOY_BUTTON_X);
188 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_Y, _360_JOY_BUTTON_Y);
189 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OK, _360_JOY_BUTTON_A);
190 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B | _360_GTC_BACK);
191 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP);
192 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN);
193 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT);
194 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT);
195 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LB);
196 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT);
197 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB);
198 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB);
199 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAUSEMENU, _360_JOY_BUTTON_START | _360_GTC_MENU);
200 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_STICK_PRESS, _360_JOY_BUTTON_LTHUMB);
201 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_PRESS, _360_JOY_BUTTON_RTHUMB);
202 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_UP, _360_JOY_BUTTON_RSTICK_UP);
203 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
204 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
205 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OTHER_STICK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
206
207 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_GTC_PAUSE, _360_GTC_PAUSE);
208 InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_GTC_RESUME, _360_GTC_PLAY);
209
210 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_LT);
211 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP);
212 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN);
213 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT);
214 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT);
215 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT);
216 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT);
217 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP);
218 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN);
219 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_RT);
220 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_A);
221 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_DPAD_RIGHT);
222 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_DPAD_LEFT);
223 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y);
224 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START | _360_GTC_MENU);
225 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B);
226 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_LB);
227 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X);
228 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_LTHUMB);
229 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK | _360_GTC_VIEW);
230
231 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT);
232 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT);
233 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP);
234 InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN);
235}
236
237#if 0
238HRESULT InitD3D( IDirect3DDevice9 **ppDevice,
239 D3DPRESENT_PARAMETERS *pd3dPP )
240{
241 IDirect3D9 *pD3D;
242
243 pD3D = Direct3DCreate9( D3D_SDK_VERSION );
244
245 // Set up the structure used to create the D3DDevice
246 // Using a permanent 1280x720 backbuffer now no matter what the actual video resolution.right Have also disabled letterboxing,
247 // which would letterbox a 1280x720 output if it detected a 4:3 video source - we're doing an anamorphic squash in this
248 // mode so don't need this functionality.
249
250 ZeroMemory( pd3dPP, sizeof(D3DPRESENT_PARAMETERS) );
251 XVIDEO_MODE VideoMode;
252 XGetVideoMode( &VideoMode );
253 g_bWidescreen = VideoMode.fIsWideScreen;
254 pd3dPP->BackBufferWidth = 1280;
255 pd3dPP->BackBufferHeight = 720;
256 pd3dPP->BackBufferFormat = D3DFMT_A8R8G8B8;
257 pd3dPP->BackBufferCount = 1;
258 pd3dPP->EnableAutoDepthStencil = TRUE;
259 pd3dPP->AutoDepthStencilFormat = D3DFMT_D24S8;
260 pd3dPP->SwapEffect = D3DSWAPEFFECT_DISCARD;
261 pd3dPP->PresentationInterval = D3DPRESENT_INTERVAL_ONE;
262 //pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX;
263 //ERR[D3D]: Can't set D3DPRESENTFLAG_NO_LETTERBOX when wide-screen is enabled
264 // in the launcher/dashboard.
265 if(g_bWidescreen)
266 pd3dPP->Flags=0;
267 else
268 pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX;
269
270 // Create the device.
271 return pD3D->CreateDevice(
272 0,
273 D3DDEVTYPE_HAL,
274 NULL,
275 D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_BUFFER_2_FRAMES,
276 pd3dPP,
277 ppDevice );
278}
279#endif
280//#define MEMORY_TRACKING
281
282#ifdef MEMORY_TRACKING
283void ResetMem();
284void DumpMem();
285void MemPixStuff();
286#else
287void MemSect(int sect)
288{
289}
290#endif
291
292
293HINSTANCE g_hInst = NULL;
294
295Platform::Agile<Windows::UI::Core::CoreWindow> g_window;
296Windows::Foundation::Rect g_windowBounds;
297
298D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL;
299D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0;
300Microsoft::WRL::ComPtr<ID3D11Device1> g_d3dDevice;
301Microsoft::WRL::ComPtr<ID3D11DeviceContext1> g_d3dContext;
302Microsoft::WRL::ComPtr<IDXGISwapChain1> g_swapChain;
303Microsoft::WRL::ComPtr<ID3D11RenderTargetView> g_renderTargetView;
304Microsoft::WRL::ComPtr<ID3D11DepthStencilView> g_depthStencilView;
305Microsoft::WRL::ComPtr<ID3D11Texture2D> g_depthStencil;
306
307void CreateDevice();
308void CreateResources();
309void InitializeDurango(Windows::UI::Core::CoreWindow^ window)
310{
311 SetThreadAffinityMask(GetCurrentThread(),1);
312
313 g_window = window;
314
315 CreateDevice();
316
317 CreateResources();
318
319 // TODO: Begin asynchronous loading of game assets.
320
321 C4JThread::StaticInit();
322}
323
324namespace DX
325{
326 inline void ThrowIfFailed(HRESULT hr)
327 {
328 if (FAILED(hr))
329 {
330 // Set a breakpoint on this line to catch DirectX API errors
331 throw Platform::Exception::CreateException(hr);
332 }
333 }
334}
335
336void CreateDevice()
337{
338 // This flag adds support for surfaces with a different color channel ordering than the API default.
339 // It is recommended usage, and is required for compatibility with Direct2D.
340 UINT creationFlags = D3D11_CREATE_DEVICE_FAST_KICKOFFS;
341#ifndef _CONTENT_PACKAGE
342 creationFlags |= D3D11_CREATE_DEVICE_VALIDATED;
343 creationFlags |= D3D11_CREATE_DEVICE_INSTRUMENTED;
344#endif
345
346 // This array defines the set of DirectX hardware feature levels this app will support.
347 // Note the ordering should be preserved.
348 // Don't forget to declare your application's minimum required feature level in its
349 // description. All applications are assumed to support 9.1 unless otherwise stated.
350 D3D_FEATURE_LEVEL featureLevels[] =
351 {
352 D3D_FEATURE_LEVEL_11_0
353 };
354
355 // Create the DX11 API device object, and get a corresponding context.
356 Microsoft::WRL::ComPtr<ID3D11Device> device;
357 Microsoft::WRL::ComPtr<ID3D11DeviceContext> context;
358
359 DX::ThrowIfFailed(
360 D3D11CreateDevice(
361 nullptr, // specify null to use the default adapter
362 D3D_DRIVER_TYPE_HARDWARE,
363 nullptr, // leave as nullptr unless software device
364 creationFlags, // optionally set debug and Direct2D compatibility flags
365 featureLevels, // list of feature levels this app can support
366 ARRAYSIZE(featureLevels), // number of entries in above list
367 D3D11_SDK_VERSION, // always set this to D3D11_SDK_VERSION
368 &device, // returns the Direct3D device created
369 &g_featureLevel, // returns feature level of device created
370 &context // returns the device immediate context
371 )
372 );
373
374 // Get the DirectX11.1 device by QI off the DirectX11 one.
375 DX::ThrowIfFailed(device.As(&g_d3dDevice));
376
377 // And get the corresponding device context in the same way.
378 DX::ThrowIfFailed(context.As(&g_d3dContext));
379}
380
381// Allocate all memory resources that change on a window SizeChanged event.
382void CreateResources()
383{
384 // Store the window bounds so the next time we get a SizeChanged event we can
385 // avoid rebuilding everything if the size is identical.
386 g_windowBounds = g_window.Get()->Bounds;
387
388 // If the swap chain already exists, resize it,
389 // otherwise create one.
390 if(g_swapChain != nullptr)
391 {
392 DX::ThrowIfFailed(g_swapChain->ResizeBuffers(2, 0, 0, DXGI_FORMAT_B8G8R8A8_UNORM, 0));
393 }
394 else
395 {
396 // First, retrieve the underlying DXGI Device from the D3D Device
397 Microsoft::WRL::ComPtr<IDXGIDevice1> dxgiDevice;
398 DX::ThrowIfFailed(g_d3dDevice.As(&dxgiDevice));
399
400 // Identify the physical adapter (GPU or card) this device is running on.
401 Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter;
402 DX::ThrowIfFailed(dxgiDevice->GetAdapter(&dxgiAdapter));
403
404 // And obtain the factory object that created it.
405 Microsoft::WRL::ComPtr<IDXGIFactory2> dxgiFactory;
406 DX::ThrowIfFailed(dxgiAdapter->GetParent(__uuidof(IDXGIFactory2), &dxgiFactory));
407
408 // Create a descriptor for the swap chain.
409 DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
410
411 swapChainDesc.Width = 1920;
412 swapChainDesc.Height = 1080;
413 swapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
414 swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT;
415 swapChainDesc.BufferCount = 2;
416 swapChainDesc.Stereo = false;
417 swapChainDesc.SampleDesc.Count = 1;
418 swapChainDesc.SampleDesc.Quality = 0;
419 swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
420 swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
421 swapChainDesc.Flags = 0;
422
423 // Create a SwapChain from a CoreWindow.
424 DX::ThrowIfFailed(dxgiFactory->CreateSwapChainForCoreWindow(g_d3dDevice.Get(), reinterpret_cast<IUnknown*>(g_window.Get()), &swapChainDesc, nullptr, &g_swapChain));
425 }
426
427 // Obtain the backbuffer for this window which will be the final 3D rendertarget.
428 Microsoft::WRL::ComPtr<ID3D11Texture2D> backBuffer;
429 DX::ThrowIfFailed(g_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), &backBuffer));
430
431 // Create a view interface on the rendertarget to use on bind.
432 DX::ThrowIfFailed(g_d3dDevice->CreateRenderTargetView(backBuffer.Get(), nullptr, &g_renderTargetView));
433
434 // Cache the rendertarget dimensions in our helper class for convenient use.
435 D3D11_TEXTURE2D_DESC backBufferDesc = {0};
436 backBuffer->GetDesc(&backBufferDesc);
437
438 // Allocate a 2-D surface as the depth/stencil buffer and
439 // create a DepthStencil view on this surface to use on bind.
440 CD3D11_TEXTURE2D_DESC depthStencilDesc(DXGI_FORMAT_D24_UNORM_S8_UINT, backBufferDesc.Width, backBufferDesc.Height, 1, 1, D3D11_BIND_DEPTH_STENCIL);
441
442 Microsoft::WRL::ComPtr<ID3D11Texture2D> depthStencil;
443 DX::ThrowIfFailed(g_d3dDevice->CreateTexture2D(&depthStencilDesc, nullptr, &depthStencil));
444
445 CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D);
446 DX::ThrowIfFailed(g_d3dDevice->CreateDepthStencilView(depthStencil.Get(), &depthStencilViewDesc, &g_depthStencilView));
447
448 // Create a viewport descriptor of the full window size.
449 CD3D11_VIEWPORT viewPort(0.0f, 0.0f, static_cast<float>(backBufferDesc.Width), static_cast<float>(backBufferDesc.Height));
450
451 // Set the current viewport using the descriptor.
452 g_d3dContext->RSSetViewports(1, &viewPort);
453 g_d3dContext->OMSetRenderTargets( 1, g_renderTargetView.GetAddressOf(), g_depthStencilView.Get() );
454}
455
456//--------------------------------------------------------------------------------------
457// Render the frame
458//--------------------------------------------------------------------------------------
459void Render()
460{
461 // Just clear the backbuffer
462 float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; //red,green,blue,alpha
463
464 g_d3dContext->ClearRenderTargetView( g_renderTargetView.Get(), ClearColor );
465 g_swapChain->Present( 0, 0 );
466}
467
468
469void oldWinMainInit()
470{
471#if 0
472 // Main message loop
473 MSG msg = {0};
474 while( WM_QUIT != msg.message )
475 {
476 if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
477 {
478 TranslateMessage( &msg );
479 DispatchMessage( &msg );
480 }
481 else
482 {
483 Render();
484 }
485 }
486
487 return (int) msg.wParam;
488#endif
489
490
491#ifdef MEMORY_TRACKING
492 ResetMem();
493 MEMORYSTATUS memStat;
494 GlobalMemoryStatus(&memStat);
495 printf("RESETMEM start: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024));
496#endif
497
498#if 0
499 // Initialize D3D
500 hr = InitD3D( &pDevice, &d3dpp );
501 g_pD3DDevice = pDevice;
502 if( FAILED(hr) )
503 {
504 app.DebugPrintf
505 ( "Failed initializing D3D.\n" );
506 return -1;
507 }
508
509 // Initialize the application, assuming sharing of the d3d interface.
510 hr = app.InitShared( pDevice, &d3dpp,
511 XuiPNGTextureLoader );
512
513 if ( FAILED(hr) )
514 {
515 app.DebugPrintf
516 ( "Failed initializing application.\n" );
517
518 return -1;
519 }
520
521
522#endif
523
524 app.loadMediaArchive();
525
526 RenderManager.Initialise(g_d3dDevice.Get(), g_swapChain.Get());
527
528 app.loadStringTable();
529
530 ui.init(g_d3dDevice,g_d3dContext,g_renderTargetView,g_depthStencilView,1920,1080);
531
532 ////////////////
533 // Initialise //
534 ////////////////
535
536#if 0
537 // 4J Stu - XACT was creating these automatically, but we need them for QNet. The setup params
538 // are just copied from a sample app and may need changed for our purposes
539 // Start XAudio2
540 hr = XAudio2Create( &g_pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR );
541 if( FAILED( hr ) )
542 {
543 app.DebugPrintf( "Initializing XAudio2 failed (err = 0x%08x)!\n", hr );
544 app.FatalLoadError();
545 }
546
547 // Create an XAudio2 mastering voice (utilized by XHV2 when voice data is mixed to main speakers)
548 hr = g_pXAudio2->CreateMasteringVoice(&g_pXAudio2MasteringVoice, XAUDIO2_DEFAULT_CHANNELS, XAUDIO2_DEFAULT_SAMPLERATE, 0, 0, NULL);
549 if ( FAILED( hr ) )
550 {
551 app.DebugPrintf( "Creating XAudio2 mastering voice failed (err = 0x%08x)!\n", hr );
552 app.FatalLoadError();
553 }
554#endif
555 app.InitTime();
556
557 // Set the number of possible joypad layouts that the user can switch between, and the number of actions
558 InputManager.Initialise(1,3,MINECRAFT_ACTION_MAX, ACTION_MAX_MENU);
559
560 // Set the default joypad action mappings for Minecraft
561 DefineActions();
562 InputManager.SetJoypadMapVal(0,0);
563 InputManager.SetKeyRepeatRate(0.3f,0.2f);
564
565 // looks like the Durango controller is a good bit more sensitive than XBOX360/PS3. Defaults in the lib are 10000 for deadzone and 32767 for movement range
566 InputManager.SetDeadzoneAndMovementRange(10000,20000,32767);
567
568 // Initialise the profile manager with the game Title ID, Offer ID, a profile version number, and the number of profile values and settings
569 ProfileManager.Initialise(SERVICE_CONFIG_ID, TITLE_PRODUCT_ID);
570
571 ProfileManager.RegisterPresence(CONTEXT_PRESENCE_IDLE,L"Idle");
572 ProfileManager.RegisterPresence(CONTEXT_PRESENCE_MENUS,L"InMenus");
573 ProfileManager.RegisterPresence(CONTEXT_PRESENCE_MULTIPLAYER,L"PlayingMultiplayer");
574 ProfileManager.RegisterPresence(CONTEXT_PRESENCE_MULTIPLAYEROFFLINE,L"PlayingMultiplayerOffline");
575 ProfileManager.RegisterPresence(CONTEXT_PRESENCE_MULTIPLAYER_1P,L"PlayingAlone");
576 ProfileManager.RegisterPresence(CONTEXT_PRESENCE_MULTIPLAYER_1POFFLINE,L"PlayingAloneOffline");
577
578 // Fix for XboxOne #165025 - XR-049: Compliance: Title does not display Rich Presence strings for profiles in main menu.
579 ProfileManager.SetGameActivityForAllActiveUsers(CONTEXT_PRESENCE_IDLE);
580
581 Compression::CreateNewThreadStorage();
582 app.ReadLocalDLCList();
583
584 // initialise the storage manager with a default save display name, a Minimum save size, and a callback for displaying the saving message
585 StorageManager.Init(0,app.GetString(IDS_DEFAULT_SAVENAME),"savegame.dat",FIFTY_ONE_MB,&CConsoleMinecraftApp::DisplaySavingMessage,(LPVOID)&app, app.UpdateProductId,SERVICE_CONFIG_ID,TITLE_PRODUCT_ID);
586
587 StorageManager.SetMaxSaves(99);
588
589 byteArray baSaveThumbnail = app.getArchiveFile(L"DefaultSaveThumbnail64x64.png");
590
591 StorageManager.InitialiseProfileData(PROFILE_VERSION_BUILD_JUNE14,
592 NUM_PROFILE_VALUES,
593 NUM_PROFILE_SETTINGS,
594 dwProfileSettingsA,
595 app.GAME_DEFINED_PROFILE_DATA_BYTES*XUSER_MAX_COUNT,
596 &app.uiGameDefinedDataChangedBitmask);
597
598 StorageManager.SetDefaultImages((PBYTE)baSaveThumbnail.data, baSaveThumbnail.length);
599
600 // Set function to be called if a save game operation can't complete due to running out of storage space etc.
601 StorageManager.SetIncompleteSaveCallback(CConsoleMinecraftApp::Callback_SaveGameIncomplete, (LPVOID)&app);
602
603 // 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
604 ProfileManager.SetSignInChangeCallback(&CConsoleMinecraftApp::SignInChangeCallback,(LPVOID)&app);
605
606 // Set a callback for the default player options to be set - when there is no profile data for the player
607 StorageManager.SetDefaultOptionsCallback(&CConsoleMinecraftApp::DefaultOptionsCallback,(LPVOID)&app);
608 StorageManager.SetOptionsDataCallback(&CConsoleMinecraftApp::OptionsDataCallback,(LPVOID)&app);
609
610
611 // Set a callback to deal with old profile versions needing updated to new versions
612 StorageManager.SetOldProfileVersionCallback(&CConsoleMinecraftApp::OldProfileVersionCallback,(LPVOID)&app);
613
614 g_NetworkManager.Initialise();
615
616
617 // Initialise TLS for tesselator, for this main thread
618 Tesselator::CreateNewThreadStorage(1024*1024);
619 // Initialise TLS for AABB and Vec3 pools, for this main thread
620 AABB::CreateNewThreadStorage();
621 Vec3::CreateNewThreadStorage();
622 IntCache::CreateNewThreadStorage();
623 OldChunkStorage::CreateNewThreadStorage();
624 Level::enableLightingCache();
625 Tile::CreateNewThreadStorage();
626
627 //4J-PB - after the init, which will have read all the local DLC, update the product ids by reading the local dlc file
628 StorageManager.UpdateDLCProductIDs();
629
630 Minecraft::main();
631 Minecraft *pMinecraft=Minecraft::GetInstance();
632 app.InitGameSettings();
633
634 // read the options here for controller 0
635 // 4J-PB - we have no valid user to read a profile for on Xbox One, and there's no EULA anyway
636 //StorageManager.ReadFromProfile(0);
637
638 app.InitialiseDLCDetails();
639 StorageManager.SetLicenseChangeFn(&app.HandleDLCLicenseChange);
640
641
642 // debug switch to trial version
643 ProfileManager.SetDebugFullOverride(true);
644
645 // set default values for controllers
646// for(int i=0;i<4;i++)
647// {
648// //app.SetDefaultOptions(app.GetGameDefinedProfileData(i),i);
649// app.SetDefaultOptions(ProfileManager.GetGameDefinedProfileData(i),i);
650// }
651
652
653#if 0
654 //bool bDisplayPauseMenu=false;
655
656 // set the default gamma level
657 float fVal=50.0f*327.68f;
658 RenderManager.UpdateGamma((unsigned short)fVal);
659
660 // load any skins
661 //app.AddSkinsToMemoryTextureFiles();
662
663 // set the achievement text for a trial achievement, now we have the string table loaded
664 ProfileManager.SetTrialTextStringTable(app.GetStringTable(),IDS_CONFIRM_OK, IDS_CONFIRM_CANCEL);
665 ProfileManager.SetTrialAwardText(eAwardType_Achievement,IDS_UNLOCK_TITLE,IDS_UNLOCK_ACHIEVEMENT_TEXT);
666 ProfileManager.SetTrialAwardText(eAwardType_GamerPic,IDS_UNLOCK_TITLE,IDS_UNLOCK_GAMERPIC_TEXT);
667 ProfileManager.SetTrialAwardText(eAwardType_AvatarItem,IDS_UNLOCK_TITLE,IDS_UNLOCK_AVATAR_TEXT);
668 ProfileManager.SetTrialAwardText(eAwardType_Theme,IDS_UNLOCK_TITLE,IDS_UNLOCK_THEME_TEXT);
669 ProfileManager.SetUpsellCallback(&app.UpsellReturnedCallback,&app);
670
671 // Set up a debug character press sequence
672#ifndef _FINAL_BUILD
673 app.SetDebugSequence("LRLRYYY");
674#endif
675
676 // Initialise the social networking manager.
677 CSocialManager::Instance()->Initialise();
678
679 // Update the base scene quick selects now that the minecraft class exists
680 //CXuiSceneBase::UpdateScreenSettings(0);
681#endif
682 app.InitialiseTips();
683#if 0
684
685 DWORD initData=0;
686
687
688
689#ifndef _FINAL_BUILD
690#ifndef _DEBUG
691 #pragma message(__LOC__"Need to define the _FINAL_BUILD before submission")
692#endif
693#endif
694
695 // Set the default sound levels
696 pMinecraft->options->set(Options::Option::MUSIC,1.0f);
697 pMinecraft->options->set(Options::Option::SOUND,1.0f);
698
699 app.NavigateToScene(XUSER_INDEX_ANY,eUIScene_Intro,&initData);
700#endif
701
702
703
704 //app.TemporaryCreateGameStart();
705
706 //Sleep(10000);
707#if 0
708 // Intro loop ?
709 while(app.IntroRunning())
710 {
711 ProfileManager.Tick();
712 // Tick XUI
713 app.RunFrame();
714
715 // 4J : WESTY : Added to ensure we always have clear background for intro.
716 RenderManager.SetClearColour(D3DCOLOR_RGBA(0,0,0,255));
717 RenderManager.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
718
719 // Render XUI
720 hr = app.Render();
721
722 // Present the frame.
723 RenderManager.Present();
724
725 // Update XUI Timers
726 hr = XuiTimersRun();
727 }
728#endif
729}
730void oldWinMainTick()
731{
732 static bool bTrialTimerDisplayed=true;
733
734 Minecraft *pMinecraft=Minecraft::GetInstance();
735 RenderManager.StartFrame();
736#if 0
737 if(pMinecraft->soundEngine->isStreamingWavebankReady() &&
738 !pMinecraft->soundEngine->isPlayingStreamingGameMusic() &&
739 !pMinecraft->soundEngine->isPlayingStreamingCDMusic() )
740 {
741 // play some music in the menus
742 pMinecraft->soundEngine->playStreaming(L"", 0, 0, 0, 0, 0, false);
743 }
744#endif
745 app.UpdateTime();
746 PIXBeginNamedEvent(0,"Input manager tick");
747 InputManager.Tick();
748 PIXEndNamedEvent();
749 PIXBeginNamedEvent(0,"Profile manager tick");
750 ProfileManager.Tick();
751 PIXEndNamedEvent();
752 PIXBeginNamedEvent(0,"Storage manager tick");
753 StorageManager.Tick();
754 PIXEndNamedEvent();
755 PIXBeginNamedEvent(0,"Render manager tick");
756 RenderManager.Tick();
757 PIXEndNamedEvent();
758
759 // Tick the social networking manager.
760 PIXBeginNamedEvent(0,"Social network manager tick");
761// CSocialManager::Instance()->Tick();
762 PIXEndNamedEvent();
763
764 // Tick sentient.
765 PIXBeginNamedEvent(0,"Sentient tick");
766 MemSect(37);
767// SentientManager.Tick();
768 MemSect(0);
769 PIXEndNamedEvent();
770
771 GameProgress::Tick();
772
773 PIXBeginNamedEvent(PIX_COLOR_INDEX(2),"Network manager do work #1");
774 g_NetworkManager.DoWork();
775 PIXEndNamedEvent();
776
777 LeaderboardManager::Instance()->Tick();
778 // Render game graphics.
779 if(app.GetGameStarted())
780 {
781 pMinecraft->run_middle();
782 app.SetAppPaused( g_NetworkManager.IsLocalGame() && g_NetworkManager.GetPlayerCount() == 1 && ui.IsPauseMenuDisplayed(ProfileManager.GetPrimaryPad()) );
783 }
784 else
785 {
786 MemSect(28);
787 pMinecraft->soundEngine->tick(NULL, 0.0f);
788 MemSect(0);
789 pMinecraft->textures->tick(true,false);
790 IntCache::Reset();
791 if( app.GetReallyChangingSessionType() )
792 {
793 pMinecraft->tickAllConnections(); // Added to stop timing out when we are waiting after converting to an offline game
794 }
795 }
796
797 pMinecraft->soundEngine->playMusicTick();
798
799
800#ifdef MEMORY_TRACKING
801 static bool bResetMemTrack = false;
802 static bool bDumpMemTrack = false;
803
804 MemPixStuff();
805
806 if( bResetMemTrack )
807 {
808 ResetMem();
809 MEMORYSTATUS memStat;
810 GlobalMemoryStatus(&memStat);
811 printf("RESETMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024));
812 bResetMemTrack = false;
813 }
814
815 if( bDumpMemTrack )
816 {
817 DumpMem();
818 bDumpMemTrack = false;
819 MEMORYSTATUS memStat;
820 GlobalMemoryStatus(&memStat);
821 printf("DUMPMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024));
822 printf("Renderer used: %d\n",RenderManager.CBuffSize(-1));
823 }
824#endif
825#if 0
826 static bool bDumpTextureUsage = false;
827 if( bDumpTextureUsage )
828 {
829 RenderManager.TextureGetStats();
830 bDumpTextureUsage = false;
831 }
832#endif
833 ui.tick();
834 ui.render();
835#if 0
836 app.HandleButtonPresses();
837
838 // store the minecraft renderstates, and re-set them after the xui render
839 GetRenderAndSamplerStates(pDevice,RenderStateA,SamplerStateA);
840
841 // Tick XUI
842 PIXBeginNamedEvent(0,"Xui running");
843 app.RunFrame();
844 PIXEndNamedEvent();
845
846 // Render XUI
847
848 PIXBeginNamedEvent(0,"XUI render");
849 MemSect(7);
850 hr = app.Render();
851 MemSect(0);
852 GetRenderAndSamplerStates(pDevice,RenderStateA2,SamplerStateA2);
853 PIXEndNamedEvent();
854
855 for(int i=0;i<8;i++)
856 {
857 if(RenderStateA2[i]!=RenderStateA[i])
858 {
859 //printf("Reseting RenderStateA[%d] after a XUI render\n",i);
860 pDevice->SetRenderState(RenderStateModes[i],RenderStateA[i]);
861 }
862 }
863 for(int i=0;i<5;i++)
864 {
865 if(SamplerStateA2[i]!=SamplerStateA[i])
866 {
867 //printf("Reseting SamplerStateA[%d] after a XUI render\n",i);
868 pDevice->SetSamplerState(0,SamplerStateModes[i],SamplerStateA[i]);
869 }
870 }
871
872 RenderManager.Set_matrixDirty();
873#endif
874
875#if 0 // ndef _CONTENT_PACKAGE
876 if( InputManager.ButtonPressed(0,MINECRAFT_ACTION_DPAD_LEFT) ||
877 InputManager.ButtonPressed(0,ACTION_MENU_STICK_PRESS))
878 {
879 RenderManager.DoScreenGrabOnNextPresent();
880 }
881#endif
882
883 // Present the frame.
884 RenderManager.Present();
885
886 ui.CheckMenuDisplayed();
887
888 PIXBeginNamedEvent(0,"Profile load check");
889 // has the game defined profile data been changed (by a profile load)
890 if(app.uiGameDefinedDataChangedBitmask!=0)
891 {
892 void *pData;
893 for(int i=0;i<XUSER_MAX_COUNT;i++)
894 {
895 if(app.uiGameDefinedDataChangedBitmask&(1<<i))
896 {
897 // It has - game needs to update its values with the data from the profile
898 pData=StorageManager.GetGameDefinedProfileData(i);
899 // reset the changed flag
900 app.ClearGameSettingsChangedFlag(i);
901 app.DebugPrintf("*** - APPLYING GAME SETTINGS CHANGE for pad %d\n",i);
902 app.ApplyGameSettingsChanged(i);
903
904#ifdef _DEBUG_MENUS_ENABLED
905 if(app.DebugSettingsOn())
906 {
907 app.ActionDebugMask(i);
908 }
909 else
910 {
911 // force debug mask off
912 app.ActionDebugMask(i,true);
913 }
914#endif
915 // clear the stats first - there could have beena signout and sign back in in the menus
916 // need to clear the player stats - can't assume it'll be done in setlevel - we may not be in the game
917 pMinecraft->stats[ i ]->clear();
918 pMinecraft->stats[i]->parse(pData);
919 }
920 }
921
922#if 0
923 // Check to see if we can post to social networks.
924 CSocialManager::Instance()->RefreshPostingCapability();
925#endif
926
927 // clear the flag
928 app.uiGameDefinedDataChangedBitmask=0;
929
930 // Check if any profile write are needed
931 app.CheckGameSettingsChanged();
932
933 }
934 PIXEndNamedEvent();
935 app.TickTMSPPFilesRetrieved();
936
937 app.TickDLCOffersRetrieved();
938
939 PIXBeginNamedEvent(0,"Network manager do work #2");
940 // 4J Stu - Added this back as it was causing horrendous lag (and eventually a crash on a client) when playing with multiple clients
941 g_NetworkManager.DoWork(); // TODO - consider putting this back in. Removed because we are having trouble with how long the tick is taking on Durango
942 PIXEndNamedEvent();
943
944#if 0
945 PIXBeginNamedEvent(0,"Misc extra xui");
946 // Update XUI Timers
947 hr = XuiTimersRun();
948#endif
949 // Any threading type things to deal with from the xui side?
950 app.HandleXuiActions();
951#if 0
952 PIXEndNamedEvent();
953#endif
954
955 // 4J-PB - Update the trial timer display if we are in the trial version
956 if(!ProfileManager.IsFullVersion())
957 {
958 // display the trial timer
959 if(app.GetGameStarted())
960 {
961 // 4J-PB - if the game is paused, add the elapsed time to the trial timer count so it doesn't tick down
962 if(app.IsAppPaused())
963 {
964 app.UpdateTrialPausedTimer();
965 }
966 ui.UpdateTrialTimer(ProfileManager.GetPrimaryPad());
967 }
968 }
969 else
970 {
971 // need to turn off the trial timer if it was on , and we've unlocked the full version
972 if(bTrialTimerDisplayed)
973 {
974 ui.ShowTrialTimer(false);
975 bTrialTimerDisplayed=false;
976 }
977 }
978
979 // Fix for #7318 - Title crashes after short soak in the leaderboards menu
980 // A memory leak was caused because the icon renderer kept creating new Vec3's because the pool wasn't reset
981 Vec3::resetPool();
982}
983
984#ifdef MEMORY_TRACKING
985
986int totalAllocGen = 0;
987unordered_map<int,int> allocCounts;
988bool trackEnable = false;
989bool trackStarted = false;
990volatile size_t sizeCheckMin = 1160;
991volatile size_t sizeCheckMax = 1160;
992volatile int sectCheck = 48;
993CRITICAL_SECTION memCS;
994DWORD tlsIdx;
995
996LPVOID XMemAlloc(SIZE_T dwSize, DWORD dwAllocAttributes)
997{
998 if( !trackStarted )
999 {
1000 void *p = XMemAllocDefault(dwSize,dwAllocAttributes);
1001 size_t realSize = XMemSizeDefault(p, dwAllocAttributes);
1002 totalAllocGen += realSize;
1003 return p;
1004 }
1005
1006 EnterCriticalSection(&memCS);
1007
1008 void *p=XMemAllocDefault(dwSize + 16,dwAllocAttributes);
1009 size_t realSize = XMemSizeDefault(p,dwAllocAttributes) - 16;
1010
1011 if( trackEnable )
1012 {
1013#if 1
1014 int sect = ((int) TlsGetValue(tlsIdx)) & 0x3f;
1015 *(((unsigned char *)p)+realSize) = sect;
1016
1017 if( ( realSize >= sizeCheckMin ) && ( realSize <= sizeCheckMax ) && ( ( sect == sectCheck ) || ( sectCheck == -1 ) ) )
1018 {
1019 app.DebugPrintf("Found one\n");
1020 }
1021#endif
1022
1023 if( p )
1024 {
1025 totalAllocGen += realSize;
1026 trackEnable = false;
1027 int key = ( sect << 26 ) | realSize;
1028 int oldCount = allocCounts[key];
1029 allocCounts[key] = oldCount + 1;
1030
1031 trackEnable = true;
1032 }
1033 }
1034
1035 LeaveCriticalSection(&memCS);
1036
1037 return p;
1038}
1039
1040void* operator new (size_t size)
1041{
1042 return (unsigned char *)XMemAlloc(size,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP));
1043}
1044
1045void operator delete (void *p)
1046{
1047 XMemFree(p,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP));
1048}
1049
1050void WINAPI XMemFree(PVOID pAddress, DWORD dwAllocAttributes)
1051{
1052 bool special = false;
1053 if( dwAllocAttributes == 0 )
1054 {
1055 dwAllocAttributes = MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP);
1056 special = true;
1057 }
1058 if(!trackStarted )
1059 {
1060 size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes);
1061 XMemFreeDefault(pAddress, dwAllocAttributes);
1062 totalAllocGen -= realSize;
1063 return;
1064 }
1065 EnterCriticalSection(&memCS);
1066 if( pAddress )
1067 {
1068 size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes) - 16;
1069
1070 if(trackEnable)
1071 {
1072 int sect = *(((unsigned char *)pAddress)+realSize);
1073 totalAllocGen -= realSize;
1074 trackEnable = false;
1075 int key = ( sect << 26 ) | realSize;
1076 int oldCount = allocCounts[key];
1077 allocCounts[key] = oldCount - 1;
1078 trackEnable = true;
1079
1080 }
1081 XMemFreeDefault(pAddress, dwAllocAttributes);
1082 }
1083 LeaveCriticalSection(&memCS);
1084}
1085
1086SIZE_T WINAPI XMemSize(
1087 PVOID pAddress,
1088 DWORD dwAllocAttributes
1089)
1090{
1091 if( trackStarted )
1092 {
1093 return XMemSizeDefault(pAddress, dwAllocAttributes) - 16;
1094 }
1095 else
1096 {
1097 return XMemSizeDefault(pAddress, dwAllocAttributes);
1098 }
1099}
1100
1101
1102void DumpMem()
1103{
1104 int totalLeak = 0;
1105 for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ )
1106 {
1107 if(it->second > 0 )
1108 {
1109 app.DebugPrintf("%d %d %d %d\n",( it->first >> 26 ) & 0x3f,it->first & 0x03ffffff, it->second, (it->first & 0x03ffffff) * it->second);
1110 totalLeak += ( it->first & 0x03ffffff ) * it->second;
1111 }
1112 }
1113 app.DebugPrintf("Total %d\n",totalLeak);
1114}
1115
1116void ResetMem()
1117{
1118 if( !trackStarted )
1119 {
1120 trackEnable = true;
1121 trackStarted = true;
1122 totalAllocGen = 0;
1123 InitializeCriticalSection(&memCS);
1124 tlsIdx = TlsAlloc();
1125 }
1126 EnterCriticalSection(&memCS);
1127 trackEnable = false;
1128 allocCounts.clear();
1129 trackEnable = true;
1130 LeaveCriticalSection(&memCS);
1131}
1132
1133void MemSect(int section)
1134{
1135 unsigned int value = (unsigned int)TlsGetValue(tlsIdx);
1136 if( section == 0 ) // pop
1137 {
1138 value = (value >> 6) & 0x03ffffff;
1139 }
1140 else
1141 {
1142 value = (value << 6) | section;
1143 }
1144 TlsSetValue(tlsIdx, (LPVOID)value);
1145}
1146
1147void MemPixStuff()
1148{
1149 const int MAX_SECT = 46;
1150
1151 int totals[MAX_SECT] = {0};
1152
1153 for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ )
1154 {
1155 if(it->second > 0 )
1156 {
1157 int sect = ( it->first >> 26 ) & 0x3f;
1158 int bytes = it->first & 0x03ffffff;
1159 totals[sect] += bytes * it->second;
1160 }
1161 }
1162
1163 unsigned int allSectsTotal = 0;
1164 for( int i = 0; i < MAX_SECT; i++ )
1165 {
1166 allSectsTotal += totals[i];
1167 PIXAddNamedCounter(((float)totals[i])/1024.0f,"MemSect%d",i);
1168 }
1169
1170 PIXAddNamedCounter(((float)allSectsTotal)/(4096.0f),"MemSect total pages");
1171}
1172
1173#endif