Skip to content
Permalink
Browse files
Fixed a small inaccuracy of moving layers
Here is required to replicate the same number rounding behavior as that works in VB6.
  • Loading branch information
Wohlstand committed Jun 10, 2020
1 parent 6e8de24 commit a5e016b63fadaf6f2828cea321af7ef8722844af
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
@@ -553,3 +553,64 @@ void initAll()
NPC.fill(NPC_t());
}


const double power10[] =
{
1.0,
10.0,
100.0,
1000.0,
10000.0,

100000.0,
1000000.0,
10000000.0,
100000000.0,
1000000000.0,

10000000000.0,
100000000000.0,
1000000000000.0,
10000000000000.0,
100000000000000.0,

1000000000000000.0,
10000000000000000.0,
100000000000000000.0,
1000000000000000000.0,
10000000000000000000.0,

100000000000000000000.0,
1000000000000000000000.0
};

int vb6Round(double x)
{
return static_cast<int>(vb6Round(x, 0));
}

double vb6Round(double x, int decimals)
{
double res;
if(decimals < 0 || decimals > 22)
decimals = 0;

res = x;

if(SDL_fabs(x) < 1.0e16)
{
double v4 = power10[decimals];
double st = x * v4;

int intpart = static_cast<int>(SDL_floor(st));
int iseven = intpart % 2;
if(iseven)
st += 0.00000001;
else
st -= 0.00000001;
st = std::round(st);
res = st / v4;
}

return res;
}
@@ -106,6 +106,20 @@ const char *getKeyName(int key);
struct KM_Key;
std::string getJoyKeyName(const KM_Key &key);

/**
* @brief Rounding function that works same as in VB6
* @param x Floating point value to round
* @return rounded result
*/
extern int vb6Round(double x);

/**
* @brief Rounding function that works same as in VB6
* @param x Floating point value to round
* @param decimals Round to a specific number of decimals
* @return rounded result
*/
extern double vb6Round(double x, int decimals);

//'Saved Events
//Public numSavedEvents As Integer
@@ -555,7 +555,7 @@ void ProcEvent(std::string EventName, bool NoEffect)
tempBool = false;
if(!Events[A].TriggerEvent.empty())
{
if(int(Events[A].TriggerDelay) == 0)
if(std::round(Events[A].TriggerDelay) == 0.0)
{
for(B = 0; B <= maxEvents; B++)
{
@@ -566,16 +566,15 @@ void ProcEvent(std::string EventName, bool NoEffect)
break;
}
}
if(tempBool == false)
{

if(!tempBool)
ProcEvent(Events[A].TriggerEvent);
}
}
else
{
newEventNum++;
NewEvent[newEventNum] = Events[A].TriggerEvent;
newEventDelay[newEventNum] = Events[A].TriggerDelay * 6.5;
newEventDelay[newEventNum] = vb6Round(Events[A].TriggerDelay * 6.5);
}
}
}

0 comments on commit a5e016b

Please sign in to comment.