-
Notifications
You must be signed in to change notification settings - Fork 145
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
Conversation
/// # Safety | ||
/// This function may not be called from multiple threads | ||
/// at once. | ||
pub fn init_vtable(s: FStr) -> Result<(), serde_json::Error> { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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
?
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.
This PR will implement an initial design for
fapi
, our plugin API, and the associated API bindings and plugin loader infeather-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
plugin_init
proc macro to mark a plugin's initialization function. (Question: this naming isn't ideal; ideally it would be calledplugin
, but that's taken by the Rust compiler. Other ideas are welcome)fapi
to crates.io