My Project
Public Types | Public Member Functions | List of all members
ParaEngine::CTerrainTileRoot Class Reference

the root of the quad-tree terrain tiles. More...

#include <TerrainTileRoot.h>

Inheritance diagram for ParaEngine::CTerrainTileRoot:
ParaEngine::CTerrainTile ParaEngine::IAttributeFields ParaEngine::IObject ParaEngine::CRefCounted

Public Types

enum  DIRECTION {
  DIR_SOUTHWEST = 0, DIR_SOUTH = 1, DIR_SOUTHEAST = 2, DIR_WEST = 3,
  DIR_CENTER = 4, DIR_EAST = 5, DIR_NORTHWEST = 6, DIR_NORTH = 7,
  DIR_NORTHEAST = 8, DIR_INVALID = 9
}
 These values are used by Terrain TILE. More...
 
- Public Types inherited from ParaEngine::IAttributeFields
typedef ParaEngine::weak_ptr< IObject, IAttributeFieldsWeakPtr_type
 
- Public Types inherited from ParaEngine::IObject
typedef ParaEngine::weak_ptr< IObjectWeakPtr_type
 

Public Member Functions

virtual int GetAttributeClassID ()
 attribute class ID should be identical, unless one knows how overriding rules work. More...
 
virtual const char * GetAttributeClassName ()
 a static string, describing the attribute class object's name
 
virtual IAttributeFieldsGetChildAttributeObject (const std::string &sName)
 get attribute by child object. More...
 
virtual int GetChildAttributeObjectCount (int nColumnIndex=0)
 get the number of child objects (row count) in the given column. More...
 
virtual int GetChildAttributeColumnCount ()
 we support multi-dimensional child object. More...
 
virtual IAttributeFieldsGetChildAttributeObject (int nRowIndex, int nColumnIndex=0)
 
virtual void Cleanup ()
 
void ResetTerrain (float fRadius, int nDepth)
 Reset Terrain.
 
CTerrainTileGetAdjacentTile (CTerrainTile *pTile, DIRECTION nDirection)
 get any of the 9 adjacent tile of pTile. More...
 
CTerrainTileGetAdjacentTile (const Vector3 &vPos, DIRECTION nDirection, float fRadius=0.f)
 get any of the 9 adjacent tiles of a given point. More...
 
CTerrainTileAttachLocalObject (CBaseObject *obj)
 attach object to the proper tile that tells most exactly where it is if the object is already in the tile, it will be attached twice.So it is the caller's responsibility to check for duplicate calls to this function for the same object. More...
 
CTerrainTileAttachGlobalObject (CBaseObject *obj)
 the object will be attached to the root tile as solid object. More...
 
bool DetachObject (CBaseObject *pObject)
 detach the object from the tile or its sub tiles. More...
 
CTerrainTileGetTileByPoint (float fAbsoluteX, float fAbsoluteY)
 get existing smallest tile that contains the given point More...
 
CTerrainTileGetTileByRect (float fAbsoluteX, float fAbsoluteY, float fPtWidth, float fPtHeight)
 get existing smallest tile that contains the given rect More...
 
CBaseObjectGetGlobalObject (const string &sName)
 get the global object by its name. More...
 
CBaseObjectGetLocalObject (const string &sName, const Vector3 &vPos, DWORD dwFlag=3)
 Get an object. More...
 
CBaseObjectGetLocalObject (const Vector3 &vPos, float fEpsilon=0.01f)
 get the first local object,whose position is very close to vPos. More...
 
CBaseObjectGetLocalObject (const Vector3 &vPos, const std::string &sName, float fEpsilon=0.01f)
 
CBaseObjectGetObjectByViewBox (const CShapeAABB &viewbox)
 get an object(usually a static mesh object) by a given view box. More...
 
- Public Member Functions inherited from ParaEngine::CTerrainTile
 CTerrainTile ()
 2009.8.26: if defined, we will attach mesh object to the most suitable terrain tile if not defined, we will always attach mesh object to the leaf terrain tile. More...
 
 CTerrainTile (float x, float y, float r)
 
 ATTRIBUTE_DEFINE_CLASS (CTerrainTile)
 
void GetPosition (Vector3 *pV)
 get object position in the world space
 
bool TestCollisionSphere (const Vector3 *pvCenter, FLOAT radius)
 
bool TestCollisionObject (CBaseObject *pObj)
 desc: test if the object collide with this object in the world view. More...
 
float GetSphereCollisionDepth (Vector3 *pvCenter, FLOAT radius, bool bSolveDepth=false)
 
float GetObjectCollisionDepth (CBaseObject *pObj)
 desc: test if the circle in the y=0 plane collide with this object in the world view Note: radius can be zero. More...
 
