Skip to content

High-Level Entity Methods (WIP) - #397

Draft
caelunshun wants to merge 1 commit into
mainfrom
high-level-entity-methods
Draft

caelunshun wants to merge 1 commit into
mainfrom
high-level-entity-methods

Conversation

@caelunshun

@caelunshun caelunshun commented Mar 9, 2021

Copy link
Copy Markdown
Member

This PR aims to create a framework for high-level entity methods like "get item in main hand," "deal damage," "send message," etc. These methods require access to multiple components, so they cannot be implemented as methods on a single component struct. The approach taken by this PR is to provide entity wrapper structs for each entity. These wrapper structs implement traits providing the high-level methods.

For example, the Player struct implements the SendMessage trait providing the send_message() method.

Entity wrappers can be used in queries in the same way components are used right now. For example, to send a message to all players using Quill:

use quill::entities::{Player, SendMessage};
for (_, player) in game.query::<Player>() {
    player.send_message("Hello world");
}

All marker components have been suffixed with Marker (e.g. PlayerMarker) to make them distinct from the new wrapper structs, and to indicate their purpose is secondary to that of wrapper structs.

I also intend to add wrappers for abstract entities like LivingEntity, which would implement the Damageable, HasInventory, etc. traits.

This PR is incomplete. I still need to figure out how we can provide entity wrappers in Feather internally as well as Quill without duplicating code. Also, I haven't actually implemented the traits yet.

This might act as an alternative to #388.

@caelunshun
caelunshun marked this pull request as draft March 9, 2021 04:02

@Defman Defman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm I feel like this hides which components you are querying, could we maybe create the QueryFrom struct via a query! macro.

let query = query! {
  _: &PlayerMarker,
  health: &mut Health,
  position: &mut Position,
  gamemode: &Gamemode,
  _: MessageReciver,
}

impl crate::entity::FromQuery for $wrapper_struct {
type Item = Self;

fn add_component_types(components: &mut impl Extend<crate::HostComponent>) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, $wrapper_struct can only contain a single component or are $marker going to become $($marker:ident),*?

Comment thread quill/api/src/query.rs
Q: FromQuery,
{
pub(crate) fn new() -> Self {
let mut component_types = Vec::new();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this maybe not be a set, since FromQuery can have overlapping components?

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.

2 participants