Skip to content

Client Component Division #266

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

Merged
merged 31 commits into from
Mar 11, 2023
Merged

Client Component Division #266

merged 31 commits into from
Mar 11, 2023

Conversation

rj00a
Copy link
Member

@rj00a rj00a commented Mar 3, 2023

Description

Divides the Client component into a set of smaller components as described by #199 (with many deviations). McEntity will be dealt with in a future PR.

  • Divide Client into smaller components (There's a lot to look at).
  • Rename McEntity to Actor to avoid confusion between ECS entities and Minecraft entities.
  • Move common components to component module.
  • Remove Username type from valence_protocol because the added complexity wasn't adding much benefit.
  • Clean up the inventory module.

I've stopped worrying about the "Effect When Added" and "Effect When Removed" behavior of components so much, and instead assume that all components of a particular thing are required unless otherwise stated.

Blocked on:

Test Plan

Steps:

  1. Run examples and tests.

A large number of tweaks have been made to the inventory module. I tried to preserve semantics but I could have made a mistake there.

@dyc3
Copy link
Collaborator

dyc3 commented Mar 3, 2023

I very much don't like renaming McEntity to Actor. I feel like the confusion between Entity and McEntity can be very easily remedied with proper doc comments. Do we really get questions/see confusion about it often?

@qualterz
Copy link
Contributor

qualterz commented Mar 3, 2023

I very much don't like renaming McEntity to Actor.

Yeah, Actor may sound too abstract but on the other hand McEntity too verbose.

@qualterz
Copy link
Contributor

qualterz commented Mar 3, 2023

Maybe confusions should be avoided by leveraging namespaces like mc::Entity and ecs::Entity?

@dyc3
Copy link
Collaborator

dyc3 commented Mar 3, 2023

McEntity is not too verbose. Using namespaces like that almost certainly makes the problem worse.

@AviiNL
Copy link
Contributor

AviiNL commented Mar 3, 2023

In my humble opinion, the valence project interfaces at least for a user to minecraft first, bevy last, so i would probably use Entity for a minecraft entity, and re-export the bevy entity to something like BevyEntity. Or have them both as Entity and leave it up to the user to qualify it, either with an as keyword in the use statement, or qualify in-line where needed.. point being, both are entities, so why not just call them that?

@qualterz
Copy link
Contributor

qualterz commented Mar 3, 2023

Also, the invention of new terms would be better to avoid, because it's additional cognitive load for newcomers.

@rj00a
Copy link
Member Author

rj00a commented Mar 4, 2023

I'll just revert the McEntity -> Actor change.

In my humble opinion, the valence project interfaces at least for a user to minecraft first, bevy last, so i would probably use Entity for a minecraft entity, and re-export the bevy entity to something like BevyEntity.

Not sure that's feasible with the way imports/exports work in Rust. We're re-exporting bevy_app and bevy_ecs at the root of valence, so the BevyEntity name would only be available in our prelude? But then we wouldn't be able re-export the bevy prelude in our prelude easily without something like Haskell's hiding.

Or have them both as Entity and leave it up to the user to qualify it

That would make using valence::prelude unpleasant IMO.

@rj00a rj00a changed the title Component Division Client Component Division Mar 6, 2023
dyc3 and others added 4 commits March 6, 2023 15:08
## Description

Makes it so that unit tests build. Does not make any changes to make
them pass.

## Test Plan

Steps:
1. `cargo test -p valence --tests`

#### Related

targets #266
## Description

- update assert_packet_count with better fail message
- fix failing inventory unit test

## Test Plan

Steps:
1. `cargo test -p valence --tests`
2. see that all inventory tests pass
@dyc3
Copy link
Collaborator

dyc3 commented Mar 8, 2023

I'm getting some ridiculous rubber banding when running all of the examples. The packet inspector shows really big client bound packets at regular intervals. I think that chunks keep getting sent to the client when they aren't needed? Not really sure

dyc3 and others added 2 commits March 8, 2023 10:10
- fix duplicate Inventory component being placed on clients
- fix playground extras
- fix chest example so it builds
- fix building example
- fix bench players

## Description

Describe the changes you've made. Link to any issues that this PR fixes
or addresses.

## Test Plan

Explain the steps necessary to test your changes. If you used a
playground, include the code in the details below.

Steps:
1.

<details>

<summary>Playground</summary>

```rust
PASTE YOUR PLAYGROUND CODE HERE
```

</details>
@rj00a
Copy link
Member Author

rj00a commented Mar 9, 2023

I'm getting some ridiculous rubber banding when running all of the examples.

This is caused by modifications to player position, yaw, pitch, in the packet handler triggering change detection for those components. A system later picks up on those changes and sends a teleport packet. We aren't distinguishing changes made by clients and changes made by users.

Some possible solutions:

  1. Bypass change detection in the packet handler. To detect movement you need to listen for player move events instead. I'm not happy with this because:
    • Potential footgun when using Changed<Position> in user code.
    • A lot of systems that listen for movement likely only care about the final position of an entity or client and not any of the intermediate steps that tick. Emulating that with events is painful.
    • Position components on entities and position components on players cannot be treated uniformly in some situations.
  2. Store a boolean in the Position, Yaw, Pitch components indicating when a change is made by users. Guard the inner value with a setter. This works, but now you've got useless booleans on every entity when it's only needed on clients. The boolean gets included in your queries even if you don't need it, degrading query performance.
  3. Store the client's desired position and direction in separate components from its real position and direction. Compare real and desired at the end of the tick. If they don't match, then desired := real and a teleport occurs.

Option 3 seems like the best but maybe there's a better way. What do you think?

@dyc3
Copy link
Collaborator

dyc3 commented Mar 9, 2023

I concur, I think option 3 seems best.

@rj00a rj00a marked this pull request as ready for review March 11, 2023 13:16
@rj00a rj00a merged commit b46cc50 into main Mar 11, 2023
@rj00a rj00a deleted the component-division branch March 11, 2023 14:04
@rj00a rj00a mentioned this pull request Mar 19, 2023
3 tasks
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.

4 participants