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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
#pragma once
#include "StarRootBase.hpp"
#include "StarJson.hpp"
#include "StarLogging.hpp"
#include "StarListener.hpp"
#include "StarConfiguration.hpp"
namespace Star {
STAR_CLASS(ItemDatabase);
STAR_CLASS(MaterialDatabase);
STAR_CLASS(ObjectDatabase);
STAR_CLASS(PlantDatabase);
STAR_CLASS(ProjectileDatabase);
STAR_CLASS(MonsterDatabase);
STAR_CLASS(NpcDatabase);
STAR_CLASS(StagehandDatabase);
STAR_CLASS(VehicleDatabase);
STAR_CLASS(PlayerFactory);
STAR_CLASS(EntityFactory);
STAR_CLASS(TerrainDatabase);
STAR_CLASS(BiomeDatabase);
STAR_CLASS(LiquidsDatabase);
STAR_CLASS(StatusEffectDatabase);
STAR_CLASS(DamageDatabase);
STAR_CLASS(ParticleDatabase);
STAR_CLASS(EffectSourceDatabase);
STAR_CLASS(FunctionDatabase);
STAR_CLASS(TreasureDatabase);
STAR_CLASS(DungeonDefinitions);
STAR_CLASS(TilesetDatabase);
STAR_CLASS(StatisticsDatabase);
STAR_CLASS(EmoteProcessor);
STAR_CLASS(SpeciesDatabase);
STAR_CLASS(ImageMetadataDatabase);
STAR_CLASS(VersioningDatabase);
STAR_CLASS(QuestTemplateDatabase);
STAR_CLASS(AiDatabase);
STAR_CLASS(TechDatabase);
STAR_CLASS(CodexDatabase);
STAR_CLASS(BehaviorDatabase);
STAR_CLASS(TenantDatabase);
STAR_CLASS(PatternedNameGenerator);
STAR_CLASS(DanceDatabase);
STAR_CLASS(SpawnTypeDatabase);
STAR_CLASS(RadioMessageDatabase);
STAR_CLASS(CollectionDatabase);
STAR_CLASS(Root);
// Singleton Root object for starbound providing access to the unique
// Configuration class, as well as the assets, root factories, and databases.
// Root, and all members of Root, should be thread safe. Root initialization
// should be completed before any code dependent on Root is started in any
// thread, and all Root dependent code in any thread should be finished before
// letting Root destruct.
class Root : public RootBase {
public:
struct Settings {
Assets::Settings assetsSettings;
// Asset sources are scanned for in the given directories, in order.
StringList assetDirectories;
// Just raw asset source paths.
StringList assetSources;
Json defaultConfiguration;
// Top-level storage directory under which all game data is saved
String storageDirectory;
// Directory to store logs - if not set, uses storage directory and keeps old logs in seperate folder
Maybe<String> logDirectory;
// Name of the log file that should be written, if any, relative to the
// log directory
Maybe<String> logFile;
// Number of rotated log file backups
unsigned logFileBackups;
// The minimum log level to write to any log sink
LogLevel logLevel;
// If true, doesn't write any logging to stdout, only to the log file if
// given.
bool quiet;
// If given, will write changed configuration to the given file within the
// storage directory.
Maybe<String> runtimeConfigFile;
};
// Get pointer to the singleton root instance, if it exists. Otherwise,
// returns nullptr.
static Root* singletonPtr();
// Gets reference to root singleton, throws RootException if root is not
// initialized.
static Root& singleton();
// Initializes the starbound root object and does the initial load. All of
// the Root members will be just in time loaded as they are accessed, unless
// fullyLoad is called beforehand.
Root(Settings settings);
Root(Root const&) = delete;
Root& operator=(Root const&) = delete;
~Root();
// Clears existing Root members, allowing them to be loaded fresh from disk.
void reload();
// Reloads with the given mod sources applied on top of the base mod source
// specified in the settings. Mods in the base mod source will override mods
// in the given mod sources
void reloadWithMods(StringList modDirectories);
// Ensures all Root members are loaded without waiting for them to be auto
// loaded.
void fullyLoad();
// Add a listener that will be called on Root reload. Automatically managed,
// if the listener is destroyed then it will automatically be removed from
// the internal listener list.
void registerReloadListener(ListenerWeakPtr reloadListener);
// Translates the given path to be relative to the configured storage
// location.
String toStoragePath(String const& path) const;
// All of the Root member accessors are safe to call at any time after Root
// initialization, if they are not loaded they will load before returning.
AssetsConstPtr assets() override;
ConfigurationPtr configuration() override;
ObjectDatabaseConstPtr objectDatabase();
PlantDatabaseConstPtr plantDatabase();
ProjectileDatabaseConstPtr projectileDatabase();
MonsterDatabaseConstPtr monsterDatabase();
NpcDatabaseConstPtr npcDatabase();
StagehandDatabaseConstPtr stagehandDatabase();
VehicleDatabaseConstPtr vehicleDatabase();
PlayerFactoryConstPtr playerFactory();
EntityFactoryConstPtr entityFactory();
PatternedNameGeneratorConstPtr nameGenerator();
ItemDatabaseConstPtr itemDatabase();
MaterialDatabaseConstPtr materialDatabase();
TerrainDatabaseConstPtr terrainDatabase();
BiomeDatabaseConstPtr biomeDatabase();
LiquidsDatabaseConstPtr liquidsDatabase();
StatusEffectDatabaseConstPtr statusEffectDatabase();
DamageDatabaseConstPtr damageDatabase();
ParticleDatabaseConstPtr particleDatabase();
EffectSourceDatabaseConstPtr effectSourceDatabase();
FunctionDatabaseConstPtr functionDatabase();
TreasureDatabaseConstPtr treasureDatabase();
DungeonDefinitionsConstPtr dungeonDefinitions();
TilesetDatabaseConstPtr tilesetDatabase();
StatisticsDatabaseConstPtr statisticsDatabase();
EmoteProcessorConstPtr emoteProcessor();
SpeciesDatabaseConstPtr speciesDatabase();
ImageMetadataDatabaseConstPtr imageMetadataDatabase();
VersioningDatabaseConstPtr versioningDatabase();
QuestTemplateDatabaseConstPtr questTemplateDatabase();
AiDatabaseConstPtr aiDatabase();
TechDatabaseConstPtr techDatabase();
CodexDatabaseConstPtr codexDatabase();
BehaviorDatabaseConstPtr behaviorDatabase();
TenantDatabaseConstPtr tenantDatabase();
DanceDatabaseConstPtr danceDatabase();
SpawnTypeDatabaseConstPtr spawnTypeDatabase();
RadioMessageDatabaseConstPtr radioMessageDatabase();
CollectionDatabaseConstPtr collectionDatabase();
private:
static StringList scanForAssetSources(StringList const& directories, StringList const& manual = {});
template <typename T, typename... Params>
static shared_ptr<T> loadMember(shared_ptr<T>& ptr, Mutex& mutex, char const* name, Params&&... params);
template <typename T>
static shared_ptr<T> loadMemberFunction(shared_ptr<T>& ptr, Mutex& mutex, char const* name, function<shared_ptr<T>()> loadFunction);
// m_configurationMutex must be held when calling
void writeConfig();
Settings m_settings;
Mutex m_modsMutex;
StringList m_modDirectories;
ListenerGroup m_reloadListeners;
Json m_lastRuntimeConfig;
Maybe<String> m_runtimeConfigFile;
ThreadFunction<void> m_maintenanceThread;
Mutex m_maintenanceStopMutex;
ConditionVariable m_maintenanceStopCondition;
bool m_stopMaintenanceThread;
AssetsPtr m_assets;
Mutex m_assetsMutex;
ConfigurationPtr m_configuration;
Mutex m_configurationMutex;
ObjectDatabasePtr m_objectDatabase;
Mutex m_objectDatabaseMutex;
PlantDatabasePtr m_plantDatabase;
Mutex m_plantDatabaseMutex;
ProjectileDatabasePtr m_projectileDatabase;
Mutex m_projectileDatabaseMutex;
MonsterDatabasePtr m_monsterDatabase;
Mutex m_monsterDatabaseMutex;
NpcDatabasePtr m_npcDatabase;
Mutex m_npcDatabaseMutex;
StagehandDatabasePtr m_stagehandDatabase;
Mutex m_stagehandDatabaseMutex;
VehicleDatabasePtr m_vehicleDatabase;
Mutex m_vehicleDatabaseMutex;
PlayerFactoryPtr m_playerFactory;
Mutex m_playerFactoryMutex;
EntityFactoryPtr m_entityFactory;
Mutex m_entityFactoryMutex;
PatternedNameGeneratorPtr m_nameGenerator;
Mutex m_nameGeneratorMutex;
ItemDatabasePtr m_itemDatabase;
Mutex m_itemDatabaseMutex;
MaterialDatabasePtr m_materialDatabase;
Mutex m_materialDatabaseMutex;
TerrainDatabasePtr m_terrainDatabase;
Mutex m_terrainDatabaseMutex;
BiomeDatabasePtr m_biomeDatabase;
Mutex m_biomeDatabaseMutex;
LiquidsDatabasePtr m_liquidsDatabase;
Mutex m_liquidsDatabaseMutex;
StatusEffectDatabasePtr m_statusEffectDatabase;
Mutex m_statusEffectDatabaseMutex;
DamageDatabasePtr m_damageDatabase;
Mutex m_damageDatabaseMutex;
ParticleDatabasePtr m_particleDatabase;
Mutex m_particleDatabaseMutex;
EffectSourceDatabasePtr m_effectSourceDatabase;
Mutex m_effectSourceDatabaseMutex;
FunctionDatabasePtr m_functionDatabase;
Mutex m_functionDatabaseMutex;
TreasureDatabasePtr m_treasureDatabase;
Mutex m_treasureDatabaseMutex;
DungeonDefinitionsPtr m_dungeonDefinitions;
Mutex m_dungeonDefinitionsMutex;
TilesetDatabasePtr m_tilesetDatabase;
Mutex m_tilesetDatabaseMutex;
StatisticsDatabasePtr m_statisticsDatabase;
Mutex m_statisticsDatabaseMutex;
EmoteProcessorPtr m_emoteProcessor;
Mutex m_emoteProcessorMutex;
SpeciesDatabasePtr m_speciesDatabase;
Mutex m_speciesDatabaseMutex;
ImageMetadataDatabasePtr m_imageMetadataDatabase;
Mutex m_imageMetadataDatabaseMutex;
VersioningDatabasePtr m_versioningDatabase;
Mutex m_versioningDatabaseMutex;
QuestTemplateDatabasePtr m_questTemplateDatabase;
Mutex m_questTemplateDatabaseMutex;
AiDatabasePtr m_aiDatabase;
Mutex m_aiDatabaseMutex;
TechDatabasePtr m_techDatabase;
Mutex m_techDatabaseMutex;
CodexDatabasePtr m_codexDatabase;
Mutex m_codexDatabaseMutex;
BehaviorDatabasePtr m_behaviorDatabase;
Mutex m_behaviorDatabaseMutex;
TenantDatabasePtr m_tenantDatabase;
Mutex m_tenantDatabaseMutex;
DanceDatabasePtr m_danceDatabase;
Mutex m_danceDatabaseMutex;
SpawnTypeDatabasePtr m_spawnTypeDatabase;
Mutex m_spawnTypeDatabaseMutex;
RadioMessageDatabasePtr m_radioMessageDatabase;
Mutex m_radioMessageDatabaseMutex;
CollectionDatabasePtr m_collectionDatabase;
Mutex m_collectionDatabaseMutex;
};
}
|