mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-02-03 18:14:01 +00:00
Add precacher for mods
This commit is contained in:
parent
f7740eb6e8
commit
0611568d3e
5 changed files with 38 additions and 3 deletions
|
@ -2334,6 +2334,8 @@ void DSQ::playPositionalSfx(const std::string &name, const Vector &position, flo
|
||||||
|
|
||||||
void DSQ::shutdown()
|
void DSQ::shutdown()
|
||||||
{
|
{
|
||||||
|
mod.stop();
|
||||||
|
|
||||||
Network::shutdown();
|
Network::shutdown();
|
||||||
|
|
||||||
scriptInterface.shutdown();
|
scriptInterface.shutdown();
|
||||||
|
|
|
@ -257,6 +257,7 @@ class Mod
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Mod();
|
Mod();
|
||||||
|
~Mod();
|
||||||
void clear();
|
void clear();
|
||||||
void setActive(bool v);
|
void setActive(bool v);
|
||||||
void start();
|
void start();
|
||||||
|
@ -297,6 +298,7 @@ protected:
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string path;
|
std::string path;
|
||||||
|
Precacher modcache;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AquariaScreenTransition : public ScreenTransition
|
class AquariaScreenTransition : public ScreenTransition
|
||||||
|
|
|
@ -39,6 +39,11 @@ Mod::Mod()
|
||||||
shuttingDown = false;
|
shuttingDown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Mod::~Mod()
|
||||||
|
{
|
||||||
|
modcache.clean();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
queue for actual stop and recache
|
queue for actual stop and recache
|
||||||
which happens in game::applystate
|
which happens in game::applystate
|
||||||
|
@ -182,6 +187,23 @@ void Mod::recache()
|
||||||
|
|
||||||
core->resetTimer();
|
core->resetTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(active)
|
||||||
|
{
|
||||||
|
modcache.setBaseDir(dsq->secondaryTexturePath);
|
||||||
|
std::string fname = path;
|
||||||
|
if(fname[fname.length() - 1] != '/')
|
||||||
|
fname += '/';
|
||||||
|
fname += "precache.txt";
|
||||||
|
fname = localisePath(fname, dsq->mod.getPath());
|
||||||
|
fname = core->adjustFilenameCase(fname);
|
||||||
|
if (exists(fname))
|
||||||
|
modcache.precacheList(fname);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
modcache.clean();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mod::start()
|
void Mod::start()
|
||||||
|
|
|
@ -34,6 +34,11 @@ Precacher::~Precacher()
|
||||||
errorLog ("Precacher shutdown unclean");
|
errorLog ("Precacher shutdown unclean");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Precacher::setBaseDir(const std::string& dir)
|
||||||
|
{
|
||||||
|
basedirOverride = dir;
|
||||||
|
}
|
||||||
|
|
||||||
void Precacher::clean()
|
void Precacher::clean()
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < renderObjects.size(); i++)
|
for (unsigned int i = 0; i < renderObjects.size(); i++)
|
||||||
|
@ -88,6 +93,8 @@ void Precacher::precacheTex(const std::string &tex)
|
||||||
}
|
}
|
||||||
if (tex.empty()) return;
|
if (tex.empty()) return;
|
||||||
|
|
||||||
|
std::string basedir = basedirOverride.empty() ? core->getBaseTextureDirectory() : basedirOverride;
|
||||||
|
|
||||||
if (core->debugLogTextures)
|
if (core->debugLogTextures)
|
||||||
debugLog("PRECACHING: " + tex);
|
debugLog("PRECACHING: " + tex);
|
||||||
|
|
||||||
|
@ -99,7 +106,7 @@ void Precacher::precacheTex(const std::string &tex)
|
||||||
int loc = tex.find('*');
|
int loc = tex.find('*');
|
||||||
std::string path = tex.substr(0, loc);
|
std::string path = tex.substr(0, loc);
|
||||||
std::string type = tex.substr(loc+1, tex.size());
|
std::string type = tex.substr(loc+1, tex.size());
|
||||||
path = core->getBaseTextureDirectory() + path;
|
path = basedir + path;
|
||||||
forEachFile(path, type, precacherCallback, (intptr_t)this);
|
forEachFile(path, type, precacherCallback, (intptr_t)this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -108,9 +115,9 @@ void Precacher::precacheTex(const std::string &tex)
|
||||||
if (loadProgressCallback)
|
if (loadProgressCallback)
|
||||||
loadProgressCallback();
|
loadProgressCallback();
|
||||||
std::string t = tex;
|
std::string t = tex;
|
||||||
if (tex.find(core->getBaseTextureDirectory()) != std::string::npos)
|
if (tex.find(basedir) != std::string::npos)
|
||||||
{
|
{
|
||||||
t = tex.substr(core->getBaseTextureDirectory().size(), tex.size());
|
t = tex.substr(basedir.size(), tex.size());
|
||||||
}
|
}
|
||||||
Quad *q = new Quad;
|
Quad *q = new Quad;
|
||||||
q->setTexture(t);
|
q->setTexture(t);
|
||||||
|
|
|
@ -32,11 +32,13 @@ public:
|
||||||
void precacheList(const std::string &list, void progressCallback() = NULL);
|
void precacheList(const std::string &list, void progressCallback() = NULL);
|
||||||
void clean();
|
void clean();
|
||||||
void loadTextureRange(const std::string &file, const std::string &type, int start, int end);
|
void loadTextureRange(const std::string &file, const std::string &type, int start, int end);
|
||||||
|
void setBaseDir(const std::string& dir);
|
||||||
|
|
||||||
std::vector<RenderObject*> renderObjects;
|
std::vector<RenderObject*> renderObjects;
|
||||||
private:
|
private:
|
||||||
bool cleaned;
|
bool cleaned;
|
||||||
void (*loadProgressCallback)();
|
void (*loadProgressCallback)();
|
||||||
|
std::string basedirOverride;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue