My Project
|
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... | |
TextureEntity * | GetTexture (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... | |
HighResTextureInfo * | m_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< TextureCacheItem > | m_CachedTextureItems |
all cached items | |
vector< string > | m_listTextures |
all texture file path lists. More... | |
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.
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.
TextureEntity * CDetailTextureFactory::GetTexture | ( | int | index | ) |
first search in the cache
load into the cache if it is not in it.
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.
nLayer | the layer number, up to 4. The default is the 0th layer. |
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
float ParaTerrain::CDetailTextureFactory::m_fTileSize |
the size of each tile in world unit.
vector<string> ParaTerrain::CDetailTextureFactory::m_listTextures |
all texture file path lists.
int ParaTerrain::CDetailTextureFactory::m_nTileNum |
the number of tiles in the x or y direction.They must be equal.
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