mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-19 14:43:47 +00:00
Adds a new function for defining static console fields on NetObjects - addNetworkedField()
This lets you attach a 32 bit netMask to the field, so that when it is changed, it automatically flags the associated bitmasks on the netobject as dirty. This is to shortcut having to flag certain masks being marked as dirty through protected fields and just simplify/streamline the code.
This commit is contained in:
parent
463cd50d0a
commit
b0e8a1f032
5 changed files with 167 additions and 2 deletions
|
|
@ -37,6 +37,7 @@
|
|||
#include "console/engineTypes.h"
|
||||
#include "console/engineAPI.h"
|
||||
|
||||
#include "sim/netObject.h"
|
||||
|
||||
IMPLEMENT_SCOPE( ConsoleAPI, Console,,
|
||||
"Functionality related to the legacy TorqueScript console system." );
|
||||
|
|
@ -372,6 +373,7 @@ void ConsoleObject::addGroup(const char* in_pGroupname, const char* in_pGroupDoc
|
|||
f.setDataFn = &defaultProtectedSetFn;
|
||||
f.getDataFn = &defaultProtectedGetFn;
|
||||
f.writeDataFn = &defaultProtectedWriteFn;
|
||||
f.networkMask = 0;
|
||||
|
||||
// Add to field list.
|
||||
sg_tempFieldList.push_back(f);
|
||||
|
|
@ -396,6 +398,7 @@ void ConsoleObject::endGroup(const char* in_pGroupname)
|
|||
f.getDataFn = &defaultProtectedGetFn;
|
||||
f.writeDataFn = &defaultProtectedWriteFn;
|
||||
f.elementCount = 0;
|
||||
f.networkMask = 0;
|
||||
|
||||
// Add to field list.
|
||||
sg_tempFieldList.push_back(f);
|
||||
|
|
@ -418,6 +421,7 @@ void ConsoleObject::addArray( const char *arrayName, S32 count )
|
|||
f.setDataFn = &defaultProtectedSetFn;
|
||||
f.getDataFn = &defaultProtectedGetFn;
|
||||
f.writeDataFn = &defaultProtectedWriteFn;
|
||||
f.networkMask = 0;
|
||||
|
||||
// Add to field list.
|
||||
sg_tempFieldList.push_back(f);
|
||||
|
|
@ -439,6 +443,7 @@ void ConsoleObject::endArray( const char *arrayName )
|
|||
f.getDataFn = &defaultProtectedGetFn;
|
||||
f.writeDataFn = &defaultProtectedWriteFn;
|
||||
f.elementCount = 0;
|
||||
f.networkMask = 0;
|
||||
|
||||
// Add to field list.
|
||||
sg_tempFieldList.push_back(f);
|
||||
|
|
@ -515,6 +520,7 @@ void ConsoleObject::addField(const char* in_pFieldname,
|
|||
f.setDataFn = &defaultProtectedSetFn;
|
||||
f.getDataFn = &defaultProtectedGetFn;
|
||||
f.writeDataFn = in_writeDataFn;
|
||||
f.networkMask = 0;
|
||||
|
||||
ConsoleBaseType* conType = ConsoleBaseType::getType(in_fieldType);
|
||||
AssertFatal(conType, "ConsoleObject::addField - invalid console type");
|
||||
|
|
@ -609,6 +615,7 @@ void ConsoleObject::addProtectedField(const char* in_pFieldname,
|
|||
f.setDataFn = in_setDataFn;
|
||||
f.getDataFn = in_getDataFn;
|
||||
f.writeDataFn = in_writeDataFn;
|
||||
f.networkMask = 0;
|
||||
|
||||
ConsoleBaseType* conType = ConsoleBaseType::getType(in_fieldType);
|
||||
AssertFatal(conType, "ConsoleObject::addProtectedField - invalid console type");
|
||||
|
|
@ -635,6 +642,7 @@ void ConsoleObject::addFieldV(const char* in_pFieldname,
|
|||
f.getDataFn = &defaultProtectedGetFn;
|
||||
f.writeDataFn = &defaultProtectedWriteFn;
|
||||
f.validator = v;
|
||||
f.networkMask = 0;
|
||||
v->fieldIndex = sg_tempFieldList.size();
|
||||
|
||||
sg_tempFieldList.push_back(f);
|
||||
|
|
@ -652,11 +660,12 @@ void ConsoleObject::addDeprecatedField(const char *fieldName)
|
|||
f.setDataFn = &defaultProtectedSetFn;
|
||||
f.getDataFn = &defaultProtectedGetFn;
|
||||
f.writeDataFn = &defaultProtectedWriteFn;
|
||||
f.networkMask = 0;
|
||||
|
||||
sg_tempFieldList.push_back(f);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------
|
||||
bool ConsoleObject::removeField(const char* in_pFieldname)
|
||||
{
|
||||
for (U32 i = 0; i < sg_tempFieldList.size(); i++) {
|
||||
|
|
|
|||
|
|
@ -495,7 +495,8 @@ public:
|
|||
table( NULL ),
|
||||
validator( NULL ),
|
||||
setDataFn( NULL ),
|
||||
getDataFn( NULL )
|
||||
getDataFn( NULL ),
|
||||
networkMask(0)
|
||||
{
|
||||
doNotSubstitute = keepClearSubsOnly = false;
|
||||
}
|
||||
|
|
@ -518,6 +519,7 @@ public:
|
|||
bool doNotSubstitute;
|
||||
bool keepClearSubsOnly;
|
||||
WriteDataNotify writeDataFn; ///< Function to determine whether data should be written or not.
|
||||
U32 networkMask;
|
||||
};
|
||||
typedef Vector<Field> FieldList;
|
||||
|
||||
|
|
|
|||
|
|
@ -41,6 +41,8 @@
|
|||
#include "core/fileObject.h"
|
||||
#include "persistence/taml/tamlCustom.h"
|
||||
|
||||
#include "sim/netObject.h"
|
||||
|
||||
IMPLEMENT_CONOBJECT( SimObject );
|
||||
|
||||
// See full description in the new CHM manual
|
||||
|
|
@ -912,6 +914,12 @@ void SimObject::assignFieldsFrom(SimObject *parent)
|
|||
|
||||
if((*f->setDataFn)( this, NULL, bufferSecure ) )
|
||||
Con::setData(f->type, (void *) (((const char *)this) + f->offset), j, 1, &fieldVal, f->table);
|
||||
|
||||
if (f->networkMask != 0)
|
||||
{
|
||||
NetObject* netObj = static_cast<NetObject*>(this);
|
||||
netObj->setMaskBits(f->networkMask);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -988,6 +996,12 @@ void SimObject::setDataField(StringTableEntry slotName, const char *array, const
|
|||
if(fld->validator)
|
||||
fld->validator->validateType(this, (void *) (((const char *)this) + fld->offset));
|
||||
|
||||
if (fld->networkMask != 0)
|
||||
{
|
||||
NetObject* netObj = static_cast<NetObject*>(this);
|
||||
netObj->setMaskBits(fld->networkMask);
|
||||
}
|
||||
|
||||
onStaticModified( slotName, value );
|
||||
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue