Deprecate CalculateDistance() script function

This commit is contained in:
Sezz 2025-02-08 02:58:03 +11:00
parent 34ff933e5b
commit 2c6331f583
3 changed files with 13 additions and 54 deletions

View file

@ -121,10 +121,6 @@
<td class="summary">Determine if there is a clear line of sight between two positions.</td>
</tr>
<tr>
<td class="name" ><a href="#CalculateDistance">CalculateDistance(posA, posB)</a></td>
<td class="summary">Calculate the distance between two positions.</td>
</tr>
<tr>
<td class="name" ><a href="#CalculateHorizontalDistance">CalculateHorizontalDistance(posA, posB)</a></td>
<td class="summary">Calculate the horizontal distance between two positions.</td>
</tr>
@ -202,38 +198,6 @@
<span class="global">print</span>(Misc.HasLineOfSight(enemyHead:GetRoomNumber(), enemyHead:GetPosition(), flamePlinthPos))</pre>
</ul>
</dd>
<dt>
<a name = "CalculateDistance"></a>
<strong>CalculateDistance(posA, posB)</strong>
</dt>
<dd>
Calculate the distance between two positions.
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">posA</span>
<span class="types"><a class="type" href="../3 primitive classes/Vec3.html#">Vec3</a></span>
First position.
</li>
<li><span class="parameter">posB</span>
<span class="types"><a class="type" href="../3 primitive classes/Vec3.html#">Vec3</a></span>
Second position.
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">float</span></span>
Distance between two positions.
</ol>
</dd>
<dt>
<a name = "CalculateHorizontalDistance"></a>

View file

@ -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";

View file

@ -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);
}