* Get rid of framework and move the files to game and shared.
--HG-- branch : trunk
This commit is contained in:
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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_GRID_H
|
||||
#define TRINITY_GRID_H
|
||||
|
||||
/*
|
||||
@class Grid
|
||||
Grid is a logical segment of the game world represented inside TrinIty.
|
||||
Grid is bind at compile time to a particular type of object which
|
||||
we call it the object of interested. There are many types of loader,
|
||||
specially, dynamic loader, static loader, or on-demand loader. There's
|
||||
a subtle difference between dynamic loader and on-demand loader but
|
||||
this is implementation specific to the loader class. From the
|
||||
Grid's perspective, the loader meets its API requirement is suffice.
|
||||
*/
|
||||
|
||||
#include "Platform/Define.h"
|
||||
#include "Policies/ThreadingModel.h"
|
||||
#include "TypeContainer.h"
|
||||
#include "TypeContainerVisitor.h"
|
||||
|
||||
// forward declaration
|
||||
template<class A, class T, class O> class GridLoader;
|
||||
|
||||
template
|
||||
<
|
||||
class ACTIVE_OBJECT,
|
||||
class WORLD_OBJECT_TYPES,
|
||||
class GRID_OBJECT_TYPES,
|
||||
class ThreadModel = Trinity::SingleThreaded<ACTIVE_OBJECT>
|
||||
>
|
||||
class Grid
|
||||
{
|
||||
// allows the GridLoader to access its internals
|
||||
template<class A, class T, class O> friend class GridLoader;
|
||||
public:
|
||||
|
||||
/** destructor to clean up its resources. This includes unloading the
|
||||
grid if it has not been unload.
|
||||
*/
|
||||
~Grid() {}
|
||||
|
||||
/** an object of interested enters the grid
|
||||
*/
|
||||
template<class SPECIFIC_OBJECT> void AddWorldObject(SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
if(!i_objects.template insert<SPECIFIC_OBJECT>(obj))
|
||||
assert(false);
|
||||
}
|
||||
|
||||
/** an object of interested exits the grid
|
||||
*/
|
||||
template<class SPECIFIC_OBJECT> void RemoveWorldObject(SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
if(!i_objects.template remove<SPECIFIC_OBJECT>(obj))
|
||||
assert(false);
|
||||
}
|
||||
|
||||
/** Refreshes/update the grid. This required for remote grids.
|
||||
*/
|
||||
void RefreshGrid(void) { /* TBI */}
|
||||
|
||||
/** Locks a grid. Any object enters must wait until the grid is unlock.
|
||||
*/
|
||||
void LockGrid(void) { /* TBI */ }
|
||||
|
||||
/** Unlocks the grid.
|
||||
*/
|
||||
void UnlockGrid(void) { /* TBI */ }
|
||||
|
||||
/** Grid visitor for grid objects
|
||||
*/
|
||||
template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<GRID_OBJECT_TYPES> > &visitor)
|
||||
{
|
||||
visitor.Visit(i_container);
|
||||
}
|
||||
|
||||
/** Grid visitor for world objects
|
||||
*/
|
||||
template<class T> void Visit(TypeContainerVisitor<T, TypeMapContainer<WORLD_OBJECT_TYPES> > &visitor)
|
||||
{
|
||||
visitor.Visit(i_objects);
|
||||
}
|
||||
|
||||
/** Returns the number of object within the grid.
|
||||
*/
|
||||
unsigned int ActiveObjectsInGrid(void) const { return /*m_activeGridObjects.size()+*/i_objects.template Count<ACTIVE_OBJECT>(); }
|
||||
|
||||
/** Inserts a container type object into the grid.
|
||||
*/
|
||||
template<class SPECIFIC_OBJECT> void AddGridObject(SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
if(!i_container.template insert<SPECIFIC_OBJECT>(obj))
|
||||
assert(false);
|
||||
}
|
||||
|
||||
/** Removes a containter type object from the grid
|
||||
*/
|
||||
template<class SPECIFIC_OBJECT> void RemoveGridObject(SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
if(!i_container.template remove<SPECIFIC_OBJECT>(obj))
|
||||
assert(false);
|
||||
}
|
||||
|
||||
/*bool NoWorldObjectInGrid() const
|
||||
{
|
||||
return i_objects.GetElements().isEmpty();
|
||||
}
|
||||
|
||||
bool NoGridObjectInGrid() const
|
||||
{
|
||||
return i_container.GetElements().isEmpty();
|
||||
}*/
|
||||
private:
|
||||
|
||||
typedef typename ThreadModel::Lock Guard;
|
||||
typedef typename ThreadModel::VolatileType VolatileType;
|
||||
|
||||
TypeMapContainer<GRID_OBJECT_TYPES> i_container;
|
||||
TypeMapContainer<WORLD_OBJECT_TYPES> i_objects;
|
||||
//typedef std::set<void*> ActiveGridObjects;
|
||||
//ActiveGridObjects m_activeGridObjects;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* 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_GRIDLOADER_H
|
||||
#define TRINITY_GRIDLOADER_H
|
||||
|
||||
/**
|
||||
@class GridLoader
|
||||
The GridLoader is working in conjuction with the Grid and responsible
|
||||
for loading and unloading object-types (one or more) when objects
|
||||
enters a grid. Unloading is scheduled and might be canceled if
|
||||
an interested object re-enters. GridLoader does not do the actuall
|
||||
loading and unloading but implements as a template pattern that
|
||||
delicate its loading and unloading for the actualy loader and unloader.
|
||||
GridLoader manages the grid (both local and remote).
|
||||
*/
|
||||
|
||||
#include "Platform/Define.h"
|
||||
#include "Grid.h"
|
||||
#include "TypeContainerVisitor.h"
|
||||
|
||||
template
|
||||
<
|
||||
class ACTIVE_OBJECT,
|
||||
class WORLD_OBJECT_TYPES,
|
||||
class GRID_OBJECT_TYPES
|
||||
>
|
||||
class GridLoader
|
||||
{
|
||||
public:
|
||||
|
||||
/** Loads the grid
|
||||
*/
|
||||
template<class LOADER>
|
||||
void Load(Grid<ACTIVE_OBJECT,WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, LOADER &loader)
|
||||
{
|
||||
grid.LockGrid();
|
||||
loader.Load(grid);
|
||||
grid.UnlockGrid();
|
||||
}
|
||||
|
||||
/** Stop the grid
|
||||
*/
|
||||
template<class STOPER>
|
||||
void Stop(Grid<ACTIVE_OBJECT,WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, STOPER &stoper)
|
||||
{
|
||||
grid.LockGrid();
|
||||
stoper.Stop(grid);
|
||||
grid.UnlockGrid();
|
||||
}
|
||||
/** Unloads the grid
|
||||
*/
|
||||
template<class UNLOADER>
|
||||
void Unload(Grid<ACTIVE_OBJECT,WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> &grid, UNLOADER &unloader)
|
||||
{
|
||||
grid.LockGrid();
|
||||
unloader.Unload(grid);
|
||||
grid.UnlockGrid();
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 _GRIDREFMANAGER
|
||||
#define _GRIDREFMANAGER
|
||||
|
||||
#include "Utilities/LinkedReference/RefManager.h"
|
||||
|
||||
template<class OBJECT>
|
||||
class GridReference;
|
||||
|
||||
template<class OBJECT>
|
||||
class GridRefManager : public RefManager<GridRefManager<OBJECT>, OBJECT>
|
||||
{
|
||||
public:
|
||||
typedef LinkedListHead::Iterator< GridReference<OBJECT> > iterator;
|
||||
|
||||
GridReference<OBJECT>* getFirst() { return (GridReference<OBJECT>*)RefManager<GridRefManager<OBJECT>, OBJECT>::getFirst(); }
|
||||
GridReference<OBJECT>* getLast() { return (GridReference<OBJECT>*)RefManager<GridRefManager<OBJECT>, OBJECT>::getLast(); }
|
||||
|
||||
iterator begin() { return iterator(getFirst()); }
|
||||
iterator end() { return iterator(NULL); }
|
||||
iterator rbegin() { return iterator(getLast()); }
|
||||
iterator rend() { return iterator(NULL); }
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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 _GRIDREFERENCE_H
|
||||
#define _GRIDREFERENCE_H
|
||||
|
||||
#include "Utilities/LinkedReference/Reference.h"
|
||||
|
||||
template<class OBJECT>
|
||||
class GridRefManager;
|
||||
|
||||
template<class OBJECT>
|
||||
class GridReference : public Reference<GridRefManager<OBJECT>, OBJECT>
|
||||
{
|
||||
protected:
|
||||
void targetObjectBuildLink()
|
||||
{
|
||||
// called from link()
|
||||
this->getTarget()->insertFirst(this);
|
||||
this->getTarget()->incSize();
|
||||
}
|
||||
void targetObjectDestroyLink()
|
||||
{
|
||||
// called from unlink()
|
||||
if(this->isValid()) this->getTarget()->decSize();
|
||||
}
|
||||
void sourceObjectDestroyLink()
|
||||
{
|
||||
// called from invalidate()
|
||||
this->getTarget()->decSize();
|
||||
}
|
||||
public:
|
||||
GridReference() : Reference<GridRefManager<OBJECT>, OBJECT>() {}
|
||||
~GridReference() { this->unlink(); }
|
||||
GridReference *next() { return (GridReference*)Reference<GridRefManager<OBJECT>, OBJECT>::next(); }
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* 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_NGRID_H
|
||||
#define TRINITY_NGRID_H
|
||||
|
||||
/** NGrid is nothing more than a wrapper of the Grid with an NxN cells
|
||||
*/
|
||||
|
||||
#include "GameSystem/Grid.h"
|
||||
#include "GameSystem/GridReference.h"
|
||||
#include "Timer.h"
|
||||
#include "Util.h"
|
||||
|
||||
#define DEFAULT_VISIBILITY_NOTIFY_PERIOD 1000
|
||||
|
||||
class GridInfo
|
||||
{
|
||||
public:
|
||||
GridInfo()
|
||||
: i_timer(0), i_unloadActiveLockCount(0), i_unloadExplicitLock(false), i_unloadReferenceLock(false),
|
||||
vis_Update(0, irand(0,DEFAULT_VISIBILITY_NOTIFY_PERIOD)) {}
|
||||
GridInfo(time_t expiry, bool unload = true )
|
||||
: i_timer(expiry), i_unloadActiveLockCount(0), i_unloadExplicitLock(!unload), i_unloadReferenceLock(false),
|
||||
vis_Update(0, irand(0,DEFAULT_VISIBILITY_NOTIFY_PERIOD)) {}
|
||||
const TimeTracker& getTimeTracker() const { return i_timer; }
|
||||
bool getUnloadLock() const { return i_unloadActiveLockCount || i_unloadExplicitLock || i_unloadReferenceLock; }
|
||||
void setUnloadExplicitLock( bool on ) { i_unloadExplicitLock = on; }
|
||||
void setUnloadReferenceLock( bool on ) { i_unloadReferenceLock = on; }
|
||||
void incUnloadActiveLock() { ++i_unloadActiveLockCount; }
|
||||
void decUnloadActiveLock() { if(i_unloadActiveLockCount) --i_unloadActiveLockCount; }
|
||||
|
||||
void setTimer(const TimeTracker& pTimer) { i_timer = pTimer; }
|
||||
void ResetTimeTracker(time_t interval) { i_timer.Reset(interval); }
|
||||
void UpdateTimeTracker(time_t diff) { i_timer.Update(diff); }
|
||||
PeriodicTimer& getRelocationTimer() { return vis_Update; }
|
||||
private:
|
||||
TimeTracker i_timer;
|
||||
PeriodicTimer vis_Update;
|
||||
|
||||
uint16 i_unloadActiveLockCount : 16; // lock from active object spawn points (prevent clone loading)
|
||||
bool i_unloadExplicitLock : 1; // explicit manual lock or config setting
|
||||
bool i_unloadReferenceLock : 1; // lock from instance map copy
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GRID_STATE_INVALID = 0,
|
||||
GRID_STATE_ACTIVE = 1,
|
||||
GRID_STATE_IDLE = 2,
|
||||
GRID_STATE_REMOVAL= 3,
|
||||
MAX_GRID_STATE = 4
|
||||
} grid_state_t;
|
||||
|
||||
template
|
||||
<
|
||||
unsigned int N,
|
||||
class ACTIVE_OBJECT,
|
||||
class WORLD_OBJECT_TYPES,
|
||||
class GRID_OBJECT_TYPES,
|
||||
class ThreadModel = Trinity::SingleThreaded<ACTIVE_OBJECT>
|
||||
>
|
||||
class NGrid
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES, ThreadModel> GridType;
|
||||
NGrid(uint32 id, int32 x, int32 y, time_t expiry, bool unload = true)
|
||||
: i_gridId(id), i_x(x), i_y(y), i_cellstate(GRID_STATE_INVALID), i_GridObjectDataLoaded(false)
|
||||
{
|
||||
i_GridInfo = GridInfo(expiry, unload);
|
||||
}
|
||||
|
||||
const GridType& operator()(unsigned short x, unsigned short y) const
|
||||
{
|
||||
ASSERT(x < N);
|
||||
ASSERT(y < N);
|
||||
return i_cells[x][y];
|
||||
}
|
||||
|
||||
GridType& operator()(unsigned short x, unsigned short y)
|
||||
{
|
||||
ASSERT(x < N);
|
||||
ASSERT(y < N);
|
||||
return i_cells[x][y];
|
||||
}
|
||||
|
||||
const uint32& GetGridId(void) const { return i_gridId; }
|
||||
void SetGridId(const uint32 id) const { i_gridId = id; }
|
||||
grid_state_t GetGridState(void) const { return i_cellstate; }
|
||||
void SetGridState(grid_state_t s) { i_cellstate = s; }
|
||||
int32 getX() const { return i_x; }
|
||||
int32 getY() const { return i_y; }
|
||||
|
||||
void link(GridRefManager<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES, ThreadModel> >* pTo)
|
||||
{
|
||||
i_Reference.link(pTo, this);
|
||||
}
|
||||
bool isGridObjectDataLoaded() const { return i_GridObjectDataLoaded; }
|
||||
void setGridObjectDataLoaded(bool pLoaded) { i_GridObjectDataLoaded = pLoaded; }
|
||||
|
||||
GridInfo* getGridInfoRef() { return &i_GridInfo; }
|
||||
const TimeTracker& getTimeTracker() const { return i_GridInfo.getTimeTracker(); }
|
||||
bool getUnloadLock() const { return i_GridInfo.getUnloadLock(); }
|
||||
void setUnloadExplicitLock( bool on ) { i_GridInfo.setUnloadExplicitLock(on); }
|
||||
void setUnloadReferenceLock( bool on ) { i_GridInfo.setUnloadReferenceLock(on); }
|
||||
void incUnloadActiveLock() { i_GridInfo.incUnloadActiveLock(); }
|
||||
void decUnloadActiveLock() { i_GridInfo.decUnloadActiveLock(); }
|
||||
void ResetTimeTracker(time_t interval) { i_GridInfo.ResetTimeTracker(interval); }
|
||||
void UpdateTimeTracker(time_t diff) { i_GridInfo.UpdateTimeTracker(diff); }
|
||||
|
||||
template<class SPECIFIC_OBJECT> void AddWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
getGridType(x, y).AddWorldObject(obj);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> void RemoveWorldObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
getGridType(x, y).RemoveWorldObject(obj);
|
||||
}
|
||||
|
||||
template<class T, class TT> void Visit(TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor)
|
||||
{
|
||||
for (unsigned int x=0; x < N; ++x)
|
||||
for (unsigned int y=0; y < N; ++y)
|
||||
getGridType(x, y).Visit(visitor);
|
||||
}
|
||||
|
||||
template<class T, class TT> void Visit(const uint32 &x, const uint32 &y, TypeContainerVisitor<T, TypeMapContainer<TT> > &visitor)
|
||||
{
|
||||
getGridType(x, y).Visit(visitor);
|
||||
}
|
||||
|
||||
unsigned int ActiveObjectsInGrid(void) const
|
||||
{
|
||||
unsigned int count=0;
|
||||
for (unsigned int x=0; x < N; ++x)
|
||||
for (unsigned int y=0; y < N; ++y)
|
||||
count += i_cells[x][y].ActiveObjectsInGrid();
|
||||
return count;
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> bool AddGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
return getGridType(x, y).AddGridObject(obj);
|
||||
}
|
||||
|
||||
template<class SPECIFIC_OBJECT> bool RemoveGridObject(const uint32 x, const uint32 y, SPECIFIC_OBJECT *obj)
|
||||
{
|
||||
return getGridType(x, y).RemoveGridObject(obj);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
GridType& getGridType(const uint32& x, const uint32& y)
|
||||
{
|
||||
ASSERT(x < N);
|
||||
ASSERT(y < N);
|
||||
return i_cells[x][y];
|
||||
}
|
||||
|
||||
uint32 i_gridId;
|
||||
GridInfo i_GridInfo;
|
||||
GridReference<NGrid<N, ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES, ThreadModel> > i_Reference;
|
||||
int32 i_x;
|
||||
int32 i_y;
|
||||
grid_state_t i_cellstate;
|
||||
GridType i_cells[N][N];
|
||||
bool i_GridObjectDataLoaded;
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user