Talk:Node Name (RW Section)
Revision as of 22:26, 13 March 2009 by ModelingMan (talk | contribs) (New page: ==NodeName== Frame is kind of the wrong name to use for this section, it's a bit misleading. It makes it sound like Frame is a Rockstar plugin when infact RwFrame is a core object. Rocksta...)
NodeName
Frame is kind of the wrong name to use for this section, it's a bit misleading. It makes it sound like Frame is a Rockstar plugin when infact RwFrame is a core object. Rockstar's name for this section is NodeName, which can be seen internally.
Below is code which functions like Rockstar's NodeName plugin. (C/C++)
struct NodeNameData { char frameName[24]; }; #define VENDOR_ROCKSTAR 0x253F2 #define OBJECT_NODENAME 0xFE /* Macro to easily retrieve the NodeName data from a RwFrame object. */ #define NODENAMEDATA(_object) \ ((NodeNameData *)((RwUInt8 *)(_object) + (NodeNameDataOffset))) /* Offset to NodeName plugin data. */ RwInt32 NodeNameDataOffset; /***************** Data Functions ******************/ void *NodeNameConstructor(void *object, RwInt32, RwInt32) { if ( NodeNameDataOffset > 0 ) { NODENAMEDATA(object)->frameName[0] = '\0'; } return object; } void *NodeNameDestructor(void *object, RwInt32, RwInt32) { return object; } void *NodeNameCopy(void *dstObject, const void *srcObject, RwInt32, RwInt32) { NodeNameData *dstData = NODENAMEDATA(dstObject); const NodeNameData *srcData = NODENAMEDATA(srcObject); strncpy(dstData->frameName, srcData->frameName, sizeof(NodeNameData)-1); return dstObject; } /**************** Stream Functions *****************/ RwStream *NodeNameStreamRead(RwStream *stream, RwInt32 binaryLength, void *object, RwInt32, RwInt32) { NodeNameData *data = NODENAMEDATA(object); RwStreamRead(stream, data->frameName, binaryLength); data->frameName[binaryLength] = '\0'; return stream; } RwStream *NodeNameStreamWrite(RwStream *stream, RwInt32 binaryLength, const void *object, RwInt32, RwInt32) { const NodeNameData *data = NODENAMEDATA(object); RwStreamWrite(stream, data->frameName, binaryLength); return stream; } RwInt32 NodeNameStreamGetSize(const void *object, RwInt32, RwInt32) { const NodeNameData *data = NODENAMEDATA(object); if ( data ) { return (RwInt32)strlen(data->frameName); } return 0; } /**************** Attach Function ******************/ RwBool NodeNamePluginAttach() { NodeNameDataOffset = RwFrameRegisterPlugin(sizeof(NodeNameData), MAKECHUNKID(VENDOR_ROCKSTAR, OBJECT_NODENAME), NodeNameConstructor, NodeNameDestructor, NodeNameCopy); RwFrameRegisterPluginStream(MAKECHUNKID(VENDOR_ROCKSTAR, OBJECT_NODENAME), NodeNameStreamRead, NodeNameStreamWrite, NodeNameStreamGetSize); return (RwBool)( NodeNameDataOffset != -1 ); } /***************************************************/ char *NodeNameGetFrameNodeName(RwFrame *frame) { char *result = NODENAMEDATA(frame)->frameName; if ( NodeNameDataOffset > 0 && frame ) return result; return NULL; }