74 points · by bluesilver07 · 9y ago · 75 comments
The growing adoption of C# among game engines, brings me back memories of when game engines finally started to allow C++ on their source code.
Switching from C/C++ to a GC language is nothing like switching from Assembler to C/C++. We did not write Assembler because we liked it. We wrote it because we targeted 8/16-bit archs, which did not fit C/C++ memory model quite well. Because of this Assembler had huge speed and size advantage. As soon as flat memory archs became viable almost everybody dropped Assembler without regret. We lost a bit of performance (which could have been easily regained by rewriting inner loops in Assembler) in exchange of reusable, portable code, type system and terse program texts. These allowed to write much more complex games by engaging bigger teams who could sensibly collaborate over a much bigger project in C/C++.
What is the transition to GC from C++? You sacrifice a lot of performance for freedom from managing memory. I don't know about other people but having shipped few AAA games my only concern was fitting shit into available memory (which GC does not help, to say the least). You allocate memory on load. If you load multiple levels you nuke the previous level's memory. If you stream you do the same but your "levels" are now "segments" in a pool. Of course, if you want to go full-GC and allocate your structures byte by byte, uint32_t by uint32_t - be my guest, not sure how you plan to compete but, hey, load times (same as frame rate) are not that important as they say on the internet :) Nevertheless, as soon as 32-bit targets become completely obsolete people will find out that you can pre-allocate everything off-line in 64-bit so all you will have to do at run-time is map/unmap pages (which GC won't help either). In conclusion: one dropped performance on the floor (due to cache issues, SIMD issues, off-line vs JIT quality issues etc) and picked up the solution to the problem one should not have had in the first place.
> Also, it would mean I didn't have to use OOP to write games.
There are many instances where other programming paradigms are more usable - but in my experience, gameplay logic, specifically, maps very well onto classic OOP concepts.
Since C# is a multiparadigm language with strong functional as well as OO fundamentals, I suspect it will make it possible for libraries and frameworks to be built which enable allocation free code in C# gameloops. It's not just game engines which have these requirements - the same functionality is also critical for high performance servers, and machine learning applications, so this is a language feature with a lot of demand.
Same goes for memory: textures and other assets are managed through the engine; C# only contains game logic data and handles to the assets.
At the time I had many issues with the GC, Large Object Heap and fragmentation (although this had still been in a much older .NET version).
For a game project, both for speed and memory, you want as much as possible to be pre-allocated (and all at once). During run-time you want as few objects as possible being instantiated, that way you save cycles on both the objects, and eventually on the GC. Of course it's not always that easy.
After that it depends on your targets, you'll never fit a Unity C# game as tightly into any target as a native app, but it's a trade-off that's worth making in many cases.
Switching from Assembly into C, Pascal, Modula-2, QuickBasic was mostly an amateur thing until SDKs started to be based on C.
Same with C++, we were the outliers until console vendors started pushing C++ into devs. See Mike Acton's talks about about how he enjoyed having been forced to move from C into C++.
The thing with GC is not the freedom to manage memory, you still need to take care about how memory is managed. What one gets is type safety and an uniform way to manage memory across libraries.
You know exactly who is responsible for releasing it, there are no double deallocations, releasing invalid addresses, or having to deal with library specific smart pointers (CPtr, QSmartPtr, unique_ptr, my_in-house_ptr, ...).
> due to cache issues, SIMD issues, off-line vs JIT quality issues etc
Having a GC doesn't preclude lack of support for cache handling or SIMD.
Many GC based languages have such support and actually C# 7 with Microsoft's toolchain (not Unity's one) does offer such features, even if they can still be improved.
As for JIT quality, it is no different from any other compiler, otherwise as I referred, why not discuss C performance using MS-DOS compiler's benchmarks.
As for smart pointers in C++: they are only useful in a code architecture that essentially emulates C# or Java (all objects as single entities on the heap) using C or C++ in such a "memory-managed style" really doesn't make much sense since it will be slower then a GC. The point about manual memory management is to reduce dynamic allocations as much as possible and have all your data either on the stack or in long-lived, big memory chunks. If you need to allocate and deallocate all the time, or track the ownership and lifetime for every little memory chunk, you're not using C/C++ to its advantage.
PS: C# for tools is great though (not so much because of the language, but because of the standard framework, which is much nicer than the C++ stdlib).
[edit: typos]
The first (major) console C++ SDK library is GNM/GNMX for PS4. Are you saying C++ games has been outliers till 201x? I guess this depends on how you define outliers then. Other than the guy casting his game writing on youtube (Code Hero?) I don't know of any significant titles in C past 2000. I have not seen all the games but I shipped a few myself and have friends working on many more and nobody that I know had been writing pure C. Think of all vtbl-> you'd have to write if you are targeting Windows/Xbox just for the pleasure to name your source file .c instead of .cpp!
>What one gets is type safety
Thanks, we've got this in C++ already.
>You know exactly who is responsible for releasing it, there are no double deallocations, releasing invalid addresses, or having to deal with library specific smart pointers (CPtr, QSmartPtr, unique_ptr, my_in-house_ptr, ...).
Never had been a problem for me. The only game I touched that had smart pointers had them because it used NetImmerse and it got cancelled anyways.
>Having a GC doesn't preclude lack of support for cache handling or SIMD.
I don't know what is cache handling, to be honest, but what I meant is that, since GC moves stuff around memory, it's likely to create cache hazards. And since it probably uses a single pool, you cannot change cache policies on per-entity basis.
>As for JIT quality, it is no different from any other compiler, otherwise as I referred, why not discuss C performance using MS-DOS compiler's benchmarks.
Really? You believe JIT will be on-par with a profile assisted, bruteforcing compiler, which can spend a week optimizing a single function?
By the same metrics, we should evaluate performance of C and C++ code by using benchmarks with MS-DOS C and C++ compilers, which should be about the same age.
Don't mix languages with implementation when talking about performance.
1. Jai is not even released.
2. Jai is a programming language, not a game engine.
Unity is slow because they are using an outdated C# implementation (some old Mono).
Regardless of their GC implementation, in games you don't want opaque runtime behaviour, which a GC always introduces. This leads to weird workarounds in your code that nobody understands instead of having clear and explicit memory management.
Is there a way of running C# with reference counting?
So many of the problems you run into making a game on Unity, Unreal, etc come down to the out-of-the-ordinary requirements of your game and the inevitable peculiarities of the engine itself. Part of becoming an "expert" in building games on a third party engine is knowing where the pain points lie, where you should absolutely not fight The Way It's Done, and what bugs remain unfixed for years on end (Unity asset bundle system, looking at you).
Edit: My point being that unless you know the needs of your particular game and have familiarity with a candidate engine, it will be very difficult to determine if your choice is "best" or not.
Unity is the most known and jobs and markets have sprung up around it as well as a massive asset store now exists, it also has many integrations such as apis and tools that take years to acquire.
Unreal and Epic have Tencent money and are on the way.
The OSS side of this engine is pretty interesting. Will be fun to have another competitor in this area. Xenko looks like a direct Unity competitor even down the the pricing and tiers. The big challenge is the community, asset stores and launched titles under the engine. Branding is important as well, to me Shiva and Xenko are forgettable brands, Unity and Unreal are set in minds.
are they stopping with development?
Edit: Oh, nevermind - on the home page they explicitly say that they're open source.
The old version (which is on github) is GPLv3 apparently.
Unreal may not be open source, but having source access at all license levels continues to be incredibly attractive.
> Next-Level C# Game Engine
> Xenko is an open-source C# game engine designed for the future of gaming. It comes with a full toolchain and is especially well suited to create realistic games but allows you much more!
The Economist is a good example here. In every article, every time a new name or topic is introduced, it will provide a few words describing the person/thing. An example taken from the first sentence of the first article I opened: "Much of the language used by Mike Pence, America’s vice-president, [...]"
Writers for "progress announcements" blogs like this one, don't tend to write in this style, because these writers know that the only interest anyone would have in a such a blog is if they already knew what the subject was and then wanted to subscribe for updates.
Which is to say, deep-linking to a progress-announcement blog from another website is basically almost always entirely useless, and the webmasters of such blogs would actually do well to disable it entirely (e.g. with a robots.txt policy + a server-side hotlink-detection redirection rule) and just suggest that people interested in sharing the announcement, should instead write a few lines of "actual journalism" on their own blog about the release, and then share that.
People who like linking directly to primary sources would hate this, but sometimes primary sources are not in the easily-consumed essay or encyclopedia-article styles that much of the modern web has become. Sometimes a primary source is just a commit log, or a diary, where you need to "go back" to get any context. The primary source gets to do what it likes; it's not beholden to the Internet. If someone wants a good summary to share, they're beholden to write one.