41
41
// -----------------------------------------------------------------------------
42
42
extern IEngineTrace *enginetrace;
43
43
extern IPhysics *physics;
44
+ extern CGlobalVars *gpGlobals;
44
45
45
46
46
47
// -----------------------------------------------------------------------------
47
48
// CCollisionManager class.
48
49
// -----------------------------------------------------------------------------
49
50
CCollisionManager::CCollisionManager ():
50
51
m_bInitialized(false ),
51
- m_uiRefCount(0 )
52
+ m_uiRefCount(0 ),
53
+ m_nTickCount(-1 )
52
54
{
53
55
54
56
}
@@ -206,6 +208,7 @@ void CCollisionManager::RegisterHook(T tFunc, unsigned int uiFilterIndex, unsign
206
208
bool CCollisionManager::EnterScope (HookType_t eHookType, CHook *pHook)
207
209
{
208
210
static CCollisionManager *pManager = GetCollisionManager ();
211
+ pManager->RefreshCache ();
209
212
210
213
CollisionScope_t scope;
211
214
scope.m_bSkip = true ;
@@ -288,6 +291,7 @@ bool CCollisionManager::EnterScope(HookType_t eHookType, CHook *pHook)
288
291
289
292
scope.m_pFilter = pWrapper;
290
293
scope.m_uiIndex = uiIndex;
294
+ scope.m_pCache = pManager->GetCache (uiIndex);
291
295
scope.m_pExtraShouldHitCheckFunction = pWrapper->m_pExtraShouldHitCheckFunction ;
292
296
pWrapper->m_pExtraShouldHitCheckFunction = (ShouldHitFunc_t)CCollisionManager::ShouldHitEntity;
293
297
@@ -349,14 +353,20 @@ bool CCollisionManager::ShouldHitEntity(IHandleEntity *pHandleEntity, int conten
349
353
}
350
354
}
351
355
356
+ if (scope.m_pCache ->HasResult (uiIndex)) {
357
+ return scope.m_pCache ->GetResult (uiIndex);
358
+ }
359
+
352
360
FOR_EACH_VEC (pManager->m_vecHashes , i) {
353
361
if (pManager->m_vecHashes [i]->HasPair ((void *)scope.m_pFilter ->m_pPassEnt , (void *)pHandleEntity)) {
362
+ scope.m_pCache ->SetResult (uiIndex, false );
354
363
return false ;
355
364
}
356
365
}
357
366
358
367
static CEntityCollisionListenerManager *pListener = GetOnEntityCollisionListenerManager ();
359
368
if (!pListener->GetCount ()) {
369
+ scope.m_pCache ->SetResult (uiIndex, true );
360
370
return true ;
361
371
}
362
372
@@ -369,14 +379,43 @@ bool CCollisionManager::ShouldHitEntity(IHandleEntity *pHandleEntity, int conten
369
379
BEGIN_BOOST_PY ()
370
380
object oResult = pListener->m_vecCallables [i](oEntity, oOther);
371
381
if (!oResult.is_none () && !extract<bool >(oResult)) {
382
+ scope.m_pCache ->SetResult (uiIndex, false );
372
383
return false ;
373
384
}
374
385
END_BOOST_PY_NORET ()
375
386
}
376
387
388
+ scope.m_pCache ->SetResult (uiIndex, true );
377
389
return true ;
378
390
}
379
391
392
+ void CCollisionManager::RefreshCache ()
393
+ {
394
+ if (gpGlobals->tickcount == m_nTickCount) {
395
+ return ;
396
+ }
397
+
398
+ for (CollisionCacheMap_t::const_iterator it = m_mapCache.begin (); it != m_mapCache.end (); it++) {
399
+ delete it->second ;
400
+ }
401
+
402
+ m_mapCache.clear ();
403
+ m_nTickCount = gpGlobals->tickcount ;
404
+ }
405
+
406
+ CCollisionCache *CCollisionManager::GetCache (unsigned int uiIndex)
407
+ {
408
+ CollisionCacheMap_t::const_iterator it = m_mapCache.find (uiIndex);
409
+ if (it != m_mapCache.end ()) {
410
+ return it->second ;
411
+ }
412
+
413
+ CCollisionCache *pCache = new CCollisionCache ();
414
+ m_mapCache[uiIndex] = pCache;
415
+
416
+ return pCache;
417
+ }
418
+
380
419
381
420
// -----------------------------------------------------------------------------
382
421
// ICollisionHash class.
@@ -399,6 +438,26 @@ void ICollisionHash::UnloadInstance()
399
438
}
400
439
401
440
441
+ // -----------------------------------------------------------------------------
442
+ // CCollisionCache class.
443
+ // -----------------------------------------------------------------------------
444
+ bool CCollisionCache::HasResult (unsigned int uiIndex)
445
+ {
446
+ return IsBitSet (uiIndex);
447
+ }
448
+
449
+ bool CCollisionCache::GetResult (unsigned int uiIndex)
450
+ {
451
+ return m_vecCache.IsBitSet (uiIndex);
452
+ }
453
+
454
+ void CCollisionCache::SetResult (unsigned int uiIndex, bool bResult)
455
+ {
456
+ Set (uiIndex);
457
+ m_vecCache.Set ((int )uiIndex, bResult);
458
+ }
459
+
460
+
402
461
// -----------------------------------------------------------------------------
403
462
// CCollisionHash class.
404
463
// -----------------------------------------------------------------------------
0 commit comments