Let's Code A Multiplayer Voxel Game in C++ - The Engine
HTML-код
- Опубликовано: 8 сен 2024
- In this new series, we will be creating a voxel multiplayer minecrafty cloney clone from the ground up using C++ and OpenGL, with some libraries for support such as SFML and ENET.
=========
SOURCE CODE: github.com/Hop...
=========
RESOURCES:
Going 3D:
ogldev.atspace....
ogldev.atspace....
Client and Server Connection - gafferongames....
=========
MUSIC USED:
Donkey Kong Country - In A Snow-Bound Land - • Video
Rayman 1 - Betilla The Fairy
Donkey Kong Country - Forest Interlude
Rayman 1 - Bandland Theme
Beyond Good And Evil - Home Sweet Home - • Beyond Good and Evil S...
Rayman 1 - Bonus Level Music
Ratchet and clank - Wupash Nebula
Chrono Trigger - Winds That Cross Time
=========================================
LINKS:
GitHub: github.com/Hop...
Discord Server: / discord
Support me on Patreon: / hopson
Follow me on Twitter: / hopson1997
Follow me on Twitch: / hopsonn
Community Channel:
/ @hopsoncommunity8184
Still a more reliable uploader than Code Bullet.
}:^
Yeah, but opengl is 1998-tastic.
Hey, he's not... well... I guess you ARE right.
@@tsalVlog you say that like it's a bad thing
@@tsalVlog What are you talking about? 90% of 3D games made today use OpenGL.
It took you so long to make a video that you actually gave me enough time to go from only knowing python to learning C and OpenGL
how do you learn so fast? :/
Justin X. By doing
@@qwerasdfhjkio I said I learnt OpenGL but honestly for now I can only render quads on the screen. I still have no idea how to rotate a cube on the screen, but I will get there later
That happened
@@Cal97g Why wouldn't that happen?
We missed you
ikr
same
Yes we did, truly!
No
We missed you a lot
finally, we are getting hopsoncraft
Oh my, it's happening!
In this series you have basically started to create my dream game:
A multiplayer minecraft clone which I have created myself from scratch, in which I can hang out with friends and mess around, and implement cool features which vanilla minecraft does not have, e.g. coloured lighting, items which refer to inside jokes, etc, etc. Some of these could be implemented with mods, but it is not the same as being hard coded and the whole game created by me.
My goal one day is to create this game, and have a blast playing this game with my friends and family. This series and your other minecraft videos is one of my favourites of all time on the whole of RUclips - my grin was from ear-to-ear for the entire duration of watching.
Thank you, Hopson.
Ooooh me too - I've always wanted to create something like this. I'm currently procrastinating learning opengl, how's your journey going?
@@jumbledfox2098 Thanks for asking, I haven't really touched OpenGL since commenting as I am getting more familiar with C++ and SFML atm.
@@EpicVideoGamer7771 oooh nice! its always good to make dozens of little projects than one big and hard one
@@jumbledfox2098 Yeah I am currently making a top town 2d shooter, might release it on itch when im done
Idk why but why seeing these type of videos are SOO satisfacting
I made my own multiplayer game, and I can feel the pain with making good networking---
You know you're godlike when you refer to the internet as "some network"
but... that’s what it is
Awesome, loved these videos can't wait for this series.
I'm currently studying networking (cisco) and this video is amazing! I just realised that it could be used in developing multiplayer games.
Amazing video ! Can't wait for the next part !
"Hmm maybe making my own engine with OpenGL would be fun"
*Sees video*
I think I'll stick to unity
You're part of the problem then.
Seriously though, I'd recommend trying it at least once. Most 3D engines are built around pretty much these exact principles, so if you're doing serious development it's good to know how they work. Unity isn't too much more abstract than this stuff and if you ever want to go into more advanced stuff like shaders you will have to understand stuff like this.
@Sticks Studios And that's yet another reason why Apple is terrible. They almost always design their own "standards" instead of adopting widely-used, already available ones.
OpenGL is on mac, Apple just stopped updating it beyond 4.1.
@@lupinedreamexpress How is using Unity to create games a problem? Many amazing games are powered by it.
Amazing job on this! Networking in particular is something I've been meaning to get into
Holy shit I didn't expect to randomly find you here lol
At the very beginning of the video I thought: Alright, if it's about networking, you have to use ENet!
I was highly surprised when at the end you actually did. I feel like although being old, it is good enough to deserve attention.
I ALMOST HAD A HEART ATTACK SEEING THIS UPLOAD
Did you... Did you just explain a heckton of knowledge in just a couple of sentences? Like... I understood nearly every sentence and was following through with ease...
Fricking admireable.
It's interesting to see you making these first steps... I started working on a voxel game 5 years ago and I'm still not finished.
Bonus challenge: make the blocks 0.5m in size and have fun with the optimizations you need for that :)
is it finished yet? what is the progress
@@hugofoltin5647 Still working on it. I'm adding a couple of advanced multiplayer features now, like easily switching between servers without having to create a new character. Kinda important when you got a game where everyone can host a server.
9:48 "Reliable UDP sockets"
So... TCP sockets?
Nope, tcp carries a lot more weight ontop it. Also its optional reliability, so no need to have that unless absolutely nessesary(eg sending player positions, it's safe to miss a few packets here and there, but sending chunk data needs guaranteed delivery)
@@Hopsonn So the protocol he used was basically TCP minus the congestion control?
@@GamingBlake2002 So the topic is covered in the talk GDC - Networking for physics programmers.
TCP has head of line blocking, TCP waits for an ack, not get it, and then request the packet to be resent, there is congestion avoidance, slow start.
These features are what separate TCP from UDP and also what makes TCP untenable for a lot of real time uses when you include latency and packet loss as your connection becomes jittery.
You can get reliability without these features while still retaining a stable connection by building only what features you need on top of UDP.
@@MINIMAN10000 networking is a dragon you cannot see, but witness the effects of everyday
"Strawberry flavoured candies"
So... strawberries?
The legend is back
Authenticate the disconnect using the IP and have the server compare it against the table of users, it will be a lot harder to discover and spoof the IP of every user in the game rather than iterating 1-12 or however many players
Also in order to prevent teleport hacks, the clients should send translations that should be clamped by the server and then applied, returning a position to avoid desync
Dude! I watched your original videos and decided to make a voxel multiplayer game in JavaScript using webrtc great vid!
we need to respect him and also notch
since they make their on engine from ground by using OpenGL and i still stuck in learning in Unity
I love this, can't wait for the next episode
Really great video, explains the core functionality and how it works for people learning SFML. I wish I knew about ENET before! Really cool.
Ohh this is super nice to see, it ALMOST gives me back the motivation to make the voxel-esc game I've been wanting to create, and the talk of how "chunks" are rendered/saved certainly helped in my motivation. Only trouble is my lack of experience now!
Holy shit, the Ratchet and Clank music!!! You have some good taste my man, also one of the best tracks as well!
Hearing that Beyond Good & Evil ost was a pleasant surprise.
happy to see another one of your videos
for moving foreward i would use a vector facing the way the player does and rotates with him while beeing parallel to the xz-plane. If you instanciate it with a length of one (e.g. v=(1,0,0)) you make sure that by adding this vector to the players position you moved him exactly 1 unit. For moving him half a unit simply multiply .5vand so on. I'm sure you know how vectors work. For rotating Vectors around the y axle there is an easy matrix. ^^
I smell a DoS method by sending a lot of chunk requests for areas that haven't been generated yet, bogging down the server and increasing its CPU use. Regardless, super cool video, subbed and liked!
Make a stream. I would love to see this being made live
Another dope video ty hopson
I wish you go more in depth on these topics. This is all interesting stuff.
Hi! I really enjoyed your code Minecraft series so I'm happy to see you do it again. Are you planning to make it look like the vanilla Minecraft, or are you planning to add some nice shaders to it, maybe even some RTX?
Thanks! In terms of that, I haven't really got any plans about how it should look but I am open to ideas in this area. (Also I have no clue how RTX actually works, let alone a graphics card that actually support that :P)
If you should get famous with this, I was since beginning here :]
loving the Ratchet and Clank going commando ost
Wow👍👍👍 Thanks for sharing and visiting Kelly
God. Ill never be this good at coding
Incredible, really. Compliments for your hard work and thanks for sharing!
Man this is awesome, I'm waiting for the next episode of this. May you do volumetric clouds btw?
You could try to make compression if there are multiple blocks you can make the coordinates of just the shape of blocks.
You should make tutorials about how to code this, seems very interesting
Well, he explains how he does it and the code is on github
to learn C++: www.learncpp.com/
to learn OpenGL: learnopengl.com/
www.sfml-dev.org/index.php this is the library he is using to simplify much of the work, it also has a networking implementation which you can build on (they have a tutorial here www.sfml-dev.org/tutorials/2.5/)
learning those things will put you on a good path to do what he's doing. trust me when i say this: learning this on your own is much better than learning through endless tutorials.
Feel like there's a bit much going on here to explain each line of code in a tutorial. What he's done here is very similar to what we learned in my year 2, semester 1 at uni. A basic multiplayer module, and a 3D rendering with a programmable pipeline module, and that took us 3 months to learn with a course dedicated to it.
Prochy's comment above is a good starting place though, I'd advise learning one thing at a time rather than trying to create a voxel renderer and multiplayer game at the same time, if you've done neither before it'll be a very daunting task.
Or using Unity for a similar project would simplify things a lot, as once you've generated the mesh it's very simple to render and don't have to learn about using OpenGL/DirectX render functions, and Unity has multiplayer support in the asset store. Good luck :)
But where exactly can i download OpenGL??In internet on this tutorial the people download SFML or/and glew/glut and similar.Is it connected to the OpenGL??
@@antonioambrosio2064 OpenGL(dot)org, then it's on the right of the website. You use SFML/GLEW/GLUT to use OpenGL. You might not have to download OpenGL though, I'd look for a getting started with OpenGL guide on youtube.
Programmers
are so smart, they're so underappreciated.
Aw. Thank you.
Aw. Thank you.
Aw. Thank you.
Aw. Thank you.
HI im just here to break the chain :)
Hytale: "Let's kill Minecraft!"
Hopson: "Let's kill Hytale"
Its so much fun and interesting to watch! Thank you for this video :)
Please, keep using Rayman 1 musics ! Those are so cool to hear while listening at your explanations :) Btw, great video. I'm waiting for the next ones ;)
WELCOME BACK HOPSON LOOKING FORWARD TO THIS
Hey! Glad your back, can't wait for the next episode.
I liked the Chrono Trigger Epoch song at the end 👏
I love the Rayman music
9:00 ratchet ans clank music maaan, good old days.
Great video. I'd love to see one using Vulkan.
wow, you explanation is incredible, it's simple, and yet you can make it easy to understand
Wait, a multiplayer Voxel game/engine with mod support and open-source code? You're making Minetest 2 lol (Not saying that's a bad thing, infact I think the fact that your project has a more permissive license is awesome!)
Mine test is awesome and is one of my main motivations to creating this, it's just always fun to create it yourself :)
Literally no one:
Python developer when sees more than 15 lines of code:
**Scared screams**
"developer"
You dont need the no one part of your meme
My dumb-ass a couple years ago:
wanting to flex on my 8th grade classmates so I make a quiz in python that has 1k+ lines of code
(most of it was copy-paste but still)
@@tilengasparic6765 how do manage to make a quiz 1000 lines long?
@@frigtear4460 I didn't know how to programme for shit so it was all un-organised and I had ~15 questions so I had to open 15 new windows. and once I made 1 question I just copy-pasted it 15 times and changed the text
Since your Textures can be set to repeat have you considered mapping similar adjacent blocks into a single block which only contains the 8 vertices? I guess it's effectiveness would be determined where your main bottle neck is be it the CPU or GPU. Idk due to instancing you could likely do without such a thing but it was just a random thought I had while watching. Nice video, gl on the project.
remember to normalize the player movement vector so that the player doesn't move faster when walking diagonally
Thumbs up for the Beyond Good and Evil music!
Oh my gosh that Rayman music!
Awesome!
Dude, you're awesome. Good code.
Love your videos, man
Same here. Hopson makes great, great videos~
Would love to see your engine being ported to vulkan ^^
Amazing as always!
I barely understand this but it's still interesting
you study well been making game engines since i was 11 Zelon Studios Inc.
You're back! ❤
Why didn't you use ENet for player everything then? It's easy to do that, just assign the first byte as a message type then check for the message type and read the data accordingly. Very easy, no need for other things.
Thanks, great content i really appreciate it
It's been so long that I actually forgot why I subbed an joined your discord. I couldn't even remember who you were.
Now I remember why.
Hey Hopson it would be great if you create a tutorial how to setup sfml for visual studio code
Check out the CMake tutorial on SFML, just follow it
It took minecraft around 10.5 years to get to where it is now
so how long do you think you will need to do more or less the same ?
Id guess a bit shy of a year maybe ?
Good to see you back again (:
Welcome back, we missed you!
Btw, how did this took 5 days to get to my feed?
rest in peace Rémi Gazel : (
What is you just made a list of operation types for the server and gave each one an importance value and the server would then do the most important task at the moment
If you chose to do this to do this I would put world gen at the not so important end because updating entity position and talking with players is more important so you can give him layers the ability to generate chunks if the server is overloaded by entities like animals or other entities and the player just transfers this information back to the server
Is there any popular tutorial series on RUclips or any website which talks about making visual c++ 3d game
this is so smart ight im migrating to c++
What the heck?? I just wanted to try to make a voxel game in c++ but didn't know where to start!
Nice, you're back...I use unity niw
gets to 0:57 OK... it's not that kind of night.. Going back to playing Kerbals..
i hear that r1 music, nice.
I know that right now your focus is making a playable prototype, but if you decide to 'refine' it in the end, you should probably make so that instead of sending your position (which is very exploitable, but you don't care for now), you send your 'input', kind of a snapshot of the 'client keyboard/mouse', this way you can simulate it in the server and send the correct coordinates to the client and all other clients listening. This has some good advantages, like making your game deterministic and will allow you to 'record' the inputs and maybe make some kind of replay, for example. I would suggest looking at this post if you want to know more about it: developer.valvesoftware.com/wiki/Source_Multiplayer_Networking.
That's a good idea. Would the client still be able to update their own positions, or will it have to be fully server side? Just worried about input latency. Thanks for the info! (haven't read article yet, as on mobile for now)
@@Hopsonn Take a look at the article and you'll understand better, but essentially, yes, you'll have problems with latency, the solution (as in the article) is interpolation between where the client thinks it'll be at (it calculates it's future position and applies it right away) and what the server decides where it is (as the client gets it's real position). There are other ways to do this, but I think most games do this (interpolation). One noticable effect of this in some games with high latency are rollbacks, which are disagreement between client and server where they should be at, although in most connections the interpolation should be almost unnoticeable.
@@Hopsonn I should also add that the article I presented is only a overview of how Valve does it's networking, but the terms used and it's ideas should be a good starting point in a more 'refined' and realistic approach to multiplayer, should you actually go this way.
Как посмотрел видео от БУЛДЖАТЬ о Вангерах, как сразу пошли Воксели и мемы о них
the most helpful part about this video was actually looking at your CMakeLists.txt file lmao
CMakeLists can be very weird, I still find it archaic to this day lol
Glad it was able to help out :)
Our saviour has returned!
How did you learn OpenGL? I really want to learn it and am inspired by your work!
Cheers! I learned from a few places,
learnopengl.com/ this is really good for basics but can be a lot of waffle
ogldev.atspace.co.uk/ another great resource
Also learned from thin matrix opengl tutorials (RUclips) but he does it in java, and not particularly the best approaches to it, but some of the most easy to understand explanations
Good luck!
4:48 and thats what the large game studios nowadays think every time
I wish programmer-youtubers would mention how long it took them to get their project to the current state. Can be a little demoralizing otherwise. :3
This one is a funky question.
In theory it took about 4 months, if you include the learning I did to understand how to use networking.
If you don't include that, then it would be around 16 or 17 days I think
@@Hopsonn Thank you
I am interested in why didn't you just use TCP for sending chunk data from server to client?
UDP is usually used for game systems because it is message oriented as opposed to stream oriented. It's faster, there's no buffering, no worries about having to disable Nagle's algorithm, an *generally* you don't care if a packet gets dropped. It's almost *always* a better choice for multiplayer games.
All that being said, I don't know what his reasons are. He said he's new to network programming, so maybe he just lucked into making the right choice, or maybe he did a bit of research beforehand.
Lenon Kitchens I believe most games use UDP for things like position, but also TCP for important parts.
I see in GTA V Online that our client tries to predict where all entities will be (so it also receives entities’ velocity) so players don’t just teleport around like in minecraft.
@@lenonkitchens7727 In the case of chunk data TCP should be used though because it's important that all data is received correctly.
@@deadaccount3994 It's still probably better to implement a form of guaranteed delivery via UDP for such data, and relax the guaranteed delivery requirements for data that isn't as important. TCP should really only be used for something like a connection to a RESTful API in a game system.
This looks awesome man
Thanks!
Oh my soal I remember I played this game in grade 6 in my school computer lab with my friends😂
How can you play a game that doesn't exist yet?
YES! The dreams have come true!
nice ratchet and clank music
ohh shit here we go!
OH HELL YEAH BABY, HE IS BACK!!!!!
Why not just store the changes in the map? As the world should be generated by a seed that is the same evwrytime you run the world, if you just store changes to each chunk it will be wayyy more storage efficient and still work.
It would be nice if someone added (english) subtitles. English is not my first language and it is hard to keep up with what you say, especially when you are explaining complex problems.
Whats ur main language?
@@TUTOSANDROIDtutorialesymas I think English subtitles would be nice
@@TUTOSANDROIDtutorialesymas Polish.
Witaj kolego z internetu :)
@@internetwanderer9053 siema
My main language is not english too, but try to understand what he says based on the context
woo new series!