.o hAk o.

Hi folks !

I need to compute some stuff for an own kind of LUA scripting... so my question is, how do I get a "pointer" to some var so that I can first assing two different "variable pointers" to two vars and then do some calculation on them - passing the result of var1+var2 to var1...... all that in c#

My script should work like assembler::

> add v1, 0.1f
> out rot.x, v1

So this one should (obviously) add 0.1 to a temp var and then output the result to a object property called ROTation.X ...

The script should do::

set tempVar1 to zero (simple)
add 0.1 to reference to var #1
set rotation.x to var1's value

I hope someone does understand my words...

regards


Re: Visual C# Language Referenced objects or data types

Figo Fei - MSFT

Hi,

Can you give a specific example for us to discuss Since I didnt catch what your exact meaning, thank you






Re: Visual C# Language Referenced objects or data types

.o hAk o.

That's al little bit complicated, since I do not know the syntax ... so I will try to describe a little bit more...


Let's say I have an object with the property Vector3 position. The user can pass a little script in the form mentioned above. In the first step (add v1, 0.1f) v1 should receive a value of 0.1 - so this is obvious. Because the first and second parameter of the command can refer to a couple of variables (or better properties) of the object (the position, orientation, scale, ...). I would have to write a huge amount of source to cover all posible combinations of input var, output var and the command.itself.
I would be more efficient, if I could store a pointer to the real first parameter (so here to a local tempVar) and the second one (here userData) and then do the "add" command like (float)refToVar1 += (float)refToUserData. So I would only have to write two/three switch..case blocks to manage all posible combinations... The next step (
out rot.x, v1) could be performed like (float)refToPostion.X = (float)refToVar1.

I hope this helps a little bit.





Re: Visual C# Language Referenced objects or data types

.o hAk o.

Sorry for that push, but here the source of my solution so far... perhaps it will help to explain the problem a little bit better. The contained TMovementScriptVars is simply an enumaration. All posible values are found in the switch..case block.

TScriptParameter is defined as

    public struct TScriptParameter
    {
        public TMovementScriptParams useAs;
        public object RefVar;

        public TScriptParameter(TMovementScriptParams useAs, object refVar)
        {
            this.useAs = useAs;
            RefVar = refVar;
        }
    }/// <summary>


and holds *tada* the params passed from the calling object - since it's neither neccessary nor possible to pass all parameters all the time. Here the function to calc the stuff:


