<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Coder's Block</title><link>https://codersblock.org/</link><description>Recent content on Coder's Block</description><generator>Hugo</generator><language>en-gb</language><lastBuildDate>Fri, 07 Jun 2019 00:00:00 +0000</lastBuildDate><atom:link href="https://codersblock.org/index.xml" rel="self" type="application/rss+xml"/><item><title>Making a Multiplayer FPS in C++ Part 8: Client-Side Prediction Revisited</title><link>https://codersblock.org/multiplayer-fps/part8/</link><pubDate>Fri, 07 Jun 2019 00:00:00 +0000</pubDate><guid>https://codersblock.org/multiplayer-fps/part8/</guid><description>&lt;p&gt;I was lucky enough to go to GDC 2018, and while there I had the pleasure of sitting down with Glenn Fiedler in a really rather swanky tea place. For those not already aware, Glenn is pretty much &amp;ldquo;the netcode guy&amp;rdquo;. If you’re looking on the web for information about netcode and network models, then you’ll almost certainly read &lt;a href="https://gafferongames.com/"&gt;some of his articles&lt;/a&gt;. They contain a lot more detail than most about the actual implementation of the ideas, you can watch all the GDC videos about networking that you like, at some point it’s great to see some actual code. Even the &lt;a href="https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Protocol_Design_and_Optimization"&gt;Barnier paper from 2001&lt;/a&gt; was pretty high level really - you could download the Source Engine source code, but it’ll take a while to get a foothold in a new large codebase. In 2009 when I was in my first job in the industry as a lowly intern, I was tasked with making an MMO client. I’d never even opened a socket at that point, in my googling I found Glenn’s site, I soon got pretty obsessed with netcode, and the rest is history.&lt;/p&gt;</description></item><item><title>Making a Multiplayer FPS in C++ Part 7: The Vulkan Projection Matrix, and Other Graphics Things</title><link>https://codersblock.org/multiplayer-fps/part7/</link><pubDate>Wed, 29 May 2019 00:00:00 +0000</pubDate><guid>https://codersblock.org/multiplayer-fps/part7/</guid><description>&lt;p&gt;In the previous part of the series I mostly did some miscellaneous cleanup. This part unfortunately has no netcode whatsoever - it’s all about graphics (&lt;a href="https://github.com/spectre1989/odin/tree/87247f5f0fd5acd86873e3f3bc8524fcafeced46"&gt;browse code here, it’s not pretty&lt;/a&gt;).&lt;/p&gt;&#10;&lt;h3 id="youre-not-a-graphics-programmer-stupid"&gt;&amp;ldquo;You’re Not A Graphics Programmer, Stupid&amp;rdquo;&lt;/h3&gt;&#10;&lt;p&gt;I’m no graphics guy, but I’m hoping I can still make an acceptable renderer. I’m trying to take a from-scratch approach with this thing, and graphics will be no exception. This means I need to derive the most basic building blocks like projection and transformation matrices, armed only with my B grade in A-Level maths from more than a decade ago. Though you don’t ever really &lt;em&gt;need&lt;/em&gt; to do this sort of thing these days, it’s still (in my view) an interesting and worthwhile exercise.&lt;/p&gt;</description></item><item><title>Client-Side Prediction With Physics In Unity</title><link>https://codersblock.org/posts/unity-client-side-prediction/</link><pubDate>Sat, 14 Apr 2018 00:00:00 +0000</pubDate><guid>https://codersblock.org/posts/unity-client-side-prediction/</guid><description>&lt;h3 id="tldr"&gt;TL;DR&lt;/h3&gt;&#10;&lt;p&gt;I made a demo showing how to do client-side prediction with physics-based player movement in Unity - &lt;a href="https://github.com/spectre1989/unity_physics_csp"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;&#10;&lt;h3 id="update"&gt;UPDATE:&lt;/h3&gt;&#10;&lt;p&gt;&lt;a href="http://www.aran-koning.com/"&gt;Aran Koning&lt;/a&gt; submitted a pull request which improves upon the code in this article using even newer and shinier Unity features. By putting the client and the server cubes in different physics scenes, there’s no need to selectively disable one cube or the other, which causes issues with determinism.&lt;/p&gt;&#10;&lt;h3 id="introduction"&gt;Introduction&lt;/h3&gt;&#10;&lt;p&gt;Back in early 2012 I wrote a blog post about kind-of-but-not-really implementing client-side prediction of physics-based player movement in Unity. That nasty workaround that I described, is no longer necessary thanks to &lt;a href="https://docs.unity3d.com/ScriptReference/Physics.Simulate.html"&gt;Physics.Simulate()&lt;/a&gt;. That old post is still one of the most popular posts on here, but with Unity today, that information is just sort of wrong. So here goes, the 2018 edition.&lt;/p&gt;</description></item><item><title>Making a Multiplayer FPS in C++ Part 6: Cleanup</title><link>https://codersblock.org/multiplayer-fps/part6/</link><pubDate>Thu, 11 Jan 2018 00:00:00 +0000</pubDate><guid>https://codersblock.org/multiplayer-fps/part6/</guid><description>&lt;p&gt;In the previous part of this series, we added client-side prediction. At this point the codebase was getting a bit creaky with all the &amp;ldquo;todo&amp;rdquo; comments in the code, so I took a bit of time to address as many of them as possible (browse the code for this part &lt;a href="https://github.com/spectre1989/odin/tree/6d97c43ddfc0c21d99bb6cb63e332ca28de69fe5"&gt;here&lt;/a&gt;).&lt;/p&gt;&#10;&lt;h3 id="a-circular-buffer-utility"&gt;A Circular Buffer Utility&lt;/h3&gt;&#10;&lt;p&gt;Circular buffers are a great way to avoid dynamic allocation/deallocation, you can usually calculate how many items you&amp;rsquo;d need at maximum and just do a single allocation. There were a few places where I was using one - input buffering on the server, client recording of inputs and predicted results for client-side prediction, and the packet buffers used for faking lag on the client. It would be nice to compress the code common to all three, into some kind of generic utility. The classic template container approach would be something like:&lt;/p&gt;</description></item><item><title>Making a Multiplayer FPS in C++ Part 5: Client-Side Prediction</title><link>https://codersblock.org/multiplayer-fps/part5/</link><pubDate>Sun, 31 Dec 2017 00:00:00 +0000</pubDate><guid>https://codersblock.org/multiplayer-fps/part5/</guid><description>&lt;p&gt;In the previous part of the series, we rebuilt the game client in C++. Now we crack on with the real reason we bothered to do that - &lt;em&gt;&lt;strong&gt;client-side prediction&lt;/strong&gt;&lt;/em&gt;. Currently the &amp;ldquo;game&amp;rdquo; only really works with close to no latency (i.e. client and server running on the same machine or network). Now is the time to introduce some artificial lag, &lt;em&gt;dealing&lt;/em&gt; with that lag is really where netcode gets interesting.&lt;/p&gt;</description></item><item><title>Making a Multiplayer FPS in C++ Part 4: Rebuilding The Client in C++</title><link>https://codersblock.org/multiplayer-fps/part4/</link><pubDate>Mon, 03 Jul 2017 00:00:00 +0000</pubDate><guid>https://codersblock.org/multiplayer-fps/part4/</guid><description>&lt;p&gt;In the previous part of this series we had an outline of an online game with a fixed tick rate, and support for multiple clients to connect and move around. In this part we bin the horrible client made in Unity, and implement one in C++. You can browse the repository at this stage of development &lt;a href="https://github.com/spectre1989/odin/tree/8395cc31bb211a39b2c9553c2728b3c8f06f7934"&gt;here&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;The reason I want to rebuild the client in C++ is that for upcoming work on client-side prediction, we&amp;rsquo;ll need the server and client to have a certain amount of shared code. It&amp;rsquo;s possible to re-implement this shared code in C# for the client, but it would be easier to maintain if we just had one codebase written in C++. Plus I just prefer doing stuff in C++, so there.&lt;/p&gt;</description></item><item><title>Making a Multiplayer FPS in C++ Part 3: Multiple Players</title><link>https://codersblock.org/multiplayer-fps/part3/</link><pubDate>Tue, 30 Aug 2016 00:00:00 +0000</pubDate><guid>https://codersblock.org/multiplayer-fps/part3/</guid><description>&lt;p&gt;In the previous part of this series we ended up with a basic outline of an online game with some very simple game logic, a fixed tick rate, and support for a single connected client. In this part, we&amp;rsquo;ll be adding support for multiple clients. You can see the repository as it was at this stage of development &lt;a href="https://github.com/spectre1989/odin/tree/5fd76d229bef8cbd8c78bf75cb4991a1ad940bdf"&gt;here&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;The first thing we&amp;rsquo;ll need is to actually keep track of the clients who send the server packets. At the moment we store their IP address and port we get from &lt;code&gt;recvfrom&lt;/code&gt;, but now we&amp;rsquo;ll need some kind of list of IP addresses and ports of the clients so they can be sent state packets en masse. For this I created an &lt;code&gt;IP_Endpoint&lt;/code&gt; struct:&lt;/p&gt;</description></item><item><title>Making a Multiplayer FPS in C++ Part 2: The Main Loop</title><link>https://codersblock.org/multiplayer-fps/part2/</link><pubDate>Sun, 21 Aug 2016 00:00:00 +0000</pubDate><guid>https://codersblock.org/multiplayer-fps/part2/</guid><description>&lt;p&gt;The previous part of this series was at best the &amp;ldquo;Hello, world!&amp;rdquo; stage of an online game. Now it&amp;rsquo;s time to actually start actually laying the groundwork.&lt;/p&gt;&#10;&lt;h3 id="the-input-loop"&gt;The Input Loop&lt;/h3&gt;&#10;&lt;p&gt;Back in the day when multiplayer games were only played on a LAN, the clients would collect their user input, and send it to the server. The server would wait until it had the input from all clients, and then tick the game simulation, and send back the new game state. This is viable on a LAN because latency is so low, but it&amp;rsquo;s not workable today, input lag of even a hundred milliseconds would feel sluggish, let alone two or three.&lt;/p&gt;</description></item><item><title>Making a Multiplayer FPS in C++ Part 1: Hello Multiplayer World</title><link>https://codersblock.org/multiplayer-fps/part1/</link><pubDate>Sun, 14 Aug 2016 00:00:00 +0000</pubDate><guid>https://codersblock.org/multiplayer-fps/part1/</guid><description>&lt;p&gt;I write netcode because I love it. The problems that have to be solved in online games are particularly interesting to me - how to hide lag, how to replicate game state, how to compress data to save bandwidth, etc. I&amp;rsquo;ve spent most of my career working on multiplayer games of one sort or another - I built a couple of MMO clients at an indie startup, I was part of the online services team of Total War: Arena, and most recently I was on the network team for Halo Wars 2 DLC. My work has always been confined to just the client, or just services, or just some particular area. It&amp;rsquo;s a necessity of modern game development that you can&amp;rsquo;t do everything (or even some of everything), unless you&amp;rsquo;re at a really small studio. I&amp;rsquo;d like to though, so I&amp;rsquo;m going to try to do it in some small way, and write about it here.&lt;/p&gt;</description></item><item><title>Ditching the Mutex</title><link>https://codersblock.org/posts/ditching-the-mutex/</link><pubDate>Thu, 02 Jun 2016 00:00:00 +0000</pubDate><guid>https://codersblock.org/posts/ditching-the-mutex/</guid><description>&lt;p&gt;TL;DR - I wrote a multiple-producer multiple-consumer queue without any mutexes, it&amp;rsquo;s pretty fast, &lt;a href="https://github.com/spectre1989/fast_mpmc_queue"&gt;GitHub&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;About a year ago, a colleague was explaining why Erlang is so scalable, and it essentially comes down to a lack of shared memory. When you have two or more threads which share a section of memory, then whenever a thread is writing to that memory, no other threads can perform a read or write at the same time. This can result in code spending too much time waiting for the shared memory to be available for reading/writing, and therefore poor performance.&lt;/p&gt;</description></item></channel></rss>