WorldThing Event Disabling Flags

Post a reply

Smilies
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :geek: :ugeek: :!: :?: :idea: :arrow: :| :mrgreen: :3: :wub: >:( :blergh:
View more smilies

BBCode is OFF
Smilies are ON

Topic review
   

Expand view Topic review: WorldThing Event Disabling Flags

Re: WorldThing Event Disabling Flags

by Major Cooke » Fri Sep 07, 2018 10:31 am

This can be closed. I no longer care about this.

Re: WorldThing Event Disabling Flags

by Graf Zahl » Wed Apr 11, 2018 3:45 am

ZZYZX wrote: But not sure if it's actually going to make it faster.

That answers MC's question.

Re: WorldThing Event Disabling Flags

by Major Cooke » Wed Apr 11, 2018 2:05 am

When you potentially have lots of array controls in there, it could make a difference. And, I too am wondering why blacklisting won't happen, Graf?

Re: WorldThing Event Disabling Flags

by ZZYZX » Wed Apr 11, 2018 1:57 am

I think blacklisting specific event handler names should be ok to control it in your specific mod (don't see how this can be abused in the future if subclasses are not included). But not sure if it's actually going to make it faster.

Re: WorldThing Event Disabling Flags

by Major Cooke » Tue Apr 10, 2018 4:48 pm

I agree that it being an opt-in would have been nice, but limiting it to just important actors would have only hurt creativity, resorting to hacks. A_RadiusGive certainly taught me that.

Re: WorldThing Event Disabling Flags

by Graf Zahl » Tue Apr 10, 2018 3:10 pm

I'm sorry but that's not going to happen. Seriously, the only solution here can be: Do not use event handlers if you spawn tons of stuff.

In retrospect I have to say that it was a stupid idea to have an event handler being unconditionally called whenever ANY actor gets spawned. This should have been restricted from the start to 'important' actors like monsters and inventory stuff and for the test been purely opt-in.

Re: WorldThing Event Disabling Flags

by Major Cooke » Tue Apr 10, 2018 2:42 pm

The thing about AEoD is, it's very hands on about the effects in game.

There can be a TON of effects too, but that doesn't cause the same notable amount of lag as including the event handlers on top of it. And those spawn/destroy functions are called on every actor that spawns.

Which is why I now propose a blacklist/whitelist approach for actors.

Code: Select all

BlacklistHandler "Handler1", "Handler2", ...;
Or blacklisting which handler's functions are allowed to trigger:

Code: Select all

BlacklistHandlerSpawn "Handler1", ...;
Thoughts? Ideas?

Re: WorldThing Event Disabling Flags

by ZZYZX » Tue Apr 10, 2018 1:37 pm

Ok, I added array access, it now reads/writes all secondary actors to an array. Logs array size of 5000. Still no lag. I didn't measure exact millisecond timing but by FPS counter it takes approximately 10-17ms on the "hard" frames.

So while overall I understand that this might be caused by lag accumulation in AEoD (due to AEoD being complex enough for lag accumulation to be possible), but I don't think this is an event handlers problem.

upd: I'll try to hack the full AEoD version of this code tomorrow once I'm a bit more awake. Will know what's wrong better at that point. I hope I provided enough evidence that it's not as simple as event handlers being laggy here so that it doesn't get changed until more is known :P
Attachments
testhandlers.pk3
(915 Bytes) Downloaded 55 times

Re: WorldThing Event Disabling Flags

by Graf Zahl » Tue Apr 10, 2018 1:27 pm

The culprit is that you actually *DO* something in your handler. Of course, with a nearly empty handler the impact will be considerably less severe.

Re: WorldThing Event Disabling Flags

by Major Cooke » Tue Apr 10, 2018 1:14 pm

I'll be more specific: the lag comes from the compounding dual event handlers spawning and destroying calls happening. And specifically, I'm recording them to an array of interactable entities.

Whenever they're spawned, they're pushed to an array in ONE event handler:

Code: Select all

Array<Actor> FX;
Array<SpecialMons> Spec;
Array<Actor> Monsters;
Array<Inventory> Absorbables;

override void WorldThingSpawned(WorldEvent e)
{
	Actor mo = e.Thing;
	if (!mo || mo.bNOINTERACTION || mo.bNOBLOCKMAP || mo.bNOSECTOR ||
		mo is "AEoDMonsterSpawner" || mo is "DirectorBase")
	{
		return;
	}
	if (mo.bISMONSTER || mo.bCORPSE)
	{
		if (mo is "SpecialMonsterBase")
		{
			let SpecialMon = SpecialMonsterBase(mo);
			if (SpecialMon)
			{
				SpecialMon.Tracker = self;
				Spec.Push(SpecialMon);
			}
		}
		else if (Spec.Size())	Monsters.Push(mo);
	}
	else if (mo is "Inventory" && mo.species == 'Absorbable')
	{
		Absorbables.Push(mo);
	}
	else if (mo is "PlayerPawn" && Spec.Size())
	{
		Monsters.Push(mo);
	}
}
While another does this:

Code: Select all

override void WorldThingSpawned(WorldEvent e)
{
	if (DemonMorph)
	{
		Actor mo = e.Thing;
		if (!mo || mo.bNOINTERACTION || mo is "DirectorBase")	return;
		if (mo.bISMONSTER && mo.health > 0)
		{
			mo.A_GiveInventory("DemonMorphTranslationItem", 1);
		}
	}
}
...Hmm, I think the culprit might be the array functions...

Re: WorldThing Event Disabling Flags

by ZZYZX » Tue Apr 10, 2018 12:53 pm

This script creates 5000 actors all of which are registered by two handlers (verified using counter). Does not lag.
Each actor spawns, waits for 1 tick, spawns more actors and dies. First 500 are spawned (by summon testactor), then each of these spawns 10 more.

I also bound "summon testactor" to a key and could not produce any noticeable FPS drop by spamming that key.

FPS drop only becomes apparent when I crank the first number up to 5000 (5000 then each spawns 10), but that's... not very good either way. nuts.wad is not recommended.

Expected log (from 5000) looks like this: https://i.imgur.com/Qta3Puk.png

This is to back my point that I don't understand why it should lag. It does almost nothing if the first thing in the function is "if actor should not be handled".
Attachments
testhandlers.pk3
(828 Bytes) Downloaded 72 times

Re: WorldThing Event Disabling Flags

by Major Cooke » Tue Apr 10, 2018 12:48 pm

Well, more like 2 event handlers where WorldThingSpawned and WorldThingDestroyed are both called so that quickly adds up.

So I'm wondering if perhaps a blacklist approach similar to Forbidden/RestrictedTo would do the trick?

And yes, it is being called on everything that spawns and destroys.

Re: WorldThing Event Disabling Flags

by Graf Zahl » Tue Apr 10, 2018 12:42 pm

ZZYZX wrote:I don't understand why 500*4 "if..return" calls in a tic should bring FPS to zero.
They probably don't. But executing 500 event handlers can surely have a devastating impact. Major Cooke is correct about one thing: If these events are being called on every chunk of debris that gets spawned, destroyed or mutilated they surely will kill performance quite efficiently.

Re: WorldThing Event Disabling Flags

by Major Cooke » Tue Apr 10, 2018 12:38 pm

I'll make one.

But in the mean time, perhaps a blacklist/whitelist approach like inventory items have Forbidden/RestrictedTo would be better.

Re: WorldThing Event Disabling Flags

by ZZYZX » Tue Apr 10, 2018 12:15 pm

I don't like this.

Quote from Discord
[9:12 PM] ZZYZX: WorldThing events are created so that custom mods can do stuff to arbitrary other mods
[9:12 PM] ZZYZX: In an universal way
[9:12 PM] ZZYZX: What you propose will cause things like
[9:12 PM] ZZYZX: mymod.pk3 and mymod_aeod_compat_patch.pk3
[9:13 PM] ZZYZX: Because inheritance is not possible when the parent actor is not defined... which means the inheritance patch cannot be loaded by default
[9:13 PM] ZZYZX: Which basically breaks the whole point of having an event handler
[9:13 PM] ZZYZX: So please find another reason why it lags and don't do this
Please provide minimal example of laggy code so that it can be debugged. I don't understand why 500*4 "if..return" calls in a tic should bring FPS to zero.

Top