Skip to content

Commit

Permalink
Fixed level.remove_call
Browse files Browse the repository at this point in the history
Removed dead code
  • Loading branch information
qweasdd136963 committed Sep 26, 2018
1 parent dde9380 commit 0dd7254
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 103 deletions.
80 changes: 19 additions & 61 deletions src/xrGame/PHCommander.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include "stdafx.h"
#include "PHCommander.h"

#include "phsimplecalls.h"
#ifdef DEBUG

// extern CPHWorld *ph_world;
#ifdef DEBUG
#include "xrPhysics/IPHWorld.h"
#endif

Expand All @@ -19,7 +17,7 @@ CPHCall::~CPHCall()
xr_delete(m_action);
xr_delete(m_condition);
}
bool CPHCall::obsolete() { return m_action->obsolete() || m_condition->obsolete(); }
bool CPHCall::obsolete() { return !m_action || m_action->obsolete() || !m_condition || m_condition->obsolete(); }
void CPHCall::check()
{
if (m_condition && m_condition->is_true() && m_action)
Expand Down Expand Up @@ -50,14 +48,6 @@ void CPHCommander::clear()
{
remove_call(m_calls.end() - 1);
}
while (m_calls_as_add_buffer.size())
{
remove_call(m_calls_as_add_buffer.end() - 1);
}
while (m_calls_as_remove_buffer.size())
{
remove_call(m_calls_as_remove_buffer.end() - 1);
}
}

void CPHCommander::update()
Expand Down Expand Up @@ -96,12 +86,13 @@ void CPHCommander::add_call_threadsafety(CPHCondition* condition, CPHAction* act
add_call(condition, action);
lock.Leave();
}
void CPHCommander::add_call(CPHCondition* condition, CPHAction* action, PHCALL_STORAGE& cs)

void CPHCommander::add_call(CPHCondition* condition, CPHAction* action)
{
cs.push_back(new CPHCall(condition, action));
m_calls.push_back(new CPHCall(condition, action));
}
void CPHCommander::add_call(CPHCondition* condition, CPHAction* action) { add_call(condition, action, m_calls); }
void CPHCommander::remove_call(PHCALL_I i, PHCALL_STORAGE& cs)

void CPHCommander::remove_call(PHCALL_I i)
{
#ifdef DEBUG
const CPHCallOnStepCondition* esc = smart_cast<const CPHCallOnStepCondition*>((*i)->condition());
Expand All @@ -117,10 +108,9 @@ void CPHCommander::remove_call(PHCALL_I i, PHCALL_STORAGE& cs)
}
#endif
delete_call(*i);
cs.erase(i);
m_calls.erase(i);
}

void CPHCommander::remove_call(PHCALL_I i) { remove_call(i, m_calls); }
struct SFEqualPred
{
CPHReqComparerV *cmp_condition, *cmp_action;
Expand Down Expand Up @@ -150,46 +140,33 @@ struct SFRemovePred2
}
};

PHCALL_I CPHCommander::find_call(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action, PHCALL_STORAGE& cs)
{
return std::find_if(cs.begin(), cs.end(), SFEqualPred(cmp_condition, cmp_action));
}

PHCALL_I CPHCommander::find_call(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action)
{
return find_call(cmp_condition, cmp_action, m_calls);
return std::find_if(m_calls.begin(), m_calls.end(), SFEqualPred(cmp_condition, cmp_action));
}

bool CPHCommander::has_call(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action)
{
return find_call(cmp_condition, cmp_action) != m_calls.end();
}

void CPHCommander::remove_call(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action, PHCALL_STORAGE& cs)
{
cs.erase(std::remove_if(cs.begin(), cs.end(), SFRemovePred2(cmp_condition, cmp_action)), cs.end());
}

void CPHCommander::remove_call(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action)
{
remove_call(cmp_condition, cmp_action, m_calls);
m_calls.erase(
std::remove_if(m_calls.begin(), m_calls.end(), SFRemovePred2(cmp_condition, cmp_action)), m_calls.end());
}

bool CPHCommander::add_call_unique(CPHCondition* condition, CPHReqComparerV* cmp_condition, CPHAction* action,
CPHReqComparerV* cmp_action, PHCALL_STORAGE& cs)
bool CPHCommander::add_call_unique(
CPHCondition* condition, CPHReqComparerV* cmp_condition, CPHAction* action, CPHReqComparerV* cmp_action)
{
if (cs.end() == find_call(cmp_condition, cmp_action, cs))
if (m_calls.end() == find_call(cmp_condition, cmp_action))
{
add_call(condition, action, cs);
add_call(condition, action);
return true;
}
return false;
}
bool CPHCommander::add_call_unique(
CPHCondition* condition, CPHReqComparerV* cmp_condition, CPHAction* action, CPHReqComparerV* cmp_action)
{
return add_call_unique(condition, cmp_condition, action, cmp_action, m_calls);
}

struct SRemoveRped
{
CPHReqComparerV* cmp_object;
Expand All @@ -206,37 +183,18 @@ struct SRemoveRped
}
};

