Tidy up OO helpers
authorTimePath <andrew.hardaker1995@gmail.com>
Sun, 3 May 2015 21:54:22 +0000 (07:54 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sun, 3 May 2015 21:54:22 +0000 (07:54 +1000)
qcsrc/menu/anim/animation.qc
qcsrc/menu/anim/easing.qc
qcsrc/menu/oo/base.qh
qcsrc/menu/oo/implementation.qc
qcsrc/menu/oo/interface.qc
qcsrc/menu/xonotic/dialog_firstrun.qc
qcsrc/menu/xonotic/listbox.qc
qcsrc/menu/xonotic/playerlist.qc
qcsrc/menu/xonotic/rootdialog.qc
qcsrc/menu/xonotic/slider_resolution.qc
qcsrc/menu/xonotic/textslider.qc

index 411896a..d327dde 100644 (file)
@@ -1,4 +1,5 @@
 #ifdef INTERFACE
+void setterDummy(entity, float);
 CLASS(Animation, Object)
        METHOD(Animation, configureAnimation, void(entity, entity, void(entity, float), float, float, float, float))
        METHOD(Animation, setTimeStartEnd, void(entity, float, float))
@@ -23,7 +24,6 @@ CLASS(Animation, Object)
        ATTRIB(Animation, stopped, float, false)
        ATTRIB(Animation, finished, float, false)
 ENDCLASS(Animation)
-void setterDummy(entity, float);
 #endif
 
 #ifdef IMPLEMENTATION
index 9856c23..fa64339 100644 (file)
@@ -1,15 +1,15 @@
 #ifdef INTERFACE
-CLASS(Easing, Animation)
-       METHOD(Easing, calcValue, float(entity, float, float, float, float))
-       METHOD(Easing, setMath, void(entity, float(float, float, float, float)))
-       ATTRIB(Easing, math, float(float, float, float, float), easingLinear)
-ENDCLASS(Easing)
 entity makeHostedEasing(entity, void(entity, float), float(float, float, float, float), float, float, float);
 entity makeEasing(entity, void(entity, float), float(float, float, float, float), float, float, float, float);
 float easingLinear(float, float, float, float);
 float easingQuadIn(float, float, float, float);
 float easingQuadOut(float, float, float, float);
 float easingQuadInOut(float, float, float, float);
+CLASS(Easing, Animation)
+       METHOD(Easing, calcValue, float(entity, float, float, float, float))
+       METHOD(Easing, setMath, void(entity, float(float, float, float, float)))
+       ATTRIB(Easing, math, float(float, float, float, float), easingLinear)
+ENDCLASS(Easing)
 #endif
 
 #ifdef IMPLEMENTATION
index 3042385..a833750 100644 (file)
@@ -2,33 +2,27 @@
 #define BASE_H
 
 .string classname;
-entity Object_vtbl;
 .string vtblname;
 .entity vtblbase;
-// THIS LINE INTENTIONALLY LEFT BLANK
-entity spawnVtbl(entity e, entity b)
+entity spawnVtbl(entity this, entity base)
 {
-       entity v;
-       v = spawn();
-       copyentity(e, v);
-       v.vtblname = v.classname;
-       v.classname = "vtbl";
-       if(b)
-               v.vtblbase = b;
-       else
-               v.vtblbase = v;
-       return v;
+       entity vtbl = spawn();
+       copyentity(this, vtbl);
+       vtbl.vtblname = vtbl.classname;
+       vtbl.classname = "vtbl";
+       vtbl.vtblbase = base ? base : vtbl; // Top level objects use vtbl as base
+       return vtbl;
 }
-entity spawnObject()
+
+entity Object_vtbl;
+entity spawnObject(entity this, entity)
 {
-       entity e;
-       e = spawn();
-       e.classname = "Object";
-       if(!Object_vtbl)
-               Object_vtbl = spawnVtbl(e, null_entity);
-       return e;
+       this = spawn();
+       this.classname = "Object";
+       if (!Object_vtbl) Object_vtbl = spawnVtbl(this, null_entity);
+       return this;
 }
 
-#define NEW(cname) (spawn##cname())
+#define NEW(cname) (spawn##cname(null_entity, null_entity))
 
 #endif
index 78cba1d..3850db4 100644 (file)
 #undef SUPER
 #endif
 
-// for the constructor
-#define CLASS(cname,base)                  entity spawn##cname() { entity me = spawn##base (); entity basevtbl; basevtbl = base##_vtbl;
-#define METHOD(cname,name,prototype)       me.name = cname##_##name;
-#define ATTRIB(cname,name,type,val)        me.name = val;
-#define ATTRIBARRAY(cname,name,type,cnt)
-#define ENDCLASS(cname)                    me.instanceOf##cname = 1; me.classname = #cname; if(!cname##_vtbl) cname##_vtbl = spawnVtbl(me, basevtbl); return me; }
-
-// for the implementation
+#define CLASS(cname, base)
+#define METHOD(cname, name, prototype)
+#define ATTRIB(cname, name, type, val)
+#define ATTRIBARRAY(cname, name, type, cnt)
+#define ENDCLASS(cname)
 #define SUPER(cname) (cname##_vtbl.vtblbase)
 
 #include "../classes.inc"
index 5062045..d78a6a5 100644 (file)
 #undef SUPER
 #endif
 
-#define CLASS(cname,base)                  entity spawn##cname(); entity cname##_vtbl;
-#define METHOD(cname,name,prototype)       prototype cname##_##name; .prototype name;
-#define ATTRIB(cname,name,type,val)        .type name;
-#define ATTRIBARRAY(cname,name,type,cnt)   .type name[cnt];
-#define ENDCLASS(cname)                    .float instanceOf##cname;
+#define CLASS(cname, base)                                          \
+[[accumulate]] entity spawn##cname(entity this, entity basevtbl) {  \
+    this = NEW(base); basevtbl = base##_vtbl;                       \
+}
+
+#define METHOD(cname, name, prototype)                              \
+prototype cname##_##name;                                           \
+.prototype name;                                                    \
+[[accumulate]] entity spawn##cname(entity this, entity basevtbl) {  \
+    this.name = cname##_##name;                                     \
+}
+
+#define ATTRIB(cname, name, type, val)                              \
+.type name;                                                         \
+[[accumulate]] entity spawn##cname(entity this, entity basevtbl) {  \
+    this.name = val;                                                \
+}
+
+#define ATTRIBARRAY(cname, name, type, cnt)                         \
+.type name[cnt];
+
+#define ENDCLASS(cname)                                             \
+.bool instanceOf##cname;                                            \
+entity cname##_vtbl;                                                \
+[[accumulate]] entity spawn##cname(entity this, entity basevtbl) {  \
+    this.instanceOf##cname = true;                                  \
+    this.classname = #cname;                                        \
+    if (!cname##_vtbl) cname##_vtbl = spawnVtbl(this, basevtbl);    \
+    return this;                                                    \
+}
+
 #define SUPER(cname)
 
 #include "../classes.inc"
