]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/models/models.qh
Fix overkill superweapon waypoints
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / models / models.qh
1 #ifndef MODELS_H
2 #define MODELS_H
3
4 #define setmodel(e, m) _setmodel((e), (m).model_str())
5
6 void RegisterModels();
7 const int MAX_MODELS = 128;
8 entity MODELS[MAX_MODELS], MODELS_first, MODELS_last;
9 int MODELS_COUNT;
10
11 CLASS(Model, Object)
12     ATTRIB(Model, m_id, int, 0)
13     ATTRIB(Model, model_str, string(), func_null)
14     CONSTRUCTOR(Model, string() path)
15     {
16         CONSTRUCT(Model);
17         this.model_str = path;
18     }
19     METHOD(Model, model_precache, void(entity this)) {
20         string s = this.model_str();
21         int fh = fopen(s, FILE_READ);
22         if (fh >= 0) {
23             fclose(fh);
24         } else if (s && s != "" && s != "null") {
25             LOG_WARNINGF("Missing model: \"%s\"\n", s);
26             return;
27         }
28         LOG_TRACEF("precache_model(\"%s\")\n", s);
29         precache_model(s);
30     }
31 ENDCLASS(Model)
32
33 #define MODEL(name, path) \
34     string MDL_##name##_get() { return path; } \
35     REGISTER(RegisterModels, MDL, MODELS, MODELS_COUNT, name, m_id, NEW(Model, MDL_##name##_get))
36 REGISTER_REGISTRY(RegisterModels)
37
38 STATIC_INIT(RegisterModels_precache) {
39     FOREACH(MODELS, true, LAMBDA({
40         it.model_precache(it);
41     }));
42 }
43
44 MODEL(Null, "null");
45 #include "models.inc"
46
47 #endif