From 2c6331f583a7669a0ab6a645ead9623f967b4d29 Mon Sep 17 00:00:00 2001 From: Sezz Date: Sat, 8 Feb 2025 02:58:03 +1100 Subject: [PATCH] Deprecate CalculateDistance() script function --- Documentation/doc/1 modules/Util.html | 36 ------------------- .../Scripting/Internal/ReservedScriptNames.h | 1 - .../Scripting/Internal/TEN/Util/Util.cpp | 30 +++++++--------- 3 files changed, 13 insertions(+), 54 deletions(-) diff --git a/Documentation/doc/1 modules/Util.html b/Documentation/doc/1 modules/Util.html index a10d262ec..53c70459f 100644 --- a/Documentation/doc/1 modules/Util.html +++ b/Documentation/doc/1 modules/Util.html @@ -121,10 +121,6 @@ Determine if there is a clear line of sight between two positions. - CalculateDistance(posA, posB) - Calculate the distance between two positions. - - CalculateHorizontalDistance(posA, posB) Calculate the horizontal distance between two positions. @@ -202,38 +198,6 @@ print(Misc.HasLineOfSight(enemyHead:GetRoomNumber(), enemyHead:GetPosition(), flamePlinthPos)) - -
- - CalculateDistance(posA, posB) -
-
- Calculate the distance between two positions. - - - -

Parameters:

- - -

Returns:

-
    - - float - Distance between two positions. -
- - - -
diff --git a/TombEngine/Scripting/Internal/ReservedScriptNames.h b/TombEngine/Scripting/Internal/ReservedScriptNames.h index e96f8e854..93493b887 100644 --- a/TombEngine/Scripting/Internal/ReservedScriptNames.h +++ b/TombEngine/Scripting/Internal/ReservedScriptNames.h @@ -298,7 +298,6 @@ static constexpr char ScriptReserved_GetSoundSourceByName[] = "GetSoundSourceB static constexpr char ScriptReserved_GetVolumeByName[] = "GetVolumeByName"; static constexpr char ScriptReserved_GetRoomsByTag[] = "GetRoomsByTag"; static constexpr char ScriptReserved_GetRoomByName[] = "GetRoomByName"; -static constexpr char ScriptReserved_CalculateDistance[] = "CalculateDistance"; static constexpr char ScriptReserved_CalculateHorizontalDistance[] = "CalculateHorizontalDistance"; static constexpr char ScriptReserved_PercentToScreen[] = "PercentToScreen"; static constexpr char ScriptReserved_ScreenToPercent[] = "ScreenToPercent"; diff --git a/TombEngine/Scripting/Internal/TEN/Util/Util.cpp b/TombEngine/Scripting/Internal/TEN/Util/Util.cpp index 1ce19b295..61769657f 100644 --- a/TombEngine/Scripting/Internal/TEN/Util/Util.cpp +++ b/TombEngine/Scripting/Internal/TEN/Util/Util.cpp @@ -20,12 +20,12 @@ using TEN::Renderer::g_Renderer; -/// Utility functions for various calculations. -// @tentable Util -// @pragma nostrip - namespace TEN::Scripting::Util { + /// Utility functions for various calculations. + // @tentable Util + // @pragma nostrip + /// Determine if there is a clear line of sight between two positions. // NOTE: Limited to room geometry. Objects are ignored. // @function HasLineOfSight() @@ -43,18 +43,7 @@ namespace TEN::Scripting::Util MESH_INFO* mesh = nullptr; auto vector = Vector3i::Zero; - return (LOS(&vector0, &vector1) && - ObjectOnLOS2(&vector0, &vector1, &vector, &mesh) == NO_LOS_ITEM); - } - - ///Calculate the distance between two positions. - //@function CalculateDistance - //@tparam Vec3 posA First position. - //@tparam Vec3 posB Second position. - //@treturn float Distance between two positions. - static float CalculateDistance(const Vec3& posA, const Vec3& posB) - { - return posA.Distance(posB); + return (LOS(&vector0, &vector1) && ObjectOnLOS2(&vector0, &vector1, &vector, &mesh) == NO_LOS_ITEM); } /// Calculate the horizontal distance between two positions. @@ -192,13 +181,17 @@ namespace TEN::Scripting::Util TENLog(message, level, LogConfig::All, USE_IF_HAVE(bool, allowSpam, false)); } + static float CalculateDistance(const Vec3& posA, const Vec3& posB) + { + return posA.Distance(posB); + } + void Register(sol::state* state, sol::table& parent) { auto tableUtil = sol::table(state->lua_state(), sol::create); parent.set(ScriptReserved_Util, tableUtil); tableUtil.set_function(ScriptReserved_HasLineOfSight, &HasLineOfSight); - tableUtil.set_function(ScriptReserved_CalculateDistance, &CalculateDistance); tableUtil.set_function(ScriptReserved_CalculateHorizontalDistance, &CalculateHorizontalDistance); tableUtil.set_function(ScriptReserved_GetDisplayPosition, &GetDisplayPosition); tableUtil.set_function(ScriptReserved_PickMoveable, &PickMoveable); @@ -207,6 +200,9 @@ namespace TEN::Scripting::Util tableUtil.set_function(ScriptReserved_ScreenToPercent, &ScreenToPercent); tableUtil.set_function(ScriptReserved_PrintLog, &PrintLog); + // COMPATIBILITY + tableUtil.set_function("CalculateDistance", &CalculateDistance); + auto handler = LuaHandler(state); handler.MakeReadOnlyTable(tableUtil, ScriptReserved_LogLevel, LOG_LEVEL_IDS); }