public static void doProcScriptEntry_old( List<TMovementScriptEntry> aScript, ref List<TScriptParameter> aParams )
{
if (aScript == null)
return;

float tempVar1, tempVar2, tempVar3, tempVar4;
float userDataFrac;
Vector3 Position, Rotation, Scale, LookAt;

tempVar1 = 0;
tempVar2 = 0;
tempVar3 = 0;
tempVar4 = 0;
Position = new Vector3(0,0,0);
Rotation = new Vector3(0, 0, 0);
LookAt = new Vector3(0, 0, 0);
Scale = new Vector3(0, 0, 0);

foreach (TScriptParameter lParam in aParams)
{
switch (lParam.useAs)
{
case TMovementScriptParams.LookAt: { LookAt = (Vector3)lParam.RefVar; break; }
case TMovementScriptParams.Position: { Position = (Vector3)lParam.RefVar; break; }
case TMovementScriptParams.Rotation: { Rotation = (Vector3)lParam.RefVar; break; }
case TMovementScriptParams.Scale: { Scale = (Vector3)lParam.RefVar; break; }
}
}

foreach (TMovementScriptEntry lEntry in aScript)
{
userDataFrac = lEntry.userData * Wrapper_Direct3D.RenderStats.lastFrameTime;

// Representations of the vars used - since pointers are not supported :.(
float lVar1 = 0;
float lVar2 = 0;

#region Get lVar1
switch (lEntry.Op1)
{
case TMovementScriptVars.Temp1: { lVar1 = tempVar1; break; }
case TMovementScriptVars.Temp2: { lVar1 = tempVar2; break; }
case TMovementScriptVars.Temp3: { lVar1 = tempVar3; break; }
case TMovementScriptVars.Temp4: { lVar1 = tempVar4; break; }
case TMovementScriptVars.PositionX: { lVar1 = Position.X; break; }
case TMovementScriptVars.PositionY: { lVar1 = Position.Y; break; }
case TMovementScriptVars.PositionZ: { lVar1 = Position.Z; break; }
case TMovementScriptVars.RotationX: { lVar1 = Rotation.X; break; }
case TMovementScriptVars.RotationY: { lVar1 = Rotation.Y; break; }
case TMovementScriptVars.RotationZ: { lVar1 = Rotation.Z; break; }
case TMovementScriptVars.ScaleX: { lVar1 = Scale.X; break; }
case TMovementScriptVars.ScaleY: { lVar1 = Scale.Y; break; }
case TMovementScriptVars.ScaleZ: { lVar1 = Scale.Z; break; }
case TMovementScriptVars.LookAtX: { lVar1 = LookAt.X; break; }
case TMovementScriptVars.LookAtY: { lVar1 = LookAt.Y; break; }
case TMovementScriptVars.LookAtZ: { lVar1 = LookAt.Z; break; }
}
#endregion
#region Get lVar2
switch (lEntry.Op2)
{
case TMovementScriptVars.Temp1: { lVar2 = tempVar1; break; }
case TMovementScriptVars.Temp2: { lVar2 = tempVar2; break; }
case TMovementScriptVars.Temp3: { lVar2 = tempVar3; break; }
case TMovementScriptVars.Temp4: { lVar2 = tempVar4; break; }
case TMovementScriptVars.PositionX: { lVar2 = Position.X; break; }
case TMovementScriptVars.PositionY: { lVar2 = Position.Y; break; }
case TMovementScriptVars.PositionZ: { lVar2 = Position.Z; break; }
case TMovementScriptVars.RotationX: { lVar2 = Rotation.X; break; }
case TMovementScriptVars.RotationY: { lVar2 = Rotation.Y; break; }
case TMovementScriptVars.RotationZ: { lVar2 = Rotation.Z; break; }
case TMovementScriptVars.ScaleX: { lVar2 = Scale.X; break; }
case TMovementScriptVars.ScaleY: { lVar2 = Scale.Y; break; }
case TMovementScriptVars.ScaleZ: { lVar2 = Scale.Z; break; }
case TMovementScriptVars.UserData: { lVar2 = lEntry.userData; break; } //userDataFrac
case TMovementScriptVars.UserDataFrac: { lVar2 = userDataFrac; break; } //userDataFrac
case TMovementScriptVars.LookAtX: { lVar2 = LookAt.X; break; }
case TMovementScriptVars.LookAtY: { lVar2 = LookAt.Y; break; }
case TMovementScriptVars.LookAtZ: { lVar2 = LookAt.Z; break; }
case TMovementScriptVars.lastFrameTime: { lVar2 = Wrapper_Direct3D.RenderStats.lastFrameTime; break; }
case TMovementScriptVars.overallTime: { lVar2 = Wrapper_Direct3D.RenderStats.overallTime; break; }
}
#endregion
#region Perform operation
switch (lEntry.Operation)
{
case TMovementScriptOperation.Add: { lVar1 += lVar2; break; }
case TMovementScriptOperation.Sub: { lVar1 -= lVar2; break; }
case TMovementScriptOperation.Mul: { lVar1 *= lVar2; break; }
case TMovementScriptOperation.Div: { lVar1 /= lVar2; break; }
case TMovementScriptOperation.Set: { lVar1 = lVar2; break; }

case TMovementScriptOperation.Sin: { lVar1 = (float)Math.Sin(StaticHelpers.DegToRad(lVar2)); break; }
case TMovementScriptOperation.Cos: { lVar1 = (float)Math.Cos(StaticHelpers.DegToRad(lVar2)); break; }
}
#endregion
#region Set operation target to lVar1
switch (lEntry.Op1)
{
case TMovementScriptVars.Temp1: { tempVar1 = lVar1; break; }
case TMovementScriptVars.Temp2: { tempVar2 = lVar1; break; }
case TMovementScriptVars.Temp3: { tempVar3 = lVar1; break; }
case TMovementScriptVars.Temp4: { tempVar4 = lVar1; break; }
case TMovementScriptVars.PositionX: { Position.X = lVar1; break; }
case TMovementScriptVars.PositionY: { Position.Y = lVar1; break; }
case TMovementScriptVars.PositionZ: { Position.Z = lVar1; break; }
case TMovementScriptVars.RotationX: { Rotation.X = lVar1; break; }
case TMovementScriptVars.RotationY: { Rotation.Y = lVar1; break; }
case TMovementScriptVars.RotationZ: { Rotation.Z = lVar1; break; }
case TMovementScriptVars.ScaleX: { Scale.X = lVar1; break; }
case TMovementScriptVars.ScaleY: { Scale.Y = lVar1; break; }
case TMovementScriptVars.ScaleZ: { Scale.Z = lVar1; break; }
case TMovementScriptVars.LookAtX: { LookAt.X = lVar1; break; }
case TMovementScriptVars.LookAtY: { LookAt.Y = lVar1; break; }
case TMovementScriptVars.LookAtZ: { LookAt.Z = lVar1; break; }
}
#endregion
}
TScriptParameter Param;
for (int i = 0; i < aParams.Count; i++)
{
Param = aParamsIdea;
switch (Param.useAs)
{
case TMovementScriptParams.LookAt: { Param.RefVar = (object)LookAt; break; }
case TMovementScriptParams.Position: { Param.RefVar = (object)Position; break; }
case TMovementScriptParams.Rotation: { Param.RefVar = (object)Rotation; break; }
case TMovementScriptParams.Scale: { Param.RefVar = (object)Scale; break; }
}
aParamsIdea = Param;
}
}