Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial plugin support #213

Closed
wants to merge 1 commit into from
Closed

Initial plugin support #213

wants to merge 1 commit into from

Conversation

caelunshun
Copy link
Member

@caelunshun caelunshun commented May 5, 2020

This PR will implement an initial design for fapi, our plugin API, and the associated API bindings and plugin loader in feather-server.

The current design is based on dynamic loading of shared libraries using a C-compatible FFI interface. The decision was made to hold off on the use of WebAssembly as the WASM ecosystem lacks the maturity we desire. For example, networking is still unimplemented in WASI (and has been for well over a year since the issue was filed...). Networking is a critical feature for plugins needing database interaction.

The current API can be ported to WASM with a bit of effort, should WASI implement the features we need.

Resolves #106, at least initially.

Checklist

  • host vtable abstraction + macro
  • plugin_init proc macro to mark a plugin's initialization function. (Question: this naming isn't ideal; ideally it would be called plugin, but that's taken by the Rust compiler. Other ideas are welcome)
  • Plugin logging
  • Test framework to test the API and server implementation
  • Registration of systems
  • Registration of event handlers
  • Interaction with entities and the world
  • Custom components
  • Plugin state
  • Interaction between plugins
  • Documentation
  • Release fapi to crates.io

@caelunshun caelunshun added this to the 0.7 milestone May 5, 2020
@caelunshun caelunshun marked this pull request as draft May 5, 2020 06:00
/// # Safety
/// This function may not be called from multiple threads
/// at once.
pub fn init_vtable(s: FStr) -> Result<(), serde_json::Error> {
Copy link
Member

@Defman Defman May 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we enforce this by having a static lock, for initialization?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cost will likely be significant, since this is hot code. This is an internal API, so there's not too much need for enforcing safety, as long as we're careful. For now, though, I can switch this to a safe implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the function has safety implications for calling, wouldn't it be better to make it an unsafe fn rather than wrap that up with a note in the docs?

#[repr(C)]
pub struct SystemSpec {
/// A pointer to the function to run when the system is invoked.
pub f: fn(*mut GameState),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change the name to something more descriptive than f, like run, invoke, or step?

///
/// The function may assume the `OpaqueEvent` pointer
/// points to the event type associated with `event`.
pub f: fn(*mut GameState, *mut OpaqueEvent),
Copy link
Member

@Defman Defman May 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better field name like, handle, act, run?

caelunshun added a commit that referenced this pull request May 11, 2020
Implement survival mode

This PR implements survival mode. Resolves #40.

#213 is blocked on this as we are developing the design we will use to approach gamemodes, and moreover, how we will implement gameplay features with regard to component architecture. The current approach is heavily based on data-oriented design. Rather than checking a player's gamemode in systems, there are a number of marker components—e.g. CanBreak, CanInstaBreak, CanTakeDamage, CanFly—which describe the capabilities of a player. These are inserted based on gamemode on player join, but the architecture allows for extensive customization of functionality through plugins.

Ideally, we would have a /gamemode command, but this is blocked on #209 being merged. I may merge it early, depending on how complete people deem it to be. Currently, the only way to affect a player's gamemode is through the default-gamemode setting in the config or manual editing of the player data files.

# Inventory handling
Only basic survival mode inventory handling (i.e. single clicks) has been implemented. I will hold off on the rest until our inventory indexing situation has improved.

# Block breaking
Survival mode digging has been implemented, for the most part. All which remains is to write down the harvest tools for all blocks (currently, only stone and dirt are in the list). This file is in definitions/data/tool.ron.
@Schuwi Schuwi mentioned this pull request Sep 13, 2020
Base automatically changed from develop to main February 27, 2021 01:51
@caelunshun
Copy link
Member Author

Superseded by #307 and #349.

@caelunshun caelunshun closed this Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement a plugin system
3 participants