ent_boneparent behavior

Posted By: txesmi

ent_boneparent behavior - 04/28/14 10:39

Hello,
I have been playing with 'ent_bonehandle' and 'ent_boneparent' and as far I undertand when any of both functions are called with a NULL bone handle it returns the bone handle of the bone name the string contains.

'ent_bonehandle' works good as far as the bone name continues been the same but 'ent_boneparent' also overwrites the bone name contained in the string. I guess it should not overwrite the bone name string when called with a null bone handle in order to mantain the source string as it is.

The code I used to test the instructions functionality
Code:
#include <acknex.h>

void main ()
{
	int bone_index = 0, parent_index = 0, child_index = 0;
	video_mode = 12;
	wait(2);
	level_load ( "" );
	FONT *fnt10 = font_create ( "Arial#12" );
	ENTITY *entBones = ent_create ( "biped.mdl", nullvector, NULL );
	int numBones = ent_bones ( entBones );
	int step = screen_size.x / numBones;
	
	//----------------------------------------------------------------------------------------
	
	TEXT **txtBones = sys_malloc ( sizeof(TEXT*) * numBones );
	for ( bone_index=0; bone_index<numBones; bone_index+=1 )
	{
		txtBones[bone_index] = txt_create ( numBones, 1 );
		txtBones[bone_index]->pos_x = bone_index * step;
		txtBones[bone_index]->font = fnt10;
		txtBones[bone_index]->flags = SHOW;
	}
	
	for ( bone_index=0; bone_index<numBones; bone_index+=1 )
		ent_bonehandle ( entBones, (txtBones[bone_index]->pstring)[0], bone_index+1 );
	
	for ( bone_index=0; bone_index<numBones; bone_index+=1 )
	{
		int parent_index = 1;
		long handle = ent_boneparent ( entBones, (txtBones[bone_index]->pstring)[parent_index], bone_index+1 );
		while ( handle )
		{
			parent_index += 1;
			handle = ent_boneparent ( entBones, (txtBones[bone_index]->pstring)[parent_index], (var)handle );
		}
	}
	
	//----------------------------------------------------------------------------------------
	
	TEXT **txtBones2 = sys_malloc ( sizeof(TEXT*) * numBones );
	for ( bone_index=0; bone_index<numBones; bone_index+=1 )
	{
		txtBones2[bone_index] = txt_create ( numBones, 1 );
		txtBones2[bone_index]->pos_x = bone_index * step;
		txtBones2[bone_index]->pos_y = 250;
		txtBones2[bone_index]->font = fnt10;
		txtBones2[bone_index]->flags = SHOW;
	}
	
	for ( bone_index=0; bone_index<numBones; bone_index+=1 )
		ent_bonehandle ( entBones, (txtBones2[bone_index]->pstring)[0], bone_index+1 );
	
	for ( bone_index=0; bone_index<numBones; bone_index+=1 )
	{
		child_index = 0;
		long handle = ent_boneparent ( entBones, (txtBones2[bone_index]->pstring)[child_index], 0 );
		while ( handle )
		{
			child_index += 1;
			ent_bonehandle ( entBones, (txtBones2[bone_index]->pstring)[child_index], (var)handle );
			handle = ent_boneparent ( entBones, (txtBones2[bone_index]->pstring)[child_index], 0 );
		}
	}
	
	//----------------------------------------------------------------------------------------
	
	while ( !key_esc )
		wait(1);
	
	sys_exit ( NULL );
}



The model: https://app.box.com/s/tozj882s0qvlztcp19tm

Is this a desired behavior?

Thanks in advance,
txes
Posted By: oliver2s

Re: ent_boneparent behavior - 04/28/14 11:48

This is not a bug. It's desired behavior and works very well. From the manual:

Quote:
If name and index are both given, index is used to find the bone and name is set to the name of the bone resp. of the parent bone.
Posted By: txesmi

Re: ent_boneparent behavior - 04/28/14 12:08

Hi,
I tryed to explain that the case I was speaking about is the case where the name and index are both not given. Just the bone name contained in the string and a NULL handle (The second part of the code).

I based my speculations on the example into the manual:

Originally Posted By: manual - ent_bonehandle

// get the name of the parent bone when a child name is given.
STRING* child_name = "foot_left";
long handle = ent_setboneparent(ent,child_name,0); // return a handle to the parent bone
ent_setbonehandle(ent,parent_name,(var)handle); // retrieve the parant name from the parent handle.

Ignore the instructions names in the example. They are also wrong in the manual...

This example retrieves the parent bone name after retrieving the parent bone handle, but with the actual 'ent_boneparent' behavior 'child_name' has been already overwritten with the parent bone name so there is no need of retrieving the parent bone name in the las instruction. That is why I thougth it is a bug.

Salud!
Posted By: oliver2s

Re: ent_boneparent behavior - 04/28/14 12:54

Now I understand. It seems this is really a bug.
Posted By: jcl

Re: ent_boneparent behavior - 04/28/14 14:06

Yes, I have to agree. We'll look into that.
Posted By: txesmi

Re: ent_boneparent behavior - 04/28/14 22:22

Thanks for your attention.
Cheers!
© 2024 lite-C Forums