hooks

by Konlet
Hook atoms together to share properties and events. [More]
To download this library for your Linux/Mac installation, enter this on your command line:

DreamDownload byond://Konlet.hooks##version=2

Emulator users, in the BYOND pager go to File | Open Location and enter this URL:

byond://Konlet.hooks##version=2

25 downloads
Version 2
Date added: Dec 21 2015
Last updated: Apr 6 2018
0 fans
Plug-N-Play.
Uses an update loop.

Comments

GatewayRa: (Dec 25 2015, 10:07 pm)
Okay, I've looked at your code and for starters, you're making the same mistake Kozuma did by hiding the update loop from the profiler. It's not as efficient as you think it is, and as a matter of fact, what you have has the potential to be a huge performance bottleneck.

It's filled with redundancies, and it's not user friendly at all to my standard. The hooks variable ideally wouldn't be accessed directly, it should be encapsulated.

"A.hooks = list(null)" Is this you trying to clear the list...?

Okay. Let's see. Your whole library is centered around syncing variables at every tick. Why on Earth can't you just share the same reference to a datum instead? Your library has no point to it but added overhead. It isn't even practical for syncing object appearances; there are SO much better ways to accomplish this.
Konlet: (Dec 23 2015, 7:45 am)
Thanks, I made those changes aside from the soft deletion.
Lummox JR: (Dec 22 2015, 1:58 pm)
There's a huge problem here:

atom/var/list/hooks[] = new

That means every atom in the world, turfs included, will have an init proc that initializes this list. Very bad idea. Instead, don't initialize your list at all; don't use [] or the new command (which are redundant together).

atom/var/list/hooks

When you need to add a hook, only then should you create the hooks list. Likewise you should set the var to null when the last hook has been removed.

Another issue: Calling A.Del() directly is wrong. Del() should never be called directly. That should be del A instead. Ideally, it'd be even better to find a way to soft-delete A.

The global lists "special" and "active" are not well named for a library because they're likely to come into conflict with other code.

For performance reasons, special() would be best made into an associative list, at least when the library first starts up, so you can check if(special[V]) instead of if(special.Find(V)).

A.hooks.Find(src) should be replaced with src in A.hooks, since with list husbandry the A.hooks value could be null. Although I'd completely alter the datum/Del() for performance. Looping through the active list every time any object is deleted will murder your performance.