MinoMino / minqlx

Extends Quake Live's dedicated server with extra functionality and scripting.
GNU General Public License v3.0
112 stars 42 forks source link

Setting handlers, only if it is required by plugins #124

Open em92 opened 1 year ago

em92 commented 1 year ago

For example:

  1. we have accepted PR with new damage hook https://github.com/MinoMino/minqlx/pull/120
  2. QLDS server does not use plugin, which uses introduced "damage" hook.
  3. minqlx.register_handler("damage", handle_damage) is executed from PR above.

When damage is registered QLDS runs python code around handle_damage and https://github.com/MinoMino/minqlx/blob/390d6c11ec15c2df060765a7416f64f6d0eebfd3/python/minqlx/_events.py#L41-L98, which wastes extra CPU time and clearly does not do anything useful.

So it would be better, if minqlx.register_handler("damage", handle_damage) only if plugin or minqlx itself requires it.

That also concerns to other hooks below, but comparing to damage hook, they are executed less frequently

mgaertne commented 1 year ago

Hmmmm, that should be possible by modifying the last_init method, and plugin_load mechanism, and modifying add_hook in the plugin class to register the handler for the given hook.

mgaertne commented 1 year ago

Note that I also added the handle_frame event which is called once per server frame, i.e. 40 times per second on default server settings to your list of events that maybe should be hot pluggable.