Skip to content

Commit 0dd7254

Browse files
committed
Fixed level.remove_call
Removed dead code
1 parent dde9380 commit 0dd7254

File tree

4 files changed

+26
-103
lines changed

4 files changed

+26
-103
lines changed

src/xrGame/PHCommander.cpp

Lines changed: 19 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
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(); }
2321
void 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

6353
void 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); }
124114
struct 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-
158143
PHCALL_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

163148
bool 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-
173153
void 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+
193170
struct 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-
}
213186
void 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+
240198
void CPHCommander::phys_shell_relcase(CPhysicsShell* sh)
241199
{
242200
CPHReqComparerHasShell c(sh);

src/xrGame/PHCommander.h

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,6 @@ class CPHCommander : public IPHWorldUpdateCallbck
7373
{
7474
Lock lock;
7575
PHCALL_STORAGE m_calls;
76-
PHCALL_STORAGE m_calls_as_add_buffer;
77-
PHCALL_STORAGE m_calls_as_remove_buffer;
7876

7977
public:
8078
~CPHCommander();
@@ -94,30 +92,9 @@ class CPHCommander : public IPHWorldUpdateCallbck
9492

9593
void update();
9694
void update_threadsafety();
97-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
98-
void add_call_unique_as(
99-
CPHCondition* condition, CPHReqComparerV* cmp_condition, CPHAction* action, CPHReqComparerV* cmp_action);
100-
void add_call_as(CPHCondition* condition, CPHAction* action);
101-
102-
void remove_call_as(PHCALL_I i);
103-
PHCALL_I find_call_as(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action);
104-
void remove_call_as(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action);
105-
void remove_calls_as(CPHReqComparerV* cmp_object);
106-
107-
void update_as();
108-
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
95+
10996
void clear();
11097

111-
private:
112-
IC bool add_call_unique(CPHCondition* condition, CPHReqComparerV* cmp_condition, CPHAction* action,
113-
CPHReqComparerV* cmp_action, PHCALL_STORAGE& cs);
114-
IC void add_call(CPHCondition* condition, CPHAction* action, PHCALL_STORAGE& cs);
115-
116-
IC void remove_call(PHCALL_I i, PHCALL_STORAGE& cs);
117-
IC PHCALL_I find_call(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action, PHCALL_STORAGE& cs);
118-
IC void remove_call(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action, PHCALL_STORAGE& cs);
119-
IC void remove_calls(CPHReqComparerV* cmp_object, PHCALL_STORAGE& cs);
120-
12198
private:
12299
virtual void update_step() { update_threadsafety(); }
123100
virtual void phys_shell_relcase(CPhysicsShell* sh);

src/xrGame/PHScriptCall.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
#include "script_callback_ex.h"
77
#include "xrEngine/xr_object.h"
88

9-
// template<>
10-
// IC bool compare_safe(const functor<>& f1,const functor<>& f2)
11-
//{
12-
// f1.typ
13-
//}
14-
159
class CPHScriptCondition : public CPHCondition, public CPHReqComparerV
1610
{
1711
luabind::functor<bool>* m_lua_function;
@@ -24,10 +18,12 @@ class CPHScriptCondition : public CPHCondition, public CPHReqComparerV
2418
virtual bool is_true();
2519
virtual bool obsolete() const;
2620
virtual bool compare(const CPHReqComparerV* v) const { return v->compare(this); }
27-
// XXX: compare values instead of pointers?
28-
virtual bool compare(const CPHScriptCondition* v) const { return v->m_lua_function == m_lua_function; }
29-
/// virtual bool is_equal (CPHReqBase* v) ;
30-
// virtual bool is_relative (CPHReqBase* v) ;
21+
virtual bool compare(const CPHScriptCondition* v) const
22+
{
23+
const auto& lhs = static_cast<const luabind::adl::object&>(*m_lua_function);
24+
const auto& rhs = static_cast<const luabind::adl::object&>(*v->m_lua_function);
25+
return lhs == rhs;
26+
}
3127
};
3228

3329
class CPHScriptAction : public CPHAction, public CPHReqComparerV

src/xrGame/level_script.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,19 +304,11 @@ void remove_call(const luabind::functor<bool>& condition, const luabind::functor
304304

305305
void add_call(const luabind::object& lua_object, LPCSTR condition, LPCSTR action)
306306
{
307-
// try{
308-
// CPHScriptObjectCondition *c=new CPHScriptObjectCondition(lua_object,condition);
309-
// CPHScriptObjectAction *a=new CPHScriptObjectAction(lua_object,action);
310307
luabind::functor<bool> _condition = object_cast<luabind::functor<bool>>(lua_object[condition]);
311308
luabind::functor<void> _action = object_cast<luabind::functor<void>>(lua_object[action]);
312309
CPHScriptObjectConditionN* c = new CPHScriptObjectConditionN(lua_object, _condition);
313310
CPHScriptObjectActionN* a = new CPHScriptObjectActionN(lua_object, _action);
314311
Level().ph_commander_scripts().add_call_unique(c, c, a, a);
315-
// }
316-
// catch(...)
317-
// {
318-
// Msg("add_call excepted!!");
319-
// }
320312
}
321313

322314
void remove_call(const luabind::object& lua_object, LPCSTR condition, LPCSTR action)

0 commit comments

Comments
 (0)