From b6241ea5578ca9cb7346678e31108d5eafde5b0d Mon Sep 17 00:00:00 2001 From: Webster Sheets Date: Tue, 12 Mar 2024 18:44:19 -0400 Subject: [PATCH 1/2] Fix incorrect spaceport locations - Existing spaceports were defined in Lua with negative inclination/longitude, but constrained to only positive on load --- src/galaxy/CustomSystem.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/galaxy/CustomSystem.cpp b/src/galaxy/CustomSystem.cpp index f86937a055d..09ba003ad26 100644 --- a/src/galaxy/CustomSystem.cpp +++ b/src/galaxy/CustomSystem.cpp @@ -138,7 +138,6 @@ CSB_FIELD_SETTER_FIXED(mass, bodyData.m_mass) CSB_FIELD_SETTER_INT(temp, bodyData.m_averageTemp) CSB_FIELD_SETTER_FIXED(semi_major_axis, bodyData.m_semiMajorAxis) CSB_FIELD_SETTER_FIXED(eccentricity, bodyData.m_eccentricity) -CSB_FIELD_SETTER_FIXED(inclination, bodyData.m_inclination) CSB_FIELD_SETTER_FIXED(rotation_period, bodyData.m_rotationPeriod) CSB_FIELD_SETTER_FIXED(axial_tilt, bodyData.m_axialTilt) CSB_FIELD_SETTER_FIXED(metallicity, bodyData.m_metallicity) @@ -185,6 +184,17 @@ static int l_csb_orbital_offset(lua_State *L) return 1; } +static int l_csb_inclination(lua_State *L) +{ + CustomSystemBody *csb = l_csb_check(L, 1); + double *value = getDoubleOrFixed(L, 2); + if (value == nullptr) + return luaL_error(L, "Bad datatype. Expected fixed or float, got %s", luaL_typename(L, 2)); + csb->bodyData.m_inclination = fixed::FromDouble(*value); + lua_settop(L, 1); + return 1; +} + static int l_csb_orbital_phase_at_start(lua_State *L) { CustomSystemBody *csb = l_csb_check(L, 1); From db80b33ba73a8e9e48c7491cc9fb5f53b89e6b77 Mon Sep 17 00:00:00 2001 From: Webster Sheets Date: Tue, 12 Mar 2024 18:52:06 -0400 Subject: [PATCH 2/2] Fix loading fixed-point from JSON on Windows - std::strtol returns a 32-bit signed integer on Windows but 64-bit on Linux - Use 64-bit version to ensure we can load the entire fractional bit range --- src/JsonUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/JsonUtils.cpp b/src/JsonUtils.cpp index 866681e70be..3bbe4a2d8ed 100644 --- a/src/JsonUtils.cpp +++ b/src/JsonUtils.cpp @@ -560,13 +560,13 @@ void from_json(const Json &obj, fixed &f) throw Json::type_error::create(320, "cannot pickle string to fixed point number"); char *next_str = const_cast(str.c_str()) + 1; - int64_t integer = std::strtol(next_str, &next_str, 10); + int64_t integer = std::strtoll(next_str, &next_str, 10); // handle cases: f/34, f1356, f14+4 if (next_str == nullptr || size_t(next_str - str.c_str()) >= str.size() || *next_str++ != '/') throw Json::type_error::create(320, "cannot pickle string to fixed point number"); - int64_t fractional = std::strtol(next_str, &next_str, 10); + int64_t fractional = std::strtoll(next_str, &next_str, 10); // handle cases f1345/7684gfrty; fixed numbers should not have any garbage data involved if (next_str != str.c_str() + str.size()) throw Json::type_error::create(320, "cannot pickle string to fixed point number");