* Even more restructuring of the game library.

--HG--
branch : trunk
This commit is contained in:
XTZGZoReX
2010-06-06 22:55:56 +02:00
parent 840d4ab99d
commit 62200e8d02
169 changed files with 0 additions and 0 deletions
+88
View File
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef TRINITYCORE_PATH_H
#define TRINITYCORE_PATH_H
#include "Common.h"
#include <vector>
class Path
{
public:
struct PathNode
{
float x,y,z;
};
void SetLength(const unsigned int sz)
{
i_nodes.resize(sz);
}
unsigned int Size() const { return i_nodes.size(); }
bool Empty() const { return i_nodes.empty(); }
void Resize(unsigned int sz) { i_nodes.resize(sz); }
void Clear(void) { i_nodes.clear(); }
PathNode const* GetNodes(uint32 start = 0) const { return &i_nodes[start]; }
float GetTotalLength() const { return GetTotalLength(0,Size()); }
float GetTotalLength(uint32 start, uint32 end) const
{
float len = 0, xd, yd, zd;
for (unsigned int idx=start+1; idx < end; ++idx)
{
xd = i_nodes[ idx ].x - i_nodes[ idx-1 ].x;
yd = i_nodes[ idx ].y - i_nodes[ idx-1 ].y;
zd = i_nodes[ idx ].z - i_nodes[ idx-1 ].z;
len += sqrtf(xd*xd + yd*yd + zd*zd);
}
return len;
}
float GetPassedLength(uint32 curnode, float x, float y, float z)
{
float len = 0, xd, yd, zd;
for (unsigned int idx=1; idx < curnode; ++idx)
{
xd = i_nodes[ idx ].x - i_nodes[ idx-1 ].x;
yd = i_nodes[ idx ].y - i_nodes[ idx-1 ].y;
zd = i_nodes[ idx ].z - i_nodes[ idx-1 ].z;
len += sqrtf(xd*xd + yd*yd + zd*zd);
}
if (curnode > 0)
{
xd = x - i_nodes[curnode-1].x;
yd = y - i_nodes[curnode-1].y;
zd = z - i_nodes[curnode-1].z;
len += sqrtf(xd*xd + yd*yd + zd*zd);
}
return len;
}
PathNode& operator[](const unsigned int idx) { return i_nodes[idx]; }
const PathNode& operator()(const unsigned int idx) const { return i_nodes[idx]; }
protected:
std::vector<PathNode> i_nodes;
};
#endif
@@ -0,0 +1,152 @@
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "Database/DatabaseEnv.h"
#include "GridDefines.h"
#include "WaypointManager.h"
#include "ProgressBar.h"
#include "MapManager.h"
void WaypointStore::Free()
{
for (UNORDERED_MAP<uint32, WaypointPath*>::const_iterator itr = waypoint_map.begin(); itr != waypoint_map.end(); ++itr)
{
for (WaypointPath::const_iterator it = itr->second->begin(); it != itr->second->end(); ++it)
delete *it;
itr->second->clear();
delete itr->second;
}
waypoint_map.clear();
}
void WaypointStore::Load()
{
QueryResult_AutoPtr result = WorldDatabase.Query("SELECT COUNT(id) FROM waypoint_data");
if (!result)
{
sLog.outError("an error occured while loading the table `waypoint_data` (maybe it doesn't exist ?)");
exit(1); // Stop server at loading non exited table or not accessable table
}
records = (*result)[0].GetUInt32();
result = WorldDatabase.Query("SELECT id,point,position_x,position_y,position_z,move_flag,delay,action,action_chance FROM waypoint_data ORDER BY id, point");
if (!result)
{
sLog.outErrorDb("The table `waypoint_data` is empty or corrupted");
return;
}
WaypointPath* path_data = NULL;
uint32 total_records = result->GetRowCount();
barGoLink bar(total_records);
uint32 count = 0;
Field *fields;
uint32 last_id = 0;
do
{
fields = result->Fetch();
uint32 id = fields[0].GetUInt32();
bar.step();
count++;
WaypointData *wp = new WaypointData;
if (last_id != id)
path_data = new WaypointPath;
float x,y,z;
x = fields[2].GetFloat();
y = fields[3].GetFloat();
z = fields[4].GetFloat();
Trinity::NormalizeMapCoord(x);
Trinity::NormalizeMapCoord(y);
wp->id = fields[1].GetUInt32();
wp->x = x;
wp->y = y;
wp->z = z;
wp->run = fields[5].GetBool();
wp->delay = fields[6].GetUInt32();
wp->event_id = fields[7].GetUInt32();
wp->event_chance = fields[8].GetUInt8();
path_data->push_back(wp);
if (id != last_id)
waypoint_map[id] = path_data;
last_id = id;
} while (result->NextRow()) ;
sLog.outString();
sLog.outString(">> Loaded %u waypoints", count);
}
void WaypointStore::UpdatePath(uint32 id)
{
if (waypoint_map.find(id)!= waypoint_map.end())
waypoint_map[id]->clear();
QueryResult_AutoPtr result;
result = WorldDatabase.PQuery("SELECT point,position_x,position_y,position_z,move_flag,delay,action,action_chance FROM waypoint_data WHERE id = %u ORDER BY point", id);
if (!result)
return;
WaypointPath* path_data;
path_data = new WaypointPath;
Field *fields;
do
{
fields = result->Fetch();
WaypointData *wp = new WaypointData;
float x,y,z;
x = fields[1].GetFloat();
y = fields[2].GetFloat();
z = fields[3].GetFloat();
Trinity::NormalizeMapCoord(x);
Trinity::NormalizeMapCoord(y);
wp->id = fields[0].GetUInt32();
wp->x = x;
wp->y = y;
wp->z = z;
wp->run = fields[4].GetBool();
wp->delay = fields[5].GetUInt32();
wp->event_id = fields[6].GetUInt32();
wp->event_chance = fields[7].GetUInt8();
path_data->push_back(wp);
}
while (result->NextRow());
waypoint_map[id] = path_data;
}
@@ -0,0 +1,68 @@
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef TRINITY_WAYPOINTMANAGER_H
#define TRINITY_WAYPOINTMANAGER_H
#include <ace/Singleton.h>
#include <ace/Null_Mutex.h>
#include <vector>
struct WaypointData
{
uint32 id;
float x,y,z;
bool run;
uint32 delay;
uint32 event_id;
uint8 event_chance;
};
typedef std::vector<WaypointData*> WaypointPath;
class WaypointStore
{
private :
uint32 records;
UNORDERED_MAP<uint32, WaypointPath*> waypoint_map;
public:
// Null Mutex is OK because WaypointMgr is initialized in the World thread before World is initialized
static WaypointStore* instance() { return ACE_Singleton<WaypointStore, ACE_Null_Mutex>::instance(); }
~WaypointStore() { Free(); }
void UpdatePath(uint32 id);
void Load();
void Free();
WaypointPath* GetPath(uint32 id)
{
if (waypoint_map.find(id) != waypoint_map.end())
return waypoint_map[id];
else return 0;
}
inline uint32 GetRecordsCount() { return records; }
};
#define sWaypointMgr WaypointStore::instance()
#endif