0ad/source/graphics/TextureManager.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

108 lines
2.9 KiB
C++

#ifndef INCLUDED_TEXTUREMANAGER
#define INCLUDED_TEXTUREMANAGER
#include <vector>
#include <map>
#include <boost/shared_ptr.hpp>
#include "lib/res/handle.h"
#include "ps/CStr.h"
#include "ps/Singleton.h"
// access to sole CTextureManager object
#define g_TexMan CTextureManager ::GetSingleton()
class XMBElement;
class CXeromyces;
class CTextureEntry;
class CTerrainProperties;
typedef shared_ptr<CTerrainProperties> CTerrainPropertiesPtr;
class CTerrainGroup
{
// name of this terrain group (as specified by the terrain XML)
CStr m_Name;
// "index".. basically a bogus integer that can be used by ScEd to set texture
// priorities
size_t m_Index;
// list of textures of this type (found from the texture directory)
std::vector<CTextureEntry*> m_Terrains;
public:
CTerrainGroup(CStr name, size_t index):
m_Name(name),
m_Index(index)
{}
// Add a texture entry to this terrain type
void AddTerrain(CTextureEntry *);
// Remove a texture entry
void RemoveTerrain(CTextureEntry *);
size_t GetIndex() const
{ return m_Index; }
CStr GetName() const
{ return m_Name; }
const std::vector<CTextureEntry*> &GetTerrains() const
{ return m_Terrains; }
};
///////////////////////////////////////////////////////////////////////////////////////////
// CTextureManager : manager class for all terrain texture objects
class CTextureManager : public Singleton<CTextureManager>
{
public:
typedef std::map<CStr, CTerrainGroup *> TerrainGroupMap;
private:
// All texture entries created by this class, for easy freeing now that
// textures may be in several STextureType's
std::vector<CTextureEntry *> m_TextureEntries;
TerrainGroupMap m_TerrainGroups;
size_t m_LastGroupIndex;
// Find+load all textures in directory; check if
// there's an override XML with the same basename (if there is, load it)
void LoadTextures(CTerrainPropertiesPtr props, const char* dir);
// Load all terrains below path, using props as the parent property sheet.
void RecurseDirectory(CTerrainPropertiesPtr props, const char* dir);
CTerrainPropertiesPtr GetPropertiesFromFile(CTerrainPropertiesPtr props, const char* path);
public:
// constructor, destructor
CTextureManager();
~CTextureManager();
// Find all XML's in the directory (with subdirs) and try to load them as
// terrain XML's
int LoadTerrainTextures();
void UnloadTerrainTextures();
CTextureEntry* FindTexture(CStr tag);
CTextureEntry* FindTexture(Handle handle);
// Create a texture object for a new terrain texture at path, using the
// property sheet props.
CTextureEntry *AddTexture(CTerrainPropertiesPtr props, const CStr& path);
// Remove the texture from all our maps and lists and delete it afterwards.
void DeleteTexture(CTextureEntry* entry);
// Find or create a new texture group. All terrain groups are owned by the
// texturemanager (TerrainTypeManager)
CTerrainGroup *FindGroup(const CStr& name);
const TerrainGroupMap &GetGroups() const
{ return m_TerrainGroups; }
};
#endif