My Project
Classes | Public Member Functions | Public Attributes | List of all members
ParaTerrain::CDetailTextureFactory Class Reference

this class implements a texture factory class for detailed tile based terrain surface texture. More...

#include <DetailTextureFactory.h>

Classes

struct  HighResTextureInfo
 index to he texture list for each layer More...
 
struct  TextureCacheItem
 a cached texture item More...
 

Public Member Functions

void Init (int numTiles, float fTileSize)
 Initialize the texture factory. More...
 
void cleanup ()
 clear this class to uninitialized state
 
void DeleteAllTextures ()
 delete all textures in the cache
 
int GetTextureIDAt (float originX, float originY, short nLayer=0)
 check whether there is detailed texture at the specified world coordinates if so its index is returned. More...
 
void AdvanceFrame ()
 advance one frame, this is only used for managing texture cache hit counts. More...
 
TextureEntityGetTexture (int index)
 
void UnloadTexture (int index)
 

Public Attributes

string m_sFileName
 the low-res texture file path
 
int m_nTileNum
 the number of tiles in the x or y direction.They must be equal. More...
 
float m_fTileSize
 the size of each tile in world unit. More...
 
HighResTextureInfom_TexturesMatrix
 a m_nTileNumX*m_nTileNumY matrix, with the cell storing the texture index. More...
 
int m_nNumTextureCache
 maximum number of tile textures to cache in memory
 
list< TextureCacheItemm_CachedTextureItems
 all cached items
 
vector< string > m_listTextures
 all texture file path lists. More...
 

Detailed Description

this class implements a texture factory class for detailed tile based terrain surface texture.

This high-resolution texture is has 16 or 32 times the resolution of the low-res surface which is managed by the terrain class internally. Hence, This high-resolution texture can not be stored in one file, nor can it be persistent in the memory. it is always divided in square tiles. The naming conventions of these files are given below: "{file name} [x] [y].[jpg|bmp|...]", where x, y is the tile coordinates of the file in the terrain surface. e.g. "World 0 8.bmp" will be the detailed texture for the tile (0,8). All {file name} must be the same as the low-res terrain texture file specified in the main terrain class. e.g. the low-res texture, in the above case, should be called "World.bmp". This factory will cache a total tile textures of m_nMaxTextureCache in memory.

Member Function Documentation

§ AdvanceFrame()

void CDetailTextureFactory::AdvanceFrame ( )

advance one frame, this is only used for managing texture cache hit counts.

this function should be called once per frame. Here frame is means whenever the the terrain view changed.

§ GetTexture()

TextureEntity * CDetailTextureFactory::GetTexture ( int  index)

first search in the cache

load into the cache if it is not in it.

§ GetTextureIDAt()

int CDetailTextureFactory::GetTextureIDAt ( float  originX,
float  originY,
short  nLayer = 0 
)

check whether there is detailed texture at the specified world coordinates if so its index is returned.

If not,a negative number (-1) is returned.

Parameters
nLayerthe layer number, up to 4. The default is the 0th layer.

§ Init()

void CDetailTextureFactory::Init ( int  numTiles,
float  fTileSize 
)

Initialize the texture factory.

numTiles: the number of tiles in both x and y direction. fTileSize: the size of each tile in world unit usually they should be a power of 2. such as 16, 32

Member Data Documentation

§ m_fTileSize

float ParaTerrain::CDetailTextureFactory::m_fTileSize

the size of each tile in world unit.

§ m_listTextures

vector<string> ParaTerrain::CDetailTextureFactory::m_listTextures

all texture file path lists.

§ m_nTileNum

int ParaTerrain::CDetailTextureFactory::m_nTileNum

the number of tiles in the x or y direction.They must be equal.

§ m_TexturesMatrix

HighResTextureInfo* ParaTerrain::CDetailTextureFactory::m_TexturesMatrix

a m_nTileNumX*m_nTileNumY matrix, with the cell storing the texture index.

if the index is negative at m_TexturesMatrix[x,y], it means that there is no detailed texture at the tile [x,y] and that the low-res texture should be used instead


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