TheTermos / mobkit

Entity API for Minetest
MIT License
26 stars 12 forks source link

force delete entities with memories by negative timeouts #33

Closed berengma closed 3 years ago

berengma commented 3 years ago

This took me several months until I found out what was the problem on my server Lilly. Finally I found in your dokumentation that entities get not deleted by the actfunc and their timeout value if they saved something in their memory before.

This grew up to a problem on my server and using aerotest mod. The eagles use memory function to save hunger and other bio data. But because of landscape they sometimes disappear from ABR. (that biodata is not that important)

They never got deleted, because of their memory and on the other side they keep on spawning and adding more to the unloaded area.

This can grow to bigger problem for a server which is not restarted every day (eagles are static_save = false) After a day I had server CPUtime of 50% busy without a single player online.

What I changed is that entities with negative timeout are always deleted, even if they have memories. Everything else is untouched.

Now modders can chose:

timeout > 0 deleted after timeout and inactivity but not when having memory stored timeout = 0 never deleted timeout < 0 force delete after inactivity and timout

TheTermos commented 3 years ago

eagles are static_save = false

So they should be deleted regardless. There was an engine issue related to static_save not working properly, maybe it's still unresolved? https://github.com/minetest/minetest/issues/9821

Still, timeout behavior needs to be changed, let me think on this.

berengma commented 3 years ago

Unfortunately they weren't deleted. When you visited the neighbouring mapblocks they were full of eagles. I run the modified mobkit on Lilly and now they get deleted after the time you set in self.timeout. CPU time is back to normal. <5 % if no one around. Minetest 5.3.0 stable

TheTermos commented 3 years ago

I see, the fix was merged after 5.3 release so current stable is still broken.

What would you say if you could just set timeout at runtime, and it would work independent from memory?

berengma commented 3 years ago

Independence from memory would need to rewrite a bunch of functions. Not only aerotest, but also wildcow. Water_life I did not check. Then I would have to implement memory again when I add tamed eagles and cows in the future.

berengma commented 3 years ago

https://github.com/minetest/minetest/issues/9821 I can see that this issue was closed, somehow I cannot see if there was a solution, something which got merged into 5.4.0.

berengma commented 3 years ago

@sfan5 sfan5 added the Won't add label on Nov 27, 2020

looks like not. Changing to static_save = true, won't help me as the entities still get not removed when using memories. I do not know how many online servers out there use aerotest. I know of at least one: "Your Land". In singleplayer this not an issue, because you frequently close your server/client.

TheTermos commented 3 years ago

Well with static_save = false there's going to be a problem no matter what we do, because if entities are never deactivated then timeout can't have any effect - it works only after deactivation and subsequent reactivation. Good idea never to use static_save = false

berengma commented 3 years ago

Ok, so maybe now they only get removed because of that bug. I will change all my mobs to static.save =true then.

sfan5 commented 3 years ago

sfan5 added the Won't add label on Nov 27, 2020

looks like not.

Huh what? static_save=false not working as documented was fixed with commit https://github.com/minetest/minetest/commit/4f2303849e0f929524695a9e3719ec486b47ddd1.

TheTermos commented 3 years ago

Huh what? static_save=false not working as documented was fixed with commit minetest/minetest@4f23038.

Yup, but that's 5.4 dev if I'm not mistaken. We work with stable versions.

berengma commented 3 years ago

sfan5 added the Won't add label on Nov 27, 2020

looks like not.

Huh what? static_save=false not working as documented was fixed with commit minetest/minetest@4f23038.

Oh thanks. I must have misunderstood that label.

Nevertheless turning static_save to true will not solve problems of aerotest.

TheTermos commented 3 years ago

Nevertheless turning static_save to true will not solve problems of aerotest.

Yes, making timeout depend on memory was not so great idea, my bad. Will probably merge, just let me think on it a bit.

berengma commented 3 years ago

I just tried today water_life with static_save true and positive timeouts. That will break the whole thing. All my amphibious animals and the gulls also use mobkit.remember to save timestamps to know when it is time to switch from land to water and vv. After less than an hour we had a serious crocodile and snake overpopulation at a lake. Branch 'staticsaveIsTrue '.

berengma commented 3 years ago

We can wait until minetest 5.4 is out. If that helps you :relaxed:

TheTermos commented 3 years ago

No, 5.4 doesn't make a difference. Done a quick test and seems to be working allright. merging. Let's be quiet about it for now, so people don't start relying on it too much in case I find another solution.

berengma commented 3 years ago

Thanks. It did make a big difference on my servers and I think other server owners running water_life will feel a difference. I keep quiet. The next 4 weeks I will not have time for minetest and my mods anyway.