11#include " stdafx.h"
22#include " PHCommander.h"
3-
43#include " phsimplecalls.h"
5- #ifdef DEBUG
64
7- // extern CPHWorld *ph_world;
5+ # ifdef DEBUG
86#include " xrPhysics/IPHWorld.h"
97#endif
108
@@ -19,7 +17,7 @@ CPHCall::~CPHCall()
1917 xr_delete (m_action);
2018 xr_delete (m_condition);
2119}
22- bool CPHCall::obsolete () { return m_action->obsolete () || m_condition->obsolete (); }
20+ bool CPHCall::obsolete () { return ! m_action || m_action ->obsolete () || !m_condition || m_condition->obsolete (); }
2321void CPHCall::check ()
2422{
2523 if (m_condition && m_condition->is_true () && m_action)
@@ -50,14 +48,6 @@ void CPHCommander::clear()
5048 {
5149 remove_call (m_calls.end () - 1 );
5250 }
53- while (m_calls_as_add_buffer.size ())
54- {
55- remove_call (m_calls_as_add_buffer.end () - 1 );
56- }
57- while (m_calls_as_remove_buffer.size ())
58- {
59- remove_call (m_calls_as_remove_buffer.end () - 1 );
60- }
6151}
6252
6353void CPHCommander::update ()
@@ -96,12 +86,13 @@ void CPHCommander::add_call_threadsafety(CPHCondition* condition, CPHAction* act
9686 add_call (condition, action);
9787 lock.Leave ();
9888}
99- void CPHCommander::add_call (CPHCondition* condition, CPHAction* action, PHCALL_STORAGE& cs)
89+
90+ void CPHCommander::add_call (CPHCondition* condition, CPHAction* action)
10091{
101- cs .push_back (new CPHCall (condition, action));
92+ m_calls .push_back (new CPHCall (condition, action));
10293}
103- void CPHCommander::add_call (CPHCondition* condition, CPHAction* action) { add_call (condition, action, m_calls); }
104- void CPHCommander::remove_call (PHCALL_I i, PHCALL_STORAGE& cs )
94+
95+ void CPHCommander::remove_call (PHCALL_I i)
10596{
10697#ifdef DEBUG
10798 const CPHCallOnStepCondition* esc = smart_cast<const CPHCallOnStepCondition*>((*i)->condition ());
@@ -117,10 +108,9 @@ void CPHCommander::remove_call(PHCALL_I i, PHCALL_STORAGE& cs)
117108 }
118109#endif
119110 delete_call (*i);
120- cs .erase (i);
111+ m_calls .erase (i);
121112}
122113
123- void CPHCommander::remove_call (PHCALL_I i) { remove_call (i, m_calls); }
124114struct SFEqualPred
125115{
126116 CPHReqComparerV *cmp_condition, *cmp_action;
@@ -150,46 +140,33 @@ struct SFRemovePred2
150140 }
151141};
152142
153- PHCALL_I CPHCommander::find_call (CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action, PHCALL_STORAGE& cs)
154- {
155- return std::find_if (cs.begin (), cs.end (), SFEqualPred (cmp_condition, cmp_action));
156- }
157-
158143PHCALL_I CPHCommander::find_call (CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action)
159144{
160- return find_call (cmp_condition, cmp_action, m_calls );
145+ return std::find_if (m_calls. begin (), m_calls. end (), SFEqualPred (cmp_condition, cmp_action) );
161146}
162147
163148bool CPHCommander::has_call (CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action)
164149{
165150 return find_call (cmp_condition, cmp_action) != m_calls.end ();
166151}
167152
168- void CPHCommander::remove_call (CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action, PHCALL_STORAGE& cs)
169- {
170- cs.erase (std::remove_if (cs.begin (), cs.end (), SFRemovePred2 (cmp_condition, cmp_action)), cs.end ());
171- }
172-
173153void CPHCommander::remove_call (CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action)
174154{
175- remove_call (cmp_condition, cmp_action, m_calls);
155+ m_calls.erase (
156+ std::remove_if (m_calls.begin (), m_calls.end (), SFRemovePred2 (cmp_condition, cmp_action)), m_calls.end ());
176157}
177158
178- bool CPHCommander::add_call_unique (CPHCondition* condition, CPHReqComparerV* cmp_condition, CPHAction* action,
179- CPHReqComparerV* cmp_action, PHCALL_STORAGE& cs )
159+ bool CPHCommander::add_call_unique (
160+ CPHCondition* condition, CPHReqComparerV* cmp_condition, CPHAction* action, CPHReqComparerV* cmp_action )
180161{
181- if (cs .end () == find_call (cmp_condition, cmp_action, cs ))
162+ if (m_calls .end () == find_call (cmp_condition, cmp_action))
182163 {
183- add_call (condition, action, cs );
164+ add_call (condition, action);
184165 return true ;
185166 }
186167 return false ;
187168}
188- bool CPHCommander::add_call_unique (
189- CPHCondition* condition, CPHReqComparerV* cmp_condition, CPHAction* action, CPHReqComparerV* cmp_action)
190- {
191- return add_call_unique (condition, cmp_condition, action, cmp_action, m_calls);
192- }
169+
193170struct SRemoveRped
194171{
195172 CPHReqComparerV* cmp_object;
@@ -206,37 +183,18 @@ struct SRemoveRped
206183 }
207184};
208185
209- void CPHCommander::remove_calls (CPHReqComparerV* cmp_object, PHCALL_STORAGE& cs)
210- {
211- cs.erase (std::remove_if (cs.begin (), cs.end (), SRemoveRped (cmp_object)), cs.end ());
212- }
213186void CPHCommander::remove_calls_threadsafety (CPHReqComparerV* cmp_object)
214187{
215188 lock.Enter ();
216189 remove_calls (cmp_object);
217190 lock.Leave ();
218191}
219- void CPHCommander::remove_calls (CPHReqComparerV* cmp_object) { remove_calls (cmp_object, m_calls); }
220- void CPHCommander::add_call_unique_as (
221- CPHCondition* condition, CPHReqComparerV* cmp_condition, CPHAction* action, CPHReqComparerV* cmp_action)
222- {
223- add_call_unique (condition, cmp_condition, action, cmp_action, m_calls_as_add_buffer);
224- }
225- void CPHCommander::add_call_as (CPHCondition* condition, CPHAction* action)
226- {
227- add_call (condition, action, m_calls_as_add_buffer);
228- }
229192
230- PHCALL_I CPHCommander::find_call_as (CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action)
231- {
232- return find_call (cmp_condition, cmp_action, m_calls);
233- }
234- void CPHCommander::remove_call_as (CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action)
193+ void CPHCommander::remove_calls (CPHReqComparerV* cmp_object)
235194{
236- remove_call (cmp_condition, cmp_action, m_calls_as_add_buffer );
195+ m_calls. erase ( std::remove_if (m_calls. begin (), m_calls. end (), SRemoveRped (cmp_object)), m_calls. end () );
237196}
238- void CPHCommander::remove_calls_as (CPHReqComparerV* cmp_object) {}
239- void CPHCommander::update_as () {}
197+
240198void CPHCommander::phys_shell_relcase (CPhysicsShell* sh)
241199{
242200 CPHReqComparerHasShell c (sh);
0 commit comments