[x] I have followed [proper The Forgotten Server code styling][code].
[x] I have read and understood the [contribution guidelines][cont] before making this PR.
[x] I am aware that this PR may be closed if the above-mentioned criteria are not fulfilled.
Changes Proposed
A while ago this PR was merged: #4483 and it fixes the memory leak problem with NPCs very well, however that PR includes the creation of a separate instance of NpcLuaScriptInterface, when in reality we can use a single one that is shared with everyone the NPCs, so this PR adds this possibility
The Npcs class has been removed for an Npcs namespace, I decided to make this change because it is not possible to have a static shared pointer and this class does not have any singletons to reuse.
Added a destructor to the NpcEventsHandler class to remove loaded event ids from the npc lua interface reference table. (inspired by #3553)
Now when we do /reload npc, the libraries will also be reloaded. It was always annoying to have to restart the server to be able to test changes to the libraries when we are in development. I don't know if maybe we should move it to the global reload type?
Tested with the following simple script:
local talkAction = TalkAction("!npcs")
function talkAction.onSay(player, words, param, type)
local pos = player:getPosition()
local npcs = {}
for i = 1, 1000 do
Game.createNpc("Deruno", Position(pos.x + math.random(-5, 5), pos.y + math.random(-5, 5), pos.z)):remove()
end
Changes Proposed
A while ago this PR was merged: #4483 and it fixes the memory leak problem with NPCs very well, however that PR includes the creation of a separate instance of NpcLuaScriptInterface, when in reality we can use a single one that is shared with everyone the NPCs, so this PR adds this possibility
The
Npcs class
has been removed for anNpcs namespace
, I decided to make this change because it is not possible to have a static shared pointer and this class does not have any singletons to reuse.Added a destructor to the
NpcEventsHandler
class to remove loaded event ids from the npc lua interface reference table. (inspired by #3553)Now when we do
/reload npc
, the libraries will also be reloaded. It was always annoying to have to restart the server to be able to test changes to the libraries when we are in development. I don't know if maybe we should move it to theglobal reload type
?Tested with the following simple script:
function talkAction.onSay(player, words, param, type) local pos = player:getPosition() local npcs = {} for i = 1, 1000 do Game.createNpc("Deruno", Position(pos.x + math.random(-5, 5), pos.y + math.random(-5, 5), pos.z)):remove() end
end
talkAction:register()