From 858f913facb8ffbb3b4d50a9d65074a07973c711 Mon Sep 17 00:00:00 2001 From: withmorten Date: Mon, 9 Aug 2021 16:34:05 +0200 Subject: [PATCH 1/7] small fix --- src/save/GenericGameStorage.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index 798aeb7e..e4ee4542 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -1030,6 +1030,7 @@ FixSave(int32 slot, uint8 save_type) totalSize = 0; CFileMgr::Read(file_in, (const char *)&size, sizeof(size)); + size = align4bytes(size); buf = work_buff; CFileMgr::Read(file_in, (const char *)work_buff, size); // simple vars + scripts From ab5965cc8d8c6a04c7e09b566b1d9035f869d76f Mon Sep 17 00:00:00 2001 From: withmorten Date: Mon, 9 Aug 2021 16:36:15 +0200 Subject: [PATCH 2/7] fix steam saves --- src/save/GenericGameStorage.cpp | 50 +++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/src/save/GenericGameStorage.cpp b/src/save/GenericGameStorage.cpp index c696726b..b68b805a 100644 --- a/src/save/GenericGameStorage.cpp +++ b/src/save/GenericGameStorage.cpp @@ -693,6 +693,7 @@ enum SAVE_TYPE_64_BIT = 2, SAVE_TYPE_MSVC = 4, SAVE_TYPE_GCC = 8, + SAVE_TYPE_STEAM = 16, }; uint8 @@ -707,6 +708,14 @@ GetSaveType(char *savename) uint8 *buf = work_buff; CFileMgr::Read(file, (const char *)work_buff, size); // simple vars + scripts + buf += 0x40 + sizeof(int32) + sizeof(int32) + sizeof(float) * 3; + + int8 steam_byte; + ReadDataFromBufferPointer(buf, steam_byte); + + if (steam_byte == -3) + save_type |= SAVE_TYPE_STEAM; + LoadSaveDataBlockNoCheck(buf, file, size); // ped pool LoadSaveDataBlockNoCheck(buf, file, size); // garages @@ -757,6 +766,29 @@ GetSaveType(char *savename) return save_type; } +static void +FixSimpleVarsAndScripts(uint8 save_type, uint8 *buf, uint8 *buf2, uint32 *size) +{ + uint8 *buf_start = buf; + uint8 *buf2_start = buf2; + uint32 read = *size; + uint32 written = *size - (sizeof(int8) + 3); + + uint32 pre_steam = 0x40 + sizeof(int32) + sizeof(int32) + sizeof(float) * 3; + uint32 post_steam = *size - (sizeof(int8) + 3) - pre_steam; + + CopyBuf(buf, buf2, pre_steam); + SkipBuf(buf, sizeof(int8) + 3); + CopyBuf(buf, buf2, post_steam); + + *size = 0; + + assert(buf - buf_start == read); + assert(buf2 - buf2_start == written); + + *size = written; +} + static void FixGarages(uint8 save_type, uint8 *buf, uint8 *buf2, uint32 *size) { @@ -1018,7 +1050,7 @@ FixScriptPaths(uint8 save_type, uint8 *buf, uint8 *buf2, uint32 *size) bool FixSave(int32 slot, uint8 save_type) { - if (save_type & SAVE_TYPE_32_BIT && save_type & SAVE_TYPE_MSVC) + if (save_type & SAVE_TYPE_32_BIT && save_type & SAVE_TYPE_MSVC && !(save_type & SAVE_TYPE_STEAM)) return true; bool success = false; @@ -1044,17 +1076,29 @@ FixSave(int32 slot, uint8 save_type) totalSize = 0; CFileMgr::Read(file_in, (const char *)&size, sizeof(size)); + size = align4bytes(size); buf = work_buff; CFileMgr::Read(file_in, (const char *)work_buff, size); // simple vars + scripts - WriteSavaDataBlockNoFunc(buf, file_out, size); + if (save_type & SAVE_TYPE_STEAM && save_type & SAVE_TYPE_MSVC && save_type & SAVE_TYPE_32_BIT) { + memset(work_buff2, 0, sizeof(work_buff2)); + buf2 = work_buff2; + FixSimpleVarsAndScripts(save_type, buf, buf2, &size); + if (!PcSaveHelper.PcClassSaveRoutine(file_out, work_buff2, size)) + goto fail; + totalSize += size; + } else + WriteSavaDataBlockNoFunc(buf, file_out, size); LoadSaveDataBlockNoCheck(buf, file_in, size); // ped pool WriteSavaDataBlockNoFunc(buf, file_out, size); LoadSaveDataBlockNoCheck(buf, file_in, size); // garages - FixSaveDataBlock(FixGarages, file_out, size); // garages need to be fixed in either case + if (!(save_type & SAVE_TYPE_STEAM && save_type & SAVE_TYPE_MSVC && save_type & SAVE_TYPE_32_BIT)) + FixSaveDataBlock(FixGarages, file_out, size); + else + WriteSavaDataBlockNoFunc(buf, file_out, size); LoadSaveDataBlockNoCheck(buf, file_in, size); // game logic WriteSavaDataBlockNoFunc(buf, file_out, size); From 8ea411e4c5c7191b0e67f0c569a32733b99a81bc Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Mon, 2 Aug 2021 14:45:37 +0300 Subject: [PATCH 3/7] Add sprite to the waypoint marker --- src/core/Radar.cpp | 59 +++++++++++++++++++++++++++++++++++++++++---- src/core/Radar.h | 4 +++ src/fakerw/fake.cpp | 4 +-- src/fakerw/rwcore.h | 8 ++++++ 4 files changed, 68 insertions(+), 7 deletions(-) diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index cccf1d2e..011c8464 100644 --- a/src/core/Radar.cpp +++ b/src/core/Radar.cpp @@ -45,6 +45,9 @@ CSprite2d CRadar::SaveSprite; CSprite2d CRadar::SpraySprite; CSprite2d CRadar::TonySprite; CSprite2d CRadar::WeaponSprite; +#ifdef MENU_MAP +CSprite2d CRadar::WaypointSprite; +#endif CSprite2d *CRadar::RadarSprites[RADAR_SPRITE_COUNT] = { nil, @@ -67,7 +70,10 @@ CSprite2d *CRadar::RadarSprites[RADAR_SPRITE_COUNT] = { &SaveSprite, &SpraySprite, &TonySprite, - &WeaponSprite + &WeaponSprite, +#ifdef MENU_MAP + &WaypointSprite +#endif }; // Why this doesn't coincide with world coordinates i don't know @@ -917,6 +923,9 @@ void CRadar::DrawRadarSection(int32 x, int32 y) void CRadar::DrawRadarSprite(uint16 sprite, float x, float y, uint8 alpha) { +#ifdef MENU_MAP + if(sprite == RADAR_SPRITE_WAYPOINT) alpha = 255; +#endif RadarSprites[sprite]->Draw(CRect(x - SCREEN_SCALE_X(8.0f), y - SCREEN_SCALE_Y(8.0f), x + SCREEN_SCALE_X(8.0f), y + SCREEN_SCALE_Y(8.0f)), CRGBA(255, 255, 255, alpha)); } @@ -1094,6 +1103,43 @@ CRadar::LoadTextures() SpraySprite.SetTexture("radar_spray"); TonySprite.SetTexture("radar_tony"); WeaponSprite.SetTexture("radar_weapon"); +#ifdef MENU_MAP + WaypointSprite.SetTexture("radar_waypoint"); + if(!WaypointSprite.m_pTexture) { + // create the texture if it's missing in TXD +#define WAYPOINT_R (255) +#define WAYPOINT_G (72) +#define WAYPOINT_B (77) + + RwRaster *raster = RwRasterCreate(16, 16, 0, rwRASTERTYPETEXTURE | rwRASTERFORMAT8888); + + RwUInt32 *pixels = (RwUInt32 *)RwRasterLock(raster, 0, rwRASTERLOCKWRITE); + for(int x = 0; x < 16; x++) + for(int y = 0; y < 16; y++) + { + int x2 = x < 8 ? x : 7 - (x & 7); + int y2 = y < 8 ? y : 7 - (y & 7); + if ((y2 >= 4 && x2 >= 4) // square in the center is transparent + || (x2 < 2 && y2 == 0) // two pixels on each side of first/last line are transparent + || (x2 < 1 && y2 == 1)) // one pixel on each side of second to first/last line is transparent + pixels[x + y * 16] = 0; + else if((x2 == 2 && y2 >= 2)|| (y2 == 2 && x2 >= 2) )// colored square inside +#ifdef RW_GL3 + pixels[x + y * 16] = WAYPOINT_R | (WAYPOINT_G << 8) | (WAYPOINT_B << 16) | (255 << 24); +#else + pixels[x + y * 16] = WAYPOINT_B | (WAYPOINT_G << 8) | (WAYPOINT_R << 16) | (255 << 24); +#endif + else + pixels[x + y * 16] = 0xFF000000; // black + } + RwRasterUnlock(raster); + WaypointSprite.m_pTexture = RwTextureCreate(raster); + RwTextureSetFilterMode(WaypointSprite.m_pTexture, rwFILTERLINEAR); +#undef WAYPOINT_R +#undef WAYPOINT_G +#undef WAYPOINT_B + } +#endif CTxdStore::PopCurrentTxd(); } @@ -1293,6 +1339,9 @@ void CRadar::Shutdown() SpraySprite.Delete(); TonySprite.Delete(); WeaponSprite.Delete(); +#ifdef MENU_MAP + WaypointSprite.Delete(); +#endif RemoveRadarSections(); } @@ -1488,12 +1537,12 @@ CRadar::ToggleTargetMarker(float x, float y) { if (TargetMarkerId == -1) { int nextBlip; - for (nextBlip = 0; nextBlip < NUMRADARBLIPS; nextBlip++) { + for (nextBlip = NUMRADARBLIPS-1; nextBlip >= 0; nextBlip--) { if (!ms_RadarTrace[nextBlip].m_bInUse) break; } #ifdef FIX_BUGS - if (nextBlip == NUMRADARBLIPS) + if (nextBlip == 0) return; #endif ms_RadarTrace[nextBlip].m_eBlipType = BLIP_COORD; @@ -1501,14 +1550,14 @@ CRadar::ToggleTargetMarker(float x, float y) ms_RadarTrace[nextBlip].m_bDim = 0; ms_RadarTrace[nextBlip].m_bInUse = 1; ms_RadarTrace[nextBlip].m_Radius = 1.0f; - CVector pos(x, y, CWorld::FindGroundZForCoord(x,y)); + CVector pos(x, y, 0.0f/*CWorld::FindGroundZForCoord(x,y)*/); TargetMarkerPos = pos; ms_RadarTrace[nextBlip].m_vec2DPos = pos; ms_RadarTrace[nextBlip].m_vecPos = pos; ms_RadarTrace[nextBlip].m_nEntityHandle = 0; ms_RadarTrace[nextBlip].m_wScale = 5; ms_RadarTrace[nextBlip].m_eBlipDisplay = BLIP_DISPLAY_BLIP_ONLY; - ms_RadarTrace[nextBlip].m_eRadarSprite = RADAR_SPRITE_NONE; + ms_RadarTrace[nextBlip].m_eRadarSprite = RADAR_SPRITE_WAYPOINT; TargetMarkerId = CRadar::GetNewUniqueBlipIndex(nextBlip); } else { ClearBlip(TargetMarkerId); diff --git a/src/core/Radar.h b/src/core/Radar.h index 5b38d350..ae87d0fa 100644 --- a/src/core/Radar.h +++ b/src/core/Radar.h @@ -47,6 +47,9 @@ enum eRadarSprite RADAR_SPRITE_SPRAY, RADAR_SPRITE_TONY, RADAR_SPRITE_WEAPON, +#ifdef MENU_MAP + RADAR_SPRITE_WAYPOINT, +#endif RADAR_SPRITE_COUNT }; @@ -144,6 +147,7 @@ public: static float cachedCos; static float cachedSin; #ifdef MENU_MAP + static CSprite2d WaypointSprite; static int TargetMarkerId; static CVector TargetMarkerPos; diff --git a/src/fakerw/fake.cpp b/src/fakerw/fake.cpp index 1d4c881f..6dfebb39 100644 --- a/src/fakerw/fake.cpp +++ b/src/fakerw/fake.cpp @@ -235,8 +235,8 @@ RwRaster *RwRasterGetCurrentContext(void) { return Raster::getCurrentContext( RwBool RwRasterClear(RwInt32 pixelValue); RwBool RwRasterClearRect(RwRect * rpRect, RwInt32 pixelValue); RwRaster *RwRasterShowRaster(RwRaster * raster, void *dev, RwUInt32 flags); -RwUInt8 *RwRasterLock(RwRaster * raster, RwUInt8 level, RwInt32 lockMode); -RwRaster *RwRasterUnlock(RwRaster * raster); +RwUInt8 *RwRasterLock(RwRaster * raster, RwUInt8 level, RwInt32 lockMode) { return raster->lock(level, lockMode); } +RwRaster *RwRasterUnlock(RwRaster * raster) { raster->unlock(0); return raster; } RwUInt8 *RwRasterLockPalette(RwRaster * raster, RwInt32 lockMode); RwRaster *RwRasterUnlockPalette(RwRaster * raster); RwInt32 RwRasterRegisterPlugin(RwInt32 size, RwUInt32 pluginID, RwPluginObjectConstructor constructCB, RwPluginObjectDestructor destructCB, RwPluginObjectCopy copyCB); diff --git a/src/fakerw/rwcore.h b/src/fakerw/rwcore.h index e5d21865..ab0a719f 100644 --- a/src/fakerw/rwcore.h +++ b/src/fakerw/rwcore.h @@ -104,6 +104,14 @@ enum RwRasterFormat rwRASTERFORMATMASK = 0xff00 }; +enum RwRasterLockMode +{ + rwRASTERLOCKWRITE = rw::Raster::LOCKWRITE, + rwRASTERLOCKREAD = rw::Raster::LOCKREAD, + rwRASTERLOCKNOFETCH = rw::Raster::LOCKNOFETCH, + rwRASTERLOCKRAW = rw::Raster::LOCKRAW, +}; + enum RwRasterFlipMode { rwRASTERFLIPDONTWAIT = 0, From 1f98f01dcb006783755bd58fa458bb515626b2dd Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Mon, 9 Aug 2021 18:14:19 +0300 Subject: [PATCH 4/7] Fix a bunch of CModelInfo::GetModelInfo->GetColModel calls --- src/collision/Collision.cpp | 2 +- src/control/CarCtrl.cpp | 2 +- src/control/Garages.cpp | 2 +- src/control/RoadBlocks.cpp | 6 +++--- src/control/Script.cpp | 2 +- src/core/Radar.cpp | 4 ++-- src/core/World.cpp | 8 ++++---- src/peds/Ped.cpp | 12 ++++++------ src/peds/Population.cpp | 2 +- src/renderer/Renderer.cpp | 4 ++-- src/vehicles/CarGen.cpp | 4 ++-- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/collision/Collision.cpp b/src/collision/Collision.cpp index 9d656581..832d773e 100644 --- a/src/collision/Collision.cpp +++ b/src/collision/Collision.cpp @@ -130,7 +130,7 @@ GetCollisionInSectorList(CPtrList &list) for(node = list.first; node; node = node->next){ e = (CEntity*)node->item; - level = CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel()->level; + level = CModelInfo::GetColModel(e->GetModelIndex())->level; if(level != LEVEL_GENERIC) return (eLevelName)level; } diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp index 37312b89..ca83603f 100644 --- a/src/control/CarCtrl.cpp +++ b/src/control/CarCtrl.cpp @@ -354,7 +354,7 @@ CCarCtrl::GenerateOneRandomCar() pVehicle->m_bSirenOrAlarm = true; pVehicle->AutoPilot.m_nNextPathNodeInfo = connectionId; pVehicle->AutoPilot.m_nNextLane = pVehicle->AutoPilot.m_nCurrentLane = CGeneral::GetRandomNumber() % lanesOnCurrentRoad; - CColBox* boundingBox = &CModelInfo::GetModelInfo(pVehicle->GetModelIndex())->GetColModel()->boundingBox; + CColBox* boundingBox = &CModelInfo::GetColModel(pVehicle->GetModelIndex())->boundingBox; float carLength = 1.0f + (boundingBox->max.y - boundingBox->min.y) / 2; float distanceBetweenNodes = (pCurNode->GetPosition() - pNextNode->GetPosition()).Magnitude2D(); /* If car is so long that it doesn't fit between two car nodes, place it directly in the middle. */ diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index 245e961d..bb919eae 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -2023,7 +2023,7 @@ void CGarages::GivePlayerDetonator() float CGarages::FindDoorHeightForMI(int32 mi) { - return CModelInfo::GetModelInfo(mi)->GetColModel()->boundingBox.max.z - CModelInfo::GetModelInfo(mi)->GetColModel()->boundingBox.min.z - 0.1f; + return CModelInfo::GetColModel(mi)->boundingBox.max.z - CModelInfo::GetColModel(mi)->boundingBox.min.z - 0.1f; } void CGarage::TidyUpGarage() diff --git a/src/control/RoadBlocks.cpp b/src/control/RoadBlocks.cpp index c22bebaa..4c3307c5 100644 --- a/src/control/RoadBlocks.cpp +++ b/src/control/RoadBlocks.cpp @@ -51,7 +51,7 @@ CRoadBlocks::GenerateRoadBlockCopsForCar(CVehicle* pVehicle, int32 roadBlockType CEntity* pEntityToAttack = (CEntity*)FindPlayerVehicle(); if (!pEntityToAttack) pEntityToAttack = (CEntity*)FindPlayerPed(); - CColModel* pPoliceColModel = CModelInfo::GetModelInfo(MI_POLICE)->GetColModel(); + CColModel* pPoliceColModel = CModelInfo::GetColModel(MI_POLICE); float fRadius = pVehicle->GetBoundRadius() / pPoliceColModel->boundingSphere.radius; for (int32 i = 0; i < 2; i++) { const int32 roadBlockIndex = i + 2 * roadBlockType; @@ -130,7 +130,7 @@ CRoadBlocks::GenerateRoadBlocks(void) vehicleId = MI_ENFORCER; if (!CStreaming::HasModelLoaded(vehicleId)) vehicleId = MI_POLICE; - CColModel *pVehicleColModel = CModelInfo::GetModelInfo(vehicleId)->GetColModel(); + CColModel *pVehicleColModel = CModelInfo::GetColModel(vehicleId); float fModelRadius = 2.0f * pVehicleColModel->boundingSphere.radius + 0.25f; int16 radius = (int16)(fMapObjectRadius / fModelRadius); if (radius >= 6) @@ -152,7 +152,7 @@ CRoadBlocks::GenerateRoadBlocks(void) else offsetMatrix.GetPosition() = CVector(i * fModelRadius - fOffset, 0.0f, 0.6f); CMatrix vehicleMatrix = mapObject->GetMatrix() * offsetMatrix; - float fModelRadius = CModelInfo::GetModelInfo(vehicleId)->GetColModel()->boundingSphere.radius - 0.25f; + float fModelRadius = CModelInfo::GetColModel(vehicleId)->boundingSphere.radius - 0.25f; int16 colliding = 0; CWorld::FindObjectsKindaColliding(vehicleMatrix.GetPosition(), fModelRadius, 0, &colliding, 2, nil, false, true, true, false, false); if (!colliding) { diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 4501c27f..f1c8b348 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -2814,7 +2814,7 @@ int8 CRunningScript::ProcessCommands200To299(int32 command) CTheScripts::ReadTextLabelFromScript(&m_nIp, label); int zoneToCheck = CTheZones::FindZoneByLabelAndReturnIndex(label); if (zoneToCheck != -1) - m_nIp += KEY_LENGTH_IN_SCRIPT; /* why only if zone != 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)); diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index 011c8464..d74ce007 100644 --- a/src/core/Radar.cpp +++ b/src/core/Radar.cpp @@ -447,7 +447,7 @@ void CRadar::Draw3dMarkers() CEntity *entity = CPools::GetVehiclePool()->GetAt(ms_RadarTrace[i].m_nEntityHandle); if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) { CVector pos = entity->GetPosition(); - pos.z += 1.2f * CModelInfo::GetModelInfo(entity->GetModelIndex())->GetColModel()->boundingBox.max.z + 2.5f; + pos.z += 1.2f * CModelInfo::GetColModel(entity->GetModelIndex())->boundingBox.max.z + 2.5f; C3dMarkers::PlaceMarker(i | (ms_RadarTrace[i].m_BlipIndex << 16), MARKERTYPE_ARROW, pos, 2.5f, 0, 128, 255, 255, 1024, 0.2f, 5); } break; @@ -471,7 +471,7 @@ void CRadar::Draw3dMarkers() CEntity *entity = CPools::GetObjectPool()->GetAt(ms_RadarTrace[i].m_nEntityHandle); if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) { CVector pos = entity->GetPosition(); - pos.z += CModelInfo::GetModelInfo(entity->GetModelIndex())->GetColModel()->boundingBox.max.z + 1.0f + 1.0f; + pos.z += CModelInfo::GetColModel(entity->GetModelIndex())->boundingBox.max.z + 1.0f + 1.0f; C3dMarkers::PlaceMarker(i | (ms_RadarTrace[i].m_BlipIndex << 16), MARKERTYPE_ARROW, pos, 1.0f, 0, 128, 255, 255, 1024, 0.2f, 5); } break; diff --git a/src/core/World.cpp b/src/core/World.cpp index 6e8314f4..1c34a633 100644 --- a/src/core/World.cpp +++ b/src/core/World.cpp @@ -358,7 +358,7 @@ CWorld::ProcessLineOfSightSectorList(CPtrList &list, const CColLine &line, CColP } else colmodel = nil; } else if(e->bUsesCollision) - colmodel = CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(); + colmodel = CModelInfo::GetColModel(e->GetModelIndex()); if(colmodel && CCollision::ProcessLineOfSight(line, e->GetMatrix(), *colmodel, point, mindist, ignoreSeeThrough)) @@ -444,7 +444,7 @@ CWorld::ProcessVerticalLineSectorList(CPtrList &list, const CColLine &line, CCol if(e->m_scanCode != GetCurrentScanCode() && e->bUsesCollision) { e->m_scanCode = GetCurrentScanCode(); - colmodel = CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(); + colmodel = CModelInfo::GetColModel(e->GetModelIndex()); if(CCollision::ProcessVerticalLine(line, e->GetMatrix(), *colmodel, point, mindist, ignoreSeeThrough, poly)) entity = e; @@ -645,7 +645,7 @@ CWorld::GetIsLineOfSightSectorListClear(CPtrList &list, const CColLine &line, bo if(e != pIgnoreEntity && !(ignoreSomeObjects && CameraToIgnoreThisObject(e))) { - colmodel = CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(); + colmodel = CModelInfo::GetColModel(e->GetModelIndex()); if(CCollision::TestLineOfSight(line, e->GetMatrix(), *colmodel, ignoreSeeThrough)) return false; @@ -955,7 +955,7 @@ CWorld::TestSphereAgainstSectorList(CPtrList &list, CVector spherePos, float rad float distance = diff.Magnitude(); if(e->GetBoundRadius() + radius > distance) { - CColModel *eCol = CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(); + CColModel *eCol = CModelInfo::GetColModel(e->GetModelIndex()); int collidedSpheres = CCollision::ProcessColModels(sphereMat, OurColModel, e->GetMatrix(), *eCol, gaTempSphereColPoints, nil, nil); diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 3ccae5d0..96c1d094 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -2308,7 +2308,7 @@ CPed::ProcessControl(void) } else { DMAudio.PlayOneShot(collidingVeh->m_audioEntityId, SOUND_CAR_PED_COLLISION, m_fDamageImpulse); if (IsPlayer()) { - CColModel *collidingCol = CModelInfo::GetModelInfo(collidingVeh->GetModelIndex())->GetColModel(); + CColModel *collidingCol = CModelInfo::GetColModel(collidingVeh->GetModelIndex()); CVector colMinVec = collidingCol->boundingBox.min; CVector colMaxVec = collidingCol->boundingBox.max; @@ -3061,8 +3061,8 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) CColPoint intersectionPoint; CColLine ourLine; - CColModel *ourCol = CModelInfo::GetModelInfo(GetModelIndex())->GetColModel(); - CColModel *hisCol = CModelInfo::GetModelInfo(collidingEnt->GetModelIndex())->GetColModel(); + CColModel *ourCol = CModelInfo::GetColModel(GetModelIndex()); + CColModel *hisCol = CModelInfo::GetColModel(collidingEnt->GetModelIndex()); if (!bUsesCollision) return 0; @@ -3556,7 +3556,7 @@ void CPed::SetDirectionToWalkAroundObject(CEntity *obj) { float distLimitForTimer = 8.0f; - CColModel *objCol = CModelInfo::GetModelInfo(obj->GetModelIndex())->GetColModel(); + CColModel *objCol = CModelInfo::GetColModel(obj->GetModelIndex()); CVector objColMin = objCol->boundingBox.min; CVector objColMax = objCol->boundingBox.max; CVector objColCenter = (objColMin + objColMax) / 2.0f; @@ -4886,7 +4886,7 @@ CPed::PreRender(void) if (CWeather::Rain > 0.3f && TheCamera.SoundDistUp > 15.0f) { if ((TheCamera.GetPosition() - GetPosition()).Magnitude() < 25.0f) { bool doSplashUp = true; - CColModel *ourCol = CModelInfo::GetModelInfo(GetModelIndex())->GetColModel(); + CColModel *ourCol = CModelInfo::GetColModel(GetModelIndex()); CVector speed = FindPlayerSpeed(); if (Abs(speed.x) <= 0.05f && Abs(speed.y) <= 0.05f) { @@ -8044,7 +8044,7 @@ CPed::FinishLaunchCB(CAnimBlendAssociation *animAssoc, void *arg) return; CVector forward(0.15f * ped->GetForward() + ped->GetPosition()); - forward.z += CModelInfo::GetModelInfo(ped->GetModelIndex())->GetColModel()->spheres->center.z + 0.25f; + forward.z += CModelInfo::GetColModel(ped->GetModelIndex())->spheres->center.z + 0.25f; CEntity *obstacle = CWorld::TestSphereAgainstWorld(forward, 0.25f, nil, true, true, false, true, false, false); if (!obstacle) { diff --git a/src/peds/Population.cpp b/src/peds/Population.cpp index fcabff91..5c80702f 100644 --- a/src/peds/Population.cpp +++ b/src/peds/Population.cpp @@ -999,7 +999,7 @@ bool CPopulation::TestRoomForDummyObject(CObject *obj) { int16 collidingObjs; - CWorld::FindObjectsKindaColliding(obj->m_objectMatrix.GetPosition(), CModelInfo::GetModelInfo(obj->GetModelIndex())->GetColModel()->boundingSphere.radius, + CWorld::FindObjectsKindaColliding(obj->m_objectMatrix.GetPosition(), CModelInfo::GetColModel(obj->GetModelIndex())->boundingSphere.radius, false, &collidingObjs, 2, nil, false, true, true, false, false); return collidingObjs == 0; diff --git a/src/renderer/Renderer.cpp b/src/renderer/Renderer.cpp index 25effc81..334f3954 100644 --- a/src/renderer/Renderer.cpp +++ b/src/renderer/Renderer.cpp @@ -158,7 +158,7 @@ CRenderer::RenderOneRoad(CEntity *e) if(gbDontRenderBuildings) return; if(gbShowCollisionPolys) - CCollision::DrawColModel_Coloured(e->GetMatrix(), *CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(), e->GetModelIndex()); + CCollision::DrawColModel_Coloured(e->GetMatrix(), *CModelInfo::GetColModel(e->GetModelIndex()), e->GetModelIndex()); else #endif { @@ -191,7 +191,7 @@ CRenderer::RenderOneNonRoad(CEntity *e) #ifndef MASTER if(gbShowCollisionPolys){ if(!e->IsVehicle()){ - CCollision::DrawColModel_Coloured(e->GetMatrix(), *CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(), e->GetModelIndex()); + CCollision::DrawColModel_Coloured(e->GetMatrix(), *CModelInfo::GetColModel(e->GetModelIndex()), e->GetModelIndex()); return; } }else if(e->IsBuilding()){ diff --git a/src/vehicles/CarGen.cpp b/src/vehicles/CarGen.cpp index 22b2fc60..ebb767dd 100644 --- a/src/vehicles/CarGen.cpp +++ b/src/vehicles/CarGen.cpp @@ -172,8 +172,8 @@ void CCarGenerator::Setup(float x, float y, float z, float angle, int32 mi, int1 m_nTimer = CTimer::GetTimeInMilliseconds() + 1; m_nUsesRemaining = 0; m_bIsBlocking = false; - m_vecInf = CModelInfo::GetModelInfo(m_nModelIndex)->GetColModel()->boundingBox.min; - m_vecSup = CModelInfo::GetModelInfo(m_nModelIndex)->GetColModel()->boundingBox.max; + m_vecInf = CModelInfo::GetColModel(m_nModelIndex)->boundingBox.min; + m_vecSup = CModelInfo::GetColModel(m_nModelIndex)->boundingBox.max; m_fSize = Max(m_vecInf.Magnitude(), m_vecSup.Magnitude()); } From 0544beb00d5eaf6c974bb7ebcf1f871e3ce94cfb Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Wed, 11 Aug 2021 08:15:30 +0300 Subject: [PATCH 5/7] Add sprite to the waypoint marker --- src/core/Radar.cpp | 62 +++++++++++++++++++++++++++++++++++++++++---- src/core/Radar.h | 4 +++ src/fakerw/fake.cpp | 4 +-- src/fakerw/rwcore.h | 8 ++++++ 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index ff9231c6..faf11387 100644 --- a/src/core/Radar.cpp +++ b/src/core/Radar.cpp @@ -66,6 +66,9 @@ CSprite2d CRadar::RadioVCPRSprite; CSprite2d CRadar::RadioEspantosoSprite; CSprite2d CRadar::RadioEmotionSprite; CSprite2d CRadar::RadioWaveSprite; +#ifdef MAP_ENHANCEMENTS +CSprite2d CRadar::WaypointSprite; +#endif CSprite2d *CRadar::RadarSprites[RADAR_SPRITE_COUNT] = { nil, @@ -107,7 +110,10 @@ CSprite2d *CRadar::RadarSprites[RADAR_SPRITE_COUNT] = { &RadioVCPRSprite, &RadioEspantosoSprite, &RadioEmotionSprite, - &RadioWaveSprite + &RadioWaveSprite, +#ifdef MAP_ENHANCEMENTS + &WaypointSprite, +#endif }; // Why this doesn't coincide with world coordinates i don't know @@ -819,6 +825,9 @@ void CRadar::DrawRadarSection(int32 x, int32 y) void CRadar::DrawRadarSprite(uint16 sprite, float x, float y, uint8 alpha) { +#ifdef MAP_ENHANCEMENTS + if(sprite == RADAR_SPRITE_WAYPOINT) alpha = 255; +#endif RadarSprites[sprite]->Draw(CRect(x - SCREEN_SCALE_X(8.0f), y - SCREEN_SCALE_Y(8.0f), x + SCREEN_SCALE_X(8.0f), y + SCREEN_SCALE_Y(8.0f)), CRGBA(255, 255, 255, alpha)); if (FrontEndMenuManager.m_bMenuMapActive) { @@ -936,6 +945,9 @@ const char* gRadarTexNames[] = { void CRadar::Initialise() { +#ifdef MAP_ENHANCEMENTS + TargetMarkerId = -1; +#endif for (int i = 0; i < NUMRADARBLIPS; i++) { ms_RadarTrace[i].m_BlipIndex = 1; SetRadarMarkerState(i, false); @@ -1084,6 +1096,43 @@ CRadar::LoadTextures() RadioEspantosoSprite.SetTexture("REspantoso"); RadioEmotionSprite.SetTexture("REmotion"); RadioWaveSprite.SetTexture("RWave"); +#ifdef MAP_ENHANCEMENTS + WaypointSprite.SetTexture("radar_waypoint"); + if(!WaypointSprite.m_pTexture) { + // create the texture if it's missing in TXD +#define WAYPOINT_R (255) +#define WAYPOINT_G (72) +#define WAYPOINT_B (77) + + RwRaster *raster = RwRasterCreate(16, 16, 0, rwRASTERTYPETEXTURE | rwRASTERFORMAT8888); + + RwUInt32 *pixels = (RwUInt32 *)RwRasterLock(raster, 0, rwRASTERLOCKWRITE); + for(int x = 0; x < 16; x++) + for(int y = 0; y < 16; y++) + { + int x2 = x < 8 ? x : 7 - (x & 7); + int y2 = y < 8 ? y : 7 - (y & 7); + if ((y2 >= 4 && x2 >= 4) // square in the center is transparent + || (x2 < 2 && y2 == 0) // two pixels on each side of first/last line are transparent + || (x2 < 1 && y2 == 1)) // one pixel on each side of second to first/last line is transparent + pixels[x + y * 16] = 0; + else if((x2 == 2 && y2 >= 2)|| (y2 == 2 && x2 >= 2) )// colored square inside +#ifdef RW_GL3 + pixels[x + y * 16] = WAYPOINT_R | (WAYPOINT_G << 8) | (WAYPOINT_B << 16) | (255 << 24); +#else + pixels[x + y * 16] = WAYPOINT_B | (WAYPOINT_G << 8) | (WAYPOINT_R << 16) | (255 << 24); +#endif + else + pixels[x + y * 16] = 0xFF000000; // black + } + RwRasterUnlock(raster); + WaypointSprite.m_pTexture = RwTextureCreate(raster); + RwTextureSetFilterMode(WaypointSprite.m_pTexture, rwFILTERLINEAR); +#undef WAYPOINT_R +#undef WAYPOINT_G +#undef WAYPOINT_B + } +#endif CTxdStore::PopCurrentTxd(); } @@ -1278,6 +1327,9 @@ void CRadar::Shutdown() RadioEspantosoSprite.Delete(); RadioEmotionSprite.Delete(); RadioWaveSprite.Delete(); +#ifdef MAP_ENHANCEMENTS + WaypointSprite.Delete(); +#endif RemoveRadarSections(); } @@ -1439,12 +1491,12 @@ CRadar::ToggleTargetMarker(float x, float y) { if (TargetMarkerId == -1) { int nextBlip; - for (nextBlip = 0; nextBlip < NUMRADARBLIPS; nextBlip++) { + for (nextBlip = NUMRADARBLIPS-1; nextBlip >= 0; nextBlip--) { if (!ms_RadarTrace[nextBlip].m_bInUse) break; } - if (nextBlip == NUMRADARBLIPS) + if (nextBlip == 0) return; ms_RadarTrace[nextBlip].m_eBlipType = BLIP_COORD; @@ -1452,14 +1504,14 @@ CRadar::ToggleTargetMarker(float x, float y) ms_RadarTrace[nextBlip].m_bDim = 0; ms_RadarTrace[nextBlip].m_bInUse = 1; ms_RadarTrace[nextBlip].m_Radius = 1.0f; - CVector pos(x, y, CWorld::FindGroundZForCoord(x,y)); + CVector pos(x, y, 0.0f/*CWorld::FindGroundZForCoord(x,y)*/); TargetMarkerPos = pos; ms_RadarTrace[nextBlip].m_vec2DPos = pos; ms_RadarTrace[nextBlip].m_vecPos = pos; ms_RadarTrace[nextBlip].m_nEntityHandle = 0; ms_RadarTrace[nextBlip].m_wScale = 5; ms_RadarTrace[nextBlip].m_eBlipDisplay = BLIP_DISPLAY_BLIP_ONLY; - ms_RadarTrace[nextBlip].m_eRadarSprite = RADAR_SPRITE_NONE; + ms_RadarTrace[nextBlip].m_eRadarSprite = RADAR_SPRITE_WAYPOINT; TargetMarkerId = CRadar::GetNewUniqueBlipIndex(nextBlip); } else { ClearBlip(TargetMarkerId); diff --git a/src/core/Radar.h b/src/core/Radar.h index b01a5d04..afb37fe4 100644 --- a/src/core/Radar.h +++ b/src/core/Radar.h @@ -93,6 +93,9 @@ enum eRadarSprite RADAR_SPRITE_RADIO_ESPANTOSO, RADAR_SPRITE_RADIO_EMOTION, RADAR_SPRITE_RADIO_WAVE, +#ifdef MAP_ENHANCEMENTS + RADAR_SPRITE_WAYPOINT, +#endif RADAR_SPRITE_COUNT }; @@ -233,6 +236,7 @@ public: static int16 MapLegendCounter; #ifdef MAP_ENHANCEMENTS + static CSprite2d WaypointSprite; static int TargetMarkerId; static CVector TargetMarkerPos; #endif diff --git a/src/fakerw/fake.cpp b/src/fakerw/fake.cpp index e51a0821..ee779788 100644 --- a/src/fakerw/fake.cpp +++ b/src/fakerw/fake.cpp @@ -235,8 +235,8 @@ RwRaster *RwRasterGetCurrentContext(void) { return Raster::getCurrentContext( RwBool RwRasterClear(RwInt32 pixelValue); RwBool RwRasterClearRect(RwRect * rpRect, RwInt32 pixelValue); RwRaster *RwRasterShowRaster(RwRaster * raster, void *dev, RwUInt32 flags); -RwUInt8 *RwRasterLock(RwRaster * raster, RwUInt8 level, RwInt32 lockMode); -RwRaster *RwRasterUnlock(RwRaster * raster); +RwUInt8 *RwRasterLock(RwRaster * raster, RwUInt8 level, RwInt32 lockMode) { return raster->lock(level, lockMode); } +RwRaster *RwRasterUnlock(RwRaster * raster) { raster->unlock(0); return raster; } RwUInt8 *RwRasterLockPalette(RwRaster * raster, RwInt32 lockMode); RwRaster *RwRasterUnlockPalette(RwRaster * raster); RwInt32 RwRasterRegisterPlugin(RwInt32 size, RwUInt32 pluginID, RwPluginObjectConstructor constructCB, RwPluginObjectDestructor destructCB, RwPluginObjectCopy copyCB); diff --git a/src/fakerw/rwcore.h b/src/fakerw/rwcore.h index e5d21865..ab0a719f 100644 --- a/src/fakerw/rwcore.h +++ b/src/fakerw/rwcore.h @@ -104,6 +104,14 @@ enum RwRasterFormat rwRASTERFORMATMASK = 0xff00 }; +enum RwRasterLockMode +{ + rwRASTERLOCKWRITE = rw::Raster::LOCKWRITE, + rwRASTERLOCKREAD = rw::Raster::LOCKREAD, + rwRASTERLOCKNOFETCH = rw::Raster::LOCKNOFETCH, + rwRASTERLOCKRAW = rw::Raster::LOCKRAW, +}; + enum RwRasterFlipMode { rwRASTERFLIPDONTWAIT = 0, From d7a28c4d2b80a82646f15b4fdbce7a26aeb2eaa8 Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Wed, 11 Aug 2021 08:35:01 +0300 Subject: [PATCH 6/7] Fix a bunch of CModelInfo::GetModelInfo->GetColModel calls --- src/collision/Collision.cpp | 2 +- src/control/Garages.cpp | 2 +- src/control/RoadBlocks.cpp | 6 +++--- src/control/Script.cpp | 2 +- src/core/Radar.cpp | 4 ++-- src/core/World.cpp | 8 ++++---- src/peds/Ped.cpp | 12 ++++++------ src/renderer/Renderer.cpp | 4 ++-- src/vehicles/CarGen.cpp | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/collision/Collision.cpp b/src/collision/Collision.cpp index 0ffcd09a..f39f3f35 100644 --- a/src/collision/Collision.cpp +++ b/src/collision/Collision.cpp @@ -101,7 +101,7 @@ GetCollisionInSectorList(CPtrList &list) for(node = list.first; node; node = node->next){ e = (CEntity*)node->item; - level = CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel()->level; + level = CModelInfo::GetColModel(e->GetModelIndex())->level; if(level != LEVEL_GENERIC) return (eLevelName)level; } diff --git a/src/control/Garages.cpp b/src/control/Garages.cpp index 34ed11eb..b24c9122 100644 --- a/src/control/Garages.cpp +++ b/src/control/Garages.cpp @@ -1986,7 +1986,7 @@ void CGarages::GivePlayerDetonator() float CGarages::FindDoorHeightForMI(int32 mi) { - return CModelInfo::GetModelInfo(mi)->GetColModel()->boundingBox.max.z - CModelInfo::GetModelInfo(mi)->GetColModel()->boundingBox.min.z - 0.1f; + return CModelInfo::GetColModel(mi)->boundingBox.max.z - CModelInfo::GetColModel(mi)->boundingBox.min.z - 0.1f; } void CGarage::TidyUpGarage() diff --git a/src/control/RoadBlocks.cpp b/src/control/RoadBlocks.cpp index 46eee71f..02afb7d8 100644 --- a/src/control/RoadBlocks.cpp +++ b/src/control/RoadBlocks.cpp @@ -60,7 +60,7 @@ CRoadBlocks::GenerateRoadBlockCopsForCar(CVehicle* pVehicle, int32 roadBlockType CEntity* pEntityToAttack = (CEntity*)FindPlayerVehicle(); if (!pEntityToAttack) pEntityToAttack = (CEntity*)FindPlayerPed(); - CColModel* pPoliceColModel = CModelInfo::GetModelInfo(MI_POLICE)->GetColModel(); + CColModel *pPoliceColModel = CModelInfo::GetColModel(MI_POLICE); float fRadius = pVehicle->GetBoundRadius() / pPoliceColModel->boundingSphere.radius; for (int32 i = 0; i < 2; i++) { const int32 roadBlockIndex = i + 2 * roadBlockType; @@ -217,7 +217,7 @@ CRoadBlocks::CreateRoadBlockBetween2Points(CVector point1, CVector point2) vehicleId = MI_ENFORCER; if (!CStreaming::HasModelLoaded(vehicleId)) vehicleId = MI_POLICE; - CColModel* pVehicleColModel = CModelInfo::GetModelInfo(vehicleId)->GetColModel(); + CColModel *pVehicleColModel = CModelInfo::GetColModel(vehicleId); float fModelRadius = 2.0f * pVehicleColModel->boundingSphere.radius + 0.25f; int16 numRoadblockVehicles = Min(6, (int16)(distBetween / fModelRadius)); for (int16 i = 0; i < numRoadblockVehicles; i++) { @@ -231,7 +231,7 @@ CRoadBlocks::CreateRoadBlockBetween2Points(CVector point1, CVector point2) tmp.RotateZ(((CGeneral::GetRandomNumber() & 0xFF) - 128.0f) * 0.003f + 3.1416f); tmp.SetTranslateOnly(offset * forward + pos); tmp.GetPosition().z += 0.6f; - float fModelRadius = CModelInfo::GetModelInfo(vehicleId)->GetColModel()->boundingSphere.radius - 0.25f; + float fModelRadius = CModelInfo::GetColModel(vehicleId)->boundingSphere.radius - 0.25f; int16 colliding = 0; CWorld::FindObjectsKindaColliding(tmp.GetPosition(), fModelRadius, 0, &colliding, 2, nil, false, true, true, false, false); if (!colliding) { diff --git a/src/control/Script.cpp b/src/control/Script.cpp index 0e403c49..5b5825eb 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -3073,7 +3073,7 @@ int8 CRunningScript::ProcessCommands200To299(int32 command) CTheScripts::ReadTextLabelFromScript(&m_nIp, label); int zoneToCheck = CTheZones::FindZoneByLabelAndReturnIndex(label, ZONE_DEFAULT); if (zoneToCheck != -1) - m_nIp += KEY_LENGTH_IN_SCRIPT; /* why only if zone != 1? */ + m_nIp += KEY_LENGTH_IN_SCRIPT; /* why only if zone != -1? */ CVector pos = pPlayer->GetPos(); CZone* pZone = CTheZones::GetNavigationZone(zoneToCheck); UpdateCompareFlag(CTheZones::PointLiesWithinZone(&pos, pZone)); diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index faf11387..dab82c3e 100644 --- a/src/core/Radar.cpp +++ b/src/core/Radar.cpp @@ -485,7 +485,7 @@ void CRadar::Draw3dMarkers() CEntity *entity = CPools::GetVehiclePool()->GetAt(ms_RadarTrace[i].m_nEntityHandle); if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) { CVector pos = entity->GetPosition(); - pos.z += 1.2f * CModelInfo::GetModelInfo(entity->GetModelIndex())->GetColModel()->boundingBox.max.z + 2.5f; + pos.z += 1.2f * CModelInfo::GetColModel(entity->GetModelIndex())->boundingBox.max.z + 2.5f; C3dMarkers::PlaceMarker(i | (ms_RadarTrace[i].m_BlipIndex << 16), MARKERTYPE_ARROW, pos, 2.5f, CARBLIP_MARKER_COLOR_R, CARBLIP_MARKER_COLOR_G, CARBLIP_MARKER_COLOR_B, CARBLIP_MARKER_COLOR_A, 1024, 0.2f, 5); } break; @@ -509,7 +509,7 @@ void CRadar::Draw3dMarkers() CEntity *entity = CPools::GetObjectPool()->GetAt(ms_RadarTrace[i].m_nEntityHandle); if (ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_BOTH || ms_RadarTrace[i].m_eBlipDisplay == BLIP_DISPLAY_MARKER_ONLY) { CVector pos = entity->GetPosition(); - pos.z += CModelInfo::GetModelInfo(entity->GetModelIndex())->GetColModel()->boundingBox.max.z + 1.0f + 1.0f; + pos.z += CModelInfo::GetColModel(entity->GetModelIndex())->boundingBox.max.z + 1.0f + 1.0f; C3dMarkers::PlaceMarker(i | (ms_RadarTrace[i].m_BlipIndex << 16), MARKERTYPE_ARROW, pos, 1.0f, OBJECTBLIP_MARKER_COLOR_R, OBJECTBLIP_MARKER_COLOR_G, OBJECTBLIP_MARKER_COLOR_B, OBJECTBLIP_MARKER_COLOR_A, 1024, 0.2f, 5); } break; diff --git a/src/core/World.cpp b/src/core/World.cpp index 841aab40..549c2cc0 100644 --- a/src/core/World.cpp +++ b/src/core/World.cpp @@ -365,7 +365,7 @@ CWorld::ProcessLineOfSightSectorList(CPtrList &list, const CColLine &line, CColP colmodel = nil; } else if(e->bUsesCollision) - colmodel = CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(); + colmodel = CModelInfo::GetColModel(e->GetModelIndex()); if(colmodel && CCollision::ProcessLineOfSight(line, e->GetMatrix(), *colmodel, point, mindist, ignoreSeeThrough, ignoreShootThrough)) @@ -465,7 +465,7 @@ CWorld::ProcessVerticalLineSectorList(CPtrList &list, const CColLine &line, CCol if(e->m_scanCode != GetCurrentScanCode() && e->bUsesCollision) { e->m_scanCode = GetCurrentScanCode(); - colmodel = CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(); + colmodel = CModelInfo::GetColModel(e->GetModelIndex()); if(CCollision::ProcessVerticalLine(line, e->GetMatrix(), *colmodel, point, mindist, ignoreSeeThrough, false, poly)) entity = e; @@ -666,7 +666,7 @@ CWorld::GetIsLineOfSightSectorListClear(CPtrList &list, const CColLine &line, bo if(e != pIgnoreEntity && !(ignoreSomeObjects && CameraToIgnoreThisObject(e))) { - colmodel = CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(); + colmodel = CModelInfo::GetColModel(e->GetModelIndex()); if(CCollision::TestLineOfSight(line, e->GetMatrix(), *colmodel, ignoreSeeThrough, false)) return false; @@ -971,7 +971,7 @@ CWorld::TestSphereAgainstSectorList(CPtrList &list, CVector spherePos, float rad float distance = diff.Magnitude(); if(e->GetBoundRadius() + radius > distance) { - CColModel *eCol = CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(); + CColModel *eCol = CModelInfo::GetColModel(e->GetModelIndex()); int collidedSpheres = CCollision::ProcessColModels(sphereMat, OurColModel, e->GetMatrix(), *eCol, gaTempSphereColPoints, nil, nil); diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 535445c5..fbe63a1a 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -2204,7 +2204,7 @@ CPed::ProcessControl(void) Say(SOUND_PED_DAMAGE); } - CColModel* collidingCol = CModelInfo::GetModelInfo(collidingVeh->m_modelIndex)->GetColModel(); + CColModel *collidingCol = CModelInfo::GetColModel(collidingVeh->m_modelIndex); CVector colMinVec = collidingCol->boundingBox.min; CVector colMaxVec = collidingCol->boundingBox.max; @@ -2896,8 +2896,8 @@ CPed::ProcessEntityCollision(CEntity *collidingEnt, CColPoint *collidingPoints) CColPoint intersectionPoint; CColLine ourLine; - CColModel *ourCol = CModelInfo::GetModelInfo(GetModelIndex())->GetColModel(); - CColModel *hisCol = CModelInfo::GetModelInfo(collidingEnt->GetModelIndex())->GetColModel(); + CColModel *ourCol = CModelInfo::GetColModel(GetModelIndex()); + CColModel *hisCol = CModelInfo::GetColModel(collidingEnt->GetModelIndex()); if (!bUsesCollision && !bJustCheckCollision) return 0; @@ -3414,7 +3414,7 @@ void CPed::SetDirectionToWalkAroundObject(CEntity *obj) { float distLimitForTimer = 8.0f; - CColModel *objCol = CModelInfo::GetModelInfo(obj->GetModelIndex())->GetColModel(); + CColModel *objCol = CModelInfo::GetColModel(obj->GetModelIndex()); CVector objColMin = objCol->boundingBox.min; CVector objColMax = objCol->boundingBox.max; CVector objColCenter = (objColMin + objColMax) / 2.0f; @@ -4963,7 +4963,7 @@ CPed::PreRender(void) if (CWeather::Rain > 0.3f && TheCamera.SoundDistUp > 15.0f) { if ((TheCamera.GetPosition() - GetPosition()).Magnitude() < 25.0f) { bool doSplashUp = true; - CColModel *ourCol = CModelInfo::GetModelInfo(GetModelIndex())->GetColModel(); + CColModel *ourCol = CModelInfo::GetColModel(GetModelIndex()); CVector speed = FindPlayerSpeed(); if (Abs(speed.x) <= 0.05f && Abs(speed.y) <= 0.05f) { @@ -9183,7 +9183,7 @@ CPed::FinishLaunchCB(CAnimBlendAssociation *animAssoc, void *arg) return; CVector forward(0.09f * ped->GetForward() + ped->GetPosition()); - forward.z += CModelInfo::GetModelInfo(ped->GetModelIndex())->GetColModel()->spheres[2].center.z + 0.35f; + forward.z += CModelInfo::GetColModel(ped->GetModelIndex())->spheres[2].center.z + 0.35f; CEntity *obstacle = CWorld::TestSphereAgainstWorld(forward, 0.25f, nil, true, true, false, true, false, false); if (!obstacle) { diff --git a/src/renderer/Renderer.cpp b/src/renderer/Renderer.cpp index 49e8e611..96e3a329 100644 --- a/src/renderer/Renderer.cpp +++ b/src/renderer/Renderer.cpp @@ -134,7 +134,7 @@ CRenderer::RenderOneRoad(CEntity *e) #endif #ifndef MASTER if(gbShowCollisionPolys || gbShowCollisionPolysReflections || gbShowCollisionPolysNoShadows) - CCollision::DrawColModel_Coloured(e->GetMatrix(), *CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(), e->GetModelIndex()); + CCollision::DrawColModel_Coloured(e->GetMatrix(), *CModelInfo::GetColModel(e->GetModelIndex()), e->GetModelIndex()); else #endif { @@ -157,7 +157,7 @@ CRenderer::RenderOneNonRoad(CEntity *e) #ifndef MASTER if(gbShowCollisionPolys || gbShowCollisionPolysReflections || gbShowCollisionPolysNoShadows){ if(!e->IsVehicle()){ - CCollision::DrawColModel_Coloured(e->GetMatrix(), *CModelInfo::GetModelInfo(e->GetModelIndex())->GetColModel(), e->GetModelIndex()); + CCollision::DrawColModel_Coloured(e->GetMatrix(), *CModelInfo::GetColModel(e->GetModelIndex()), e->GetModelIndex()); return; } }else diff --git a/src/vehicles/CarGen.cpp b/src/vehicles/CarGen.cpp index 29d0c5c7..bce8cdab 100644 --- a/src/vehicles/CarGen.cpp +++ b/src/vehicles/CarGen.cpp @@ -202,7 +202,7 @@ bool CCarGenerator::CheckForBlockage(int32 mi) { int16 entities; CEntity* pEntities[8]; - CColModel* pColModel = CModelInfo::GetModelInfo(mi)->GetColModel(); + CColModel* pColModel = CModelInfo::GetColModel(mi); CWorld::FindObjectsKindaColliding(CVector(m_vecPos), pColModel->boundingSphere.radius, 1, &entities, 8, pEntities, false, true, true, false, false); for (int i = 0; i < entities; i++) { if (m_vecPos.z + pColModel->boundingBox.min.z < pEntities[i]->GetPosition().z + pEntities[i]->GetColModel()->boundingBox.max.z + 1.0f && From 463fdab6a48502b0610f944b9de0853edef3615e Mon Sep 17 00:00:00 2001 From: Sergeanur Date: Wed, 11 Aug 2021 08:42:26 +0300 Subject: [PATCH 7/7] Fix a bunch of CModelInfo::GetModelInfo->GetColModel calls, part 2 --- src/control/CarCtrl.cpp | 2 +- src/peds/Population.cpp | 8 ++++---- src/renderer/Fluff.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp index 6e1b5f21..1cf09a9f 100644 --- a/src/control/CarCtrl.cpp +++ b/src/control/CarCtrl.cpp @@ -400,7 +400,7 @@ CCarCtrl::GenerateOneRandomCar() pVehicle->m_bSirenOrAlarm = true; pVehicle->AutoPilot.m_nNextPathNodeInfo = connectionId; pVehicle->AutoPilot.m_nNextLane = pVehicle->AutoPilot.m_nCurrentLane = CGeneral::GetRandomNumber() % lanesOnCurrentRoad; - CBox* boundingBox = &CModelInfo::GetModelInfo(pVehicle->GetModelIndex())->GetColModel()->boundingBox; + CBox* boundingBox = &CModelInfo::GetColModel(pVehicle->GetModelIndex())->boundingBox; float carLength = 1.0f + (boundingBox->max.y - boundingBox->min.y) / 2; float distanceBetweenNodes = (pCurNode->GetPosition() - pNextNode->GetPosition()).Magnitude2D(); /* If car is so long that it doesn't fit between two car nodes, place it directly in the middle. */ diff --git a/src/peds/Population.cpp b/src/peds/Population.cpp index 65bc80da..495cad16 100644 --- a/src/peds/Population.cpp +++ b/src/peds/Population.cpp @@ -1546,7 +1546,7 @@ CPopulation::PlaceGangMembersInCircle(ePedType pedType, int pedAmount, CVector c int gangModel = ChooseGangOccupation(pedType - PEDTYPE_GANG1); if (((CPedModelInfo*)CModelInfo::GetModelInfo(gangModel))->GetRwObject()) { CEntity* obstacles[6] = { nil, nil, nil, nil, nil, nil }; - CPedPlacement::IsPositionClearForPed(finalPos, CModelInfo::GetModelInfo(gangModel)->GetColModel()->boundingSphere.radius, ARRAY_SIZE(obstacles), obstacles); + CPedPlacement::IsPositionClearForPed(finalPos, CModelInfo::GetColModel(gangModel)->boundingSphere.radius, ARRAY_SIZE(obstacles), obstacles); bool foundObstacle = false; for (int m = 0; m < ARRAY_SIZE(obstacles); m++) { CEntity* obstacle = obstacles[m]; @@ -1630,7 +1630,7 @@ CPopulation::PlaceCouple(ePedType manType, int32 manModel, ePedType womanType, i return; if (!TheCamera.IsSphereVisible(coors, 1.5f) || MIN_CREATION_DIST * PedCreationDistMultiplier() <= (coors - FindPlayerPed()->GetPosition()).Magnitude2D()) { - if (CPedPlacement::IsPositionClearForPed(coors, CModelInfo::GetModelInfo(manModel)->GetColModel()->boundingSphere.radius, -1, nil)) { + if (CPedPlacement::IsPositionClearForPed(coors, CModelInfo::GetColModel(manModel)->boundingSphere.radius, -1, nil)) { bool manFoundGround; float manGroundZ = CWorld::FindGroundZFor3DCoord(coors.x, coors.y, coors.z, &manFoundGround) + 1.0f; if (manFoundGround) { @@ -1664,7 +1664,7 @@ CPopulation::PlaceCouple(ePedType manType, int32 manModel, ePedType womanType, i CEntity* obstacles[3]; memcpy(obstacles, gCoupleObstacles, sizeof(gCoupleObstacles)); - CPedPlacement::IsPositionClearForPed(womanPos, CModelInfo::GetModelInfo(womanModel)->GetColModel()->boundingSphere.radius, ARRAY_SIZE(obstacles), obstacles); + CPedPlacement::IsPositionClearForPed(womanPos, CModelInfo::GetColModel(womanModel)->boundingSphere.radius, ARRAY_SIZE(obstacles), obstacles); for (int i = 0; i < ARRAY_SIZE(obstacles); i++) { CEntity *obstacle = obstacles[i]; if (obstacle) { @@ -1740,7 +1740,7 @@ CPopulation::PlaceMallPedsAsStationaryGroup(CVector const& coors, int32 group) if (pedModelInfo->GetRwObject()) { CEntity* obstacles[6] = { nil, nil, nil, nil, nil, nil }; - CPedPlacement::IsPositionClearForPed(finalPos, CModelInfo::GetModelInfo(pedModel)->GetColModel()->boundingSphere.radius, ARRAY_SIZE(obstacles), obstacles); + CPedPlacement::IsPositionClearForPed(finalPos, CModelInfo::GetColModel(pedModel)->boundingSphere.radius, ARRAY_SIZE(obstacles), obstacles); bool foundObstacle = false; for (int m = 0; m < ARRAY_SIZE(obstacles); m++) { CEntity* obstacle = obstacles[m]; diff --git a/src/renderer/Fluff.cpp b/src/renderer/Fluff.cpp index 1e4d289b..59d3668d 100644 --- a/src/renderer/Fluff.cpp +++ b/src/renderer/Fluff.cpp @@ -928,7 +928,7 @@ CEscalator::AddThisOne(CVector pos0, CVector pos1, CVector pos2, CVector pos3, b m_pos2 = pos2; m_pos3 = pos3; - float escalatorStepHeight = CModelInfo::GetModelInfo(MI_ESCALATORSTEP)->GetColModel()->boundingBox.max.z; + float escalatorStepHeight = CModelInfo::GetColModel(MI_ESCALATORSTEP)->boundingBox.max.z; m_pos0.z -= escalatorStepHeight; m_pos1.z -= escalatorStepHeight; m_pos2.z -= escalatorStepHeight;