BulletSim: small tweaks and formatting in the parameter fetching code.

user_profiles
Robert Adams 2013-03-23 11:03:59 -07:00
parent 953090fd62
commit c96a6f1de6
1 changed files with 16 additions and 5 deletions

View File

@ -203,10 +203,10 @@ public static class BSParam
public delegate void PSetOnObject<T>(BSScene scene, BSPhysObject obj); public delegate void PSetOnObject<T>(BSScene scene, BSPhysObject obj);
public sealed class ParameterDefn<T> : ParameterDefnBase public sealed class ParameterDefn<T> : ParameterDefnBase
{ {
T defaultValue; private T defaultValue;
PSetValue<T> setter; private PSetValue<T> setter;
PGetValue<T> getter; private PGetValue<T> getter;
PSetOnObject<T> objectSet; private PSetOnObject<T> objectSet;
public ParameterDefn(string pName, string pDesc, T pDefault, PGetValue<T> pGetter, PSetValue<T> pSetter) public ParameterDefn(string pName, string pDesc, T pDefault, PGetValue<T> pGetter, PSetValue<T> pSetter)
: base(pName, pDesc) : base(pName, pDesc)
{ {
@ -223,13 +223,23 @@ public static class BSParam
getter = pGetter; getter = pGetter;
objectSet = pObjSetter; objectSet = pObjSetter;
} }
/* Wish I could simplify using this definition but CLR doesn't store references so closure around delegates of references won't work
public ParameterDefn(string pName, string pDesc, T pDefault, ref T loc)
: base(pName, pDesc)
{
defaultValue = pDefault;
setter = (s, v) => { loc = v; };
getter = (s) => { return loc; };
objectSet = null;
}
*/
public override void AssignDefault(BSScene s) public override void AssignDefault(BSScene s)
{ {
setter(s, defaultValue); setter(s, defaultValue);
} }
public override string GetValue(BSScene s) public override string GetValue(BSScene s)
{ {
return String.Format("{0}", getter(s)); return getter(s).ToString();
} }
public override void SetValue(BSScene s, string valAsString) public override void SetValue(BSScene s, string valAsString)
{ {
@ -252,6 +262,7 @@ public static class BSParam
try try
{ {
T setValue = (T)parser.Invoke(genericType, new Object[] { valAsString }); T setValue = (T)parser.Invoke(genericType, new Object[] { valAsString });
// Store the parsed value
setter(s, setValue); setter(s, setValue);
// s.Logger.DebugFormat("{0} Parameter {1} = {2}", LogHeader, name, setValue); // s.Logger.DebugFormat("{0} Parameter {1} = {2}", LogHeader, name, setValue);
} }