/
ancestor.cc
82 lines (63 loc) · 1.5 KB
/
ancestor.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "stage.hh"
using namespace Stg;
//using names
Ancestor::Ancestor() :
children(),
debug( false ),
token( NULL )
{
for( int i=0; i<MODEL_TYPE_COUNT; i++ )
child_type_counts[i] = 0;
}
Ancestor::~Ancestor()
{
FOR_EACH( it, children )
delete (*it);
}
void Ancestor::AddChild( Model* mod )
{
// poke a name into the child
char* buf = new char[TOKEN_MAX];
// printf( "adding child of type %d token %s\n", mod->type, mod->Token() );
std::string typestr = Model::type_map[ mod->type ];
if( token ) // if this object has a name, use it
snprintf( buf, TOKEN_MAX, "%s.%s:%d",
token,
typestr.c_str(),
child_type_counts[mod->type] );
else
snprintf( buf, TOKEN_MAX, "%s:%d",
typestr.c_str(),
child_type_counts[mod->type] );
//printf( "%s generated a name for my child %s\n", token, buf );
mod->SetToken( buf );
children.push_back( mod );
child_type_counts[mod->type]++;
delete[] buf;
}
void Ancestor::RemoveChild( Model* mod )
{
child_type_counts[mod->type]--;
children.erase( std::remove( children.begin(), children.end(), mod ) );
}
Pose Ancestor::GetGlobalPose()
{
Pose pose;
bzero( &pose, sizeof(pose));
return pose;
}
void Ancestor::ForEachDescendant( stg_model_callback_t func, void* arg )
{
FOR_EACH( it, children )
{
Model* mod = (*it);
func( mod, arg );
mod->ForEachDescendant( func, arg );
}
}
void Ancestor::Load( Worldfile* wf, int section )
{
}
void Ancestor::Save( Worldfile* wf, int section )
{
}