/
MD5AnimationCache.cpp
70 lines (53 loc) · 1.43 KB
/
MD5AnimationCache.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "MD5AnimationCache.h"
#include "iarchive.h"
#include "ifilesystem.h"
#include "itextstream.h"
#include "parser/DefTokeniser.h"
namespace md5
{
IMD5AnimPtr MD5AnimationCache::getAnim(const std::string& vfsPath)
{
// Check the cache first
AnimationMap::iterator found = _animations.find(vfsPath);
if (found != _animations.end())
{
return found->second;
}
// Not found, construct new animation with the given path
ArchiveTextFilePtr file = GlobalFileSystem().openTextFile(vfsPath);
if (file == NULL)
{
rWarning() << "Animation file " << vfsPath << " does not exist." << std::endl;
return IMD5AnimPtr();
}
std::istream inputStream(&file->getInputStream());
// Create the anim from scratch
MD5AnimPtr anim(new MD5Anim);
anim->parseFromStream(inputStream);
// Store the anim in our cache
_animations.insert(AnimationMap::value_type(vfsPath, anim));
return anim;
}
const std::string& MD5AnimationCache::getName() const
{
static std::string _name(MODULE_ANIMATIONCACHE);
return _name;
}
const StringSet& MD5AnimationCache::getDependencies() const
{
static StringSet _dependencies;
if (_dependencies.empty())
{
_dependencies.insert(MODULE_VIRTUALFILESYSTEM);
}
return _dependencies;
}
void MD5AnimationCache::initialiseModule(const IApplicationContext& ctx)
{
rMessage() << getName() << "::initialiseModule called." << std::endl;
}
void MD5AnimationCache::shutdownModule()
{
_animations.clear();
}
} // namespace