2010-05-28 01:31:03 +02:00
|
|
|
/* Copyright (C) 2010 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-09-10 23:02:10 +02:00
|
|
|
#ifndef INCLUDED_TERRAINTEXTUREMANAGER
|
|
|
|
#define INCLUDED_TERRAINTEXTUREMANAGER
|
2004-05-29 22:56:24 +02:00
|
|
|
|
|
|
|
#include <vector>
|
2005-06-20 17:14:36 +02:00
|
|
|
#include <map>
|
2006-06-02 03:01:39 +02:00
|
|
|
#include <boost/shared_ptr.hpp>
|
2005-06-20 17:14:36 +02:00
|
|
|
|
2005-08-12 19:06:53 +02:00
|
|
|
#include "lib/res/handle.h"
|
2010-07-04 12:15:53 +02:00
|
|
|
#include "lib/file/vfs/vfs_path.h"
|
2006-06-02 04:10:27 +02:00
|
|
|
#include "ps/CStr.h"
|
|
|
|
#include "ps/Singleton.h"
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2010-09-04 23:26:52 +02:00
|
|
|
// access to sole CTerrainTextureManager object
|
|
|
|
#define g_TexMan CTerrainTextureManager::GetSingleton()
|
2004-05-30 02:46:58 +02:00
|
|
|
|
2005-06-20 17:14:36 +02:00
|
|
|
class XMBElement;
|
|
|
|
class CXeromyces;
|
2010-09-04 23:26:52 +02:00
|
|
|
class CTerrainTextureEntry;
|
2005-08-07 23:58:36 +02:00
|
|
|
class CTerrainProperties;
|
2005-06-20 17:14:36 +02:00
|
|
|
|
2007-12-20 21:21:45 +01:00
|
|
|
typedef shared_ptr<CTerrainProperties> CTerrainPropertiesPtr;
|
2005-10-28 03:43:16 +02:00
|
|
|
|
2005-08-07 23:58:36 +02:00
|
|
|
class CTerrainGroup
|
2005-06-20 17:14:36 +02:00
|
|
|
{
|
2005-08-07 23:58:36 +02:00
|
|
|
// name of this terrain group (as specified by the terrain XML)
|
2005-06-20 17:14:36 +02:00
|
|
|
CStr m_Name;
|
2005-06-20 19:34:17 +02:00
|
|
|
// "index".. basically a bogus integer that can be used by ScEd to set texture
|
|
|
|
// priorities
|
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 20:48:32 +02:00
|
|
|
size_t m_Index;
|
2005-06-20 17:14:36 +02:00
|
|
|
// list of textures of this type (found from the texture directory)
|
2010-09-04 23:26:52 +02:00
|
|
|
std::vector<CTerrainTextureEntry*> m_Terrains;
|
2005-06-20 17:14:36 +02:00
|
|
|
|
|
|
|
public:
|
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 20:48:32 +02:00
|
|
|
CTerrainGroup(CStr name, size_t index):
|
2005-06-20 19:34:17 +02:00
|
|
|
m_Name(name),
|
|
|
|
m_Index(index)
|
2005-06-20 17:14:36 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
// Add a texture entry to this terrain type
|
2010-09-04 23:26:52 +02:00
|
|
|
void AddTerrain(CTerrainTextureEntry *);
|
2005-06-20 17:14:36 +02:00
|
|
|
// Remove a texture entry
|
2010-09-04 23:26:52 +02:00
|
|
|
void RemoveTerrain(CTerrainTextureEntry *);
|
2005-06-20 19:34:17 +02:00
|
|
|
|
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 20:48:32 +02:00
|
|
|
size_t GetIndex() const
|
2005-06-20 19:34:17 +02:00
|
|
|
{ return m_Index; }
|
|
|
|
CStr GetName() const
|
|
|
|
{ return m_Name; }
|
|
|
|
|
2010-09-04 23:26:52 +02:00
|
|
|
const std::vector<CTerrainTextureEntry*> &GetTerrains() const
|
2005-06-20 19:34:17 +02:00
|
|
|
{ return m_Terrains; }
|
2005-06-20 17:14:36 +02:00
|
|
|
};
|
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////
|
2010-09-04 23:26:52 +02:00
|
|
|
// CTerrainTextureManager : manager class for all terrain texture objects
|
|
|
|
class CTerrainTextureManager : public Singleton<CTerrainTextureManager>
|
2004-05-29 22:56:24 +02:00
|
|
|
{
|
2005-06-20 19:34:17 +02:00
|
|
|
public:
|
2005-08-07 23:58:36 +02:00
|
|
|
typedef std::map<CStr, CTerrainGroup *> TerrainGroupMap;
|
2005-06-20 19:34:17 +02:00
|
|
|
|
|
|
|
private:
|
2005-06-20 17:14:36 +02:00
|
|
|
// All texture entries created by this class, for easy freeing now that
|
|
|
|
// textures may be in several STextureType's
|
2010-09-04 23:26:52 +02:00
|
|
|
std::vector<CTerrainTextureEntry *> m_TextureEntries;
|
2005-06-20 17:14:36 +02:00
|
|
|
|
2005-08-07 23:58:36 +02:00
|
|
|
TerrainGroupMap m_TerrainGroups;
|
2005-06-20 17:14:36 +02:00
|
|
|
|
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 20:48:32 +02:00
|
|
|
size_t m_LastGroupIndex;
|
2005-06-20 19:34:17 +02:00
|
|
|
|
2005-10-24 01:57:59 +02:00
|
|
|
// Find+load all textures in directory; check if
|
2005-08-07 23:58:36 +02:00
|
|
|
// there's an override XML with the same basename (if there is, load it)
|
2009-11-03 22:46:35 +01:00
|
|
|
void LoadTextures(const CTerrainPropertiesPtr& props, const VfsPath& path);
|
2005-08-07 23:58:36 +02:00
|
|
|
|
|
|
|
// Load all terrains below path, using props as the parent property sheet.
|
2009-11-03 22:46:35 +01:00
|
|
|
void RecurseDirectory(const CTerrainPropertiesPtr& props, const VfsPath& path);
|
2005-08-07 23:58:36 +02:00
|
|
|
|
2009-11-03 22:46:35 +01:00
|
|
|
CTerrainPropertiesPtr GetPropertiesFromFile(const CTerrainPropertiesPtr& props, const VfsPath& pathname);
|
2004-05-29 22:56:24 +02:00
|
|
|
|
2004-05-30 02:46:58 +02:00
|
|
|
public:
|
2004-05-29 22:56:24 +02:00
|
|
|
// constructor, destructor
|
2010-09-04 23:26:52 +02:00
|
|
|
CTerrainTextureManager();
|
|
|
|
~CTerrainTextureManager();
|
2005-08-09 17:55:44 +02:00
|
|
|
|
|
|
|
// Find all XML's in the directory (with subdirs) and try to load them as
|
|
|
|
// terrain XML's
|
2005-05-03 23:36:57 +02:00
|
|
|
int LoadTerrainTextures();
|
2005-11-06 06:05:07 +01:00
|
|
|
|
|
|
|
void UnloadTerrainTextures();
|
2005-08-07 23:58:36 +02:00
|
|
|
|
2010-09-04 23:26:52 +02:00
|
|
|
CTerrainTextureEntry* FindTexture(const CStr& tag);
|
2005-08-07 23:58:36 +02:00
|
|
|
|
|
|
|
// Create a texture object for a new terrain texture at path, using the
|
|
|
|
// property sheet props.
|
2010-09-04 23:26:52 +02:00
|
|
|
CTerrainTextureEntry *AddTexture(const CTerrainPropertiesPtr& props, const VfsPath& path);
|
2005-08-07 23:58:36 +02:00
|
|
|
|
|
|
|
// Remove the texture from all our maps and lists and delete it afterwards.
|
2010-09-04 23:26:52 +02:00
|
|
|
void DeleteTexture(CTerrainTextureEntry* entry);
|
2005-06-20 17:14:36 +02:00
|
|
|
|
|
|
|
// Find or create a new texture group. All terrain groups are owned by the
|
|
|
|
// texturemanager (TerrainTypeManager)
|
2006-07-20 16:37:58 +02:00
|
|
|
CTerrainGroup *FindGroup(const CStr& name);
|
2005-06-20 19:34:17 +02:00
|
|
|
|
2005-08-07 23:58:36 +02:00
|
|
|
const TerrainGroupMap &GetGroups() const
|
|
|
|
{ return m_TerrainGroups; }
|
2004-05-29 22:56:24 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|