]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/models/all.qh
Registry: overflow check
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / models / all.qh
1 #ifndef MODELS_ALL_H
2 #define MODELS_ALL_H
3
4 #define setmodel(e, m) _setmodel((e), (m).model_str())
5
6 REGISTRY(Models, BIT(9))
7 REGISTER_REGISTRY(RegisterModels)
8
9 CLASS(Model, Object)
10     ATTRIB(Model, m_id, int, 0)
11     ATTRIB(Model, model_str, string(), func_null)
12     CONSTRUCTOR(Model, string() path)
13     {
14         CONSTRUCT(Model);
15         this.model_str = path;
16     }
17     METHOD(Model, model_precache, void(entity this)) {
18         string s = this.model_str();
19         if (s != "" && s != "null" && !fexists(s)) {
20             LOG_WARNINGF("Missing model: \"%s\"\n", s);
21             return;
22         }
23         LOG_TRACEF("precache_model(\"%s\")\n", s);
24         precache_model(s);
25     }
26 ENDCLASS(Model)
27
28 #define MODEL(name, path) \
29     string MDL_##name##_get() { return path; } \
30     REGISTER(RegisterModels, MDL, Models, name, m_id, NEW(Model, MDL_##name##_get))
31
32 STATIC_INIT(RegisterModels_precache) {
33     FOREACH(Models, true, LAMBDA({
34         it.model_precache(it);
35     }));
36 }
37
38 MODEL(Null, "null");
39 #include "all.inc"
40
41 #endif