mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-23 18:36:31 +01:00
Merge branch 'master' of github.com:TrinityCore/TrinityCore into mmaps
Conflicts: src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp
This commit is contained in:
@@ -130,14 +130,6 @@
|
||||
|
||||
#endif
|
||||
|
||||
#define UI64FMTD ACE_UINT64_FORMAT_SPECIFIER
|
||||
#define UI64LIT(N) ACE_UINT64_LITERAL(N)
|
||||
|
||||
#define SI64FMTD ACE_INT64_FORMAT_SPECIFIER
|
||||
#define SI64LIT(N) ACE_INT64_LITERAL(N)
|
||||
|
||||
#define SIZEFMTD ACE_SIZE_T_FORMAT_SPECIFIER
|
||||
|
||||
inline float finiteAlways(float f) { return finite(f) ? f : 0.0f; }
|
||||
|
||||
#define atol(a) strtoul( a, NULL, 10)
|
||||
|
||||
@@ -50,12 +50,20 @@
|
||||
# define COMPILER COMPILER_INTEL
|
||||
#elif defined( __GNUC__ )
|
||||
# define COMPILER COMPILER_GNU
|
||||
# define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
|
||||
#else
|
||||
# pragma error "FATAL ERROR: Unknown compiler."
|
||||
# error "FATAL ERROR: Unknown compiler."
|
||||
#endif
|
||||
|
||||
#if COMPILER == COMPILER_MICROSOFT
|
||||
# pragma warning( disable : 4267 ) // conversion from 'size_t' to 'int', possible loss of data
|
||||
# pragma warning( disable : 4786 ) // identifier was truncated to '255' characters in the debug information
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus) && __cplusplus == 201103L
|
||||
# define COMPILER_HAS_CPP11_SUPPORT 1
|
||||
#else
|
||||
# define COMPILER_HAS_CPP11_SUPPORT 0
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -41,7 +41,7 @@ struct MySQLConnectionInfo
|
||||
MySQLConnectionInfo() {}
|
||||
MySQLConnectionInfo(const std::string& infoString)
|
||||
{
|
||||
Tokens tokens(infoString, ';');
|
||||
Tokenizer tokens(infoString, ';');
|
||||
|
||||
if (tokens.size() != 5)
|
||||
return;
|
||||
|
||||
@@ -19,12 +19,12 @@
|
||||
#ifndef TRINITY_DEFINE_H
|
||||
#define TRINITY_DEFINE_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "CompilerDefs.h"
|
||||
|
||||
#include <ace/Basic_Types.h>
|
||||
#include <ace/ACE_export.h>
|
||||
|
||||
#include "CompilerDefs.h"
|
||||
#include <cstddef>
|
||||
|
||||
#define TRINITY_LITTLEENDIAN 0
|
||||
#define TRINITY_BIGENDIAN 1
|
||||
@@ -70,6 +70,14 @@
|
||||
# define ATTR_DEPRECATED
|
||||
#endif //COMPILER == COMPILER_GNU
|
||||
|
||||
#define UI64FMTD ACE_UINT64_FORMAT_SPECIFIER
|
||||
#define UI64LIT(N) ACE_UINT64_LITERAL(N)
|
||||
|
||||
#define SI64FMTD ACE_INT64_FORMAT_SPECIFIER
|
||||
#define SI64LIT(N) ACE_INT64_LITERAL(N)
|
||||
|
||||
#define SIZEFMTD ACE_SIZE_T_FORMAT_SPECIFIER
|
||||
|
||||
typedef ACE_INT64 int64;
|
||||
typedef ACE_INT32 int32;
|
||||
typedef ACE_INT16 int16;
|
||||
|
||||
119
src/server/shared/Dynamic/HashNamespace.h
Normal file
119
src/server/shared/Dynamic/HashNamespace.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TRINITY_HASH_NAMESPACE_H
|
||||
#define TRINITY_HASH_NAMESPACE_H
|
||||
|
||||
#include "Define.h"
|
||||
|
||||
#if COMPILER_HAS_CPP11_SUPPORT
|
||||
# define HASH_NAMESPACE_START namespace std {
|
||||
# define HASH_NAMESPACE_END }
|
||||
#elif defined(_STLPORT_VERSION)
|
||||
# define HASH_NAMESPACE_START namespace std {
|
||||
# define HASH_NAMESPACE_END }
|
||||
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1600 // VS100
|
||||
# define HASH_NAMESPACE_START namespace std {
|
||||
# define HASH_NAMESPACE_END }
|
||||
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1500 && _HAS_TR1
|
||||
# define HASH_NAMESPACE_START namespace std { namespace tr1 {
|
||||
# define HASH_NAMESPACE_END } }
|
||||
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1300
|
||||
# define HASH_NAMESPACE_START namespace stdext {
|
||||
# define HASH_NAMESPACE_END }
|
||||
|
||||
#if !_HAS_TRADITIONAL_STL
|
||||
#ifndef HASH_NAMESPACE
|
||||
#define HASH_NAMESPACE
|
||||
#else
|
||||
|
||||
// can be not used by some platforms, so provide fake forward
|
||||
HASH_NAMESPACE_START
|
||||
|
||||
template<class K>
|
||||
class hash
|
||||
{
|
||||
public:
|
||||
size_t operator() (K const&);
|
||||
};
|
||||
|
||||
HASH_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#elif COMPILER == COMPILER_INTEL
|
||||
# define HASH_NAMESPACE_START namespace std {
|
||||
# define HASH_NAMESPACE_END }
|
||||
#elif COMPILER == COMPILER_GNU && defined(__clang__) && defined(_LIBCPP_VERSION)
|
||||
# define HASH_NAMESPACE_START namespace std {
|
||||
# define HASH_NAMESPACE_END }
|
||||
#elif COMPILER == COMPILER_GNU && GCC_VERSION > 40200
|
||||
# define HASH_NAMESPACE_START namespace std { namespace tr1 {
|
||||
# define HASH_NAMESPACE_END } }
|
||||
#elif COMPILER == COMPILER_GNU && GCC_VERSION >= 30000
|
||||
# define HASH_NAMESPACE_START namespace __gnu_cxx {
|
||||
# define HASH_NAMESPACE_END }
|
||||
|
||||
#include <ext/hash_fun.h>
|
||||
#include <string>
|
||||
|
||||
HASH_NAMESPACE_START
|
||||
|
||||
template<>
|
||||
class hash<unsigned long long>
|
||||
{
|
||||
public:
|
||||
size_t operator()(const unsigned long long &__x) const { return (size_t)__x; }
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class hash<T *>
|
||||
{
|
||||
public:
|
||||
size_t operator()(T * const &__x) const { return (size_t)__x; }
|
||||
};
|
||||
|
||||
template<> struct hash<std::string>
|
||||
{
|
||||
size_t operator()(const std::string &__x) const
|
||||
{
|
||||
return hash<char const *>()(__x.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
HASH_NAMESPACE_END
|
||||
|
||||
#else
|
||||
# define HASH_NAMESPACE_START namespace std {
|
||||
# define HASH_NAMESPACE_END }
|
||||
#endif
|
||||
|
||||
#if COMPILER != COMPILER_MICROSOFT
|
||||
|
||||
// Visual Studio use non standard hash calculation function, so provide fake forward for other
|
||||
HASH_NAMESPACE_START
|
||||
|
||||
template<class K>
|
||||
size_t hash_value(K const&);
|
||||
|
||||
HASH_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -19,7 +19,8 @@
|
||||
#ifndef _LINKEDLIST
|
||||
#define _LINKEDLIST
|
||||
|
||||
#include "Common.h"
|
||||
#include "Define.h"
|
||||
#include <iterator>
|
||||
|
||||
//============================================
|
||||
class LinkedListHead;
|
||||
@@ -32,7 +33,7 @@ class LinkedListElement
|
||||
LinkedListElement* iNext;
|
||||
LinkedListElement* iPrev;
|
||||
public:
|
||||
LinkedListElement() { iNext = NULL; iPrev = NULL; }
|
||||
LinkedListElement(): iNext(NULL), iPrev(NULL) {}
|
||||
~LinkedListElement() { delink(); }
|
||||
|
||||
bool hasNext() const { return(iNext && iNext->iNext != NULL); }
|
||||
@@ -83,13 +84,12 @@ class LinkedListHead
|
||||
LinkedListElement iLast;
|
||||
uint32 iSize;
|
||||
public:
|
||||
LinkedListHead()
|
||||
LinkedListHead(): iSize(0)
|
||||
{
|
||||
// create empty list
|
||||
|
||||
iFirst.iNext = &iLast;
|
||||
iLast.iPrev = &iFirst;
|
||||
iSize = 0;
|
||||
}
|
||||
|
||||
bool isEmpty() const { return(!iFirst.iNext->isInList()); }
|
||||
@@ -153,13 +153,14 @@ class LinkedListHead
|
||||
|
||||
Iterator& operator=(Iterator const &_Right)
|
||||
{
|
||||
return (*this) = _Right._Ptr;
|
||||
_Ptr = _Right._Ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Iterator& operator=(const_pointer const &_Right)
|
||||
{
|
||||
_Ptr = (pointer)_Right;
|
||||
return (*this);
|
||||
_Ptr = pointer(_Right);
|
||||
return *this;
|
||||
}
|
||||
|
||||
reference operator*()
|
||||
@@ -242,4 +243,3 @@ class LinkedListHead
|
||||
|
||||
//============================================
|
||||
#endif
|
||||
|
||||
|
||||
@@ -57,13 +57,21 @@ template <class TO, class FROM> class Reference : public LinkedListElement
|
||||
|
||||
// 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; }
|
||||
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;
|
||||
sourceObjectDestroyLink();
|
||||
delink();
|
||||
iRefTo = NULL;
|
||||
}
|
||||
|
||||
bool isValid() const // Only check the iRefTo
|
||||
@@ -89,4 +97,3 @@ template <class TO, class FROM> class Reference : public LinkedListElement
|
||||
|
||||
//=====================================================
|
||||
#endif
|
||||
|
||||
|
||||
@@ -101,7 +101,6 @@ class ObjectRegistry
|
||||
}
|
||||
private:
|
||||
RegistryMapType i_registeredObjects;
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -19,55 +19,54 @@
|
||||
#ifndef TRINITY_UNORDERED_MAP_H
|
||||
#define TRINITY_UNORDERED_MAP_H
|
||||
|
||||
#include "CompilerDefs.h"
|
||||
#include "Define.h"
|
||||
#include "HashNamespace.h"
|
||||
|
||||
#if COMPILER == COMPILER_INTEL
|
||||
#include <ext/hash_map>
|
||||
#elif COMPILER == COMPILER_GNU && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 3)
|
||||
#include <tr1/unordered_map>
|
||||
#elif COMPILER == COMPILER_GNU && __GNUC__ >= 3
|
||||
#include <ext/hash_map>
|
||||
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1500 && _HAS_TR1 // VC9.0 and later
|
||||
#include <unordered_map>
|
||||
#if COMPILER_HAS_CPP11_SUPPORT
|
||||
# include <unordered_map>
|
||||
#elif COMPILER == COMPILER_INTEL
|
||||
# include <ext/hash_map>
|
||||
#elif COMPILER == COMPILER_GNU && defined(__clang__) && defined(_LIBCPP_VERSION)
|
||||
# include <unordered_map>
|
||||
#elif COMPILER == COMPILER_GNU && GCC_VERSION > 40200
|
||||
# include <tr1/unordered_map>
|
||||
#elif COMPILER == COMPILER_GNU && GCC_VERSION >= 30000
|
||||
# include <ext/hash_map>
|
||||
#elif COMPILER == COMPILER_MICROSOFT && ((_MSC_VER >= 1500 && _HAS_TR1) || _MSC_VER >= 1700) // VC9.0 SP1 and later
|
||||
# include <unordered_map>
|
||||
#else
|
||||
#include <hash_map>
|
||||
# include <hash_map>
|
||||
#endif
|
||||
|
||||
#ifdef _STLPORT_VERSION
|
||||
#define UNORDERED_MAP std::hash_map
|
||||
using std::hash_map;
|
||||
# define UNORDERED_MAP std::hash_map
|
||||
# define UNORDERED_MULTIMAP std::hash_multimap
|
||||
#elif COMPILER_HAS_CPP11_SUPPORT
|
||||
# define UNORDERED_MAP std::unordered_map
|
||||
# define UNORDERED_MULTIMAP std::unordered_multimap
|
||||
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1600 // VS100
|
||||
# define UNORDERED_MAP std::tr1::unordered_map
|
||||
# define UNORDERED_MULTIMAP std::tr1::unordered_multimap
|
||||
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1500 && _HAS_TR1
|
||||
#define UNORDERED_MAP std::tr1::unordered_map
|
||||
# define UNORDERED_MAP std::tr1::unordered_map
|
||||
# define UNORDERED_MULTIMAP std::tr1::unordered_multimap
|
||||
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1300
|
||||
#define UNORDERED_MAP stdext::hash_map
|
||||
using stdext::hash_map;
|
||||
#elif COMPILER == COMPILER_GNU && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 3)
|
||||
#define UNORDERED_MAP std::tr1::unordered_map
|
||||
#elif (COMPILER == COMPILER_GNU && __GNUC__ >= 3) || COMPILER == COMPILER_INTEL
|
||||
#define UNORDERED_MAP __gnu_cxx::hash_map
|
||||
|
||||
namespace __gnu_cxx
|
||||
{
|
||||
template<> struct hash<unsigned long long>
|
||||
{
|
||||
size_t operator()(const unsigned long long &__x) const { return (size_t)__x; }
|
||||
};
|
||||
template<typename T> struct hash<T *>
|
||||
{
|
||||
size_t operator()(T * const &__x) const { return (size_t)__x; }
|
||||
};
|
||||
template<> struct hash<std::string>
|
||||
{
|
||||
size_t operator()(const std::string &__x) const
|
||||
{
|
||||
return hash<const char *>()(__x.c_str());
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
# define UNORDERED_MAP stdext::hash_map
|
||||
# define UNORDERED_MULTIMAP stdext::hash_multimap
|
||||
#elif COMPILER == COMPILER_INTEL
|
||||
# define UNORDERED_MAP std::hash_map
|
||||
# define UNORDERED_MULTIMAP std::hash_multimap
|
||||
#elif COMPILER == COMPILER_GNU && defined(__clang__) && defined(_LIBCPP_VERSION)
|
||||
# define UNORDERED_MAP std::unordered_map
|
||||
# define UNORDERED_MULTIMAP std::unordered_multimap
|
||||
#elif COMPILER == COMPILER_GNU && GCC_VERSION > 40200
|
||||
# define UNORDERED_MAP std::tr1::unordered_map
|
||||
# define UNORDERED_MULTIMAP std::tr1::unordered_multimap
|
||||
#elif COMPILER == COMPILER_GNU && GCC_VERSION >= 30000
|
||||
# define UNORDERED_MAP __gnu_cxx::hash_map
|
||||
# define UNORDERED_MULTIMAP __gnu_cxx::hash_multimap
|
||||
#else
|
||||
#define UNORDERED_MAP std::hash_map
|
||||
using std::hash_map;
|
||||
# define UNORDERED_MAP std::hash_map
|
||||
# define UNORDERED_MULTIMAP std::hash_multimap
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
66
src/server/shared/Dynamic/UnorderedSet.h
Normal file
66
src/server/shared/Dynamic/UnorderedSet.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TRINITY_UNORDERED_SET_H
|
||||
#define TRINITY_UNORDERED_SET_H
|
||||
|
||||
#include "HashNamespace.h"
|
||||
|
||||
#if COMPILER_HAS_CPP11_SUPPORT
|
||||
# include <unordered_set>
|
||||
#elif COMPILER == COMPILER_INTEL
|
||||
# include <ext/hash_set>
|
||||
#elif COMPILER == COMPILER_GNU && defined(__clang__) && defined(_LIBCPP_VERSION)
|
||||
# include <unordered_set>
|
||||
#elif COMPILER == COMPILER_GNU && GCC_VERSION > 40200
|
||||
# include <tr1/unordered_set>
|
||||
#elif COMPILER == COMPILER_GNU && GCC_VERSION >= 30000
|
||||
# include <ext/hash_set>
|
||||
#elif COMPILER == COMPILER_MICROSOFT && ((_MSC_VER >= 1500 && _HAS_TR1) || _MSC_VER >= 1700) // VC9.0 SP1 and later
|
||||
# include <unordered_set>
|
||||
#else
|
||||
# include <hash_set>
|
||||
#endif
|
||||
|
||||
#ifdef _STLPORT_VERSION
|
||||
# define UNORDERED_SET std::hash_set
|
||||
using std::hash_set;
|
||||
#elif COMPILER_HAS_CPP11_SUPPORT
|
||||
# define UNORDERED_SET std::unordered_set
|
||||
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1600 // VS100
|
||||
# define UNORDERED_SET std::tr1::unordered_set
|
||||
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1500 && _HAS_TR1
|
||||
# define UNORDERED_SET std::tr1::unordered_set
|
||||
#elif COMPILER == COMPILER_MICROSOFT && _MSC_VER >= 1300
|
||||
# define UNORDERED_SET stdext::hash_set
|
||||
using stdext::hash_set;
|
||||
#elif COMPILER == COMPILER_INTEL
|
||||
# define UNORDERED_SET std::hash_set
|
||||
using std::hash_set;
|
||||
#elif COMPILER == COMPILER_GNU && defined(__clang__) && defined(_LIBCPP_VERSION)
|
||||
# define UNORDERED_SET std::unordered_set
|
||||
#elif COMPILER == COMPILER_GNU && GCC_VERSION > 40200
|
||||
# define UNORDERED_SET std::tr1::unordered_set
|
||||
#elif COMPILER == COMPILER_GNU && GCC_VERSION >= 30000
|
||||
# define UNORDERED_SET __gnu_cxx::hash_set
|
||||
#else
|
||||
# define UNORDERED_SET std::hash_set
|
||||
using std::hash_set;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -88,8 +88,8 @@ void Log::CreateAppenderFromConfig(const char* name)
|
||||
std::string options = "Appender.";
|
||||
options.append(name);
|
||||
options = ConfigMgr::GetStringDefault(options.c_str(), "");
|
||||
Tokens tokens(options, ',');
|
||||
Tokens::iterator iter = tokens.begin();
|
||||
Tokenizer tokens(options, ',');
|
||||
Tokenizer::const_iterator iter = tokens.begin();
|
||||
|
||||
if (tokens.size() < 2)
|
||||
{
|
||||
@@ -181,8 +181,8 @@ void Log::CreateLoggerFromConfig(const char* name)
|
||||
return;
|
||||
}
|
||||
|
||||
Tokens tokens(options, ',');
|
||||
Tokens::iterator iter = tokens.begin();
|
||||
Tokenizer tokens(options, ',');
|
||||
Tokenizer::const_iterator iter = tokens.begin();
|
||||
|
||||
if (tokens.size() != 3)
|
||||
{
|
||||
|
||||
@@ -24,12 +24,12 @@
|
||||
*/
|
||||
|
||||
#include "Define.h"
|
||||
#include<algorithm>
|
||||
#include <algorithm>
|
||||
|
||||
namespace ByteConverter
|
||||
{
|
||||
template<size_t T>
|
||||
inline void convert(char *val)
|
||||
inline void convert(char *val)
|
||||
{
|
||||
std::swap(*val, *(val + T - 1));
|
||||
convert<T - 2>(val + 1);
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#include "Define.h"
|
||||
|
||||
#include<map>
|
||||
#include <map>
|
||||
|
||||
// Note. All times are in milliseconds here.
|
||||
|
||||
@@ -29,9 +29,7 @@ class BasicEvent
|
||||
{
|
||||
public:
|
||||
BasicEvent() { to_Abort = false; }
|
||||
virtual ~BasicEvent() // override destructor to perform some actions on event removal
|
||||
{
|
||||
};
|
||||
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
|
||||
@@ -68,4 +66,3 @@ class EventProcessor
|
||||
bool m_aborting;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include "Util.h"
|
||||
#include "Common.h"
|
||||
#include "utf8.h"
|
||||
#include "SFMT.h"
|
||||
#include <ace/TSS_T.h>
|
||||
@@ -56,13 +56,13 @@ double rand_chance(void)
|
||||
return sfmtRand->Random() * 100.0;
|
||||
}
|
||||
|
||||
Tokens::Tokens(const std::string &src, const char sep, uint32 vectorReserve)
|
||||
Tokenizer::Tokenizer(const std::string &src, const char sep, uint32 vectorReserve)
|
||||
{
|
||||
m_str = new char[src.length() + 1];
|
||||
memcpy(m_str, src.c_str(), src.length() + 1);
|
||||
|
||||
if (vectorReserve)
|
||||
reserve(vectorReserve);
|
||||
m_storage.reserve(vectorReserve);
|
||||
|
||||
char* posold = m_str;
|
||||
char* posnew = m_str;
|
||||
@@ -71,17 +71,17 @@ Tokens::Tokens(const std::string &src, const char sep, uint32 vectorReserve)
|
||||
{
|
||||
if (*posnew == sep)
|
||||
{
|
||||
push_back(posold);
|
||||
m_storage.push_back(posold);
|
||||
posold = posnew + 1;
|
||||
|
||||
*posnew = 0x00;
|
||||
*posnew = '\0';
|
||||
}
|
||||
else if (*posnew == 0x00)
|
||||
else if (*posnew == '\0')
|
||||
{
|
||||
// Hack like, but the old code accepted these kind of broken strings,
|
||||
// so changing it would break other things
|
||||
if (posold != posnew)
|
||||
push_back(posold);
|
||||
m_storage.push_back(posold);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -471,32 +471,24 @@ void vutf8printf(FILE* out, const char *str, va_list* ap)
|
||||
#endif
|
||||
}
|
||||
|
||||
void hexEncodeByteArray(uint8* bytes, uint32 arrayLen, std::string& result)
|
||||
std::string ByteArrayToHexStr(uint8 const* bytes, uint32 arrayLen, bool reverse /* = false */)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
for (uint32 i=0; i<arrayLen; ++i)
|
||||
{
|
||||
for (uint8 j=0; j<2; ++j)
|
||||
{
|
||||
unsigned char nibble = 0x0F & (bytes[i]>>((1-j)*4));
|
||||
char encodedNibble;
|
||||
if (nibble < 0x0A)
|
||||
encodedNibble = '0'+nibble;
|
||||
else
|
||||
encodedNibble = 'A'+nibble-0x0A;
|
||||
ss << encodedNibble;
|
||||
}
|
||||
}
|
||||
result = ss.str();
|
||||
}
|
||||
int32 init = 0;
|
||||
int32 end = arrayLen;
|
||||
int8 op = 1;
|
||||
|
||||
if (reverse)
|
||||
{
|
||||
init = arrayLen - 1;
|
||||
end = -1;
|
||||
op = -1;
|
||||
}
|
||||
|
||||
std::string ByteArrayToHexStr(uint8* bytes, uint32 length)
|
||||
{
|
||||
std::ostringstream ss;
|
||||
for (uint32 i = 0; i < length; ++i)
|
||||
for (int32 i = init; i != end; i += op)
|
||||
{
|
||||
char buffer[4];
|
||||
sprintf(buffer, "%02X ", bytes[i]);
|
||||
sprintf(buffer, "%02X", bytes[i]);
|
||||
ss << buffer;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,27 +19,49 @@
|
||||
#ifndef _UTIL_H
|
||||
#define _UTIL_H
|
||||
|
||||
#include "Common.h"
|
||||
#include "Containers.h"
|
||||
#include "Define.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
// Searcher for map of structs
|
||||
template<typename T, class S> struct Finder
|
||||
{
|
||||
T val_;
|
||||
T S::* idMember_;
|
||||
|
||||
|
||||
Finder(T val, T S::* idMember) : val_(val), idMember_(idMember) {}
|
||||
bool operator()(const std::pair<int, S> &obj) { return obj.second.*idMember_ == val_; }
|
||||
};
|
||||
|
||||
struct Tokens: public std::vector<char*>
|
||||
class Tokenizer
|
||||
{
|
||||
Tokens(const std::string &src, const char sep, uint32 vectorReserve = 0);
|
||||
~Tokens() { delete[] m_str; }
|
||||
public:
|
||||
typedef std::vector<char const *> StorageType;
|
||||
|
||||
typedef StorageType::size_type size_type;
|
||||
|
||||
typedef StorageType::const_iterator const_iterator;
|
||||
typedef StorageType::reference reference;
|
||||
typedef StorageType::const_reference const_reference;
|
||||
|
||||
public:
|
||||
Tokenizer(const std::string &src, char const sep, uint32 vectorReserve = 0);
|
||||
~Tokenizer() { delete[] m_str; }
|
||||
|
||||
const_iterator begin() const { return m_storage.begin(); }
|
||||
const_iterator end() const { return m_storage.end(); }
|
||||
|
||||
size_type size() const { return m_storage.size(); }
|
||||
|
||||
reference operator [] (size_type i) { return m_storage[i]; }
|
||||
const_reference operator [] (size_type i) const { return m_storage[i]; }
|
||||
|
||||
private:
|
||||
char* m_str;
|
||||
StorageType m_storage;
|
||||
};
|
||||
|
||||
void stripLineInvisibleChars(std::string &src);
|
||||
@@ -49,27 +71,29 @@ uint32 TimeStringToSecs(const std::string& timestring);
|
||||
std::string TimeToTimestampStr(time_t t);
|
||||
|
||||
/* Return a random number in the range min..max; (max-min) must be smaller than 32768. */
|
||||
int32 irand(int32 min, int32 max);
|
||||
int32 irand(int32 min, int32 max);
|
||||
|
||||
/* Return a random number in the range min..max (inclusive). For reliable results, the difference
|
||||
* between max and min should be less than RAND32_MAX. */
|
||||
uint32 urand(uint32 min, uint32 max);
|
||||
uint32 urand(uint32 min, uint32 max);
|
||||
|
||||
/* Return a random number in the range 0 .. RAND32_MAX. */
|
||||
int32 rand32();
|
||||
int32 rand32();
|
||||
|
||||
/* Return a random number in the range min..max */
|
||||
float frand(float min, float max);
|
||||
/* Return a random number in the range min..max */
|
||||
float frand(float min, float max);
|
||||
|
||||
/* Return a random double from 0.0 to 1.0 (exclusive). Floats support only 7 valid decimal digits.
|
||||
* A double supports up to 15 valid decimal digits and is used internally (RAND32_MAX has 10 digits).
|
||||
* With an FPU, there is usually no difference in performance between float and double. */
|
||||
double rand_norm(void);
|
||||
* With an FPU, there is usually no difference in performance between float and double.
|
||||
*/
|
||||
double rand_norm(void);
|
||||
|
||||
/* Return a random double from 0.0 to 99.9999999999999. Floats support only 7 valid decimal digits.
|
||||
* A double supports up to 15 valid decimal digits and is used internally (RAND32_MAX has 10 digits).
|
||||
* With an FPU, there is usually no difference in performance between float and double. */
|
||||
double rand_chance(void);
|
||||
* With an FPU, there is usually no difference in performance between float and double.
|
||||
*/
|
||||
double rand_chance(void);
|
||||
|
||||
/* Return true if a random roll fits in the specified chance (range 0-100). */
|
||||
inline bool roll_chance_f(float chance)
|
||||
@@ -91,58 +115,22 @@ inline void ApplyPercentModFloatVar(float& var, float val, bool apply)
|
||||
}
|
||||
|
||||
// Percentage calculation
|
||||
template <class T>
|
||||
inline T CalculatePctF(T base, float pct)
|
||||
template <class T, class U>
|
||||
inline T CalculatePct(T base, U pct)
|
||||
{
|
||||
return T(base * pct / 100.0f);
|
||||
return T(base * static_cast<float>(pct) / 100.0f);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T CalculatePctN(T base, int32 pct)
|
||||
template <class T, class U>
|
||||
inline T AddPct(T &base, U pct)
|
||||
{
|
||||
return T(base * float(pct) / 100.0f);
|
||||
return base += CalculatePct(base, pct);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T CalculatePctU(T base, uint32 pct)
|
||||
template <class T, class U>
|
||||
inline T ApplyPct(T &base, U pct)
|
||||
{
|
||||
return T(base * float(pct) / 100.0f);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T AddPctF(T& base, float pct)
|
||||
{
|
||||
return base += CalculatePctF(base, pct);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T AddPctN(T& base, int32 pct)
|
||||
{
|
||||
return base += CalculatePctN(base, pct);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T AddPctU(T& base, uint32 pct)
|
||||
{
|
||||
return base += CalculatePctU(base, pct);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T ApplyPctF(T& base, float pct)
|
||||
{
|
||||
return base = CalculatePctF(base, pct);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T ApplyPctN(T& base, int32 pct)
|
||||
{
|
||||
return base = CalculatePctN(base, pct);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline T ApplyPctU(T& base, uint32 pct)
|
||||
{
|
||||
return base = CalculatePctU(base, pct);
|
||||
return base = CalculatePct(base, pct);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@@ -355,8 +343,7 @@ void vutf8printf(FILE* out, const char *str, va_list* ap);
|
||||
bool IsIPAddress(char const* ipaddress);
|
||||
uint32 CreatePIDFile(const std::string& filename);
|
||||
|
||||
void hexEncodeByteArray(uint8* bytes, uint32 arrayLen, std::string& result);
|
||||
std::string ByteArrayToHexStr(uint8* bytes, uint32 length);
|
||||
std::string ByteArrayToHexStr(uint8 const* bytes, uint32 length, bool reverse = false);
|
||||
#endif
|
||||
|
||||
//handler for operations on large flags
|
||||
@@ -404,232 +391,140 @@ class flag96
|
||||
{
|
||||
private:
|
||||
uint32 part[3];
|
||||
|
||||
public:
|
||||
flag96(uint32 p1=0, uint32 p2=0, uint32 p3=0)
|
||||
flag96(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0)
|
||||
{
|
||||
part[0]=p1;
|
||||
part[1]=p2;
|
||||
part[2]=p3;
|
||||
part[0] = p1;
|
||||
part[1] = p2;
|
||||
part[2] = p3;
|
||||
}
|
||||
|
||||
flag96(uint64 p1, uint32 p2)
|
||||
{
|
||||
part[0]=PAIR64_LOPART(p1);
|
||||
part[1]=PAIR64_HIPART(p1);
|
||||
part[2]=p2;
|
||||
part[0] = PAIR64_LOPART(p1);
|
||||
part[1] = PAIR64_HIPART(p1);
|
||||
part[2] = p2;
|
||||
}
|
||||
|
||||
inline bool IsEqual(uint32 p1=0, uint32 p2=0, uint32 p3=0) const
|
||||
inline bool IsEqual(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0) const
|
||||
{
|
||||
return (
|
||||
part[0]==p1 &&
|
||||
part[1]==p2 &&
|
||||
part[2]==p3);
|
||||
};
|
||||
|
||||
inline bool HasFlag(uint32 p1=0, uint32 p2=0, uint32 p3=0) const
|
||||
{
|
||||
return (
|
||||
part[0]&p1 ||
|
||||
part[1]&p2 ||
|
||||
part[2]&p3);
|
||||
};
|
||||
|
||||
inline void Set(uint32 p1=0, uint32 p2=0, uint32 p3=0)
|
||||
{
|
||||
part[0]=p1;
|
||||
part[1]=p2;
|
||||
part[2]=p3;
|
||||
};
|
||||
|
||||
template<class type>
|
||||
inline bool operator < (type & right)
|
||||
{
|
||||
for (uint8 i=3; i > 0; --i)
|
||||
{
|
||||
if (part[i-1]<right.part[i-1])
|
||||
return 1;
|
||||
else if (part[i-1]>right.part[i-1])
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
return (part[0] == p1 && part[1] == p2 && part[2] == p3);
|
||||
}
|
||||
|
||||
template<class type>
|
||||
inline bool operator < (type & right) const
|
||||
inline bool HasFlag(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0) const
|
||||
{
|
||||
return (part[0] & p1 || part[1] & p2 || part[2] & p3);
|
||||
}
|
||||
|
||||
inline void Set(uint32 p1 = 0, uint32 p2 = 0, uint32 p3 = 0)
|
||||
{
|
||||
part[0] = p1;
|
||||
part[1] = p2;
|
||||
part[2] = p3;
|
||||
}
|
||||
|
||||
inline bool operator <(const flag96 &right) const
|
||||
{
|
||||
for (uint8 i = 3; i > 0; --i)
|
||||
{
|
||||
if (part[i-1]<right.part[i-1])
|
||||
return 1;
|
||||
else if (part[i-1]>right.part[i-1])
|
||||
return 0;
|
||||
if (part[i - 1] < right.part[i - 1])
|
||||
return true;
|
||||
else if (part[i - 1] > right.part[i - 1])
|
||||
return false;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class type>
|
||||
inline bool operator != (type & right)
|
||||
{
|
||||
if (part[0]!=right.part[0]
|
||||
|| part[1]!=right.part[1]
|
||||
|| part[2]!=right.part[2])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class type>
|
||||
inline bool operator != (type & right) const
|
||||
inline bool operator ==(const flag96 &right) const
|
||||
{
|
||||
if (part[0]!=right.part[0]
|
||||
|| part[1]!=right.part[1]
|
||||
|| part[2]!=right.part[2])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
template<class type>
|
||||
inline bool operator == (type & right)
|
||||
{
|
||||
if (part[0]!=right.part[0]
|
||||
|| part[1]!=right.part[1]
|
||||
|| part[2]!=right.part[2])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class type>
|
||||
inline bool operator == (type & right) const
|
||||
{
|
||||
if (part[0]!=right.part[0]
|
||||
|| part[1]!=right.part[1]
|
||||
|| part[2]!=right.part[2])
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class type>
|
||||
inline void operator = (type & right)
|
||||
{
|
||||
part[0]=right.part[0];
|
||||
part[1]=right.part[1];
|
||||
part[2]=right.part[2];
|
||||
}
|
||||
|
||||
template<class type>
|
||||
inline flag96 operator & (type & right)
|
||||
{
|
||||
flag96 ret(part[0] & right.part[0], part[1] & right.part[1], part[2] & right.part[2]);
|
||||
return
|
||||
ret;
|
||||
(
|
||||
part[0] == right.part[0] &&
|
||||
part[1] == right.part[1] &&
|
||||
part[2] == right.part[2]
|
||||
);
|
||||
}
|
||||
|
||||
template<class type>
|
||||
inline flag96 operator & (type & right) const
|
||||
inline bool operator !=(const flag96 &right) const
|
||||
{
|
||||
flag96 ret(part[0] & right.part[0], part[1] & right.part[1], part[2] & right.part[2]);
|
||||
return
|
||||
ret;
|
||||
return !this->operator ==(right);
|
||||
}
|
||||
|
||||
template<class type>
|
||||
inline void operator &= (type & right)
|
||||
inline flag96 & operator =(const flag96 &right)
|
||||
{
|
||||
*this=*this & right;
|
||||
part[0] = right.part[0];
|
||||
part[1] = right.part[1];
|
||||
part[2] = right.part[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class type>
|
||||
inline flag96 operator | (type & right)
|
||||
inline flag96 operator &(const flag96 &right) const
|
||||
{
|
||||
flag96 ret(part[0] | right.part[0], part[1] | right.part[1], part[2] | right.part[2]);
|
||||
return
|
||||
ret;
|
||||
return flag96(part[0] & right.part[0], part[1] & right.part[1],
|
||||
part[2] & right.part[2]);
|
||||
}
|
||||
|
||||
template<class type>
|
||||
inline flag96 operator | (type & right) const
|
||||
inline flag96 & operator &=(const flag96 &right)
|
||||
{
|
||||
flag96 ret(part[0] | right.part[0], part[1] | right.part[1], part[2] | right.part[2]);
|
||||
return
|
||||
ret;
|
||||
part[0] &= right.part[0];
|
||||
part[1] &= right.part[1];
|
||||
part[2] &= right.part[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class type>
|
||||
inline void operator |= (type & right)
|
||||
inline flag96 operator |(const flag96 &right) const
|
||||
{
|
||||
*this=*this | right;
|
||||
return flag96(part[0] | right.part[0], part[1] | right.part[1],
|
||||
part[2] | right.part[2]);
|
||||
}
|
||||
|
||||
inline void operator ~ ()
|
||||
inline flag96 & operator |=(const flag96 &right)
|
||||
{
|
||||
part[2]=~part[2];
|
||||
part[1]=~part[1];
|
||||
part[0]=~part[0];
|
||||
};
|
||||
|
||||
template<class type>
|
||||
inline flag96 operator ^ (type & right)
|
||||
{
|
||||
flag96 ret(part[0] ^ right.part[0], part[1] ^ right.part[1], part[2] ^ right.part[2]);
|
||||
return
|
||||
ret;
|
||||
part[0] |= right.part[0];
|
||||
part[1] |= right.part[1];
|
||||
part[2] |= right.part[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class type>
|
||||
inline flag96 operator ^ (type & right) const
|
||||
inline flag96 operator ~() const
|
||||
{
|
||||
flag96 ret(part[0] ^ right.part[0], part[1] ^ right.part[1], part[2] ^ right.part[2]);
|
||||
return
|
||||
ret;
|
||||
return flag96(~part[0], ~part[1], ~part[2]);
|
||||
}
|
||||
|
||||
template<class type>
|
||||
inline void operator ^= (type & right)
|
||||
inline flag96 operator ^(const flag96 &right) const
|
||||
{
|
||||
*this=*this^right;
|
||||
return flag96(part[0] ^ right.part[0], part[1] ^ right.part[1],
|
||||
part[2] ^ right.part[2]);
|
||||
}
|
||||
|
||||
inline flag96 & operator ^=(const flag96 &right)
|
||||
{
|
||||
part[0] ^= right.part[0];
|
||||
part[1] ^= right.part[1];
|
||||
part[2] ^= right.part[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline operator bool() const
|
||||
{
|
||||
return(
|
||||
part[0] != 0 ||
|
||||
part[1] != 0 ||
|
||||
part[2] != 0);
|
||||
};
|
||||
return (part[0] != 0 || part[1] != 0 || part[2] != 0);
|
||||
}
|
||||
|
||||
inline operator bool()
|
||||
inline bool operator !() const
|
||||
{
|
||||
return(
|
||||
part[0] != 0 ||
|
||||
part[1] != 0 ||
|
||||
part[2] != 0);
|
||||
};
|
||||
return !this->operator bool();
|
||||
}
|
||||
|
||||
inline bool operator ! () const
|
||||
inline uint32 & operator [](uint8 el)
|
||||
{
|
||||
return(
|
||||
part[0] == 0 &&
|
||||
part[1] == 0 &&
|
||||
part[2] == 0);
|
||||
};
|
||||
return part[el];
|
||||
}
|
||||
|
||||
inline bool operator ! ()
|
||||
inline const uint32 & operator [](uint8 el) const
|
||||
{
|
||||
return(
|
||||
part[0] == 0 &&
|
||||
part[1] == 0 &&
|
||||
part[2] == 0);
|
||||
};
|
||||
|
||||
inline uint32 & operator[](uint8 el)
|
||||
{
|
||||
return (part[el]);
|
||||
};
|
||||
|
||||
inline uint32 operator[](uint8 el) const
|
||||
{
|
||||
return (part[el]);
|
||||
};
|
||||
return part[el];
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user