int GetSubTileIndexByPoint (FLOAT fAbsoluteX, FLOAT fAbsoluteY)
 desc: get the sub tile index which best tells the position of point given sub tile and its locations. More...
 
int GetChildTileIndexByRect (FLOAT fAbsoluteX, FLOAT fAbsoluteY, FLOAT fWidth, FLOAT fHeight)
 return the indice of child tiles which contain or intersect with a rectangular. More...
 
CTerrainTileCreateSubTile (int nIndex)
 nIndex: which tile to get. If the tile is blank, we will create it. More...
 
CBaseObjectSearchObject (const char *pSearchString, int search_mode=0, int reserved=0)
 find a object by its name. More...
 
CBaseObjectGetObject (const string &sName)
 get the object by its name. More...
 
void DestroyObjectByName (const char *sName)
 destroy an object by its name. More...
 
CBaseObjectGetLocalObject (const Vector3 &vPos, float fEpsilon=0.01f)
 get the first local object,whose position is very close to vPos. More...
 
CBaseObjectGetLocalObject (const Vector3 &vPos, const std::string &sName, float fEpsilon=0.01f)
 
void AddVisitor (IGameObject *pObj, bool bCheckDuplicate=false)
 add a new visitor to the terrain tile. More...
 
bool RemoveVisitor (IGameObject *pObj)
 delete a visitor to the terrain tile. More...
 
- Public Member Functions inherited from ParaEngine::IAttributeFields
virtual const char * GetAttributeClassDescription ()
 a static string, describing the attribute class object
 
virtual int InstallFields (CAttributeClass *pClass, bool bOverride)
 this class should be implemented if one wants to add new attribute. More...
 
 ATTRIBUTE_METHOD1 (IAttributeFields, GetName_s, const char **)
 
 ATTRIBUTE_METHOD1 (IAttributeFields, SetName_s, const char *)
 
 ATTRIBUTE_METHOD (IAttributeFields, PrintObject_s)
 
 ATTRIBUTE_METHOD (IAttributeFields, AddRef_s)
 
 ATTRIBUTE_METHOD1 (IAttributeFields, GetRefCount_s, int *)
 
 ATTRIBUTE_METHOD1 (IAttributeFields, SetTime_s, int)
 
 ATTRIBUTE_METHOD1 (IAttributeFields, GetTime_s, int *)
 
 ATTRIBUTE_METHOD (IAttributeFields, Release_s)
 
virtual const std::string & GetIdentifier ()
 
virtual void SetIdentifier (const std::string &sID)
 
virtual bool IsModified ()
 whether some of the fields are modified.It is up to the implementation class to provide this functionality if necessary. More...
 
virtual void SetModified (bool bModified)
 set whether any field has been modified. More...
 
virtual bool ValidateFields ()
 validate all fields and return true if validation passed. More...
 
virtual string GetValidationMessage ()
 get the recent validation message due to the most recent call to ValidateFields()
 
virtual bool ResetField (int nFieldID)
 Reset the field to its initial or default value. More...
 
virtual bool InvokeEditor (int nFieldID, const std::string &sParameters)
 Invoke an (external) editor for a given field. More...
 
virtual bool AddChildAttributeObject (IAttributeFields *pChild, int nRowIndex=-1, int nColumnIndex=0)
 add child object. More...
 
virtual void * QueryObjectByName (const std::string &sObjectType)
 convert to object of a given type. More...
 
virtual void * QueryObject (int nObjectType)
 convert to object of a given type. More...
 
virtual int GetTime ()
 get the current local time in case it is animated in milli seconds frames. More...
 
virtual void SetTime (int nTime)
 
virtual CDynamicAttributeFieldGetDynamicField (const std::string &sName)
 Get a dynamic field with a given name. More...
 
virtual CDynamicAttributeFieldGetDynamicField (int nIndex)
 Get a dynamic field with a given index. More...
 
virtual const char * GetDynamicFieldNameByIndex (int nIndex)
 get field name by index
 
virtual int GetDynamicFieldCount ()
 how many dynamic field this object currently have. More...
 
virtual int SetDynamicField (const std::string &sName, const CVariable &value)
 set a dynamic field with a given name. More...
 
virtual int AddDynamicField (const std::string &sName, ATTRIBUTE_FIELDTYPE dwType)
 add dynamic field and return field index
 
virtual void RemoveAllDynamicFields ()
 remove all dynamic fields
 
virtual int SaveDynamicFieldsToString (std::string &output)
 save only text dynamic fields to fieldname = value text strings. More...
 
virtual int LoadDynamicFieldsFromString (const std::string &input)
 load only text dynamic fields from string More...
 
CAttributeClassGetAttributeClass ()
 get the main attribute class object. More...
 
void PrintObject ()
 print the content of this object to a text file at temp/doc/[ClassName].txt. More...
 
