Skip to content

[Merged by Bors] - feat: reimplement stomp boots#595

Closed
legendiguess wants to merge 1 commit intofishfolk:mainfrom
legendiguess:reimplement-stomp-boots
Closed

[Merged by Bors] - feat: reimplement stomp boots#595
legendiguess wants to merge 1 commit intofishfolk:mainfrom
legendiguess:reimplement-stomp-boots

Conversation

@legendiguess
Copy link
Copy Markdown
Collaborator

@legendiguess legendiguess commented Feb 2, 2023

No description provided.

@legendiguess legendiguess requested a review from zicklag February 2, 2023 07:26
@legendiguess legendiguess self-assigned this Feb 2, 2023
Copy link
Copy Markdown
Member

@zicklag zicklag left a comment

Choose a reason for hiding this comment

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

Left a comment about the entity comparison and how that plays into the bigger picture a little.

Let me know if you need more clarification over chat. It's something I'd like to improve the ergonomics/confusingness of later I think.

);
}

attachments_to_remove.iter().for_each(|ent| {
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.

I think it'd be better to remove attachments when the player despawns in the player event handler here:

https://github.com/fishfolk/jumpy/pull/595/files#diff-f883183ceb48d98a583aa8dfaad668ac21a6af3307db17218f4dc5ed8532f65fR123

inventories.insert(entity, default());

for (attachment_entity, attachment) in entities.iter_with(&mut attachments) {
if attachment.entity.index() == entity.index() {
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.

Entities should be able to be compared directly without comparing their indexes. That is also important to make sure that they don't have the same index but a different generation.

After testing I can see where the issue with just comparing th entities is.

So, when comparing the entities directly, the reason that this doesn't end up deleting the attachment is because when the player is killed, the old entities dies, and he spawns with a new entity. So even though the entity happens to have the same index, it is actually a new entity.

Then we run into the question of why the attachment continues to follow the newly spawned player when it has a different entity. This has to do with a nuance in the way bones_ecs works.

When you do atlas_sprites.get(entity), unfortunately, it only checks the entity index, and if it finds component data at that index, it returns it. So if we have an entity such as attachment.entity, and that entity has been killed, the only way for us to know is if we manually check !entities.is_alive(entity) before we call atlas_sprites.get(entity). So technically, we should, in the attachment system, check that the entity is still alive, before attaching to it.

That would mean that the attachment would behave properly and just stop moving, if the entity it was attached to is killed.


Then, if we want to fix the attachment despawning issue, we just need to despawn the attachments for a player when he is despawned in the handle_player_events system, not when he is respawned. That way, the player entity is still alive, and we do proper entity comparison to find it's attachments, right before killing the player entity.

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.

Here's an issue I just opened that gives an overview of the confusing aspect of entity liveness: fishfolk/bones#82.

@zicklag zicklag mentioned this pull request Feb 2, 2023
6 tasks
@zicklag
Copy link
Copy Markdown
Member

zicklag commented Feb 3, 2023

Awesome, thanks!

bors merge

bors bot pushed a commit that referenced this pull request Feb 3, 2023
@bors
Copy link
Copy Markdown
Contributor

bors bot commented Feb 3, 2023

Pull request successfully merged into main.

Build succeeded:

@bors bors bot changed the title feat: reimplement stomp boots [Merged by Bors] - feat: reimplement stomp boots Feb 3, 2023
@bors bors bot closed this Feb 3, 2023
@legendiguess legendiguess deleted the reimplement-stomp-boots branch February 8, 2023 16:17
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