Processing inputs right away

Started by
4 comments, last by Farkon 11 years, 2 months ago

Hello,

I was reading some Carmack updates about the QuakeWorld development here : http://fabiensanglard.net/quakeSource/johnc-log.aug.htm

And that part made me think about how to process inputs :

Instead of expecting everyone's messages to be dealt with at once, I now
deal with each packet as it comes in. That player alone is moved forward
in time, and a custom response is sent out in very short order. The rest
of the objects in the world are spread out between the incoming packets.
There are a lot of issues that that brings up. Time is no longer advancing
uniformly for all objects in the world, which can cause a lot of problems.

It works, though! The average time from a packet ariving at the system to
the time a response is sent back is down to under 4ms, as opposed to over
50 with the old dedicated servers.

In my projects I usually have a big server loop, processing all the received messages and sending back "independently" the server updates to all the players.

It works but indeed, as he said, it adds some latency if you process the messages at 30 or 60fps but I always just dealed with it; now i'm wondering how you handle cheat with this kind of architecture.

The issue being cheaters trying to speedhack by just sending packets at a different expected rate. Do you average the number of packets received from the client and try to consume them at an arbitrary rate ?

Is it a good route to take ? Any drawback ?

Advertisement
Personally, I don't like the "everyone moves when their packets come in" mechanism. It may move for certain fast-paced games with little physical interaction between entities, but it is inherently nondeterministic and doesn't work well at all for multi-entity interactions (e g two rolling balls colliding or whatever.)
enum Bool { True, False, FileNotFound };
I'm with hplus.

This is a technique that can be useful for certain types of simulation, but for anything with nontrivial physics, it's a bloody nightmare.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Thanks for the help.

I thought more about how to process MY inputs and i need a few enlightments :

The client is sending ~2 frames per packet.

What i used to do in my other projects is checking on the server if there are datas to dispatch, if so, call movePlayer() or throwArrow() and since i'm having 2 frames i was sometimes calling throwArrow() twice in a row.

But right now i'm using an entity/component architecture, the same as T=Machine where an entity can only have one component type. So when i'm receiving a client packet about throwing arrows the networkSystem would attach a CThrowArrowEvent component to my client entity and then the event would propagate through all my systems.

That's my server loop :


timerSystem.processOneGameTick();
networkSystem.processOneGameTick();

roomSystem.processOneGameTick();
inputSystem.processOneGameTick();
actionSystem.processOneGameTick();
repairSystem.processOneGameTick();
towerDetectorSystem.processOneGameTick();
towerActionSystem.processOneGameTick();
lineSystem.processOneGameTick();
energySystem.processOneGameTick();
healthSystem.processOneGameTick();

characterMovementSystem.processOneGameTick();
characterPositionSystem.processOneGameTick();

networkOutSystem.processOneGameTick();
 

So if i'm having two events in the same packet about throwing arrows, i can't just attach 2 events to my player entity as soon as i'm processing the packet since my entityManager structure doesn't allow it.

I would like to avoid changing my entityManager but i'm not sure what method would fit the best my architecture.

I could make one server loop per packet frame for all the players which mean that i would make two loops in a row independently of my server fps. I would still send back datas at regular interval. How does that sound ?

Typically, events are time stamped, which means that you will only dispatch/attach events for a particular time stamp during a particular loop through your simulation loop. The other event would wait in a queue until its time stamp comes up, and be handled at that time.
enum Bool { True, False, FileNotFound };

I have no idea why i thought it would be different from what i was doing, i actually had a bug when spamming an action key would cumulate latency, so i started from that and made wrong premises. Thanks putting me on the right track :3

(I actually have more questions but i'll make another thread);

This topic is closed to new replies.

Advertisement