//----------------------------------------------------------------------------- // Purpose: Hack to allow this code to run on a client that's not connected to a server // (i.e., demo playback, or multiplayer game ) // Input : ent_num - // origin - // mins - // maxs - // Output : static void //----------------------------------------------------------------------------- static bool GetEntityOriginClientOrServer( int ent_num, Vector& origin ) { // Assume failure origin.Init(); if ( sv.active ) { edict_t *e = EDICT_NUM( ent_num ); if ( e ) { IServerEntity *serverEntity = e->GetIServerEntity(); if ( serverEntity ) { CM_WorldSpaceCenter( serverEntity->GetCollideable(), &origin ); } return true; } } else { IClientEntity *clent = entitylist->GetClientEntity( ent_num ); if ( clent ) { CM_WorldSpaceCenter( clent->GetClientCollideable(), &origin ); return true; } } return false; }
CBaseEntity* CNeeded::GetEntityByIndex( int idx ) { if( g_pEntList == NULL ) return NULL; IClientEntity *pClient = g_pEntList->GetClientEntity( idx ); if( pClient == NULL ) return NULL; return pClient->GetBaseEntity(); }
IterationRetval_t CFlaggedEntitiesEnum::EnumElement( IHandleEntity *pHandleEntity ) { IClientEntity *pClientEntity = cl_entitylist->GetClientEntityFromHandle( pHandleEntity->GetRefEHandle() ); C_BaseEntity *pEntity = pClientEntity ? pClientEntity->GetBaseEntity() : NULL; if ( pEntity ) { if ( m_flagMask && !(pEntity->GetFlags() & m_flagMask) ) // Does it meet the criteria? return ITERATION_CONTINUE; if ( !AddToList( pEntity ) ) return ITERATION_STOP; } return ITERATION_CONTINUE; }
void EffectGlow::Render(int x, int y, int w, int h) { if (!effect_glow::enable) return; if (!init) Init(); if (!isHackActive() || (g_IEngine->IsTakingScreenshot() && clean_screenshots) || g_Settings.bInvalid) return; CMatRenderContextPtr ptr(GET_RENDER_CONTEXT); ptr->ClearColor4ub(0, 0, 0, 255); ptr->PushRenderTargetAndViewport(mat_fullframe); ptr->ClearBuffers(true, true); ptr->OverrideAlphaWriteEnable(true, true); ptr->PopRenderTargetAndViewport(); ptr->ClearStencilBufferRectangle(0, 0, w, h, 0); ptr->DepthRange(0.0f, 0.01f); SS_First.SetStencilState(ptr); drawing = true; for (int i = 1; i <= HIGHEST_ENTITY; i++) { IClientEntity *ent = g_IEntityList->GetClientEntity(i); if (ent && !ent->IsDormant() && ShouldRenderGlow(ent)) { ptr->PushRenderTargetAndViewport(mat_fullframe); g_IVRenderView->SetColorModulation(GlowColor(ent)); g_IVModelRender->ForcedMaterialOverride(mat_glow); DrawEntity(ent); ptr->PopRenderTargetAndViewport(); g_IVRenderView->SetBlend(0.0f); g_IVModelRender->ForcedMaterialOverride(mat_unlit_z); DrawEntity(ent); g_IVRenderView->SetBlend(1.0f); } } drawing = false; SS_Last.SetStencilState(ptr); g_IVModelRender->ForcedMaterialOverride(NULL); ptr->DepthRange(0.0f, 1.0f); ptr->DrawScreenSpaceRectangle(mat_halo, x, y, w, h, 0, 0, w, h, w, h); ptr->SetStencilEnable(false); }
// Glory to the maker of Zeus TF2 base for getting the math part down bool TF2Player::GetHitboxPos(Vector& v, int hitboxindex, BonePos::Enum pos) { if (hitboxindex == -1){ v = vecOrigin(); return true; } int correctedhitbox = CorrectedHitbox(hitboxindex); if (correctedhitbox > 20) return false; matrix3x4_t pmatrix[MAXSTUDIOBONES]; IClientEntity* clientent = ValveInterfaces::pClientEntList->GetClientEntity( this->index() ); if(!clientent || !clientent->SetupBones(pmatrix, MAXSTUDIOBONES, BONE_USED_BY_HITBOX, 0)) return false; studiohdr_t* pStudioHdr = 0; if(isDisguised()) { const int ispyindex = ValveInterfaces::pModelInfo->GetModelIndex("models/player/spy.mdl"); const model_t *pSpyModel = ValveInterfaces::pModelInfo->GetModel( ispyindex ); pStudioHdr = ValveInterfaces::pModelInfo->GetStudiomodel( pSpyModel ); } else { const model_t* modelinfo = clientent->GetModel(); pStudioHdr = ValveInterfaces::pModelInfo->GetStudiomodel(modelinfo); } mstudiobbox_t* hitbox = pStudioHdr->pHitbox(correctedhitbox, 0); MatrixAngles( pmatrix[ hitbox->bone ], angEyeAngles(), v ); Vector min,max; VectorTransform( hitbox->bbmin, pmatrix[ hitbox->bone ], min ); VectorTransform( hitbox->bbmax, pmatrix[ hitbox->bone ], max ); if (pos == BonePos::MIDDLE) v = ((min + max) * 0.5f);//LOL FLOATING POINT OPTIMIZATIONS else if (pos == BonePos::MIN) v = min; else v = max; return true; }
void CTF2PlayerTools::Run(CUserCmd*) { static int runover = 0; int length = ValveInterfaces::pEngine->GetMaxClients() + 1; for (int i = 1; i < length; i++) { IClientEntity* clEnt = ValveInterfaces::pClientEntList->GetClientEntity(i); if (!clEnt) continue; if (clEnt->IsDormant()) m_iDormantPeriods[i]++; else m_iDormantPeriods[i] = 0; memcpy(vecPast2, vecPast1, sizeof vecPast1); memcpy(vecPast1, vecCurrent, sizeof vecCurrent); vecCurrent[i] = TF2Entity::GetPlayer(clEnt->entindex())->vecOrigin(); } runover++; if (runover == 3) m_bCanPredict = true; }
void CPhysicsSystem::PhysicsSimulate() { CMiniProfilerGuard mpg(&g_mp_PhysicsSimulate); VPROF_BUDGET( "CPhysicsSystem::PhysicsSimulate", VPROF_BUDGETGROUP_PHYSICS ); float frametime = gpGlobals->frametime; if ( physenv ) { g_Collisions.BufferTouchEvents( true ); #ifdef _DEBUG physenv->DebugCheckContacts(); #endif frametime *= cl_phys_timescale.GetFloat(); int maxTicks = cl_phys_maxticks.GetInt(); if ( maxTicks ) { float maxFrameTime = physenv->GetDeltaFrameTime( maxTicks ) - 1e-4f; frametime = clamp( frametime, 0, maxFrameTime ); } physenv->Simulate( frametime ); int activeCount = physenv->GetActiveObjectCount(); g_mp_active_object_count.Add(activeCount); IPhysicsObject **pActiveList = NULL; if ( activeCount ) { PHYS_PROFILE(aUpdateActiveObjects) pActiveList = (IPhysicsObject **)stackalloc( sizeof(IPhysicsObject *)*activeCount ); physenv->GetActiveObjects( pActiveList ); for ( int i = 0; i < activeCount; i++ ) { C_BaseEntity *pEntity = reinterpret_cast<C_BaseEntity *>(pActiveList[i]->GetGameData()); if ( pEntity ) { //const CCollisionProperty *collProp = pEntity->CollisionProp(); //debugoverlay->AddBoxOverlay( collProp->GetCollisionOrigin(), collProp->OBBMins(), collProp->OBBMaxs(), collProp->GetCollisionAngles(), 190, 190, 0, 0, 0.01 ); if ( pEntity->CollisionProp()->DoesVPhysicsInvalidateSurroundingBox() ) { pEntity->CollisionProp()->MarkSurroundingBoundsDirty(); } pEntity->VPhysicsUpdate( pActiveList[i] ); IPhysicsShadowController *pShadow = pActiveList[i]->GetShadowController(); if ( pShadow ) { // active shadow object, check for error Vector pos, targetPos; QAngle rot, targetAngles; pShadow->GetTargetPosition( &targetPos, &targetAngles ); pActiveList[i]->GetPosition( &pos, &rot ); Vector delta = targetPos - pos; float dist = VectorNormalize(delta); bool bBlocked = false; if ( dist > cl_phys_block_dist.GetFloat() ) { Vector vel; pActiveList[i]->GetImplicitVelocity( &vel, NULL ); float proj = DotProduct(vel, delta); if ( proj < dist * cl_phys_block_fraction.GetFloat() ) { bBlocked = true; //Msg("%s was blocked %.3f (%.3f proj)!\n", pEntity->GetClassname(), dist, proj ); } } Vector targetAxis; float deltaTargetAngle; RotationDeltaAxisAngle( rot, targetAngles, targetAxis, deltaTargetAngle ); if ( fabsf(deltaTargetAngle) > 0.5f ) { AngularImpulse angVel; pActiveList[i]->GetImplicitVelocity( NULL, &angVel ); float proj = DotProduct( angVel, targetAxis ) * Sign(deltaTargetAngle); if ( proj < (fabsf(deltaTargetAngle) * cl_phys_block_fraction.GetFloat()) ) { bBlocked = true; //Msg("%s was rot blocked %.3f proj %.3f!\n", pEntity->GetClassname(), deltaTargetAngle, proj ); } } if ( bBlocked ) { C_BaseEntity *pBlocker = FindPhysicsBlocker( pActiveList[i] ); if ( pBlocker ) { if ( IsBlockedShouldDisableCollisions( pEntity ) ) { PhysDisableEntityCollisions( pEntity, pBlocker ); pActiveList[i]->RecheckContactPoints(); // GetClassname returns a pointer to the same buffer always! //Msg("%s blocked !", pEntity->GetClassname() ); Msg("by %s\n", pBlocker->GetClassname() ); } } } } } } } #if 0 if ( cl_visualize_physics_shadows.GetBool() ) { int entityCount = NUM_ENT_ENTRIES; for ( int i = 0; i < entityCount; i++ ) { IClientEntity *pClientEnt = cl_entitylist->GetClientEntity(i); if ( !pClientEnt ) continue; C_BaseEntity *pEntity = pClientEnt->GetBaseEntity(); if ( !pEntity ) continue; Vector pos; QAngle angle; IPhysicsObject *pObj = pEntity->VPhysicsGetObject(); if ( !pObj || !pObj->GetShadowController() ) continue; pObj->GetShadowPosition( &pos, &angle ); debugoverlay->AddBoxOverlay( pos, pEntity->CollisionProp()->OBBMins(), pEntity->CollisionProp()->OBBMaxs(), angle, 255, 255, 0, 32, 0 ); char tmp[256]; V_snprintf( tmp, sizeof(tmp),"%s, (%s)\n", pEntity->GetClassname(), VecToString(angle) ); debugoverlay->AddTextOverlay( pos, 0, tmp ); } } #endif g_Collisions.BufferTouchEvents( false ); g_Collisions.FrameUpdate(); } physicssound::PlayImpactSounds( m_impactSounds ); }
C_BaseEntity *CNeeded::GetBaseEntityByIndex( int iIndex ) { IClientEntity *pClientEnt = g_pEntList->GetClientEntity( iIndex ); if( !pClientEnt ) { return NULL; } return pClientEnt->GetBaseEntity(); }
ICollideable *CEngineTraceClient::GetWorldCollideable() { IClientEntity *pUnk = entitylist->GetClientEntity( 0 ); Assert( pUnk ); return pUnk ? pUnk->GetClientCollideable() : NULL; }
//----------------------------------------------------------------------------- // // Inherited from SocketMessageHandler // //----------------------------------------------------------------------------- void ClientStatePlay::OnSocketMessage( SocketMessage* socketMessage ) { MessageType messageType; socketMessage->Read( *(uint32*)&messageType ); // initial data to set up our world representation? if( messageType == MESSAGETYPE_INITIALWORLDDATA ) { uint32 length; uint32 depth; uint32 minSize; socketMessage->Read( length ); socketMessage->Read( depth ); socketMessage->Read( minSize ); MaterialAPI()->InitOcTree( length, depth, minSize ); } // new entity message? else if( messageType == MESSAGETYPE_NEWENTITY ) { char entityClassName[ MAX_ENTITYCLASSNAME ]; uint32 entityUID; socketMessage->Read( entityClassName ); socketMessage->Read( entityUID ); // create and set UID IClientEntity* entity = GetClientEntityList()->Create( entityClassName ); entity->SetUID( entityUID ); // unserialize entity->UnserializeFromNetwork( socketMessage ); // 'spawn' entity entity->Spawn(); // add to list entities_.InsertBack( entity ); } // entity update message? else if( messageType == MESSAGETYPE_ENTITYUPDATE ) { uint32 entityUID; socketMessage->Read( entityUID ); // find entity for( uint32 i = 0; i < entities_.GetCount(); ++ i ) { if( entityUID == entities_[ i ]->GetUID() ) { // unserialize entities_[ i ]->UnserializeFromNetwork( socketMessage ); break; } } } // destroy entity message? else if( messageType == MESSAGETYPE_DESTROYENTITY ) { uint32 entityUID; socketMessage->Read( entityUID ); for( uint32 i = 0; i < entities_.GetCount(); ++i ) { if( entityUID == entities_[ i ]->GetUID() ) { // 'despawn' entities_[ i ]->Despawn(); // destroy entities_.RemoveAndDelete( i ); break; } } } // unrecognised message else { FAssert(); } }