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.
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)
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
In the current code base (Hazel2D), what is the point of using std::shared_ptr, if you're passing it as a const reference basically everywhere, therefore not incrementing the counter, and not avoiding the same things you are concerned about. I wonder if this is the same for the dev branch.
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
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 ! ^^
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.
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.
@@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. )
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.
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
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.
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.
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.
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.
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.
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.
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.
@@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.
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.
@@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.
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.
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.
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"
Cooking with Cherno, I need it please
We need some Turkey too!
That would be the best series on TH-cam
Cooking while doing analogies with programming and c++, would love that content !
@@bandolero818 "Now we're going to dice this here and its kind of like making a shared pointer"
cherno really stepping up his metahphor game in this series. Honestly tho i think you are getting better and better at communicating
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.
Now i'm curious how that asset manager will look.
Thank you for your dedication to this series, it's really motivating and informational.
9:29 I was not prepared for that, now I'm concerned about memory ownership and management. Thanks Cherno!
Just made a patreon account to support your channel! This is by a mile the best C++ and game dev content on TH-cam!
Love you Cherno!!! Your C++ series has helped me a lot. Thankk you
0:10 nah m8 EVERY SINGLE episode is EXCITING
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)
2021 and still no "Cooking with Cherno". In the mean time, patreons should get access to a shared pointer to his kitchen
he's getting funnier every episode
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! ;)
Cooking With Cherno - Episode 1: The Perfect Cup of Coffee
I'm still waiting for the 'Cooking with Cherno' series ! ;)
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
Boy I Love this guy
In the current code base (Hazel2D), what is the point of using std::shared_ptr, if you're passing it as a const reference basically everywhere, therefore not incrementing the counter, and not avoiding the same things you are concerned about.
I wonder if this is the same for the dev branch.
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
"all cool and hip and trendy"
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..
Cooking with chernoooooooo!!!!!! Let's go babyyyy!!!!
Great job
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
I live in sad 2022 😔. Can i get a reference to *"Cooking with Cherno"* ? Or at least a pointer address?
nice new haircut :D
thanks!!!
Still waiting for cooking with cherno, 3 years later :-(
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 ! ^^
all of us crying xD
I love dealing with refs and pointers. Not an irony.
Great tutorials.
Great video as always, thanks! :)
Could you (or someone else) explain the difference between atomic count and regular one? How it works? Thanks.
401 patrons !!
"We have a very exciting epesode" says without anny emotion.
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.
'better general performance' : no,
get a few more ns with micro optimizations : yes
essentially don't prematurely optimize
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.
@@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. )
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.
24:26 you didn't say what you will do in the next episode 🤷♂️
textures :)
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
i destroyed my entire code base with the replace all function I basically have to start over
This is why you want to use git and commit often. :)
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.
9:35 lmao
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.
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.
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.
loving the metaphors and cooking with cherno statement lol. ~^_^~.
Hello, World!!!
First Vue!!!!
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.
New pc
Hey, Yan - its a russian name, and Chernikov - its like russian surname, isnt it?
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.
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.
@@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.
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.
@@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.
Would delaying the rendering cause noticeable input lag for the user?
Generally not
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.
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.
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"
when you make your own engine can use blender
It's pronounced decrement, not decrement