Merge pull request #417 from Azaezel/alpha40_shapeMacroMagic

corrected and implemented a usage of shapeasset macros
This commit is contained in:
Areloch 2020-12-28 00:15:04 -06:00 committed by GitHub
commit 3b111b14cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 59 deletions

View file

@ -57,7 +57,9 @@
#ifdef TORQUE_TOOLS #ifdef TORQUE_TOOLS
#include "gui/editor/guiInspectorTypes.h" #include "gui/editor/guiInspectorTypes.h"
#endif #endif
#ifndef _BITSTREAM_H_
#include "core/stream/bitStream.h"
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class ShapeAsset : public AssetBase class ShapeAsset : public AssetBase
{ {
@ -207,19 +209,19 @@ public:
#define assetText(x,suff) std::string(std::string(#x) + std::string(#suff)).c_str() #define assetText(x,suff) std::string(std::string(#x) + std::string(#suff)).c_str()
#define initShapeAsset(name) m##name##Filename = StringTable->EmptyString(); m##name##AssetId = StringTable->EmptyString(); m##name##Asset = NULL; #define initShapeAsset(name) m##name##Name = StringTable->EmptyString(); m##name##AssetId = StringTable->EmptyString(); m##name##Asset = NULL;
#define cloneShapeAsset(name) m##name##Name = other.m##name##Name; m##name##AssetId = other.m##name##AssetId; m##name##Asset = other.m##name##Asset;
#define bindShapeAsset(name) if (m##name##AssetId != StringTable->EmptyString()) m##name##Asset = m##name##AssetId; #define bindShapeAsset(name) if (m##name##AssetId != StringTable->EmptyString()) m##name##Asset = m##name##AssetId;
#define scriptBindShapeAsset(name, consoleClass, docs) addProtectedField(assetText(name, File), TypeShapeFilename, Offset(m##name##Filename, consoleClass), consoleClass::_set##name##Filename, & defaultProtectedGetFn, assetText(name, docs)); \ #define scriptBindShapeAsset(name, consoleClass, docs) addProtectedField(assetText(name, File), TypeShapeFilename, Offset(m##name##Name, consoleClass), consoleClass::_set##name##Filename, & defaultProtectedGetFn, assetText(name, docs)); \
addProtectedField(assetText(name, Asset), TypeShapeAssetId, Offset(m##name##AssetId, consoleClass), consoleClass::_set##name##Asset, & defaultProtectedGetFn, assetText(name, asset reference.)); addProtectedField(assetText(name, Asset), TypeShapeAssetId, Offset(m##name##AssetId, consoleClass), consoleClass::_set##name##Asset, & defaultProtectedGetFn, assetText(name, asset reference.));
#define DECLARE_SHAPEASSET(className,name) protected: \ #define DECLARE_SHAPEASSET(className,name)\
StringTableEntry m##name##Filename;\ StringTableEntry m##name##Name;\
StringTableEntry m##name##AssetId;\ StringTableEntry m##name##AssetId;\
AssetPtr<ShapeAsset> m##name##Asset;\ AssetPtr<ShapeAsset> m##name##Asset;\
public: \ const StringTableEntry& get##name() const { return m##name##Name; }\
const StringTableEntry& get##name() const { return m##name##Filename; }\ void set##name(FileName _in) { m##name##Name = _in; }\
void set##name(FileName _in) { m##name##Filename = _in; }\
const AssetPtr<ShapeAsset> & get##name##Asset() const { return m##name##Asset; }\ const AssetPtr<ShapeAsset> & get##name##Asset() const { return m##name##Asset; }\
void set##name##Asset(AssetPtr<ShapeAsset>_in) { m##name##Asset = _in; }\ void set##name##Asset(AssetPtr<ShapeAsset>_in) { m##name##Asset = _in; }\
static bool _set##name##Filename(void* obj, const char* index, const char* data)\ static bool _set##name##Filename(void* obj, const char* index, const char* data)\
@ -233,7 +235,7 @@ static bool _set##name##Filename(void* obj, const char* index, const char* data)
{\ {\
if (assetId == StringTable->insert("Core_Rendering:noShape"))\ if (assetId == StringTable->insert("Core_Rendering:noShape"))\
{\ {\
shape->m##name##Filename = data;\ shape->m##name##Name = data;\
shape->m##name##AssetId = StringTable->EmptyString();\ shape->m##name##AssetId = StringTable->EmptyString();\
\ \
return true;\ return true;\
@ -241,7 +243,7 @@ static bool _set##name##Filename(void* obj, const char* index, const char* data)
else\ else\
{\ {\
shape->m##name##AssetId = assetId;\ shape->m##name##AssetId = assetId;\
shape->m##name##Filename = StringTable->EmptyString();\ shape->m##name##Name = StringTable->EmptyString();\
\ \
return false;\ return false;\
}\ }\
@ -262,12 +264,28 @@ static bool _set##name##Asset(void* obj, const char* index, const char* data)\
if (ShapeAsset::getAssetById(shape->m##name##AssetId, &shape->m##name##Asset))\ if (ShapeAsset::getAssetById(shape->m##name##AssetId, &shape->m##name##Asset))\
{\ {\
if (shape->m##name##Asset.getAssetId() != StringTable->insert("Core_Rendering:noShape"))\ if (shape->m##name##Asset.getAssetId() != StringTable->insert("Core_Rendering:noShape"))\
shape->m##name##Filename = StringTable->EmptyString();\ shape->m##name##Name = StringTable->EmptyString();\
\
shape->setMaskBits(-1);\
return true;\ return true;\
}\ }\
return false;\ return false;\
}\
void className::pack##name##Asset(BitStream *stream)\
{\
if (stream->writeFlag(m##name##Asset.notNull()))\
stream->writeString(m##name##Asset.getAssetId());\
else\
stream->writeString(m##name##Name);\
}\
void className::unpack##name##Asset(BitStream *stream)\
{\
if (stream->readFlag())\
{\
m##name##AssetId = stream->readSTString();\
ShapeAsset::getAssetById(m##name##AssetId, &m##name##Asset);\
m##name##Name = m##name##Asset->getShapeFilename(); \
}\
else\
m##name##Name = stream->readSTString();\
} }
#endif #endif

View file

@ -291,7 +291,7 @@ bool RigidShapeData::preload(bool server, String &errorStr)
if (!collisionDetails.size() || collisionDetails[0] == -1) if (!collisionDetails.size() || collisionDetails[0] == -1)
{ {
Con::errorf("RigidShapeData::preload failed: Rigid shapes must define a collision-1 detail"); Con::errorf("RigidShapeData::preload failed: Rigid shapes must define a collision-1 detail");
errorStr = String::ToString("RigidShapeData: Couldn't load shape \"%s\"",shapeName); errorStr = String::ToString("RigidShapeData: Couldn't load shape \"%s\"", mShapeName);
return false; return false;
} }

View file

@ -158,9 +158,6 @@ ShapeBaseData::ShapeBaseData()
shadowMaxVisibleDistance( 80.0f ), shadowMaxVisibleDistance( 80.0f ),
shadowProjectionDistance( 10.0f ), shadowProjectionDistance( 10.0f ),
shadowSphereAdjust( 1.0f ), shadowSphereAdjust( 1.0f ),
shapeName( StringTable->EmptyString() ),
shapeAsset(StringTable->EmptyString()),
shapeAssetId(StringTable->EmptyString()),
cloakTexName( StringTable->EmptyString() ), cloakTexName( StringTable->EmptyString() ),
cubeDescId( 0 ), cubeDescId( 0 ),
reflectorDesc( NULL ), reflectorDesc( NULL ),
@ -200,7 +197,8 @@ ShapeBaseData::ShapeBaseData()
isInvincible( false ), isInvincible( false ),
renderWhenDestroyed( true ), renderWhenDestroyed( true ),
inheritEnergyFromMount( false ) inheritEnergyFromMount( false )
{ {
initShapeAsset(Shape);
dMemset( mountPointNode, -1, sizeof( S32 ) * SceneObject::NumMountPoints ); dMemset( mountPointNode, -1, sizeof( S32 ) * SceneObject::NumMountPoints );
remap_txr_tags = NULL; remap_txr_tags = NULL;
remap_buffer = NULL; remap_buffer = NULL;
@ -214,10 +212,8 @@ ShapeBaseData::ShapeBaseData(const ShapeBaseData& other, bool temp_clone) : Game
shadowMaxVisibleDistance = other.shadowMaxVisibleDistance; shadowMaxVisibleDistance = other.shadowMaxVisibleDistance;
shadowProjectionDistance = other.shadowProjectionDistance; shadowProjectionDistance = other.shadowProjectionDistance;
shadowSphereAdjust = other.shadowSphereAdjust; shadowSphereAdjust = other.shadowSphereAdjust;
shapeName = other.shapeName;
shapeAsset = other.shapeAsset;
shapeAssetId = other.shapeAssetId;
cloakTexName = other.cloakTexName; cloakTexName = other.cloakTexName;
cloneShapeAsset(Shape);
cubeDescName = other.cubeDescName; cubeDescName = other.cubeDescName;
cubeDescId = other.cubeDescId; cubeDescId = other.cubeDescId;
reflectorDesc = other.reflectorDesc; reflectorDesc = other.reflectorDesc;
@ -368,26 +364,26 @@ bool ShapeBaseData::preload(bool server, String &errorStr)
} }
//Legacy catch //Legacy catch
if (shapeName != StringTable->EmptyString()) if (mShapeName != StringTable->EmptyString())
{ {
shapeAssetId = ShapeAsset::getAssetIdByFilename(shapeName); mShapeAssetId = ShapeAsset::getAssetIdByFilename(mShapeName);
} }
U32 assetState = ShapeAsset::getAssetById(shapeAssetId, &shapeAsset); U32 assetState = ShapeAsset::getAssetById(mShapeAssetId, &mShapeAsset);
if (ShapeAsset::Failed != assetState) if (ShapeAsset::Failed != assetState)
{ {
//only clear the legacy direct file reference if everything checks out fully //only clear the legacy direct file reference if everything checks out fully
if (assetState == ShapeAsset::Ok) if (assetState == ShapeAsset::Ok)
{ {
shapeName = StringTable->EmptyString(); mShapeName = StringTable->EmptyString();
} }
else Con::warnf("Warning: ShapeBaseData::preload-%s", ShapeAsset::getAssetErrstrn(assetState).c_str()); else Con::warnf("Warning: ShapeBaseData::preload-%s", ShapeAsset::getAssetErrstrn(assetState).c_str());
S32 i; S32 i;
// Resolve shapename // Resolve shapename
mShape = shapeAsset->getShapeResource(); mShape = mShapeAsset->getShapeResource();
if (bool(mShape) == false) if (bool(mShape) == false)
{ {
errorStr = String::ToString("ShapeBaseData: Couldn't load shape \"%s\"",shapeName); errorStr = String::ToString("ShapeBaseData: Couldn't load shape \"%s\"",mShapeName);
return false; return false;
} }
if(!server && !mShape->preloadMaterialList(mShape.getPath()) && NetConnection::filesWereDownloaded()) if(!server && !mShape->preloadMaterialList(mShape.getPath()) && NetConnection::filesWereDownloaded())
@ -395,13 +391,13 @@ bool ShapeBaseData::preload(bool server, String &errorStr)
if(computeCRC) if(computeCRC)
{ {
Con::printf("Validation required for shape: %s", shapeName); Con::printf("Validation required for shape: %s", mShapeName);
Torque::FS::FileNodeRef fileRef = Torque::FS::GetFileNode(mShape.getPath()); Torque::FS::FileNodeRef fileRef = Torque::FS::GetFileNode(mShape.getPath());
if (!fileRef) if (!fileRef)
{ {
errorStr = String::ToString("ShapeBaseData: Couldn't load shape \"%s\"",shapeName); errorStr = String::ToString("ShapeBaseData: Couldn't load shape \"%s\"", mShapeName);
return false; return false;
} }
@ -409,7 +405,7 @@ bool ShapeBaseData::preload(bool server, String &errorStr)
mCRC = fileRef->getChecksum(); mCRC = fileRef->getChecksum();
else if(mCRC != fileRef->getChecksum()) else if(mCRC != fileRef->getChecksum())
{ {
errorStr = String::ToString("Shape \"%s\" does not match version on server.",shapeName); errorStr = String::ToString("Shape \"%s\" does not match version on server.", mShapeName);
return false; return false;
} }
} }
@ -431,13 +427,13 @@ bool ShapeBaseData::preload(bool server, String &errorStr)
if (!mShape->mBounds.isContained(collisionBounds.last())) if (!mShape->mBounds.isContained(collisionBounds.last()))
{ {
if (!silent_bbox_check) if (!silent_bbox_check)
Con::warnf("Warning: shape %s collision detail %d (Collision-%d) bounds exceed that of shape.", shapeName, collisionDetails.size() - 1, collisionDetails.last()); Con::warnf("Warning: shape %s collision detail %d (Collision-%d) bounds exceed that of shape.", mShapeName, collisionDetails.size() - 1, collisionDetails.last());
collisionBounds.last() = mShape->mBounds; collisionBounds.last() = mShape->mBounds;
} }
else if (collisionBounds.last().isValidBox() == false) else if (collisionBounds.last().isValidBox() == false)
{ {
if (!silent_bbox_check) if (!silent_bbox_check)
Con::errorf("Error: shape %s-collision detail %d (Collision-%d) bounds box invalid!", shapeName, collisionDetails.size() - 1, collisionDetails.last()); Con::errorf("Error: shape %s-collision detail %d (Collision-%d) bounds box invalid!", mShapeName, collisionDetails.size() - 1, collisionDetails.last());
collisionBounds.last() = mShape->mBounds; collisionBounds.last() = mShape->mBounds;
} }
@ -597,10 +593,10 @@ void ShapeBaseData::initPersistFields()
addGroup( "Render" ); addGroup( "Render" );
addField("shapeAsset", TypeShapeAssetId, Offset(shapeAssetId, ShapeBaseData), addField("shapeAsset", TypeShapeAssetId, Offset(mShapeAssetId, ShapeBaseData),
"The source shape asset."); "The source shape asset.");
addField( "shapeFile", TypeShapeFilename, Offset(shapeName, ShapeBaseData), addField( "shapeFile", TypeShapeFilename, Offset(mShapeName, ShapeBaseData),
"The DTS or DAE model to use for this object." ); "The DTS or DAE model to use for this object." );
endGroup( "Render" ); endGroup( "Render" );
@ -805,14 +801,7 @@ void ShapeBaseData::packData(BitStream* stream)
stream->write(shadowSphereAdjust); stream->write(shadowSphereAdjust);
if (stream->writeFlag(shapeAsset.notNull())) packShapeAsset(stream);
{
stream->writeString(shapeAsset.getAssetId());
}
else
{
stream->writeString(shapeName);
}
stream->writeString(cloakTexName); stream->writeString(cloakTexName);
if(stream->writeFlag(mass != gShapeBaseDataProto.mass)) if(stream->writeFlag(mass != gShapeBaseDataProto.mass))
@ -891,16 +880,7 @@ void ShapeBaseData::unpackData(BitStream* stream)
stream->read(&shadowSphereAdjust); stream->read(&shadowSphereAdjust);
if (stream->readFlag()) unpackShapeAsset(stream);
{
shapeAssetId = stream->readSTString();
ShapeAsset::getAssetById(shapeAssetId, &shapeAsset);
shapeName = shapeAsset->getShapeFilename();
}
else
{
shapeName = stream->readSTString();
}
cloakTexName = stream->readSTString(); cloakTexName = stream->readSTString();
if(stream->readFlag()) if(stream->readFlag())

View file

@ -538,11 +538,7 @@ public:
F32 shadowProjectionDistance; F32 shadowProjectionDistance;
F32 shadowSphereAdjust; F32 shadowSphereAdjust;
DECLARE_SHAPEASSET(ShapeBaseData, Shape);
StringTableEntry shapeName;
AssetPtr<ShapeAsset> shapeAsset;
StringTableEntry shapeAssetId;
StringTableEntry cloakTexName; StringTableEntry cloakTexName;

View file

@ -208,7 +208,7 @@ bool VehicleData::preload(bool server, String &errorStr)
if (!collisionDetails.size() || collisionDetails[0] == -1) if (!collisionDetails.size() || collisionDetails[0] == -1)
{ {
Con::errorf("VehicleData::preload failed: Vehicle models must define a collision-1 detail"); Con::errorf("VehicleData::preload failed: Vehicle models must define a collision-1 detail");
errorStr = String::ToString("VehicleData: Couldn't load shape \"%s\"",shapeName); errorStr = String::ToString("VehicleData: Couldn't load shape \"%s\"", mShapeName);
return false; return false;
} }

View file

@ -86,7 +86,7 @@ public:
virtual U32 packUpdate(NetConnection*, U32, BitStream*); virtual U32 packUpdate(NetConnection*, U32, BitStream*);
virtual void unpackUpdate(NetConnection*, BitStream*); virtual void unpackUpdate(NetConnection*, BitStream*);
const char* getShapeFileName() const { return mDataBlock->shapeName; } const char* getShapeFileName() const { return mDataBlock->mShapeName; }
void setVisibility(bool flag) { mIs_visible = flag; } void setVisibility(bool flag) { mIs_visible = flag; }
DECLARE_CONOBJECT(afxStaticShape); DECLARE_CONOBJECT(afxStaticShape);