Mercurial > projects > mde
diff mde/Options.d @ 36:57d000574d75
Enabled drawing on demand, and made the polling interval configurable.
Renamed mde.global to mde.imde.
Enabled drawing on demand.
Allowed options to take double values.
Made the main loop's polling interval (sleep duration) settable from config files.
committer: Diggory Hardy <diggory.hardy@gmail.com>
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Fri, 02 May 2008 17:38:43 +0100 |
parents | 316b0230a849 |
children | 1530d9c04d4d |
line wrap: on
line diff
--- a/mde/Options.d Fri May 02 16:20:35 2008 +0100 +++ b/mde/Options.d Fri May 02 17:38:43 2008 +0100 @@ -59,8 +59,9 @@ // The "pointer lists": protected bool* [ID] optsBool; + protected int* [ID] optsInt; + protected double*[ID] optsDouble; protected char[]*[ID] optsCharA; - protected int* [ID] optsInt; //BEGIN Mergetag loading/saving code void addTag (char[] tp, ID id, char[] dt) { @@ -70,14 +71,19 @@ } else if (tp == "char[]") { char[]** p = id in optsCharA; if (p !is null) **p = parseTo!(char[]) (dt); + } else if (tp == "double") { + double** p = id in optsDouble; + if (p !is null) **p = parseTo!(double) (dt); } else if (tp == "int") { int** p = id in optsInt; if (p !is null) **p = parseTo!(int) (dt); } } + void writeAll (ItemDelg dlg) { foreach (ID id, bool* val; optsBool) dlg ("bool" , id, parseFrom!(bool ) (*val)); foreach (ID id, char[]* val; optsCharA) dlg ("char[]", id, parseFrom!(char[]) (*val)); + foreach (ID id, double* val; optsDouble)dlg ("double", id, parseFrom!(double) (*val)); foreach (ID id, int* val; optsInt) dlg ("int" , id, parseFrom!(int ) (*val)); } //END Mergetag loading/saving code @@ -123,6 +129,17 @@ logger.error (ERR_MSG); } } + static void setDouble (char[] subClass, char[] symbol, double val) { + changed = true; // something got set (don't bother checking this isn't what it already was) + + try { + *(subClasses[cast(ID) subClass].optsDouble[cast(ID) symbol]) = val; + subClassChanges[cast(ID) subClass].setDouble (cast(ID) symbol, val); + } catch (ArrayBoundsException) { + // log and ignore: + logger.error (ERR_MSG); + } + } static void setCharA (char[] subClass, char[] symbol, char[] val) { changed = true; // something got set (don't bother checking this isn't what it already was) @@ -217,12 +234,15 @@ template decBool(A...) { const char[] decBool = "bool " ~ decRecurse!(A) ~ ";\n"; } + template decInt(A...) { + const char[] decInt = "int " ~ decRecurse!(A) ~ ";\n"; + } + template decDouble(A...) { + const char[] decDouble = "double " ~ decRecurse!(A) ~ ";\n"; + } template decCharA(A...) { const char[] decCharA = "char[] " ~ decRecurse!(A) ~ ";\n"; } - template decInt(A...) { - const char[] decInt = "int " ~ decRecurse!(A) ~ ";\n"; - } template aaRecurse(char[] A, B...) { static if (B.length) const char[] aaRecurse = "\""~A~"\"[]:&"~A ~ ", " ~ aaRecurse!(B); else const char[] aaRecurse = "\""~A~"\"[]:&"~A; @@ -233,6 +253,9 @@ template aaInt(A...) { const char[] aaInt = "optsInt = [" ~ aaRecurse!(A) ~ "];\n"; } + template aaDouble(A...) { + const char[] aaDouble = "optsDouble = [" ~ aaRecurse!(A) ~ "];\n"; + } template aaCharA(A...) { const char[] aaCharA = "optsCharA = [" ~ aaRecurse!(A) ~ "];\n"; } @@ -245,6 +268,7 @@ // optsX store pointers to each item added along with the ID and are used for access. bool[] bools; int[] ints; + double[] doubles; char[][] strings; this () {} @@ -265,6 +289,14 @@ optsInt[id] = &ints[$-1]; } } + void setDouble (ID id, double x) { + double** p = id in optsDouble; + if (p !is null) **p = x; + else { + doubles ~= x; + optsDouble[id] = &doubles[$-1]; + } + } void setCharA (ID id, char[] x) { char[]** p = id in optsCharA; if (p !is null) **p = x; @@ -311,15 +343,18 @@ class OptionsMisc : Options { alias store!("useThreads") BOOL; alias store!("logLevel") INT; + alias store!("pollInterval") DOUBLE; alias store!("L10n") CHARA; mixin (decBool!(BOOL.a)); mixin (decInt!(INT.a)); + mixin (decDouble!(DOUBLE.a)); mixin (decCharA!(CHARA.a)); this () { mixin (aaBool!(BOOL.a)); mixin (aaInt!(INT.a)); + mixin (aaDouble!(DOUBLE.a)); mixin (aaCharA!(CHARA.a)); }