file An interesting glitch and its fix

  • whirligig
  • whirligig's Avatar Topic Author
  • Offline
  • Professional Marbler
  • Professional Marbler
  • Posts: 444
  • Thank you received: 261
15 Jul 2014 18:13 #1
I wasn't sure if this should be in a coding subforum, so correct me if I was wrong.

As many of you know, MBG's timer freezes at 60:00.99. Oddly enough, however, this is *not* the correct value--the time stored in the game's engine is 3599999 milliseconds, or 59:59.99. The reason why this occurs is due to a floating-point bug. First, MBG calculates the hundredths of a second, which correctly return as 99. Then, the code divides by 1000 and rounds down to find the total number of seconds. This erroneously comes out as 3600. So the game thinks 3600.99 seconds have passed, while the actual value is 3599.99.

Strangely enough, the fault seems to lie in the division operator. When the game divides 3599999 by 1000, it somehow decides to round the answer up slightly, losing the precision. I checked in C, and single-precision floats don't do this -- maybe Jeff or someone who knows more about the workings of the engine can figure out why this happens.

In any case, the glitch could be fixed as follows if anyone wants to. Replace the following line of code in marble/client/playGui.cs:
Code:
%totalSeconds = mFloor(%et / 1000);
with:
Code:
%totalSeconds = mFloor((%et - %et % 1000) / 1000);
Although I haven't tested this directly, it should work according to console tests.

For the record, MBP's clock continues until 99:59.99 and displays it correctly (at least in 1.50 beta 3).
The following user(s) said Thank You: Jeff

Please Log in or Create an account to join the conversation.

  • Jeff
  • Jeff's Avatar
  • Offline
  • Elite Marbler
  • Elite Marbler
  • PlatinumQuest Programmer
  • Posts: 1680
  • Thank you received: 205
15 Jul 2014 18:33 #2
neat find, will have to look into this more. Will also show the Torque3D guys because maybe that division error still exists after 10 years later?

I am a programmer. Most here know me for being one of the major contributors to Marble Blast Platinum and PlatinumQuest.

Please Log in or Create an account to join the conversation.

  • StewMan46
  • StewMan46's Avatar
  • Offline
  • Professional Marbler
  • Professional Marbler
  • Posts: 369
  • Thank you received: 46
15 Jul 2014 20:01 #3
Applied to MBSuper. Thanks for the find!!

Please Log in or Create an account to join the conversation.

Moderators: Doomblah
Time to create page: 1.080 seconds
We use cookies

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.