projectile

This commit is contained in:
marauder2k7 2025-06-19 16:29:59 +01:00
parent 51f4255c14
commit 1949ff9d7b
2 changed files with 19 additions and 21 deletions

View file

@ -145,7 +145,7 @@ U32 Projectile::smProjectileWarpTicks = 5;
// //
ProjectileData::ProjectileData() ProjectileData::ProjectileData()
{ {
INIT_ASSET(ProjectileShape); mProjectileShapeAsset.registerRefreshNotify(this);
INIT_ASSET(ProjectileSound); INIT_ASSET(ProjectileSound);
@ -223,7 +223,7 @@ ProjectileData::ProjectileData(const ProjectileData& other, bool temp_clone) : G
CLONE_ASSET(ProjectileSound); CLONE_ASSET(ProjectileSound);
lightDesc = other.lightDesc; lightDesc = other.lightDesc;
lightDescId = other.lightDescId; // -- for pack/unpack of lightDesc ptr lightDescId = other.lightDescId; // -- for pack/unpack of lightDesc ptr
CLONE_ASSET(ProjectileShape);// -- TSShape loads using mProjectileShapeName mProjectileShapeAsset = other.mProjectileShapeAsset;// -- TSShape loads using mProjectileShapeName
activateSeq = other.activateSeq; // -- from projectileShape sequence "activate" activateSeq = other.activateSeq; // -- from projectileShape sequence "activate"
maintainSeq = other.maintainSeq; // -- from projectileShape sequence "maintain" maintainSeq = other.maintainSeq; // -- from projectileShape sequence "maintain"
particleEmitter = other.particleEmitter; particleEmitter = other.particleEmitter;
@ -237,9 +237,7 @@ void ProjectileData::initPersistFields()
{ {
docsURL; docsURL;
addGroup("Shapes"); addGroup("Shapes");
addProtectedField("projectileShapeName", TypeShapeFilename, Offset(mProjectileShapeName, ProjectileData), &_setProjectileShapeData, &defaultProtectedGetFn, INITPERSISTFIELD_SHAPEASSET_REFACTOR(ProjectileShape, ProjectileData, "@brief The model of the projectile.\n\n");
"@brief File path to the model of the projectile.\n\n", AbstractClassRep::FIELD_HideInInspectors);
INITPERSISTFIELD_SHAPEASSET(ProjectileShape, ProjectileData, "@brief The model of the projectile.\n\n");
addField("scale", TypePoint3F, Offset(scale, ProjectileData), addField("scale", TypePoint3F, Offset(scale, ProjectileData),
"@brief Scale to apply to the projectile's size.\n\n" "@brief Scale to apply to the projectile's size.\n\n"
"@note This is applied after SceneObject::scale\n"); "@note This is applied after SceneObject::scale\n");
@ -383,20 +381,20 @@ bool ProjectileData::preload(bool server, String &errorStr)
Con::errorf(ConsoleLogEntry::General, "ProjectileData::preload: Invalid packet, bad datablockid(lightDesc): %d", lightDescId); Con::errorf(ConsoleLogEntry::General, "ProjectileData::preload: Invalid packet, bad datablockid(lightDesc): %d", lightDescId);
} }
if (mProjectileShapeAssetId != StringTable->EmptyString()) if (mProjectileShapeAsset.notNull())
{ {
//If we've got a shapeAsset assigned for our projectile, but we failed to load the shape data itself, report the error //If we've got a shapeAsset assigned for our projectile, but we failed to load the shape data itself, report the error
if (!mProjectileShape) if (!getProjectileShape())
{ {
errorStr = String::ToString("ProjectileData::load: Couldn't load shape \"%s\"", mProjectileShapeAssetId); errorStr = String::ToString("ProjectileData::load: Couldn't load shape \"%s\"", _getProjectileShapeAssetId());
return false; return false;
} }
else else
{ {
activateSeq = mProjectileShape->findSequence("activate"); activateSeq = getProjectileShape()->findSequence("activate");
maintainSeq = mProjectileShape->findSequence("maintain"); maintainSeq = getProjectileShape()->findSequence("maintain");
TSShapeInstance* pDummy = new TSShapeInstance(mProjectileShape, !server); TSShapeInstance* pDummy = new TSShapeInstance(getProjectileShape(), !server);
delete pDummy; delete pDummy;
} }
} }
@ -409,7 +407,7 @@ void ProjectileData::packData(BitStream* stream)
{ {
Parent::packData(stream); Parent::packData(stream);
PACKDATA_ASSET(ProjectileShape); PACKDATA_ASSET_REFACTOR(ProjectileShape);
stream->writeFlag(faceViewer); stream->writeFlag(faceViewer);
if(stream->writeFlag(scale.x != 1 || scale.y != 1 || scale.z != 1)) if(stream->writeFlag(scale.x != 1 || scale.y != 1 || scale.z != 1))
@ -474,7 +472,7 @@ void ProjectileData::unpackData(BitStream* stream)
{ {
Parent::unpackData(stream); Parent::unpackData(stream);
UNPACKDATA_ASSET(ProjectileShape); UNPACKDATA_ASSET_REFACTOR(ProjectileShape);
faceViewer = stream->readFlag(); faceViewer = stream->readFlag();
if(stream->readFlag()) if(stream->readFlag())
@ -800,9 +798,9 @@ bool Projectile::onAdd()
} }
else else
{ {
if (bool(mDataBlock->mProjectileShape)) if (bool(mDataBlock->getProjectileShape()))
{ {
mProjectileShape = new TSShapeInstance(mDataBlock->mProjectileShape, isClientObject()); mProjectileShape = new TSShapeInstance(mDataBlock->getProjectileShape(), isClientObject());
if (mDataBlock->activateSeq != -1) if (mDataBlock->activateSeq != -1)
{ {
@ -841,8 +839,8 @@ bool Projectile::onAdd()
processAfter(mSourceObject); processAfter(mSourceObject);
// Setup our bounding box // Setup our bounding box
if (bool(mDataBlock->mProjectileShape) == true) if (bool(mDataBlock->getProjectileShape()) == true)
mObjBox = mDataBlock->mProjectileShape->mBounds; mObjBox = mDataBlock->getProjectileShape()->mBounds;
else else
mObjBox = Box3F(Point3F(0, 0, 0), Point3F(0, 0, 0)); mObjBox = Box3F(Point3F(0, 0, 0), Point3F(0, 0, 0));

View file

@ -63,7 +63,7 @@ class Projectile;
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
/// Datablock for projectiles. This class is the base class for all other projectiles. /// Datablock for projectiles. This class is the base class for all other projectiles.
class ProjectileData : public GameBaseData class ProjectileData : public GameBaseData, protected AssetPtrCallback
{ {
typedef GameBaseData Parent; typedef GameBaseData Parent;
@ -71,8 +71,7 @@ protected:
bool onAdd() override; bool onAdd() override;
public: public:
DECLARE_SHAPEASSET(ProjectileData, ProjectileShape, onShapeChanged); DECLARE_SHAPEASSET_REFACTOR(ProjectileData, ProjectileShape)
DECLARE_ASSET_SETGET(ProjectileData, ProjectileShape);
/// Set to true if it is a billboard and want it to always face the viewer, false otherwise /// Set to true if it is a billboard and want it to always face the viewer, false otherwise
bool faceViewer; bool faceViewer;
@ -154,7 +153,8 @@ public:
ProjectileData(const ProjectileData&, bool = false); ProjectileData(const ProjectileData&, bool = false);
bool allowSubstitutions() const override { return true; } bool allowSubstitutions() const override { return true; }
void onShapeChanged() protected:
void onAssetRefreshed(AssetPtrBase* pAssetPtrBase) override
{ {
reloadOnLocalClient(); reloadOnLocalClient();
} }