1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2025-10-04 05:13:19 +00:00

Fixes to prev commit - restore ttvfs functionality when reading XML files, and minor other things

This commit is contained in:
fgenesis 2014-06-09 23:39:33 +02:00
commit 065def0674
9 changed files with 73 additions and 24 deletions

View file

@ -538,6 +538,29 @@ char *readFile(const std::string& path, unsigned long *size_ret)
return buffer;
}
tinyxml2::XMLError readXML(const std::string& fn, tinyxml2::XMLDocument& doc)
{
unsigned long sz = 0;
char *buf = readFile(fn, &sz);
tinyxml2::XMLError err = doc.Parse(buf, sz);
delete [] buf;
return err;
}
tinyxml2::XMLDocument *readXML(const std::string& fn, tinyxml2::XMLError *perr /* = 0 */)
{
tinyxml2::XMLDocument *doc = new tinyxml2::XMLDocument();
tinyxml2::XMLError err = readXML(fn, *doc);
if(perr)
*perr = err;
if(err != tinyxml2::XML_SUCCESS)
{
delete doc;
doc = NULL;
}
return doc;
}
/*
void pForEachFile(std::string path, std::string type, void callback(const std::string &filename, int param), int param)
{

View file

@ -143,6 +143,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "math.h"
#include "ttvfs_stdio.h"
#include "tinyxml2.h"
#ifdef BBGE_BUILD_LINUX
# include <sys/types.h>
# include <stdint.h>
@ -204,6 +206,8 @@ bool exists(const std::string &f, bool makeFatal = false, bool skipVFS = false);
void errorLog(const std::string &s);
void debugLog(const std::string &s);
char *readFile(const std::string& path, unsigned long *size_ret = 0);
tinyxml2::XMLDocument *readXML(const std::string& fn, tinyxml2::XMLError *perr = 0);
tinyxml2::XMLError readXML(const std::string& fn, tinyxml2::XMLDocument& doc);
char *readCompressedFile(std::string path, unsigned long *size_ret = 0);
void forEachFile(std::string path, std::string type, void callback(const std::string &filename, intptr_t param), intptr_t param);
std::string stripEndlineForUnix(const std::string &in);

View file

@ -36,20 +36,19 @@ static std::map<std::string, XMLDocument*> skelCache;
static XMLDocument *_retrieveSkeletalXML(const std::string& name)
{
XMLDocument *doc = skelCache[name];
if (!doc) {
doc = new XMLDocument();
doc->LoadFile(name.c_str());
std::map<std::string, XMLDocument*>::iterator it = skelCache.find(name);
if(it != skelCache.end())
return it->second;
XMLDocument *doc = readXML(name);
if(doc)
skelCache[name] = doc;
}
return doc;
}
void SkeletalSprite::clearCache()
{
for (std::map<std::string, XMLDocument*>::iterator i = skelCache.begin(); i != skelCache.end(); i++)
delete i->second;
skelCache.clear();
}
@ -1316,16 +1315,21 @@ void SkeletalSprite::loadSkeletal(const std::string &fn)
if (!exists(file))
{
filenameLoaded = "";
errorLog("Could not load skeletal[" + file + "]");
errorLog("Could not load skeletal[" + file + "] - File not found.");
return;
}
file = core->adjustFilenameCase(file);
loaded = true;
XMLDocument *xml = _retrieveSkeletalXML(file);
xml->LoadFile(file.c_str());
if(!xml)
{
filenameLoaded = "";
errorLog("Could not load skeletal[" + file + "] - Malformed XML.");
return;
}
loaded = true;
XMLElement *bones = xml->FirstChildElement("Bones");
if (bones)