No video

Learning Programming by Trying and Failing // Code Review

  Рет қаралды 38,509

The Cherno

The Cherno

Күн бұрын

Пікірлер: 96
@TheCherno
@TheCherno 8 ай бұрын
Thanks for watching! Don’t forget you can try everything Brilliant has to offer-free-for a full 30 days, visit brilliant.org/TheCherno. The first 200 of you will get 20% off Brilliant’s annual premium subscription!
@wjrasmussen666
@wjrasmussen666 8 ай бұрын
Sure, do another video on how you would refactor this code. Or, have you done a video on profiling?
@y4ni608
@y4ni608 8 ай бұрын
@@wjrasmussen666 I have actually implemented all the stuff cherno advised me to do (build system, project strcture, scenehandler, and even the naming conventions) i just really hope he can create a last and final episode, i hope to get a review for that. And i didnt even really intent to create a ECS
@mobslicer1529
@mobslicer1529 8 ай бұрын
did you see my email about my c game engine
@learningtoride1714
@learningtoride1714 8 ай бұрын
Failing to learn or failing, to learn.
@prakashraj4519
@prakashraj4519 8 ай бұрын
I think it's the later
@user-sl6gn1ss8p
@user-sl6gn1ss8p 8 ай бұрын
you should open a fortune cookie business
@BruceOnder
@BruceOnder 7 ай бұрын
​@@user-sl6gn1ss8p Or, should they open a fortune, cookie business?
@alexkhazov7264
@alexkhazov7264 8 ай бұрын
I don't think the object slicing remark is entirely correct. It has nothing to do with the objects being stack allocated. The issue would occur if you were to pass in a subclass type by value to a base class type. This could happen even with a heap allocated object if you were to dereference the subclass type when calling a function that takes a base type by value. The most important thing is everywhere where you take in a base class to take it in by pointer or reference... Which you should be doing normally anyways - don't make redundant copies :)
@Gastrostomi
@Gastrostomi 8 ай бұрын
That was informative in a way I did not expect. I have never really thought about the deeper inner workings of how an ECS is structured and how it works.
@user-sl6gn1ss8p
@user-sl6gn1ss8p 8 ай бұрын
I really like these reviews, but I do feel like in a multi-episode series like this one it would have been nice to see what the thing actually does and maybe skim a sample project.
@GB_Parametric
@GB_Parametric 8 ай бұрын
Would love to see the implementation of ECS.
@whoshotdk
@whoshotdk 8 ай бұрын
Me too, proper ECS is *hard*, for many of the memory reasons The Cherno stated. I've made a partial-ECS which works like "old" Unity does (Entity has Components) but trying to come up with something more efficient than that has beaten me many times so far!
@AnteP-dx4my
@AnteP-dx4my 7 ай бұрын
SAME !!
@aboliguu1168
@aboliguu1168 Ай бұрын
This comes a bit late and probably isn’t too helpful but i can give the basic idea on how to hold different sized objects in tightly packed arrays. It was the main problem for me before. You basically want to have a hash map of std::type_index -> some pointer of BaseComponentArray. Then you inherit from that Base array with a templated ComponentArray class that holds a vector of type T. When you add a component, you call a templated function so you can get it’s corresponding vector from the hasmap with std::type_index(typeid(T)). Then just cast the pointer to the vector to the correct type and push it there. I can elaborate if needed.
@mariwanj5292
@mariwanj5292 8 ай бұрын
Please make a diagram design structure how all these parts should be designed and make it visual .. from entity, to requiremnets for each entity.
@ProGaming-kb9io
@ProGaming-kb9io 8 ай бұрын
He already has the game engine series, there he does it in the right way
@mariwanj5292
@mariwanj5292 8 ай бұрын
@@ProGaming-kb9io I know, but visualizing that in a structured diagram will help to understand better.
@TheAxeForgetsTheTreeRemembers
@TheAxeForgetsTheTreeRemembers 8 ай бұрын
Yes! Possible solutions would be a great follow up!
@lromaniuk
@lromaniuk 8 ай бұрын
Weather members will be stack or heap allocated is determined how you allocate them, not where you put them in the code. There is nothing wrong with use of polimorphism to make an ECS - and still you can put derived classes in their seperate memory buckets - nothing stops you from doing so. Personally I would not put any functionality in components - just the data. All of this continious memory effort is useless if you have to process logic that requires multiple component types at the same time - basically you will be fetchind data from different buckets all the time causing a lot of cache misses - but its true that some systems (rendering) may benefit from such arrangement.
@natescode
@natescode 7 ай бұрын
*whether
@Spirrwell
@Spirrwell 8 ай бұрын
Man, with how hard you're tearing into this, you should do a code review of the Source SDK for Source Engine. This code here, while having some questionable design decisions, is not that bad.
@bluesillybeard
@bluesillybeard 8 ай бұрын
If what I've heard is correct, the source engine is a (still fairly well optimized) mess and a half.
@Theawesomeking4444
@Theawesomeking4444 8 ай бұрын
the dev : please roast me the cherno : for each (lines of code) make a 30 minute video on why that line of code is bad
@maxrinehart4177
@maxrinehart4177 8 ай бұрын
Every dev would be lucky to get roasted like this. learning new things, getting feedback on why their implementation is wrong, and how to fix it is by far the best kind of code roasting.
@sirpalee
@sirpalee 8 ай бұрын
Memory layout of components is an implementation detail of ECS, not a requirement for an ECS system.
@rtc44
@rtc44 8 ай бұрын
1. Fields are not stack allocated. 2. Object slicing is not about allocation, it's about copying the object by assigning to somewhere, It's about static type. Sorry, can't resist)))
@Stroopwafe1
@Stroopwafe1 8 ай бұрын
When the class/struct is stack allocated, its fields are stack allocated, when the class/struct is heap allocated, its fields are also heap allocated. Check it out in godbolt. Fields are just an offset from the first field
@gabrielciordas3369
@gabrielciordas3369 8 ай бұрын
Great video as always Cherno, you're like the Bob Ross of programming in c++
@gelis07
@gelis07 3 ай бұрын
sebastian lague is the bob ross of programming
@tiagocerqueira9459
@tiagocerqueira9459 8 ай бұрын
If your child component need access to the parent and you store the parent pointer, it is usually a red flag.
@sub-harmonik
@sub-harmonik 8 ай бұрын
how would you do that otherwise? store an index into some entities table?
@DeusExAstra
@DeusExAstra 8 ай бұрын
I dont think that's necessarily the case. It depends on how things are structured and what the entities and components do.
@yesntpittzant4156
@yesntpittzant4156 8 ай бұрын
​@@sub-harmonikDepending on the situation, having a list of certain entities can be reasonable. But that's not the point. If you make an Entity Component System and your child components needs access to the parent, then it kinda defeats the whole purpose of having an ECS. Because ECS is "best" when you have a clear hierarchy and independent components. If the child component needs access to the parent, you might as well make it one component. Or restructure the components
@RigelOrionBeta
@RigelOrionBeta 8 ай бұрын
An index is essentially a pointer. Just an offset to a memory address. Depends entirely on what that thing points to. Not necessarily a bad thing.
@MrHaggyy
@MrHaggyy 8 ай бұрын
@sub-harmonik - just implement child in parent and not every object needs every method - try different data and function structures that avoid the problem by good design. - try a virtual class and propper VTable design. -put each object in a data structure and let the program code deal with seperaten, do not abstract in the class.
@sinom
@sinom 8 ай бұрын
Writing a custom arena allocator would be an interesting video topic
@gabrielbeaudin3546
@gabrielbeaudin3546 8 ай бұрын
After listening to your channel a bunch, I realised what I really wanted to build is an engine and not an editor. My "Compositions" should just be known at compile time because I won't use an editor to build them. I ended up not having a entity component system at all. I know my classes will be next to each other in memory and won't cache miss.
@thygrrr
@thygrrr 3 ай бұрын
I actually enjoyed reading the architecture of s2d, because it's a fresh perspective on some things. (sometimes a dangerous perspective, see Object Slicing) After >30 years of programming, I learn primarily not from reading "best" practices, I learn from good practices and even bad practices I observe in the field. :3
@the_gobbo
@the_gobbo 8 ай бұрын
Really cool book reference! will definitely check it out!
@user-sl6gn1ss8p
@user-sl6gn1ss8p 8 ай бұрын
it is a kinda dense book, but it is really, really good
@MasonDixonAutistic
@MasonDixonAutistic 8 ай бұрын
The Game Engine Architecture(3rd edition) book is currently discounted on Routledge, so I've ordered it and can stop sucking and start failing...upwards.
@informagico6331
@informagico6331 8 ай бұрын
It is simply about to study enough to get the knowledge that boosts your project, and to practice enough to learn, get results, and not to get frustrated becuse of the infnite available contents to study. I feel this the most difficult part of software engineering, to make the optimal solution acquiring enough knowledge to reach it. Do not just study programming and do not just make programs, find the optimal way to get things done.
@MrHaggyy
@MrHaggyy 8 ай бұрын
And once you are decent with your study start and keep breaking and fixing larger and larger systems. If you know how an problem or issue is made in a small scale it much more likely that you catch it in a big system.
@_blank86a
@_blank86a 8 ай бұрын
Multi threaded design patterns would be a great because as we start to scale the applications by adding more features the applications start to get slow so please 🙏 do teach us by giving some suggestions and stuff...
@mad_circuits
@mad_circuits 8 ай бұрын
1:35 It is not possible to "just build, not learning". My opinion.
@zanagi
@zanagi 8 ай бұрын
Would want to see young Cherno code
@spaaske
@spaaske 8 ай бұрын
Where can I find more elaborate information on keeping a flat structure rather than keeping a hierarchy?
@R4t4n
@R4t4n 8 ай бұрын
I actually have pure virtual base class in my current "ECS" I am building and I still store them in continuous memory for performance. Reasoning behind is that all our components have to have some common functionality and some required methods for template hell that is happening around. I am trying to shield colleagues from engine related things as we are not any close to gaming project and renderer is just a tool for us.
@gabetobias443
@gabetobias443 8 ай бұрын
I would love to see you build a memory arena system but I'm also curious to see how you would go about creating a simple custom ECS system
@fappylp2574
@fappylp2574 8 ай бұрын
Me too, i always get hung up on iterating over groups of components. Separating the component arrays into archetypes seems sensible, but how do you then access these separate arrays in a sorted manner (for example for forward rendering)?
@lromaniuk
@lromaniuk 8 ай бұрын
@@fappylp2574 You dont, you just itarate over all renderables and submit work to your rendering system which sorts your rendering commands however you need and then you submit your sorted rendering commands to the rendering API. Decouple systems and keep their responsibilities isolated.
@Nhurgle
@Nhurgle 8 ай бұрын
If you are on a budget, Game Engine Architecture can be read on the Internet Archive ;)
@gsestream
@gsestream 8 ай бұрын
learning is not copying, by instructors commands, as you said its more 1st hand experiencing (the why's rather than 2nd hand copying like a machine). why do you have to call something ecs or something btw, thats the teachers dictation. the term definition or even dictating of using those terms will nuke a learner into a copy machine. get rid of pointers and all complexity as fast as you can. not productive, its an inhibitor. first solve figure out the memory pointers issue, to make a base system to build on, so that the future building is more simply constructed, you would not re-solve making a building block each time, but solve it once, then use the same mold for all the other less custom blocks. iterating versions of the same program, prototypes is no shame or detriment, its the actual learning, by you, not someone else. you should design and rewrite your stuff many times, after writing it for the n previous times lol.
@vcv6560
@vcv6560 8 ай бұрын
Success or failure, its all yours. Try, fail, correct, continue. I'm nearly 60 and this remains a truism in my life. Its the only thing that works. For the next I'll quote Calvin Colliage (President of the United States in the 20s): “Nothing in this world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination alone are omnipotent. The slogan 'Press On!' has solved and always will solve the problems of the human race.”
@Driver___
@Driver___ 8 ай бұрын
I actually have 2-3 other similar projects downloaded and opened from where I am learning to write my 2d-3d engine
@rmt3589
@rmt3589 8 ай бұрын
Yes! Please show us how to solve these issues. I just, in this video, found out you can have hierarchy in ECS, which I thought was a defining thing in OOP besides classes and subclasses.
@tematoscybersage5626
@tematoscybersage5626 8 ай бұрын
I think that iterating contiguous memory gives benefits, because in that cases computer knows start and end point of data that need to be computed and can activate assembler feature called DMA(Direct Memory Access). I used this feature when I was making game for NES to draw background of level in fast way. But I am not sure does C++ uses that same feature with contiguous data.
@whoshotdk
@whoshotdk 8 ай бұрын
Its been such a long time since I did NES ASM but "STA $2007" rings a faint bell :P Did you ever finish and release any games? I'd be interested in seeing them. I started several myself (including a version of Stardew Valley lol) but never got round to completing lol.
@tematoscybersage5626
@tematoscybersage5626 8 ай бұрын
@@whoshotdk I just made simple side-scroller with easy boss fight. It was the beginning of my gameDev path. Yes, I released more then one project, but not for NES. For example Dreamcast remake of Textorcist. If you want, I can send you my game and also sources for it;) but I need to correct it a bit, because it was made as a present for person that I don't like to be in a game anymore😄so if you want, after correction I will send it;) P.S. the only one thing that I didn't get my hands on it was sound, when I understand complexity, I understood that there is not much free time left, to implement that
@whoshotdk
@whoshotdk 8 ай бұрын
​@@tematoscybersage5626That sounds really good! I remember how hard it was to implement decent platformer physics. Don't go out of your way to correct your game just to show me. But if you ever decide to upload to Github or somewhere like that, do send me a link!
@tematoscybersage5626
@tematoscybersage5626 8 ай бұрын
@@whoshotdk Ok, so I will do that. Will notify you here when it will be ready
@sub-harmonik
@sub-harmonik 8 ай бұрын
these days it has a lot to do with cache and ram locality. (the caches will read 'cache lines' into faster locations closer to the registers, so when you get data that's next to itself it's way faster because it will already be read into the cache as part of the same cache line)
@maarten9222
@maarten9222 8 ай бұрын
A lot of the things you mention I see in Rockstar's Rage engine although they love inheritance.
@rishavgaming8662
@rishavgaming8662 8 ай бұрын
I was thinking that can dani have comeback but not with unity but with Hazel make video like back then
@user-ib3gl6pj6h
@user-ib3gl6pj6h 8 ай бұрын
Nice to see you again
@meistrimeez
@meistrimeez 8 ай бұрын
There is always the dilemma when choosing between composition and inheritance. I don't think there is right and wrong here. It's just the experience or history of the individual developer.
@CreativeSteve69
@CreativeSteve69 8 ай бұрын
I work with using python, when I start on a small scale project can I send it your way Cherno for a episode of this fun series in the future? or in css/html?
@bekdev564
@bekdev564 8 ай бұрын
I'd love to see your reaction on GTA VI trailer just like your Unreal Engine 5 reaction video!
@scoliossis
@scoliossis 8 ай бұрын
happy birthday for 5 days ago i think
@ev3rybodygets177
@ev3rybodygets177 5 ай бұрын
lol every time i watch one of these reviews i always walk away thinking there are more issues with the underlying language c++ than the actual code....
@TheMrTka4
@TheMrTka4 8 ай бұрын
I think a lot of things have been said over the course of all these videos. The code author can begin to correct or rework the project at this stage. Everyone needs a little refresher, different code, different author.
@y4ni608
@y4ni608 8 ай бұрын
Yeah i did spent alot of time rewriting it and im really happy now. I hope he reviews the newly written code + project structure
@powerclan1910
@powerclan1910 8 ай бұрын
@@y4ni608 let's hope @The Cherno gets to see this
@andreirusei2466
@andreirusei2466 8 ай бұрын
What theme are you using for visual studio?
@lalishansh
@lalishansh 8 ай бұрын
Dark theme and visual assist color scheme, though if you are student i would recommend JetBrains IDE's (Rider for Visual Studio Solution based), they are faster and more accurate than `Visual Studio + Visual assist` (they just took time indexing symbols, after that they blaze through)
@gower1973
@gower1973 8 ай бұрын
He also spelt physicsbody wrong in the typename
@nathbarbosa83
@nathbarbosa83 7 ай бұрын
I love your videos, but for some reason they give me headaches
@n8style
@n8style 8 ай бұрын
love a Ph *s* ysicsBody, much better than a PhysicsBody lol
@mjthebest7294
@mjthebest7294 8 ай бұрын
Where is the raytracing series? :/
@Mempler
@Mempler 8 ай бұрын
ive eaten it.
@krids3546
@krids3546 8 ай бұрын
Black myth wukong,i need reaction from u,please❤
@skeleton_craftGaming
@skeleton_craftGaming 8 ай бұрын
Java code is always horrible... (saying this makes me happy) though no its not Java. All code written in any true OOL* (ie java, JavaScript) . I think that true OOP generates messy code as a necessity *to be a true OOL at least two things have to be the case 1) the smallest exposed unit in a translation layer has to be an object 2) all classes [either directly or indirectly] have to inherit from one single base class [most of the time named Object]
@leshommesdupilly
@leshommesdupilly 8 ай бұрын
Did the same lol
@easyBob100
@easyBob100 8 ай бұрын
Over complicated IMO.
@sakithanavod9289
@sakithanavod9289 8 ай бұрын
First ❤
@OwnerZBAT
@OwnerZBAT 8 ай бұрын
second
@mehmedcavas3069
@mehmedcavas3069 8 ай бұрын
24 sec ago :O
@leshommesdupilly
@leshommesdupilly 8 ай бұрын
Moral of the story kids: std::vector
@MrHuman-iy5lw
@MrHuman-iy5lw 8 ай бұрын
I think we had enough of this repo
PATH TRACER made by 15-YEAR-OLD in C++ OpenGL! // Code Review
36:56
Don't Make This Mistake! // Code Review
29:21
The Cherno
Рет қаралды 52 М.
CHOCKY MILK.. 🤣 #shorts
00:20
Savage Vlogs
Рет қаралды 29 МЛН
女孩妒忌小丑女? #小丑#shorts
00:34
好人小丑
Рет қаралды 46 МЛН
艾莎撒娇得到王子的原谅#艾莎
00:24
在逃的公主
Рет қаралды 49 МЛН
Performance Bottlenecks in My Game Engine
22:45
The Cherno
Рет қаралды 42 М.
LEARNING C++ with Java/C#/Python Experience // Code Review
47:46
The Cherno
Рет қаралды 146 М.
How I Made My Game Engine MUCH Faster...
24:29
The Cherno
Рет қаралды 101 М.
WHY did this C++ code FAIL?
38:10
The Cherno
Рет қаралды 249 М.
The moment we stopped understanding AI [AlexNet]
17:38
Welch Labs
Рет қаралды 931 М.
STOP Watching Coding Tutorials Right Now! My LEARNING FRAMEWORK
12:19
Harkirat Singh
Рет қаралды 252 М.
BEST WAY to understand graphics and rendering code
34:46
The Cherno
Рет қаралды 36 М.
The Importance of Scalable Code // Code Review
32:10
The Cherno
Рет қаралды 139 М.
Global Variables in C++... not as easy as it seems
18:25
The Cherno
Рет қаралды 62 М.