]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/Lazy.qh
Expand /lib
[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) { this.m_get = _compute; }
9 ENDCLASS(Lazy)
10
11 #define LAZY(id) __lazy_##id
12 #define LAZY_NEW(id, compute) entity LAZY(id)() { \
13     static bool done; \
14     static entity it; \
15     if (!done) { it = compute; done = true; } \
16     return it; \
17 }
18 #endif