- Public Member Functions inherited from ParaEngine::IObject
virtual void Clone (IObject *obj) const
 Clone the object's contains to a pointer. More...
 
virtual IObjectClone () const
 Clone the object's contains and return a pointer to the newly created object. More...
 
virtual bool Equals (const IObject *obj) const
 Compare the object with another object. More...
 
virtual const ITypeGetType () const
 
virtual std::string ToString () const
 
WeakPtr_typeGetWeakReference ()
 get weak reference object. More...
 
virtual int ProcessObjectEvent (const ObjectEvent &event)
 this function is only used to backward compatibility of ParaObject:AddEvent() function. More...
 
- Public Member Functions inherited from ParaEngine::CRefCounted
void addref () const
 add reference count of the object. More...
 
bool delref () const
 decrease reference count of the object. More...
 
int GetRefCount () const
 get the reference count
 
virtual int Release ()
 
CRefCountedAddToAutoReleasePool ()
 addref and releases the ownership sometime soon automatically (usually at the end of the current frame). More...
 

Additional Inherited Members

- Static Public Member Functions inherited from ParaEngine::IAttributeFields
static HRESULT GetAttributeClassID_s (IAttributeFields *cls, int *p1)
 
static HRESULT GetAttributeClassName_s (IAttributeFields *cls, const char **p1)
 
static bool OpenWithDefaultEditor (const char *sFilename, bool bWaitOnReturn=false)
 Open a given file with the default registered editor in the game engine. More...
 
- Public Attributes inherited from ParaEngine::CTerrainTile
CTerrainTilem_subtiles [MAX_NUM_SUBTILE]
 
ObjectRefArray_type m_listSolidObj
 solid objects list. Mobile objects might collide with this kind of objects
 
ObjectRefArray_type m_listFreespace
 Free space objects list, might contains a rendering hierarchy. More...
 
VisitorList_type m_listVisitors
 mobile game objects that is moving in this region
 
map< string, CBaseObject * > m_namemap
 global name mapping.
 
unordered_ref_array< IAttributeFields * > m_children
 
float m_fX
 the central position of the terrain.
 
float m_fY
 
float m_fRadius
 the radius of the entire terrain (half the length of the square terrain).
 
- Protected Member Functions inherited from ParaEngine::IAttributeFields
virtual CAttributeClassCreateAttributeClass ()
 initialize fields
 
virtual CDynamicAttributesSetGetDynamicAttributes (bool bCreateIfNotExist=false)
 
- Protected Attributes inherited from ParaEngine::IObject
WeakPtr_type m_weak_reference
 
- Protected Attributes inherited from ParaEngine::CRefCounted
int m_refcount
 

Detailed Description

the root of the quad-tree terrain tiles.

When Tile Object is attached to the scene, they are automatically attached to this quad-tree. Once attached, a strong reference of the object is kept, once detached, object will be added to the auto release pool, which will be deleted some time in the next frame if reference count is zero.

Member Enumeration Documentation

§ DIRECTION

These values are used by Terrain TILE.

Enumerator
DIR_SOUTHWEST 

Offset along negative x and y axes.

DIR_SOUTH 

Offset along negative y axis.

DIR_SOUTHEAST 

Offset along positive x and negative y axes.

DIR_WEST 

Offset along negative x axis.

DIR_CENTER 

No offset.

DIR_EAST 

Offset along positive x axis.

DIR_NORTHWEST 

Offset along negative x and positive y axes.

DIR_NORTH 

Offset along the positive y axis.

DIR_NORTHEAST 

Offset along positive x and y axes.

DIR_INVALID 

Placeholder for uninitialized and maximum values.

Member Function Documentation

§ AttachGlobalObject()

CTerrainTile * CTerrainTileRoot::AttachGlobalObject ( CBaseObject obj)

the object will be attached to the root tile as solid object.

global objects can be retrieved very fast by its name.

Returns
: the terrain tile which the object is attached is returned

§ AttachLocalObject()

CTerrainTile * CTerrainTileRoot::AttachLocalObject ( CBaseObject obj)

attach object to the proper tile that tells most exactly where it is if the object is already in the tile, it will be attached twice.So it is the caller's responsibility to check for duplicate calls to this function for the same object.

Returns
: the terrain tile which the object is attached is returned

§ DetachObject()

bool CTerrainTileRoot::DetachObject ( CBaseObject pObject)

detach the object from the tile or its sub tiles.

it will not be found. the function will return once the first matching object is found and detached

Parameters
pObjectthe object to be detached.
Returns
: true if the object has been found and detached.

§ GetAdjacentTile() [1/2]

CTerrainTile * CTerrainTileRoot::GetAdjacentTile ( CTerrainTile pTile,
DIRECTION  nDirection 
)

get any of the 9 adjacent tile of pTile.

