static inline void d3d_GetSpriteColor(LTObject *pObject, RGBColor *pColor) { LTVector dynamicLightAdd, color; LTRGBColor theColor; pColor->rgb.a = (uint8)pObject->m_ColorA; if((pObject->m_Flags & FLAG_NOLIGHT) || !g_have_world || (!g_CV_DynamicLightSprites.m_Val)) { // Default case if the other stuff doesn't work. pColor->rgb.r = pObject->m_ColorR; pColor->rgb.g = pObject->m_ColorG; pColor->rgb.b = pObject->m_ColorB; } else { w_DoLightLookup(world_bsp_shared->LightTable(), &pObject->GetPos(), &theColor); d3d_CalcLightAdd(pObject, &dynamicLightAdd); color.x = (float)pObject->m_ColorR + (float)theColor.rgb.r + dynamicLightAdd.x; color.x = LTCLAMP(color.x, 0.0f, 255.0f); color.y = (float)pObject->m_ColorG + (float)theColor.rgb.g + dynamicLightAdd.y; color.y = LTCLAMP(color.y, 0.0f, 255.0f); color.z = (float)pObject->m_ColorB + (float)theColor.rgb.b + dynamicLightAdd.z; color.z = LTCLAMP(color.z, 0.0f, 255.0f); pColor->rgb.r = (uint8)RoundFloatToInt(color.x); pColor->rgb.g = (uint8)RoundFloatToInt(color.y); pColor->rgb.b = (uint8)RoundFloatToInt(color.z); } }
void LightBase::HandleColorMsg( HOBJECT /*hSender*/, const CParsedMsg &crParsedMsg ) { if(crParsedMsg.GetArgCount() == 4) { //read in our new dimensions and apply them m_vColor.Init( LTCLAMP((float)atof(crParsedMsg.GetArg(1)), 0.0f, 255.0f) / 255.0f, LTCLAMP((float)atof(crParsedMsg.GetArg(2)), 0.0f, 255.0f) / 255.0f, LTCLAMP((float)atof(crParsedMsg.GetArg(3)), 0.0f, 255.0f) / 255.0f); g_pLTServer->SetObjectColor(m_hObject, m_vColor.x, m_vColor.y, m_vColor.z, 1.0f); } }
void LightBase::HandleSpotFOVMsg( HOBJECT /*hSender*/, const CParsedMsg &crParsedMsg ) { if(crParsedMsg.GetArgCount() == 3) { //read in our new dimensions and apply them m_fSpotFovX = LTCLAMP((float)atof(crParsedMsg.GetArg(1)), 0.0f, 90.0f); m_fSpotFovY = LTCLAMP((float)atof(crParsedMsg.GetArg(2)), 0.0f, 90.0f); g_pLTServer->SetLightSpotInfo(m_hObject, MATH_DEGREES_TO_RADIANS(m_fSpotFovX * 0.5f), MATH_DEGREES_TO_RADIANS(m_fSpotFovY * 0.5f), m_fSpotNearClip); } }
//called to get the controller modifier given a camera position. This controller modifier //is the intensity of each of the controller motors, wich will be in the range of [0..1] void CClientFXMgr::GetControllerModifier( const LTRigidTransform& tCameraTrans, float fMotors[NUM_CLIENTFX_CONTROLLER_MOTORS]) { //track our performance CTimedSystemBlock TimingBlock(g_tsClientFXUpdateController); //initialize our output for(uint32 nCurrMotor = 0; nCurrMotor < NUM_CLIENTFX_CONTROLLER_MOTORS; nCurrMotor++) fMotors[nCurrMotor] = 0.0f; //run through the list of instances that we have LTListIter<IClientFXController*> itControlFX = m_ControllerList.Begin(); while(itControlFX != m_ControllerList.End()) { //cache the next one in case it goes away IClientFXController* pIController = *itControlFX; itControlFX++; pIController->GetControllerModifier(tCameraTrans, fMotors); } //and clamp our output for(uint32 nCurrMotor = 0; nCurrMotor < NUM_CLIENTFX_CONTROLLER_MOTORS; nCurrMotor++) fMotors[nCurrMotor] = LTCLAMP(fMotors[nCurrMotor], 0.0f, 1.0f); }
//---------------------------------------------------------------------------- // // ROUTINE: CHoverMovementModifier::Interpolate() // // PURPOSE: Attempt to smooth the vertical movement a bit, so the hovering // AI does not snap on stairs. // //---------------------------------------------------------------------------- float CHoverMovementModifier::Interpolate(float OldY, float LowerY, float flSpeed ) { if ( fabs(LowerY - OldY) < 1.0f ) { // If the distance to travel is less than 1, just move there so we can // stop interpolating so frequently. return LowerY; } // Find the distance we are changing. float flAdjustingDiff = (LowerY - OldY); float flScalar = (float)fabs(flAdjustingDiff) / m_cMaxVerticalDifference; // AI wants to go upwards faster when the distance is greater float flPotentialDifference = flAdjustingDiff*flScalar; // AI cannot go up faster than it is going forward(?) float flSpeedDifferenceLimiter; if ( flSpeed == 0.0f ) { flSpeedDifferenceLimiter = m_cStoppedMovementRate; } else { flSpeedDifferenceLimiter = flSpeed * m_cMaxRateSpeedScalar; } float flOffset = LTCLAMP( flPotentialDifference, (-flSpeedDifferenceLimiter), flSpeedDifferenceLimiter ); return ( OldY + flOffset ); }
void CClientFXMgr::SetDisableDistance( int nLOD, float fDistance ) { nLOD = LTCLAMP(nLOD, FXLOD_LOW, FXLOD_HIGH); m_dDetailDistSqr[nLOD] = fDistance * fDistance; }
void CClientFXMgr::SetDetailLevel( int nLOD ) { nLOD = LTCLAMP(nLOD, FXLOD_LOW, FXLOD_HIGH); // Set our detail vars switch( nLOD ) { case 0 : { m_eDetailLevel = FXLOD_LOW; } break; case 1 : { m_eDetailLevel = FXLOD_MED; } break; default : { m_eDetailLevel = FXLOD_HIGH; } break; } }
void LightBase::HandleIntensityMsg( HOBJECT /*hSender*/, const CParsedMsg &crParsedMsg ) { if(crParsedMsg.GetArgCount() == 2) { //read in our new dimensions and apply them m_fIntensityScale = LTCLAMP((float)atof(crParsedMsg.GetArg(1)), 0.0f, 1.0f); g_pLTServer->SetLightIntensityScale(m_hObject, m_fIntensityScale); } }
bool CDynaLightFX::Update(float tmFrameTime) { // Base class update first if (!CBaseFX::Update(tmFrameTime)) return false; if (IsShuttingDown()) { m_pLTClient->SetLightRadius(m_hObject, 0); return true; } // If we're flickering, change some of the attributes slightly if (GetProps()->m_bFlicker) { float fRand = 0.3f + GetRandom(0.0f, 0.19f); m_red *= fRand; m_green *= fRand; m_blue *= fRand; } // Try to add some sort of intensity based off the alpha... m_red = LTCLAMP( m_red * m_alpha, 0.0f, 1.0f ); m_green = LTCLAMP( m_green * m_alpha, 0.0f, 1.0f ); m_blue = LTCLAMP( m_blue * m_alpha, 0.0f, 1.0f ); // Set the new light colour m_pLTClient->SetLightColor(m_hObject, m_red, m_green, m_blue); // Set the new light scale m_pLTClient->SetLightRadius(m_hObject, m_scale); // Success !! return true; }
// --------------------------------------------------------------------------- CUI_RESULTTYPE CUISlider_Impl::SetSliderSizePercent(uint16 percent) { m_SliderSizePercent = LTCLAMP(percent, 0, 100); //m_SliderSizePercent = percent; this->RepositionInterval(); // return an error if the value was clamped if ( (percent < 0) || (percent > 100) ) return CUIR_ERROR; return CUIR_OK; }
bool ObjectDetector::TestParamsCustom( ObjectDetectorLink* pLink, float& fMetRR ) { // Make sure we've got some valid parameters if( !m_pCustomTestFn ) { fMetRR = 1.0f; return false; } bool bPassed = ( *m_pCustomTestFn )( pLink, fMetRR, m_pCustomTestUserData ); // Make sure it's clamped fMetRR = LTCLAMP( fMetRR, 0.0f, 1.0f ); return bPassed; }
//given a weight value, it will determine if it is above 0, and if it is will use that. Otherwise //it will look at the weighting of each node and use that to determine the value void DetermineNodeWeights(float fDefaultWeight, const CRagDollNode* pNode1, const CRagDollNode* pNode2, float& fWeight1, float& fWeight2) { if(fDefaultWeight < 0.0f) { //we want to determine the weighting based upon the weight of each node fWeight1 = pNode2->m_fWeight / (pNode1->m_fWeight + pNode2->m_fWeight); } else { fWeight1 = fDefaultWeight; } //clamp it to ensure it is valid fWeight1 = LTCLAMP(fWeight1, 0.0f, 1.0f); //the other weight is simply the compliment of the first fWeight2 = 1.0f - fWeight1; }
void CHUDDamageDir::Update() { if (m_nSize <= 0) { m_bDraw = LTFALSE; return; } if (m_fScale != g_pInterfaceResMgr->GetXRatio()) UpdateScale(); float fAlphaRange = g_vtDamageMaxAlpha.GetFloat() - g_vtDamageMinAlpha.GetFloat(); float fDamTotal = 0.0f; for (uint8 i = 0; i < kNumDamageSectors; i++) { float fDam = g_pPlayerMgr->GetDamageFromSector(i); fDam = LTCLAMP( fDam, 0.0f, 1.0f ); if (g_vtDamageShowAll.GetFloat() > 0.0f && fDam < 0.1f) fDam = 0.1f; fDamTotal += fDam; uint8 nAlpha = 0; if (fDam > 0.0f) { float fA = g_vtDamageMinAlpha.GetFloat() + fDam * fAlphaRange; nAlpha = (uint8) (fA * 255.0f); } uint32 argbCol = SET_ARGB(nAlpha,255,255,255); g_pDrawPrim->SetRGBA(&m_Poly[i],argbCol); } m_bDraw = (fDamTotal > 0.0f); }
void CFresnelTable::GenerateTable(float fVolumeIOR, float fBaseReflection) { //just always assume that the player is in a standard air volume static const float kfViewerIOR = 1.0003f; //calculate the ratio of volume to viewer float fIORRatioSqr = Sqr(fVolumeIOR / kfViewerIOR); float fCos = 0.0f; float fCosInc = 1.0f / TABLE_SIZE; //run through and calculate our values for(uint32 nCurrEntry = 0; nCurrEntry < TABLE_SIZE; nCurrEntry++) { //now precalculate some values float fG = fIORRatioSqr + Sqr(fCos) - 1.0f; //figure out the final fresnel term float fVal = (Sqr(fG - fCos) / (2.0f * Sqr(fG + fCos))) * (1.0f + Sqr(fCos * (fG + fCos) - 1.0f) / Sqr(fCos * (fG - fCos) + 1.0f)); //this should always be (0..1) assert(fVal >= 0.0f); assert(fVal <= 1.0f); //add our base reflection onto it fVal += fBaseReflection; //and now clamp it to be in range fVal = LTCLAMP(fVal, 0.0f, 1.0f); //now convert it to the appropriate format m_nTable[nCurrEntry] = ((uint32)(fVal * 255.0f)) << 24; if(nCurrEntry && m_nTable[nCurrEntry] < m_nTable[nCurrEntry - 1]) int nBreakme = 1; fCos += fCosInc; } m_fVolumeIOR = fVolumeIOR; m_fBaseReflection = fBaseReflection; }
void CHUDDamageDir::Update() { if (m_nOuterRadius <= 0) { m_bDraw = false; return; } float fAlphaRange = m_fMaxAlpha - m_fMinAlpha; float fDamTotal = 0.0f; for (uint8 i = 0; i < kNumDamageSectors; i++) { float fDam = g_pPlayerMgr->GetDamageFromSector(i); fDam = LTCLAMP( fDam, 0.0f, 1.0f ); if (g_vtDamageShowAll.GetFloat() > 0.0f && fDam < 0.1f) fDam = 0.1f; fDamTotal += fDam; uint8 nAlpha = 0; if (fDam > 0.0f) { float fA = m_fMinAlpha + fDam * fAlphaRange; nAlpha = (uint8) (fA * 255.0f); } DrawPrimSetRGBA(m_Poly[i], 0xFF, 0xFF, 0xFF, nAlpha); } m_bDraw = (fDamTotal > 0.0f); }
//given a detail level of an effect, this will determine if the effect key should //be played based upon the current LOD settings on the object bool CClientFXMgr::IsDetailLevelEnabled(uint32 nDetailLevel) const { //helper table for the different detail settings on an effect. Each has 3 bools, one for //if it is enabled in low detail level, medium, and high. Note that this table must match //the prop settings as listed in clientfx.cpp static bool bDetailTable[FX_NUM_DETAIL_SETTINGS][3] = { { true, true, true }, //All { false, false, true }, //High { false, true, false }, //Medium { true, false, false }, //Low { false, true, true }, //Medium+High { true, true, false }, //Low+Medium { true, false, true } //Low+High }; //check for out of bounds detail levels if(nDetailLevel >= FX_NUM_DETAIL_SETTINGS) return true; //use the table as a guide return bDetailTable[nDetailLevel][LTCLAMP((uint32)(g_vtClientFXDetailLevel.GetFloat() + 0.5f), 0, 2)]; }
static void d3d_DrawSprite(const ViewParams& Params, SpriteInstance *pInstance, SharedTexture *pShared) { //the basis up and right vectors LTVector vBasisRight, vBasisUp, vBasisPos, vBasisForward; // If it's really close, change the near Z and transform it into clipping space if(pInstance->m_Flags & FLAG_REALLYCLOSE) { //we are in camera space, so up and right are always the standard vBasisRight.Init(1.0f, 0.0f, 0.0f); vBasisUp.Init(0.0f, 1.0f, 0.0f); vBasisForward.Init(0.0f, 0.0f, 1.0f); vBasisPos.Init(0.0f, 0.0f, 0.0f); } else { //Otherwise we need to grab the camera's up and right vBasisRight = Params.m_Right; vBasisUp = Params.m_Up; vBasisForward = Params.m_Forward; vBasisPos = Params.m_Pos; } //get the object position LTVector vPos = pInstance->GetPos(); //find the Z distance float fZ = (vPos - vBasisPos).Dot(vBasisForward); //bail if this is too close to even be seen if(!(pInstance->m_Flags & FLAG_REALLYCLOSE) && (fZ < NEARZ)) return; if(!d3d_SetTexture(pShared, 0, eFS_SpriteTexMemory)) return; float fWidth = (float)((RTexture*)pShared->m_pRenderData)->GetBaseWidth(); float fHeight = (float)((RTexture*)pShared->m_pRenderData)->GetBaseHeight(); float fSizeX = fWidth * pInstance->m_Scale.x; float fSizeY = fHeight * pInstance->m_Scale.y; if(pInstance->m_Flags & FLAG_GLOWSPRITE) { //find the scale factor float fFactor = (fZ - SPRITE_MINFACTORDIST) / (SPRITE_MAXFACTORDIST - SPRITE_MINFACTORDIST); fFactor = LTCLAMP(fFactor, 0.0f, 1.0f); fFactor = SPRITE_MINFACTOR + ((SPRITE_MAXFACTOR-SPRITE_MINFACTOR) * fFactor); fSizeX *= fFactor; fSizeY *= fFactor; } //find the color of this sprite RGBColor Color; d3d_GetSpriteColor(pInstance, &Color); uint32 nColor = Color.color; //scale up to be the appropriate half height LTVector vRight = vBasisRight * fSizeX; LTVector vUp = vBasisUp * fSizeY; // Generate our vertices CSpriteVertex SpriteVerts[4]; SpriteVerts[0].SetupVert(vPos + vUp - vRight, nColor, 0.0f, 0.0f); SpriteVerts[1].SetupVert(vPos + vUp + vRight, nColor, 1.0f, 0.0f); SpriteVerts[2].SetupVert(vPos + vRight - vUp, nColor, 1.0f, 1.0f); SpriteVerts[3].SetupVert(vPos - vRight - vUp, nColor, 0.0f, 1.0f); if((pInstance->m_Flags & FLAG_SPRITEBIAS) && !(pInstance->m_Flags & FLAG_REALLYCLOSE)) { //find the bias, up to, but not including the near plane float fBiasDist = SPRITE_POSITION_ZBIAS; if((fZ + fBiasDist) < NEARZ) fBiasDist = NEARZ - fZ; //now adjust our vectors accordingly so that we can move it forward //but have it be the same size float fScale = 1 + fBiasDist / fZ; //adjust the points for(uint32 nCurrPt = 0; nCurrPt < 4; nCurrPt++) { LTVector& vPt = SpriteVerts[nCurrPt].m_Vec; vPt = vBasisRight * (vPt - vBasisPos).Dot(vBasisRight) * fScale + vBasisUp * (vPt - vBasisPos).Dot(vBasisUp) * fScale + (fZ + fBiasDist) * vBasisForward + vBasisPos; } } //Render our lovely verts LTEffectImpl* pEffect = (LTEffectImpl*)LTEffectShaderMgr::GetSingleton().GetEffectShader(pInstance->m_nEffectShaderID); if(pEffect) { pEffect->UploadVertexDeclaration(); ID3DXEffect* pD3DEffect = pEffect->GetEffect(); if(pD3DEffect) { RTexture* pTexture = (RTexture*)pShared->m_pRenderData; pD3DEffect->SetTexture("texture0", pTexture->m_pD3DTexture); i_client_shell->OnEffectShaderSetParams(pEffect, NULL, NULL, LTShaderDeviceStateImp::GetSingleton()); UINT nPasses = 0; pD3DEffect->Begin(&nPasses, 0); for(UINT i = 0; i < nPasses; ++i) { pD3DEffect->BeginPass(i); D3D_CALL(PD3DDEVICE->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, SpriteVerts, sizeof(CSpriteVertex))); pD3DEffect->EndPass(); } pD3DEffect->End(); } } else { D3D_CALL(PD3DDEVICE->SetVertexShader(NULL)); D3D_CALL(PD3DDEVICE->SetFVF(SPRITEVERTEX_FORMAT)); D3D_CALL(PD3DDEVICE->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, SpriteVerts, sizeof(CSpriteVertex))); } d3d_DisableTexture(0); }
void Controller::HandleFadeCommand(const CParsedMsg &cMsg) { static CParsedMsg::CToken s_cTok_Alpha("ALPHA"); static CParsedMsg::CToken s_cTok_Color("COLOR"); const char *pValue, *pDuration; ParamType paramType; ParamValue paramValue; WaveType waveType; float duration; uint32 i; if(cMsg.GetArgCount() < 4) { ShowTriggerError(cMsg); return; } const CParsedMsg::CToken &cParamType = cMsg.GetArg(1); pValue = cMsg.GetArg(2); pDuration = cMsg.GetArg(3); // Parse everything.. it doesn't do anything if there's an error. if(cParamType == s_cTok_Alpha) { paramType = Param_Alpha; } else if(cParamType == s_cTok_Color) { paramType = Param_Color; } else { ShowTriggerError(cMsg); return; } paramValue = ParseValue(paramType, pValue); duration = (float)atof(pDuration); duration = LTCLAMP(duration, 0.0f, 100000.0f); waveType = Wave_Sine; if(cMsg.GetArgCount() >= 5) { waveType = ParseWaveType(cMsg.GetArg(4)); } // Ok, configure... m_fStartTime = g_pLTServer->GetTime() + g_pLTServer->GetFrameTime(); m_fDuration = duration; m_ParamType = paramType; m_WaveType = waveType; m_DestValue = paramValue; ObjArray <HOBJECT, MAX_OBJECT_ARRAY_SIZE> objArray; for(i=0; i < MAX_CONTROLLER_TARGETS; i++) { g_pLTServer->FindNamedObjects(m_Fades[i].m_ObjectName, objArray); if (objArray.NumObjects()) { HOBJECT hObject = objArray.GetObject(0); m_Fades[i].m_hTarget = hObject; } SetupCurrentValue(&m_Fades[i]); } m_State = CState_Fade; Activate(); }
bool CClientFXDB::ReadFXKey( bool bText, ILTStream* pFxFile, float fTotalTime, FX_KEY* pKey, FX_PROP* pPropBuffer, uint32 nBuffLen ) { // Read in the reference name char sTmp[128]; if( bText ) { ReadTextFile( pFxFile, "%s %s", sTmp ); } else { pFxFile->Read(sTmp, 128); } pKey->m_pFxRef = FindFX( strtok(sTmp, ";" )); // Read in the key ID if( bText ) { ReadTextFile( pFxFile, "%s %lu", &pKey->m_dwID ); } else { pFxFile->Read(&pKey->m_dwID, sizeof(uint32)); } // Read in the link status LINK_STATUS ls; if( bText ) { ReadTextFile( pFxFile, "%s %i", &ls.m_bLinked ); ReadTextFile( pFxFile, "%s %lu", &ls.m_dwLinkedID ); //read in the linked node name but make sure that it is cleared out first ls.m_sLinkedNodeName[0] = '\0'; ReadTextFile( pFxFile, "%s %s", ls.m_sLinkedNodeName ); } else { pFxFile->Read(&ls, sizeof(LINK_STATUS)); } pKey->m_bLinked = ls.m_bLinked; pKey->m_dwLinkedID = ls.m_dwLinkedID; strcpy(pKey->m_sLinkedNodeName, ls.m_sLinkedNodeName); //check to make sure that the key is not motion linked to itself though if(pKey->m_bLinked && (pKey->m_dwLinkedID == pKey->m_dwID)) { pKey->m_bLinked = false; } // Read in the start time if( bText ) { ReadTextFile( pFxFile, "%s %f", &pKey->m_tmStart ); } else { pFxFile->Read(&pKey->m_tmStart, sizeof(float)); } // Read in the end time if( bText ) { ReadTextFile( pFxFile, "%s %f", &pKey->m_tmEnd ); } else { pFxFile->Read(&pKey->m_tmEnd, sizeof(float)); } // Read in the key repeat uint32 nKeyRepeats = 0; if( bText ) { ReadTextFile( pFxFile, "%s %lu", &nKeyRepeats ); } else { pFxFile->Read(&nKeyRepeats, sizeof(uint32)); } // Read in dummy values uint32 dwDummy; LTFLOAT fDummy; if( bText ) { ReadTextFile( pFxFile, "%s %lu", &dwDummy ); ReadTextFile( pFxFile, "%s %f", &fDummy ); ReadTextFile( pFxFile, "%s %f", &fDummy ); } else { pFxFile->Read(&dwDummy, sizeof(uint32)); pFxFile->Read(&dwDummy, sizeof(uint32)); pFxFile->Read(&dwDummy, sizeof(uint32)); } // Read in the number of properties uint32 dwNumProps; if( bText ) { ReadTextFile( pFxFile, "%s %lu", &dwNumProps ); } else { pFxFile->Read(&dwNumProps, sizeof(uint32)); } for (uint32 k = 0; k < dwNumProps; k ++) { if(k >= nBuffLen) { assert(!"Error: Found a key with too many properties, truncating additional properties"); break; } else { ReadFXProp( bText, pFxFile, pPropBuffer[k] ); } } //ok, we can now convert our properties over to the appropriate form int32 nFXID = FindFXID(pKey->m_pFxRef->m_sName); if(nFXID < 0) return false; //alright, get our property object pKey->m_pProps = m_pfnCreatePropList(nFXID); if(!pKey->m_pProps) return false; //make sure to clamp the times to always be between 0 and the length of the group, //otherwise numerical accuracy problems will arise pKey->m_tmStart = LTCLAMP(pKey->m_tmStart, 0.0f, fTotalTime); pKey->m_tmEnd = LTCLAMP(pKey->m_tmEnd, 0.0f, fTotalTime); //now setup the lifespan of the key pKey->m_pProps->SetLifetime(pKey->m_tmEnd - pKey->m_tmStart, nKeyRepeats); //and let it convert its properties if(!pKey->m_pProps->ParseProperties(pPropBuffer, k)) { m_pfnFreePropList(pKey->m_pProps); pKey->m_pProps = NULL; return false; } //setup this key (read out our keys and base properties) SetupKey(pKey, pPropBuffer, k); return true; }
void CScreenGame::OnFocus(bool bFocus) { CUserProfile *pProfile = g_pProfileMgr->GetCurrentProfile(); if (bFocus) { pProfile->SetGameOptions(); m_nDifficulty = pProfile->m_nDifficulty; m_bSubtitles = pProfile->m_bSubtitles; m_bGore = pProfile->m_bGore; m_bAlwaysRun = pProfile->m_bAlwaysRun; m_bCrouchToggle = pProfile->m_bCrouchToggle; m_nHeadBob = pProfile->m_nHeadBob; m_nMsgDur = pProfile->m_nMsgDur; m_bSlowMoFX = pProfile->m_bSlowMoFX; m_nAutoWeaponSwitch = 0; m_bSPAutoWeaponSwitch = pProfile->m_bSPAutoWeaponSwitch; m_bMPAutoWeaponSwitch = pProfile->m_bMPAutoWeaponSwitch; if (m_bSPAutoWeaponSwitch) { m_nAutoWeaponSwitch += 1; } if (m_bMPAutoWeaponSwitch) { m_nAutoWeaponSwitch += 2; } if (pProfile->m_bPersistentHUD) { m_nHUDFade = kMinFade; } else { m_nHUDFade = int(kfFadeDefault * pProfile->m_fHUDFadeSpeed); m_nHUDFade = LTCLAMP(m_nHUDFade,kMinFade,kMaxFade); } #if !defined(_DEMO) || defined(_SPDEMO) m_pDifficultyCtrl->Enable( !(g_pLTClient->IsConnected() && IsMultiplayerGameClient()) ); #endif UpdateData(false); } else { UpdateData(); pProfile->m_nDifficulty = m_nDifficulty; pProfile->m_bSubtitles = m_bSubtitles; pProfile->m_bGore = !!m_bGore; pProfile->m_bAlwaysRun = m_bAlwaysRun; pProfile->m_bCrouchToggle = m_bCrouchToggle; pProfile->m_nHeadBob = m_nHeadBob; pProfile->m_nMsgDur = m_nMsgDur; pProfile->m_bSlowMoFX = m_bSlowMoFX; #if defined(_MPDEMO) pProfile->m_bMPAutoWeaponSwitch = m_bMPAutoWeaponSwitch; #elif defined(_SPDEMO) pProfile->m_bSPAutoWeaponSwitch = m_bSPAutoWeaponSwitch; #else pProfile->m_bSPAutoWeaponSwitch = !!(m_nAutoWeaponSwitch & 0x01 ); pProfile->m_bMPAutoWeaponSwitch = !!(m_nAutoWeaponSwitch & 0x02 ); #endif pProfile->m_bPersistentHUD = (m_nHUDFade == kMinFade); if (pProfile->m_bPersistentHUD) g_pHUDMgr->ResetAllFades(); pProfile->m_fHUDFadeSpeed = float(m_nHUDFade) / kfFadeDefault; pProfile->ApplyGameOptions(); pProfile->Save(); } CBaseScreen::OnFocus(bFocus); }
bool CTrackedNodeMgr::SetNodeConstraints( HTRACKEDNODE ID, const LTVector& vMovConeAxis, const LTVector& vMovConeUp, float fXDiscomfortAngle, float fYDiscomfortAngle, float fXMaxAngle, float fYMaxAngle, float fMaxAngVel ) { //sanity checks if(!CheckValidity(ID)) return false; //ok, we have a valid ID, so let us setup the parameters CTrackedNode* pNode = (CTrackedNode*)ID; //see if the up and forward vectors are valid LTVector vForward = vMovConeAxis; LTVector vUp = vMovConeUp; //ensure proper scale vForward.Normalize(); vUp.Normalize(); //ensure they form a valid space (and not a plane) if(vUp.Dot(vForward) > 0.99f) { //not valid, we need to try a different up, our preference is the world up vUp.Init(0.0f, 1.0f, 0.0f); if(vUp.Dot(vForward) > 0.99f) { //ok, forward is already taking the up....so, tilt us back vUp.Init(0.0f, 0.0f, -1.0f); } } //now generate the right, and ensure orthogonality LTVector vRight = vForward.Cross(vUp); vUp = vRight.Cross(vForward); vRight.Normalize(); vUp.Normalize(); //setup this as the basis space pNode->m_mInvTargetTransform.SetBasisVectors(&vRight, &vUp, &vForward); pNode->m_mInvTargetTransform.Transpose(); //we need to make sure that their angular constraints are valid (meaning that they are positive and //less than 90 deg) fXMaxAngle = LTCLAMP(fXMaxAngle, 0.0f, DEG2RAD(89.0f)); fYMaxAngle = LTCLAMP(fYMaxAngle, 0.0f, DEG2RAD(89.0f)); fXDiscomfortAngle = LTCLAMP(fXDiscomfortAngle, 0.0f, fXMaxAngle); fYDiscomfortAngle = LTCLAMP(fYDiscomfortAngle, 0.0f, fYMaxAngle); //now precompute the tangent of those values (used for finding the height of the cone created which //is used in the threshold determination code) pNode->m_fTanXDiscomfort = (float)tan(fXDiscomfortAngle); pNode->m_fTanYDiscomfort = (float)tan(fYDiscomfortAngle); pNode->m_fTanXThreshold = (float)tan(fXMaxAngle); pNode->m_fTanYThreshold = (float)tan(fYMaxAngle); //handle setting up the maximum angular velocity pNode->m_fMaxAngVel = (float)fabs(fMaxAngVel); //and we are ready for primetime return true; }
bool CTracerFX::Update(float tmFrameTime) { //track our performance CTimedSystemBlock TimingBlock(g_tsClientFXTracer); // Base class update first BaseUpdate(tmFrameTime); //determine the length of this tracer float fTracerLen = GetTracerLength(); //update the position along the ray m_fRayPosition += GetProps()->m_fVelocity * tmFrameTime; float fTracerHead = m_fRayPosition; float fTracerTail = m_fRayPosition - fTracerLen; //now we need to find the extents of the segment float fSegmentStart = LTCLAMP(fTracerHead, 0.0f, m_fRayLength); float fSegmentEnd = LTCLAMP(fTracerTail, 0.0f, m_fRayLength); //now we generate a bounding box around these points LTVector vCenter = m_vStartPos + m_vDirection * ((fSegmentStart + fSegmentEnd) * 0.5f); //and now the half dimensions that encompass the tracer LTVector vHalfDims = m_vDirection * ((fSegmentStart - fSegmentEnd) * 0.5f); //make sure that this half dims represents the maximum extents vHalfDims.Max(-vHalfDims); //extend the half dims to include the thickness of the tracer float fUnitLifetime = GetUnitLifetime(); float fHalfThickness = GetProps()->m_ffcThickness.GetValue(fUnitLifetime) * 0.5f; vHalfDims += LTVector(fHalfThickness, fHalfThickness, fHalfThickness); //and now setup the object position and visibility g_pLTClient->SetObjectPos(m_hObject, vCenter); g_pLTClient->GetCustomRender()->SetVisBoundingBox(m_hObject, -vHalfDims, vHalfDims); //handle updating the light if we have one if(m_hTracerLight) { //the light needs to be moved to the center of the tracer g_pLTClient->SetObjectPos(m_hTracerLight, vCenter); //and have the intensity controlled by how much of the tracer is visible float fVisible = (fSegmentStart - fSegmentEnd) / fTracerLen; if(fVisible > 0.01f) { g_pLTClient->Common()->SetObjectFlags(m_hTracerLight, OFT_Flags, FLAG_VISIBLE, FLAG_VISIBLE); g_pLTClient->SetLightIntensityScale(m_hTracerLight, fVisible); } else { g_pLTClient->Common()->SetObjectFlags(m_hTracerLight, OFT_Flags, 0, FLAG_VISIBLE); } } //we are done if the tracer is past the end of the ray return (m_fRayPosition - GetTracerLength() < m_fRayLength); }
void CNetMgr::Update(char *pPrefix, LTFLOAT curTime, bool bAllowTimeout) { uint32 i; m_pCurPrefix = pPrefix; float timeDelta = curTime - m_fLastTime; timeDelta = LTCLAMP(timeDelta, 0.001f, 0.3f); m_fLastTime = curTime; m_FrameTime = timeDelta; for (i = 0; i < m_Connections; ++i) { CBaseConn *pConn = m_Connections[i]; // Countdown the latent packets and ship them off. for (GPOS pos = pConn->m_Latent.GetHeadPosition(); pos;) { LatentPacket *pLatent = pConn->m_Latent.GetNext(pos); pLatent->m_SendTimeCounter += timeDelta; if(pLatent->m_SendTimeCounter >= g_CV_LatencySim) { ReallySendPacket(pLatent->m_cPacket, pConn, pLatent->m_nPacketFlags); pConn->m_Latent.RemoveAt(pLatent); m_LatentPacketBank.Free(pLatent); } } // Update timers and do guaranteed delivery stuff... pConn->m_SendPPS.Update(timeDelta); pConn->m_SendBPS.Update(timeDelta); pConn->m_RecvPPS.Update(timeDelta); pConn->m_RecvBPS.Update(timeDelta); } // Update the global send rate tracker m_SendBPS.Update(timeDelta); // Output stats on stuff. if (g_CV_ShowConnStats) { for (i = 0; i < m_Connections; ++i) { CBaseConn *pConn = m_Connections[i]; NetDebugOut2(pConn, 0, "Conn %d Info - Ping: %.2f", i, pConn->GetPing()); NetDebugOut2(pConn, 0, "Conn %d Recv - PPS: %.1f, BPS: %.1f", i, pConn->m_RecvPPS.GetRate(), pConn->m_RecvBPS.GetRate()); NetDebugOut2(pConn, 0, "Conn %d Send - PPS: %.1f, BPS: %.1f", i, pConn->m_SendPPS.GetRate(), pConn->m_SendBPS.GetRate()); NetDebugOut2(pConn, 0, "Conn %d Raw - Recv: %7d, Send: %7d, Loss: %6.2f", i, pConn->GetIncomingBandwidthUsage(), pConn->GetOutgoingBandwidthUsage(), pConn->GetPacketLoss()); } } // Update the drivers. for (i = 0; i < m_Drivers; ++i) m_Drivers[i]->Update(); }
void HeadBobMgr::SetCustomCycleNotifyFn( HeadBobCycleNotifyFn pFn, void* pUserData, float fRange ) { m_pCustomCycleNotifyFn = pFn; m_pCustomCycleNotifyUserData = pUserData; m_fCustomCycleNotifyRange = LTCLAMP( fRange, -1.0f, 1.0f ); }
LTRESULT CRotatingWorldModelPlugin::PreHook_Light( ILTPreLight *pInterface, HPREOBJECT hObject) { GenericProp gProp; char shadowLights[256]; char className[64]; char rwmName[64]; char animName[128]; HPREOBJECT hShadowLight; ConParse cParse; KLProps theProps; DWORD iStep; float fPercent; int iAxis; uint32 iRwmLight; PreLightAnimFrameInfo *pFrame; PreLightInfo *pLightInfo; PreWorldModelInfo *pWorldModelInfo; PreLightAnimFrameInfo frames[MAX_RWM_LIGHT_STEPS+1]; PreLightInfo lightInfos[MAX_RWM_LIGHT_STEPS+1]; PreWorldModelInfo worldModelInfos[MAX_RWM_LIGHT_STEPS+1]; uint32 uLightFrames; iAxis = 0; iRwmLight = 0; pInterface->GetPropGeneric(hObject, "ShadowAxis", &gProp); if (gProp.m_Vec.x) iAxis = 1; else if (gProp.m_Vec.y) iAxis = 2; else if (gProp.m_Vec.z) iAxis = 3; pInterface->GetPropGeneric(hObject, "Name", &gProp); if (!iAxis) { pInterface->CPrint("No shadow axis set for RotatingWorldModel %s, won't light", gProp.m_String); return LT_OK; } else { switch(iAxis) { case 1: pInterface->CPrint("Lighting for %s rotated on x axis.", gProp.m_String); break; case 2: pInterface->CPrint("Lighting for %s rotated on y axis.", gProp.m_String); break; case 3: pInterface->CPrint("Lighting for %s rotated on z axis.", gProp.m_String); break; } } if (pInterface->GetPropGeneric(hObject, "LightFrames", &gProp) == LT_OK) uLightFrames = gProp.m_Long; else uLightFrames = 1; // Go through the ShadowLights. iRwmLight = 0; pInterface->GetPropGeneric(hObject, "ShadowLights", &gProp); SAFE_STRCPY(shadowLights, gProp.m_String); cParse.Init(shadowLights); while(pInterface->Parse(&cParse) == LT_OK) { if(cParse.m_nArgs == 0) continue; // Look for the object and make sure it's a keyframer light. if(pInterface->FindObject(cParse.m_Args[0], hShadowLight) != LT_OK || pInterface->GetClassName(hShadowLight, className, sizeof(className)) != LT_OK || stricmp(className, KEYFRAMERLIGHT_CLASSNAME) != 0) { continue; } // Read in all the light properties. ReadKLProps(pInterface, hShadowLight, &theProps); // Get some of the door properties. pInterface->GetPropGeneric(hObject, "Name", &gProp); SAFE_STRCPY(rwmName, gProp.m_String); // Hinged doors don't look good unless they have an odd number of frames. if((uLightFrames & 1) == 0) ++uLightFrames; uLightFrames = LTCLAMP(uLightFrames, 2, MAX_RWM_LIGHT_STEPS); for(iStep=0; iStep < (uLightFrames+1); iStep++) { pFrame = &frames[iStep]; pLightInfo = &lightInfos[iStep]; pWorldModelInfo = &worldModelInfos[iStep]; fPercent = (float)iStep / (uLightFrames - 1); pFrame->m_bSunLight = LTFALSE; pFrame->m_Lights = pLightInfo; pFrame->m_nLights = 1; pFrame->m_WorldModels = pWorldModelInfo; pFrame->m_nWorldModels = 1; pLightInfo->m_bDirectional = theProps.m_bDirLight; pLightInfo->m_FOV = theProps.m_fFOV; pLightInfo->m_Radius = theProps.m_fRadius; pLightInfo->m_vInnerColor = theProps.m_vInnerColor; pLightInfo->m_vOuterColor = theProps.m_vOuterColor; pLightInfo->m_vDirection = theProps.m_vForwardVec; pLightInfo->m_vPos = theProps.m_vPos; SAFE_STRCPY(pWorldModelInfo->m_WorldModelName, rwmName); if(iStep == uLightFrames) { // The last frame is without the world model for when it's destroyed. pWorldModelInfo->m_bInvisible = LTTRUE; } else { pInterface->GetWorldModelRuntimePos(hObject, pWorldModelInfo->m_Pos); switch (iAxis) { case 1: pInterface->GetMathLT()->SetupEuler(pWorldModelInfo->m_Rot, MATH_CIRCLE * fPercent, 0.0f, 0.0f); break; case 2: pInterface->GetMathLT()->SetupEuler(pWorldModelInfo->m_Rot, 0.0f, MATH_CIRCLE * fPercent, 0.0f); break; case 3: pInterface->GetMathLT()->SetupEuler(pWorldModelInfo->m_Rot, 0.0f, 0.0f, MATH_CIRCLE * fPercent); break; } } } SetupRWMLightAnimName(animName, rwmName, iRwmLight); pInterface->CreateLightAnim( animName, frames, uLightFrames+1, theProps.m_bUseShadowMaps); ++iRwmLight; } return LT_OK; }