Hey guys, awesome work!
I've found this masterpiece two days ago and didn't have the time to further investigate the code - sorry for that! I hope this is the correct section for this.
I noticed, that event's are globally registered.
(An example of what I mean: One event HOOK_PLAYER_MOVING, raised for every player)
Many plugins (especially mini-games or stuff like MagicCarpet) are only interested in the events of some players. Coulnd't it significantly improve the performance of these plugins if events were propagated to the affected entity (for example the player) where they can then be selectively registered by plugins? Leaving the global events only for plugins that really need all fired events.
So MagicCarpet would look something like this (using pseudo-API for removing hook):
This should reduce the amount of invocations into the lua-code (I don't know how expensive these invocations are) - but it should be more expensive than identifiying the affected entity and propagating the events especially on servers with many players, shouldn't it?
But in order to be an improvement, this would need a RemoveHook function, to deregister an event - Is there already something similar?
The only problem I found with this approach are events on blocks: If I want to listen the event of only one block (for example the redstone-status), the chunk containing this block can't be unloaded - even when it is unused - or it is unloaded anyway and the event is deregistered, which would then lead to the handler never being called again - except it is re-registered by the plugin.
Is there another reason (except the amount of work), for the events being global only up to date?
I've found this masterpiece two days ago and didn't have the time to further investigate the code - sorry for that! I hope this is the correct section for this.
I noticed, that event's are globally registered.
(An example of what I mean: One event HOOK_PLAYER_MOVING, raised for every player)
Many plugins (especially mini-games or stuff like MagicCarpet) are only interested in the events of some players. Coulnd't it significantly improve the performance of these plugins if events were propagated to the affected entity (for example the player) where they can then be selectively registered by plugins? Leaving the global events only for plugins that really need all fired events.
So MagicCarpet would look something like this (using pseudo-API for removing hook):
local CarpetHooks = {} -- array with hooks -- bind Command PluginManager:BindCommand("/mc", "magiccarpet", HandleCarpetCommand, " - Spawns a magical carpet") function HandleCarpetCommand(Player){ C_Hook = CarpetHooks[ Player ] if( C_Hook == nil ) then -- register move-event for player - who requested carpet CarpetHooks[ Player ] = Player.AddHook(HOOK_PLAYER_MOVE, OnCarpetPlayerMove) else -- deregister move-event for player - who disabled carpet C_Hook::remove() -- pseudo-API for removing hooks CarpetHooks[ Player ] = nil end } function OnCarpetPlayerMove(Player) -- handle moving carpet ... end
This should reduce the amount of invocations into the lua-code (I don't know how expensive these invocations are) - but it should be more expensive than identifiying the affected entity and propagating the events especially on servers with many players, shouldn't it?
But in order to be an improvement, this would need a RemoveHook function, to deregister an event - Is there already something similar?
The only problem I found with this approach are events on blocks: If I want to listen the event of only one block (for example the redstone-status), the chunk containing this block can't be unloaded - even when it is unused - or it is unloaded anyway and the event is deregistered, which would then lead to the handler never being called again - except it is re-registered by the plugin.
Is there another reason (except the amount of work), for the events being global only up to date?