Is it worth auto-loading custom packages?

Discuss API design here.
User avatar
iPlayer
Developer
Posts: 482
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Is it worth auto-loading custom packages?

Postby iPlayer » Thu Apr 28, 2016 8:00 pm

Hey there,

Writing this after noticing some kind of a flaw in my packages.

The question is, maybe it's worth to pre-load custom packages on server startup? Just import them from their directories so that they can register their events, start listening to listeners etc.

Example 1. Hot plug issue.
If you load the plugin that uses the package only after somebody joins the server, your package won't know of this player. You'll need to implement some kind of a hot-plug mechanism to go through PlayerIter and detect all existing players on the server. You don't need to do it, however, if the package was pre-loaded in the first place.

Example 2. Package doesn't always need to be imported by the plugins it's used by.
I have a package that basically works with events. It doesn't export anything to be imported by the actual plugin. The thing is, since it's never imported - it's never actually loaded. I was developing my plugin and was like, "ah, why the package doesn't fire its events?..". Then I realized I have to add an extra (unused) import statement for this package so it will get loaded when the plugin gets loaded. But then again, it will be loaded only with the plugin - and what if the plugin is being hot-plugged?

Maybe not all packages deserve or need pre-loading, but for some packages it will simplify the things. So maybe it's worth implementing some kind of a list of the packages that should load on startup, or even creating another directory for such packages?
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • arcadmin • AdPurge

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
Ayuto
Project Leader
Posts: 1577
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Re: Is it worth auto-loading custom packages?

Postby Ayuto » Thu Apr 28, 2016 8:13 pm

Thanks for the suggestion! But I don't think it's worth loading them. If you have a package that doesn't provide any objects that could be imported by plugins, it's not a package, but a plugin.

iPlayer wrote:[...] or even creating another directory for such packages?

There is a directory for those packages. It's called "plugins"! :D
User avatar
iPlayer
Developer
Posts: 482
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Is it worth auto-loading custom packages?

Postby iPlayer » Thu Apr 28, 2016 8:16 pm

Well, it's can still be used by multiple plugins.

How would it be nice to include a plugin in another plugin's requirements?
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • arcadmin • AdPurge

Hail, Companion. [...] Hands to yourself, sneak thief. Image
User avatar
satoon101
Project Leader
Posts: 2319
Joined: Sat Jul 07, 2012 1:59 am

Re: Is it worth auto-loading custom packages?

Postby satoon101 » Fri Apr 29, 2016 1:19 am

Well, I would really like to see this use-case to see if there is a better resolution. I really don't like the idea of pre-loading custom packages.

As far as your first example, I don't see the need to use PlayerIter as a bad thing. That is certainly something that is fairly easily done and easy to implement.

The 2nd example, though, is the one I would like to better understand. Could you provide a full example to see and test?
User avatar
iPlayer
Developer
Posts: 482
Joined: Sat Nov 14, 2015 8:37 am
Location: Moscow
Contact:

Re: Is it worth auto-loading custom packages?

Postby iPlayer » Fri Apr 29, 2016 1:36 am

Yeah, sorry, should've given the example in the first place

https://github.com/KirillMysnik/ArcJail/blob/master/srcds/addons/source-python/packages/custom/arc_death_tools.py is the package that fits 2nd example.

Basically what it does is:
1. Exports fake_death method that allows to set up and fire a fake player_death event - so that everybody will see a notification in a killfeed
2. Now, player_death event becomes invalid with this package, because plugins can't rely on this event anymore - it can be fake. So the package provides two more events - player_death_real and player_death_fake. Every player_death event will be followed by either of those.

Now to the 2nd example. Some plugins might not use fake_death method, but may still be designed to be compatible with the package - so they just listen to player_death_real event, for example. But once there's no plugin that imports fake_death method, the package won't actually be loaded, and player_death_real will never fire, making all these friendly-designed plugins invalid.
Image /id/its_iPlayer
My plugins: Map Cycle • Killstreaker • DeadChat • Infinite Jumping • TripMines • arcadmin • AdPurge

Hail, Companion. [...] Hands to yourself, sneak thief. Image

Return to “API Design”

Who is online

Users browsing this forum: No registered users and 1 guest