Skip to content

Implement a plugin system #106

@caelunshun

Description

@caelunshun

This is a key component in making Feather usable.

Requirements:

  • Implement a system which dynamically loads plugins at runtime. Plugins should be able to handle events and register Systems.
  • Plugins should be able to access and modify components.
  • The boundary between plugins and server should be efficient, ideally zero-cost.
  • Plugins should be written in Rust.

The proposal is to compile plugins to WebAssembly and run them using wasmer. At server startup, plugins will be loaded and an init function will be called. Here, plugins will be able to register systems and event handlers with the host.

Any systems registered by a plugin will be added to the DispatcherBuilder at init time. This means that plugin systems will run in the same way normal ones do.

Plugins will be required to specify the system data they require for each system, much like systems on the host, but components and resources will be represented in a more abstract way. For example, they will not have to manually write events; rather, this will be handled transparently on the host.

Any requests and updates of data by a plugin will require a host call. The host exposes functions to query and update data. On the host side, any SystemData required by the plugin will be stored in wasmer::Ctx, and inside a host function, the function will take the SystemData from the Ctx and use it as necessary. The exact details in how this will be implemented will be investigated later, but we know it is possible.

The plugin API itself will look much like the Bukkit API at first glance, with the main difference being the requirement for specifying what data an event handler requires. In addition, plugins will be allowed to have a state struct which is also passed to any event handler or system. Using this, it can access any necessary global state. The state struct will be required to be Send + Sync, since in the future, plugins may be invoked in parallel (although currently, this is not possible since wasmer::Instance does not implement Sync).

Several types from feather-core will have to be moved to the plugin API, such as Position. Also, feather-blocks and feather-items will be exposed to plugins.

The current plan is to first implement a proof of concept using Specs with Wasmer before proceeding to write the actual plugin system. Work on this should begin within the next few months.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions