Using C# Scripting with the Entity Component System // Game Engine series
Вставка
- Опубліковано 27 лип 2022
- Stream ► / thecherno
Support the series and Hazel! ► / thecherno
Main Channel ► / thechernoproject
Code ► github.com/TheCherno/Hazel (scripting branch)
CHAPTERS
#Hazel #GameEngineSeries
If I am not aware, if we do not hold script instance using mono_gc_handle_new, then after 50 or 60 seconds in runtime, mono will delete the script instance and crash. I think this is because we initialize the script on the c++ side and not in the c# scope. And in on runtime stop we have to release this gc handle so that mono GC can delete this object later. Peter knows about this problem, I think.
23:44 There's no need to use "fmt::format". The "std::string" class can append "const char*" as long as they're on the right:
fullName += nameSpace;
fullName += ".";
fullName += name;
fmt::format is superior (performance-wise) and one line of code instead of the three that you've written. It's also just generally easier to read imo
i feel like the script component should take the actual c# source file as an argument and JIT compile it.
the sole reason one would like to have a scripting language usually is the convenience of not having to compile while writing gameplay code.
this "prebuild c# dll" feels a bit odd tbh...
iirc the end goal is that the engine will compile it for you after it detects changes to your C# code. Regardless, there isn't much difference, between an end-user compiling the DLL themselves vs the engine compiling it for you. I imagine it'll take the same amount of time.. one is just a different workflow. Although I see your point.
*Godot devs spending years on 4.0 Vulkan rewrite*
Cherno: I'm going to do it in one day
1:21:56 Is there a particular reason why the EnTT id can't be used instead of an UUID? The underlying type is just a uint32_t if I'm not mistaken. Or can be statically casted as such. uint32_t gives you ~4.3 billion entities.
I ended up completely removing the "ScriptClass" and "ScriptInstance" classes and just added the pointers (MonoClass*, MonoObject*, MonoMethod*) to the script component struct itself. And only storing MonoClass* pointers in that unordered map, no need for two unordered maps.
So many functions that call other functions that call other functions that....... Don't these have a performance penalty?
- Entities aren't just created locally, they can be created all over the place - picture a team developing a game and constantly creating identifiers for assets, entities, scenes etc. So we definitely can't just use an ascending index like entt uses for identification, hence we use randomized IDs. Aside from that, with a 32-bit integer it's not that improbable to get a collision (meaning we create an entity with an ID that's already in use), which is why we use 64-bit identifiers
- Ultimately no, there will be no performance penalty. This is just largely an abstraction we ourselves create, the compiler will inline most of these functions and they will all disappear into pretty much nothing. This has also partially been written with future features in mind
Just like a side note, I like to check for non-empty c-str like this: if(str && *str)
3 6 0 p g a n g
Astigmatism tribute
I'm with Jonathan Blow, after thinking about it I'd rather write everything in one language, both engine and game, and have a powerful visual/data driven scripting solution. Unity basically came to the same conclusion, but the performance of C# becomes a problem, hence the high speed C# with specialized compiler.
Hot reloading C++ is possible. Access voilation as exception is possible. Yes, the std lib is shait. Yes, the syntax is shait. But for the engine you have to do your own libs anyway. And the syntax can be alleviated by exclusively using modern C++. And if that's not good enough I'd think about using a different language for the whole thing. Compile speed, if done right, should honestly not be a problem. My medium sized Unity project takes like 5-6 seconds to reload which feels like an eternity.
Thanks
is this missing from the github for anyone else?
Checkout the scripting branch
@@mjthebest7294 in the next stream he said he forgot to commit it, but thanks for the tip
@@devinschlegel1763 oh, excuse me, I misunderstood :) have a nice day ^^
Hey Cherno, what do you think about C++ scripting? :)
You wouldn't use C++ for scripting specifically, because it has following disadvantages:
1. You have to rely on platform specific ways of dynamically linking the scripts to the engine (or some other complicated things).
2. If you need a feature that is really performance critical, you can write it inside the engine directly using C++ anyway.
3. C++ is hard and unpleasant to work with (But there haven't been any real alternatives until like a years ago)
4. C++ ABI is a giant pain (never worked with it though, so don't listen to me).
5. Some people say you likely should use neither scripting nor an engine at all and just make the game (yt: 'Jonathan Blow on scripting languages').
@@nexovec I respectfully disagree with 3 & 4. Also your point 1, I've done it and it's not that hard :)
Point 2: Everyone might not have access to the engine core
Point 5: It's ok not to use an engine for solo projects. But when you need to be able to make a variety of games in it, you need one. + everyone is not a programmer ;)
What do you guys think about assembly scripting?
@@koki10190 And I have done it in Windows :)
480p gang over here!!
144p gang
finally, HD.
360p gang
Nah, 144p
@@p3rk4n27 I don't even have 144p, only 360p
I'd almost rather watch it on Twitch until the HD version finishes processing.
@@itr00ow93 I have both
Only 360p (I know that it's because the video is new)
360p.
Why this recommend for musicians
UA-cam recommends diversifying your interests in case musicians were to go out of favor
Sea Sharp is a musical notation. Someone used that symbol in the chat (♯ vs #) and UA-cam picked it up, and now you're here. The algorithm will probably pick THIS comment up and add it to the mix.