Game Programming S2 E02 – Multiplayer Servers


Source Code ►

Twitter ►
Slack ►
Stream ►
Website ►
Facebook ►

Want more? You can help out by supporting me on Patreon!


Steam Group:


Outro music is by Approaching Nirvana:


Xem thêm bài viết khác:


  1. I heard OOP was bad (thanks youtube) and now i'm worried of designing a game in OOP instead of procedural…
    any tips on how to do solve problems without OOP Cherno???

  2. I feel pretty confident that setters are created in order to make sure that a member variable does not have a wrong value which could cause unhandled problems within member methods.

  3. So in probably to stupid to do matrix multiplication my code looks like this:
    void matrix :: mulitplicate (GLdouble [16] )
    char x,a,b;
    for(x=0; x < 16; ++x)
    a = x % 4; b = (x/4) * 4;
    tm[x] = nm[a] * mx[b] + nm[ a + 4] * mx[b+1] + nm[a+8] * mx[b+2] + nm[a+12] * mx[b+3];
    for(x=0;x<16;++x) mx[x] = tm[x];

    Two prerequisites
    First it must be done with an one dimensional array
    Two it should work without pointers

  4. The whole idea behind private variables was hiding state from external code, at least in the cases where you have to control how it gets accessed; for example, if you're only allowed to increment a variable you should have it private with a getter and an increment method (but no setter). Except most OOP programmers think that everything should have a getter and a setter to "control" access to a variable; in reality they just write a few extra lines because they've heard something vaguely similar being mentioned as good practice before. If your getter and setter are doing the same thing as having a public method, you're NOT controlling access to a variable and you're NOT hiding state. All you're doing is making the state more of a pain in the ass to deal with when it needs to be dealt with and exposing it in places where it shouldn't be dealt with. It really annoys me how so many programmers just blindly sit there and write getters/setters because they heard it was a good idea without even considering what it does or why people say to do it.

  5. Hey Cherno, just wondering: You planning on doing anything video wise with C++ soon? If not, I would love it if you could at least consider it!

  6. totally agree on getters and setters (just watching for listening to something while doing other stuff :D) and could you please change to a dark theme?

  7. I think it's great to ear your opinions about coding practices and why you write code the way you do =)

  8. IMO, in java a Getter is almost always useful because you can use it as method reference for a Comparator or something. But to be honest I almost never use setters so I mostly go with private with a getter

  9. One thing with getters and setters is you are guaranteed a consistent way to interact with the classes in your project. For example, if I was writing a complex number class which stored the real and imaginary parts I would use getters and setters for those because I can then write other functions which are like the getters but compute the result rather than just returning the variable. For example if you wanted Arg(z) then you'd use complex.getArg() in the same way as complex.getImg() or complex.getRe(). Since there is practically no hindrance on performance I'd argue that this consistency and ease of understanding is better than saving 8 or so lines in the complex class

  10. As for the getter/setter thing. Me from when I first watched your videos was probably one of the guys going "Why does he make class fields public?", as I was in my first year of University, and being taught the dogma of "You MUST keep class fields private." These days I see it more a guideline than a strict rule.

    In OO code, you want to try and keep details of the class internal to the class, but this is not always practical. If you find that you are writing getters and setters for a class, than you may as well make it public, unless those getters and setters do some bounds checking or something (which is where C#'s Properties shine).

  11. The point in getters/setters is, there are some situations where you dont want the programmer to have access to a specific field. For example if you have a server: You can't change the port after server initialization so you're creating a getter for the port field but not a setter because that would make no sense. For another example, if you want to notify a listener for a changed value you just need to implement the "listener-notification-code" under the setter, when using public fields you have to manage it somehow otherwise.

  12. I definitely love when programmers talk about their personal styles and preferences, keep it up 🙂

  13. When you create the listener thread, instead of using lambdas, you could also use method references which are new in Java 8.

    Lambda: listenThread = new Thread(() -> listen());

    Method reference: listenThread = new Thread(this::listen);

    Does the same thing, but looks a bit nicer in my opinion =)

  14. The thing I dont like is that you are ranting about wether or not to use getters and setters or make the variable public, and not making the server stuff and explaining it on the way. If I want to know what the 'best' way is to program in java, ill look it up, and I'm watching your series to learn how to make a server.

  15. I am with this dilemma. Java game programming seems easy, but games get laggy quick. using LWJGL seems more professional and way better optimized. using the GPU. but learning LWJGL is annoying with all the tutorials outdated and all the little things that need to be done.
    Going with a different programming language could work but you may run into other problems.
    Any suggestions to a way to make a good game?

  16. I thought you would create a new game with less shitty code so it's a little bit more neat etc. And possibly in C++ or using LWJGL or something.. 🙁

  17. Getting the server set up….love it! For those who've strayed ridiculously from TheCherno's original code (like I've done for my own single-player games), maybe do what I'm doing and get on Patreon to download all the original code so you can follow along this new season. Exciting stuff!!



Please enter your comment!
Please enter your name here