As far as I understood the multithreading works like if there are some 'spikes' the next 'AddTimer' event can be called before the previous one finished, so this can result in 2 gameloop updates running simultaneously (http://playerio.com/forum/csharp/server-lag-spikes-t2061), and the only way to solve this is via a 'Lock'.
This is a simplified gameloop:
- Code: Select all
void gameloop(timedelta)
{
_fullFrameStartTime+= timedelta;
_lockstepProtocol.update();
for(int i = 0; i < _worldState.entities.Count; i++)
_worldState.entities[i].update(timedelta);
for(int j = 0; j < _worldState.players.Count; j++)
_worldState.players[j].update(timedelta);
}
class entity
{
vector2D _position;
void update(timedelta)
{
_position *= timedelta;
}
}
- what do I need to lock out of these? is it enough if I just lock '_worldState'? or do I have to individually lock each List/Object/Entity/etc that is accessed via the _worldstate?
Ideally, as it is a lockstep deterministic game, everything would need to behave as a single threaded app, and NOTHING should be touched by another thread while the previous state update has not finished completely.
Help?!:)