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

explore how to rewind ECS world state #40

Open
mreinstein opened this issue Feb 14, 2024 · 2 comments
Open

explore how to rewind ECS world state #40

mreinstein opened this issue Feb 14, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@mreinstein
Copy link
Owner

this is something that is useful for client prediction and lag compensated shots, where the world state needs rewinding.

currently this is possible on a per-component basis, you can store all the data for <n> frames:

const e = ECS.createEntity(world)

// store position data for the last 60 frames
const positions = new Array(60) 
for (let i=0; i < 60; i++)
        positions[i] = vec2.create()

ECS.addComponentToEntity(world, e, 'lagCompensated', {
    positions
})

This is a little cumbersome though; you have to manually walk through each component and grab the data you're interested in. It would be really nice if there were a more convenient interface, something like:

const  w = ECS.rewindTo(world, tick)

// w is now pointing at what was in the ECS world at simulation tick <tick>
const pos = ECS.getEntity(w, [ 'hero' ]).transform.position

It's unclear if this would be better to offer as a feature internal to this ecs, or if it should be in some wrapper layer.

@mreinstein
Copy link
Owner Author

mreinstein commented Feb 14, 2024

There's a lot of questions this idea raises:

  • does the entire ECS world just get stored per tick? or is there some way to register intent and only store certain entities/components per tick in the collection?
  • is there some way of making a change to a previous tick, and then simulating forward? going back to the input prediction, one needs to rewind back to a specific tick where we received authoritative server input, and then simulate forward to the current tick. would this be handled implicitly by a simulate forward function, or is that left to the implementor?

@mreinstein
Copy link
Owner Author

mreinstein commented Feb 14, 2024

Valve's engine has a feature for lag compensation where you can do things in fenced areas:

Simply wrap whatever code you want lag compensated within two calls to the lagcompensation object:

void CMyPlayer::FireBullets ( const FireBulletsInfo_t &info )
{
	lagcompensation->StartLagCompensation( this, LAG_COMPENSATE_HITBOXES );

	BaseClass::FireBullets(info);

	lagcompensation->FinishLagCompensation( this );
}

Time will be wound back on the call to StartLagCompensation(), and wound forward again on the call to FinishLagCompensation().

@mreinstein mreinstein changed the title explore how to store ECS world state per game tick explore how to rewind ECS world state Feb 27, 2024
@mreinstein mreinstein added the enhancement New feature or request label Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant