CWorld fixes

This commit is contained in:
saml1er 2020-04-17 16:13:55 +05:00
parent e777f24064
commit ce7d6848ba

View File

@ -731,11 +731,10 @@ CWorld::FindObjectsInRange(CVector &centre, float radius, bool ignoreZ, short *n
void
CWorld::FindObjectsOfTypeInRangeSectorList(uint32 modelId, CPtrList& list, const CVector& position, float radius, bool bCheck2DOnly, int16* nEntitiesFound, int16 maxEntitiesToFind, CEntity** aEntities)
{
CPtrNode* pNode = list.first;
while (pNode) {
for (CPtrNode* pNode = list.first; pNode; pNode = pNode->next) {
CEntity* pEntity = (CEntity*)pNode->item;
if (pEntity->m_scanCode != ms_nCurrentScanCode) {
pEntity->m_scanCode = ms_nCurrentScanCode;
if (pEntity->m_scanCode != GetCurrentScanCode()) {
pEntity->m_scanCode = GetCurrentScanCode();
float fMagnitude = 0.0f;
if (bCheck2DOnly)
fMagnitude = (position - pEntity->GetPosition()).MagnitudeSqr2D();
@ -747,7 +746,6 @@ CWorld::FindObjectsOfTypeInRangeSectorList(uint32 modelId, CPtrList& list, const
++*nEntitiesFound;
}
}
pNode = pNode->next;
}
}
@ -1037,11 +1035,10 @@ CWorld::FindObjectsKindaColliding(const CVector& position, float radius, bool bC
void
CWorld::FindObjectsKindaCollidingSectorList(CPtrList& list, const CVector& position, float radius, bool bCheck2DOnly, int16* nCollidingEntities, int16 maxEntitiesToFind, CEntity** aEntities)
{
CPtrNode* pNode = list.first;
while (pNode) {
for (CPtrNode* pNode = list.first; pNode; pNode = pNode->next) {
CEntity* pEntity = (CEntity*)pNode->item;
if (pEntity->m_scanCode != ms_nCurrentScanCode) {
pEntity->m_scanCode = ms_nCurrentScanCode;
if (pEntity->m_scanCode != GetCurrentScanCode()) {
pEntity->m_scanCode = GetCurrentScanCode();
float fMagnitude = 0.0f;
if (bCheck2DOnly)
fMagnitude = (position - pEntity->GetPosition()).Magnitude2D();
@ -1053,7 +1050,6 @@ CWorld::FindObjectsKindaCollidingSectorList(CPtrList& list, const CVector& posit
++*nCollidingEntities;
}
}
pNode = pNode->next;
}
}
@ -1097,11 +1093,10 @@ CWorld::FindObjectsIntersectingCube(const CVector& vecStartPos, const CVector& v
void
CWorld::FindObjectsIntersectingCubeSectorList(CPtrList& list, const CVector& vecStartPos, const CVector& vecEndPos, int16* nIntersecting, int16 maxEntitiesToFind, CEntity** aEntities)
{
CPtrNode* pNode = list.first;
while (pNode) {
for (CPtrNode* pNode = list.first; pNode; pNode = pNode->next) {
CEntity* pEntity = (CEntity*)pNode->item;
if (pEntity->m_scanCode != CWorld::ms_nCurrentScanCode) {
pEntity->m_scanCode = CWorld::ms_nCurrentScanCode;
if (pEntity->m_scanCode != GetCurrentScanCode()) {
pEntity->m_scanCode = GetCurrentScanCode();
float fRadius = pEntity->GetBoundRadius();
const CVector& entityPos = pEntity->GetPosition();
if (fRadius + entityPos.x >= vecStartPos.x && entityPos.x - fRadius <= vecEndPos.x &&
@ -1113,7 +1108,6 @@ CWorld::FindObjectsIntersectingCubeSectorList(CPtrList& list, const CVector& vec
++*nIntersecting;
}
}
pNode = pNode->next;
}
}
@ -1156,11 +1150,10 @@ CWorld::FindObjectsIntersectingAngledCollisionBox(const CColBox& boundingBox, co
void
CWorld::FindObjectsIntersectingAngledCollisionBoxSectorList(CPtrList& list, const CColBox& boundingBox, const CMatrix& matrix, const CVector& position, int16* nEntitiesFound, int16 maxEntitiesToFind, CEntity** aEntities)
{
CPtrNode* pNode = list.first;
while (pNode) {
for (CPtrNode* pNode = list.first; pNode; pNode = pNode->next) {
CEntity* pEntity = (CEntity*)pNode->item;
if (pEntity->m_scanCode != CWorld::ms_nCurrentScanCode) {
pEntity->m_scanCode = CWorld::ms_nCurrentScanCode;
if (pEntity->m_scanCode != GetCurrentScanCode()) {
pEntity->m_scanCode = GetCurrentScanCode();
CColSphere sphere;
CVector vecDistance = pEntity->GetPosition() - position;
sphere.radius = pEntity->GetBoundRadius();
@ -1171,7 +1164,6 @@ CWorld::FindObjectsIntersectingAngledCollisionBoxSectorList(CPtrList& list, cons
++*nEntitiesFound;
}
}
pNode = pNode->next;
}
}
@ -1206,11 +1198,10 @@ CWorld::FindMissionEntitiesIntersectingCube(const CVector& vecStartPos, const CV
void
CWorld::FindMissionEntitiesIntersectingCubeSectorList(CPtrList& list, const CVector& vecStartPos, const CVector& vecEndPos, int16* nIntersecting, int16 maxEntitiesToFind, CEntity** aEntities, bool bIsVehicleList, bool bIsPedList)
{
CPtrNode* pNode = list.first;
while (pNode) {
for (CPtrNode* pNode = list.first; pNode; pNode = pNode->next) {
CEntity* pEntity = (CEntity*)pNode->item;
if (pEntity->m_scanCode != CWorld::ms_nCurrentScanCode) {
pEntity->m_scanCode = CWorld::ms_nCurrentScanCode;
if (pEntity->m_scanCode != GetCurrentScanCode()) {
pEntity->m_scanCode = GetCurrentScanCode();
bool bIsMissionEntity = false;
if (bIsVehicleList)
bIsMissionEntity = ((CVehicle*)pEntity)->VehicleCreatedBy == MISSION_VEHICLE;
@ -1230,7 +1221,6 @@ CWorld::FindMissionEntitiesIntersectingCubeSectorList(CPtrList& list, const CVec
++*nIntersecting;
}
}
pNode = pNode->next;
}
}
@ -1397,11 +1387,10 @@ CWorld::CallOffChaseForArea(float x1, float y1, float x2, float y2)
void
CWorld::CallOffChaseForAreaSectorListVehicles(CPtrList& list, float x1, float y1, float x2, float y2, float fStartX, float fStartY, float fEndX, float fEndY)
{
CPtrNode* pNode = list.first;
while (pNode) {
for (CPtrNode* pNode = list.first; pNode; pNode = pNode->next) {
CVehicle *pVehicle = (CVehicle*)pNode->item;
if (pVehicle->m_scanCode != CWorld::ms_nCurrentScanCode) {
pVehicle->m_scanCode = CWorld::ms_nCurrentScanCode;
if (pVehicle->m_scanCode != GetCurrentScanCode()) {
pVehicle->m_scanCode = GetCurrentScanCode();
const CVector& vehiclePos = pVehicle->GetPosition();
eCarMission carMission = pVehicle->AutoPilot.m_nCarMission;
if (pVehicle != FindPlayerVehicle() &&
@ -1433,20 +1422,18 @@ CWorld::CallOffChaseForAreaSectorListVehicles(CPtrList& list, float x1, float y1
}
}
}
pNode = pNode->next;
}
}
void
CWorld::CallOffChaseForAreaSectorListPeds(CPtrList& list, float x1, float y1, float x2, float y2)
{
CPtrNode* pNode = list.first;
while (pNode) {
for (CPtrNode* pNode = list.first; pNode; pNode = pNode->next) {
CPed* pPed = (CPed*)pNode->item;
const CVector& pedPos = pPed->GetPosition();
if (pPed->m_scanCode != CWorld::ms_nCurrentScanCode)
if (pPed->m_scanCode != GetCurrentScanCode())
{
pPed->m_scanCode = CWorld::ms_nCurrentScanCode;
pPed->m_scanCode = GetCurrentScanCode();
if (pPed != FindPlayerPed() && pPed->m_leader != FindPlayerPed() &&
pedPos.x > x1 && pedPos.x < x2 &&
pedPos.y > y1 && pedPos.y < y2 &&
@ -1582,105 +1569,77 @@ CWorld::AddParticles(void)
void
CWorld::ShutDown(void)
{
for (int32 y = 0; y < NUMSECTORS_Y; y++) {
for (int32 x = 0; x < NUMSECTORS_X; x++) {
CSector *pSector = GetSector(x, y);
CPtrNode *pNode = pSector->m_lists[ENTITYLIST_BUILDINGS].first;
while (pNode) {
for (int i = 0; i < NUMSECTORS_X * NUMSECTORS_Y; i++) {
CSector *pSector = GetSector(i % NUMSECTORS_X, i / NUMSECTORS_Y);
for (CPtrNode *pNode = pSector->m_lists[ENTITYLIST_BUILDINGS].first; pNode; pNode = pNode->next) {
CEntity* pEntity = (CEntity*)pNode->item;
if (pEntity) {
CWorld::Remove(pEntity);
delete pEntity;
}
pNode = pNode->next;
}
pNode = pSector->m_lists[ENTITYLIST_VEHICLES].first;
while (pNode) {
for (CPtrNode* pNode = pSector->m_lists[ENTITYLIST_VEHICLES].first; pNode; pNode = pNode->next) {
CEntity* pEntity = (CEntity*)pNode->item;
if (pEntity) {
CWorld::Remove(pEntity);
delete pEntity;
}
pNode = pNode->next;
}
pNode = pSector->m_lists[ENTITYLIST_PEDS].first;
while (pNode) {
for (CPtrNode* pNode = pSector->m_lists[ENTITYLIST_PEDS].first; pNode; pNode = pNode->next) {
CEntity *pEntity = (CEntity*)pNode->item;
if (pEntity) {
CWorld::Remove(pEntity);
delete pEntity;
}
pNode = pNode->next;
}
pNode = pSector->m_lists[ENTITYLIST_OBJECTS].first;
while (pNode) {
for (CPtrNode* pNode = pSector->m_lists[ENTITYLIST_OBJECTS].first; pNode; pNode = pNode->next) {
CEntity *pEntity = (CEntity*)pNode->item;
if (pEntity) {
CWorld::Remove(pEntity);
delete pEntity;
}
pNode = pNode->next;
}
pNode = pSector->m_lists[ENTITYLIST_DUMMIES].first;
while (pNode) {
for (CPtrNode* pNode = pSector->m_lists[ENTITYLIST_DUMMIES].first; pNode; pNode = pNode->next) {
CEntity *pEntity = (CEntity*)pNode->item;
if (pEntity) {
CWorld::Remove(pEntity);
delete pEntity;
}
pNode = pNode->next;
}
pSector->m_lists[ENTITYLIST_BUILDINGS].Flush();
pSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP].Flush();
pSector->m_lists[ENTITYLIST_DUMMIES].Flush();
pSector->m_lists[ENTITYLIST_DUMMIES_OVERLAP].Flush();
}
}
for (int32 i = 0; i < 4; i ++) {
CPtrNode *pNode = GetBigBuildingList((eLevelName)i).first;
while (pNode) {
for (CPtrNode* pNode = GetBigBuildingList((eLevelName)i).first; pNode; pNode = pNode->next) {
CEntity *pEntity = (CEntity*)pNode->item;
if (pEntity) {
// Maybe remove from world here?
delete pEntity;
}
pNode = pNode->next;
}
GetBigBuildingList((eLevelName)i).Flush();
}
for (int32 y = 0; y < NUMSECTORS_Y; y++) {
for (int32 x = 0; x < NUMSECTORS_X; x++) {
CSector *pSector = GetSector(x, y);
for (int i = 0; i < NUMSECTORS_X * NUMSECTORS_Y; i++) {
CSector *pSector = GetSector(i % NUMSECTORS_X, i / NUMSECTORS_Y);
if (pSector->m_lists[ENTITYLIST_BUILDINGS].first) {
sprintf(gString, "Building list %d,%d not empty\n", x, y);
sprintf(gString, "Building list %d,%d not empty\n", i % NUMSECTORS_X, i / NUMSECTORS_Y);
pSector->m_lists[ENTITYLIST_BUILDINGS].Flush();
}
if (pSector->m_lists[ENTITYLIST_DUMMIES].first) {
sprintf(gString, "Dummy list %d,%d not empty\n", x, y);
sprintf(gString, "Dummy list %d,%d not empty\n", i % NUMSECTORS_X, i / NUMSECTORS_Y);
pSector->m_lists[ENTITYLIST_DUMMIES].Flush();
}
if (pSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP].first) {
sprintf(gString, "Building overlap list %d,%d not empty\n", x, y);
sprintf(gString, "Building overlap list %d,%d not empty\n", i % NUMSECTORS_X, i / NUMSECTORS_Y);
pSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP].Flush();
}
if (pSector->m_lists[ENTITYLIST_VEHICLES_OVERLAP].first) {
sprintf(gString, "Vehicle overlap list %d,%d not empty\n", x, y);
sprintf(gString, "Vehicle overlap list %d,%d not empty\n", i % NUMSECTORS_X, i / NUMSECTORS_Y);
pSector->m_lists[ENTITYLIST_VEHICLES_OVERLAP].Flush();
}
if (pSector->m_lists[ENTITYLIST_PEDS_OVERLAP].first) {
sprintf(gString, "Ped overlap list %d,%d not empty\n", x, y);
sprintf(gString, "Ped overlap list %d,%d not empty\n", i % NUMSECTORS_X, i / NUMSECTORS_Y);
pSector->m_lists[ENTITYLIST_PEDS_OVERLAP].Flush();
}
if (pSector->m_lists[ENTITYLIST_OBJECTS_OVERLAP].first) {
sprintf(gString, "Object overlap list %d,%d not empty\n", x, y);
sprintf(gString, "Object overlap list %d,%d not empty\n", i % NUMSECTORS_X, i / NUMSECTORS_Y);
pSector->m_lists[ENTITYLIST_OBJECTS_OVERLAP].Flush();
}
if (pSector->m_lists[ENTITYLIST_DUMMIES_OVERLAP].first) {
sprintf(gString, "Dummy overlap list %d,%d not empty\n", x, y);
sprintf(gString, "Dummy overlap list %d,%d not empty\n", i % NUMSECTORS_X, i / NUMSECTORS_Y);
pSector->m_lists[ENTITYLIST_DUMMIES_OVERLAP].Flush();
}
}
}
ms_listMovingEntityPtrs.Flush();
}
@ -1693,37 +1652,25 @@ CWorld::ClearForRestart(void)
CObject::DeleteAllTempObjects();
CObject::DeleteAllMissionObjects();
CPopulation::ConvertAllObjectsToDummyObjects();
for (int32 y = 0; y < NUMSECTORS_Y; y++) {
for (int32 x = 0; x < NUMSECTORS_X; x++) {
CSector *pSector = GetSector(x, y);
CPtrNode *pNode = pSector->m_lists[ENTITYLIST_PEDS].first;
while (pNode) {
for (int i = 0; i < NUMSECTORS_X * NUMSECTORS_Y; i++) {
CSector* pSector = GetSector(i % NUMSECTORS_X, i / NUMSECTORS_Y);
for (CPtrNode* pNode = pSector->m_lists[ENTITYLIST_PEDS].first; pNode; pNode = pNode->next) {
CEntity *pEntity = (CEntity*)pNode->item;
if (pEntity) {
CWorld::Remove(pEntity);
delete pEntity;
}
pNode = pNode->next;
}
pNode = GetBigBuildingList(LEVEL_NONE).first;
while (pNode) {
for (CPtrNode* pNode = GetBigBuildingList(LEVEL_NONE).first; pNode; pNode = pNode->next) {
CVehicle *pVehicle = (CVehicle*)pNode->item;
if (pVehicle && pVehicle->IsVehicle() && pVehicle->IsPlane()) {
CWorld::Remove(pVehicle);
delete pVehicle;
}
pNode = pNode->next;
}
pNode = pSector->m_lists[ENTITYLIST_VEHICLES].first;
while (pNode) {
for (CPtrNode* pNode = pSector->m_lists[ENTITYLIST_VEHICLES].first; pNode; pNode = pNode->next) {
CEntity* pEntity = (CEntity*)pNode->item;
if (pEntity) {
CWorld::Remove(pEntity);
delete pEntity;
}
pNode = pNode->next;
}
}
}
CPools::CheckPoolsEmpty();
}
@ -1833,43 +1780,29 @@ CWorld::SetPedsOnFire(float x, float y, float z, float radius, CEntity* reason)
void
CWorld::RemoveStaticObjects()
{
for (int32 y = 0; y < NUMSECTORS_Y; y++) {
for (int32 x = 0; x < NUMSECTORS_X; x++) {
CSector* pSector = GetSector(x, y);
CPtrNode* pNode = pSector->m_lists[ENTITYLIST_BUILDINGS].first;
while (pNode) {
for(int i = 0; i < NUMSECTORS_X * NUMSECTORS_Y; i++) {
CSector *pSector = GetSector(i % NUMSECTORS_X, i / NUMSECTORS_Y);
for (CPtrNode* pNode = pSector->m_lists[ENTITYLIST_BUILDINGS].first; pNode; pNode = pNode->next) {
CEntity* pEntity = (CEntity*)pNode->item;
if (pEntity) {
CWorld::Remove(pEntity);
delete pEntity;
}
pNode = pNode->next;
}
pNode = pSector->m_lists[ENTITYLIST_OBJECTS].first;
while (pNode) {
for (CPtrNode* pNode = pSector->m_lists[ENTITYLIST_OBJECTS].first; pNode; pNode = pNode->next) {
CEntity* pEntity = (CEntity*)pNode->item;
if (pEntity) {
CWorld::Remove(pEntity);
delete pEntity;
}
pNode = pNode->next;
}
pNode = pSector->m_lists[ENTITYLIST_DUMMIES].first;
while (pNode) {
for (CPtrNode* pNode = pSector->m_lists[ENTITYLIST_DUMMIES].first; pNode; pNode = pNode->next) {
CEntity* pEntity = (CEntity*)pNode->item;
if (pEntity) {
CWorld::Remove(pEntity);
delete pEntity;
}
pNode = pNode->next;
}
pSector->m_lists[ENTITYLIST_BUILDINGS].Flush();
pSector->m_lists[ENTITYLIST_BUILDINGS_OVERLAP].Flush();
pSector->m_lists[ENTITYLIST_DUMMIES].Flush();
pSector->m_lists[ENTITYLIST_DUMMIES_OVERLAP].Flush();
}
}
}
void
CWorld::Process(void)
@ -2072,8 +2005,7 @@ CWorld::TriggerExplosion(const CVector& position, float fRadius, float fPower, C
void
CWorld::TriggerExplosionSectorList(CPtrList& list, const CVector& position, float fRadius, float fPower, CEntity* pCreator, bool bProcessVehicleBombTimer)
{
CPtrNode* pNode = list.first;
while (pNode) {
for (CPtrNode* pNode = list.first; pNode; pNode = pNode->next) {
CPhysical* pEntity = (CPhysical*)pNode->item;
CVector vecDistance = pEntity->GetPosition() - position;
float fMagnitude = vecDistance.Magnitude();
@ -2170,7 +2102,6 @@ CWorld::TriggerExplosionSectorList(CPtrList& list, const CVector& position, floa
}
}
}
pNode = pNode->next;
}
}