*Massive cleanup (\n\n -> \n, *\n -> \n, cleanup for(...) to for (...), and some other cleanups by hand)
*Fix a possible crash in Spell::DoAllEffectOnTarget --HG-- branch : trunk
This commit is contained in:
@@ -17,17 +17,13 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef TRINITY_BYTECONVERTER_H
|
||||
#define TRINITY_BYTECONVERTER_H
|
||||
|
||||
/** ByteConverter reverse your byte order. This is use
|
||||
for cross platform where they have different endians.
|
||||
*/
|
||||
|
||||
#include<Platform/Define.h>
|
||||
#include<algorithm>
|
||||
|
||||
namespace ByteConverter
|
||||
{
|
||||
template<size_t T>
|
||||
@@ -36,16 +32,13 @@ namespace ByteConverter
|
||||
std::swap(*val, *(val + T - 1));
|
||||
convert<T - 2>(val + 1);
|
||||
}
|
||||
|
||||
template<> inline void convert<0>(char *) {}
|
||||
template<> inline void convert<1>(char *) {} // ignore central byte
|
||||
|
||||
template<typename T> inline void apply(T *val)
|
||||
{
|
||||
convert<sizeof(T)>((char *)(val));
|
||||
}
|
||||
}
|
||||
|
||||
#if TRINITY_ENDIAN == TRINITY_BIGENDIAN
|
||||
template<typename T> inline void EndianConvert(T& val) { ByteConverter::apply<T>(&val); }
|
||||
template<typename T> inline void EndianConvertReverse(T&) { }
|
||||
@@ -53,14 +46,11 @@ template<typename T> inline void EndianConvertReverse(T&) { }
|
||||
template<typename T> inline void EndianConvert(T&) { }
|
||||
template<typename T> inline void EndianConvertReverse(T& val) { ByteConverter::apply<T>(&val); }
|
||||
#endif
|
||||
|
||||
template<typename T> void EndianConvert(T*); // will generate link error
|
||||
template<typename T> void EndianConvertReverse(T*); // will generate link error
|
||||
|
||||
inline void EndianConvert(uint8&) { }
|
||||
inline void EndianConvert( int8&) { }
|
||||
inline void EndianConvertReverse(uint8&) { }
|
||||
inline void EndianConvertReverse( int8&) { }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -17,12 +17,9 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef TRINITY_CALLBACK_H
|
||||
#define TRINITY_CALLBACK_H
|
||||
|
||||
/// ------------ BASE CLASSES ------------
|
||||
|
||||
namespace Trinity
|
||||
{
|
||||
template < class Class, typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void, typename ParamType4 = void >
|
||||
@@ -43,7 +40,6 @@ namespace Trinity
|
||||
_Callback(_Callback < Class, ParamType1, ParamType2, ParamType3, ParamType4> const& cb)
|
||||
: m_object(cb.object), m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2), m_param3(cb.m_param3), m_param4(cb.m_param4) {}
|
||||
};
|
||||
|
||||
template < class Class, typename ParamType1, typename ParamType2, typename ParamType3 >
|
||||
class _Callback < Class, ParamType1, ParamType2, ParamType3 >
|
||||
{
|
||||
@@ -61,7 +57,6 @@ namespace Trinity
|
||||
_Callback(_Callback < Class, ParamType1, ParamType2, ParamType3 > const& cb)
|
||||
: m_object(cb.object), m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2), m_param3(cb.m_param3) {}
|
||||
};
|
||||
|
||||
template < class Class, typename ParamType1, typename ParamType2 >
|
||||
class _Callback < Class, ParamType1, ParamType2 >
|
||||
{
|
||||
@@ -78,7 +73,6 @@ namespace Trinity
|
||||
_Callback(_Callback < Class, ParamType1, ParamType2 > const& cb)
|
||||
: m_object(cb.m_object), m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2) {}
|
||||
};
|
||||
|
||||
template < class Class, typename ParamType1 >
|
||||
class _Callback < Class, ParamType1 >
|
||||
{
|
||||
@@ -94,7 +88,6 @@ namespace Trinity
|
||||
_Callback(_Callback < Class, ParamType1 > const& cb)
|
||||
: m_object(cb.m_object), m_method(cb.m_method), m_param1(cb.m_param1) {}
|
||||
};
|
||||
|
||||
template < class Class >
|
||||
class _Callback < Class >
|
||||
{
|
||||
@@ -109,9 +102,7 @@ namespace Trinity
|
||||
_Callback(_Callback < Class > const& cb)
|
||||
: m_object(cb.m_object), m_method(cb.m_method) {}
|
||||
};
|
||||
|
||||
/// ---- Statics ----
|
||||
|
||||
template < typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void, typename ParamType4 = void >
|
||||
class _SCallback
|
||||
{
|
||||
@@ -129,7 +120,6 @@ namespace Trinity
|
||||
_SCallback(_SCallback < ParamType1, ParamType2, ParamType3, ParamType4> const& cb)
|
||||
: m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2), m_param3(cb.m_param3), m_param4(cb.m_param4) {}
|
||||
};
|
||||
|
||||
template < typename ParamType1, typename ParamType2, typename ParamType3 >
|
||||
class _SCallback < ParamType1, ParamType2, ParamType3 >
|
||||
{
|
||||
@@ -146,7 +136,6 @@ namespace Trinity
|
||||
_SCallback(_SCallback < ParamType1, ParamType2, ParamType3 > const& cb)
|
||||
: m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2), m_param3(cb.m_param3) {}
|
||||
};
|
||||
|
||||
template < typename ParamType1, typename ParamType2 >
|
||||
class _SCallback < ParamType1, ParamType2 >
|
||||
{
|
||||
@@ -162,7 +151,6 @@ namespace Trinity
|
||||
_SCallback(_SCallback < ParamType1, ParamType2 > const& cb)
|
||||
: m_method(cb.m_method), m_param1(cb.m_param1), m_param2(cb.m_param2) {}
|
||||
};
|
||||
|
||||
template < typename ParamType1 >
|
||||
class _SCallback < ParamType1 >
|
||||
{
|
||||
@@ -177,7 +165,6 @@ namespace Trinity
|
||||
_SCallback(_SCallback < ParamType1 > const& cb)
|
||||
: m_method(cb.m_method), m_param1(cb.m_param1) {}
|
||||
};
|
||||
|
||||
template < >
|
||||
class _SCallback < >
|
||||
{
|
||||
@@ -192,9 +179,7 @@ namespace Trinity
|
||||
: m_method(cb.m_method) {}
|
||||
};
|
||||
}
|
||||
|
||||
/// --------- GENERIC CALLBACKS ----------
|
||||
|
||||
namespace Trinity
|
||||
{
|
||||
class ICallback
|
||||
@@ -203,7 +188,6 @@ namespace Trinity
|
||||
virtual void Execute() = 0;
|
||||
virtual ~ICallback() {}
|
||||
};
|
||||
|
||||
template < class CB >
|
||||
class _ICallback : public CB, public ICallback
|
||||
{
|
||||
@@ -211,7 +195,6 @@ namespace Trinity
|
||||
_ICallback(CB const& cb) : CB(cb) {}
|
||||
void Execute() { CB::_Execute(); }
|
||||
};
|
||||
|
||||
template < class Class, typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void, typename ParamType4 = void >
|
||||
class Callback :
|
||||
public _ICallback< _Callback < Class, ParamType1, ParamType2, ParamType3, ParamType4 > >
|
||||
@@ -222,7 +205,6 @@ namespace Trinity
|
||||
Callback(Class *object, typename C4::Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3, ParamType4 param4)
|
||||
: _ICallback< C4 >(C4(object, method, param1, param2, param3, param4)) {}
|
||||
};
|
||||
|
||||
template < class Class, typename ParamType1, typename ParamType2, typename ParamType3 >
|
||||
class Callback < Class, ParamType1, ParamType2, ParamType3 > :
|
||||
public _ICallback< _Callback < Class, ParamType1, ParamType2, ParamType3 > >
|
||||
@@ -233,7 +215,6 @@ namespace Trinity
|
||||
Callback(Class *object, typename C3::Method method, ParamType1 param1, ParamType2 param2, ParamType3 param3)
|
||||
: _ICallback< C3 >(C3(object, method, param1, param2, param3)) {}
|
||||
};
|
||||
|
||||
template < class Class, typename ParamType1, typename ParamType2 >
|
||||
class Callback < Class, ParamType1, ParamType2 > :
|
||||
public _ICallback< _Callback < Class, ParamType1, ParamType2 > >
|
||||
@@ -244,7 +225,6 @@ namespace Trinity
|
||||
Callback(Class *object, typename C2::Method method, ParamType1 param1, ParamType2 param2)
|
||||
: _ICallback< C2 >(C2(object, method, param1, param2)) {}
|
||||
};
|
||||
|
||||
template < class Class, typename ParamType1 >
|
||||
class Callback < Class, ParamType1 > :
|
||||
public _ICallback< _Callback < Class, ParamType1 > >
|
||||
@@ -255,7 +235,6 @@ namespace Trinity
|
||||
Callback(Class *object, typename C1::Method method, ParamType1 param1)
|
||||
: _ICallback< C1 >(C1(object, method, param1)) {}
|
||||
};
|
||||
|
||||
template < class Class >
|
||||
class Callback < Class > : public _ICallback< _Callback < Class > >
|
||||
{
|
||||
@@ -266,11 +245,8 @@ namespace Trinity
|
||||
: _ICallback< C0 >(C0(object, method)) {}
|
||||
};
|
||||
}
|
||||
|
||||
/// ---------- QUERY CALLBACKS -----------
|
||||
|
||||
class QueryResult;
|
||||
|
||||
namespace Trinity
|
||||
{
|
||||
class IQueryCallback
|
||||
@@ -281,7 +257,6 @@ namespace Trinity
|
||||
virtual void SetResult(QueryResult* result) = 0;
|
||||
virtual QueryResult* GetResult() = 0;
|
||||
};
|
||||
|
||||
template < class CB >
|
||||
class _IQueryCallback : public CB, public IQueryCallback
|
||||
{
|
||||
@@ -291,7 +266,6 @@ namespace Trinity
|
||||
void SetResult(QueryResult* result) { CB::m_param1 = result; }
|
||||
QueryResult* GetResult() { return CB::m_param1; }
|
||||
};
|
||||
|
||||
template < class Class, typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void >
|
||||
class QueryCallback :
|
||||
public _IQueryCallback< _Callback < Class, QueryResult*, ParamType1, ParamType2, ParamType3 > >
|
||||
@@ -302,7 +276,6 @@ namespace Trinity
|
||||
QueryCallback(Class *object, typename QC3::Method method, QueryResult* result, ParamType1 param1, ParamType2 param2, ParamType3 param3)
|
||||
: _IQueryCallback< QC3 >(QC3(object, method, result, param1, param2, param3)) {}
|
||||
};
|
||||
|
||||
template < class Class, typename ParamType1, typename ParamType2 >
|
||||
class QueryCallback < Class, ParamType1, ParamType2 > :
|
||||
public _IQueryCallback< _Callback < Class, QueryResult*, ParamType1, ParamType2 > >
|
||||
@@ -313,7 +286,6 @@ namespace Trinity
|
||||
QueryCallback(Class *object, typename QC2::Method method, QueryResult* result, ParamType1 param1, ParamType2 param2)
|
||||
: _IQueryCallback< QC2 >(QC2(object, method, result, param1, param2)) {}
|
||||
};
|
||||
|
||||
template < class Class, typename ParamType1 >
|
||||
class QueryCallback < Class, ParamType1 > :
|
||||
public _IQueryCallback< _Callback < Class, QueryResult*, ParamType1 > >
|
||||
@@ -324,7 +296,6 @@ namespace Trinity
|
||||
QueryCallback(Class *object, typename QC1::Method method, QueryResult* result, ParamType1 param1)
|
||||
: _IQueryCallback< QC1 >(QC1(object, method, result, param1)) {}
|
||||
};
|
||||
|
||||
template < class Class >
|
||||
class QueryCallback < Class > : public _IQueryCallback< _Callback < Class, QueryResult* > >
|
||||
{
|
||||
@@ -334,9 +305,7 @@ namespace Trinity
|
||||
QueryCallback(Class *object, typename QC0::Method method, QueryResult* result)
|
||||
: _IQueryCallback< QC0 >(QC0(object, method, result)) {}
|
||||
};
|
||||
|
||||
/// ---- Statics ----
|
||||
|
||||
template < typename ParamType1 = void, typename ParamType2 = void, typename ParamType3 = void >
|
||||
class SQueryCallback :
|
||||
public _IQueryCallback< _SCallback < QueryResult*, ParamType1, ParamType2, ParamType3 > >
|
||||
@@ -347,7 +316,6 @@ namespace Trinity
|
||||
SQueryCallback(typename QC3::Method method, QueryResult* result, ParamType1 param1, ParamType2 param2, ParamType3 param3)
|
||||
: _IQueryCallback< QC3 >(QC3(method, result, param1, param2, param3)) {}
|
||||
};
|
||||
|
||||
template < typename ParamType1, typename ParamType2 >
|
||||
class SQueryCallback < ParamType1, ParamType2 > :
|
||||
public _IQueryCallback< _SCallback < QueryResult*, ParamType1, ParamType2 > >
|
||||
@@ -358,7 +326,6 @@ namespace Trinity
|
||||
SQueryCallback(typename QC2::Method method, QueryResult* result, ParamType1 param1, ParamType2 param2)
|
||||
: _IQueryCallback< QC2 >(QC2(method, result, param1, param2)) {}
|
||||
};
|
||||
|
||||
template < typename ParamType1 >
|
||||
class SQueryCallback < ParamType1 > :
|
||||
public _IQueryCallback< _SCallback < QueryResult*, ParamType1 > >
|
||||
@@ -369,7 +336,6 @@ namespace Trinity
|
||||
SQueryCallback(typename QC1::Method method, QueryResult* result, ParamType1 param1)
|
||||
: _IQueryCallback< QC1 >(QC1(method, result, param1)) {}
|
||||
};
|
||||
|
||||
template < >
|
||||
class SQueryCallback < > : public _IQueryCallback< _SCallback < QueryResult* > >
|
||||
{
|
||||
@@ -380,6 +346,5 @@ namespace Trinity
|
||||
: _IQueryCallback< QC0 >(QC0(method, result)) {}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -17,10 +17,8 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef TRINITY_REFERENCE_H
|
||||
#define TRINITY_REFERENCE_H
|
||||
|
||||
/**
|
||||
* Referencer<T>
|
||||
* Referencer is an object that holds a reference holder that hold a reference
|
||||
@@ -31,12 +29,10 @@
|
||||
* reference around. Objects can be reference counted in both single threaded
|
||||
* model and multi-threaded model
|
||||
*/
|
||||
|
||||
#include <stdexcept>
|
||||
#include "Platform/Define.h"
|
||||
#include "Policies/ThreadingModel.h"
|
||||
#include "ReferenceHolder.h"
|
||||
|
||||
template
|
||||
<
|
||||
typename T,
|
||||
@@ -47,52 +43,39 @@ class TRINITY_DLL_DECL Referencer
|
||||
typedef typename THREADING_MODEL::Lock Lock;
|
||||
typedef ReferenceHolder<T, THREADING_MODEL> ReferenceeHolder;
|
||||
public:
|
||||
|
||||
/// Constructs a referencer.
|
||||
Referencer(T *ref = NULL);
|
||||
|
||||
/// Copy constructor
|
||||
Referencer(const Referencer &obj) : i_holder(NULL) { *this = obj; }
|
||||
|
||||
/// Destructor
|
||||
~Referencer();
|
||||
|
||||
/// Referencee accessor
|
||||
T* referencee(void) { return (i_holder == NULL ? NULL : i_holder->i_referencee); }
|
||||
const T* referencee(void) const { return (i_holder == NULL ? NULL : i_holder->i_referencee); }
|
||||
|
||||
//T& referencee(void){ return _referencee(); }
|
||||
//const T& referencee(void) const { return const_cast<Referencer *>(this)->_referencee(); }
|
||||
operator T&(void) { return _referencee(); }
|
||||
operator const T&(void) const { return *const_cast<Referencer *>(this)->_referencee(); }
|
||||
|
||||
/// cast operators
|
||||
T* operator*() { return (i_holder == NULL ? NULL : i_holder->i_referencee); }
|
||||
T const * operator*() const { return (i_holder == NULL ? NULL : i_holder->i_referencee); }
|
||||
|
||||
/// overload operators
|
||||
T* operator->() { return (i_holder == NULL ? NULL : i_holder->i_referencee); }
|
||||
const T * operator->() const { return (i_holder == NULL ? NULL : i_holder->i_referencee); }
|
||||
|
||||
/// operator =
|
||||
Referencer& operator=(const Referencer &obj);
|
||||
Referencer& operator=(T *);
|
||||
|
||||
/// returns true if i_referencee is null
|
||||
bool isNull(void) const { return i_holder == NULL; }
|
||||
|
||||
private:
|
||||
|
||||
T& _referencee(void)
|
||||
{
|
||||
if( i_holder == NULL )
|
||||
throw std::runtime_error("Invalid access to null pointer");
|
||||
return *i_holder->i_referencee;
|
||||
}
|
||||
|
||||
void deReference(ReferenceeHolder *);
|
||||
void addReference(ReferenceeHolder *);
|
||||
|
||||
// private data
|
||||
ReferenceeHolder *i_holder;
|
||||
};
|
||||
|
||||
@@ -17,15 +17,12 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef TRINITY_REFERENCEHOLDER_H
|
||||
#define TRINITY_REFERENCEHOLDER_H
|
||||
|
||||
/** ReferenceHolder holds the actualy referenced obejct as well the refence
|
||||
count. The ReferenecHolder implements as a policy base object and
|
||||
will decided by the Reference class to be consnsitent.
|
||||
*/
|
||||
|
||||
template
|
||||
<
|
||||
typename T,
|
||||
|
||||
@@ -17,12 +17,9 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef TRINITY_REFERENCEIMPL_H
|
||||
#define TRINITY_REFERENCEIMPL_H
|
||||
|
||||
#include "Reference.h"
|
||||
|
||||
template
|
||||
<
|
||||
typename T,
|
||||
@@ -37,7 +34,6 @@ Referencer<T, THREADING_MODEL>::Referencer(T *ref)
|
||||
++i_holder->i_referenceCount;
|
||||
}
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename T,
|
||||
@@ -49,7 +45,6 @@ Referencer<T, THREADING_MODEL>::~Referencer()
|
||||
deReference(i_holder);
|
||||
i_holder = NULL;
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename T,
|
||||
@@ -65,7 +60,6 @@ Referencer<T, THREADING_MODEL>::operator=(const Referencer<T, THREADING_MODEL> &
|
||||
i_holder = obj.i_holder;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename T,
|
||||
@@ -82,10 +76,8 @@ Referencer<T, THREADING_MODEL>::operator=(T *ref)
|
||||
i_holder = new ReferenceeHolder(ref);
|
||||
++i_holder->i_referenceCount;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename T,
|
||||
@@ -96,25 +88,21 @@ Referencer<T, THREADING_MODEL>::deReference(ReferenceHolder<T, THREADING_MODEL>
|
||||
{
|
||||
assert( holder != NULL && holder->i_referenceCount > 0);
|
||||
bool delete_object = false;
|
||||
|
||||
{
|
||||
// The guard is within the scope due to the guard
|
||||
// must release earlier than expected.
|
||||
Lock guard(*holder);
|
||||
Guard(&guard);
|
||||
|
||||
--holder->i_referenceCount;
|
||||
if( holder->i_referenceCount == 0 )
|
||||
delete_object = true;
|
||||
}
|
||||
|
||||
if( delete_object )
|
||||
{
|
||||
delete holder->i_referencee;
|
||||
delete holder;
|
||||
}
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename T,
|
||||
@@ -126,7 +114,6 @@ Referencer<T, THREADING_MODEL>::addReference(ReferenceHolder<T, THREADING_MODEL>
|
||||
assert( i_holder != NULL );
|
||||
Lock guard(*holder);
|
||||
Guard(&guard);
|
||||
|
||||
++holder->i_referenceCount;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -17,25 +17,20 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "EventProcessor.h"
|
||||
|
||||
EventProcessor::EventProcessor()
|
||||
{
|
||||
m_time = 0;
|
||||
m_aborting = false;
|
||||
}
|
||||
|
||||
EventProcessor::~EventProcessor()
|
||||
{
|
||||
KillAllEvents(true);
|
||||
}
|
||||
|
||||
void EventProcessor::Update(uint32 p_time)
|
||||
{
|
||||
// update time
|
||||
m_time += p_time;
|
||||
|
||||
// main event loop
|
||||
EventList::iterator i;
|
||||
while (((i = m_events.begin()) != m_events.end()) && i->first <= m_time)
|
||||
@@ -43,7 +38,6 @@ void EventProcessor::Update(uint32 p_time)
|
||||
// get and remove event from queue
|
||||
BasicEvent* Event = i->second;
|
||||
m_events.erase(i);
|
||||
|
||||
if (!Event->to_Abort)
|
||||
{
|
||||
if (Event->Execute(m_time, p_time))
|
||||
@@ -59,41 +53,34 @@ void EventProcessor::Update(uint32 p_time)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EventProcessor::KillAllEvents(bool force)
|
||||
{
|
||||
// prevent event insertions
|
||||
m_aborting = true;
|
||||
|
||||
// first, abort all existing events
|
||||
for (EventList::iterator i = m_events.begin(); i != m_events.end();)
|
||||
{
|
||||
EventList::iterator i_old = i;
|
||||
++i;
|
||||
|
||||
i_old->second->to_Abort = true;
|
||||
i_old->second->Abort(m_time);
|
||||
if(force || i_old->second->IsDeletable())
|
||||
{
|
||||
delete i_old->second;
|
||||
|
||||
if(!force) // need per-element cleanup
|
||||
m_events.erase (i_old);
|
||||
}
|
||||
}
|
||||
|
||||
// fast clear event list (in force case)
|
||||
if(force)
|
||||
m_events.clear();
|
||||
}
|
||||
|
||||
void EventProcessor::AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime)
|
||||
{
|
||||
if (set_addtime) Event->m_addTime = m_time;
|
||||
Event->m_execTime = e_time;
|
||||
m_events.insert(std::pair<uint64, BasicEvent*>(e_time, Event));
|
||||
}
|
||||
|
||||
uint64 EventProcessor::CalculateTime(uint64 t_offset)
|
||||
{
|
||||
return(m_time + t_offset);
|
||||
|
||||
@@ -17,16 +17,11 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef __EVENTPROCESSOR_H
|
||||
#define __EVENTPROCESSOR_H
|
||||
|
||||
#include "Platform/Define.h"
|
||||
|
||||
#include<map>
|
||||
|
||||
// Note. All times are in milliseconds here.
|
||||
|
||||
class BasicEvent
|
||||
{
|
||||
public:
|
||||
@@ -34,32 +29,24 @@ class BasicEvent
|
||||
virtual ~BasicEvent() // override destructor to perform some actions on event removal
|
||||
{
|
||||
};
|
||||
|
||||
// this method executes when the event is triggered
|
||||
// return false if event does not want to be deleted
|
||||
// e_time is execution time, p_time is update interval
|
||||
virtual bool Execute(uint64 /*e_time*/, uint32 /*p_time*/) { return true; }
|
||||
|
||||
virtual bool IsDeletable() const { return true; } // this event can be safely deleted
|
||||
|
||||
virtual void Abort(uint64 /*e_time*/) {} // this method executes when the event is aborted
|
||||
|
||||
bool to_Abort; // set by externals when the event is aborted, aborted events don't execute
|
||||
// and get Abort call when deleted
|
||||
|
||||
// these can be used for time offset control
|
||||
uint64 m_addTime; // time when the event was added to queue, filled by event handler
|
||||
uint64 m_execTime; // planned time of next execution, filled by event handler
|
||||
};
|
||||
|
||||
typedef std::multimap<uint64, BasicEvent*> EventList;
|
||||
|
||||
class EventProcessor
|
||||
{
|
||||
public:
|
||||
EventProcessor();
|
||||
~EventProcessor();
|
||||
|
||||
void Update(uint32 p_time);
|
||||
void KillAllEvents(bool force);
|
||||
void AddEvent(BasicEvent* Event, uint64 e_time, bool set_addtime = true);
|
||||
|
||||
@@ -17,40 +17,31 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _LINKEDLIST
|
||||
#define _LINKEDLIST
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
//============================================
|
||||
class LinkedListHead;
|
||||
|
||||
class LinkedListElement
|
||||
{
|
||||
private:
|
||||
friend class LinkedListHead;
|
||||
|
||||
LinkedListElement* iNext;
|
||||
LinkedListElement* iPrev;
|
||||
public:
|
||||
LinkedListElement() { iNext = NULL; iPrev = NULL; }
|
||||
~LinkedListElement() { delink(); }
|
||||
|
||||
bool hasNext() const { return(iNext->iNext != NULL); }
|
||||
bool hasPrev() const { return(iPrev->iPrev != NULL); }
|
||||
bool isInList() const { return(iNext != NULL && iPrev != NULL); }
|
||||
|
||||
LinkedListElement * next() { return hasNext() ? iNext : NULL; }
|
||||
LinkedListElement const* next() const { return hasNext() ? iNext : NULL; }
|
||||
LinkedListElement * prev() { return hasPrev() ? iPrev : NULL; }
|
||||
LinkedListElement const* prev() const { return hasPrev() ? iPrev : NULL; }
|
||||
|
||||
LinkedListElement * nocheck_next() { return iNext; }
|
||||
LinkedListElement const* nocheck_next() const { return iNext; }
|
||||
LinkedListElement * nocheck_prev() { return iPrev; }
|
||||
LinkedListElement const* nocheck_prev() const { return iPrev; }
|
||||
|
||||
void delink()
|
||||
{
|
||||
if(isInList())
|
||||
@@ -58,7 +49,6 @@ class LinkedListElement
|
||||
iNext->iPrev = iPrev; iPrev->iNext = iNext; iNext = NULL; iPrev = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void insertBefore(LinkedListElement* pElem)
|
||||
{
|
||||
pElem->iNext = this;
|
||||
@@ -66,7 +56,6 @@ class LinkedListElement
|
||||
iPrev->iNext = pElem;
|
||||
iPrev = pElem;
|
||||
}
|
||||
|
||||
void insertAfter(LinkedListElement* pElem)
|
||||
{
|
||||
pElem->iPrev = this;
|
||||
@@ -75,9 +64,7 @@ class LinkedListElement
|
||||
iNext = pElem;
|
||||
}
|
||||
};
|
||||
|
||||
//============================================
|
||||
|
||||
class LinkedListHead
|
||||
{
|
||||
private:
|
||||
@@ -88,30 +75,23 @@ class LinkedListHead
|
||||
LinkedListHead()
|
||||
{
|
||||
// create empty list
|
||||
|
||||
iFirst.iNext = &iLast;
|
||||
iLast.iPrev = &iFirst;
|
||||
iSize = 0;
|
||||
}
|
||||
|
||||
bool isEmpty() const { return(!iFirst.iNext->isInList()); }
|
||||
|
||||
LinkedListElement * getFirst() { return(isEmpty() ? NULL : iFirst.iNext); }
|
||||
LinkedListElement const* getFirst() const { return(isEmpty() ? NULL : iFirst.iNext); }
|
||||
|
||||
LinkedListElement * getLast() { return(isEmpty() ? NULL : iLast.iPrev); }
|
||||
LinkedListElement const* getLast() const { return(isEmpty() ? NULL : iLast.iPrev); }
|
||||
|
||||
void insertFirst(LinkedListElement* pElem)
|
||||
{
|
||||
iFirst.insertAfter(pElem);
|
||||
}
|
||||
|
||||
void insertLast(LinkedListElement* pElem)
|
||||
{
|
||||
iLast.insertBefore(pElem);
|
||||
}
|
||||
|
||||
uint32 getSize() const
|
||||
{
|
||||
if(!iSize)
|
||||
@@ -128,10 +108,8 @@ class LinkedListHead
|
||||
else
|
||||
return iSize;
|
||||
}
|
||||
|
||||
void incSize() { ++iSize; }
|
||||
void decSize() { --iSize; }
|
||||
|
||||
template<class _Ty>
|
||||
class Iterator
|
||||
{
|
||||
@@ -145,105 +123,85 @@ class LinkedListHead
|
||||
typedef _Ty& reference;
|
||||
typedef _Ty const & const_reference;
|
||||
|
||||
|
||||
Iterator() : _Ptr(0)
|
||||
{ // construct with null node pointer
|
||||
}
|
||||
|
||||
Iterator(pointer _Pnode) : _Ptr(_Pnode)
|
||||
{ // construct with node pointer _Pnode
|
||||
}
|
||||
|
||||
Iterator& operator=(Iterator const &_Right)
|
||||
{
|
||||
return (*this) = _Right._Ptr;
|
||||
}
|
||||
|
||||
Iterator& operator=(const_pointer const &_Right)
|
||||
{
|
||||
_Ptr = (pointer)_Right;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
reference operator*()
|
||||
{ // return designated value
|
||||
return *_Ptr;
|
||||
}
|
||||
|
||||
pointer operator->()
|
||||
{ // return pointer to class object
|
||||
return _Ptr;
|
||||
}
|
||||
|
||||
Iterator& operator++()
|
||||
{ // preincrement
|
||||
_Ptr = _Ptr->next();
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Iterator operator++(int)
|
||||
{ // postincrement
|
||||
iterator _Tmp = *this;
|
||||
++*this;
|
||||
return (_Tmp);
|
||||
}
|
||||
|
||||
Iterator& operator--()
|
||||
{ // predecrement
|
||||
_Ptr = _Ptr->prev();
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Iterator operator--(int)
|
||||
{ // postdecrement
|
||||
iterator _Tmp = *this;
|
||||
--*this;
|
||||
return (_Tmp);
|
||||
}
|
||||
|
||||
bool operator==(Iterator const &_Right) const
|
||||
{ // test for iterator equality
|
||||
return (_Ptr == _Right._Ptr);
|
||||
}
|
||||
|
||||
bool operator!=(Iterator const &_Right) const
|
||||
{ // test for iterator inequality
|
||||
return (!(*this == _Right));
|
||||
}
|
||||
|
||||
bool operator==(pointer const &_Right) const
|
||||
{ // test for pointer equality
|
||||
return (_Ptr != _Right);
|
||||
}
|
||||
|
||||
bool operator!=(pointer const &_Right) const
|
||||
{ // test for pointer equality
|
||||
return (!(*this == _Right));
|
||||
}
|
||||
|
||||
bool operator==(const_reference _Right) const
|
||||
{ // test for reference equality
|
||||
return (_Ptr == &_Right);
|
||||
}
|
||||
|
||||
bool operator!=(const_reference _Right) const
|
||||
{ // test for reference equality
|
||||
return (_Ptr != &_Right);
|
||||
}
|
||||
|
||||
|
||||
pointer _Mynode()
|
||||
{ // return node pointer
|
||||
return (_Ptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
pointer _Ptr; // pointer to node
|
||||
};
|
||||
|
||||
typedef Iterator<LinkedListElement> iterator;
|
||||
};
|
||||
|
||||
//============================================
|
||||
#endif
|
||||
|
||||
|
||||
@@ -17,31 +17,25 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _REFMANAGER_H
|
||||
#define _REFMANAGER_H
|
||||
//=====================================================
|
||||
|
||||
#include "Utilities/LinkedList.h"
|
||||
#include "Utilities/LinkedReference/Reference.h"
|
||||
|
||||
template <class TO, class FROM> class RefManager : public LinkedListHead
|
||||
{
|
||||
public:
|
||||
typedef LinkedListHead::Iterator< Reference<TO, FROM> > iterator;
|
||||
RefManager() { }
|
||||
virtual ~RefManager() { clearReferences(); }
|
||||
|
||||
Reference<TO, FROM>* getFirst() { return ((Reference<TO, FROM>*) LinkedListHead::getFirst()); }
|
||||
Reference<TO, FROM> const* getFirst() const { return ((Reference<TO, FROM> const*) LinkedListHead::getFirst()); }
|
||||
Reference<TO, FROM>* getLast() { return ((Reference<TO, FROM>*) LinkedListHead::getLast()); }
|
||||
Reference<TO, FROM> const* getLast() const { return ((Reference<TO, FROM> const*) LinkedListHead::getLast()); }
|
||||
|
||||
iterator begin() { return iterator(getFirst()); }
|
||||
iterator end() { return iterator(NULL); }
|
||||
iterator rbegin() { return iterator(getLast()); }
|
||||
iterator rend() { return iterator(NULL); }
|
||||
|
||||
void clearReferences()
|
||||
{
|
||||
LinkedListElement* ref;
|
||||
@@ -52,7 +46,6 @@ template <class TO, class FROM> class RefManager : public LinkedListHead
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//=====================================================
|
||||
#endif
|
||||
|
||||
|
||||
@@ -17,14 +17,10 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef _REFERENCE_H
|
||||
#define _REFERENCE_H
|
||||
|
||||
#include "Utilities/LinkedList.h"
|
||||
|
||||
//=====================================================
|
||||
|
||||
template <class TO, class FROM> class Reference : public LinkedListElement
|
||||
{
|
||||
private:
|
||||
@@ -33,16 +29,13 @@ template <class TO, class FROM> class Reference : public LinkedListElement
|
||||
protected:
|
||||
// Tell our refTo (target) object that we have a link
|
||||
virtual void targetObjectBuildLink() = 0;
|
||||
|
||||
// Tell our refTo (taget) object, that the link is cut
|
||||
virtual void targetObjectDestroyLink() = 0;
|
||||
|
||||
// Tell our refFrom (source) object, that the link is cut (Target destroyed)
|
||||
virtual void sourceObjectDestroyLink() = 0;
|
||||
public:
|
||||
Reference() { iRefTo = NULL; iRefFrom = NULL; }
|
||||
virtual ~Reference() {}
|
||||
|
||||
// Create new link
|
||||
void link(TO* toObj, FROM* fromObj)
|
||||
{
|
||||
@@ -56,39 +49,31 @@ template <class TO, class FROM> class Reference : public LinkedListElement
|
||||
targetObjectBuildLink();
|
||||
}
|
||||
}
|
||||
|
||||
// We don't need the reference anymore. Call comes from the refFrom object
|
||||
// Tell our refTo object, that the link is cut
|
||||
void unlink() { targetObjectDestroyLink(); delink(); iRefTo = NULL; iRefFrom = NULL; }
|
||||
|
||||
// Link is invalid due to destruction of referenced target object. Call comes from the refTo object
|
||||
// Tell our refFrom object, that the link is cut
|
||||
void invalidate() // the iRefFrom MUST remain!!
|
||||
{
|
||||
sourceObjectDestroyLink(); delink(); iRefTo = NULL;
|
||||
}
|
||||
|
||||
bool isValid() const // Only check the iRefTo
|
||||
{
|
||||
return iRefTo != NULL;
|
||||
}
|
||||
|
||||
Reference<TO,FROM> * next() { return((Reference<TO,FROM> *) LinkedListElement::next()); }
|
||||
Reference<TO,FROM> const * next() const { return((Reference<TO,FROM> const *) LinkedListElement::next()); }
|
||||
Reference<TO,FROM> * prev() { return((Reference<TO,FROM> *) LinkedListElement::prev()); }
|
||||
Reference<TO,FROM> const * prev() const { return((Reference<TO,FROM> const *) LinkedListElement::prev()); }
|
||||
|
||||
Reference<TO,FROM> * nocheck_next() { return((Reference<TO,FROM> *) LinkedListElement::nocheck_next()); }
|
||||
Reference<TO,FROM> const * nocheck_next() const { return((Reference<TO,FROM> const *) LinkedListElement::nocheck_next()); }
|
||||
Reference<TO,FROM> * nocheck_prev() { return((Reference<TO,FROM> *) LinkedListElement::nocheck_prev()); }
|
||||
Reference<TO,FROM> const * nocheck_prev() const { return((Reference<TO,FROM> const *) LinkedListElement::nocheck_prev()); }
|
||||
|
||||
TO* operator ->() const { return iRefTo; }
|
||||
TO* getTarget() const { return iRefTo; }
|
||||
|
||||
FROM* getSource() const { return iRefFrom; }
|
||||
};
|
||||
|
||||
//=====================================================
|
||||
#endif
|
||||
|
||||
|
||||
@@ -17,25 +17,20 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef TRINITY_TYPELIST_H
|
||||
#define TRINITY_TYPELIST_H
|
||||
|
||||
/*
|
||||
@struct TypeList
|
||||
TypeList is the most simple but yet the most powerfull class of all. It holds
|
||||
at compile time the different type of objects in a linked list.
|
||||
*/
|
||||
|
||||
class TypeNull;
|
||||
|
||||
template<typename HEAD, typename TAIL>
|
||||
struct TypeList
|
||||
{
|
||||
typedef HEAD Head;
|
||||
typedef TAIL Tail;
|
||||
};
|
||||
|
||||
// enough for now.. can be expand at any point in time as needed
|
||||
#define TYPELIST_1(T1) TypeList<T1,TypeNull>
|
||||
#define TYPELIST_2(T1, T2) TypeList<T1, TYPELIST_1(T2) >
|
||||
|
||||
@@ -17,13 +17,10 @@
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef TRINITY_UNORDERED_MAP_H
|
||||
#define TRINITY_UNORDERED_MAP_H
|
||||
|
||||
#include "Platform/CompilerDefs.h"
|
||||
#include "Platform/Define.h"
|
||||
|
||||
#if COMPILER == COMPILER_INTEL
|
||||
#include <ext/hash_map>
|
||||
#elif COMPILER == COMPILER_GNU && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 3)
|
||||
@@ -35,7 +32,6 @@
|
||||
#else
|
||||
#include <hash_map>
|
||||
#endif
|
||||
|
||||
#ifdef _STLPORT_VERSION
|
||||
#define UNORDERED_MAP std::hash_map
|
||||
using std::hash_map;
|
||||
@@ -51,7 +47,6 @@ using std::hash_map;
|
||||
#define UNORDERED_MAP std::tr1::unordered_map
|
||||
#elif COMPILER == COMPILER_GNU && __GNUC__ >= 3
|
||||
#define UNORDERED_MAP __gnu_cxx::hash_map
|
||||
|
||||
namespace __gnu_cxx
|
||||
{
|
||||
template<> struct hash<unsigned long long>
|
||||
@@ -62,9 +57,7 @@ namespace __gnu_cxx
|
||||
{
|
||||
size_t operator()(T * const &__x) const { return (size_t)__x; }
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#else
|
||||
#define UNORDERED_MAP std::hash_map
|
||||
using std::hash_map;
|
||||
|
||||
Reference in New Issue
Block a user