Skip to content

High-Level Entity Methods (WIP) #397

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

caelunshun
Copy link
Member

@caelunshun caelunshun commented Mar 9, 2021

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
Copy link
Member

@Defman Defman left a comment

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
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),*?

@@ -106,7 +19,7 @@ pub struct QueryIter<Q> {

impl<Q> QueryIter<Q>
where
Q: Query,
Q: FromQuery,
{
pub(crate) fn new() -> Self {
let mut component_types = Vec::new();
Copy link
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