mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 16:23:21 +00:00
Merge pull request #1554 from feelfreetofee/dev
refactor(es_extended/client/imports/point.lua) and (es_extended/client/modules/points.lua): Performace Improvement
This commit is contained in:
@@ -1,44 +1,53 @@
|
|||||||
Point = ESX.Class()
|
local Point = ESX.Class()
|
||||||
|
|
||||||
function Point:constructor(properties)
|
local nearby, loop = {}
|
||||||
self.coords = properties.coords
|
|
||||||
self.hidden = properties.hidden or false
|
function Point:constructor(properties)
|
||||||
self.inside = properties.inside or function() end
|
self.coords = properties.coords
|
||||||
self.enter = properties.enter or function() end
|
self.hidden = properties.hidden
|
||||||
self.leave = properties.leave or function() end
|
self.enter = properties.enter
|
||||||
self.handle = ESX.CreatePointInternal(properties.coords, properties.distance, properties.hidden, function()
|
self.leave = properties.leave
|
||||||
self.nearby = true
|
self.inside = properties.inside
|
||||||
if self.enter then
|
self.handle = ESX.CreatePointInternal(properties.coords, properties.distance, properties.hidden, function()
|
||||||
self:enter()
|
nearby[self.handle] = self
|
||||||
end
|
if self.enter then
|
||||||
if self.inside then
|
self:enter()
|
||||||
CreateThread(function()
|
end
|
||||||
while self.nearby do
|
if not loop then
|
||||||
local coords = GetEntityCoords(ESX.PlayerData.ped)
|
loop = true
|
||||||
self.currDistance = #(coords - self.coords)
|
CreateThread(function()
|
||||||
self:inside()
|
while loop do
|
||||||
Wait(0)
|
local coords = GetEntityCoords(ESX.PlayerData.ped)
|
||||||
end
|
for handle, point in pairs(nearby) do
|
||||||
end)
|
if point.inside then
|
||||||
end
|
point:inside(#(coords - point.coords))
|
||||||
end, function()
|
end
|
||||||
self.nearby = false
|
end
|
||||||
if self.leave then
|
Wait()
|
||||||
self:leave()
|
end
|
||||||
end
|
end)
|
||||||
end)
|
end
|
||||||
end
|
end, function()
|
||||||
|
nearby[self.handle] = nil
|
||||||
function Point:delete()
|
if self.leave then
|
||||||
ESX.RemovePointInternal(self.handle)
|
self:leave()
|
||||||
end
|
end
|
||||||
|
if #nearby == 0 then
|
||||||
function Point:toggle(hidden)
|
loop = false
|
||||||
if hidden == nil then
|
end
|
||||||
hidden = not self.hidden
|
end)
|
||||||
end
|
end
|
||||||
self.hidden = hidden
|
|
||||||
ESX.HidePointInternal(self.handle, hidden)
|
function Point:delete()
|
||||||
end
|
ESX.RemovePointInternal(self.handle)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Point:toggle(hidden)
|
||||||
|
if hidden == nil then
|
||||||
|
hidden = not self.hidden
|
||||||
|
end
|
||||||
|
self.hidden = hidden
|
||||||
|
ESX.HidePointInternal(self.handle, hidden)
|
||||||
|
end
|
||||||
|
|
||||||
return Point
|
return Point
|
||||||
@@ -1,57 +1,54 @@
|
|||||||
local points = {}
|
local points = {}
|
||||||
|
|
||||||
function ESX.CreatePointInternal(coords, distance, hidden, enter, leave)
|
function ESX.CreatePointInternal(coords, distance, hidden, enter, leave)
|
||||||
local point = {
|
local point = {
|
||||||
coords = coords,
|
coords = coords,
|
||||||
distance = distance,
|
distance = distance,
|
||||||
hidden = hidden,
|
hidden = hidden,
|
||||||
enter = enter,
|
enter = enter,
|
||||||
leave = leave,
|
leave = leave,
|
||||||
resource = GetInvokingResource()
|
resource = GetInvokingResource()
|
||||||
}
|
}
|
||||||
local handle = ESX.Table.SizeOf(points) + 1
|
local handle = ESX.Table.SizeOf(points) + 1
|
||||||
points[handle] = point
|
points[handle] = point
|
||||||
return handle
|
return handle
|
||||||
end
|
end
|
||||||
|
|
||||||
function ESX.RemovePointInternal(handle)
|
function ESX.RemovePointInternal(handle)
|
||||||
points[handle] = nil
|
points[handle] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function ESX.HidePointInternal(handle, hidden)
|
function ESX.HidePointInternal(handle, hidden)
|
||||||
if points[handle] then
|
if points[handle] then
|
||||||
points[handle].hidden = hidden
|
points[handle].hidden = hidden
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function StartPointsLoop()
|
function StartPointsLoop()
|
||||||
CreateThread(function()
|
CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
local coords = GetEntityCoords(ESX.PlayerData.ped)
|
local coords = GetEntityCoords(ESX.PlayerData.ped)
|
||||||
for i, point in pairs(points) do
|
for handle, point in pairs(points) do
|
||||||
local distance = #(coords - point.coords)
|
if not point.hidden and #(coords - point.coords) <= point.distance then
|
||||||
|
if not point.nearby then
|
||||||
if not point.hidden and distance <= point.distance then
|
points[handle].nearby = true
|
||||||
if not point.nearby then
|
points[handle].enter()
|
||||||
points[i].nearby = true
|
end
|
||||||
points[i].enter()
|
elseif point.nearby then
|
||||||
end
|
points[handle].nearby = false
|
||||||
point.currentDistance = distance
|
points[handle].leave()
|
||||||
elseif point.nearby then
|
end
|
||||||
points[i].nearby = false
|
end
|
||||||
points[i].leave()
|
Wait(500)
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
Wait(500)
|
end
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
AddEventHandler('onResourceStop', function(resource)
|
||||||
|
for handle, point in pairs(points) do
|
||||||
|
if point.resource == resource then
|
||||||
AddEventHandler('onResourceStop', function(resource)
|
points[handle] = nil
|
||||||
for i, point in pairs(points) do
|
end
|
||||||
if point.resource == resource then
|
end
|
||||||
points[i] = nil
|
end)
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
Reference in New Issue
Block a user