Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 64 additions & 5 deletions Engine/source/T3D/projectile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "T3D/lightDescription.h"
#include "console/engineAPI.h"
#include "T3D/rigidShape.h"
#include "materials/materialPropertiesManager.h"


IMPLEMENT_CO_DATABLOCK_V1(ProjectileData);
Expand Down Expand Up @@ -1122,8 +1123,14 @@ void Projectile::explode( const Point3F &p, const Point3F &n, const U32 collideT
}
}

// Client (impact) decal.
if ( mDataBlock->decal )
RayInfo matRay;
BaseMatInstance* hitMat = NULL;
if (gClientContainer.castRay(p + n * 0.05f, p - n * 0.01f, csmStaticCollisionMask, &matRay))
hitMat = matRay.material;

// Fallback to datablock decal if no surface effect matched
MaterialPropertiesData* fx = MaterialFXManager.resolve(hitMat);
if (!fx && mDataBlock->decal)
gDecalManager->addDecal(p, n, 0.0f, mDataBlock->decal);

// Client object
Expand Down Expand Up @@ -1267,10 +1274,62 @@ void Projectile::simulate( F32 dt )
// specific code should be placed inside the function!
onCollision( rInfo.point, rInfo.normal, rInfo.object );
// Next order of business: do we explode on this hit?
if ( mCurrTick > mDataBlock->armingDelay || mDataBlock->armingDelay == 0 )
if (mCurrTick > mDataBlock->armingDelay || mDataBlock->armingDelay == 0)
{
mCurrVelocity = Point3F::Zero;
explode( rInfo.point, rInfo.normal, objectType );
MaterialPropertiesResult fx_result = resolveImpact(
rInfo.material,
mCurrVelocity,
rInfo.normal,
mDataBlock->impactForce,
false);

// Fire visual effects on client only
if (isClientObject())
{
MaterialFXManager.fireEffect(
rInfo.material,
rInfo.point,
rInfo.normal,
mCurrVelocity.len(),
mDataBlock->impactForce,
fx_result.didRicochet,
false);
}

if (fx_result.didRicochet)
{
mCurrVelocity = fx_result.ricochetDirection * fx_result.ricochetSpeed;
newPosition = rInfo.point + rInfo.normal * 0.05f;
}

if (fx_result.didPenetrate)
{
mCurrVelocity *= fx_result.remainingVelocityFactor;
VectorF normVel = mCurrVelocity;
normVel.normalizeSafe();
newPosition = rInfo.point + normVel * 0.1f;
}

if (fx_result.didPenetrate || fx_result.didRicochet)
{
if (isServerObject())
setMaskBits(BounceMask);

if (disableSourceObjCollision)
mSourceObject->enableCollision();
enableCollision();

mCurrDeltaBase = newPosition;
mCurrBackDelta = mCurrPosition - newPosition;
mCurrPosition = newPosition;

xform.setColumn(3, mCurrPosition);
setTransform(xform);
return;
}

mCurrVelocity = Point3F::Zero;
explode(rInfo.point, rInfo.normal, objectType);
}

if ( mDataBlock->isBallistic )
Expand Down
9 changes: 9 additions & 0 deletions Engine/source/app/mainLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
#include "assets/assetManager.h"
#endif

#ifndef _MATERIAL_PROPERTIES_MANAGER_H_
#include "materials/materialPropertiesManager.h"
#endif // !_MATERIAL_PROPERTIES_MANAGER_H_


DITTS( F32, gTimeScale, 1.0 );
DITTS( U32, gTimeAdvance, 0 );
DITTS( U32, gFrameSkip, 0 );
Expand Down Expand Up @@ -284,6 +289,8 @@ void StandardMainLoop::init()

// Register the asset database as a module listener.
ModuleDatabase.addListener(&AssetDatabase);

MaterialFXManager.registerObject("MaterialFXManager");

ActionMap* globalMap = new ActionMap;
globalMap->registerObject("GlobalActionMap");
Expand All @@ -310,6 +317,8 @@ void StandardMainLoop::shutdown()
delete tm;
preShutdown();

MaterialFXManager.unregisterObject();

// Unregister the module database.
ModuleDatabase.unregisterObject();

Expand Down
Loading
Loading