Making Minecraft, but the server can have UNLIMITED threads (almost)

Поділитися
Вставка
  • Опубліковано 7 тра 2024
  • In this video, I will talk about how I optimized the server for my Minecraft C++ clone
    #cpp #gamedev #multiplayer #minecraft
    Join my Discord:
    / discord
    Wishlist Midnight Arrow:
    store.steampowered.com/app/23...
    Join this channel if you want to support me 😻:
    / @lowlevelgamedev9330
    Music:
    Evan King - Everything is Okay
    / contextsensitive
    contextsensitive.bandcamp.com/
    Minecraft soundtrack: C418 - Haggstrom
    Minecraft soundtrack: C418 - Aria Math

КОМЕНТАРІ • 87

  • @marklisjak2740
    @marklisjak2740 20 днів тому +77

    The same second i finished watching the last minecraft clone video you drop a new video. Keep up the good work!

    • @lowlevelgamedev9330
      @lowlevelgamedev9330  20 днів тому +18

      fuck now I need to make a new one in like 2 minutes 😭😂

    • @marklisjak2740
      @marklisjak2740 20 днів тому +5

      Do it please i think we can all agree they are great!😊

    • @BlatentCheater
      @BlatentCheater 20 днів тому +1

      yo llgd can you make a tutorial on multiplayer game with features like chat and stat saving? Im too dumb to do it lmao.

  • @LuaanTi
    @LuaanTi 19 днів тому +30

    In my old Minecraft clone attempt, I decoupled the entities from chunks too; it can get really painful when entities habitually cross chunk boundaries - such as exactly in the crazy chicken farm in your example. And of course, you don't want the _player_ to have to think about chunk boundaries if you can help it. Quadtrees can be much more stable, and allow you to keep your worker threads actually working, since you don't have to assign individual chunks (which 99% of the time have nothing to actually compute) and instead, you try to balance the quadtree nodes to have similar amount of computation (in this case, mostly just entities, but you also want to support active blocks most likely). At the same time, the way the quadtrees are made, you can still have fairly simple random access and storage, and decreasing or increasing "resolution" is relatively cheap (you definitely want to have a sort of hysteresis, though, to make sure you don't go there and back again every frame).
    Mind, chunks work reasonably fine too; my main motivation was to make proper synchronization reliable. Chunks make things like duping almost unavoidable (and fairly trivially predictable) without massively compromising performance, especially in multiplayer. It's crazy how many games still have to resort to silly solutions like "two people can't open the same chest at the same time" :D And they're still probably by far the _simplest_ way to build worlds like this. Simplicity is a huge boon.

    • @chriss3404
      @chriss3404 16 днів тому

      I'm curious, did your use of quadtrees impact the networking side of things (specifically compression) for your clone?
      I know that Minecraft uses palette-based compression for chunks. What approach did you take (& why pls :) )?

    • @LuaanTi
      @LuaanTi 16 днів тому +1

      @@chriss3404 No, this was strictly server-side stuff; the client worked on chunks and received full chunks for just the blocks from the server, as well as a list of "potentially visible" entities.
      I experimented with a few approaches to compression, but ultimately Gzipping the palettised data was already way better than my target and very simple. Some of the approaches I tried had much better performance or compression, but in the end, it was mostly a waste of time, honestly :D It would have been awesome if we were still on 56k internet, though.
      My current project uses a more complicated system, but it also isn't just about chunks of voxels, and is designed for decently realistic geology. It's also still buggy as hell :D Every time I have to work with it painfully reminds me of how ridiculously easy a simple heightmap or voxel world is in comparison.

  • @user-uq8lz9oq4i
    @user-uq8lz9oq4i 19 днів тому +30

    You thought about adding lods? There's a mod called Distant Horizons for Minecraft which adds just that. The mod is kinda crazy as it lets you do render distances like 512 without basically any major performance penalty. Do recommend you give it a look

    • @viper_exe_
      @viper_exe_ 17 днів тому +7

      the Voxy mod is a much better solution. It performs better, looks better, and has practically no overhead. While at the same time being much less of a headache to get working for this minecraft clone.

    • @user-uq8lz9oq4i
      @user-uq8lz9oq4i 17 днів тому

      @@viper_exe_ Wow, did not even know this mod existed. Thanks!

  • @dan2800
    @dan2800 18 днів тому +6

    You are making basically folia (paper mc shot at making Minecraft multithreaded) implementation of splitting chunks into threads without hopefully like 40-60% overhead of java

  • @JerryThings
    @JerryThings 15 днів тому +2

    I'd be interested in seeing how it scales with more and more simulated players 100, 500 and 1000, where about 25% of them explore the world and load chunks. Love this series!

    • @lowlevelgamedev9330
      @lowlevelgamedev9330  15 днів тому +1

      well I still have to move world generation to another thread and for now sending packets is not optimized so it's a bottle neck but well see

  • @Kajetanv22
    @Kajetanv22 19 днів тому +7

    Could you create a highly technical video discussing caching and multithreading in C++? One of the challenges I encounter with C++ is the abundance of options and varying approaches adopted by different developers. Recently, a friend shared a video from a conference where the speaker said that jthreads are preferable 99% of the time. BTW, I had an interview with Nvidia's DLSS team where I was tasked with designing and implementing a simplified cache (20 min for it), only problem for me was just writing in modern cpp STL (I prefer to have my implementations and use them). You have great videos! :)

  • @Mormert
    @Mormert 20 днів тому +13

    Thanks for the Midnight Arrow steam key ;)

  • @sharokhkeshawarz2122
    @sharokhkeshawarz2122 20 днів тому +1

    Oh boy you give me so much inspiration! Love your videos keep it up man!

  • @fudjinator
    @fudjinator 19 днів тому +4

    if you are concerned about it being slow to move entities to a new chunk you can just make each entity only move its own chunk ownership when its position in chunk space is larger than the size of the chunk, and the check can just be done within whatever method is used to change the position of the entity. For instance if the entities position in "chunk space" is 15.5 8 we know the entity has now "left" the chunk since the max block index in chunk space along x is 15 so the entity can be marked to move to a new chunk.

    • @lowlevelgamedev9330
      @lowlevelgamedev9330  19 днів тому +4

      well actually that's what I do, in the end it is just a few extra checks per entity so it shouldn't be that bad, thanks 💪

    • @oliverbiwer4300
      @oliverbiwer4300 19 днів тому +1

      this can still become tricky. what if your chicken wanders to a currently in-active chunk? what if it wanders diagonally into a region that is loaded by another thread. how does it even know that this movement is allowed? (that there is no block that prevents the movement)
      what if you have 3 chunks in a row, the left chunk is handle by thread A because a player is somewhere in the left side doing stuff. it is full of pig. the right chunk is handled by thread B, because a player is somewhere in the right and the chunk is full of chicken. the center chunk is inactive since it is too far away from both players. now you have pigs walking across the chunk borders and chickens walking across the chunkborders and suddenly both threads need to lock this foreign chunk a few times to transition their animals into it.
      also later the animals need to check if they even can leave the chunk since there are animals piling up at the inactive chunk border !? or maybe same level of worse-ness: when an animal wanders into an unloaded chunk this chunk will be loaded for a few seconds, to not have them pile up, but now ... which thread handles this chunk? or maybe better: in this case the chunk regions count as "connected" and will be merged!?

    • @fudjinator
      @fudjinator 19 днів тому

      ​@@oliverbiwer4300 This is also why I suggested marking it to moving and designating the work later (eg. when the requested chunk is valid). If the chunk isn't valid yet we can consider the current chunk as the fallback and the entity can load in with a slight error.
      In practice when I make my chunks I try to separate it into modules for each purpose for this very reason. Hence the entities can be put into entity chunk groups with a chunk position while the actual chunk data and mesh may not exist yet, but it doesn't matter because these "entity groups" already do, and if they don't I can just create it on the fly in the same thread, since its trivial to make a list opposed to generating thousands of blocks.
      As for which thread "owns" the chunk I don't think it matters. Just let one thread win and when its done the other thread can stop waiting and do its work after. Of course this is using a mutex but I think it's fine in this scenario since the work is trivial and not often.

  • @limieon
    @limieon 7 днів тому

    Those videos always motivate me and bring me to continue working on my voxel "engine" but everytime I do, I see how hard it is and wanna switch to Unreal

  • @Noe_
    @Noe_ 19 днів тому +3

    I think this is a similar implementation to the folia project by paper mc. Very interesting! But I still don’t understand how you would teleport entities between different chunks and threads

    • @lowlevelgamedev9330
      @lowlevelgamedev9330  19 днів тому

      well I can put entities anywhere in the word and they will get asigned to their new chunk as a post process step after the multi threaded things, so I would still need to somehow know where's the position I want to teleportan entity to. But it is possiblt.

  • @GavinBogie
    @GavinBogie 14 днів тому

    This is like PaperMC's Folia! Awesome project!

  • @NinetyUnderScore
    @NinetyUnderScore 15 днів тому

    I think there is something similar to this used on 2b2t for optimization due to the constant 300+ player count in one world. Its called Folia.

  • @user-iy9dr3vv5u
    @user-iy9dr3vv5u 19 днів тому +1

    seems like mojang actually does work on the updates, its just not visible to us

  • @Madman5465
    @Madman5465 19 днів тому +1

    Great video as usual :)

  • @sam02h
    @sam02h 15 днів тому

    I've been working on a paper (not intending to publish) with a very similar multiplayer chunking systems for the last 2-3 years.
    The idea is to adapt a game protocol, and allow it to be able have this style of what I call "sub-space environments" across a distributed cluster of servers. Allowing the game server to be distributed and served at the edge.
    The basis of it is to discuss unique issues that arise, such as what I refer to as the "line problem". If 1000 players stood in perfect positions in a long line, how would the server split up the handling of that "environment".
    There are multiple solutions to this, but they all come with drawbacks. I would love to hear your solution to this!

  • @NoobStuff2007
    @NoobStuff2007 19 днів тому

    this is so good! where did you learn all of this man?

  • @zipiro8942
    @zipiro8942 20 днів тому +3

    Hope they see the thing...

  • @unitazer
    @unitazer 18 днів тому

    Randomly got it into my recomendations, and so far this is probably one of the best things that i've seen. Like in general, this is extremely impressive. but i still have 1 question that you might have already gave the answer to in another video ( but im too lazy to watch every single one ), why dont you use linux? You sound like the kind of guy to recompile your custom kernel fork on your gentoo thinkpad 12 times per day, and only use neovim, but somehow you dont?

    • @lowlevelgamedev9330
      @lowlevelgamedev9330  17 днів тому

      😂😂 I mean if I would do os dev and I gave it a small try I would do it fully from scratch so no unix starting point, and for now since I do gamedev linux doesn't really help me with developement

  • @asdanjer
    @asdanjer 13 днів тому

    You should take a look at folia as it implementes exactly this in Minecraft Java.

  • @Ht-60
    @Ht-60 18 днів тому

    Will you add colored lighting?
    Its super hard, im aware
    But colored lights in minecraft would be so cool

    • @lowlevelgamedev9330
      @lowlevelgamedev9330  18 днів тому

      I would like to but right now the light updates take the most time to compute so unless I find a way to optimize them very well I won't be able :((

  • @UnifiedCode
    @UnifiedCode 20 днів тому +3

    pls fix the normals light looks weird on blocks

    • @lowlevelgamedev9330
      @lowlevelgamedev9330  20 днів тому

      hmmmm Idk what exactly you are talking about but I would like to fix it so can you please send me a message on my discord server and tag me, with a screenshot or something?

  • @causalguide
    @causalguide 19 днів тому +1

    what if cross multiplayer wirh real mc?

  • @pepethegood
    @pepethegood 17 днів тому

    does it have AO on blocks? It would be much fancy

  • @Ddos2212
    @Ddos2212 20 днів тому

    What is the goal for the project, or just for fun? When will you consider it finished?

  • @Broom-fz2gm
    @Broom-fz2gm 18 днів тому

    I think you start creating the first video of the C++ tutorial series for beginners when C++23 comes out, because in C++23, the hello world script will be different compared to C++20.
    *Hello world script in C++20:*
    #include
    int main()
    {
    std::cout

  • @celdaemon
    @celdaemon 18 днів тому +1

    the fov feels so claustrophobic TwT

  • @patrlim
    @patrlim 17 днів тому

    it would be sick if this worked with vanilla minecraft

    • @lowlevelgamedev9330
      @lowlevelgamedev9330  17 днів тому

      ther's actually a mod that adds this to minecraft, it's called folia

  • @alacastersoi8265
    @alacastersoi8265 17 днів тому

    umm just make the world load in blobs about how they are connected, load a new blob alongside two separate blobs, then switch over to them. easy.

  • @addmix
    @addmix 19 днів тому +3

    No, this can't be. You have to run everything on the server under a single thread, because that's how minecraft does it.

    • @_HetShah_
      @_HetShah_ 19 днів тому

      My friend, it's a clone dedicated to improve what we already have so it doesn't hurt anyone running server on multi-threaded

    • @addmix
      @addmix 19 днів тому

      @@_HetShah_ Bro really has autism, doesn't he?

    • @kayastuff9367
      @kayastuff9367 19 днів тому +4

      ​@@_HetShah_ i think he's joking

    • @_HetShah_
      @_HetShah_ 15 днів тому

      @@kayastuff9367 Who knows 🤷🏻‍♂️

  • @fazin85
    @fazin85 19 днів тому

    epic mate

  • @TheMyszeek
    @TheMyszeek 15 днів тому

    What would happen if 2 players running regions on separate threads would approach each others?

    • @lowlevelgamedev9330
      @lowlevelgamedev9330  15 днів тому

      the regions are calculated each tick, so the 2 regions would just become one, ther's no performance penalty to joining 2 regions because they are just recalculated each time and that doesn't take much, it's just a matter of moving some pointers around

  • @Assassinboy3000
    @Assassinboy3000 16 днів тому

    could you fix the camera and physics, it feels really robotic and weird for some reason

  • @glenn6657
    @glenn6657 17 днів тому

    I always wonder why mojang inst able to do stuff like this, cuz others are able to so what's holding them back?

    • @lowlevelgamedev9330
      @lowlevelgamedev9330  17 днів тому

      wellmany reasons, they havea big team and big codebase so this slows them down (for the caves updates they had to refactor the entire world gen), give a task to a programmer he'll do it in a month, give it to to programmers, they will do it in 2 :)))

    • @hilligans1
      @hilligans1 16 днів тому

      Because this is not possible to implement and retain a lot of Minecraft mechanics the way they are, doing it region based like this works well yes but limits what blocks are allowed to do. Redstone as we know it isn't possible with this system for example.

  • @NoorquackerInd
    @NoorquackerInd 19 днів тому

    This sounds similar to the Folia project from PaperMC devs

    • @lowlevelgamedev9330
      @lowlevelgamedev9330  19 днів тому

      I think yes they also do this, but that's what someone told me, I haven't looked it up

  • @user-sb5vt8iy5q
    @user-sb5vt8iy5q 20 днів тому +1

    subbed

  • @lozaramon1126
    @lozaramon1126 19 днів тому

    sa mor eu daca nu esti roman, imi plac mult videoclipurile tale , tine-o tot asa :)

    • @mihaelasimerea9700
      @mihaelasimerea9700 19 днів тому

      De ce sa fie roman?

    • @lowlevelgamedev9330
      @lowlevelgamedev9330  19 днів тому

      da exact cum zice si Mihaela, de ce sa fiu roman?

    • @Papieog
      @Papieog 19 днів тому

      I am guessing he thinks that because of the accent, to me it sound more like polish

  • @Satoshinork
    @Satoshinork 19 днів тому

    Add a hand

  • @ChillerDragon
    @ChillerDragon 19 днів тому +1

    Are you planning to open source the game?

  • @gargamel3478
    @gargamel3478 19 днів тому +1

    Your clone is nice, but I don't like the lighting used. All blocks look too shiny, it's very unnatural.

    • @lowlevelgamedev9330
      @lowlevelgamedev9330  19 днів тому

      I actually have some shading settings, the first pre release will allow you to configure the shading in hopefully something that suits every one 💪

  • @marks_shot
    @marks_shot 20 днів тому

    cmek

  • @javierignacioavalos3028
    @javierignacioavalos3028 20 днів тому +2

    Shame for mojang, glory to you. What mojang did in 10 years, you my friend, did in months.

    • @itsmeagain1415
      @itsmeagain1415 20 днів тому

      bro, you know notch did it before mojang had shit on minecraft, and he fokin made it in YAVA!!!

    • @HassanIQ777
      @HassanIQ777 20 днів тому +3

      shame that the Java game is more optimized than the C++ game

    • @javierignacioavalos3028
      @javierignacioavalos3028 20 днів тому +1

      @@itsmeagain1415 Exactly. Thats why I posted what I posted. Mojang has going a downward slope since it was bought by Microsoft. I have no beef against Notch, my thing is against Microsoft.

    • @itsmeagain1415
      @itsmeagain1415 20 днів тому

      ​@@javierignacioavalos3028 all my homies poop on microsoft and their terrible decision-making fuckster mind responsible for all their depression inducing software experience across the board

    • @itsmeagain1415
      @itsmeagain1415 20 днів тому +1

      @@HassanIQ777 idk how this happens exactly but I think the thing is that the JVM has on its side A HUGE LOT of low-level optimisation mechanisms and they are able to utilise them in the most efficient way possible for programs written in java to have this huge boost in highly optimised environment/masterfully parallelisable, yeah some mastermind 10x C++ engineer can achieve some similar performance for a piece of his highly optimised code, but would never use this level of optimisation for normal stuff/maybe performance intensive but not REALLY

  • @inxomnyaa
    @inxomnyaa 19 днів тому

    watching this felt like a waste of time, i learned nothing sadly