Learning Programming by Trying and Failing // Code Review

  Рет қаралды 39,492

The Cherno

The Cherno

Күн бұрын

Пікірлер: 97
@TheCherno
@TheCherno 11 ай бұрын
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 11 ай бұрын
Sure, do another video on how you would refactor this code. Or, have you done a video on profiling?
@y4ni608
@y4ni608 11 ай бұрын
@@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 11 ай бұрын
did you see my email about my c game engine
@mathsDOTearth
@mathsDOTearth 11 ай бұрын
Failing to learn or failing, to learn.
@prakashraj4519
@prakashraj4519 11 ай бұрын
I think it's the later
@user-sl6gn1ss8p
@user-sl6gn1ss8p 11 ай бұрын
you should open a fortune cookie business
@BruceOnder
@BruceOnder 10 ай бұрын
​@@user-sl6gn1ss8p Or, should they open a fortune, cookie business?
@alexkhazov7264
@alexkhazov7264 11 ай бұрын
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 :)
@user-sl6gn1ss8p
@user-sl6gn1ss8p 11 ай бұрын
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.
@lromaniuk
@lromaniuk 11 ай бұрын
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 10 ай бұрын
*whether
@Gastrostomi
@Gastrostomi 11 ай бұрын
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.
@TheAxeForgetsTheTreeRemembers
@TheAxeForgetsTheTreeRemembers 11 ай бұрын
Yes! Possible solutions would be a great follow up!
@informagico6331
@informagico6331 11 ай бұрын
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 11 ай бұрын
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.
@GB_Parametric
@GB_Parametric 11 ай бұрын
Would love to see the implementation of ECS.
@whoshotdk
@whoshotdk 11 ай бұрын
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 10 ай бұрын
SAME !!
@aboliguu1168
@aboliguu1168 4 ай бұрын
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.
@marcsh_dev
@marcsh_dev Ай бұрын
@@whoshotdk Read up on data oriented design. Watch videos from Mike Acton Lookup structure of arrays vs array of structures (ECSs are structures of arrays) Restating what aboliguu said, I like to have in an array. then in another array. Each index of matches the same index of . can be individual arrays themself, or things like vector3. Ive played around with changing up the data, and it really depends on what operations I need to make on the data. Theres quite a few really solid examples running around, so good luck!
@Spirrwell
@Spirrwell 11 ай бұрын
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 11 ай бұрын
If what I've heard is correct, the source engine is a (still fairly well optimized) mess and a half.
@mariwanj5292
@mariwanj5292 11 ай бұрын
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 11 ай бұрын
He already has the game engine series, there he does it in the right way
@mariwanj5292
@mariwanj5292 11 ай бұрын
@@ProGaming-kb9io I know, but visualizing that in a structured diagram will help to understand better.
@gabrielbeaudin3546
@gabrielbeaudin3546 11 ай бұрын
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.
@Theawesomeking4444
@Theawesomeking4444 11 ай бұрын
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 11 ай бұрын
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.
@thygrrr
@thygrrr 6 ай бұрын
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
@gabrielciordas3369
@gabrielciordas3369 11 ай бұрын
Great video as always Cherno, you're like the Bob Ross of programming in c++
@gelis07
@gelis07 6 ай бұрын
sebastian lague is the bob ross of programming
@mad_circuits
@mad_circuits 11 ай бұрын
1:35 It is not possible to "just build, not learning". My opinion.
@NotherPleb
@NotherPleb 11 ай бұрын
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 11 ай бұрын
how would you do that otherwise? store an index into some entities table?
@DeusExAstra
@DeusExAstra 11 ай бұрын
I dont think that's necessarily the case. It depends on how things are structured and what the entities and components do.
@yesntpittzant4156
@yesntpittzant4156 11 ай бұрын
​@@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 11 ай бұрын
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 11 ай бұрын
@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.
@vcv6560
@vcv6560 11 ай бұрын
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.”
@rtc44
@rtc44 11 ай бұрын
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 11 ай бұрын
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
@R4t4n
@R4t4n 11 ай бұрын
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.
@sinom
@sinom 11 ай бұрын
Writing a custom arena allocator would be an interesting video topic
@MasonDixonAutistic
@MasonDixonAutistic 11 ай бұрын
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.
@gsestream
@gsestream 11 ай бұрын
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.
@Nhurgle
@Nhurgle 11 ай бұрын
If you are on a budget, Game Engine Architecture can be read on the Internet Archive ;)
@_blank86a
@_blank86a 11 ай бұрын
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...
@zanagi
@zanagi 11 ай бұрын
Would want to see young Cherno code
@spaaske
@spaaske 11 ай бұрын
Where can I find more elaborate information on keeping a flat structure rather than keeping a hierarchy?
@the_gobbo
@the_gobbo 11 ай бұрын
Really cool book reference! will definitely check it out!
@user-sl6gn1ss8p
@user-sl6gn1ss8p 11 ай бұрын
it is a kinda dense book, but it is really, really good
@meistrimeez
@meistrimeez 11 ай бұрын
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.
@gabetobias443
@gabetobias443 11 ай бұрын
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 11 ай бұрын
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 11 ай бұрын
@@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.
@Driver___
@Driver___ 11 ай бұрын
I actually have 2-3 other similar projects downloaded and opened from where I am learning to write my 2d-3d engine
@tematoscybersage5626
@tematoscybersage5626 11 ай бұрын
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 11 ай бұрын
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 11 ай бұрын
@@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 11 ай бұрын
​@@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 11 ай бұрын
@@whoshotdk Ok, so I will do that. Will notify you here when it will be ready
@sub-harmonik
@sub-harmonik 11 ай бұрын
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)
@rmt3589
@rmt3589 11 ай бұрын
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.
@user-ib3gl6pj6h
@user-ib3gl6pj6h 11 ай бұрын
Nice to see you again
@CreativeSteve69
@CreativeSteve69 11 ай бұрын
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?
@maarten9222
@maarten9222 11 ай бұрын
A lot of the things you mention I see in Rockstar's Rage engine although they love inheritance.
@TheMrTka4
@TheMrTka4 11 ай бұрын
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 11 ай бұрын
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 11 ай бұрын
@@y4ni608 let's hope @The Cherno gets to see this
@andreirusei2466
@andreirusei2466 11 ай бұрын
What theme are you using for visual studio?
@lalishansh
@lalishansh 11 ай бұрын
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)
@bekdev564
@bekdev564 11 ай бұрын
I'd love to see your reaction on GTA VI trailer just like your Unreal Engine 5 reaction video!
@rishavgaming8662
@rishavgaming8662 11 ай бұрын
I was thinking that can dani have comeback but not with unity but with Hazel make video like back then
@sirpalee
@sirpalee 11 ай бұрын
Memory layout of components is an implementation detail of ECS, not a requirement for an ECS system.
@scoliosissy
@scoliosissy 11 ай бұрын
happy birthday for 5 days ago i think
@gower1973
@gower1973 11 ай бұрын
He also spelt physicsbody wrong in the typename
@skeleton_craftGaming
@skeleton_craftGaming 11 ай бұрын
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]
@ev3rybodygets177
@ev3rybodygets177 9 ай бұрын
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....
@mjthebest7294
@mjthebest7294 11 ай бұрын
Where is the raytracing series? :/
@Mempler
@Mempler 11 ай бұрын
ive eaten it.
@n8style
@n8style 11 ай бұрын
love a Ph *s* ysicsBody, much better than a PhysicsBody lol
@nathbarbosa83
@nathbarbosa83 10 ай бұрын
I love your videos, but for some reason they give me headaches
@krids3546
@krids3546 11 ай бұрын
Black myth wukong,i need reaction from u,please❤
@easyBob100
@easyBob100 11 ай бұрын
Over complicated IMO.
@leshommesdupilly
@leshommesdupilly 11 ай бұрын
Did the same lol
@sakithanavod9289
@sakithanavod9289 11 ай бұрын
First ❤
@OwnerZBAT
@OwnerZBAT 11 ай бұрын
second
@mehmedcavas3069
@mehmedcavas3069 11 ай бұрын
24 sec ago :O
@leshommesdupilly
@leshommesdupilly 11 ай бұрын
Moral of the story kids: std::vector
@MrHuman-iy5lw
@MrHuman-iy5lw 11 ай бұрын
I think we had enough of this repo
I HAD to fix this immediately // Code Review
31:47
The Cherno
Рет қаралды 30 М.
PATH TRACER made by 15-YEAR-OLD in C++ OpenGL! // Code Review
36:56
快乐总是短暂的!😂 #搞笑夫妻 #爱美食爱生活 #搞笑达人
00:14
朱大帅and依美姐
Рет қаралды 13 МЛН
УДИВИЛ ВСЕХ СВОИМ УХОДОМ!😳 #shorts
00:49
HARD_MMA
Рет қаралды 2,4 МЛН
Yay😃 Let's make a Cute Handbag for me 👜 #diycrafts #shorts
00:33
LearnToon - Learn & Play
Рет қаралды 117 МЛН
Twin Telepathy Challenge!
00:23
Stokes Twins
Рет қаралды 115 МЛН
The Downsides Of C++ | Prime Reacts
21:23
ThePrimeTime
Рет қаралды 144 М.
Harder Than It Seems? 5 Minute Timer in C++
20:10
The Cherno
Рет қаралды 217 М.
2000 HOUR 2D Game Engine! // Code Review
32:01
The Cherno
Рет қаралды 91 М.
How I Made My Game Engine MUCH Faster...
24:29
The Cherno
Рет қаралды 102 М.
Clean Code is SLOW But REQUIRED? | Prime Reacts
28:22
ThePrimeTime
Рет қаралды 323 М.
Don't Make This Mistake! // Code Review
29:21
The Cherno
Рет қаралды 55 М.
I did a C++ University Assignment
50:23
The Cherno
Рет қаралды 299 М.
Is C BETTER than C++ for beginners? // Code Review
31:16
The Cherno
Рет қаралды 52 М.
快乐总是短暂的!😂 #搞笑夫妻 #爱美食爱生活 #搞笑达人
00:14
朱大帅and依美姐
Рет қаралды 13 МЛН