I made the same game in Assembly, C and C++

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
I set out to create the same game in three  different languages x86 assembly C and C++   I wanted to go bottom up and see what each  successive technology brings to the table and   this is what I learnt I wanted to make breakout  because conceptually it's quite a simple game and   by the time you strip out scoring, game states and  most things actually make it a game you're left   with hopefully not a lot to implement there's a  paddle a ball some bricks and some basic collision   detection and response so starting with x86 the  best way for me to describe my experiences was   pain I didn't find a whole lot enjoyable about  this and even getting started was difficult cmake   took some coercing to actually build a binary from  pure assembly and then actually programming was a   lesson in patients you get nothing out of the  box just a bunch of instructions for shifting   memory around and manipulating numbers I thought  I know I'll need a linked list so let's just code   that up quickly okay but then I actually need  to allocate some memory but I don't have malloc   right so let's Implement a super simple malloc  but I've got no way of actually requesting more   memory from the kernel fine I'll start off with  asking the kernel to mapping some more memory   pages I'll carve that up to get a basic malloc  and then on top of that I'll add a linked list   so I can actually store and iterate through data  I had to create a really basic version of several   libc functions from scratch including malloc print  assert exit sleep and gettimeofday I was issuing   direct calls to the X11 windowing system which  seemed the most basic way to do things I was able   to pull together the basics of the gameplay but  even with my attempts to create a proper game loop   in assembly it wasn't exactly a smooth experience  next up was C and it was a real breath of fresh   air compared to the previous misery especially as  I switched to using SDL for windowing and graphics   being able to create if statements and loops  without having to worry about jumping to labels   and preserving registers was surprisingly  satisfying libc is quite simple though so I   still had to add a linked list to store data this  highlights to me one of the nice things about C in   that you get pretty much perfect encapsulation  you declare but don't define a struct and then   just a bunch of functions that work on that for  someone consuming your code as a library they have   no way of knowing what's inside that struct and  are completely limited to the API you provide the   lack of namespace proved tedious though as I ended  up having to prefix everything to avoid clashes   finally C++ I want to point out that this  video isn't meant as a C versus C++ argument   I thought it would be fun to talk about what  I observed when using both so C++ provides the   next layer of abstraction up from C it has a much  larger standard library as well as more language   features I could create a class with methods for  my primitives like Vector2 and Rectangle I could   add operator overloads so I could use arithmetic  operations on objects I could use std::vector   out of the box which is way more efficient for  iterating than any linked list I would write   and I could use exceptions to make the error  handling cleaner some other things that just made   development easy for me was first class support  for namespaces so everything had simpler names   classes and RAII for safer resource management  and more vocabulary types like std::optional   which simplified the API even accounting for the  fact that each iteration provided learnings for   the next it was definitely quickest for me to  implement the C++ version so I actually quite   enjoyed this mini project it was nice to see how  each successive technology made development easier   safer and more efficient and if we dive a little  deeper we can see this using the data structures   example in x86 I created a linked list and it  just gets assembled to machine code it's only   as efficient as I could write it for instance  if I wanted to tail call optimizations I would   have to add that myself in C I can write a  simple linked list and the compiler can do   all sorts of crazy optimizations for me finally  in C++ we get all these data structures for us   and I'm sure efficient data structures are  available as libraries in C and assembly but   with C++ not only are they available out of the  box but it's also type safe and automatically   handles object lifetimes all this code is open  source and linked In the description if you're   interested to see why you might use C++ for  a project then check out this next video
Info
Channel: Nathan Baggs
Views: 668,740
Rating: undefined out of 5
Keywords: C++, Cpp, Assembly, X86, Programming, Game dev, Game
Id: 2eeXj-ck9VA
Channel Id: undefined
Length: 4min 19sec (259 seconds)
Published: Sat Nov 12 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.