]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/lazy.qh
Prefer lowercase filenames
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / lazy.qh
diff --git a/qcsrc/lib/lazy.qh b/qcsrc/lib/lazy.qh
new file mode 100644 (file)
index 0000000..f632b38
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef LAZY_H
+#define LAZY_H
+
+#include "oo.qh"
+
+CLASS(Lazy, Object)
+    ATTRIB(Lazy, m_get, entity(), func_null);
+    CONSTRUCTOR(Lazy, entity() _compute) { this.m_get = _compute; }
+ENDCLASS(Lazy)
+
+#define LAZY(id) __lazy_##id
+#define LAZY_NEW(id, compute) entity LAZY(id)() { \
+    static bool done; \
+    static entity it; \
+    if (!done) { it = compute; done = true; } \
+    return it; \
+}
+#endif