Refs, Scopes and Smart Pointers | Game Engine series

Patreon ► / thecherno
GitHub repository ► github.com/TheCherno/Hazel
Instagram ► / thecherno
Twitter ► / thecherno
Discord ► thecherno.com/discord
Series Playlist ► thecherno.com/engine
Gear I use:
-----------------
BEST laptop for programming! ► geni.us/pakTES
My FAVOURITE keyboard for programming! ► geni.us/zNhB
FAVOURITE monitors for programming! ► geni.us/Ig6KBq
MAIN Camera ► geni.us/t6xyDRO
MAIN Lens ► geni.us/xGoDWT
Second Camera ► geni.us/CYUQ
Microphone ► geni.us/wqO6g7K

Пікірлер: 81

  • @sebastiannocke3725
    @sebastiannocke37254 жыл бұрын

    Cooking with Cherno, I need it please

  • @jamesmnguyen

    @jamesmnguyen

    4 жыл бұрын

    We need some Turkey too!

  • @austindrane3162

    @austindrane3162

    4 жыл бұрын

    That would be the best series on KZread

  • @bandolero818

    @bandolero818

    Жыл бұрын

    Cooking while doing analogies with programming and c++, would love that content !

  • @cyqry

    @cyqry

    Жыл бұрын

    @@bandolero818 "Now we're going to dice this here and its kind of like making a shared pointer"

  • @mrhidetf2
    @mrhidetf24 жыл бұрын

    cherno really stepping up his metahphor game in this series. Honestly tho i think you are getting better and better at communicating

  • @carlosgarciavigoa7937
    @carlosgarciavigoa79374 жыл бұрын

    Guys & Girls, this is a simple tip. If anyone here goes to the beginning of the series and watch the first episode again, it will increase watching time, popularity, ranking and many other things that will help the Series. Of course, it will help Cherno too. More view more ranking and at the same time more subscriber than eventually will become Patrons. Remember now is a FULL-TIME JOB. We need to keep that. TY in advantages.

  • @mario7501
    @mario75014 жыл бұрын

    Just made a patreon account to support your channel! This is by a mile the best C++ and game dev content on KZread!

  • @jdev6402
    @jdev64024 жыл бұрын

    Now i'm curious how that asset manager will look. Thank you for your dedication to this series, it's really motivating and informational.

  • @felipecarlin8540
    @felipecarlin85404 жыл бұрын

    9:29 I was not prepared for that, now I'm concerned about memory ownership and management. Thanks Cherno!

  • @SandFoxling
    @SandFoxling3 жыл бұрын

    2021 and still no "Cooking with Cherno". In the mean time, patreons should get access to a shared pointer to his kitchen

  • @colorcookie6088
    @colorcookie60884 жыл бұрын

    Love you Cherno!!! Your C++ series has helped me a lot. Thankk you

  • @robertocabiddu6008
    @robertocabiddu60083 жыл бұрын

    0:10 nah m8 EVERY SINGLE episode is EXCITING

  • @__jan
    @__jan4 жыл бұрын

    he's getting funnier every episode

  • @davencharity
    @davencharity4 жыл бұрын

    Cooking with Cherno? It's been over four years since Sparky, and I don't think you've ever remembered to take the turkey out of the oven! ;)

  • @thecookiegeneration
    @thecookiegeneration4 жыл бұрын

    You can check if the sharedptr is lock free, most atomic increment and decrement operations can be done threadsafe without a lock (single cpu instruction for read increment write)

  • @quanghong3922
    @quanghong39224 жыл бұрын

    Great job

  • @simonbaxter8001
    @simonbaxter80014 жыл бұрын

    I'm still waiting for the 'Cooking with Cherno' series ! ;)

  • @stanleythehandsome5402
    @stanleythehandsome54024 жыл бұрын

    Boy I Love this guy

  • @herrdingenz6295
    @herrdingenz62954 жыл бұрын

    3:30 but isn't the layerstack designed in a way that the layer isn't destroyed after we pop it off the layerstack? which brings me to another question: in the destructor of the layerstack we cycle through all layers in it and destroy them... but what happens to layers which we popped off the layerstack? they won't be deleted, will they?

  • @Thiago1337
    @Thiago13374 жыл бұрын

    Great tutorials.

  • @TriNity-GER
    @TriNity-GER4 жыл бұрын

    Whenever I need a pointer, I always ask myself: who is the owner? Are there multiple owners? Using this though massively helped me to choose between unique_ptr and shared_ptr. Also my favorite replacement for raw pointer is object_ptr :D

  • @misterbenjamin7845
    @misterbenjamin7845 Жыл бұрын

    Cooking With Cherno - Episode 1: The Perfect Cup of Coffee

  • @GalaxySoftwareStudio
    @GalaxySoftwareStudio4 жыл бұрын

    What do you using about using glad2 instead in the future ? As it supports Vulkan too, multiple GL contexts, internal loader and you can even generate a header only version ! ^^

  • @fryderykst
    @fryderykst4 жыл бұрын

    Great video as always, thanks! :) Could you (or someone else) explain the difference between atomic count and regular one? How it works? Thanks.

  • @colorcookie6088
    @colorcookie60884 жыл бұрын

    Cooking with chernoooooooo!!!!!! Let's go babyyyy!!!!

  • @ZyklonV
    @ZyklonV4 жыл бұрын

    Man, last time I heard the word "ownership" so many times was during a talk presenting the Rust programming language. Love C/C++, love Rust more

  • @sam_is_people1170
    @sam_is_people11702 жыл бұрын

    thanks!!!

  • @bies_moron4404
    @bies_moron44044 жыл бұрын

    401 patrons !!

  • @FurtoMega
    @FurtoMega2 жыл бұрын

    I was having a big problem with a dangling pointer in my code. Weak pointer saved my life. Every since then I use shared pointers only..

  • @jakobfriedl3098
    @jakobfriedl30984 жыл бұрын

    all of us crying xD

  • @jdev6402
    @jdev64024 жыл бұрын

    9:35 lmao

  • @jamesdadabo
    @jamesdadabo3 жыл бұрын

    "all cool and hip and trendy"

  • @alopmemes1964
    @alopmemes19642 жыл бұрын

    nice new haircut :D

  • @mytech6779
    @mytech67794 жыл бұрын

    I was trying to slog through a bunch of the CPPcon videos, mind blown. Getting down to manipulating L2 and L3 to achieve better atomic multi-threading; actually considering the physical time to transmit an electric pulse between cores and predictive fetching from memory. And they always say "use vectors", I'm not sure if this is an old running joke or actual advice for better general performance.

  • @reductor_

    @reductor_

    4 жыл бұрын

    'better general performance' : no, get a few more ns with micro optimizations : yes essentially don't prematurely optimize

  • @daleowens7695

    @daleowens7695

    2 жыл бұрын

    As you are aware, it's a consequence of cache. "Everything" is probably a vector, and now with cache, this is doubly so. @ReDucT0r; 'better general performance' : yes. I sugges you research cpu cache. vectors are beating out linked lists, even for tasks classically thought of as optimized for linked lists, like midpoint insertions and deletions because cpu cache is orders of magnitude faster than going to RAM.

  • @mytech6779

    @mytech6779

    2 жыл бұрын

    @@daleowens7695 2 years on and I know a good deal more about c++. The vector referenced was the std library dynamic array, not the SIMD hardware or math concepts. And yes they were mostly comparing it to [linked] list performance, but it was also about moving away from old style C and improving code quality both in reading the logic and in avoiding memory leaks associated with deleting manually allocated dynamic memory for classic arrays. (Though if done just right a classic array can be a hair more optimized if needed for some very critical corner case, but in most cases the payoff isn't worth the effort and would need a lot of profiling and testing to proove. In many cases careful use of vec1.reserve(n) will close most of that gap without the hassle. )

  • @clodgozon3968
    @clodgozon39684 жыл бұрын

    I love dealing with refs and pointers. Not an irony.

  • @engsayed2007
    @engsayed20074 жыл бұрын

    I Am developing a program which I draw objects using the mouse I draw a point _ line and polygon with any number of sides I save each created object (line or point or polygon) as a mesh having its own vba_vbo_ibo Till now I can select each object and individually without any problems My problem is I want to create large number of objects say 2 millions When I create more objects the program becomes too slow in rendering I tried to make all vertices coordinates in one buffer and all created objects share this buffer according to its indices How can I handle such a huge number of objects ?????? Thanx in advance

  • @theo-dr2dz
    @theo-dr2dz7 ай бұрын

    What he says at minute 3 is not correct. std::unique_ptr can't be copied (if it could, it would not be unique anymore), but it can be moved. Moving a std::unique_ptr transfers the ownership. But of course, if you need shared ownership, use a shared_ptr

  • @_Omni
    @_Omni4 жыл бұрын

    24:26 you didn't say what you will do in the next episode 🤷‍♂️

  • @raffallo

    @raffallo

    2 жыл бұрын

    textures :)

  • @cubefish2320
    @cubefish23204 жыл бұрын

    Give me lapsis episode 9 i'm still waiting after all these years I've become nothing, dedicating every second of my waking time to trying to solve what episode 9 would be. I lost my job, my wife, my family outed me, and I lost all my friends. I live on the streets, wandering with my phone, theorizing about how the Minecraft Machinima 'Lapsis' episode 9 would have ended. I need this. please.

  • @popplestones886
    @popplestones8862 жыл бұрын

    Still waiting for cooking with cherno, 3 years later :-(

  • @MieysoFelix
    @MieysoFelix Жыл бұрын

    I live in sad 2022 😔. Can i get a reference to *"Cooking with Cherno"* ? Or at least a pointer address?

  • @gracicot42
    @gracicot424 жыл бұрын

    What I do usually is to decouple the refcount to the asset. I have the asset object that contains only the minimum necessary to use it, and a refcount. For example, the asset object for a shader program would contain the id and the refcount. But having a refcount of some sort, whether it's with a shared pointer or something like I do is absolutely necessary. Keeping resources around from scene to scene makes the engine not loading things over and over. We don't know when we will destroy the texture or when it won't be needed anymore. So shared ownership is ideal.

  • @denisbalcom1429
    @denisbalcom14294 жыл бұрын

    loving the metaphors and cooking with cherno statement lol. ~^_^~.

  • @huyvole9724
    @huyvole97244 жыл бұрын

    New pc

  • @jamesmnguyen
    @jamesmnguyen4 жыл бұрын

    Would delaying the rendering cause noticeable input lag for the user?

  • @nielsvs2203

    @nielsvs2203

    4 жыл бұрын

    Generally not

  • @bensettiabderrahmane1801
    @bensettiabderrahmane18014 жыл бұрын

    Hello, World!!!

  • @bensettiabderrahmane1801

    @bensettiabderrahmane1801

    4 жыл бұрын

    First Vue!!!!

  • @billclinton4913
    @billclinton49134 жыл бұрын

    "We have a very exciting epesode" says without anny emotion.

  • @vitaliiseptember266
    @vitaliiseptember2664 жыл бұрын

    Hey, Yan - its a russian name, and Chernikov - its like russian surname, isnt it?

  • @aarondraws7699
    @aarondraws76992 жыл бұрын

    i destroyed my entire code base with the replace all function I basically have to start over

  • @mjthebest7294

    @mjthebest7294

    2 жыл бұрын

    This is why you want to use git and commit often. :)

  • @Rekongstor
    @Rekongstor4 жыл бұрын

    I love smart pointers and especially shared ones, the main idea of this video is good. But what's the point of renaming std::shared_ptr into Hazel::Ref or std::unique_ptr into Hazel::Scope? You still have to type a bunch of letters but new Hazel users will not intuitively understand what Hazel::Ref stands for without peeking on the code or reading the documentation. Like maybe it would be better to remain std library without Hazel aliases because there're more people familiar with std naming, not Hazel's.

  • @madeso

    @madeso

    3 жыл бұрын

    Premature refactoring. At 14:03 he says it's because he might want to implement a shared_ptr for "assets" with the same exact api as std::shared_ptr and changing it then would be too hard.

  • @kopuz.co.uk.
    @kopuz.co.uk.3 жыл бұрын

    Haha imagine having an electric stove :):):):):):):)

  • @jarekmyszko3332
    @jarekmyszko3332 Жыл бұрын

    Thread pool system is better than dividing engine into specialized threads. 1) Easy to add to existing engine structure. 2) Easy to synchronize(you don't need to use double buffering) 3) Memory efficient(look above) 4) Scales better for computers with more than 4 cores. 5) Great for ECS pattern.

  • @optimusfjstudio3345
    @optimusfjstudio33454 жыл бұрын

    when you make your own engine can use blender

  • @graph2001
    @graph2001 Жыл бұрын

    ChatGPT3.5 Generated: - The transcript is from a video in a game engine series. - The video discusses references and smart pointers for the engine's core system. - Shared pointers are being used to encapsulate objects on the heap to control their lifetime. - The issue of ownership is important for smart pointers as they automate the deletion of objects. - The renderer of the engine needs to hold references to assets such as shaders and vertex arrays for deferred rendering.

  • @nextlifeonearth
    @nextlifeonearth4 жыл бұрын

    Somehow in the poll people imply 2D would be a stepping stone to 3D.. If you look at any given 2D or 3D engine editor you see they're almost nothing alike. "use the feedback from 2D for 3D" That's not how it works. Outside of some scripting, the UI feedback will be of no benefit in the 3D editor. There are fewer materials in 2D, so no material editor except for its texture and maybe some filters, that's out. The world editor, is vastly different in 3D again, that's out. Will it be faster? Yes, you can look at 100+ tutorials to make 2D engines online today and see for yourself it can be pretty easy. If you'd like to compare it a a PBR capable 3D engine tutorial, good luck, there's about 5 of which most are behind a paywall and/or abstracted from the code. Then what it the purpose of this engine? Making it modern. Is 2D modern? Pretty much every modern effect only applies to 3D.

  • @Sevo779Gaming

    @Sevo779Gaming

    4 жыл бұрын

    2D and 3D both have modern developments, new rendering technics are always being developed, now that is not to say that 3D is not more complex, or different but you seem to be heavily biased because it is obvious that building a simpler engine is a stepping stone to a more complex and demanding one. Also, I have made a UI that works in both 2D and 3D so I am not sure what you mean there.

  • @nextlifeonearth

    @nextlifeonearth

    4 жыл бұрын

    ​@@Sevo779Gaming Works doesn't mean work well. An optimal workflow in either are little alike. I don't doubt you can make it more complex, but we don't want complexity, we want sophistication without it being complex. That's mainly it, you COULD make an editor for 2D and modify it for 3D later, but it would not work as well as if you were designing it for 3D from the beginning. It's a compromise and "compromises are the enemy of success", to quote someone.

  • @DovydasV2

    @DovydasV2

    4 жыл бұрын

    He's not going to make a full on 2D editor at first, nor a 3d editor. I hope you do understand that. (By the way, you can totally use a 3d editor for 2d games, that's what unity does, they only make the camera orthographic) He is going to create a 2D Renderer at first which will do sprite batching and stuff like that, and then after that he will continue on to 3d PBR renderer which will take a lot of episodes and time to make. There is no debate, what kind of engine it is going to be. As he said, he will do both, but he's asking which one should come first. Also, I think that world editor is not coming anytime soon, since what is the reason to make an editor right now? I will repeat myself again, but he's not going to build a 3d renderer on top of a 2d renderer. They are going to both eventually come and the poll is a debate whether 3D rendering or 2D rendering should come first.

  • @nextlifeonearth

    @nextlifeonearth

    4 жыл бұрын

    @@DovydasV2 "you can totally use a 3d editor for 2d games, that's what unity does" And it's terrible. I have used it and I'd rather use Gamemaker than that for 2D games, because unlike Unity, Gamemaker was actually designed for 2D. I have too much of a bad experience with people saying "X will come later even though it's the primary purpose of the software, we'll do Y first" and then it vastly compromises what can be done with X. That's why I have a big aversion of what's essentially a sidetrack that has little to do with 3D and could actually get in the way of the final product and at the very least delay it simply to sate some people who weren't into this series for its purpose in the first place.

  • @jamespong6588
    @jamespong65884 жыл бұрын

    So it's either ugly code or cryptic code Plus you still have to manage when things get deleted but in an abstract way instead of shouting to the world HERE IN THIS VERY MOMENT I AM RELEASED FROM MEMORY New and delete is fine.

  • @ricardopieper11

    @ricardopieper11

    4 жыл бұрын

    It's fine, but we forget to do it all the time. No matter how genius of a C++ programmer you are, you are bound to forget it at some point. Or you'll double-free, or dereference a dangling pointer, or return a pointer to a stack value... so much can go wrong. It's no surprise they created Rust because of this very problem.

  • @jamespong6588

    @jamespong6588

    4 жыл бұрын

    Ricardo Pieper yeah people forget to call delete, but you can follow the code and figure out if you forgot it, also we have powerful tools to trace memory leaks, it's orders of magnitude harder to figure out when something is released by code structure, than Ctrl+F and find "delete xyz"

  • @TheKbdering
    @TheKbdering4 жыл бұрын

    It's pronounced decrement, not decrement