Merge pull request #1535 from GarageGames/AbstractConObjects

[CLONE] Add support for abstract ConObjects
This commit is contained in:
Anis 2016-02-27 02:38:39 +01:00
commit fa5a6f3eae
2 changed files with 154 additions and 116 deletions

View file

@ -567,47 +567,9 @@ extern AbstractClassRep::FieldList sg_tempFieldList;
/// @see AbtractClassRep /// @see AbtractClassRep
/// @see ConsoleObject /// @see ConsoleObject
template< class T > template< class T >
class ConcreteClassRep : public AbstractClassRep class ConcreteAbstractClassRep : public AbstractClassRep
{ {
public: public:
static EnginePropertyTable _smPropertyTable;
static EnginePropertyTable& smPropertyTable;
ConcreteClassRep( const char* name,
const char* conTypeName,
S32* conTypeIdPtr,
S32 netClassGroupMask,
S32 netClassType,
S32 netEventDir,
AbstractClassRep* parent,
const char* ( *parentDesc )() )
: AbstractClassRep( conTypeIdPtr, conTypeName )
{
mClassName = StringTable->insert( name );
mCategory = T::__category();
mTypeInfo = _MAPTYPE< T >();
if( mTypeInfo )
const_cast< EngineTypeInfo* >( mTypeInfo )->mPropertyTable = &smPropertyTable;
if( &T::__description != parentDesc )
mDescription = T::__description();
// Clean up mClassId
for(U32 i = 0; i < NetClassGroupsCount; i++)
mClassId[i] = -1;
// Set properties for this ACR
mClassType = netClassType;
mClassGroupMask = netClassGroupMask;
mNetEventDir = netEventDir;
parentClass = parent;
mClassSizeof = sizeof(T);
// Finally, register ourselves.
registerClassRep(this);
};
virtual AbstractClassRep* getContainerChildClass(const bool recurse) virtual AbstractClassRep* getContainerChildClass(const bool recurse)
{ {
@ -630,6 +592,47 @@ class ConcreteClassRep : public AbstractClassRep
return T::getStaticWriteCustomTamlSchema(); return T::getStaticWriteCustomTamlSchema();
} }
static EnginePropertyTable _smPropertyTable;
static EnginePropertyTable& smPropertyTable;
ConcreteAbstractClassRep(const char* name,
const char* conTypeName,
S32* conTypeIdPtr,
S32 netClassGroupMask,
S32 netClassType,
S32 netEventDir,
AbstractClassRep* parent,
const char* (*parentDesc)())
: AbstractClassRep(conTypeIdPtr, conTypeName)
{
mClassName = StringTable->insert(name);
mCategory = T::__category();
mTypeInfo = _MAPTYPE< T >();
if (mTypeInfo)
const_cast< EngineTypeInfo* >(mTypeInfo)->mPropertyTable = &smPropertyTable;
if (&T::__description != parentDesc)
mDescription = T::__description();
// Clean up mClassId
for (U32 i = 0; i < NetClassGroupsCount; i++)
mClassId[i] = -1;
// Set properties for this ACR
mClassType = netClassType;
mClassGroupMask = netClassGroupMask;
mNetEventDir = netEventDir;
parentClass = parent;
mClassSizeof = sizeof(T);
// Finally, register ourselves.
registerClassRep(this);
};
/// Wrap constructor.
ConsoleObject* create() const { return NULL; }
/// Perform class specific initialization tasks. /// Perform class specific initialization tasks.
/// ///
/// Link namespaces, call initPersistFields() and consoleInit(). /// Link namespaces, call initPersistFields() and consoleInit().
@ -640,7 +643,7 @@ class ConcreteClassRep : public AbstractClassRep
AbstractClassRep *child = T::getStaticClassRep(); AbstractClassRep *child = T::getStaticClassRep();
// If we got reps, then link those namespaces! (To get proper inheritance.) // If we got reps, then link those namespaces! (To get proper inheritance.)
if(parent && child) if (parent && child)
Con::classLinkNamespaces(parent->getNameSpace(), child->getNameSpace()); Con::classLinkNamespaces(parent->getNameSpace(), child->getNameSpace());
// Finally, do any class specific initialization... // Finally, do any class specific initialization...
@ -651,38 +654,54 @@ class ConcreteClassRep : public AbstractClassRep
AbstractClassRep::init(); AbstractClassRep::init();
} }
/// Wrap constructor.
ConsoleObject* create() const { return new T; }
/// @name Console Type Interface /// @name Console Type Interface
/// @{ /// @{
virtual void setData( void* dptr, S32 argc, const char** argv, const EnumTable* tbl, BitSet32 flag ) virtual void setData(void* dptr, S32 argc, const char** argv, const EnumTable* tbl, BitSet32 flag)
{ {
if( argc == 1 ) if (argc == 1)
{ {
T** obj = ( T** ) dptr; T** obj = (T**)dptr;
*obj = dynamic_cast< T* >( T::__findObject( argv[ 0 ] ) ); *obj = dynamic_cast< T* >(T::__findObject(argv[0]));
} }
else else
Con::errorf( "Cannot set multiple args to a single ConsoleObject*."); Con::errorf("Cannot set multiple args to a single ConsoleObject*.");
} }
virtual const char* getData( void* dptr, const EnumTable* tbl, BitSet32 flag ) virtual const char* getData(void* dptr, const EnumTable* tbl, BitSet32 flag)
{ {
T** obj = ( T** ) dptr; T** obj = (T**)dptr;
return Con::getReturnBuffer( T::__getObjectId( *obj ) ); return Con::getReturnBuffer(T::__getObjectId(*obj));
} }
virtual const char* getTypeClassName() { return mClassName; } virtual const char* getTypeClassName() { return mClassName; }
virtual const bool isDatablock() { return T::__smIsDatablock; }; virtual const bool isDatablock() { return T::__smIsDatablock; };
/// @} /// @}
};
template< class T >
class ConcreteClassRep : public ConcreteAbstractClassRep<T>
{
public:
ConcreteClassRep(const char* name,
const char* conTypeName,
S32* conTypeIdPtr,
S32 netClassGroupMask,
S32 netClassType,
S32 netEventDir,
AbstractClassRep* parent,
const char* (*parentDesc)())
: ConcreteAbstractClassRep<T>(name, conTypeName, conTypeIdPtr, netClassGroupMask, netClassType, netEventDir, parent, parentDesc)
{
}
/// Wrap constructor.
ConsoleObject* create() const { return new T; }
}; };
template< typename T > EnginePropertyTable ConcreteClassRep< T >::_smPropertyTable( 0, NULL ); template< typename T > EnginePropertyTable ConcreteAbstractClassRep< T >::_smPropertyTable(0, NULL);
template< typename T > EnginePropertyTable& ConcreteClassRep< T >::smPropertyTable = ConcreteClassRep< T >::_smPropertyTable; template< typename T > EnginePropertyTable& ConcreteAbstractClassRep< T >::smPropertyTable = ConcreteAbstractClassRep< T >::_smPropertyTable;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Forward declaration of this function so it can be used in the class // Forward declaration of this function so it can be used in the class
@ -763,6 +782,15 @@ public:
/// Gets the ClassRep. /// Gets the ClassRep.
virtual AbstractClassRep* getClassRep() const; virtual AbstractClassRep* getClassRep() const;
#define DECLARE_ABSTRACT_CONOBJECT( className ) \
DECLARE_ABSTRACT_CLASS( className, Parent ); \
static S32 _smTypeId; \
static ConcreteAbstractClassRep< className > dynClassRep; \
static AbstractClassRep* getParentStaticClassRep(); \
static AbstractClassRep* getStaticClassRep(); \
static SimObjectRefConsoleBaseType< className > ptrRefType; \
virtual AbstractClassRep* getClassRep() const
/// Set the value of a field. /// Set the value of a field.
bool setField(const char *fieldName, const char *value); bool setField(const char *fieldName, const char *value);
@ -1172,6 +1200,16 @@ inline bool& ConsoleObject::getDynamicGroupExpand()
AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return schema; } \ AbstractClassRep::WriteCustomTamlSchema className::getStaticWriteCustomTamlSchema() { return schema; } \
ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description ) ConcreteClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
#define IMPLEMENT_ABSTRACT_CONOBJECT( className ) \
IMPLEMENT_NONINSTANTIABLE_CLASS( className, NULL ) \
END_IMPLEMENT_CLASS; \
S32 className::_smTypeId; \
SimObjectRefConsoleBaseType< className > className::ptrRefType( "Type" #className "Ref" ); \
AbstractClassRep* className::getClassRep() const { return &className::dynClassRep; } \
AbstractClassRep* className::getStaticClassRep() { return &dynClassRep; } \
AbstractClassRep* className::getParentStaticClassRep() { return Parent::getStaticClassRep(); } \
ConcreteAbstractClassRep<className> className::dynClassRep( #className, "Type" #className, &_smTypeId, 0, -1, 0, className::getParentStaticClassRep(), &Parent::__description )
#define IMPLEMENT_CO_NETOBJECT_V1( className ) \ #define IMPLEMENT_CO_NETOBJECT_V1( className ) \
IMPLEMENT_CLASS( className, NULL ) \ IMPLEMENT_CLASS( className, NULL ) \
END_IMPLEMENT_CLASS; \ END_IMPLEMENT_CLASS; \

View file

@ -362,7 +362,7 @@ class EngineTypeInfo : public EngineExportScope
// them to retroactively install property tables. Will be removed // them to retroactively install property tables. Will be removed
// when the console interop is removed and all classes are migrated // when the console interop is removed and all classes are migrated
// to the new system. // to the new system.
template< typename T > friend class ConcreteClassRep; template< typename T > friend class ConcreteAbstractClassRep;
protected: protected: