Ancurio / mkxp

Free Software implementation of the Ruby Game Scripting System (RGSS)
GNU General Public License v2.0
509 stars 128 forks source link

Expect retrieved value to be the same as assigned value #235

Open khiav223577 opened 3 years ago

khiav223577 commented 3 years ago

Example:

sprite = Sprite.new
sprite.zoom_x = 0.9
p sprite.zoom_x

In original RPG Maker XP engine, it prints 0.9 But it prints 0.8999999761581421 in mkxp (OSX binary)

cremno commented 3 years ago

mkxp uses the single-precision floating-point format for this and similar attributes while RGSS uses double-precision.

However even if it would be changed to double-precision you would still be able to find differences in very few cases. 1.8.1 is ancient and the code to convert between floating-point numbers and strings contained some bugs.

khiav223577 commented 3 years ago

Maybe a wrapper class is one possible solution?

  1. Rename the Sprite class implemented by mkxp as MkxpSprite
  2. Define new Sprite class that inherits from MkxpSprite
  3. Override zoom_x and zoom_x= method.

    class Sprite < MkxpSprite
    attr_reader :zoom_x
    
    def zoom_x=(val)
    @zoom_x = val
    super
    end
    end

It will be nice if mkxp can implement it. Make mkxp behave more consistent with original engine.


The following is a surprising behavior I found in current implementation:

# let (xxxxx / yyyyy.to_f) to be 0.9
sprite.zoom_x = xxxxx / yyyyy.to_f 

# ...
# ...

# sprite.zoom_x is 0.8999 here and fail to enter the if-condition since 0.8999 is not larger than or equals to 0.9
if sprite.zoom_x >= 0.9 
  #  ...
  #  ...
end
Ancurio commented 2 years ago

I am curious what exact in-game issues this inaccuracy is causing.