index 444478e..894a702 100644 (file)
@@ -1,4 +1,6 @@
-#ifdef INTERFACE
+#ifndef DIALOG_FIRSTRUN_H
+#define DIALOG_FIRSTRUN_H
+#include "rootdialog.qc"
 CLASS(XonoticFirstRunDialog, XonoticRootDialog)
        METHOD(XonoticFirstRunDialog, fill, void(entity)) // to be overridden by user to fill the dialog with controls
        ATTRIB(XonoticFirstRunDialog, title, string, _("Welcome"))
index d3897f5..010b0d2 100644 (file)
@@ -1,4 +1,5 @@
-#ifdef INTERFACE
+#ifndef LISTBOX_H
+#define LISTBOX_H
 CLASS(XonoticListBox, ListBox)
        METHOD(XonoticListBox, configureXonoticListBox, void(entity))
        ATTRIB(XonoticListBox, fontSize, float, SKINFONTSIZE_NORMAL)
index 3c04814..437206b 100644 (file)
@@ -1,4 +1,6 @@
-#ifdef INTERFACE
+#ifndef PLAYERLIST_H
+#define PLAYERLIST_H
+#include "listbox.qc"
 CLASS(XonoticPlayerList, XonoticListBox)
        ATTRIB(XonoticPlayerList, rowsPerItem, float, 1)
        METHOD(XonoticPlayerList, resizeNotify, void(entity, vector, vector, vector, vector))
index 954cb73..24d1063 100644 (file)
@@ -1,4 +1,5 @@
-#ifdef INTERFACE
+#ifndef ROOTDIALOG_H
+#define ROOTDIALOG_H
 CLASS(XonoticRootDialog, XonoticDialog)
        // still to be customized by user
        /*
index b15e130..3d1f830 100644 (file)
@@ -1,4 +1,6 @@
-#ifdef INTERFACE
+#ifndef SLIDER_RESOLUTION_H
+#define SLIDER_RESOLUTION_H
+#include "textslider.qc"
 CLASS(XonoticResolutionSlider, XonoticTextSlider)
        METHOD(XonoticResolutionSlider, configureXonoticResolutionSlider, void(entity))
        METHOD(XonoticResolutionSlider, loadResolutions, void(entity, float))
index 131f35b..7759e20 100644 (file)
@@ -1,4 +1,5 @@
-#ifdef INTERFACE
+#ifndef TEXTSLIDER_H
+#define TEXTSLIDER_H
 CLASS(XonoticTextSlider, TextSlider)
        METHOD(XonoticTextSlider, configureXonoticTextSlider, void(entity, string))
        METHOD(XonoticTextSlider, setValue, void(entity, float))