]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/defer.qh
Merge branch 'master' into Lyberta/StandaloneOverkillWeapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / defer.qh
index 2a13611168fd806382b42b069897591d6582b1f0..4f34bb4853ade7f0149274ebdb3c325d4468147a 100644 (file)
@@ -1,46 +1,38 @@
-#ifndef MENUQC
-#ifndef DEFER_H
-#define DEFER_H
-#include "oo.qh"
+#pragma once
 
-entityclass(Defer);
-class(Defer) .entity owner;
-class(Defer) .void() think;
-class(Defer) .float nextthink;
+#ifdef GAMEQC
 
-/*
-==================
-SUB_Remove
+       #include "oo.qh"
+       #include "self.qh"
 
-Remove self
-==================
-*/
-void SUB_Remove()
-{SELFPARAM();
-       remove (self);
-}
+       entityclass(Defer);
+       class(Defer).entity owner;
+       class(Defer).void(entity) defer_func;
 
-void defer_think()
-{SELFPARAM();
-    self.think     = SUB_Remove;
-    self.nextthink = time;
-    WITH(entity, self, self.owner, self.use());
-}
+       /** Remove entity */
+       void SUB_Remove(entity this)
+       {
+               delete(this);
+       }
 
-/*
-    Execute func() after time + fdelay.
-    self when func is executed = self when defer is called
-*/
-void defer(float fdelay, void() func)
-{SELFPARAM();
-    entity e;
+       void defer_think(entity this)
+       {
+               setthink(this, SUB_Remove);
+               this.nextthink = time;
+               this.defer_func(this.owner);
+       }
 
-    e           = spawn();
-    e.owner     = self;
-    e.use       = func;
-    e.think     = defer_think;
-    e.nextthink = time + fdelay;
-}
+    /**
+     * Execute func() after time + fdelay.
+     * self when func is executed = self when defer is called
+     */
+       void defer(entity this, float fdelay, void(entity) func)
+       {
+               entity e    = new_pure(deferred);
+               e.owner     = this;
+               e.defer_func = func;
+               setthink(e, defer_think);
+               e.nextthink = time + fdelay;
+       }
 
 #endif
-#endif