void CGamePlayerZone::Use(CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value) { int playersInCount = 0; int playersOutCount = 0; if (!CanFireForActivator(pActivator)) return; CBaseEntity *pPlayer = NULL; for (int i = 1; i <= gpGlobals->maxClients; i++) { pPlayer = UTIL_PlayerByIndex(i); if (pPlayer) { TraceResult trace; int hullNumber; hullNumber = human_hull; if (pPlayer->pev->flags & FL_DUCKING) { hullNumber = head_hull; } UTIL_TraceModel(pPlayer->pev->origin, pPlayer->pev->origin, hullNumber, edict(), &trace); if (trace.fStartSolid) { playersInCount++; if (m_iszInTarget) { FireTargets(STRING(m_iszInTarget), pPlayer, pActivator, useType, value); } } else { playersOutCount++; if (m_iszOutTarget) { FireTargets(STRING(m_iszOutTarget), pPlayer, pActivator, useType, value); } } } } if (m_iszInCount) { FireTargets(STRING(m_iszInCount), pActivator, this, USE_SET, playersInCount); } if (m_iszOutCount) { FireTargets(STRING(m_iszOutCount), pActivator, this, USE_SET, playersOutCount); } }
//----------------------------------------------------------------------------- // Purpose: Counts all the players in the zone. Fires one output per player // in the zone, one output per player out of the zone, and outputs // with the total counts of players in and out of the zone. //----------------------------------------------------------------------------- void CGamePlayerZone::InputCountPlayersInZone( inputdata_t &inputdata ) { int playersInCount = 0; int playersOutCount = 0; if ( !CanFireForActivator( inputdata.pActivator ) ) return; CBaseEntity *pPlayer = NULL; for ( int i = 1; i <= gpGlobals->maxClients; i++ ) { pPlayer = UTIL_PlayerByIndex( i ); if ( pPlayer ) { trace_t trace; Hull_t hullType; hullType = HULL_HUMAN; if ( pPlayer->GetFlags() & FL_DUCKING ) { hullType = HULL_SMALL_CENTERED; } UTIL_TraceModel( pPlayer->GetAbsOrigin(), pPlayer->GetAbsOrigin(), NAI_Hull::Mins(hullType), NAI_Hull::Maxs(hullType), this, COLLISION_GROUP_NONE, &trace ); if ( trace.startsolid ) { playersInCount++; m_OnPlayerInZone.FireOutput(pPlayer, this); } else { playersOutCount++; m_OnPlayerOutZone.FireOutput(pPlayer, this); } } } m_PlayersInCount.Set(playersInCount, inputdata.pActivator, this); m_PlayersOutCount.Set(playersOutCount, inputdata.pActivator, this); }
void CC_CollisionTest( const CCommand &args ) { if ( !physenv ) return; Msg( "Testing collision system\n" ); int i; CBaseEntity *pSpot = gEntList.FindEntityByClassname( NULL, "info_player_start"); Vector start = pSpot->GetAbsOrigin(); static Vector *targets = NULL; static bool first = true; static float test[2] = {1,1}; if ( first ) { targets = new Vector[NUM_COLLISION_TESTS]; float radius = 0; float theta = 0; float phi = 0; for ( i = 0; i < NUM_COLLISION_TESTS; i++ ) { radius += NUM_COLLISION_TESTS * 123.123; radius = fabs(fmod(radius, 128)); theta += NUM_COLLISION_TESTS * 76.76; theta = fabs(fmod(theta, DEG2RAD(360))); phi += NUM_COLLISION_TESTS * 1997.99; phi = fabs(fmod(phi, DEG2RAD(180))); float st, ct, sp, cp; SinCos( theta, &st, &ct ); SinCos( phi, &sp, &cp ); targets[i].x = radius * ct * sp; targets[i].y = radius * st * sp; targets[i].z = radius * cp; // make the trace 1024 units long Vector dir = targets[i] - start; VectorNormalize(dir); targets[i] = start + dir * 1024; } first = false; } //Vector results[NUM_COLLISION_TESTS]; int testType = 0; if ( args.ArgC() >= 2 ) { testType = atoi( args[1] ); } float duration = 0; Vector size[2]; size[0].Init(0,0,0); size[1].Init(16,16,16); unsigned int dots = 0; for ( int j = 0; j < 2; j++ ) { float startTime = engine->Time(); if ( testType == 1 ) { const CPhysCollide *pCollide = g_PhysWorldObject->GetCollide(); trace_t tr; for ( i = 0; i < NUM_COLLISION_TESTS; i++ ) { physcollision->TraceBox( start, targets[i], -size[j], size[j], pCollide, vec3_origin, vec3_angle, &tr ); dots += physcollision->ReadStat(0); //results[i] = tr.endpos; } } else { testType = 0; CBaseEntity *pWorld = GetContainingEntity( INDEXENT(0) ); trace_t tr; for ( i = 0; i < NUM_COLLISION_TESTS; i++ ) { UTIL_TraceModel( start, targets[i], -size[j], size[j], pWorld, COLLISION_GROUP_NONE, &tr ); //results[i] = tr.endpos; } } duration += engine->Time() - startTime; } test[testType] = duration; Msg("%d collisions in %.2f ms (%u dots)\n", NUM_COLLISION_TESTS, duration*1000, dots ); Msg("Current speed ratio: %.2fX BSP:JGJK\n", test[1] / test[0] ); #if 0 int red = 255, green = 0, blue = 0; for ( i = 0; i < NUM_COLLISION_TESTS; i++ ) { NDebugOverlay::Line( start, results[i], red, green, blue, false, 2 ); } #endif }
static int luasrc_UTIL_TraceModel (lua_State *L) { UTIL_TraceModel(luaL_checkvector(L, 1), luaL_checkvector(L, 2), luaL_checkvector(L, 3), luaL_checkvector(L, 4), luaL_checkentity(L, 5), luaL_checkint(L, 6), &luaL_checktrace(L, 7)); return 0; }