TerrainProperties: Use CTerrainPropertiesPtr (boost::shared_ptr) instead of CTerrainProperties*, to fix (slightly inelegantly) memory leaks.
Renderer: Initialise pointers when HW lighting is unavailable. Atlas: Avoid strange VS2005 iterator complaint. This was SVN commit r3036.
This commit is contained in:
parent
e3b0f20d4e
commit
bbda296289
@ -15,7 +15,7 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
CTerrainProperties::CTerrainProperties(CTerrainProperties *parent):
|
||||
CTerrainProperties::CTerrainProperties(CTerrainPropertiesPtr parent):
|
||||
m_pParent(parent),
|
||||
m_BaseColor(0),
|
||||
m_HasBaseColor(false)
|
||||
@ -24,11 +24,11 @@ CTerrainProperties::CTerrainProperties(CTerrainProperties *parent):
|
||||
m_Groups = m_pParent->m_Groups;
|
||||
}
|
||||
|
||||
CTerrainProperties *CTerrainProperties::FromXML(CTerrainProperties *parent, const char* path)
|
||||
CTerrainPropertiesPtr CTerrainProperties::FromXML(CTerrainPropertiesPtr parent, const char* path)
|
||||
{
|
||||
CXeromyces XeroFile;
|
||||
if (XeroFile.Load(path) != PSRETURN_OK)
|
||||
return NULL;
|
||||
return CTerrainPropertiesPtr();
|
||||
|
||||
XMBElement root = XeroFile.getRoot();
|
||||
CStr rootName = XeroFile.getElementString(root.getNodeName());
|
||||
@ -41,7 +41,7 @@ CTerrainProperties *CTerrainProperties::FromXML(CTerrainProperties *parent, cons
|
||||
"TextureManager: Loading %s: Root node is not terrains (found \"%s\")",
|
||||
path,
|
||||
rootName.c_str());
|
||||
return NULL;
|
||||
return CTerrainPropertiesPtr();
|
||||
}
|
||||
|
||||
#define ELMT(x) int el_##x = XeroFile.getElementID(#x)
|
||||
@ -62,7 +62,7 @@ CTerrainProperties *CTerrainProperties::FromXML(CTerrainProperties *parent, cons
|
||||
|
||||
if (child.getNodeName() == el_terrain)
|
||||
{
|
||||
CTerrainProperties *ret=new CTerrainProperties(parent);
|
||||
CTerrainPropertiesPtr ret (new CTerrainProperties(parent));
|
||||
ret->LoadXML(child, &XeroFile);
|
||||
return ret;
|
||||
}
|
||||
@ -76,7 +76,7 @@ CTerrainProperties *CTerrainProperties::FromXML(CTerrainProperties *parent, cons
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return CTerrainPropertiesPtr();
|
||||
}
|
||||
|
||||
void CTerrainProperties::LoadXML(XMBElement node, CXeromyces *pFile)
|
||||
|
@ -11,10 +11,14 @@
|
||||
#define graphics_TerrainProperties_H
|
||||
|
||||
#include "CStr.h"
|
||||
#include "boost/shared_ptr.hpp"
|
||||
|
||||
class CTerrainGroup;
|
||||
class XMBElement;
|
||||
class CXeromyces;
|
||||
class CTerrainProperties;
|
||||
|
||||
typedef boost::shared_ptr<CTerrainProperties> CTerrainPropertiesPtr;
|
||||
|
||||
class CTerrainProperties
|
||||
{
|
||||
@ -22,7 +26,7 @@ public:
|
||||
typedef std::vector<CTerrainGroup *> GroupVector;
|
||||
|
||||
private:
|
||||
CTerrainProperties *m_pParent;
|
||||
CTerrainPropertiesPtr m_pParent;
|
||||
|
||||
// BGRA color of topmost mipmap level, for coloring minimap, or a color
|
||||
// manually specified in the Terrain XML (or by any parent)
|
||||
@ -38,17 +42,17 @@ private:
|
||||
void LoadXML(XMBElement node, CXeromyces *pFile);
|
||||
|
||||
public:
|
||||
CTerrainProperties(CTerrainProperties *parent);
|
||||
CTerrainProperties(CTerrainPropertiesPtr parent);
|
||||
|
||||
// Create a new object and load the XML file specified. Returns NULL upon
|
||||
// failure
|
||||
// The parent pointer may be NULL, for the "root" terrainproperties object.
|
||||
static CTerrainProperties *FromXML(CTerrainProperties *parent, const char* path);
|
||||
static CTerrainPropertiesPtr FromXML(CTerrainPropertiesPtr parent, const char* path);
|
||||
|
||||
// Save the object to an XML file. Implement when needed! ;-)
|
||||
// bool WriteXML(CStr path);
|
||||
|
||||
inline CTerrainProperties *GetParent() const
|
||||
inline CTerrainPropertiesPtr GetParent() const
|
||||
{ return m_pParent; }
|
||||
|
||||
// Return true if this property object or any of its parents has a basecolor
|
||||
|
@ -21,7 +21,7 @@ map<Handle, CTextureEntry *> CTextureEntry::m_LoadedTextures;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// CTextureEntry constructor
|
||||
CTextureEntry::CTextureEntry(CTerrainProperties *props, CStr path):
|
||||
CTextureEntry::CTextureEntry(CTerrainPropertiesPtr props, CStr path):
|
||||
m_pProperties(props),
|
||||
m_Bitmap(NULL),
|
||||
m_Handle(-1),
|
||||
|
@ -24,7 +24,7 @@ private:
|
||||
CStr m_Tag;
|
||||
|
||||
// The property sheet used by this texture
|
||||
CTerrainProperties *m_pProperties;
|
||||
CTerrainPropertiesPtr m_pProperties;
|
||||
|
||||
// Path to the texture file
|
||||
CStr m_TexturePath;
|
||||
@ -52,13 +52,13 @@ private:
|
||||
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(CTerrainProperties *props, CStr path);
|
||||
CTextureEntry(CTerrainPropertiesPtr props, CStr path);
|
||||
~CTextureEntry();
|
||||
|
||||
CStr GetTag() const
|
||||
{ return m_Tag; }
|
||||
|
||||
CTerrainProperties *GetProperties() const
|
||||
CTerrainPropertiesPtr GetProperties() const
|
||||
{ return m_pProperties; }
|
||||
|
||||
CStr GetTexturePath() const
|
||||
|
@ -63,12 +63,12 @@ CTextureEntry* CTextureManager::FindTexture(Handle handle)
|
||||
return CTextureEntry::GetByHandle(handle);
|
||||
}
|
||||
|
||||
CTerrainProperties *CTextureManager::GetPropertiesFromFile(CTerrainProperties *props, const char* path)
|
||||
CTerrainPropertiesPtr CTextureManager::GetPropertiesFromFile(CTerrainPropertiesPtr props, const char* path)
|
||||
{
|
||||
return CTerrainProperties::FromXML(props, path);
|
||||
}
|
||||
|
||||
CTextureEntry *CTextureManager::AddTexture(CTerrainProperties *props, CStr path)
|
||||
CTextureEntry *CTextureManager::AddTexture(CTerrainPropertiesPtr props, CStr path)
|
||||
{
|
||||
CTextureEntry *entry = new CTextureEntry(props, path);
|
||||
m_TextureEntries.push_back(entry);
|
||||
@ -91,7 +91,7 @@ void CTextureManager::DeleteTexture(CTextureEntry* entry)
|
||||
// jw: indeed this is inefficient and RecurseDirectory should be implemented
|
||||
// via VFSUtil::EnumFiles, but it works fine and "only" takes 25ms for
|
||||
// typical maps. therefore, we'll leave it for now.
|
||||
void CTextureManager::LoadTextures(CTerrainProperties *props, const char* dir)
|
||||
void CTextureManager::LoadTextures(CTerrainPropertiesPtr props, const char* dir)
|
||||
{
|
||||
VFSUtil::FileList files;
|
||||
if(!VFSUtil::FindFiles(dir, 0, files))
|
||||
@ -111,17 +111,20 @@ void CTextureManager::LoadTextures(CTerrainProperties *props, const char* dir)
|
||||
const char* ext = strrchr(texture_name, '.');
|
||||
if(!ext || !stricmp(ext, ".xml") || !stricmp(ext, ".xmb") || !stricmp(ext, ".dtd"))
|
||||
continue;
|
||||
// Also allow storage of temporary files in the texture directories
|
||||
if(ext[strlen(ext)-1] == '~')
|
||||
continue;
|
||||
|
||||
// build name of associated xml file (i.e. replace extension)
|
||||
char xml_name[PATH_MAX+5]; // add room for .XML
|
||||
strcpy_s(xml_name, PATH_MAX, texture_name);
|
||||
strcpy(xml_name + (ext-texture_name), ".xml"); // safe
|
||||
|
||||
CTerrainProperties *myprops = NULL;
|
||||
CTerrainPropertiesPtr myprops;
|
||||
// Has XML file -> attempt to load properties
|
||||
if (vfs_exists(xml_name))
|
||||
{
|
||||
myprops=GetPropertiesFromFile(props, xml_name);
|
||||
myprops = GetPropertiesFromFile(props, xml_name);
|
||||
if (myprops)
|
||||
LOG(NORMAL, LOG_CATEGORY, "CTextureManager: Successfully loaded override xml %s for texture %s\n", xml_name, texture_name);
|
||||
}
|
||||
@ -134,17 +137,17 @@ void CTextureManager::LoadTextures(CTerrainProperties *props, const char* dir)
|
||||
}
|
||||
}
|
||||
|
||||
void CTextureManager::RecurseDirectory(CTerrainProperties *parentProps, const char* cur_dir_path)
|
||||
void CTextureManager::RecurseDirectory(CTerrainPropertiesPtr parentProps, const char* cur_dir_path)
|
||||
{
|
||||
//LOG(NORMAL, LOG_CATEGORY, "CTextureManager::RecurseDirectory(%s)", path.c_str());
|
||||
|
||||
CTerrainProperties *props=NULL;
|
||||
CTerrainPropertiesPtr props;
|
||||
|
||||
// Load terrains.xml first, if it exists
|
||||
char fn[PATH_MAX];
|
||||
snprintf(fn, PATH_MAX, "%s/%s", cur_dir_path, "terrains.xml");
|
||||
if (vfs_exists(fn))
|
||||
props=GetPropertiesFromFile(parentProps, fn);
|
||||
props = GetPropertiesFromFile(parentProps, fn);
|
||||
|
||||
// No terrains.xml, or read failures -> use parent props (i.e.
|
||||
if (!props)
|
||||
@ -168,7 +171,7 @@ void CTextureManager::RecurseDirectory(CTerrainProperties *parentProps, const ch
|
||||
|
||||
int CTextureManager::LoadTerrainTextures()
|
||||
{
|
||||
RecurseDirectory(NULL, "art/textures/terrain/types");
|
||||
RecurseDirectory(CTerrainPropertiesPtr(), "art/textures/terrain/types");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "boost/shared_ptr.hpp"
|
||||
|
||||
#include "lib/res/handle.h"
|
||||
|
||||
@ -17,6 +18,8 @@ class CXeromyces;
|
||||
class CTextureEntry;
|
||||
class CTerrainProperties;
|
||||
|
||||
typedef boost::shared_ptr<CTerrainProperties> CTerrainPropertiesPtr;
|
||||
|
||||
class CTerrainGroup
|
||||
{
|
||||
// name of this terrain group (as specified by the terrain XML)
|
||||
@ -65,12 +68,12 @@ private:
|
||||
|
||||
// Find+load all textures in directory; check if
|
||||
// there's an override XML with the same basename (if there is, load it)
|
||||
void LoadTextures(CTerrainProperties *props, const char* dir);
|
||||
void LoadTextures(CTerrainPropertiesPtr props, const char* dir);
|
||||
|
||||
// Load all terrains below path, using props as the parent property sheet.
|
||||
void RecurseDirectory(CTerrainProperties *props, const char* dir);
|
||||
void RecurseDirectory(CTerrainPropertiesPtr props, const char* dir);
|
||||
|
||||
CTerrainProperties *GetPropertiesFromFile(CTerrainProperties *props, const char* path);
|
||||
CTerrainPropertiesPtr GetPropertiesFromFile(CTerrainPropertiesPtr props, const char* path);
|
||||
|
||||
public:
|
||||
// constructor, destructor
|
||||
@ -87,7 +90,7 @@ public:
|
||||
|
||||
// Create a texture object for a new terrain texture at path, using the
|
||||
// property sheet props.
|
||||
CTextureEntry *AddTexture(CTerrainProperties *props, CStr path);
|
||||
CTextureEntry *AddTexture(CTerrainPropertiesPtr props, CStr path);
|
||||
|
||||
// Remove the texture from all our maps and lists and delete it afterwards.
|
||||
void DeleteTexture(CTextureEntry* entry);
|
||||
|
@ -101,6 +101,12 @@ CRenderer::CRenderer()
|
||||
m_Models.PlayerHWLit = new HWLightingModelRenderer;
|
||||
m_Models.TransparentHWLit = new HWLightingModelRenderer;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Models.NormalHWLit = NULL;
|
||||
m_Models.PlayerHWLit = NULL;
|
||||
m_Models.TransparentHWLit = NULL;
|
||||
}
|
||||
m_Models.Transparency = new TransparencyRenderer;
|
||||
|
||||
m_Models.ModWireframe = RenderModifierPtr(new WireframeRenderModifier);
|
||||
|
@ -15,6 +15,8 @@ template<typename T, typename I> void delete_erase(T list, I first, I last)
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T> void delete_fn(T* v) { delete v; }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
using namespace AtlasMessage;
|
||||
@ -43,7 +45,8 @@ CommandProc::CommandProc()
|
||||
|
||||
CommandProc::~CommandProc()
|
||||
{
|
||||
delete_erase(m_Commands, m_Commands.begin(), m_Commands.end());
|
||||
for_each(m_Commands.begin(), m_Commands.end(), delete_fn<Command>);
|
||||
m_Commands.clear();
|
||||
}
|
||||
|
||||
void CommandProc::Submit(Command* cmd)
|
||||
|
Loading…
Reference in New Issue
Block a user