refactor(Core/Common): restyle common lib with astyle (#3461)

This commit is contained in:
Kargatum
2020-09-12 03:50:48 +07:00
committed by GitHub
parent e15a493927
commit 3a0b0356ac
101 changed files with 4524 additions and 4418 deletions
+5 -5
View File
@@ -12,12 +12,12 @@
namespace acore namespace acore
{ {
template <class Pointer, class Lock> template <class Pointer, class Lock>
class AutoPtr : public ACE_Strong_Bound_Ptr<Pointer, Lock> class AutoPtr : public ACE_Strong_Bound_Ptr<Pointer, Lock>
{ {
typedef ACE_Strong_Bound_Ptr<Pointer, Lock> Base; typedef ACE_Strong_Bound_Ptr<Pointer, Lock> Base;
public: public:
AutoPtr() AutoPtr()
: Base() : Base()
{ } { }
@@ -35,7 +35,7 @@ public:
{ {
return Base::null(); return Base::null();
} }
}; };
} // namespace acore } // namespace acore
@@ -7,12 +7,12 @@
#include "BoundingIntervalHierarchy.h" #include "BoundingIntervalHierarchy.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#define isnan _isnan #define isnan _isnan
#else #else
#define isnan std::isnan #define isnan std::isnan
#endif #endif
void BIH::buildHierarchy(std::vector<uint32> &tempTree, buildData &dat, BuildStats &stats) void BIH::buildHierarchy(std::vector<uint32>& tempTree, buildData& dat, BuildStats& stats)
{ {
// create space for the first node // create space for the first node
tempTree.push_back(uint32(3 << 30)); // dummy leaf tempTree.push_back(uint32(3 << 30)); // dummy leaf
@@ -26,7 +26,7 @@ void BIH::buildHierarchy(std::vector<uint32> &tempTree, buildData &dat, BuildSta
subdivide(0, dat.numPrims - 1, tempTree, dat, gridBox, nodeBox, 0, 1, stats); subdivide(0, dat.numPrims - 1, tempTree, dat, gridBox, nodeBox, 0, 1, stats);
} }
void BIH::subdivide(int left, int right, std::vector<uint32> &tempTree, buildData &dat, AABound &gridBox, AABound &nodeBox, int nodeIndex, int depth, BuildStats &stats) void BIH::subdivide(int left, int right, std::vector<uint32>& tempTree, buildData& dat, AABound& gridBox, AABound& nodeBox, int nodeIndex, int depth, BuildStats& stats)
{ {
if ((right - left + 1) <= dat.maxPrims || depth >= MAX_STACK_SIZE) if ((right - left + 1) <= dat.maxPrims || depth >= MAX_STACK_SIZE)
{ {
@@ -121,13 +121,15 @@ void BIH::subdivide(int left, int right, std::vector<uint32> &tempTree, buildDat
if (right == rightOrig) if (right == rightOrig)
{ {
// all left // all left
if (prevAxis == axis && G3D::fuzzyEq(prevSplit, split)) { if (prevAxis == axis && G3D::fuzzyEq(prevSplit, split))
{
// we are stuck here - create a leaf // we are stuck here - create a leaf
stats.updateLeaf(depth, right - left + 1); stats.updateLeaf(depth, right - left + 1);
createNode(tempTree, nodeIndex, left, right); createNode(tempTree, nodeIndex, left, right);
return; return;
} }
if (clipL <= split) { if (clipL <= split)
{
// keep looping on left half // keep looping on left half
gridBox.hi[axis] = split; gridBox.hi[axis] = split;
prevClip = clipL; prevClip = clipL;
@@ -140,14 +142,16 @@ void BIH::subdivide(int left, int right, std::vector<uint32> &tempTree, buildDat
else if (left > right) else if (left > right)
{ {
// all right // all right
if (prevAxis == axis && G3D::fuzzyEq(prevSplit, split)) { if (prevAxis == axis && G3D::fuzzyEq(prevSplit, split))
{
// we are stuck here - create a leaf // we are stuck here - create a leaf
stats.updateLeaf(depth, right - left + 1); stats.updateLeaf(depth, right - left + 1);
createNode(tempTree, nodeIndex, left, right); createNode(tempTree, nodeIndex, left, right);
return; return;
} }
right = rightOrig; right = rightOrig;
if (clipR >= split) { if (clipR >= split)
{
// keep looping on right half // keep looping on right half
gridBox.lo[axis] = split; gridBox.lo[axis] = split;
prevClip = clipR; prevClip = clipR;
@@ -169,14 +173,17 @@ void BIH::subdivide(int left, int right, std::vector<uint32> &tempTree, buildDat
tempTree.push_back(0); tempTree.push_back(0);
tempTree.push_back(0); tempTree.push_back(0);
tempTree.push_back(0); tempTree.push_back(0);
if (wasLeft) { if (wasLeft)
{
// create a node with a left child // create a node with a left child
// write leaf node // write leaf node
stats.updateInner(); stats.updateInner();
tempTree[nodeIndex + 0] = (prevAxis << 30) | nextIndex; tempTree[nodeIndex + 0] = (prevAxis << 30) | nextIndex;
tempTree[nodeIndex + 1] = floatToRawIntBits(prevClip); tempTree[nodeIndex + 1] = floatToRawIntBits(prevClip);
tempTree[nodeIndex + 2] = floatToRawIntBits(G3D::inf()); tempTree[nodeIndex + 2] = floatToRawIntBits(G3D::inf());
} else { }
else
{
// create a node with a right child // create a node with a right child
// write leaf node // write leaf node
stats.updateInner(); stats.updateInner();
@@ -198,14 +205,17 @@ void BIH::subdivide(int left, int right, std::vector<uint32> &tempTree, buildDat
// allocate left node // allocate left node
int nl = right - left + 1; int nl = right - left + 1;
int nr = rightOrig - (right + 1) + 1; int nr = rightOrig - (right + 1) + 1;
if (nl > 0) { if (nl > 0)
{
tempTree.push_back(0); tempTree.push_back(0);
tempTree.push_back(0); tempTree.push_back(0);
tempTree.push_back(0); tempTree.push_back(0);
} else }
else
nextIndex -= 3; nextIndex -= 3;
// allocate right node // allocate right node
if (nr > 0) { if (nr > 0)
{
tempTree.push_back(0); tempTree.push_back(0);
tempTree.push_back(0); tempTree.push_back(0);
tempTree.push_back(0); tempTree.push_back(0);
@@ -235,7 +245,7 @@ void BIH::subdivide(int left, int right, std::vector<uint32> &tempTree, buildDat
bool BIH::writeToFile(FILE* wf) const bool BIH::writeToFile(FILE* wf) const
{ {
uint32 treeSize = tree.size(); uint32 treeSize = tree.size();
uint32 check=0, count; uint32 check = 0, count;
check += fwrite(&bounds.low(), sizeof(float), 3, wf); check += fwrite(&bounds.low(), sizeof(float), 3, wf);
check += fwrite(&bounds.high(), sizeof(float), 3, wf); check += fwrite(&bounds.high(), sizeof(float), 3, wf);
check += fwrite(&treeSize, sizeof(uint32), 1, wf); check += fwrite(&treeSize, sizeof(uint32), 1, wf);
@@ -250,7 +260,7 @@ bool BIH::readFromFile(FILE* rf)
{ {
uint32 treeSize; uint32 treeSize;
G3D::Vector3 lo, hi; G3D::Vector3 lo, hi;
uint32 check=0, count=0; uint32 check = 0, count = 0;
check += fread(&lo, sizeof(float), 3, rf); check += fread(&lo, sizeof(float), 3, rf);
check += fread(&hi, sizeof(float), 3, rf); check += fread(&hi, sizeof(float), 3, rf);
bounds = G3D::AABox(lo, hi); bounds = G3D::AABox(lo, hi);
@@ -54,7 +54,7 @@ struct AABound
class BIH class BIH
{ {
private: private:
void init_empty() void init_empty()
{ {
tree.clear(); tree.clear();
@@ -63,10 +63,10 @@ class BIH
tree.push_back(3u << 30u); // dummy leaf tree.push_back(3u << 30u); // dummy leaf
tree.insert(tree.end(), 2, 0); tree.insert(tree.end(), 2, 0);
} }
public: public:
BIH() { init_empty(); } BIH() { init_empty(); }
template< class BoundsFunc, class PrimArray > template< class BoundsFunc, class PrimArray >
void build(const PrimArray &primitives, BoundsFunc &getBounds, uint32 leafSize = 3, bool printStats=false) void build(const PrimArray& primitives, BoundsFunc& getBounds, uint32 leafSize = 3, bool printStats = false)
{ {
if (primitives.size() == 0) if (primitives.size() == 0)
{ {
@@ -80,7 +80,7 @@ class BIH
dat.indices = new uint32[dat.numPrims]; dat.indices = new uint32[dat.numPrims];
dat.primBound = new G3D::AABox[dat.numPrims]; dat.primBound = new G3D::AABox[dat.numPrims];
getBounds(primitives[0], bounds); getBounds(primitives[0], bounds);
for (uint32 i=0; i<dat.numPrims; ++i) for (uint32 i = 0; i < dat.numPrims; ++i)
{ {
dat.indices[i] = i; dat.indices[i] = i;
getBounds(primitives[i], dat.primBound[i]); getBounds(primitives[i], dat.primBound[i]);
@@ -93,7 +93,7 @@ class BIH
stats.printStats(); stats.printStats();
objects.resize(dat.numPrims); objects.resize(dat.numPrims);
for (uint32 i=0; i<dat.numPrims; ++i) for (uint32 i = 0; i < dat.numPrims; ++i)
objects[i] = dat.indices[i]; objects[i] = dat.indices[i];
//nObjects = dat.numPrims; //nObjects = dat.numPrims;
tree = tempTree; tree = tempTree;
@@ -103,14 +103,14 @@ class BIH
uint32 primCount() const { return objects.size(); } uint32 primCount() const { return objects.size(); }
template<typename RayCallback> template<typename RayCallback>
void intersectRay(const G3D::Ray &r, RayCallback& intersectCallback, float &maxDist, bool stopAtFirstHit) const void intersectRay(const G3D::Ray& r, RayCallback& intersectCallback, float& maxDist, bool stopAtFirstHit) const
{ {
float intervalMin = -1.f; float intervalMin = -1.f;
float intervalMax = -1.f; float intervalMax = -1.f;
G3D::Vector3 org = r.origin(); G3D::Vector3 org = r.origin();
G3D::Vector3 dir = r.direction(); G3D::Vector3 dir = r.direction();
G3D::Vector3 invDir; G3D::Vector3 invDir;
for (int i=0; i<3; ++i) for (int i = 0; i < 3; ++i)
{ {
invDir[i] = 1.f / dir[i]; invDir[i] = 1.f / dir[i];
if (G3D::fuzzyNe(dir[i], 0.0f)) if (G3D::fuzzyNe(dir[i], 0.0f))
@@ -141,7 +141,7 @@ class BIH
uint32 offsetBack3[3]; uint32 offsetBack3[3];
// compute custom offsets from direction sign bit // compute custom offsets from direction sign bit
for (int i=0; i<3; ++i) for (int i = 0; i < 3; ++i)
{ {
offsetFront[i] = floatToRawIntBits(dir[i]) >> 31; offsetFront[i] = floatToRawIntBits(dir[i]) >> 31;
offsetBack[i] = offsetFront[i] ^ 1; offsetBack[i] = offsetFront[i] ^ 1;
@@ -157,7 +157,8 @@ class BIH
int stackPos = 0; int stackPos = 0;
int node = 0; int node = 0;
while (true) { while (true)
{
while (true) while (true)
{ {
uint32 tn = tree[node]; uint32 tn = tree[node];
@@ -177,13 +178,15 @@ class BIH
int back = offset + offsetBack3[axis]; int back = offset + offsetBack3[axis];
node = back; node = back;
// ray passes through far node only // ray passes through far node only
if (tf < intervalMin) { if (tf < intervalMin)
{
intervalMin = (tb >= intervalMin) ? tb : intervalMin; intervalMin = (tb >= intervalMin) ? tb : intervalMin;
continue; continue;
} }
node = offset + offsetFront3[axis]; // front node = offset + offsetFront3[axis]; // front
// ray passes through near node only // ray passes through near node only
if (tb > intervalMax) { if (tb > intervalMax)
{
intervalMax = (tf <= intervalMax) ? tf : intervalMax; intervalMax = (tf <= intervalMax) ? tf : intervalMax;
continue; continue;
} }
@@ -201,7 +204,8 @@ class BIH
{ {
// leaf - test some objects // leaf - test some objects
int n = tree[node + 1]; int n = tree[node + 1];
while (n > 0) { while (n > 0)
{
bool hit = intersectCallback(r, objects[offset], maxDist, stopAtFirstHit); bool hit = intersectCallback(r, objects[offset], maxDist, stopAtFirstHit);
if (stopAtFirstHit && hit) return; if (stopAtFirstHit && hit) return;
--n; --n;
@@ -212,7 +216,7 @@ class BIH
} }
else else
{ {
if (axis>2) if (axis > 2)
return; // should not happen return; // should not happen
float tf = (intBitsToFloat(tree[node + offsetFront[axis]]) - org[axis]) * invDir[axis]; float tf = (intBitsToFloat(tree[node + offsetFront[axis]]) - org[axis]) * invDir[axis];
float tb = (intBitsToFloat(tree[node + offsetBack[axis]]) - org[axis]) * invDir[axis]; float tb = (intBitsToFloat(tree[node + offsetBack[axis]]) - org[axis]) * invDir[axis];
@@ -242,7 +246,7 @@ class BIH
} }
template<typename IsectCallback> template<typename IsectCallback>
void intersectPoint(const G3D::Vector3 &p, IsectCallback& intersectCallback) const void intersectPoint(const G3D::Vector3& p, IsectCallback& intersectCallback) const
{ {
if (!bounds.contains(p)) if (!bounds.contains(p))
return; return;
@@ -251,7 +255,8 @@ class BIH
int stackPos = 0; int stackPos = 0;
int node = 0; int node = 0;
while (true) { while (true)
{
while (true) while (true)
{ {
uint32 tn = tree[node]; uint32 tn = tree[node];
@@ -271,12 +276,14 @@ class BIH
int right = offset + 3; int right = offset + 3;
node = right; node = right;
// point is in right node only // point is in right node only
if (tl < p[axis]) { if (tl < p[axis])
{
continue; continue;
} }
node = offset; // left node = offset; // left
// point is in left node only // point is in left node only
if (tr > p[axis]) { if (tr > p[axis])
{
continue; continue;
} }
// point is in both nodes // point is in both nodes
@@ -289,7 +296,8 @@ class BIH
{ {
// leaf - test some objects // leaf - test some objects
int n = tree[node + 1]; int n = tree[node + 1];
while (n > 0) { while (n > 0)
{
intersectCallback(p, objects[offset]); // !!! intersectCallback(p, objects[offset]); // !!!
--n; --n;
++offset; ++offset;
@@ -299,7 +307,7 @@ class BIH
} }
else // BVH2 node (empty space cut off left and right) else // BVH2 node (empty space cut off left and right)
{ {
if (axis>2) if (axis > 2)
return; // should not happen return; // should not happen
float tl = intBitsToFloat(tree[node + 1]); float tl = intBitsToFloat(tree[node + 1]);
float tr = intBitsToFloat(tree[node + 2]); float tr = intBitsToFloat(tree[node + 2]);
@@ -322,15 +330,15 @@ class BIH
bool writeToFile(FILE* wf) const; bool writeToFile(FILE* wf) const;
bool readFromFile(FILE* rf); bool readFromFile(FILE* rf);
protected: protected:
std::vector<uint32> tree; std::vector<uint32> tree;
std::vector<uint32> objects; std::vector<uint32> objects;
G3D::AABox bounds; G3D::AABox bounds;
struct buildData struct buildData
{ {
uint32 *indices; uint32* indices;
G3D::AABox *primBound; G3D::AABox* primBound;
uint32 numPrims; uint32 numPrims;
int maxPrims; int maxPrims;
}; };
@@ -361,7 +369,7 @@ class BIH
maxObjects(0xFFFFFFFF), sumDepth(0), minDepth(0x0FFFFFFF), maxObjects(0xFFFFFFFF), sumDepth(0), minDepth(0x0FFFFFFF),
maxDepth(0xFFFFFFFF), numBVH2(0) maxDepth(0xFFFFFFFF), numBVH2(0)
{ {
for (int i=0; i<6; ++i) numLeavesN[i] = 0; for (int i = 0; i < 6; ++i) numLeavesN[i] = 0;
} }
void updateInner() { numNodes++; } void updateInner() { numNodes++; }
@@ -370,16 +378,16 @@ class BIH
void printStats(); void printStats();
}; };
void buildHierarchy(std::vector<uint32> &tempTree, buildData &dat, BuildStats &stats); void buildHierarchy(std::vector<uint32>& tempTree, buildData& dat, BuildStats& stats);
void createNode(std::vector<uint32> &tempTree, int nodeIndex, uint32 left, uint32 right) const void createNode(std::vector<uint32>& tempTree, int nodeIndex, uint32 left, uint32 right) const
{ {
// write leaf node // write leaf node
tempTree[nodeIndex + 0] = (3 << 30) | left; tempTree[nodeIndex + 0] = (3 << 30) | left;
tempTree[nodeIndex + 1] = right - left + 1; tempTree[nodeIndex + 1] = right - left + 1;
} }
void subdivide(int left, int right, std::vector<uint32> &tempTree, buildData &dat, AABound &gridBox, AABound &nodeBox, int nodeIndex, int depth, BuildStats &stats); void subdivide(int left, int right, std::vector<uint32>& tempTree, buildData& dat, AABound& gridBox, AABound& nodeBox, int nodeIndex, int depth, BuildStats& stats);
}; };
#endif // _BIH_H #endif // _BIH_H
@@ -66,7 +66,7 @@ public:
{ {
++unbalanced_times; ++unbalanced_times;
uint32 Idx = 0; uint32 Idx = 0;
const T * temp; const T* temp;
if (m_obj2Idx.getRemove(&obj, temp, Idx)) if (m_obj2Idx.getRemove(&obj, temp, Idx))
m_objects[Idx] = NULL; m_objects[Idx] = NULL;
else else
+13 -9
View File
@@ -21,21 +21,25 @@
using VMAP::ModelInstance; using VMAP::ModelInstance;
namespace { namespace
{
int CHECK_TREE_PERIOD = 200; int CHECK_TREE_PERIOD = 200;
} // namespace } // namespace
template<> struct HashTrait< GameObjectModel>{ template<> struct HashTrait< GameObjectModel>
{
static size_t hashCode(const GameObjectModel& g) { return (size_t)(void*)&g; } static size_t hashCode(const GameObjectModel& g) { return (size_t)(void*)&g; }
}; };
template<> struct PositionTrait< GameObjectModel> { template<> struct PositionTrait< GameObjectModel>
{
static void getPosition(const GameObjectModel& g, G3D::Vector3& p) { p = g.getPosition(); } static void getPosition(const GameObjectModel& g, G3D::Vector3& p) { p = g.getPosition(); }
}; };
template<> struct BoundsTrait< GameObjectModel> { template<> struct BoundsTrait< GameObjectModel>
{
static void getBounds(const GameObjectModel& g, G3D::AABox& out) { out = g.getBounds();} static void getBounds(const GameObjectModel& g, G3D::AABox& out) { out = g.getBounds();}
static void getBounds2(const GameObjectModel* g, G3D::AABox& out) { out = g->getBounds();} static void getBounds2(const GameObjectModel* g, G3D::AABox& out) { out = g->getBounds();}
}; };
@@ -172,7 +176,7 @@ bool DynamicMapTree::getObjectHitPos(const uint32 phasemask, const G3D::Vector3&
resultHit = endPos; resultHit = endPos;
return false; return false;
} }
G3D::Vector3 dir = (endPos - startPos)/maxDist; // direction with length of 1 G3D::Vector3 dir = (endPos - startPos) / maxDist; // direction with length of 1
G3D::Ray ray(startPos, dir); G3D::Ray ray(startPos, dir);
float dist = maxDist; float dist = maxDist;
if (getIntersectionTime(phasemask, ray, endPos, dist)) if (getIntersectionTime(phasemask, ray, endPos, dist))
@@ -181,12 +185,12 @@ bool DynamicMapTree::getObjectHitPos(const uint32 phasemask, const G3D::Vector3&
if (modifyDist < 0) if (modifyDist < 0)
{ {
if ((resultHit - startPos).magnitude() > -modifyDist) if ((resultHit - startPos).magnitude() > -modifyDist)
resultHit = resultHit + dir*modifyDist; resultHit = resultHit + dir * modifyDist;
else else
resultHit = startPos; resultHit = startPos;
} }
else else
resultHit = resultHit + dir*modifyDist; resultHit = resultHit + dir * modifyDist;
result = true; result = true;
} }
@@ -207,7 +211,7 @@ bool DynamicMapTree::isInLineOfSight(float x1, float y1, float z1, float x2, flo
if (!G3D::fuzzyGt(maxDist, 0) ) if (!G3D::fuzzyGt(maxDist, 0) )
return true; return true;
G3D::Ray r(v1, (v2-v1) / maxDist); G3D::Ray r(v1, (v2 - v1) / maxDist);
DynamicTreeIntersectionCallback callback(phasemask); DynamicTreeIntersectionCallback callback(phasemask);
impl->intersectRay(r, callback, maxDist, v2, true); impl->intersectRay(r, callback, maxDist, v2, true);
+1 -1
View File
@@ -20,7 +20,7 @@ struct DynTreeImpl;
class DynamicMapTree class DynamicMapTree
{ {
DynTreeImpl *impl; DynTreeImpl* impl;
public: public:
@@ -26,8 +26,8 @@ namespace VMAP
VMAP_LOAD_RESULT_IGNORED VMAP_LOAD_RESULT_IGNORED
}; };
#define VMAP_INVALID_HEIGHT -100000.0f // for check #define VMAP_INVALID_HEIGHT -100000.0f // for check
#define VMAP_INVALID_HEIGHT_VALUE -200000.0f // real assigned value in unknown height case #define VMAP_INVALID_HEIGHT_VALUE -200000.0f // real assigned value in unknown height case
//=========================================================== //===========================================================
class IVMapManager class IVMapManager
@@ -54,11 +54,11 @@ namespace VMAP
test if we hit an object. return true if we hit one. rx, ry, rz will hold the hit position or the dest position, if no intersection was found test if we hit an object. return true if we hit one. rx, ry, rz will hold the hit position or the dest position, if no intersection was found
return a position, that is pReduceDist closer to the origin return a position, that is pReduceDist closer to the origin
*/ */
virtual bool getObjectHitPos(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float &ry, float& rz, float pModifyDist) = 0; virtual bool getObjectHitPos(unsigned int pMapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float& ry, float& rz, float pModifyDist) = 0;
/** /**
send debug commands send debug commands
*/ */
virtual bool processCommand(char *pCommand)= 0; virtual bool processCommand(char* pCommand) = 0;
/** /**
Enable/disable LOS calculation Enable/disable LOS calculation
@@ -75,13 +75,13 @@ namespace VMAP
bool isHeightCalcEnabled() const { return(iEnableHeightCalc); } bool isHeightCalcEnabled() const { return(iEnableHeightCalc); }
bool isMapLoadingEnabled() const { return(iEnableLineOfSightCalc || iEnableHeightCalc ); } bool isMapLoadingEnabled() const { return(iEnableLineOfSightCalc || iEnableHeightCalc ); }
virtual std::string getDirFileName(unsigned int pMapId, int x, int y) const =0; virtual std::string getDirFileName(unsigned int pMapId, int x, int y) const = 0;
/** /**
Query world model area info. Query world model area info.
\param z gets adjusted to the ground height for which this are info is valid \param z gets adjusted to the ground height for which this are info is valid
*/ */
virtual bool getAreaInfo(unsigned int pMapId, float x, float y, float &z, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const=0; virtual bool getAreaInfo(unsigned int pMapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const = 0;
virtual bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float &level, float &floor, uint32 &type) const=0; virtual bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 ReqLiquidType, float& level, float& floor, uint32& type) const = 0;
}; };
} }
@@ -12,7 +12,7 @@ namespace MMAP
{ {
// ######################## MMapFactory ######################## // ######################## MMapFactory ########################
// our global singleton copy // our global singleton copy
MMapManager *g_MMapManager = NULL; MMapManager* g_MMapManager = NULL;
bool MMapFactory::forbiddenMaps[1000] = {0}; bool MMapFactory::forbiddenMaps[1000] = {0};
MMapManager* MMapFactory::createOrGetMMapManager() MMapManager* MMapFactory::createOrGetMMapManager()
@@ -27,9 +27,9 @@ namespace MMAP
return true; return true;
// load and init dtNavMesh - read parameters from file // load and init dtNavMesh - read parameters from file
uint32 pathLen = sWorld->GetDataPath().length() + strlen("mmaps/%03i.mmap")+1; uint32 pathLen = sWorld->GetDataPath().length() + strlen("mmaps/%03i.mmap") + 1;
char *fileName = new char[pathLen]; char* fileName = new char[pathLen];
snprintf(fileName, pathLen, (sWorld->GetDataPath()+"mmaps/%03i.mmap").c_str(), mapId); snprintf(fileName, pathLen, (sWorld->GetDataPath() + "mmaps/%03i.mmap").c_str(), mapId);
FILE* file = fopen(fileName, "rb"); FILE* file = fopen(fileName, "rb");
if (!file) if (!file)
@@ -112,11 +112,11 @@ namespace MMAP
} }
// load this tile :: mmaps/MMMXXYY.mmtile // load this tile :: mmaps/MMMXXYY.mmtile
uint32 pathLen = sWorld->GetDataPath().length() + strlen("mmaps/%03i%02i%02i.mmtile")+1; uint32 pathLen = sWorld->GetDataPath().length() + strlen("mmaps/%03i%02i%02i.mmtile") + 1;
char *fileName = new char[pathLen]; char* fileName = new char[pathLen];
snprintf(fileName, pathLen, (sWorld->GetDataPath()+"mmaps/%03i%02i%02i.mmtile").c_str(), mapId, x, y); snprintf(fileName, pathLen, (sWorld->GetDataPath() + "mmaps/%03i%02i%02i.mmtile").c_str(), mapId, x, y);
FILE *file = fopen(fileName, "rb"); FILE* file = fopen(fileName, "rb");
if (!file) if (!file)
{ {
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS)
@@ -16,7 +16,7 @@ namespace VMAP
IVMapManager* VMapFactory::createOrGetVMapManager() IVMapManager* VMapFactory::createOrGetVMapManager()
{ {
if (gVMapManager == 0) if (gVMapManager == 0)
gVMapManager= new VMapManager2(); // should be taken from config ... Please change if you like :-) gVMapManager = new VMapManager2(); // should be taken from config ... Please change if you like :-)
return gVMapManager; return gVMapManager;
} }
@@ -158,7 +158,7 @@ namespace VMAP
get the hit position and return true if we hit something get the hit position and return true if we hit something
otherwise the result pos will be the dest pos otherwise the result pos will be the dest pos
*/ */
bool VMapManager2::getObjectHitPos(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float &ry, float& rz, float modifyDist) bool VMapManager2::getObjectHitPos(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float& ry, float& rz, float modifyDist)
{ {
#if defined(ENABLE_EXTRAS) && defined(ENABLE_VMAP_CHECKS) #if defined(ENABLE_EXTRAS) && defined(ENABLE_VMAP_CHECKS)
if (isLineOfSightCalcEnabled() && !DisableMgr::IsDisabledFor(DISABLE_TYPE_VMAP, mapId, NULL, VMAP_DISABLE_LOS)) if (isLineOfSightCalcEnabled() && !DisableMgr::IsDisabledFor(DISABLE_TYPE_VMAP, mapId, NULL, VMAP_DISABLE_LOS))
@@ -283,7 +283,7 @@ namespace VMAP
return model->second.getModel(); return model->second.getModel();
} }
void VMapManager2::releaseModelInstance(const std::string &filename) void VMapManager2::releaseModelInstance(const std::string& filename)
{ {
//! Critical section, thread safe access to iLoadedModelFiles //! Critical section, thread safe access to iLoadedModelFiles
ACORE_GUARD(ACE_Thread_Mutex, LoadedModelFilesLock); ACORE_GUARD(ACE_Thread_Mutex, LoadedModelFilesLock);
@@ -114,7 +114,7 @@ namespace VMAP
} }
virtual bool existsMap(const char* basePath, unsigned int mapId, int x, int y); virtual bool existsMap(const char* basePath, unsigned int mapId, int x, int y);
public: public:
void getInstanceMapTree(InstanceTreeMap &instanceMapTree); void getInstanceMapTree(InstanceTreeMap& instanceMapTree);
typedef uint32(*GetLiquidFlagsFn)(uint32 liquidType); typedef uint32(*GetLiquidFlagsFn)(uint32 liquidType);
GetLiquidFlagsFn GetLiquidFlagsPtr; GetLiquidFlagsFn GetLiquidFlagsPtr;
+18 -18
View File
@@ -57,7 +57,7 @@ namespace VMAP
class LocationInfoCallback class LocationInfoCallback
{ {
public: public:
LocationInfoCallback(ModelInstance* val, LocationInfo &info): prims(val), locInfo(info), result(false) {} LocationInfoCallback(ModelInstance* val, LocationInfo& info): prims(val), locInfo(info), result(false) {}
void operator()(const Vector3& point, uint32 entry) void operator()(const Vector3& point, uint32 entry)
{ {
#if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) && defined(VMAP_DEBUG) #if defined(ENABLE_EXTRAS) && defined(ENABLE_EXTRA_LOGS) && defined(VMAP_DEBUG)
@@ -68,7 +68,7 @@ namespace VMAP
} }
ModelInstance* prims; ModelInstance* prims;
LocationInfo &locInfo; LocationInfo& locInfo;
bool result; bool result;
}; };
@@ -84,7 +84,7 @@ namespace VMAP
return tilefilename.str(); return tilefilename.str();
} }
bool StaticMapTree::getAreaInfo(Vector3 &pos, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const bool StaticMapTree::getAreaInfo(Vector3& pos, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const
{ {
AreaInfoCallback intersectionCallBack(iTreeValues); AreaInfoCallback intersectionCallBack(iTreeValues);
iTree.intersectPoint(pos, intersectionCallBack); iTree.intersectPoint(pos, intersectionCallBack);
@@ -100,17 +100,17 @@ namespace VMAP
return false; return false;
} }
bool StaticMapTree::GetLocationInfo(const Vector3 &pos, LocationInfo &info) const bool StaticMapTree::GetLocationInfo(const Vector3& pos, LocationInfo& info) const
{ {
LocationInfoCallback intersectionCallBack(iTreeValues, info); LocationInfoCallback intersectionCallBack(iTreeValues, info);
iTree.intersectPoint(pos, intersectionCallBack); iTree.intersectPoint(pos, intersectionCallBack);
return intersectionCallBack.result; return intersectionCallBack.result;
} }
StaticMapTree::StaticMapTree(uint32 mapID, const std::string &basePath) StaticMapTree::StaticMapTree(uint32 mapID, const std::string& basePath)
: iMapID(mapID), iIsTiled(false), iTreeValues(0), iBasePath(basePath) : iMapID(mapID), iIsTiled(false), iTreeValues(0), iBasePath(basePath)
{ {
if (iBasePath.length() > 0 && iBasePath[iBasePath.length()-1] != '/' && iBasePath[iBasePath.length()-1] != '\\') if (iBasePath.length() > 0 && iBasePath[iBasePath.length() - 1] != '/' && iBasePath[iBasePath.length() - 1] != '\\')
{ {
iBasePath.push_back('/'); iBasePath.push_back('/');
} }
@@ -129,7 +129,7 @@ namespace VMAP
Else, pMaxDist is not modified and returns false; Else, pMaxDist is not modified and returns false;
*/ */
bool StaticMapTree::getIntersectionTime(const G3D::Ray& pRay, float &pMaxDist, bool StopAtFirstHit) const bool StaticMapTree::getIntersectionTime(const G3D::Ray& pRay, float& pMaxDist, bool StopAtFirstHit) const
{ {
float distance = pMaxDist; float distance = pMaxDist;
MapRayCallback intersectionCallBack(iTreeValues); MapRayCallback intersectionCallBack(iTreeValues);
@@ -153,7 +153,7 @@ namespace VMAP
if (maxDist < 1e-10f) if (maxDist < 1e-10f)
return true; return true;
// direction with length of 1 // direction with length of 1
G3D::Ray ray = G3D::Ray::fromOriginAndDirection(pos1, (pos2 - pos1)/maxDist); G3D::Ray ray = G3D::Ray::fromOriginAndDirection(pos1, (pos2 - pos1) / maxDist);
if (getIntersectionTime(ray, maxDist, true)) if (getIntersectionTime(ray, maxDist, true))
return false; return false;
@@ -167,7 +167,7 @@ namespace VMAP
bool StaticMapTree::getObjectHitPos(const Vector3& pPos1, const Vector3& pPos2, Vector3& pResultHitPos, float pModifyDist) const bool StaticMapTree::getObjectHitPos(const Vector3& pPos1, const Vector3& pPos2, Vector3& pResultHitPos, float pModifyDist) const
{ {
bool result=false; bool result = false;
float maxDist = (pPos2 - pPos1).magnitude(); float maxDist = (pPos2 - pPos1).magnitude();
// valid map coords should *never ever* produce float overflow, but this would produce NaNs too // valid map coords should *never ever* produce float overflow, but this would produce NaNs too
ASSERT(maxDist < std::numeric_limits<float>::max()); ASSERT(maxDist < std::numeric_limits<float>::max());
@@ -177,7 +177,7 @@ namespace VMAP
pResultHitPos = pPos2; pResultHitPos = pPos2;
return false; return false;
} }
Vector3 dir = (pPos2 - pPos1)/maxDist; // direction with length of 1 Vector3 dir = (pPos2 - pPos1) / maxDist; // direction with length of 1
G3D::Ray ray(pPos1, dir); G3D::Ray ray(pPos1, dir);
float dist = maxDist; float dist = maxDist;
if (getIntersectionTime(ray, dist, false)) if (getIntersectionTime(ray, dist, false))
@@ -187,7 +187,7 @@ namespace VMAP
{ {
if ((pResultHitPos - pPos1).magnitude() > -pModifyDist) if ((pResultHitPos - pPos1).magnitude() > -pModifyDist)
{ {
pResultHitPos = pResultHitPos + dir*pModifyDist; pResultHitPos = pResultHitPos + dir * pModifyDist;
} }
else else
{ {
@@ -196,7 +196,7 @@ namespace VMAP
} }
else else
{ {
pResultHitPos = pResultHitPos + dir*pModifyDist; pResultHitPos = pResultHitPos + dir * pModifyDist;
} }
result = true; result = true;
} }
@@ -225,10 +225,10 @@ namespace VMAP
//========================================================= //=========================================================
bool StaticMapTree::CanLoadMap(const std::string &vmapPath, uint32 mapID, uint32 tileX, uint32 tileY) bool StaticMapTree::CanLoadMap(const std::string& vmapPath, uint32 mapID, uint32 tileX, uint32 tileY)
{ {
std::string basePath = vmapPath; std::string basePath = vmapPath;
if (basePath.length() > 0 && basePath[basePath.length()-1] != '/' && basePath[basePath.length()-1] != '\\') if (basePath.length() > 0 && basePath[basePath.length() - 1] != '/' && basePath[basePath.length() - 1] != '\\')
basePath.push_back('/'); basePath.push_back('/');
std::string fullname = basePath + VMapManager2::getMapFileName(mapID); std::string fullname = basePath + VMapManager2::getMapFileName(mapID);
bool success = true; bool success = true;
@@ -262,7 +262,7 @@ namespace VMAP
//========================================================= //=========================================================
bool StaticMapTree::InitMap(const std::string &fname, VMapManager2* vm) bool StaticMapTree::InitMap(const std::string& fname, VMapManager2* vm)
{ {
//VMAP_DEBUG_LOG(LOG_FILTER_MAPS, "StaticMapTree::InitMap() : initializing StaticMapTree '%s'", fname.c_str()); //VMAP_DEBUG_LOG(LOG_FILTER_MAPS, "StaticMapTree::InitMap() : initializing StaticMapTree '%s'", fname.c_str());
bool success = false; bool success = false;
@@ -354,7 +354,7 @@ namespace VMAP
uint32 numSpawns = 0; uint32 numSpawns = 0;
if (result && fread(&numSpawns, sizeof(uint32), 1, tf) != 1) if (result && fread(&numSpawns, sizeof(uint32), 1, tf) != 1)
result = false; result = false;
for (uint32 i=0; i<numSpawns && result; ++i) for (uint32 i = 0; i < numSpawns && result; ++i)
{ {
// read model spawns // read model spawns
ModelSpawn spawn; ModelSpawn spawn;
@@ -423,14 +423,14 @@ namespace VMAP
FILE* tf = fopen(tilefile.c_str(), "rb"); FILE* tf = fopen(tilefile.c_str(), "rb");
if (tf) if (tf)
{ {
bool result=true; bool result = true;
char chunk[8]; char chunk[8];
if (!readChunk(tf, chunk, VMAP_MAGIC, 8)) if (!readChunk(tf, chunk, VMAP_MAGIC, 8))
result = false; result = false;
uint32 numSpawns; uint32 numSpawns;
if (fread(&numSpawns, sizeof(uint32), 1, tf) != 1) if (fread(&numSpawns, sizeof(uint32), 1, tf) != 1)
result = false; result = false;
for (uint32 i=0; i<numSpawns && result; ++i) for (uint32 i = 0; i < numSpawns && result; ++i)
{ {
// read model spawns // read model spawns
ModelSpawn spawn; ModelSpawn spawn;
+9 -9
View File
@@ -45,30 +45,30 @@ namespace VMAP
std::string iBasePath; std::string iBasePath;
private: private:
bool getIntersectionTime(const G3D::Ray& pRay, float &pMaxDist, bool StopAtFirstHit) const; bool getIntersectionTime(const G3D::Ray& pRay, float& pMaxDist, bool StopAtFirstHit) const;
//bool containsLoadedMapTile(unsigned int pTileIdent) const { return(iLoadedMapTiles.containsKey(pTileIdent)); } //bool containsLoadedMapTile(unsigned int pTileIdent) const { return(iLoadedMapTiles.containsKey(pTileIdent)); }
public: public:
static std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY); static std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY);
static uint32 packTileID(uint32 tileX, uint32 tileY) { return tileX<<16 | tileY; } static uint32 packTileID(uint32 tileX, uint32 tileY) { return tileX << 16 | tileY; }
static void unpackTileID(uint32 ID, uint32 &tileX, uint32 &tileY) { tileX = ID>>16; tileY = ID&0xFF; } static void unpackTileID(uint32 ID, uint32& tileX, uint32& tileY) { tileX = ID >> 16; tileY = ID & 0xFF; }
static bool CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY); static bool CanLoadMap(const std::string& basePath, uint32 mapID, uint32 tileX, uint32 tileY);
StaticMapTree(uint32 mapID, const std::string &basePath); StaticMapTree(uint32 mapID, const std::string& basePath);
~StaticMapTree(); ~StaticMapTree();
bool isInLineOfSight(const G3D::Vector3& pos1, const G3D::Vector3& pos2) const; bool isInLineOfSight(const G3D::Vector3& pos1, const G3D::Vector3& pos2) const;
bool getObjectHitPos(const G3D::Vector3& pos1, const G3D::Vector3& pos2, G3D::Vector3& pResultHitPos, float pModifyDist) const; bool getObjectHitPos(const G3D::Vector3& pos1, const G3D::Vector3& pos2, G3D::Vector3& pResultHitPos, float pModifyDist) const;
float getHeight(const G3D::Vector3& pPos, float maxSearchDist) const; float getHeight(const G3D::Vector3& pPos, float maxSearchDist) const;
bool getAreaInfo(G3D::Vector3 &pos, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const; bool getAreaInfo(G3D::Vector3& pos, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const;
bool GetLocationInfo(const G3D::Vector3 &pos, LocationInfo &info) const; bool GetLocationInfo(const G3D::Vector3& pos, LocationInfo& info) const;
bool InitMap(const std::string &fname, VMapManager2* vm); bool InitMap(const std::string& fname, VMapManager2* vm);
void UnloadMap(VMapManager2* vm); void UnloadMap(VMapManager2* vm);
bool LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm); bool LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm);
void UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm); void UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm);
bool isTiled() const { return iIsTiled; } bool isTiled() const { return iIsTiled; }
uint32 numLoadedTiles() const { return iLoadedTiles.size(); } uint32 numLoadedTiles() const { return iLoadedTiles.size(); }
void getModelInstances(ModelInstance* &models, uint32 &count); void getModelInstances(ModelInstance*& models, uint32& count);
}; };
struct AreaInfo struct AreaInfo
+37 -37
View File
@@ -22,12 +22,12 @@ using std::pair;
template<> struct BoundsTrait<VMAP::ModelSpawn*> template<> struct BoundsTrait<VMAP::ModelSpawn*>
{ {
static void getBounds(const VMAP::ModelSpawn* const &obj, G3D::AABox& out) { out = obj->getBounds(); } static void getBounds(const VMAP::ModelSpawn* const& obj, G3D::AABox& out) { out = obj->getBounds(); }
}; };
namespace VMAP namespace VMAP
{ {
bool readChunk(FILE* rf, char *dest, const char *compare, uint32 len) bool readChunk(FILE* rf, char* dest, const char* compare, uint32 len)
{ {
if (fread(dest, sizeof(char), len, rf) != len) return false; if (fread(dest, sizeof(char), len, rf) != len) return false;
return memcmp(dest, compare, len) == 0; return memcmp(dest, compare, len) == 0;
@@ -79,7 +79,7 @@ namespace VMAP
{ {
/// @todo remove extractor hack and uncomment below line: /// @todo remove extractor hack and uncomment below line:
//entry->second.iPos += Vector3(533.33333f*32, 533.33333f*32, 0.f); //entry->second.iPos += Vector3(533.33333f*32, 533.33333f*32, 0.f);
entry->second.iBound = entry->second.iBound + Vector3(533.33333f*32, 533.33333f*32, 0.f); entry->second.iBound = entry->second.iBound + Vector3(533.33333f * 32, 533.33333f * 32, 0.f);
} }
mapSpawns.push_back(&(entry->second)); mapSpawns.push_back(&(entry->second));
spawnedModelFiles.insert(entry->second.name); spawnedModelFiles.insert(entry->second.name);
@@ -100,7 +100,7 @@ namespace VMAP
// ===> possibly move this code to StaticMapTree class // ===> possibly move this code to StaticMapTree class
std::map<uint32, uint32> modelNodeIdx; std::map<uint32, uint32> modelNodeIdx;
for (uint32 i=0; i<mapSpawns.size(); ++i) for (uint32 i = 0; i < mapSpawns.size(); ++i)
modelNodeIdx.insert(pair<uint32, uint32>(mapSpawns[i]->ID, i)); modelNodeIdx.insert(pair<uint32, uint32>(mapSpawns[i]->ID, i));
// write map tree file // write map tree file
@@ -126,7 +126,7 @@ namespace VMAP
// global map spawns (WDT), if any (most instances) // global map spawns (WDT), if any (most instances)
if (success && fwrite("GOBJ", 4, 1, mapfile) != 1) success = false; if (success && fwrite("GOBJ", 4, 1, mapfile) != 1) success = false;
for (TileMap::iterator glob=globalRange.first; glob != globalRange.second && success; ++glob) for (TileMap::iterator glob = globalRange.first; glob != globalRange.second && success; ++glob)
{ {
success = ModelSpawn::writeToFile(mapfile, map_iter->second->UniqueEntries[glob->second]); success = ModelSpawn::writeToFile(mapfile, map_iter->second->UniqueEntries[glob->second]);
} }
@@ -136,11 +136,11 @@ namespace VMAP
// <==== // <====
// write map tile files, similar to ADT files, only with extra BSP tree node info // write map tile files, similar to ADT files, only with extra BSP tree node info
TileMap &tileEntries = map_iter->second->TileEntries; TileMap& tileEntries = map_iter->second->TileEntries;
TileMap::iterator tile; TileMap::iterator tile;
for (tile = tileEntries.begin(); tile != tileEntries.end(); ++tile) for (tile = tileEntries.begin(); tile != tileEntries.end(); ++tile)
{ {
const ModelSpawn &spawn = map_iter->second->UniqueEntries[tile->second]; const ModelSpawn& spawn = map_iter->second->UniqueEntries[tile->second];
if (spawn.flags & MOD_WORLDSPAWN) // WDT spawn, saved as tile 65/65 currently... if (spawn.flags & MOD_WORLDSPAWN) // WDT spawn, saved as tile 65/65 currently...
continue; continue;
uint32 nSpawns = tileEntries.count(tile->first); uint32 nSpawns = tileEntries.count(tile->first);
@@ -157,11 +157,11 @@ namespace VMAP
// write number of tile spawns // write number of tile spawns
if (success && fwrite(&nSpawns, sizeof(uint32), 1, tilefile) != 1) success = false; if (success && fwrite(&nSpawns, sizeof(uint32), 1, tilefile) != 1) success = false;
// write tile spawns // write tile spawns
for (uint32 s=0; s<nSpawns; ++s) for (uint32 s = 0; s < nSpawns; ++s)
{ {
if (s) if (s)
++tile; ++tile;
const ModelSpawn &spawn2 = map_iter->second->UniqueEntries[tile->second]; const ModelSpawn& spawn2 = map_iter->second->UniqueEntries[tile->second];
success = success && ModelSpawn::writeToFile(tilefile, spawn2); success = success && ModelSpawn::writeToFile(tilefile, spawn2);
// MapTree nodes to update when loading tile: // MapTree nodes to update when loading tile:
std::map<uint32, uint32>::iterator nIdx = modelNodeIdx.find(spawn2.ID); std::map<uint32, uint32>::iterator nIdx = modelNodeIdx.find(spawn2.ID);
@@ -206,7 +206,7 @@ namespace VMAP
return false; return false;
} }
printf("Read coordinate mapping...\n"); printf("Read coordinate mapping...\n");
uint32 mapID, tileX, tileY, check=0; uint32 mapID, tileX, tileY, check = 0;
G3D::Vector3 v1, v2; G3D::Vector3 v1, v2;
ModelSpawn spawn; ModelSpawn spawn;
while (!feof(dirf)) while (!feof(dirf))
@@ -221,7 +221,7 @@ namespace VMAP
if (!ModelSpawn::readFromFile(dirf, spawn)) if (!ModelSpawn::readFromFile(dirf, spawn))
break; break;
MapSpawns *current; MapSpawns* current;
MapData::iterator map_iter = mapData.find(mapID); MapData::iterator map_iter = mapData.find(mapID);
if (map_iter == mapData.end()) if (map_iter == mapData.end())
{ {
@@ -237,7 +237,7 @@ namespace VMAP
return success; return success;
} }
bool TileAssembler::calculateTransformedBound(ModelSpawn &spawn) bool TileAssembler::calculateTransformedBound(ModelSpawn& spawn)
{ {
std::string modelFilename(iSrcDir); std::string modelFilename(iSrcDir);
modelFilename.push_back('/'); modelFilename.push_back('/');
@@ -257,9 +257,9 @@ namespace VMAP
printf("Warning: '%s' does not seem to be a M2 model!\n", modelFilename.c_str()); printf("Warning: '%s' does not seem to be a M2 model!\n", modelFilename.c_str());
AABox modelBound; AABox modelBound;
bool boundEmpty=true; bool boundEmpty = true;
for (uint32 g=0; g<groups; ++g) // should be only one for M2 files... for (uint32 g = 0; g < groups; ++g) // should be only one for M2 files...
{ {
std::vector<Vector3>& vertices = raw_model.groupsArray[g].vertexArray; std::vector<Vector3>& vertices = raw_model.groupsArray[g].vertexArray;
@@ -275,7 +275,7 @@ namespace VMAP
Vector3 v = modelPosition.transform(vertices[i]); Vector3 v = modelPosition.transform(vertices[i]);
if (boundEmpty) if (boundEmpty)
modelBound = AABox(v, v), boundEmpty=false; modelBound = AABox(v, v), boundEmpty = false;
else else
modelBound.merge(v); modelBound.merge(v);
} }
@@ -298,7 +298,7 @@ namespace VMAP
{ {
bool success = true; bool success = true;
std::string filename = iSrcDir; std::string filename = iSrcDir;
if (filename.length() >0) if (filename.length() > 0)
filename.push_back('/'); filename.push_back('/');
filename.append(pModelFilename); filename.append(pModelFilename);
@@ -391,11 +391,11 @@ namespace VMAP
fclose(model_list_copy); fclose(model_list_copy);
} }
// temporary use defines to simplify read/check code (close file and return at fail) // temporary use defines to simplify read/check code (close file and return at fail)
#define READ_OR_RETURN(V, S) if (fread((V), (S), 1, rf) != 1) { \ #define READ_OR_RETURN(V, S) if (fread((V), (S), 1, rf) != 1) { \
fclose(rf); printf("readfail, op = %i\n", readOperation); return(false); } fclose(rf); printf("readfail, op = %i\n", readOperation); return(false); }
#define READ_OR_RETURN_WITH_DELETE(V, S) if (fread((V), (S), 1, rf) != 1) { \ #define READ_OR_RETURN_WITH_DELETE(V, S) if (fread((V), (S), 1, rf) != 1) { \
fclose(rf); printf("readfail, op = %i\n", readOperation); delete[] V; return(false); }; fclose(rf); printf("readfail, op = %i\n", readOperation); delete[] V; return(false); };
#define CMP_OR_RETURN(V, S) if (strcmp((V), (S)) != 0) { \ #define CMP_OR_RETURN(V, S) if (strcmp((V), (S)) != 0) { \
fclose(rf); printf("cmpfail, %s!=%s\n", V, S);return(false); } fclose(rf); printf("cmpfail, %s!=%s\n", V, S);return(false); }
bool GroupModel_Raw::Read(FILE* rf) bool GroupModel_Raw::Read(FILE* rf)
@@ -423,7 +423,7 @@ namespace VMAP
CMP_OR_RETURN(blockId, "GRP "); CMP_OR_RETURN(blockId, "GRP ");
READ_OR_RETURN(&blocksize, sizeof(int)); READ_OR_RETURN(&blocksize, sizeof(int));
READ_OR_RETURN(&branches, sizeof(uint32)); READ_OR_RETURN(&branches, sizeof(uint32));
for (uint32 b=0; b<branches; ++b) for (uint32 b = 0; b < branches; ++b)
{ {
uint32 indexes; uint32 indexes;
// indexes for each branch (not used jet) // indexes for each branch (not used jet)
@@ -436,13 +436,13 @@ namespace VMAP
READ_OR_RETURN(&blocksize, sizeof(int)); READ_OR_RETURN(&blocksize, sizeof(int));
uint32 nindexes; uint32 nindexes;
READ_OR_RETURN(&nindexes, sizeof(uint32)); READ_OR_RETURN(&nindexes, sizeof(uint32));
if (nindexes >0) if (nindexes > 0)
{ {
uint16 *indexarray = new uint16[nindexes]; uint16* indexarray = new uint16[nindexes];
READ_OR_RETURN_WITH_DELETE(indexarray, nindexes*sizeof(uint16)); READ_OR_RETURN_WITH_DELETE(indexarray, nindexes * sizeof(uint16));
triangles.reserve(nindexes / 3); triangles.reserve(nindexes / 3);
for (uint32 i=0; i<nindexes; i+=3) for (uint32 i = 0; i < nindexes; i += 3)
triangles.push_back(MeshTriangle(indexarray[i], indexarray[i+1], indexarray[i+2])); triangles.push_back(MeshTriangle(indexarray[i], indexarray[i + 1], indexarray[i + 2]));
delete[] indexarray; delete[] indexarray;
} }
@@ -454,18 +454,18 @@ namespace VMAP
uint32 nvectors; uint32 nvectors;
READ_OR_RETURN(&nvectors, sizeof(uint32)); READ_OR_RETURN(&nvectors, sizeof(uint32));
if (nvectors >0) if (nvectors > 0)
{ {
float *vectorarray = new float[nvectors*3]; float* vectorarray = new float[nvectors * 3];
READ_OR_RETURN_WITH_DELETE(vectorarray, nvectors*sizeof(float)*3); READ_OR_RETURN_WITH_DELETE(vectorarray, nvectors * sizeof(float) * 3);
for (uint32 i=0; i<nvectors; ++i) for (uint32 i = 0; i < nvectors; ++i)
vertexArray.push_back( Vector3(vectorarray + 3*i) ); vertexArray.push_back( Vector3(vectorarray + 3 * i) );
delete[] vectorarray; delete[] vectorarray;
} }
// ----- liquid // ----- liquid
liquid = 0; liquid = 0;
if (liquidflags& 1) if (liquidflags & 1)
{ {
WMOLiquidHeader hlq; WMOLiquidHeader hlq;
READ_OR_RETURN(&blockId, 4); READ_OR_RETURN(&blockId, 4);
@@ -473,9 +473,9 @@ namespace VMAP
READ_OR_RETURN(&blocksize, sizeof(int)); READ_OR_RETURN(&blocksize, sizeof(int));
READ_OR_RETURN(&hlq, sizeof(WMOLiquidHeader)); READ_OR_RETURN(&hlq, sizeof(WMOLiquidHeader));
liquid = new WmoLiquid(hlq.xtiles, hlq.ytiles, Vector3(hlq.pos_x, hlq.pos_y, hlq.pos_z), hlq.type); liquid = new WmoLiquid(hlq.xtiles, hlq.ytiles, Vector3(hlq.pos_x, hlq.pos_y, hlq.pos_z), hlq.type);
uint32 size = hlq.xverts*hlq.yverts; uint32 size = hlq.xverts * hlq.yverts;
READ_OR_RETURN(liquid->GetHeightStorage(), size*sizeof(float)); READ_OR_RETURN(liquid->GetHeightStorage(), size * sizeof(float));
size = hlq.xtiles*hlq.ytiles; size = hlq.xtiles * hlq.ytiles;
READ_OR_RETURN(liquid->GetFlagsStorage(), size); READ_OR_RETURN(liquid->GetFlagsStorage(), size);
} }
@@ -488,7 +488,7 @@ namespace VMAP
delete liquid; delete liquid;
} }
bool WorldModel_Raw::Read(const char * path) bool WorldModel_Raw::Read(const char* path)
{ {
FILE* rf = fopen(path, "rb"); FILE* rf = fopen(path, "rb");
if (!rf) if (!rf)
@@ -523,6 +523,6 @@ namespace VMAP
} }
// drop of temporary use defines // drop of temporary use defines
#undef READ_OR_RETURN #undef READ_OR_RETURN
#undef CMP_OR_RETURN #undef CMP_OR_RETURN
} }
+5 -5
View File
@@ -34,7 +34,7 @@ namespace VMAP
float iScale; float iScale;
void init() void init()
{ {
iRotation = G3D::Matrix3::fromEulerAnglesZYX(G3D::pif()*iDir.y/180.f, G3D::pif()*iDir.x/180.f, G3D::pif()*iDir.z/180.f); iRotation = G3D::Matrix3::fromEulerAnglesZYX(G3D::pif() * iDir.y / 180.f, G3D::pif() * iDir.x / 180.f, G3D::pif() * iDir.z / 180.f);
} }
G3D::Vector3 transform(const G3D::Vector3& pIn) const; G3D::Vector3 transform(const G3D::Vector3& pIn) const;
void moveToBasePos(const G3D::Vector3& pBasePos) { iPos -= pBasePos; } void moveToBasePos(const G3D::Vector3& pBasePos) { iPos -= pBasePos; }
@@ -75,7 +75,7 @@ namespace VMAP
uint32 RootWMOID; uint32 RootWMOID;
std::vector<GroupModel_Raw> groupsArray; std::vector<GroupModel_Raw> groupsArray;
bool Read(const char * path); bool Read(const char* path);
}; };
class TileAssembler class TileAssembler
@@ -83,7 +83,7 @@ namespace VMAP
private: private:
std::string iDestDir; std::string iDestDir;
std::string iSrcDir; std::string iSrcDir;
bool (*iFilterMethod)(char *pName); bool (*iFilterMethod)(char* pName);
G3D::Table<std::string, unsigned int > iUniqueNameIds; G3D::Table<std::string, unsigned int > iUniqueNameIds;
unsigned int iCurrentUniqueNameId; unsigned int iCurrentUniqueNameId;
MapData mapData; MapData mapData;
@@ -95,11 +95,11 @@ namespace VMAP
bool convertWorld2(); bool convertWorld2();
bool readMapSpawns(); bool readMapSpawns();
bool calculateTransformedBound(ModelSpawn &spawn); bool calculateTransformedBound(ModelSpawn& spawn);
void exportGameobjectModels(); void exportGameobjectModels();
bool convertRawFile(const std::string& pModelFilename); bool convertRawFile(const std::string& pModelFilename);
void setModelNameFilterMethod(bool (*pFilterMethod)(char *pName)) { iFilterMethod = pFilterMethod; } void setModelNameFilterMethod(bool (*pFilterMethod)(char* pName)) { iFilterMethod = pFilterMethod; }
std::string getDirEntryNameFromModName(unsigned int pMapId, const std::string& pModPosName); std::string getDirEntryNameFromModName(unsigned int pMapId, const std::string& pModPosName);
}; };
@@ -36,9 +36,9 @@ ModelList model_list;
void LoadGameObjectModelList() void LoadGameObjectModelList()
{ {
//#ifndef NO_CORE_FUNCS //#ifndef NO_CORE_FUNCS
uint32 oldMSTime = getMSTime(); uint32 oldMSTime = getMSTime();
//#endif //#endif
FILE* model_list_file = fopen((sWorld->GetDataPath() + "vmaps/" + VMAP::GAMEOBJECT_MODELS).c_str(), "rb"); FILE* model_list_file = fopen((sWorld->GetDataPath() + "vmaps/" + VMAP::GAMEOBJECT_MODELS).c_str(), "rb");
if (!model_list_file) if (!model_list_file)
+12 -12
View File
@@ -14,10 +14,10 @@ using G3D::Ray;
namespace VMAP namespace VMAP
{ {
ModelInstance::ModelInstance(const ModelSpawn &spawn, WorldModel* model): ModelSpawn(spawn), iModel(model) ModelInstance::ModelInstance(const ModelSpawn& spawn, WorldModel* model): ModelSpawn(spawn), iModel(model)
{ {
iInvRot = G3D::Matrix3::fromEulerAnglesZYX(G3D::pi()*iRot.y/180.f, G3D::pi()*iRot.x/180.f, G3D::pi()*iRot.z/180.f).inverse(); iInvRot = G3D::Matrix3::fromEulerAnglesZYX(G3D::pi() * iRot.y / 180.f, G3D::pi() * iRot.x / 180.f, G3D::pi() * iRot.z / 180.f).inverse();
iInvScale = 1.f/iScale; iInvScale = 1.f / iScale;
} }
bool ModelInstance::intersectRay(const G3D::Ray& pRay, float& pMaxDist, bool StopAtFirstHit) const bool ModelInstance::intersectRay(const G3D::Ray& pRay, float& pMaxDist, bool StopAtFirstHit) const
@@ -30,12 +30,12 @@ namespace VMAP
float time = pRay.intersectionTime(iBound); float time = pRay.intersectionTime(iBound);
if (time == G3D::inf()) if (time == G3D::inf())
{ {
// std::cout << "Ray does not hit '" << name << "'\n"; // std::cout << "Ray does not hit '" << name << "'\n";
return false; return false;
} }
// std::cout << "Ray crosses bound of '" << name << "'\n"; // std::cout << "Ray crosses bound of '" << name << "'\n";
/* std::cout << "ray from:" << pRay.origin().x << ", " << pRay.origin().y << ", " << pRay.origin().z /* std::cout << "ray from:" << pRay.origin().x << ", " << pRay.origin().y << ", " << pRay.origin().z
<< " dir:" << pRay.direction().x << ", " << pRay.direction().y << ", " << pRay.direction().z << " dir:" << pRay.direction().x << ", " << pRay.direction().y << ", " << pRay.direction().z
<< " t/tmax:" << time << '/' << pMaxDist; << " t/tmax:" << time << '/' << pMaxDist;
std::cout << "\nBound lo:" << iBound.low().x << ", " << iBound.low().y << ", " << iBound.low().z << " hi: " std::cout << "\nBound lo:" << iBound.low().x << ", " << iBound.low().y << ", " << iBound.low().z << " hi: "
@@ -53,7 +53,7 @@ namespace VMAP
return hit; return hit;
} }
void ModelInstance::intersectPoint(const G3D::Vector3& p, AreaInfo &info) const void ModelInstance::intersectPoint(const G3D::Vector3& p, AreaInfo& info) const
{ {
if (!iModel) if (!iModel)
{ {
@@ -87,7 +87,7 @@ namespace VMAP
} }
} }
bool ModelInstance::GetLocationInfo(const G3D::Vector3& p, LocationInfo &info) const bool ModelInstance::GetLocationInfo(const G3D::Vector3& p, LocationInfo& info) const
{ {
if (!iModel) if (!iModel)
{ {
@@ -123,7 +123,7 @@ namespace VMAP
return false; return false;
} }
bool ModelInstance::GetLiquidLevel(const G3D::Vector3& p, LocationInfo &info, float &liqHeight) const bool ModelInstance::GetLiquidLevel(const G3D::Vector3& p, LocationInfo& info, float& liqHeight) const
{ {
// child bounds are defined in object space: // child bounds are defined in object space:
Vector3 pModel = iInvRot * (p - iPos) * iInvScale; Vector3 pModel = iInvRot * (p - iPos) * iInvScale;
@@ -139,7 +139,7 @@ namespace VMAP
return false; return false;
} }
bool ModelSpawn::readFromFile(FILE* rf, ModelSpawn &spawn) bool ModelSpawn::readFromFile(FILE* rf, ModelSpawn& spawn)
{ {
uint32 check = 0, nameLen; uint32 check = 0, nameLen;
check += fread(&spawn.flags, sizeof(uint32), 1, rf); check += fread(&spawn.flags, sizeof(uint32), 1, rf);
@@ -185,9 +185,9 @@ namespace VMAP
return true; return true;
} }
bool ModelSpawn::writeToFile(FILE* wf, const ModelSpawn &spawn) bool ModelSpawn::writeToFile(FILE* wf, const ModelSpawn& spawn)
{ {
uint32 check=0; uint32 check = 0;
check += fwrite(&spawn.flags, sizeof(uint32), 1, wf); check += fwrite(&spawn.flags, sizeof(uint32), 1, wf);
check += fwrite(&spawn.adtId, sizeof(uint16), 1, wf); check += fwrite(&spawn.adtId, sizeof(uint16), 1, wf);
check += fwrite(&spawn.ID, sizeof(uint32), 1, wf); check += fwrite(&spawn.ID, sizeof(uint32), 1, wf);
+9 -9
View File
@@ -23,8 +23,8 @@ namespace VMAP
enum ModelFlags enum ModelFlags
{ {
MOD_M2 = 1, MOD_M2 = 1,
MOD_WORLDSPAWN = 1<<1, MOD_WORLDSPAWN = 1 << 1,
MOD_HAS_BOUND = 1<<2 MOD_HAS_BOUND = 1 << 2
}; };
class ModelSpawn class ModelSpawn
@@ -39,25 +39,25 @@ namespace VMAP
float iScale; float iScale;
G3D::AABox iBound; G3D::AABox iBound;
std::string name; std::string name;
bool operator==(const ModelSpawn &other) const { return ID == other.ID; } bool operator==(const ModelSpawn& other) const { return ID == other.ID; }
//uint32 hashCode() const { return ID; } //uint32 hashCode() const { return ID; }
// temp? // temp?
const G3D::AABox& getBounds() const { return iBound; } const G3D::AABox& getBounds() const { return iBound; }
static bool readFromFile(FILE* rf, ModelSpawn &spawn); static bool readFromFile(FILE* rf, ModelSpawn& spawn);
static bool writeToFile(FILE* rw, const ModelSpawn &spawn); static bool writeToFile(FILE* rw, const ModelSpawn& spawn);
}; };
class ModelInstance: public ModelSpawn class ModelInstance: public ModelSpawn
{ {
public: public:
ModelInstance(): iInvScale(0.0f), iModel(0) { } ModelInstance(): iInvScale(0.0f), iModel(0) { }
ModelInstance(const ModelSpawn &spawn, WorldModel* model); ModelInstance(const ModelSpawn& spawn, WorldModel* model);
void setUnloaded() { iModel = 0; } void setUnloaded() { iModel = 0; }
bool intersectRay(const G3D::Ray& pRay, float& pMaxDist, bool StopAtFirstHit) const; bool intersectRay(const G3D::Ray& pRay, float& pMaxDist, bool StopAtFirstHit) const;
void intersectPoint(const G3D::Vector3& p, AreaInfo &info) const; void intersectPoint(const G3D::Vector3& p, AreaInfo& info) const;
bool GetLocationInfo(const G3D::Vector3& p, LocationInfo &info) const; bool GetLocationInfo(const G3D::Vector3& p, LocationInfo& info) const;
bool GetLiquidLevel(const G3D::Vector3& p, LocationInfo &info, float &liqHeight) const; bool GetLiquidLevel(const G3D::Vector3& p, LocationInfo& info, float& liqHeight) const;
protected: protected:
G3D::Matrix3 iInvRot; G3D::Matrix3 iInvRot;
float iInvScale; float iInvScale;
+51 -47
View File
@@ -19,7 +19,7 @@ template<> struct BoundsTrait<VMAP::GroupModel>
namespace VMAP namespace VMAP
{ {
bool IntersectTriangle(const MeshTriangle &tri, std::vector<Vector3>::const_iterator points, const G3D::Ray &ray, float &distance) bool IntersectTriangle(const MeshTriangle& tri, std::vector<Vector3>::const_iterator points, const G3D::Ray& ray, float& distance)
{ {
static const float EPS = 1e-5f; static const float EPS = 1e-5f;
@@ -30,7 +30,8 @@ namespace VMAP
const Vector3 p(ray.direction().cross(e2)); const Vector3 p(ray.direction().cross(e2));
const float a = e1.dot(p); const float a = e1.dot(p);
if (fabs(a) < EPS) { if (fabs(a) < EPS)
{
// Determinant is ill-conditioned; abort early // Determinant is ill-conditioned; abort early
return false; return false;
} }
@@ -39,7 +40,8 @@ namespace VMAP
const Vector3 s(ray.origin() - points[tri.idx0]); const Vector3 s(ray.origin() - points[tri.idx0]);
const float u = f * s.dot(p); const float u = f * s.dot(p);
if ((u < 0.0f) || (u > 1.0f)) { if ((u < 0.0f) || (u > 1.0f))
{
// We hit the plane of the m_geometry, but outside the m_geometry // We hit the plane of the m_geometry, but outside the m_geometry
return false; return false;
} }
@@ -47,7 +49,8 @@ namespace VMAP
const Vector3 q(s.cross(e1)); const Vector3 q(s.cross(e1));
const float v = f * ray.direction().dot(q); const float v = f * ray.direction().dot(q);
if ((v < 0.0f) || ((u + v) > 1.0f)) { if ((v < 0.0f) || ((u + v) > 1.0f))
{
// We hit the plane of the triangle, but outside the triangle // We hit the plane of the triangle, but outside the triangle
return false; return false;
} }
@@ -72,8 +75,8 @@ namespace VMAP
class TriBoundFunc class TriBoundFunc
{ {
public: public:
TriBoundFunc(std::vector<Vector3> &vert): vertices(vert.begin()) { } TriBoundFunc(std::vector<Vector3>& vert): vertices(vert.begin()) { }
void operator()(const MeshTriangle &tri, G3D::AABox &out) const void operator()(const MeshTriangle& tri, G3D::AABox& out) const
{ {
G3D::Vector3 lo = vertices[tri.idx0]; G3D::Vector3 lo = vertices[tri.idx0];
G3D::Vector3 hi = lo; G3D::Vector3 hi = lo;
@@ -89,14 +92,14 @@ namespace VMAP
// ===================== WmoLiquid ================================== // ===================== WmoLiquid ==================================
WmoLiquid::WmoLiquid(uint32 width, uint32 height, const Vector3 &corner, uint32 type): WmoLiquid::WmoLiquid(uint32 width, uint32 height, const Vector3& corner, uint32 type):
iTilesX(width), iTilesY(height), iCorner(corner), iType(type) iTilesX(width), iTilesY(height), iCorner(corner), iType(type)
{ {
iHeight = new float[(width+1)*(height+1)]; iHeight = new float[(width + 1) * (height + 1)];
iFlags = new uint8[width*height]; iFlags = new uint8[width * height];
} }
WmoLiquid::WmoLiquid(const WmoLiquid &other): iHeight(0), iFlags(0) WmoLiquid::WmoLiquid(const WmoLiquid& other): iHeight(0), iFlags(0)
{ {
*this = other; // use assignment operator... *this = other; // use assignment operator...
} }
@@ -107,7 +110,7 @@ namespace VMAP
delete[] iFlags; delete[] iFlags;
} }
WmoLiquid& WmoLiquid::operator=(const WmoLiquid &other) WmoLiquid& WmoLiquid::operator=(const WmoLiquid& other)
{ {
if (this == &other) if (this == &other)
return *this; return *this;
@@ -119,8 +122,8 @@ namespace VMAP
delete[] iFlags; delete[] iFlags;
if (other.iHeight) if (other.iHeight)
{ {
iHeight = new float[(iTilesX+1)*(iTilesY+1)]; iHeight = new float[(iTilesX + 1) * (iTilesY + 1)];
memcpy(iHeight, other.iHeight, (iTilesX+1)*(iTilesY+1)*sizeof(float)); memcpy(iHeight, other.iHeight, (iTilesX + 1) * (iTilesY + 1)*sizeof(float));
} }
else else
iHeight = 0; iHeight = 0;
@@ -134,20 +137,20 @@ namespace VMAP
return *this; return *this;
} }
bool WmoLiquid::GetLiquidHeight(const Vector3 &pos, float &liqHeight) const bool WmoLiquid::GetLiquidHeight(const Vector3& pos, float& liqHeight) const
{ {
float tx_f = (pos.x - iCorner.x)/LIQUID_TILE_SIZE; float tx_f = (pos.x - iCorner.x) / LIQUID_TILE_SIZE;
uint32 tx = uint32(tx_f); uint32 tx = uint32(tx_f);
if (tx_f < 0.0f || tx >= iTilesX) if (tx_f < 0.0f || tx >= iTilesX)
return false; return false;
float ty_f = (pos.y - iCorner.y)/LIQUID_TILE_SIZE; float ty_f = (pos.y - iCorner.y) / LIQUID_TILE_SIZE;
uint32 ty = uint32(ty_f); uint32 ty = uint32(ty_f);
if (ty_f < 0.0f || ty >= iTilesY) if (ty_f < 0.0f || ty >= iTilesY)
return false; return false;
// check if tile shall be used for liquid level // check if tile shall be used for liquid level
// checking for 0x08 *might* be enough, but disabled tiles always are 0x?F: // checking for 0x08 *might* be enough, but disabled tiles always are 0x?F:
if ((iFlags[tx + ty*iTilesX] & 0x0F) == 0x0F) if ((iFlags[tx + ty * iTilesX] & 0x0F) == 0x0F)
return false; return false;
// (dx, dy) coordinates inside tile, in [0, 1]^2 // (dx, dy) coordinates inside tile, in [0, 1]^2
@@ -170,14 +173,14 @@ namespace VMAP
const uint32 rowOffset = iTilesX + 1; const uint32 rowOffset = iTilesX + 1;
if (dx > dy) // case (a) if (dx > dy) // case (a)
{ {
float sx = iHeight[tx+1 + ty * rowOffset] - iHeight[tx + ty * rowOffset]; float sx = iHeight[tx + 1 + ty * rowOffset] - iHeight[tx + ty * rowOffset];
float sy = iHeight[tx+1 + (ty+1) * rowOffset] - iHeight[tx+1 + ty * rowOffset]; float sy = iHeight[tx + 1 + (ty + 1) * rowOffset] - iHeight[tx + 1 + ty * rowOffset];
liqHeight = iHeight[tx + ty * rowOffset] + dx * sx + dy * sy; liqHeight = iHeight[tx + ty * rowOffset] + dx * sx + dy * sy;
} }
else // case (b) else // case (b)
{ {
float sx = iHeight[tx+1 + (ty+1) * rowOffset] - iHeight[tx + (ty+1) * rowOffset]; float sx = iHeight[tx + 1 + (ty + 1) * rowOffset] - iHeight[tx + (ty + 1) * rowOffset];
float sy = iHeight[tx + (ty+1) * rowOffset] - iHeight[tx + ty * rowOffset]; float sy = iHeight[tx + (ty + 1) * rowOffset] - iHeight[tx + ty * rowOffset];
liqHeight = iHeight[tx + ty * rowOffset] + dx * sx + dy * sy; liqHeight = iHeight[tx + ty * rowOffset] + dx * sx + dy * sy;
} }
return true; return true;
@@ -187,7 +190,7 @@ namespace VMAP
{ {
return 2 * sizeof(uint32) + return 2 * sizeof(uint32) +
sizeof(Vector3) + sizeof(Vector3) +
(iTilesX + 1)*(iTilesY + 1) * sizeof(float) + (iTilesX + 1) * (iTilesY + 1) * sizeof(float) +
iTilesX * iTilesY; iTilesX * iTilesY;
} }
@@ -202,7 +205,7 @@ namespace VMAP
uint32 size = (iTilesX + 1) * (iTilesY + 1); uint32 size = (iTilesX + 1) * (iTilesY + 1);
if (fwrite(iHeight, sizeof(float), size, wf) == size) if (fwrite(iHeight, sizeof(float), size, wf) == size)
{ {
size = iTilesX*iTilesY; size = iTilesX * iTilesY;
result = fwrite(iFlags, sizeof(uint8), size, wf) == size; result = fwrite(iFlags, sizeof(uint8), size, wf) == size;
} }
} }
@@ -210,7 +213,7 @@ namespace VMAP
return result; return result;
} }
bool WmoLiquid::readFromFile(FILE* rf, WmoLiquid* &out) bool WmoLiquid::readFromFile(FILE* rf, WmoLiquid*& out)
{ {
bool result = false; bool result = false;
WmoLiquid* liquid = new WmoLiquid(); WmoLiquid* liquid = new WmoLiquid();
@@ -240,7 +243,7 @@ namespace VMAP
// ===================== GroupModel ================================== // ===================== GroupModel ==================================
GroupModel::GroupModel(const GroupModel &other): GroupModel::GroupModel(const GroupModel& other):
iBound(other.iBound), iMogpFlags(other.iMogpFlags), iGroupWMOID(other.iGroupWMOID), iBound(other.iBound), iMogpFlags(other.iMogpFlags), iGroupWMOID(other.iGroupWMOID),
vertices(other.vertices), triangles(other.triangles), meshTree(other.meshTree), iLiquid(0) vertices(other.vertices), triangles(other.triangles), meshTree(other.meshTree), iLiquid(0)
{ {
@@ -248,7 +251,7 @@ namespace VMAP
iLiquid = new WmoLiquid(*other.iLiquid); iLiquid = new WmoLiquid(*other.iLiquid);
} }
void GroupModel::setMeshData(std::vector<Vector3> &vert, std::vector<MeshTriangle> &tri) void GroupModel::setMeshData(std::vector<Vector3>& vert, std::vector<MeshTriangle>& tri)
{ {
vertices.swap(vert); vertices.swap(vert);
triangles.swap(tri); triangles.swap(tri);
@@ -268,7 +271,7 @@ namespace VMAP
// write vertices // write vertices
if (result && fwrite("VERT", 1, 4, wf) != 4) result = false; if (result && fwrite("VERT", 1, 4, wf) != 4) result = false;
count = vertices.size(); count = vertices.size();
chunkSize = sizeof(uint32)+ sizeof(Vector3)*count; chunkSize = sizeof(uint32) + sizeof(Vector3) * count;
if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false; if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false; if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false;
if (!count) // models without (collision) geometry end here, unsure if they are useful if (!count) // models without (collision) geometry end here, unsure if they are useful
@@ -278,7 +281,7 @@ namespace VMAP
// write triangle mesh // write triangle mesh
if (result && fwrite("TRIM", 1, 4, wf) != 4) result = false; if (result && fwrite("TRIM", 1, 4, wf) != 4) result = false;
count = triangles.size(); count = triangles.size();
chunkSize = sizeof(uint32)+ sizeof(MeshTriangle)*count; chunkSize = sizeof(uint32) + sizeof(MeshTriangle) * count;
if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false; if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false; if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false;
if (result && fwrite(&triangles[0], sizeof(MeshTriangle), count, wf) != count) result = false; if (result && fwrite(&triangles[0], sizeof(MeshTriangle), count, wf) != count) result = false;
@@ -347,12 +350,12 @@ namespace VMAP
struct GModelRayCallback struct GModelRayCallback
{ {
GModelRayCallback(const std::vector<MeshTriangle> &tris, const std::vector<Vector3> &vert): GModelRayCallback(const std::vector<MeshTriangle>& tris, const std::vector<Vector3>& vert):
vertices(vert.begin()), triangles(tris.begin()), hit(false) { } vertices(vert.begin()), triangles(tris.begin()), hit(false) { }
bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool /*StopAtFirstHit*/) bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool /*StopAtFirstHit*/)
{ {
bool result = IntersectTriangle(triangles[entry], vertices, ray, distance); bool result = IntersectTriangle(triangles[entry], vertices, ray, distance);
if (result) hit=true; if (result) hit = true;
return hit; return hit;
} }
std::vector<Vector3>::const_iterator vertices; std::vector<Vector3>::const_iterator vertices;
@@ -360,7 +363,7 @@ namespace VMAP
bool hit; bool hit;
}; };
bool GroupModel::IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const bool GroupModel::IntersectRay(const G3D::Ray& ray, float& distance, bool stopAtFirstHit) const
{ {
if (triangles.empty()) if (triangles.empty())
return false; return false;
@@ -370,7 +373,7 @@ namespace VMAP
return callback.hit; return callback.hit;
} }
bool GroupModel::IsInsideObject(const Vector3 &pos, const Vector3 &down, float &z_dist) const bool GroupModel::IsInsideObject(const Vector3& pos, const Vector3& down, float& z_dist) const
{ {
if (triangles.empty() || !iBound.contains(pos)) if (triangles.empty() || !iBound.contains(pos))
return false; return false;
@@ -384,7 +387,7 @@ namespace VMAP
return hit; return hit;
} }
bool GroupModel::GetLiquidLevel(const Vector3 &pos, float &liqHeight) const bool GroupModel::GetLiquidLevel(const Vector3& pos, float& liqHeight) const
{ {
if (iLiquid) if (iLiquid)
return iLiquid->GetLiquidHeight(pos, liqHeight); return iLiquid->GetLiquidHeight(pos, liqHeight);
@@ -400,7 +403,7 @@ namespace VMAP
// ===================== WorldModel ================================== // ===================== WorldModel ==================================
void WorldModel::setGroupModels(std::vector<GroupModel> &models) void WorldModel::setGroupModels(std::vector<GroupModel>& models)
{ {
groupModels.swap(models); groupModels.swap(models);
groupTree.build(groupModels, BoundsTrait<GroupModel>::getBounds, 1); groupTree.build(groupModels, BoundsTrait<GroupModel>::getBounds, 1);
@@ -408,18 +411,18 @@ namespace VMAP
struct WModelRayCallBack struct WModelRayCallBack
{ {
WModelRayCallBack(const std::vector<GroupModel> &mod): models(mod.begin()), hit(false) { } WModelRayCallBack(const std::vector<GroupModel>& mod): models(mod.begin()), hit(false) { }
bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool StopAtFirstHit) bool operator()(const G3D::Ray& ray, uint32 entry, float& distance, bool StopAtFirstHit)
{ {
bool result = models[entry].IntersectRay(ray, distance, StopAtFirstHit); bool result = models[entry].IntersectRay(ray, distance, StopAtFirstHit);
if (result) hit=true; if (result) hit = true;
return hit; return hit;
} }
std::vector<GroupModel>::const_iterator models; std::vector<GroupModel>::const_iterator models;
bool hit; bool hit;
}; };
bool WorldModel::IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const bool WorldModel::IntersectRay(const G3D::Ray& ray, float& distance, bool stopAtFirstHit) const
{ {
// small M2 workaround, maybe better make separate class with virtual intersection funcs // small M2 workaround, maybe better make separate class with virtual intersection funcs
// in any case, there's no need to use a bound tree if we only have one submodel // in any case, there's no need to use a bound tree if we only have one submodel
@@ -431,9 +434,10 @@ namespace VMAP
return isc.hit; return isc.hit;
} }
class WModelAreaCallback { class WModelAreaCallback
{
public: public:
WModelAreaCallback(const std::vector<GroupModel> &vals, const Vector3 &down): WModelAreaCallback(const std::vector<GroupModel>& vals, const Vector3& down):
prims(vals.begin()), hit(vals.end()), minVol(G3D::inf()), zDist(G3D::inf()), zVec(down) { } prims(vals.begin()), hit(vals.end()), minVol(G3D::inf()), zDist(G3D::inf()), zVec(down) { }
std::vector<GroupModel>::const_iterator prims; std::vector<GroupModel>::const_iterator prims;
std::vector<GroupModel>::const_iterator hit; std::vector<GroupModel>::const_iterator hit;
@@ -457,7 +461,7 @@ namespace VMAP
hit = prims + entry; hit = prims + entry;
} }
#ifdef VMAP_DEBUG #ifdef VMAP_DEBUG
const GroupModel &gm = prims[entry]; const GroupModel& gm = prims[entry];
printf("%10u %8X %7.3f, %7.3f, %7.3f | %7.3f, %7.3f, %7.3f | z=%f, p_z=%f\n", gm.GetWmoID(), gm.GetMogpFlags(), printf("%10u %8X %7.3f, %7.3f, %7.3f | %7.3f, %7.3f, %7.3f | z=%f, p_z=%f\n", gm.GetWmoID(), gm.GetMogpFlags(),
gm.GetBound().low().x, gm.GetBound().low().y, gm.GetBound().low().z, gm.GetBound().low().x, gm.GetBound().low().y, gm.GetBound().low().z,
gm.GetBound().high().x, gm.GetBound().high().y, gm.GetBound().high().z, group_Z, point.z); gm.GetBound().high().x, gm.GetBound().high().y, gm.GetBound().high().z, group_Z, point.z);
@@ -468,7 +472,7 @@ namespace VMAP
} }
}; };
bool WorldModel::IntersectPoint(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, AreaInfo &info) const bool WorldModel::IntersectPoint(const G3D::Vector3& p, const G3D::Vector3& down, float& dist, AreaInfo& info) const
{ {
if (groupModels.empty()) if (groupModels.empty())
return false; return false;
@@ -487,7 +491,7 @@ namespace VMAP
return false; return false;
} }
bool WorldModel::GetLocationInfo(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, LocationInfo &info) const bool WorldModel::GetLocationInfo(const G3D::Vector3& p, const G3D::Vector3& down, float& dist, LocationInfo& info) const
{ {
if (groupModels.empty()) if (groupModels.empty())
return false; return false;
@@ -503,7 +507,7 @@ namespace VMAP
return false; return false;
} }
bool WorldModel::writeFile(const std::string &filename) bool WorldModel::writeFile(const std::string& filename)
{ {
FILE* wf = fopen(filename.c_str(), "wb"); FILE* wf = fopen(filename.c_str(), "wb");
if (!wf) if (!wf)
@@ -517,14 +521,14 @@ namespace VMAP
if (result && fwrite(&RootWMOID, sizeof(uint32), 1, wf) != 1) result = false; if (result && fwrite(&RootWMOID, sizeof(uint32), 1, wf) != 1) result = false;
// write group models // write group models
count=groupModels.size(); count = groupModels.size();
if (count) if (count)
{ {
if (result && fwrite("GMOD", 1, 4, wf) != 4) result = false; if (result && fwrite("GMOD", 1, 4, wf) != 4) result = false;
//chunkSize = sizeof(uint32)+ sizeof(GroupModel)*count; //chunkSize = sizeof(uint32)+ sizeof(GroupModel)*count;
//if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false; //if (result && fwrite(&chunkSize, sizeof(uint32), 1, wf) != 1) result = false;
if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false; if (result && fwrite(&count, sizeof(uint32), 1, wf) != 1) result = false;
for (uint32 i=0; i<groupModels.size() && result; ++i) for (uint32 i = 0; i < groupModels.size() && result; ++i)
result = groupModels[i].writeToFile(wf); result = groupModels[i].writeToFile(wf);
// write group BIH // write group BIH
@@ -536,7 +540,7 @@ namespace VMAP
return result; return result;
} }
bool WorldModel::readFile(const std::string &filename) bool WorldModel::readFile(const std::string& filename)
{ {
FILE* rf = fopen(filename.c_str(), "rb"); FILE* rf = fopen(filename.c_str(), "rb");
if (!rf) if (!rf)
@@ -560,7 +564,7 @@ namespace VMAP
if (result && fread(&count, sizeof(uint32), 1, rf) != 1) result = false; if (result && fread(&count, sizeof(uint32), 1, rf) != 1) result = false;
if (result) groupModels.resize(count); if (result) groupModels.resize(count);
//if (result && fread(&groupModels[0], sizeof(GroupModel), count, rf) != count) result = false; //if (result && fread(&groupModels[0], sizeof(GroupModel), count, rf) != count) result = false;
for (uint32 i=0; i<count && result; ++i) for (uint32 i = 0; i < count && result; ++i)
result = groupModels[i].readFromFile(rf); result = groupModels[i].readFromFile(rf);
// read group BIH // read group BIH
+24 -24
View File
@@ -35,27 +35,27 @@ namespace VMAP
class WmoLiquid class WmoLiquid
{ {
public: public:
WmoLiquid(uint32 width, uint32 height, const G3D::Vector3 &corner, uint32 type); WmoLiquid(uint32 width, uint32 height, const G3D::Vector3& corner, uint32 type);
WmoLiquid(const WmoLiquid &other); WmoLiquid(const WmoLiquid& other);
~WmoLiquid(); ~WmoLiquid();
WmoLiquid& operator=(const WmoLiquid &other); WmoLiquid& operator=(const WmoLiquid& other);
bool GetLiquidHeight(const G3D::Vector3 &pos, float &liqHeight) const; bool GetLiquidHeight(const G3D::Vector3& pos, float& liqHeight) const;
uint32 GetType() const { return iType; } uint32 GetType() const { return iType; }
float *GetHeightStorage() { return iHeight; } float* GetHeightStorage() { return iHeight; }
uint8 *GetFlagsStorage() { return iFlags; } uint8* GetFlagsStorage() { return iFlags; }
uint32 GetFileSize(); uint32 GetFileSize();
bool writeToFile(FILE* wf); bool writeToFile(FILE* wf);
static bool readFromFile(FILE* rf, WmoLiquid* &liquid); static bool readFromFile(FILE* rf, WmoLiquid*& liquid);
private: private:
WmoLiquid(): iTilesX(0), iTilesY(0), iType(0), iHeight(0), iFlags(0) { } WmoLiquid(): iTilesX(0), iTilesY(0), iType(0), iHeight(0), iFlags(0) { }
uint32 iTilesX; //!< number of tiles in x direction, each uint32 iTilesX; //!< number of tiles in x direction, each
uint32 iTilesY; uint32 iTilesY;
G3D::Vector3 iCorner; //!< the lower corner G3D::Vector3 iCorner; //!< the lower corner
uint32 iType; //!< liquid type uint32 iType; //!< liquid type
float *iHeight; //!< (tilesX + 1)*(tilesY + 1) height values float* iHeight; //!< (tilesX + 1)*(tilesY + 1) height values
uint8 *iFlags; //!< info if liquid tile is used uint8* iFlags; //!< info if liquid tile is used
public: public:
void getPosInfo(uint32 &tilesX, uint32 &tilesY, G3D::Vector3 &corner) const; void getPosInfo(uint32& tilesX, uint32& tilesY, G3D::Vector3& corner) const;
}; };
/*! holding additional info for WMO group files */ /*! holding additional info for WMO group files */
@@ -63,17 +63,17 @@ namespace VMAP
{ {
public: public:
GroupModel(): iMogpFlags(0), iGroupWMOID(0), iLiquid(0) { } GroupModel(): iMogpFlags(0), iGroupWMOID(0), iLiquid(0) { }
GroupModel(const GroupModel &other); GroupModel(const GroupModel& other);
GroupModel(uint32 mogpFlags, uint32 groupWMOID, const G3D::AABox &bound): GroupModel(uint32 mogpFlags, uint32 groupWMOID, const G3D::AABox& bound):
iBound(bound), iMogpFlags(mogpFlags), iGroupWMOID(groupWMOID), iLiquid(0) { } iBound(bound), iMogpFlags(mogpFlags), iGroupWMOID(groupWMOID), iLiquid(0) { }
~GroupModel() { delete iLiquid; } ~GroupModel() { delete iLiquid; }
//! pass mesh data to object and create BIH. Passed vectors get get swapped with old geometry! //! pass mesh data to object and create BIH. Passed vectors get get swapped with old geometry!
void setMeshData(std::vector<G3D::Vector3> &vert, std::vector<MeshTriangle> &tri); void setMeshData(std::vector<G3D::Vector3>& vert, std::vector<MeshTriangle>& tri);
void setLiquidData(WmoLiquid*& liquid) { iLiquid = liquid; liquid = NULL; } void setLiquidData(WmoLiquid*& liquid) { iLiquid = liquid; liquid = NULL; }
bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const; bool IntersectRay(const G3D::Ray& ray, float& distance, bool stopAtFirstHit) const;
bool IsInsideObject(const G3D::Vector3 &pos, const G3D::Vector3 &down, float &z_dist) const; bool IsInsideObject(const G3D::Vector3& pos, const G3D::Vector3& down, float& z_dist) const;
bool GetLiquidLevel(const G3D::Vector3 &pos, float &liqHeight) const; bool GetLiquidLevel(const G3D::Vector3& pos, float& liqHeight) const;
uint32 GetLiquidType() const; uint32 GetLiquidType() const;
bool writeToFile(FILE* wf); bool writeToFile(FILE* wf);
bool readFromFile(FILE* rf); bool readFromFile(FILE* rf);
@@ -89,7 +89,7 @@ namespace VMAP
BIH meshTree; BIH meshTree;
WmoLiquid* iLiquid; WmoLiquid* iLiquid;
public: public:
void getMeshData(std::vector<G3D::Vector3> &vertices, std::vector<MeshTriangle> &triangles, WmoLiquid* &liquid); void getMeshData(std::vector<G3D::Vector3>& vertices, std::vector<MeshTriangle>& triangles, WmoLiquid*& liquid);
}; };
/*! Holds a model (converted M2 or WMO) in its original coordinate space */ /*! Holds a model (converted M2 or WMO) in its original coordinate space */
class WorldModel class WorldModel
@@ -98,19 +98,19 @@ namespace VMAP
WorldModel(): RootWMOID(0) { } WorldModel(): RootWMOID(0) { }
//! pass group models to WorldModel and create BIH. Passed vector is swapped with old geometry! //! pass group models to WorldModel and create BIH. Passed vector is swapped with old geometry!
void setGroupModels(std::vector<GroupModel> &models); void setGroupModels(std::vector<GroupModel>& models);
void setRootWmoID(uint32 id) { RootWMOID = id; } void setRootWmoID(uint32 id) { RootWMOID = id; }
bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const; bool IntersectRay(const G3D::Ray& ray, float& distance, bool stopAtFirstHit) const;
bool IntersectPoint(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, AreaInfo &info) const; bool IntersectPoint(const G3D::Vector3& p, const G3D::Vector3& down, float& dist, AreaInfo& info) const;
bool GetLocationInfo(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, LocationInfo &info) const; bool GetLocationInfo(const G3D::Vector3& p, const G3D::Vector3& down, float& dist, LocationInfo& info) const;
bool writeFile(const std::string &filename); bool writeFile(const std::string& filename);
bool readFile(const std::string &filename); bool readFile(const std::string& filename);
protected: protected:
uint32 RootWMOID; uint32 RootWMOID;
std::vector<GroupModel> groupModels; std::vector<GroupModel> groupModels;
BIH groupTree; BIH groupTree;
public: public:
void getGroupModels(std::vector<GroupModel> &groupModels); void getGroupModels(std::vector<GroupModel>& groupModels);
}; };
} // namespace VMAP } // namespace VMAP
+29 -25
View File
@@ -16,7 +16,7 @@ public:
explicit NodeArray() { memset(&_nodes, 0, sizeof(_nodes)); } explicit NodeArray() { memset(&_nodes, 0, sizeof(_nodes)); }
void AddNode(Node* n) void AddNode(Node* n)
{ {
for (uint8 i=0; i<9; ++i) for (uint8 i = 0; i < 9; ++i)
if (_nodes[i] == 0) if (_nodes[i] == 0)
{ {
_nodes[i] = n; _nodes[i] = n;
@@ -29,37 +29,41 @@ public:
}; };
template<class Node> template<class Node>
struct NodeCreator{ struct NodeCreator
static Node * makeNode(int /*x*/, int /*y*/) { return new Node();} {
static Node* makeNode(int /*x*/, int /*y*/) { return new Node();}
}; };
template<class T, template<class T,
class Node, class Node,
class NodeCreatorFunc = NodeCreator<Node>, class NodeCreatorFunc = NodeCreator<Node>,
/*class BoundsFunc = BoundsTrait<T>,*/ /*class BoundsFunc = BoundsTrait<T>,*/
class PositionFunc = PositionTrait<T> class PositionFunc = PositionTrait<T>
> >
class RegularGrid2D class RegularGrid2D
{ {
public: public:
enum{ enum
{
CELL_NUMBER = 64, CELL_NUMBER = 64,
}; };
#define HGRID_MAP_SIZE (533.33333f * 64.f) // shouldn't be changed #define HGRID_MAP_SIZE (533.33333f * 64.f) // shouldn't be changed
#define CELL_SIZE float(HGRID_MAP_SIZE/(float)CELL_NUMBER) #define CELL_SIZE float(HGRID_MAP_SIZE/(float)CELL_NUMBER)
typedef G3D::Table<const T*, NodeArray<Node> > MemberTable; typedef G3D::Table<const T*, NodeArray<Node> > MemberTable;
MemberTable memberTable; MemberTable memberTable;
Node* nodes[CELL_NUMBER][CELL_NUMBER]; Node* nodes[CELL_NUMBER][CELL_NUMBER];
RegularGrid2D(){ RegularGrid2D()
{
memset(nodes, 0, sizeof(nodes)); memset(nodes, 0, sizeof(nodes));
} }
~RegularGrid2D(){ ~RegularGrid2D()
{
for (int x = 0; x < CELL_NUMBER; ++x) for (int x = 0; x < CELL_NUMBER; ++x)
for (int y = 0; y < CELL_NUMBER; ++y) for (int y = 0; y < CELL_NUMBER; ++y)
delete nodes[x][y]; delete nodes[x][y];
@@ -72,14 +76,14 @@ public:
pos[1] = value.getBounds().corner(1); pos[1] = value.getBounds().corner(1);
pos[2] = value.getBounds().corner(2); pos[2] = value.getBounds().corner(2);
pos[3] = value.getBounds().corner(3); pos[3] = value.getBounds().corner(3);
pos[4] = (pos[0] + pos[1])/2.0f; pos[4] = (pos[0] + pos[1]) / 2.0f;
pos[5] = (pos[1] + pos[2])/2.0f; pos[5] = (pos[1] + pos[2]) / 2.0f;
pos[6] = (pos[2] + pos[3])/2.0f; pos[6] = (pos[2] + pos[3]) / 2.0f;
pos[7] = (pos[3] + pos[0])/2.0f; pos[7] = (pos[3] + pos[0]) / 2.0f;
pos[8] = (pos[0] + pos[2])/2.0f; pos[8] = (pos[0] + pos[2]) / 2.0f;
NodeArray<Node> na; NodeArray<Node> na;
for (uint8 i=0; i<9; ++i) for (uint8 i = 0; i < 9; ++i)
{ {
Cell c = Cell::ComputeCell(pos[i].x, pos[i].y); Cell c = Cell::ComputeCell(pos[i].x, pos[i].y);
if (!c.isValid()) if (!c.isValid())
@@ -88,7 +92,7 @@ public:
na.AddNode(&node); na.AddNode(&node);
} }
for (uint8 i=0; i<9; ++i) for (uint8 i = 0; i < 9; ++i)
{ {
if (na._nodes[i]) if (na._nodes[i])
na._nodes[i]->insert(value); na._nodes[i]->insert(value);
@@ -102,7 +106,7 @@ public:
void remove(const T& value) void remove(const T& value)
{ {
NodeArray<Node>& na = memberTable[&value]; NodeArray<Node>& na = memberTable[&value];
for (uint8 i=0; i<9; ++i) for (uint8 i = 0; i < 9; ++i)
{ {
if (na._nodes[i]) if (na._nodes[i])
na._nodes[i]->remove(value); na._nodes[i]->remove(value);
@@ -132,7 +136,7 @@ public:
static Cell ComputeCell(float fx, float fy) static Cell ComputeCell(float fx, float fy)
{ {
Cell c = { int(fx * (1.f/CELL_SIZE) + (CELL_NUMBER/2)), int(fy * (1.f/CELL_SIZE) + (CELL_NUMBER/2)) }; Cell c = { int(fx * (1.f / CELL_SIZE) + (CELL_NUMBER / 2)), int(fy * (1.f / CELL_SIZE) + (CELL_NUMBER / 2)) };
return c; return c;
} }
@@ -185,26 +189,26 @@ public:
if (kx_inv >= 0) if (kx_inv >= 0)
{ {
stepX = 1; stepX = 1;
float x_border = (cell.x+1) * voxel; float x_border = (cell.x + 1) * voxel;
tMaxX = (x_border - bx) * kx_inv; tMaxX = (x_border - bx) * kx_inv;
} }
else else
{ {
stepX = -1; stepX = -1;
float x_border = (cell.x-1) * voxel; float x_border = (cell.x - 1) * voxel;
tMaxX = (x_border - bx) * kx_inv; tMaxX = (x_border - bx) * kx_inv;
} }
if (ky_inv >= 0) if (ky_inv >= 0)
{ {
stepY = 1; stepY = 1;
float y_border = (cell.y+1) * voxel; float y_border = (cell.y + 1) * voxel;
tMaxY = (y_border - by) * ky_inv; tMaxY = (y_border - by) * ky_inv;
} }
else else
{ {
stepY = -1; stepY = -1;
float y_border = (cell.y-1) * voxel; float y_border = (cell.y - 1) * voxel;
tMaxY = (y_border - by) * ky_inv; tMaxY = (y_border - by) * ky_inv;
} }
+1 -1
View File
@@ -17,6 +17,6 @@ namespace VMAP
const char GAMEOBJECT_MODELS[] = "GameObjectModels.dtree"; const char GAMEOBJECT_MODELS[] = "GameObjectModels.dtree";
// defined in TileAssembler.cpp currently... // defined in TileAssembler.cpp currently...
bool readChunk(FILE* rf, char *dest, const char *compare, uint32 len); bool readChunk(FILE* rf, char* dest, const char* compare, uint32 len);
} }
#endif #endif
+4 -2
View File
@@ -21,13 +21,15 @@ The collision detection is modified to return true, if we are inside an object.
namespace VMAP namespace VMAP
{ {
template<class TValue> template<class TValue>
class IntersectionCallBack { class IntersectionCallBack
{
public: public:
TValue* closestEntity; TValue* closestEntity;
G3D::Vector3 hitLocation; G3D::Vector3 hitLocation;
G3D::Vector3 hitNormal; G3D::Vector3 hitNormal;
void operator()(const G3D::Ray& ray, const TValue* entity, bool StopAtFirstHit, float& distance) { void operator()(const G3D::Ray& ray, const TValue* entity, bool StopAtFirstHit, float& distance)
{
entity->intersect(ray, distance, StopAtFirstHit, hitLocation, hitNormal); entity->intersect(ray, distance, StopAtFirstHit, hitLocation, hitNormal);
} }
}; };
+6 -5
View File
@@ -6,7 +6,8 @@
#include "Common.h" #include "Common.h"
char const* localeNames[TOTAL_LOCALES] = { char const* localeNames[TOTAL_LOCALES] =
{
"enUS", "enUS",
"koKR", "koKR",
"frFR", "frFR",
@@ -21,7 +22,7 @@ char const* localeNames[TOTAL_LOCALES] = {
LocaleConstant GetLocaleByName(const std::string& name) LocaleConstant GetLocaleByName(const std::string& name)
{ {
for (uint32 i = 0; i < TOTAL_LOCALES; ++i) for (uint32 i = 0; i < TOTAL_LOCALES; ++i)
if (name==localeNames[i]) if (name == localeNames[i])
return LocaleConstant(i); return LocaleConstant(i);
return LOCALE_enUS; // including enGB case return LOCALE_enUS; // including enGB case
@@ -30,8 +31,8 @@ LocaleConstant GetLocaleByName(const std::string& name)
void CleanStringForMysqlQuery(std::string& str) void CleanStringForMysqlQuery(std::string& str)
{ {
std::string::size_type n = 0; std::string::size_type n = 0;
while ((n=str.find('\\')) != str.npos) str.erase(n,1); while ((n = str.find('\\')) != str.npos) str.erase(n, 1);
while ((n=str.find('"')) != str.npos) str.erase(n,1); while ((n = str.find('"')) != str.npos) str.erase(n, 1);
while ((n=str.find('\'')) != str.npos) str.erase(n,1); while ((n = str.find('\'')) != str.npos) str.erase(n, 1);
} }
+5 -5
View File
@@ -136,11 +136,11 @@ inline bool myisfinite(float f) { return isfinite(f) && !isnan(f); }
enum TimeConstants enum TimeConstants
{ {
MINUTE = 60, MINUTE = 60,
HOUR = MINUTE*60, HOUR = MINUTE * 60,
DAY = HOUR*24, DAY = HOUR * 24,
WEEK = DAY*7, WEEK = DAY * 7,
MONTH = DAY*30, MONTH = DAY * 30,
YEAR = MONTH*12, YEAR = MONTH * 12,
IN_MILLISECONDS = 1000 IN_MILLISECONDS = 1000
}; };
+3 -3
View File
@@ -43,7 +43,7 @@ namespace acore
using reference = T&; using reference = T&;
using difference_type = std::ptrdiff_t; using difference_type = std::ptrdiff_t;
CheckedBufferOutputIterator(T* buf, size_t n) : _buf(buf), _end(buf+n) {} CheckedBufferOutputIterator(T* buf, size_t n) : _buf(buf), _end(buf + n) {}
T& operator*() const { check(); return *_buf; } T& operator*() const { check(); return *_buf; }
CheckedBufferOutputIterator& operator++() { check(); ++_buf; return *this; } CheckedBufferOutputIterator& operator++() { check(); ++_buf; return *this; }
@@ -64,7 +64,7 @@ namespace acore
namespace Containers namespace Containers
{ {
template<class T> template<class T>
void RandomResizeList(std::list<T> &list, uint32 size) void RandomResizeList(std::list<T>& list, uint32 size)
{ {
size_t list_size = list.size(); size_t list_size = list.size();
@@ -78,7 +78,7 @@ namespace acore
} }
template<class T, class Predicate> template<class T, class Predicate>
void RandomResizeList(std::list<T> &list, Predicate& predicate, uint32 size) void RandomResizeList(std::list<T>& list, Predicate& predicate, uint32 size)
{ {
//! First use predicate filter //! First use predicate filter
std::list<T> listCopy; std::list<T> listCopy;
+2 -2
View File
@@ -12,13 +12,13 @@
class ARC4 class ARC4
{ {
public: public:
ARC4(uint32 len); ARC4(uint32 len);
ARC4(uint8* seed, uint32 len); ARC4(uint8* seed, uint32 len);
~ARC4(); ~ARC4();
void Init(uint8* seed); void Init(uint8* seed);
void UpdateData(int len, uint8* data); void UpdateData(int len, uint8* data);
private: private:
EVP_CIPHER_CTX* m_ctx; EVP_CIPHER_CTX* m_ctx;
}; };
@@ -17,11 +17,11 @@ void AuthCrypt::Init(BigNumber* K)
{ {
uint8 ServerEncryptionKey[SEED_KEY_SIZE] = { 0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA, 0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57 }; uint8 ServerEncryptionKey[SEED_KEY_SIZE] = { 0xCC, 0x98, 0xAE, 0x04, 0xE8, 0x97, 0xEA, 0xCA, 0x12, 0xDD, 0xC0, 0x93, 0x42, 0x91, 0x53, 0x57 };
HmacHash serverEncryptHmac(SEED_KEY_SIZE, (uint8*)ServerEncryptionKey); HmacHash serverEncryptHmac(SEED_KEY_SIZE, (uint8*)ServerEncryptionKey);
uint8 *encryptHash = serverEncryptHmac.ComputeHash(K); uint8* encryptHash = serverEncryptHmac.ComputeHash(K);
uint8 ServerDecryptionKey[SEED_KEY_SIZE] = { 0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5, 0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE }; uint8 ServerDecryptionKey[SEED_KEY_SIZE] = { 0xC2, 0xB3, 0x72, 0x3C, 0xC6, 0xAE, 0xD9, 0xB5, 0x34, 0x3C, 0x53, 0xEE, 0x2F, 0x43, 0x67, 0xCE };
HmacHash clientDecryptHmac(SEED_KEY_SIZE, (uint8*)ServerDecryptionKey); HmacHash clientDecryptHmac(SEED_KEY_SIZE, (uint8*)ServerDecryptionKey);
uint8 *decryptHash = clientDecryptHmac.ComputeHash(K); uint8* decryptHash = clientDecryptHmac.ComputeHash(K);
//ARC4 _serverDecrypt(encryptHash); //ARC4 _serverDecrypt(encryptHash);
_clientDecrypt.Init(decryptHash); _clientDecrypt.Init(decryptHash);
@@ -43,7 +43,7 @@ void AuthCrypt::Init(BigNumber* K)
_initialized = true; _initialized = true;
} }
void AuthCrypt::DecryptRecv(uint8 *data, size_t len) void AuthCrypt::DecryptRecv(uint8* data, size_t len)
{ {
if (!_initialized) if (!_initialized)
return; return;
@@ -51,7 +51,7 @@ void AuthCrypt::DecryptRecv(uint8 *data, size_t len)
_clientDecrypt.UpdateData(len, data); _clientDecrypt.UpdateData(len, data);
} }
void AuthCrypt::EncryptSend(uint8 *data, size_t len) void AuthCrypt::EncryptSend(uint8* data, size_t len)
{ {
if (!_initialized) if (!_initialized)
return; return;
@@ -13,16 +13,16 @@ class BigNumber;
class AuthCrypt class AuthCrypt
{ {
public: public:
AuthCrypt(); AuthCrypt();
void Init(BigNumber* K); void Init(BigNumber* K);
void DecryptRecv(uint8 *, size_t); void DecryptRecv(uint8*, size_t);
void EncryptSend(uint8 *, size_t); void EncryptSend(uint8*, size_t);
bool IsInitialized() const { return _initialized; } bool IsInitialized() const { return _initialized; }
private: private:
ARC4 _clientDecrypt; ARC4 _clientDecrypt;
ARC4 _serverEncrypt; ARC4 _serverEncrypt;
bool _initialized; bool _initialized;
+7 -7
View File
@@ -87,7 +87,7 @@ BigNumber BigNumber::operator-=(BigNumber const& bn)
BigNumber BigNumber::operator*=(BigNumber const& bn) BigNumber BigNumber::operator*=(BigNumber const& bn)
{ {
BN_CTX *bnctx; BN_CTX* bnctx;
bnctx = BN_CTX_new(); bnctx = BN_CTX_new();
BN_mul(_bn, _bn, bn._bn, bnctx); BN_mul(_bn, _bn, bn._bn, bnctx);
@@ -98,7 +98,7 @@ BigNumber BigNumber::operator*=(BigNumber const& bn)
BigNumber BigNumber::operator/=(BigNumber const& bn) BigNumber BigNumber::operator/=(BigNumber const& bn)
{ {
BN_CTX *bnctx; BN_CTX* bnctx;
bnctx = BN_CTX_new(); bnctx = BN_CTX_new();
BN_div(_bn, NULL, _bn, bn._bn, bnctx); BN_div(_bn, NULL, _bn, bn._bn, bnctx);
@@ -109,7 +109,7 @@ BigNumber BigNumber::operator/=(BigNumber const& bn)
BigNumber BigNumber::operator%=(BigNumber const& bn) BigNumber BigNumber::operator%=(BigNumber const& bn)
{ {
BN_CTX *bnctx; BN_CTX* bnctx;
bnctx = BN_CTX_new(); bnctx = BN_CTX_new();
BN_mod(_bn, _bn, bn._bn, bnctx); BN_mod(_bn, _bn, bn._bn, bnctx);
@@ -121,7 +121,7 @@ BigNumber BigNumber::operator%=(BigNumber const& bn)
BigNumber BigNumber::Exp(BigNumber const& bn) BigNumber BigNumber::Exp(BigNumber const& bn)
{ {
BigNumber ret; BigNumber ret;
BN_CTX *bnctx; BN_CTX* bnctx;
bnctx = BN_CTX_new(); bnctx = BN_CTX_new();
BN_exp(ret._bn, _bn, bn._bn, bnctx); BN_exp(ret._bn, _bn, bn._bn, bnctx);
@@ -133,7 +133,7 @@ BigNumber BigNumber::Exp(BigNumber const& bn)
BigNumber BigNumber::ModExp(BigNumber const& bn1, BigNumber const& bn2) BigNumber BigNumber::ModExp(BigNumber const& bn1, BigNumber const& bn2)
{ {
BigNumber ret; BigNumber ret;
BN_CTX *bnctx; BN_CTX* bnctx;
bnctx = BN_CTX_new(); bnctx = BN_CTX_new();
BN_mod_exp(ret._bn, _bn, bn1._bn, bn2._bn, bnctx); BN_mod_exp(ret._bn, _bn, bn1._bn, bn2._bn, bnctx);
@@ -178,12 +178,12 @@ std::unique_ptr<uint8[]> BigNumber::AsByteArray(int32 minSize, bool littleEndian
return ret; return ret;
} }
char * BigNumber::AsHexStr() const char* BigNumber::AsHexStr() const
{ {
return BN_bn2hex(_bn); return BN_bn2hex(_bn);
} }
char * BigNumber::AsDecStr() const char* BigNumber::AsDecStr() const
{ {
return BN_bn2dec(_bn); return BN_bn2dec(_bn);
} }
+6 -6
View File
@@ -17,7 +17,7 @@ struct bignum_st;
class BigNumber class BigNumber
{ {
public: public:
BigNumber(); BigNumber();
BigNumber(BigNumber const& bn); BigNumber(BigNumber const& bn);
BigNumber(uint32); BigNumber(uint32);
@@ -74,17 +74,17 @@ class BigNumber
int32 GetNumBytes(void); int32 GetNumBytes(void);
struct bignum_st *BN() { return _bn; } struct bignum_st* BN() { return _bn; }
uint32 AsDword(); uint32 AsDword();
std::unique_ptr<uint8[]> AsByteArray(int32 minSize = 0, bool littleEndian = true); std::unique_ptr<uint8[]> AsByteArray(int32 minSize = 0, bool littleEndian = true);
char * AsHexStr() const; char* AsHexStr() const;
char * AsDecStr() const; char* AsDecStr() const;
private: private:
struct bignum_st *_bn; struct bignum_st* _bn;
}; };
#endif #endif
+1 -1
View File
@@ -12,7 +12,7 @@
#if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L #if defined(OPENSSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX* HMAC_CTX_new() HMAC_CTX* HMAC_CTX_new()
{ {
HMAC_CTX *ctx = new HMAC_CTX(); HMAC_CTX* ctx = new HMAC_CTX();
HMAC_CTX_init(ctx); HMAC_CTX_init(ctx);
return ctx; return ctx;
} }
+2 -2
View File
@@ -18,7 +18,7 @@ class BigNumber;
class HmacHash class HmacHash
{ {
public: public:
HmacHash(uint32 len, uint8* seed); HmacHash(uint32 len, uint8* seed);
~HmacHash(); ~HmacHash();
void UpdateData(std::string const& str); void UpdateData(std::string const& str);
@@ -27,7 +27,7 @@ class HmacHash
uint8* ComputeHash(BigNumber* bn); uint8* ComputeHash(BigNumber* bn);
uint8* GetDigest() { return m_digest; } uint8* GetDigest() { return m_digest; }
int GetLength() const { return SHA_DIGEST_LENGTH; } int GetLength() const { return SHA_DIGEST_LENGTH; }
private: private:
HMAC_CTX* m_ctx; HMAC_CTX* m_ctx;
uint8 m_digest[SHA_DIGEST_LENGTH]; uint8 m_digest[SHA_DIGEST_LENGTH];
}; };
+1 -1
View File
@@ -19,7 +19,7 @@ static void lockingCallback(int mode, int type, char const* /*file*/, int /*line
else else
cryptoLocks[type]->unlock(); cryptoLocks[type]->unlock();
} }
static void threadIdCallback(CRYPTO_THREADID * id) static void threadIdCallback(CRYPTO_THREADID* id)
{ {
(void)id; (void)id;
CRYPTO_THREADID_set_numeric(id, std::hash<std::thread::id>()(std::this_thread::get_id())); CRYPTO_THREADID_set_numeric(id, std::hash<std::thread::id>()(std::this_thread::get_id()));
+2 -2
View File
@@ -19,12 +19,12 @@ SHA1Hash::~SHA1Hash()
SHA1_Init(&mC); SHA1_Init(&mC);
} }
void SHA1Hash::UpdateData(const uint8 *dta, int len) void SHA1Hash::UpdateData(const uint8* dta, int len)
{ {
SHA1_Update(&mC, dta, len); SHA1_Update(&mC, dta, len);
} }
void SHA1Hash::UpdateData(const std::string &str) void SHA1Hash::UpdateData(const std::string& str)
{ {
UpdateData((uint8 const*)str.c_str(), str.length()); UpdateData((uint8 const*)str.c_str(), str.length());
} }
+5 -5
View File
@@ -15,22 +15,22 @@ class BigNumber;
class SHA1Hash class SHA1Hash
{ {
public: public:
SHA1Hash(); SHA1Hash();
~SHA1Hash(); ~SHA1Hash();
void UpdateBigNumbers(BigNumber* bn0, ...); void UpdateBigNumbers(BigNumber* bn0, ...);
void UpdateData(const uint8 *dta, int len); void UpdateData(const uint8* dta, int len);
void UpdateData(const std::string &str); void UpdateData(const std::string& str);
void Initialize(); void Initialize();
void Finalize(); void Finalize();
uint8 *GetDigest(void) { return mDigest; }; uint8* GetDigest(void) { return mDigest; };
int GetLength(void) const { return SHA_DIGEST_LENGTH; }; int GetLength(void) const { return SHA_DIGEST_LENGTH; };
private: private:
SHA_CTX mC; SHA_CTX mC;
uint8 mDigest[SHA_DIGEST_LENGTH]; uint8 mDigest[SHA_DIGEST_LENGTH];
}; };
@@ -14,7 +14,7 @@ class SHA1Randx
public: public:
SHA1Randx(uint8* buff, uint32 size) SHA1Randx(uint8* buff, uint32 size)
{ {
uint32 taken = size/2; uint32 taken = size / 2;
sh.Initialize(); sh.Initialize();
sh.UpdateData(buff, taken); sh.UpdateData(buff, taken);
+4 -4
View File
@@ -84,7 +84,7 @@ bool DBCFileLoader::Load(char const* filename, char const* fmt)
} }
data = new unsigned char[recordSize * recordCount + stringSize]; data = new unsigned char[recordSize * recordCount + stringSize];
stringTable = data + recordSize*recordCount; stringTable = data + recordSize * recordCount;
if (fread(data, recordSize * recordCount + stringSize, 1, f) != 1) if (fread(data, recordSize * recordCount + stringSize, 1, f) != 1)
{ {
@@ -210,7 +210,7 @@ char* DBCFileLoader::AutoProduceData(char const* format, uint32& records, char**
else else
indexTable[y] = &dataTable[offset]; indexTable[y] = &dataTable[offset];
for (uint32 x=0; x < fieldCount; ++x) for (uint32 x = 0; x < fieldCount; ++x)
{ {
switch (format[x]) switch (format[x])
{ {
@@ -278,9 +278,9 @@ char* DBCFileLoader::AutoProduceStrings(char const* format, char* dataTable)
{ {
// fill only not filled entries // fill only not filled entries
char** slot = (char**)(&dataTable[offset]); char** slot = (char**)(&dataTable[offset]);
if (!*slot || !**slot) if (!*slot || !** slot)
{ {
const char * st = getRecord(y).getString(x); const char* st = getRecord(y).getString(x);
*slot = stringPool + (st - (char const*)stringTable); *slot = stringPool + (st - (char const*)stringTable);
} }
offset += sizeof(char*); offset += sizeof(char*);
+12 -12
View File
@@ -30,7 +30,7 @@ public:
DBCFileLoader(); DBCFileLoader();
~DBCFileLoader(); ~DBCFileLoader();
bool Load(const char *filename, const char *fmt); bool Load(const char* filename, const char* fmt);
class Record class Record
{ {
@@ -38,7 +38,7 @@ public:
float getFloat(size_t field) const float getFloat(size_t field) const
{ {
ASSERT(field < file.fieldCount); ASSERT(field < file.fieldCount);
float val = *reinterpret_cast<float*>(offset+file.GetOffset(field)); float val = *reinterpret_cast<float*>(offset + file.GetOffset(field));
EndianConvert(val); EndianConvert(val);
return val; return val;
} }
@@ -46,7 +46,7 @@ public:
uint32 getUInt(size_t field) const uint32 getUInt(size_t field) const
{ {
ASSERT(field < file.fieldCount); ASSERT(field < file.fieldCount);
uint32 val = *reinterpret_cast<uint32*>(offset+file.GetOffset(field)); uint32 val = *reinterpret_cast<uint32*>(offset + file.GetOffset(field));
EndianConvert(val); EndianConvert(val);
return val; return val;
} }
@@ -54,10 +54,10 @@ public:
uint8 getUInt8(size_t field) const uint8 getUInt8(size_t field) const
{ {
ASSERT(field < file.fieldCount); ASSERT(field < file.fieldCount);
return *reinterpret_cast<uint8*>(offset+file.GetOffset(field)); return *reinterpret_cast<uint8*>(offset + file.GetOffset(field));
} }
const char *getString(size_t field) const const char* getString(size_t field) const
{ {
ASSERT(field < file.fieldCount); ASSERT(field < file.fieldCount);
size_t stringOffset = getUInt(field); size_t stringOffset = getUInt(field);
@@ -66,9 +66,9 @@ public:
} }
private: private:
Record(DBCFileLoader &file_, unsigned char *offset_): offset(offset_), file(file_) { } Record(DBCFileLoader& file_, unsigned char* offset_): offset(offset_), file(file_) { }
unsigned char *offset; unsigned char* offset;
DBCFileLoader &file; DBCFileLoader& file;
friend class DBCFileLoader; friend class DBCFileLoader;
@@ -84,16 +84,16 @@ public:
bool IsLoaded() const { return data != nullptr; } bool IsLoaded() const { return data != nullptr; }
char* AutoProduceData(char const* fmt, uint32& count, char**& indexTable); char* AutoProduceData(char const* fmt, uint32& count, char**& indexTable);
char* AutoProduceStrings(char const* fmt, char* dataTable); char* AutoProduceStrings(char const* fmt, char* dataTable);
static uint32 GetFormatRecordSize(const char * format, int32 * index_pos = nullptr); static uint32 GetFormatRecordSize(const char* format, int32* index_pos = nullptr);
private: private:
uint32 recordSize; uint32 recordSize;
uint32 recordCount; uint32 recordCount;
uint32 fieldCount; uint32 fieldCount;
uint32 stringSize; uint32 stringSize;
uint32 *fieldsOffset; uint32* fieldsOffset;
unsigned char *data; unsigned char* data;
unsigned char *stringTable; unsigned char* stringTable;
DBCFileLoader(DBCFileLoader const& right) = delete; DBCFileLoader(DBCFileLoader const& right) = delete;
DBCFileLoader& operator=(DBCFileLoader const& right) = delete; DBCFileLoader& operator=(DBCFileLoader const& right) = delete;
+3 -3
View File
@@ -9,14 +9,14 @@
/*! Basic, ad-hoc queries. */ /*! Basic, ad-hoc queries. */
BasicStatementTask::BasicStatementTask(const char* sql) : BasicStatementTask::BasicStatementTask(const char* sql) :
m_has_result(false) m_has_result(false)
{ {
m_sql = strdup(sql); m_sql = strdup(sql);
} }
BasicStatementTask::BasicStatementTask(const char* sql, QueryResultFuture result) : BasicStatementTask::BasicStatementTask(const char* sql, QueryResultFuture result) :
m_has_result(true), m_has_result(true),
m_result(result) m_result(result)
{ {
m_sql = strdup(sql); m_sql = strdup(sql);
} }
+2 -2
View File
@@ -14,14 +14,14 @@ typedef ACE_Future<QueryResult> QueryResultFuture;
/*! Raw, ad-hoc query. */ /*! Raw, ad-hoc query. */
class BasicStatementTask : public SQLOperation class BasicStatementTask : public SQLOperation
{ {
public: public:
BasicStatementTask(const char* sql); BasicStatementTask(const char* sql);
BasicStatementTask(const char* sql, QueryResultFuture result); BasicStatementTask(const char* sql, QueryResultFuture result);
~BasicStatementTask(); ~BasicStatementTask();
bool Execute(); bool Execute();
private: private:
const char* m_sql; //- Raw query to be executed const char* m_sql; //- Raw query to be executed
bool m_has_result; bool m_has_result;
QueryResultFuture m_result; QueryResultFuture m_result;
+3 -3
View File
@@ -11,8 +11,8 @@
#include "MySQLThreading.h" #include "MySQLThreading.h"
DatabaseWorker::DatabaseWorker(ACE_Activation_Queue* new_queue, MySQLConnection* con) : DatabaseWorker::DatabaseWorker(ACE_Activation_Queue* new_queue, MySQLConnection* con) :
m_queue(new_queue), m_queue(new_queue),
m_conn(con) m_conn(con)
{ {
/// Assign thread to task /// Assign thread to task
activate(); activate();
@@ -23,7 +23,7 @@ int DatabaseWorker::svc()
if (!m_queue) if (!m_queue)
return -1; return -1;
SQLOperation *request = NULL; SQLOperation* request = NULL;
while (1) while (1)
{ {
request = (SQLOperation*)(m_queue->dequeue()); request = (SQLOperation*)(m_queue->dequeue());
+2 -2
View File
@@ -14,14 +14,14 @@ class MySQLConnection;
class DatabaseWorker : protected ACE_Task_Base class DatabaseWorker : protected ACE_Task_Base
{ {
public: public:
DatabaseWorker(ACE_Activation_Queue* new_queue, MySQLConnection* con); DatabaseWorker(ACE_Activation_Queue* new_queue, MySQLConnection* con);
///- Inherited from ACE_Task_Base ///- Inherited from ACE_Task_Base
int svc(); int svc();
int wait() { return ACE_Task_Base::wait(); } int wait() { return ACE_Task_Base::wait(); }
private: private:
DatabaseWorker() : ACE_Task_Base() { } DatabaseWorker() : ACE_Task_Base() { }
ACE_Activation_Queue* m_queue; ACE_Activation_Queue* m_queue;
MySQLConnection* m_conn; MySQLConnection* m_conn;
+4 -4
View File
@@ -12,8 +12,8 @@
template <class T> template <class T>
DatabaseWorkerPool<T>::DatabaseWorkerPool() : DatabaseWorkerPool<T>::DatabaseWorkerPool() :
_mqueue(new ACE_Message_Queue<ACE_SYNCH>(2*1024*1024, 2*1024*1024)), _mqueue(new ACE_Message_Queue<ACE_SYNCH>(2 * 1024 * 1024, 2 * 1024 * 1024)),
_queue(new ACE_Activation_Queue(_mqueue)) _queue(new ACE_Activation_Queue(_mqueue))
{ {
memset(_connectionCount, 0, sizeof(_connectionCount)); memset(_connectionCount, 0, sizeof(_connectionCount));
_connections.resize(IDX_SIZE); _connections.resize(IDX_SIZE);
@@ -212,7 +212,7 @@ SQLTransaction DatabaseWorkerPool<T>::BeginTransaction()
template <class T> template <class T>
void DatabaseWorkerPool<T>::CommitTransaction(SQLTransaction transaction) void DatabaseWorkerPool<T>::CommitTransaction(SQLTransaction transaction)
{ {
#ifdef ACORE_DEBUG #ifdef ACORE_DEBUG
//! Only analyze transaction weaknesses in Debug mode. //! Only analyze transaction weaknesses in Debug mode.
//! Ideally we catch the faults in Debug mode and then correct them, //! Ideally we catch the faults in Debug mode and then correct them,
//! so there's no need to waste these CPU cycles in Release mode. //! so there's no need to waste these CPU cycles in Release mode.
@@ -227,7 +227,7 @@ void DatabaseWorkerPool<T>::CommitTransaction(SQLTransaction transaction)
default: default:
break; break;
} }
#endif // ACORE_DEBUG #endif // ACORE_DEBUG
Enqueue(new TransactionTask(transaction)); Enqueue(new TransactionTask(transaction));
} }
+8 -8
View File
@@ -34,7 +34,7 @@ class PingOperation : public SQLOperation
template <class T> template <class T>
class DatabaseWorkerPool class DatabaseWorkerPool
{ {
public: public:
/* Activity state */ /* Activity state */
DatabaseWorkerPool(); DatabaseWorkerPool();
@@ -55,7 +55,7 @@ class DatabaseWorkerPool
//! Enqueues a one-way SQL operation in string format -with variable args- that will be executed asynchronously. //! Enqueues a one-way SQL operation in string format -with variable args- that will be executed asynchronously.
//! This method should only be used for queries that are only executed once, e.g during startup. //! This method should only be used for queries that are only executed once, e.g during startup.
template<typename Format, typename... Args> template<typename Format, typename... Args>
void PExecute(Format&& sql, Args&&... args) void PExecute(Format&& sql, Args&& ... args)
{ {
if (acore::IsFormatEmptyOrNull(sql)) if (acore::IsFormatEmptyOrNull(sql))
return; return;
@@ -78,7 +78,7 @@ class DatabaseWorkerPool
//! Directly executes a one-way SQL operation in string format -with variable args-, that will block the calling thread until finished. //! Directly executes a one-way SQL operation in string format -with variable args-, that will block the calling thread until finished.
//! This method should only be used for queries that are only executed once, e.g during startup. //! This method should only be used for queries that are only executed once, e.g during startup.
template<typename Format, typename... Args> template<typename Format, typename... Args>
void DirectPExecute(Format&& sql, Args&&... args) void DirectPExecute(Format&& sql, Args&& ... args)
{ {
if (acore::IsFormatEmptyOrNull(sql)) if (acore::IsFormatEmptyOrNull(sql))
return; return;
@@ -101,7 +101,7 @@ class DatabaseWorkerPool
//! Directly executes an SQL query in string format -with variable args- that will block the calling thread until finished. //! Directly executes an SQL query in string format -with variable args- that will block the calling thread until finished.
//! Returns reference counted auto pointer, no need for manual memory management in upper level code. //! Returns reference counted auto pointer, no need for manual memory management in upper level code.
template<typename Format, typename... Args> template<typename Format, typename... Args>
QueryResult PQuery(Format&& sql, T* conn, Args&&... args) QueryResult PQuery(Format&& sql, T* conn, Args&& ... args)
{ {
if (acore::IsFormatEmptyOrNull(sql)) if (acore::IsFormatEmptyOrNull(sql))
return QueryResult(nullptr); return QueryResult(nullptr);
@@ -112,7 +112,7 @@ class DatabaseWorkerPool
//! Directly executes an SQL query in string format -with variable args- that will block the calling thread until finished. //! Directly executes an SQL query in string format -with variable args- that will block the calling thread until finished.
//! Returns reference counted auto pointer, no need for manual memory management in upper level code. //! Returns reference counted auto pointer, no need for manual memory management in upper level code.
template<typename Format, typename... Args> template<typename Format, typename... Args>
QueryResult PQuery(Format&& sql, Args&&... args) QueryResult PQuery(Format&& sql, Args&& ... args)
{ {
if (acore::IsFormatEmptyOrNull(sql)) if (acore::IsFormatEmptyOrNull(sql))
return QueryResult(nullptr); return QueryResult(nullptr);
@@ -136,7 +136,7 @@ class DatabaseWorkerPool
//! Enqueues a query in string format -with variable args- that will set the value of the QueryResultFuture return object as soon as the query is executed. //! Enqueues a query in string format -with variable args- that will set the value of the QueryResultFuture return object as soon as the query is executed.
//! The return value is then processed in ProcessQueryCallback methods. //! The return value is then processed in ProcessQueryCallback methods.
template<typename Format, typename... Args> template<typename Format, typename... Args>
QueryResultFuture AsyncPQuery(Format&& sql, Args&&... args) QueryResultFuture AsyncPQuery(Format&& sql, Args&& ... args)
{ {
if (acore::IsFormatEmptyOrNull(sql)) if (acore::IsFormatEmptyOrNull(sql))
return QueryResult(nullptr); return QueryResult(nullptr);
@@ -215,7 +215,7 @@ class DatabaseWorkerPool
delete[] buf; delete[] buf;
} }
private: private:
void Enqueue(SQLOperation* op) void Enqueue(SQLOperation* op)
{ {
@@ -226,7 +226,7 @@ class DatabaseWorkerPool
//! Caller MUST call t->Unlock() after touching the MySQL context to prevent deadlocks. //! Caller MUST call t->Unlock() after touching the MySQL context to prevent deadlocks.
T* GetFreeConnection(); T* GetFreeConnection();
private: private:
enum _internalIndex enum _internalIndex
{ {
IDX_ASYNC, IDX_ASYNC,
+1 -1
View File
@@ -44,7 +44,7 @@ void Field::SetStructuredValue(char* newValue, enum_field_types newType)
if (newValue) if (newValue)
{ {
size_t size = strlen(newValue); size_t size = strlen(newValue);
data.value = new char [size+1]; data.value = new char [size + 1];
strcpy((char*)data.value, newValue); strcpy((char*)data.value, newValue);
data.length = size; data.length = size;
} }
+91 -64
View File
@@ -17,7 +17,7 @@ class Field
friend class ResultSet; friend class ResultSet;
friend class PreparedResultSet; friend class PreparedResultSet;
public: public:
bool GetBool() const // Wrapper, actually gets integer bool GetBool() const // Wrapper, actually gets integer
{ {
@@ -29,13 +29,13 @@ class Field
if (!data.value) if (!data.value)
return 0; return 0;
#ifdef ACORE_DEBUG #ifdef ACORE_DEBUG
if (!IsType(MYSQL_TYPE_TINY)) if (!IsType(MYSQL_TYPE_TINY))
{ {
sLog->outSQLDriver("Warning: GetUInt8() on non-tinyint field. Using type: %s.", FieldTypeToString(data.type)); sLog->outSQLDriver("Warning: GetUInt8() on non-tinyint field. Using type: %s.", FieldTypeToString(data.type));
return 0; return 0;
} }
#endif #endif
if (data.raw) if (data.raw)
return *reinterpret_cast<uint8*>(data.value); return *reinterpret_cast<uint8*>(data.value);
@@ -47,13 +47,13 @@ class Field
if (!data.value) if (!data.value)
return 0; return 0;
#ifdef ACORE_DEBUG #ifdef ACORE_DEBUG
if (!IsType(MYSQL_TYPE_TINY)) if (!IsType(MYSQL_TYPE_TINY))
{ {
sLog->outSQLDriver("Warning: GetInt8() on non-tinyint field. Using type: %s.", FieldTypeToString(data.type)); sLog->outSQLDriver("Warning: GetInt8() on non-tinyint field. Using type: %s.", FieldTypeToString(data.type));
return 0; return 0;
} }
#endif #endif
if (data.raw) if (data.raw)
return *reinterpret_cast<int8*>(data.value); return *reinterpret_cast<int8*>(data.value);
@@ -72,13 +72,13 @@ class Field
if (!data.value) if (!data.value)
return 0; return 0;
#ifdef ACORE_DEBUG #ifdef ACORE_DEBUG
if (!IsType(MYSQL_TYPE_SHORT) && !IsType(MYSQL_TYPE_YEAR)) if (!IsType(MYSQL_TYPE_SHORT) && !IsType(MYSQL_TYPE_YEAR))
{ {
sLog->outSQLDriver("Warning: GetUInt16() on non-smallint field. Using type: %s.", FieldTypeToString(data.type)); sLog->outSQLDriver("Warning: GetUInt16() on non-smallint field. Using type: %s.", FieldTypeToString(data.type));
return 0; return 0;
} }
#endif #endif
if (data.raw) if (data.raw)
return *reinterpret_cast<uint16*>(data.value); return *reinterpret_cast<uint16*>(data.value);
@@ -90,13 +90,13 @@ class Field
if (!data.value) if (!data.value)
return 0; return 0;
#ifdef ACORE_DEBUG #ifdef ACORE_DEBUG
if (!IsType(MYSQL_TYPE_SHORT) && !IsType(MYSQL_TYPE_YEAR)) if (!IsType(MYSQL_TYPE_SHORT) && !IsType(MYSQL_TYPE_YEAR))
{ {
sLog->outSQLDriver("Warning: GetInt16() on non-smallint field. Using type: %s.", FieldTypeToString(data.type)); sLog->outSQLDriver("Warning: GetInt16() on non-smallint field. Using type: %s.", FieldTypeToString(data.type));
return 0; return 0;
} }
#endif #endif
if (data.raw) if (data.raw)
return *reinterpret_cast<int16*>(data.value); return *reinterpret_cast<int16*>(data.value);
@@ -108,13 +108,13 @@ class Field
if (!data.value) if (!data.value)
return 0; return 0;
#ifdef ACORE_DEBUG #ifdef ACORE_DEBUG
if (!IsType(MYSQL_TYPE_INT24) && !IsType(MYSQL_TYPE_LONG)) if (!IsType(MYSQL_TYPE_INT24) && !IsType(MYSQL_TYPE_LONG))
{ {
sLog->outSQLDriver("Warning: GetUInt32() on non-(medium)int field. Using type: %s.", FieldTypeToString(data.type)); sLog->outSQLDriver("Warning: GetUInt32() on non-(medium)int field. Using type: %s.", FieldTypeToString(data.type));
return 0; return 0;
} }
#endif #endif
if (data.raw) if (data.raw)
return *reinterpret_cast<uint32*>(data.value); return *reinterpret_cast<uint32*>(data.value);
@@ -126,13 +126,13 @@ class Field
if (!data.value) if (!data.value)
return 0; return 0;
#ifdef ACORE_DEBUG #ifdef ACORE_DEBUG
if (!IsType(MYSQL_TYPE_INT24) && !IsType(MYSQL_TYPE_LONG)) if (!IsType(MYSQL_TYPE_INT24) && !IsType(MYSQL_TYPE_LONG))
{ {
sLog->outSQLDriver("Warning: GetInt32() on non-(medium)int field. Using type: %s.", FieldTypeToString(data.type)); sLog->outSQLDriver("Warning: GetInt32() on non-(medium)int field. Using type: %s.", FieldTypeToString(data.type));
return 0; return 0;
} }
#endif #endif
if (data.raw) if (data.raw)
return *reinterpret_cast<int32*>(data.value); return *reinterpret_cast<int32*>(data.value);
@@ -144,13 +144,13 @@ class Field
if (!data.value) if (!data.value)
return 0; return 0;
#ifdef ACORE_DEBUG #ifdef ACORE_DEBUG
if (!IsType(MYSQL_TYPE_LONGLONG) && !IsType(MYSQL_TYPE_BIT)) if (!IsType(MYSQL_TYPE_LONGLONG) && !IsType(MYSQL_TYPE_BIT))
{ {
sLog->outSQLDriver("Warning: GetUInt64() on non-bigint field. Using type: %s.", FieldTypeToString(data.type)); sLog->outSQLDriver("Warning: GetUInt64() on non-bigint field. Using type: %s.", FieldTypeToString(data.type));
return 0; return 0;
} }
#endif #endif
if (data.raw) if (data.raw)
return *reinterpret_cast<uint64*>(data.value); return *reinterpret_cast<uint64*>(data.value);
@@ -162,13 +162,13 @@ class Field
if (!data.value) if (!data.value)
return 0; return 0;
#ifdef ACORE_DEBUG #ifdef ACORE_DEBUG
if (!IsType(MYSQL_TYPE_LONGLONG) && !IsType(MYSQL_TYPE_BIT)) if (!IsType(MYSQL_TYPE_LONGLONG) && !IsType(MYSQL_TYPE_BIT))
{ {
sLog->outSQLDriver("Warning: GetInt64() on non-bigint field. Using type: %s.", FieldTypeToString(data.type)); sLog->outSQLDriver("Warning: GetInt64() on non-bigint field. Using type: %s.", FieldTypeToString(data.type));
return 0; return 0;
} }
#endif #endif
if (data.raw) if (data.raw)
return *reinterpret_cast<int64*>(data.value); return *reinterpret_cast<int64*>(data.value);
@@ -180,13 +180,13 @@ class Field
if (!data.value) if (!data.value)
return 0.0f; return 0.0f;
#ifdef ACORE_DEBUG #ifdef ACORE_DEBUG
if (!IsType(MYSQL_TYPE_FLOAT)) if (!IsType(MYSQL_TYPE_FLOAT))
{ {
sLog->outSQLDriver("Warning: GetFloat() on non-float field. Using type: %s.", FieldTypeToString(data.type)); sLog->outSQLDriver("Warning: GetFloat() on non-float field. Using type: %s.", FieldTypeToString(data.type));
return 0.0f; return 0.0f;
} }
#endif #endif
if (data.raw) if (data.raw)
return *reinterpret_cast<float*>(data.value); return *reinterpret_cast<float*>(data.value);
@@ -198,13 +198,13 @@ class Field
if (!data.value) if (!data.value)
return 0.0f; return 0.0f;
#ifdef ACORE_DEBUG #ifdef ACORE_DEBUG
if (!IsType(MYSQL_TYPE_DOUBLE)) if (!IsType(MYSQL_TYPE_DOUBLE))
{ {
sLog->outSQLDriver("Warning: GetDouble() on non-double field. Using type: %s.", FieldTypeToString(data.type)); sLog->outSQLDriver("Warning: GetDouble() on non-double field. Using type: %s.", FieldTypeToString(data.type));
return 0.0f; return 0.0f;
} }
#endif #endif
if (data.raw) if (data.raw)
return *reinterpret_cast<double*>(data.value); return *reinterpret_cast<double*>(data.value);
@@ -216,13 +216,13 @@ class Field
if (!data.value) if (!data.value)
return NULL; return NULL;
#ifdef ACORE_DEBUG #ifdef ACORE_DEBUG
if (IsNumeric()) if (IsNumeric())
{ {
sLog->outSQLDriver("Error: GetCString() on numeric field. Using type: %s.", FieldTypeToString(data.type)); sLog->outSQLDriver("Error: GetCString() on numeric field. Using type: %s.", FieldTypeToString(data.type));
return NULL; return NULL;
} }
#endif #endif
return static_cast<char const*>(data.value); return static_cast<char const*>(data.value);
} }
@@ -247,15 +247,15 @@ class Field
return data.value == NULL; return data.value == NULL;
} }
protected: protected:
Field(); Field();
~Field(); ~Field();
#if defined(__GNUC__) #if defined(__GNUC__)
#pragma pack(1) #pragma pack(1)
#else #else
#pragma pack(push, 1) #pragma pack(push, 1)
#endif #endif
struct struct
{ {
uint32 length; // Length (prepared strings only) uint32 length; // Length (prepared strings only)
@@ -263,11 +263,11 @@ class Field
enum_field_types type; // Field type enum_field_types type; // Field type
bool raw; // Raw bytes? (Prepared statement or ad hoc) bool raw; // Raw bytes? (Prepared statement or ad hoc)
} data; } data;
#if defined(__GNUC__) #if defined(__GNUC__)
#pragma pack() #pragma pack()
#else #else
#pragma pack(pop) #pragma pack(pop)
#endif #endif
void SetByteValue(void const* newValue, size_t const newSize, enum_field_types newType, uint32 length); void SetByteValue(void const* newValue, size_t const newSize, enum_field_types newType, uint32 length);
void SetStructuredValue(char* newValue, enum_field_types newType); void SetStructuredValue(char* newValue, enum_field_types newType);
@@ -344,42 +344,69 @@ class Field
data.type == MYSQL_TYPE_LONGLONG ); data.type == MYSQL_TYPE_LONGLONG );
} }
private: private:
#ifdef ACORE_DEBUG #ifdef ACORE_DEBUG
static char const* FieldTypeToString(enum_field_types type) static char const* FieldTypeToString(enum_field_types type)
{ {
switch (type) switch (type)
{ {
case MYSQL_TYPE_BIT: return "BIT"; case MYSQL_TYPE_BIT:
case MYSQL_TYPE_BLOB: return "BLOB"; return "BIT";
case MYSQL_TYPE_DATE: return "DATE"; case MYSQL_TYPE_BLOB:
case MYSQL_TYPE_DATETIME: return "DATETIME"; return "BLOB";
case MYSQL_TYPE_NEWDECIMAL: return "NEWDECIMAL"; case MYSQL_TYPE_DATE:
case MYSQL_TYPE_DECIMAL: return "DECIMAL"; return "DATE";
case MYSQL_TYPE_DOUBLE: return "DOUBLE"; case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_ENUM: return "ENUM"; return "DATETIME";
case MYSQL_TYPE_FLOAT: return "FLOAT"; case MYSQL_TYPE_NEWDECIMAL:
case MYSQL_TYPE_GEOMETRY: return "GEOMETRY"; return "NEWDECIMAL";
case MYSQL_TYPE_INT24: return "INT24"; case MYSQL_TYPE_DECIMAL:
case MYSQL_TYPE_LONG: return "LONG"; return "DECIMAL";
case MYSQL_TYPE_LONGLONG: return "LONGLONG"; case MYSQL_TYPE_DOUBLE:
case MYSQL_TYPE_LONG_BLOB: return "LONG_BLOB"; return "DOUBLE";
case MYSQL_TYPE_MEDIUM_BLOB: return "MEDIUM_BLOB"; case MYSQL_TYPE_ENUM:
case MYSQL_TYPE_NEWDATE: return "NEWDATE"; return "ENUM";
case MYSQL_TYPE_NULL: return "NULL"; case MYSQL_TYPE_FLOAT:
case MYSQL_TYPE_SET: return "SET"; return "FLOAT";
case MYSQL_TYPE_SHORT: return "SHORT"; case MYSQL_TYPE_GEOMETRY:
case MYSQL_TYPE_STRING: return "STRING"; return "GEOMETRY";
case MYSQL_TYPE_TIME: return "TIME"; case MYSQL_TYPE_INT24:
case MYSQL_TYPE_TIMESTAMP: return "TIMESTAMP"; return "INT24";
case MYSQL_TYPE_TINY: return "TINY"; case MYSQL_TYPE_LONG:
case MYSQL_TYPE_TINY_BLOB: return "TINY_BLOB"; return "LONG";
case MYSQL_TYPE_VAR_STRING: return "VAR_STRING"; case MYSQL_TYPE_LONGLONG:
case MYSQL_TYPE_YEAR: return "YEAR"; return "LONGLONG";
default: return "-Unknown-"; case MYSQL_TYPE_LONG_BLOB:
return "LONG_BLOB";
case MYSQL_TYPE_MEDIUM_BLOB:
return "MEDIUM_BLOB";
case MYSQL_TYPE_NEWDATE:
return "NEWDATE";
case MYSQL_TYPE_NULL:
return "NULL";
case MYSQL_TYPE_SET:
return "SET";
case MYSQL_TYPE_SHORT:
return "SHORT";
case MYSQL_TYPE_STRING:
return "STRING";
case MYSQL_TYPE_TIME:
return "TIME";
case MYSQL_TYPE_TIMESTAMP:
return "TIMESTAMP";
case MYSQL_TYPE_TINY:
return "TINY";
case MYSQL_TYPE_TINY_BLOB:
return "TINY_BLOB";
case MYSQL_TYPE_VAR_STRING:
return "VAR_STRING";
case MYSQL_TYPE_YEAR:
return "YEAR";
default:
return "-Unknown-";
} }
} }
#endif #endif
}; };
#endif #endif
@@ -403,7 +403,7 @@ void CharacterDatabaseConnection::DoPrepareStatements()
PrepareStatement(CHAR_DEL_CHAR_AURA_FROZEN, "DELETE FROM character_aura WHERE spell = 9454 AND guid = ?", CONNECTION_ASYNC); PrepareStatement(CHAR_DEL_CHAR_AURA_FROZEN, "DELETE FROM character_aura WHERE spell = 9454 AND guid = ?", CONNECTION_ASYNC);
PrepareStatement(CHAR_SEL_CHAR_INVENTORY_COUNT_ITEM, "SELECT COUNT(itemEntry) FROM character_inventory ci INNER JOIN item_instance ii ON ii.guid = ci.item WHERE itemEntry = ?", CONNECTION_SYNCH); PrepareStatement(CHAR_SEL_CHAR_INVENTORY_COUNT_ITEM, "SELECT COUNT(itemEntry) FROM character_inventory ci INNER JOIN item_instance ii ON ii.guid = ci.item WHERE itemEntry = ?", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_MAIL_COUNT_ITEM, "SELECT COUNT(itemEntry) FROM mail_items mi INNER JOIN item_instance ii ON ii.guid = mi.item_guid WHERE itemEntry = ?", CONNECTION_SYNCH); PrepareStatement(CHAR_SEL_MAIL_COUNT_ITEM, "SELECT COUNT(itemEntry) FROM mail_items mi INNER JOIN item_instance ii ON ii.guid = mi.item_guid WHERE itemEntry = ?", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_AUCTIONHOUSE_COUNT_ITEM,"SELECT COUNT(itemEntry) FROM auctionhouse ah INNER JOIN item_instance ii ON ii.guid = ah.itemguid WHERE itemEntry = ?", CONNECTION_SYNCH); PrepareStatement(CHAR_SEL_AUCTIONHOUSE_COUNT_ITEM, "SELECT COUNT(itemEntry) FROM auctionhouse ah INNER JOIN item_instance ii ON ii.guid = ah.itemguid WHERE itemEntry = ?", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_GUILD_BANK_COUNT_ITEM, "SELECT COUNT(itemEntry) FROM guild_bank_item gbi INNER JOIN item_instance ii ON ii.guid = gbi.item_guid WHERE itemEntry = ?", CONNECTION_SYNCH); PrepareStatement(CHAR_SEL_GUILD_BANK_COUNT_ITEM, "SELECT COUNT(itemEntry) FROM guild_bank_item gbi INNER JOIN item_instance ii ON ii.guid = gbi.item_guid WHERE itemEntry = ?", CONNECTION_SYNCH);
PrepareStatement(CHAR_SEL_CHAR_INVENTORY_ITEM_BY_ENTRY, "SELECT ci.item, cb.slot AS bag, ci.slot, ci.guid, c.account, c.name FROM characters c " PrepareStatement(CHAR_SEL_CHAR_INVENTORY_ITEM_BY_ENTRY, "SELECT ci.item, cb.slot AS bag, ci.slot, ci.guid, c.account, c.name FROM characters c "
"INNER JOIN character_inventory ci ON ci.guid = c.guid " "INNER JOIN character_inventory ci ON ci.guid = c.guid "
@@ -12,7 +12,7 @@
class CharacterDatabaseConnection : public MySQLConnection class CharacterDatabaseConnection : public MySQLConnection
{ {
public: public:
//- Constructors for sync and async connections //- Constructors for sync and async connections
CharacterDatabaseConnection(MySQLConnectionInfo& connInfo) : MySQLConnection(connInfo) {} CharacterDatabaseConnection(MySQLConnectionInfo& connInfo) : MySQLConnection(connInfo) {}
CharacterDatabaseConnection(ACE_Activation_Queue* q, MySQLConnectionInfo& connInfo) : MySQLConnection(q, connInfo) {} CharacterDatabaseConnection(ACE_Activation_Queue* q, MySQLConnectionInfo& connInfo) : MySQLConnection(q, connInfo) {}
@@ -12,7 +12,7 @@
class LoginDatabaseConnection : public MySQLConnection class LoginDatabaseConnection : public MySQLConnection
{ {
public: public:
//- Constructors for sync and async connections //- Constructors for sync and async connections
LoginDatabaseConnection(MySQLConnectionInfo& connInfo) : MySQLConnection(connInfo) { } LoginDatabaseConnection(MySQLConnectionInfo& connInfo) : MySQLConnection(connInfo) { }
LoginDatabaseConnection(ACE_Activation_Queue* q, MySQLConnectionInfo& connInfo) : MySQLConnection(q, connInfo) { } LoginDatabaseConnection(ACE_Activation_Queue* q, MySQLConnectionInfo& connInfo) : MySQLConnection(q, connInfo) { }
@@ -12,7 +12,7 @@
class WorldDatabaseConnection : public MySQLConnection class WorldDatabaseConnection : public MySQLConnection
{ {
public: public:
//- Constructors for sync and async connections //- Constructors for sync and async connections
WorldDatabaseConnection(MySQLConnectionInfo& connInfo) : MySQLConnection(connInfo) { } WorldDatabaseConnection(MySQLConnectionInfo& connInfo) : MySQLConnection(connInfo) { }
WorldDatabaseConnection(ACE_Activation_Queue* q, MySQLConnectionInfo& connInfo) : MySQLConnection(q, connInfo) { } WorldDatabaseConnection(ACE_Activation_Queue* q, MySQLConnectionInfo& connInfo) : MySQLConnection(q, connInfo) { }
+24 -23
View File
@@ -24,23 +24,23 @@
#endif #endif
MySQLConnection::MySQLConnection(MySQLConnectionInfo& connInfo) : MySQLConnection::MySQLConnection(MySQLConnectionInfo& connInfo) :
m_reconnecting(false), m_reconnecting(false),
m_prepareError(false), m_prepareError(false),
m_queue(NULL), m_queue(NULL),
m_worker(NULL), m_worker(NULL),
m_Mysql(NULL), m_Mysql(NULL),
m_connectionInfo(connInfo), m_connectionInfo(connInfo),
m_connectionFlags(CONNECTION_SYNCH) m_connectionFlags(CONNECTION_SYNCH)
{ {
} }
MySQLConnection::MySQLConnection(ACE_Activation_Queue* queue, MySQLConnectionInfo& connInfo) : MySQLConnection::MySQLConnection(ACE_Activation_Queue* queue, MySQLConnectionInfo& connInfo) :
m_reconnecting(false), m_reconnecting(false),
m_prepareError(false), m_prepareError(false),
m_queue(queue), m_queue(queue),
m_Mysql(NULL), m_Mysql(NULL),
m_connectionInfo(connInfo), m_connectionInfo(connInfo),
m_connectionFlags(CONNECTION_ASYNC) m_connectionFlags(CONNECTION_ASYNC)
{ {
m_worker = new DatabaseWorker(m_queue, this); m_worker = new DatabaseWorker(m_queue, this);
} }
@@ -63,7 +63,7 @@ void MySQLConnection::Close()
bool MySQLConnection::Open() bool MySQLConnection::Open()
{ {
MYSQL *mysqlInit; MYSQL* mysqlInit;
mysqlInit = mysql_init(NULL); mysqlInit = mysql_init(NULL);
if (!mysqlInit) if (!mysqlInit)
{ {
@@ -77,7 +77,7 @@ bool MySQLConnection::Open()
mysql_options(mysqlInit, MYSQL_SET_CHARSET_NAME, "utf8"); mysql_options(mysqlInit, MYSQL_SET_CHARSET_NAME, "utf8");
//mysql_options(mysqlInit, MYSQL_OPT_READ_TIMEOUT, (char const*)&timeout); //mysql_options(mysqlInit, MYSQL_OPT_READ_TIMEOUT, (char const*)&timeout);
#ifdef _WIN32 #ifdef _WIN32
if (m_connectionInfo.host == ".") // named pipe use option (Windows) if (m_connectionInfo.host == ".") // named pipe use option (Windows)
{ {
unsigned int opt = MYSQL_PROTOCOL_PIPE; unsigned int opt = MYSQL_PROTOCOL_PIPE;
@@ -90,7 +90,7 @@ bool MySQLConnection::Open()
port = atoi(m_connectionInfo.port_or_socket.c_str()); port = atoi(m_connectionInfo.port_or_socket.c_str());
unix_socket = 0; unix_socket = 0;
} }
#else #else
if (m_connectionInfo.host == ".") // socket use option (Unix/Linux) if (m_connectionInfo.host == ".") // socket use option (Unix/Linux)
{ {
unsigned int opt = MYSQL_PROTOCOL_SOCKET; unsigned int opt = MYSQL_PROTOCOL_SOCKET;
@@ -104,13 +104,14 @@ bool MySQLConnection::Open()
port = atoi(m_connectionInfo.port_or_socket.c_str()); port = atoi(m_connectionInfo.port_or_socket.c_str());
unix_socket = 0; unix_socket = 0;
} }
#endif #endif
// Possible improvement for future: make ATTEMPTS and SECONDS configurable values // Possible improvement for future: make ATTEMPTS and SECONDS configurable values
uint32 const ATTEMPTS = 180; uint32 const ATTEMPTS = 180;
uint32 count = 0; uint32 count = 0;
do { do
{
m_Mysql = mysql_real_connect( m_Mysql = mysql_real_connect(
mysqlInit, mysqlInit,
m_connectionInfo.host.c_str(), m_connectionInfo.host.c_str(),
@@ -250,7 +251,7 @@ bool MySQLConnection::Execute(PreparedStatement* stmt)
} }
} }
bool MySQLConnection::_Query(PreparedStatement* stmt, MYSQL_RES **pResult, uint64* pRowCount, uint32* pFieldCount) bool MySQLConnection::_Query(PreparedStatement* stmt, MYSQL_RES** pResult, uint64* pRowCount, uint32* pFieldCount)
{ {
if (!m_Mysql) if (!m_Mysql)
return false; return false;
@@ -315,8 +316,8 @@ ResultSet* MySQLConnection::Query(const char* sql)
if (!sql) if (!sql)
return NULL; return NULL;
MYSQL_RES *result = NULL; MYSQL_RES* result = NULL;
MYSQL_FIELD *fields = NULL; MYSQL_FIELD* fields = NULL;
uint64 rowCount = 0; uint64 rowCount = 0;
uint32 fieldCount = 0; uint32 fieldCount = 0;
@@ -326,7 +327,7 @@ ResultSet* MySQLConnection::Query(const char* sql)
return new ResultSet(result, fields, rowCount, fieldCount); return new ResultSet(result, fields, rowCount, fieldCount);
} }
bool MySQLConnection::_Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64* pRowCount, uint32* pFieldCount) bool MySQLConnection::_Query(const char* sql, MYSQL_RES** pResult, MYSQL_FIELD** pFields, uint64* pRowCount, uint32* pFieldCount)
{ {
if (!m_Mysql) if (!m_Mysql)
return false; return false;
@@ -490,7 +491,7 @@ void MySQLConnection::PrepareStatement(uint32 index, const char* sql, Connection
PreparedResultSet* MySQLConnection::Query(PreparedStatement* stmt) PreparedResultSet* MySQLConnection::Query(PreparedStatement* stmt)
{ {
MYSQL_RES *result = NULL; MYSQL_RES* result = NULL;
uint64 rowCount = 0; uint64 rowCount = 0;
uint32 fieldCount = 0; uint32 fieldCount = 0;
+9 -9
View File
@@ -58,7 +58,7 @@ class MySQLConnection
template <class T> friend class DatabaseWorkerPool; template <class T> friend class DatabaseWorkerPool;
friend class PingOperation; friend class PingOperation;
public: public:
MySQLConnection(MySQLConnectionInfo& connInfo); //! Constructor for synchronous connections. MySQLConnection(MySQLConnectionInfo& connInfo); //! Constructor for synchronous connections.
MySQLConnection(ACE_Activation_Queue* queue, MySQLConnectionInfo& connInfo); //! Constructor for asynchronous connections. MySQLConnection(ACE_Activation_Queue* queue, MySQLConnectionInfo& connInfo); //! Constructor for asynchronous connections.
virtual ~MySQLConnection(); virtual ~MySQLConnection();
@@ -66,13 +66,13 @@ class MySQLConnection
virtual bool Open(); virtual bool Open();
void Close(); void Close();
public: public:
bool Execute(const char* sql); bool Execute(const char* sql);
bool Execute(PreparedStatement* stmt); bool Execute(PreparedStatement* stmt);
ResultSet* Query(const char* sql); ResultSet* Query(const char* sql);
PreparedResultSet* Query(PreparedStatement* stmt); PreparedResultSet* Query(PreparedStatement* stmt);
bool _Query(const char *sql, MYSQL_RES **pResult, MYSQL_FIELD **pFields, uint64* pRowCount, uint32* pFieldCount); bool _Query(const char* sql, MYSQL_RES** pResult, MYSQL_FIELD** pFields, uint64* pRowCount, uint32* pFieldCount);
bool _Query(PreparedStatement* stmt, MYSQL_RES **pResult, uint64* pRowCount, uint32* pFieldCount); bool _Query(PreparedStatement* stmt, MYSQL_RES** pResult, uint64* pRowCount, uint32* pFieldCount);
void BeginTransaction(); void BeginTransaction();
void RollbackTransaction(); void RollbackTransaction();
@@ -84,7 +84,7 @@ class MySQLConnection
uint32 GetLastError() { return mysql_errno(m_Mysql); } uint32 GetLastError() { return mysql_errno(m_Mysql); }
protected: protected:
bool LockIfReady() bool LockIfReady()
{ {
/// Tries to acquire lock. If lock is acquired by another thread /// Tries to acquire lock. If lock is acquired by another thread
@@ -105,19 +105,19 @@ class MySQLConnection
bool PrepareStatements(); bool PrepareStatements();
virtual void DoPrepareStatements() = 0; virtual void DoPrepareStatements() = 0;
protected: protected:
std::vector<MySQLPreparedStatement*> m_stmts; //! PreparedStatements storage std::vector<MySQLPreparedStatement*> m_stmts; //! PreparedStatements storage
PreparedStatementMap m_queries; //! Query storage PreparedStatementMap m_queries; //! Query storage
bool m_reconnecting; //! Are we reconnecting? bool m_reconnecting; //! Are we reconnecting?
bool m_prepareError; //! Was there any error while preparing statements? bool m_prepareError; //! Was there any error while preparing statements?
private: private:
bool _HandleMySQLErrno(uint32 errNo); bool _HandleMySQLErrno(uint32 errNo);
private: private:
ACE_Activation_Queue* m_queue; //! Queue shared with other asynchronous connections. ACE_Activation_Queue* m_queue; //! Queue shared with other asynchronous connections.
DatabaseWorker* m_worker; //! Core worker task. DatabaseWorker* m_worker; //! Core worker task.
MYSQL * m_Mysql; //! MySQL Handle. MYSQL* m_Mysql; //! MySQL Handle.
MySQLConnectionInfo& m_connectionInfo; //! Connection info (used for logging) MySQLConnectionInfo& m_connectionInfo; //! Connection info (used for logging)
ConnectionFlags m_connectionFlags; //! Connection flags (for preparing relevant statements) ConnectionFlags m_connectionFlags; //! Connection flags (for preparing relevant statements)
ACE_Thread_Mutex m_Mutex; ACE_Thread_Mutex m_Mutex;
+1 -1
View File
@@ -11,7 +11,7 @@
class MySQL class MySQL
{ {
public: public:
/*! Create a thread on the MySQL server to mirrior the calling thread, /*! Create a thread on the MySQL server to mirrior the calling thread,
initializes thread-specific variables and allows thread-specific initializes thread-specific variables and allows thread-specific
operations without concurrence from other threads. operations without concurrence from other threads.
+30 -30
View File
@@ -9,8 +9,8 @@
#include "Log.h" #include "Log.h"
PreparedStatement::PreparedStatement(uint32 index) : PreparedStatement::PreparedStatement(uint32 index) :
m_stmt(NULL), m_stmt(NULL),
m_index(index) m_index(index)
{ {
} }
@@ -68,17 +68,17 @@ void PreparedStatement::BindParameters()
break; break;
} }
} }
#ifdef _DEBUG #ifdef _DEBUG
if (i < m_stmt->m_paramCount) if (i < m_stmt->m_paramCount)
sLog->outSQLDriver("[WARNING]: BindParameters() for statement %u did not bind all allocated parameters", m_index); sLog->outSQLDriver("[WARNING]: BindParameters() for statement %u did not bind all allocated parameters", m_index);
#endif #endif
} }
//- Bind to buffer //- Bind to buffer
void PreparedStatement::setBool(const uint8 index, const bool value) void PreparedStatement::setBool(const uint8 index, const bool value)
{ {
if (index >= statement_data.size()) if (index >= statement_data.size())
statement_data.resize(index+1); statement_data.resize(index + 1);
statement_data[index].data.boolean = value; statement_data[index].data.boolean = value;
statement_data[index].type = TYPE_BOOL; statement_data[index].type = TYPE_BOOL;
@@ -87,7 +87,7 @@ void PreparedStatement::setBool(const uint8 index, const bool value)
void PreparedStatement::setUInt8(const uint8 index, const uint8 value) void PreparedStatement::setUInt8(const uint8 index, const uint8 value)
{ {
if (index >= statement_data.size()) if (index >= statement_data.size())
statement_data.resize(index+1); statement_data.resize(index + 1);
statement_data[index].data.ui8 = value; statement_data[index].data.ui8 = value;
statement_data[index].type = TYPE_UI8; statement_data[index].type = TYPE_UI8;
@@ -96,7 +96,7 @@ void PreparedStatement::setUInt8(const uint8 index, const uint8 value)
void PreparedStatement::setUInt16(const uint8 index, const uint16 value) void PreparedStatement::setUInt16(const uint8 index, const uint16 value)
{ {
if (index >= statement_data.size()) if (index >= statement_data.size())
statement_data.resize(index+1); statement_data.resize(index + 1);
statement_data[index].data.ui16 = value; statement_data[index].data.ui16 = value;
statement_data[index].type = TYPE_UI16; statement_data[index].type = TYPE_UI16;
@@ -105,7 +105,7 @@ void PreparedStatement::setUInt16(const uint8 index, const uint16 value)
void PreparedStatement::setUInt32(const uint8 index, const uint32 value) void PreparedStatement::setUInt32(const uint8 index, const uint32 value)
{ {
if (index >= statement_data.size()) if (index >= statement_data.size())
statement_data.resize(index+1); statement_data.resize(index + 1);
statement_data[index].data.ui32 = value; statement_data[index].data.ui32 = value;
statement_data[index].type = TYPE_UI32; statement_data[index].type = TYPE_UI32;
@@ -114,7 +114,7 @@ void PreparedStatement::setUInt32(const uint8 index, const uint32 value)
void PreparedStatement::setUInt64(const uint8 index, const uint64 value) void PreparedStatement::setUInt64(const uint8 index, const uint64 value)
{ {
if (index >= statement_data.size()) if (index >= statement_data.size())
statement_data.resize(index+1); statement_data.resize(index + 1);
statement_data[index].data.ui64 = value; statement_data[index].data.ui64 = value;
statement_data[index].type = TYPE_UI64; statement_data[index].type = TYPE_UI64;
@@ -123,7 +123,7 @@ void PreparedStatement::setUInt64(const uint8 index, const uint64 value)
void PreparedStatement::setInt8(const uint8 index, const int8 value) void PreparedStatement::setInt8(const uint8 index, const int8 value)
{ {
if (index >= statement_data.size()) if (index >= statement_data.size())
statement_data.resize(index+1); statement_data.resize(index + 1);
statement_data[index].data.i8 = value; statement_data[index].data.i8 = value;
statement_data[index].type = TYPE_I8; statement_data[index].type = TYPE_I8;
@@ -132,7 +132,7 @@ void PreparedStatement::setInt8(const uint8 index, const int8 value)
void PreparedStatement::setInt16(const uint8 index, const int16 value) void PreparedStatement::setInt16(const uint8 index, const int16 value)
{ {
if (index >= statement_data.size()) if (index >= statement_data.size())
statement_data.resize(index+1); statement_data.resize(index + 1);
statement_data[index].data.i16 = value; statement_data[index].data.i16 = value;
statement_data[index].type = TYPE_I16; statement_data[index].type = TYPE_I16;
@@ -141,7 +141,7 @@ void PreparedStatement::setInt16(const uint8 index, const int16 value)
void PreparedStatement::setInt32(const uint8 index, const int32 value) void PreparedStatement::setInt32(const uint8 index, const int32 value)
{ {
if (index >= statement_data.size()) if (index >= statement_data.size())
statement_data.resize(index+1); statement_data.resize(index + 1);
statement_data[index].data.i32 = value; statement_data[index].data.i32 = value;
statement_data[index].type = TYPE_I32; statement_data[index].type = TYPE_I32;
@@ -150,7 +150,7 @@ void PreparedStatement::setInt32(const uint8 index, const int32 value)
void PreparedStatement::setInt64(const uint8 index, const int64 value) void PreparedStatement::setInt64(const uint8 index, const int64 value)
{ {
if (index >= statement_data.size()) if (index >= statement_data.size())
statement_data.resize(index+1); statement_data.resize(index + 1);
statement_data[index].data.i64 = value; statement_data[index].data.i64 = value;
statement_data[index].type = TYPE_I64; statement_data[index].type = TYPE_I64;
@@ -159,7 +159,7 @@ void PreparedStatement::setInt64(const uint8 index, const int64 value)
void PreparedStatement::setFloat(const uint8 index, const float value) void PreparedStatement::setFloat(const uint8 index, const float value)
{ {
if (index >= statement_data.size()) if (index >= statement_data.size())
statement_data.resize(index+1); statement_data.resize(index + 1);
statement_data[index].data.f = value; statement_data[index].data.f = value;
statement_data[index].type = TYPE_FLOAT; statement_data[index].type = TYPE_FLOAT;
@@ -168,7 +168,7 @@ void PreparedStatement::setFloat(const uint8 index, const float value)
void PreparedStatement::setDouble(const uint8 index, const double value) void PreparedStatement::setDouble(const uint8 index, const double value)
{ {
if (index >= statement_data.size()) if (index >= statement_data.size())
statement_data.resize(index+1); statement_data.resize(index + 1);
statement_data[index].data.d = value; statement_data[index].data.d = value;
statement_data[index].type = TYPE_DOUBLE; statement_data[index].type = TYPE_DOUBLE;
@@ -177,7 +177,7 @@ void PreparedStatement::setDouble(const uint8 index, const double value)
void PreparedStatement::setString(const uint8 index, const std::string& value) void PreparedStatement::setString(const uint8 index, const std::string& value)
{ {
if (index >= statement_data.size()) if (index >= statement_data.size())
statement_data.resize(index+1); statement_data.resize(index + 1);
statement_data[index].str = value; statement_data[index].str = value;
statement_data[index].type = TYPE_STRING; statement_data[index].type = TYPE_STRING;
@@ -186,15 +186,15 @@ void PreparedStatement::setString(const uint8 index, const std::string& value)
void PreparedStatement::setNull(const uint8 index) void PreparedStatement::setNull(const uint8 index)
{ {
if (index >= statement_data.size()) if (index >= statement_data.size())
statement_data.resize(index+1); statement_data.resize(index + 1);
statement_data[index].type = TYPE_NULL; statement_data[index].type = TYPE_NULL;
} }
MySQLPreparedStatement::MySQLPreparedStatement(MYSQL_STMT* stmt) : MySQLPreparedStatement::MySQLPreparedStatement(MYSQL_STMT* stmt) :
m_stmt(NULL), m_stmt(NULL),
m_Mstmt(stmt), m_Mstmt(stmt),
m_bind(NULL) m_bind(NULL)
{ {
/// Initialize variable parameters /// Initialize variable parameters
m_paramCount = mysql_stmt_param_count(stmt); m_paramCount = mysql_stmt_param_count(stmt);
@@ -221,7 +221,7 @@ MySQLPreparedStatement::~MySQLPreparedStatement()
void MySQLPreparedStatement::ClearParameters() void MySQLPreparedStatement::ClearParameters()
{ {
for (uint32 i=0; i < m_paramCount; ++i) for (uint32 i = 0; i < m_paramCount; ++i)
{ {
delete m_bind[i].length; delete m_bind[i].length;
m_bind[i].length = NULL; m_bind[i].length = NULL;
@@ -339,12 +339,12 @@ void MySQLPreparedStatement::setString(const uint8 index, const char* value)
MYSQL_BIND* param = &m_bind[index]; MYSQL_BIND* param = &m_bind[index];
size_t len = strlen(value) + 1; size_t len = strlen(value) + 1;
param->buffer_type = MYSQL_TYPE_VAR_STRING; param->buffer_type = MYSQL_TYPE_VAR_STRING;
delete [] static_cast<char *>(param->buffer); delete [] static_cast<char*>(param->buffer);
param->buffer = new char[len]; param->buffer = new char[len];
param->buffer_length = len; param->buffer_length = len;
param->is_null_value = 0; param->is_null_value = 0;
delete param->length; delete param->length;
param->length = new unsigned long(len-1); param->length = new unsigned long(len - 1);
memcpy(param->buffer, value, len); memcpy(param->buffer, value, len);
} }
@@ -355,7 +355,7 @@ void MySQLPreparedStatement::setNull(const uint8 index)
m_paramsSet[index] = true; m_paramsSet[index] = true;
MYSQL_BIND* param = &m_bind[index]; MYSQL_BIND* param = &m_bind[index];
param->buffer_type = MYSQL_TYPE_NULL; param->buffer_type = MYSQL_TYPE_NULL;
delete [] static_cast<char *>(param->buffer); delete [] static_cast<char*>(param->buffer);
param->buffer = NULL; param->buffer = NULL;
param->buffer_length = 0; param->buffer_length = 0;
param->is_null_value = 1; param->is_null_value = 1;
@@ -366,7 +366,7 @@ void MySQLPreparedStatement::setNull(const uint8 index)
void MySQLPreparedStatement::setValue(MYSQL_BIND* param, enum_field_types type, const void* value, uint32 len, bool isUnsigned) void MySQLPreparedStatement::setValue(MYSQL_BIND* param, enum_field_types type, const void* value, uint32 len, bool isUnsigned)
{ {
param->buffer_type = type; param->buffer_type = type;
delete [] static_cast<char *>(param->buffer); delete [] static_cast<char*>(param->buffer);
param->buffer = new char[len]; param->buffer = new char[len];
param->buffer_length = 0; param->buffer_length = 0;
param->is_null_value = 0; param->is_null_value = 0;
@@ -439,15 +439,15 @@ std::string MySQLPreparedStatement::getQueryString(std::string const& sqlPattern
//- Execution //- Execution
PreparedStatementTask::PreparedStatementTask(PreparedStatement* stmt) : PreparedStatementTask::PreparedStatementTask(PreparedStatement* stmt) :
m_stmt(stmt), m_stmt(stmt),
m_has_result(false) m_has_result(false)
{ {
} }
PreparedStatementTask::PreparedStatementTask(PreparedStatement* stmt, PreparedQueryResultFuture result) : PreparedStatementTask::PreparedStatementTask(PreparedStatement* stmt, PreparedQueryResultFuture result) :
m_stmt(stmt), m_stmt(stmt),
m_has_result(true), m_has_result(true),
m_result(result) m_result(result)
{ {
} }
+9 -9
View File
@@ -65,7 +65,7 @@ class PreparedStatement
friend class MySQLPreparedStatement; friend class MySQLPreparedStatement;
friend class MySQLConnection; friend class MySQLConnection;
public: public:
explicit PreparedStatement(uint32 index); explicit PreparedStatement(uint32 index);
~PreparedStatement(); ~PreparedStatement();
@@ -83,10 +83,10 @@ class PreparedStatement
void setString(const uint8 index, const std::string& value); void setString(const uint8 index, const std::string& value);
void setNull(const uint8 index); void setNull(const uint8 index);
protected: protected:
void BindParameters(); void BindParameters();
protected: protected:
MySQLPreparedStatement* m_stmt; MySQLPreparedStatement* m_stmt;
uint32 m_index; uint32 m_index;
std::vector<PreparedStatementData> statement_data; //- Buffer of parameters, not tied to MySQL in any way yet std::vector<PreparedStatementData> statement_data; //- Buffer of parameters, not tied to MySQL in any way yet
@@ -100,7 +100,7 @@ class MySQLPreparedStatement
friend class MySQLConnection; friend class MySQLConnection;
friend class PreparedStatement; friend class PreparedStatement;
public: public:
MySQLPreparedStatement(MYSQL_STMT* stmt); MySQLPreparedStatement(MYSQL_STMT* stmt);
~MySQLPreparedStatement(); ~MySQLPreparedStatement();
@@ -118,7 +118,7 @@ class MySQLPreparedStatement
void setString(const uint8 index, const char* value); void setString(const uint8 index, const char* value);
void setNull(const uint8 index); void setNull(const uint8 index);
protected: protected:
MYSQL_STMT* GetSTMT() { return m_Mstmt; } MYSQL_STMT* GetSTMT() { return m_Mstmt; }
MYSQL_BIND* GetBind() { return m_bind; } MYSQL_BIND* GetBind() { return m_bind; }
PreparedStatement* m_stmt; PreparedStatement* m_stmt;
@@ -126,10 +126,10 @@ class MySQLPreparedStatement
bool CheckValidIndex(uint8 index); bool CheckValidIndex(uint8 index);
std::string getQueryString(std::string const& sqlPattern) const; std::string getQueryString(std::string const& sqlPattern) const;
private: private:
void setValue(MYSQL_BIND* param, enum_field_types type, const void* value, uint32 len, bool isUnsigned); void setValue(MYSQL_BIND* param, enum_field_types type, const void* value, uint32 len, bool isUnsigned);
private: private:
MYSQL_STMT* m_Mstmt; MYSQL_STMT* m_Mstmt;
uint32 m_paramCount; uint32 m_paramCount;
std::vector<bool> m_paramsSet; std::vector<bool> m_paramsSet;
@@ -141,14 +141,14 @@ typedef ACE_Future<PreparedQueryResult> PreparedQueryResultFuture;
//- Lower-level class, enqueuable operation //- Lower-level class, enqueuable operation
class PreparedStatementTask : public SQLOperation class PreparedStatementTask : public SQLOperation
{ {
public: public:
PreparedStatementTask(PreparedStatement* stmt); PreparedStatementTask(PreparedStatement* stmt);
PreparedStatementTask(PreparedStatement* stmt, PreparedQueryResultFuture result); PreparedStatementTask(PreparedStatement* stmt, PreparedQueryResultFuture result);
~PreparedStatementTask(); ~PreparedStatementTask();
bool Execute(); bool Execute();
protected: protected:
PreparedStatement* m_stmt; PreparedStatement* m_stmt;
bool m_has_result; bool m_has_result;
PreparedQueryResultFuture m_result; PreparedQueryResultFuture m_result;
+3 -3
View File
@@ -9,7 +9,7 @@
#include "PreparedStatement.h" #include "PreparedStatement.h"
#include "Log.h" #include "Log.h"
bool SQLQueryHolder::SetQuery(size_t index, const char *sql) bool SQLQueryHolder::SetQuery(size_t index, const char* sql)
{ {
if (m_queries.size() <= index) if (m_queries.size() <= index)
{ {
@@ -29,7 +29,7 @@ bool SQLQueryHolder::SetQuery(size_t index, const char *sql)
return true; return true;
} }
bool SQLQueryHolder::SetPQuery(size_t index, const char *format, ...) bool SQLQueryHolder::SetPQuery(size_t index, const char* format, ...)
{ {
if (!format) if (!format)
{ {
@@ -165,7 +165,7 @@ bool SQLQueryHolderTask::Execute()
return false; return false;
/// we can do this, we are friends /// we can do this, we are friends
std::vector<SQLQueryHolder::SQLResultPair> &queries = m_holder->m_queries; std::vector<SQLQueryHolder::SQLResultPair>& queries = m_holder->m_queries;
for (size_t i = 0; i < queries.size(); i++) for (size_t i = 0; i < queries.size(); i++)
{ {
+9 -9
View File
@@ -12,14 +12,14 @@
class SQLQueryHolder class SQLQueryHolder
{ {
friend class SQLQueryHolderTask; friend class SQLQueryHolderTask;
private: private:
typedef std::pair<SQLElementData, SQLResultSetUnion> SQLResultPair; typedef std::pair<SQLElementData, SQLResultSetUnion> SQLResultPair;
std::vector<SQLResultPair> m_queries; std::vector<SQLResultPair> m_queries;
public: public:
SQLQueryHolder() { } SQLQueryHolder() { }
~SQLQueryHolder(); ~SQLQueryHolder();
bool SetQuery(size_t index, const char *sql); bool SetQuery(size_t index, const char* sql);
bool SetPQuery(size_t index, const char *format, ...) ATTR_PRINTF(3, 4); bool SetPQuery(size_t index, const char* format, ...) ATTR_PRINTF(3, 4);
bool SetPreparedQuery(size_t index, PreparedStatement* stmt); bool SetPreparedQuery(size_t index, PreparedStatement* stmt);
void SetSize(size_t size); void SetSize(size_t size);
QueryResult GetResult(size_t index); QueryResult GetResult(size_t index);
@@ -32,13 +32,13 @@ typedef ACE_Future<SQLQueryHolder*> QueryResultHolderFuture;
class SQLQueryHolderTask : public SQLOperation class SQLQueryHolderTask : public SQLOperation
{ {
private: private:
SQLQueryHolder * m_holder; SQLQueryHolder* m_holder;
QueryResultHolderFuture m_result; QueryResultHolderFuture m_result;
public: public:
SQLQueryHolderTask(SQLQueryHolder *holder, QueryResultHolderFuture res) SQLQueryHolderTask(SQLQueryHolder* holder, QueryResultHolderFuture res)
: m_holder(holder), m_result(res){ }; : m_holder(holder), m_result(res) { };
bool Execute(); bool Execute();
}; };
+14 -14
View File
@@ -7,25 +7,25 @@
#include "DatabaseEnv.h" #include "DatabaseEnv.h"
#include "Log.h" #include "Log.h"
ResultSet::ResultSet(MYSQL_RES *result, MYSQL_FIELD *fields, uint64 rowCount, uint32 fieldCount) : ResultSet::ResultSet(MYSQL_RES* result, MYSQL_FIELD* fields, uint64 rowCount, uint32 fieldCount) :
_rowCount(rowCount), _rowCount(rowCount),
_fieldCount(fieldCount), _fieldCount(fieldCount),
_result(result), _result(result),
_fields(fields) _fields(fields)
{ {
_currentRow = new Field[_fieldCount]; _currentRow = new Field[_fieldCount];
ASSERT(_currentRow); ASSERT(_currentRow);
} }
PreparedResultSet::PreparedResultSet(MYSQL_STMT* stmt, MYSQL_RES *result, uint64 rowCount, uint32 fieldCount) : PreparedResultSet::PreparedResultSet(MYSQL_STMT* stmt, MYSQL_RES* result, uint64 rowCount, uint32 fieldCount) :
m_rowCount(rowCount), m_rowCount(rowCount),
m_rowPosition(0), m_rowPosition(0),
m_fieldCount(fieldCount), m_fieldCount(fieldCount),
m_rBind(NULL), m_rBind(NULL),
m_stmt(stmt), m_stmt(stmt),
m_res(result), m_res(result),
m_isNull(NULL), m_isNull(NULL),
m_length(NULL) m_length(NULL)
{ {
if (!m_res) if (!m_res)
return; return;
+9 -9
View File
@@ -14,7 +14,7 @@
#include "Field.h" #include "Field.h"
#ifdef _WIN32 #ifdef _WIN32
#include <winsock2.h> #include <winsock2.h>
#endif #endif
#include <mysql.h> #include <mysql.h>
@@ -24,7 +24,7 @@ typedef bool my_bool;
class ResultSet class ResultSet
{ {
public: public:
ResultSet(MYSQL_RES* result, MYSQL_FIELD* fields, uint64 rowCount, uint32 fieldCount); ResultSet(MYSQL_RES* result, MYSQL_FIELD* fields, uint64 rowCount, uint32 fieldCount);
~ResultSet(); ~ResultSet();
@@ -35,18 +35,18 @@ class ResultSet
std::string GetFieldName(uint32 index) const; std::string GetFieldName(uint32 index) const;
#endif #endif
Field* Fetch() const { return _currentRow; } Field* Fetch() const { return _currentRow; }
const Field & operator [] (uint32 index) const const Field& operator [] (uint32 index) const
{ {
ASSERT(index < _fieldCount); ASSERT(index < _fieldCount);
return _currentRow[index]; return _currentRow[index];
} }
protected: protected:
uint64 _rowCount; uint64 _rowCount;
Field* _currentRow; Field* _currentRow;
uint32 _fieldCount; uint32 _fieldCount;
private: private:
void CleanUp(); void CleanUp();
MYSQL_RES* _result; MYSQL_RES* _result;
MYSQL_FIELD* _fields; MYSQL_FIELD* _fields;
@@ -56,7 +56,7 @@ typedef acore::AutoPtr<ResultSet, ACE_Thread_Mutex> QueryResult;
class PreparedResultSet class PreparedResultSet
{ {
public: public:
PreparedResultSet(MYSQL_STMT* stmt, MYSQL_RES* result, uint64 rowCount, uint32 fieldCount); PreparedResultSet(MYSQL_STMT* stmt, MYSQL_RES* result, uint64 rowCount, uint32 fieldCount);
~PreparedResultSet(); ~PreparedResultSet();
@@ -70,20 +70,20 @@ class PreparedResultSet
return m_rows[uint32(m_rowPosition)]; return m_rows[uint32(m_rowPosition)];
} }
const Field & operator [] (uint32 index) const const Field& operator [] (uint32 index) const
{ {
ASSERT(m_rowPosition < m_rowCount); ASSERT(m_rowPosition < m_rowCount);
ASSERT(index < m_fieldCount); ASSERT(index < m_fieldCount);
return m_rows[uint32(m_rowPosition)][index]; return m_rows[uint32(m_rowPosition)][index];
} }
protected: protected:
std::vector<Field*> m_rows; std::vector<Field*> m_rows;
uint64 m_rowCount; uint64 m_rowCount;
uint64 m_rowPosition; uint64 m_rowPosition;
uint32 m_fieldCount; uint32 m_fieldCount;
private: private:
MYSQL_BIND* m_rBind; MYSQL_BIND* m_rBind;
MYSQL_STMT* m_stmt; MYSQL_STMT* m_stmt;
MYSQL_RES* m_res; MYSQL_RES* m_res;
+1 -1
View File
@@ -47,7 +47,7 @@ class MySQLConnection;
class SQLOperation : public ACE_Method_Request class SQLOperation : public ACE_Method_Request
{ {
public: public:
SQLOperation(): m_conn(NULL) { } SQLOperation(): m_conn(NULL) { }
virtual int call() virtual int call()
{ {
+1 -1
View File
@@ -44,7 +44,7 @@ void Transaction::Cleanup()
while (!m_queries.empty()) while (!m_queries.empty())
{ {
SQLElementData const &data = m_queries.front(); SQLElementData const& data = m_queries.front();
switch (data.type) switch (data.type)
{ {
case SQL_ELEMENT_PREPARED: case SQL_ELEMENT_PREPARED:
+6 -6
View File
@@ -21,7 +21,7 @@ class Transaction
template <typename T> template <typename T>
friend class DatabaseWorkerPool; friend class DatabaseWorkerPool;
public: public:
Transaction() : _cleanedUp(false) { } Transaction() : _cleanedUp(false) { }
~Transaction() { Cleanup(); } ~Transaction() { Cleanup(); }
@@ -31,11 +31,11 @@ class Transaction
size_t GetSize() const { return m_queries.size(); } size_t GetSize() const { return m_queries.size(); }
protected: protected:
void Cleanup(); void Cleanup();
std::list<SQLElementData> m_queries; std::list<SQLElementData> m_queries;
private: private:
bool _cleanedUp; bool _cleanedUp;
}; };
@@ -47,11 +47,11 @@ class TransactionTask : public SQLOperation
template <class T> friend class DatabaseWorkerPool; template <class T> friend class DatabaseWorkerPool;
friend class DatabaseWorker; friend class DatabaseWorker;
public: public:
TransactionTask(SQLTransaction trans) : m_trans(trans) { } ; TransactionTask(SQLTransaction trans) : m_trans(trans) { } ;
~TransactionTask(){ }; ~TransactionTask() { };
protected: protected:
bool Execute(); bool Execute();
SQLTransaction m_trans; SQLTransaction m_trans;
+21 -21
View File
@@ -57,16 +57,16 @@ namespace
namespace acore namespace acore
{ {
void Assert(char const* file, int line, char const* function, std::string const& debugInfo, char const* message) void Assert(char const* file, int line, char const* function, std::string const& debugInfo, char const* message)
{ {
std::string formattedMessage = acore::StringFormat("\n%s:%i in %s ASSERTION FAILED:\n %s\n", file, line, function, message) + debugInfo + '\n'; std::string formattedMessage = acore::StringFormat("\n%s:%i in %s ASSERTION FAILED:\n %s\n", file, line, function, message) + debugInfo + '\n';
fprintf(stderr, "%s", formattedMessage.c_str()); fprintf(stderr, "%s", formattedMessage.c_str());
fflush(stderr); fflush(stderr);
Crash(formattedMessage.c_str()); Crash(formattedMessage.c_str());
} }
void Assert(char const* file, int line, char const* function, std::string const& debugInfo, char const* message, char const* format, ...) void Assert(char const* file, int line, char const* function, std::string const& debugInfo, char const* message, char const* format, ...)
{ {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
@@ -77,10 +77,10 @@ void Assert(char const* file, int line, char const* function, std::string const&
fflush(stderr); fflush(stderr);
Crash(formattedMessage.c_str()); Crash(formattedMessage.c_str());
} }
void Fatal(char const* file, int line, char const* function, char const* message, ...) void Fatal(char const* file, int line, char const* function, char const* message, ...)
{ {
va_list args; va_list args;
va_start(args, message); va_start(args, message);
@@ -92,38 +92,38 @@ void Fatal(char const* file, int line, char const* function, char const* message
std::this_thread::sleep_for(std::chrono::seconds(10)); std::this_thread::sleep_for(std::chrono::seconds(10));
Crash(formattedMessage.c_str()); Crash(formattedMessage.c_str());
} }
void Error(char const* file, int line, char const* function, char const* message) void Error(char const* file, int line, char const* function, char const* message)
{ {
std::string formattedMessage = acore::StringFormat("\n%s:%i in %s ERROR:\n %s\n", file, line, function, message); std::string formattedMessage = acore::StringFormat("\n%s:%i in %s ERROR:\n %s\n", file, line, function, message);
fprintf(stderr, "%s", formattedMessage.c_str()); fprintf(stderr, "%s", formattedMessage.c_str());
fflush(stderr); fflush(stderr);
Crash(formattedMessage.c_str()); Crash(formattedMessage.c_str());
} }
void Warning(char const* file, int line, char const* function, char const* message) void Warning(char const* file, int line, char const* function, char const* message)
{ {
fprintf(stderr, "\n%s:%i in %s WARNING:\n %s\n", fprintf(stderr, "\n%s:%i in %s WARNING:\n %s\n",
file, line, function, message); file, line, function, message);
} }
void Abort(char const* file, int line, char const* function) void Abort(char const* file, int line, char const* function)
{ {
std::string formattedMessage = acore::StringFormat("\n%s:%i in %s ABORTED.\n", file, line, function); std::string formattedMessage = acore::StringFormat("\n%s:%i in %s ABORTED.\n", file, line, function);
fprintf(stderr, "%s", formattedMessage.c_str()); fprintf(stderr, "%s", formattedMessage.c_str());
fflush(stderr); fflush(stderr);
Crash(formattedMessage.c_str()); Crash(formattedMessage.c_str());
} }
void AbortHandler(int sigval) void AbortHandler(int sigval)
{ {
// nothing useful to log here, no way to pass args // nothing useful to log here, no way to pass args
std::string formattedMessage = acore::StringFormat("Caught signal %i\n", sigval); std::string formattedMessage = acore::StringFormat("Caught signal %i\n", sigval);
fprintf(stderr, "%s", formattedMessage.c_str()); fprintf(stderr, "%s", formattedMessage.c_str());
fflush(stderr); fflush(stderr);
Crash(formattedMessage.c_str()); Crash(formattedMessage.c_str());
} }
} // namespace acore } // namespace acore
+47 -46
View File
@@ -110,7 +110,7 @@ WheatyExceptionReport::~WheatyExceptionReport()
// Entry point where control comes on an unhandled exception // Entry point where control comes on an unhandled exception
//=========================================================== //===========================================================
LONG WINAPI WheatyExceptionReport::WheatyUnhandledExceptionFilter( LONG WINAPI WheatyExceptionReport::WheatyUnhandledExceptionFilter(
PEXCEPTION_POINTERS pExceptionInfo) PEXCEPTION_POINTERS pExceptionInfo)
{ {
std::unique_lock<std::mutex> guard(alreadyCrashedLock); std::unique_lock<std::mutex> guard(alreadyCrashedLock);
// Handle only 1 exception in the whole process lifetime // Handle only 1 exception in the whole process lifetime
@@ -272,13 +272,13 @@ BOOL WheatyExceptionReport::_GetWindowsVersion(TCHAR* szVersion, DWORD cntMax)
// Windows NT product family. // Windows NT product family.
case VER_PLATFORM_WIN32_NT: case VER_PLATFORM_WIN32_NT:
{ {
#if WINVER < 0x0500 #if WINVER < 0x0500
BYTE suiteMask = osvi.wReserved[0]; BYTE suiteMask = osvi.wReserved[0];
BYTE productType = osvi.wReserved[1]; BYTE productType = osvi.wReserved[1];
#else #else
WORD suiteMask = osvi.wSuiteMask; WORD suiteMask = osvi.wSuiteMask;
BYTE productType = osvi.wProductType; BYTE productType = osvi.wProductType;
#endif // WINVER < 0x0500 #endif // WINVER < 0x0500
// Test for the specific product family. // Test for the specific product family.
if (osvi.dwMajorVersion == 10) if (osvi.dwMajorVersion == 10)
@@ -434,10 +434,10 @@ void WheatyExceptionReport::PrintSystemInfo()
Log(_T("//=====================================================\r\n")); Log(_T("//=====================================================\r\n"));
if (_GetProcessorName(sString, countof(sString))) if (_GetProcessorName(sString, countof(sString)))
Log(_T("*** Hardware ***\r\nProcessor: %s\r\nNumber Of Processors: %d\r\nPhysical Memory: %d KB (Available: %d KB)\r\nCommit Charge Limit: %d KB\r\n"), Log(_T("*** Hardware ***\r\nProcessor: %s\r\nNumber Of Processors: %d\r\nPhysical Memory: %d KB (Available: %d KB)\r\nCommit Charge Limit: %d KB\r\n"),
sString, SystemInfo.dwNumberOfProcessors, MemoryStatus.dwTotalPhys/0x400, MemoryStatus.dwAvailPhys/0x400, MemoryStatus.dwTotalPageFile/0x400); sString, SystemInfo.dwNumberOfProcessors, MemoryStatus.dwTotalPhys / 0x400, MemoryStatus.dwAvailPhys / 0x400, MemoryStatus.dwTotalPageFile / 0x400);
else else
Log(_T("*** Hardware ***\r\nProcessor: <unknown>\r\nNumber Of Processors: %d\r\nPhysical Memory: %d KB (Available: %d KB)\r\nCommit Charge Limit: %d KB\r\n"), Log(_T("*** Hardware ***\r\nProcessor: <unknown>\r\nNumber Of Processors: %d\r\nPhysical Memory: %d KB (Available: %d KB)\r\nCommit Charge Limit: %d KB\r\n"),
SystemInfo.dwNumberOfProcessors, MemoryStatus.dwTotalPhys/0x400, MemoryStatus.dwAvailPhys/0x400, MemoryStatus.dwTotalPageFile/0x400); SystemInfo.dwNumberOfProcessors, MemoryStatus.dwTotalPhys / 0x400, MemoryStatus.dwAvailPhys / 0x400, MemoryStatus.dwTotalPageFile / 0x400);
if (_GetWindowsVersion(sString, countof(sString))) if (_GetWindowsVersion(sString, countof(sString)))
Log(_T("\r\n*** Operation System ***\r\n%s\r\n"), sString); Log(_T("\r\n*** Operation System ***\r\n%s\r\n"), sString);
@@ -488,7 +488,7 @@ void WheatyExceptionReport::printTracesForAllThreads(bool bWriteVariables)
} }
} while (Thread32Next(hThreadSnap, &te32)); } while (Thread32Next(hThreadSnap, &te32));
// Don't forget to clean up the snapshot object. // Don't forget to clean up the snapshot object.
CloseHandle(hThreadSnap); CloseHandle(hThreadSnap);
} }
@@ -497,7 +497,7 @@ void WheatyExceptionReport::printTracesForAllThreads(bool bWriteVariables)
// WheatyUnhandledExceptionFilter // WheatyUnhandledExceptionFilter
//=========================================================================== //===========================================================================
void WheatyExceptionReport::GenerateExceptionReport( void WheatyExceptionReport::GenerateExceptionReport(
PEXCEPTION_POINTERS pExceptionInfo) PEXCEPTION_POINTERS pExceptionInfo)
{ {
__try __try
{ {
@@ -612,7 +612,7 @@ PEXCEPTION_POINTERS pExceptionInfo)
//====================================================================== //======================================================================
LPTSTR WheatyExceptionReport::GetExceptionString(DWORD dwCode) LPTSTR WheatyExceptionReport::GetExceptionString(DWORD dwCode)
{ {
#define EXCEPTION(x) case EXCEPTION_##x: return _T(#x); #define EXCEPTION(x) case EXCEPTION_##x: return _T(#x);
switch (dwCode) switch (dwCode)
{ {
@@ -660,7 +660,7 @@ LPTSTR WheatyExceptionReport::GetExceptionString(DWORD dwCode)
// by the len parameter (in characters!) // by the len parameter (in characters!)
//============================================================================= //=============================================================================
BOOL WheatyExceptionReport::GetLogicalAddress( BOOL WheatyExceptionReport::GetLogicalAddress(
PVOID addr, PTSTR szModule, DWORD len, DWORD& section, DWORD_PTR& offset) PVOID addr, PTSTR szModule, DWORD len, DWORD& section, DWORD_PTR& offset)
{ {
MEMORY_BASIC_INFORMATION mbi; MEMORY_BASIC_INFORMATION mbi;
@@ -701,7 +701,7 @@ PVOID addr, PTSTR szModule, DWORD len, DWORD& section, DWORD_PTR& offset)
// Yes, address is in the section. Calculate section and offset, // Yes, address is in the section. Calculate section and offset,
// and store in the "section" & "offset" params, which were // and store in the "section" & "offset" params, which were
// passed by reference. // passed by reference.
section = i+1; section = i + 1;
offset = rva - sectionStart; offset = rva - sectionStart;
return TRUE; return TRUE;
} }
@@ -725,8 +725,8 @@ struct CSymbolInfoPackage : public SYMBOL_INFO_PACKAGE
// Walks the stack, and writes the results to the report file // Walks the stack, and writes the results to the report file
//============================================================ //============================================================
void WheatyExceptionReport::WriteStackDetails( void WheatyExceptionReport::WriteStackDetails(
PCONTEXT pContext, PCONTEXT pContext,
bool bWriteVariables, HANDLE pThreadHandle) // true if local/params should be output bool bWriteVariables, HANDLE pThreadHandle) // true if local/params should be output
{ {
Log(_T("\r\nCall stack:\r\n")); Log(_T("\r\nCall stack:\r\n"));
@@ -738,7 +738,7 @@ bool bWriteVariables, HANDLE pThreadHandle)
STACKFRAME64 sf; STACKFRAME64 sf;
memset(&sf, 0, sizeof(sf)); memset(&sf, 0, sizeof(sf));
#ifdef _M_IX86 #ifdef _M_IX86
// Initialize the STACKFRAME structure for the first call. This is only // Initialize the STACKFRAME structure for the first call. This is only
// necessary for Intel CPUs, and isn't mentioned in the documentation. // necessary for Intel CPUs, and isn't mentioned in the documentation.
sf.AddrPC.Offset = pContext->Eip; sf.AddrPC.Offset = pContext->Eip;
@@ -749,7 +749,7 @@ bool bWriteVariables, HANDLE pThreadHandle)
sf.AddrFrame.Mode = AddrModeFlat; sf.AddrFrame.Mode = AddrModeFlat;
dwMachineType = IMAGE_FILE_MACHINE_I386; dwMachineType = IMAGE_FILE_MACHINE_I386;
#endif #endif
#ifdef _M_X64 #ifdef _M_X64
sf.AddrPC.Offset = pContext->Rip; sf.AddrPC.Offset = pContext->Rip;
@@ -847,9 +847,9 @@ bool bWriteVariables, HANDLE pThreadHandle)
BOOL CALLBACK BOOL CALLBACK
WheatyExceptionReport::EnumerateSymbolsCallback( WheatyExceptionReport::EnumerateSymbolsCallback(
PSYMBOL_INFO pSymInfo, PSYMBOL_INFO pSymInfo,
ULONG /*SymbolSize*/, ULONG /*SymbolSize*/,
PVOID UserContext) PVOID UserContext)
{ {
__try __try
{ {
@@ -871,8 +871,8 @@ PVOID UserContext)
// values. // values.
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
bool WheatyExceptionReport::FormatSymbolValue( bool WheatyExceptionReport::FormatSymbolValue(
PSYMBOL_INFO pSym, PSYMBOL_INFO pSym,
STACKFRAME64 * sf) STACKFRAME64* sf)
{ {
// If it's a function, don't do anything. // If it's a function, don't do anything.
if (pSym->Tag == SymTagFunction) // SymTagFunction from CVCONST.H from the DIA SDK if (pSym->Tag == SymTagFunction) // SymTagFunction from CVCONST.H from the DIA SDK
@@ -883,7 +883,8 @@ STACKFRAME64 * sf)
if (pSym->Flags & IMAGEHLP_SYMBOL_INFO_REGRELATIVE) if (pSym->Flags & IMAGEHLP_SYMBOL_INFO_REGRELATIVE)
{ {
// if (pSym->Register == 8) // EBP is the value 8 (in DBGHELP 5.1) // if (pSym->Register == 8) // EBP is the value 8 (in DBGHELP 5.1)
{ // This may change!!! {
// This may change!!!
#ifdef _M_IX86 #ifdef _M_IX86
pVariable = sf->AddrFrame.Offset; pVariable = sf->AddrFrame.Offset;
#elif _M_X64 #elif _M_X64
@@ -942,14 +943,14 @@ STACKFRAME64 * sf)
// bHandled = false, so that FormatSymbolValue() will format them. // bHandled = false, so that FormatSymbolValue() will format them.
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
void WheatyExceptionReport::DumpTypeIndex( void WheatyExceptionReport::DumpTypeIndex(
DWORD64 modBase, DWORD64 modBase,
DWORD dwTypeIndex, DWORD dwTypeIndex,
DWORD_PTR offset, DWORD_PTR offset,
bool & bHandled, bool& bHandled,
char const* Name, char const* Name,
char* /*suffix*/, char* /*suffix*/,
bool newSymbol, bool newSymbol,
bool logChildren) bool logChildren)
{ {
bHandled = false; bHandled = false;
@@ -962,7 +963,7 @@ bool logChildren)
// Get the name of the symbol. This will either be a Type name (if a UDT), // Get the name of the symbol. This will either be a Type name (if a UDT),
// or the structure member name. // or the structure member name.
WCHAR * pwszTypeName; WCHAR* pwszTypeName;
if (SymGetTypeInfo(m_hProcess, modBase, dwTypeIndex, TI_GET_SYMNAME, if (SymGetTypeInfo(m_hProcess, modBase, dwTypeIndex, TI_GET_SYMNAME,
&pwszTypeName)) &pwszTypeName))
{ {
@@ -1196,12 +1197,12 @@ bool logChildren)
// TI_FINDCHILDREN_PARAMS struct has. Use derivation to accomplish this. // TI_FINDCHILDREN_PARAMS struct has. Use derivation to accomplish this.
struct FINDCHILDREN : TI_FINDCHILDREN_PARAMS struct FINDCHILDREN : TI_FINDCHILDREN_PARAMS
{ {
ULONG MoreChildIds[1024*2]; ULONG MoreChildIds[1024 * 2];
FINDCHILDREN(){Count = sizeof(MoreChildIds) / sizeof(MoreChildIds[0]);} FINDCHILDREN() {Count = sizeof(MoreChildIds) / sizeof(MoreChildIds[0]);}
} children; } children;
children.Count = dwChildrenCount; children.Count = dwChildrenCount;
children.Start= 0; children.Start = 0;
// Get the array of TypeIds, one for each child type // Get the array of TypeIds, one for each child type
if (!SymGetTypeInfo(m_hProcess, modBase, dwTypeIndex, TI_FINDCHILDREN, if (!SymGetTypeInfo(m_hProcess, modBase, dwTypeIndex, TI_FINDCHILDREN,
@@ -1282,12 +1283,12 @@ bool logChildren)
return; return;
} }
void WheatyExceptionReport::FormatOutputValue(char * pszCurrBuffer, void WheatyExceptionReport::FormatOutputValue(char* pszCurrBuffer,
BasicType basicType, BasicType basicType,
DWORD64 length, DWORD64 length,
PVOID pAddress, PVOID pAddress,
size_t bufferSize, size_t bufferSize,
size_t countOverride) size_t countOverride)
{ {
__try __try
{ {
@@ -1333,7 +1334,7 @@ size_t countOverride)
if (basicType == btFloat) if (basicType == btFloat)
{ {
pszCurrBuffer += sprintf(pszCurrBuffer, "%f", pszCurrBuffer += sprintf(pszCurrBuffer, "%f",
*(double *)pAddress); *(double*)pAddress);
} }
else else
pszCurrBuffer += sprintf(pszCurrBuffer, "0x%I64X", pszCurrBuffer += sprintf(pszCurrBuffer, "0x%I64X",
@@ -1341,11 +1342,11 @@ size_t countOverride)
} }
else else
{ {
#if _WIN64 #if _WIN64
pszCurrBuffer += sprintf(pszCurrBuffer, "0x%I64X", (DWORD64)pAddress); pszCurrBuffer += sprintf(pszCurrBuffer, "0x%I64X", (DWORD64)pAddress);
#else #else
pszCurrBuffer += sprintf(pszCurrBuffer, "0x%X", (DWORD)pAddress); pszCurrBuffer += sprintf(pszCurrBuffer, "0x%X", (DWORD)pAddress);
#endif #endif
} }
break; break;
} }
@@ -1401,7 +1402,7 @@ DWORD_PTR WheatyExceptionReport::DereferenceUnsafePointer(DWORD_PTR address)
// Helper function that writes to the report file, and allows the user to use // Helper function that writes to the report file, and allows the user to use
// printf style formating // printf style formating
//============================================================================ //============================================================================
int __cdecl WheatyExceptionReport::Log(const TCHAR * format, ...) int __cdecl WheatyExceptionReport::Log(const TCHAR* format, ...)
{ {
int retValue; int retValue;
va_list argptr; va_list argptr;
@@ -1417,7 +1418,7 @@ int __cdecl WheatyExceptionReport::Log(const TCHAR * format, ...)
return retValue; return retValue;
} }
int __cdecl WheatyExceptionReport::StackLog(const TCHAR * format, va_list argptr) int __cdecl WheatyExceptionReport::StackLog(const TCHAR* format, va_list argptr)
{ {
int retValue; int retValue;
DWORD cbWritten; DWORD cbWritten;
@@ -1429,7 +1430,7 @@ int __cdecl WheatyExceptionReport::StackLog(const TCHAR * format, va_list argptr
return retValue; return retValue;
} }
int __cdecl WheatyExceptionReport::HeapLog(const TCHAR * format, va_list argptr) int __cdecl WheatyExceptionReport::HeapLog(const TCHAR* format, va_list argptr)
{ {
int retValue = 0; int retValue = 0;
DWORD cbWritten; DWORD cbWritten;
+9 -9
View File
@@ -133,7 +133,7 @@ struct SymbolDetail
class WheatyExceptionReport class WheatyExceptionReport
{ {
public: public:
WheatyExceptionReport(); WheatyExceptionReport();
~WheatyExceptionReport(); ~WheatyExceptionReport();
@@ -145,7 +145,7 @@ class WheatyExceptionReport
static void __cdecl WheatyCrtHandler(wchar_t const* expression, wchar_t const* function, wchar_t const* file, unsigned int line, uintptr_t pReserved); static void __cdecl WheatyCrtHandler(wchar_t const* expression, wchar_t const* function, wchar_t const* file, unsigned int line, uintptr_t pReserved);
static void printTracesForAllThreads(bool); static void printTracesForAllThreads(bool);
private: private:
// where report info is extracted and generated // where report info is extracted and generated
static void GenerateExceptionReport(PEXCEPTION_POINTERS pExceptionInfo); static void GenerateExceptionReport(PEXCEPTION_POINTERS pExceptionInfo);
static void PrintSystemInfo(); static void PrintSystemInfo();
@@ -161,20 +161,20 @@ class WheatyExceptionReport
static BOOL CALLBACK EnumerateSymbolsCallback(PSYMBOL_INFO, ULONG, PVOID); static BOOL CALLBACK EnumerateSymbolsCallback(PSYMBOL_INFO, ULONG, PVOID);
static bool FormatSymbolValue(PSYMBOL_INFO, STACKFRAME64 *); static bool FormatSymbolValue(PSYMBOL_INFO, STACKFRAME64*);
static void DumpTypeIndex(DWORD64, DWORD, DWORD_PTR, bool &, char const*, char*, bool, bool); static void DumpTypeIndex(DWORD64, DWORD, DWORD_PTR, bool&, char const*, char*, bool, bool);
static void FormatOutputValue(char * pszCurrBuffer, BasicType basicType, DWORD64 length, PVOID pAddress, size_t bufferSize, size_t countOverride = 0); static void FormatOutputValue(char* pszCurrBuffer, BasicType basicType, DWORD64 length, PVOID pAddress, size_t bufferSize, size_t countOverride = 0);
static BasicType GetBasicType(DWORD typeIndex, DWORD64 modBase); static BasicType GetBasicType(DWORD typeIndex, DWORD64 modBase);
static DWORD_PTR DereferenceUnsafePointer(DWORD_PTR address); static DWORD_PTR DereferenceUnsafePointer(DWORD_PTR address);
static int __cdecl Log(const TCHAR * format, ...); static int __cdecl Log(const TCHAR* format, ...);
static int __cdecl StackLog(const TCHAR * format, va_list argptr); static int __cdecl StackLog(const TCHAR* format, va_list argptr);
static int __cdecl HeapLog(const TCHAR * format, va_list argptr); static int __cdecl HeapLog(const TCHAR* format, va_list argptr);
static bool StoreSymbol(DWORD type , DWORD_PTR offset); static bool StoreSymbol(DWORD type, DWORD_PTR offset);
static void ClearSymbols(); static void ClearSymbols();
// Variables used by the class // Variables used by the class
+2 -2
View File
@@ -41,9 +41,9 @@ private:
template<class T> template<class T>
class Permissible class Permissible
{ {
public: public:
virtual ~Permissible() { } virtual ~Permissible() { }
virtual int Permit(const T *) const = 0; virtual int Permit(const T*) const = 0;
}; };
#endif #endif
+51 -33
View File
@@ -15,12 +15,12 @@ class LinkedListHead;
class LinkedListElement class LinkedListElement
{ {
private: private:
friend class LinkedListHead; friend class LinkedListHead;
LinkedListElement* iNext; LinkedListElement* iNext;
LinkedListElement* iPrev; LinkedListElement* iPrev;
public: public:
LinkedListElement(): iNext(NULL), iPrev(NULL) { } LinkedListElement(): iNext(NULL), iPrev(NULL) { }
~LinkedListElement() { delink(); } ~LinkedListElement() { delink(); }
@@ -28,21 +28,24 @@ class LinkedListElement
bool hasPrev() const { return(iPrev && iPrev->iPrev != NULL); } bool hasPrev() const { return(iPrev && iPrev->iPrev != NULL); }
bool isInList() const { return(iNext != NULL && iPrev != NULL); } bool isInList() const { return(iNext != NULL && iPrev != NULL); }
LinkedListElement * next() { return hasNext() ? iNext : NULL; } LinkedListElement* next() { return hasNext() ? iNext : NULL; }
LinkedListElement const* next() const { return hasNext() ? iNext : NULL; } LinkedListElement const* next() const { return hasNext() ? iNext : NULL; }
LinkedListElement * prev() { return hasPrev() ? iPrev : NULL; } LinkedListElement* prev() { return hasPrev() ? iPrev : NULL; }
LinkedListElement const* prev() const { return hasPrev() ? iPrev : NULL; } LinkedListElement const* prev() const { return hasPrev() ? iPrev : NULL; }
LinkedListElement * nocheck_next() { return iNext; } LinkedListElement* nocheck_next() { return iNext; }
LinkedListElement const* nocheck_next() const { return iNext; } LinkedListElement const* nocheck_next() const { return iNext; }
LinkedListElement * nocheck_prev() { return iPrev; } LinkedListElement* nocheck_prev() { return iPrev; }
LinkedListElement const* nocheck_prev() const { return iPrev; } LinkedListElement const* nocheck_prev() const { return iPrev; }
void delink() void delink()
{ {
if (isInList()) if (isInList())
{ {
iNext->iPrev = iPrev; iPrev->iNext = iNext; iNext = NULL; iPrev = NULL; iNext->iPrev = iPrev;
iPrev->iNext = iNext;
iNext = NULL;
iPrev = NULL;
} }
} }
@@ -67,11 +70,11 @@ class LinkedListElement
class LinkedListHead class LinkedListHead
{ {
private: private:
LinkedListElement iFirst; LinkedListElement iFirst;
LinkedListElement iLast; LinkedListElement iLast;
uint32 iSize; uint32 iSize;
public: public:
LinkedListHead(): iSize(0) LinkedListHead(): iSize(0)
{ {
// create empty list // create empty list
@@ -82,10 +85,10 @@ class LinkedListHead
bool isEmpty() const { return(!iFirst.iNext->isInList()); } bool isEmpty() const { return(!iFirst.iNext->isInList()); }
LinkedListElement * getFirst() { return(isEmpty() ? NULL : iFirst.iNext); } LinkedListElement* getFirst() { return(isEmpty() ? NULL : iFirst.iNext); }
LinkedListElement const* getFirst() const { return(isEmpty() ? NULL : iFirst.iNext); } LinkedListElement const* getFirst() const { return(isEmpty() ? NULL : iFirst.iNext); }
LinkedListElement * getLast() { return(isEmpty() ? NULL : iLast.iPrev); } LinkedListElement* getLast() { return(isEmpty() ? NULL : iLast.iPrev); }
LinkedListElement const* getLast() const { return(isEmpty() ? NULL : iLast.iPrev); } LinkedListElement const* getLast() const { return(isEmpty() ? NULL : iLast.iPrev); }
void insertFirst(LinkedListElement* pElem) void insertFirst(LinkedListElement* pElem)
@@ -129,96 +132,111 @@ class LinkedListHead
typedef _Ty* pointer; typedef _Ty* pointer;
typedef _Ty const* const_pointer; typedef _Ty const* const_pointer;
typedef _Ty& reference; typedef _Ty& reference;
typedef _Ty const & const_reference; typedef _Ty const& const_reference;
Iterator() : _Ptr(0) Iterator() : _Ptr(0)
{ // construct with null node pointer {
// construct with null node pointer
} }
Iterator(pointer _Pnode) : _Ptr(_Pnode) Iterator(pointer _Pnode) : _Ptr(_Pnode)
{ // construct with node pointer _Pnode {
// construct with node pointer _Pnode
} }
Iterator& operator=(Iterator const &_Right) Iterator& operator=(Iterator const& _Right)
{ {
_Ptr = _Right._Ptr; _Ptr = _Right._Ptr;
return *this; return *this;
} }
Iterator& operator=(const_pointer const &_Right) Iterator& operator=(const_pointer const& _Right)
{ {
_Ptr = pointer(_Right); _Ptr = pointer(_Right);
return *this; return *this;
} }
reference operator*() reference operator*()
{ // return designated value {
// return designated value
return *_Ptr; return *_Ptr;
} }
pointer operator->() pointer operator->()
{ // return pointer to class object {
// return pointer to class object
return _Ptr; return _Ptr;
} }
Iterator& operator++() Iterator& operator++()
{ // preincrement {
// preincrement
_Ptr = _Ptr->next(); _Ptr = _Ptr->next();
return (*this); return (*this);
} }
Iterator operator++(int) Iterator operator++(int)
{ // postincrement {
// postincrement
iterator _Tmp = *this; iterator _Tmp = *this;
++*this; ++*this;
return (_Tmp); return (_Tmp);
} }
Iterator& operator--() Iterator& operator--()
{ // predecrement {
// predecrement
_Ptr = _Ptr->prev(); _Ptr = _Ptr->prev();
return (*this); return (*this);
} }
Iterator operator--(int) Iterator operator--(int)
{ // postdecrement {
// postdecrement
iterator _Tmp = *this; iterator _Tmp = *this;
--*this; --*this;
return (_Tmp); return (_Tmp);
} }
bool operator==(Iterator const &_Right) const bool operator==(Iterator const& _Right) const
{ // test for iterator equality {
// test for iterator equality
return (_Ptr == _Right._Ptr); return (_Ptr == _Right._Ptr);
} }
bool operator!=(Iterator const &_Right) const bool operator!=(Iterator const& _Right) const
{ // test for iterator inequality {
// test for iterator inequality
return (!(*this == _Right)); return (!(*this == _Right));
} }
bool operator==(pointer const &_Right) const bool operator==(pointer const& _Right) const
{ // test for pointer equality {
// test for pointer equality
return (_Ptr != _Right); return (_Ptr != _Right);
} }
bool operator!=(pointer const &_Right) const bool operator!=(pointer const& _Right) const
{ // test for pointer equality {
// test for pointer equality
return (!(*this == _Right)); return (!(*this == _Right));
} }
bool operator==(const_reference _Right) const bool operator==(const_reference _Right) const
{ // test for reference equality {
// test for reference equality
return (_Ptr == &_Right); return (_Ptr == &_Right);
} }
bool operator!=(const_reference _Right) const bool operator!=(const_reference _Right) const
{ // test for reference equality {
// test for reference equality
return (_Ptr != &_Right); return (_Ptr != &_Right);
} }
pointer _Mynode() pointer _Mynode()
{ // return node pointer {
// return node pointer
return (_Ptr); return (_Ptr);
} }
@@ -13,7 +13,7 @@
template <class TO, class FROM> class RefManager : public LinkedListHead template <class TO, class FROM> class RefManager : public LinkedListHead
{ {
public: public:
typedef LinkedListHead::Iterator< Reference<TO, FROM> > iterator; typedef LinkedListHead::Iterator< Reference<TO, FROM> > iterator;
RefManager() { } RefManager() { }
virtual ~RefManager() { clearReferences(); } virtual ~RefManager() { clearReferences(); }
@@ -14,10 +14,10 @@
template <class TO, class FROM> class Reference : public LinkedListElement template <class TO, class FROM> class Reference : public LinkedListElement
{ {
private: private:
TO* iRefTo; TO* iRefTo;
FROM* iRefFrom; FROM* iRefFrom;
protected: protected:
// Tell our refTo (target) object that we have a link // Tell our refTo (target) object that we have a link
virtual void targetObjectBuildLink() = 0; virtual void targetObjectBuildLink() = 0;
@@ -26,7 +26,7 @@ template <class TO, class FROM> class Reference : public LinkedListElement
// Tell our refFrom (source) object, that the link is cut (Target destroyed) // Tell our refFrom (source) object, that the link is cut (Target destroyed)
virtual void sourceObjectDestroyLink() = 0; virtual void sourceObjectDestroyLink() = 0;
public: public:
Reference() { iRefTo = NULL; iRefFrom = NULL; } Reference() { iRefTo = NULL; iRefFrom = NULL; }
virtual ~Reference() { } virtual ~Reference() { }
@@ -68,14 +68,14 @@ template <class TO, class FROM> class Reference : public LinkedListElement
return iRefTo != NULL; return iRefTo != NULL;
} }
Reference<TO, FROM> * next() { return((Reference<TO, FROM> *) LinkedListElement::next()); } 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> const* next() const { return((Reference<TO, FROM> const*) LinkedListElement::next()); }
Reference<TO, FROM> * prev() { return((Reference<TO, FROM> *) LinkedListElement::prev()); } 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> 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>* 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> 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>* nocheck_prev() { return((Reference<TO, FROM>*) LinkedListElement::nocheck_prev()); }
Reference<TO, FROM> const* nocheck_prev() const { return((Reference<TO, FROM> const*) LinkedListElement::nocheck_prev()); } Reference<TO, FROM> const* nocheck_prev() const { return((Reference<TO, FROM> const*) LinkedListElement::nocheck_prev()); }
TO* operator ->() const { return iRefTo; } TO* operator ->() const { return iRefTo; }
+7 -7
View File
@@ -18,8 +18,8 @@
template<class T, class Key = std::string> template<class T, class Key = std::string>
class ObjectRegistry class ObjectRegistry
{ {
public: public:
typedef std::map<Key, T *> RegistryMapType; typedef std::map<Key, T*> RegistryMapType;
/// Returns a registry item /// Returns a registry item
const T* GetRegistryItem(Key key) const const T* GetRegistryItem(Key key) const
@@ -35,7 +35,7 @@ class ObjectRegistry
} }
/// Inserts a registry item /// Inserts a registry item
bool InsertItem(T *obj, Key key, bool override = false) bool InsertItem(T* obj, Key key, bool override = false)
{ {
typename RegistryMapType::iterator iter = i_registeredObjects.find(key); typename RegistryMapType::iterator iter = i_registeredObjects.find(key);
if ( iter != i_registeredObjects.end() ) if ( iter != i_registeredObjects.end() )
@@ -69,7 +69,7 @@ class ObjectRegistry
} }
/// Inefficiently return a vector of registered items /// Inefficiently return a vector of registered items
unsigned int GetRegisteredItems(std::vector<Key> &l) const unsigned int GetRegisteredItems(std::vector<Key>& l) const
{ {
unsigned int sz = l.size(); unsigned int sz = l.size();
l.resize(sz + i_registeredObjects.size()); l.resize(sz + i_registeredObjects.size());
@@ -79,7 +79,7 @@ class ObjectRegistry
} }
/// Return the map of registered items /// Return the map of registered items
RegistryMapType const &GetRegisteredItems() const RegistryMapType const& GetRegisteredItems() const
{ {
return i_registeredObjects; return i_registeredObjects;
} }
@@ -87,11 +87,11 @@ class ObjectRegistry
ObjectRegistry() { } ObjectRegistry() { }
~ObjectRegistry() ~ObjectRegistry()
{ {
for (typename RegistryMapType::iterator iter=i_registeredObjects.begin(); iter != i_registeredObjects.end(); ++iter) for (typename RegistryMapType::iterator iter = i_registeredObjects.begin(); iter != i_registeredObjects.end(); ++iter)
delete iter->second; delete iter->second;
i_registeredObjects.clear(); i_registeredObjects.clear();
} }
private: private:
RegistryMapType i_registeredObjects; RegistryMapType i_registeredObjects;
}; };
+5 -5
View File
@@ -85,11 +85,11 @@ template<class H, class T> struct ContainerList<TypeList<H, T> >
template<class OBJECT_TYPES> template<class OBJECT_TYPES>
class TypeMapContainer class TypeMapContainer
{ {
public: public:
template<class SPECIFIC_TYPE> size_t Count() const { return acore::Count(i_elements, (SPECIFIC_TYPE*)NULL); } template<class SPECIFIC_TYPE> size_t Count() const { return acore::Count(i_elements, (SPECIFIC_TYPE*)NULL); }
/// inserts a specific object into the container /// inserts a specific object into the container
template<class SPECIFIC_TYPE> bool insert(SPECIFIC_TYPE *obj) template<class SPECIFIC_TYPE> bool insert(SPECIFIC_TYPE* obj)
{ {
SPECIFIC_TYPE* t = acore::Insert(i_elements, obj); SPECIFIC_TYPE* t = acore::Insert(i_elements, obj);
return (t != NULL); return (t != NULL);
@@ -102,10 +102,10 @@ class TypeMapContainer
// return (t != NULL); // return (t != NULL);
//} //}
ContainerMapList<OBJECT_TYPES> & GetElements(void) { return i_elements; } ContainerMapList<OBJECT_TYPES>& GetElements(void) { return i_elements; }
const ContainerMapList<OBJECT_TYPES> & GetElements(void) const { return i_elements;} const ContainerMapList<OBJECT_TYPES>& GetElements(void) const { return i_elements;}
private: private:
ContainerMapList<OBJECT_TYPES> i_elements; ContainerMapList<OBJECT_TYPES> i_elements;
}; };
#endif #endif
+10 -10
View File
@@ -21,54 +21,54 @@ namespace acore
{ {
/* ContainerMapList Helpers */ /* ContainerMapList Helpers */
// count functions // count functions
template<class SPECIFIC_TYPE> size_t Count(const ContainerMapList<SPECIFIC_TYPE> &elements, SPECIFIC_TYPE* /*fake*/) template<class SPECIFIC_TYPE> size_t Count(const ContainerMapList<SPECIFIC_TYPE>& elements, SPECIFIC_TYPE* /*fake*/)
{ {
return elements._element.getSize(); return elements._element.getSize();
} }
template<class SPECIFIC_TYPE> size_t Count(const ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE* /*fake*/) template<class SPECIFIC_TYPE> size_t Count(const ContainerMapList<TypeNull>& /*elements*/, SPECIFIC_TYPE* /*fake*/)
{ {
return 0; return 0;
} }
template<class SPECIFIC_TYPE, class T> size_t Count(const ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE* /*fake*/) template<class SPECIFIC_TYPE, class T> size_t Count(const ContainerMapList<T>& /*elements*/, SPECIFIC_TYPE* /*fake*/)
{ {
return 0; return 0;
} }
template<class SPECIFIC_TYPE, class T> size_t Count(const ContainerMapList<TypeList<SPECIFIC_TYPE, T> >&elements, SPECIFIC_TYPE* fake) template<class SPECIFIC_TYPE, class T> size_t Count(const ContainerMapList<TypeList<SPECIFIC_TYPE, T> >& elements, SPECIFIC_TYPE* fake)
{ {
return Count(elements._elements, fake); return Count(elements._elements, fake);
} }
template<class SPECIFIC_TYPE, class H, class T> size_t Count(const ContainerMapList<TypeList<H, T> >&elements, SPECIFIC_TYPE* fake) template<class SPECIFIC_TYPE, class H, class T> size_t Count(const ContainerMapList<TypeList<H, T> >& elements, SPECIFIC_TYPE* fake)
{ {
return Count(elements._TailElements, fake); return Count(elements._TailElements, fake);
} }
// non-const insert functions // non-const insert functions
template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Insert(ContainerMapList<SPECIFIC_TYPE> &elements, SPECIFIC_TYPE *obj) template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Insert(ContainerMapList<SPECIFIC_TYPE>& elements, SPECIFIC_TYPE* obj)
{ {
//elements._element[hdl] = obj; //elements._element[hdl] = obj;
obj->AddToGrid(elements._element); obj->AddToGrid(elements._element);
return obj; return obj;
} }
template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Insert(ContainerMapList<TypeNull> &/*elements*/, SPECIFIC_TYPE * /*obj*/) template<class SPECIFIC_TYPE> SPECIFIC_TYPE* Insert(ContainerMapList<TypeNull>& /*elements*/, SPECIFIC_TYPE* /*obj*/)
{ {
return NULL; return NULL;
} }
// this is a missed // this is a missed
template<class SPECIFIC_TYPE, class T> SPECIFIC_TYPE* Insert(ContainerMapList<T> &/*elements*/, SPECIFIC_TYPE * /*obj*/) template<class SPECIFIC_TYPE, class T> SPECIFIC_TYPE* Insert(ContainerMapList<T>& /*elements*/, SPECIFIC_TYPE* /*obj*/)
{ {
return NULL; // a missed return NULL; // a missed
} }
// Recursion // Recursion
template<class SPECIFIC_TYPE, class H, class T> SPECIFIC_TYPE* Insert(ContainerMapList<TypeList<H, T> >&elements, SPECIFIC_TYPE *obj) template<class SPECIFIC_TYPE, class H, class T> SPECIFIC_TYPE* Insert(ContainerMapList<TypeList<H, T> >& elements, SPECIFIC_TYPE* obj)
{ {
SPECIFIC_TYPE* t= Insert(elements._elements, obj); SPECIFIC_TYPE* t = Insert(elements._elements, obj);
return (t != NULL ? t : Insert(elements._TailElements, obj)); return (t != NULL ? t : Insert(elements._TailElements, obj));
} }
+19 -19
View File
@@ -47,48 +47,48 @@ namespace acore
// } // }
// non-const find functions // non-const find functions
template<class SPECIFIC_TYPE> CountedPtr<SPECIFIC_TYPE>& Find(ContainerMapList<SPECIFIC_TYPE> &elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/) template<class SPECIFIC_TYPE> CountedPtr<SPECIFIC_TYPE>& Find(ContainerMapList<SPECIFIC_TYPE>& elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/)
{ {
typename std::map<OBJECT_HANDLE, CountedPtr<SPECIFIC_TYPE> >::iterator iter = elements._element.find(hdl); typename std::map<OBJECT_HANDLE, CountedPtr<SPECIFIC_TYPE> >::iterator iter = elements._element.find(hdl);
return (iter == elements._element.end() ? NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL) : iter->second); return (iter == elements._element.end() ? NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL) : iter->second);
}; };
template<class SPECIFIC_TYPE> CountedPtr<SPECIFIC_TYPE>& Find(ContainerMapList<TypeNull> &elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/) template<class SPECIFIC_TYPE> CountedPtr<SPECIFIC_TYPE>& Find(ContainerMapList<TypeNull>& elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/)
{ {
return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL);// terminate recursion return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL);// terminate recursion
} }
template<class SPECIFIC_TYPE, class T> CountedPtr<SPECIFIC_TYPE>& Find(ContainerMapList<T> &elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/) template<class SPECIFIC_TYPE, class T> CountedPtr<SPECIFIC_TYPE>& Find(ContainerMapList<T>& elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/)
{ {
return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL);// this is a missed return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL);// this is a missed
} }
template<class SPECIFIC_TYPE, class H, class T> CountedPtr<SPECIFIC_TYPE>& Find(ContainerMapList<TypeList<H, T> >&elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* fake) template<class SPECIFIC_TYPE, class H, class T> CountedPtr<SPECIFIC_TYPE>& Find(ContainerMapList<TypeList<H, T> >& elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* fake)
{ {
CountedPtr<SPECIFIC_TYPE> &t = Find(elements._elements, hdl, fake); CountedPtr<SPECIFIC_TYPE>& t = Find(elements._elements, hdl, fake);
return (!t ? Find(elements._TailElements, hdl, fake) : t); return (!t ? Find(elements._TailElements, hdl, fake) : t);
} }
// const find functions // const find functions
template<class SPECIFIC_TYPE> const CountedPtr<SPECIFIC_TYPE>& Find(const ContainerMapList<SPECIFIC_TYPE> &elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/) template<class SPECIFIC_TYPE> const CountedPtr<SPECIFIC_TYPE>& Find(const ContainerMapList<SPECIFIC_TYPE>& elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/)
{ {
typename CountedPtr<SPECIFIC_TYPE>::iterator iter = elements._element.find(hdl); typename CountedPtr<SPECIFIC_TYPE>::iterator iter = elements._element.find(hdl);
return (iter == elements._element.end() ? NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL) : iter->second); return (iter == elements._element.end() ? NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL) : iter->second);
}; };
template<class SPECIFIC_TYPE> const CountedPtr<SPECIFIC_TYPE>& Find(const ContainerMapList<TypeNull> &elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/) template<class SPECIFIC_TYPE> const CountedPtr<SPECIFIC_TYPE>& Find(const ContainerMapList<TypeNull>& elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/)
{ {
return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL); return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL);
} }
template<class SPECIFIC_TYPE, class T> const CountedPtr<SPECIFIC_TYPE>& Find(const ContainerMapList<T> &elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/) template<class SPECIFIC_TYPE, class T> const CountedPtr<SPECIFIC_TYPE>& Find(const ContainerMapList<T>& elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* /*fake*/)
{ {
return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL); return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL);
} }
template<class SPECIFIC_TYPE, class H, class T> CountedPtr<SPECIFIC_TYPE>& Find(const ContainerMapList<TypeList<H, T> >&elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* fake) template<class SPECIFIC_TYPE, class H, class T> CountedPtr<SPECIFIC_TYPE>& Find(const ContainerMapList<TypeList<H, T> >& elements, OBJECT_HANDLE hdl, CountedPtr<SPECIFIC_TYPE>* fake)
{ {
CountedPtr<SPECIFIC_TYPE> &t = Find(elements._elements, hdl, fake); CountedPtr<SPECIFIC_TYPE>& t = Find(elements._elements, hdl, fake);
if (!t) if (!t)
t = Find(elements._TailElement, hdl, fake); t = Find(elements._TailElement, hdl, fake);
@@ -96,32 +96,32 @@ namespace acore
} }
// non-const insert functions // non-const insert functions
template<class SPECIFIC_TYPE> CountedPtr<SPECIFIC_TYPE>& Insert(ContainerMapList<SPECIFIC_TYPE> &elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) template<class SPECIFIC_TYPE> CountedPtr<SPECIFIC_TYPE>& Insert(ContainerMapList<SPECIFIC_TYPE>& elements, CountedPtr<SPECIFIC_TYPE>& obj, OBJECT_HANDLE hdl)
{ {
elements._element[hdl] = obj; elements._element[hdl] = obj;
return obj; return obj;
}; };
template<class SPECIFIC_TYPE> CountedPtr<SPECIFIC_TYPE>& Insert(ContainerMapList<TypeNull> &elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) template<class SPECIFIC_TYPE> CountedPtr<SPECIFIC_TYPE>& Insert(ContainerMapList<TypeNull>& elements, CountedPtr<SPECIFIC_TYPE>& obj, OBJECT_HANDLE hdl)
{ {
return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL); return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL);
} }
// this is a missed // this is a missed
template<class SPECIFIC_TYPE, class T> CountedPtr<SPECIFIC_TYPE>& Insert(ContainerMapList<T> &elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) template<class SPECIFIC_TYPE, class T> CountedPtr<SPECIFIC_TYPE>& Insert(ContainerMapList<T>& elements, CountedPtr<SPECIFIC_TYPE>& obj, OBJECT_HANDLE hdl)
{ {
return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL);// a missed return NullPtr<SPECIFIC_TYPE>((SPECIFIC_TYPE*)NULL);// a missed
} }
// Recursion // Recursion
template<class SPECIFIC_TYPE, class H, class T> CountedPtr<SPECIFIC_TYPE>& Insert(ContainerMapList<TypeList<H, T> >&elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) template<class SPECIFIC_TYPE, class H, class T> CountedPtr<SPECIFIC_TYPE>& Insert(ContainerMapList<TypeList<H, T> >& elements, CountedPtr<SPECIFIC_TYPE>& obj, OBJECT_HANDLE hdl)
{ {
CountedPtr<SPECIFIC_TYPE> &t= Insert(elements._elements, obj, hdl); CountedPtr<SPECIFIC_TYPE>& t = Insert(elements._elements, obj, hdl);
return (!t ? Insert(elements._TailElements, obj, hdl) : t); return (!t ? Insert(elements._TailElements, obj, hdl) : t);
} }
// non-const remove method // non-const remove method
template<class SPECIFIC_TYPE> bool Remove(ContainerMapList<SPECIFIC_TYPE> &elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) template<class SPECIFIC_TYPE> bool Remove(ContainerMapList<SPECIFIC_TYPE>& elements, CountedPtr<SPECIFIC_TYPE>& obj, OBJECT_HANDLE hdl)
{ {
typename std::map<OBJECT_HANDLE, CountedPtr<SPECIFIC_TYPE> >::iterator iter = elements._element.find(hdl); typename std::map<OBJECT_HANDLE, CountedPtr<SPECIFIC_TYPE> >::iterator iter = elements._element.find(hdl);
if ( iter != elements._element.end() ) if ( iter != elements._element.end() )
@@ -133,18 +133,18 @@ namespace acore
return false; // found... terminate the search return false; // found... terminate the search
} }
template<class SPECIFIC_TYPE> bool Remove(ContainerMapList<TypeNull> &elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) template<class SPECIFIC_TYPE> bool Remove(ContainerMapList<TypeNull>& elements, CountedPtr<SPECIFIC_TYPE>& obj, OBJECT_HANDLE hdl)
{ {
return false; return false;
} }
// this is a missed // this is a missed
template<class SPECIFIC_TYPE, class T> bool Remove(ContainerMapList<T> &elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) template<class SPECIFIC_TYPE, class T> bool Remove(ContainerMapList<T>& elements, CountedPtr<SPECIFIC_TYPE>& obj, OBJECT_HANDLE hdl)
{ {
return false; return false;
} }
template<class SPECIFIC_TYPE, class T, class H> bool Remove(ContainerMapList<TypeList<H, T> > &elements, CountedPtr<SPECIFIC_TYPE> &obj, OBJECT_HANDLE hdl) template<class SPECIFIC_TYPE, class T, class H> bool Remove(ContainerMapList<TypeList<H, T> >& elements, CountedPtr<SPECIFIC_TYPE>& obj, OBJECT_HANDLE hdl)
{ {
// The head element is bad // The head element is bad
bool t = Remove(elements._elements, obj, hdl); bool t = Remove(elements._elements, obj, hdl);
+17 -17
View File
@@ -20,58 +20,58 @@
template<class T, class Y> class TypeContainerVisitor; template<class T, class Y> class TypeContainerVisitor;
// visitor helper // visitor helper
template<class VISITOR, class TYPE_CONTAINER> void VisitorHelper(VISITOR &v, TYPE_CONTAINER &c) template<class VISITOR, class TYPE_CONTAINER> void VisitorHelper(VISITOR& v, TYPE_CONTAINER& c)
{ {
v.Visit(c); v.Visit(c);
} }
// terminate condition for container list // terminate condition for container list
template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerList<TypeNull> &/*c*/) { } template<class VISITOR> void VisitorHelper(VISITOR& /*v*/, ContainerList<TypeNull>& /*c*/) { }
template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerList<T> &c) template<class VISITOR, class T> void VisitorHelper(VISITOR& v, ContainerList<T>& c)
{ {
v.Visit(c._element); v.Visit(c._element);
} }
// recursion for container list // recursion for container list
template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerList<TypeList<H, T> > &c) template<class VISITOR, class H, class T> void VisitorHelper(VISITOR& v, ContainerList<TypeList<H, T> >& c)
{ {
VisitorHelper(v, c._elements); VisitorHelper(v, c._elements);
VisitorHelper(v, c._TailElements); VisitorHelper(v, c._TailElements);
} }
// terminate condition container map list // terminate condition container map list
template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerMapList<TypeNull> &/*c*/) { } template<class VISITOR> void VisitorHelper(VISITOR& /*v*/, ContainerMapList<TypeNull>& /*c*/) { }
template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerMapList<T> &c) template<class VISITOR, class T> void VisitorHelper(VISITOR& v, ContainerMapList<T>& c)
{ {
v.Visit(c._element); v.Visit(c._element);
} }
// recursion container map list // recursion container map list
template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerMapList<TypeList<H, T> > &c) template<class VISITOR, class H, class T> void VisitorHelper(VISITOR& v, ContainerMapList<TypeList<H, T> >& c)
{ {
VisitorHelper(v, c._elements); VisitorHelper(v, c._elements);
VisitorHelper(v, c._TailElements); VisitorHelper(v, c._TailElements);
} }
// array list // array list
template<class VISITOR, class T> void VisitorHelper(VISITOR &v, ContainerArrayList<T> &c) template<class VISITOR, class T> void VisitorHelper(VISITOR& v, ContainerArrayList<T>& c)
{ {
v.Visit(c._element); v.Visit(c._element);
} }
template<class VISITOR> void VisitorHelper(VISITOR &/*v*/, ContainerArrayList<TypeNull> &/*c*/) { } template<class VISITOR> void VisitorHelper(VISITOR& /*v*/, ContainerArrayList<TypeNull>& /*c*/) { }
// recursion // recursion
template<class VISITOR, class H, class T> void VisitorHelper(VISITOR &v, ContainerArrayList<TypeList<H, T> > &c) template<class VISITOR, class H, class T> void VisitorHelper(VISITOR& v, ContainerArrayList<TypeList<H, T> >& c)
{ {
VisitorHelper(v, c._elements); VisitorHelper(v, c._elements);
VisitorHelper(v, c._TailElements); VisitorHelper(v, c._TailElements);
} }
// for TypeMapContainer // for TypeMapContainer
template<class VISITOR, class OBJECT_TYPES> void VisitorHelper(VISITOR &v, TypeMapContainer<OBJECT_TYPES> &c) template<class VISITOR, class OBJECT_TYPES> void VisitorHelper(VISITOR& v, TypeMapContainer<OBJECT_TYPES>& c)
{ {
VisitorHelper(v, c.GetElements()); VisitorHelper(v, c.GetElements());
} }
@@ -79,21 +79,21 @@ template<class VISITOR, class OBJECT_TYPES> void VisitorHelper(VISITOR &v, TypeM
template<class VISITOR, class TYPE_CONTAINER> template<class VISITOR, class TYPE_CONTAINER>
class TypeContainerVisitor class TypeContainerVisitor
{ {
public: public:
TypeContainerVisitor(VISITOR &v) : i_visitor(v) { } TypeContainerVisitor(VISITOR& v) : i_visitor(v) { }
void Visit(TYPE_CONTAINER &c) void Visit(TYPE_CONTAINER& c)
{ {
VisitorHelper(i_visitor, c); VisitorHelper(i_visitor, c);
} }
void Visit(const TYPE_CONTAINER &c) const void Visit(const TYPE_CONTAINER& c) const
{ {
VisitorHelper(i_visitor, c); VisitorHelper(i_visitor, c);
} }
private: private:
VISITOR &i_visitor; VISITOR& i_visitor;
}; };
#endif #endif
+38 -38
View File
@@ -71,7 +71,7 @@ Log* Log::instance()
return &instance; return &instance;
} }
void Log::SetLogLevel(char *Level) void Log::SetLogLevel(char* Level)
{ {
int32 NewLevel = atoi((char*)Level); int32 NewLevel = atoi((char*)Level);
if (NewLevel < 0) if (NewLevel < 0)
@@ -81,7 +81,7 @@ void Log::SetLogLevel(char *Level)
outString("LogLevel is %u", m_logLevel); outString("LogLevel is %u", m_logLevel);
} }
void Log::SetLogFileLevel(char *Level) void Log::SetLogFileLevel(char* Level)
{ {
int32 NewLevel = atoi((char*)Level); int32 NewLevel = atoi((char*)Level);
if (NewLevel < 0) if (NewLevel < 0)
@@ -126,7 +126,7 @@ void Log::Initialize()
bool m_gmlog_timestamp = sConfigMgr->GetBoolDefault("GmLogTimestamp", false, false); bool m_gmlog_timestamp = sConfigMgr->GetBoolDefault("GmLogTimestamp", false, false);
size_t dot_pos = m_gmlog_filename_format.find_last_of('.'); size_t dot_pos = m_gmlog_filename_format.find_last_of('.');
if (dot_pos!=m_gmlog_filename_format.npos) if (dot_pos != m_gmlog_filename_format.npos)
{ {
if (m_gmlog_timestamp) if (m_gmlog_timestamp)
m_gmlog_filename_format.insert(dot_pos, m_logsTimestamp); m_gmlog_filename_format.insert(dot_pos, m_logsTimestamp);
@@ -151,7 +151,7 @@ void Log::Initialize()
chatLogfile = openLogFile("ChatLogFile", "ChatLogTimestamp", "a"); chatLogfile = openLogFile("ChatLogFile", "ChatLogTimestamp", "a");
sqlLogFile = openLogFile("SQLDriverLogFile", NULL, "a"); sqlLogFile = openLogFile("SQLDriverLogFile", NULL, "a");
sqlDevLogFile = openLogFile("SQLDeveloperLogFile", NULL, "a"); sqlDevLogFile = openLogFile("SQLDeveloperLogFile", NULL, "a");
miscLogFile = fopen((m_logsDir+"Misc.log").c_str(), "a"); miscLogFile = fopen((m_logsDir + "Misc.log").c_str(), "a");
// Main log file settings // Main log file settings
m_logLevel = sConfigMgr->GetIntDefault("LogLevel", LOGL_NORMAL, false); m_logLevel = sConfigMgr->GetIntDefault("LogLevel", LOGL_NORMAL, false);
@@ -184,20 +184,20 @@ void Log::ReloadConfig()
FILE* Log::openLogFile(char const* configFileName, char const* configTimeStampFlag, char const* mode) FILE* Log::openLogFile(char const* configFileName, char const* configTimeStampFlag, char const* mode)
{ {
std::string logfn=sConfigMgr->GetStringDefault(configFileName, "", false); std::string logfn = sConfigMgr->GetStringDefault(configFileName, "", false);
if (logfn.empty()) if (logfn.empty())
return NULL; return NULL;
if (configTimeStampFlag && sConfigMgr->GetBoolDefault(configTimeStampFlag, false, false)) if (configTimeStampFlag && sConfigMgr->GetBoolDefault(configTimeStampFlag, false, false))
{ {
size_t dot_pos = logfn.find_last_of("."); size_t dot_pos = logfn.find_last_of(".");
if (dot_pos!=logfn.npos) if (dot_pos != logfn.npos)
logfn.insert(dot_pos, m_logsTimestamp); logfn.insert(dot_pos, m_logsTimestamp);
else else
logfn += m_logsTimestamp; logfn += m_logsTimestamp;
} }
return fopen((m_logsDir+logfn).c_str(), mode); return fopen((m_logsDir + logfn).c_str(), mode);
} }
FILE* Log::openGmlogPerAccount(uint32 account) FILE* Log::openGmlogPerAccount(uint32 account)
@@ -220,7 +220,7 @@ void Log::outTimestamp(FILE* file)
// HH hour (2 digits 00-23) // HH hour (2 digits 00-23)
// MM minutes (2 digits 00-59) // MM minutes (2 digits 00-59)
// SS seconds (2 digits 00-59) // SS seconds (2 digits 00-59)
fprintf(file, "%-4d-%02d-%02d %02d:%02d:%02d ", aTm->tm_year+1900, aTm->tm_mon+1, aTm->tm_mday, aTm->tm_hour, aTm->tm_min, aTm->tm_sec); fprintf(file, "%-4d-%02d-%02d %02d:%02d:%02d ", aTm->tm_year + 1900, aTm->tm_mon + 1, aTm->tm_mday, aTm->tm_hour, aTm->tm_min, aTm->tm_sec);
} }
void Log::InitColors(const std::string& str) void Log::InitColors(const std::string& str)
@@ -254,7 +254,7 @@ void Log::InitColors(const std::string& str)
void Log::SetColor(bool stdout_stream, ColorTypes color) void Log::SetColor(bool stdout_stream, ColorTypes color)
{ {
#if AC_PLATFORM == AC_PLATFORM_WINDOWS #if AC_PLATFORM == AC_PLATFORM_WINDOWS
static WORD WinColorFG[Colors] = static WORD WinColorFG[Colors] =
{ {
0, // BLACK 0, // BLACK
@@ -282,24 +282,24 @@ void Log::SetColor(bool stdout_stream, ColorTypes color)
HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE ); HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE );
SetConsoleTextAttribute(hConsole, WinColorFG[color]); SetConsoleTextAttribute(hConsole, WinColorFG[color]);
#else #else
enum ANSITextAttr enum ANSITextAttr
{ {
TA_NORMAL=0, TA_NORMAL = 0,
TA_BOLD=1, TA_BOLD = 1,
TA_BLINK=5, TA_BLINK = 5,
TA_REVERSE=7 TA_REVERSE = 7
}; };
enum ANSIFgTextAttr enum ANSIFgTextAttr
{ {
FG_BLACK=30, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE, FG_BLACK = 30, FG_RED, FG_GREEN, FG_BROWN, FG_BLUE,
FG_MAGENTA, FG_CYAN, FG_WHITE, FG_YELLOW FG_MAGENTA, FG_CYAN, FG_WHITE, FG_YELLOW
}; };
enum ANSIBgTextAttr enum ANSIBgTextAttr
{ {
BG_BLACK=40, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE, BG_BLACK = 40, BG_RED, BG_GREEN, BG_BROWN, BG_BLUE,
BG_MAGENTA, BG_CYAN, BG_WHITE BG_MAGENTA, BG_CYAN, BG_WHITE
}; };
@@ -322,18 +322,18 @@ void Log::SetColor(bool stdout_stream, ColorTypes color)
FG_WHITE // LWHITE FG_WHITE // LWHITE
}; };
fprintf((stdout_stream? stdout : stderr), "\x1b[%d%sm", UnixColorFG[color], (color >= YELLOW && color < Colors ? ";1" : "")); fprintf((stdout_stream ? stdout : stderr), "\x1b[%d%sm", UnixColorFG[color], (color >= YELLOW && color < Colors ? ";1" : ""));
#endif #endif
} }
void Log::ResetColor(bool stdout_stream) void Log::ResetColor(bool stdout_stream)
{ {
#if AC_PLATFORM == AC_PLATFORM_WINDOWS #if AC_PLATFORM == AC_PLATFORM_WINDOWS
HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE ); HANDLE hConsole = GetStdHandle(stdout_stream ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE );
SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED ); SetConsoleTextAttribute(hConsole, FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED );
#else #else
fprintf(( stdout_stream ? stdout : stderr ), "\x1b[0m"); fprintf(( stdout_stream ? stdout : stderr ), "\x1b[0m");
#endif #endif
} }
std::string Log::GetTimestampStr() std::string Log::GetTimestampStr()
@@ -348,7 +348,7 @@ std::string Log::GetTimestampStr()
// MM minutes (2 digits 00-59) // MM minutes (2 digits 00-59)
// SS seconds (2 digits 00-59) // SS seconds (2 digits 00-59)
char buf[20]; char buf[20];
int ret = snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year+1900, aTm.tm_mon+1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec); int ret = snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year + 1900, aTm.tm_mon + 1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec);
if (ret < 0) if (ret < 0)
{ {
@@ -358,7 +358,7 @@ std::string Log::GetTimestampStr()
return std::string(buf); return std::string(buf);
} }
void Log::outDB(LogTypes type, const char * str) void Log::outDB(LogTypes type, const char* str)
{ {
if(!str || std::string(str).empty() || type >= MAX_LOG_TYPES) if(!str || std::string(str).empty() || type >= MAX_LOG_TYPES)
return; return;
@@ -370,7 +370,7 @@ void Log::outDB(LogTypes type, const char * str)
"VALUES (" UI64FMTD ", %u, %u, '%s');", uint64(time(0)), realm, (uint32)type, new_str.c_str()); "VALUES (" UI64FMTD ", %u, %u, '%s');", uint64(time(0)), realm, (uint32)type, new_str.c_str());
} }
void Log::outString(const char * str, ...) void Log::outString(const char* str, ...)
{ {
if (!str) if (!str)
return; return;
@@ -423,7 +423,7 @@ void Log::outString()
fflush(stdout); fflush(stdout);
} }
void Log::outCrash(const char * err, ...) void Log::outCrash(const char* err, ...)
{ {
if (!err) if (!err)
return; return;
@@ -466,7 +466,7 @@ void Log::outCrash(const char * err, ...)
fflush(stderr); fflush(stderr);
} }
void Log::outError(const char * err, ...) void Log::outError(const char* err, ...)
{ {
if (!err) if (!err)
return; return;
@@ -537,7 +537,7 @@ void Log::outSQLDriver(const char* str, ...)
fflush(stdout); fflush(stdout);
} }
void Log::outErrorDb(const char * err, ...) void Log::outErrorDb(const char* err, ...)
{ {
if (!err) if (!err)
return; return;
@@ -592,7 +592,7 @@ void Log::outErrorDb(const char * err, ...)
fflush(stderr); fflush(stderr);
} }
void Log::outBasic(const char * str, ...) void Log::outBasic(const char* str, ...)
{ {
if (!str) if (!str)
return; return;
@@ -636,7 +636,7 @@ void Log::outBasic(const char * str, ...)
fflush(stdout); fflush(stdout);
} }
void Log::outDetail(const char * str, ...) void Log::outDetail(const char* str, ...)
{ {
if (!str) if (!str)
return; return;
@@ -708,7 +708,7 @@ void Log::outSQLDev(const char* str, ...)
fflush(stdout); fflush(stdout);
} }
void Log::outDebug(DebugLogFilters f, const char * str, ...) void Log::outDebug(DebugLogFilters f, const char* str, ...)
{ {
if (!(m_DebugLogMask & f)) if (!(m_DebugLogMask & f))
return; return;
@@ -756,7 +756,7 @@ void Log::outDebug(DebugLogFilters f, const char * str, ...)
fflush(stdout); fflush(stdout);
} }
void Log::outStaticDebug(const char * str, ...) void Log::outStaticDebug(const char* str, ...)
{ {
if (!str) if (!str)
return; return;
@@ -801,7 +801,7 @@ void Log::outStaticDebug(const char * str, ...)
fflush(stdout); fflush(stdout);
} }
void Log::outStringInLine(const char * str, ...) void Log::outStringInLine(const char* str, ...)
{ {
if (!str) if (!str)
return; return;
@@ -820,7 +820,7 @@ void Log::outStringInLine(const char * str, ...)
} }
} }
void Log::outCommand(uint32 account, const char * str, ...) void Log::outCommand(uint32 account, const char* str, ...)
{ {
if (!str) if (!str)
return; return;
@@ -890,7 +890,7 @@ void Log::outCommand(uint32 account, const char * str, ...)
fflush(stdout); fflush(stdout);
} }
void Log::outChar(const char * str, ...) void Log::outChar(const char* str, ...)
{ {
if (!str) if (!str)
return; return;
@@ -917,7 +917,7 @@ void Log::outChar(const char * str, ...)
} }
} }
void Log::outCharDump(const char * str, uint32 account_id, uint32 guid, const char * name) void Log::outCharDump(const char* str, uint32 account_id, uint32 guid, const char* name)
{ {
FILE* file = NULL; FILE* file = NULL;
if (m_charLog_Dump_Separate) if (m_charLog_Dump_Separate)
@@ -940,7 +940,7 @@ void Log::outCharDump(const char * str, uint32 account_id, uint32 guid, const ch
} }
} }
void Log::outChat(const char * str, ...) void Log::outChat(const char* str, ...)
{ {
if (!str) if (!str)
return; return;
@@ -967,7 +967,7 @@ void Log::outChat(const char * str, ...)
} }
} }
void Log::outRemote(const char * str, ...) void Log::outRemote(const char* str, ...)
{ {
if (!str) if (!str)
return; return;
@@ -994,7 +994,7 @@ void Log::outRemote(const char * str, ...)
} }
} }
void Log::outMisc(const char * str, ...) void Log::outMisc(const char* str, ...)
{ {
if (!str) if (!str)
return; return;
+24 -24
View File
@@ -58,7 +58,7 @@ enum LogTypes
LOG_TYPE_CRASH = 9, LOG_TYPE_CRASH = 9,
LOG_TYPE_CHAT = 10, LOG_TYPE_CHAT = 10,
LOG_TYPE_PERF = 11, LOG_TYPE_PERF = 11,
LOG_TYPE_MULTITH= 12, LOG_TYPE_MULTITH = 12,
MAX_LOG_TYPES MAX_LOG_TYPES
}; };
@@ -70,7 +70,7 @@ enum LogLevel
LOGL_DEBUG LOGL_DEBUG
}; };
const int LogLevels = int(LOGL_DEBUG)+1; const int LogLevels = int(LOGL_DEBUG) + 1;
enum ColorTypes enum ColorTypes
{ {
@@ -91,11 +91,11 @@ enum ColorTypes
WHITE WHITE
}; };
const int Colors = int(WHITE)+1; const int Colors = int(WHITE) + 1;
class Log class Log
{ {
private: private:
Log(); Log();
~Log(); ~Log();
Log(Log const&) = delete; Log(Log const&) = delete;
@@ -103,7 +103,7 @@ class Log
Log& operator=(Log const&) = delete; Log& operator=(Log const&) = delete;
Log& operator=(Log&&) = delete; Log& operator=(Log&&) = delete;
public: public:
static Log* instance(); static Log* instance();
void Initialize(); void Initialize();
@@ -114,31 +114,31 @@ class Log
void SetColor(bool stdout_stream, ColorTypes color); void SetColor(bool stdout_stream, ColorTypes color);
void ResetColor(bool stdout_stream); void ResetColor(bool stdout_stream);
void outDB(LogTypes type, const char * str); void outDB(LogTypes type, const char* str);
void outString(const char * str, ...) ATTR_PRINTF(2, 3); void outString(const char* str, ...) ATTR_PRINTF(2, 3);
void outString(); void outString();
void outStringInLine(const char * str, ...) ATTR_PRINTF(2, 3); void outStringInLine(const char* str, ...) ATTR_PRINTF(2, 3);
void outError(const char * err, ...) ATTR_PRINTF(2, 3); void outError(const char* err, ...) ATTR_PRINTF(2, 3);
void outCrash(const char * err, ...) ATTR_PRINTF(2, 3); void outCrash(const char* err, ...) ATTR_PRINTF(2, 3);
void outBasic(const char * str, ...) ATTR_PRINTF(2, 3); void outBasic(const char* str, ...) ATTR_PRINTF(2, 3);
void outDetail(const char * str, ...) ATTR_PRINTF(2, 3); void outDetail(const char* str, ...) ATTR_PRINTF(2, 3);
void outSQLDev(const char * str, ...) ATTR_PRINTF(2, 3); void outSQLDev(const char* str, ...) ATTR_PRINTF(2, 3);
void outDebug(DebugLogFilters f, const char* str, ...) ATTR_PRINTF(3, 4); void outDebug(DebugLogFilters f, const char* str, ...) ATTR_PRINTF(3, 4);
void outStaticDebug(const char * str, ...) ATTR_PRINTF(2, 3); void outStaticDebug(const char* str, ...) ATTR_PRINTF(2, 3);
void outErrorDb(const char * str, ...) ATTR_PRINTF(2, 3); void outErrorDb(const char* str, ...) ATTR_PRINTF(2, 3);
void outChar(const char * str, ...) ATTR_PRINTF(2, 3); void outChar(const char* str, ...) ATTR_PRINTF(2, 3);
void outCommand(uint32 account, const char * str, ...) ATTR_PRINTF(3, 4); void outCommand(uint32 account, const char* str, ...) ATTR_PRINTF(3, 4);
void outChat(const char * str, ...) ATTR_PRINTF(2, 3); void outChat(const char* str, ...) ATTR_PRINTF(2, 3);
void outRemote(const char * str, ...) ATTR_PRINTF(2, 3); void outRemote(const char* str, ...) ATTR_PRINTF(2, 3);
void outSQLDriver(const char* str, ...) ATTR_PRINTF(2, 3); void outSQLDriver(const char* str, ...) ATTR_PRINTF(2, 3);
void outMisc(const char * str, ...) ATTR_PRINTF(2, 3); // pussywizard void outMisc(const char* str, ...) ATTR_PRINTF(2, 3); // pussywizard
void outCharDump(const char * str, uint32 account_id, uint32 guid, const char * name); void outCharDump(const char* str, uint32 account_id, uint32 guid, const char* name);
static void outTimestamp(FILE* file); static void outTimestamp(FILE* file);
static std::string GetTimestampStr(); static std::string GetTimestampStr();
void SetLogLevel(char * Level); void SetLogLevel(char* Level);
void SetLogFileLevel(char * Level); void SetLogFileLevel(char* Level);
void SetSQLDriverQueryLogging(bool newStatus) { m_sqlDriverQueryLogging = newStatus; } void SetSQLDriverQueryLogging(bool newStatus) { m_sqlDriverQueryLogging = newStatus; }
void SetRealmID(uint32 id) { realm = id; } void SetRealmID(uint32 id) { realm = id; }
@@ -148,7 +148,7 @@ class Log
bool GetLogDB() const { return m_enableLogDB; } bool GetLogDB() const { return m_enableLogDB; }
void SetLogDB(bool enable) { m_enableLogDB = enable; } void SetLogDB(bool enable) { m_enableLogDB = enable; }
bool GetSQLDriverQueryLogging() const { return m_sqlDriverQueryLogging; } bool GetSQLDriverQueryLogging() const { return m_sqlDriverQueryLogging; }
private: private:
FILE* openLogFile(char const* configFileName, char const* configTimeStampFlag, char const* mode); FILE* openLogFile(char const* configFileName, char const* configTimeStampFlag, char const* mode);
FILE* openGmlogPerAccount(uint32 account); FILE* openGmlogPerAccount(uint32 account);
+49 -49
View File
@@ -27,7 +27,7 @@ public:
char const* what() const throw() { return msg_.c_str(); } char const* what() const throw() { return msg_.c_str(); }
protected: protected:
std::string & message() throw() { return msg_; } std::string& message() throw() { return msg_; }
private: private:
std::string msg_; std::string msg_;
@@ -51,7 +51,7 @@ public:
class ByteBuffer class ByteBuffer
{ {
public: public:
const static size_t DEFAULT_SIZE = 0x1000; const static size_t DEFAULT_SIZE = 0x1000;
// constructor // constructor
@@ -66,16 +66,16 @@ class ByteBuffer
} }
// copy constructor // copy constructor
ByteBuffer(const ByteBuffer &buf) : _rpos(buf._rpos), _wpos(buf._wpos), ByteBuffer(const ByteBuffer& buf) : _rpos(buf._rpos), _wpos(buf._wpos),
_storage(buf._storage) _storage(buf._storage)
{ {
} }
/* requried as of C++ 11 */ /* requried as of C++ 11 */
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
ByteBuffer(ByteBuffer&&) = default; ByteBuffer(ByteBuffer&&) = default;
ByteBuffer& operator=(const ByteBuffer&) = default; ByteBuffer& operator=(const ByteBuffer&) = default;
ByteBuffer& operator=(ByteBuffer&&) = default; ByteBuffer& operator=(ByteBuffer&&) = default;
#endif #endif
void clear() void clear()
{ {
@@ -86,78 +86,78 @@ class ByteBuffer
template <typename T> void append(T value) template <typename T> void append(T value)
{ {
EndianConvert(value); EndianConvert(value);
append((uint8 *)&value, sizeof(value)); append((uint8*)&value, sizeof(value));
} }
template <typename T> void put(size_t pos, T value) template <typename T> void put(size_t pos, T value)
{ {
EndianConvert(value); EndianConvert(value);
put(pos, (uint8 *)&value, sizeof(value)); put(pos, (uint8*)&value, sizeof(value));
} }
ByteBuffer &operator<<(uint8 value) ByteBuffer& operator<<(uint8 value)
{ {
append<uint8>(value); append<uint8>(value);
return *this; return *this;
} }
ByteBuffer &operator<<(uint16 value) ByteBuffer& operator<<(uint16 value)
{ {
append<uint16>(value); append<uint16>(value);
return *this; return *this;
} }
ByteBuffer &operator<<(uint32 value) ByteBuffer& operator<<(uint32 value)
{ {
append<uint32>(value); append<uint32>(value);
return *this; return *this;
} }
ByteBuffer &operator<<(uint64 value) ByteBuffer& operator<<(uint64 value)
{ {
append<uint64>(value); append<uint64>(value);
return *this; return *this;
} }
// signed as in 2e complement // signed as in 2e complement
ByteBuffer &operator<<(int8 value) ByteBuffer& operator<<(int8 value)
{ {
append<int8>(value); append<int8>(value);
return *this; return *this;
} }
ByteBuffer &operator<<(int16 value) ByteBuffer& operator<<(int16 value)
{ {
append<int16>(value); append<int16>(value);
return *this; return *this;
} }
ByteBuffer &operator<<(int32 value) ByteBuffer& operator<<(int32 value)
{ {
append<int32>(value); append<int32>(value);
return *this; return *this;
} }
ByteBuffer &operator<<(int64 value) ByteBuffer& operator<<(int64 value)
{ {
append<int64>(value); append<int64>(value);
return *this; return *this;
} }
// floating points // floating points
ByteBuffer &operator<<(float value) ByteBuffer& operator<<(float value)
{ {
append<float>(value); append<float>(value);
return *this; return *this;
} }
ByteBuffer &operator<<(double value) ByteBuffer& operator<<(double value)
{ {
append<double>(value); append<double>(value);
return *this; return *this;
} }
ByteBuffer &operator<<(const std::string &value) ByteBuffer& operator<<(const std::string& value)
{ {
if (size_t len = value.length()) if (size_t len = value.length())
append((uint8 const*)value.c_str(), len); append((uint8 const*)value.c_str(), len);
@@ -165,7 +165,7 @@ class ByteBuffer
return *this; return *this;
} }
ByteBuffer &operator<<(const char *str) ByteBuffer& operator<<(const char* str)
{ {
if (size_t len = (str ? strlen(str) : 0)) if (size_t len = (str ? strlen(str) : 0))
append((uint8 const*)str, len); append((uint8 const*)str, len);
@@ -173,62 +173,62 @@ class ByteBuffer
return *this; return *this;
} }
ByteBuffer &operator>>(bool &value) ByteBuffer& operator>>(bool& value)
{ {
value = (read<char>() > 0); value = (read<char>() > 0);
return *this; return *this;
} }
ByteBuffer &operator>>(uint8 &value) ByteBuffer& operator>>(uint8& value)
{ {
value = read<uint8>(); value = read<uint8>();
return *this; return *this;
} }
ByteBuffer &operator>>(uint16 &value) ByteBuffer& operator>>(uint16& value)
{ {
value = read<uint16>(); value = read<uint16>();
return *this; return *this;
} }
ByteBuffer &operator>>(uint32 &value) ByteBuffer& operator>>(uint32& value)
{ {
value = read<uint32>(); value = read<uint32>();
return *this; return *this;
} }
ByteBuffer &operator>>(uint64 &value) ByteBuffer& operator>>(uint64& value)
{ {
value = read<uint64>(); value = read<uint64>();
return *this; return *this;
} }
//signed as in 2e complement //signed as in 2e complement
ByteBuffer &operator>>(int8 &value) ByteBuffer& operator>>(int8& value)
{ {
value = read<int8>(); value = read<int8>();
return *this; return *this;
} }
ByteBuffer &operator>>(int16 &value) ByteBuffer& operator>>(int16& value)
{ {
value = read<int16>(); value = read<int16>();
return *this; return *this;
} }
ByteBuffer &operator>>(int32 &value) ByteBuffer& operator>>(int32& value)
{ {
value = read<int32>(); value = read<int32>();
return *this; return *this;
} }
ByteBuffer &operator>>(int64 &value) ByteBuffer& operator>>(int64& value)
{ {
value = read<int64>(); value = read<int64>();
return *this; return *this;
} }
ByteBuffer &operator>>(float &value) ByteBuffer& operator>>(float& value)
{ {
value = read<float>(); value = read<float>();
if (!myisfinite(value)) if (!myisfinite(value))
@@ -239,7 +239,7 @@ class ByteBuffer
return *this; return *this;
} }
ByteBuffer &operator>>(double &value) ByteBuffer& operator>>(double& value)
{ {
value = read<double>(); value = read<double>();
if (!myisfinite(value)) if (!myisfinite(value))
@@ -250,7 +250,7 @@ class ByteBuffer
return *this; return *this;
} }
ByteBuffer &operator>>(std::string& value) ByteBuffer& operator>>(std::string& value)
{ {
value.clear(); value.clear();
while (rpos() < size()) // prevent crash at wrong string format in packet while (rpos() < size()) // prevent crash at wrong string format in packet
@@ -324,7 +324,7 @@ class ByteBuffer
return val; return val;
} }
void read(uint8 *dest, size_t len) void read(uint8* dest, size_t len)
{ {
if (_rpos + len > size()) if (_rpos + len > size())
throw ByteBufferPositionException(false, _rpos, len, size()); throw ByteBufferPositionException(false, _rpos, len, size());
@@ -378,14 +378,14 @@ class ByteBuffer
return *this; return *this;
} }
uint8 * contents() uint8* contents()
{ {
if (_storage.empty()) if (_storage.empty())
throw ByteBufferException(); throw ByteBufferException();
return &_storage[0]; return &_storage[0];
} }
const uint8 *contents() const const uint8* contents() const
{ {
if (_storage.empty()) if (_storage.empty())
throw ByteBufferException(); throw ByteBufferException();
@@ -408,17 +408,17 @@ class ByteBuffer
_storage.reserve(ressize); _storage.reserve(ressize);
} }
void append(const char *src, size_t cnt) void append(const char* src, size_t cnt)
{ {
return append((const uint8 *)src, cnt); return append((const uint8*)src, cnt);
} }
template<class T> void append(const T *src, size_t cnt) template<class T> void append(const T* src, size_t cnt)
{ {
return append((const uint8 *)src, cnt * sizeof(T)); return append((const uint8*)src, cnt * sizeof(T));
} }
void append(const uint8 *src, size_t cnt) void append(const uint8* src, size_t cnt)
{ {
if (!cnt) if (!cnt)
throw ByteBufferSourceException(_wpos, size(), cnt); throw ByteBufferSourceException(_wpos, size(), cnt);
@@ -467,10 +467,10 @@ class ByteBuffer
void appendPackGUID(uint64 guid) void appendPackGUID(uint64 guid)
{ {
uint8 packGUID[8+1]; uint8 packGUID[8 + 1];
packGUID[0] = 0; packGUID[0] = 0;
size_t size = 1; size_t size = 1;
for (uint8 i = 0;guid != 0;++i) for (uint8 i = 0; guid != 0; ++i)
{ {
if (guid & 0xFF) if (guid & 0xFF)
{ {
@@ -491,7 +491,7 @@ class ByteBuffer
append<uint32>((lt.tm_year - 100) << 24 | lt.tm_mon << 20 | (lt.tm_mday - 1) << 14 | lt.tm_wday << 11 | lt.tm_hour << 6 | lt.tm_min); append<uint32>((lt.tm_year - 100) << 24 | lt.tm_mon << 20 | (lt.tm_mday - 1) << 14 | lt.tm_wday << 11 | lt.tm_hour << 6 | lt.tm_min);
} }
void put(size_t pos, const uint8 *src, size_t cnt) void put(size_t pos, const uint8* src, size_t cnt)
{ {
if (pos + cnt > size()) if (pos + cnt > size())
throw ByteBufferPositionException(true, pos, cnt, size()); throw ByteBufferPositionException(true, pos, cnt, size());
@@ -504,13 +504,13 @@ class ByteBuffer
void hexlike(bool outString = false) const; void hexlike(bool outString = false) const;
protected: protected:
size_t _rpos, _wpos; size_t _rpos, _wpos;
std::vector<uint8> _storage; std::vector<uint8> _storage;
}; };
template <typename T> template <typename T>
inline ByteBuffer &operator<<(ByteBuffer &b, std::vector<T> v) inline ByteBuffer& operator<<(ByteBuffer& b, std::vector<T> v)
{ {
b << (uint32)v.size(); b << (uint32)v.size();
for (typename std::vector<T>::iterator i = v.begin(); i != v.end(); ++i) for (typename std::vector<T>::iterator i = v.begin(); i != v.end(); ++i)
@@ -521,7 +521,7 @@ inline ByteBuffer &operator<<(ByteBuffer &b, std::vector<T> v)
} }
template <typename T> template <typename T>
inline ByteBuffer &operator>>(ByteBuffer &b, std::vector<T> &v) inline ByteBuffer& operator>>(ByteBuffer& b, std::vector<T>& v)
{ {
uint32 vsize; uint32 vsize;
b >> vsize; b >> vsize;
@@ -536,7 +536,7 @@ inline ByteBuffer &operator>>(ByteBuffer &b, std::vector<T> &v)
} }
template <typename T> template <typename T>
inline ByteBuffer &operator<<(ByteBuffer &b, std::list<T> v) inline ByteBuffer& operator<<(ByteBuffer& b, std::list<T> v)
{ {
b << (uint32)v.size(); b << (uint32)v.size();
for (typename std::list<T>::iterator i = v.begin(); i != v.end(); ++i) for (typename std::list<T>::iterator i = v.begin(); i != v.end(); ++i)
@@ -547,7 +547,7 @@ inline ByteBuffer &operator<<(ByteBuffer &b, std::list<T> v)
} }
template <typename T> template <typename T>
inline ByteBuffer &operator>>(ByteBuffer &b, std::list<T> &v) inline ByteBuffer& operator>>(ByteBuffer& b, std::list<T>& v)
{ {
uint32 vsize; uint32 vsize;
b >> vsize; b >> vsize;
@@ -562,7 +562,7 @@ inline ByteBuffer &operator>>(ByteBuffer &b, std::list<T> &v)
} }
template <typename K, typename V> template <typename K, typename V>
inline ByteBuffer &operator<<(ByteBuffer &b, std::map<K, V> &m) inline ByteBuffer& operator<<(ByteBuffer& b, std::map<K, V>& m)
{ {
b << (uint32)m.size(); b << (uint32)m.size();
for (typename std::map<K, V>::iterator i = m.begin(); i != m.end(); ++i) for (typename std::map<K, V>::iterator i = m.begin(); i != m.end(); ++i)
@@ -573,7 +573,7 @@ inline ByteBuffer &operator<<(ByteBuffer &b, std::map<K, V> &m)
} }
template <typename K, typename V> template <typename K, typename V>
inline ByteBuffer &operator>>(ByteBuffer &b, std::map<K, V> &m) inline ByteBuffer& operator>>(ByteBuffer& b, std::map<K, V>& m)
{ {
uint32 msize; uint32 msize;
b >> msize; b >> msize;
+7 -7
View File
@@ -12,24 +12,24 @@
class WorldPacket : public ByteBuffer class WorldPacket : public ByteBuffer
{ {
public: public:
// just container for later use // just container for later use
WorldPacket() : ByteBuffer(0), m_opcode(0) WorldPacket() : ByteBuffer(0), m_opcode(0)
{ {
} }
explicit WorldPacket(uint16 opcode, size_t res=200) : ByteBuffer(res), m_opcode(opcode) { } explicit WorldPacket(uint16 opcode, size_t res = 200) : ByteBuffer(res), m_opcode(opcode) { }
// copy constructor // copy constructor
WorldPacket(const WorldPacket &packet) : ByteBuffer(packet), m_opcode(packet.m_opcode) WorldPacket(const WorldPacket& packet) : ByteBuffer(packet), m_opcode(packet.m_opcode)
{ {
} }
/* requried as of C++ 11 */ /* requried as of C++ 11 */
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
WorldPacket(WorldPacket&&) = default; WorldPacket(WorldPacket&&) = default;
WorldPacket& operator=(const WorldPacket&) = default; WorldPacket& operator=(const WorldPacket&) = default;
WorldPacket& operator=(WorldPacket&&) = default; WorldPacket& operator=(WorldPacket&&) = default;
#endif #endif
void Initialize(uint16 opcode, size_t newres=200) void Initialize(uint16 opcode, size_t newres = 200)
{ {
clear(); clear();
_storage.reserve(newres); _storage.reserve(newres);
@@ -39,7 +39,7 @@ class WorldPacket : public ByteBuffer
uint16 GetOpcode() const { return m_opcode; } uint16 GetOpcode() const { return m_opcode; }
void SetOpcode(uint16 opcode) { m_opcode = opcode; } void SetOpcode(uint16 opcode) { m_opcode = opcode; }
protected: protected:
uint16 m_opcode; uint16 m_opcode;
}; };
#endif #endif
+6 -6
View File
@@ -23,7 +23,7 @@ typedef ACE_Future<PreparedQueryResult> PreparedQueryResultFuture;
template <typename Result, typename ParamType, bool chain = false> template <typename Result, typename ParamType, bool chain = false>
class QueryCallback class QueryCallback
{ {
public: public:
QueryCallback() : _param(), _stage(chain ? 0 : CALLBACK_STAGE_INVALID) {} QueryCallback() : _param(), _stage(chain ? 0 : CALLBACK_STAGE_INVALID) {}
//! The parameter of this function should be a resultset returned from either .AsyncQuery or .AsyncPQuery //! The parameter of this function should be a resultset returned from either .AsyncQuery or .AsyncPQuery
@@ -94,7 +94,7 @@ class QueryCallback
ResetStage(); ResetStage();
} }
private: private:
ACE_Future<Result> _result; ACE_Future<Result> _result;
ParamType _param; ParamType _param;
uint8 _stage; uint8 _stage;
@@ -103,7 +103,7 @@ class QueryCallback
template <typename Result, typename ParamType1, typename ParamType2, bool chain = false> template <typename Result, typename ParamType1, typename ParamType2, bool chain = false>
class QueryCallback_2 class QueryCallback_2
{ {
public: public:
QueryCallback_2() : _stage(chain ? 0 : CALLBACK_STAGE_INVALID) {} QueryCallback_2() : _stage(chain ? 0 : CALLBACK_STAGE_INVALID) {}
//! The parameter of this function should be a resultset returned from either .AsyncQuery or .AsyncPQuery //! The parameter of this function should be a resultset returned from either .AsyncQuery or .AsyncPQuery
@@ -185,7 +185,7 @@ class QueryCallback_2
ResetStage(); ResetStage();
} }
private: private:
ACE_Future<Result> _result; ACE_Future<Result> _result;
ParamType1 _param_1; ParamType1 _param_1;
ParamType2 _param_2; ParamType2 _param_2;
@@ -195,7 +195,7 @@ class QueryCallback_2
template <typename Result, typename ParamType1, typename ParamType2, typename ParamType3, bool chain = false> template <typename Result, typename ParamType1, typename ParamType2, typename ParamType3, bool chain = false>
class QueryCallback_3 class QueryCallback_3
{ {
public: public:
QueryCallback_3() : _stage(chain ? 0 : CALLBACK_STAGE_INVALID) {} QueryCallback_3() : _stage(chain ? 0 : CALLBACK_STAGE_INVALID) {}
//! The parameter of this function should be a resultset returned from either .AsyncQuery or .AsyncPQuery //! The parameter of this function should be a resultset returned from either .AsyncQuery or .AsyncPQuery
@@ -288,7 +288,7 @@ class QueryCallback_3
ResetStage(); ResetStage();
} }
private: private:
ACE_Future<Result> _result; ACE_Future<Result> _result;
ParamType1 _param_1; ParamType1 _param_1;
ParamType2 _param_2; ParamType2 _param_2;
+1 -1
View File
@@ -10,7 +10,7 @@ DelayExecutor* DelayExecutor::instance()
} }
DelayExecutor::DelayExecutor() DelayExecutor::DelayExecutor()
: pre_svc_hook_(0), post_svc_hook_(0), activated_(false), mqueue_(1*1024*1024, 1*1024*1024), queue_(&mqueue_) : pre_svc_hook_(0), post_svc_hook_(0), activated_(false), mqueue_(1 * 1024 * 1024, 1 * 1024 * 1024), queue_(&mqueue_)
{ {
} }
+2 -2
View File
@@ -7,7 +7,7 @@
class DelayExecutor : protected ACE_Task_Base class DelayExecutor : protected ACE_Task_Base
{ {
public: public:
DelayExecutor(); DelayExecutor();
virtual ~DelayExecutor(); virtual ~DelayExecutor();
@@ -24,7 +24,7 @@ class DelayExecutor : protected ACE_Task_Base
virtual int svc(); virtual int svc();
private: private:
ACE_Method_Request* pre_svc_hook_; ACE_Method_Request* pre_svc_hook_;
ACE_Method_Request* post_svc_hook_; ACE_Method_Request* post_svc_hook_;
+1 -1
View File
@@ -15,7 +15,7 @@
namespace ACE_Based namespace ACE_Based
{ {
template <class T, class LockType, typename StorageType=std::deque<T> > template <class T, class LockType, typename StorageType = std::deque<T> >
class LockedQueue class LockedQueue
{ {
//! Lock access to the queue. //! Lock access to the queue.
+1 -1
View File
@@ -95,7 +95,7 @@ private:
typename std::enable_if<std::is_pointer<E>::value>::type DeleteQueuedObject(E& obj) { delete obj; } typename std::enable_if<std::is_pointer<E>::value>::type DeleteQueuedObject(E& obj) { delete obj; }
template<typename E = T> template<typename E = T>
typename std::enable_if<!std::is_pointer<E>::value>::type DeleteQueuedObject(E const& /*packet*/) { } typename std::enable_if < !std::is_pointer<E>::value >::type DeleteQueuedObject(E const& /*packet*/) { }
}; };
#endif #endif
+21 -7
View File
@@ -88,13 +88,27 @@ void Thread::setPriority(Priority priority)
switch (priority) switch (priority)
{ {
#ifdef WIN32 #ifdef WIN32
case Priority_Realtime: _ok = SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL); break; case Priority_Realtime:
case Priority_Highest: _ok = SetThreadPriority(handle, THREAD_PRIORITY_HIGHEST); break; _ok = SetThreadPriority(handle, THREAD_PRIORITY_TIME_CRITICAL);
case Priority_High: _ok = SetThreadPriority(handle, THREAD_PRIORITY_ABOVE_NORMAL); break; break;
case Priority_Normal: _ok = SetThreadPriority(handle, THREAD_PRIORITY_NORMAL); break; case Priority_Highest:
case Priority_Low: _ok = SetThreadPriority(handle, THREAD_PRIORITY_BELOW_NORMAL); break; _ok = SetThreadPriority(handle, THREAD_PRIORITY_HIGHEST);
case Priority_Lowest: _ok = SetThreadPriority(handle, THREAD_PRIORITY_LOWEST); break; break;
case Priority_Idle: _ok = SetThreadPriority(handle, THREAD_PRIORITY_IDLE); break; case Priority_High:
_ok = SetThreadPriority(handle, THREAD_PRIORITY_ABOVE_NORMAL);
break;
case Priority_Normal:
_ok = SetThreadPriority(handle, THREAD_PRIORITY_NORMAL);
break;
case Priority_Low:
_ok = SetThreadPriority(handle, THREAD_PRIORITY_BELOW_NORMAL);
break;
case Priority_Lowest:
_ok = SetThreadPriority(handle, THREAD_PRIORITY_LOWEST);
break;
case Priority_Idle:
_ok = SetThreadPriority(handle, THREAD_PRIORITY_IDLE);
break;
#endif #endif
default: default:
break; break;
+6 -6
View File
@@ -17,18 +17,18 @@
namespace ByteConverter namespace ByteConverter
{ {
template<size_t T> template<size_t T>
inline void convert(char *val) inline void convert(char* val)
{ {
std::swap(*val, *(val + T - 1)); std::swap(*val, *(val + T - 1));
convert<T - 2>(val + 1); convert < T - 2 > (val + 1);
} }
template<> inline void convert<0>(char *) { } template<> inline void convert<0>(char*) { }
template<> inline void convert<1>(char *) { } // ignore central byte template<> inline void convert<1>(char*) { } // ignore central byte
template<typename T> inline void apply(T *val) template<typename T> inline void apply(T* val)
{ {
convert<sizeof(T)>((char *)(val)); convert<sizeof(T)>((char*)(val));
} }
} }
+6 -4
View File
@@ -26,7 +26,8 @@ public:
/** /**
* Returns a pointer to object of requested type stored with given key or nullptr * Returns a pointer to object of requested type stored with given key or nullptr
*/ */
template<class T> T* Get(std::string const & k) const { template<class T> T* Get(std::string const& k) const
{
static_assert(std::is_base_of<Base, T>::value, "T must derive from Base"); static_assert(std::is_base_of<Base, T>::value, "T must derive from Base");
if (Container.empty()) if (Container.empty())
return nullptr; return nullptr;
@@ -42,7 +43,8 @@ public:
* or default constructs one and returns that one * or default constructs one and returns that one
*/ */
template<class T, typename std::enable_if<std::is_default_constructible<T>::value, int>::type = 0> template<class T, typename std::enable_if<std::is_default_constructible<T>::value, int>::type = 0>
T* GetDefault(std::string const & k) { T * GetDefault(std::string const& k)
{
static_assert(std::is_base_of<Base, T>::value, "T must derive from Base"); static_assert(std::is_base_of<Base, T>::value, "T must derive from Base");
if (T* v = Get<T>(k)) if (T* v = Get<T>(k))
return v; return v;
@@ -54,12 +56,12 @@ public:
/** /**
* Stores a new object that inherits the Base class with the given key * Stores a new object that inherits the Base class with the given key
*/ */
void Set(std::string const & k, Base* v) { Container[k] = std::unique_ptr<Base>(v); } void Set(std::string const& k, Base* v) { Container[k] = std::unique_ptr<Base>(v); }
/** /**
* Removes objects with given key and returns true if one was removed, false otherwise * Removes objects with given key and returns true if one was removed, false otherwise
*/ */
bool Erase(std::string const & k) { return Container.erase(k) != 0; } bool Erase(std::string const& k) { return Container.erase(k) != 0; }
private: private:
std::unordered_map<std::string, std::unique_ptr<Base>> Container; std::unordered_map<std::string, std::unique_ptr<Base>> Container;
+3 -3
View File
@@ -15,7 +15,7 @@
class BasicEvent class BasicEvent
{ {
public: public:
BasicEvent() BasicEvent()
{ {
to_Abort = false; to_Abort = false;
@@ -45,7 +45,7 @@ typedef std::multimap<uint64, BasicEvent*> EventList;
class EventProcessor class EventProcessor
{ {
public: public:
EventProcessor(); EventProcessor();
~EventProcessor(); ~EventProcessor();
@@ -57,7 +57,7 @@ class EventProcessor
// Xinef: calculates next queue tick time // Xinef: calculates next queue tick time
uint64 CalculateQueueTime(uint64 delay) const; uint64 CalculateQueueTime(uint64 delay) const;
protected: protected:
uint64 m_time; uint64 m_time;
EventList m_events; EventList m_events;
bool m_aborting; bool m_aborting;
+6 -6
View File
@@ -25,7 +25,7 @@
#endif #endif
#endif #endif
extern int main(int argc, char ** argv); extern int main(int argc, char** argv);
extern char serviceLongName[]; extern char serviceLongName[];
extern char serviceName[]; extern char serviceName[];
extern char serviceDescription[]; extern char serviceDescription[];
@@ -36,7 +36,7 @@ SERVICE_STATUS serviceStatus;
SERVICE_STATUS_HANDLE serviceStatusHandle = 0; SERVICE_STATUS_HANDLE serviceStatusHandle = 0;
typedef WINADVAPI BOOL (WINAPI *CSD_T)(SC_HANDLE, DWORD, LPCVOID); typedef WINADVAPI BOOL (WINAPI* CSD_T)(SC_HANDLE, DWORD, LPCVOID);
bool WinServiceInstall() bool WinServiceInstall()
{ {
@@ -45,7 +45,7 @@ bool WinServiceInstall()
if (serviceControlManager) if (serviceControlManager)
{ {
char path[_MAX_PATH + 10]; char path[_MAX_PATH + 10];
if (GetModuleFileName( 0, path, sizeof(path)/sizeof(path[0]) ) > 0) if (GetModuleFileName( 0, path, sizeof(path) / sizeof(path[0]) ) > 0)
{ {
SC_HANDLE service; SC_HANDLE service;
std::strcat(path, " --service"); std::strcat(path, " --service");
@@ -95,7 +95,7 @@ bool WinServiceInstall()
ZeroMemory(&sfa, sizeof(SERVICE_FAILURE_ACTIONS)); ZeroMemory(&sfa, sizeof(SERVICE_FAILURE_ACTIONS));
sfa.lpsaActions = _action; sfa.lpsaActions = _action;
sfa.cActions = 1; sfa.cActions = 1;
sfa.dwResetPeriod =INFINITE; sfa.dwResetPeriod = INFINITE;
ChangeService_Config2( ChangeService_Config2(
service, // handle to service service, // handle to service
SERVICE_CONFIG_FAILURE_ACTIONS, // information level SERVICE_CONFIG_FAILURE_ACTIONS, // information level
@@ -173,7 +173,7 @@ void WINAPI ServiceControlHandler(DWORD controlCode)
SetServiceStatus(serviceStatusHandle, &serviceStatus); SetServiceStatus(serviceStatusHandle, &serviceStatus);
} }
void WINAPI ServiceMain(DWORD argc, char *argv[]) void WINAPI ServiceMain(DWORD argc, char* argv[])
{ {
// initialise service status // initialise service status
serviceStatus.dwServiceType = SERVICE_WIN32; serviceStatus.dwServiceType = SERVICE_WIN32;
@@ -191,7 +191,7 @@ void WINAPI ServiceMain(DWORD argc, char *argv[])
char path[_MAX_PATH + 1]; char path[_MAX_PATH + 1];
unsigned int i, last_slash = 0; unsigned int i, last_slash = 0;
GetModuleFileName(0, path, sizeof(path)/sizeof(path[0])); GetModuleFileName(0, path, sizeof(path) / sizeof(path[0]));
for (i = 0; i < std::strlen(path); i++) for (i = 0; i < std::strlen(path); i++)
{ {
+4 -4
View File
@@ -12,9 +12,9 @@
namespace acore namespace acore
{ {
/// Handle termination signals /// Handle termination signals
class SignalHandler : public ACE_Event_Handler class SignalHandler : public ACE_Event_Handler
{ {
public: public:
int handle_signal(int SigNum, siginfo_t* = NULL, ucontext_t* = NULL) int handle_signal(int SigNum, siginfo_t* = NULL, ucontext_t* = NULL)
{ {
@@ -22,7 +22,7 @@ class SignalHandler : public ACE_Event_Handler
return 0; return 0;
} }
virtual void HandleSignal(int /*SigNum*/) { }; virtual void HandleSignal(int /*SigNum*/) { };
}; };
} }
+8 -8
View File
@@ -50,7 +50,7 @@ inline uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
struct IntervalTimer struct IntervalTimer
{ {
public: public:
IntervalTimer() IntervalTimer()
: _interval(0), _current(0) : _interval(0), _current(0)
@@ -95,7 +95,7 @@ struct IntervalTimer
return _current; return _current;
} }
private: private:
time_t _interval; time_t _interval;
time_t _current; time_t _current;
@@ -103,7 +103,7 @@ struct IntervalTimer
struct TimeTracker struct TimeTracker
{ {
public: public:
TimeTracker(time_t expiry) TimeTracker(time_t expiry)
: i_expiryTime(expiry) : i_expiryTime(expiry)
@@ -130,14 +130,14 @@ struct TimeTracker
return i_expiryTime; return i_expiryTime;
} }
private: private:
time_t i_expiryTime; time_t i_expiryTime;
}; };
struct TimeTrackerSmall struct TimeTrackerSmall
{ {
public: public:
TimeTrackerSmall(uint32 expiry = 0) TimeTrackerSmall(uint32 expiry = 0)
: i_expiryTime(expiry) : i_expiryTime(expiry)
@@ -164,14 +164,14 @@ struct TimeTrackerSmall
return i_expiryTime; return i_expiryTime;
} }
private: private:
int32 i_expiryTime; int32 i_expiryTime;
}; };
struct PeriodicTimer struct PeriodicTimer
{ {
public: public:
PeriodicTimer(int32 period, int32 start_time) PeriodicTimer(int32 period, int32 start_time)
: i_period(period), i_expireTime(start_time) : i_period(period), i_expireTime(start_time)
@@ -198,7 +198,7 @@ struct PeriodicTimer
bool TPassed() const { return i_expireTime <= 0; } bool TPassed() const { return i_expireTime <= 0; }
void TReset(int32 diff, int32 period) { i_expireTime += period > diff ? period : diff; } void TReset(int32 diff, int32 period) { i_expireTime += period > diff ? period : diff; }
private: private:
int32 i_period; int32 i_period;
int32 i_expireTime; int32 i_expireTime;
+48 -38
View File
@@ -68,7 +68,7 @@ SFMTEngine& SFMTEngine::Instance()
return engine; return engine;
} }
Tokenizer::Tokenizer(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]; m_str = new char[src.length() + 1];
memcpy(m_str, src.c_str(), src.length() + 1); memcpy(m_str, src.c_str(), src.length() + 1);
@@ -141,7 +141,7 @@ time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime)
return hourLocal; return hourLocal;
} }
void stripLineInvisibleChars(std::string &str) void stripLineInvisibleChars(std::string& str)
{ {
static std::string const invChars = " \t\7\n"; static std::string const invChars = " \t\7\n";
@@ -150,7 +150,7 @@ void stripLineInvisibleChars(std::string &str)
bool space = false; bool space = false;
for (size_t pos = 0; pos < str.size(); ++pos) for (size_t pos = 0; pos < str.size(); ++pos)
{ {
if (invChars.find(str[pos])!=std::string::npos) if (invChars.find(str[pos]) != std::string::npos)
{ {
if (!space) if (!space)
{ {
@@ -160,7 +160,7 @@ void stripLineInvisibleChars(std::string &str)
} }
else else
{ {
if (wpos!=pos) if (wpos != pos)
str[wpos++] = str[pos]; str[wpos++] = str[pos];
else else
++wpos; ++wpos;
@@ -170,7 +170,7 @@ void stripLineInvisibleChars(std::string &str)
if (wpos < str.size()) if (wpos < str.size())
str.erase(wpos, str.size()); str.erase(wpos, str.size());
if (str.find("|TInterface")!=std::string::npos) if (str.find("|TInterface") != std::string::npos)
str.clear(); str.clear();
} }
@@ -194,8 +194,8 @@ std::string secsToTimeString(uint64 timeInSecs, bool shortText)
std::string str = ss.str(); std::string str = ss.str();
if (!shortText && !str.empty() && str[str.size()-1] == ' ') if (!shortText && !str.empty() && str[str.size() - 1] == ' ')
str.resize(str.size()-1); str.resize(str.size() - 1);
return str; return str;
} }
@@ -241,22 +241,31 @@ uint32 TimeStringToSecs(const std::string& timestring)
{ {
if (isdigit(*itr)) if (isdigit(*itr))
{ {
buffer*=10; buffer *= 10;
buffer+= (*itr)-'0'; buffer += (*itr) - '0';
} }
else else
{ {
switch (*itr) switch (*itr)
{ {
case 'd': multiplier = DAY; break; case 'd':
case 'h': multiplier = HOUR; break; multiplier = DAY;
case 'm': multiplier = MINUTE; break; break;
case 's': multiplier = 1; break; case 'h':
default : return 0; //bad format multiplier = HOUR;
break;
case 'm':
multiplier = MINUTE;
break;
case 's':
multiplier = 1;
break;
default :
return 0; //bad format
} }
buffer*=multiplier; buffer *= multiplier;
secs+=buffer; secs += buffer;
buffer=0; buffer = 0;
} }
} }
@@ -274,7 +283,7 @@ std::string TimeToTimestampStr(time_t t)
// MM minutes (2 digits 00-59) // MM minutes (2 digits 00-59)
// SS seconds (2 digits 00-59) // SS seconds (2 digits 00-59)
char buf[20]; char buf[20];
int ret = snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year+1900, aTm.tm_mon+1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec); int ret = snprintf(buf, 20, "%04d-%02d-%02d_%02d-%02d-%02d", aTm.tm_year + 1900, aTm.tm_mon + 1, aTm.tm_mday, aTm.tm_hour, aTm.tm_min, aTm.tm_sec);
if (ret < 0) if (ret < 0)
{ {
@@ -349,7 +358,7 @@ size_t utf8length(std::string& utf8str)
{ {
try try
{ {
return utf8::distance(utf8str.c_str(), utf8str.c_str()+utf8str.size()); return utf8::distance(utf8str.c_str(), utf8str.c_str() + utf8str.size());
} }
catch(std::exception const&) catch(std::exception const&)
{ {
@@ -362,16 +371,16 @@ void utf8truncate(std::string& utf8str, size_t len)
{ {
try try
{ {
size_t wlen = utf8::distance(utf8str.c_str(), utf8str.c_str()+utf8str.size()); size_t wlen = utf8::distance(utf8str.c_str(), utf8str.c_str() + utf8str.size());
if (wlen <= len) if (wlen <= len)
return; return;
std::wstring wstr; std::wstring wstr;
wstr.resize(wlen); wstr.resize(wlen);
utf8::utf8to16(utf8str.c_str(), utf8str.c_str()+utf8str.size(), &wstr[0]); utf8::utf8to16(utf8str.c_str(), utf8str.c_str() + utf8str.size(), &wstr[0]);
wstr.resize(len); wstr.resize(len);
char* oend = utf8::utf16to8(wstr.c_str(), wstr.c_str()+wstr.size(), &utf8str[0]); char* oend = utf8::utf16to8(wstr.c_str(), wstr.c_str() + wstr.size(), &utf8str[0]);
utf8str.resize(oend-(&utf8str[0])); // remove unused tail utf8str.resize(oend - (&utf8str[0])); // remove unused tail
} }
catch(std::exception const&) catch(std::exception const&)
{ {
@@ -384,7 +393,7 @@ bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize)
try try
{ {
acore::CheckedBufferOutputIterator<wchar_t> out(wstr, wsize); acore::CheckedBufferOutputIterator<wchar_t> out(wstr, wsize);
out = utf8::utf8to16(utf8str, utf8str+csize, out); out = utf8::utf8to16(utf8str, utf8str + csize, out);
wsize -= out.remaining(); // remaining unused space wsize -= out.remaining(); // remaining unused space
wstr[wsize] = L'\0'; wstr[wsize] = L'\0';
} }
@@ -418,7 +427,7 @@ bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr)
wstr.clear(); wstr.clear();
try try
{ {
utf8::utf8to16(utf8str.c_str(), utf8str.c_str()+utf8str.size(), std::back_inserter(wstr)); utf8::utf8to16(utf8str.c_str(), utf8str.c_str() + utf8str.size(), std::back_inserter(wstr));
} }
catch(std::exception const&) catch(std::exception const&)
{ {
@@ -434,12 +443,12 @@ bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str)
try try
{ {
std::string utf8str2; std::string utf8str2;
utf8str2.resize(size*4); // allocate for most long case utf8str2.resize(size * 4); // allocate for most long case
if (size) if (size)
{ {
char* oend = utf8::utf16to8(wstr, wstr+size, &utf8str2[0]); char* oend = utf8::utf16to8(wstr, wstr + size, &utf8str2[0]);
utf8str2.resize(oend-(&utf8str2[0])); // remove unused tail utf8str2.resize(oend - (&utf8str2[0])); // remove unused tail
} }
utf8str = utf8str2; utf8str = utf8str2;
} }
@@ -457,12 +466,12 @@ bool WStrToUtf8(std::wstring const& wstr, std::string& utf8str)
try try
{ {
std::string utf8str2; std::string utf8str2;
utf8str2.resize(wstr.size()*4); // allocate for most long case utf8str2.resize(wstr.size() * 4); // allocate for most long case
if (wstr.size()) if (wstr.size())
{ {
char* oend = utf8::utf16to8(wstr.c_str(), wstr.c_str()+wstr.size(), &utf8str2[0]); char* oend = utf8::utf16to8(wstr.c_str(), wstr.c_str() + wstr.size(), &utf8str2[0]);
utf8str2.resize(oend-(&utf8str2[0])); // remove unused tail utf8str2.resize(oend - (&utf8str2[0])); // remove unused tail
} }
utf8str = utf8str2; utf8str = utf8str2;
} }
@@ -518,7 +527,8 @@ std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension)
{ &u_End, &yu_End, &o_End, &ie_End, &soft_End, &ya_End, &a_End }, { &u_End, &yu_End, &o_End, &ie_End, &soft_End, &ya_End, &a_End },
{ &oj_End, &io_j_End, &ie_j_End, &o_m_End, &io_m_End, &ie_m_End, &yu_End }, { &oj_End, &io_j_End, &ie_j_End, &o_m_End, &io_m_End, &ie_m_End, &yu_End },
{ &ie_End, &i_End, nullptr, nullptr, nullptr, nullptr, nullptr } { &ie_End, &i_End, nullptr, nullptr, nullptr, nullptr, nullptr }
}}; }
};
std::size_t const thisLen = wname.length(); std::size_t const thisLen = wname.length();
std::array<std::wstring const*, 7> const& endings = dropEnds[declension]; std::array<std::wstring const*, 7> const& endings = dropEnds[declension];
@@ -529,8 +539,8 @@ std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension)
if (!(endLen <= thisLen)) if (!(endLen <= thisLen))
continue; continue;
if (wname.substr(thisLen-endLen, thisLen) == ending) if (wname.substr(thisLen - endLen, thisLen) == ending)
return wname.substr(0, thisLen-endLen); return wname.substr(0, thisLen - endLen);
} }
return wname; return wname;
@@ -584,7 +594,7 @@ bool Utf8FitTo(const std::string& str, std::wstring const& search)
return true; return true;
} }
void utf8printf(FILE* out, const char *str, ...) void utf8printf(FILE* out, const char* str, ...)
{ {
va_list ap; va_list ap;
va_start(ap, str); va_start(ap, str);
@@ -592,7 +602,7 @@ void utf8printf(FILE* out, const char *str, ...)
va_end(ap); va_end(ap);
} }
void vutf8printf(FILE* out, const char *str, va_list* ap) void vutf8printf(FILE* out, const char* str, va_list* ap)
{ {
#if AC_PLATFORM == AC_PLATFORM_WINDOWS #if AC_PLATFORM == AC_PLATFORM_WINDOWS
char temp_buf[32 * 1024]; char temp_buf[32 * 1024];
@@ -601,9 +611,9 @@ void vutf8printf(FILE* out, const char *str, va_list* ap)
size_t temp_len = vsnprintf(temp_buf, 32 * 1024, str, *ap); size_t temp_len = vsnprintf(temp_buf, 32 * 1024, str, *ap);
//vsnprintf returns -1 if the buffer is too small //vsnprintf returns -1 if the buffer is too small
if (temp_len == size_t(-1)) if (temp_len == size_t(-1))
temp_len = 32*1024-1; temp_len = 32 * 1024 - 1;
size_t wtemp_len = 32*1024-1; size_t wtemp_len = 32 * 1024 - 1;
Utf8toWStr(temp_buf, temp_len, wtemp_buf, wtemp_len); Utf8toWStr(temp_buf, temp_len, wtemp_buf, wtemp_len);
CharToOemBuffW(&wtemp_buf[0], &temp_buf[0], uint32(wtemp_len + 1)); CharToOemBuffW(&wtemp_buf[0], &temp_buf[0], uint32(wtemp_len + 1));
+32 -32
View File
@@ -25,7 +25,7 @@ template<typename T, class S> struct Finder
T S::* idMember_; T S::* idMember_;
Finder(T val, T S::* idMember) : val_(val), idMember_(idMember) {} Finder(T val, T S::* idMember) : val_(val), idMember_(idMember) {}
bool operator()(const std::pair<int, S> &obj) { return obj.second.*idMember_ == val_; } bool operator()(const std::pair<int, S>& obj) { return obj.second.*idMember_ == val_; }
}; };
class Tokenizer class Tokenizer
@@ -40,7 +40,7 @@ public:
typedef StorageType::const_reference const_reference; typedef StorageType::const_reference const_reference;
public: public:
Tokenizer(const std::string &src, char const sep, uint32 vectorReserve = 0); Tokenizer(const std::string& src, char const sep, uint32 vectorReserve = 0);
~Tokenizer() { delete[] m_str; } ~Tokenizer() { delete[] m_str; }
const_iterator begin() const { return m_storage.begin(); } const_iterator begin() const { return m_storage.begin(); }
@@ -61,7 +61,7 @@ time_t LocalTimeToUTCTime(time_t time);
time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime = true); time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime = true);
tm TimeBreakdown(time_t t); tm TimeBreakdown(time_t t);
void stripLineInvisibleChars(std::string &src); void stripLineInvisibleChars(std::string& src);
int32 MoneyStringToMoney(const std::string& moneyString); int32 MoneyStringToMoney(const std::string& moneyString);
@@ -117,13 +117,13 @@ inline T CalculatePct(T base, U pct)
} }
template <class T, class U> template <class T, class U>
inline T AddPct(T &base, U pct) inline T AddPct(T& base, U pct)
{ {
return base += CalculatePct(base, pct); return base += CalculatePct(base, pct);
} }
template <class T, class U> template <class T, class U>
inline T ApplyPct(T &base, U pct) inline T ApplyPct(T& base, U pct)
{ {
return base = CalculatePct(base, pct); return base = CalculatePct(base, pct);
} }
@@ -215,12 +215,12 @@ inline bool isEastAsianCharacter(wchar_t wchar)
inline bool isNumeric(wchar_t wchar) inline bool isNumeric(wchar_t wchar)
{ {
return (wchar >= L'0' && wchar <=L'9'); return (wchar >= L'0' && wchar <= L'9');
} }
inline bool isNumeric(char c) inline bool isNumeric(char c)
{ {
return (c >= '0' && c <='9'); return (c >= '0' && c <= '9');
} }
inline bool isNumeric(char const* str) inline bool isNumeric(char const* str)
@@ -237,7 +237,7 @@ inline bool isNumericOrSpace(wchar_t wchar)
return isNumeric(wchar) || wchar == L' '; return isNumeric(wchar) || wchar == L' ';
} }
inline bool isBasicLatinString(const std::wstring &wstr, bool numericOrSpace) inline bool isBasicLatinString(const std::wstring& wstr, bool numericOrSpace)
{ {
for (size_t i = 0; i < wstr.size(); ++i) for (size_t i = 0; i < wstr.size(); ++i)
if (!isBasicLatinCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i]))) if (!isBasicLatinCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
@@ -245,7 +245,7 @@ inline bool isBasicLatinString(const std::wstring &wstr, bool numericOrSpace)
return true; return true;
} }
inline bool isExtendedLatinString(const std::wstring &wstr, bool numericOrSpace) inline bool isExtendedLatinString(const std::wstring& wstr, bool numericOrSpace)
{ {
for (size_t i = 0; i < wstr.size(); ++i) for (size_t i = 0; i < wstr.size(); ++i)
if (!isExtendedLatinCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i]))) if (!isExtendedLatinCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
@@ -253,7 +253,7 @@ inline bool isExtendedLatinString(const std::wstring &wstr, bool numericOrSpace)
return true; return true;
} }
inline bool isCyrillicString(const std::wstring &wstr, bool numericOrSpace) inline bool isCyrillicString(const std::wstring& wstr, bool numericOrSpace)
{ {
for (size_t i = 0; i < wstr.size(); ++i) for (size_t i = 0; i < wstr.size(); ++i)
if (!isCyrillicCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i]))) if (!isCyrillicCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
@@ -261,7 +261,7 @@ inline bool isCyrillicString(const std::wstring &wstr, bool numericOrSpace)
return true; return true;
} }
inline bool isEastAsianString(const std::wstring &wstr, bool numericOrSpace) inline bool isEastAsianString(const std::wstring& wstr, bool numericOrSpace)
{ {
for (size_t i = 0; i < wstr.size(); ++i) for (size_t i = 0; i < wstr.size(); ++i)
if (!isEastAsianCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i]))) if (!isEastAsianCharacter(wstr[i]) && (!numericOrSpace || !isNumericOrSpace(wstr[i])))
@@ -272,20 +272,20 @@ inline bool isEastAsianString(const std::wstring &wstr, bool numericOrSpace)
inline wchar_t wcharToUpper(wchar_t wchar) inline wchar_t wcharToUpper(wchar_t wchar)
{ {
if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z if (wchar >= L'a' && wchar <= L'z') // LATIN SMALL LETTER A - LATIN SMALL LETTER Z
return wchar_t(uint16(wchar)-0x0020); return wchar_t(uint16(wchar) - 0x0020);
if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S if (wchar == 0x00DF) // LATIN SMALL LETTER SHARP S
return wchar_t(0x1E9E); return wchar_t(0x1E9E);
if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS if (wchar >= 0x00E0 && wchar <= 0x00F6) // LATIN SMALL LETTER A WITH GRAVE - LATIN SMALL LETTER O WITH DIAERESIS
return wchar_t(uint16(wchar)-0x0020); return wchar_t(uint16(wchar) - 0x0020);
if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN if (wchar >= 0x00F8 && wchar <= 0x00FE) // LATIN SMALL LETTER O WITH STROKE - LATIN SMALL LETTER THORN
return wchar_t(uint16(wchar)-0x0020); return wchar_t(uint16(wchar) - 0x0020);
if (wchar >= 0x0101 && wchar <= 0x012F) // LATIN SMALL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK (only %2=1) if (wchar >= 0x0101 && wchar <= 0x012F) // LATIN SMALL LETTER A WITH MACRON - LATIN SMALL LETTER I WITH OGONEK (only %2=1)
{ {
if (wchar % 2 == 1) if (wchar % 2 == 1)
return wchar_t(uint16(wchar)-0x0001); return wchar_t(uint16(wchar) - 0x0001);
} }
if (wchar >= 0x0430 && wchar <= 0x044F) // CYRILLIC SMALL LETTER A - CYRILLIC SMALL LETTER YA if (wchar >= 0x0430 && wchar <= 0x044F) // CYRILLIC SMALL LETTER A - CYRILLIC SMALL LETTER YA
return wchar_t(uint16(wchar)-0x0020); return wchar_t(uint16(wchar) - 0x0020);
if (wchar == 0x0451) // CYRILLIC SMALL LETTER IO if (wchar == 0x0451) // CYRILLIC SMALL LETTER IO
return wchar_t(0x0401); return wchar_t(0x0401);
@@ -300,22 +300,22 @@ inline wchar_t wcharToUpperOnlyLatin(wchar_t wchar)
inline wchar_t wcharToLower(wchar_t wchar) inline wchar_t wcharToLower(wchar_t wchar)
{ {
if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z if (wchar >= L'A' && wchar <= L'Z') // LATIN CAPITAL LETTER A - LATIN CAPITAL LETTER Z
return wchar_t(uint16(wchar)+0x0020); return wchar_t(uint16(wchar) + 0x0020);
if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS if (wchar >= 0x00C0 && wchar <= 0x00D6) // LATIN CAPITAL LETTER A WITH GRAVE - LATIN CAPITAL LETTER O WITH DIAERESIS
return wchar_t(uint16(wchar)+0x0020); return wchar_t(uint16(wchar) + 0x0020);
if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN if (wchar >= 0x00D8 && wchar <= 0x00DE) // LATIN CAPITAL LETTER O WITH STROKE - LATIN CAPITAL LETTER THORN
return wchar_t(uint16(wchar)+0x0020); return wchar_t(uint16(wchar) + 0x0020);
if (wchar >= 0x0100 && wchar <= 0x012E) // LATIN CAPITAL LETTER A WITH MACRON - LATIN CAPITAL LETTER I WITH OGONEK (only %2=0) if (wchar >= 0x0100 && wchar <= 0x012E) // LATIN CAPITAL LETTER A WITH MACRON - LATIN CAPITAL LETTER I WITH OGONEK (only %2=0)
{ {
if (wchar % 2 == 0) if (wchar % 2 == 0)
return wchar_t(uint16(wchar)+0x0001); return wchar_t(uint16(wchar) + 0x0001);
} }
if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S if (wchar == 0x1E9E) // LATIN CAPITAL LETTER SHARP S
return wchar_t(0x00DF); return wchar_t(0x00DF);
if (wchar == 0x0401) // CYRILLIC CAPITAL LETTER IO if (wchar == 0x0401) // CYRILLIC CAPITAL LETTER IO
return wchar_t(0x0451); return wchar_t(0x0451);
if (wchar >= 0x0410 && wchar <= 0x042F) // CYRILLIC CAPITAL LETTER A - CYRILLIC CAPITAL LETTER YA if (wchar >= 0x0410 && wchar <= 0x042F) // CYRILLIC CAPITAL LETTER A - CYRILLIC CAPITAL LETTER YA
return wchar_t(uint16(wchar)+0x0020); return wchar_t(uint16(wchar) + 0x0020);
return wchar; return wchar;
} }
@@ -328,8 +328,8 @@ std::wstring GetMainPartOfName(std::wstring const& wname, uint32 declension);
bool utf8ToConsole(const std::string& utf8str, std::string& conStr); bool utf8ToConsole(const std::string& utf8str, std::string& conStr);
bool consoleToUtf8(const std::string& conStr, std::string& utf8str); bool consoleToUtf8(const std::string& conStr, std::string& utf8str);
bool Utf8FitTo(const std::string& str, std::wstring const& search); bool Utf8FitTo(const std::string& str, std::wstring const& search);
void utf8printf(FILE* out, const char *str, ...); void utf8printf(FILE* out, const char* str, ...);
void vutf8printf(FILE* out, const char *str, va_list* ap); void vutf8printf(FILE* out, const char* str, va_list* ap);
bool Utf8ToUpperOnlyLatin(std::string& utf8String); bool Utf8ToUpperOnlyLatin(std::string& utf8String);
bool IsIPAddress(char const* ipaddress); bool IsIPAddress(char const* ipaddress);
@@ -364,15 +364,15 @@ template <typename T>
class HookList class HookList
{ {
typedef typename std::list<T>::iterator ListIterator; typedef typename std::list<T>::iterator ListIterator;
private: private:
typename std::list<T> m_list; typename std::list<T> m_list;
public: public:
HookList<T> & operator+=(T t) HookList<T>& operator+=(T t)
{ {
m_list.push_back(t); m_list.push_back(t);
return *this; return *this;
} }
HookList<T> & operator-=(T t) HookList<T>& operator-=(T t)
{ {
m_list.remove(t); m_list.remove(t);
return *this; return *this;
@@ -456,10 +456,10 @@ public:
return *this; return *this;
} }
/* requried as of C++ 11 */ /* requried as of C++ 11 */
#if __cplusplus >= 201103L #if __cplusplus >= 201103L
flag96(const flag96&) = default; flag96(const flag96&) = default;
flag96(flag96&&) = default; flag96(flag96&&) = default;
#endif #endif
inline flag96 operator&(flag96 const& right) const inline flag96 operator&(flag96 const& right) const
{ {
@@ -577,7 +577,7 @@ class EventMap
{ {
typedef std::multimap<uint32, uint32> EventStore; typedef std::multimap<uint32, uint32> EventStore;
public: public:
EventMap() : _time(0), _phase(0) { } EventMap() : _time(0), _phase(0) { }
/** /**
@@ -791,7 +791,7 @@ class EventMap
{ {
for (EventStore::iterator itr = _eventMap.begin(); itr != _eventMap.end();) for (EventStore::iterator itr = _eventMap.begin(); itr != _eventMap.end();)
{ {
if (itr->first < _time+delay && (group == 0 || ((1 << (group + 15)) & itr->second))) if (itr->first < _time + delay && (group == 0 || ((1 << (group + 15)) & itr->second)))
{ {
ScheduleEvent(itr->second, delay); ScheduleEvent(itr->second, delay);
_eventMap.erase(itr); _eventMap.erase(itr);
@@ -909,7 +909,7 @@ class EventMap
return phase <= 8 && (!phase || _phase & (1 << (phase - 1))); return phase <= 8 && (!phase || _phase & (1 << (phase - 1)));
} }
private: private:
uint32 _time; uint32 _time;
uint32 _phase; uint32 _phase;