mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-03-06 05:50:31 +00:00
merged numerous changes from upstream
This commit is contained in:
commit
d3956cb532
50 changed files with 914 additions and 363 deletions
|
|
@ -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 )
|
||||
{
|
||||
|
|
@ -515,8 +540,8 @@ void Lightning::renderObject(ObjectRenderInst *ri, SceneRenderState *state, Base
|
|||
}
|
||||
|
||||
//GFX->setZWriteEnable(true);
|
||||
//GFX->setAlphaTestEnable(false);
|
||||
//GFX->setAlphaBlendEnable(false);
|
||||
//GFX->setAlphaTestEnable(false);
|
||||
//GFX->setAlphaBlendEnable(false);
|
||||
}
|
||||
|
||||
void Lightning::scheduleThunder(Strike* newStrike)
|
||||
|
|
@ -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;
|
||||
|
|
@ -709,6 +734,7 @@ void Lightning::warningFlashes()
|
|||
{
|
||||
AssertFatal(isServerObject(), "Error, client objects may not initiate lightning!");
|
||||
|
||||
Point3F strikePoint( gRandGen.randF( 0.0f, 1.0f ), gRandGen.randF( 0.0f, 1.0f ), 0.0f );
|
||||
|
||||
SimGroup* pClientGroup = Sim::getClientGroup();
|
||||
for (SimGroup::iterator itr = pClientGroup->begin(); itr != pClientGroup->end(); itr++) {
|
||||
|
|
@ -717,6 +743,9 @@ void Lightning::warningFlashes()
|
|||
{
|
||||
LightningStrikeEvent* pEvent = new LightningStrikeEvent;
|
||||
pEvent->mLightning = this;
|
||||
|
||||
pEvent->mStart.x = strikePoint.x;
|
||||
pEvent->mStart.y = strikePoint.y;
|
||||
|
||||
nc->postNetEvent(pEvent);
|
||||
}
|
||||
|
|
@ -731,18 +760,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,
|
||||
|
|
@ -837,13 +867,53 @@ void Lightning::strikeRandomPoint()
|
|||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
void Lightning::strikeObject(ShapeBase*)
|
||||
void Lightning::strikeObject(ShapeBase* targetObj)
|
||||
{
|
||||
AssertFatal(isServerObject(), "Error, client objects may not initiate lightning!");
|
||||
|
||||
AssertFatal(false, "Lightning::strikeObject is not implemented.");
|
||||
}
|
||||
Point3F strikePoint = targetObj->getPosition();
|
||||
Point3F objectCenter;
|
||||
|
||||
Box3F wb = getWorldBox();
|
||||
if (!wb.isContained(strikePoint))
|
||||
return;
|
||||
|
||||
Point3F targetRel = strikePoint - getPosition();
|
||||
Point3F length(wb.len_x() / 2.0f, wb.len_y() / 2.0f, wb.len_z() / 2.0f);
|
||||
|
||||
Point3F strikePos = targetRel / length;
|
||||
|
||||
bool playerInWarmup = false;
|
||||
Player *playerObj = dynamic_cast< Player * >(targetObj);
|
||||
if (playerObj)
|
||||
{
|
||||
if (!playerObj->getControllingClient())
|
||||
{
|
||||
playerInWarmup = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!playerInWarmup)
|
||||
{
|
||||
applyDamage_callback(targetObj->getWorldSphere().center, VectorF(0.0, 0.0, 1.0), targetObj);
|
||||
}
|
||||
|
||||
SimGroup* pClientGroup = Sim::getClientGroup();
|
||||
for (SimGroup::iterator itr = pClientGroup->begin(); itr != pClientGroup->end(); itr++) {
|
||||
NetConnection* nc = static_cast<NetConnection*>(*itr);
|
||||
if (nc != NULL)
|
||||
{
|
||||
LightningStrikeEvent* pEvent = new LightningStrikeEvent;
|
||||
pEvent->mLightning = this;
|
||||
|
||||
pEvent->mStart.x = strikePoint.x;
|
||||
pEvent->mStart.y = strikePoint.y;
|
||||
pEvent->mTarget = targetObj;
|
||||
|
||||
nc->postNetEvent(pEvent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
U32 Lightning::packUpdate(NetConnection* con, U32 mask, BitStream* stream)
|
||||
|
|
@ -864,6 +934,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 +966,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 +1002,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" )
|
||||
{
|
||||
|
|
@ -1028,7 +1100,7 @@ void LightningBolt::render( const Point3F &camPos )
|
|||
renderSegment(mMinorNodes[i], camPos, false);
|
||||
}
|
||||
|
||||
PrimBuild::end();
|
||||
PrimBuild::end();
|
||||
|
||||
for(LightingBoltList::Iterator i = splitList.begin(); i != splitList.end(); ++i)
|
||||
{
|
||||
|
|
@ -1154,26 +1226,26 @@ 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;
|
||||
|
||||
|
||||
F32 chanceToEnd = gRandGen.randF();
|
||||
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 +1256,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 );
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -1203,7 +1275,7 @@ void LightningBolt::startSplits()
|
|||
for( U32 i=0; i<mMajorNodes.numNodes-1; i++ )
|
||||
{
|
||||
if( gRandGen.randF() > 0.3f )
|
||||
continue;
|
||||
continue;
|
||||
|
||||
Node node = mMajorNodes.nodeList[i];
|
||||
Node node2 = mMajorNodes.nodeList[i+1];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue