- Added the frandom decorate function, which is exactly like random except

that it works with floating point instead of integers.


SVN r1797 (trunk)
This commit is contained in:
Randy Heit 2009-09-06 02:16:55 +00:00
parent c1a578ba08
commit e8d1416d81
7 changed files with 1333 additions and 1221 deletions

View File

@ -1,4 +1,6 @@
September 5, 2009
- Added the frandom decorate function, which is exactly like random except
that it works with floating point instead of integers.
- Split the bounce types completely into separate flags and consolidated
the various bounce-related flags spread across the different Actor flags
field into a single BounceFlags field.

View File

@ -209,6 +209,7 @@ enum
TK_Abs,
TK_Random,
TK_Random2,
TK_FRandom,
TK_LastToken
};

File diff suppressed because it is too large Load Diff

View File

@ -147,6 +147,7 @@ std2:
'abs' { RET(TK_Abs); }
'random' { RET(TK_Random); }
'random2' { RET(TK_Random2); }
'frandom' { RET(TK_FRandom); }
L (L|D)* { RET(TK_Identifier); }

View File

@ -359,6 +359,29 @@ static FxExpression *ParseExpression0 (FScanner &sc, const PClass *cls)
return new FxRandom(rng, min, max, sc);
}
else if (sc.CheckToken(TK_FRandom))
{
FRandom *rng;
if (sc.CheckToken('['))
{
sc.MustGetToken(TK_Identifier);
rng = FRandom::StaticFindRNG(sc.String);
sc.MustGetToken(']');
}
else
{
rng = &pr_exrandom;
}
sc.MustGetToken('(');
FxExpression *min = ParseExpressionM (sc, cls);
sc.MustGetToken(',');
FxExpression *max = ParseExpressionM (sc, cls);
sc.MustGetToken(')');
return new FxFRandom(rng, min, max, sc);
}
else if (sc.CheckToken(TK_Random2))
{
FRandom *rng;

View File

@ -540,6 +540,7 @@ public:
class FxRandom : public FxExpression
{
protected:
FRandom * rng;
FxExpression *min, *max;
@ -552,7 +553,18 @@ public:
ExpVal EvalExpression (AActor *self);
};
//==========================================================================
//
//
//
//==========================================================================
class FxFRandom : public FxRandom
{
public:
FxFRandom(FRandom *, FxExpression *mi, FxExpression *ma, const FScriptPosition &pos);
ExpVal EvalExpression (AActor *self);
};
//==========================================================================
//

View File

@ -1661,7 +1661,6 @@ ExpVal FxRandom::EvalExpression (AActor *self)
int minval = min->EvalExpression (self).GetInt();
int maxval = max->EvalExpression (self).GetInt();
if (maxval < minval)
{
swap (maxval, minval);
@ -1676,6 +1675,53 @@ ExpVal FxRandom::EvalExpression (AActor *self)
return val;
}
//==========================================================================
//
//
//
//==========================================================================
FxFRandom::FxFRandom(FRandom *r, FxExpression *mi, FxExpression *ma, const FScriptPosition &pos)
: FxRandom(r, NULL, NULL, pos)
{
if (mi != NULL && ma != NULL)
{
min = mi;
max = ma;
}
}
//==========================================================================
//
//
//
//==========================================================================
ExpVal FxFRandom::EvalExpression (AActor *self)
{
ExpVal val;
val.Type = VAL_Float;
int random = (*rng)(0x40000000);
double frandom = random / double(0x40000000);
if (min != NULL && max != NULL)
{
double minval = min->EvalExpression (self).GetFloat();
double maxval = max->EvalExpression (self).GetFloat();
if (maxval < minval)
{
swap (maxval, minval);
}
val.Float = frandom * (maxval - minval) + minval;
}
else
{
val.Float = frandom;
}
return val;
}
//==========================================================================
//
//