0ad/source/graphics/TextureEntry.h
janwas c0ed950657 had to remove uint and ulong from lib/types.h due to conflict with other library.
this snowballed into a massive search+destroy of the hodgepodge of
mostly equivalent types we had in use (int, uint, unsigned, unsigned
int, i32, u32, ulong, uintN).

it is more efficient to use 64-bit types in 64-bit mode, so the
preferred default is size_t (for anything remotely resembling a size or
index). tile coordinates are ssize_t to allow more efficient conversion
to/from floating point. flags are int because we almost never need more
than 15 distinct bits, bit test/set is not slower and int is fastest to
type. finally, some data that is pretty much directly passed to OpenGL
is now typed accordingly.

after several hours, the code now requires fewer casts and less
guesswork.

other changes:
- unit and player IDs now have an "invalid id" constant in the
respective class to avoid casting and -1
- fix some endian/64-bit bugs in the map (un)packing. added a
convenience function to write/read a size_t.
- ia32: change CPUID interface to allow passing in ecx (required for
cache topology detection, which I need at work). remove some unneeded
functions from asm, replace with intrinsics where possible.

This was SVN commit r5942.
2008-05-11 18:48:32 +00:00

96 lines
2.6 KiB
C++

#ifndef INCLUDED_TEXTUREENTRY
#define INCLUDED_TEXTUREENTRY
#include <map>
#include "lib/res/handle.h"
#include "ps/CStr.h"
#include "TextureManager.h"
class XMBElement;
class CXeromyces;
//////////////////////////////////////////////////////////////////////////////////////////////////////////
// CTextureEntry: class wrapping a terrain texture object; contains various other required
// elements - color of minimap, terrain "group" it belongs to, etc
class CTextureEntry
{
public:
typedef std::vector<CTerrainGroup *> GroupVector;
private:
// Tag = file name stripped of path and extension (grass_dark_1)
CStr m_Tag;
// The property sheet used by this texture
CTerrainPropertiesPtr m_pProperties;
// Path to the texture file
CStr m_TexturePath;
void* m_Bitmap; // UI bitmap object (user data for ScEd)
Handle m_Handle; // handle to GL texture data
// BGRA color of topmost mipmap level, for coloring minimap, or a color
// specified by the terrain properties
u32 m_BaseColor;
// ..Valid is true if the base color has been cached
bool m_BaseColorValid;
// All terrain type groups we're a member of
GroupVector m_Groups;
// A map of all loaded textures and their texture handles for GetByHandle.
static std::map<Handle, CTextureEntry *> m_LoadedTextures;
// load texture from file
void LoadTexture();
// calculate the root color of the texture, used for coloring minimap
void BuildBaseColor();
public:
// Most of the texture's data is delay-loaded, so after the constructor has
// been called, the texture entry is ready to be used.
CTextureEntry(CTerrainPropertiesPtr props, const CStr& path);
~CTextureEntry();
CStr GetTag() const
{ return m_Tag; }
CTerrainPropertiesPtr GetProperties() const
{ return m_pProperties; }
CStr GetTexturePath() const
{ return m_TexturePath; }
void* GetBitmap() const { return m_Bitmap; }
void SetBitmap(void* bmp) { m_Bitmap=bmp; }
// Get texture handle, load texture if not loaded.
Handle GetHandle() {
if (m_Handle==-1) LoadTexture();
return m_Handle;
}
// Get mipmap color in BGRA format
u32 GetBaseColor() {
if (!m_BaseColorValid) BuildBaseColor();
return m_BaseColor;
}
// ScEd wants to sort textures by their group's index.
size_t GetType() const
{ return m_Groups[0]->GetIndex(); }
const GroupVector &GetGroups() const
{ return m_Groups; }
// returns whether this texture-entry has loaded any data yet
bool IsLoaded() { return (m_Handle!=-1); }
// The texture entry class maintains a map of loaded textures and their
// handles.
static CTextureEntry *GetByHandle(Handle handle);
};
#endif