- 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 1059 additions and 947 deletions
|
|
@ -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…
Add table
Add a link
Reference in a new issue