Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use single shared lua interface for all npc #4666

Closed

Conversation

MillhioreBT
Copy link
Contributor

  • I have followed [proper The Forgotten Server code styling][code].
  • I have read and understood the [contribution guidelines][cont] before making this PR.
  • 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 first attempt at clearing npc events(callbacks) from scriptinterface … #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

	return false
end

talkAction:register()

and reloads...

Issues addressed: Nothing!

@MillhioreBT MillhioreBT added the enhancement Increase or improvement in quality, value, or extent label May 3, 2024
@EvilHero90
Copy link
Contributor

I'll close this, since this is already included in #4671

@EvilHero90 EvilHero90 closed this May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Increase or improvement in quality, value, or extent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants