From bb0541404d79e91cde0ffe2dac8506df134e18b7 Mon Sep 17 00:00:00 2001 From: aap Date: Wed, 6 May 2020 09:24:12 +0200 Subject: [PATCH 1/5] updated librw --- librw | 2 +- premake5.lua | 92 ++++++++++++++++++++++++++++++++++++++++++++ src/fakerw/fake.cpp | 3 +- src/fakerw/rwcore.h | 10 ++--- src/render/Lines.cpp | 2 + src/skel/win/win.cpp | 2 - 6 files changed, 101 insertions(+), 10 deletions(-) diff --git a/librw b/librw index b3ad490d..40eae78e 160000 --- a/librw +++ b/librw @@ -1 +1 @@ -Subproject commit b3ad490d1be3c1f41b416d3ceeaff3453bd2d28d +Subproject commit 40eae78e793f234e332aff08265c41683faeb7f7 diff --git a/premake5.lua b/premake5.lua index 1c313a10..cfba8e01 100644 --- a/premake5.lua +++ b/premake5.lua @@ -192,3 +192,95 @@ project "re3" libdirs { path.join(_OPTIONS["glewdir"], "lib/Release/Win32") } libdirs { path.join(_OPTIONS["glfwdir"], "lib-" .. string.gsub(_ACTION, "vs", "vc")) } links { "opengl32", "glew32s", "glfw3" } + + +project "reVC" + kind "WindowedApp" + targetname "reVC" + targetdir "bin/%{cfg.platform}/%{cfg.buildcfg}" + targetextension ".exe" + characterset ("MBCS") + linkoptions "/SAFESEH:NO" + + defines { "MIAMI" } + + files { "src/*.*" } + files { "src/animation/*.*" } + files { "src/audio/*.*" } + files { "src/control/*.*" } + files { "src/core/*.*" } + files { "src/entities/*.*" } + files { "src/math/*.*" } + files { "src/modelinfo/*.*" } + files { "src/objects/*.*" } + files { "src/peds/*.*" } + files { "src/render/*.*" } + files { "src/rw/*.*" } + files { "src/save/*.*" } + files { "src/skel/*.*" } + files { "src/skel/win/*.*" } + files { "src/skel/glfw/*.*" } + files { "src/text/*.*" } + files { "src/vehicles/*.*" } + files { "src/weapons/*.*" } + files { "src/extras/*.*" } + files { "eax/*.*" } + + includedirs { "src" } + includedirs { "src/animation" } + includedirs { "src/audio" } + includedirs { "src/control" } + includedirs { "src/core" } + includedirs { "src/entities" } + includedirs { "src/math" } + includedirs { "src/modelinfo" } + includedirs { "src/objects" } + includedirs { "src/peds" } + includedirs { "src/render" } + includedirs { "src/rw" } + includedirs { "src/save/" } + includedirs { "src/skel/" } + includedirs { "src/skel/win" } + includedirs { "src/skel/glfw" } + includedirs { "src/text" } + includedirs { "src/vehicles" } + includedirs { "src/weapons" } + includedirs { "src/extras" } + includedirs { "eax" } + + includedirs { "milessdk/include" } + includedirs { "eax" } + + libdirs { "milessdk/lib" } + + setpaths("$(GTA_VC_RE_DIR)/", "$(TargetFileName)", "") + + filter "platforms:*RW33*" + staticruntime "on" + includedirs { "rwsdk/include/d3d8" } + libdirs { "rwsdk/lib/d3d8/release" } + links { "rwcore", "rpworld", "rpmatfx", "rpskin", "rphanim", "rtbmp", "rtquat", "rtcharse" } + defines { "RWLIBS" } + linkoptions "/SECTION:_rwcseg,ER!W /MERGE:_rwcseg=.text" + + filter "platforms:*librw*" + defines { "LIBRW" } + files { "src/fakerw/*.*" } + includedirs { "src/fakerw" } + includedirs { Librw } + if(_OPTIONS["with-librw"]) then + libdirs { "lib/%{cfg.platform}/%{cfg.buildcfg}" } + end + links { "rw" } + + filter "platforms:*d3d*" + includedirs { "dxsdk/include" } + libdirs { "dxsdk/lib" } + + filter "platforms:*d3d9*" + links { "d3d9" } + + filter "platforms:*gl3_glfw*" + libdirs { path.join(_OPTIONS["glewdir"], "lib/Release/Win32") } + libdirs { path.join(_OPTIONS["glfwdir"], "lib-" .. string.gsub(_ACTION, "vs", "vc")) } + links { "opengl32", "glew32s", "glfw3" } diff --git a/src/fakerw/fake.cpp b/src/fakerw/fake.cpp index 76d7865c..e569dea9 100644 --- a/src/fakerw/fake.cpp +++ b/src/fakerw/fake.cpp @@ -429,8 +429,7 @@ void RwIm3DVertexSetU(RwIm3DVertex *vert, RwReal u) { vert->setU(u); } void RwIm3DVertexSetV(RwIm3DVertex *vert, RwReal v) { vert->setV(v); } void RwIm3DVertexSetRGBA(RwIm3DVertex *vert, RwUInt8 r, RwUInt8 g, RwUInt8 b, RwUInt8 a) { vert->setColor(r, g, b, a); } -// WARNING: ignoring flags -void *RwIm3DTransform(RwIm3DVertex *pVerts, RwUInt32 numVerts, RwMatrix *ltm, RwUInt32 flags) { im3d::Transform(pVerts, numVerts, ltm); return pVerts; } +void *RwIm3DTransform(RwIm3DVertex *pVerts, RwUInt32 numVerts, RwMatrix *ltm, RwUInt32 flags) { im3d::Transform(pVerts, numVerts, ltm, flags); return pVerts; } RwBool RwIm3DEnd(void) { im3d::End(); return true; } RwBool RwIm3DRenderLine(RwInt32 vert1, RwInt32 vert2) { RwImVertexIndex indices[2]; diff --git a/src/fakerw/rwcore.h b/src/fakerw/rwcore.h index 22e29737..31bc5541 100644 --- a/src/fakerw/rwcore.h +++ b/src/fakerw/rwcore.h @@ -20,11 +20,11 @@ typedef RwUInt16 RwImVertexIndex; enum RwIm3DTransformFlags { - rwIM3D_VERTEXUV = 1, - rwIM3D_ALLOPAQUE = 2, - rwIM3D_NOCLIP = 4, - rwIM3D_VERTEXXYZ = 8, - rwIM3D_VERTEXRGBA = 16, + rwIM3D_VERTEXUV = rw::im3d::VERTEXUV, + rwIM3D_ALLOPAQUE = rw::im3d::ALLOPAQUE, + rwIM3D_NOCLIP = rw::im3d::NOCLIP, + rwIM3D_VERTEXXYZ = rw::im3d::VERTEXXYZ, + rwIM3D_VERTEXRGBA = rw::im3d::VERTEXRGBA, }; void RwIm2DVertexSetCameraX(RwIm2DVertex *vert, RwReal camx); diff --git a/src/render/Lines.cpp b/src/render/Lines.cpp index b5c85149..84d3683b 100644 --- a/src/render/Lines.cpp +++ b/src/render/Lines.cpp @@ -60,6 +60,8 @@ CLines::RenderLineWithClipping(float x1, float y1, float z1, float x2, float y2, col2.green = c2>>16; col2.blue = c2>>8; col2.alpha = c2; +// HACK HACK until i got im3d fixed +RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); RwIm3DVertexSetRGBA(&v[0], col1.red, col1.green, col1.blue, col1.alpha); RwIm3DVertexSetRGBA(&v[1], col2.red, col2.green, col2.blue, col2.alpha); diff --git a/src/skel/win/win.cpp b/src/skel/win/win.cpp index d20cc0bf..ec72bf7e 100644 --- a/src/skel/win/win.cpp +++ b/src/skel/win/win.cpp @@ -1884,13 +1884,11 @@ WinMain(HINSTANCE instance, StaticPatcher::Apply(); SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, nil, SPIF_SENDCHANGE); -/* // TODO: make this an option somewhere AllocConsole(); freopen("CONIN$", "r", stdin); freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); -*/ /* * Initialize the platform independent data. From edd9301d7f6ae01725cfc1331d018e7b65565657 Mon Sep 17 00:00:00 2001 From: aap Date: Wed, 6 May 2020 09:59:04 +0200 Subject: [PATCH 2/5] reverting fuckup --- librw | 2 +- premake5.lua | 92 -------------------------------------------- src/render/Lines.cpp | 2 - src/skel/win/win.cpp | 2 + 4 files changed, 3 insertions(+), 95 deletions(-) diff --git a/librw b/librw index 40eae78e..bdbc92d8 160000 --- a/librw +++ b/librw @@ -1 +1 @@ -Subproject commit 40eae78e793f234e332aff08265c41683faeb7f7 +Subproject commit bdbc92d86eef28344e01c992d55a9c4f43629f84 diff --git a/premake5.lua b/premake5.lua index f8e3af81..fbd2e011 100644 --- a/premake5.lua +++ b/premake5.lua @@ -198,95 +198,3 @@ project "re3" libdirs { path.join(_OPTIONS["glewdir"], "lib/Release/Win32") } libdirs { path.join(_OPTIONS["glfwdir"], "lib-" .. string.gsub(_ACTION, "vs", "vc")) } links { "opengl32", "glew32s", "glfw3" } - - -project "reVC" - kind "WindowedApp" - targetname "reVC" - targetdir "bin/%{cfg.platform}/%{cfg.buildcfg}" - targetextension ".exe" - characterset ("MBCS") - linkoptions "/SAFESEH:NO" - - defines { "MIAMI" } - - files { "src/*.*" } - files { "src/animation/*.*" } - files { "src/audio/*.*" } - files { "src/control/*.*" } - files { "src/core/*.*" } - files { "src/entities/*.*" } - files { "src/math/*.*" } - files { "src/modelinfo/*.*" } - files { "src/objects/*.*" } - files { "src/peds/*.*" } - files { "src/render/*.*" } - files { "src/rw/*.*" } - files { "src/save/*.*" } - files { "src/skel/*.*" } - files { "src/skel/win/*.*" } - files { "src/skel/glfw/*.*" } - files { "src/text/*.*" } - files { "src/vehicles/*.*" } - files { "src/weapons/*.*" } - files { "src/extras/*.*" } - files { "eax/*.*" } - - includedirs { "src" } - includedirs { "src/animation" } - includedirs { "src/audio" } - includedirs { "src/control" } - includedirs { "src/core" } - includedirs { "src/entities" } - includedirs { "src/math" } - includedirs { "src/modelinfo" } - includedirs { "src/objects" } - includedirs { "src/peds" } - includedirs { "src/render" } - includedirs { "src/rw" } - includedirs { "src/save/" } - includedirs { "src/skel/" } - includedirs { "src/skel/win" } - includedirs { "src/skel/glfw" } - includedirs { "src/text" } - includedirs { "src/vehicles" } - includedirs { "src/weapons" } - includedirs { "src/extras" } - includedirs { "eax" } - - includedirs { "milessdk/include" } - includedirs { "eax" } - - libdirs { "milessdk/lib" } - - setpaths("$(GTA_VC_RE_DIR)/", "$(TargetFileName)", "") - - filter "platforms:*RW33*" - staticruntime "on" - includedirs { "rwsdk/include/d3d8" } - libdirs { "rwsdk/lib/d3d8/release" } - links { "rwcore", "rpworld", "rpmatfx", "rpskin", "rphanim", "rtbmp", "rtquat", "rtcharse" } - defines { "RWLIBS" } - linkoptions "/SECTION:_rwcseg,ER!W /MERGE:_rwcseg=.text" - - filter "platforms:*librw*" - defines { "LIBRW" } - files { "src/fakerw/*.*" } - includedirs { "src/fakerw" } - includedirs { Librw } - if(_OPTIONS["with-librw"]) then - libdirs { "lib/%{cfg.platform}/%{cfg.buildcfg}" } - end - links { "rw" } - - filter "platforms:*d3d*" - includedirs { "dxsdk/include" } - libdirs { "dxsdk/lib" } - - filter "platforms:*d3d9*" - links { "d3d9" } - - filter "platforms:*gl3_glfw*" - libdirs { path.join(_OPTIONS["glewdir"], "lib/Release/Win32") } - libdirs { path.join(_OPTIONS["glfwdir"], "lib-" .. string.gsub(_ACTION, "vs", "vc")) } - links { "opengl32", "glew32s", "glfw3" } diff --git a/src/render/Lines.cpp b/src/render/Lines.cpp index 84d3683b..b5c85149 100644 --- a/src/render/Lines.cpp +++ b/src/render/Lines.cpp @@ -60,8 +60,6 @@ CLines::RenderLineWithClipping(float x1, float y1, float z1, float x2, float y2, col2.green = c2>>16; col2.blue = c2>>8; col2.alpha = c2; -// HACK HACK until i got im3d fixed -RwRenderStateSet(rwRENDERSTATETEXTURERASTER, nil); RwIm3DVertexSetRGBA(&v[0], col1.red, col1.green, col1.blue, col1.alpha); RwIm3DVertexSetRGBA(&v[1], col2.red, col2.green, col2.blue, col2.alpha); diff --git a/src/skel/win/win.cpp b/src/skel/win/win.cpp index ec72bf7e..d20cc0bf 100644 --- a/src/skel/win/win.cpp +++ b/src/skel/win/win.cpp @@ -1884,11 +1884,13 @@ WinMain(HINSTANCE instance, StaticPatcher::Apply(); SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, nil, SPIF_SENDCHANGE); +/* // TODO: make this an option somewhere AllocConsole(); freopen("CONIN$", "r", stdin); freopen("CONOUT$", "w", stdout); freopen("CONOUT$", "w", stderr); +*/ /* * Initialize the platform independent data. From cbfc45b3f72468e7880bec852773955d3886b5ff Mon Sep 17 00:00:00 2001 From: aap Date: Wed, 6 May 2020 12:23:26 +0200 Subject: [PATCH 3/5] some work on zones --- src/audio/PoliceRadio.cpp | 4 +- src/control/Replay.cpp | 4 +- src/control/Script.cpp | 30 ++++++------ src/core/FileLoader.cpp | 4 +- src/core/Streaming.cpp | 2 +- src/core/User.cpp | 12 ++--- src/core/ZoneCull.cpp | 2 +- src/core/Zones.cpp | 99 ++++++++++++++++++++------------------- src/core/Zones.h | 15 +++--- src/entities/Entity.cpp | 2 +- src/peds/Population.cpp | 2 +- 11 files changed, 90 insertions(+), 86 deletions(-) diff --git a/src/audio/PoliceRadio.cpp b/src/audio/PoliceRadio.cpp index 5470a1af..ec02368e 100644 --- a/src/audio/PoliceRadio.cpp +++ b/src/audio/PoliceRadio.cpp @@ -306,7 +306,7 @@ cAudioManager::SetupCrimeReport() if (i == ARRAY_SIZE(m_sPoliceRadioQueue.crimes)) return false; audioZoneId = CTheZones::FindAudioZone(&m_sPoliceRadioQueue.crimes[i].position); if (audioZoneId >= 0 && audioZoneId < NUMAUDIOZONES) { - zone = &CTheZones::ZoneArray[CTheZones::AudioZoneArray[audioZoneId]]; + zone = CTheZones::GetAudioZone(audioZoneId); for (int j = 0; j < NUMAUDIOZONES; j++) { if (strcmp(zone->name, ZoneSfx[j].m_aName) == 0) { sampleIndex = ZoneSfx[j].m_nSampleIndex; @@ -722,7 +722,7 @@ cAudioManager::PlaySuspectLastSeen(float x, float y, float z) if (MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE && 60 - m_sPoliceRadioQueue.policeChannelTimer > 9) { audioZone = CTheZones::FindAudioZone(&vec); if (audioZone >= 0 && audioZone < NUMAUDIOZONES) { - zone = &CTheZones::ZoneArray[CTheZones::AudioZoneArray[audioZone]]; + zone = CTheZones::GetAudioZone(audioZone); for (int i = 0; i < NUMAUDIOZONES; i++) { if (strcmp(zone->name, ZoneSfx[i].m_aName) == 0) { sample = ZoneSfx[i].m_nSampleIndex; diff --git a/src/control/Replay.cpp b/src/control/Replay.cpp index fd5448cc..707f1d87 100644 --- a/src/control/Replay.cpp +++ b/src/control/Replay.cpp @@ -987,7 +987,7 @@ void CReplay::FinishPlayback(void) Mode = MODE_RECORD; if (bDoLoadSceneWhenDone){ CVector v_ls(LoadSceneX, LoadSceneY, LoadSceneZ); - CGame::currLevel = CTheZones::GetLevelFromPosition(v_ls); + CGame::currLevel = CTheZones::GetLevelFromPosition(&v_ls); CCollision::SortOutCollisionAfterLoad(); CStreaming::LoadScene(v_ls); } @@ -1101,7 +1101,7 @@ void CReplay::TriggerPlayback(uint8 cam_mode, float cam_x, float cam_y, float ca LoadSceneZ = TheCamera.GetPosition().z; CVector ff_coord; FindFirstFocusCoordinate(&ff_coord); - CGame::currLevel = CTheZones::GetLevelFromPosition(ff_coord); + CGame::currLevel = CTheZones::GetLevelFromPosition(&ff_coord); CCollision::SortOutCollisionAfterLoad(); CStreaming::LoadScene(ff_coord); } diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 2bb945d3..a274c289 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -1729,7 +1729,7 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) ped->SetOrientation(0.0f, 0.0f, 0.0f); CTheScripts::ClearSpaceForMissionEntity(pos, ped); CWorld::Add(ped); - ped->m_nZoneLevel = CTheZones::GetLevelFromPosition(pos); + ped->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pos); CPopulation::ms_nTotalMissionPeds++; ScriptParams[0] = CPools::GetPedPool()->GetIndex(ped); StoreParameters(&m_nIp, 1); @@ -1968,7 +1968,7 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) car->AutoPilot.m_nCruiseSpeed = car->AutoPilot.m_fMaxTrafficSpeed = 9.0f; car->AutoPilot.m_nCurrentLane = car->AutoPilot.m_nNextLane = 0; car->bEngineOn = false; - car->m_nZoneLevel = CTheZones::GetLevelFromPosition(pos); + car->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pos); car->bHasBeenOwnedByPlayer = true; CWorld::Add(car); handle = CPools::GetVehiclePool()->GetIndex(car); @@ -2674,7 +2674,7 @@ int8 CRunningScript::ProcessCommands200To299(int32 command) m_nIp += KEY_LENGTH_IN_SCRIPT; /* why only if zone != 1? */ CVector pos = pPlayer->GetPos(); CZone* pZone = CTheZones::GetZone(zoneToCheck); - UpdateCompareFlag(CTheZones::PointLiesWithinZone(pos, pZone)); + UpdateCompareFlag(CTheZones::PointLiesWithinZone(&pos, pZone)); return 0; } case COMMAND_IS_PLAYER_PRESSING_HORN: @@ -2773,7 +2773,7 @@ int8 CRunningScript::ProcessCommands200To299(int32 command) #endif pPed->m_pVehicleAnim = CAnimManager::BlendAnimation(pPed->GetClump(), ASSOCGRP_STD, anim, 100.0f); pPed->StopNonPartialAnims(); - pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(pPed->GetPosition()); + pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pPed->GetPosition()); CWorld::Add(pPed); ScriptParams[0] = CPools::GetPedPool()->GetIndex(pPed); StoreParameters(&m_nIp, 1); @@ -3026,7 +3026,7 @@ int8 CRunningScript::ProcessCommands300To399(int32 command) if (zone != -1) m_nIp += KEY_LENGTH_IN_SCRIPT; CVector pos = pPed->bInVehicle ? pPed->m_pMyVehicle->GetPosition() : pPed->GetPosition(); - UpdateCompareFlag(CTheZones::PointLiesWithinZone(pos, CTheZones::GetZone(zone))); + UpdateCompareFlag(CTheZones::PointLiesWithinZone(&pos, CTheZones::GetZone(zone))); return 0; } case COMMAND_SET_CAR_DENSITY: @@ -3964,7 +3964,7 @@ int8 CRunningScript::ProcessCommands400To499(int32 command) #endif pPed->m_pVehicleAnim = CAnimManager::BlendAnimation(pPed->GetClump(), ASSOCGRP_STD, anim, 100.0f); pPed->StopNonPartialAnims(); - pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(pPed->GetPosition()); + pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pPed->GetPosition()); CWorld::Add(pPed); ScriptParams[0] = CPools::GetPedPool()->GetIndex(pPed); StoreParameters(&m_nIp, 1); @@ -5880,7 +5880,7 @@ int8 CRunningScript::ProcessCommands700To799(int32 command) continue; if (pPed->bIsLeader || pPed->m_leader) continue; - if (!CTheZones::PointLiesWithinZone(pPed->GetPosition(), pZone)) + if (!CTheZones::PointLiesWithinZone(&pPed->GetPosition(), pZone)) continue; if (pos.z - PED_FIND_Z_OFFSET > pPed->GetPosition().z) continue; @@ -6536,7 +6536,7 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) continue; if (pVehicle->VehicleCreatedBy != RANDOM_VEHICLE) continue; - if (!CTheZones::PointLiesWithinZone(pVehicle->GetPosition(), pZone)) + if (!CTheZones::PointLiesWithinZone(&pVehicle->GetPosition(), pZone)) continue; handle = CPools::GetVehiclePool()->GetIndex(pVehicle); pVehicle->VehicleCreatedBy = MISSION_VEHICLE; @@ -7347,7 +7347,7 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) ped->SetOrientation(0.0f, 0.0f, 0.0f); CTheScripts::ClearSpaceForMissionEntity(pos, ped); CWorld::Add(ped); - ped->m_nZoneLevel = CTheZones::GetLevelFromPosition(pos); + ped->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pos); CPopulation::ms_nTotalMissionPeds++; ScriptParams[0] = CPools::GetPedPool()->GetIndex(ped); StoreParameters(&m_nIp, 1); @@ -8178,7 +8178,7 @@ int8 CRunningScript::ProcessCommands900To999(int32 command) car->AutoPilot.m_nCruiseSpeed = car->AutoPilot.m_fMaxTrafficSpeed = 9.0f; car->AutoPilot.m_nCurrentLane = car->AutoPilot.m_nNextLane = 0; car->bEngineOn = false; - car->m_nZoneLevel = CTheZones::GetLevelFromPosition(pos); + car->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pos); CWorld::Add(car); return 0; } @@ -8504,7 +8504,7 @@ int8 CRunningScript::ProcessCommands1000To1099(int32 command) CVehicle* pVehicle = CPools::GetVehiclePool()->GetAt(ScriptParams[0]); assert(pVehicle); if (ScriptParams[1]) - pVehicle->m_nZoneLevel = CTheZones::GetLevelFromPosition(pVehicle->GetPosition()); + pVehicle->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pVehicle->GetPosition()); else pVehicle->m_nZoneLevel = LEVEL_NONE; return 0; @@ -8515,7 +8515,7 @@ int8 CRunningScript::ProcessCommands1000To1099(int32 command) CPed* pPed = CPools::GetPedPool()->GetAt(ScriptParams[0]); assert(pPed); if (ScriptParams[1]) - pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(pPed->GetPosition()); + pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pPed->GetPosition()); else pPed->m_nZoneLevel = LEVEL_NONE; return 0; @@ -8920,7 +8920,7 @@ int8 CRunningScript::ProcessCommands1000To1099(int32 command) if (ScriptParams[1]) pPed->m_nZoneLevel = LEVEL_IGNORE; else - pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(pPed->GetPosition()); + pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pPed->GetPosition()); return 0; } case COMMAND_GET_CHASE_CAR: @@ -9119,7 +9119,7 @@ int8 CRunningScript::ProcessCommands1100To1199(int32 command) if (ScriptParams[1]) pVehicle->m_nZoneLevel = LEVEL_IGNORE; else - pVehicle->m_nZoneLevel = CTheZones::GetLevelFromPosition(pVehicle->GetPosition()); + pVehicle->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pVehicle->GetPosition()); return 0; } case COMMAND_MAKE_CRAIGS_CAR_A_BIT_STRONGER: @@ -9465,7 +9465,7 @@ int8 CRunningScript::ProcessCommands1100To1199(int32 command) continue; if (pPed->bIsLeader || pPed->m_leader) continue; - if (!CTheZones::PointLiesWithinZone(pPed->GetPosition(), pZone)) + if (!CTheZones::PointLiesWithinZone(&pPed->GetPosition(), pZone)) continue; if (pos.z - PED_FIND_Z_OFFSET > pPed->GetPosition().z) continue; diff --git a/src/core/FileLoader.cpp b/src/core/FileLoader.cpp index a2654369..25c43778 100644 --- a/src/core/FileLoader.cpp +++ b/src/core/FileLoader.cpp @@ -1088,7 +1088,7 @@ CFileLoader::LoadObjectInstance(const char *line) entity = new CBuilding; entity->SetModelIndexNoCreate(id); entity->GetMatrix() = CMatrix(xform); - entity->m_level = CTheZones::GetLevelFromPosition(entity->GetPosition()); + entity->m_level = CTheZones::GetLevelFromPosition(&entity->GetPosition()); if(mi->IsSimple()){ if(mi->m_isBigBuilding) entity->SetupBigBuilding(); @@ -1105,7 +1105,7 @@ CFileLoader::LoadObjectInstance(const char *line) CWorld::Add(entity); if(IsGlass(entity->GetModelIndex())) entity->bIsVisible = false; - entity->m_level = CTheZones::GetLevelFromPosition(entity->GetPosition()); + entity->m_level = CTheZones::GetLevelFromPosition(&entity->GetPosition()); } RwMatrixDestroy(xform); diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index da9e7d33..dab8bafb 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -2422,7 +2422,7 @@ CStreaming::LoadScene(const CVector &pos) CStreamingInfo *si, *prev; eLevelName level; - level = CTheZones::GetLevelFromPosition(pos); + level = CTheZones::GetLevelFromPosition(&pos); debug("Start load scene\n"); for(si = ms_endRequestedList.m_prev; si != &ms_startRequestedList; si = prev){ prev = si->m_prev; diff --git a/src/core/User.cpp b/src/core/User.cpp index 50eb7d9d..f906ae44 100644 --- a/src/core/User.cpp +++ b/src/core/User.cpp @@ -32,15 +32,15 @@ void CPlaceName::Process() { CVector pos = CWorld::Players[CWorld::PlayerInFocus].GetPos(); - CZone *navigZone = CTheZones::FindSmallestZonePositionType(&pos, ZONE_TYPE1); - CZone *audioZone = CTheZones::FindSmallestZonePositionType(&pos, ZONE_AUDIO); + CZone *navigZone = CTheZones::FindSmallestZonePositionType(&pos, ZONE_NAVIG); + CZone *defaultZone = CTheZones::FindSmallestZonePositionType(&pos, ZONE_DEFAULT); if (navigZone == nil) m_pZone = nil; - if (audioZone == nil) m_pZone2 = nil; + if (defaultZone == nil) m_pZone2 = nil; if (navigZone == m_pZone) { - if (audioZone == m_pZone2 || m_pZone != nil) { - if (navigZone != nil || audioZone != nil) { + if (defaultZone == m_pZone2 || m_pZone != nil) { + if (navigZone != nil || defaultZone != nil) { if (m_nAdditionalTimer != 0) m_nAdditionalTimer--; } else { @@ -49,7 +49,7 @@ CPlaceName::Process() m_pZone2 = nil; } } else { - m_pZone2 = audioZone; + m_pZone2 = defaultZone; m_nAdditionalTimer = 250; } } else { diff --git a/src/core/ZoneCull.cpp b/src/core/ZoneCull.cpp index 780c180e..6dcd0f18 100644 --- a/src/core/ZoneCull.cpp +++ b/src/core/ZoneCull.cpp @@ -533,7 +533,7 @@ CCullZone::IsEntityCloseEnoughToZone(CEntity *entity, bool checkLevel) if (lodDist > distToZone) return true; if (!checkLevel) return false; - return CTheZones::GetLevelFromPosition(pos) == CTheZones::GetLevelFromPosition(CVector(minx, miny, minz)); + return CTheZones::GetLevelFromPosition(&pos) == CTheZones::GetLevelFromPosition(&CVector(minx, miny, minz)); } bool diff --git a/src/core/Zones.cpp b/src/core/Zones.cpp index 804708b4..22c0735a 100644 --- a/src/core/Zones.cpp +++ b/src/core/Zones.cpp @@ -23,6 +23,8 @@ CZoneInfo CTheZones::ZoneInfoArray[2*NUMZONES]; #define SWAPF(a, b) { float t; t = a; a = b; b = t; } +inline bool IsNormalZone(int type) { return type == ZONE_DEFAULT || type == ZONE_NAVIG || type == ZONE_INFO; } + static void CheckZoneInfo(CZoneInfo *info) { @@ -58,6 +60,9 @@ CTheZones::Init(void) AudioZoneArray[i] = -1; NumberOfAudioZones = 0; + for(i = 0; i < NUMZONES; i++) + memset(&ZoneArray[i], 0, sizeof(CZone)); + CZoneInfo *zonei; int x = 1000/6; for(i = 0; i < 2*NUMZONES; i++){ @@ -81,10 +86,13 @@ CTheZones::Init(void) zonei->gangThreshold[8] = zonei->gangThreshold[7]; CheckZoneInfo(zonei); } - TotalNumberOfZoneInfos = 1; // why 1? - for(i = 0; i < NUMZONES; i++) - memset(&ZoneArray[i], 0, sizeof(CZone)); + TotalNumberOfZoneInfos = 1; // why 1? + TotalNumberOfZones = 1; + + m_CurrLevel = LEVEL_NONE; + m_pPlayersZone = &ZoneArray[0]; + strcpy(ZoneArray[0].name, "CITYZON"); ZoneArray[0].minx = -4000.0f; ZoneArray[0].miny = -4000.0f; @@ -93,15 +101,14 @@ CTheZones::Init(void) ZoneArray[0].maxy = 4000.0f; ZoneArray[0].maxz = 500.0f; ZoneArray[0].level = LEVEL_NONE; - TotalNumberOfZones = 1; - - m_CurrLevel = LEVEL_NONE; - m_pPlayersZone = &ZoneArray[0]; for(i = 0; i < NUMMAPZONES; i++){ memset(&MapZoneArray[i], 0, sizeof(CZone)); MapZoneArray[i].type = ZONE_MAPZONE; } + + TotalNumberOfMapZones = 1; + strcpy(MapZoneArray[0].name, "THEMAP"); MapZoneArray[0].minx = -4000.0f; MapZoneArray[0].miny = -4000.0f; @@ -110,7 +117,6 @@ CTheZones::Init(void) MapZoneArray[0].maxy = 4000.0f; MapZoneArray[0].maxz = 500.0f; MapZoneArray[0].level = LEVEL_NONE; - TotalNumberOfMapZones = 1; } void @@ -119,7 +125,7 @@ CTheZones::Update(void) CVector pos; pos = FindPlayerCoors(); m_pPlayersZone = FindSmallestZonePosition(&pos); - m_CurrLevel = GetLevelFromPosition(pos); + m_CurrLevel = GetLevelFromPosition(&pos); } void @@ -128,8 +134,8 @@ CTheZones::CreateZone(char *name, eZoneType type, float maxx, float maxy, float maxz, eLevelName level) { - CZone *zone; char *p; + char tmpname[8]; if(minx > maxx) SWAPF(minx, maxx); if(miny > maxy) SWAPF(miny, maxy); @@ -139,21 +145,22 @@ CTheZones::CreateZone(char *name, eZoneType type, for(p = name; *p; p++) if(islower(*p)) *p = toupper(*p); // add zone - zone = &ZoneArray[TotalNumberOfZones++]; - strncpy(zone->name, name, 7); - zone->name[7] = '\0'; - zone->type = type; - zone->minx = minx; - zone->miny = miny; - zone->minz = minz; - zone->maxx = maxx; - zone->maxy = maxy; - zone->maxz = maxz; - zone->level = level; - if(type == ZONE_AUDIO || type == ZONE_TYPE1 || type == ZONE_TYPE2){ - zone->zoneinfoDay = TotalNumberOfZoneInfos++; - zone->zoneinfoNight = TotalNumberOfZoneInfos++; + strncpy(tmpname, name, 7); + tmpname[7] = '\0'; + strcpy(ZoneArray[TotalNumberOfZones].name, tmpname); + ZoneArray[TotalNumberOfZones].type = type; + ZoneArray[TotalNumberOfZones].minx = minx; + ZoneArray[TotalNumberOfZones].miny = miny; + ZoneArray[TotalNumberOfZones].minz = minz; + ZoneArray[TotalNumberOfZones].maxx = maxx; + ZoneArray[TotalNumberOfZones].maxy = maxy; + ZoneArray[TotalNumberOfZones].maxz = maxz; + ZoneArray[TotalNumberOfZones].level = level; + if(IsNormalZone(type)){ + ZoneArray[TotalNumberOfZones].zoneinfoDay = TotalNumberOfZoneInfos++; + ZoneArray[TotalNumberOfZones].zoneinfoNight = TotalNumberOfZoneInfos++; } + TotalNumberOfZones++; } void @@ -259,11 +266,11 @@ CTheZones::ZoneIsEntirelyContainedWithinOtherZone(CZone *inner, CZone *outer) inner->minz < outer->minz || inner->maxz > outer->maxz){ CVector vmin(inner->minx, inner->miny, inner->minz); - if(PointLiesWithinZone(vmin, outer)) + if(PointLiesWithinZone(&vmin, outer)) sprintf(tmp, "Overlapping zones %s and %s\n", inner->name, outer->name); CVector vmax(inner->maxx, inner->maxy, inner->maxz); - if(PointLiesWithinZone(vmax, outer)) + if(PointLiesWithinZone(&vmax, outer)) sprintf(tmp, "Overlapping zones %s and %s\n", inner->name, outer->name); return false; @@ -272,15 +279,15 @@ CTheZones::ZoneIsEntirelyContainedWithinOtherZone(CZone *inner, CZone *outer) } bool -CTheZones::PointLiesWithinZone(const CVector &v, CZone *zone) +CTheZones::PointLiesWithinZone(const CVector *v, CZone *zone) { - return zone->minx <= v.x && v.x <= zone->maxx && - zone->miny <= v.y && v.y <= zone->maxy && - zone->minz <= v.z && v.z <= zone->maxz; + return zone->minx <= v->x && v->x <= zone->maxx && + zone->miny <= v->y && v->y <= zone->maxy && + zone->minz <= v->z && v->z <= zone->maxz; } eLevelName -CTheZones::GetLevelFromPosition(CVector const &v) +CTheZones::GetLevelFromPosition(CVector const *v) { int i; // char tmp[116]; @@ -300,7 +307,7 @@ CTheZones::FindSmallestZonePosition(const CVector *v) CZone *zone = ZoneArray[0].child; while(zone) // if in zone, descent into children - if(PointLiesWithinZone(*v, zone)){ + if(PointLiesWithinZone(v, zone)){ best = zone; zone = zone->child; // otherwise try next zone @@ -319,7 +326,7 @@ CTheZones::FindSmallestZonePositionType(const CVector *v, eZoneType type) CZone *zone = ZoneArray[0].child; while(zone) // if in zone, descent into children - if(PointLiesWithinZone(*v, zone)){ + if(PointLiesWithinZone(v, zone)){ if(zone->type == type) best = zone; zone = zone->child; @@ -333,18 +340,14 @@ CZone* CTheZones::FindSmallestZonePositionILN(const CVector *v) { CZone *best = nil; - if(ZoneArray[0].type == ZONE_AUDIO || - ZoneArray[0].type == ZONE_TYPE1 || - ZoneArray[0].type == ZONE_TYPE2) + if(IsNormalZone(ZoneArray[0].type)) best = &ZoneArray[0]; // zone to test next CZone *zone = ZoneArray[0].child; while(zone) // if in zone, descent into children - if(PointLiesWithinZone(*v, zone)){ - if(zone->type == ZONE_AUDIO || - zone->type == ZONE_TYPE1 || - zone->type == ZONE_TYPE2) + if(PointLiesWithinZone(v, zone)){ + if(IsNormalZone(zone->type)) best = zone; zone = zone->child; // otherwise try next zone @@ -532,7 +535,7 @@ CTheZones::SetCarDensity(uint16 zoneid, uint8 day, uint16 cardensity) { CZone *zone; zone = GetZone(zoneid); - if(zone->type == ZONE_AUDIO || zone->type == ZONE_TYPE1 || zone->type == ZONE_TYPE2) + if(IsNormalZone(zone->type)) ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].carDensity = cardensity; } @@ -541,7 +544,7 @@ CTheZones::SetPedDensity(uint16 zoneid, uint8 day, uint16 peddensity) { CZone *zone; zone = GetZone(zoneid); - if(zone->type == ZONE_AUDIO || zone->type == ZONE_TYPE1 || zone->type == ZONE_TYPE2) + if(IsNormalZone(zone->type)) ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].pedDensity = peddensity; } @@ -550,7 +553,7 @@ CTheZones::SetPedGroup(uint16 zoneid, uint8 day, uint16 pedgroup) { CZone *zone; zone = GetZone(zoneid); - if(zone->type == ZONE_AUDIO || zone->type == ZONE_TYPE1 || zone->type == ZONE_TYPE2) + if(IsNormalZone(zone->type)) ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].pedGroup = pedgroup; } @@ -560,7 +563,7 @@ CTheZones::FindAudioZone(CVector *pos) int i; for(i = 0; i < NumberOfAudioZones; i++) - if(PointLiesWithinZone(*pos, GetZone(AudioZoneArray[i]))) + if(PointLiesWithinZone(pos, GetAudioZone(i))) return i; return -1; } @@ -568,11 +571,11 @@ CTheZones::FindAudioZone(CVector *pos) eLevelName CTheZones::FindZoneForPoint(const CVector &pos) { - if(PointLiesWithinZone(pos, GetZone(FindZoneByLabelAndReturnIndex("IND_ZON")))) + if(PointLiesWithinZone(&pos, GetZone(FindZoneByLabelAndReturnIndex("IND_ZON")))) return LEVEL_INDUSTRIAL; - if(PointLiesWithinZone(pos, GetZone(FindZoneByLabelAndReturnIndex("COM_ZON")))) + if(PointLiesWithinZone(&pos, GetZone(FindZoneByLabelAndReturnIndex("COM_ZON")))) return LEVEL_COMMERCIAL; - if(PointLiesWithinZone(pos, GetZone(FindZoneByLabelAndReturnIndex("SUB_ZON")))) + if(PointLiesWithinZone(&pos, GetZone(FindZoneByLabelAndReturnIndex("SUB_ZON")))) return LEVEL_SUBURBAN; return LEVEL_NONE; } @@ -582,7 +585,7 @@ CTheZones::AddZoneToAudioZoneArray(CZone *zone) { int i, z; - if(zone->type != ZONE_AUDIO) + if(zone->type != ZONE_DEFAULT) return; /* This is a bit stupid */ diff --git a/src/core/Zones.h b/src/core/Zones.h index bb1585dc..67800569 100644 --- a/src/core/Zones.h +++ b/src/core/Zones.h @@ -5,9 +5,9 @@ enum eZoneType { - ZONE_AUDIO, - ZONE_TYPE1, // this should be NAVIG - ZONE_TYPE2, // this should be INFO...but all except MAPINFO get zoneinfo?? + ZONE_DEFAULT, + ZONE_NAVIG, + ZONE_INFO, ZONE_MAPZONE, }; @@ -51,8 +51,6 @@ public: class CTheZones { -public: - static eLevelName m_CurrLevel; static CZone *m_pPlayersZone; static int16 FindIndex; @@ -64,6 +62,8 @@ public: static CZone MapZoneArray[NUMMAPZONES]; static uint16 TotalNumberOfZoneInfos; static CZoneInfo ZoneInfoArray[2*NUMZONES]; +public: + static eLevelName m_CurrLevel; static void Init(void); static void Update(void); @@ -76,12 +76,13 @@ public: float maxx, float maxy, float maxz, eLevelName level); static CZone *GetZone(uint16 i) { return &ZoneArray[i]; } + static CZone *GetAudioZone(uint16 i) { return &ZoneArray[AudioZoneArray[i]]; } static void PostZoneCreation(void); static void InsertZoneIntoZoneHierarchy(CZone *zone); static bool InsertZoneIntoZoneHierRecursive(CZone *z1, CZone *z2); static bool ZoneIsEntirelyContainedWithinOtherZone(CZone *z1, CZone *z2); - static bool PointLiesWithinZone(const CVector &v, CZone *zone); - static eLevelName GetLevelFromPosition(CVector const &v); + static bool PointLiesWithinZone(const CVector *v, CZone *zone); + static eLevelName GetLevelFromPosition(const CVector *v); static CZone *FindSmallestZonePosition(const CVector *v); static CZone *FindSmallestZonePositionType(const CVector *v, eZoneType type); static CZone *FindSmallestZonePositionILN(const CVector *v); diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp index e2b91552..ec50dd30 100644 --- a/src/entities/Entity.cpp +++ b/src/entities/Entity.cpp @@ -331,7 +331,7 @@ CEntity::SetupBigBuilding(void) bIsBIGBuilding = true; bStreamingDontDelete = true; bUsesCollision = false; - m_level = CTheZones::GetLevelFromPosition(GetPosition()); + m_level = CTheZones::GetLevelFromPosition(&GetPosition()); if(m_level == LEVEL_NONE){ if(mi->GetTxdSlot() != CTxdStore::FindTxdSlot("generic")){ mi->SetTexDictionary("generic"); diff --git a/src/peds/Population.cpp b/src/peds/Population.cpp index ce781983..1566ba3d 100644 --- a/src/peds/Population.cpp +++ b/src/peds/Population.cpp @@ -396,7 +396,7 @@ CPopulation::FindCollisionZoneForCoors(CVector *coors, int *safeZoneOut, eLevelN if (*safeZoneOut >= 0) *levelOut = LEVEL_NONE; else - *levelOut = CTheZones::GetLevelFromPosition(*coors); + *levelOut = CTheZones::GetLevelFromPosition(coors); } void From e0568a19d52e7aebef65960df93a90d0693c7b56 Mon Sep 17 00:00:00 2001 From: aap Date: Wed, 6 May 2020 12:23:57 +0200 Subject: [PATCH 4/5] new zone stuff --- src/audio/PoliceRadio.cpp | 4 +- src/control/Replay.cpp | 4 +- src/control/Restart.cpp | 8 +- src/control/Script.cpp | 93 +++----- src/core/FileLoader.cpp | 4 +- src/core/Game.cpp | 3 - src/core/Streaming.cpp | 2 +- src/core/User.cpp | 12 +- src/core/ZoneCull.cpp | 448 +------------------------------------- src/core/ZoneCull.h | 68 ------ src/core/Zones.cpp | 388 +++++++++++++++++++++------------ src/core/Zones.h | 41 ++-- src/core/config.h | 11 +- src/entities/Entity.cpp | 2 +- src/peds/Population.cpp | 2 +- src/render/Renderer.cpp | 149 ++++--------- src/render/Renderer.h | 4 - 17 files changed, 386 insertions(+), 857 deletions(-) diff --git a/src/audio/PoliceRadio.cpp b/src/audio/PoliceRadio.cpp index 5470a1af..ec02368e 100644 --- a/src/audio/PoliceRadio.cpp +++ b/src/audio/PoliceRadio.cpp @@ -306,7 +306,7 @@ cAudioManager::SetupCrimeReport() if (i == ARRAY_SIZE(m_sPoliceRadioQueue.crimes)) return false; audioZoneId = CTheZones::FindAudioZone(&m_sPoliceRadioQueue.crimes[i].position); if (audioZoneId >= 0 && audioZoneId < NUMAUDIOZONES) { - zone = &CTheZones::ZoneArray[CTheZones::AudioZoneArray[audioZoneId]]; + zone = CTheZones::GetAudioZone(audioZoneId); for (int j = 0; j < NUMAUDIOZONES; j++) { if (strcmp(zone->name, ZoneSfx[j].m_aName) == 0) { sampleIndex = ZoneSfx[j].m_nSampleIndex; @@ -722,7 +722,7 @@ cAudioManager::PlaySuspectLastSeen(float x, float y, float z) if (MusicManager.m_nMusicMode != MUSICMODE_CUTSCENE && 60 - m_sPoliceRadioQueue.policeChannelTimer > 9) { audioZone = CTheZones::FindAudioZone(&vec); if (audioZone >= 0 && audioZone < NUMAUDIOZONES) { - zone = &CTheZones::ZoneArray[CTheZones::AudioZoneArray[audioZone]]; + zone = CTheZones::GetAudioZone(audioZone); for (int i = 0; i < NUMAUDIOZONES; i++) { if (strcmp(zone->name, ZoneSfx[i].m_aName) == 0) { sample = ZoneSfx[i].m_nSampleIndex; diff --git a/src/control/Replay.cpp b/src/control/Replay.cpp index fd5448cc..707f1d87 100644 --- a/src/control/Replay.cpp +++ b/src/control/Replay.cpp @@ -987,7 +987,7 @@ void CReplay::FinishPlayback(void) Mode = MODE_RECORD; if (bDoLoadSceneWhenDone){ CVector v_ls(LoadSceneX, LoadSceneY, LoadSceneZ); - CGame::currLevel = CTheZones::GetLevelFromPosition(v_ls); + CGame::currLevel = CTheZones::GetLevelFromPosition(&v_ls); CCollision::SortOutCollisionAfterLoad(); CStreaming::LoadScene(v_ls); } @@ -1101,7 +1101,7 @@ void CReplay::TriggerPlayback(uint8 cam_mode, float cam_x, float cam_y, float ca LoadSceneZ = TheCamera.GetPosition().z; CVector ff_coord; FindFirstFocusCoordinate(&ff_coord); - CGame::currLevel = CTheZones::GetLevelFromPosition(ff_coord); + CGame::currLevel = CTheZones::GetLevelFromPosition(&ff_coord); CCollision::SortOutCollisionAfterLoad(); CStreaming::LoadScene(ff_coord); } diff --git a/src/control/Restart.cpp b/src/control/Restart.cpp index 3926db45..64cabf5d 100644 --- a/src/control/Restart.cpp +++ b/src/control/Restart.cpp @@ -80,13 +80,13 @@ CRestart::FindClosestHospitalRestartPoint(const CVector &pos, CVector *outPos, f return; } - eLevelName curlevel = CTheZones::GetLevelFromPosition(pos); + eLevelName curlevel = CTheZones::GetLevelFromPosition(&pos); float fMinDist = 16000000.0f; int closestPoint = NUM_RESTART_POINTS; // find closest point on this level for (int i = 0; i < NumberOfHospitalRestarts; i++) { - if (CTheZones::GetLevelFromPosition(HospitalRestartPoints[i]) == (OverrideHospitalLevel != LEVEL_NONE ? OverrideHospitalLevel : curlevel)) { + if (CTheZones::GetLevelFromPosition(&HospitalRestartPoints[i]) == (OverrideHospitalLevel != LEVEL_NONE ? OverrideHospitalLevel : curlevel)) { float dist = (pos - HospitalRestartPoints[i]).MagnitudeSqr(); if (fMinDist >= dist) { fMinDist = dist; @@ -127,13 +127,13 @@ CRestart::FindClosestPoliceRestartPoint(const CVector &pos, CVector *outPos, flo return; } - eLevelName curlevel = CTheZones::GetLevelFromPosition(pos); + eLevelName curlevel = CTheZones::GetLevelFromPosition(&pos); float fMinDist = 16000000.0f; int closestPoint = NUM_RESTART_POINTS; // find closest point on this level for (int i = 0; i < NumberOfPoliceRestarts; i++) { - if (CTheZones::GetLevelFromPosition(PoliceRestartPoints[i]) == (OverridePoliceStationLevel != LEVEL_NONE ? OverridePoliceStationLevel : curlevel)) { + if (CTheZones::GetLevelFromPosition(&PoliceRestartPoints[i]) == (OverridePoliceStationLevel != LEVEL_NONE ? OverridePoliceStationLevel : curlevel)) { float dist = (pos - PoliceRestartPoints[i]).MagnitudeSqr(); if (fMinDist >= dist) { fMinDist = dist; diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 72a14fe2..8db2db81 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -1729,7 +1729,7 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) ped->SetOrientation(0.0f, 0.0f, 0.0f); CTheScripts::ClearSpaceForMissionEntity(pos, ped); CWorld::Add(ped); - ped->m_nZoneLevel = CTheZones::GetLevelFromPosition(pos); + ped->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pos); CPopulation::ms_nTotalMissionPeds++; ScriptParams[0] = CPools::GetPedPool()->GetIndex(ped); StoreParameters(&m_nIp, 1); @@ -1968,7 +1968,7 @@ int8 CRunningScript::ProcessCommands100To199(int32 command) car->AutoPilot.m_nCruiseSpeed = car->AutoPilot.m_fMaxTrafficSpeed = 9.0f; car->AutoPilot.m_nCurrentLane = car->AutoPilot.m_nNextLane = 0; car->bEngineOn = false; - car->m_nZoneLevel = CTheZones::GetLevelFromPosition(pos); + car->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pos); car->bHasBeenOwnedByPlayer = true; CWorld::Add(car); handle = CPools::GetVehiclePool()->GetIndex(car); @@ -2669,12 +2669,12 @@ int8 CRunningScript::ProcessCommands200To299(int32 command) CPlayerInfo* pPlayer = &CWorld::Players[ScriptParams[0]]; char label[12]; CTheScripts::ReadTextLabelFromScript(&m_nIp, label); - int zoneToCheck = CTheZones::FindZoneByLabelAndReturnIndex(label); + int zoneToCheck = CTheZones::FindZoneByLabelAndReturnIndex(label, ZONE_DEFAULT); if (zoneToCheck != -1) m_nIp += KEY_LENGTH_IN_SCRIPT; /* why only if zone != 1? */ CVector pos = pPlayer->GetPos(); - CZone* pZone = CTheZones::GetZone(zoneToCheck); - UpdateCompareFlag(CTheZones::PointLiesWithinZone(pos, pZone)); + CZone* pZone = CTheZones::GetNavigationZone(zoneToCheck); + UpdateCompareFlag(CTheZones::PointLiesWithinZone(&pos, pZone)); return 0; } case COMMAND_IS_PLAYER_PRESSING_HORN: @@ -2773,7 +2773,7 @@ int8 CRunningScript::ProcessCommands200To299(int32 command) #endif pPed->m_pVehicleAnim = CAnimManager::BlendAnimation(pPed->GetClump(), ASSOCGRP_STD, anim, 100.0f); pPed->StopNonPartialAnims(); - pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(pPed->GetPosition()); + pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pPed->GetPosition()); CWorld::Add(pPed); ScriptParams[0] = CPools::GetPedPool()->GetIndex(pPed); StoreParameters(&m_nIp, 1); @@ -3001,7 +3001,7 @@ int8 CRunningScript::ProcessCommands300To399(int32 command) CTheScripts::ReadTextLabelFromScript(&m_nIp, label); m_nIp += KEY_LENGTH_IN_SCRIPT; CollectParameters(&m_nIp, 16); - int zone = CTheZones::FindZoneByLabelAndReturnIndex(label); + int zone = CTheZones::FindZoneByLabelAndReturnIndex(label, ZONE_INFO); if (zone < 0) { debug("Couldn't find zone - %s\n", label); return 0; @@ -3022,41 +3022,17 @@ int8 CRunningScript::ProcessCommands300To399(int32 command) assert(pPed); char label[12]; CTheScripts::ReadTextLabelFromScript(&m_nIp, label); - int zone = CTheZones::FindZoneByLabelAndReturnIndex(label); + int zone = CTheZones::FindZoneByLabelAndReturnIndex(label, ZONE_DEFAULT); if (zone != -1) m_nIp += KEY_LENGTH_IN_SCRIPT; CVector pos = pPed->bInVehicle ? pPed->m_pMyVehicle->GetPosition() : pPed->GetPosition(); - UpdateCompareFlag(CTheZones::PointLiesWithinZone(pos, CTheZones::GetZone(zone))); + UpdateCompareFlag(CTheZones::PointLiesWithinZone(&pos, CTheZones::GetNavigationZone(zone))); return 0; } + /* Not implemented. case COMMAND_SET_CAR_DENSITY: - { - char label[12]; - CTheScripts::ReadTextLabelFromScript(&m_nIp, label); - int16 zone = CTheZones::FindZoneByLabelAndReturnIndex(label); - m_nIp += 8; - CollectParameters(&m_nIp, 2); - if (zone < 0) { - debug("Couldn't find zone - %s\n", label); - return 0; - } - CTheZones::SetCarDensity(zone, ScriptParams[0], ScriptParams[1]); - return 0; - } case COMMAND_SET_PED_DENSITY: - { - char label[12]; - CTheScripts::ReadTextLabelFromScript(&m_nIp, label); - int16 zone = CTheZones::FindZoneByLabelAndReturnIndex(label); - m_nIp += KEY_LENGTH_IN_SCRIPT; - CollectParameters(&m_nIp, 2); - if (zone < 0) { - debug("Couldn't find zone - %s\n", label); - return 0; - } - CTheZones::SetPedDensity(zone, ScriptParams[0], ScriptParams[1]); - return 0; - } + */ case COMMAND_POINT_CAMERA_AT_PLAYER: { CollectParameters(&m_nIp, 3); @@ -3092,7 +3068,7 @@ int8 CRunningScript::ProcessCommands300To399(int32 command) CTheScripts::ReadTextLabelFromScript(&m_nIp, label); m_nIp += KEY_LENGTH_IN_SCRIPT; CollectParameters(&m_nIp, 10); - int16 zone = CTheZones::FindZoneByLabelAndReturnIndex(label); + int16 zone = CTheZones::FindZoneByLabelAndReturnIndex(label, ZONE_INFO); if (zone < 0) { debug("Couldn't find zone - %s\n", label); return 0; @@ -3964,7 +3940,7 @@ int8 CRunningScript::ProcessCommands400To499(int32 command) #endif pPed->m_pVehicleAnim = CAnimManager::BlendAnimation(pPed->GetClump(), ASSOCGRP_STD, anim, 100.0f); pPed->StopNonPartialAnims(); - pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(pPed->GetPosition()); + pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pPed->GetPosition()); CWorld::Add(pPed); ScriptParams[0] = CPools::GetPedPool()->GetIndex(pPed); StoreParameters(&m_nIp, 1); @@ -5853,10 +5829,10 @@ int8 CRunningScript::ProcessCommands700To799(int32 command) { char zone[KEY_LENGTH_IN_SCRIPT]; strncpy(zone, (const char*)&CTheScripts::ScriptSpace[m_nIp], KEY_LENGTH_IN_SCRIPT); - int nZone = CTheZones::FindZoneByLabelAndReturnIndex(zone); + int nZone = CTheZones::FindZoneByLabelAndReturnIndex(zone, ZONE_DEFAULT); if (nZone != -1) m_nIp += KEY_LENGTH_IN_SCRIPT; - CZone* pZone = CTheZones::GetZone(nZone); + CZone* pZone = CTheZones::GetNavigationZone(nZone); int ped_handle = -1; CVector pos = FindPlayerCoors(); int i = CPools::GetPedPool()->GetSize(); @@ -5880,7 +5856,7 @@ int8 CRunningScript::ProcessCommands700To799(int32 command) continue; if (pPed->bIsLeader || pPed->m_leader) continue; - if (!CTheZones::PointLiesWithinZone(pPed->GetPosition(), pZone)) + if (!CTheZones::PointLiesWithinZone(&pPed->GetPosition(), pZone)) continue; if (pos.z - PED_FIND_Z_OFFSET > pPed->GetPosition().z) continue; @@ -6461,7 +6437,7 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) CTheScripts::ReadTextLabelFromScript(&m_nIp, zone); m_nIp += KEY_LENGTH_IN_SCRIPT; CollectParameters(&m_nIp, 2); - int zone_id = CTheZones::FindZoneByLabelAndReturnIndex(zone); + int zone_id = CTheZones::FindZoneByLabelAndReturnIndex(zone, ZONE_INFO); if (zone_id < 0) { printf("Couldn't find zone - %s\n", zone); return 0; @@ -6521,10 +6497,11 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) { char zone[KEY_LENGTH_IN_SCRIPT]; CTheScripts::ReadTextLabelFromScript(&m_nIp, zone); - int zone_id = CTheZones::FindZoneByLabelAndReturnIndex(zone); +// TODO(MIAMI): just getting this to compile with new argument + int zone_id = CTheZones::FindZoneByLabelAndReturnIndex(zone, ZONE_DEFAULT); if (zone_id != -1) m_nIp += KEY_LENGTH_IN_SCRIPT; - CZone* pZone = CTheZones::GetZone(zone_id); + CZone* pZone = CTheZones::GetNavigationZone(zone_id); CollectParameters(&m_nIp, 1); int handle = -1; uint32 i = CPools::GetVehiclePool()->GetSize(); @@ -6536,7 +6513,7 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) continue; if (pVehicle->VehicleCreatedBy != RANDOM_VEHICLE) continue; - if (!CTheZones::PointLiesWithinZone(pVehicle->GetPosition(), pZone)) + if (!CTheZones::PointLiesWithinZone(&pVehicle->GetPosition(), pZone)) continue; handle = CPools::GetVehiclePool()->GetIndex(pVehicle); pVehicle->VehicleCreatedBy = MISSION_VEHICLE; @@ -7027,10 +7004,11 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) CollectParameters(&m_nIp, 1); char zone[KEY_LENGTH_IN_SCRIPT]; CTheScripts::ReadTextLabelFromScript(&m_nIp, zone); - int zone_id = CTheZones::FindZoneByLabelAndReturnIndex(zone); +// TODO(MIAMI): just getting this to compile with new argument + int zone_id = CTheZones::FindZoneByLabelAndReturnIndex(zone, ZONE_DEFAULT); if (zone_id != -1) m_nIp += KEY_LENGTH_IN_SCRIPT; - CZone* pZone = CTheZones::GetZone(zone_id); + CZone* pZone = CTheZones::GetNavigationZone(zone_id); UpdateCompareFlag(CExplosion::TestForExplosionInArea((eExplosionType)ScriptParams[0], pZone->minx, pZone->maxx, pZone->miny, pZone->maxy, pZone->minz, pZone->maxz)); return 0; @@ -7162,7 +7140,7 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) if (total == 0) CWorld::FindObjectsOfTypeInRangeSectorList(mi, CWorld::GetBigBuildingList(LEVEL_NONE), pos, range, true, &total, 16, apEntities); if (total == 0) - CWorld::FindObjectsOfTypeInRangeSectorList(mi, CWorld::GetBigBuildingList(CTheZones::GetLevelFromPosition(pos)), pos, range, true, &total, 16, apEntities); + CWorld::FindObjectsOfTypeInRangeSectorList(mi, CWorld::GetBigBuildingList(CTheZones::GetLevelFromPosition(&pos)), pos, range, true, &total, 16, apEntities); CEntity* pClosestEntity = nil; float min_dist = 2.0f * range; for (int i = 0; i < total; i++) { @@ -7347,7 +7325,7 @@ int8 CRunningScript::ProcessCommands800To899(int32 command) ped->SetOrientation(0.0f, 0.0f, 0.0f); CTheScripts::ClearSpaceForMissionEntity(pos, ped); CWorld::Add(ped); - ped->m_nZoneLevel = CTheZones::GetLevelFromPosition(pos); + ped->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pos); CPopulation::ms_nTotalMissionPeds++; ScriptParams[0] = CPools::GetPedPool()->GetIndex(ped); StoreParameters(&m_nIp, 1); @@ -7914,7 +7892,7 @@ int8 CRunningScript::ProcessCommands900To999(int32 command) if (total == 0) CWorld::FindObjectsOfTypeInRangeSectorList(mi1, CWorld::GetBigBuildingList(LEVEL_NONE), pos, radius, true, &total, 16, apEntities); if (total == 0) - CWorld::FindObjectsOfTypeInRangeSectorList(mi1, CWorld::GetBigBuildingList(CTheZones::GetLevelFromPosition(pos)), pos, radius, true, &total, 16, apEntities); + CWorld::FindObjectsOfTypeInRangeSectorList(mi1, CWorld::GetBigBuildingList(CTheZones::GetLevelFromPosition(&pos)), pos, radius, true, &total, 16, apEntities); CEntity* pClosestEntity = nil; float min_dist = 2.0f * radius; for (int i = 0; i < total; i++) { @@ -8178,7 +8156,7 @@ int8 CRunningScript::ProcessCommands900To999(int32 command) car->AutoPilot.m_nCruiseSpeed = car->AutoPilot.m_fMaxTrafficSpeed = 9.0f; car->AutoPilot.m_nCurrentLane = car->AutoPilot.m_nNextLane = 0; car->bEngineOn = false; - car->m_nZoneLevel = CTheZones::GetLevelFromPosition(pos); + car->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pos); CWorld::Add(car); return 0; } @@ -8504,7 +8482,7 @@ int8 CRunningScript::ProcessCommands1000To1099(int32 command) CVehicle* pVehicle = CPools::GetVehiclePool()->GetAt(ScriptParams[0]); assert(pVehicle); if (ScriptParams[1]) - pVehicle->m_nZoneLevel = CTheZones::GetLevelFromPosition(pVehicle->GetPosition()); + pVehicle->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pVehicle->GetPosition()); else pVehicle->m_nZoneLevel = LEVEL_NONE; return 0; @@ -8515,7 +8493,7 @@ int8 CRunningScript::ProcessCommands1000To1099(int32 command) CPed* pPed = CPools::GetPedPool()->GetAt(ScriptParams[0]); assert(pPed); if (ScriptParams[1]) - pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(pPed->GetPosition()); + pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pPed->GetPosition()); else pPed->m_nZoneLevel = LEVEL_NONE; return 0; @@ -8920,7 +8898,7 @@ int8 CRunningScript::ProcessCommands1000To1099(int32 command) if (ScriptParams[1]) pPed->m_nZoneLevel = LEVEL_IGNORE; else - pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(pPed->GetPosition()); + pPed->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pPed->GetPosition()); return 0; } case COMMAND_GET_CHASE_CAR: @@ -9119,7 +9097,7 @@ int8 CRunningScript::ProcessCommands1100To1199(int32 command) if (ScriptParams[1]) pVehicle->m_nZoneLevel = LEVEL_IGNORE; else - pVehicle->m_nZoneLevel = CTheZones::GetLevelFromPosition(pVehicle->GetPosition()); + pVehicle->m_nZoneLevel = CTheZones::GetLevelFromPosition(&pVehicle->GetPosition()); return 0; } case COMMAND_MAKE_CRAIGS_CAR_A_BIT_STRONGER: @@ -9440,10 +9418,11 @@ int8 CRunningScript::ProcessCommands1100To1199(int32 command) { char zone[KEY_LENGTH_IN_SCRIPT]; strncpy(zone, (const char*)&CTheScripts::ScriptSpace[m_nIp], KEY_LENGTH_IN_SCRIPT); - int nZone = CTheZones::FindZoneByLabelAndReturnIndex(zone); +// TODO(MIAMI): just getting this to compile with new argument + int nZone = CTheZones::FindZoneByLabelAndReturnIndex(zone, ZONE_DEFAULT); if (nZone != -1) m_nIp += KEY_LENGTH_IN_SCRIPT; - CZone* pZone = CTheZones::GetZone(nZone); + CZone* pZone = CTheZones::GetNavigationZone(nZone); int ped_handle = -1; CVector pos = FindPlayerCoors(); int i = CPools::GetPedPool()->GetSize(); @@ -9465,7 +9444,7 @@ int8 CRunningScript::ProcessCommands1100To1199(int32 command) continue; if (pPed->bIsLeader || pPed->m_leader) continue; - if (!CTheZones::PointLiesWithinZone(pPed->GetPosition(), pZone)) + if (!CTheZones::PointLiesWithinZone(&pPed->GetPosition(), pZone)) continue; if (pos.z - PED_FIND_Z_OFFSET > pPed->GetPosition().z) continue; diff --git a/src/core/FileLoader.cpp b/src/core/FileLoader.cpp index fee15a04..9e7423f4 100644 --- a/src/core/FileLoader.cpp +++ b/src/core/FileLoader.cpp @@ -1139,7 +1139,7 @@ CFileLoader::LoadObjectInstance(const char *line) entity = new CBuilding; entity->SetModelIndexNoCreate(id); entity->GetMatrix() = CMatrix(xform); - entity->m_level = CTheZones::GetLevelFromPosition(entity->GetPosition()); + entity->m_level = CTheZones::GetLevelFromPosition(&entity->GetPosition()); entity->m_area = area; if(mi->IsSimple()){ if(mi->m_isBigBuilding) @@ -1165,7 +1165,7 @@ CFileLoader::LoadObjectInstance(const char *line) CWorld::Add(entity); if(IsGlass(entity->GetModelIndex()) && !mi->m_isArtistGlass) entity->bIsVisible = false; - entity->m_level = CTheZones::GetLevelFromPosition(entity->GetPosition()); + entity->m_level = CTheZones::GetLevelFromPosition(&entity->GetPosition()); entity->m_area = area; } diff --git a/src/core/Game.cpp b/src/core/Game.cpp index a2ec362c..22d4de99 100644 --- a/src/core/Game.cpp +++ b/src/core/Game.cpp @@ -483,9 +483,6 @@ void CGame::ReInitGameObjectVariables(void) CSpecialFX::Init(); CWaterCannons::Init(); CParticle::ReloadConfig(); -#ifdef GTA_ZONECULL - CCullZones::ResolveVisibilities(); -#endif if ( !FrontEndMenuManager.m_bWantToLoad ) { diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index a347bc78..52886604 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -2405,7 +2405,7 @@ CStreaming::LoadScene(const CVector &pos) CStreamingInfo *si, *prev; eLevelName level; - level = CTheZones::GetLevelFromPosition(pos); + level = CTheZones::GetLevelFromPosition(&pos); debug("Start load scene\n"); for(si = ms_endRequestedList.m_prev; si != &ms_startRequestedList; si = prev){ prev = si->m_prev; diff --git a/src/core/User.cpp b/src/core/User.cpp index 50eb7d9d..716d6393 100644 --- a/src/core/User.cpp +++ b/src/core/User.cpp @@ -32,15 +32,15 @@ void CPlaceName::Process() { CVector pos = CWorld::Players[CWorld::PlayerInFocus].GetPos(); - CZone *navigZone = CTheZones::FindSmallestZonePositionType(&pos, ZONE_TYPE1); - CZone *audioZone = CTheZones::FindSmallestZonePositionType(&pos, ZONE_AUDIO); + CZone *navigZone = CTheZones::FindSmallestNavigationZoneForPosition(&pos, false, true); + CZone *defaultZone = CTheZones::FindSmallestNavigationZoneForPosition(&pos, true, false); if (navigZone == nil) m_pZone = nil; - if (audioZone == nil) m_pZone2 = nil; + if (defaultZone == nil) m_pZone2 = nil; if (navigZone == m_pZone) { - if (audioZone == m_pZone2 || m_pZone != nil) { - if (navigZone != nil || audioZone != nil) { + if (defaultZone == m_pZone2 || m_pZone != nil) { + if (navigZone != nil || defaultZone != nil) { if (m_nAdditionalTimer != 0) m_nAdditionalTimer--; } else { @@ -49,7 +49,7 @@ CPlaceName::Process() m_pZone2 = nil; } } else { - m_pZone2 = audioZone; + m_pZone2 = defaultZone; m_nAdditionalTimer = 250; } } else { diff --git a/src/core/ZoneCull.cpp b/src/core/ZoneCull.cpp index 1e9c00f0..729cc35d 100644 --- a/src/core/ZoneCull.cpp +++ b/src/core/ZoneCull.cpp @@ -11,228 +11,32 @@ #include "ZoneCull.h" #include "Zones.h" -int32 CCullZones::NumCullZones; -CCullZone CCullZones::aZones[NUMCULLZONES]; int32 CCullZones::NumAttributeZones; CAttributeZone CCullZones::aAttributeZones[NUMATTRIBZONES]; -uint16 CCullZones::aIndices[NUMZONEINDICES]; -int16 CCullZones::aPointersToBigBuildingsForBuildings[NUMBUILDINGS]; -int16 CCullZones::aPointersToBigBuildingsForTreadables[NUMTREADABLES]; int32 CCullZones::CurrentWantedLevelDrop_Player; int32 CCullZones::CurrentFlags_Camera; int32 CCullZones::CurrentFlags_Player; -int32 CCullZones::OldCullZone; -int32 CCullZones::EntityIndicesUsed; bool CCullZones::bCurrentSubwayIsInvisible; -bool CCullZones::bCullZonesDisabled; - void CCullZones::Init(void) { - int i; - NumAttributeZones = 0; CurrentWantedLevelDrop_Player = 0; CurrentFlags_Camera = 0; CurrentFlags_Player = 0; bCurrentSubwayIsInvisible = false; -#ifdef GTA_ZONECULL - NumCullZones = 0; - OldCullZone = -1; - EntityIndicesUsed = 0; - - for(i = 0; i < NUMBUILDINGS; i++) - aPointersToBigBuildingsForBuildings[i] = -1; - for(i = 0; i < NUMTREADABLES; i++) - aPointersToBigBuildingsForTreadables[i] = -1; -#endif } -#ifdef GTA_ZONECULL -bool CCullZone::TestLine(CVector vec1, CVector vec2) -{ - CColPoint colPoint; - CEntity *entity; - - if (CWorld::ProcessLineOfSight(vec1, vec2, colPoint, entity, true, false, false, false, false, true, false)) - return true; - if (CWorld::ProcessLineOfSight(CVector(vec1.x + 0.05f, vec1.y, vec1.z), CVector(vec2.x + 0.05f, vec2.y, vec2.z), colPoint, entity, true, false, false, false, false, true, false)) - return true; - if (CWorld::ProcessLineOfSight(CVector(vec1.x - 0.05f, vec1.y, vec1.z), CVector(vec2.x - 0.05f, vec2.y, vec2.z), colPoint, entity, true, false, false, false, false, true, false)) - return true; - if (CWorld::ProcessLineOfSight(CVector(vec1.x, vec1.y + 0.05f, vec1.z), CVector(vec2.x, vec2.y + 0.05f, vec2.z), colPoint, entity, true, false, false, false, false, true, false)) - return true; - if (CWorld::ProcessLineOfSight(CVector(vec1.x, vec1.y - 0.05f, vec1.z), CVector(vec2.x, vec2.y - 0.05f, vec2.z), colPoint, entity, true, false, false, false, false, true, false)) - return true; - if (CWorld::ProcessLineOfSight(CVector(vec1.x, vec1.y, vec1.z + 0.05f), CVector(vec2.x, vec2.y, vec2.z + 0.05f), colPoint, entity, true, false, false, false, false, true, false)) - return true; - return CWorld::ProcessLineOfSight(CVector(vec1.x, vec1.y, vec1.z - 0.05f), CVector(vec2.x, vec2.y, vec2.z - 0.05f), colPoint, entity, true, false, false, false, false, true, false); -} - - -uint16* pTempArrayIndices; -int TempEntityIndicesUsed; - -void -CCullZones::ResolveVisibilities(void) -{ - int fd; - - CFileMgr::SetDir(""); - fd = CFileMgr::OpenFile("DATA\\cullzone.dat", "rb"); - if(fd > 0){ - CFileMgr::Read(fd, (char*)&NumCullZones, sizeof(NumCullZones)); - CFileMgr::Read(fd, (char*)aZones, sizeof(aZones)); - CFileMgr::Read(fd, (char*)&NumAttributeZones, sizeof(NumAttributeZones)); - CFileMgr::Read(fd, (char*)aAttributeZones, sizeof(aAttributeZones)); - CFileMgr::Read(fd, (char*)aIndices, sizeof(aIndices)); - CFileMgr::Read(fd, (char*)aPointersToBigBuildingsForBuildings, sizeof(aPointersToBigBuildingsForBuildings)); - CFileMgr::Read(fd, (char*)aPointersToBigBuildingsForTreadables, sizeof(aPointersToBigBuildingsForTreadables)); - CFileMgr::CloseFile(fd); - }else{ -#if 0 - // TODO: implement code from mobile to generate data here - EntityIndicesUsed = 0; - BuildListForBigBuildings(); - pTempArrayIndices = new uint16[140000]; - TempEntityIndicesUsed = 0; - - for (int i = 0; i < NumCullZones; i++) { - DoVisibilityTestCullZone(i, true); - } - - CompressIndicesArray(); - delete[] pTempArrayIndices; - - fd = CFileMgr::OpenFileForWriting("data\\cullzone.dat"); - if (fd != 0) { - CFileMgr::Write(fd, (char*)&NumCullZones, sizeof(NumCullZones)); - CFileMgr::Write(fd, (char*)aZones, sizeof(aZones)); - CFileMgr::Write(fd, (char*)&NumAttributeZones, sizeof(NumAttributeZones)); - CFileMgr::Write(fd, (char*)&aAttributeZones, sizeof(aAttributeZones)); - CFileMgr::Write(fd, (char*)&aIndices, sizeof(aIndices)); - CFileMgr::Write(fd, (char*)&aPointersToBigBuildingsForBuildings, sizeof(aPointersToBigBuildingsForBuildings)); - CFileMgr::Write(fd, (char*)&aPointersToBigBuildingsForTreadables, sizeof(aPointersToBigBuildingsForTreadables)); - CFileMgr::CloseFile(fd); - } -#endif - } -} - -void -CCullZones::BuildListForBigBuildings() -{ - for (int i = CPools::GetBuildingPool()->GetSize()-1; i >= 0; i--) { - CBuilding *building = CPools::GetBuildingPool()->GetSlot(i); - if (building == nil || !building->bIsBIGBuilding) continue; - CSimpleModelInfo *nonlod = (CSimpleModelInfo*)((CSimpleModelInfo *)CModelInfo::GetModelInfo(building->GetModelIndex()))->m_atomics[2]; - if (nonlod == nil) continue; - - for (int j = i; j >= 0; j--) { - CBuilding *building2 = CPools::GetBuildingPool()->GetSlot(j); - if (building2 == nil || building2->bIsBIGBuilding) continue; - if (CModelInfo::GetModelInfo(building2->GetModelIndex()) == nonlod) { - if ((building2->GetPosition() - building->GetPosition()).Magnitude() < 5.0f) { - aPointersToBigBuildingsForBuildings[j] = i; - } - } - } - - for (int j = CPools::GetTreadablePool()->GetSize()-1; j >= 0; j--) { - CTreadable *treadable = CPools::GetTreadablePool()->GetSlot(j); - if (treadable == nil || treadable->bIsBIGBuilding) continue; - if (CModelInfo::GetModelInfo(treadable->GetModelIndex()) == nonlod) { - if ((treadable->GetPosition() - building->GetPosition()).Magnitude() < 5.0f) { - aPointersToBigBuildingsForTreadables[j] = i; - } - } - } - } -} - -void -CCullZones::DoVisibilityTestCullZone(int zoneId, bool doIt) -{ - aZones[zoneId].m_groupIndexCount[0] = 0; - aZones[zoneId].m_groupIndexCount[1] = 0; - aZones[zoneId].m_groupIndexCount[2] = 0; - aZones[zoneId].m_indexStart = TempEntityIndicesUsed; - aZones[zoneId].FindTestPoints(); - - if (!doIt) return; - - for (int i = CPools::GetBuildingPool()->GetSize() - 1; i >= 0; i--) { - CBuilding *building = CPools::GetBuildingPool()->GetSlot(i); - if (building != nil && !building->bIsBIGBuilding && aZones[zoneId].IsEntityCloseEnoughToZone(building, aPointersToBigBuildingsForBuildings[i] != -1)) { - CBuilding *building2 = nil; - if (aPointersToBigBuildingsForBuildings[i] != -1) - building2 = CPools::GetBuildingPool()->GetSlot(aPointersToBigBuildingsForBuildings[i]); - - if (!aZones[zoneId].TestEntityVisibilityFromCullZone(building, 0.0f, building2)) { - pTempArrayIndices[TempEntityIndicesUsed++] = i; - aZones[zoneId].m_groupIndexCount[0]++; - } - } - } - - for (int i = CPools::GetTreadablePool()->GetSize() - 1; i >= 0; i--) { - CTreadable* building = CPools::GetTreadablePool()->GetSlot(i); - if (building != nil && aZones[zoneId].IsEntityCloseEnoughToZone(building, aPointersToBigBuildingsForTreadables[i] != -1)) { - CTreadable* building2 = nil; - if (aPointersToBigBuildingsForTreadables[i] != -1) - building2 = CPools::GetTreadablePool()->GetSlot(aPointersToBigBuildingsForTreadables[i]); - - if (!aZones[zoneId].TestEntityVisibilityFromCullZone(building, 10.0f, building2)) { - pTempArrayIndices[TempEntityIndicesUsed++] = i; - aZones[zoneId].m_groupIndexCount[1]++; - } - } - } - - for (int i = CPools::GetTreadablePool()->GetSize() - 1; i >= 0; i--) { - CTreadable *building = CPools::GetTreadablePool()->GetSlot(i); - if (building != nil && aZones[zoneId].CalcDistToCullZoneSquared(building->GetPosition().x, building->GetPosition().y) < 40000.0f) { - int start = aZones[zoneId].m_groupIndexCount[0] + aZones[zoneId].m_indexStart; - int end = aZones[zoneId].m_groupIndexCount[1] + start; - - bool alreadyAdded = false; - - for (int k = start; k < end; k++) { - if (aIndices[k] == i) - alreadyAdded = true; - } - - if (!alreadyAdded) { - CBuilding *building2 = nil; - if (aPointersToBigBuildingsForTreadables[i] != -1) - building2 = CPools::GetBuildingPool()->GetSlot(aPointersToBigBuildingsForTreadables[i]); - if (!aZones[zoneId].TestEntityVisibilityFromCullZone(building, 0.0f, building2)) { - pTempArrayIndices[TempEntityIndicesUsed++] = i; - aZones[zoneId].m_groupIndexCount[2]++; - } - } - } - } -} -#endif - void CCullZones::Update(void) { bool invisible; - if(bCullZonesDisabled) - return; - switch(CTimer::GetFrameCounter() & 7){ case 0: case 4: -#ifdef GTA_ZONECULL - /* Update Cull zone */ - ForceCullZoneCoors(TheCamera.GetGameCamPosition()); -#endif break; case 2: @@ -256,34 +60,8 @@ CCullZones::Update(void) void CCullZones::ForceCullZoneCoors(CVector coors) { -#ifdef GTA_ZONECULL - int32 z; - z = FindCullZoneForCoors(coors); - if(z != OldCullZone){ - if(OldCullZone >= 0) - aZones[OldCullZone].DoStuffLeavingZone(); - if(z >= 0) - aZones[z].DoStuffEnteringZone(); - OldCullZone = z; - } -#endif } -#ifdef GTA_ZONECULL -int32 -CCullZones::FindCullZoneForCoors(CVector coors) -{ - int i; - - for(i = 0; i < NumCullZones; i++) - if(coors.x >= aZones[i].minx && coors.x <= aZones[i].maxx && - coors.y >= aZones[i].miny && coors.y <= aZones[i].maxy && - coors.z >= aZones[i].minz && coors.z <= aZones[i].maxz) - return i; - return -1; -} -#endif - int32 CCullZones::FindAttributesForCoors(CVector coors, int32 *wantedLevel) { @@ -356,222 +134,16 @@ CCullZones::AddCullZone(CVector const &position, float minz, float maxz, uint16 flag, int16 wantedLevel) { - CCullZone *cull; CAttributeZone *attrib; - CVector v; -#ifdef GTA_ZONECULL - if((flag & ATTRZONE_NOTCULLZONE) == 0){ - cull = &aZones[NumCullZones++]; - v = position; - // WTF is this? - if((v-CVector(1032.14f, -624.255f, 24.93f)).Magnitude() < 1.0f) - v = CVector(1061.7f, -613.0f, 19.0f); - if((v-CVector(1029.48f, -495.757f, 21.98f)).Magnitude() < 1.0f) - v = CVector(1061.4f, -506.0f, 18.5f); - cull->position.x = clamp(v.x, minx, maxx); - cull->position.y = clamp(v.y, miny, maxy); - cull->position.z = clamp(v.z, minz, maxz); - cull->minx = minx; - cull->maxx = maxx; - cull->miny = miny; - cull->maxy = maxy; - cull->minz = minz; - cull->maxz = maxz; - cull->m_groupIndexCount[0] = 0; - cull->m_groupIndexCount[1] = 0; - cull->m_groupIndexCount[2] = 0; - cull->m_indexStart = 0; - } -#endif - if(flag & ~ATTRZONE_NOTCULLZONE){ - attrib = &aAttributeZones[NumAttributeZones++]; - attrib->minx = minx; - attrib->maxx = maxx; - attrib->miny = miny; - attrib->maxy = maxy; - attrib->minz = minz; - attrib->maxz = maxz; - attrib->attributes = flag; - attrib->wantedLevel = wantedLevel; - } + assert(NumAttributeZones < NUMATTRIBZONES); + attrib = &aAttributeZones[NumAttributeZones++]; + attrib->minx = minx; + attrib->maxx = maxx; + attrib->miny = miny; + attrib->maxy = maxy; + attrib->minz = minz; + attrib->maxz = maxz; + attrib->attributes = flag; + attrib->wantedLevel = wantedLevel; } - - -#ifdef GTA_ZONECULL -void -CCullZone::DoStuffLeavingZone(void) -{ - int i; - - for(i = 0; i < m_numBuildings; i++) - DoStuffLeavingZone_OneBuilding(CCullZones::aIndices[m_indexStart + i]); - for(; i < m_numBuildings + m_numTreadablesPlus10m + m_numTreadables ; i++) - DoStuffLeavingZone_OneTreadableBoth(CCullZones::aIndices[m_indexStart + i]); -} - -void -CCullZone::DoStuffLeavingZone_OneBuilding(uint16 i) -{ - int16 bb; - int j; - - if(i < 6000){ - CPools::GetBuildingPool()->GetSlot(i)->bZoneCulled = false; - bb = CCullZones::aPointersToBigBuildingsForBuildings[i]; - if(bb != -1) - CPools::GetBuildingPool()->GetSlot(bb)->bZoneCulled = false; - }else{ - i -= 6000; - for(j = 0; j < 3; j++) - DoStuffLeavingZone_OneBuilding(CCullZones::aIndices[i+j]); - } -} - -void -CCullZone::DoStuffLeavingZone_OneTreadableBoth(uint16 i) -{ - int16 bb; - int j; - - if(i < 6000){ - CPools::GetTreadablePool()->GetSlot(i)->bZoneCulled = false; - CPools::GetTreadablePool()->GetSlot(i)->bZoneCulled2 = false; - bb = CCullZones::aPointersToBigBuildingsForTreadables[i]; - if(bb != -1) - CPools::GetBuildingPool()->GetSlot(bb)->bZoneCulled = false; - }else{ - i -= 6000; - for(j = 0; j < 3; j++) - DoStuffLeavingZone_OneTreadableBoth(CCullZones::aIndices[i+j]); - } -} - -void -CCullZone::DoStuffEnteringZone(void) -{ - int i; - - for(i = 0; i < m_numBuildings; i++) - DoStuffEnteringZone_OneBuilding(CCullZones::aIndices[m_indexStart + i]); - for(; i < m_numBuildings + m_numTreadablesPlus10m; i++) - DoStuffEnteringZone_OneTreadablePlus10m(CCullZones::aIndices[m_indexStart + i]); - for(; i < m_numBuildings + m_numTreadablesPlus10m + m_numTreadables; i++) - DoStuffEnteringZone_OneTreadable(CCullZones::aIndices[m_indexStart + i]); -} - -void -CCullZone::DoStuffEnteringZone_OneBuilding(uint16 i) -{ - int16 bb; - int j; - - if(i < 6000){ - CPools::GetBuildingPool()->GetSlot(i)->bZoneCulled = true; - bb = CCullZones::aPointersToBigBuildingsForBuildings[i]; - if(bb != -1) - CPools::GetBuildingPool()->GetSlot(bb)->bZoneCulled = true; - }else{ - i -= 6000; - for(j = 0; j < 3; j++) - DoStuffEnteringZone_OneBuilding(CCullZones::aIndices[i+j]); - } -} - -void -CCullZone::DoStuffEnteringZone_OneTreadablePlus10m(uint16 i) -{ - int16 bb; - int j; - - if(i < 6000){ - CPools::GetTreadablePool()->GetSlot(i)->bZoneCulled = true; - CPools::GetTreadablePool()->GetSlot(i)->bZoneCulled2 = true; - bb = CCullZones::aPointersToBigBuildingsForTreadables[i]; - if(bb != -1) - CPools::GetBuildingPool()->GetSlot(bb)->bZoneCulled = true; - }else{ - i -= 6000; - for(j = 0; j < 3; j++) - DoStuffEnteringZone_OneTreadablePlus10m(CCullZones::aIndices[i+j]); - } -} - -void -CCullZone::DoStuffEnteringZone_OneTreadable(uint16 i) -{ - int16 bb; - int j; - - if(i < 6000){ - CPools::GetTreadablePool()->GetSlot(i)->bZoneCulled = true; - bb = CCullZones::aPointersToBigBuildingsForTreadables[i]; - if(bb != -1) - CPools::GetBuildingPool()->GetSlot(bb)->bZoneCulled = true; - }else{ - i -= 6000; - for(j = 0; j < 3; j++) - DoStuffEnteringZone_OneTreadable(CCullZones::aIndices[i+j]); - } -} - -float -CCullZone::CalcDistToCullZoneSquared(float x, float y) -{ - float rx, ry; - - if (x < minx) rx = sq(x - minx); - else if (x > maxx) rx = sq(x - maxx); - else rx = 0.0f; - - if (y < miny) ry = sq(y - miny); - else if (y > maxy) ry = sq(y - maxy); - else ry = 0.0f; - - return rx + ry; -} - -bool -CCullZone::IsEntityCloseEnoughToZone(CEntity *entity, bool checkLevel) -{ - const CVector &pos = entity->GetPosition(); - - CSimpleModelInfo *minfo = (CSimpleModelInfo*)CModelInfo::GetModelInfo(entity->GetModelIndex()); - float distToZone = CalcDistToCullZone(pos.x, pos.y); - float lodDist; - if (minfo->m_isSubway) - lodDist = minfo->GetLargestLodDistance() + 30.0f; - else - lodDist = minfo->GetLargestLodDistance() + 50.0f; - - if (lodDist > distToZone) return true; - if (!checkLevel) return false; - return CTheZones::GetLevelFromPosition(pos) == CTheZones::GetLevelFromPosition(CVector(minx, miny, minz)); -} - -bool -CCullZones::DoWeHaveMoreThanXOccurencesOfSet(int32 count, uint16 *set) -{ - int32 curCount; - int32 start; - int32 size; - - for (int i = 0; i < NumCullZones; i++) { - curCount = 0; - for (int group = 0; group < 3; group++) { - aZones[i].GetGroupStartAndSize(group, start, size); - - int unk = 0; // TODO: figure out - for (int j = 0; j < size; j++) { - for (int k = 0; k < 3; k++) { - if (set[k] == pTempArrayIndices[start+j]) - unk++; - } - } - if (unk == 3 && ++curCount >= count) - return true; - } - } - return false; -} -#endif \ No newline at end of file diff --git a/src/core/ZoneCull.h b/src/core/ZoneCull.h index e0a905e4..e76b7a44 100644 --- a/src/core/ZoneCull.h +++ b/src/core/ZoneCull.h @@ -1,57 +1,5 @@ class CEntity; -class CCullZone -{ -public: - CVector position; - float minx; - float maxx; - float miny; - float maxy; - float minz; - float maxz; - - int32 m_indexStart; - int16 m_groupIndexCount[3]; - int16 m_numBuildings; - int16 m_numTreadablesPlus10m; - int16 m_numTreadables; - - void DoStuffLeavingZone(void); - static void DoStuffLeavingZone_OneBuilding(uint16 i); - static void DoStuffLeavingZone_OneTreadableBoth(uint16 i); - void DoStuffEnteringZone(void); - static void DoStuffEnteringZone_OneBuilding(uint16 i); - static void DoStuffEnteringZone_OneTreadablePlus10m(uint16 i); - static void DoStuffEnteringZone_OneTreadable(uint16 i); - - - static bool TestLine(CVector a1, CVector a2); - float CalcDistToCullZoneSquared(float x, float y); - float CalcDistToCullZone(float x, float y) { return Sqrt(CalcDistToCullZoneSquared(x, y)); }; - bool IsEntityCloseEnoughToZone(CEntity* entity, bool checkLevel); - - void GetGroupStartAndSize(int32 groupid, int32 &start, int32 &size) { - switch (groupid) { - case 1: - start = m_groupIndexCount[0] + m_indexStart; - size = m_groupIndexCount[1]; - break; - case 2: - start = m_groupIndexCount[0] + m_groupIndexCount[1] + m_indexStart; - size = m_groupIndexCount[2]; - break; - default: - start = m_indexStart; - size = m_groupIndexCount[0]; - break; - } - } - - void FindTestPoints() {}; // todo - bool TestEntityVisibilityFromCullZone(CEntity*, float, CEntity*) { return false; }; // todo -}; - enum eZoneAttribs { ATTRZONE_CAMCLOSEIN = 1, @@ -79,27 +27,17 @@ struct CAttributeZone class CCullZones { public: - static int32 NumCullZones; - static CCullZone aZones[NUMCULLZONES]; static int32 NumAttributeZones; static CAttributeZone aAttributeZones[NUMATTRIBZONES]; - static uint16 aIndices[NUMZONEINDICES]; - static int16 aPointersToBigBuildingsForBuildings[NUMBUILDINGS]; - static int16 aPointersToBigBuildingsForTreadables[NUMTREADABLES]; static int32 CurrentWantedLevelDrop_Player; static int32 CurrentFlags_Camera; static int32 CurrentFlags_Player; - static int32 OldCullZone; - static int32 EntityIndicesUsed; static bool bCurrentSubwayIsInvisible; - static bool bCullZonesDisabled; static void Init(void); - static void ResolveVisibilities(void); static void Update(void); static void ForceCullZoneCoors(CVector coors); - static int32 FindCullZoneForCoors(CVector coors); static int32 FindAttributesForCoors(CVector coors, int32 *wantedLevel); static CAttributeZone *FindZoneWithStairsAttributeForPlayer(void); static void MarkSubwayAsInvisible(bool visible); @@ -117,12 +55,6 @@ public: static bool CamNoRain(void) { return (CurrentFlags_Camera & ATTRZONE_NORAIN) != 0; } static int32 GetWantedLevelDrop(void) { return CurrentWantedLevelDrop_Player; } - static void BuildListForBigBuildings(); - static void DoVisibilityTestCullZone(int zoneId, bool doIt); - static bool DoWeHaveMoreThanXOccurencesOfSet(int32 count, uint16 *set); - - static void CompressIndicesArray() {};// todo - //--MIAMI: TODO static bool PoliceAbandonCars(void) { return false; } }; diff --git a/src/core/Zones.cpp b/src/core/Zones.cpp index d30f3718..247f1501 100644 --- a/src/core/Zones.cpp +++ b/src/core/Zones.cpp @@ -9,17 +9,19 @@ #include "World.h" eLevelName CTheZones::m_CurrLevel; -CZone *CTheZones::m_pPlayersZone; int16 CTheZones::FindIndex; uint16 CTheZones::NumberOfAudioZones; int16 CTheZones::AudioZoneArray[NUMAUDIOZONES]; uint16 CTheZones::TotalNumberOfMapZones; -uint16 CTheZones::TotalNumberOfZones; -CZone CTheZones::ZoneArray[NUMZONES]; +uint16 CTheZones::TotalNumberOfInfoZones; +uint16 CTheZones::TotalNumberOfNavigationZones; +CZone CTheZones::InfoZoneArray[NUMINFOZONES]; CZone CTheZones::MapZoneArray[NUMMAPZONES]; +CZone CTheZones::NavigationZoneArray[NUMNAVIGZONES]; uint16 CTheZones::TotalNumberOfZoneInfos; -CZoneInfo CTheZones::ZoneInfoArray[2*NUMZONES]; +CZoneInfo CTheZones::ZoneInfoArray[2*NUMINFOZONES]; + #define SWAPF(a, b) { float t; t = a; a = b; b = t; } @@ -44,12 +46,14 @@ CheckZoneInfo(CZoneInfo *info) assert(info->gangThreshold[7] <= info->gangThreshold[8]); } +//--MIAMI: done wchar* CZone::GetTranslatedName(void) { return TheText.Get(name); } +//--MIAMI: check out zoneinfo void CTheZones::Init(void) { @@ -58,9 +62,15 @@ CTheZones::Init(void) AudioZoneArray[i] = -1; NumberOfAudioZones = 0; + for(i = 0; i < NUMNAVIGZONES; i++) + memset(&NavigationZoneArray[i], 0, sizeof(CZone)); + + for(i = 0; i < NUMINFOZONES; i++) + memset(&InfoZoneArray[i], 0, sizeof(CZone)); + CZoneInfo *zonei; int x = 1000/6; - for(i = 0; i < 2*NUMZONES; i++){ + for(i = 0; i < 2*NUMINFOZONES; i++){ zonei = &ZoneInfoArray[i]; zonei->carDensity = 10; zonei->carThreshold[0] = x; @@ -81,54 +91,64 @@ CTheZones::Init(void) zonei->gangThreshold[8] = zonei->gangThreshold[7]; CheckZoneInfo(zonei); } - TotalNumberOfZoneInfos = 1; // why 1? - for(i = 0; i < NUMZONES; i++) - memset(&ZoneArray[i], 0, sizeof(CZone)); - strcpy(ZoneArray[0].name, "CITYZON"); - ZoneArray[0].minx = -4000.0f; - ZoneArray[0].miny = -4000.0f; - ZoneArray[0].minz = -500.0f; - ZoneArray[0].maxx = 4000.0f; - ZoneArray[0].maxy = 4000.0f; - ZoneArray[0].maxz = 500.0f; - ZoneArray[0].level = LEVEL_NONE; - TotalNumberOfZones = 1; + TotalNumberOfZoneInfos = 1; // why 1? + TotalNumberOfNavigationZones = 1; + TotalNumberOfInfoZones = 1; + + strcpy(InfoZoneArray[0].name, "CITYINF"); + InfoZoneArray[0].minx = -2400.0f; + InfoZoneArray[0].miny = -2000.0f; + InfoZoneArray[0].minz = -500.0f; + InfoZoneArray[0].maxx = 1600.0f; + InfoZoneArray[0].maxy = 2000.0f; + InfoZoneArray[0].maxz = 500.0f; + InfoZoneArray[0].level = LEVEL_NONE; + InfoZoneArray[0].type = ZONE_INFO; + + strcpy(NavigationZoneArray[0].name, "VICE_C"); + NavigationZoneArray[0].minx = -2400.0f; + NavigationZoneArray[0].miny = -2000.0f; + NavigationZoneArray[0].minz = -500.0f; + NavigationZoneArray[0].maxx = 1600.0f; + NavigationZoneArray[0].maxy = 2000.0f; + NavigationZoneArray[0].maxz = 500.0f; + NavigationZoneArray[0].level = LEVEL_NONE; + NavigationZoneArray[0].type = ZONE_NAVIG; m_CurrLevel = LEVEL_NONE; - m_pPlayersZone = &ZoneArray[0]; for(i = 0; i < NUMMAPZONES; i++){ memset(&MapZoneArray[i], 0, sizeof(CZone)); MapZoneArray[i].type = ZONE_MAPZONE; } strcpy(MapZoneArray[0].name, "THEMAP"); - MapZoneArray[0].minx = -4000.0f; - MapZoneArray[0].miny = -4000.0f; + MapZoneArray[0].minx = -2400.0f; + MapZoneArray[0].miny = -2000.0f; MapZoneArray[0].minz = -500.0f; - MapZoneArray[0].maxx = 4000.0f; - MapZoneArray[0].maxy = 4000.0f; + MapZoneArray[0].maxx = 1600.0f; + MapZoneArray[0].maxy = 2000.0f; MapZoneArray[0].maxz = 500.0f; MapZoneArray[0].level = LEVEL_NONE; - TotalNumberOfMapZones = 1; } +//--MIAMI: done void CTheZones::Update(void) { CVector pos; pos = FindPlayerCoors(); - m_pPlayersZone = FindSmallestZonePosition(&pos); - m_CurrLevel = GetLevelFromPosition(pos); + m_CurrLevel = GetLevelFromPosition(&pos); } +//--MIAMI: done void CTheZones::CreateZone(char *name, eZoneType type, float minx, float miny, float minz, float maxx, float maxy, float maxz, eLevelName level) { - CZone *zone; + char tmpname[24]; char *p; if(minx > maxx) SWAPF(minx, maxx); @@ -138,46 +158,94 @@ CTheZones::CreateZone(char *name, eZoneType type, // make upper case for(p = name; *p; p++) if(islower(*p)) *p = toupper(*p); + strncpy(tmpname, name, 7); + tmpname[7] = '\0'; + // add zone -// TODO(MIAMI): do this properly, also navig zones - if(type == ZONE_MAPZONE) - zone = &MapZoneArray[TotalNumberOfMapZones++]; - else - zone = &ZoneArray[TotalNumberOfZones++]; - strncpy(zone->name, name, 7); - zone->name[7] = '\0'; - zone->type = type; - zone->minx = minx; - zone->miny = miny; - zone->minz = minz; - zone->maxx = maxx; - zone->maxy = maxy; - zone->maxz = maxz; - zone->level = level; - if(type == ZONE_AUDIO || type == ZONE_TYPE1 || type == ZONE_TYPE2){ - zone->zoneinfoDay = TotalNumberOfZoneInfos++; - zone->zoneinfoNight = TotalNumberOfZoneInfos++; + switch(type){ + case ZONE_DEFAULT: + case ZONE_NAVIG: + assert(TotalNumberOfNavigationZones < NUMNAVIGZONES); + strcpy(NavigationZoneArray[TotalNumberOfNavigationZones].name, tmpname); + NavigationZoneArray[TotalNumberOfNavigationZones].type = type; + NavigationZoneArray[TotalNumberOfNavigationZones].minx = minx; + NavigationZoneArray[TotalNumberOfNavigationZones].miny = miny; + NavigationZoneArray[TotalNumberOfNavigationZones].minz = minz; + NavigationZoneArray[TotalNumberOfNavigationZones].maxx = maxx; + NavigationZoneArray[TotalNumberOfNavigationZones].maxy = maxy; + NavigationZoneArray[TotalNumberOfNavigationZones].maxz = maxz; + NavigationZoneArray[TotalNumberOfNavigationZones].level = level; + TotalNumberOfNavigationZones++; + break; + case ZONE_INFO: + assert(TotalNumberOfInfoZones < NUMINFOZONES); + strcpy(InfoZoneArray[TotalNumberOfInfoZones].name, tmpname); + InfoZoneArray[TotalNumberOfInfoZones].type = type; + InfoZoneArray[TotalNumberOfInfoZones].minx = minx; + InfoZoneArray[TotalNumberOfInfoZones].miny = miny; + InfoZoneArray[TotalNumberOfInfoZones].minz = minz; + InfoZoneArray[TotalNumberOfInfoZones].maxx = maxx; + InfoZoneArray[TotalNumberOfInfoZones].maxy = maxy; + InfoZoneArray[TotalNumberOfInfoZones].maxz = maxz; + InfoZoneArray[TotalNumberOfInfoZones].level = level; + InfoZoneArray[TotalNumberOfInfoZones].zoneinfoDay = TotalNumberOfZoneInfos++; + InfoZoneArray[TotalNumberOfInfoZones].zoneinfoNight = TotalNumberOfZoneInfos++; + TotalNumberOfInfoZones++; + break; + case ZONE_MAPZONE: + assert(TotalNumberOfMapZones < NUMMAPZONES); + strcpy(MapZoneArray[TotalNumberOfMapZones].name, tmpname); + MapZoneArray[TotalNumberOfMapZones].type = type; + MapZoneArray[TotalNumberOfMapZones].minx = minx; + MapZoneArray[TotalNumberOfMapZones].miny = miny; + MapZoneArray[TotalNumberOfMapZones].minz = minz; + MapZoneArray[TotalNumberOfMapZones].maxx = maxx; + MapZoneArray[TotalNumberOfMapZones].maxy = maxy; + MapZoneArray[TotalNumberOfMapZones].maxz = maxz; + MapZoneArray[TotalNumberOfMapZones].level = level; + TotalNumberOfMapZones++; + break; } } +//--MIAMI: done void CTheZones::PostZoneCreation(void) { int i; - for(i = 1; i < TotalNumberOfZones; i++) - InsertZoneIntoZoneHierarchy(&ZoneArray[i]); + for(i = 1; i < TotalNumberOfNavigationZones; i++) + InsertZoneIntoZoneHierarchy(&NavigationZoneArray[i]); InitialiseAudioZoneArray(); } +//--MIAMI: done, but does nothing +void +CTheZones::CheckZonesForOverlap(void) +{ + int i, j; + char str[116]; + + for(i = 1; i < TotalNumberOfInfoZones; i++){ + ZoneIsEntirelyContainedWithinOtherZone(&InfoZoneArray[i], &InfoZoneArray[0]); + + for(j = 1; j < TotalNumberOfInfoZones; j++) + if(i != j && ZoneIsEntirelyContainedWithinOtherZone(&InfoZoneArray[i], &InfoZoneArray[j])) + sprintf(str, "Info zone %s contains %s\n", + &InfoZoneArray[j].name, &InfoZoneArray[i].name); + } +} + +//--MIAMI: done void CTheZones::InsertZoneIntoZoneHierarchy(CZone *zone) { zone->child = nil; zone->parent = nil; zone->next = nil; - InsertZoneIntoZoneHierRecursive(zone, &ZoneArray[0]); + InsertZoneIntoZoneHierRecursive(zone, &NavigationZoneArray[0]); } +//--MIAMI: done bool CTheZones::InsertZoneIntoZoneHierRecursive(CZone *inner, CZone *outer) { @@ -221,6 +289,7 @@ CTheZones::InsertZoneIntoZoneHierRecursive(CZone *inner, CZone *outer) return true; } +//--MIAMI: done bool CTheZones::ZoneIsEntirelyContainedWithinOtherZone(CZone *inner, CZone *outer) { @@ -233,11 +302,11 @@ CTheZones::ZoneIsEntirelyContainedWithinOtherZone(CZone *inner, CZone *outer) inner->minz < outer->minz || inner->maxz > outer->maxz){ CVector vmin(inner->minx, inner->miny, inner->minz); - if(PointLiesWithinZone(vmin, outer)) + if(PointLiesWithinZone(&vmin, outer)) sprintf(tmp, "Overlapping zones %s and %s\n", inner->name, outer->name); CVector vmax(inner->maxx, inner->maxy, inner->maxz); - if(PointLiesWithinZone(vmax, outer)) + if(PointLiesWithinZone(&vmax, outer)) sprintf(tmp, "Overlapping zones %s and %s\n", inner->name, outer->name); return false; @@ -245,16 +314,18 @@ CTheZones::ZoneIsEntirelyContainedWithinOtherZone(CZone *inner, CZone *outer) return true; } +//--MIAMI: done bool -CTheZones::PointLiesWithinZone(const CVector &v, CZone *zone) +CTheZones::PointLiesWithinZone(const CVector *v, CZone *zone) { - return zone->minx <= v.x && v.x <= zone->maxx && - zone->miny <= v.y && v.y <= zone->maxy && - zone->minz <= v.z && v.z <= zone->maxz; + return zone->minx <= v->x && v->x <= zone->maxx && + zone->miny <= v->y && v->y <= zone->maxy && + zone->minz <= v->z && v->z <= zone->maxz; } +//--MIAMI: done eLevelName -CTheZones::GetLevelFromPosition(CVector const &v) +CTheZones::GetLevelFromPosition(const CVector *v) { int i; // char tmp[116]; @@ -266,59 +337,35 @@ CTheZones::GetLevelFromPosition(CVector const &v) return MapZoneArray[0].level; } +//--MIAMI: done CZone* -CTheZones::FindSmallestZonePosition(const CVector *v) +CTheZones::FindInformationZoneForPosition(const CVector *v) { - CZone *best = &ZoneArray[0]; - // zone to test next - CZone *zone = ZoneArray[0].child; - while(zone) - // if in zone, descent into children - if(PointLiesWithinZone(*v, zone)){ - best = zone; - zone = zone->child; - // otherwise try next zone - }else - zone = zone->next; - return best; + int i; +// char tmp[116]; +// if(!PointLiesWithinZone(v, &InfoZoneArray[0])) +// sprintf(tmp, "x = %.3f y= %.3f z = %.3f\n", v.x, v.y, v.z); + for(i = 1; i < TotalNumberOfInfoZones; i++) + if(PointLiesWithinZone(v, &InfoZoneArray[i])) + return &InfoZoneArray[i]; + return &InfoZoneArray[0]; } +//--MIAMI: done CZone* -CTheZones::FindSmallestZonePositionType(const CVector *v, eZoneType type) +CTheZones::FindSmallestNavigationZoneForPosition(const CVector *v, bool findDefault, bool findNavig) { CZone *best = nil; - if(ZoneArray[0].type == type) - best = &ZoneArray[0]; + if(findDefault && NavigationZoneArray[0].type == ZONE_DEFAULT || + findNavig && NavigationZoneArray[0].type == ZONE_NAVIG) + best = &NavigationZoneArray[0]; // zone to test next - CZone *zone = ZoneArray[0].child; + CZone *zone = NavigationZoneArray[0].child; while(zone) // if in zone, descent into children - if(PointLiesWithinZone(*v, zone)){ - if(zone->type == type) - best = zone; - zone = zone->child; - // otherwise try next zone - }else - zone = zone->next; - return best; -} - -CZone* -CTheZones::FindSmallestZonePositionILN(const CVector *v) -{ - CZone *best = nil; - if(ZoneArray[0].type == ZONE_AUDIO || - ZoneArray[0].type == ZONE_TYPE1 || - ZoneArray[0].type == ZONE_TYPE2) - best = &ZoneArray[0]; - // zone to test next - CZone *zone = ZoneArray[0].child; - while(zone) - // if in zone, descent into children - if(PointLiesWithinZone(*v, zone)){ - if(zone->type == ZONE_AUDIO || - zone->type == ZONE_TYPE1 || - zone->type == ZONE_TYPE2) + if(PointLiesWithinZone(v, zone)){ + if(findDefault && zone->type == ZONE_DEFAULT || + findNavig && zone->type == ZONE_NAVIG) best = zone; zone = zone->child; // otherwise try next zone @@ -327,23 +374,72 @@ CTheZones::FindSmallestZonePositionILN(const CVector *v) return best; } +//--MIAMI: done int16 -CTheZones::FindZoneByLabelAndReturnIndex(char *name) +CTheZones::FindZoneByLabelAndReturnIndex(char *name, eZoneType type) { char str[8]; memset(str, 0, 8); strncpy(str, name, 8); - for(FindIndex = 0; FindIndex < TotalNumberOfZones; FindIndex++) - if(strcmp(GetZone(FindIndex)->name, name) == 0) - return FindIndex; + switch(type){ + case ZONE_DEFAULT: + case ZONE_NAVIG: + for(FindIndex = 0; FindIndex < TotalNumberOfNavigationZones; FindIndex++) + if(strcmp(GetNavigationZone(FindIndex)->name, name) == 0) + return FindIndex; + break; + + case ZONE_INFO: + for(FindIndex = 0; FindIndex < TotalNumberOfInfoZones; FindIndex++) + if(strcmp(GetInfoZone(FindIndex)->name, name) == 0) + return FindIndex; + break; + + case ZONE_MAPZONE: + for(FindIndex = 0; FindIndex < TotalNumberOfMapZones; FindIndex++) + if(strcmp(GetMapZone(FindIndex)->name, name) == 0) + return FindIndex; + break; + } return -1; } +//--MIAMI: done +int16 +CTheZones::FindNextZoneByLabelAndReturnIndex(char *name, eZoneType type) +{ + char str[8]; + memset(str, 0, 8); + strncpy(str, name, 8); + switch(type){ + case ZONE_DEFAULT: + case ZONE_NAVIG: + for(; FindIndex < TotalNumberOfNavigationZones; FindIndex++) + if(strcmp(GetNavigationZone(FindIndex)->name, name) == 0) + return FindIndex; + break; + + case ZONE_INFO: + for(; FindIndex < TotalNumberOfInfoZones; FindIndex++) + if(strcmp(GetInfoZone(FindIndex)->name, name) == 0) + return FindIndex; + break; + + case ZONE_MAPZONE: + for(; FindIndex < TotalNumberOfMapZones; FindIndex++) + if(strcmp(GetMapZone(FindIndex)->name, name) == 0) + return FindIndex; + break; + } + return -1; +} + +//--MIAMI: done CZoneInfo* CTheZones::GetZoneInfo(const CVector *v, uint8 day) { CZone *zone; - zone = FindSmallestZonePositionILN(v); + zone = FindInformationZoneForPosition(v); if(zone == nil) return &ZoneInfoArray[0]; return &ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight]; @@ -421,7 +517,7 @@ CTheZones::SetZoneCarInfo(uint16 zoneid, uint8 day, int16 carDensity, { CZone *zone; CZoneInfo *info; - zone = GetZone(zoneid); + zone = GetInfoZone(zoneid); info = &ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight]; CheckZoneInfo(info); @@ -486,7 +582,7 @@ CTheZones::SetZonePedInfo(uint16 zoneid, uint8 day, int16 pedDensity, { CZone *zone; CZoneInfo *info; - zone = GetZone(zoneid); + zone = GetInfoZone(zoneid); info = &ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight]; if(pedDensity != -1) info->pedDensity = pedDensity; if(copDensity != -1) info->copDensity = copDensity; @@ -501,60 +597,64 @@ CTheZones::SetZonePedInfo(uint16 zoneid, uint8 day, int16 pedDensity, if(gang8Density != -1) info->gangDensity[8] = gang8Density; } +//--MIAMI: done, unused void CTheZones::SetCarDensity(uint16 zoneid, uint8 day, uint16 cardensity) { CZone *zone; - zone = GetZone(zoneid); - if(zone->type == ZONE_AUDIO || zone->type == ZONE_TYPE1 || zone->type == ZONE_TYPE2) - ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].carDensity = cardensity; + zone = GetInfoZone(zoneid); + ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].carDensity = cardensity; } +//--MIAMI: done, unused void CTheZones::SetPedDensity(uint16 zoneid, uint8 day, uint16 peddensity) { CZone *zone; - zone = GetZone(zoneid); - if(zone->type == ZONE_AUDIO || zone->type == ZONE_TYPE1 || zone->type == ZONE_TYPE2) - ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].pedDensity = peddensity; + zone = GetInfoZone(zoneid); + ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].pedDensity = peddensity; } +//--MIAMI: done void CTheZones::SetPedGroup(uint16 zoneid, uint8 day, uint16 pedgroup) { CZone *zone; - zone = GetZone(zoneid); - if(zone->type == ZONE_AUDIO || zone->type == ZONE_TYPE1 || zone->type == ZONE_TYPE2) - ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].pedGroup = pedgroup; + zone = GetInfoZone(zoneid); + ZoneInfoArray[day ? zone->zoneinfoDay : zone->zoneinfoNight].pedGroup = pedgroup; } +//--MIAMI: done int16 CTheZones::FindAudioZone(CVector *pos) { int i; for(i = 0; i < NumberOfAudioZones; i++) - if(PointLiesWithinZone(*pos, GetZone(AudioZoneArray[i]))) + if(PointLiesWithinZone(pos, GetAudioZone(i))) return i; return -1; } +//--MIAMI: done void CTheZones::AddZoneToAudioZoneArray(CZone *zone) { int i, z; - if(zone->type != ZONE_AUDIO) + if(zone->type != ZONE_DEFAULT) return; /* This is a bit stupid */ z = -1; - for(i = 0; i < NUMZONES; i++) - if(&ZoneArray[i] == zone) + for(i = 0; i < NUMNAVIGZONES; i++) + if(&NavigationZoneArray[i] == zone) z = i; + assert(NumberOfAudioZones < NUMAUDIOZONES); AudioZoneArray[NumberOfAudioZones++] = z; } +//--MIAMI: done void CTheZones::InitialiseAudioZoneArray(void) { @@ -562,7 +662,7 @@ CTheZones::InitialiseAudioZoneArray(void) CZone *zone; gonext = false; - zone = &ZoneArray[0]; + zone = &NavigationZoneArray[0]; // Go deep first, // set gonext when backing up a level to visit the next child while(zone) @@ -586,6 +686,7 @@ CTheZones::InitialiseAudioZoneArray(void) } } +//--MIAMI: TODO void CTheZones::SaveAllZones(uint8 *buffer, uint32 *size) { @@ -593,32 +694,39 @@ CTheZones::SaveAllZones(uint8 *buffer, uint32 *size) int i; *size = SAVE_HEADER_SIZE - + sizeof(int32) // GetIndexForZonePointer + sizeof(m_CurrLevel) + sizeof(FindIndex) + sizeof(int16) // padding - + sizeof(ZoneArray) + sizeof(ZoneInfoArray) - + sizeof(TotalNumberOfZones) + sizeof(TotalNumberOfZoneInfos) + + sizeof(NavigationZoneArray) + sizeof(InfoZoneArray) + sizeof(ZoneInfoArray) + + sizeof(TotalNumberOfNavigationZones) + sizeof(TotalNumberOfInfoZones) + sizeof(TotalNumberOfZoneInfos) + sizeof(MapZoneArray) + sizeof(AudioZoneArray) + sizeof(TotalNumberOfMapZones) + sizeof(NumberOfAudioZones); WriteSaveHeader(buffer, 'Z', 'N', 'S', '\0', *size - SAVE_HEADER_SIZE); - WriteSaveBuf(buffer, GetIndexForZonePointer(m_pPlayersZone)); WriteSaveBuf(buffer, m_CurrLevel); WriteSaveBuf(buffer, FindIndex); WriteSaveBuf(buffer, (int16)0); // padding - for(i = 0; i < ARRAY_SIZE(ZoneArray); i++){ - CZone *zone = WriteSaveBuf(buffer, ZoneArray[i]); - zone->child = (CZone*)GetIndexForZonePointer(ZoneArray[i].child); - zone->parent = (CZone*)GetIndexForZonePointer(ZoneArray[i].parent); - zone->next = (CZone*)GetIndexForZonePointer(ZoneArray[i].next); +// TODO(MIAMI): implement SaveOneZone + for(i = 0; i < ARRAY_SIZE(NavigationZoneArray); i++){ + CZone *zone = WriteSaveBuf(buffer, NavigationZoneArray[i]); + zone->child = (CZone*)GetIndexForZonePointer(NavigationZoneArray[i].child); + zone->parent = (CZone*)GetIndexForZonePointer(NavigationZoneArray[i].parent); + zone->next = (CZone*)GetIndexForZonePointer(NavigationZoneArray[i].next); + } + + for(i = 0; i < ARRAY_SIZE(InfoZoneArray); i++){ + CZone *zone = WriteSaveBuf(buffer, InfoZoneArray[i]); + zone->child = (CZone*)GetIndexForZonePointer(InfoZoneArray[i].child); + zone->parent = (CZone*)GetIndexForZonePointer(InfoZoneArray[i].parent); + zone->next = (CZone*)GetIndexForZonePointer(InfoZoneArray[i].next); } for(i = 0; i < ARRAY_SIZE(ZoneInfoArray); i++) WriteSaveBuf(buffer, ZoneInfoArray[i]); - WriteSaveBuf(buffer, TotalNumberOfZones); + WriteSaveBuf(buffer, TotalNumberOfNavigationZones); + WriteSaveBuf(buffer, TotalNumberOfInfoZones); WriteSaveBuf(buffer, TotalNumberOfZoneInfos); for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++) { @@ -646,6 +754,7 @@ CTheZones::SaveAllZones(uint8 *buffer, uint32 *size) VALIDATESAVEBUF(*size) } +//--MIAMI: TODO void CTheZones::LoadAllZones(uint8 *buffer, uint32 size) { @@ -654,23 +763,32 @@ CTheZones::LoadAllZones(uint8 *buffer, uint32 size) CheckSaveHeader(buffer, 'Z', 'N', 'S', '\0', size - SAVE_HEADER_SIZE); - m_pPlayersZone = GetPointerForZoneIndex(ReadSaveBuf(buffer)); m_CurrLevel = ReadSaveBuf(buffer); FindIndex = ReadSaveBuf(buffer); ReadSaveBuf(buffer); - for(i = 0; i < ARRAY_SIZE(ZoneArray); i++){ - ZoneArray[i] = ReadSaveBuf(buffer); +// TODO(MIAMI): implement LoadOneZone + for(i = 0; i < ARRAY_SIZE(NavigationZoneArray); i++){ + NavigationZoneArray[i] = ReadSaveBuf(buffer); - ZoneArray[i].child = GetPointerForZoneIndex((int32)ZoneArray[i].child); - ZoneArray[i].parent = GetPointerForZoneIndex((int32)ZoneArray[i].parent); - ZoneArray[i].next = GetPointerForZoneIndex((int32)ZoneArray[i].next); + NavigationZoneArray[i].child = GetPointerForZoneIndex((int32)NavigationZoneArray[i].child); + NavigationZoneArray[i].parent = GetPointerForZoneIndex((int32)NavigationZoneArray[i].parent); + NavigationZoneArray[i].next = GetPointerForZoneIndex((int32)NavigationZoneArray[i].next); + } + + for(i = 0; i < ARRAY_SIZE(InfoZoneArray); i++){ + InfoZoneArray[i] = ReadSaveBuf(buffer); + + InfoZoneArray[i].child = GetPointerForZoneIndex((int32)InfoZoneArray[i].child); + InfoZoneArray[i].parent = GetPointerForZoneIndex((int32)InfoZoneArray[i].parent); + InfoZoneArray[i].next = GetPointerForZoneIndex((int32)InfoZoneArray[i].next); } for(i = 0; i < ARRAY_SIZE(ZoneInfoArray); i++) ZoneInfoArray[i] = ReadSaveBuf(buffer); - TotalNumberOfZones = ReadSaveBuf(buffer); + TotalNumberOfNavigationZones = ReadSaveBuf(buffer); + TotalNumberOfInfoZones = ReadSaveBuf(buffer); TotalNumberOfZoneInfos = ReadSaveBuf(buffer); for(i = 0; i < ARRAY_SIZE(MapZoneArray); i++){ diff --git a/src/core/Zones.h b/src/core/Zones.h index 7d3482f8..992bda2d 100644 --- a/src/core/Zones.h +++ b/src/core/Zones.h @@ -5,9 +5,9 @@ enum eZoneType { - ZONE_AUDIO, - ZONE_TYPE1, // this should be NAVIG - ZONE_TYPE2, // this should be INFO...but all except MAPINFO get zoneinfo?? + ZONE_DEFAULT, + ZONE_NAVIG, + ZONE_INFO, ZONE_MAPZONE, }; @@ -51,19 +51,20 @@ public: class CTheZones { -public: - static eLevelName m_CurrLevel; - static CZone *m_pPlayersZone; static int16 FindIndex; static uint16 NumberOfAudioZones; static int16 AudioZoneArray[NUMAUDIOZONES]; static uint16 TotalNumberOfMapZones; - static uint16 TotalNumberOfZones; - static CZone ZoneArray[NUMZONES]; + static uint16 TotalNumberOfInfoZones; + static uint16 TotalNumberOfNavigationZones; + static CZone InfoZoneArray[NUMINFOZONES]; static CZone MapZoneArray[NUMMAPZONES]; + static CZone NavigationZoneArray[NUMNAVIGZONES]; static uint16 TotalNumberOfZoneInfos; - static CZoneInfo ZoneInfoArray[2*NUMZONES]; + static CZoneInfo ZoneInfoArray[2*NUMINFOZONES]; +public: + static eLevelName m_CurrLevel; static void Init(void); static void Update(void); @@ -71,17 +72,21 @@ public: float minx, float miny, float minz, float maxx, float maxy, float maxz, eLevelName level); - static CZone *GetZone(uint16 i) { return &ZoneArray[i]; } + static CZone *GetInfoZone(uint16 i) { return &InfoZoneArray[i]; } + static CZone *GetNavigationZone(uint16 i) { return &NavigationZoneArray[i]; } + static CZone *GetMapZone(uint16 i) { return &MapZoneArray[i]; } + static CZone *GetAudioZone(uint16 i) { return &InfoZoneArray[AudioZoneArray[i]]; } static void PostZoneCreation(void); + static void CheckZonesForOverlap(void); static void InsertZoneIntoZoneHierarchy(CZone *zone); static bool InsertZoneIntoZoneHierRecursive(CZone *z1, CZone *z2); static bool ZoneIsEntirelyContainedWithinOtherZone(CZone *z1, CZone *z2); - static bool PointLiesWithinZone(const CVector &v, CZone *zone); - static eLevelName GetLevelFromPosition(CVector const &v); - static CZone *FindSmallestZonePosition(const CVector *v); - static CZone *FindSmallestZonePositionType(const CVector *v, eZoneType type); - static CZone *FindSmallestZonePositionILN(const CVector *v); - static int16 FindZoneByLabelAndReturnIndex(char *name); + static bool PointLiesWithinZone(const CVector *v, CZone *zone); + static eLevelName GetLevelFromPosition(const CVector *v); + static CZone *FindInformationZoneForPosition(const CVector *v); + static CZone *FindSmallestNavigationZoneForPosition(const CVector *v, bool findDefault, bool findNavig); + static int16 FindZoneByLabelAndReturnIndex(char *name, eZoneType type); + static int16 FindNextZoneByLabelAndReturnIndex(char *name, eZoneType type); static CZoneInfo *GetZoneInfo(const CVector *v, uint8 day); static void GetZoneInfoForTimeOfDay(const CVector *pos, CZoneInfo *info); static void SetZoneCarInfo(uint16 zoneid, uint8 day, int16 carDensity, @@ -99,8 +104,8 @@ public: static void SetPedDensity(uint16 zoneid, uint8 day, uint16 peddensity); static void SetPedGroup(uint16 zoneid, uint8 day, uint16 pedgroup); static int16 FindAudioZone(CVector *pos); - static CZone *GetPointerForZoneIndex(int32 i) { return i == -1 ? nil : &ZoneArray[i]; } - static int32 GetIndexForZonePointer(CZone *zone) { return zone == nil ? -1 : zone - ZoneArray; } + static CZone *GetPointerForZoneIndex(int32 i) { return i == -1 ? nil : &InfoZoneArray[i]; } + static int32 GetIndexForZonePointer(CZone *zone) { return zone == nil ? -1 : zone - InfoZoneArray; } static void AddZoneToAudioZoneArray(CZone *zone); static void InitialiseAudioZoneArray(void); static void SaveAllZones(uint8 *buffer, uint32 *length); diff --git a/src/core/config.h b/src/core/config.h index bc5b3aad..32facfe6 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -53,14 +53,13 @@ enum Config { NUMREFERENCES = 800, // Zones - NUMAUDIOZONES = 36, - NUMZONES = 50, - NUMMAPZONES = 25, + NUMAUDIOZONES = 14, + NUMINFOZONES = 169, + NUMMAPZONES = 39, + NUMNAVIGZONES = 20, // Cull zones - NUMCULLZONES = 512, - NUMATTRIBZONES = 288, - NUMZONEINDICES = 55000, + NUMATTRIBZONES = 704, NUMHANDLINGS = 57, diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp index b52efbcf..107238c3 100644 --- a/src/entities/Entity.cpp +++ b/src/entities/Entity.cpp @@ -331,7 +331,7 @@ CEntity::SetupBigBuilding(void) bIsBIGBuilding = true; bStreamingDontDelete = true; bUsesCollision = false; - m_level = CTheZones::GetLevelFromPosition(GetPosition()); + m_level = CTheZones::GetLevelFromPosition(&GetPosition()); if(mi->m_lodDistances[0] <= 2000.0f) bStreamBIGBuilding = true; if(mi->m_lodDistances[0] > 2500.0f || mi->m_ignoreDrawDist) diff --git a/src/peds/Population.cpp b/src/peds/Population.cpp index 5a0b3448..d81648fa 100644 --- a/src/peds/Population.cpp +++ b/src/peds/Population.cpp @@ -361,7 +361,7 @@ CPopulation::FindCollisionZoneForCoors(CVector *coors, int *safeZoneOut, eLevelN if (*safeZoneOut >= 0) *levelOut = LEVEL_NONE; else - *levelOut = CTheZones::GetLevelFromPosition(*coors); + *levelOut = CTheZones::GetLevelFromPosition(coors); } void diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 58b088c6..ac501919 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1003,39 +1003,28 @@ CRenderer::ScanSectorList(CPtrList *lists) continue; // already seen ent->m_scanCode = CWorld::GetCurrentScanCode(); -#ifdef GTA_ZONECULL - if(IsEntityCullZoneVisible(ent)) -#endif - switch(SetupEntityVisibility(ent)){ - case VIS_VISIBLE: - ms_aVisibleEntityPtrs[ms_nNoOfVisibleEntities++] = ent; + switch(SetupEntityVisibility(ent)){ + case VIS_VISIBLE: + ms_aVisibleEntityPtrs[ms_nNoOfVisibleEntities++] = ent; + break; + case VIS_INVISIBLE: + if(!IsGlass(ent->GetModelIndex())) break; - case VIS_INVISIBLE: - if(!IsGlass(ent->GetModelIndex())) - break; - // fall through - case VIS_OFFSCREEN: - dx = ms_vecCameraPosition.x - ent->GetPosition().x; - dy = ms_vecCameraPosition.y - ent->GetPosition().y; - if(dx > -65.0f && dx < 65.0f && - dy > -65.0f && dy < 65.0f && - ms_nNoOfInVisibleEntities < NUMINVISIBLEENTITIES - 1) - ms_aInVisibleEntityPtrs[ms_nNoOfInVisibleEntities++] = ent; - break; - case VIS_STREAMME: - if(!CStreaming::ms_disableStreaming) - if(!m_loadingPriority || CStreaming::ms_numModelsRequested < 10) - CStreaming::RequestModel(ent->GetModelIndex(), 0); - break; - } -#ifdef GTA_ZONECULL - else if(ent->IsBuilding() && ((CBuilding*)ent)->GetIsATreadable()){ + // fall through + case VIS_OFFSCREEN: + dx = ms_vecCameraPosition.x - ent->GetPosition().x; + dy = ms_vecCameraPosition.y - ent->GetPosition().y; + if(dx > -65.0f && dx < 65.0f && + dy > -65.0f && dy < 65.0f && + ms_nNoOfInVisibleEntities < NUMINVISIBLEENTITIES - 1) + ms_aInVisibleEntityPtrs[ms_nNoOfInVisibleEntities++] = ent; + break; + case VIS_STREAMME: if(!CStreaming::ms_disableStreaming) - if(SetupEntityVisibility(ent) == VIS_STREAMME) - if(!m_loadingPriority || CStreaming::ms_numModelsRequested < 10) - CStreaming::RequestModel(ent->GetModelIndex(), 0); + if(!m_loadingPriority || CStreaming::ms_numModelsRequested < 10) + CStreaming::RequestModel(ent->GetModelIndex(), 0); + break; } -#endif } } } @@ -1057,40 +1046,30 @@ CRenderer::ScanSectorList_Priority(CPtrList *lists) continue; // already seen ent->m_scanCode = CWorld::GetCurrentScanCode(); -#ifdef GTA_ZONECULL - if(IsEntityCullZoneVisible(ent)) -#endif - switch(SetupEntityVisibility(ent)){ - case VIS_VISIBLE: - ms_aVisibleEntityPtrs[ms_nNoOfVisibleEntities++] = ent; - break; - case VIS_INVISIBLE: - if(!IsGlass(ent->GetModelIndex())) - break; - // fall through - case VIS_OFFSCREEN: - dx = ms_vecCameraPosition.x - ent->GetPosition().x; - dy = ms_vecCameraPosition.y - ent->GetPosition().y; - if(dx > -65.0f && dx < 65.0f && - dy > -65.0f && dy < 65.0f && - ms_nNoOfInVisibleEntities < NUMINVISIBLEENTITIES - 1) - ms_aInVisibleEntityPtrs[ms_nNoOfInVisibleEntities++] = ent; - break; - case VIS_STREAMME: - if(!CStreaming::ms_disableStreaming){ - CStreaming::RequestModel(ent->GetModelIndex(), 0); - if(CStreaming::ms_aInfoForModel[ent->GetModelIndex()].m_loadState != STREAMSTATE_LOADED) - m_loadingPriority = true; - } + switch(SetupEntityVisibility(ent)){ + case VIS_VISIBLE: + ms_aVisibleEntityPtrs[ms_nNoOfVisibleEntities++] = ent; + break; + case VIS_INVISIBLE: + if(!IsGlass(ent->GetModelIndex())) break; + // fall through + case VIS_OFFSCREEN: + dx = ms_vecCameraPosition.x - ent->GetPosition().x; + dy = ms_vecCameraPosition.y - ent->GetPosition().y; + if(dx > -65.0f && dx < 65.0f && + dy > -65.0f && dy < 65.0f && + ms_nNoOfInVisibleEntities < NUMINVISIBLEENTITIES - 1) + ms_aInVisibleEntityPtrs[ms_nNoOfInVisibleEntities++] = ent; + break; + case VIS_STREAMME: + if(!CStreaming::ms_disableStreaming){ + CStreaming::RequestModel(ent->GetModelIndex(), 0); + if(CStreaming::ms_aInfoForModel[ent->GetModelIndex()].m_loadState != STREAMSTATE_LOADED) + m_loadingPriority = true; } -#ifdef GTA_ZONECULL - else if(ent->IsBuilding() && ((CBuilding*)ent)->GetIsATreadable()){ - if(!CStreaming::ms_disableStreaming) - if(SetupEntityVisibility(ent) == VIS_STREAMME) - CStreaming::RequestModel(ent->GetModelIndex(), 0); + break; } -#endif } } } @@ -1143,9 +1122,6 @@ CRenderer::ScanSectorList_RequestModels(CPtrList *lists) if(ent->m_scanCode == CWorld::GetCurrentScanCode()) continue; // already seen ent->m_scanCode = CWorld::GetCurrentScanCode(); -#ifdef GTA_ZONECULL - if(IsEntityCullZoneVisible(ent)) -#endif if(ShouldModelBeStreamed(ent)) CStreaming::RequestModel(ent->GetModelIndex(), 0); } @@ -1191,51 +1167,6 @@ CRenderer::ShouldModelBeStreamed(CEntity *ent) return dist - FADE_DISTANCE - STREAM_DISTANCE < mi->GetLargestLodDistance(); } -#ifdef GTA_ZONECULL -bool -CRenderer::IsEntityCullZoneVisible(CEntity *ent) -{ - CPed *ped; - CObject *obj; - - if(ent->bZoneCulled) - return false; - - switch(ent->GetType()){ - case ENTITY_TYPE_VEHICLE: - return IsVehicleCullZoneVisible(ent); - case ENTITY_TYPE_PED: - ped = (CPed*)ent; - if (ped->bInVehicle) { - if (ped->m_pMyVehicle) - return IsVehicleCullZoneVisible(ped->m_pMyVehicle); - else - return true; - } - return !(ped->m_pCurSurface && ped->m_pCurSurface->bZoneCulled2); - case ENTITY_TYPE_OBJECT: - obj = (CObject*)ent; - if(!obj->bIsStatic) - return true; - return !(obj->m_pCurSurface && obj->m_pCurSurface->bZoneCulled2); - } - return true; -} - -bool -CRenderer::IsVehicleCullZoneVisible(CEntity *ent) -{ - CVehicle *v = (CVehicle*)ent; - switch(v->GetStatus()) - case STATUS_SIMPLE: - case STATUS_PHYSICS: - case STATUS_ABANDONED: - case STATUS_WRECKED: - return !(v->m_pCurGroundEntity && v->m_pCurGroundEntity->bZoneCulled2); - return true; -} -#endif - void CRenderer::RemoveVehiclePedLights(CEntity *ent, bool reset) { diff --git a/src/render/Renderer.h b/src/render/Renderer.h index 5bf211e4..dc643722 100644 --- a/src/render/Renderer.h +++ b/src/render/Renderer.h @@ -62,10 +62,6 @@ public: static void SortBIGBuildingsForSectorList(CPtrList *list); static bool ShouldModelBeStreamed(CEntity *ent); -#ifdef GTA_ZONECULL - static bool IsEntityCullZoneVisible(CEntity *ent); - static bool IsVehicleCullZoneVisible(CEntity *ent); -#endif static void RemoveVehiclePedLights(CEntity *ent, bool reset); }; From bb8b6348ec6a0da02eca330698584847edf740dc Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Wed, 6 May 2020 14:11:21 +0300 Subject: [PATCH 5/5] Fix appveyor --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index ee25d578..611294a5 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -30,7 +30,7 @@ build: project: build/reVC.sln verbosity: minimal after_build: -- 7z a "reVC_%configuration%_%platform%_%APPVEYOR_BUILD_VERSION%.zip" bin/%PLATFORM%/%CONFIGURATION%/re3.exe bin/%PLATFORM%/%CONFIGURATION%/re3.pdb +- 7z a "reVC_%configuration%_%platform%_%APPVEYOR_BUILD_VERSION%.zip" bin/%PLATFORM%/%CONFIGURATION%/reVC.exe bin/%PLATFORM%/%CONFIGURATION%/reVC.pdb artifacts: - path: "reVC_%configuration%_%platform%_%APPVEYOR_BUILD_VERSION%.zip" name: reVC