Skip to content

Commit

Permalink
physenv: now actually do it properly.....
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphaelIT7 committed Nov 19, 2024
1 parent 2c5229a commit 5a9cd8e
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions source/modules/physenv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1712,48 +1712,50 @@ static void hook_CPhysicsEnvironment_DestroyObject(CPhysicsEnvironment* pEnviron
foundIndex = index;
pEnvironment->m_objects.FastRemove(index);
pFoundEnvironment = pEnvironment;
return;
} else {
Warning("holylib - physenv: Failed to find a PhysicsObject in our environment?!?\n");
// We somehow failed to find it in this environment.... time to loop thru ALL.
}
}

int envirnmentIndex = 0;
CPhysicsEnvironment* pEnv = pEnvironment;
while (pEnv != NULL)
if (!pFoundEnvironment)
{
int index = -1;
for (int i = pEnv->m_objects.Count(); --i >= 0; )
int envirnmentIndex = 0;
CPhysicsEnvironment* pEnv = pEnvironment;
while (pEnv != NULL)
{
if (pEnv->m_objects[i] == pObject)
int index = -1;
for (int i = pEnv->m_objects.Count(); --i >= 0; )
{
index = i;
break;
if (pEnv->m_objects[i] == pObject)
{
index = i;
break;
}
}
}

if (index != -1)
{
foundIndex = index;
pEnv->m_objects.FastRemove(index);
pFoundEnvironment = pEnv;
pEnv = NULL;
if (envirnmentIndex != 0 && g_pPhysEnvModule.InDebug())
Msg("holylib - physenv: Found right environment(%i) for physics object\n", envirnmentIndex);
if (index != -1)
{
foundIndex = index;
pEnv->m_objects.FastRemove(index);
pFoundEnvironment = pEnv;
pEnv = NULL;
if (envirnmentIndex != 0 && g_pPhysEnvModule.InDebug())
Msg("holylib - physenv: Found right environment(%i) for physics object\n", envirnmentIndex);

break;
}
break;
}

if (envirnmentIndex == 0 && g_pPhysEnvModule.InDebug())
Msg("holylib - physenv: Engine tried to delete a Object in the wrong environment\n");
if (envirnmentIndex == 0 && g_pPhysEnvModule.InDebug())
Msg("holylib - physenv: Engine tried to delete a Object in the wrong environment\n");

for (int i = 0; i < 5; ++i) // We check for any gaps like 0 -> 1 -> 5 -> 14 but thoes shouldn't be huge so at max we'll check the next 5 for now.
{
pEnv = (CPhysicsEnvironment*)physics->GetActiveEnvironmentByIndex(++envirnmentIndex);
for (int i = 0; i < 5; ++i) // We check for any gaps like 0 -> 1 -> 5 -> 14 but thoes shouldn't be huge so at max we'll check the next 5 for now.
{
pEnv = (CPhysicsEnvironment*)physics->GetActiveEnvironmentByIndex(++envirnmentIndex);

if (pEnv)
break;
if (pEnv)
break;
}
}
}

Expand Down

0 comments on commit 5a9cd8e

Please sign in to comment.