mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-29 07:12:36 +00:00
- 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:
parent
c1a578ba08
commit
e8d1416d81
7 changed files with 1333 additions and 1221 deletions
|
@ -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.
|
||||
|
|
|
@ -209,6 +209,7 @@ enum
|
|||
TK_Abs,
|
||||
TK_Random,
|
||||
TK_Random2,
|
||||
TK_FRandom,
|
||||
|
||||
TK_LastToken
|
||||
};
|
||||
|
|
2467
src/sc_man_scanner.h
2467
src/sc_man_scanner.h
File diff suppressed because it is too large
Load diff
|
@ -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); }
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue