/
Doom3SkinCache.h
97 lines (74 loc) · 2.63 KB
/
Doom3SkinCache.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
#include "Doom3ModelSkin.h"
#include "imodule.h"
#include "modelskin.h"
#include "parser/DefTokeniser.h"
#include <map>
#include <string>
#include <vector>
#include "ThreadedDefLoader.h"
namespace skins
{
/**
* Implementation of ModelSkinCache interface for Doom 3 skin management.
*/
class Doom3SkinCache :
public ModelSkinCache
{
// Table of named skin objects
typedef std::map<std::string, ModelSkinPtr> NamedSkinMap;
NamedSkinMap _namedSkins;
// List of all skins
StringList _allSkins;
// Map between model paths and a vector of names of the associated skins,
// which are contained in the main NamedSkinMap.
typedef std::map<std::string, std::vector<std::string> > ModelSkinMap;
ModelSkinMap _modelSkins;
// Helper which will invoke loadSkinFiles() in a separate thread
util::ThreadedDefLoader<void> _defLoader;
// Empty Doom3ModelSkin to return if a named skin is not found
Doom3ModelSkin _nullSkin;
sigc::signal<void> _sigSkinsReloaded;
public:
/* Constructor.
*/
Doom3SkinCache();
/* Return a specific named skin. If the named skin cannot be found, return
* the empty (null) skin with no remaps.
*/
ModelSkin& capture(const std::string& name) override;
/* Get the vector of skin names corresponding to the given model.
*/
const StringList& getSkinsForModel(const std::string& model) override;
/* Return a complete list of skins.
*/
const StringList& getAllSkins() override;
void addNamedSkin(const ModelSkinPtr& modelSkin) override;
void removeSkin(const std::string& name) override;
/**
* greebo: Clears and reloads all skins.
*/
void refresh() override;
// Public events
sigc::signal<void> signal_skinsReloaded() override;
// RegisterableModule implementation
const std::string& getName() const override;
const StringSet& getDependencies() const override;
void initialiseModule(const IApplicationContext& ctx) override;
private:
// Load and parse the skin files, populating internal data structures.
// Function may be called more than once, will do nothing if already
// realised.
void ensureDefsLoaded();
// Iterates over each skin file in the VFS skins/ folder
void loadSkinFiles();
// Parse an individual skin declaration and add return the skin object
Doom3ModelSkinPtr parseSkin(parser::DefTokeniser& tokeniser);
/* Parse the provided istream as a .skin file, and add all skins found within
* to the internal data structures.
*
* @filename: This is for informational purposes only (error message display).
*/
void parseFile(std::istream& contents, const std::string& filename);
};
} // namespace skins