📄 fxlight.cc
字号:
//Con::printf("fxLight: Attached but no object available, stopping search.");
// Finished waiting for attachment.
mAttachWait = false;
}
}
}
//------------------------------------------------------------------------------
void fxLight::setEnable(bool Status)
{
// Set Attribute.
mEnable = Status;
// Set Config Change Mask.
if (isServerObject()) setMaskBits(fxLightConfigChangeMask);
}
void fxLight::setFlareBitmap(const char* Name)
{
// Set Flare Texture Name.
mDataBlock->mFlareTextureName = StringTable->insert(Name);
// Only let the client load an actual texture.
if (isClientObject())
{
// Reset existing flare texture.
mFlareTextureHandle = NULL;
// Got a nice flare texture?
if (*mDataBlock->mFlareTextureName)
{
// Yes, so load it.
mFlareTextureHandle = TextureHandle(mDataBlock->mFlareTextureName, BitmapTexture, true);
}
}
// Set Config Change Mask.
if (isServerObject()) setMaskBits(fxLightConfigChangeMask);
}
void fxLight::reset(void)
{
// Reset Animation.
ResetAnimation();
// Set Config Change Mask.
if (isServerObject()) setMaskBits(fxLightConfigChangeMask);
}
void fxLight::attachToObject(const char* ObjectName)
{
// Find the Selected Object.
GameBase *Obj = dynamic_cast<GameBase*>(Sim::findObject(ObjectName));
// Check we found it.
if (!Obj)
{
Con::warnf("Couldn't find %s object to attach to!", ObjectName);
return;
}
// If the object has a name then output attachment.
//if (getName()) Con::printf("%s attached to object %s.", getName(), ObjectName);
// set-up dependency.
processAfter(Obj);
// Make sure we know if it's deleted.
deleteNotify(Obj);
// Set Config Change Mask.
if (isServerObject()) mAttachWait = true;
}
void fxLight::detachFromObject(void)
{
// Return if nothing to do!
if (!getProcessAfter()) return;
// If the object has a name then output detachment.
//if (getName()) Con::printf("%s detached from object %s.", getName(), getProcessAfter()->getName());
// Don't need delete notification now.
clearNotify(getProcessAfter());
// Clear dependency.
clearProcessAfter();
// Set Config Change Mask.
if (isServerObject())
{
// Signal Attach is no invalid.
mAttachValid = false;
// Tell the client it's all over.
setMaskBits(fxLightAttachChange);
}
}
//------------------------------------------------------------------------------
ConsoleMethod( fxLight, setEnable, void, 3, 3, "(bool enabled)")
{
object->setEnable(dAtob(argv[2]));
}
ConsoleMethod( fxLight, reset, void, 2, 2, "() Reset the light.")
{
object->reset();
}
ConsoleMethod( fxLight, attachToObject, void, 3, 3, "(SimObject obj) Attach to the SimObject obj.")
{
object->attachToObject(argv[2]);
}
ConsoleMethod( fxLight, detachFromObject, void, 2, 2, "() Detach from the object previously set by attachToObject.")
{
object->detachFromObject();
}
//------------------------------------------------------------------------------
void fxLight::registerLights(LightManager * lightManager, bool lightingScene)
{
// Exit if disabled.
if (!mEnable) return;
// Animate Light.
AnimateLight();
// Return if lighting scene or light off.
if (lightingScene || !mDataBlock->mLightOn) return;
// Setup light frame.
mLight.mPos = mAnimationPosition;
mLight.mRadius = mAnimationRadius;
mLight.mColor = mAnimationColour;
// Add light to light manager.
lightManager->addLight(&mLight);
}
//------------------------------------------------------------------------------
void fxLight::AnimateLight(void)
{
// Calculate Elapsed Time.
F32 mElapsedTime = (F32)((Platform::getRealMilliseconds() - mLastAnimateTime) / 1000.0f);
// Reset Last Animation Time.
mLastAnimateTime = Platform::getRealMilliseconds();
// ********************************************
// Calculate Colour.
// ********************************************
// Animating Colour?
if (mDataBlock->mUseColour)
{
U32 PosFrom;
U32 PosTo;
F32 LerpFactor;
// Yes, so adjust time-base.
mColourElapsedTime += mElapsedTime;
// Adjust to Bounds.
while (mColourElapsedTime > mDataBlock->mColourTime) { mColourElapsedTime -= mDataBlock->mColourTime; };
// Scale Time.
F32 ScaledTime = mColourElapsedTime * mColourTimeScale;
// Calculate Position From.
PosFrom = mFloor(ScaledTime);
// Are we Lerping?
if (mDataBlock->mLerpColour)
{
// Yes, so calculate Position To.
PosTo = mCeil(ScaledTime);
// Calculate Lerp Factor.
LerpFactor = ScaledTime - PosFrom;
}
else
{
// No, so clamp Position.
PosTo = PosFrom;
// Clamp lerp factor.
LerpFactor = 0.0f;
}
// Reset RGB Set Flag.
bool RedSet = false;
bool GreenSet = false;
bool BlueSet = false;
// ********************************************
// Red<GREEN,BLUE> Keys.
// ********************************************
if (mRedKeysLength)
{
// Are we using single-channel colour keys?
if (mDataBlock->mSingleColourKeys)
{
// Yes, so calculate rgb from red keys.
mAnimationColour.red = GetLerpKey(mDataBlock->mRedKeys, PosFrom, PosTo, mDataBlock->mMinColour.red, mDataBlock->mMaxColour.red, LerpFactor);
mAnimationColour.green = GetLerpKey(mDataBlock->mRedKeys, PosFrom, PosTo, mDataBlock->mMinColour.green, mDataBlock->mMaxColour.green, LerpFactor);
mAnimationColour.blue = GetLerpKey(mDataBlock->mRedKeys, PosFrom, PosTo, mDataBlock->mMinColour.blue, mDataBlock->mMaxColour.blue, LerpFactor);
// Flag RGB Set.
RedSet = GreenSet = BlueSet = true;
}
else
{
// No, so calculate Red only.
mAnimationColour.red = GetLerpKey(mDataBlock->mRedKeys, PosFrom, PosTo, mDataBlock->mMinColour.red, mDataBlock->mMaxColour.red, LerpFactor);
// Flag Red Set.
RedSet = true;
}
}
// ********************************************
// Green Keys.
// ********************************************
if (!mDataBlock->mSingleColourKeys && mGreenKeysLength)
{
// Calculate Green.
mAnimationColour.green = GetLerpKey(mDataBlock->mGreenKeys, PosFrom, PosTo, mDataBlock->mMinColour.green, mDataBlock->mMaxColour.green, LerpFactor);
// Flag Green Set.
GreenSet = true;
}
// ********************************************
// Blue Keys.
// ********************************************
if (!mDataBlock->mSingleColourKeys && mBlueKeysLength)
{
// Calculate Blue.
mAnimationColour.blue = GetLerpKey(mDataBlock->mGreenKeys, PosFrom, PosTo, mDataBlock->mMinColour.blue, mDataBlock->mMaxColour.blue, LerpFactor);
// Flag Blue Set.
BlueSet = true;
}
// Set to static colour if we failed to set RGB correctly.
if (!RedSet || !GreenSet || !BlueSet) mAnimationColour = mDataBlock->mColour;
}
else
{
// No, so set to static Colour.
mAnimationColour = mDataBlock->mColour;
}
// ********************************************
// Calculate Brightness.
// ********************************************
// Animating Brightness?
if (mDataBlock->mUseBrightness)
{
U32 PosFrom;
U32 PosTo;
F32 LerpFactor;
// Yes, so adjust time-base.
mBrightnessElapsedTime += mElapsedTime;
// Adjust to Bounds.
while (mBrightnessElapsedTime > mDataBlock->mBrightnessTime) { mBrightnessElapsedTime -= mDataBlock->mBrightnessTime; };
// Scale Time.
F32 ScaledTime = mBrightnessElapsedTime * mBrightnessTimeScale;
// Calculate Position From.
PosFrom = mFloor(ScaledTime);
// Are we Lerping?
if (mDataBlock->mLerpBrightness)
{
// Yes, so calculate Position To.
PosTo = mCeil(ScaledTime);
// Calculate Lerp Factor.
LerpFactor = ScaledTime - PosFrom;
}
else
{
// No, so clamp Position.
PosTo = PosFrom;
// Clamp lerp factor.
LerpFactor = 0.0f;
}
// ********************************************
// Brightness Keys.
// ********************************************
if (mBrightnessKeysLength)
{
// No, so calculate Brightness.
mAnimationBrightness = GetLerpKey(mDataBlock->mBrightnessKeys, PosFrom, PosTo, mDataBlock->mMinBrightness, mDataBlock->mMaxBrightness, LerpFactor);
}
else
{
// Set to static brightness if we failed to set Brightness correctly.
mAnimationBrightness = mDataBlock->mBrightness;
}
}
else
{
// No, so set to static Brightness.
mAnimationBrightness = mDataBlock->mBrightness;
}
// Adjust Colour by Brightness.
mAnimationColour *= ColorF( mAnimationBrightness, mAnimationBrightness, mAnimationBrightness );
// ********************************************
// Calculate Radius.
// ********************************************
// Animating Radius?
if (mDataBlock->mUseRadius)
{
U32 PosFrom;
U32 PosTo;
F32 LerpFactor;
// Yes, so adjust time-base.
mRadiusElapsedTime += mElapsedTime;
// Adjust to Bounds.
while (mRadiusElapsedTime > mDataBlock->mRadiusTime) { mRadiusElapsedTime -= mDataBlock->mRadiusTime; };
// Scale Time.
F32 ScaledTime = mRadiusElapsedTime * mRadiusTimeScale;
// Calculate Position From.
PosFrom = mFloor(ScaledTime);
// Are we Lerping?
if (mDataBlock->mLerpRadius)
{
// Yes, so calculate Position To.
PosTo = mCeil(ScaledTime);
// Calculate Lerp Factor.
LerpFactor = ScaledTime - PosFrom;
}
else
{
// No, so clamp Position.
PosTo = PosFrom;
// Clamp lerp factor.
LerpFactor = 0.0f;
}
// ********************************************
// Radius Keys.
// ********************************************
if (mRadiusKeysLength)
{
// No, so calculate Radius.
mAnimationRadius = GetLerpKey(mDataBlock->mRadiusKeys, PosFrom, PosTo, mDataBlock->mMinRadius, mDataBlock->mMaxRadius, LerpFactor);
}
else
{
// Set to static Radius if we failed to set Radius correctly.
mAnimationRadius = mDataBlock->mRadius;
}
}
else
{
// No, so set to static Radius.
mAnimationRadius = mDataBlock->mRadius;
}
// ********************************************
// Calculate Rotation.
// ********************************************
// Animating Rotation?
if (mDataBlock->mUseRotation)
{
U32 PosFrom;
U32 PosTo;
F32 LerpFactor;
// Yes, so adjust time-base.
mRotationElapsedTime += mElapsedTime;
// Adjust to Bounds.
while (mRotationElapsedTime > mDataBlock->mRotationTime) { mRotationElapsedTime -= mDataBlock->mRotationTime; };
// Scale Time.
F32 ScaledTime = mRotationElapsedTime * mRotationTimeScale;
// Calculate Position From.
PosFrom = mFloor(ScaledTime);
// Are we Lerping?
if (mDataBlock->mLerpRotation)
{
// Yes, so calculate Position To.
PosTo = mCeil(ScaledTime);
// Calculate Lerp Factor.
LerpFactor = ScaledTime - PosFrom;
}
else
{
// No, so clamp Position.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -