mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-01-19 20:24:49 +00:00
Merge pull request #1931 from Areloch/LightingFix
Fixes some issues with lightning
This commit is contained in:
commit
1523fe55de
|
|
@ -200,7 +200,7 @@ void LightningStrikeEvent::unpack(NetConnection* con, BitStream* stream)
|
|||
{
|
||||
if(!stream->readFlag())
|
||||
return;
|
||||
S32 mClientId = stream->readRangedU32(0, NetConnection::MaxGhostCount);
|
||||
mClientId = stream->readRangedU32(0, NetConnection::MaxGhostCount);
|
||||
mLightning = NULL;
|
||||
NetObject* pObject = con->resolveGhost(mClientId);
|
||||
if (pObject)
|
||||
|
|
@ -214,10 +214,10 @@ void LightningStrikeEvent::unpack(NetConnection* con, BitStream* stream)
|
|||
// target id
|
||||
S32 mTargetID = stream->readRangedU32(0, NetConnection::MaxGhostCount);
|
||||
|
||||
NetObject* pObject = con->resolveGhost(mTargetID);
|
||||
if( pObject != NULL )
|
||||
NetObject* tObject = con->resolveGhost(mTargetID);
|
||||
if(tObject != NULL )
|
||||
{
|
||||
mTarget = dynamic_cast<SceneObject*>(pObject);
|
||||
mTarget = dynamic_cast<SceneObject*>(tObject);
|
||||
}
|
||||
if( bool(mTarget) == false )
|
||||
{
|
||||
|
|
@ -243,6 +243,7 @@ LightningData::LightningData()
|
|||
dMemset( strikeTextureNames, 0, sizeof( strikeTextureNames ) );
|
||||
dMemset( strikeTextures, 0, sizeof( strikeTextures ) );
|
||||
dMemset( thunderSounds, 0, sizeof( thunderSounds ) );
|
||||
mNumStrikeTextures = 0;
|
||||
}
|
||||
|
||||
LightningData::~LightningData()
|
||||
|
|
@ -297,10 +298,14 @@ bool LightningData::preload(bool server, String &errorStr)
|
|||
if( !sfxResolve( &strikeSound, sfxErrorStr ) )
|
||||
Con::errorf(ConsoleLogEntry::General, "LightningData::preload: Invalid packet: %s", sfxErrorStr.c_str());
|
||||
|
||||
mNumStrikeTextures = 0;
|
||||
for (U32 i = 0; i < MaxTextures; i++)
|
||||
{
|
||||
if (strikeTextureNames[i][0])
|
||||
{
|
||||
strikeTextures[i] = GFXTexHandle(strikeTextureNames[i], &GFXDefaultStaticDiffuseProfile, avar("%s() - strikeTextures[%d] (line %d)", __FUNCTION__, i, __LINE__));
|
||||
mNumStrikeTextures++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -317,7 +322,11 @@ void LightningData::packData(BitStream* stream)
|
|||
U32 i;
|
||||
for (i = 0; i < MaxThunders; i++)
|
||||
sfxWrite( stream, thunderSounds[ i ] );
|
||||
for (i = 0; i < MaxTextures; i++) {
|
||||
|
||||
stream->writeInt(mNumStrikeTextures, 4);
|
||||
|
||||
for (i = 0; i < MaxTextures; i++)
|
||||
{
|
||||
stream->writeString(strikeTextureNames[i]);
|
||||
}
|
||||
|
||||
|
|
@ -331,7 +340,11 @@ void LightningData::unpackData(BitStream* stream)
|
|||
U32 i;
|
||||
for (i = 0; i < MaxThunders; i++)
|
||||
sfxRead( stream, &thunderSounds[ i ] );
|
||||
for (i = 0; i < MaxTextures; i++) {
|
||||
|
||||
mNumStrikeTextures = stream->readInt(4);
|
||||
|
||||
for (i = 0; i < MaxTextures; i++)
|
||||
{
|
||||
strikeTextureNames[i] = stream->readSTString();
|
||||
}
|
||||
|
||||
|
|
@ -368,16 +381,16 @@ Lightning::~Lightning()
|
|||
{
|
||||
while( mThunderListHead )
|
||||
{
|
||||
Thunder* next = mThunderListHead->next;
|
||||
Thunder* nextThunder = mThunderListHead->next;
|
||||
delete mThunderListHead;
|
||||
mThunderListHead = next;
|
||||
mThunderListHead = nextThunder;
|
||||
}
|
||||
|
||||
while( mStrikeListHead )
|
||||
{
|
||||
Strike* next = mStrikeListHead->next;
|
||||
Strike* nextStrike = mStrikeListHead->next;
|
||||
delete mStrikeListHead;
|
||||
mStrikeListHead = next;
|
||||
mStrikeListHead = nextStrike;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -478,11 +491,16 @@ void Lightning::renderObject(ObjectRenderInst *ri, SceneRenderState *state, Base
|
|||
desc.setBlend( true, GFXBlendSrcAlpha, GFXBlendOne);
|
||||
desc.setCullMode(GFXCullNone);
|
||||
desc.zWriteEnable = false;
|
||||
desc.samplersDefined = true;
|
||||
desc.samplers[0].magFilter = GFXTextureFilterLinear;
|
||||
desc.samplers[0].minFilter = GFXTextureFilterLinear;
|
||||
desc.samplers[0].addressModeU = GFXAddressWrap;
|
||||
desc.samplers[0].addressModeV = GFXAddressWrap;
|
||||
desc.vertexColorEnable = true;
|
||||
|
||||
if (mDataBlock->mNumStrikeTextures != 0)
|
||||
{
|
||||
desc.samplersDefined = true;
|
||||
desc.samplers[0].magFilter = GFXTextureFilterLinear;
|
||||
desc.samplers[0].minFilter = GFXTextureFilterLinear;
|
||||
desc.samplers[0].addressModeU = GFXAddressWrap;
|
||||
desc.samplers[0].addressModeV = GFXAddressWrap;
|
||||
}
|
||||
|
||||
mLightningSB = GFX->createStateBlock(desc);
|
||||
|
||||
|
|
@ -494,9 +512,16 @@ void Lightning::renderObject(ObjectRenderInst *ri, SceneRenderState *state, Base
|
|||
Strike* walk = mStrikeListHead;
|
||||
while (walk != NULL)
|
||||
{
|
||||
GFX->setTexture(0, mDataBlock->strikeTextures[0]);
|
||||
if (mDataBlock->mNumStrikeTextures > 1)
|
||||
{
|
||||
GFX->setTexture(0, mDataBlock->strikeTextures[sgLightningRand.randI(0, mDataBlock->mNumStrikeTextures - 1)]);
|
||||
}
|
||||
else if (mDataBlock->mNumStrikeTextures > 0)
|
||||
{
|
||||
GFX->setTexture(0, mDataBlock->strikeTextures[0]);
|
||||
}
|
||||
|
||||
for( U32 i=0; i<3; i++ )
|
||||
for( U32 i=0; i<MAX_LIGHTNING; i++ )
|
||||
{
|
||||
if( walk->bolt[i].isFading )
|
||||
{
|
||||
|
|
@ -589,7 +614,7 @@ void Lightning::advanceTime(F32 dt)
|
|||
while (*pWalker != NULL) {
|
||||
Strike* pStrike = *pWalker;
|
||||
|
||||
for( U32 i=0; i<3; i++ )
|
||||
for( U32 i=0; i<MAX_LIGHTNING; i++ )
|
||||
{
|
||||
pStrike->bolt[i].update( dt );
|
||||
}
|
||||
|
|
@ -673,7 +698,7 @@ void Lightning::processEvent(LightningStrikeEvent* pEvent)
|
|||
pStrike->currentAge = 0.0f;
|
||||
pStrike->next = mStrikeListHead;
|
||||
|
||||
for( U32 i=0; i<3; i++ )
|
||||
for( U32 i=0; i<MAX_LIGHTNING; i++ )
|
||||
{
|
||||
F32 randStart = boltStartRadius;
|
||||
F32 height = mObjScale.z * 0.5f + getPosition().z;
|
||||
|
|
@ -731,18 +756,19 @@ void Lightning::strikeRandomPoint()
|
|||
Point3F strikePoint( gRandGen.randF( 0.0f, 1.0f ), gRandGen.randF( 0.0f, 1.0f ), 0.0f );
|
||||
|
||||
// check if an object is within target range
|
||||
Point3F worldPosStrikePoint = strikePoint;
|
||||
|
||||
strikePoint *= mObjScale;
|
||||
strikePoint += getPosition();
|
||||
strikePoint += Point3F( -mObjScale.x * 0.5f, -mObjScale.y * 0.5f, 0.0f );
|
||||
worldPosStrikePoint *= mObjScale;
|
||||
worldPosStrikePoint += getPosition();
|
||||
worldPosStrikePoint += Point3F( -mObjScale.x * 0.5f, -mObjScale.y * 0.5f, 0.0f );
|
||||
|
||||
Box3F queryBox;
|
||||
F32 boxWidth = strikeRadius * 2.0f;
|
||||
|
||||
queryBox.minExtents.set( -boxWidth * 0.5f, -boxWidth * 0.5f, -mObjScale.z * 0.5f );
|
||||
queryBox.maxExtents.set( boxWidth * 0.5f, boxWidth * 0.5f, mObjScale.z * 0.5f );
|
||||
queryBox.minExtents += strikePoint;
|
||||
queryBox.maxExtents += strikePoint;
|
||||
queryBox.minExtents += worldPosStrikePoint;
|
||||
queryBox.maxExtents += worldPosStrikePoint;
|
||||
|
||||
SimpleQueryList sql;
|
||||
getContainer()->findObjects(queryBox, DAMAGEABLE_TYPEMASK,
|
||||
|
|
@ -864,6 +890,7 @@ U32 Lightning::packUpdate(NetConnection* con, U32 mask, BitStream* stream)
|
|||
stream->write(color.red);
|
||||
stream->write(color.green);
|
||||
stream->write(color.blue);
|
||||
stream->write(color.alpha);
|
||||
stream->write(fadeColor.red);
|
||||
stream->write(fadeColor.green);
|
||||
stream->write(fadeColor.blue);
|
||||
|
|
@ -895,6 +922,7 @@ void Lightning::unpackUpdate(NetConnection* con, BitStream* stream)
|
|||
stream->read(&color.red);
|
||||
stream->read(&color.green);
|
||||
stream->read(&color.blue);
|
||||
stream->read(&color.alpha);
|
||||
stream->read(&fadeColor.red);
|
||||
stream->read(&fadeColor.green);
|
||||
stream->read(&fadeColor.blue);
|
||||
|
|
@ -930,7 +958,7 @@ DefineEngineMethod(Lightning, strikeRandomPoint, void, (),,
|
|||
object->strikeRandomPoint();
|
||||
}
|
||||
|
||||
DefineEngineMethod(Lightning, strikeObject, void, (ShapeBase* pSB),,
|
||||
DefineEngineMethod(Lightning, strikeObject, void, (ShapeBase* pSB), (nullAsType<ShapeBase*>()),
|
||||
"Creates a LightningStrikeEvent which strikes a specific object.\n"
|
||||
"@note This method is currently unimplemented.\n" )
|
||||
{
|
||||
|
|
@ -1154,7 +1182,7 @@ void LightningBolt::generateMinorNodes()
|
|||
//----------------------------------------------------------------------------
|
||||
// Recursive algo to create bolts that split off from main bolt
|
||||
//----------------------------------------------------------------------------
|
||||
void LightningBolt::createSplit( const Point3F &startPoint, const Point3F &endPoint, U32 depth, F32 width )
|
||||
void LightningBolt::createSplit( const Point3F &startingPoint, const Point3F &endingPoint, U32 depth, F32 splitWidth )
|
||||
{
|
||||
if( depth == 0 )
|
||||
return;
|
||||
|
|
@ -1163,17 +1191,17 @@ void LightningBolt::createSplit( const Point3F &startPoint, const Point3F &endPo
|
|||
if( chanceToEnd > 0.70f )
|
||||
return;
|
||||
|
||||
if( width < 0.75f )
|
||||
width = 0.75f;
|
||||
if(splitWidth < 0.75f )
|
||||
splitWidth = 0.75f;
|
||||
|
||||
VectorF diff = endPoint - startPoint;
|
||||
VectorF diff = endingPoint - startingPoint;
|
||||
F32 length = diff.len();
|
||||
diff.normalizeSafe();
|
||||
|
||||
LightningBolt newBolt;
|
||||
newBolt.startPoint = startPoint;
|
||||
newBolt.endPoint = endPoint;
|
||||
newBolt.width = width;
|
||||
newBolt.startPoint = startingPoint;
|
||||
newBolt.endPoint = endingPoint;
|
||||
newBolt.width = splitWidth;
|
||||
newBolt.numMajorNodes = 3;
|
||||
newBolt.maxMajorAngle = 30.0f;
|
||||
newBolt.numMinorNodes = 3;
|
||||
|
|
@ -1184,13 +1212,13 @@ void LightningBolt::createSplit( const Point3F &startPoint, const Point3F &endPo
|
|||
splitList.pushBack( newBolt );
|
||||
|
||||
VectorF newDir1 = MathUtils::randomDir( diff, 10.0f, 45.0f );
|
||||
Point3F newEndPoint1 = endPoint + newDir1 * gRandGen.randF( 0.5f, 1.5f ) * length;
|
||||
Point3F newEndPoint1 = endingPoint + newDir1 * gRandGen.randF( 0.5f, 1.5f ) * length;
|
||||
|
||||
VectorF newDir2 = MathUtils::randomDir( diff, 10.0f, 45.0f );
|
||||
Point3F newEndPoint2 = endPoint + newDir2 * gRandGen.randF( 0.5f, 1.5f ) * length;
|
||||
Point3F newEndPoint2 = endingPoint + newDir2 * gRandGen.randF( 0.5f, 1.5f ) * length;
|
||||
|
||||
createSplit( endPoint, newEndPoint1, depth - 1, width * 0.30f );
|
||||
createSplit( endPoint, newEndPoint2, depth - 1, width * 0.30f );
|
||||
createSplit(endingPoint, newEndPoint1, depth - 1, splitWidth * 0.30f );
|
||||
createSplit(endingPoint, newEndPoint2, depth - 1, splitWidth * 0.30f );
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ class ShapeBase;
|
|||
class LightningStrikeEvent;
|
||||
class SFXTrack;
|
||||
|
||||
#define MAX_LIGHTNING 3
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
class LightningData : public GameBaseData
|
||||
|
|
@ -70,6 +71,7 @@ class LightningData : public GameBaseData
|
|||
|
||||
GFXTexHandle strikeTextures[MaxTextures];
|
||||
U32 numThunders;
|
||||
U32 mNumStrikeTextures;
|
||||
|
||||
protected:
|
||||
bool onAdd();
|
||||
|
|
|
|||
|
|
@ -83,6 +83,8 @@ datablock LightningData(DefaultStorm)
|
|||
thunderSounds[1] = ThunderCrash2Sound;
|
||||
thunderSounds[2] = ThunderCrash3Sound;
|
||||
thunderSounds[3] = ThunderCrash4Sound;
|
||||
|
||||
strikeTextures[0] = "art/environment/lightning";
|
||||
};
|
||||
|
||||
datablock ReflectorDesc( DefaultCubeDesc )
|
||||
|
|
|
|||
BIN
Templates/Full/game/art/environment/lightning.png
Normal file
BIN
Templates/Full/game/art/environment/lightning.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.8 KiB |
Loading…
Reference in a new issue