]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/lazy.qh
Merge branch 'master' into Mario/bulldozer
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / lazy.qh
1 #ifndef LAZY_H
2 #define LAZY_H
3
4 #include "oo.qh"
5
6 CLASS(Lazy, Object)
7         ATTRIB(Lazy, m_get, entity(), func_null);
8         CONSTRUCTOR(Lazy, entity() _compute)
9         {
10                 this.m_get = _compute;
11         }
12 ENDCLASS(Lazy)
13
14 #define LAZY(id) __lazy_##id
15 #define LAZY_NEW(id, compute) \
16         entity LAZY(id)() { \
17                 static bool done; \
18                 static entity it; \
19                 if (!done) { it = compute; done = true; } \
20                 return it; \
21         }
22 #endif