Skip to content
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

Broken ContainerScreen / CharacterComponent's interaction targets out of sync #4838

Open
skaldarnar opened this issue Aug 8, 2021 · 0 comments
Labels
Multiplayer Affects aspects not visible in Singleplayer mode only Topic: UI/UX Requests, Issues and Changes related to screens, artwork, sound and overall user experience Type: Bug Issues reporting and PRs fixing problems

Comments

@skaldarnar
Copy link
Member

skaldarnar commented Aug 8, 2021

Problem

In a multiplayer scenario the ContainerScreen is not working properly for remote clients.

This behavior is non-deterministic.

  • ✔️ Sometimes the interaction works as intended, i.e., the container screen shows both the player inventory and the inventory of the interaction target

  • ❌ Sometimes the inventory of the interaction target cannot be displayed correctly. Often, the container screen briefly flickers with the correct amount of inventory cells (although without content) before it vanishes. The screen does not update afterwards.

    Peek.2021-08-08.23-07.mp4

Clues

Found with https://github.com/MovingBlocks/Terasology/releases/tag/v5.1.1 but likely present before.

Such a broken screen can just be closed by hitting ESC. Upon re-interaction with the same target the screen shows up correctly.

For container screens such as chests the correct behavior can be forced by hitting the respective block once before interacting with it.

The ContainerScreen uses the CharacterComponent#predictedInteractionTarget to show the inventory of the interaction target.

/**
* This field is only set for clients (including clients that are servers). The clients set it
* best to their knowledge.
* <br><br>
* The events {@link InteractionStartPredicted} and
* {@link InteractionEndPredicted} inform about changes of this
* field.
*/
public EntityRef predictedInteractionTarget = EntityRef.NULL;

In a multiplayer scenario, there can be different entities associated with the same block (position).
The source of truth is the authority system, but clients may have local placeholder entities.
In the EntityAwareWorldProvider we destroy such placeholder entities for block entities.

@ReceiveEvent(components = BlockComponent.class)
public void onActivateBlock(OnActivatedComponent event, EntityRef entity) {
BlockComponent block = entity.getComponent(BlockComponent.class);
EntityRef oldEntity = blockEntityLookup.put(block.getPosition(new Vector3i()), entity);
// If this is a client, then an existing block entity may exist. Destroy it.
if (oldEntity != null && !Objects.equal(oldEntity, entity)) {
oldEntity.destroy();
}
}

Even though the binding in the container screen is re-evaluated with every tick it seems the predicted interaction target is never updated on the CharacterComponent to adjust for the destroyed entity/use the actual entity that was interacted with.

Attempts

The CharacterComponent offers another interaction target, the authorizedInteractionTarget. Although clients shall not modify it, they are allowed to read it.

/**
* The current interaction target of a character which has been authorized by the authority (e.g. the server).
* <br><br>
* Modules should not modify this field directly.
*/
public EntityRef authorizedInteractionTarget = EntityRef.NULL;

Not knowing about the implementation details we attempted to use the authorized target, if present, and only use the predicted target as fallback. Unfortunately, that did not help, and we could still observe the faulty behavior quite frequently.

if (characterComponent.authorizedInteractionTarget.exists()) {
    return characterComponent.authorizedInteractionTarget;
} else {
    return characterComponent.predictedInteractionTarget;
}
@skaldarnar skaldarnar added Type: Bug Issues reporting and PRs fixing problems Topic: UI/UX Requests, Issues and Changes related to screens, artwork, sound and overall user experience Multiplayer Affects aspects not visible in Singleplayer mode only labels Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Multiplayer Affects aspects not visible in Singleplayer mode only Topic: UI/UX Requests, Issues and Changes related to screens, artwork, sound and overall user experience Type: Bug Issues reporting and PRs fixing problems
Projects
None yet
Development

No branches or pull requests

1 participant