Turning off/on for events handler

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Turning off/on for events handler

Post by Apeirogon »

Right now events is a more powerful scripting tool than acs. But they lack flexibility of acs in terms of control.
Like, I can run, stop, run again and terminate any acs script from any actor, and even from different actors. And events have only one position on this scale, on. And this is sometimes lead to glitches and freeze.

For example, I want to give to every single actor on a map some item, but only at several first tick from the "beginning" of a map. For this I, obvious, use "world spawned" event with condition

Code: Select all

if(level.time < 10)
give item
and this is works as intended. And it dont give anything to any actor which was spawned after the first 10 tick of a map time.

But, if player have fast firing weapon or some actors on map spawn much of a decorations like rain drops, smoke or sparks, or even worse, monsters which spawn 999nineninenine... projectiles in tick, when such weapon/actor/monster start to do its works this event cause noticeable performance drop just to realize that it dont need to do anything!!!!!!

So, such situations require possibility to turn off this event at all.
More precisely, I dont say "make a button to turn off ALL world spawn/world tick/etc. events pls) :3: ", I say "I have "world item giver" event, which have "world spawn" and "world tick" and/or other override, and I want to turn off specifically this, "world item giver", event. Can you please make some way to do so?".
User avatar
Zhs2
Posts: 1299
Joined: Fri Nov 07, 2008 3:29 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Maryland, USA, but probably also in someone's mod somewhere
Contact:

Re: Turning off/on for events handler

Post by Zhs2 »

At the risk of invoking the evil and dreaded tenet of "just do x instead", why not iterate through every existing actor within a single early WorldTick (like, say, level.time == 1) for your effect?
_mental_
 
 
Posts: 3820
Joined: Sun Aug 07, 2011 4:32 am

Re: Turning off/on for events handler

Post by _mental_ »

Create an actor that does nothing for 10 ticks, iterates all map objects on 11th, and destroys itself.
So, you only need an event handler to spawn that actor.

In general, dynamic (de)registration of event handlers is a good idea. The problem is it's not doable with the current state of ZScript.
Without full fledged callable entities (pointers to functions, 'first class object' functions, etc) it won't fly.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Turning off/on for events handler

Post by Apeirogon »

I found more more suitable way, for me, after I realize that performance drop cause this single check in world spawn event. Network event which, after command from console event, use special thinker which give/take item to/from every actor. Probably someday I use menus, since now I poorly imagine how it works.
_mental_ wrote:The problem is it's not doable with the current state of ZScript.
Too bad.
User avatar
ZZYZX
 
 
Posts: 1384
Joined: Sun Oct 14, 2012 1:43 am
Location: Ukraine
Contact:

Re: Turning off/on for events handler

Post by ZZYZX »

I had Add/Remove event handler static function in one of the initial concepts. I don't remember why it didn't make it into the more final versions, but probably can be restored.
Either way there is EventHandler.Find (and StaticEventHandler.Find). It lets you return your object where you can then set some variable to true/false to pause the processing easily.
Post Reply

Return to “Feature Suggestions [GZDoom]”