diff options
author | rubenwardy <rw@rubenwardy.com> | 2017-12-22 10:00:57 +0000 |
---|---|---|
committer | SmallJoker <mk939@ymail.com> | 2018-06-03 17:32:00 +0200 |
commit | df0a8574dcef24e5a12a366cb10f7ac5d69a8b79 (patch) | |
tree | a9c22c93f6f208ce2d43c667454ce7f8709932ac /src/script | |
parent | 669806725637a7e97ae884b7983da6e19fcaa6f5 (diff) | |
download | minetest-df0a8574dcef24e5a12a366cb10f7ac5d69a8b79.tar.gz minetest-df0a8574dcef24e5a12a366cb10f7ac5d69a8b79.tar.bz2 minetest-df0a8574dcef24e5a12a366cb10f7ac5d69a8b79.zip |
Fix rounding error in g/set_node caused by truncation to float
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/common/c_converter.cpp | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index fc516d56a..d9b926e3e 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -196,6 +196,44 @@ v3f check_v3f(lua_State *L, int index) return pos; } +v3d read_v3d(lua_State *L, int index) +{ + v3d pos; + CHECK_POS_TAB(index); + lua_getfield(L, index, "x"); + pos.X = lua_tonumber(L, -1); + lua_pop(L, 1); + lua_getfield(L, index, "y"); + pos.Y = lua_tonumber(L, -1); + lua_pop(L, 1); + lua_getfield(L, index, "z"); + pos.Z = lua_tonumber(L, -1); + lua_pop(L, 1); + return pos; +} + +v3d check_v3d(lua_State *L, int index) +{ + v3d pos; + CHECK_POS_TAB(index); + lua_getfield(L, index, "x"); + CHECK_POS_COORD("x"); + pos.X = lua_tonumber(L, -1); + CHECK_FLOAT_RANGE(pos.X, "x") + lua_pop(L, 1); + lua_getfield(L, index, "y"); + CHECK_POS_COORD("y"); + pos.Y = lua_tonumber(L, -1); + CHECK_FLOAT_RANGE(pos.Y, "y") + lua_pop(L, 1); + lua_getfield(L, index, "z"); + CHECK_POS_COORD("z"); + pos.Z = lua_tonumber(L, -1); + CHECK_FLOAT_RANGE(pos.Z, "z") + lua_pop(L, 1); + return pos; +} + void push_ARGB8(lua_State *L, video::SColor color) { lua_newtable(L); @@ -234,15 +272,15 @@ void push_v3s16(lua_State *L, v3s16 p) v3s16 read_v3s16(lua_State *L, int index) { // Correct rounding at <0 - v3f pf = read_v3f(L, index); - return floatToInt(pf, 1.0); + v3d pf = read_v3d(L, index); + return doubleToInt(pf, 1.0); } v3s16 check_v3s16(lua_State *L, int index) { // Correct rounding at <0 - v3f pf = check_v3f(L, index); - return floatToInt(pf, 1.0); + v3d pf = check_v3d(L, index); + return doubleToInt(pf, 1.0); } bool read_color(lua_State *L, int index, video::SColor *color) |