void CPHCommander::remove_calls(CPHReqComparerV* cmp_object, PHCALL_STORAGE& cs)
{
cs.erase(std::remove_if(cs.begin(), cs.end(), SRemoveRped(cmp_object)), cs.end());
}
void CPHCommander::remove_calls_threadsafety(CPHReqComparerV* cmp_object)
{
lock.Enter();
remove_calls(cmp_object);
lock.Leave();
}
void CPHCommander::remove_calls(CPHReqComparerV* cmp_object) { remove_calls(cmp_object, m_calls); }
void CPHCommander::add_call_unique_as(
CPHCondition* condition, CPHReqComparerV* cmp_condition, CPHAction* action, CPHReqComparerV* cmp_action)
{
add_call_unique(condition, cmp_condition, action, cmp_action, m_calls_as_add_buffer);
}
void CPHCommander::add_call_as(CPHCondition* condition, CPHAction* action)
{
add_call(condition, action, m_calls_as_add_buffer);
}

PHCALL_I CPHCommander::find_call_as(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action)
{
return find_call(cmp_condition, cmp_action, m_calls);
}
void CPHCommander::remove_call_as(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action)
void CPHCommander::remove_calls(CPHReqComparerV* cmp_object)
{
remove_call(cmp_condition, cmp_action, m_calls_as_add_buffer);
m_calls.erase(std::remove_if(m_calls.begin(), m_calls.end(), SRemoveRped(cmp_object)), m_calls.end());
}
void CPHCommander::remove_calls_as(CPHReqComparerV* cmp_object) {}
void CPHCommander::update_as() {}

void CPHCommander::phys_shell_relcase(CPhysicsShell* sh)
{
CPHReqComparerHasShell c(sh);
Expand Down
25 changes: 1 addition & 24 deletions src/xrGame/PHCommander.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ class CPHCommander : public IPHWorldUpdateCallbck
{
Lock lock;
PHCALL_STORAGE m_calls;
PHCALL_STORAGE m_calls_as_add_buffer;
PHCALL_STORAGE m_calls_as_remove_buffer;

public:
~CPHCommander();
Expand All @@ -94,30 +92,9 @@ class CPHCommander : public IPHWorldUpdateCallbck

void update();
void update_threadsafety();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void add_call_unique_as(
CPHCondition* condition, CPHReqComparerV* cmp_condition, CPHAction* action, CPHReqComparerV* cmp_action);
void add_call_as(CPHCondition* condition, CPHAction* action);

void remove_call_as(PHCALL_I i);
PHCALL_I find_call_as(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action);
void remove_call_as(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action);
void remove_calls_as(CPHReqComparerV* cmp_object);

void update_as();
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void clear();

private:
IC bool add_call_unique(CPHCondition* condition, CPHReqComparerV* cmp_condition, CPHAction* action,
CPHReqComparerV* cmp_action, PHCALL_STORAGE& cs);
IC void add_call(CPHCondition* condition, CPHAction* action, PHCALL_STORAGE& cs);

IC void remove_call(PHCALL_I i, PHCALL_STORAGE& cs);
IC PHCALL_I find_call(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action, PHCALL_STORAGE& cs);
IC void remove_call(CPHReqComparerV* cmp_condition, CPHReqComparerV* cmp_action, PHCALL_STORAGE& cs);
IC void remove_calls(CPHReqComparerV* cmp_object, PHCALL_STORAGE& cs);

private:
virtual void update_step() { update_threadsafety(); }
virtual void phys_shell_relcase(CPhysicsShell* sh);
Expand Down
16 changes: 6 additions & 10 deletions src/xrGame/PHScriptCall.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
#include "script_callback_ex.h"
#include "xrEngine/xr_object.h"

// template<>
// IC bool compare_safe(const functor<>& f1,const functor<>& f2)
//{
// f1.typ
//}

class CPHScriptCondition : public CPHCondition, public CPHReqComparerV
{
luabind::functor<bool>* m_lua_function;
Expand All @@ -24,10 +18,12 @@ class CPHScriptCondition : public CPHCondition, public CPHReqComparerV
virtual bool is_true();
virtual bool obsolete() const;
virtual bool compare(const CPHReqComparerV* v) const { return v->compare(this); }
// XXX: compare values instead of pointers?
virtual bool compare(const CPHScriptCondition* v) const { return v->m_lua_function == m_lua_function; }
/// virtual bool is_equal (CPHReqBase* v) ;
// virtual bool is_relative (CPHReqBase* v) ;
virtual bool compare(const CPHScriptCondition* v) const
{
const auto& lhs = static_cast<const luabind::adl::object&>(*m_lua_function);
const auto& rhs = static_cast<const luabind::adl::object&>(*v->m_lua_function);
return lhs == rhs;
}
};

class CPHScriptAction : public CPHAction, public CPHReqComparerV
Expand Down
8 changes: 0 additions & 8 deletions src/xrGame/level_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,11 @@ void remove_call(const luabind::functor<bool>& condition, const luabind::functor

void add_call(const luabind::object& lua_object, LPCSTR condition, LPCSTR action)
{
// try{
// CPHScriptObjectCondition *c=new CPHScriptObjectCondition(lua_object,condition);
// CPHScriptObjectAction *a=new CPHScriptObjectAction(lua_object,action);
luabind::functor<bool> _condition = object_cast<luabind::functor<bool>>(lua_object[condition]);
luabind::functor<void> _action = object_cast<luabind::functor<void>>(lua_object[action]);
CPHScriptObjectConditionN* c = new CPHScriptObjectConditionN(lua_object, _condition);
CPHScriptObjectActionN* a = new CPHScriptObjectActionN(lua_object, _action);
Level().ph_commander_scripts().add_call_unique(c, c, a, a);
// }
// catch(...)
// {
// Msg("add_call excepted!!");
// }
}

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

0 comments on commit 0dd7254

Please sign in to comment.