From: TimePath Date: Sun, 3 May 2015 21:54:22 +0000 (+1000) Subject: Tidy up OO helpers X-Git-Tag: xonotic-v0.8.1~61^2~10 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2d5aa7ee7767f1efe503f0e1da6d4e7d88355b0a;p=xonotic%2Fxonotic-data.pk3dir.git Tidy up OO helpers --- diff --git a/qcsrc/menu/anim/animation.qc b/qcsrc/menu/anim/animation.qc index 411896ade..d327dded9 100644 --- a/qcsrc/menu/anim/animation.qc +++ b/qcsrc/menu/anim/animation.qc @@ -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 diff --git a/qcsrc/menu/anim/easing.qc b/qcsrc/menu/anim/easing.qc index 9856c2385..fa643390f 100644 --- a/qcsrc/menu/anim/easing.qc +++ b/qcsrc/menu/anim/easing.qc @@ -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 diff --git a/qcsrc/menu/oo/base.qh b/qcsrc/menu/oo/base.qh index 30423850e..a8337501b 100644 --- a/qcsrc/menu/oo/base.qh +++ b/qcsrc/menu/oo/base.qh @@ -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 diff --git a/qcsrc/menu/oo/implementation.qc b/qcsrc/menu/oo/implementation.qc index 78cba1ddb..3850db445 100644 --- a/qcsrc/menu/oo/implementation.qc +++ b/qcsrc/menu/oo/implementation.qc @@ -15,14 +15,11 @@ #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" diff --git a/qcsrc/menu/oo/interface.qc b/qcsrc/menu/oo/interface.qc index 5062045f5..d78a6a556 100644 --- a/qcsrc/menu/oo/interface.qc +++ b/qcsrc/menu/oo/interface.qc @@ -15,11 +15,37 @@ #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" diff --git a/qcsrc/menu/xonotic/dialog_firstrun.qc b/qcsrc/menu/xonotic/dialog_firstrun.qc index 444478e73..894a702d8 100644 --- a/qcsrc/menu/xonotic/dialog_firstrun.qc +++ b/qcsrc/menu/xonotic/dialog_firstrun.qc @@ -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")) diff --git a/qcsrc/menu/xonotic/listbox.qc b/qcsrc/menu/xonotic/listbox.qc index d3897f572..010b0d231 100644 --- a/qcsrc/menu/xonotic/listbox.qc +++ b/qcsrc/menu/xonotic/listbox.qc @@ -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) diff --git a/qcsrc/menu/xonotic/playerlist.qc b/qcsrc/menu/xonotic/playerlist.qc index 3c0481471..437206b88 100644 --- a/qcsrc/menu/xonotic/playerlist.qc +++ b/qcsrc/menu/xonotic/playerlist.qc @@ -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)) diff --git a/qcsrc/menu/xonotic/rootdialog.qc b/qcsrc/menu/xonotic/rootdialog.qc index 954cb7304..24d106344 100644 --- a/qcsrc/menu/xonotic/rootdialog.qc +++ b/qcsrc/menu/xonotic/rootdialog.qc @@ -1,4 +1,5 @@ -#ifdef INTERFACE +#ifndef ROOTDIALOG_H +#define ROOTDIALOG_H CLASS(XonoticRootDialog, XonoticDialog) // still to be customized by user /* diff --git a/qcsrc/menu/xonotic/slider_resolution.qc b/qcsrc/menu/xonotic/slider_resolution.qc index b15e13096..3d1f8302f 100644 --- a/qcsrc/menu/xonotic/slider_resolution.qc +++ b/qcsrc/menu/xonotic/slider_resolution.qc @@ -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)) diff --git a/qcsrc/menu/xonotic/textslider.qc b/qcsrc/menu/xonotic/textslider.qc index 131f35be1..7759e203b 100644 --- a/qcsrc/menu/xonotic/textslider.qc +++ b/qcsrc/menu/xonotic/textslider.qc @@ -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))