-
Notifications
You must be signed in to change notification settings - Fork 4
/
environment.cpp
121 lines (110 loc) · 3.02 KB
/
environment.cpp
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "environment.h"
CEnvironment* CEnvironment::currentEnvironment=nullptr;
int CEnvironment::_nextHandle=0;
std::vector<CEnvironment*> CEnvironment::_allEnvironments;
CEnvironment::CEnvironment()
{
objectContainer=nullptr;
ikGroupContainer=nullptr;
_flags=0;
}
CEnvironment::CEnvironment(int flags)
{
objectContainer=new CObjectContainer();
ikGroupContainer=new CIkGroupContainer();
_flags=flags;
}
CEnvironment::~CEnvironment()
{
ikGroupContainer->removeAllIkGroups();
objectContainer->removeAllObjects();
delete ikGroupContainer;
delete objectContainer;
}
int CEnvironment::getHandle() const
{
return(_handle);
}
int CEnvironment::getFlags() const
{
return(_flags);
}
void CEnvironment::setFlags(int f)
{
_flags=f;
}
CEnvironment* CEnvironment::copyYourself() const
{
CEnvironment* duplicate=new CEnvironment();
duplicate->ikGroupContainer=ikGroupContainer->copyYourself();
duplicate->objectContainer=objectContainer->copyYourself();
duplicate->_flags=_flags;
return(duplicate);
}
int CEnvironment::addEnvironment(CEnvironment* env)
{
currentEnvironment=env;
_allEnvironments.push_back(env);
currentEnvironment->_handle=_nextHandle;
_nextHandle++;
return(currentEnvironment->_handle);
}
bool CEnvironment::switchToEnvironment(int handle,bool alsoProtectedEnv)
{
bool retVal=false;
if (handle==-1)
{ // tries to switch to the first protected environment, for debug purposes
for (size_t i=0;i<_allEnvironments.size();i++)
{
if ((_allEnvironments[i]->_flags&1)!=0)
{
currentEnvironment=_allEnvironments[i];
return(true);
}
}
}
else
{
if ( (handle>=0)&&(currentEnvironment!=nullptr) )
{
if (currentEnvironment->_handle!=handle)
{
for (size_t i=0;i<_allEnvironments.size();i++)
{
if (_allEnvironments[i]->_handle==handle)
{
if ( alsoProtectedEnv||((_allEnvironments[i]->_flags&1)==0) )
{
currentEnvironment=_allEnvironments[i];
return(true);
}
}
}
return(false);
}
retVal=(alsoProtectedEnv||((currentEnvironment->_flags&1)==0));
}
}
return(retVal);
}
int CEnvironment::killEnvironment(int handle)
{
int retVal=-1;
for (size_t i=0;i<_allEnvironments.size();i++)
{
if (_allEnvironments[i]->_handle==handle)
{
delete currentEnvironment;
_allEnvironments.erase(_allEnvironments.begin()+i);
if (_allEnvironments.size()>0)
{
currentEnvironment=_allEnvironments[0];
retVal=currentEnvironment->_handle;
}
else
currentEnvironment=nullptr;
break;
}
}
return(retVal);
}