diff --git a/Minecraft.Client/Durango/Durango_Minecraft.cpp b/Minecraft.Client/Durango/Durango_Minecraft.cpp index 83264ae0..c664584e 100644 --- a/Minecraft.Client/Durango/Durango_Minecraft.cpp +++ b/Minecraft.Client/Durango/Durango_Minecraft.cpp @@ -46,20 +46,11 @@ using namespace Windows::Foundation::Collections; //#define FIFTY_TWO_MB (1024*1024*52) // Maximum TCR space required for a save (checking for this on a selected device) #define FIFTY_ONE_MB (1000000*51) // Maximum TCR space required for a save is 52MB (checking for this on a selected device) -//#define PROFILE_VERSION 3 // new version for the interim bug fix 166 TU #define NUM_PROFILE_VALUES 5 #define NUM_PROFILE_SETTINGS 4 DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]= { -#ifdef _XBOX - XPROFILE_OPTION_CONTROLLER_VIBRATION, - XPROFILE_GAMER_YAXIS_INVERSION, - XPROFILE_GAMER_CONTROL_SENSITIVITY, - XPROFILE_GAMER_ACTION_MOVEMENT_CONTROL, - XPROFILE_TITLE_SPECIFIC1, -#else 0,0,0,0,0 -#endif }; //------------------------------------------------------------------------------------- @@ -234,61 +225,9 @@ void DefineActions(void) InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN); } -#if 0 -HRESULT InitD3D( IDirect3DDevice9 **ppDevice, - D3DPRESENT_PARAMETERS *pd3dPP ) -{ - IDirect3D9 *pD3D; - - pD3D = Direct3DCreate9( D3D_SDK_VERSION ); - - // Set up the structure used to create the D3DDevice - // Using a permanent 1280x720 backbuffer now no matter what the actual video resolution.right Have also disabled letterboxing, - // which would letterbox a 1280x720 output if it detected a 4:3 video source - we're doing an anamorphic squash in this - // mode so don't need this functionality. - - ZeroMemory( pd3dPP, sizeof(D3DPRESENT_PARAMETERS) ); - XVIDEO_MODE VideoMode; - XGetVideoMode( &VideoMode ); - g_bWidescreen = VideoMode.fIsWideScreen; - pd3dPP->BackBufferWidth = 1280; - pd3dPP->BackBufferHeight = 720; - pd3dPP->BackBufferFormat = D3DFMT_A8R8G8B8; - pd3dPP->BackBufferCount = 1; - pd3dPP->EnableAutoDepthStencil = TRUE; - pd3dPP->AutoDepthStencilFormat = D3DFMT_D24S8; - pd3dPP->SwapEffect = D3DSWAPEFFECT_DISCARD; - pd3dPP->PresentationInterval = D3DPRESENT_INTERVAL_ONE; - //pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX; - //ERR[D3D]: Can't set D3DPRESENTFLAG_NO_LETTERBOX when wide-screen is enabled - // in the launcher/dashboard. - if(g_bWidescreen) - pd3dPP->Flags=0; - else - pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX; - - // Create the device. - return pD3D->CreateDevice( - 0, - D3DDEVTYPE_HAL, - NULL, - D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_BUFFER_2_FRAMES, - pd3dPP, - ppDevice ); -} -#endif -//#define MEMORY_TRACKING - -#ifdef MEMORY_TRACKING -void ResetMem(); -void DumpMem(); -void MemPixStuff(); -#else void MemSect(int sect) { } -#endif - HINSTANCE g_hInst = NULL; @@ -465,62 +404,8 @@ void Render() g_swapChain->Present( 0, 0 ); } - void oldWinMainInit() { -#if 0 - // Main message loop - MSG msg = {0}; - while( WM_QUIT != msg.message ) - { - if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) - { - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } - else - { - Render(); - } - } - - return (int) msg.wParam; -#endif - - -#ifdef MEMORY_TRACKING - ResetMem(); - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("RESETMEM start: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); -#endif - -#if 0 - // Initialize D3D - hr = InitD3D( &pDevice, &d3dpp ); - g_pD3DDevice = pDevice; - if( FAILED(hr) ) - { - app.DebugPrintf - ( "Failed initializing D3D.\n" ); - return -1; - } - - // Initialize the application, assuming sharing of the d3d interface. - hr = app.InitShared( pDevice, &d3dpp, - XuiPNGTextureLoader ); - - if ( FAILED(hr) ) - { - app.DebugPrintf - ( "Failed initializing application.\n" ); - - return -1; - } - - -#endif - app.loadMediaArchive(); RenderManager.Initialise(g_d3dDevice.Get(), g_swapChain.Get()); @@ -533,25 +418,6 @@ void oldWinMainInit() // Initialise // //////////////// -#if 0 - // 4J Stu - XACT was creating these automatically, but we need them for QNet. The setup params - // are just copied from a sample app and may need changed for our purposes - // Start XAudio2 - hr = XAudio2Create( &g_pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR ); - if( FAILED( hr ) ) - { - app.DebugPrintf( "Initializing XAudio2 failed (err = 0x%08x)!\n", hr ); - app.FatalLoadError(); - } - - // Create an XAudio2 mastering voice (utilized by XHV2 when voice data is mixed to main speakers) - hr = g_pXAudio2->CreateMasteringVoice(&g_pXAudio2MasteringVoice, XAUDIO2_DEFAULT_CHANNELS, XAUDIO2_DEFAULT_SAMPLERATE, 0, 0, NULL); - if ( FAILED( hr ) ) - { - app.DebugPrintf( "Creating XAudio2 mastering voice failed (err = 0x%08x)!\n", hr ); - app.FatalLoadError(); - } -#endif app.InitTime(); // Set the number of possible joypad layouts that the user can switch between, and the number of actions @@ -649,99 +515,22 @@ void oldWinMainInit() // app.SetDefaultOptions(ProfileManager.GetGameDefinedProfileData(i),i); // } - -#if 0 - //bool bDisplayPauseMenu=false; - - // set the default gamma level - float fVal=50.0f*327.68f; - RenderManager.UpdateGamma((unsigned short)fVal); - - // load any skins - //app.AddSkinsToMemoryTextureFiles(); - - // set the achievement text for a trial achievement, now we have the string table loaded - ProfileManager.SetTrialTextStringTable(app.GetStringTable(),IDS_CONFIRM_OK, IDS_CONFIRM_CANCEL); - ProfileManager.SetTrialAwardText(eAwardType_Achievement,IDS_UNLOCK_TITLE,IDS_UNLOCK_ACHIEVEMENT_TEXT); - ProfileManager.SetTrialAwardText(eAwardType_GamerPic,IDS_UNLOCK_TITLE,IDS_UNLOCK_GAMERPIC_TEXT); - ProfileManager.SetTrialAwardText(eAwardType_AvatarItem,IDS_UNLOCK_TITLE,IDS_UNLOCK_AVATAR_TEXT); - ProfileManager.SetTrialAwardText(eAwardType_Theme,IDS_UNLOCK_TITLE,IDS_UNLOCK_THEME_TEXT); - ProfileManager.SetUpsellCallback(&app.UpsellReturnedCallback,&app); - - // Set up a debug character press sequence -#ifndef _FINAL_BUILD - app.SetDebugSequence("LRLRYYY"); -#endif - - // Initialise the social networking manager. - CSocialManager::Instance()->Initialise(); - - // Update the base scene quick selects now that the minecraft class exists - //CXuiSceneBase::UpdateScreenSettings(0); -#endif app.InitialiseTips(); -#if 0 - DWORD initData=0; +#ifdef _TEMPORARY_CREATE_GAME + app.TemporaryCreateGameStart(); - - -#ifndef _FINAL_BUILD -#ifndef _DEBUG - #pragma message(__LOC__"Need to define the _FINAL_BUILD before submission") -#endif -#endif - - // Set the default sound levels - pMinecraft->options->set(Options::Option::MUSIC,1.0f); - pMinecraft->options->set(Options::Option::SOUND,1.0f); - - app.NavigateToScene(XUSER_INDEX_ANY,eUIScene_Intro,&initData); -#endif - - - - //app.TemporaryCreateGameStart(); - - //Sleep(10000); -#if 0 - // Intro loop ? - while(app.IntroRunning()) - { - ProfileManager.Tick(); - // Tick XUI - app.RunFrame(); - - // 4J : WESTY : Added to ensure we always have clear background for intro. - RenderManager.SetClearColour(D3DCOLOR_RGBA(0,0,0,255)); - RenderManager.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // Render XUI - hr = app.Render(); - - // Present the frame. - RenderManager.Present(); - - // Update XUI Timers - hr = XuiTimersRun(); - } + Sleep(10000); #endif } + void oldWinMainTick() { static bool bTrialTimerDisplayed=true; Minecraft *pMinecraft=Minecraft::GetInstance(); RenderManager.StartFrame(); -#if 0 - if(pMinecraft->soundEngine->isStreamingWavebankReady() && - !pMinecraft->soundEngine->isPlayingStreamingGameMusic() && - !pMinecraft->soundEngine->isPlayingStreamingCDMusic() ) - { - // play some music in the menus - pMinecraft->soundEngine->playStreaming(L"", 0, 0, 0, 0, 0, false); - } -#endif + app.UpdateTime(); PIXBeginNamedEvent(0,"Input manager tick"); InputManager.Tick(); @@ -756,18 +545,6 @@ void oldWinMainTick() RenderManager.Tick(); PIXEndNamedEvent(); - // Tick the social networking manager. - PIXBeginNamedEvent(0,"Social network manager tick"); -// CSocialManager::Instance()->Tick(); - PIXEndNamedEvent(); - - // Tick sentient. - PIXBeginNamedEvent(0,"Sentient tick"); - MemSect(37); -// SentientManager.Tick(); - MemSect(0); - PIXEndNamedEvent(); - GameProgress::Tick(); PIXBeginNamedEvent(PIX_COLOR_INDEX(2),"Network manager do work #1"); @@ -796,89 +573,8 @@ void oldWinMainTick() pMinecraft->soundEngine->playMusicTick(); - -#ifdef MEMORY_TRACKING - static bool bResetMemTrack = false; - static bool bDumpMemTrack = false; - - MemPixStuff(); - - if( bResetMemTrack ) - { - ResetMem(); - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("RESETMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); - bResetMemTrack = false; - } - - if( bDumpMemTrack ) - { - DumpMem(); - bDumpMemTrack = false; - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("DUMPMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); - printf("Renderer used: %d\n",RenderManager.CBuffSize(-1)); - } -#endif -#if 0 - static bool bDumpTextureUsage = false; - if( bDumpTextureUsage ) - { - RenderManager.TextureGetStats(); - bDumpTextureUsage = false; - } -#endif ui.tick(); ui.render(); -#if 0 - app.HandleButtonPresses(); - - // store the minecraft renderstates, and re-set them after the xui render - GetRenderAndSamplerStates(pDevice,RenderStateA,SamplerStateA); - - // Tick XUI - PIXBeginNamedEvent(0,"Xui running"); - app.RunFrame(); - PIXEndNamedEvent(); - - // Render XUI - - PIXBeginNamedEvent(0,"XUI render"); - MemSect(7); - hr = app.Render(); - MemSect(0); - GetRenderAndSamplerStates(pDevice,RenderStateA2,SamplerStateA2); - PIXEndNamedEvent(); - - for(int i=0;i<8;i++) - { - if(RenderStateA2[i]!=RenderStateA[i]) - { - //printf("Reseting RenderStateA[%d] after a XUI render\n",i); - pDevice->SetRenderState(RenderStateModes[i],RenderStateA[i]); - } - } - for(int i=0;i<5;i++) - { - if(SamplerStateA2[i]!=SamplerStateA[i]) - { - //printf("Reseting SamplerStateA[%d] after a XUI render\n",i); - pDevice->SetSamplerState(0,SamplerStateModes[i],SamplerStateA[i]); - } - } - - RenderManager.Set_matrixDirty(); -#endif - -#if 0 // ndef _CONTENT_PACKAGE - if( InputManager.ButtonPressed(0,MINECRAFT_ACTION_DPAD_LEFT) || - InputManager.ButtonPressed(0,ACTION_MENU_STICK_PRESS)) - { - RenderManager.DoScreenGrabOnNextPresent(); - } -#endif // Present the frame. RenderManager.Present(); @@ -919,11 +615,6 @@ void oldWinMainTick() } } -#if 0 - // Check to see if we can post to social networks. - CSocialManager::Instance()->RefreshPostingCapability(); -#endif - // clear the flag app.uiGameDefinedDataChangedBitmask=0; @@ -938,19 +629,11 @@ void oldWinMainTick() PIXBeginNamedEvent(0,"Network manager do work #2"); // 4J Stu - Added this back as it was causing horrendous lag (and eventually a crash on a client) when playing with multiple clients - g_NetworkManager.DoWork(); // TODO - consider putting this back in. Removed because we are having trouble with how long the tick is taking on Durango + g_NetworkManager.DoWork(); PIXEndNamedEvent(); -#if 0 - PIXBeginNamedEvent(0,"Misc extra xui"); - // Update XUI Timers - hr = XuiTimersRun(); -#endif // Any threading type things to deal with from the xui side? app.HandleXuiActions(); -#if 0 - PIXEndNamedEvent(); -#endif // 4J-PB - Update the trial timer display if we are in the trial version if(!ProfileManager.IsFullVersion()) @@ -980,194 +663,3 @@ void oldWinMainTick() // A memory leak was caused because the icon renderer kept creating new Vec3's because the pool wasn't reset Vec3::resetPool(); } - -#ifdef MEMORY_TRACKING - -int totalAllocGen = 0; -unordered_map allocCounts; -bool trackEnable = false; -bool trackStarted = false; -volatile size_t sizeCheckMin = 1160; -volatile size_t sizeCheckMax = 1160; -volatile int sectCheck = 48; -CRITICAL_SECTION memCS; -DWORD tlsIdx; - -LPVOID XMemAlloc(SIZE_T dwSize, DWORD dwAllocAttributes) -{ - if( !trackStarted ) - { - void *p = XMemAllocDefault(dwSize,dwAllocAttributes); - size_t realSize = XMemSizeDefault(p, dwAllocAttributes); - totalAllocGen += realSize; - return p; - } - - EnterCriticalSection(&memCS); - - void *p=XMemAllocDefault(dwSize + 16,dwAllocAttributes); - size_t realSize = XMemSizeDefault(p,dwAllocAttributes) - 16; - - if( trackEnable ) - { -#if 1 - int sect = ((int) TlsGetValue(tlsIdx)) & 0x3f; - *(((unsigned char *)p)+realSize) = sect; - - if( ( realSize >= sizeCheckMin ) && ( realSize <= sizeCheckMax ) && ( ( sect == sectCheck ) || ( sectCheck == -1 ) ) ) - { - app.DebugPrintf("Found one\n"); - } -#endif - - if( p ) - { - totalAllocGen += realSize; - trackEnable = false; - int key = ( sect << 26 ) | realSize; - int oldCount = allocCounts[key]; - allocCounts[key] = oldCount + 1; - - trackEnable = true; - } - } - - LeaveCriticalSection(&memCS); - - return p; -} - -void* operator new (size_t size) -{ - return (unsigned char *)XMemAlloc(size,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); -} - -void operator delete (void *p) -{ - XMemFree(p,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); -} - -void WINAPI XMemFree(PVOID pAddress, DWORD dwAllocAttributes) -{ - bool special = false; - if( dwAllocAttributes == 0 ) - { - dwAllocAttributes = MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP); - special = true; - } - if(!trackStarted ) - { - size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes); - XMemFreeDefault(pAddress, dwAllocAttributes); - totalAllocGen -= realSize; - return; - } - EnterCriticalSection(&memCS); - if( pAddress ) - { - size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes) - 16; - - if(trackEnable) - { - int sect = *(((unsigned char *)pAddress)+realSize); - totalAllocGen -= realSize; - trackEnable = false; - int key = ( sect << 26 ) | realSize; - int oldCount = allocCounts[key]; - allocCounts[key] = oldCount - 1; - trackEnable = true; - - } - XMemFreeDefault(pAddress, dwAllocAttributes); - } - LeaveCriticalSection(&memCS); -} - -SIZE_T WINAPI XMemSize( - PVOID pAddress, - DWORD dwAllocAttributes -) -{ - if( trackStarted ) - { - return XMemSizeDefault(pAddress, dwAllocAttributes) - 16; - } - else - { - return XMemSizeDefault(pAddress, dwAllocAttributes); - } -} - - -void DumpMem() -{ - int totalLeak = 0; - for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ ) - { - if(it->second > 0 ) - { - app.DebugPrintf("%d %d %d %d\n",( it->first >> 26 ) & 0x3f,it->first & 0x03ffffff, it->second, (it->first & 0x03ffffff) * it->second); - totalLeak += ( it->first & 0x03ffffff ) * it->second; - } - } - app.DebugPrintf("Total %d\n",totalLeak); -} - -void ResetMem() -{ - if( !trackStarted ) - { - trackEnable = true; - trackStarted = true; - totalAllocGen = 0; - InitializeCriticalSection(&memCS); - tlsIdx = TlsAlloc(); - } - EnterCriticalSection(&memCS); - trackEnable = false; - allocCounts.clear(); - trackEnable = true; - LeaveCriticalSection(&memCS); -} - -void MemSect(int section) -{ - unsigned int value = (unsigned int)TlsGetValue(tlsIdx); - if( section == 0 ) // pop - { - value = (value >> 6) & 0x03ffffff; - } - else - { - value = (value << 6) | section; - } - TlsSetValue(tlsIdx, (LPVOID)value); -} - -void MemPixStuff() -{ - const int MAX_SECT = 46; - - int totals[MAX_SECT] = {0}; - - for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ ) - { - if(it->second > 0 ) - { - int sect = ( it->first >> 26 ) & 0x3f; - int bytes = it->first & 0x03ffffff; - totals[sect] += bytes * it->second; - } - } - - unsigned int allSectsTotal = 0; - for( int i = 0; i < MAX_SECT; i++ ) - { - allSectsTotal += totals[i]; - PIXAddNamedCounter(((float)totals[i])/1024.0f,"MemSect%d",i); - } - - PIXAddNamedCounter(((float)allSectsTotal)/(4096.0f),"MemSect total pages"); -} - -#endif diff --git a/Minecraft.Client/Orbis/Orbis_Minecraft.cpp b/Minecraft.Client/Orbis/Orbis_Minecraft.cpp index b6224bd2..4bf5c6dc 100644 --- a/Minecraft.Client/Orbis/Orbis_Minecraft.cpp +++ b/Minecraft.Client/Orbis/Orbis_Minecraft.cpp @@ -26,10 +26,6 @@ #include "..\..\Minecraft.World\ThreadName.h" #include "..\..\Minecraft.Client\StatsCounter.h" #include "..\ConnectScreen.h" -//#include "Social\SocialManager.h" -//#include "Leaderboards\LeaderboardManager.h" -//#include "XUI\XUI_Scene_Container.h" -//#include "NetworkManager.h" #include "..\..\Minecraft.Client\Tesselator.h" #include "..\..\Minecraft.Client\Options.h" #include "Sentient\SentientManager.h" @@ -42,28 +38,13 @@ #include "Network/Orbis_NPToolkit.h" #include "Orbis\Network\SonyVoiceChat_Orbis.h" -#define THEME_NAME "584111F70AAAAAAA" -#define THEME_FILESIZE 2797568 - -//#define THREE_MB 3145728 // minimum save size (checking for this on a selected device) -//#define FIVE_MB 5242880 // minimum save size (checking for this on a selected device) -//#define FIFTY_TWO_MB (1024*1024*52) // Maximum TCR space required for a save (checking for this on a selected device) #define FIFTY_ONE_MB (1000000*51) // Maximum TCR space required for a save is 52MB (checking for this on a selected device) -//#define PROFILE_VERSION 3 // new version for the interim bug fix 166 TU #define NUM_PROFILE_VALUES 5 #define NUM_PROFILE_SETTINGS 4 DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]= { -#ifdef _XBOX - XPROFILE_OPTION_CONTROLLER_VIBRATION, - XPROFILE_GAMER_YAXIS_INVERSION, - XPROFILE_GAMER_CONTROL_SENSITIVITY, - XPROFILE_GAMER_ACTION_MOVEMENT_CONTROL, - XPROFILE_TITLE_SPECIFIC1, -#else 0,0,0,0,0 -#endif }; //------------------------------------------------------------------------------------- @@ -78,7 +59,6 @@ void FreeRichPresenceStrings(); BOOL g_bWidescreen = TRUE; - void DefineActions(void) { // The app needs to define the actions required, and the possible mappings for these @@ -325,311 +305,9 @@ void DefineActions(void) InputManager.SetGameJoypadMaps(PARTIAL_MAP_1, MINECRAFT_ACTION_GAME_INFO, _PS4_JOY_BUTTON_DPAD_UP); } -#if 0 -HRESULT InitD3D( IDirect3DDevice9 **ppDevice, - D3DPRESENT_PARAMETERS *pd3dPP ) -{ - IDirect3D9 *pD3D; - - pD3D = Direct3DCreate9( D3D_SDK_VERSION ); - - // Set up the structure used to create the D3DDevice - // Using a permanent 1280x720 backbuffer now no matter what the actual video resolution.right Have also disabled letterboxing, - // which would letterbox a 1280x720 output if it detected a 4:3 video source - we're doing an anamorphic squash in this - // mode so don't need this functionality. - - ZeroMemory( pd3dPP, sizeof(D3DPRESENT_PARAMETERS) ); - XVIDEO_MODE VideoMode; - XGetVideoMode( &VideoMode ); - g_bWidescreen = VideoMode.fIsWideScreen; - pd3dPP->BackBufferWidth = 1280; - pd3dPP->BackBufferHeight = 720; - pd3dPP->BackBufferFormat = D3DFMT_A8R8G8B8; - pd3dPP->BackBufferCount = 1; - pd3dPP->EnableAutoDepthStencil = TRUE; - pd3dPP->AutoDepthStencilFormat = D3DFMT_D24S8; - pd3dPP->SwapEffect = D3DSWAPEFFECT_DISCARD; - pd3dPP->PresentationInterval = D3DPRESENT_INTERVAL_ONE; - //pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX; - //ERR[D3D]: Can't set D3DPRESENTFLAG_NO_LETTERBOX when wide-screen is enabled - // in the launcher/dashboard. - if(g_bWidescreen) - pd3dPP->Flags=0; - else - pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX; - - // Create the device. - return pD3D->CreateDevice( - 0, - D3DDEVTYPE_HAL, - NULL, - D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_BUFFER_2_FRAMES, - pd3dPP, - ppDevice ); -} -#endif -//#define MEMORY_TRACKING - -#ifdef MEMORY_TRACKING -void ResetMem(); -void DumpMem(); -void MemPixStuff(); -#else void MemSect(int sect) { } -#endif - -#ifndef __ORBIS__ -HINSTANCE g_hInst = NULL; -HWND g_hWnd = NULL; -D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL; -D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0; -ID3D11Device* g_pd3dDevice = NULL; -ID3D11DeviceContext* g_pImmediateContext = NULL; -IDXGISwapChain* g_pSwapChain = NULL; -ID3D11RenderTargetView* g_pRenderTargetView = NULL; -ID3D11DepthStencilView* g_pDepthStencilView = NULL; -ID3D11Texture2D* g_pDepthStencilBuffer = NULL; - -// -// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) -// -// PURPOSE: Processes messages for the main window. -// -// WM_COMMAND - process the application menu -// WM_PAINT - Paint the main window -// WM_DESTROY - post a quit message and return -// -// -LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - int wmId, wmEvent; - PAINTSTRUCT ps; - HDC hdc; - - switch (message) - { - case WM_COMMAND: - wmId = LOWORD(wParam); - wmEvent = HIWORD(wParam); - // Parse the menu selections: - switch (wmId) - { - case IDM_EXIT: - DestroyWindow(hWnd); - break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - break; - case WM_PAINT: - hdc = BeginPaint(hWnd, &ps); - // TODO: Add any drawing code here... - EndPaint(hWnd, &ps); - break; - case WM_DESTROY: - PostQuitMessage(0); - break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return 0; -} - - -// -// FUNCTION: MyRegisterClass() -// -// PURPOSE: Registers the window class. -// -ATOM MyRegisterClass(HINSTANCE hInstance) -{ - WNDCLASSEX wcex; - - wcex.cbSize = sizeof(WNDCLASSEX); - - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = WndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = hInstance; - wcex.hIcon = LoadIcon(hInstance, "Minecraft"); - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wcex.lpszMenuName = "Minecraft"; - wcex.lpszClassName = "MinecraftClass"; - wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); - - return RegisterClassEx(&wcex); -} - -// -// FUNCTION: InitInstance(HINSTANCE, int) -// -// PURPOSE: Saves instance handle and creates main window -// -// COMMENTS: -// -// In this function, we save the instance handle in a global variable and -// create and display the main program window. -// -BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) -{ - g_hInst = hInstance; // Store instance handle in our global variable - - g_hWnd = CreateWindow("MinecraftClass", "Minecraft", WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); - - if (!g_hWnd) - { - return FALSE; - } - - ShowWindow(g_hWnd, nCmdShow); - UpdateWindow(g_hWnd); - - return TRUE; -} - - -//-------------------------------------------------------------------------------------- -// Create Direct3D device and swap chain -//-------------------------------------------------------------------------------------- -HRESULT InitDevice() -{ - HRESULT hr = S_OK; - - RECT rc; - GetClientRect( g_hWnd, &rc ); - UINT width = rc.right - rc.left; - UINT height = rc.bottom - rc.top; - - UINT createDeviceFlags = 0; -#ifdef _DEBUG - createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; -#endif - - D3D_DRIVER_TYPE driverTypes[] = - { - D3D_DRIVER_TYPE_HARDWARE, - D3D_DRIVER_TYPE_WARP, - D3D_DRIVER_TYPE_REFERENCE, - }; - UINT numDriverTypes = ARRAYSIZE( driverTypes ); - - D3D_FEATURE_LEVEL featureLevels[] = - { - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, - D3D_FEATURE_LEVEL_10_0, - }; - UINT numFeatureLevels = ARRAYSIZE( featureLevels ); - - DXGI_SWAP_CHAIN_DESC sd; - ZeroMemory( &sd, sizeof( sd ) ); - sd.BufferCount = 1; - sd.BufferDesc.Width = width; - sd.BufferDesc.Height = height; - sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - sd.BufferDesc.RefreshRate.Numerator = 60; - sd.BufferDesc.RefreshRate.Denominator = 1; - sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - sd.OutputWindow = g_hWnd; - sd.SampleDesc.Count = 1; - sd.SampleDesc.Quality = 0; - sd.Windowed = TRUE; - - for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ ) - { - g_driverType = driverTypes[driverTypeIndex]; - hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels, - D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext ); - if( HRESULT_SUCCEEDED( hr ) ) - break; - } - if( FAILED( hr ) ) - return hr; - - // Create a render target view - ID3D11Texture2D* pBackBuffer = NULL; - hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer ); - if( FAILED( hr ) ) - return hr; - - // Create a depth stencil buffer - D3D11_TEXTURE2D_DESC descDepth; - - descDepth.Width = width; - descDepth.Height = height; - descDepth.MipLevels = 1; - descDepth.ArraySize = 1; - descDepth.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; - descDepth.SampleDesc.Count = 1; - descDepth.SampleDesc.Quality = 0; - descDepth.Usage = D3D11_USAGE_DEFAULT; - descDepth.BindFlags = D3D11_BIND_DEPTH_STENCIL; - descDepth.CPUAccessFlags = 0; - descDepth.MiscFlags = 0; - hr = g_pd3dDevice->CreateTexture2D(&descDepth, NULL, &g_pDepthStencilBuffer); - - D3D11_DEPTH_STENCIL_VIEW_DESC descDSView; - descDSView.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; - descDSView.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; - descDSView.Texture2D.MipSlice = 0; - - hr = g_pd3dDevice->CreateDepthStencilView(g_pDepthStencilBuffer, &descDSView, &g_pDepthStencilView); - - hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView ); - pBackBuffer->Release(); - if( FAILED( hr ) ) - return hr; - - g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, g_pDepthStencilView ); - - // Setup the viewport - D3D11_VIEWPORT vp; - vp.Width = (FLOAT)width; - vp.Height = (FLOAT)height; - vp.MinDepth = 0.0f; - vp.MaxDepth = 1.0f; - vp.TopLeftX = 0; - vp.TopLeftY = 0; - g_pImmediateContext->RSSetViewports( 1, &vp ); - - RenderManager.Initialise(g_pd3dDevice, g_pSwapChain); - - return S_OK; -} - - -//-------------------------------------------------------------------------------------- -// Render the frame -//-------------------------------------------------------------------------------------- -void Render() -{ - // Just clear the backbuffer - float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; //red,green,blue,alpha - - g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetView, ClearColor ); - g_pSwapChain->Present( 0, 0 ); -} - - -//-------------------------------------------------------------------------------------- -// Clean up the objects we've created -//-------------------------------------------------------------------------------------- -void CleanupDevice() -{ - if( g_pImmediateContext ) g_pImmediateContext->ClearState(); - - if( g_pRenderTargetView ) g_pRenderTargetView->Release(); - if( g_pSwapChain ) g_pSwapChain->Release(); - if( g_pImmediateContext ) g_pImmediateContext->Release(); - if( g_pd3dDevice ) g_pd3dDevice->Release(); -} -#endif - void RegisterAwardsWithProfileManager() { @@ -689,18 +367,7 @@ void RegisterAwardsWithProfileManager() ProfileManager.RegisterAward(eAward_lionTamer, ACHIEVEMENT_50, eAwardType_Achievement); #endif -#if 0 - ProfileManager.RegisterAward(eAward_mine100Blocks, GAMER_PICTURE_GAMERPIC1, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC1,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_kill10Creepers, GAMER_PICTURE_GAMERPIC2, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC2,IDS_CONFIRM_OK); - - ProfileManager.RegisterAward(eAward_eatPorkChop, AVATARASSETAWARD_PORKCHOP_TSHIRT, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR1,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_play100Days, AVATARASSETAWARD_WATCH, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR2,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_arrowKillCreeper, AVATARASSETAWARD_CAP, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR3,IDS_CONFIRM_OK); - - ProfileManager.RegisterAward(eAward_socialPost, 0, eAwardType_Theme,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_THEME,IDS_CONFIRM_OK,THEME_NAME,THEME_FILESIZE); -#endif // Rich Presence init - number of presences, number of contexts - //printf("Rich presence strings are hard coded on PS3 for now, must change this!\n"); ProfileManager.RichPresenceInit(4,1); ProfileManager.SetRichPresenceSettingFn(SQRNetworkManager_Orbis::SetRichPresence); char *pchRichPresenceString; @@ -767,64 +434,8 @@ int main(int argc, const char *argv[] ) app.DebugPrintf("---main()\n"); OrbisInit(); - -#if 0 - // Main message loop - MSG msg = {0}; - while( WM_QUIT != msg.message ) - { - if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) - { - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } - else - { - Render(); - } - } - - return (int) msg.wParam; -#endif - static bool bTrialTimerDisplayed=true; -#ifdef MEMORY_TRACKING - ResetMem(); - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("RESETMEM start: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); -#endif - -#if 0 - // Initialize D3D - hr = InitD3D( &pDevice, &d3dpp ); - g_pD3DDevice = pDevice; - if( FAILED(hr) ) - { - app.DebugPrintf - ( "Failed initializing D3D.\n" ); - return -1; - } - - // Initialize the application, assuming sharing of the d3d interface. - hr = app.InitShared( pDevice, &d3dpp, - XuiPNGTextureLoader ); - - if ( FAILED(hr) ) - { - app.DebugPrintf - ( "Failed initializing application.\n" ); - - return -1; - } - -#endif - - - - - char *usrdirPath= getUsrDirPath(); strcpy(usrdirPath,"/app0"); @@ -839,10 +450,6 @@ int main(int argc, const char *argv[] ) app.FatalLoadError(); } -// StorageManager.SetDLCProductCode(app.GetProductCode()); -// StorageManager.SetProductUpgradeKey(app.GetUpgradeKey()); - // ProfileManager.SetServiceID(app.GetCommerceCategory()); - SceNpContentRestriction param; memset(¶m, 0x0, sizeof(param)); param.size = sizeof(param); @@ -864,8 +471,6 @@ int main(int argc, const char *argv[] ) // PEGI 7+ param.defaultAgeRestriction = 7; - - // USK 6+ strncpy(ageRestriction[0].countryCode.data, "de" , 2); ageRestriction[0].age = 6; @@ -927,27 +532,6 @@ int main(int argc, const char *argv[] ) // Initialise // //////////////// -#if 0 - // 4J Stu - XACT was creating these automatically, but we need them for QNet. The setup params - // are just copied from a sample app and may need changed for our purposes - // Start XAudio2 - hr = XAudio2Create( &g_pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR ); - if( FAILED( hr ) ) - { - app.DebugPrintf( "Initializing XAudio2 failed (err = 0x%08x)!\n", hr ); - app.FatalLoadError(); - } - - // Create an XAudio2 mastering voice (utilized by XHV2 when voice data is mixed to main speakers) - hr = g_pXAudio2->CreateMasteringVoice(&g_pXAudio2MasteringVoice, XAUDIO2_DEFAULT_CHANNELS, XAUDIO2_DEFAULT_SAMPLERATE, 0, 0, NULL); - if ( FAILED( hr ) ) - { - app.DebugPrintf( "Creating XAudio2 mastering voice failed (err = 0x%08x)!\n", hr ); - app.FatalLoadError(); - } - - -#endif app.InitTime(); NPToolkit.init(); @@ -963,13 +547,12 @@ int main(int argc, const char *argv[] ) InputManager.SetDeadzoneAndMovementRange(10000,20000,32767); // Initialise the profile manager with the game Title ID, Offer ID, a profile version number, and the number of profile values and settings - SceNpCommunicationId commsId; SceNpCommunicationSignature commsSig; ProfileManager.Initialise( &commsId, //SQRNetworkManager::GetSceNpCommsId(), &commsSig, //SQRNetworkManager::GetSceNpCommsSig(), - PROFILE_VERSION_11, + PROFILE_VERSION_12, NUM_PROFILE_VALUES, NUM_PROFILE_SETTINGS, dwProfileSettingsA, @@ -980,13 +563,9 @@ int main(int argc, const char *argv[] ) RegisterAwardsWithProfileManager(); // register the get string function with the profile lib, so it can be called within the lib - ProfileManager.SetGetStringFunc(&CConsoleMinecraftApp::GetString); ProfileManager.SetPlayerListTitleID(IDS_PLAYER_LIST_TITLE); - - - StorageManager.SetGameSaveFolderTitle((WCHAR *)app.GetString(IDS_GAMENAME)); StorageManager.SetSaveCacheFolderTitle((WCHAR *)app.GetString(IDS_SAVECACHEFILE)); StorageManager.SetOptionsFolderTitle((WCHAR *)app.GetString(IDS_OPTIONSFILE)); @@ -1003,7 +582,7 @@ int main(int argc, const char *argv[] ) byteArray baSaveThumbnail = app.getArchiveFile(L"DefaultSaveThumbnail64x64.png"); byteArray baSaveImage = app.getArchiveFile(L"DefaultSaveImage228x128.png"); - StorageManager.InitialiseProfileData(PROFILE_VERSION_11, + StorageManager.InitialiseProfileData(PROFILE_VERSION_12, NUM_PROFILE_VALUES, NUM_PROFILE_SETTINGS, dwProfileSettingsA, @@ -1023,19 +602,9 @@ int main(int argc, const char *argv[] ) assert(ret == SCE_OK); StorageManager.SetQuadrantUserIds(aUserIds); -#if 0 - // Set up the global title storage path - StorageManager.StoreTMSPathName(); - - - // set a function to be called when the ethernet is disconnected, so we can back out if required - ProfileManager.SetNotificationsCallback(&CConsoleMinecraftApp::NotificationsCallback,(LPVOID)&app); - -#endif // set a function to be called when there's a sign in change, so we can exit a level if the primary player signs out ProfileManager.SetSignInChangeCallback(&CConsoleMinecraftApp::SignInChangeCallback,(LPVOID)&app); - // Set a callback for the default player options to be set - when there is no profile data for the player StorageManager.SetDefaultOptionsCallback(&CConsoleMinecraftApp::DefaultOptionsCallback,(LPVOID)&app); StorageManager.SetOptionsDataCallback(&CConsoleMinecraftApp::OptionsDataCallback,(LPVOID)&app); @@ -1055,25 +624,7 @@ int main(int argc, const char *argv[] ) // debug switch to trial version ProfileManager.SetDebugFullOverride(true); -#if 0 - //ProfileManager.AddDLC(2); - StorageManager.SetDLCPackageRoot("DLCDrive"); - StorageManager.RegisterMarketplaceCountsCallback(&CConsoleMinecraftApp::MarketplaceCountsCallback,(LPVOID)&app); - // Kinect ! - - if(XNuiGetHardwareStatus()!=0) - { - // If the Kinect Sensor is not physically connected, this function returns 0. - NuiInitialize(NUI_INITIALIZE_FLAG_USES_HIGH_QUALITY_COLOR | NUI_INITIALIZE_FLAG_USES_DEPTH | - 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 ); - } - - // Sentient ! - hr = TelemetryManager->Init(); - - -#endif // Initialise TLS for tesselator, for this main thread Tesselator::CreateNewThreadStorage(1024*1024); // Initialise TLS for AABB and Vec3 pools, for this main thread @@ -1108,86 +659,18 @@ int main(int argc, const char *argv[] ) // 4J-PB - have to hide the auto splashscreen, or we never see our game sceSystemServiceHideSplashScreen(); - -#if 0 - //bool bDisplayPauseMenu=false; - - // set the default gamma level - float fVal=50.0f*327.68f; - RenderManager.UpdateGamma((unsigned short)fVal); - - // load any skins - //app.AddSkinsToMemoryTextureFiles(); -#endif // set the default profile values for(int i=0;iInitialise(); - - // Update the base scene quick selects now that the minecraft class exists - //CXuiSceneBase::UpdateScreenSettings(0); -#endif app.InitialiseTips(); -#if 0 - DWORD initData=0; +#ifdef _TEMPORARY_CREATE_GAME + app.TemporaryCreateGameStart(); - - -#ifndef _FINAL_BUILD -#ifndef _DEBUG - #pragma message(__LOC__"Need to define the _FINAL_BUILD before submission") -#endif -#endif - - // Set the default sound levels - pMinecraft->options->set(Options::Option::MUSIC,1.0f); - pMinecraft->options->set(Options::Option::SOUND,1.0f); - - app.NavigateToScene(XUSER_INDEX_ANY,eUIScene_Intro,&initData); -#endif - //app.TemporaryCreateGameStart(); - - //Sleep(10000); -#if 0 - // Intro loop ? - while(app.IntroRunning()) - { - ProfileManager.Tick(); - // Tick XUI - app.RunFrame(); - - // 4J : WESTY : Added to ensure we always have clear background for intro. - RenderManager.SetClearColour(D3DCOLOR_RGBA(0,0,0,255)); - RenderManager.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // Render XUI - hr = app.Render(); - - // Present the frame. - RenderManager.Present(); - - // Update XUI Timers - hr = XuiTimersRun(); - } + Sleep(10000); #endif // 4J-PB - Moved here because it crashed when the network init was called if left where it was before. @@ -1200,15 +683,7 @@ int main(int argc, const char *argv[] ) { SonyVoiceChat_Orbis::tick(); RenderManager.StartFrame(); -#if 0 - if(pMinecraft->soundEngine->isStreamingWavebankReady() && - !pMinecraft->soundEngine->isPlayingStreamingGameMusic() && - !pMinecraft->soundEngine->isPlayingStreamingCDMusic() ) - { - // play some music in the menus - pMinecraft->soundEngine->playStreaming(L"", 0, 0, 0, 0, 0, false); - } -#endif + app.UpdateTime(); PIXBeginNamedEvent(0,"Input manager tick"); InputManager.Tick(); @@ -1223,18 +698,6 @@ int main(int argc, const char *argv[] ) RenderManager.Tick(); PIXEndNamedEvent(); - // Tick the social networking manager. - PIXBeginNamedEvent(0,"Social network manager tick"); -// CSocialManager::Instance()->Tick(); - PIXEndNamedEvent(); - - // Tick sentient. - PIXBeginNamedEvent(0,"Sentient tick"); - MemSect(37); -// SentientManager.Tick(); - MemSect(0); - PIXEndNamedEvent(); - PIXBeginNamedEvent(0,"Network manager do work #1"); g_NetworkManager.DoWork(); PIXEndNamedEvent(); @@ -1267,80 +730,9 @@ int main(int argc, const char *argv[] ) g_NetworkManager.Initialise(); } -#ifdef MEMORY_TRACKING - static bool bResetMemTrack = false; - static bool bDumpMemTrack = false; - - MemPixStuff(); - - if( bResetMemTrack ) - { - ResetMem(); - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("RESETMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); - bResetMemTrack = false; - } - - if( bDumpMemTrack ) - { - DumpMem(); - bDumpMemTrack = false; - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("DUMPMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); - printf("Renderer used: %d\n",RenderManager.CBuffSize(-1)); - } -#endif -#if 0 - static bool bDumpTextureUsage = false; - if( bDumpTextureUsage ) - { - RenderManager.TextureGetStats(); - bDumpTextureUsage = false; - } -#endif ui.tick(); ui.render(); -#if 0 - app.HandleButtonPresses(); - // store the minecraft renderstates, and re-set them after the xui render - GetRenderAndSamplerStates(pDevice,RenderStateA,SamplerStateA); - - // Tick XUI - PIXBeginNamedEvent(0,"Xui running"); - app.RunFrame(); - PIXEndNamedEvent(); - - // Render XUI - - PIXBeginNamedEvent(0,"XUI render"); - MemSect(7); - hr = app.Render(); - MemSect(0); - GetRenderAndSamplerStates(pDevice,RenderStateA2,SamplerStateA2); - PIXEndNamedEvent(); - - for(int i=0;i<8;i++) - { - if(RenderStateA2[i]!=RenderStateA[i]) - { - //printf("Reseting RenderStateA[%d] after a XUI render\n",i); - pDevice->SetRenderState(RenderStateModes[i],RenderStateA[i]); - } - } - for(int i=0;i<5;i++) - { - if(SamplerStateA2[i]!=SamplerStateA[i]) - { - //printf("Reseting SamplerStateA[%d] after a XUI render\n",i); - pDevice->SetSamplerState(0,SamplerStateModes[i],SamplerStateA[i]); - } - } - - RenderManager.Set_matrixDirty(); -#endif // Present the frame. RenderManager.Present(); @@ -1406,17 +798,8 @@ int main(int argc, const char *argv[] ) g_NetworkManager.DoWork(); PIXEndNamedEvent(); -#if 0 - PIXBeginNamedEvent(0,"Misc extra xui"); - // Update XUI Timers - hr = XuiTimersRun(); - -#endif // Any threading type things to deal with from the xui side? app.HandleXuiActions(); -#if 0 - PIXEndNamedEvent(); -#endif // 4J-PB - Update the trial timer display if we are in the trial version if(!ProfileManager.IsFullVersion()) @@ -1453,10 +836,6 @@ int main(int argc, const char *argv[] ) // A memory leak was caused because the icon renderer kept creating new Vec3's because the pool wasn't reset Vec3::resetPool(); } - - // Free resources, unregister custom classes, and exit. -// app.Uninit(); -// g_pd3dDevice->Release(); } @@ -1504,195 +883,3 @@ void FreeRichPresenceStrings() } vRichPresenceStrings.clear(); } - - -#ifdef MEMORY_TRACKING - -int totalAllocGen = 0; -unordered_map allocCounts; -bool trackEnable = false; -bool trackStarted = false; -volatile size_t sizeCheckMin = 1160; -volatile size_t sizeCheckMax = 1160; -volatile int sectCheck = 48; -CRITICAL_SECTION memCS; -DWORD tlsIdx; - -LPVOID XMemAlloc(SIZE_T dwSize, DWORD dwAllocAttributes) -{ - if( !trackStarted ) - { - void *p = XMemAllocDefault(dwSize,dwAllocAttributes); - size_t realSize = XMemSizeDefault(p, dwAllocAttributes); - totalAllocGen += realSize; - return p; - } - - EnterCriticalSection(&memCS); - - void *p=XMemAllocDefault(dwSize + 16,dwAllocAttributes); - size_t realSize = XMemSizeDefault(p,dwAllocAttributes) - 16; - - if( trackEnable ) - { -#if 1 - int sect = ((int) TlsGetValue(tlsIdx)) & 0x3f; - *(((unsigned char *)p)+realSize) = sect; - - if( ( realSize >= sizeCheckMin ) && ( realSize <= sizeCheckMax ) && ( ( sect == sectCheck ) || ( sectCheck == -1 ) ) ) - { - app.DebugPrintf("Found one\n"); - } -#endif - - if( p ) - { - totalAllocGen += realSize; - trackEnable = false; - int key = ( sect << 26 ) | realSize; - int oldCount = allocCounts[key]; - allocCounts[key] = oldCount + 1; - - trackEnable = true; - } - } - - LeaveCriticalSection(&memCS); - - return p; -} - -void* operator new (size_t size) -{ - return (unsigned char *)XMemAlloc(size,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); -} - -void operator delete (void *p) -{ - XMemFree(p,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); -} - -void WINAPI XMemFree(PVOID pAddress, DWORD dwAllocAttributes) -{ - bool special = false; - if( dwAllocAttributes == 0 ) - { - dwAllocAttributes = MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP); - special = true; - } - if(!trackStarted ) - { - size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes); - XMemFreeDefault(pAddress, dwAllocAttributes); - totalAllocGen -= realSize; - return; - } - EnterCriticalSection(&memCS); - if( pAddress ) - { - size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes) - 16; - - if(trackEnable) - { - int sect = *(((unsigned char *)pAddress)+realSize); - totalAllocGen -= realSize; - trackEnable = false; - int key = ( sect << 26 ) | realSize; - int oldCount = allocCounts[key]; - allocCounts[key] = oldCount - 1; - trackEnable = true; - - } - XMemFreeDefault(pAddress, dwAllocAttributes); - } - LeaveCriticalSection(&memCS); -} - -SIZE_T WINAPI XMemSize( - PVOID pAddress, - DWORD dwAllocAttributes -) -{ - if( trackStarted ) - { - return XMemSizeDefault(pAddress, dwAllocAttributes) - 16; - } - else - { - return XMemSizeDefault(pAddress, dwAllocAttributes); - } -} - - -void DumpMem() -{ - int totalLeak = 0; - for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ ) - { - if(it->second > 0 ) - { - app.DebugPrintf("%d %d %d %d\n",( it->first >> 26 ) & 0x3f,it->first & 0x03ffffff, it->second, (it->first & 0x03ffffff) * it->second); - totalLeak += ( it->first & 0x03ffffff ) * it->second; - } - } - app.DebugPrintf("Total %d\n",totalLeak); -} - -void ResetMem() -{ - if( !trackStarted ) - { - trackEnable = true; - trackStarted = true; - totalAllocGen = 0; - InitializeCriticalSection(&memCS); - tlsIdx = TlsAlloc(); - } - EnterCriticalSection(&memCS); - trackEnable = false; - allocCounts.clear(); - trackEnable = true; - LeaveCriticalSection(&memCS); -} - -void MemSect(int section) -{ - unsigned int value = (unsigned int)TlsGetValue(tlsIdx); - if( section == 0 ) // pop - { - value = (value >> 6) & 0x03ffffff; - } - else - { - value = (value << 6) | section; - } - TlsSetValue(tlsIdx, (LPVOID)value); -} - -void MemPixStuff() -{ - const int MAX_SECT = 46; - - int totals[MAX_SECT] = {0}; - - for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ ) - { - if(it->second > 0 ) - { - int sect = ( it->first >> 26 ) & 0x3f; - int bytes = it->first & 0x03ffffff; - totals[sect] += bytes * it->second; - } - } - - unsigned int allSectsTotal = 0; - for( int i = 0; i < MAX_SECT; i++ ) - { - allSectsTotal += totals[i]; - PIXAddNamedCounter(((float)totals[i])/1024.0f,"MemSect%d",i); - } - - PIXAddNamedCounter(((float)allSectsTotal)/(4096.0f),"MemSect total pages"); -} - -#endif diff --git a/Minecraft.Client/PS3/PS3_Minecraft.cpp b/Minecraft.Client/PS3/PS3_Minecraft.cpp index 784c8d64..548f96b1 100644 --- a/Minecraft.Client/PS3/PS3_Minecraft.cpp +++ b/Minecraft.Client/PS3/PS3_Minecraft.cpp @@ -3,8 +3,6 @@ #include "stdafx.h" -#ifdef __PS3__ - #include SYS_PROCESS_PARAM(1001, 0x10000); // thread priority, and stack size @@ -79,10 +77,6 @@ char secureFileId[CELL_SAVEDATA_SECUREFILEID_SIZE] = #include "..\..\Minecraft.World\ThreadName.h" #include "..\..\Minecraft.Client\StatsCounter.h" #include "..\ConnectScreen.h" -//#include "Social\SocialManager.h" -//#include "Leaderboards\LeaderboardManager.h" -//#include "XUI\XUI_Scene_Container.h" -//#include "NetworkManager.h" #include "..\..\Minecraft.Client\Tesselator.h" #include "..\Common\Console_Awards_enum.h" #include "..\..\Minecraft.Client\Options.h" @@ -99,26 +93,13 @@ char secureFileId[CELL_SAVEDATA_SECUREFILEID_SIZE] = #include -#define THEME_NAME "584111F70AAAAAAA" -#define THEME_FILESIZE 2797568 - - #define FIFTY_ONE_MB (1000000*51) // Maximum TCR space required for a save is 52MB (checking for this on a selected device) -//#define PROFILE_VERSION 3 // new version for the interim bug fix 166 TU #define NUM_PROFILE_VALUES 5 #define NUM_PROFILE_SETTINGS 4 DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]= { -#ifdef _XBOX - XPROFILE_OPTION_CONTROLLER_VIBRATION, - XPROFILE_GAMER_YAXIS_INVERSION, - XPROFILE_GAMER_CONTROL_SENSITIVITY, - XPROFILE_GAMER_ACTION_MOVEMENT_CONTROL, - XPROFILE_TITLE_SPECIFIC1, -#else 0,0,0,0,0 -#endif }; // functions for storing and converting rich presence strings from wchar to utf8 @@ -341,50 +322,11 @@ void DefineActions(void) InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN); } - -//#define MEMORY_TRACKING - -#ifdef MEMORY_TRACKING -void ResetMem(); -void DumpMem(); -void MemPixStuff(); -#else void MemSect(int sect) { } -#endif - -ID3D11Device* g_pd3dDevice = NULL; -ID3D11DeviceContext* g_pImmediateContext = NULL; -IDXGISwapChain* g_pSwapChain = NULL; -bool g_bBootedFromInvite = false; - -//-------------------------------------------------------------------------------------- -// Create Direct3D device and swap chain -//-------------------------------------------------------------------------------------- -HRESULT InitDevice() -{ - - - return S_OK; -} - -//-------------------------------------------------------------------------------------- -// Render the frame -//-------------------------------------------------------------------------------------- -void Render() -{ - -} - -//-------------------------------------------------------------------------------------- -// Clean up the objects we've created -//-------------------------------------------------------------------------------------- -void CleanupDevice() -{ - -} +bool g_bBootedFromInvite = false; // simple function to load a file completely into memory static void * load_file( char const * name ) @@ -414,8 +356,6 @@ static void * load_file( char const * name ) return ret; } - - void debugSaveGameDirect() { @@ -506,16 +446,6 @@ void RegisterAwardsWithProfileManager() ProfileManager.RegisterAward(eAward_lionTamer, ACHIEVEMENT_50, eAwardType_Achievement); #endif -#if 0 - ProfileManager.RegisterAward(eAward_mine100Blocks, GAMER_PICTURE_GAMERPIC1, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC1,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_kill10Creepers, GAMER_PICTURE_GAMERPIC2, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC2,IDS_CONFIRM_OK); - - ProfileManager.RegisterAward(eAward_eatPorkChop, AVATARASSETAWARD_PORKCHOP_TSHIRT, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR1,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_play100Days, AVATARASSETAWARD_WATCH, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR2,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_arrowKillCreeper, AVATARASSETAWARD_CAP, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR3,IDS_CONFIRM_OK); - - ProfileManager.RegisterAward(eAward_socialPost, 0, eAwardType_Theme,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_THEME,IDS_CONFIRM_OK,THEME_NAME,THEME_FILESIZE); -#endif // Rich Presence init - number of presences, number of contexts //printf("Rich presence strings are hard coded on PS3 for now, must change this!\n"); ProfileManager.RichPresenceInit(-1,-1); // 4J-JEV - Presence and Context count not used. @@ -864,29 +794,8 @@ int main() // Initialise // //////////////// -#if 0 - // 4J Stu - XACT was creating these automatically, but we need them for QNet. The setup params - // are just copied from a sample app and may need changed for our purposes - // Start XAudio2 - hr = XAudio2Create( &g_pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR ); - if( FAILED( hr ) ) - { - app.DebugPrintf( "Initializing XAudio2 failed (err = 0x%08x)!\n", hr ); - app.FatalLoadError(); - } - - // Create an XAudio2 mastering voice (utilized by XHV2 when voice data is mixed to main speakers) - hr = g_pXAudio2->CreateMasteringVoice(&g_pXAudio2MasteringVoice, XAUDIO2_DEFAULT_CHANNELS, XAUDIO2_DEFAULT_SAMPLERATE, 0, 0, NULL); - if ( FAILED( hr ) ) - { - app.DebugPrintf( "Creating XAudio2 mastering voice failed (err = 0x%08x)!\n", hr ); - app.FatalLoadError(); - } -#endif - app.InitTime(); - // Initialise the profile manager with the game Title ID, Offer ID, a profile version number, and the number of profile values and settings ProfileManager.Initialise(SQRNetworkManager_PS3::GetSceNpCommsId(), SQRNetworkManager_PS3::GetSceNpCommsSig(), @@ -911,41 +820,13 @@ int main() // initialise the storage manager with a callback for displaying the saving message StorageManager.Init(0,app.GetString(IDS_DEFAULT_SAVENAME),"savegame.dat",FIFTY_ONE_MB,&CConsoleMinecraftApp::DisplaySavingMessage,(LPVOID)&app,""); -#if 0 - - // Set up the global title storage path - StorageManager.StoreTMSPathName(); -#endif - - // MGH - I've had to rearrange some of the ordering here, as I was getting conflicts with the sysutils for trophies and the upgrade key - - //app.FatalLoadError(); - - // set a function to be called when there's a sign in change, so we can exit a level if the primary player signs out ProfileManager.SetSignInChangeCallback(&CConsoleMinecraftApp::SignInChangeCallback,(LPVOID)&app); -#if 0 - // set a function to be called when the ethernet is disconnected, so we can back out if required - ProfileManager.SetNotificationsCallback(&CConsoleMinecraftApp::NotificationsCallback,(LPVOID)&app); -#endif // Set a callback for the default player options to be set - when there is no profile data for the player - StorageManager.SetDefaultOptionsCallback(&CConsoleMinecraftApp::DefaultOptionsCallback,(LPVOID)&app); StorageManager.SetOptionsDataCallback(&CConsoleMinecraftApp::OptionsDataCallback,(LPVOID)&app); - // Set a callback to deal with old profile versions needing updated to new versions -#if 0 - ProfileManager.SetOldProfileVersionCallback(&CConsoleMinecraftApp::OldProfileVersionCallback,(LPVOID)&app); - - // Set a callback for when there is a read error on profile data - ProfileManager.SetProfileReadErrorCallback(&CConsoleMinecraftApp::ProfileReadErrorCallback,(LPVOID)&app); - - // QNet needs to be setup after profile manager, as we do not want its Notify listener to handle - // XN_SYS_SIGNINCHANGED notifications. This does mean that we need to have a callback in the - // ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet. -#endif // 0 - SonyRemoteStorage_PS3* pRemote = (SonyRemoteStorage_PS3*)app.getRemoteStorage(); pRemote->SetSecureID(secureFileId); pRemote->SetServiceID(app.GetCommerceCategory()); @@ -1068,27 +949,6 @@ int main() InputManager.SetLostInputControlCallback(&UIController::SetSystemUIShowing,&ui); - -#ifndef _FINAL_BUILD -#ifndef _DEBUG - #pragma message(__LOC__"Need to define the _FINAL_BUILD before submission") -#endif -#endif - - - -#if 0 - - DWORD initData=0; - // Set the default sound levels - pMinecraft->options->set(Options::Option::MUSIC,1.0f); - pMinecraft->options->set(Options::Option::SOUND,1.0f); - - app.NavigateToScene(XUSER_INDEX_ANY,eUIScene_Intro,&initData); -#endif - - - //LeaderboardManager::Instance()->OpenSession(); //LeaderboardManager::Instance()->ReadStats_TopRank(DebugReadListener::m_instance, 0, LeaderboardManager::eStatsType_Travelling, 1, 1); @@ -1152,15 +1012,6 @@ int main() while( ShutdownManager::ShouldRun(ShutdownManager::eMainThread) ) { -#if 0 - if(pMinecraft->soundEngine->isStreamingWavebankReady() && - !pMinecraft->soundEngine->isPlayingStreamingGameMusic() && - !pMinecraft->soundEngine->isPlayingStreamingCDMusic() ) - { - // play some music in the menus - pMinecraft->soundEngine->playStreaming(L"", 0, 0, 0, 0, 0, false); - } -#endif app.UpdateTime(); PIXBeginNamedEvent(0,"Input manager tick"); InputManager.Tick(); @@ -1226,39 +1077,6 @@ int main() pMinecraft->soundEngine->playMusicTick(); -#ifdef MEMORY_TRACKING - static bool bResetMemTrack = false; - static bool bDumpMemTrack = false; - - MemPixStuff(); - - if( bResetMemTrack ) - { - ResetMem(); - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("RESETMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); - bResetMemTrack = false; - } - - if( bDumpMemTrack ) - { - DumpMem(); - bDumpMemTrack = false; - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("DUMPMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); - printf("Renderer used: %d\n",RenderManager.CBuffSize(-1)); - } -#endif -#if 0 - static bool bDumpTextureUsage = false; - if( bDumpTextureUsage ) - { - RenderManager.TextureGetStats(); - bDumpTextureUsage = false; - } -#endif ui.tick(); ui.render(); @@ -1315,27 +1133,10 @@ int main() } PIXEndNamedEvent(); -#if 0 - app.TickDLCOffersRetrieved(); - app.TickTMSPPFilesRetrieved(); -#endif - PIXBeginNamedEvent(0,"Network manager do work #2"); g_NetworkManager.DoWork(); PIXEndNamedEvent(); -#if 0 - PIXBeginNamedEvent(0,"Misc extra xui"); - // Update XUI Timers - hr = XuiTimersRun(); -#endif - // Any threading type things to deal with from the xui side? - app.HandleXuiActions(); - -#if 0 - PIXEndNamedEvent(); -#endif - // 4J-PB - Update the trial timer display if we are in the trial version if(!ProfileManager.IsFullVersion()) { @@ -1399,196 +1200,4 @@ void FreeRichPresenceStrings() free(strUtf8); } vRichPresenceStrings.clear(); -} - - -#ifdef MEMORY_TRACKING - -int totalAllocGen = 0; -unordered_map allocCounts; -bool trackEnable = false; -bool trackStarted = false; -volatile size_t sizeCheckMin = 1160; -volatile size_t sizeCheckMax = 1160; -volatile int sectCheck = 48; -CRITICAL_SECTION memCS; -DWORD tlsIdx; - -LPVOID XMemAlloc(SIZE_T dwSize, DWORD dwAllocAttributes) -{ - if( !trackStarted ) - { - void *p = XMemAllocDefault(dwSize,dwAllocAttributes); - size_t realSize = XMemSizeDefault(p, dwAllocAttributes); - totalAllocGen += realSize; - return p; - } - - EnterCriticalSection(&memCS); - - void *p=XMemAllocDefault(dwSize + 16,dwAllocAttributes); - size_t realSize = XMemSizeDefault(p,dwAllocAttributes) - 16; - - if( trackEnable ) - { -#if 1 - int sect = ((int) TlsGetValue(tlsIdx)) & 0x3f; - *(((unsigned char *)p)+realSize) = sect; - - if( ( realSize >= sizeCheckMin ) && ( realSize <= sizeCheckMax ) && ( ( sect == sectCheck ) || ( sectCheck == -1 ) ) ) - { - app.DebugPrintf("Found one\n"); - } -#endif - - if( p ) - { - totalAllocGen += realSize; - trackEnable = false; - int key = ( sect << 26 ) | realSize; - int oldCount = allocCounts[key]; - allocCounts[key] = oldCount + 1; - - trackEnable = true; - } - } - - LeaveCriticalSection(&memCS); - - return p; -} - -void* operator new (size_t size) -{ - return (unsigned char *)XMemAlloc(size,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); -} - -void operator delete (void *p) -{ - XMemFree(p,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); -} - -void WINAPI XMemFree(PVOID pAddress, DWORD dwAllocAttributes) -{ - bool special = false; - if( dwAllocAttributes == 0 ) - { - dwAllocAttributes = MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP); - special = true; - } - if(!trackStarted ) - { - size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes); - XMemFreeDefault(pAddress, dwAllocAttributes); - totalAllocGen -= realSize; - return; - } - EnterCriticalSection(&memCS); - if( pAddress ) - { - size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes) - 16; - - if(trackEnable) - { - int sect = *(((unsigned char *)pAddress)+realSize); - totalAllocGen -= realSize; - trackEnable = false; - int key = ( sect << 26 ) | realSize; - int oldCount = allocCounts[key]; - allocCounts[key] = oldCount - 1; - trackEnable = true; - } - XMemFreeDefault(pAddress, dwAllocAttributes); - } - LeaveCriticalSection(&memCS); -} - -SIZE_T WINAPI XMemSize( - PVOID pAddress, - DWORD dwAllocAttributes -) -{ - if( trackStarted ) - { - return XMemSizeDefault(pAddress, dwAllocAttributes) - 16; - } - else - { - return XMemSizeDefault(pAddress, dwAllocAttributes); - } -} - -void DumpMem() -{ - int totalLeak = 0; - for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ ) - { - if(it->second > 0 ) - { - app.DebugPrintf("%d %d %d %d\n",( it->first >> 26 ) & 0x3f,it->first & 0x03ffffff, it->second, (it->first & 0x03ffffff) * it->second); - totalLeak += ( it->first & 0x03ffffff ) * it->second; - } - } - app.DebugPrintf("Total %d\n",totalLeak); -} - -void ResetMem() -{ - if( !trackStarted ) - { - trackEnable = true; - trackStarted = true; - totalAllocGen = 0; - InitializeCriticalSection(&memCS); - tlsIdx = TlsAlloc(); - } - EnterCriticalSection(&memCS); - trackEnable = false; - allocCounts.clear(); - trackEnable = true; - LeaveCriticalSection(&memCS); -} - -void MemSect(int section) -{ - unsigned int value = (unsigned int)TlsGetValue(tlsIdx); - if( section == 0 ) // pop - { - value = (value >> 6) & 0x03ffffff; - } - else - { - value = (value << 6) | section; - } - TlsSetValue(tlsIdx, (LPVOID)value); -} - -void MemPixStuff() -{ - const int MAX_SECT = 46; - - int totals[MAX_SECT] = {0}; - - for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ ) - { - if(it->second > 0 ) - { - int sect = ( it->first >> 26 ) & 0x3f; - int bytes = it->first & 0x03ffffff; - totals[sect] += bytes * it->second; - } - } - - unsigned int allSectsTotal = 0; - for( int i = 0; i < MAX_SECT; i++ ) - { - allSectsTotal += totals[i]; - PIXAddNamedCounter(((float)totals[i])/1024.0f,"MemSect%d",i); - } - - PIXAddNamedCounter(((float)allSectsTotal)/(4096.0f),"MemSect total pages"); -} - -#endif - -#endif // __PS3__ \ No newline at end of file +} \ No newline at end of file diff --git a/Minecraft.Client/PS3/Xbox_Minecraft.cpp b/Minecraft.Client/PS3/Xbox_Minecraft.cpp deleted file mode 100644 index f52fb9c8..00000000 --- a/Minecraft.Client/PS3/Xbox_Minecraft.cpp +++ /dev/null @@ -1,1192 +0,0 @@ -// Minecraft.cpp : Defines the entry point for the application. -// - -#include "stdafx.h" - -#include -#include "strings.h" -#include "4J_strings.h" -#include "Minecraft_Controller_Actions.h" -#include "Xbox_App.h" -#include "GameConfig\Minecraft.spa.h" -#include "..\MinecraftServer.h" -#include "..\LocalPlayer.h" -#include "..\..\Minecraft.World\ItemInstance.h" -#include "..\..\Minecraft.World\MapItem.h" -#include "..\..\Minecraft.World\Recipes.h" -#include "..\..\Minecraft.World\Recipy.h" -#include "..\..\Minecraft.World\Language.h" -#include "..\..\Minecraft.World\StringHelpers.h" -#include "..\..\Minecraft.World\AABB.h" -#include "..\..\Minecraft.World\Vec3.h" -#include "..\..\Minecraft.World\Level.h" - -#include "..\ClientConnection.h" -#include "..\User.h" -#include "..\..\Minecraft.World\Socket.h" -#include "..\..\Minecraft.World\ThreadName.h" -#include "..\..\Minecraft.Client\StatsCounter.h" -#include "..\ConnectScreen.h" -//#include "Social\SocialManager.h" -//#include "Leaderboards\LeaderboardManager.h" -//#include "XUI\XUI_Scene_Container.h" -//#include "QNetManager.h" -#include "..\..\Minecraft.Client\Tesselator.h" -#include "Xbox_Awards_enum.h" -#include "..\..\Minecraft.Client\Options.h" -#include "Sentient\SentientManager.h" -#include "..\..\Minecraft.World\IntCache.h" -#include "..\Textures.h" -#include "Resource.h" - - -#define THEME_NAME "584111F70AAAAAAA" -#define THEME_FILESIZE 2797568 - -//#define THREE_MB 3145728 // minimum save size (checking for this on a selected device) -//#define FIVE_MB 5242880 // minimum save size (checking for this on a selected device) -//#define FIFTY_TWO_MB (1024*1024*52) // Maximum TCR space required for a save (checking for this on a selected device) -#define FIFTY_ONE_MB (1000000*51) // Maximum TCR space required for a save is 52MB (checking for this on a selected device) - -#if 0 -//#define PROFILE_VERSION 3 // new version for the interim bug fix 166 TU -#define NUM_PROFILE_VALUES 5 -#define NUM_PROFILE_SETTINGS 4 -DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]= -{ - XPROFILE_OPTION_CONTROLLER_VIBRATION, - XPROFILE_GAMER_YAXIS_INVERSION, - XPROFILE_GAMER_CONTROL_SENSITIVITY, - XPROFILE_GAMER_ACTION_MOVEMENT_CONTROL, - XPROFILE_TITLE_SPECIFIC1, -}; -#endif - -//------------------------------------------------------------------------------------- -// Time Since fAppTime is a float, we need to keep the quadword app time -// as a LARGE_INTEGER so that we don't lose precision after running -// for a long time. -//------------------------------------------------------------------------------------- - - -BOOL g_bWidescreen = TRUE; - - -void DefineActions(void) -{ -#if 0 - // The app needs to define the actions required, and the possible mappings for these - - // Split into Menu actions, and in-game actions - - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_A, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_B, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_X, _360_JOY_BUTTON_X); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_Y, _360_JOY_BUTTON_Y); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_OK, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_LT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB); - - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_LT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_RT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_RB); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_LB); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_RTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_LTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK); - - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_LEFT, _360_JOY_BUTTON_DPAD_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_UP, _360_JOY_BUTTON_DPAD_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_0,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN); - - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_A, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_B, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_X, _360_JOY_BUTTON_X); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_Y, _360_JOY_BUTTON_Y); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_OK, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_LB); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB); - - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_RB); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_RT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_LT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_DPAD_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_DPAD_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_LTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_RTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_1,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK); - - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_A, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_B, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_X, _360_JOY_BUTTON_X); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_Y, _360_JOY_BUTTON_Y); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_OK, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_CANCEL, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_UP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_DOWN, _360_JOY_BUTTON_DPAD_DOWN | _360_JOY_BUTTON_LSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_LEFT, _360_JOY_BUTTON_DPAD_LEFT | _360_JOY_BUTTON_LSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_RIGHT, _360_JOY_BUTTON_DPAD_RIGHT | _360_JOY_BUTTON_LSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAGEUP, _360_JOY_BUTTON_DPAD_UP | _360_JOY_BUTTON_LB); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_PAGEDOWN, _360_JOY_BUTTON_RT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_RIGHT_SCROLL, _360_JOY_BUTTON_RB); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,ACTION_MENU_LEFT_SCROLL, _360_JOY_BUTTON_LB); - - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_JUMP, _360_JOY_BUTTON_LT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_FORWARD, _360_JOY_BUTTON_LSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_BACKWARD, _360_JOY_BUTTON_LSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LEFT, _360_JOY_BUTTON_LSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RIGHT, _360_JOY_BUTTON_LSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_LEFT, _360_JOY_BUTTON_RSTICK_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_RIGHT, _360_JOY_BUTTON_RSTICK_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_UP, _360_JOY_BUTTON_RSTICK_UP); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LOOK_DOWN, _360_JOY_BUTTON_RSTICK_DOWN); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_USE, _360_JOY_BUTTON_RT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_ACTION, _360_JOY_BUTTON_A); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RIGHT_SCROLL, _360_JOY_BUTTON_DPAD_RIGHT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_LEFT_SCROLL, _360_JOY_BUTTON_DPAD_LEFT); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_INVENTORY, _360_JOY_BUTTON_Y); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_PAUSEMENU, _360_JOY_BUTTON_START); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DROP, _360_JOY_BUTTON_B); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_SNEAK_TOGGLE, _360_JOY_BUTTON_LB); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_CRAFTING, _360_JOY_BUTTON_X); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_RENDER_THIRD_PERSON, _360_JOY_BUTTON_LTHUMB); - InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_GAME_INFO, _360_JOY_BUTTON_BACK); -#endif -} - -#if 0 -HRESULT InitD3D( IDirect3DDevice9 **ppDevice, - D3DPRESENT_PARAMETERS *pd3dPP ) -{ - IDirect3D9 *pD3D; - - pD3D = Direct3DCreate9( D3D_SDK_VERSION ); - - // Set up the structure used to create the D3DDevice - // Using a permanent 1280x720 backbuffer now no matter what the actual video resolution.right Have also disabled letterboxing, - // which would letterbox a 1280x720 output if it detected a 4:3 video source - we're doing an anamorphic squash in this - // mode so don't need this functionality. - - ZeroMemory( pd3dPP, sizeof(D3DPRESENT_PARAMETERS) ); - XVIDEO_MODE VideoMode; - XGetVideoMode( &VideoMode ); - g_bWidescreen = VideoMode.fIsWideScreen; - pd3dPP->BackBufferWidth = 1280; - pd3dPP->BackBufferHeight = 720; - pd3dPP->BackBufferFormat = D3DFMT_A8R8G8B8; - pd3dPP->BackBufferCount = 1; - pd3dPP->EnableAutoDepthStencil = TRUE; - pd3dPP->AutoDepthStencilFormat = D3DFMT_D24S8; - pd3dPP->SwapEffect = D3DSWAPEFFECT_DISCARD; - pd3dPP->PresentationInterval = D3DPRESENT_INTERVAL_ONE; - //pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX; - //ERR[D3D]: Can't set D3DPRESENTFLAG_NO_LETTERBOX when wide-screen is enabled - // in the launcher/dashboard. - if(g_bWidescreen) - pd3dPP->Flags=0; - else - pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX; - - // Create the device. - return pD3D->CreateDevice( - 0, - D3DDEVTYPE_HAL, - NULL, - D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_BUFFER_2_FRAMES, - pd3dPP, - ppDevice ); -} -#endif -//#define MEMORY_TRACKING - -#ifdef MEMORY_TRACKING -void ResetMem(); -void DumpMem(); -void MemPixStuff(); -#else -void MemSect(int sect) -{ -} -#endif - -HINSTANCE g_hInst = NULL; -HWND g_hWnd = NULL; -D3D_DRIVER_TYPE g_driverType = D3D_DRIVER_TYPE_NULL; -D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0; -ID3D11Device* g_pd3dDevice = NULL; -ID3D11DeviceContext* g_pImmediateContext = NULL; -IDXGISwapChain* g_pSwapChain = NULL; -ID3D11RenderTargetView* g_pRenderTargetView = NULL; - -// -// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) -// -// PURPOSE: Processes messages for the main window. -// -// WM_COMMAND - process the application menu -// WM_PAINT - Paint the main window -// WM_DESTROY - post a quit message and return -// -// -LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - int wmId, wmEvent; - PAINTSTRUCT ps; - HDC hdc; - - switch (message) - { - case WM_COMMAND: - wmId = LOWORD(wParam); - wmEvent = HIWORD(wParam); - // Parse the menu selections: - switch (wmId) - { - case IDM_EXIT: - DestroyWindow(hWnd); - break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - break; - case WM_PAINT: - hdc = BeginPaint(hWnd, &ps); - // TODO: Add any drawing code here... - EndPaint(hWnd, &ps); - break; - case WM_DESTROY: - PostQuitMessage(0); - break; - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - return 0; -} - - -// -// FUNCTION: MyRegisterClass() -// -// PURPOSE: Registers the window class. -// -ATOM MyRegisterClass(HINSTANCE hInstance) -{ - WNDCLASSEX wcex; - - wcex.cbSize = sizeof(WNDCLASSEX); - - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = WndProc; - wcex.cbClsExtra = 0; - wcex.cbWndExtra = 0; - wcex.hInstance = hInstance; - wcex.hIcon = LoadIcon(hInstance, "Minecraft"); - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); - wcex.lpszMenuName = "Minecraft"; - wcex.lpszClassName = "MinecraftClass"; - wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); - - return RegisterClassEx(&wcex); -} - -// -// FUNCTION: InitInstance(HINSTANCE, int) -// -// PURPOSE: Saves instance handle and creates main window -// -// COMMENTS: -// -// In this function, we save the instance handle in a global variable and -// create and display the main program window. -// -BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) -{ - g_hInst = hInstance; // Store instance handle in our global variable - - g_hWnd = CreateWindow("MinecraftClass", "Minecraft", WS_OVERLAPPEDWINDOW, - CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); - - if (!g_hWnd) - { - return FALSE; - } - - ShowWindow(g_hWnd, nCmdShow); - UpdateWindow(g_hWnd); - - return TRUE; -} - - -//-------------------------------------------------------------------------------------- -// Create Direct3D device and swap chain -//-------------------------------------------------------------------------------------- -HRESULT InitDevice() -{ - HRESULT hr = S_OK; - - RECT rc; - GetClientRect( g_hWnd, &rc ); - UINT width = rc.right - rc.left; - UINT height = rc.bottom - rc.top; - - UINT createDeviceFlags = 0; -#ifdef _DEBUG - createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; -#endif - - D3D_DRIVER_TYPE driverTypes[] = - { - D3D_DRIVER_TYPE_HARDWARE, - D3D_DRIVER_TYPE_WARP, - D3D_DRIVER_TYPE_REFERENCE, - }; - UINT numDriverTypes = ARRAYSIZE( driverTypes ); - - D3D_FEATURE_LEVEL featureLevels[] = - { - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, - D3D_FEATURE_LEVEL_10_0, - }; - UINT numFeatureLevels = ARRAYSIZE( featureLevels ); - - DXGI_SWAP_CHAIN_DESC sd; - ZeroMemory( &sd, sizeof( sd ) ); - sd.BufferCount = 1; - sd.BufferDesc.Width = width; - sd.BufferDesc.Height = height; - sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - sd.BufferDesc.RefreshRate.Numerator = 60; - sd.BufferDesc.RefreshRate.Denominator = 1; - sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - sd.OutputWindow = g_hWnd; - sd.SampleDesc.Count = 1; - sd.SampleDesc.Quality = 0; - sd.Windowed = TRUE; - - for( UINT driverTypeIndex = 0; driverTypeIndex < numDriverTypes; driverTypeIndex++ ) - { - g_driverType = driverTypes[driverTypeIndex]; - hr = D3D11CreateDeviceAndSwapChain( NULL, g_driverType, NULL, createDeviceFlags, featureLevels, numFeatureLevels, - D3D11_SDK_VERSION, &sd, &g_pSwapChain, &g_pd3dDevice, &g_featureLevel, &g_pImmediateContext ); - if( SUCCEEDED( hr ) ) - break; - } - if( FAILED( hr ) ) - return hr; - - // Create a render target view - ID3D11Texture2D* pBackBuffer = NULL; - hr = g_pSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), ( LPVOID* )&pBackBuffer ); - if( FAILED( hr ) ) - return hr; - - hr = g_pd3dDevice->CreateRenderTargetView( pBackBuffer, NULL, &g_pRenderTargetView ); - pBackBuffer->Release(); - if( FAILED( hr ) ) - return hr; - - g_pImmediateContext->OMSetRenderTargets( 1, &g_pRenderTargetView, NULL ); - - // Setup the viewport - D3D11_VIEWPORT vp; - vp.Width = (FLOAT)width; - vp.Height = (FLOAT)height; - vp.MinDepth = 0.0f; - vp.MaxDepth = 1.0f; - vp.TopLeftX = 0; - vp.TopLeftY = 0; - g_pImmediateContext->RSSetViewports( 1, &vp ); - - RenderManager.Initialise(g_pd3dDevice, g_pSwapChain); - - return S_OK; -} - - -//-------------------------------------------------------------------------------------- -// Render the frame -//-------------------------------------------------------------------------------------- -void Render() -{ - // Just clear the backbuffer - float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; //red,green,blue,alpha - - g_pImmediateContext->ClearRenderTargetView( g_pRenderTargetView, ClearColor ); - g_pSwapChain->Present( 0, 0 ); -} - - -//-------------------------------------------------------------------------------------- -// Clean up the objects we've created -//-------------------------------------------------------------------------------------- -void CleanupDevice() -{ - if( g_pImmediateContext ) g_pImmediateContext->ClearState(); - - if( g_pRenderTargetView ) g_pRenderTargetView->Release(); - if( g_pSwapChain ) g_pSwapChain->Release(); - if( g_pImmediateContext ) g_pImmediateContext->Release(); - if( g_pd3dDevice ) g_pd3dDevice->Release(); -} - -int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, - _In_opt_ HINSTANCE hPrevInstance, - _In_ LPTSTR lpCmdLine, - _In_ int nCmdShow) -{ - UNREFERENCED_PARAMETER(hPrevInstance); - UNREFERENCED_PARAMETER(lpCmdLine); - - // Initialize global strings - MyRegisterClass(hInstance); - - // Perform application initialization: - if (!InitInstance (hInstance, nCmdShow)) - { - return FALSE; - } - - if( FAILED( InitDevice() ) ) - { - CleanupDevice(); - return 0; - } - -#if 0 - // Main message loop - MSG msg = {0}; - while( WM_QUIT != msg.message ) - { - if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) - { - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } - else - { - Render(); - } - } - - return (int) msg.wParam; -#endif - - static bool bTrialTimerDisplayed=true; - -#ifdef MEMORY_TRACKING - ResetMem(); - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("RESETMEM start: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); -#endif - -#if 0 - // Initialize D3D - hr = InitD3D( &pDevice, &d3dpp ); - g_pD3DDevice = pDevice; - if( FAILED(hr) ) - { - app.DebugPrintf - ( "Failed initializing D3D.\n" ); - return -1; - } - - // Initialize the application, assuming sharing of the d3d interface. - hr = app.InitShared( pDevice, &d3dpp, - XuiPNGTextureLoader ); - - if ( FAILED(hr) ) - { - app.DebugPrintf - ( "Failed initializing application.\n" ); - - return -1; - } - - -#endif - RenderManager.Initialise(g_pd3dDevice, g_pSwapChain); - - //////////////// - // Initialise // - //////////////// - -#if 0 - // 4J Stu - XACT was creating these automatically, but we need them for QNet. The setup params - // are just copied from a sample app and may need changed for our purposes - // Start XAudio2 - hr = XAudio2Create( &g_pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR ); - if( FAILED( hr ) ) - { - app.DebugPrintf( "Initializing XAudio2 failed (err = 0x%08x)!\n", hr ); - app.FatalLoadError(); - } - - // Create an XAudio2 mastering voice (utilized by XHV2 when voice data is mixed to main speakers) - hr = g_pXAudio2->CreateMasteringVoice(&g_pXAudio2MasteringVoice, XAUDIO2_DEFAULT_CHANNELS, XAUDIO2_DEFAULT_SAMPLERATE, 0, 0, NULL); - if ( FAILED( hr ) ) - { - app.DebugPrintf( "Creating XAudio2 mastering voice failed (err = 0x%08x)!\n", hr ); - app.FatalLoadError(); - } - - app.InitTime(); - - // Set the number of possible joypad layouts that the user can switch between, and the number of actions - InputManager.Initialise(1,3,64); - - // Set the default joypad action mappings for Minecraft - DefineActions(); - InputManager.SetJoypadMapVal(0,0); - InputManager.SetKeyRepeatRate(0.3f,0.2f); - - - // Initialise the profile manager with the game Title ID, Offer ID, a profile version number, and the number of profile values and settings - ProfileManager.Initialise(TITLEID_MINECRAFT, - app.m_dwOfferID, - PROFILE_VERSION_BUILD_TU7, - NUM_PROFILE_VALUES, - NUM_PROFILE_SETTINGS, - dwProfileSettingsA, - app.GAME_DEFINED_PROFILE_DATA_BYTES*XUSER_MAX_COUNT, - &app.uiGameDefinedDataChangedBitmask - ); - - // register the awards - ProfileManager.RegisterAward(eAward_TakingInventory, ACHIEVEMENT_01, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_GettingWood, ACHIEVEMENT_02, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_Benchmarking, ACHIEVEMENT_03, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_TimeToMine, ACHIEVEMENT_04, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_HotTopic, ACHIEVEMENT_05, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_AquireHardware, ACHIEVEMENT_06, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_TimeToFarm, ACHIEVEMENT_07, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_BakeBread, ACHIEVEMENT_08, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_TheLie, ACHIEVEMENT_09, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_GettingAnUpgrade, ACHIEVEMENT_10, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_DeliciousFish, ACHIEVEMENT_11, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_OnARail, ACHIEVEMENT_12, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_TimeToStrike, ACHIEVEMENT_13, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_MonsterHunter, ACHIEVEMENT_14, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_CowTipper, ACHIEVEMENT_15, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_WhenPigsFly, ACHIEVEMENT_16, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_LeaderOfThePack, ACHIEVEMENT_17, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_MOARTools, ACHIEVEMENT_18, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_DispenseWithThis, ACHIEVEMENT_19, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_InToTheNether, ACHIEVEMENT_20, eAwardType_Achievement); - - ProfileManager.RegisterAward(eAward_mine100Blocks, GAMER_PICTURE_GAMERPIC1, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC1,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_kill10Creepers, GAMER_PICTURE_GAMERPIC2, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC2,IDS_CONFIRM_OK); - - ProfileManager.RegisterAward(eAward_eatPorkChop, AVATARASSETAWARD_PORKCHOP_TSHIRT, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR1,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_play100Days, AVATARASSETAWARD_WATCH, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR2,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_arrowKillCreeper, AVATARASSETAWARD_CAP, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR3,IDS_CONFIRM_OK); - - ProfileManager.RegisterAward(eAward_socialPost, 0, eAwardType_Theme,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_THEME,IDS_CONFIRM_OK,THEME_NAME,THEME_FILESIZE); - - // Rich Presence init - number of presences, number of contexts - ProfileManager.RichPresenceInit(4,1); - ProfileManager.RegisterRichPresenceContext(CONTEXT_GAME_STATE); - - app.LoadXuiResources(); - - // initialise the storage manager with a default save display name, a Minimum save size, and a callback for displaying the saving message - StorageManager.Init(app.GetString(IDS_DEFAULT_SAVENAME),"savegame.dat",FIFTY_ONE_MB,&CXboxMinecraftApp::DisplaySavingMessage,(LPVOID)&app); - // Set up the global title storage path - StorageManager.StoreTMSPathName(); - - // set a function to be called when there's a sign in change, so we can exit a level if the primary player signs out - ProfileManager.SetSignInChangeCallback(&CXboxMinecraftApp::SignInChangeCallback,(LPVOID)&app); - - // set a function to be called when the ethernet is disconnected, so we can back out if required - ProfileManager.SetNotificationsCallback(&CXboxMinecraftApp::NotificationsCallback,(LPVOID)&app); - - // Set a callback for the default player options to be set - when there is no profile data for the player - ProfileManager.SetDefaultOptionsCallback(&CXboxMinecraftApp::DefaultOptionsCallback,(LPVOID)&app); - // Set a callback to deal with old profile versions needing updated to new versions - ProfileManager.SetOldProfileVersionCallback(&CXboxMinecraftApp::OldProfileVersionCallback,(LPVOID)&app); - - // Set a callback for when there is a read error on profile data - ProfileManager.SetProfileReadErrorCallback(&CXboxMinecraftApp::ProfileReadErrorCallback,(LPVOID)&app); - - - // QNet needs to be setup after profile manager, as we do not want its Notify listener to handle - // XN_SYS_SIGNINCHANGED notifications. This does mean that we need to have a callback in the - // ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet. - g_qNetManager.Initialise(); - - app.InitGameSettings(); - - // debug switch to trial version - ProfileManager.SetDebugFullOverride(true); - - //ProfileManager.AddDLC(2); - StorageManager.SetDLCPackageRoot("DLCDrive"); - StorageManager.RegisterMarketplaceCountsCallback(&CXboxMinecraftApp::MarketplaceCountsCallback,(LPVOID)&app); - // Kinect ! - - if(XNuiGetHardwareStatus()!=0) - { - // If the Kinect Sensor is not physically connected, this function returns 0. - NuiInitialize(NUI_INITIALIZE_FLAG_USES_HIGH_QUALITY_COLOR | NUI_INITIALIZE_FLAG_USES_DEPTH | - 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 ); - } - - // Sentient ! - hr = SentientManager.Init(); - - -#endif - // Initialise TLS for tesselator, for this main thread - Tesselator::CreateNewThreadStorage(1024*1024); - // Initialise TLS for AABB and Vec3 pools, for this main thread - AABB::CreateNewThreadStorage(); - Vec3::CreateNewThreadStorage(); - IntCache::CreateNewThreadStorage(); - Level::enableLightingCache(); - - - Minecraft::main(); - Minecraft *pMinecraft=Minecraft::GetInstance(); -#if 0 - //bool bDisplayPauseMenu=false; - - // set the default gamma level - float fVal=50.0f*327.68f; - RenderManager.UpdateGamma((unsigned short)fVal); - - // load any skins - //app.AddSkinsToMemoryTextureFiles(); - - // set the achievement text for a trial achievement, now we have the string table loaded - ProfileManager.SetTrialTextStringTable(app.GetStringTable(),IDS_CONFIRM_OK, IDS_CONFIRM_CANCEL); - ProfileManager.SetTrialAwardText(eAwardType_Achievement,IDS_UNLOCK_TITLE,IDS_UNLOCK_ACHIEVEMENT_TEXT); - ProfileManager.SetTrialAwardText(eAwardType_GamerPic,IDS_UNLOCK_TITLE,IDS_UNLOCK_GAMERPIC_TEXT); - ProfileManager.SetTrialAwardText(eAwardType_AvatarItem,IDS_UNLOCK_TITLE,IDS_UNLOCK_AVATAR_TEXT); - ProfileManager.SetTrialAwardText(eAwardType_Theme,IDS_UNLOCK_TITLE,IDS_UNLOCK_THEME_TEXT); - ProfileManager.SetUpsellCallback(&app.UpsellReturnedCallback,&app); - - // Set up a debug character press sequence -#ifndef _FINAL_BUILD - app.SetDebugSequence("LRLRYYY"); -#endif - - // Initialise the social networking manager. - CSocialManager::Instance()->Initialise(); - - // Update the base scene quick selects now that the minecraft class exists - //CXuiSceneBase::UpdateScreenSettings(0); - - app.InitialiseTips(); - - DWORD initData=0; - - - -#ifndef _FINAL_BUILD -#ifndef _DEBUG - #pragma message(__LOC__"Need to define the _FINAL_BUILD before submission") -#endif -#endif - - pMinecraft->soundEngine->init(NULL); - // Set the default sound levels - pMinecraft->options->set(Options::Option::MUSIC,1.0f); - pMinecraft->options->set(Options::Option::SOUND,1.0f); - - app.NavigateToScene(XUSER_INDEX_ANY,CXboxMinecraftApp::e_xuiScene_Intro,&initData); -#endif - - //Sleep(10000); -#if 0 - // Intro loop ? - while(app.IntroRunning()) - { - ProfileManager.Tick(); - // Tick XUI - app.RunFrame(); - - // 4J : WESTY : Added to ensure we always have clear background for intro. - RenderManager.SetClearColour(D3DCOLOR_RGBA(0,0,0,255)); - RenderManager.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // Render XUI - hr = app.Render(); - - // Present the frame. - RenderManager.Present(); - - // Update XUI Timers - hr = XuiTimersRun(); - } -#endif - - while( TRUE ) - { -#if 0 - if(pMinecraft->soundEngine->isStreamingWavebankReady() && - !pMinecraft->soundEngine->isPlayingStreamingGameMusic() && - !pMinecraft->soundEngine->isPlayingStreamingCDMusic() ) - { - // play some music in the menus - pMinecraft->soundEngine->playStreaming(L"", 0, 0, 0, 0, 0, false); - } -#endif - app.UpdateTime(); - PIXBeginNamedEvent(0,"Input manager tick"); -// InputManager.Tick(); - PIXEndNamedEvent(); - PIXBeginNamedEvent(0,"Profile manager tick"); -// ProfileManager.Tick(); - PIXEndNamedEvent(); - PIXBeginNamedEvent(0,"Storage manager tick"); -// StorageManager.Tick(); - PIXEndNamedEvent(); - PIXBeginNamedEvent(0,"Render manager tick"); - RenderManager.Tick(); - PIXEndNamedEvent(); - - // Tick the social networking manager. - PIXBeginNamedEvent(0,"Social network manager tick"); -// CSocialManager::Instance()->Tick(); - PIXEndNamedEvent(); - - // Tick sentient. - PIXBeginNamedEvent(0,"Sentient tick"); - MemSect(37); -// SentientManager.Tick(); - MemSect(0); - PIXEndNamedEvent(); - - PIXBeginNamedEvent(0,"Qnet do work #1"); -// g_qNetManager.DoWork(); - PIXEndNamedEvent(); - -// LeaderboardManager::Instance()->Tick(); - // Render game graphics. - if(app.GetGameStarted()) - { - pMinecraft->run_middle(); - app.SetAppPaused( g_qNetManager.IsLocalGame() && g_qNetManager.GetPlayerCount() == 1 && app.IsPauseMenuDisplayed(ProfileManager.GetPrimaryPad()) ); - } - else - { - MemSect(28); - pMinecraft->soundEngine->update(NULL, 0.0f); - MemSect(0); - pMinecraft->soundEngine->playMusicTick(); - pMinecraft->textures->tick(true,false); - IntCache::Reset(); - app.SetGameStarted(true); - } - - app.ToggleDimensionIfRequested(); - - -#ifdef MEMORY_TRACKING - static bool bResetMemTrack = false; - static bool bDumpMemTrack = false; - - MemPixStuff(); - - if( bResetMemTrack ) - { - ResetMem(); - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("RESETMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); - bResetMemTrack = false; - } - - if( bDumpMemTrack ) - { - DumpMem(); - bDumpMemTrack = false; - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("DUMPMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); - printf("Renderer used: %d\n",RenderManager.CBuffSize(-1)); - } -#endif -#if 0 - static bool bDumpTextureUsage = false; - if( bDumpTextureUsage ) - { - RenderManager.TextureGetStats(); - bDumpTextureUsage = false; - } -#endif - -#if 0 - app.HandleButtonPresses(); - - // store the minecraft renderstates, and re-set them after the xui render - GetRenderAndSamplerStates(pDevice,RenderStateA,SamplerStateA); - - // Tick XUI - PIXBeginNamedEvent(0,"Xui running"); - app.RunFrame(); - PIXEndNamedEvent(); - - // Render XUI - - PIXBeginNamedEvent(0,"XUI render"); - MemSect(7); - hr = app.Render(); - MemSect(0); - GetRenderAndSamplerStates(pDevice,RenderStateA2,SamplerStateA2); - PIXEndNamedEvent(); - - for(int i=0;i<8;i++) - { - if(RenderStateA2[i]!=RenderStateA[i]) - { - //printf("Reseting RenderStateA[%d] after a XUI render\n",i); - pDevice->SetRenderState(RenderStateModes[i],RenderStateA[i]); - } - } - for(int i=0;i<5;i++) - { - if(SamplerStateA2[i]!=SamplerStateA[i]) - { - //printf("Reseting SamplerStateA[%d] after a XUI render\n",i); - pDevice->SetSamplerState(0,SamplerStateModes[i],SamplerStateA[i]); - } - } - - RenderManager.Set_matrixDirty(); -#endif - // Present the frame. - PIXBeginNamedEvent(0,"Frame present"); - RenderManager.Present(); - PIXEndNamedEvent(); -#if 0 - app.CheckMenuDisplayed(); - PIXBeginNamedEvent(0,"Profile load check"); - // has the game defined profile data been changed (by a profile load) - if(app.uiGameDefinedDataChangedBitmask!=0) - { - void *pData; - for(int i=0;istats[ i ]->clear(); - pMinecraft->stats[i]->parse(pData); - } - } - - // Check to see if we can post to social networks. - CSocialManager::Instance()->RefreshPostingCapability(); - - // clear the flag - app.uiGameDefinedDataChangedBitmask=0; - - // Check if any profile write are needed - app.CheckGameSettingsChanged(); - - } - PIXEndNamedEvent(); - app.TickDLCOffersRetrieved(); - app.TickTMSImagesRetrieved(); - - PIXBeginNamedEvent(0,"Qnet do work #2"); - g_qNetManager.DoWork(); - PIXEndNamedEvent(); - - PIXBeginNamedEvent(0,"Misc extra xui"); - // Update XUI Timers - hr = XuiTimersRun(); - - // Any threading type things to deal with from the xui side? - app.HandleXuiActions(); - PIXEndNamedEvent(); - - // 4J-PB - Update the trial timer display if we are in the trial version - if(!ProfileManager.IsFullVersion()) - { - // display the trial timer - if(app.GetGameStarted()) - { - // 4J-PB - if the game is paused, add the elapsed time to the trial timer count so it doesn't tick down - if(app.IsAppPaused()) - { - app.UpdateTrialPausedTimer(); - } - CXuiSceneBase::UpdateTrialTimer(ProfileManager.GetPrimaryPad()); - } - } - else - { - // need to turn off the trial timer if it was on , and we've unlocked the full version - if(bTrialTimerDisplayed) - { - CXuiSceneBase::ShowTrialTimer(FALSE); - bTrialTimerDisplayed=false; - } - } -#endif - - // Fix for #7318 - Title crashes after short soak in the leaderboards menu - // A memory leak was caused because the icon renderer kept creating new Vec3's because the pool wasn't reset - Vec3::resetPool(); - } - - // Free resources, unregister custom classes, and exit. -// app.Uninit(); - g_pd3dDevice->Release(); -} - - -#ifdef MEMORY_TRACKING - -int totalAllocGen = 0; -unordered_map allocCounts; -bool trackEnable = false; -bool trackStarted = false; -volatile size_t sizeCheckMin = 1160; -volatile size_t sizeCheckMax = 1160; -volatile int sectCheck = 48; -CRITICAL_SECTION memCS; -DWORD tlsIdx; - -LPVOID XMemAlloc(SIZE_T dwSize, DWORD dwAllocAttributes) -{ - if( !trackStarted ) - { - void *p = XMemAllocDefault(dwSize,dwAllocAttributes); - size_t realSize = XMemSizeDefault(p, dwAllocAttributes); - totalAllocGen += realSize; - return p; - } - - EnterCriticalSection(&memCS); - - void *p=XMemAllocDefault(dwSize + 16,dwAllocAttributes); - size_t realSize = XMemSizeDefault(p,dwAllocAttributes) - 16; - - if( trackEnable ) - { -#if 1 - int sect = ((int) TlsGetValue(tlsIdx)) & 0x3f; - *(((unsigned char *)p)+realSize) = sect; - - if( ( realSize >= sizeCheckMin ) && ( realSize <= sizeCheckMax ) && ( ( sect == sectCheck ) || ( sectCheck == -1 ) ) ) - { - app.DebugPrintf("Found one\n"); - } -#endif - - if( p ) - { - totalAllocGen += realSize; - trackEnable = false; - int key = ( sect << 26 ) | realSize; - int oldCount = allocCounts[key]; - allocCounts[key] = oldCount + 1; - - trackEnable = true; - } - } - - LeaveCriticalSection(&memCS); - - return p; -} - -void* operator new (size_t size) -{ - return (unsigned char *)XMemAlloc(size,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); -} - -void operator delete (void *p) -{ - XMemFree(p,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); -} - -void WINAPI XMemFree(PVOID pAddress, DWORD dwAllocAttributes) -{ - bool special = false; - if( dwAllocAttributes == 0 ) - { - dwAllocAttributes = MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP); - special = true; - } - if(!trackStarted ) - { - size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes); - XMemFreeDefault(pAddress, dwAllocAttributes); - totalAllocGen -= realSize; - return; - } - EnterCriticalSection(&memCS); - if( pAddress ) - { - size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes) - 16; - - if(trackEnable) - { - int sect = *(((unsigned char *)pAddress)+realSize); - totalAllocGen -= realSize; - trackEnable = false; - int key = ( sect << 26 ) | realSize; - int oldCount = allocCounts[key]; - allocCounts[key] = oldCount - 1; - trackEnable = true; - - } - XMemFreeDefault(pAddress, dwAllocAttributes); - } - LeaveCriticalSection(&memCS); -} - -SIZE_T WINAPI XMemSize( - PVOID pAddress, - DWORD dwAllocAttributes -) -{ - if( trackStarted ) - { - return XMemSizeDefault(pAddress, dwAllocAttributes) - 16; - } - else - { - return XMemSizeDefault(pAddress, dwAllocAttributes); - } -} - - -void DumpMem() -{ - int totalLeak = 0; - for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ ) - { - if(it->second > 0 ) - { - app.DebugPrintf("%d %d %d %d\n",( it->first >> 26 ) & 0x3f,it->first & 0x03ffffff, it->second, (it->first & 0x03ffffff) * it->second); - totalLeak += ( it->first & 0x03ffffff ) * it->second; - } - } - app.DebugPrintf("Total %d\n",totalLeak); -} - -void ResetMem() -{ - if( !trackStarted ) - { - trackEnable = true; - trackStarted = true; - totalAllocGen = 0; - InitializeCriticalSection(&memCS); - tlsIdx = TlsAlloc(); - } - EnterCriticalSection(&memCS); - trackEnable = false; - allocCounts.clear(); - trackEnable = true; - LeaveCriticalSection(&memCS); -} - -void MemSect(int section) -{ - unsigned int value = (unsigned int)TlsGetValue(tlsIdx); - if( section == 0 ) // pop - { - value = (value >> 6) & 0x03ffffff; - } - else - { - value = (value << 6) | section; - } - TlsSetValue(tlsIdx, (LPVOID)value); -} - -void MemPixStuff() -{ - const int MAX_SECT = 46; - - int totals[MAX_SECT] = {0}; - - for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ ) - { - if(it->second > 0 ) - { - int sect = ( it->first >> 26 ) & 0x3f; - int bytes = it->first & 0x03ffffff; - totals[sect] += bytes * it->second; - } - } - - unsigned int allSectsTotal = 0; - for( int i = 0; i < MAX_SECT; i++ ) - { - allSectsTotal += totals[i]; - PIXAddNamedCounter(((float)totals[i])/1024.0f,"MemSect%d",i); - } - - PIXAddNamedCounter(((float)allSectsTotal)/(4096.0f),"MemSect total pages"); -} - -#endif diff --git a/Minecraft.Client/PSVita/PSVita_Minecraft.cpp b/Minecraft.Client/PSVita/PSVita_Minecraft.cpp index 7edc1687..d428e762 100644 --- a/Minecraft.Client/PSVita/PSVita_Minecraft.cpp +++ b/Minecraft.Client/PSVita/PSVita_Minecraft.cpp @@ -6,17 +6,6 @@ #include "Leaderboards\PSVitaLeaderboardManager.h" #include "PSVita\PSVitaExtras\ShutdownManager.h" -//#define HEAPINSPECTOR_PS3 1 -// when defining HEAPINSPECTOR_PS3, add this line to the linker settings -// --wrap malloc --wrap free --wrap memalign --wrap calloc --wrap realloc --wrap reallocalign --wrap _malloc_init - -#if HEAPINSPECTOR_PS3 -#include "HeapInspector\Server\HeapInspectorServer.h" -#include "HeapInspector\Server\PS3\HeapHooks.hpp" -#endif - -//#define DISABLE_MILES_SOUND - #include "PSVita_App.h" #include "PSVitaExtras\PSVitaStrings.h" #include "GameConfig\Minecraft.spa.h" @@ -39,20 +28,14 @@ #include "..\..\Minecraft.World\ThreadName.h" #include "..\..\Minecraft.Client\StatsCounter.h" #include "..\ConnectScreen.h" -//#include "Social\SocialManager.h" -//#include "Leaderboards\LeaderboardManager.h" -//#include "XUI\XUI_Scene_Container.h" -//#include "NetworkManager.h" #include "..\..\Minecraft.Client\Tesselator.h" #include "..\Common\Console_Awards_enum.h" #include "..\..\Minecraft.Client\Options.h" #include "Sentient\SentientManager.h" #include "..\..\Minecraft.World\IntCache.h" #include "..\Textures.h" -//#include "Resource.h" #include "..\..\Minecraft.World\compression.h" #include "..\..\Minecraft.World\OldChunkStorage.h" -//#include "PS3\PS3Extras\EdgeZLib.h" #include "..\..\Minecraft.World\C4JThread.h" #include "Common\Network\Sony\SQRNetworkManager.h" #include "Common\UI\IUIScene_PauseMenu.h" @@ -66,64 +49,19 @@ #include #include -#define THEME_NAME "584111F70AAAAAAA" -#define THEME_FILESIZE 2797568 - -/* Encrypted ID for protected data file (*) You must edit these binaries!! */ -/*char secureFileId[CELL_SAVEDATA_SECUREFILEID_SIZE] = -{ -0xEE, 0xA9, 0x37, 0xCC, -0x5B, 0xD4, 0xD9, 0x0D, -0x55, 0xED, 0x25, 0x31, -0xFA, 0x33, 0xBD, 0xC4 -};*/ - - #define FIFTY_ONE_MB (1000000*51) // Maximum TCR space required for a save is 52MB (checking for this on a selected device) -//#define PROFILE_VERSION 3 // new version for the interim bug fix 166 TU #define NUM_PROFILE_VALUES 5 #define NUM_PROFILE_SETTINGS 4 DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]= { -#ifdef _XBOX - XPROFILE_OPTION_CONTROLLER_VIBRATION, - XPROFILE_GAMER_YAXIS_INVERSION, - XPROFILE_GAMER_CONTROL_SENSITIVITY, - XPROFILE_GAMER_ACTION_MOVEMENT_CONTROL, - XPROFILE_TITLE_SPECIFIC1, -#else 0,0,0,0,0 -#endif }; // functions for storing and converting rich presence strings from wchar to utf8 uint8_t * AddRichPresenceString(int iID); void FreeRichPresenceStrings(); -#if HEAPINSPECTOR_PS3 - -std::vector GetHeapInfo() -{ - std::vector result = HeapInspectorServer::GetDefaultHeapInfo(); - HeapInspectorServer::HeapInfo localHeapInfo; - localHeapInfo.m_Description = "VRAM"; - localHeapInfo.m_Range.m_Min = 0xc0000000; - localHeapInfo.m_Range.m_Max = localHeapInfo.m_Range.m_Min + (249*1024*1024); - result.push_back(localHeapInfo); - return result; -} - -extern "C" void* __real__malloc_init(size_t a_Boundary, size_t a_Size); -extern "C" void* __wrap__malloc_init(size_t a_Boundary, size_t a_Size) -{ - void* result = __real__malloc_init(a_Boundary, a_Size); - HeapInspectorServer::Initialise(GetHeapInfo(), 3000, HeapInspectorServer::WaitForConnection_Enabled); - return result; -} - -#endif // HEAPINSPECTOR_PS3 - //------------------------------------------------------------------------------------- // Time Since fAppTime is a float, we need to keep the quadword app time // as a LARGE_INTEGER so that we don't lose precision after running @@ -361,16 +299,6 @@ void RegisterAwardsWithProfileManager() ProfileManager.RegisterAward(eAward_lionTamer, ACHIEVEMENT_50, eAwardType_Achievement); #endif -#if 0 - ProfileManager.RegisterAward(eAward_mine100Blocks, GAMER_PICTURE_GAMERPIC1, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC1,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_kill10Creepers, GAMER_PICTURE_GAMERPIC2, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC2,IDS_CONFIRM_OK); - - ProfileManager.RegisterAward(eAward_eatPorkChop, AVATARASSETAWARD_PORKCHOP_TSHIRT, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR1,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_play100Days, AVATARASSETAWARD_WATCH, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR2,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_arrowKillCreeper, AVATARASSETAWARD_CAP, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR3,IDS_CONFIRM_OK); - - ProfileManager.RegisterAward(eAward_socialPost, 0, eAwardType_Theme,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_THEME,IDS_CONFIRM_OK,THEME_NAME,THEME_FILESIZE); -#endif // Rich Presence init - number of presences, number of contexts //printf("Rich presence strings are hard coded on PS3 for now, must change this!\n"); ProfileManager.RichPresenceInit(4,1); @@ -630,17 +558,8 @@ int main() StorageManager.SetIncompleteSaveCallback(CConsoleMinecraftApp::Callback_SaveGameIncomplete, (LPVOID)&app); -#if 0 - // Set up the global title storage path - StorageManager.StoreTMSPathName(); -#endif - // set a function to be called when there's a sign in change, so we can exit a level if the primary player signs out ProfileManager.SetSignInChangeCallback(&CConsoleMinecraftApp::SignInChangeCallback,(LPVOID)&app); -#if 0 - // set a function to be called when the ethernet is disconnected, so we can back out if required - ProfileManager.SetNotificationsCallback(&CConsoleMinecraftApp::NotificationsCallback,(LPVOID)&app); -#endif // Set a callback for the default player options to be set - when there is no profile data for the player StorageManager.SetDefaultOptionsCallback(&CConsoleMinecraftApp::DefaultOptionsCallback,(LPVOID)&app); @@ -649,39 +568,18 @@ int main() // Set a callback to deal with old profile versions needing updated to new versions StorageManager.SetOldProfileVersionCallback(&CConsoleMinecraftApp::OldProfileVersionCallback,(LPVOID)&app); -#if 0 - // Set a callback for when there is a read error on profile data - //StorageManager.SetProfileReadErrorCallback(&CConsoleMinecraftApp::ProfileReadErrorCallback,(LPVOID)&app); -#endif - StorageManager.SetDLCInfoMap(app.GetSonyDLCMap()); app.CommerceInit(); // MGH - moved this here so GetCommerce isn't NULL // 4J-PB - Kick of the check for trial or full version - requires ui to be initialised app.GetCommerce()->CheckForTrialUpgradeKey(); - - // debug switch to trial version //ProfileManager.SetDebugFullOverride(false); //ProfileManager.AddDLC(2); StorageManager.SetDLCPackageRoot("DLCDrive"); -#if 0 - StorageManager.RegisterMarketplaceCountsCallback(&CConsoleMinecraftApp::MarketplaceCountsCallback,(LPVOID)&app); - // Kinect ! - if(XNuiGetHardwareStatus()!=0) - { - // If the Kinect Sensor is not physically connected, this function returns 0. - NuiInitialize(NUI_INITIALIZE_FLAG_USES_HIGH_QUALITY_COLOR | NUI_INITIALIZE_FLAG_USES_DEPTH | - 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 ); - } - - // Sentient ! - hr = SentientManager.Init(); - -#endif // Initialise TLS for tesselator, for this main thread Tesselator::CreateNewThreadStorage(1024*1024); // Initialise TLS for AABB and Vec3 pools, for this main thread @@ -729,22 +627,6 @@ int main() //CXuiSceneBase::UpdateScreenSettings(0); //#endif app.InitialiseTips(); -#if 0 - - DWORD initData=0; - -#ifndef _FINAL_BUILD -#ifndef _DEBUG -#pragma message(__LOC__"Need to define the _FINAL_BUILD before submission") -#endif -#endif - - // Set the default sound levels - pMinecraft->options->set(Options::Option::MUSIC,1.0f); - pMinecraft->options->set(Options::Option::SOUND,1.0f); - - app.NavigateToScene(XUSER_INDEX_ANY,eUIScene_Intro,&initData); -#endif // wait for the trophy init to complete - nonblocking semaphore while(( !ProfileManager.AreTrophiesInstalled() ) && ShutdownManager::ShouldRun(ShutdownManager::eMainThread)) @@ -769,45 +651,17 @@ int main() // read the options here for controller 0 - this won't actually be actioned until a storagemanager tick later StorageManager.ReadFromProfile(0); - //app.TemporaryCreateGameStart(); +#ifdef _TEMPORARY_CREATE_GAME + app.TemporaryCreateGameStart(); - //Sleep(10000); -#if 0 - // Intro loop ? - while(app.IntroRunning()) - { - ProfileManager.Tick(); - // Tick XUI - app.RunFrame(); - - // 4J : WESTY : Added to ensure we always have clear background for intro. - RenderManager.SetClearColour(D3DCOLOR_RGBA(0,0,0,255)); - RenderManager.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // Render XUI - hr = app.Render(); - - // Present the frame. - RenderManager.Present(); - - // Update XUI Timers - hr = XuiTimersRun(); - } + Sleep(10000); #endif + while( true ) { SonyVoiceChat_Vita::tick(); RenderManager.StartFrame(); -#if 0 - if(pMinecraft->soundEngine->isStreamingWavebankReady() && - !pMinecraft->soundEngine->isPlayingStreamingGameMusic() && - !pMinecraft->soundEngine->isPlayingStreamingCDMusic() ) - { - // play some music in the menus - pMinecraft->soundEngine->playStreaming(L"", 0, 0, 0, 0, 0, false); - } -#endif // static bool bPlay=false; // if(bPlay) @@ -868,81 +722,9 @@ int main() pMinecraft->soundEngine->playMusicTick(); -#ifdef MEMORY_TRACKING - static bool bResetMemTrack = false; - static bool bDumpMemTrack = false; - - - MemPixStuff(); - - if( bResetMemTrack ) - { - ResetMem(); - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("RESETMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); - bResetMemTrack = false; - } - - if( bDumpMemTrack ) - { - DumpMem(); - bDumpMemTrack = false; - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("DUMPMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); - printf("Renderer used: %d\n",RenderManager.CBuffSize(-1)); - } -#endif -#if 0 - static bool bDumpTextureUsage = false; - if( bDumpTextureUsage ) - { - RenderManager.TextureGetStats(); - bDumpTextureUsage = false; - } -#endif ui.tick(); ui.render(); -#if 0 - app.HandleButtonPresses(); - // store the minecraft renderstates, and re-set them after the xui render - GetRenderAndSamplerStates(pDevice,RenderStateA,SamplerStateA); - - // Tick XUI - PIXBeginNamedEvent(0,"Xui running"); - app.RunFrame(); - PIXEndNamedEvent(); - - // Render XUI - - PIXBeginNamedEvent(0,"XUI render"); - MemSect(7); - hr = app.Render(); - MemSect(0); - GetRenderAndSamplerStates(pDevice,RenderStateA2,SamplerStateA2); - PIXEndNamedEvent(); - - for(int i=0;i<8;i++) - { - if(RenderStateA2[i]!=RenderStateA[i]) - { - //printf("Reseting RenderStateA[%d] after a XUI render\n",i); - pDevice->SetRenderState(RenderStateModes[i],RenderStateA[i]); - } - } - for(int i=0;i<5;i++) - { - if(SamplerStateA2[i]!=SamplerStateA[i]) - { - //printf("Reseting SamplerStateA[%d] after a XUI render\n",i); - pDevice->SetSamplerState(0,SamplerStateModes[i],SamplerStateA[i]); - } - } - - RenderManager.Set_matrixDirty(); -#endif // Present the frame. RenderManager.Present(); @@ -999,19 +781,10 @@ int main() PIXBeginNamedEvent(0,"Network manager do work #2"); g_NetworkManager.DoWork(); PIXEndNamedEvent(); -#if 0 - PIXBeginNamedEvent(0,"Misc extra xui"); - // Update XUI Timers - hr = XuiTimersRun(); -#endif // #if 0 // Any threading type things to deal with from the xui side? app.HandleXuiActions(); -#if 0 - PIXEndNamedEvent(); -#endif - // 4J-PB - Update the trial timer display if we are in the trial version if(!ProfileManager.IsFullVersion()) { diff --git a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp index 50ae7763..bd6d8018 100644 --- a/Minecraft.Client/Windows64/Windows64_Minecraft.cpp +++ b/Minecraft.Client/Windows64/Windows64_Minecraft.cpp @@ -44,12 +44,8 @@ WINDOWPLACEMENT g_wpPrev = { sizeof(g_wpPrev) }; char chGlobalText[256]; uint16_t ui16GlobalText[256]; -//#define THREE_MB 3145728 // minimum save size (checking for this on a selected device) -//#define FIVE_MB 5242880 // minimum save size (checking for this on a selected device) -//#define FIFTY_TWO_MB (1024*1024*52) // Maximum TCR space required for a save (checking for this on a selected device) #define FIFTY_ONE_MB (1000000*51) // Maximum TCR space required for a save is 52MB (checking for this on a selected device) -//#define PROFILE_VERSION 3 // new version for the interim bug fix 166 TU #define NUM_PROFILE_VALUES 5 #define NUM_PROFILE_SETTINGS 4 DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]= @@ -260,61 +256,10 @@ void DefineActions(void) InputManager.SetGameJoypadMaps(MAP_STYLE_2,MINECRAFT_ACTION_DPAD_DOWN, _360_JOY_BUTTON_DPAD_DOWN); } -#if 0 -HRESULT InitD3D( IDirect3DDevice9 **ppDevice, - D3DPRESENT_PARAMETERS *pd3dPP ) -{ - IDirect3D9 *pD3D; - - pD3D = Direct3DCreate9( D3D_SDK_VERSION ); - - // Set up the structure used to create the D3DDevice - // Using a permanent 1280x720 backbuffer now no matter what the actual video resolution.right Have also disabled letterboxing, - // which would letterbox a 1280x720 output if it detected a 4:3 video source - we're doing an anamorphic squash in this - // mode so don't need this functionality. - - ZeroMemory( pd3dPP, sizeof(D3DPRESENT_PARAMETERS) ); - XVIDEO_MODE VideoMode; - XGetVideoMode( &VideoMode ); - g_bWidescreen = VideoMode.fIsWideScreen; - pd3dPP->BackBufferWidth = 1280; - pd3dPP->BackBufferHeight = 720; - pd3dPP->BackBufferFormat = D3DFMT_A8R8G8B8; - pd3dPP->BackBufferCount = 1; - pd3dPP->EnableAutoDepthStencil = TRUE; - pd3dPP->AutoDepthStencilFormat = D3DFMT_D24S8; - pd3dPP->SwapEffect = D3DSWAPEFFECT_DISCARD; - pd3dPP->PresentationInterval = D3DPRESENT_INTERVAL_ONE; - //pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX; - //ERR[D3D]: Can't set D3DPRESENTFLAG_NO_LETTERBOX when wide-screen is enabled - // in the launcher/dashboard. - if(g_bWidescreen) - pd3dPP->Flags=0; - else - pd3dPP->Flags = D3DPRESENTFLAG_NO_LETTERBOX; - - // Create the device. - return pD3D->CreateDevice( - 0, - D3DDEVTYPE_HAL, - NULL, - D3DCREATE_HARDWARE_VERTEXPROCESSING|D3DCREATE_BUFFER_2_FRAMES, - pd3dPP, - ppDevice ); -} -#endif -//#define MEMORY_TRACKING - -#ifdef MEMORY_TRACKING -void ResetMem(); -void DumpMem(); -void MemPixStuff(); -#else void MemSect(int sect) { //str1k3r - i feel like something should go here, i just dont know what } -#endif HINSTANCE g_hInst = NULL; HWND g_hWnd = NULL; @@ -339,24 +284,8 @@ ID3D11Texture2D* g_pDepthStencilBuffer = NULL; // LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { - int wmId, wmEvent; - switch (message) { - case WM_COMMAND: - wmId = LOWORD(wParam); - wmEvent = HIWORD(wParam); - // Parse the menu selections: - switch (wmId) - { - case IDM_EXIT: - DestroyWindow(hWnd); - break; - - default: - return DefWindowProc(hWnd, message, wParam, lParam); - } - break; case WM_ENTERSIZEMOVE: SetTimer(hWnd, 1, USER_TIMER_MINIMUM, NULL); break; @@ -385,7 +314,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) pMinecraft->soundEngine->tick(NULL, 0.0f); pMinecraft->soundEngine->playMusicTick(); } - break; + break; case WM_CLOSE: app.ExitGame(); break; @@ -782,58 +711,8 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, ToggleFullscreen(); } -#if 0 - // Main message loop - MSG msg = {0}; - while( WM_QUIT != msg.message ) - { - if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) - { - TranslateMessage( &msg ); - DispatchMessage( &msg ); - } - else - { - Render(); - } - } - - return (int) msg.wParam; -#endif - static bool bTrialTimerDisplayed=true; -#ifdef MEMORY_TRACKING - ResetMem(); - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("RESETMEM start: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); -#endif - -#if 0 - // Initialize D3D - hr = InitD3D( &pDevice, &d3dpp ); - g_pD3DDevice = pDevice; - if( FAILED(hr) ) - { - app.DebugPrintf - ( "Failed initializing D3D.\n" ); - return -1; - } - - // Initialize the application, assuming sharing of the d3d interface. - hr = app.InitShared( pDevice, &d3dpp, - XuiPNGTextureLoader ); - - if ( FAILED(hr) ) - { - app.DebugPrintf - ( "Failed initializing application.\n" ); - - return -1; - } - -#endif app.loadMediaArchive(); RenderManager.Initialise(g_pd3dDevice, g_pSwapChain); @@ -856,101 +735,28 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, // Initialise the profile manager with the game Title ID, Offer ID, a profile version number, and the number of profile values and settings ProfileManager.Initialise(TITLEID_MINECRAFT, app.m_dwOfferID, - PROFILE_VERSION_10, + PROFILE_VERSION_12, NUM_PROFILE_VALUES, NUM_PROFILE_SETTINGS, dwProfileSettingsA, app.GAME_DEFINED_PROFILE_DATA_BYTES*XUSER_MAX_COUNT, &app.uiGameDefinedDataChangedBitmask - ); -#if 0 - // register the awards - ProfileManager.RegisterAward(eAward_TakingInventory, ACHIEVEMENT_01, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_GettingWood, ACHIEVEMENT_02, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_Benchmarking, ACHIEVEMENT_03, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_TimeToMine, ACHIEVEMENT_04, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_HotTopic, ACHIEVEMENT_05, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_AquireHardware, ACHIEVEMENT_06, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_TimeToFarm, ACHIEVEMENT_07, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_BakeBread, ACHIEVEMENT_08, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_TheLie, ACHIEVEMENT_09, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_GettingAnUpgrade, ACHIEVEMENT_10, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_DeliciousFish, ACHIEVEMENT_11, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_OnARail, ACHIEVEMENT_12, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_TimeToStrike, ACHIEVEMENT_13, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_MonsterHunter, ACHIEVEMENT_14, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_CowTipper, ACHIEVEMENT_15, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_WhenPigsFly, ACHIEVEMENT_16, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_LeaderOfThePack, ACHIEVEMENT_17, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_MOARTools, ACHIEVEMENT_18, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_DispenseWithThis, ACHIEVEMENT_19, eAwardType_Achievement); - ProfileManager.RegisterAward(eAward_InToTheNether, ACHIEVEMENT_20, eAwardType_Achievement); - - ProfileManager.RegisterAward(eAward_mine100Blocks, GAMER_PICTURE_GAMERPIC1, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC1,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_kill10Creepers, GAMER_PICTURE_GAMERPIC2, eAwardType_GamerPic,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_GAMERPIC2,IDS_CONFIRM_OK); - - ProfileManager.RegisterAward(eAward_eatPorkChop, AVATARASSETAWARD_PORKCHOP_TSHIRT, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR1,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_play100Days, AVATARASSETAWARD_WATCH, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR2,IDS_CONFIRM_OK); - ProfileManager.RegisterAward(eAward_arrowKillCreeper, AVATARASSETAWARD_CAP, eAwardType_AvatarItem,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_AVATAR3,IDS_CONFIRM_OK); - - ProfileManager.RegisterAward(eAward_socialPost, 0, eAwardType_Theme,false,app.GetStringTable(),IDS_AWARD_TITLE,IDS_AWARD_THEME,IDS_CONFIRM_OK,THEME_NAME,THEME_FILESIZE); - - // Rich Presence init - number of presences, number of contexts - ProfileManager.RichPresenceInit(4,1); - ProfileManager.RegisterRichPresenceContext(CONTEXT_GAME_STATE); + ); // initialise the storage manager with a default save display name, a Minimum save size, and a callback for displaying the saving message - StorageManager.Init(app.GetString(IDS_DEFAULT_SAVENAME),"savegame.dat",FIFTY_ONE_MB,&CConsoleMinecraftApp::DisplaySavingMessage,(LPVOID)&app); - // Set up the global title storage path - StorageManager.StoreTMSPathName(); + StorageManager.Init(0,app.GetString(IDS_DEFAULT_SAVENAME),"savegame.dat",FIFTY_ONE_MB,&CConsoleMinecraftApp::DisplaySavingMessage,(LPVOID)&app,""); - // set a function to be called when there's a sign in change, so we can exit a level if the primary player signs out - ProfileManager.SetSignInChangeCallback(&CConsoleMinecraftApp::SignInChangeCallback,(LPVOID)&app); - - // set a function to be called when the ethernet is disconnected, so we can back out if required - ProfileManager.SetNotificationsCallback(&CConsoleMinecraftApp::NotificationsCallback,(LPVOID)&app); - -#endif // Set a callback for the default player options to be set - when there is no profile data for the player ProfileManager.SetDefaultOptionsCallback(&CConsoleMinecraftApp::DefaultOptionsCallback,(LPVOID)&app); -#if 0 - // Set a callback to deal with old profile versions needing updated to new versions - ProfileManager.SetOldProfileVersionCallback(&CConsoleMinecraftApp::OldProfileVersionCallback,(LPVOID)&app); - // Set a callback for when there is a read error on profile data - ProfileManager.SetProfileReadErrorCallback(&CConsoleMinecraftApp::ProfileReadErrorCallback,(LPVOID)&app); - -#endif // QNet needs to be setup after profile manager, as we do not want its Notify listener to handle // XN_SYS_SIGNINCHANGED notifications. This does mean that we need to have a callback in the // ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet. g_NetworkManager.Initialise(); - - - // 4J-PB moved further down - //app.InitGameSettings(); - // debug switch to trial version ProfileManager.SetDebugFullOverride(true); -#if 0 - //ProfileManager.AddDLC(2); - StorageManager.SetDLCPackageRoot("DLCDrive"); - StorageManager.RegisterMarketplaceCountsCallback(&CConsoleMinecraftApp::MarketplaceCountsCallback,(LPVOID)&app); - // Kinect ! - - if(XNuiGetHardwareStatus()!=0) - { - // If the Kinect Sensor is not physically connected, this function returns 0. - NuiInitialize(NUI_INITIALIZE_FLAG_USES_HIGH_QUALITY_COLOR | NUI_INITIALIZE_FLAG_USES_DEPTH | - 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 ); - } - - // Sentient ! - hr = TelemetryManager->Init(); - -#endif // Initialise TLS for tesselator, for this main thread Tesselator::CreateNewThreadStorage(1024*1024); // Initialise TLS for AABB and Vec3 pools, for this main thread @@ -967,75 +773,14 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, app.InitGameSettings(); - // set the default gamma level - float fVal=50.0f*327.68f; - RenderManager.UpdateGamma((unsigned short)fVal); -#if 0 - //bool bDisplayPauseMenu=false; - - // load any skins - //app.AddSkinsToMemoryTextureFiles(); - - // set the achievement text for a trial achievement, now we have the string table loaded - ProfileManager.SetTrialTextStringTable(app.GetStringTable(),IDS_CONFIRM_OK, IDS_CONFIRM_CANCEL); - ProfileManager.SetTrialAwardText(eAwardType_Achievement,IDS_UNLOCK_TITLE,IDS_UNLOCK_ACHIEVEMENT_TEXT); - ProfileManager.SetTrialAwardText(eAwardType_GamerPic,IDS_UNLOCK_TITLE,IDS_UNLOCK_GAMERPIC_TEXT); - ProfileManager.SetTrialAwardText(eAwardType_AvatarItem,IDS_UNLOCK_TITLE,IDS_UNLOCK_AVATAR_TEXT); - ProfileManager.SetTrialAwardText(eAwardType_Theme,IDS_UNLOCK_TITLE,IDS_UNLOCK_THEME_TEXT); - ProfileManager.SetUpsellCallback(&app.UpsellReturnedCallback,&app); - - // Set up a debug character press sequence -#ifndef _FINAL_BUILD - app.SetDebugSequence("LRLRYYY"); -#endif - - // Initialise the social networking manager. - CSocialManager::Instance()->Initialise(); - - // Update the base scene quick selects now that the minecraft class exists - //CXuiSceneBase::UpdateScreenSettings(0); -#endif app.InitialiseTips(); -#if 0 - DWORD initData=0; +#ifdef _TEMPORARY_CREATE_GAME + app.TemporaryCreateGameStart(); -#ifndef _FINAL_BUILD -#ifndef _DEBUG -#pragma message(__LOC__"Need to define the _FINAL_BUILD before submission") -#endif + Sleep(10000); #endif - // Set the default sound levels - pMinecraft->options->set(Options::Option::MUSIC,1.0f); - pMinecraft->options->set(Options::Option::SOUND,1.0f); -#endif - - //app.TemporaryCreateGameStart(); - - //Sleep(10000); -#if 0 - // Intro loop ? - while(app.IntroRunning()) - { - ProfileManager.Tick(); - // Tick XUI - app.RunFrame(); - - // 4J : WESTY : Added to ensure we always have clear background for intro. - RenderManager.SetClearColour(D3DCOLOR_RGBA(0,0,0,255)); - RenderManager.Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - // Render XUI - hr = app.Render(); - - // Present the frame. - RenderManager.Present(); - - // Update XUI Timers - hr = XuiTimersRun(); - } -#endif //str1k3r - moved here from Minecraft.cpp so the SoundEngine starts faster pMinecraft->soundEngine->init(NULL); @@ -1049,22 +794,6 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, continue; } RenderManager.StartFrame(); -#if 0 - if(pMinecraft->soundEngine->isStreamingWavebankReady() && - !pMinecraft->soundEngine->isPlayingStreamingGameMusic() && - !pMinecraft->soundEngine->isPlayingStreamingCDMusic() ) - { - // play some music in the menus - pMinecraft->soundEngine->playStreaming(L"", 0, 0, 0, 0, 0, false); - } -#endif - - // static bool bPlay=false; - // if(bPlay) - // { - // bPlay=false; - // app.audio.PlaySound(); - // } app.UpdateTime(); PIXBeginNamedEvent(0,"Input manager tick"); @@ -1109,147 +838,17 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, pMinecraft->soundEngine->playMusicTick(); -#ifdef MEMORY_TRACKING - static bool bResetMemTrack = false; - static bool bDumpMemTrack = false; - - MemPixStuff(); - - if( bResetMemTrack ) - { - ResetMem(); - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("RESETMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); - bResetMemTrack = false; - } - - if( bDumpMemTrack ) - { - DumpMem(); - bDumpMemTrack = false; - MEMORYSTATUS memStat; - GlobalMemoryStatus(&memStat); - printf("DUMPMEM: Avail. phys %d\n",memStat.dwAvailPhys/(1024*1024)); - printf("Renderer used: %d\n",RenderManager.CBuffSize(-1)); - } -#endif -#if 0 - static bool bDumpTextureUsage = false; - if( bDumpTextureUsage ) - { - RenderManager.TextureGetStats(); - bDumpTextureUsage = false; - } -#endif ui.tick(); ui.render(); -#if 0 - app.HandleButtonPresses(); - // store the minecraft renderstates, and re-set them after the xui render - GetRenderAndSamplerStates(pDevice,RenderStateA,SamplerStateA); - - // Tick XUI - PIXBeginNamedEvent(0,"Xui running"); - app.RunFrame(); - PIXEndNamedEvent(); - - // Render XUI - - PIXBeginNamedEvent(0,"XUI render"); - MemSect(7); - hr = app.Render(); - MemSect(0); - GetRenderAndSamplerStates(pDevice,RenderStateA2,SamplerStateA2); - PIXEndNamedEvent(); - - for(int i=0;i<8;i++) - { - if(RenderStateA2[i]!=RenderStateA[i]) - { - //printf("Reseting RenderStateA[%d] after a XUI render\n",i); - pDevice->SetRenderState(RenderStateModes[i],RenderStateA[i]); - } - } - for(int i=0;i<5;i++) - { - if(SamplerStateA2[i]!=SamplerStateA[i]) - { - //printf("Reseting SamplerStateA[%d] after a XUI render\n",i); - pDevice->SetSamplerState(0,SamplerStateModes[i],SamplerStateA[i]); - } - } - - RenderManager.Set_matrixDirty(); -#endif // Present the frame. RenderManager.Present(); ui.CheckMenuDisplayed(); -#if 0 - PIXBeginNamedEvent(0,"Profile load check"); - // has the game defined profile data been changed (by a profile load) - if(app.uiGameDefinedDataChangedBitmask!=0) - { - void *pData; - for(int i=0;istats[ i ]->clear(); - pMinecraft->stats[i]->parse(pData); - } - } - - // Check to see if we can post to social networks. - CSocialManager::Instance()->RefreshPostingCapability(); - - // clear the flag - app.uiGameDefinedDataChangedBitmask=0; - - // Check if any profile write are needed - app.CheckGameSettingsChanged(); - } - PIXEndNamedEvent(); - app.TickDLCOffersRetrieved(); - app.TickTMSPPFilesRetrieved(); - - PIXBeginNamedEvent(0,"Network manager do work #2"); - g_NetworkManager.DoWork(); - PIXEndNamedEvent(); - - PIXBeginNamedEvent(0,"Misc extra xui"); - // Update XUI Timers - hr = XuiTimersRun(); - -#endif // Any threading type things to deal with from the xui side? app.HandleXuiActions(); -#if 0 - PIXEndNamedEvent(); -#endif isF11Pressed = (GetAsyncKeyState(VK_F11) & 0x8000) != 0; if(isF11Pressed && !wasF11Pressed && GetFocus()) @@ -1305,192 +904,3 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, //str1k3r - pass exitcode to OS, removed app.ExitGame() as that made it always exit with 0 return (int)msg.wParam; } - -#ifdef MEMORY_TRACKING - -int totalAllocGen = 0; -unordered_map allocCounts; -bool trackEnable = false; -bool trackStarted = false; -volatile size_t sizeCheckMin = 1160; -volatile size_t sizeCheckMax = 1160; -volatile int sectCheck = 48; -CRITICAL_SECTION memCS; -DWORD tlsIdx; - -LPVOID XMemAlloc(SIZE_T dwSize, DWORD dwAllocAttributes) -{ - if( !trackStarted ) - { - void *p = XMemAllocDefault(dwSize,dwAllocAttributes); - size_t realSize = XMemSizeDefault(p, dwAllocAttributes); - totalAllocGen += realSize; - return p; - } - - EnterCriticalSection(&memCS); - - void *p=XMemAllocDefault(dwSize + 16,dwAllocAttributes); - size_t realSize = XMemSizeDefault(p,dwAllocAttributes) - 16; - - if( trackEnable ) - { -#if 1 - int sect = ((int) TlsGetValue(tlsIdx)) & 0x3f; - *(((unsigned char *)p)+realSize) = sect; - - if( ( realSize >= sizeCheckMin ) && ( realSize <= sizeCheckMax ) && ( ( sect == sectCheck ) || ( sectCheck == -1 ) ) ) - { - app.DebugPrintf("Found one\n"); - } -#endif - - if( p ) - { - totalAllocGen += realSize; - trackEnable = false; - int key = ( sect << 26 ) | realSize; - int oldCount = allocCounts[key]; - allocCounts[key] = oldCount + 1; - - trackEnable = true; - } - } - - LeaveCriticalSection(&memCS); - - return p; -} - -void* operator new (size_t size) -{ - return (unsigned char *)XMemAlloc(size,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); -} - -void operator delete (void *p) -{ - XMemFree(p,MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP)); -} - -void WINAPI XMemFree(PVOID pAddress, DWORD dwAllocAttributes) -{ - bool special = false; - if( dwAllocAttributes == 0 ) - { - dwAllocAttributes = MAKE_XALLOC_ATTRIBUTES(0,FALSE,TRUE,FALSE,0,XALLOC_PHYSICAL_ALIGNMENT_DEFAULT,XALLOC_MEMPROTECT_READWRITE,FALSE,XALLOC_MEMTYPE_HEAP); - special = true; - } - if(!trackStarted ) - { - size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes); - XMemFreeDefault(pAddress, dwAllocAttributes); - totalAllocGen -= realSize; - return; - } - EnterCriticalSection(&memCS); - if( pAddress ) - { - size_t realSize = XMemSizeDefault(pAddress, dwAllocAttributes) - 16; - - if(trackEnable) - { - int sect = *(((unsigned char *)pAddress)+realSize); - totalAllocGen -= realSize; - trackEnable = false; - int key = ( sect << 26 ) | realSize; - int oldCount = allocCounts[key]; - allocCounts[key] = oldCount - 1; - trackEnable = true; - } - XMemFreeDefault(pAddress, dwAllocAttributes); - } - LeaveCriticalSection(&memCS); -} - -SIZE_T WINAPI XMemSize( - PVOID pAddress, - DWORD dwAllocAttributes - ) -{ - if( trackStarted ) - { - return XMemSizeDefault(pAddress, dwAllocAttributes) - 16; - } - else - { - return XMemSizeDefault(pAddress, dwAllocAttributes); - } -} - -void DumpMem() -{ - int totalLeak = 0; - for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ ) - { - if(it->second > 0 ) - { - app.DebugPrintf("%d %d %d %d\n",( it->first >> 26 ) & 0x3f,it->first & 0x03ffffff, it->second, (it->first & 0x03ffffff) * it->second); - totalLeak += ( it->first & 0x03ffffff ) * it->second; - } - } - app.DebugPrintf("Total %d\n",totalLeak); -} - -void ResetMem() -{ - if( !trackStarted ) - { - trackEnable = true; - trackStarted = true; - totalAllocGen = 0; - InitializeCriticalSection(&memCS); - tlsIdx = TlsAlloc(); - } - EnterCriticalSection(&memCS); - trackEnable = false; - allocCounts.clear(); - trackEnable = true; - LeaveCriticalSection(&memCS); -} - -void MemSect(int section) -{ - unsigned int value = (unsigned int)TlsGetValue(tlsIdx); - if( section == 0 ) // pop - { - value = (value >> 6) & 0x03ffffff; - } - else - { - value = (value << 6) | section; - } - TlsSetValue(tlsIdx, (LPVOID)value); -} - -void MemPixStuff() -{ - const int MAX_SECT = 46; - - int totals[MAX_SECT] = {0}; - - for(AUTO_VAR(it, allocCounts.begin()); it != allocCounts.end(); it++ ) - { - if(it->second > 0 ) - { - int sect = ( it->first >> 26 ) & 0x3f; - int bytes = it->first & 0x03ffffff; - totals[sect] += bytes * it->second; - } - } - - unsigned int allSectsTotal = 0; - for( int i = 0; i < MAX_SECT; i++ ) - { - allSectsTotal += totals[i]; - PIXAddNamedCounter(((float)totals[i])/1024.0f,"MemSect%d",i); - } - - PIXAddNamedCounter(((float)allSectsTotal)/(4096.0f),"MemSect total pages"); -} - -#endif \ No newline at end of file