]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
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 411896adece981af003d40a613338fb76fa4dfd9..d327dded9adc81772719bd41a8fc98bcd0486fb2 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 9856c2385fa830c1b171a7a2b3ef966eb4658cbd..fa643390f3592646d58885dd69bbcc2b1833ba62 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 30423850e807a4bdd64909ecf2bc50ecb28bc7eb..a8337501be68c5d77b007bc6da7e2441aa87b377 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 78cba1ddb5abf407cc45e847cf33d0536ced7018..3850db4453a33a37c51df13bfd4d302245e7fe60 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 5062045f5950f452ec32c4094d1a20db9f4b8c61..d78a6a556ee19c8e54b59fefcdf8c292aafa5881 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 444478e7301d834ccf5ffbdb8fbfd4c7070af75d..894a702d8a026a155c1c05a1d4553003c474ec6a 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 d3897f5724e7da369208c95df2ff5f5f8fc4ece1..010b0d231ffa037fcea09cc35269812edaadd336 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 3c0481471185f1b3a9e3a8fab15da6e48ad5e929..437206b881352bbd59cff5caade6eade963125a8 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 954cb73046fe9d7fbc0fbd5a4086929bf5efc030..24d10634448582942a4cf4f8fff11db9532128e2 100644 (file)
@@ -1,4 +1,5 @@
-#ifdef INTERFACE
+#ifndef ROOTDIALOG_H
+#define ROOTDIALOG_H
 CLASS(XonoticRootDialog, XonoticDialog)
        // still to be customized by user
        /*
index b15e13096ac109141f8d6aa526e1adaf3431efb4..3d1f8302f18695c902d61d3ae93987ea6dadd680 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 131f35be1ca1e88c3b59e0ef7114855404bbc43b..7759e203b2f2a67d1a86915d51a9fbe0f6c03ed2 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))