TERMINAL GAME ENGINE! // Code Review

Try Code Rabbit for FREE now ► coderabbit.ai
Patreon ► / thecherno
Instagram ► / thecherno
Twitter ► / thecherno
Discord ► / discord
Hazel ► hazelengine.com
🕹️ Play the latest Hazel game FREE ► studiocherno.itch.io/portal-m...
Code ► github.com/ural89/ConsoleCraf...
🌏 Need web hosting? ► hostinger.com/cherno
Send an email to chernoreview@gmail.com with your source code, a brief explanation, and what you need help with/want me to review and you could be in the next episode of my Code Review series! Also let me know if you would like to remain anonymous.
💰 Links to stuff I use:
⌨ Keyboard ► geni.us/T2J7
🐭 Mouse ► geni.us/BuY7
💻 Monitors ► geni.us/wZFSwSK
This video is sponsored by Code Rabbit.

Пікірлер: 98

  • @TheCherno
    @TheCherno25 күн бұрын

    Thanks for watching! Video I mentioned at 1:05 if coming tomorrow! ❤ Also definitely try Code Rabbit's AI code reviews! Free for open-source projects ► coderabbit.ai

  • @code_with_MK

    @code_with_MK

    25 күн бұрын

    Sir I have completed your course of C++ and I want to study the C++ more in deep from you because you are teaching good so where should I get these course.

  • @abacaabaca8131

    @abacaabaca8131

    25 күн бұрын

    How do I submit game for a game review ? But, my game is only partially done.

  • @RogerTannous

    @RogerTannous

    23 күн бұрын

    ​@@abacaabaca8131check the video description.

  • @jgsw563
    @jgsw56325 күн бұрын

    Hey Cherno! Thanks for reviewing my game engine :)). And video was fantastic and very helpful for me. I'm really learning from you a lot. About solution files, for some reason I couldn't make it work with cmake. I'm using Windows and Linux PC back and forth so I decided to leave it there. And for scene deletion: I wanted to implement a scene change but I would do that later.

  • @gm_000

    @gm_000

    25 күн бұрын

    When I saw it I thought that's amazing! It's really cool! Never thought it was possible to do such great games with terminal! And that's amazing that is done by someone just for hobby, and whose main job is being a vet not a programmer. Really well done!

  • @peternimmo74

    @peternimmo74

    25 күн бұрын

    I'm very impressed with your engine having been self taught. I noticed that you are calculating milliseconds from seconds, but you are using std::chrono, so no calculations are required. You can simply assign a seconds variable to a milliseconds variable, and the milliseconds variable will hold the value you were calculating manually.

  • @ThatJay283

    @ThatJay283

    24 күн бұрын

    for scene management i would definitely suggest having an array of std::unique_ptr

  • @Redditard

    @Redditard

    24 күн бұрын

    I am really inspired by you!! This is the start of coding journey as well... and seeing a fellow who is learning and making such a cool project is such a delight!

  • @Betacak3
    @Betacak325 күн бұрын

    12:45 Terminals usually don't have a refresh rate, but more like a rate of characters or write operations per second limit. If you only ever update parts of the screen, it can go much faster than if you update the entire screen at once. Also, the Windows Terminal is ridiculously slow compared to common Linux terminals with Bash. That's likely why the demo game had some severe flickering when you tried it. I recently played with cellular automata and rendered them in the terminal. On Linux, I could fully update the full-screen, zoomed-out terminal upwards of 100x per second without flickering. The difference is crazy.

  • @gruchenstein9163

    @gruchenstein9163

    23 күн бұрын

    interestin, so thats why

  • @devwckd
    @devwckd24 күн бұрын

    I didn't know it was called defensive programming, I've always called it anxiety programming

  • @davidenzler1691
    @davidenzler169125 күн бұрын

    The 2d -> 1d array mapping was something I learned with CUDA programming. Totally blew my mind and it’s a super clever way of storing multidimensional arrays. The indexing ends up being something like [row_width * row + col] for a 2d array where row_width is a fixed value and row/col are the “indices” you would normally use in a multidimensional array.

  • @chris52000

    @chris52000

    24 күн бұрын

    std::mdspan is going to make it even cleaner too!

  • @insertcreativenamehere492

    @insertcreativenamehere492

    12 күн бұрын

    Bonus points if row_width is a power of two because then it’s just a bit shift operation

  • @fulvioabrahao
    @fulvioabrahao25 күн бұрын

    Thanks for the video @TheCherno; Knowing how to access the memory in an optimal way is one of the most important / first things a game engine developer should know! Glad you always bring this up into your reviews.

  • @StevenMartinGuitar
    @StevenMartinGuitar25 күн бұрын

    Have you seen the One Lone Coder console game engine?

  • @ade5324

    @ade5324

    25 күн бұрын

    Ye

  • @cecilectomy

    @cecilectomy

    24 күн бұрын

    **laughs in Spyro hub world rendered in console**

  • @TheLordoftheDarkness

    @TheLordoftheDarkness

    24 күн бұрын

    I think it's no longer in development and he switched entirely to his pixel game engine.

  • @MaxCE

    @MaxCE

    16 күн бұрын

    ​@@TheLordoftheDarkness yep. I follow his community. the pixelgameengine has grown to be quite impressive.

  • @williankoessler5935

    @williankoessler5935

    16 күн бұрын

    I was about to say the exact same thing!! OLC Console Game Engine is such a gem when it comes to learning c++ and programming in general

  • @GonziHere
    @GonziHere25 күн бұрын

    This "be aware of what value it might have" is the best feature about Rust. I don't care about their memory model per se, but the ability to force you to deal with the "possibly null"-like scenarios is golden.

  • @raidensama1511

    @raidensama1511

    24 күн бұрын

    Null… the billion dollar mistake

  • @mertcanzafer9901
    @mertcanzafer990125 күн бұрын

    My best video series in this channel. I learn so much things whenever I watch this videos.

  • @c.codyflick2210
    @c.codyflick221024 күн бұрын

    I'm gonna wager this is the work of the new video editor. Great job! And if not, Great job!

  • @dealloc
    @dealloc24 күн бұрын

    I've written a fair bit of terminal-based renderers for GUI and animation and there's definitely an art to making it performant, especially on older terminal emulators, but some "modern" ones like Windows Terminal are still quite slow. This is because the rate of updates is determined by the speed of I/O operations and the terminal's ability to render characters, which is bound by its internal implementation details. Rather than working with pixels, you instead work with a buffer of characters that is made up of unicode/ASCII (what you usually see on screen) and control escape codes that is used to control terminal but doesn't render on screen. Both of which takes up space in the buffer. This means you are working with a buffer size that can vary, depending on your needs. Some techniques we can use to optimize things is similar to what a GPU would do but at CPU level. For example having a virtual screen buffer that can be used to diff between cells and only update the 'dirty' ones, portion off a section of the screen buffer, rather than dealing with an entire screen at once and much more. The most prominent and still often text-based user interface API is ncurses, which is also used by vim. It can be fast, but is very low level compared to, say a game engine. It's more akin to working with something like OpenGL directly.

  • @vaijns
    @vaijns25 күн бұрын

    Regarding the vector of vectors a cool new feature in c++23 is that you can define multi-dimensional subscript (array access) operators, so you could create your own wrapper around a single-dimensional data-structure (or use mdspan for access) and access the values like a multi-dimensional array (tho with commas instead of chained [][]) e.g.: sprite[0, 1] => sprite of the 2nd column in the 1st row

  • @peternimmo74

    @peternimmo74

    25 күн бұрын

    I think you are talking about std::mdspan?

  • @vaijns

    @vaijns

    24 күн бұрын

    @@peternimmo74 not only. std::mdspan is just the library feature, which I also mentioned briefly. But the multi-dimensional subscript operator is the language feature which allows mdspan to work which it didn't (not like that at least) before C++23

  • @anon_y_mousse
    @anon_y_mousse25 күн бұрын

    This is actually a pretty cool project idea because if they do it right they can extrapolate this functionality into a 2D and later 3D game engine extending their prior work. One suggestion I would offer is that if they're associating names of objects or file system paths to objects or a combination of both, say as a mapping of strings to them, then a flat hash table would be preferable to a map since you can store everything in a contiguous array and have nearly instantaneous jumps to individual elements. You might need to write one yourself or use a third party library, depending on whether the STL implementation for your system is good enough.

  • @gorkemigman9496
    @gorkemigman949625 күн бұрын

    Good Job Ural! You've done a fantastic job, as expected of you.

  • @jgsw563

    @jgsw563

    25 күн бұрын

    Thanks görkem 😊

  • @kamil_atakan

    @kamil_atakan

    25 күн бұрын

    How nice to see not one but two fellow Turkish code enthusiasts here😁

  • @Denis-in6ur
    @Denis-in6ur25 күн бұрын

    What a cool project 🎉

  • @saxus
    @saxus25 күн бұрын

    TBH about 22-25 yars ago when I still did my secondary I've got the idea to do an "Imperium Galactica II" inspired game in Turbo Pascal using DOS and 80x25 console. I had a book about VGA card programming which had a floppy with assembly codes. There was one example to replace the standard font table with custom one. I even managed to do animated planets to replace the font table periodically. Bruh, the codes was shipped on a 5.25" floppy, I even had to find a friend who could copy those examples to a 3,5" disk. Good old memories.

  • @nextlifeonearth
    @nextlifeonearth25 күн бұрын

    I would not use the raw pointer in the vector at all, but make it a unique ptr. Looping through the destruction yourself is utterly unnecessary and error prone.

  • @GlorytoTheMany
    @GlorytoTheMany13 күн бұрын

    Just found this channel and I already like it; especially how much enphasis you put on memory safety. What is your stance on Rust? Sorry if you already have a video on it, I didn't find.

  • @ltstaffel5323
    @ltstaffel532325 күн бұрын

    Dang it I'm a decent C++ programmer and thought I'd catch everything you did but I immediately missed clearing the scenes vector at 6:08. It's really obvious to devs like me that your videos give us insight into what a senior engineer sees, which is incredibly valuable to those of us trying to push past the intermediate 3-4 years of experience stage

  • @ThatJay283
    @ThatJay28324 күн бұрын

    thanks for this video! i recognise in my game engine that i could have ALOT of guards sitting behind macros using asserts. i currently just use if() to check if things are null in the setup stage but just assume everything is fine in the render stage.

  • @IAmSegfault9051
    @IAmSegfault905123 күн бұрын

    Actual curses based engines aren't really common, but there's a ton of pseudo terminal libraries available for several languages for making traditional Roguelikes. Most of them also have utilities for a* and fov algorithms like recursive shadowcasting.

  • @ssiamantas
    @ssiamantas25 күн бұрын

    THE THREE AMIGOS THE THREE BROTHERS THE THREE MUSKETEERS

  • @gsestream
    @gsestream25 күн бұрын

    dll can just be updated/compiled separately from the main executable. if thats what you want. same for java, just compile what has changed. maybe the runtime stays the same, only the dll program changes. sometimes making a project for some IDE takes ages. avoid not-integrated make tools with all costs.

  • @jekkil1332
    @jekkil133225 күн бұрын

    Nice idea

  • @code_with_MK
    @code_with_MK25 күн бұрын

    Sir I have completed your course of C++ and I want to study the C++ more in deep from you because you are teaching good so where should I get these course.

  • @LetsDark
    @LetsDark25 күн бұрын

    Hey Cherno, I have a video idea: Why should you use pointers in some cases? For example at 6:00 the Scene is a raw pointer, but why. You have to do cleanup etc. Wouldn't it be better to not use a pointer here and if this needs to be shared using a reference instead of sharing the pointer?

  • @GRHmedia
    @GRHmedia25 күн бұрын

    It really depends on what you are doing even on a terminal game engine you could need ECS. Your problem is you are thinking purely what is being shown on the screen. But you could be doing far more in the background. Consider a game like dwarf fortress the original was terminal based. If you wanted all the entities in the game to continually do stuff even when not visible and depending on how many you have ECS would be a very good option.

  • @libberator5891
    @libberator589123 күн бұрын

    The idea of having one single long vector of all the sprites is the same concept of a sprite atlas. Not sure if they used the same term back in the day, but it's reminiscent of how they packed all the sprites to old games. Take Gameboy's Pokemon for example: when you go outside the range of expected sprite memory addresses, you get fun glitches like Missingno

  • @oglothenerd
    @oglothenerd25 күн бұрын

    I am making my own graphics API for the terminal.

  • @corprall
    @corprall19 күн бұрын

    I have seen a terminal game engine before, even kind of made one before for a uni project, this is far beyond what I made though.

  • @r.g.thesecond
    @r.g.thesecond25 күн бұрын

    Smart pointer move semantics should have been used. Better yet, have the engine call the constructors.

  • @dizimo1188
    @dizimo118825 күн бұрын

    17:19 Dwarf Fortress would probably be one of the only examples

  • @AgiaDiy
    @AgiaDiy24 күн бұрын

    Thanks , i love these code reviews, i have a question : isn't the 2d array faster in the reallocation than the continuous approach because when it needs to add to the outer vector it only has to reallocate the main (outer) array, instead of reallocate the whole thing?

  • @oscarsmith-jones4108

    @oscarsmith-jones4108

    23 күн бұрын

    The problem is in this case iteration occurs much more often than reallocation. When the CPU fetches data from memory, it fetches a chunk at a time (not a single value at a time) so if all of your data is next to each other it can grab chunks much more effectively when iterating through it. Another problem is that when the data is in different places, the memory access is much less predictable. When the code is predictable the CPU can fetch what it thinks it will need ahead of time (branch prediction). This is why sorting an array before using it can actually *improve* performance if the resulting logic is more predictable. Reallocation occurs every so often, when the capacity is exceeded. Having lots of small allocations can fragment your memory and make future allocations slower - there can be gaps made by the smaller allocations that are harder to fill up. Also, each allocation requires a separate search for available space, so reducing the number of allocations is also an important thing. So in general, keep the memory contiguous and don't use linked-lists.

  • @AgiaDiy

    @AgiaDiy

    23 күн бұрын

    @@oscarsmith-jones4108 thanks for the explanation

  • @sashareinhard6645

    @sashareinhard6645

    16 күн бұрын

    to be fair, flattening the vector was a micro optimization in this case. doubt it changed much

  • @pranavbadrinathan6693
    @pranavbadrinathan669318 күн бұрын

    Hey Cherno, a question for you. Do you only take C++ code in your code reviews? I have a project in C and another in Rust that I would love to get checked out by you, but I won't send it in if you don't do other programming languages 😅. I guess C should be fine if you already review C++ though...

  • @spectre_xo
    @spectre_xo25 күн бұрын

    Heyy cherno! I've been following you for 3 years now. Thanks for everything. You're the reason I landed my first Job. Honest Criticism: While I understand why you spend time on things like vectors of vectors and memory leaks, it would be really amazing if you actually review stuff that is interesting. You could probably look at a grass renderer or water renderer and talk about how these things work and can be improved. In this case I was really looking forward to seeing how the console sprite rendering was managed but that was barely shown. It would be really awesome to see how some actual amazing game features like GI, Volumetrics or Terrain from the perspective of an experienced engine dev - like the video that you did on asset packs. That was really useful ! Anyways I do understand that you might not have time to do both YT and Hazel at the same time but it would be really amazing to see some new content ! P.S - Editing is better these days! I guess the new editor does know his stuff.

  • @sashareinhard6645

    @sashareinhard6645

    16 күн бұрын

    the vector of vector thing felt like such a nitpick to me tbh. i understand theyre bad, but like making the change wont improve performance by any noticeable amount here

  • @warrenhenning8064
    @warrenhenning806425 күн бұрын

    You should review Mike Acton's ncurses Unity game port.

  • @patryk3772
    @patryk377225 күн бұрын

    I have a little question. Since we have smart ptrs we should use only them instead of raw ptrs or we should even use raw ptrs for some efficiency critical apps to avoid overhead of smart ptrs or this overhead is neglible and doesn't matter? I watch sometimes some cpp talks and they always talk about memory safety above efficiency. I'm a little bit confused.

  • @user-sl6gn1ss8p

    @user-sl6gn1ss8p

    24 күн бұрын

    I think the main idea is that smart pointers deal with ownership. If that's not what you're dealing with in some code, than raw pointers should be fine

  • @not_ever

    @not_ever

    24 күн бұрын

    The cpp talks talk about memory safety because that’s the whole point of smart pointers. If your pointer only points to memory but doesn’t own it then use a raw pointer. There is no point avoiding smart pointers to squeeze out a bit of performance if you introduce a bunch of memory leaks and hard to track down bugs imo, especially if you didn’t actually measure and profile the performance increase. If you are interested in cpp talks that discuss the overhead of smart pointers try chandler caruth’s “There Are No Zero-cost Abstractions” or Nicolai Josuttis’ “The real price of shared pointers”

  • @sashareinhard6645
    @sashareinhard664516 күн бұрын

    mmm u suggested iterating through the std::map of the gameobjects cuz iterating the extra std::vector of gameobjs is over optimized. but then u challenged his vector of vectors over some cache misses? i dont think flattening the vector would make any noticeable difference performance wise tbh

  • @ade5324
    @ade532425 күн бұрын

    Would you review my (or others) game engine written in c?

  • @davidfrischknecht8261
    @davidfrischknecht826124 күн бұрын

    About the vector of vectors, isn't each member of a vector stored contiguously with the previous member?

  • @ea_naseer

    @ea_naseer

    24 күн бұрын

    up until you it needs to expand the vector.

  • @davidfrischknecht8261

    @davidfrischknecht8261

    23 күн бұрын

    @@ea_naseer Then it allocates a new block of memory big enough to hold the new size and copies all the existing members to the new block of memory. That's why if you need a collection that's going to change size a lot, you should use one based on a linked-list and not an array.

  • @Mateus.007

    @Mateus.007

    23 күн бұрын

    But each vector member is a pointer to another vector.

  • @theEndermanMGS

    @theEndermanMGS

    22 күн бұрын

    With the default allocator, a vector is just a wrapper around a dynamically-allocated array. So the vector objects are allocated contiguously, but the arrays backing them are not.

  • @cooperpig
    @cooperpig25 күн бұрын

    cool vid

  • @tommclean9208
    @tommclean920812 күн бұрын

    I learned the other day dlls can be optimized at linker time

  • @maksymillian
    @maksymillian25 күн бұрын

    i was just making a terminal game engine

  • @v-for-victory
    @v-for-victory25 күн бұрын

    Hi Cherno. Are Macros still wise?

  • @theEndermanMGS

    @theEndermanMGS

    22 күн бұрын

    The preprocessor - including macros - is a tool. It is a tool that is error-prone and easy to misuse, but there are legitimate uses for it. If you can’t find a sane alternative, using the preprocessor is fine.

  • @vs.xyz.
    @vs.xyz.25 күн бұрын

    can you send me your vs settings ? only for colors no time for make it self

  • @peternimmo74

    @peternimmo74

    25 күн бұрын

    Yeah, I keep noticing his bright yellow font for the keyword in the find box. Not sure how that's done. So would love his font settings.

  • @radoslavdimitrov7505
    @radoslavdimitrov750521 күн бұрын

    I am sure this was inspired by Javidx9's Console game engine

  • @jgsw563

    @jgsw563

    16 күн бұрын

    Nope. I am seeing lots of people talking about this engine all the time. I've checked it myself after I see in the comments. And I've seen his code. And if you check his code, you will see there is no relation. He makes it single file and he is focusing more on rendering. While my focus is not rendering but making game engine related classes and architecture

  • @radoslavdimitrov7505

    @radoslavdimitrov7505

    16 күн бұрын

    @jgsw563 he made it portable but yeah, structural separation in classes is better. The principle, though, is the same if you use windows api for reading and writing to console(stdin and stdout)

  • @jgsw563

    @jgsw563

    16 күн бұрын

    @@radoslavdimitrov7505 yeah, because probably the best approach for multiplatform

  • @djupstaten2328
    @djupstaten232824 күн бұрын

    Justin Debug? He back?

  • @kotofyt
    @kotofyt25 күн бұрын

    I love vulkan->I hate vulkan->I love vulkan->I hate vulkan->...

  • @Tezla0

    @Tezla0

    24 күн бұрын

    I hate vulkan -> I hate vulkan even more

  • @firstlast-tf3fq
    @firstlast-tf3fq24 күн бұрын

    If you didn’t do delta time, terminals like alacrity would have a field day with their 12mil fps 😂

  • @ast_rsk
    @ast_rsk23 күн бұрын

    fwiw I use a terminal called Kitty which renders with a separate GPU accelerated thread for performance and feature enhancement :)

  • @steveafanador6441
    @steveafanador644125 күн бұрын

    This stuff in so hard to understand for a regular guy. I must be too dumb to even think about understanding it. Interesting though 👍👍

  • @oscarsmith-jones4108

    @oscarsmith-jones4108

    25 күн бұрын

    It is way simpler than it looks, you are probably just lacking critical information.

  • @NotNotAsian
    @NotNotAsian5 күн бұрын

  • @zohichnazirro8640
    @zohichnazirro864025 күн бұрын

    It's a shame you are not aware of javidx9's Console Game Engine

  • @dj10schannel
    @dj10schannel25 күн бұрын

    Lol

  • @keptleroymg6877
    @keptleroymg687725 күн бұрын

    Newbs should write c not cxx

  • @davidenzler1691

    @davidenzler1691

    25 күн бұрын

    I think for someone new to programming in general both are difficult to write correctly. You need to already know what you are doing for both b/c they definitely won’t do anything for you lol.

  • @sashareinhard6645

    @sashareinhard6645

    16 күн бұрын

    let beginners learn what they want