diff --git a/CMakeLists.txt b/CMakeLists.txt index 5daf1d157..59761169d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.8) project(re3 C CXX) list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ef322a9a4..d07bf5d4b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -set(THREADS_PREFER_PTHREAD_FLAG ON) +set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) if(${RE3_AUDIO} STREQUAL "OAL") @@ -76,7 +76,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang PRIVATE "-Wextra" "-Wdouble-promotion" - "-Wpedantic" ) endif() elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") @@ -91,7 +90,7 @@ set_target_properties(re3 C_STANDARD 11 C_EXTENSIONS OFF C_STANDARD_REQUIRED ON - CXX_STANDARD 11 + CXX_STANDARD 14 CXX_EXTENSIONS OFF CXX_STANDARD_REQUIRED ON PREFIX "" diff --git a/src/animation/CutsceneMgr.cpp b/src/animation/CutsceneMgr.cpp index 83c4dbcbc..a150bf970 100644 --- a/src/animation/CutsceneMgr.cpp +++ b/src/animation/CutsceneMgr.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "General.h" #include "CutsceneMgr.h" @@ -225,7 +225,7 @@ CCutsceneMgr::LoadCutsceneData(const char *szCutsceneName) ms_cutsceneOffset = CVector(0.0f, 0.0f, 0.0f); pPlayerPed = FindPlayerPed(); - CTimer::Update(); + //CTimer::Update(1000/30); pPlayerPed->m_pWanted->ClearQdCrimes(); pPlayerPed->bIsVisible = false; @@ -275,8 +275,8 @@ CCutsceneMgr::SetupCutsceneToStart(void) } } - CTimer::Update(); - CTimer::Update(); + //CTimer::Update(1000/30); + //CTimer::Update(1000/30); ms_running = true; ms_cutsceneTimer = 0.0f; } @@ -375,7 +375,7 @@ CCutsceneMgr::DeleteCutsceneData(void) } CTimer::Stop(); CGame::DrasticTidyUpMemory(TheCamera.GetScreenFadeStatus() == FADE_2); - CTimer::Update(); + //CTimer::Update(1000/30); } void diff --git a/src/audio/DMAudio.cpp b/src/audio/DMAudio.cpp index 1027a084e..e46297578 100644 --- a/src/audio/DMAudio.cpp +++ b/src/audio/DMAudio.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "DMAudio.h" #include "MusicManager.h" diff --git a/src/collision/Collision.cpp b/src/collision/Collision.cpp index 41997e323..534c61365 100644 --- a/src/collision/Collision.cpp +++ b/src/collision/Collision.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "VuVector.h" #include "main.h" @@ -2106,7 +2106,7 @@ CCollision::ProcessColModels(const CMatrix &matrixA, CColModel &modelA, assert(modelA.numLines <= MAXNUMLINES); // From model A space to model B space - matAB = Invert(matrixB, matAB); + matAB.save(Invert(matrixB, matAB)); matAB *= matrixA; CColSphere bsphereAB; // bounding sphere of A in B space @@ -2115,7 +2115,7 @@ CCollision::ProcessColModels(const CMatrix &matrixA, CColModel &modelA, if(!TestSphereBox(bsphereAB, modelB.boundingBox)) return 0; // B to A space - matBA = Invert(matrixA, matBA); + matBA.save(Invert(matrixA, matBA)); matBA *= matrixB; // transform modelA's spheres and lines to B space @@ -2592,7 +2592,7 @@ CCollision::DrawColModel_Coloured(const CMatrix &mat, const CColModel &colModel, if(s == SURFACE_TRANSPARENT_CLOTH || s == SURFACE_METAL_CHAIN_FENCE || s == SURFACE_TRANSPARENT_STONE || s == SURFACE_SCAFFOLD_POLE) - if(CTimer::GetFrameCounter() & 1){ + if(CTimer::GetTickCounter() & 1){ r = 0; g = 0; b = 0; @@ -2673,7 +2673,7 @@ CCollision::DrawColModel_Coloured(const CMatrix &mat, const CColModel &colModel, if(s == SURFACE_TRANSPARENT_CLOTH || s == SURFACE_METAL_CHAIN_FENCE || s == SURFACE_TRANSPARENT_STONE || s == SURFACE_SCAFFOLD_POLE) - if(CTimer::GetFrameCounter() & 1){ + if(CTimer::GetTickCounter() & 1){ r = 0; g = 0; b = 0; diff --git a/src/control/Bridge.cpp b/src/control/Bridge.cpp index e873062bb..c632281af 100644 --- a/src/control/Bridge.cpp +++ b/src/control/Bridge.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "Bridge.h" #include "Pools.h" diff --git a/src/control/CarAI.cpp b/src/control/CarAI.cpp index ab44510d4..677a731ca 100644 --- a/src/control/CarAI.cpp +++ b/src/control/CarAI.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "CarAI.h" @@ -204,7 +204,7 @@ void CCarAI::UpdateCarAI(CVehicle* pVehicle) pVehicle->AutoPilot.m_nCarMission = MISSION_NONE; pVehicle->AutoPilot.m_nTempAction = TEMPACT_NONE; } - else if (distance > FindSwitchDistanceFarNormalVehicle(pVehicle) && !pVehicle->AutoPilot.m_bIgnorePathfinding && (CTimer::GetFrameCounter() & 7) == 0){ + else if (distance > FindSwitchDistanceFarNormalVehicle(pVehicle) && !pVehicle->AutoPilot.m_bIgnorePathfinding && (CTimer::GetTickCounter() & 7) == 0){ pVehicle->AutoPilot.m_nTempAction = TEMPACT_NONE; pVehicle->AutoPilot.m_nCarMission = (CCarCtrl::JoinCarWithRoadSystemGotoCoors(pVehicle, pVehicle->AutoPilot.m_vecDestinationCoors, true)) ? MISSION_GOTOCOORDS_STRAIGHT : MISSION_GOTOCOORDS; @@ -260,7 +260,7 @@ void CCarAI::UpdateCarAI(CVehicle* pVehicle) pVehicle->AutoPilot.m_nCarMission = MISSION_NONE; pVehicle->AutoPilot.m_nTempAction = TEMPACT_NONE; } - else if (distance > FindSwitchDistanceFarNormalVehicle(pVehicle) && !pVehicle->AutoPilot.m_bIgnorePathfinding && (CTimer::GetFrameCounter() & 7) == 0) { + else if (distance > FindSwitchDistanceFarNormalVehicle(pVehicle) && !pVehicle->AutoPilot.m_bIgnorePathfinding && (CTimer::GetTickCounter() & 7) == 0) { pVehicle->AutoPilot.m_nTempAction = TEMPACT_NONE; pVehicle->AutoPilot.m_nCarMission = (CCarCtrl::JoinCarWithRoadSystemGotoCoors(pVehicle, pVehicle->AutoPilot.m_vecDestinationCoors, true)) ? MISSION_GOTO_COORDS_STRAIGHT_ACCURATE : MISSION_GOTOCOORDS_ACCURATE; diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp index 627d7bada..4a7783d35 100644 --- a/src/control/CarCtrl.cpp +++ b/src/control/CarCtrl.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "CarCtrl.h" @@ -168,7 +168,7 @@ CCarCtrl::GenerateOneRandomCar() testForCollision = true; frontX = TheCamera.CamFrontXNorm; frontY = TheCamera.CamFrontYNorm; - switch (CTimer::GetFrameCounter() & 1) { + switch (CTimer::GetTickCounter() & 1) { case 0: /* Spawn a vehicle relatively far away from player. */ /* Forward to his current direction (camera direction). */ @@ -190,7 +190,7 @@ CCarCtrl::GenerateOneRandomCar() frontX = vecPlayerVehicleSpeed.x / fPlayerVehicleSpeed; frontY = vecPlayerVehicleSpeed.y / fPlayerVehicleSpeed; testForCollision = false; - switch (CTimer::GetFrameCounter() & 3) { + switch (CTimer::GetTickCounter() & 3) { case 0: case 1: /* Spawn a vehicle in a very narrow gap in front of a player */ @@ -219,7 +219,7 @@ CCarCtrl::GenerateOneRandomCar() frontX = vecPlayerVehicleSpeed.x / fPlayerVehicleSpeed; frontY = vecPlayerVehicleSpeed.y / fPlayerVehicleSpeed; testForCollision = false; - switch (CTimer::GetFrameCounter() & 3) { + switch (CTimer::GetTickCounter() & 3) { case 0: /* Spawn a vehicle in a very narrow gap in front of a player */ angleLimit = 0.85f; /* approx 30 degrees */ @@ -248,7 +248,7 @@ CCarCtrl::GenerateOneRandomCar() testForCollision = true; frontX = TheCamera.CamFrontXNorm; frontY = TheCamera.CamFrontYNorm; - switch (CTimer::GetFrameCounter() & 1) { + switch (CTimer::GetTickCounter() & 1) { case 0: /* Spawn a vehicle relatively far away from player. */ /* Forward to his current direction (camera direction). */ diff --git a/src/control/Darkel.cpp b/src/control/Darkel.cpp index afdfcb829..bb4569842 100644 --- a/src/control/Darkel.cpp +++ b/src/control/Darkel.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "main.h" #include "Darkel.h" @@ -105,7 +105,7 @@ CDarkel::DrawMessages() uint32 timeLeft = CDarkel::TimeLimit - (CTimer::GetTimeInMilliseconds() - CDarkel::TimeOfFrenzyStart); sprintf(gString, "%d:%02d", timeLeft / 60000, timeLeft % 60000 / 1000); AsciiToUnicode(gString, gUString); - if (timeLeft > 4000 || CTimer::GetFrameCounter() & 1) { + if (timeLeft > 4000 || CTimer::GetTickCounter() & 1) { CFont::SetColor(CRGBA(0, 0, 0, 255)); CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(35.0f), SCREEN_SCALE_Y(109.0f), gUString); CFont::SetColor(CRGBA(150, 100, 255, 255)); diff --git a/src/control/GameLogic.cpp b/src/control/GameLogic.cpp index 59c75dd47..8a7887907 100644 --- a/src/control/GameLogic.cpp +++ b/src/control/GameLogic.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "GameLogic.h" #include "Clock.h" @@ -60,7 +60,7 @@ CGameLogic::SortOutStreamingAndMemory(const CVector &pos) CStreaming::RemoveUnusedModelsInLoadedList(); CGame::DrasticTidyUpMemory(true); CStreaming::LoadScene(pos); - CTimer::Update(); + //CTimer::Update(1000/30); } void diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index 5a04285f5..171c321c7 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "Garages.h" #include "main.h" @@ -190,7 +190,7 @@ void CGarages::Update(void) if (aGarages[i].IsUsed()) aGarages[i].Update(); } - if ((CTimer::GetFrameCounter() & 0xF) != 0xC) + if ((CTimer::GetTickCounter() & 0xF) != 0xC) return; if (++GarageToBeTidied >= NUM_GARAGES) GarageToBeTidied = 0; @@ -593,7 +593,7 @@ void CGarage::Update() switch (m_eGarageState) { case GS_OPENED: if (((CVector2D)FindPlayerCoors() - CVector2D(GetGarageCenterX(), GetGarageCenterY())).MagnitudeSqr() > SQR(DISTANCE_TO_CLOSE_MISSION_GARAGE)) { - if ((CTimer::GetFrameCounter() & 0x1F) == 0 && !IsAnyOtherCarTouchingGarage(nil)) { + if ((CTimer::GetTickCounter() & 0x1F) == 0 && !IsAnyOtherCarTouchingGarage(nil)) { m_eGarageState = GS_CLOSING; m_bClosingWithoutTargetCar = true; } @@ -859,8 +859,8 @@ void CGarage::Update() switch (m_eGarageState) { case GS_OPENED: { - int i = CPools::GetVehiclePool()->GetSize() * (CTimer::GetFrameCounter() % CRUSHER_VEHICLE_TEST_SPAN) / CRUSHER_VEHICLE_TEST_SPAN; - int end = CPools::GetVehiclePool()->GetSize() * (CTimer::GetFrameCounter() % CRUSHER_VEHICLE_TEST_SPAN + 1) / CRUSHER_VEHICLE_TEST_SPAN; + int i = CPools::GetVehiclePool()->GetSize() * (CTimer::GetTickCounter() % CRUSHER_VEHICLE_TEST_SPAN) / CRUSHER_VEHICLE_TEST_SPAN; + int end = CPools::GetVehiclePool()->GetSize() * (CTimer::GetTickCounter() % CRUSHER_VEHICLE_TEST_SPAN + 1) / CRUSHER_VEHICLE_TEST_SPAN; for (; i < end; i++) { CVehicle* pVehicle = CPools::GetVehiclePool()->GetSlot(i); if (!pVehicle) @@ -923,7 +923,7 @@ void CGarage::Update() default: break; } - if (!FindPlayerVehicle() && (CTimer::GetFrameCounter() & 0x1F) == 0x17 && IsEntityEntirelyInside(FindPlayerPed())) + if (!FindPlayerVehicle() && (CTimer::GetTickCounter() & 0x1F) == 0x17 && IsEntityEntirelyInside(FindPlayerPed())) FindPlayerPed()->InflictDamage(nil, WEAPONTYPE_RAMMEDBYCAR, 300.0f, PEDPIECE_TORSO, 0); break; case GARAGE_MISSION_KEEPCAR: diff --git a/src/control/Phones.cpp b/src/control/Phones.cpp index ad29d4fb0..c155c7ce0 100644 --- a/src/control/Phones.cpp +++ b/src/control/Phones.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "Phones.h" #include "Pools.h" @@ -148,7 +148,7 @@ CPhoneInfo::Update(void) } if (CVector2D(TheCamera.GetPosition() - m_aPhones[phoneId].m_vecPos).MagnitudeSqr() > sq(100.0f)) m_aPhones[phoneId].m_visibleToCam = false; - } else if (!((CTimer::GetFrameCounter() + m_aPhones[phoneId].m_pEntity->m_randomSeed) % 16)) { + } else if (!((CTimer::GetTickCounter() + m_aPhones[phoneId].m_pEntity->m_randomSeed) % 16)) { if (CVector2D(TheCamera.GetPosition() - m_aPhones[phoneId].m_vecPos).MagnitudeSqr() < sq(60.0f)) m_aPhones[phoneId].m_visibleToCam = true; } diff --git a/src/control/Pickups.cpp b/src/control/Pickups.cpp index 8951ed82f..3fd5fad00 100644 --- a/src/control/Pickups.cpp +++ b/src/control/Pickups.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "main.h" @@ -666,9 +666,9 @@ CPickups::Update() #endif #define PICKUPS_FRAME_SPAN (6) #ifdef FIX_BUGS - for (uint32 i = NUMGENERALPICKUPS * (CTimer::GetFrameCounter() % PICKUPS_FRAME_SPAN) / PICKUPS_FRAME_SPAN; i < NUMGENERALPICKUPS * (CTimer::GetFrameCounter() % PICKUPS_FRAME_SPAN + 1) / PICKUPS_FRAME_SPAN; i++) { + for (uint32 i = NUMGENERALPICKUPS * (CTimer::GetTickCounter() % PICKUPS_FRAME_SPAN) / PICKUPS_FRAME_SPAN; i < NUMGENERALPICKUPS * (CTimer::GetTickCounter() % PICKUPS_FRAME_SPAN + 1) / PICKUPS_FRAME_SPAN; i++) { #else // BUG: this code can only reach 318 out of 320 pickups - for (uint32 i = NUMGENERALPICKUPS / PICKUPS_FRAME_SPAN * (CTimer::GetFrameCounter() % PICKUPS_FRAME_SPAN); i < NUMGENERALPICKUPS / PICKUPS_FRAME_SPAN * (CTimer::GetFrameCounter() % PICKUPS_FRAME_SPAN + 1); i++) { + for (uint32 i = NUMGENERALPICKUPS / PICKUPS_FRAME_SPAN * (CTimer::GetTickCounter() % PICKUPS_FRAME_SPAN); i < NUMGENERALPICKUPS / PICKUPS_FRAME_SPAN * (CTimer::GetTickCounter() % PICKUPS_FRAME_SPAN + 1); i++) { #endif if (aPickUps[i].m_eType != PICKUP_NONE && aPickUps[i].Update(FindPlayerPed(), FindPlayerVehicle(), CWorld::PlayerInFocus)) { AddToCollectedPickupsArray(i); @@ -1111,7 +1111,7 @@ CPacManPickups::Update() } if (bPMActive) { #define PACMANPICKUPS_FRAME_SPAN (4) - for (uint32 i = (CTimer::GetFrameCounter() % PACMANPICKUPS_FRAME_SPAN) * (NUMPACMANPICKUPS / PACMANPICKUPS_FRAME_SPAN); i < ((CTimer::GetFrameCounter() % PACMANPICKUPS_FRAME_SPAN) + 1) * (NUMPACMANPICKUPS / PACMANPICKUPS_FRAME_SPAN); i++) { + for (uint32 i = (CTimer::GetTickCounter() % PACMANPICKUPS_FRAME_SPAN) * (NUMPACMANPICKUPS / PACMANPICKUPS_FRAME_SPAN); i < ((CTimer::GetTickCounter() % PACMANPICKUPS_FRAME_SPAN) + 1) * (NUMPACMANPICKUPS / PACMANPICKUPS_FRAME_SPAN); i++) { if (aPMPickUps[i].m_eType != PACMAN_NONE) aPMPickUps[i].Update(); } @@ -1343,7 +1343,7 @@ CPacManPickups::Render() if (CSprite::CalcScreenCoors(aPMPickUps[i].m_vecPosn, &pos, &w, &h, true) && pos.z < 100.0f) { if (aPMPickUps[i].m_pObject != nil) { aPMPickUps[i].m_pObject->GetMatrix().SetRotateZOnly((CTimer::GetTimeInMilliseconds() % 1024) * TWOPI / 1024.0f); - aPMPickUps[i].m_pObject->GetMatrix().UpdateRW(); + aPMPickUps[i].m_pObject->GetMatrix().UpdateRWInterPolated(); aPMPickUps[i].m_pObject->UpdateRwFrame(); } float fsin = Sin((CTimer::GetTimeInMilliseconds() % 1024) * 6.28f / 1024.0f); // yes, it is 6.28f when it was TWOPI just now... diff --git a/src/control/Record.cpp b/src/control/Record.cpp index 8a23ffded..adc6be08a 100644 --- a/src/control/Record.cpp +++ b/src/control/Record.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "Record.h" @@ -209,8 +209,8 @@ void CRecordDataForChase::SaveOrRetrieveDataForThisFrame(void) return; case STATE_RECORD: { - if ((CTimer::GetFrameCounter() & 1) == 0) - StoreInfoForCar(pChaseCars[CurrentCar], &pBaseMemForCar[CurrentCar][CTimer::GetFrameCounter() / 2]); + if ((CTimer::GetTickCounter() & 1) == 0) + StoreInfoForCar(pChaseCars[CurrentCar], &pBaseMemForCar[CurrentCar][CTimer::GetTickCounter() / 2]); if (CTimer::GetFrameCounter() < CHASE_SCENE_LENGTH_IN_FRAMES * 2) return; CFileMgr::SetDir("data\\paths"); @@ -267,14 +267,14 @@ void CRecordDataForChase::SaveOrRetrieveCarPositions(void) case STATE_RECORD: case STATE_PLAYBACK_BEFORE_RECORDING: for (int i = 0; i < NUM_CHASE_CARS; i++) { - if (i != CurrentCar && CTimer::GetFrameCounter()) { - RestoreInfoForCar(pChaseCars[i], &pBaseMemForCar[i][CTimer::GetFrameCounter() / 2], false); + if (i != CurrentCar && CTimer::GetTickCounter()) { + RestoreInfoForCar(pChaseCars[i], &pBaseMemForCar[i][CTimer::GetTickCounter() / 2], false); pChaseCars[i]->GetMatrix().UpdateRW(); pChaseCars[i]->UpdateRwFrame(); } } - if (Status == STATE_PLAYBACK_BEFORE_RECORDING && CTimer::GetFrameCounter()) { - RestoreInfoForCar(pChaseCars[CurrentCar], &pBaseMemForCar[CurrentCar][CTimer::GetFrameCounter() / 2], false); + if (Status == STATE_PLAYBACK_BEFORE_RECORDING && CTimer::GetTickCounter()) { + RestoreInfoForCar(pChaseCars[CurrentCar], &pBaseMemForCar[CurrentCar][CTimer::GetTickCounter() / 2], false); pChaseCars[CurrentCar]->GetMatrix().UpdateRW(); pChaseCars[CurrentCar]->UpdateRwFrame(); } diff --git a/src/control/Replay.cpp b/src/control/Replay.cpp index f21703ac3..b096b32f7 100644 --- a/src/control/Replay.cpp +++ b/src/control/Replay.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "AnimBlendAssociation.h" #include "Boat.h" @@ -492,7 +492,7 @@ void CReplay::ProcessPedUpdate(CPed *ped, float interpolation, CAddressInReplayB ped->m_fRotationDest = pp->heading * PI / 128.0f; CMatrix ped_matrix; pp->matrix.DecompressIntoFullMatrix(ped_matrix); - ped->GetMatrix() = ped->GetMatrix() * CMatrix(1.0f - interpolation); + ped->GetMatrix().save(ped->GetMatrix() * CMatrix(1.0f - interpolation)); ped->GetMatrix().GetPosition() *= (1.0f - interpolation); ped->GetMatrix() += CMatrix(interpolation) * ped_matrix; if (pp->vehicle_index) { @@ -717,7 +717,7 @@ void CReplay::ProcessCarUpdate(CVehicle *vehicle, float interpolation, CAddressI } CMatrix vehicle_matrix; vp->matrix.DecompressIntoFullMatrix(vehicle_matrix); - vehicle->GetMatrix() = vehicle->GetMatrix() * CMatrix(1.0f - interpolation); + vehicle->GetMatrix().save(vehicle->GetMatrix() * CMatrix(1.0f - interpolation)); vehicle->GetMatrix().GetPosition() *= (1.0f - interpolation); vehicle->GetMatrix() += CMatrix(interpolation) * vehicle_matrix; vehicle->m_vecTurnSpeed = CVector(0.0f, 0.0f, 0.0f); @@ -896,7 +896,7 @@ bool CReplay::PlayBackThisFrameInterpolation(CAddressInReplayBuffer *buffer, flo case REPLAYPACKET_GENERAL: { tGeneralPacket* pg = (tGeneralPacket*)&ptr[offset]; - TheCamera.GetMatrix() = TheCamera.GetMatrix() * CMatrix(split); + TheCamera.GetMatrix().save(TheCamera.GetMatrix() * CMatrix(split)); TheCamera.GetMatrix().GetPosition() *= split; TheCamera.GetMatrix() += CMatrix(interpolation) * pg->camera_pos; RwMatrix* pm = RwFrameGetMatrix(RwCameraGetFrame(TheCamera.m_pRwCamera)); diff --git a/src/control/RoadBlocks.cpp b/src/control/RoadBlocks.cpp index 1496b307d..3883ef169 100644 --- a/src/control/RoadBlocks.cpp +++ b/src/control/RoadBlocks.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "RoadBlocks.h" #include "PathFind.h" @@ -110,7 +110,7 @@ CRoadBlocks::GenerateRoadBlocks(void) return; #endif CMatrix offsetMatrix; - uint32 frame = CTimer::GetFrameCounter() & 0xF; + uint32 frame = CTimer::GetTickCounter() & 0xF; int16 nRoadblockNode = (int16)(NUMROADBLOCKS * frame) / 16; const int16 maxRoadBlocks = (int16)(NUMROADBLOCKS * (frame + 1)) / 16; for (; nRoadblockNode < Min(NumRoadBlocks, maxRoadBlocks); nRoadblockNode++) { @@ -163,7 +163,7 @@ CRoadBlocks::GenerateRoadBlocks(void) pVehicle->SetStatus(STATUS_ABANDONED); // pVehicle->GetHeightAboveRoad(); // called but return value is ignored? vehicleMatrix.GetPosition().z += fModelRadius - 0.6f; - pVehicle->m_matrix = vehicleMatrix; + pVehicle->m_matrix.save(vehicleMatrix); pVehicle->PlaceOnRoadProperly(); pVehicle->SetIsStatic(false); pVehicle->m_matrix.UpdateRW(); diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 085c773a7..fda941c77 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "Script.h" #include "ScriptCommands.h" @@ -4314,7 +4314,6 @@ int8 CRunningScript::ProcessCommands200To299(int32 command) return -1; } - void CRunningScript::Save(uint8*& buf) { #ifdef COMPATIBLE_SAVES diff --git a/src/control/TrafficLights.cpp b/src/control/TrafficLights.cpp index 278366a3e..fc75a0c09 100644 --- a/src/control/TrafficLights.cpp +++ b/src/control/TrafficLights.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "Camera.h" #include "Clock.h" @@ -52,23 +52,23 @@ CTrafficLights::DisplayActualLight(CEntity *ent) case CAR_LIGHTS_GREEN: r = 0; g = 255; - pos1 = ent->GetMatrix() * CVector(x, yMax, zMin); - pos2 = ent->GetMatrix() * CVector(x, yMin, zMin); + pos1 = ent->GetMatrix().GetMatrixInterpolated() * CVector(x, yMax, zMin); + pos2 = ent->GetMatrix().GetMatrixInterpolated() * CVector(x, yMin, zMin); id = 0; break; case CAR_LIGHTS_YELLOW: r = 255; g = 128; - pos1 = ent->GetMatrix() * CVector(x, yMax, (zMin+zMax)/2.0f); - pos2 = ent->GetMatrix() * CVector(x, yMin, (zMin+zMax)/2.0f); + pos1 = ent->GetMatrix().GetMatrixInterpolated() * CVector(x, yMax, (zMin+zMax)/2.0f); + pos2 = ent->GetMatrix().GetMatrixInterpolated() * CVector(x, yMin, (zMin+zMax)/2.0f); id = 1; break; case CAR_LIGHTS_RED: default: r = 255; g = 0; - pos1 = ent->GetMatrix() * CVector(x, yMax, zMax); - pos2 = ent->GetMatrix() * CVector(x, yMin, zMax); + pos1 = ent->GetMatrix().GetMatrixInterpolated() * CVector(x, yMax, zMax); + pos2 = ent->GetMatrix().GetMatrixInterpolated() * CVector(x, yMin, zMax); id = 2; break; } @@ -119,7 +119,7 @@ CTrafficLights::DisplayActualLight(CEntity *ent) CVector p1(2.7f, left, top); CVector p2(2.7f, right, mid); CVector p3(2.7f, left, mid); - CShinyTexts::RegisterOne(ent->GetMatrix()*p0, ent->GetMatrix()*p1, ent->GetMatrix()*p2, ent->GetMatrix()*p3, + CShinyTexts::RegisterOne(ent->GetMatrix().GetMatrixInterpolated()*p0, ent->GetMatrix().GetMatrixInterpolated()*p1, ent->GetMatrix().GetMatrixInterpolated()*p2, ent->GetMatrix()*p3, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, SHINYTEXT_WALK, 255, 0, 0, 60.0f); }else if(phase == PED_LIGHTS_WALK || CTimer::GetTimeInMilliseconds() & 0x100){ @@ -127,7 +127,7 @@ CTrafficLights::DisplayActualLight(CEntity *ent) CVector p1(2.7f, left, mid); CVector p2(2.7f, right, bot); CVector p3(2.7f, left, bot); - CShinyTexts::RegisterOne(ent->GetMatrix()*p0, ent->GetMatrix()*p1, ent->GetMatrix()*p2, ent->GetMatrix()*p3, + CShinyTexts::RegisterOne(ent->GetMatrix().GetMatrixInterpolated()*p0, ent->GetMatrix().GetMatrixInterpolated()*p1, ent->GetMatrix().GetMatrixInterpolated()*p2, ent->GetMatrix().GetMatrixInterpolated()*p3, 1.0f, 0.5f, 0.0f, 0.5f, 1.0f, 1.0f, 0.0f, 1.0f, SHINYTEXT_WALK, 255, 255, 255, 60.0f); } diff --git a/src/core/Cam.cpp b/src/core/Cam.cpp index 3e016667d..d3a89962a 100644 --- a/src/core/Cam.cpp +++ b/src/core/Cam.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "main.h" #include "Draw.h" diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index 56225fed7..85ccdaeb6 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "main.h" #include "Draw.h" @@ -99,7 +99,7 @@ CCamera::Init(void) #ifdef FIX_BUGS static const CCamera DummyCamera = CCamera(0.f); - *this = DummyCamera; + //*this = DummyCamera; #else memset(this, 0, sizeof(CCamera)); // getting rid of vtable, eh? #endif @@ -1805,7 +1805,7 @@ CCamera::UpdateSoundDistances(void) center = GetPosition() + 5.0f*GetForward(); // check up - n = CTimer::GetFrameCounter() % 12; + n = CTimer::GetTickCounter() % 12; if(n == 0){ SoundDistUpAsReadOld = SoundDistUpAsRead; if(CWorld::ProcessVerticalLine(center, center.z+SOUND_DIST, colPoint, entity, true, false, false, false, true, false, nil)) @@ -1817,7 +1817,7 @@ CCamera::UpdateSoundDistances(void) SoundDistUp = (1.0f-f)*SoundDistUpAsReadOld + f*SoundDistUpAsRead; // check left - n = (CTimer::GetFrameCounter()+2) % 12; + n = (CTimer::GetTickCounter()+2) % 12; if(n == 0){ SoundDistLeftAsReadOld = SoundDistLeftAsRead; end = center + SOUND_DIST*GetRight(); @@ -1831,7 +1831,7 @@ CCamera::UpdateSoundDistances(void) // check right // end = center - SOUND_DIST*GetRight(); // useless - n = (CTimer::GetFrameCounter()+4) % 12; + n = (CTimer::GetTickCounter()+4) % 12; if(n == 0){ SoundDistRightAsReadOld = SoundDistRightAsRead; end = center - SOUND_DIST*GetRight(); @@ -3584,7 +3584,7 @@ CCamera::SetRwCamera(RwCamera *cam) void CCamera::CalculateDerivedValues(void) { - m_cameraMatrix = Invert(m_matrix); + m_cameraMatrix.save(Invert(m_matrix)); float hfov = DEGTORAD(CDraw::GetScaledFOV()/2.0f); float c = Cos(hfov); diff --git a/src/core/Camera.h b/src/core/Camera.h index 0797db9b8..7b3ae8dc2 100644 --- a/src/core/Camera.h +++ b/src/core/Camera.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "Placeable.h" class CEntity; diff --git a/src/core/CdStreamPosix.cpp b/src/core/CdStreamPosix.cpp index 35a90a742..f3936b6bf 100644 --- a/src/core/CdStreamPosix.cpp +++ b/src/core/CdStreamPosix.cpp @@ -1,4 +1,4 @@ -#ifndef _WIN32 +#ifndef _WIN32 #include "common.h" #include "crossplatform.h" #include diff --git a/src/core/FileLoader.cpp b/src/core/FileLoader.cpp index f46b6134b..7aced2b11 100644 --- a/src/core/FileLoader.cpp +++ b/src/core/FileLoader.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "main.h" #include "General.h" @@ -1051,7 +1051,7 @@ CFileLoader::LoadMLOInstance(int id, const char *line) RwMatrixRotate(matrix, &rot, -RADTODEG(rad), rwCOMBINEPOSTCONCAT); RwMatrixTranslate(matrix, &pos, rwCOMBINEPOSTCONCAT); - inst->GetMatrix() = CMatrix(matrix); + inst->GetMatrix().save(CMatrix(matrix)); inst->GetMatrix().UpdateRW(); inst->m_modelIndex = modelIndex; @@ -1453,7 +1453,7 @@ CFileLoader::LoadObjectInstance(const char *line) }else entity = new CBuilding; entity->SetModelIndexNoCreate(id); - entity->GetMatrix() = CMatrix(xform); + entity->GetMatrix().save(CMatrix(xform)); entity->m_level = CTheZones::GetLevelFromPosition(&entity->GetPosition()); if(mi->IsSimple()){ if(mi->m_isBigBuilding) @@ -1467,7 +1467,7 @@ CFileLoader::LoadObjectInstance(const char *line) }else{ entity = new CDummyObject; entity->SetModelIndexNoCreate(id); - entity->GetMatrix() = CMatrix(xform); + entity->GetMatrix().save(CMatrix(xform)); CWorld::Add(entity); if(IsGlass(entity->GetModelIndex())) entity->bIsVisible = false; diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index b84b691d4..0206b50a6 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -1,4 +1,4 @@ -#if defined RW_D3D9 || defined RWLIBS +#if defined RW_D3D9 || defined RWLIBS #define DIRECTINPUT_VERSION 0x0800 #include #endif @@ -3461,7 +3461,7 @@ CMenuManager::InitialiseChangedLanguageSettings() CTimer::Stop(); TheText.Unload(); TheText.Load(); - CTimer::Update(); + //CTimer::Update(1000/30); CGame::frenchGame = false; CGame::germanGame = false; #ifdef MORE_LANGUAGES @@ -3570,7 +3570,7 @@ CMenuManager::LoadAllTextures() #endif #ifdef GTA3_1_1_PATCH CStreaming::IHaveUsedStreamingMemory(); - CTimer::Update(); + //CTimer::Update(1000/30); #endif m_bSpritesLoaded = true; CTxdStore::PopCurrentTxd(); diff --git a/src/core/Game.cpp b/src/core/Game.cpp index 1283ecd1d..50d9ed396 100644 --- a/src/core/Game.cpp +++ b/src/core/Game.cpp @@ -1,4 +1,4 @@ -#pragma warning( push ) +#pragma warning( push ) #pragma warning( disable : 4005) #pragma warning( pop ) #include "common.h" @@ -638,7 +638,7 @@ void CGame::ReloadIPLs(void) CWorld::RepositionCertainDynamicObjects(); CCullZones::ResolveVisibilities(); CRenderer::SortBIGBuildings(); - CTimer::Update(); + //CTimer::Update(1000/30); } void CGame::ShutDownForRestart(void) @@ -799,7 +799,7 @@ void CGame::InitialiseWhenRestarting(void) } #endif - CTimer::Update(); + //CTimer::Update(1000/30); DMAudio.ChangeMusicMode(MUSICMODE_GAME); } @@ -886,6 +886,25 @@ void CGame::Process(void) #endif } +void +CGame::UpdateMatrices() +{ + for(CPtrNode *node = CWorld::GetMovingEntityList().first; node; node = node->next) { + CPlaceable *movingEnt = (CPlaceable *)node->item; + if(movingEnt) { movingEnt->m_matrix.SaveOldMatrix(); } + } +} + +void +CGame::InterpolateMatrices() +{ + for(CPtrNode *node = CWorld::GetMovingEntityList().first; node; node = node->next) { + CPhysical *movingEnt = (CPhysical *)node->item; + movingEnt->m_matrix.UpdateRWInterPolated(); + movingEnt->UpdateRwFrameInterpolated(); + } +} + void CGame::DrasticTidyUpMemory(bool) { #ifdef PS2 diff --git a/src/core/Game.h b/src/core/Game.h index 46e8fc680..e5ceb2d16 100644 --- a/src/core/Game.h +++ b/src/core/Game.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once enum eLevelName { LEVEL_IGNORE = -1, // beware, this is only used in CPhysical's m_nZoneLevel @@ -36,7 +36,9 @@ class CGame static void ShutDownForRestart(void); static void InitialiseWhenRestarting(void); static void Process(void); - + static void UpdateMatrices(); + static void InterpolateMatrices(); + // NB: these do something on PS2 static void TidyUpMemory(bool, bool); static void DrasticTidyUpMemory(bool); diff --git a/src/core/Placeable.h b/src/core/Placeable.h index 970c0d486..6ee51da2d 100644 --- a/src/core/Placeable.h +++ b/src/core/Placeable.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once class CPlaceable { @@ -11,17 +11,22 @@ class CPlaceable CPlaceable(void); virtual ~CPlaceable(void); const CVector &GetPosition(void) { return m_matrix.GetPosition(); } - void SetPosition(float x, float y, float z) { + const CVector &GetPositionInterpolated(void) { return m_matrix.GetPositionInterpolated(); } + void SetPosition(float x, float y, float z) + { m_matrix.GetPosition().x = x; m_matrix.GetPosition().y = y; m_matrix.GetPosition().z = z; } void SetPosition(const CVector &pos) { m_matrix.GetPosition() = pos; } + CVector &GetRight(void) { return m_matrix.GetRight(); } CVector &GetForward(void) { return m_matrix.GetForward(); } CVector &GetUp(void) { return m_matrix.GetUp(); } + CMatrix &GetMatrix(void) { return m_matrix; } - void SetTransform(RwMatrix *m) { m_matrix = CMatrix(m, false); } + + //void SetTransform(RwMatrix *m) { m_matrix.save(CMatrix(m, false)); } void SetHeading(float angle); void SetOrientation(float x, float y, float z){ CVector pos = m_matrix.GetPosition(); diff --git a/src/core/PlayerInfo.cpp b/src/core/PlayerInfo.cpp index 09b3a4991..a7baee7e5 100644 --- a/src/core/PlayerInfo.cpp +++ b/src/core/PlayerInfo.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "Automobile.h" #include "Bridge.h" @@ -383,7 +383,7 @@ CPlayerInfo::Process(void) m_nVisibleMoney += changeBy; } - if (!(CTimer::GetFrameCounter() & 15)) { + if (!(CTimer::GetTickCounter() & 15)) { CVector2D playerPos = m_pPed->bInVehicle ? m_pPed->m_pMyVehicle->GetPosition() : m_pPed->GetPosition(); m_fRoadDensity = ThePaths.CalcRoadDensity(playerPos.x, playerPos.y); } @@ -515,7 +515,7 @@ CPlayerInfo::Process(void) CCullZones::ForceCullZoneCoors(TheCamera.GetPosition()); CRenderer::RequestObjectsInFrustum(); CStreaming::LoadAllRequestedModels(false); - CTimer::Update(); + //CTimer::Update(1000/30); } m_bInRemoteMode = false; CWorld::Players[CWorld::PlayerInFocus].m_pRemoteVehicle = nil; @@ -524,7 +524,7 @@ CPlayerInfo::Process(void) } } } - if (!(CTimer::GetFrameCounter() & 31)) { + if (!(CTimer::GetTickCounter() & 31)) { CVehicle *veh = FindPlayerVehicle(); if (veh && m_pPed->bInVehicle && veh->GetUp().z < 0.0f && veh->m_vecMoveSpeed.Magnitude() < 0.05f && veh->IsCar() && !veh->bIsInWater) { diff --git a/src/core/Pools.cpp b/src/core/Pools.cpp index bd0814d0f..093303061 100644 --- a/src/core/Pools.cpp +++ b/src/core/Pools.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "Pools.h" @@ -397,12 +397,12 @@ INITSAVEBUF if (GetObjectPool()->GetSlot(ref >> 8)) CPopulation::ConvertToDummyObject(GetObjectPool()->GetSlot(ref >> 8)); CObject* pObject = new(ref) CObject(mi, false); - pObject->GetMatrix() = pBufferObject->GetMatrix(); + pObject->GetMatrix().save(pBufferObject->GetMatrix()); #ifdef COMPATIBLE_SAVES pObject->LoadEntityFlags(buf); #endif pObject->m_fUprootLimit = pBufferObject->m_fUprootLimit; - pObject->m_objectMatrix = pBufferObject->m_objectMatrix; + pObject->m_objectMatrix.save(pBufferObject->m_objectMatrix); pObject->ObjectCreatedBy = pBufferObject->ObjectCreatedBy; pObject->bIsPickup = pBufferObject->bIsPickup; pObject->bPickupObjWithMessage = pBufferObject->bPickupObjWithMessage; diff --git a/src/core/Timer.cpp b/src/core/Timer.cpp index ed5580fd8..76a388d81 100644 --- a/src/core/Timer.cpp +++ b/src/core/Timer.cpp @@ -1,4 +1,4 @@ -#define WITHWINDOWS +#define WITHWINDOWS #include "common.h" #include "crossplatform.h" @@ -11,6 +11,7 @@ uint32 CTimer::m_snTimeInMillisecondsPauseMode = 1; uint32 CTimer::m_snTimeInMillisecondsNonClipped; uint32 CTimer::m_snPreviousTimeInMilliseconds; uint32 CTimer::m_FrameCounter; +uint32 CTimer::m_TickCounter; float CTimer::ms_fTimeScale; float CTimer::ms_fTimeStep; float CTimer::ms_fTimeStepNonClipped; @@ -69,6 +70,7 @@ void CTimer::Initialise(void) m_snTimeInMilliseconds = m_snPreviousTimeInMilliseconds; m_FrameCounter = 0; + m_TickCounter = 0; DMAudio.ResetTimers(m_snPreviousTimeInMilliseconds); @@ -80,7 +82,7 @@ void CTimer::Shutdown(void) ; } -void CTimer::Update(void) +void CTimer::Update(float timeMs) { m_snPreviousTimeInMilliseconds = m_snTimeInMilliseconds; @@ -124,7 +126,7 @@ void CTimer::Update(void) #ifndef FIX_BUGS double #endif - frameTime = (double)updInMs * ms_fTimeScale; + frameTime = (double)timeMs * ms_fTimeScale; oldPcTimer = timer; @@ -159,7 +161,7 @@ void CTimer::Update(void) m_snTimeInMilliseconds = m_snPreviousTimeInMilliseconds + 16; } - m_FrameCounter++; + m_TickCounter++; } void CTimer::Suspend(void) diff --git a/src/core/Timer.h b/src/core/Timer.h index 393242dde..0bdd63953 100644 --- a/src/core/Timer.h +++ b/src/core/Timer.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once class CTimer { @@ -8,6 +8,7 @@ class CTimer static uint32 m_snTimeInMillisecondsNonClipped; static uint32 m_snPreviousTimeInMilliseconds; static uint32 m_FrameCounter; + static uint32 m_TickCounter; static float ms_fTimeScale; static float ms_fTimeStep; static float ms_fTimeStepNonClipped; @@ -24,6 +25,7 @@ class CTimer static float GetTimeStepNonClippedInMilliseconds(void) { return ms_fTimeStepNonClipped / 50.0f * 1000.0f; } static void SetTimeStepNonClipped(float ts) { ms_fTimeStepNonClipped = ts; } static const uint32 &GetFrameCounter(void) { return m_FrameCounter; } + static const uint32 &GetTickCounter(void) { return m_FrameCounter; } static void SetFrameCounter(uint32 fc) { m_FrameCounter = fc; } static const uint32 &GetTimeInMilliseconds(void) { return m_snTimeInMilliseconds; } static void SetTimeInMilliseconds(uint32 t) { m_snTimeInMilliseconds = t; } @@ -44,7 +46,7 @@ class CTimer static void Initialise(void); static void Shutdown(void); - static void Update(void); + static void Update(float timeMs); static void Suspend(void); static void Resume(void); static uint32 GetCyclesPerMillisecond(void); diff --git a/src/core/World.cpp b/src/core/World.cpp index d65d57dd4..3d789cd9c 100644 --- a/src/core/World.cpp +++ b/src/core/World.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "Camera.h" #include "CarCtrl.h" #include "CopPed.h" @@ -1917,7 +1917,7 @@ CWorld::RemoveStaticObjects() void CWorld::Process(void) { - if(!(CTimer::GetFrameCounter() & 63)) CReferences::PruneAllReferencesInWorld(); + if(!(CTimer::GetTickCounter() & 63)) CReferences::PruneAllReferencesInWorld(); if(bProcessCutsceneOnly) { for(int i = 0; i < NUMCUTSCENEOBJECTS; i++) { @@ -2079,9 +2079,9 @@ CWorld::Process(void) CMessages::Process(); Players[PlayerInFocus].Process(); CRecordDataForChase::SaveOrRetrieveCarPositions(); - if((CTimer::GetFrameCounter() & 7) == 1) { + if((CTimer::GetTickCounter() & 7) == 1) { RemoveFallenPeds(); - } else if((CTimer::GetFrameCounter() & 7) == 5) { + } else if((CTimer::GetTickCounter() & 7) == 5) { RemoveFallenCars(); } } diff --git a/src/core/ZoneCull.cpp b/src/core/ZoneCull.cpp index 075a13bcd..f4ddbf192 100644 --- a/src/core/ZoneCull.cpp +++ b/src/core/ZoneCull.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "General.h" #include "Building.h" @@ -258,7 +258,7 @@ CCullZones::Update(void) if(bCullZonesDisabled) return; - switch(CTimer::GetFrameCounter() & 7){ + switch(CTimer::GetTickCounter() & 7){ case 0: case 4: /* Update Cull zone */ diff --git a/src/core/Zones.cpp b/src/core/Zones.cpp index 2e3e0f6ee..0948e46d3 100644 --- a/src/core/Zones.cpp +++ b/src/core/Zones.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include @@ -124,7 +124,7 @@ void CTheZones::Update(void) { #ifdef SQUEEZE_PERFORMANCE - if (CTimer::GetFrameCounter() % 5 != 0) + if (CTimer::GetTickCounter() % 5 != 0) return; #endif CVector pos; diff --git a/src/core/main.cpp b/src/core/main.cpp index 843f0671f..ce047142a 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "rpmatfx.h" #include "rphanim.h" #include "rpskin.h" @@ -68,6 +68,8 @@ #include "screendroplets.h" #include "frontendoption.h" +#include + GlobalScene Scene; uint8 work_buff[55000]; @@ -1022,6 +1024,11 @@ Render2dStuffAfterFade(void) CFont::DrawFonts(); } +#include +namespace chrono = std::chrono; +float timeAlpha = 0.f; +bool toProcess = false; + void Idle(void *arg) { @@ -1029,13 +1036,7 @@ Idle(void *arg) CDraw::SetAspectRatio(CDraw::FindAspectRatio()); #endif - CTimer::Update(); - tbInit(); - - CSprite2d::InitPerFrame(); - CFont::InitPerFrame(); - // We're basically merging FrontendIdle and Idle (just like TheGame on PS2) #ifdef PS2_SAVE_DIALOG // Only exists on PC FrontendIdle, probably some PS2 bug fix @@ -1056,20 +1057,55 @@ Idle(void *arg) tbEndTimer("DMAudio.Service"); } - if (RsGlobal.quit) - return; + if(RsGlobal.quit) return; #else - CPointLights::InitPerFrame(); + // + static auto lastFrame = chrono::steady_clock::now(); + static float accumulatedTime = 0.f; + + auto now = chrono::steady_clock::now(); + auto deltaTime = chrono::duration(now - lastFrame).count(); + static constexpr float timestep = 1.f / 30; + lastFrame = now; + + accumulatedTime += deltaTime; + if(accumulatedTime > 0.25f) accumulatedTime = 0.25f; + while(accumulatedTime >= timestep) { + TheCamera.m_matrix.SaveOldMatrix(); + CGame::UpdateMatrices(); + tbStartTimer(0, "CGame::Process"); + CGame::Process(); + tbEndTimer("CGame::Process"); + tbStartTimer(0, "DMAudio.Service"); + DMAudio.Service(); + tbEndTimer("DMAudio.Service"); + CTimer::Update(timestep * 1000); + accumulatedTime -= timestep; + } - tbStartTimer(0, "CGame::Process"); - CGame::Process(); - tbEndTimer("CGame::Process"); + timeAlpha = accumulatedTime / timestep; + CGame::InterpolateMatrices(); + + if(TheCamera.m_pRwCamera) { + static RwMatrix interpolated; + interpolated = TheCamera.m_matrix.CreateMatrixInterpolated(); + RwFrame *frame = RwCameraGetFrame(TheCamera.m_pRwCamera); + *RwMatrixGetPos(RwFrameGetMatrix(frame)) = interpolated.pos; + *RwMatrixGetAt(RwFrameGetMatrix(frame)) = interpolated.up; + *RwMatrixGetUp(RwFrameGetMatrix(frame)) = interpolated.at; + *RwMatrixGetRight(RwFrameGetMatrix(frame)) = interpolated.right; + RwMatrixUpdate(RwFrameGetMatrix(frame)); + RwFrameUpdateObjects(frame); + } - tbStartTimer(0, "DMAudio.Service"); - DMAudio.Service(); - tbEndTimer("DMAudio.Service"); + uint32 f = CTimer::GetFrameCounter() + 1; + CTimer::SetFrameCounter(f); + CPointLights::InitPerFrame(); #endif + CSprite2d::InitPerFrame(); + CFont::InitPerFrame(); + if(CGame::bDemoMode && CTimer::GetTimeInMilliseconds() > (3*60 + 30)*1000 && !CCutsceneMgr::IsCutsceneProcessing()){ #ifdef PS2_MENU TheMemoryCard.m_bWantToLoad = false; @@ -1138,7 +1174,6 @@ Idle(void *arg) RwCameraSetFarClipPlane(Scene.camera, CTimeCycle::GetFarClip()); RwCameraSetFogDistance(Scene.camera, CTimeCycle::GetFogStart()); #endif - tbStartTimer(0, "RenderScene"); RenderScene(); tbEndTimer("RenderScene"); @@ -1219,7 +1254,7 @@ FrontendIdle(void) CDraw::SetAspectRatio(CDraw::FindAspectRatio()); #endif - CTimer::Update(); + CTimer::Update(1000.f/30); CSprite2d::SetRecipNearClip(); // this should be on InitialiseRenderWare according to PS2 asm. seems like a bug fix CSprite2d::InitPerFrame(); CFont::InitPerFrame(); @@ -1357,7 +1392,7 @@ TheModelViewer(void) CDraw::SetAspectRatio(CDraw::FindAspectRatio()); #endif CAnimViewer::Update(); - CTimer::Update(); + CTimer::Update(1000.f/30); SetLightsWithTimeOfDayColour(Scene.world); CRenderer::ConstructRenderList(); DoRWStuffStartOfFrame(CTimeCycle::GetSkyTopRed(), CTimeCycle::GetSkyTopGreen(), CTimeCycle::GetSkyTopBlue(), diff --git a/src/entities/Entity.cpp b/src/entities/Entity.cpp index 5e3204b2e..1a0824985 100644 --- a/src/entities/Entity.cpp +++ b/src/entities/Entity.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "General.h" #include "RwHelper.h" @@ -313,6 +313,17 @@ CEntity::DeleteRwObject(void) void CEntity::UpdateRwFrame(void) +{ + if(m_rwObject) { + if(RwObjectGetType(m_rwObject) == rpATOMIC) + RwFrameUpdateObjects(RpAtomicGetFrame((RpAtomic *)m_rwObject)); + else if(RwObjectGetType(m_rwObject) == rpCLUMP) + RwFrameUpdateObjects(RpClumpGetFrame((RpClump *)m_rwObject)); + } +} + +void +CEntity::UpdateRwFrameInterpolated(void) { if(m_rwObject){ if(RwObjectGetType(m_rwObject) == rpATOMIC) @@ -381,24 +392,24 @@ CEntity::PreRender(void) case ENTITY_TYPE_OBJECT: if(GetModelIndex() == MI_COLLECTABLE1){ CPickups::DoCollectableEffects(this); - GetMatrix().UpdateRW(); + GetMatrix().UpdateRWInterPolated(); UpdateRwFrame(); }else if(GetModelIndex() == MI_MONEY){ CPickups::DoMoneyEffects(this); - GetMatrix().UpdateRW(); + GetMatrix().UpdateRWInterPolated(); UpdateRwFrame(); }else if(GetModelIndex() == MI_NAUTICALMINE || GetModelIndex() == MI_CARMINE || GetModelIndex() == MI_BRIEFCASE){ if(((CObject*)this)->bIsPickup){ CPickups::DoMineEffects(this); - GetMatrix().UpdateRW(); + GetMatrix().UpdateRWInterPolated(); UpdateRwFrame(); } }else if(IsPickupModel(GetModelIndex())){ if(((CObject*)this)->bIsPickup){ CPickups::DoPickUpEffects(this); - GetMatrix().UpdateRW(); + GetMatrix().UpdateRWInterPolated(); UpdateRwFrame(); }else if(GetModelIndex() == MI_GRENADE){ CMotionBlurStreaks::RegisterStreak((uintptr)this, diff --git a/src/entities/Entity.h b/src/entities/Entity.h index ba4f7ab08..d14cc6824 100644 --- a/src/entities/Entity.h +++ b/src/entities/Entity.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once #include "ModelInfo.h" #include "Placeable.h" @@ -152,6 +152,7 @@ class CEntity : public CPlaceable bool IsVisibleComplex(void) { return m_rwObject && bIsVisible && GetIsOnScreenComplex(); } int16 GetModelIndex(void) const { return m_modelIndex; } void UpdateRwFrame(void); + void UpdateRwFrameInterpolated(); void SetupBigBuilding(void); void AttachToRwObject(RwObject *obj); diff --git a/src/entities/Physical.cpp b/src/entities/Physical.cpp index 172bae3f0..f87fa48b8 100644 --- a/src/entities/Physical.cpp +++ b/src/entities/Physical.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "World.h" #include "Timer.h" @@ -321,7 +321,7 @@ CPhysical::PlacePhysicalRelativeToOtherPhysical(CPhysical *other, CPhysical *phy CVector pos = other->m_vecMoveSpeed*step + worldPos; CWorld::Remove(phys); - phys->GetMatrix() = other->GetMatrix(); + phys->GetMatrix().save(other->GetMatrix()); phys->SetPosition(pos); phys->m_vecMoveSpeed = other->m_vecMoveSpeed; phys->GetMatrix().UpdateRW(); @@ -1791,7 +1791,7 @@ CPhysical::ProcessShift(void) CWorld::AdvanceCurrentScanCode(); for(node = m_entryInfoList.first; node; node = node->next) if(ProcessCollisionSectorList(node->sector->m_lists)){ - GetMatrix() = matrix; + GetMatrix().save(matrix); return; } } @@ -1898,7 +1898,7 @@ CPhysical::ProcessCollision(void) !ped->bWasStanding && ped->bIsStanding) savedMatrix.GetPosition().z = GetPosition().z; - GetMatrix() = savedMatrix; + GetMatrix().save(savedMatrix); CTimer::SetTimeStep(savedTimeStep); return; } @@ -1906,7 +1906,7 @@ CPhysical::ProcessCollision(void) !ped->bWasStanding && ped->bIsStanding) savedMatrix.GetPosition().z = GetPosition().z; - GetMatrix() = savedMatrix; + GetMatrix().save(savedMatrix); CTimer::SetTimeStep(savedTimeStep); if(IsVehicle()){ CVehicle *veh = (CVehicle*)this; @@ -1937,7 +1937,7 @@ CPhysical::ProcessCollision(void) if(IsVehicle()) ((CVehicle*)this)->bVehicleColProcessed = true; if(CheckCollision()){ - GetMatrix() = savedMatrix; + GetMatrix().save(savedMatrix); return; } } diff --git a/src/math/Matrix.cpp b/src/math/Matrix.cpp index a8b1b1821..030b1131c 100644 --- a/src/math/Matrix.cpp +++ b/src/math/Matrix.cpp @@ -1,4 +1,6 @@ -#include "common.h" +#include "common.h" + +extern float timeAlpha; CMatrix::CMatrix(void) { @@ -66,18 +68,31 @@ CMatrix::Update(void) void CMatrix::UpdateRW(void) { - if (m_attachment) { + if(m_attachment) { *m_attachment = m_matrix; RwMatrixUpdate(m_attachment); } } +void +CMatrix::UpdateRWInterPolated(void) +{ + if(m_attachment) { + *m_attachment = CreateMatrixInterpolated(); + RwMatrixUpdate(m_attachment); + } +} + void CMatrix::operator=(CMatrix const &rhs) { m_matrix = rhs.m_matrix; - if (m_attachment) - UpdateRW(); +} + +void +CMatrix::save(CMatrix const &rhs) +{ + m_matrix = rhs.m_matrix; } void @@ -419,11 +434,58 @@ CMatrix::operator*=(CMatrix const &rhs) } void -CMatrix::Reorthogonalise(void) +CMatrix::SaveOldMatrix() +{ + m_matrix_old = m_matrix; +} + +RwMatrix +CMatrix::CreateMatrixInterpolated() { - CVector &r = GetRight(); - CVector &f = GetForward(); - CVector &u = GetUp(); + RwMatrix m_matrix_interpolated; + if(*(CVector *)&m_matrix_old.pos != CVector(0, 0, 0)) + m_matrix_interpolated = InterpolateMatrix(m_matrix_old, m_matrix, timeAlpha); + else + m_matrix_interpolated = m_matrix; + return m_matrix_interpolated; +} + +CVector & +CMatrix::GetPositionInterpolated() +{ + return *(CVector*)RwMatrixGetPos(m_attachment); +} + +CVector & +CMatrix::GetRightInterpolated() +{ + return *(CVector *)RwMatrixGetRight(m_attachment); +} + +CVector & +CMatrix::GetForwardInterpolated() +{ + return *(CVector *)RwMatrixGetUp(m_attachment); +} + +CVector & +CMatrix::GetUpInterpolated() +{ + return *(CVector *)RwMatrixGetAt(m_attachment); +} + +RwMatrix & +CMatrix::GetMatrixInterpolated() +{ + return *m_attachment; +} + +void +CMatrix::Reorthogonalise(void) const +{ + CVector &r = *(CVector *)&m_matrix.right; + CVector &f = *(CVector *)&m_matrix.up; + CVector &u = *(CVector *)&m_matrix.at; u = CrossProduct(r, f); u.Normalise(); r = CrossProduct(f, u); @@ -518,6 +580,79 @@ Invert(const CMatrix &src, CMatrix &dst) return dst; } +RwMatrix +Mult(const RwMatrix &src1_, const RwMatrix &src2_) +{ + RwMatrix result; + RwMatrix *dst = &result; + const RwMatrix *src1 = &src1_; + const RwMatrix *src2 = &src2_; + dst->right.x = src1->right.x * src2->right.x + src1->up.x * src2->right.y + src1->at.x * src2->right.z; + dst->right.y = src1->right.y * src2->right.x + src1->up.y * src2->right.y + src1->at.y * src2->right.z; + dst->right.z = src1->right.z * src2->right.x + src1->up.z * src2->right.y + src1->at.z * src2->right.z; + dst->up.x = src1->right.x * src2->up.x + src1->up.x * src2->up.y + src1->at.x * src2->up.z; + dst->up.y = src1->right.y * src2->up.x + src1->up.y * src2->up.y + src1->at.y * src2->up.z; + dst->up.z = src1->right.z * src2->up.x + src1->up.z * src2->up.y + src1->at.z * src2->up.z; + dst->at.x = src1->right.x * src2->at.x + src1->up.x * src2->at.y + src1->at.x * src2->at.z; + dst->at.y = src1->right.y * src2->at.x + src1->up.y * src2->at.y + src1->at.y * src2->at.z; + dst->at.z = src1->right.z * src2->at.x + src1->up.z * src2->at.y + src1->at.z * src2->at.z; + dst->pos.x = src1->right.x * src2->pos.x + src1->up.x * src2->pos.y + src1->at.x * src2->pos.z + src1->pos.x; + dst->pos.y = src1->right.y * src2->pos.x + src1->up.y * src2->pos.y + src1->at.y * src2->pos.z + src1->pos.y; + dst->pos.z = src1->right.z * src2->pos.x + src1->up.z * src2->pos.y + src1->at.z * src2->pos.z + src1->pos.z; + return result; +} + +RwMatrix +CreateMatrixWithScale(float s) +{ + RwMatrix m_matrix; + m_matrix.right.x = s; + m_matrix.right.y = 0.0f; + m_matrix.right.z = 0.0f; + + m_matrix.up.x = 0.0f; + m_matrix.up.y = s; + m_matrix.up.z = 0.0f; + + m_matrix.at.x = 0.0f; + m_matrix.at.y = 0.0f; + m_matrix.at.z = s; + + m_matrix.pos.x = 0.0f; + m_matrix.pos.y = 0.0f; + m_matrix.pos.z = 0.0f; + return m_matrix; +} + +RwMatrix +Add(const RwMatrix &m1, const RwMatrix &m2) +{ + RwMatrix o; + o.right.x = m1.right.x + m2.right.x; + o.up.x = m1.up.x + m2.up.x; + o.at.x = m1.at.x + m2.at.x; + o.right.y = m1.right.y + m2.right.y; + o.up.y = m1.up.y + m2.up.y; + o.at.y = m1.at.y + m2.at.y; + o.right.z = m1.right.z + m2.right.z; + o.up.z = m1.up.z + m2.up.z; + o.at.z = m1.at.z + m2.at.z; + o.pos.x = m1.pos.x + m2.pos.x; + o.pos.y = m1.pos.y + m2.pos.y; + o.pos.z = m1.pos.z + m2.pos.z; + return o; +} + +RwMatrix +InterpolateMatrix(RwMatrix &prev, RwMatrix &now, float interpolation) +{ + RwMatrix result; + result = Mult(prev, CreateMatrixWithScale(1.0f - interpolation)); + result.pos = result.pos * (1.f - interpolation); + result = Add(result, Mult(CreateMatrixWithScale(interpolation), now)); + return result; +} + CMatrix Invert(const CMatrix &matrix) { @@ -526,7 +661,7 @@ Invert(const CMatrix &matrix) } void -CCompressedMatrixNotAligned::CompressFromFullMatrix(CMatrix &other) +CCompressedMatrixNotAligned::CompressFromFullMatrix(CMatrix other) { m_rightX = 127.0f * other.GetRight().x; m_rightY = 127.0f * other.GetRight().y; diff --git a/src/math/Matrix.h b/src/math/Matrix.h index d8f6388de..2757f5f5f 100644 --- a/src/math/Matrix.h +++ b/src/math/Matrix.h @@ -1,9 +1,10 @@ -#pragma once +#pragma once class CMatrix { public: RwMatrix m_matrix; + RwMatrix m_matrix_old; RwMatrix *m_attachment; bool m_hasRwMatrix; // are we the owner? @@ -21,14 +22,26 @@ class CMatrix void Detach(void); void Update(void); void UpdateRW(void); + void UpdateRWInterPolated(); void operator=(CMatrix const &rhs); + void save(CMatrix const &rhs); CMatrix &operator+=(CMatrix const &rhs); CMatrix &operator*=(CMatrix const &rhs); - CVector &GetPosition(void){ return *(CVector*)&m_matrix.pos; } - CVector &GetRight(void) { return *(CVector*)&m_matrix.right; } - CVector &GetForward(void) { return *(CVector*)&m_matrix.up; } - CVector &GetUp(void) { return *(CVector*)&m_matrix.at; } + void SaveOldMatrix(); + RwMatrix CreateMatrixInterpolated(); + + CVector &GetPosition(void) { return *(CVector *)&m_matrix.pos; } + CVector &GetRight(void) { return *(CVector *)&m_matrix.right; } + CVector &GetForward(void) { return *(CVector *)&m_matrix.up; } + CVector &GetUp(void) { return *(CVector *)&m_matrix.at; } + + + CVector &GetPositionInterpolated(void); // we assume that matrix was interpolated and updated earlier + CVector &GetRightInterpolated(void); // also here + CVector &GetForwardInterpolated(void); // also here + CVector &GetUpInterpolated(void); // also here + RwMatrix &GetMatrixInterpolated(void); // also here void SetTranslate(float x, float y, float z); void SetTranslate(const CVector &trans){ SetTranslate(trans.x, trans.y, trans.z); } @@ -81,7 +94,7 @@ class CMatrix void RotateY(float y); void RotateZ(float z); - void Reorthogonalise(void); + void Reorthogonalise(void) const; void CopyOnlyMatrix(CMatrix *other); void SetUnity(void); void ResetOrientation(void); @@ -109,7 +122,10 @@ inline CVector MultiplyInverse(const CMatrix &mat, const CVector &vec) mat.m_matrix.at.x * v.x + mat.m_matrix.at.y * v.y + mat.m_matrix.at.z * v.z); } - +RwMatrix Mult(const RwMatrix &src1_, const RwMatrix &src2_); +RwMatrix CreateMatrixWithScale(float s); +RwMatrix Add(const RwMatrix &m1, const RwMatrix &m2); +RwMatrix InterpolateMatrix(RwMatrix &prev, RwMatrix &now, float t); class CCompressedMatrixNotAligned { @@ -121,7 +137,7 @@ class CCompressedMatrixNotAligned int8 m_upY; int8 m_upZ; public: - void CompressFromFullMatrix(CMatrix &other); + void CompressFromFullMatrix(CMatrix other); void DecompressIntoFullMatrix(CMatrix &other); }; diff --git a/src/math/Vector.cpp b/src/math/Vector.cpp index 42e1828ed..fc8d29383 100644 --- a/src/math/Vector.cpp +++ b/src/math/Vector.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" void CVector::Normalise(void) @@ -44,3 +44,12 @@ operator*(const CMatrix &mat, const CVector &vec) mat.m_matrix.right.y * vec.x + mat.m_matrix.up.y * vec.y + mat.m_matrix.at.y * vec.z + mat.m_matrix.pos.y, mat.m_matrix.right.z * vec.x + mat.m_matrix.up.z * vec.y + mat.m_matrix.at.z * vec.z + mat.m_matrix.pos.z); } + +CVector +operator*(const RwMatrix &mat, const CVector &vec) +{ + // TODO: VU0 code + return CVector(mat.right.x * vec.x + mat.up.x * vec.y + mat.at.x * vec.z + mat.pos.x, + mat.right.y * vec.x + mat.up.y * vec.y + mat.at.y * vec.z + mat.pos.y, + mat.right.z * vec.x + mat.up.z * vec.y + mat.at.z * vec.z + mat.pos.z); +} diff --git a/src/math/Vector.h b/src/math/Vector.h index 082b296f2..f5d6c4b3e 100644 --- a/src/math/Vector.h +++ b/src/math/Vector.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once class CVector { @@ -127,4 +127,5 @@ class CMatrix; CVector Multiply3x3(const CMatrix &mat, const CVector &vec); CVector Multiply3x3(const CVector &vec, const CMatrix &mat); -CVector operator*(const CMatrix &mat, const CVector &vec); \ No newline at end of file +CVector operator*(const CMatrix &mat, const CVector &vec); +CVector operator*(const RwMatrix &mat, const CVector &vec); \ No newline at end of file diff --git a/src/objects/CutsceneHead.cpp b/src/objects/CutsceneHead.cpp index 15611c297..d6c718ed9 100644 --- a/src/objects/CutsceneHead.cpp +++ b/src/objects/CutsceneHead.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include #include "main.h" @@ -125,7 +125,7 @@ CCutsceneHead::Render(void) m_matrix = CMatrix(RwFrameGetLTM(m_pHeadNode)) * m_matrix; } - UpdateRwFrame(); + UpdateRwFrameInterpolated(); assert(RwObjectGetType(m_rwObject) == rpCLUMP); atm = GetFirstAtomic((RpClump*)m_rwObject); diff --git a/src/objects/ParticleObject.cpp b/src/objects/ParticleObject.cpp index 71f223d76..0c435e450 100644 --- a/src/objects/ParticleObject.cpp +++ b/src/objects/ParticleObject.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "ParticleObject.h" #include "Timer.h" @@ -427,7 +427,7 @@ CParticleObject::UpdateAll(void) } { - int32 frame = CTimer::GetFrameCounter() & 31; + int32 frame = CTimer::GetTickCounter() & 31; int32 counter = 0; CParticleObject *pobj = pFarListHead; diff --git a/src/peds/CopPed.cpp b/src/peds/CopPed.cpp index f289697ec..a0bdb6243 100644 --- a/src/peds/CopPed.cpp +++ b/src/peds/CopPed.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "World.h" #include "PlayerPed.h" @@ -710,7 +710,7 @@ CCopPed::ProcessControl(void) bool dontShoot = false; if (GetIsOnScreen() && CRenderer::IsEntityCullZoneVisible(this)) { - if (((CTimer::GetFrameCounter() + m_randomSeed) & 0x1F) == 17) { + if (((CTimer::GetTickCounter() + m_randomSeed) & 0x1F) == 17) { CEntity *foundBuilding = nil; CColPoint foundCol; CVector lookPos = GetPosition() + CVector(0.0f, 0.0f, 0.7f); diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index c41c1f0cc..5ad07c11e 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "main.h" #include "Pools.h" @@ -348,7 +348,7 @@ CPed::SetPedStats(ePedStats pedStat) void CPed::BuildPedLists(void) { - if (((CTimer::GetFrameCounter() + m_randomSeed) % 16) == 0) { + if (((CTimer::GetTickCounter() + m_randomSeed) % 16) == 0) { CVector centre = CEntity::GetBoundCentre(); CRect rect(centre.x - 20.0f, centre.y - 20.0f, @@ -746,7 +746,7 @@ CPed::ScanForThreats(void) bool weSawOurEnemy = false; bool weMaySeeOurEnemy = false; float closestEnemyDist = 60.0f; - if ((CTimer::GetFrameCounter() + (uint8)m_randomSeed + 16) & 4) { + if ((CTimer::GetTickCounter() + (uint8)m_randomSeed + 16) & 4) { for (int i = 0; i < m_numNearPeds; ++i) { if (CharCreatedBy == RANDOM_CHAR && m_nearPeds[i]->CharCreatedBy == MISSION_CHAR && !m_nearPeds[i]->IsPlayer()) { @@ -2502,7 +2502,7 @@ CPed::ProcessControl(void) } #endif } - } else if ((CTimer::GetFrameCounter() + m_randomSeed % 256 + 3) & 7) { + } else if ((CTimer::GetTickCounter() + m_randomSeed % 256 + 3) & 7) { if (IsPlayer() && m_nPedState != PED_JUMP && pad0->JumpJustDown()) { int16 padWalkX = pad0->GetPedWalkLeftRight(); int16 padWalkY = pad0->GetPedWalkUpDown(); @@ -2992,7 +2992,7 @@ CPed::ProcessControl(void) SetMoveAnim(); if (bPedIsBleeding) { if (CGame::nastyGame) { - if (!(CTimer::GetFrameCounter() & 3)) { + if (!(CTimer::GetTickCounter() & 3)) { CVector cameraDist = GetPosition() - TheCamera.GetPosition(); if (cameraDist.MagnitudeSqr() < sq(50.0f)) { @@ -3434,7 +3434,7 @@ CPed::PlayFootSteps(void) if (m_nSurfaceTouched == SURFACE_WATER) { float pedSpeed = CVector2D(m_vecMoveSpeed).Magnitude(); - if (pedSpeed > 0.03f && CTimer::GetFrameCounter() % 2 == 0 && pedSpeed > 0.13f) { + if (pedSpeed > 0.03f && CTimer::GetTickCounter() % 2 == 0 && pedSpeed > 0.13f) { #ifdef PC_PARTICLE float particleSize = pedSpeed * 2.0f; @@ -4824,7 +4824,7 @@ CPed::PreRender(void) } #endif - if (bBodyPartJustCameOff && bIsPedDieAnimPlaying && m_bodyPartBleeding != -1 && (CTimer::GetFrameCounter() & 7) > 3) { + if (bBodyPartJustCameOff && bIsPedDieAnimPlaying && m_bodyPartBleeding != -1 && (CTimer::GetTickCounter() & 7) > 3) { CVector bloodDir(0.0f, 0.0f, 0.0f); CVector bloodPos(0.0f, 0.0f, 0.0f); @@ -5078,13 +5078,13 @@ CPed::SetFall(int extraTime, AnimationId animId, uint8 evenIfNotInControl) m_getUpTimer = 1000.0f * fallAssoc->hierarchy->totalLength + CTimer::GetTimeInMilliseconds() + extraTime - + ((m_randomSeed + CTimer::GetFrameCounter()) % 1000); + + ((m_randomSeed + CTimer::GetTickCounter()) % 1000); } } else { m_getUpTimer = extraTime + CTimer::GetTimeInMilliseconds() + 1000 - + ((m_randomSeed + CTimer::GetFrameCounter()) % 1000); + + ((m_randomSeed + CTimer::GetTickCounter()) % 1000); } bFallenDown = true; } @@ -5227,7 +5227,7 @@ CPed::SetGetUp(void) CVehicle *veh = (CVehicle*)CPedPlacement::IsPositionClearOfCars(&GetPosition()); if (veh && veh->m_vehType != VEHICLE_TYPE_BIKE || collidingVeh && collidingVeh->IsVehicle() && collidingVeh->m_vehType != VEHICLE_TYPE_BIKE - && ((uint8)(CTimer::GetFrameCounter() + m_randomSeed + 5) % 8 || + && ((uint8)(CTimer::GetTickCounter() + m_randomSeed + 5) % 8 || CCollision::ProcessColModels(GetMatrix(), *GetColModel(), collidingVeh->GetMatrix(), *collidingVeh->GetColModel(), aTempPedColPts, nil, nil) > 0)) { @@ -5421,7 +5421,7 @@ CPed::Seek(void) m_objective != OBJECTIVE_ENTER_CAR_AS_PASSENGER && m_objective != OBJECTIVE_SOLICIT_VEHICLE && !bDuckAndCover) { if ((!m_pedInObjective || !m_pedInObjective->bInVehicle) - && !((CTimer::GetFrameCounter() + (m_randomSeed % 256) + 17) & 7)) { + && !((CTimer::GetTickCounter() + (m_randomSeed % 256) + 17) & 7)) { CEntity *obstacle = CWorld::TestSphereAgainstWorld(m_vecSeekPos, 0.4f, nil, false, true, false, false, false, false); @@ -5822,7 +5822,7 @@ CPed::WanderRange(void) bool arrived = Seek(); if (arrived) { Idle(); - if ((m_randomSeed + 3 * CTimer::GetFrameCounter()) % 1000 > 997) { + if ((m_randomSeed + 3 * CTimer::GetTickCounter()) % 1000 > 997) { CVector2D newCoords2D = m_wanderRangeBounds->GetRandomPointInRange(); SetSeek(CVector(newCoords2D.x, newCoords2D.y, GetPosition().z), 2.5f); } @@ -5894,7 +5894,7 @@ CPed::WanderPath(void) return; CPathNode *previousLastNode = m_pLastPathNode; - uint8 randVal = (m_randomSeed + 3 * CTimer::GetFrameCounter()) % 100; + uint8 randVal = (m_randomSeed + 3 * CTimer::GetTickCounter()) % 100; // We don't prefer 180-degree turns in normal situations uint8 dirWeWouldntPrefer = m_nPathDir; @@ -6000,7 +6000,7 @@ CPed::Avoid(void) if (distToPed.Magnitude() <= 1.0f && OurPedCanSeeThisOne((CEntity*)nearestPed)) { m_nPedStateTimer = CTimer::GetTimeInMilliseconds() - + 500 + (m_randomSeed + 3 * CTimer::GetFrameCounter()) + + 500 + (m_randomSeed + 3 * CTimer::GetTickCounter()) % 1000 / 5; m_fRotationDest += DEGTORAD(45.0f); @@ -7063,7 +7063,7 @@ CPed::LookForInterestingNodes(void) C2dEffect *effect; CMatrix *objMat; - if ((CTimer::GetFrameCounter() + (m_randomSeed % 256)) & 7 || CTimer::GetTimeInMilliseconds() <= m_standardTimer) { + if ((CTimer::GetTickCounter() + (m_randomSeed % 256)) & 7 || CTimer::GetTimeInMilliseconds() <= m_standardTimer) { return false; } bool found = false; diff --git a/src/peds/PedAI.cpp b/src/peds/PedAI.cpp index 383034732..4784b2579 100644 --- a/src/peds/PedAI.cpp +++ b/src/peds/PedAI.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "main.h" #include "Particle.h" @@ -897,8 +897,8 @@ CPed::ProcessObjective(void) int chosenModel = CCarCtrl::ChooseModel(&zoneInfo, &ourPos, &chosenCarClass); CAutomobile *newVeh = new CAutomobile(chosenModel, RANDOM_VEHICLE); if (newVeh) { - newVeh->GetMatrix().GetPosition() = ThePaths.m_pathNodes[closestNode].GetPosition(); - newVeh->GetMatrix().GetPosition().z += 4.0f; + newVeh->GetMatrix().GetPosition() = ThePaths.m_pathNodes[closestNode].GetPosition(); + newVeh->GetMatrix().GetPosition().z += 4.0f; newVeh->SetHeading(DEGTORAD(200.0f)); newVeh->SetStatus(STATUS_ABANDONED); newVeh->m_nDoorLock = CARLOCK_UNLOCKED; @@ -3280,7 +3280,7 @@ CPed::LineUpPedWithCar(PedLineUpPhase phase) CMatrix vehDoorMat(veh->GetMatrix()); vehDoorMat.GetPosition() += Multiply3x3(vehDoorMat, GetLocalPositionToOpenCarDoor(veh, m_vehEnterType, 0.0f)); // VC couch anims are inverted, so they're fixing it here. - GetMatrix() = vehDoorMat; + GetMatrix().save(vehDoorMat); } } diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp index fa865aec6..dda836254 100644 --- a/src/peds/PlayerPed.cpp +++ b/src/peds/PlayerPed.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "RwHelper.h" #include "PlayerPed.h" @@ -1257,7 +1257,7 @@ CPlayerPed::ProcessControl(void) if (m_pCurrentPhysSurface && m_pCurrentPhysSurface->IsVehicle() && ((CVehicle*)m_pCurrentPhysSurface)->IsBoat()) { bTryingToReachDryLand = true; - } else if (!(((uint8)CTimer::GetFrameCounter() + m_randomSeed) & 0xF)) { + } else if (!(((uint8)CTimer::GetTickCounter() + m_randomSeed) & 0xF)) { CVehicle *nearVeh = (CVehicle*)CWorld::TestSphereAgainstWorld(GetPosition(), 7.0f, nil, false, true, false, false, false, false); if (nearVeh && nearVeh->IsBoat()) diff --git a/src/peds/Population.cpp b/src/peds/Population.cpp index b3eaf4718..e09651ab6 100644 --- a/src/peds/Population.cpp +++ b/src/peds/Population.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "Game.h" #include "General.h" @@ -859,7 +859,7 @@ CPopulation::MoveCarsAndPedsOutOfAbandonedZones() { eLevelName level; int zone; - int frame = CTimer::GetFrameCounter() & 7; + int frame = CTimer::GetTickCounter() & 7; if (frame == 1) { int movedVehicleCount = 0; int poolSize = CPools::GetVehiclePool()->GetSize(); @@ -1067,7 +1067,7 @@ CPopulation::TestSafeForRealObject(CDummyObject *dummy) void CPopulation::ManagePopulation(void) { - int frameMod32 = CTimer::GetFrameCounter() & 31; + int frameMod32 = CTimer::GetTickCounter() & 31; CVector playerPos = FindPlayerCentreOfWorld(CWorld::PlayerInFocus); // Why this code is here?! Delete temporary objects when they got too far, and convert others to "dummy" objects. (like lamp posts) diff --git a/src/render/Clouds.cpp b/src/render/Clouds.cpp index 05ddbcdc3..f7da4dedc 100644 --- a/src/render/Clouds.cpp +++ b/src/render/Clouds.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "Sprite.h" #include "Sprite2d.h" @@ -336,7 +336,7 @@ CClouds::RenderBackground(int16 topred, int16 topgreen, int16 topblue, ms_colourTop.b = 50; ms_colourTop.a = 255; if(gbShowCollisionPolys){ - if(CTimer::GetFrameCounter() & 1){ + if(CTimer::GetTickCounter() & 1){ ms_colourTop.r = 0; ms_colourTop.g = 0; ms_colourTop.b = 0; diff --git a/src/render/Coronas.cpp b/src/render/Coronas.cpp index 33c3f4bfa..d0dbaaa19 100644 --- a/src/render/Coronas.cpp +++ b/src/render/Coronas.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "main.h" #include "General.h" @@ -443,7 +443,7 @@ CCoronas::RenderReflections(void) // check if we want a reflection on this corona if(aCoronas[i].renderReflection){ - if(((CTimer::GetFrameCounter() + i) & 0xF) == 0 && + if(((CTimer::GetTickCounter() + i) & 0xF) == 0 && CWorld::ProcessVerticalLine(aCoronas[i].coors, -1000.0f, point, entity, true, false, false, false, true, false, nil)) aCoronas[i].heightAboveRoad = aCoronas[i].coors.z - point.point.z; }else{ diff --git a/src/render/Fluff.cpp b/src/render/Fluff.cpp index 690a1d3f1..473248ae2 100644 --- a/src/render/Fluff.cpp +++ b/src/render/Fluff.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "main.h" #include "Entity.h" @@ -156,7 +156,7 @@ void CMovingThings::Update() #ifndef SQUEEZE_PERFORMANCE const int TIME_SPAN = 64; // frames to process all aMovingThings - int block = CTimer::GetFrameCounter() % TIME_SPAN; + int block = CTimer::GetTickCounter() % TIME_SPAN; for (i = (block * NUMMOVINGTHINGS) / TIME_SPAN; i < ((block + 1) * NUMMOVINGTHINGS) / TIME_SPAN; i++) { if (aMovingThings[i].m_nHidden == 1) @@ -171,17 +171,17 @@ void CMovingThings::Update() for (i = 0; i < ARRAY_SIZE(aScrollBars); ++i) { - if (aScrollBars[i].IsVisible() || (CTimer::GetFrameCounter() + i) % 8 == 0) + if (aScrollBars[i].IsVisible() || (CTimer::GetTickCounter() + i) % 8 == 0) aScrollBars[i].Update(); } for (i = 0; i < ARRAY_SIZE(aTowerClocks); ++i) { - if (aTowerClocks[i].IsVisible() || (CTimer::GetFrameCounter() + i) % 8 == 0) + if (aTowerClocks[i].IsVisible() || (CTimer::GetTickCounter() + i) % 8 == 0) aTowerClocks[i].Update(); } for (i = 0; i < ARRAY_SIZE(aDigitalClocks); ++i) { - if (aDigitalClocks[i].IsVisible() || (CTimer::GetFrameCounter() + i) % 8 == 0) + if (aDigitalClocks[i].IsVisible() || (CTimer::GetTickCounter() + i) % 8 == 0) aDigitalClocks[i].Update(); } } diff --git a/src/render/Particle.cpp b/src/render/Particle.cpp index acce946b2..d4a08c677 100644 --- a/src/render/Particle.cpp +++ b/src/render/Particle.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "General.h" #include "Timer.h" @@ -781,7 +781,7 @@ CParticle *CParticle::AddParticle(tParticleType type, CVector const &vecPos, CVe || type == PARTICLE_BURNINGRUBBER_SMOKE || type == PARTICLE_EXHAUST_FUMES || type == PARTICLE_CARCOLLISION_DUST ) - && nParticleCreationInterval & CTimer::GetFrameCounter() ) + && nParticleCreationInterval & CTimer::GetTickCounter() ) { return nil; } diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 83bd0d21f..f141fb8b6 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "main.h" #include "Lights.h" diff --git a/src/render/Rubbish.cpp b/src/render/Rubbish.cpp index bfd50c07e..56e2160ca 100644 --- a/src/render/Rubbish.cpp +++ b/src/render/Rubbish.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "main.h" #include "General.h" @@ -142,7 +142,7 @@ CRubbish::Render(void) void CRubbish::StirUp(CVehicle *veh) { - if((CTimer::GetFrameCounter() ^ (veh->m_randomSeed&3)) == 0) + if((CTimer::GetTickCounter() ^ (veh->m_randomSeed&3)) == 0) return; if(Abs(veh->GetPosition().x - TheCamera.GetPosition().x) < 20.0f && @@ -295,7 +295,7 @@ CRubbish::Update(void) freq = 1; else freq = 0; - if((CTimer::GetFrameCounter() & freq) == 0){ + if((CTimer::GetTickCounter() & freq) == 0){ // Pick a random sheet and set animation state if static int i = CGeneral::GetRandomNumber() % NUM_RUBBISH_SHEETS; if(aSheets[i].m_state == 1){ @@ -324,8 +324,8 @@ CRubbish::Update(void) } // Remove sheets that are too far away - int i = (CTimer::GetFrameCounter()%(NUM_RUBBISH_SHEETS/4))*4; - int last = ((CTimer::GetFrameCounter()%(NUM_RUBBISH_SHEETS/4)) + 1)*4; + int i = (CTimer::GetTickCounter()%(NUM_RUBBISH_SHEETS/4))*4; + int last = ((CTimer::GetTickCounter()%(NUM_RUBBISH_SHEETS/4)) + 1)*4; for(; i < last; i++){ if(aSheets[i].m_state == 1 && (aSheets[i].m_basePos - TheCamera.GetPosition()).MagnitudeSqr2D() > SQR(RUBBISH_MAX_DIST+1.0f)){ diff --git a/src/render/SpecialFX.cpp b/src/render/SpecialFX.cpp index 34423d83d..03ab80d98 100644 --- a/src/render/SpecialFX.cpp +++ b/src/render/SpecialFX.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "SpecialFX.h" #include "RenderBuffer.h" @@ -1108,7 +1108,7 @@ CRGBA FoamColour(255, 255, 255, 255); unsigned int CSpecialParticleStuff::BoatFromStart; void -CSpecialParticleStuff::CreateFoamAroundObject(CMatrix* pMatrix, float innerFw, float innerRg, float innerUp, int32 particles) +CSpecialParticleStuff::CreateFoamAroundObject(CMatrix *pMatrix, float innerFw, float innerRg, float innerUp, int32 particles) { float outerFw = innerFw + 5.0f; float outerRg = innerRg + 5.0f; @@ -1147,7 +1147,7 @@ CSpecialParticleStuff::StartBoatFoamAnimation() } void -CSpecialParticleStuff::UpdateBoatFoamAnimation(CMatrix* pMatrix) +CSpecialParticleStuff::UpdateBoatFoamAnimation(CMatrix *pMatrix) { static int32 FrameInAnimation = 0; static float X, Y, Z, dX, dY, dZ; diff --git a/src/render/SpecialFX.h b/src/render/SpecialFX.h index 2d9f18b13..c213ae2a2 100644 --- a/src/render/SpecialFX.h +++ b/src/render/SpecialFX.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once class CSpecialFX { @@ -218,7 +218,7 @@ class CSpecialParticleStuff { static uint32 BoatFromStart; public: - static void CreateFoamAroundObject(CMatrix*, float, float, float, int32); + static void CreateFoamAroundObject(CMatrix *, float, float, float, int32); static void StartBoatFoamAnimation(); - static void UpdateBoatFoamAnimation(CMatrix*); + static void UpdateBoatFoamAnimation(CMatrix *); }; diff --git a/src/render/WaterCannon.cpp b/src/render/WaterCannon.cpp index f54b31b9c..9b2367fb3 100644 --- a/src/render/WaterCannon.cpp +++ b/src/render/WaterCannon.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "WaterCannon.h" #include "Vector.h" @@ -81,7 +81,7 @@ void CWaterCannon::Update_OncePerFrame(int16 index) if ( m_abUsed[extinguishingPoint] ) gFireManager.ExtinguishPoint(m_avecPos[extinguishingPoint], 3.0f); - if ( ((index + CTimer::GetFrameCounter()) & 3) == 0 ) + if ( ((index + CTimer::GetTickCounter()) & 3) == 0 ) PushPeds(); // free if unused diff --git a/src/render/Weather.cpp b/src/render/Weather.cpp index f16467b63..c4d2c446d 100644 --- a/src/render/Weather.cpp +++ b/src/render/Weather.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "Weather.h" @@ -163,7 +163,7 @@ void CWeather::Update(void) else { // 0.125 probability LightningBurst = false; - LightningDuration = Min(CTimer::GetFrameCounter() - LightningStart, 20); + LightningDuration = Min(CTimer::GetTickCounter() - LightningStart, 20); LightningFlash = false; WhenToPlayLightningSound = CTimer::GetTimeInMilliseconds() + 150 * (20 - LightningDuration); } @@ -175,7 +175,7 @@ void CWeather::Update(void) } else { LightningBurst = true; - LightningStart = CTimer::GetFrameCounter(); + LightningStart = CTimer::GetTickCounter(); LightningFlashLastChange = CTimer::GetTimeInMilliseconds(); LightningFlash = true; } diff --git a/src/rw/RwHelper.cpp b/src/rw/RwHelper.cpp index 0069934ff..38a7c3706 100644 --- a/src/rw/RwHelper.cpp +++ b/src/rw/RwHelper.cpp @@ -1,4 +1,4 @@ -#if defined RW_D3D9 || defined RWLIBS +#if defined RW_D3D9 || defined RWLIBS #define WITHD3D #endif #include "common.h" diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index ec71f6900..a5ab72ecb 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -1108,7 +1108,7 @@ CAutomobile::ProcessControl(void) ProcessDelayedExplosion(); - if(m_bSirenOrAlarm && (CTimer::GetFrameCounter()&7) == 5 && + if(m_bSirenOrAlarm && (CTimer::GetTickCounter()&7) == 5 && UsesSiren(GetModelIndex()) && GetModelIndex() != MI_MRWHOOP) CCarAI::MakeWayForCarWithSiren(this); @@ -1234,9 +1234,10 @@ CAutomobile::PreRender(void) { int i, j, n; CVehicleModelInfo *mi = (CVehicleModelInfo*)CModelInfo::GetModelInfo(GetModelIndex()); + CVector camPos = *RwMatrixGetPos(RwFrameGetMatrix(RwCameraGetFrame(TheCamera.m_pRwCamera))); if(GetModelIndex() == MI_RCBANDIT){ - CVector pos = GetMatrix() * CVector(0.218f, -0.444f, 0.391f); + CVector pos = GetMatrix().GetMatrixInterpolated() * CVector(0.218f, -0.444f, 0.391f); CAntennas::RegisterOne((uintptr)this, GetUp(), pos, 1.0f); } @@ -1269,25 +1270,25 @@ CAutomobile::PreRender(void) mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RB])); pos = mat.GetPosition(); pos.z = 1.5f*m_aWheelPosition[CARWHEEL_REAR_RIGHT]; - m_aWheelColPoints[CARWHEEL_REAR_RIGHT].point = GetMatrix() * pos; + m_aWheelColPoints[CARWHEEL_REAR_RIGHT].point = GetMatrix().GetMatrixInterpolated() * pos; m_aWheelColPoints[CARWHEEL_REAR_RIGHT].surfaceB = SURFACE_DEFAULT; mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LB])); pos = mat.GetPosition(); pos.z = 1.5f*m_aWheelPosition[CARWHEEL_REAR_LEFT]; - m_aWheelColPoints[CARWHEEL_REAR_LEFT].point = GetMatrix() * pos; + m_aWheelColPoints[CARWHEEL_REAR_LEFT].point = GetMatrix().GetMatrixInterpolated() * pos; m_aWheelColPoints[CARWHEEL_REAR_LEFT].surfaceB = SURFACE_DEFAULT; mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_RF])); pos = mat.GetPosition(); pos.z = 1.5f*m_aWheelPosition[CARWHEEL_FRONT_RIGHT]; - m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].point = GetMatrix() * pos; + m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].point = GetMatrix().GetMatrixInterpolated() * pos; m_aWheelColPoints[CARWHEEL_FRONT_RIGHT].surfaceB = SURFACE_DEFAULT; mat.Attach(RwFrameGetMatrix(m_aCarNodes[CAR_WHEEL_LF])); pos = mat.GetPosition(); pos.z = 1.5f*m_aWheelPosition[CARWHEEL_FRONT_LEFT]; - m_aWheelColPoints[CARWHEEL_FRONT_LEFT].point = GetMatrix() * pos; + m_aWheelColPoints[CARWHEEL_FRONT_LEFT].point = GetMatrix().GetMatrixInterpolated() * pos; m_aWheelColPoints[CARWHEEL_FRONT_LEFT].surfaceB = SURFACE_DEFAULT; } @@ -1415,11 +1416,11 @@ CAutomobile::PreRender(void) CVector p1, p2, p3, c; colModel->GetTrianglePoint(p1, colModel->triangles[i].a); - p1 = GetMatrix() * p1; + p1 = GetMatrix().GetMatrixInterpolated() * p1; colModel->GetTrianglePoint(p2, colModel->triangles[i].b); - p2 = GetMatrix() * p2; + p2 = GetMatrix().GetMatrixInterpolated() * p2; colModel->GetTrianglePoint(p3, colModel->triangles[i].c); - p3 = GetMatrix() * p3; + p3 = GetMatrix().GetMatrixInterpolated() * p3; c = (p1 + p2 + p3)/3.0f; n = 6.0f*CWeather::Rain; @@ -1442,7 +1443,7 @@ CAutomobile::PreRender(void) dir.z = 0.0f; if(fwdSpeed < 10.0f){ CVector steerFwd(-Sin(m_fSteerAngle), Cos(m_fSteerAngle), 0.0f); - steerFwd = Multiply3x3(GetMatrix(), steerFwd); + steerFwd = GetMatrix().GetMatrixInterpolated() * steerFwd; float r = CGeneral::GetRandomNumberInRange(-0.06f, -0.03f); dir.x = steerFwd.x * r; dir.y = steerFwd.y * r; @@ -1452,12 +1453,12 @@ CAutomobile::PreRender(void) } bool dblExhaust = false; - pos1 = GetMatrix() * exhaustPos; + pos1 = GetMatrix().GetMatrixInterpolated() * exhaustPos; if(pHandling->Flags & HANDLING_DBL_EXHAUST){ dblExhaust = true; pos2 = exhaustPos; pos2.x = -pos2.x; - pos2 = GetMatrix() * pos2; + pos2 = GetMatrix().GetMatrixInterpolated() * pos2; } n = 4.0f*m_fGasPedal; @@ -1547,8 +1548,8 @@ CAutomobile::PreRender(void) pos + GetUp()*2.0f, CVector(0.0f, 0.0f, 0.0f), 12.0f, r*0.02f, g*0.02f, b*0.02f, CPointLights::FOG_NONE, true); - pos1 = GetMatrix() * pos1; - pos2 = GetMatrix() * pos2; + pos1 = GetMatrix().GetMatrixInterpolated() * pos1; + pos2 = GetMatrix().GetMatrixInterpolated() * pos2; for(i = 0; i < 4; i++){ uint8 sirenTimer = ((CTimer::GetTimeInMilliseconds() + (i<<6))>>8) & 3; @@ -1581,9 +1582,9 @@ CAutomobile::PreRender(void) case MI_FBICAR: if(m_bSirenOrAlarm){ - CVector pos = GetMatrix() * CVector(0.4f, 0.6f, 0.3f); + CVector pos = GetMatrix().GetMatrixInterpolated() * CVector(0.4f, 0.6f, 0.3f); if(CTimer::GetTimeInMilliseconds() & 0x100 && - DotProduct(GetForward(), GetPosition() - TheCamera.GetPosition()) < 0.0f) + DotProduct(GetForward(), GetPositionInterpolated() - camPos) < 0.0f) CCoronas::RegisterCorona((uintptr)this + 21, 0, 0, 255, 255, pos, 0.4f, 50.0f, @@ -1629,7 +1630,7 @@ CAutomobile::PreRender(void) if(GetStatus() == STATUS_ABANDONED){ // Turn off lights on abandoned vehicles only when we they're far away if(bLightsOn && - Abs(TheCamera.GetPosition().x - GetPosition().x) + Abs(TheCamera.GetPosition().y - GetPosition().y) > 100.0f) + Abs(camPos.x - GetPositionInterpolated().x) + Abs(camPos.y - GetPositionInterpolated().y) > 100.0f) bLightsOn = false; }else bLightsOn = shouldLightsBeOn; @@ -1645,10 +1646,10 @@ CAutomobile::PreRender(void) alarmOff = true; } if(bEngineOn && bLightsOn || alarmOn || alarmOff){ - CVector lookVector = GetPosition() - TheCamera.GetPosition(); + CVector lookVector = GetPositionInterpolated() - camPos; float camDist = lookVector.Magnitude(); if(camDist != 0.0f) - lookVector *= 1.0f/camDist; + lookVector *= 1.0f / camDist; else lookVector = CVector(1.0f, 0.0f, 0.0f); @@ -1663,7 +1664,7 @@ CAutomobile::PreRender(void) // Headlights CVector headLightPos = mi->m_positions[CAR_POS_HEADLIGHTS]; - CVector lightR = GetMatrix() * headLightPos; + CVector lightR = GetMatrix().GetMatrixInterpolated() * headLightPos; CVector lightL = lightR; lightL -= GetRight()*2.0f*headLightPos.x; @@ -1753,7 +1754,7 @@ CAutomobile::PreRender(void) // Taillights CVector tailLightPos = mi->m_positions[CAR_POS_TAILLIGHTS]; - lightR = GetMatrix() * tailLightPos; + lightR = GetMatrix().GetMatrixInterpolated() * tailLightPos; lightL = lightR; lightL -= GetRight()*2.0f*tailLightPos.x; @@ -1866,7 +1867,7 @@ CAutomobile::PreRender(void) // Lights off CVector lightPos = mi->m_positions[CAR_POS_TAILLIGHTS]; - CVector lightR = GetMatrix() * lightPos; + CVector lightR = GetMatrix().GetMatrixInterpolated() * lightPos; CVector lightL = lightR; lightL -= GetRight()*2.0f*lightPos.x; @@ -1948,7 +1949,7 @@ CAutomobile::Render(void) CVector contactPoints[4]; // relative to model CVector contactSpeeds[4]; // speed at contact points - CVector frontWheelFwd = Multiply3x3(GetMatrix(), CVector(-Sin(m_fSteerAngle), Cos(m_fSteerAngle), 0.0f)); + CVector frontWheelFwd = GetMatrix().GetMatrixInterpolated() * CVector(-Sin(m_fSteerAngle), Cos(m_fSteerAngle), 0.0f); CVector rearWheelFwd = GetForward(); for(i = 0; i < 4; i++){ if (m_aWheelTimer[i] > 0.0f) { @@ -2990,11 +2991,11 @@ CAutomobile::ProcessBuoyancy(void) pos + GetPosition(), -0.6f*right, nil, size, smokeCol, 0, 0, 0, 0); - if((CTimer::GetFrameCounter() & 0xF) == 0) + if((CTimer::GetTickCounter() & 0xF) == 0) DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_SPLASH, 2000.0f*fSpeed); } #else - if ( ( (CTimer::GetFrameCounter() + i) & 3 ) == 0 ) + if ( ( (CTimer::GetTickCounter() + i) & 3 ) == 0 ) { if(fSpeed > sq(0.05f)) { @@ -3017,7 +3018,7 @@ CAutomobile::ProcessBuoyancy(void) 0.75f*m_vecMoveSpeed, NULL, 0.0f, color); } - if((CTimer::GetFrameCounter() & 0xF) == 0) + if((CTimer::GetTickCounter() & 0xF) == 0) DMAudio.PlayOneShot(m_audioEntityId, SOUND_CAR_SPLASH, 2000.0f*fSpeed); } } @@ -3583,7 +3584,7 @@ CAutomobile::AddWheelDirtAndWater(CColPoint *colpoint, uint32 belowEffectSpeed) default: if ( CWeather::WetRoads > 0.01f #ifdef PC_PARTICLE - && CTimer::GetFrameCounter() & 1 + && CTimer::GetTickCounter() & 1 #endif ) { diff --git a/src/vehicles/Boat.cpp b/src/vehicles/Boat.cpp index aba48bad8..92c1e4656 100644 --- a/src/vehicles/Boat.cpp +++ b/src/vehicles/Boat.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "General.h" #include "Timecycle.h" @@ -252,7 +252,7 @@ CBoat::ProcessControl(void) BlowUpCar(m_pSetOnFireEntity); } - if(speedSq < 0.25f && (CTimer::GetFrameCounter() + m_randomSeed) & 1) + if(speedSq < 0.25f && (CTimer::GetTickCounter() + m_randomSeed) & 1) CParticle::AddParticle(PARTICLE_ENGINE_STEAM, smokePos, smokeDir); if(speedSq < 0.25f && m_fHealth <= 350.0f) CParticle::AddParticle(PARTICLE_ENGINE_SMOKE, smokePos, 1.25f*smokeDir); @@ -370,7 +370,7 @@ CBoat::ProcessControl(void) #endif if(!cameraHack) CParticle::AddParticle(PARTICLE_BOAT_WAKE, wakePos, wakeDir, nil, 0.0f, jetColor); - }else if((CTimer::GetFrameCounter() + m_randomSeed) & 1){ + }else if((CTimer::GetTickCounter() + m_randomSeed) & 1){ #ifdef PC_PARTICLE jetDir.z = 0.018f; jetDir.x *= 0.01f; diff --git a/src/vehicles/Heli.cpp b/src/vehicles/Heli.cpp index a8705524d..b634ce6df 100644 --- a/src/vehicles/Heli.cpp +++ b/src/vehicles/Heli.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "main.h" #include "General.h" @@ -299,7 +299,7 @@ CHeli::ProcessControl(void) CVector2D targetSpeed = vTargetDist * speed; if(m_heliStatus == HELI_STATUS_HOVER2 || m_heliStatus == HELI_STATUS_SHOT_DOWN){ - bool force = !!((CTimer::GetFrameCounter() + m_randomSeed) & 8); + bool force = !!((CTimer::GetTickCounter() + m_randomSeed) & 8); if(m_bTestRight){ if(force || CWorld::TestSphereAgainstWorld(GetPosition() + 4.0f*GetRight(), 2.0f, this, true, false, false, false, false, false) == nil){ if(m_heliStatus == HELI_STATUS_SHOT_DOWN){ @@ -567,7 +567,7 @@ CHeli::PreRender(void) uint8 r, g, b; float testLowZ = FindPlayerCoors().z - 10.0f; float radius = (GetPosition().z - FindPlayerCoors().z - 10.0f - 1.0f) * 0.3f + 10.0f; - int frm = CTimer::GetFrameCounter() & 7; + int frm = CTimer::GetTickCounter() & 7; i = 0; for(angle = 0.0f; angle < TWOPI; angle += TWOPI/32){ diff --git a/src/vehicles/Plane.cpp b/src/vehicles/Plane.cpp index 1a6f1a881..f6cbeae8e 100644 --- a/src/vehicles/Plane.cpp +++ b/src/vehicles/Plane.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "main.h" #include "General.h" @@ -127,7 +127,7 @@ CPlane::ProcessControl(void) if(m_bHasBeenHit){ // BUG: since this is all based on frames, you can skip the explosion processing when you go into the menu if(GetModelIndex() == MI_AIRTRAIN){ - int frm = CTimer::GetFrameCounter() - m_nFrameWhenHit; + int frm = CTimer::GetTickCounter() - m_nFrameWhenHit; if(frm == 20){ static int nFrameGen; CRGBA colors[8]; @@ -181,7 +181,7 @@ CPlane::ProcessControl(void) FlagToDestroyWhenNextProcessed(); } }else{ - int frm = CTimer::GetFrameCounter() - m_nFrameWhenHit; + int frm = CTimer::GetTickCounter() - m_nFrameWhenHit; if(frm == 20){ static int nFrameGen; CRGBA colors[8]; @@ -246,7 +246,7 @@ CPlane::ProcessControl(void) } // Update plane position and speed - if(GetModelIndex() == MI_AIRTRAIN || !m_isFarAway || ((CTimer::GetFrameCounter() + m_randomSeed) & 7) == 0){ + if(GetModelIndex() == MI_AIRTRAIN || !m_isFarAway || ((CTimer::GetTickCounter() + m_randomSeed) & 7) == 0){ if(GetModelIndex() == MI_AIRTRAIN){ float pathPositionRear = PlanePathPosition[m_nPlaneId] - 30.0f; if(pathPositionRear < 0.0f) @@ -910,7 +910,7 @@ CPlane::TestRocketCollision(CVector *rocketPos) plane->GetModelIndex() != MI_AIRTRAIN && plane->GetModelIndex() == MI_DEADDODO && // strange check #endif !plane->m_bHasBeenHit && (*rocketPos - plane->GetPosition()).Magnitude() < 25.0f){ - plane->m_nFrameWhenHit = CTimer::GetFrameCounter(); + plane->m_nFrameWhenHit = CTimer::GetTickCounter(); plane->m_bHasBeenHit = true; CWorld::Players[CWorld::PlayerInFocus].m_pPed->m_pWanted->RegisterCrime_Immediately(CRIME_DESTROYED_CESSNA, plane->GetPosition(), i+1983, false); diff --git a/src/vehicles/Train.cpp b/src/vehicles/Train.cpp index 4250f6f45..c01c671a4 100644 --- a/src/vehicles/Train.cpp +++ b/src/vehicles/Train.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "main.h" #include "Timer.h" @@ -83,7 +83,7 @@ CTrain::SetModelIndex(uint32 id) void CTrain::ProcessControl(void) { - if(gbModelViewer || m_isFarAway && (CTimer::GetFrameCounter() + m_nWagonId) & 0xF) + if(gbModelViewer || m_isFarAway && (CTimer::GetTickCounter() + m_nWagonId) & 0xF) return; CTrainNode *trackNodes; @@ -304,7 +304,7 @@ CTrain::PreRender(void) if(behindness < 0.0f){ // In front of train CVector lightPos = mi->m_positions[TRAIN_POS_LIGHT_FRONT]; - CVector lightR = GetMatrix() * lightPos; + CVector lightR = GetMatrix().GetMatrixInterpolated() * lightPos; CVector lightL = lightR; lightL -= GetRight()*2.0f*lightPos.x; @@ -336,7 +336,7 @@ CTrain::PreRender(void) if(m_bIsLastWagon){ CVector lightPos = mi->m_positions[TRAIN_POS_LIGHT_REAR]; - CVector lightR = GetMatrix() * lightPos; + CVector lightR = GetMatrix().GetMatrixInterpolated() * lightPos; CVector lightL = lightR; lightL -= GetRight()*2.0f*lightPos.x; diff --git a/src/weapons/Explosion.cpp b/src/weapons/Explosion.cpp index d0a682799..20da34c3b 100644 --- a/src/weapons/Explosion.cpp +++ b/src/weapons/Explosion.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "Automobile.h" #include "Bike.h" @@ -330,7 +330,7 @@ CExplosion::Update() case EXPLOSION_HELI: case EXPLOSION_MINE: case EXPLOSION_BARREL: - if (CTimer::GetFrameCounter() & 1) { + if (CTimer::GetTickCounter() & 1) { CPointLights::AddLight(CPointLights::LIGHT_POINT, explosion.m_vecPosition, CVector(0.0f, 0.0f, 0.0f), 20.0f, 1.0f, 1.0f, 0.5f, CPointLights::FOG_NONE, true); CCoronas::RegisterCorona((uintptr)&explosion, 255, 255, 200, 255, explosion.m_vecPosition, 8.0f, 120.0f, gpCoronaTexture[0], CCoronas::TYPE_NORMAL, CCoronas::REFLECTION_ON, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); } else @@ -390,7 +390,7 @@ CExplosion::Update() } } } - if (CTimer::GetFrameCounter() & 1) { + if (CTimer::GetTickCounter() & 1) { CPointLights::AddLight(CPointLights::LIGHT_POINT, explosion.m_vecPosition, CVector(0.0f, 0.0f, 0.0f), 15.0f, 1.0f, 0.0f, 0.0f, CPointLights::FOG_NONE, true); CCoronas::RegisterCorona((uintptr)&explosion, 200, 100, 0, 255, explosion.m_vecPosition, 6.0f, 80.0f, gpCoronaTexture[0], CCoronas::TYPE_NORMAL, CCoronas::REFLECTION_ON, CCoronas::LOSCHECK_OFF, CCoronas::STREAK_OFF, 0.0f); } else diff --git a/src/weapons/ShotInfo.cpp b/src/weapons/ShotInfo.cpp index c0ab9ac15..85a6035e7 100644 --- a/src/weapons/ShotInfo.cpp +++ b/src/weapons/ShotInfo.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "ShotInfo.h" #include "Entity.h" @@ -143,7 +143,7 @@ CShotInfo::Update() } } } - if (!((CTimer::GetFrameCounter() + slot) & 3)) + if (!((CTimer::GetTickCounter() + slot) & 3)) CWorld::SetCarsOnFire(shot.m_startPos.x, shot.m_startPos.y, shot.m_startPos.z, 4.0f, shot.m_sourceEntity); } } \ No newline at end of file diff --git a/src/weapons/Weapon.cpp b/src/weapons/Weapon.cpp index dc15485e3..799c5b84e 100644 --- a/src/weapons/Weapon.cpp +++ b/src/weapons/Weapon.cpp @@ -1,4 +1,4 @@ -#include "common.h" +#include "common.h" #include "Weapon.h" #include "AnimBlendAssociation.h" @@ -636,7 +636,7 @@ CWeapon::FireInstantHit(CEntity *shooter, CVector *fireSource) if ( shooter == FindPlayerPed() ) { CStats::InstantHitsFiredByPlayer++; - if ( !(CTimer::GetFrameCounter() & 3) ) + if ( !(CTimer::GetTickCounter() & 3) ) MakePedsJumpAtShot((CPhysical*)shooter, fireSource, &target); } @@ -1697,7 +1697,7 @@ CWeapon::FireInstantHitFromCar(CAutomobile *shooter, bool left) CEntity *victim; ProcessLineOfSight(source, target, point, victim, m_eWeaponType, shooter, true, true, true, true, true, true, false); - if ( !(CTimer::GetFrameCounter() & 3) ) + if ( !(CTimer::GetTickCounter() & 3) ) MakePedsJumpAtShot(shooter, &source, &target); if ( victim )