diff options
Diffstat (limited to 'src/core/Game.cpp')
-rw-r--r-- | src/core/Game.cpp | 291 |
1 files changed, 131 insertions, 160 deletions
diff --git a/src/core/Game.cpp b/src/core/Game.cpp index 93f0d1b0..a8637980 100644 --- a/src/core/Game.cpp +++ b/src/core/Game.cpp @@ -65,6 +65,7 @@ #include "Script.h" #include "Shadows.h" #include "Skidmarks.h" +#include "SetPieces.h" #include "SpecialFX.h" #include "Sprite2d.h" #include "Stats.h" @@ -85,12 +86,16 @@ #include "World.h" #include "ZoneCull.h" #include "Zones.h" +#include "Occlusion.h" #include "debugmenu.h" -#include "frontendoption.h" +#include "Ropes.h" +#include "WindModifiers.h" +#include "WaterCreatures.h" #include "postfx.h" #include "custompipes.h" eLevelName CGame::currLevel; +int32 CGame::currArea; bool CGame::bDemoMode = true; bool CGame::nastyGame = true; bool CGame::frenchGame; @@ -105,6 +110,7 @@ bool CGame::japaneseGame = false; int gameTxdSlot; +// --MIAMI: File done bool DoRWStuffStartOfFrame(int16 TopRed, int16 TopGreen, int16 TopBlue, int16 BottomRed, int16 BottomGreen, int16 BottomBlue, int16 Alpha); void DoRWStuffEndOfFrame(void); @@ -149,7 +155,11 @@ CGame::InitialiseOnceBeforeRW(void) { CFileMgr::Initialise(); CdStreamInit(MAX_CDCHANNELS); - ValidateVersion(); + debug("size of matrix %d\n", sizeof(CMatrix)); + debug("size of placeable %d\n", sizeof(CPlaceable)); + debug("size of entity %d\n", sizeof(CEntity)); + debug("size of building %d\n", sizeof(CBuilding)); + debug("size of dummy %d\n", sizeof(CDummy)); #ifdef EXTENDED_COLOURFILTER CPostFX::InitOnce(); #endif @@ -168,6 +178,7 @@ void ReplaceAtomicPipeCallback(); bool CGame::InitialiseRenderWare(void) { + ValidateVersion(); #ifdef USE_TEXTURE_POOL _TexturePoolsInitialise(); #endif @@ -233,7 +244,6 @@ CGame::InitialiseRenderWare(void) void CGame::ShutdownRenderWare(void) { - CMBlur::MotionBlurClose(); DestroySplashScreen(); CHud::Shutdown(); CFont::Shutdown(); @@ -266,44 +276,29 @@ void CGame::ShutdownRenderWare(void) bool CGame::InitialiseOnceAfterRW(void) { TheText.Load(); - DMAudio.Initialise(); CTimer::Initialise(); CTempColModels::Initialise(); mod_HandlingManager.Initialise(); CSurfaceTable::Initialise("DATA\\SURFACE.DAT"); CPedStats::Initialise(); CTimeCycle::Initialise(); - + DMAudio.Initialise(); if ( DMAudio.GetNum3DProvidersAvailable() == 0 ) - FrontEndMenuManager.m_nPrefsAudio3DProviderIndex = -1; + FrontEndMenuManager.m_nPrefsAudio3DProviderIndex = NO_AUDIO_PROVIDER; - if ( FrontEndMenuManager.m_nPrefsAudio3DProviderIndex == -99 || FrontEndMenuManager.m_nPrefsAudio3DProviderIndex == -2 ) + if ( FrontEndMenuManager.m_nPrefsAudio3DProviderIndex == AUDIO_PROVIDER_NOT_DETERMINED || FrontEndMenuManager.m_nPrefsAudio3DProviderIndex == -2 ) { - CMenuManager::m_PrefsSpeakers = 0; - int8 provider = DMAudio.AutoDetect3DProviders(); - if ( provider != -1 ) - FrontEndMenuManager.m_nPrefsAudio3DProviderIndex = provider; + FrontEndMenuManager.m_PrefsSpeakers = 0; + FrontEndMenuManager.m_nPrefsAudio3DProviderIndex = DMAudio.AutoDetect3DProviders(); } DMAudio.SetCurrent3DProvider(FrontEndMenuManager.m_nPrefsAudio3DProviderIndex); - DMAudio.SetSpeakerConfig(CMenuManager::m_PrefsSpeakers); - DMAudio.SetDynamicAcousticModelingStatus(CMenuManager::m_PrefsDMA); - DMAudio.SetMusicMasterVolume(CMenuManager::m_PrefsMusicVolume); - DMAudio.SetEffectsMasterVolume(CMenuManager::m_PrefsSfxVolume); + DMAudio.SetSpeakerConfig(FrontEndMenuManager.m_PrefsSpeakers); + DMAudio.SetDynamicAcousticModelingStatus(FrontEndMenuManager.m_PrefsDMA); + DMAudio.SetMusicMasterVolume(FrontEndMenuManager.m_PrefsMusicVolume); + DMAudio.SetEffectsMasterVolume(FrontEndMenuManager.m_PrefsSfxVolume); DMAudio.SetEffectsFadeVol(127); DMAudio.SetMusicFadeVol(127); - CWorld::Players[0].SetPlayerSkin(CMenuManager::m_PrefsSkinFile); - -#ifdef CUSTOM_FRONTEND_OPTIONS - // Apparently this func. can be run multiple times at the start. - if (numCustomFrontendOptions == 0 && numCustomFrontendScreens == 0) { - // needs stored language and TheText to be loaded, and last TheText reload is at the start of here - CustomFrontendOptionsPopulate(); - } -#endif -#ifdef LOAD_INI_SETTINGS - LoadINISettings(); // needs frontend options to be loaded -#endif return true; } @@ -321,7 +316,11 @@ bool CGame::Initialise(const char* datFile) strcpy(aDatFile, datFile); CPools::Initialise(); CIniFile::LoadIniFile(); - currLevel = LEVEL_INDUSTRIAL; +#ifdef USE_TEXTURE_POOL + _TexturePoolsUnknown(false); +#endif + currLevel = LEVEL_BEACH; + currArea = AREA_MAIN_MAP; LoadingScreen("Loading the Game", "Loading generic textures", GetRandomSplashScreen()); gameTxdSlot = CTxdStore::AddTxdSlot("generic"); CTxdStore::Create(gameTxdSlot); @@ -339,12 +338,12 @@ bool CGame::Initialise(const char* datFile) CDebug::DebugInitTextBuffer(); ThePaths.Init(); ThePaths.AllocatePathFindInfoMem(4500); + CScriptPaths::Init(); CWeather::Init(); CCullZones::Init(); + COcclusion::Init(); CCollision::Init(); -#ifdef PS2_MENU - TheText.Load(); -#endif + CSetPieces::Init(); CTheZones::Init(); CUserDisplay::Init(); CMessages::Init(); @@ -372,30 +371,33 @@ bool CGame::Initialise(const char* datFile) // for generic fallback CustomPipes::SetTxdFindCallback(); #endif + LoadingScreen("Loading the Game", "Add Particles", nil); CWorld::AddParticles(); CVehicleModelInfo::LoadVehicleColours(); CVehicleModelInfo::LoadEnvironmentMaps(); CTheZones::PostZoneCreation(); - LoadingScreen("Loading the Game", "Setup paths", GetRandomSplashScreen()); + LoadingScreen("Loading the Game", "Setup paths", nil); ThePaths.PreparePathData(); for (int i = 0; i < NUMPLAYERS; i++) CWorld::Players[i].Clear(); CWorld::Players[0].LoadPlayerSkin(); TestModelIndices(); LoadingScreen("Loading the Game", "Setup water", nil); - CWaterLevel::Initialise("DATA\\WATER.DAT"); + WaterLevelInitialise("DATA\\WATER.DAT"); TheConsole.Init(); CDraw::SetFOV(120.0f); CDraw::ms_fLODDistance = 500.0f; LoadingScreen("Loading the Game", "Setup streaming", nil); - CStreaming::Init(); CStreaming::LoadInitialVehicles(); CStreaming::LoadInitialPeds(); CStreaming::RequestBigBuildings(LEVEL_GENERIC); CStreaming::LoadAllRequestedModels(false); + CStreaming::RemoveIslandsNotUsed(currLevel); printf("Streaming uses %zuK of its memory", CStreaming::ms_memoryUsed / 1024); // original modifier was %d LoadingScreen("Loading the Game", "Load animations", GetRandomSplashScreen()); CAnimManager::LoadAnimFiles(); + CStreaming::LoadInitialWeapons(); + CStreaming::LoadAllRequestedModels(0); CPed::Initialise(); CRouteNode::Initialise(); CEventList::Initialise(); @@ -433,13 +435,12 @@ bool CGame::Initialise(const char* datFile) CRubbish::Init(); CClouds::Init(); CSpecialFX::Init(); + CRopes::Init(); CWaterCannons::Init(); CBridge::Init(); CGarages::Init(); LoadingScreen("Loading the Game", "Position dynamic objects", nil); - CWorld::RepositionCertainDynamicObjects(); LoadingScreen("Loading the Game", "Initialise vehicle paths", nil); - CCullZones::ResolveVisibilities(); CTrain::InitTrains(); CPlane::InitPlanes(); CCredits::Init(); @@ -457,18 +458,28 @@ bool CGame::Initialise(const char* datFile) } #endif LoadingScreen("Loading the Game", "Load scene", nil); - CModelInfo::RemoveColModelsFromOtherLevels(currLevel); CCollision::ms_collisionInMemory = currLevel; for (int i = 0; i < MAX_PADS; i++) CPad::GetPad(i)->Clear(true); +#ifdef USE_TEXTURE_POOL + _TexturePoolsUnknown(true); +#endif + DMAudio.SetStartingTrackPositions(true); + DMAudio.ChangeMusicMode(MUSICMODE_GAME); return true; } bool CGame::ShutDown(void) { +#ifdef USE_TEXTURE_POOL + _TexturePoolsUnknown(false); +#endif CReplay::FinishPlayback(); + CReplay::EmptyReplayBuffer(); CPlane::Shutdown(); CTrain::Shutdown(); + CScriptPaths::Shutdown(); + CWaterCreatures::RemoveAll(); CSpecialFX::Shutdown(); #ifndef PS2 CGarages::Shutdown(); @@ -503,7 +514,7 @@ bool CGame::ShutDown(void) CStreaming::Shutdown(); CTxdStore::GameShutdown(); CCollision::Shutdown(); - CWaterLevel::Shutdown(); + CWaterLevel::DestroyWavyAtomic(); CRubbish::Shutdown(); CClouds::Shutdown(); CShadows::Shutdown(); @@ -513,7 +524,11 @@ bool CGame::ShutDown(void) CParticle::Shutdown(); CPools::ShutDown(); CTxdStore::RemoveTxdSlot(gameTxdSlot); + CMBlur::MotionBlurClose(); CdStreamRemoveImages(); +#ifdef USE_TEXTURE_POOL + _TexturePoolsFinalShutdown(); +#endif return true; } @@ -547,7 +562,10 @@ void CGame::ReInitGameObjectVariables(void) CDraw::SetFOV(120.0f); CDraw::ms_fLODDistance = 500.0f; CStreaming::RequestBigBuildings(LEVEL_GENERIC); + CStreaming::RemoveIslandsNotUsed(LEVEL_BEACH); + CStreaming::RemoveIslandsNotUsed(LEVEL_MAINLAND); CStreaming::LoadAllRequestedModels(false); + currArea = AREA_MAIN_MAP; CPed::Initialise(); CEventList::Initialise(); CWeapon::InitialiseWeapons(); @@ -581,9 +599,10 @@ void CGame::ReInitGameObjectVariables(void) CRemote::Init(); #endif CSpecialFX::Init(); + CRopes::Init(); CWaterCannons::Init(); + CScriptPaths::Init(); CParticle::ReloadConfig(); - CCullZones::ResolveVisibilities(); #ifdef PS2_MENU if ( !TheMemoryCard.m_bWantToLoad ) @@ -605,31 +624,18 @@ void CGame::ReInitGameObjectVariables(void) void CGame::ReloadIPLs(void) { - CTimer::Stop(); - CWorld::RemoveStaticObjects(); - ThePaths.Init(); - CCullZones::Init(); - CFileLoader::ReloadPaths("GTA3.IDE"); - CFileLoader::LoadScene("INDUST.IPL"); - CFileLoader::LoadScene("COMMER.IPL"); - CFileLoader::LoadScene("SUBURBAN.IPL"); - CFileLoader::LoadScene("CULL.IPL"); - ThePaths.PreparePathData(); - CTrafficLights::ScanForLightsOnMap(); - CRoadBlocks::Init(); - CCranes::InitCranes(); - CGarages::Init(); - CWorld::RepositionCertainDynamicObjects(); - CCullZones::ResolveVisibilities(); - CRenderer::SortBIGBuildings(); - CTimer::Update(); + // Empty and unused } void CGame::ShutDownForRestart(void) { +#ifdef USE_TEXTURE_POOL + _TexturePoolsUnknown(false); +#endif CReplay::FinishPlayback(); CReplay::EmptyReplayBuffer(); DMAudio.DestroyAllGameCreatedEntities(); + CMovingThings::Shutdown(); for (int i = 0; i < NUMPLAYERS; i++) CWorld::Players[i].Clear(); @@ -638,19 +644,16 @@ void CGame::ShutDownForRestart(void) CTheScripts::UndoBuildingSwaps(); CTheScripts::UndoEntityInvisibilitySettings(); CWorld::ClearForRestart(); + CGameLogic::ClearShortCut(); CTimer::Shutdown(); - CStreaming::FlushRequestList(); - CStreaming::DeleteAllRwObjects(); - CStreaming::RemoveAllUnusedModels(); - CStreaming::ms_disableStreaming = false; + CStreaming::ReInit(); CRadar::RemoveRadarSections(); FrontEndMenuManager.UnloadTextures(); - CParticleObject::RemoveAllParticleObjects(); -#ifndef PS2 + CParticleObject::RemoveAllExpireableParticleObjects(); + CWaterCreatures::RemoveAll(); + CSetPieces::Init(); CPedType::Shutdown(); CSpecialFX::Shutdown(); -#endif - TidyUpMemory(true, false); } void CGame::InitialiseWhenRestarting(void) @@ -661,103 +664,29 @@ void CGame::InitialiseWhenRestarting(void) CTimer::Initialise(); CSprite2d::SetRecipNearClip(); -#ifdef PS2_MENU - if ( TheMemoryCard.b_FoundRecentSavedGameWantToLoad == true || TheMemoryCard.m_bWantToLoad == false ) + if (b_FoundRecentSavedGameWantToLoad || FrontEndMenuManager.m_bWantToLoad) { - if ( TheMemoryCard.m_bWantToLoad == true ) - MessageScreen("MCLOAD"); // Loading Data. Please do not remove the Memory Card (PS2) in MEMORY CARD slot 1, reset or switch off the console. - else - MessageScreen("RESTART"); // Starting new game + LoadSplash("splash1"); + if (FrontEndMenuManager.m_bWantToLoad) + FrontEndMenuManager.MessageScreen("FELD_WR", true); } -#endif - -#ifdef PS2_MENU - TheMemoryCard.b_FoundRecentSavedGameWantToLoad = false; -#else + b_FoundRecentSavedGameWantToLoad = false; -#endif TheCamera.Init(); -#ifdef PS2_MENU - if ( TheMemoryCard.m_bWantToLoad == true ) - { - TheMemoryCard.RestoreForStartLoad(); - CStreaming::LoadScene(TheCamera.GetPosition()); - } -#else if ( FrontEndMenuManager.m_bWantToLoad == true ) { RestoreForStartLoad(); - CStreaming::LoadScene(TheCamera.GetPosition()); } -#endif ReInitGameObjectVariables(); -#ifdef PS2_MENU - if ( TheMemoryCard.m_bWantToLoad == true ) - { - if ( TheMemoryCard.LoadSavedGame() == CMemoryCard::RES_SUCCESS ) - { - for ( int32 i = 0; i < 35; i++ ) - { - MessageScreen("FESZ_LS"); // Load Successful. - } - - DMAudio.ResetTimers(CTimer::GetTimeInMilliseconds()); - CTrain::InitTrains(); - CPlane::InitPlanes(); - } - else - { - for ( int32 i = 0; i < 50; i++ ) - { - DoRWStuffStartOfFrame(50, 50, 50, 0, 0, 0, 255); - - CSprite2d::InitPerFrame(); - CFont::InitPerFrame(); - DefinedState(); - - CSprite2d *splash = LoadSplash(NULL); - splash->Draw(rect, color, color, color, color); - splash->DrawRect(CRect(SCREEN_SCALE_X(20.0f), SCREEN_SCALE_Y(110.0f), SCREEN_SCALE_X(620.0f), SCREEN_SCALE_Y(300.0f)), CRGBA(50, 50, 50, 192)); - - //CFont::SetFontStyle(?); - CFont::SetBackgroundOff(); - CFont::SetWrapx(SCREEN_SCALE_FROM_RIGHT(160.0f)); // 480.0f - CFont::SetScale(SCREEN_SCALE_X(1.0f), SCREEN_SCALE_Y(1.0f)); - CFont::SetCentreOn(); - CFont::SetCentreSize(SCREEN_SCALE_FROM_RIGHT(160.0f)); // 480.0f - CFont::SetJustifyOff(); - CFont::SetColor(CRGBA(255, 255, 255, 255)); - CFont::SetBackGroundOnlyTextOff(); - CFont::SetDropColor(CRGBA(32, 32, 32, 255)); - CFont::SetDropShadowPosition(3); - CFont::SetPropOn(); - CFont::PrintString(SCREEN_SCALE_X(320.0f), SCREEN_SCALE_Y(130.0f), TheText.Get("MC_LDFL")); // Load Failed! - CFont::PrintString(SCREEN_SCALE_X(320.0f), SCREEN_SCALE_Y(170.0f), TheText.Get("FES_NOC")); // No Memory Card (PS2) in MEMORY CARD slot 1. - CFont::PrintString(SCREEN_SCALE_X(320.0f), SCREEN_SCALE_Y(240.0f), TheText.Get("MC_NWRE")); // Now Restarting Game. - CFont::DrawFonts(); - - DoRWStuffEndOfFrame(); - } - - ShutDownForRestart(); - CTimer::Stop(); - CTimer::Initialise(); - TheMemoryCard.m_bWantToLoad = false; - ReInitGameObjectVariables(); - currLevel = LEVEL_INDUSTRIAL; - CCollision::SortOutCollisionAfterLoad(); - - FrontEndMenuManager.SetSoundLevelsForMusicMenu(); - FrontEndMenuManager.InitialiseMenuContentsAfterLoadingGame(); - } - } -#else if ( FrontEndMenuManager.m_bWantToLoad == true ) { + FrontEndMenuManager.m_bWantToLoad = false; + // TODO(Miami) + //InitRadioStationPositionList(); if ( GenericLoad() == true ) { DMAudio.ResetTimers(CTimer::GetTimeInMilliseconds()); @@ -769,23 +698,26 @@ void CGame::InitialiseWhenRestarting(void) for ( int32 i = 0; i < 50; i++ ) { HandleExit(); - FrontEndMenuManager.MessageScreen("FED_LFL"); // Loading save game has failed. The game will restart now. + FrontEndMenuManager.MessageScreen("FED_LFL", true); // Loading save game has failed. The game will restart now. } + TheCamera.SetFadeColour(0, 0, 0); ShutDownForRestart(); CTimer::Stop(); CTimer::Initialise(); FrontEndMenuManager.m_bWantToLoad = false; ReInitGameObjectVariables(); - currLevel = LEVEL_INDUSTRIAL; + currLevel = LEVEL_GENERIC; CCollision::SortOutCollisionAfterLoad(); } } -#endif CTimer::Update(); DMAudio.ChangeMusicMode(MUSICMODE_GAME); +#ifdef USE_TEXTURE_POOL + _TexturePoolsUnknown(true); +#endif } void CGame::Process(void) @@ -794,19 +726,20 @@ void CGame::Process(void) #ifdef GTA_PS2 ProcessTidyUpMemory(); #endif - TheCamera.SetMotionBlurAlpha(0); - if (TheCamera.m_BlurType == MOTION_BLUR_NONE || TheCamera.m_BlurType == MOTION_BLUR_SNIPER || TheCamera.m_BlurType == MOTION_BLUR_LIGHT_SCENE) - TheCamera.SetMotionBlur(0, 0, 0, 0, MOTION_BLUR_NONE); #ifdef DEBUGMENU DebugMenuProcess(); #endif CCutsceneMgr::Update(); if (!CCutsceneMgr::IsCutsceneProcessing() && !CTimer::GetIsCodePaused()) FrontEndMenuManager.Process(); + CTheZones::Update(); + // DRM call in here + uint32 startTime = CTimer::GetCurrentTimeInCycles() / CTimer::GetCyclesPerMillisecond(); CStreaming::Update(); + uint32 processTime = CTimer::GetCurrentTimeInCycles() / CTimer::GetCyclesPerMillisecond() - startTime; + CWindModifiers::Number = 0; if (!CTimer::GetIsPaused()) { - CTheZones::Update(); CSprite2d::SetRecipNearClip(); CSprite2d::InitPerFrame(); CFont::InitPerFrame(); @@ -817,6 +750,7 @@ void CGame::Process(void) CWeather::Update(); CTheScripts::Process(); CCollision::Update(); + CScriptPaths::Update(); CTrain::UpdateTrains(); CPlane::UpdatePlanes(); CHeli::UpdateHelis(); @@ -825,10 +759,17 @@ void CGame::Process(void) CAntennas::Update(); CGlass::Update(); CSceneEdit::Update(); + CSetPieces::Update(); CEventList::Update(); CParticle::Update(); gFireManager.Update(); - CPopulation::Update(); + if (processTime >= 2) { + CPopulation::Update(false); + } else { + uint32 startTime = CTimer::GetCurrentTimeInCycles() / CTimer::GetCyclesPerMillisecond(); + CPopulation::Update(true); + processTime = CTimer::GetCurrentTimeInCycles() / CTimer::GetCyclesPerMillisecond() - startTime; + } CWeapon::UpdateWeapons(); if (!CCutsceneMgr::IsRunning()) CTheCarGenerators::Process(); @@ -846,6 +787,7 @@ void CGame::Process(void) CGarages::Update(); CRubbish::Update(); CSpecialFX::Update(); + CRopes::Update(); CTimeCycle::Update(); if (CReplay::ShouldStandardCameraBeProcessed()) TheCamera.Process(); @@ -860,28 +802,57 @@ void CGame::Process(void) gPhoneInfo.Update(); if (!CReplay::IsPlayingBack()) { - CCarCtrl::GenerateRandomCars(); + if (processTime < 2) + CCarCtrl::GenerateRandomCars(); CRoadBlocks::GenerateRoadBlocks(); CCarCtrl::RemoveDistantCars(); + CCarCtrl::RemoveCarsIfThePoolGetsFull(); } } -#ifdef PS2 - CMemCheck::DoTest(); -#endif +} + +void +CGame::InitAfterFocusLoss() +{ + FrontEndMenuManager.m_nPrefsAudio3DProviderIndex = FrontEndMenuManager.m_lastWorking3DAudioProvider; + DMAudio.SetCurrent3DProvider(FrontEndMenuManager.m_lastWorking3DAudioProvider); + + if (!FrontEndMenuManager.m_bGameNotLoaded && !FrontEndMenuManager.m_bMenuActive) + FrontEndMenuManager.m_bStartUpFrontEndRequested = true; +} + +bool +CGame::CanSeeWaterFromCurrArea(void) +{ + return currArea == AREA_MAIN_MAP || currArea == AREA_MANSION + || currArea == AREA_HOTEL; +} + +bool +CGame::CanSeeOutSideFromCurrArea(void) +{ + return currArea == AREA_MAIN_MAP || currArea == AREA_MALL || + currArea == AREA_MANSION || currArea == AREA_HOTEL; } void CGame::DrasticTidyUpMemory(bool) { +#ifdef USE_TEXTURE_POOL + // TODO +#endif #ifdef PS2 // meow #endif } -void CGame::TidyUpMemory(bool, bool) +void CGame::TidyUpMemory(bool unk1, bool unk2) { #ifdef PS2 // meow #endif + if (unk2) { + DrasticTidyUpMemory(true); // parameter is unknown too + } } void CGame::ProcessTidyUpMemory(void) |