2023-05-22 13:44:23 +00:00
|
|
|
* Client-Side-Prediction-Test
|
|
|
|
An example of client-side prediction for networked games, as research and
|
|
|
|
training for 'Spacewar!'
|
|
|
|
|
|
|
|
** What is this repository for?
|
2023-07-12 22:56:48 +00:00
|
|
|
I realized that the current net-code of Spacewar was fine for simply running two
|
2023-05-22 13:44:23 +00:00
|
|
|
instances of the game on the same computer; but it would not hold up to
|
|
|
|
latencies of actual networks nor would it be able to do any structured
|
|
|
|
communication due to being entirely over UDP. I knew this when writing it, but I
|
|
|
|
needed to learn how to do it properly first. Hence, this repository. I will be
|
|
|
|
keeping notes on the techniques and a devlog as I come up against any issues.
|
2023-05-22 14:19:21 +00:00
|
|
|
|
|
|
|
* Developer's Log:
|
|
|
|
** Entry 00: Intentions:
|
|
|
|
I intend to build a simple networked "game" where players can join a server
|
|
|
|
using a client, and then move around in an empty 2D space where they can see
|
|
|
|
other players. I intend to have the positional data transmitted over UDP, and
|
|
|
|
command data transmitted over TCP, such as allowing the connection and
|
|
|
|
disconnection of players. This simulation must be relatively resistant to
|
|
|
|
latency issues, and must be reasonably smooth.
|
|
|
|
|
|
|
|
This will provide a simple enough simulation to learn the techniques, while also
|
|
|
|
being similar enough to "Spacewar!" so that it's not too big of a stretch to
|
2023-07-12 22:56:48 +00:00
|
|
|
update that project's net-code. It may be cute to have this be some sort of chat
|
2023-05-22 14:19:21 +00:00
|
|
|
program, but that's another project for another day.
|
|
|
|
|
|
|
|
For now, circles moving around in an empty space that move smoothly over network
|
|
|
|
connections is the goal. Let's get started!
|
|
|
|
|
|
|
|
** Entry 01: First Steps:
|
|
|
|
I think my first step will be creating the TCP portion of the client-server
|
|
|
|
interaction. This should be relatively trivial, so I can get right to it. Simply
|
|
|
|
transmitting a few integers back and forth will do well.
|
|
|
|
|
2023-07-09 00:15:05 +00:00
|
|
|
** Entry 02: TCP & UDP basics completed:
|
|
|
|
The TCP portion is completed, and I have also created a basic simulation which
|
|
|
|
is based on the model that is described in the first article in the series, and
|
|
|
|
the model which "Spacewar!" currently uses. Time to start work on actual client
|
|
|
|
side prediction and other techniques.
|
|
|
|
|
|
|
|
** Entry 03: That seems far too easy:
|
|
|
|
Simply duplicating the server's game thread seems to meet the concept of client
|
|
|
|
side prediction described in the second article. I'd imagine there's still a lot
|
|
|
|
more to deal with, but we'll see how much of a difference this makes to how it
|
|
|
|
feels. I'll report back.
|
2023-05-22 14:19:21 +00:00
|
|
|
|
2023-07-09 00:30:58 +00:00
|
|
|
** Entry 04: Whoops, little oversight!
|
|
|
|
I didn't make the client update it's own input in the state constantly, so there
|
|
|
|
wasn't the required "single-player" feeling in the client. Not exactly what
|
|
|
|
we're going for, here!
|
|
|
|
|
2023-07-09 16:45:51 +00:00
|
|
|
** Entry 05: How client side prediction performs:
|
|
|
|
After running a basic test on my LAN, it appears as if my naive implementation
|
|
|
|
isn't performing as expected. It's possible that just spamming the client with
|
|
|
|
packets that aren't tied to the game tick is causing it; I'm going to change
|
|
|
|
that. It probably should have been done that way from the start; but I didn't
|
|
|
|
really think about that.
|
|
|
|
|
2023-07-12 22:56:48 +00:00
|
|
|
** Entry 06: Fixed it!
|
|
|
|
Tying it to the game ticks made it much better. Packet spam was not the way to
|
|
|
|
go, and I should have realized that had I thought about it more. I'm now going
|
|
|
|
to work on improving the client and separating out the techniques so at the end
|
|
|
|
just by changing preprocessor statements you'll be able to see the effects of
|
|
|
|
each technique.
|
|
|
|
|
2023-05-22 14:19:21 +00:00
|
|
|
* Notes On Techniques:
|
|
|
|
** Entry 00: Where I'm Learning All This From:
|
|
|
|
I'm using a series of articles from gabrielgambetta.com, which seem to be well
|
|
|
|
written, and reasonably clear. (So big thanks, Gabriel!) I intend to note my
|
|
|
|
understanding as I progress through these articles (while simultaneously
|
|
|
|
implementing them), and therefore provide a more practically based version of
|
|
|
|
the information. Will it be better? Possibly, though unlikely!
|
|
|
|
|
|
|
|
[[https://www.gabrielgambetta.com/client-server-game-architecture.html][Fast-Paced Multiplayer by Gabriel Gambetta]]
|