Remarks
: Please note that because tiles are a dynamic quad tree, the same tile may be returned for two different directions.
Parameters
nDirectionnumber 0-8,
See also
DIRECTION.
Returns
: pointer to the adjacent tiles. If there is no tile at that position, its parent tile is returned. hence, the same tile may be returned when querying different directions.

§ GetAdjacentTile() [2/2]

CTerrainTile * CTerrainTileRoot::GetAdjacentTile ( const Vector3 vPos,
DIRECTION  nDirection,
float  fRadius = 0.f 
)

get any of the 9 adjacent tiles of a given point.

Remarks
: Please note that because tiles are a dynamic quad tree, the same tile may be returned for two different directions.
Parameters
vPosthe position centered at which the 9 adjacent tiles are queried.Please note that only x,z component is used. y is ignored.
nDirectionnumber 0-8,
See also
DIRECTION.
Parameters
fRadiusradius of the adjacent region. If this is 0 or negative, the smallest quad tree size will be used.
Returns
pointer to the adjacent tiles. If there is no tile at that position, its parent tile is returned. hence, the same tile may be returned when querying different directions.

§ GetAttributeClassID()

virtual int ParaEngine::CTerrainTileRoot::GetAttributeClassID ( )
inlinevirtual

attribute class ID should be identical, unless one knows how overriding rules work.

Reimplemented from ParaEngine::IAttributeFields.

§ GetChildAttributeColumnCount()

int ParaEngine::CTerrainTileRoot::GetChildAttributeColumnCount ( )
virtual

we support multi-dimensional child object.

by default objects have only one column.

Reimplemented from ParaEngine::CTerrainTile.

§ GetChildAttributeObject()

IAttributeFields * ParaEngine::CTerrainTileRoot::GetChildAttributeObject ( const std::string &  sName)
virtual

get attribute by child object.

used to iterate across the attribute field hierarchy.

Reimplemented from ParaEngine::CTerrainTile.

§ GetChildAttributeObjectCount()

int ParaEngine::CTerrainTileRoot::GetChildAttributeObjectCount ( int  nColumnIndex = 0)
virtual

get the number of child objects (row count) in the given column.

please note different columns can have different row count.

Reimplemented from ParaEngine::CTerrainTile.

§ GetGlobalObject()

CBaseObject * CTerrainTileRoot::GetGlobalObject ( const string &  sName)

get the global object by its name.

If there have been several objects with the same name, the most recently attached object is returned.

Remarks
: if local mesh's name begins with "g_", it can also be retrieved by calling this function. however, if a global object has the same name, the global object is always returned instead of the local mesh.
Parameters
sNameexact name of the object

§ GetLocalObject() [1/2]

CBaseObject * CTerrainTileRoot::GetLocalObject ( const string &  sName,
const Vector3 vPos,
DWORD  dwFlag = 3 
)

Get an object.

Call this function to see if object with a given identifier is already attached.

Parameters
sNamename of the object, if this is "", the function always returns NULL
vPosthe location to search for the object.
dwFlag: [reserved] a value specifying the search range:
  • 1 for global object only,
  • 2 for local object only,
  • 3 for both global and local object.
Returns
return the object if found, otherwise NULL.

§ GetLocalObject() [2/2]

CBaseObject * CTerrainTileRoot::GetLocalObject ( const Vector3 vPos,
float  fEpsilon = 0.01f 
)

get the first local object,whose position is very close to vPos.

This function will search for the first (local mesh) object throughout the hierachy of the scene. this function is kind of slow, please do not call on a per frame basis. Use GetObjectByViewBox() to get an object faster.

Parameters
vPosworld position of the local mesh object
fEpsilonif a mesh is close enough to vPos within this value.
Returns
: NULL if not found

§ GetObjectByViewBox()

CBaseObject * CTerrainTileRoot::GetObjectByViewBox ( const CShapeAABB viewbox)

get an object(usually a static mesh object) by a given view box.

Parameters
viewboxOne can get the view box by getting the view culling object. see example in the ParaObject:GetViewBox().
Returns
: return the object with the closest match with the bounding box. NULL is returned if there is no match.

search for free space objects

§ GetTileByPoint()

CTerrainTile * CTerrainTileRoot::GetTileByPoint ( float  fAbsoluteX,
float  fAbsoluteY 
)

get existing smallest tile that contains the given point

Parameters
fAbsoluteX
fAbsoluteY
Returns

§ GetTileByRect()

CTerrainTile * CTerrainTileRoot::GetTileByRect ( float  fAbsoluteX,
float  fAbsoluteY,
float  fPtWidth,
float  fPtHeight 
)

get existing smallest tile that contains the given rect

Parameters
fAbsoluteX
fAbsoluteY
fPtWidth
fPtHeight
Returns

The documentation for this class was generated from the following files: