Talk:Node Name (RW Section)

From GTAMods Wiki
Revision as of 17:43, 29 October 2010 by Aschratt (talk | contribs) (moved Talk:Frame (RW Section) to Talk:Node Name (RW Section): Usage of internal name (see discussion page))
Jump to navigation Jump to search

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;
}

--ModelingMan 22:26, 13 March 2009 (UTC)