Building the Smallest C# Game That Doesn’t Need .NET

  Рет қаралды 52,174

Nick Chapsas

Nick Chapsas

4 ай бұрын

Check out my courses on Dometrain: dometrain.com
Become a Patreon and get special perks: / nickchapsas
Hello, everybody, I'm Nick, and in this video, I will show you how we can build a C# Native game that is smaller than 2kb in .NET.
Michal's post: migeel.sk/blog/2024/01/02/bui...
Workshops: bit.ly/nickworkshops
Don't forget to comment, like and subscribe :)
Social Media:
Follow me on GitHub: github.com/Elfocrash
Follow me on Twitter: / nickchapsas
Connect on LinkedIn: / nick-chapsas
Keep coding merch: keepcoding.shop
#csharp #dotnet

Пікірлер: 128
@pritishranjan
@pritishranjan 4 ай бұрын
This is insane. Please tell us more on bflat and more like this.
@XennialGeek
@XennialGeek 4 ай бұрын
I read that article yesterday. Pretty cool that you are doing a video about it, despite its extremely niche use case.
@EduardoAG
@EduardoAG 4 ай бұрын
I just got this article on yesterday's C# Digest but I prefer a 12 min video than a 14 min read lol
@tonicblue
@tonicblue 4 ай бұрын
This was super interesting and I'm glad the algorithm recommended it. I was a C# dev for about 8 or 9 years but switched to pretty much straight Node.js for the last 7. Seeing tooling and this sort of thing is making want to come back a bit and see what I can do. I've got enough gripes with JS and its eco system but I see it's benefits. Knowing that you can do this sort of thing with C# is inviting. I'd really want to see how it compares to Go in performance. Might give it a try, just hope it plays well with Linux!
@F1nalspace
@F1nalspace 4 ай бұрын
Wow i never expected this in C#. Really cool! I didn't read the article, but i assume it works by fully stripping out the entire runtime and unused functions. Because the game itself just calls pure system functions from the win32 api stack and does not use the GC. Also the win32 libraries that are used (kernel32 and user32) are not statically linked, instead it is runtime linked - meaning LoadLibrary() and GetProcAddress() is used. Btw. these techniques are well known in the demo-scene and used in languages such as C and object pascal. For example there was a fully working C64 emulator (Brotkästchen) written in borland delphi 5 that compiles to an executable with just 64 KB.
@shahzaibhassan2777
@shahzaibhassan2777 4 ай бұрын
Does static linking kinda mean 'Embedded'?
@F1nalspace
@F1nalspace 4 ай бұрын
@@shahzaibhassan2777 Yes, the more libraries you statically link, the more larger your executable will become.
@xormak3935
@xormak3935 4 ай бұрын
@@shahzaibhassan2777 Pretty much, yeah.
@ProtossOP
@ProtossOP 4 ай бұрын
@@shahzaibhassan2777 it means code is pasted inside your program
@patvax532
@patvax532 4 ай бұрын
@@shahzaibhassan2777 Static Linking effectively means that whatever you linked will be inside of your final output, as opposed to dynamic linking where your libraries will be linked during startup. Embedded as in contained in your final exe/dll.
@jongeduard
@jongeduard 4 ай бұрын
Wow! NO garbage collector! That is one of the points that Bflat mentions. I guess that means that most standard dotnet stuff becomes totally impossible, even Strings. LOL. But an unsafe application that only targets native Win32 stuff should indeed be able to run. Everything completely unmanaged. However, to be honest, I don't think C# is really a serious option anymore here. Here is where I just like Rust a lot more, or even C and C++, because those languages are actually designed for this job. And C# is simply not. As an experimental showcase though, I think this is cool. Rust with a garbage collector would also by nice for one moment. Just to see that it's possible.
@HimmDawg
@HimmDawg 4 ай бұрын
There's a video from MattKC where he actually put a game into a QR-Code and he also used crinkler. However he could only fit snake into the code. Having a 3d graphics game this small kinda blew me from my chair, not gonna lie.
@jemakrol
@jemakrol 4 ай бұрын
IOCCC for C# next? :D The line between language abuse and optimization is thin. AWESOME!!
@Mosern1977
@Mosern1977 4 ай бұрын
Very interesting. Some times you need smaller executables, so these are some very good tricks to know about.
@yordantodorov1890
@yordantodorov1890 4 ай бұрын
Man, this stuff is crazy! You are great🎉
@stevenj8261
@stevenj8261 4 ай бұрын
This is Michal creator of bflat which rocks podcasts.google.com/feed/aHR0cHM6Ly90aGVkb3RuZXRjb3JlcG9kY2FzdC5saWJzeW4uY29tL3Jzcw/episode/NmI2OWU4NWYtMzcwMS00ZTRmLWI2NGMtZjZmMTI3MjJlZDVk?ep=14
@JoelBrage
@JoelBrage 4 ай бұрын
This just so cool. I love optimizations in general but this is something extra. What happened to performance and memory usage along the way?
@felipealves4856
@felipealves4856 4 ай бұрын
For this particular project, you say? If it is, I believe that it is very optimized, as the maze game makes full usage of OS API calls and unsafe, self-managed resources. There doesn't seem to be any need for garbage collection at all, in this case.
@mona_raiden
@mona_raiden 4 ай бұрын
memory? GC left from building a long time ago in the video lmao (jk jk)
@modernkennnern
@modernkennnern 4 ай бұрын
This is really cool, and shows the potential future of native aot
@ionutdogaru8533
@ionutdogaru8533 4 ай бұрын
Best in wasm projects. Thanks !
@iron_spark
@iron_spark 4 ай бұрын
This is amazing!
@josephizang6187
@josephizang6187 4 ай бұрын
Please a bflat video would make a ton of sense
@logank.70
@logank.70 4 ай бұрын
If I'm being honest. My brain is saying two things. The first is "this is really cool" and the second one is "but why?" There are times where just because you can doesn't mean you should. Maybe the Bflat project falls into that or maybe it doesn't. I honestly don't know. It definitely is really neat though.
@SudhanshuMishrafxpert
@SudhanshuMishrafxpert 4 ай бұрын
Great to see what's possible! Please make a video about bflat, it looks intriguing.
@obinnaokafor6252
@obinnaokafor6252 4 ай бұрын
Michael already did that. C# and #dotnet are amazing.
@alistermunro7090
@alistermunro7090 4 ай бұрын
Nice to see some proper code in C#
@ukasz-xn8kn
@ukasz-xn8kn 4 ай бұрын
Some ideas for practical usage of bflat would be welcome. Thank you for the video!
@daStitches
@daStitches 4 ай бұрын
This is wild, would definitely like to see more on bflat.
@user-hr7yc3qp8e
@user-hr7yc3qp8e 4 ай бұрын
Thanks for the video :) Please make a video about bflat too
@brucebroussard2565
@brucebroussard2565 4 ай бұрын
Reminds me of the old borland turboc from the 80's which as very fast and could be optimized extremely well. Everything old is new again.
@Lombardio
@Lombardio 4 ай бұрын
I don't see myself using bflat in my day job, but I would watch a video about its features.
@CharlesBurnsPrime
@CharlesBurnsPrime 4 ай бұрын
Look up 4k demos. One I remember is droplets of water, rendered with software raytracing, merging and splitting in real-time (and the program was under 4KB. This C# demo is in some ways more impressive because it is written in a high-level (sort of, looking at the code) language rather than assembly language, and it doesn't use any crazy tricks like fractal data generation. Another was the first level of the Interplay game Descent, including music, the 3D level, and lava animations, in 4k. Another was a terrain generator called "mars", which was, IIRC, about 2.8K, and generated unlimited random Martian terrain (the detail wasn't great, mostly red hills). Still a better plot than most Bethesda games.
@AndrewJonkers
@AndrewJonkers 4 ай бұрын
I started programming way back when hand coding byte sized registers with switches. I have NEVER understood the size bloat that has been with us in the decades since. All we are doing here is returning to what should have been before memory and disk space became so cheap and we did not have to bother doing it right first time. My own view is that a code executable should always be derived from a complete source code that then goes with compiler/linker tooling options right to the metal of the CPU. None of this proprietary library crap.
@dsuess
@dsuess 4 ай бұрын
**Make Code Small Again** I LOVE this!! Amazing video, Nick. Every year new toolings come out and default sizes only get larger and larger. Long gone are the days of KB sized GUI apps with minimum resource usage. Really hope this makes a come back again.
@mariocamspam72
@mariocamspam72 4 ай бұрын
The idea itself I agree with, but like, this is sacrificing essential parts of the runtime and portability just for code size reduction
@Biztactix
@Biztactix 4 ай бұрын
Yeah, I'd like to know more about the limitations for Bflat... as I have a few apps which call external windows functions, registry, eventlogs, wmi etc... and I have them AOT'd already... but if there's a significant difference in size, that could be interesting
@nimce4u
@nimce4u 4 ай бұрын
bflat sounds amazing! please do a video about it
@ErazerPT
@ErazerPT 4 ай бұрын
Impressive, but in the end i think it more illustrates how the "usual thing" is pretty wasteful and "loose" than anything else. Reason that "trim obvious fat" isn't default is probably because lord knows how much dependency you have on reflection and/or dynamic code creation.
@qj0n
@qj0n 4 ай бұрын
There is also a tradeoff between binary size, memory allocation, startup time and performance. If you optimize towards one of them, you probably loose the others In this case, he compresses the binary, so startup is longer and possibly you might store both versions in ram, at least for some time. The static loading of libraries prohibits you from usibg gac or sharing the same lib between apps. Size optimisation will not expand loops, so you loose performance on branch prediction Everything has its cost
@waleed-alshinawi
@waleed-alshinawi 4 ай бұрын
Thank you for the video Nick, can you make a video where this is related to dotnet api. Thanks again
@shioli3927
@shioli3927 4 ай бұрын
The zero std lib sais it does not have a garbage collector? So does that mean your game will just memory leak if it ever allocates anything, at any point. I mean I get it for small CLI tools, garbage collection tends to be useless work, because you can just explode the process afterwards. If your total program runtime is a fraction of a second who cares. Is that the intention? Because, I have no idea how I would even deallocate anything in c# by hand. There might be some unsafe black magic.
@alexclark6777
@alexclark6777 4 ай бұрын
I read through Michal's entire blog a few weeks ago when this popped up on Reddit. I'm fairly certain he lives on an island somewhere with a white cat and a giant fish tank full of sharks (possibly with lasers attached to their heads).
@jigneshkusakiya8570
@jigneshkusakiya8570 4 ай бұрын
Hello Nick, Please can you make a video on how to start with DSA in C# or a road map kind of video. Thanks
@SajjadArifGul
@SajjadArifGul 4 ай бұрын
awesome 😮
@antonmartyniuk
@antonmartyniuk 4 ай бұрын
After seeing this I need to hire Nick to trim one of the applications running on the paying terminal device
@mariocamspam72
@mariocamspam72 4 ай бұрын
If CsWinRT were trimmable, could it perhaps could have been used instead of manual Win32 pinvoking?
@aurinator
@aurinator 4 ай бұрын
While I can definitely agree with more than a few posters that this is insane, I'm also going to argue that this isn't really C# - certainly not by itself IMO. But I can at least agree that everything is being orchestrated in C# but it's just P/Invoking into the native land where all the magic happens. So in that respect C# is almost like a Kubernetes to all of the linked (P/Invoked) Services.
@obinnaokafor6252
@obinnaokafor6252 4 ай бұрын
It is C#. Every programming language has interoperable capabilities as well as ability to call into the native layer.
@vandermjr
@vandermjr 4 ай бұрын
Very good raycast!!!!
@tellur808
@tellur808 4 ай бұрын
Reminds me of that 64Kb game from a couple years back that was a fully fledged shooter with for the time decent graphics and sound, all in a 64 kilobyte install. Technologically completely different (they used DirectX or openGL to do most of the heavy lifting) but still crazy what can be done with extremely little
@instazx2
@instazx2 4 ай бұрын
farbrausch!
@samuelschwager
@samuelschwager 4 ай бұрын
kkrieger?
@reikooters
@reikooters 4 ай бұрын
I remember playing it when it came out and that was more like 20 years ago actually
@tellur808
@tellur808 4 ай бұрын
@@reikooters don't think it was quite 20 years, but more than 10 definitely
@samuelschwager
@samuelschwager 4 ай бұрын
@@tellur808 2004!
@JoelSantosPt
@JoelSantosPt 4 ай бұрын
I would just go with C++ at that point 😅
@MaximilienNoal
@MaximilienNoal 4 ай бұрын
Nah, Rust all the way.
@foobar69
@foobar69 4 ай бұрын
​@@MaximilienNoalrust is just an uglier way of doing the same thing as cpp.
@aul7643
@aul7643 4 ай бұрын
damn this is insane
@Spud9
@Spud9 4 ай бұрын
I think if this was boiled down to a single tool and simplified command flags it would be super useful if size was something you were focused on.
@derangedftw
@derangedftw 4 ай бұрын
I wish I could create a framework / engine that takes advantage of this and become a Unity competitor. I wouldn't even know where to start and I've been engineering for 14 years in a completely different field of study. I better get on it...
@finald1316
@finald1316 4 ай бұрын
B flat for C sharp... I see no pun here.
@nius3774
@nius3774 4 ай бұрын
It takes something sharp and commands it to be flat (the opposite of sharp). I guess it could be called RemovEdge or NoEdge, but that's not allowed at Microsoft.
@themiwi
@themiwi 4 ай бұрын
Have you tried running the exe through UPX? Usually that's able to squeeze out 50ish%.
@oscareriksson9414
@oscareriksson9414 4 ай бұрын
Finally!🎉
@naveedahmed6868
@naveedahmed6868 4 ай бұрын
Definitely, I would like to know more about bflat 😂
@khsumate
@khsumate 4 ай бұрын
cool, please do more vdo for bFlat. also the c# self-contain aot .exe with windows gui from both .net and bFlat. thanks
@Andrew90046zero
@Andrew90046zero 3 ай бұрын
I appreciate that you didn't want us to have a stroke from seeing egregious code XD (btw, I didn't see the code yet, still watching the video) The only thing I am dissapointed by with this video is, not seeing a QR code of the binary exe file :P I hope that is indeed possible.
@QwDragon
@QwDragon 4 ай бұрын
Great! But what does antivirus thinks about this app?
@ziaulhasanhamim3931
@ziaulhasanhamim3931 4 ай бұрын
anything on memory usage and performance of bflat?
@shahzaibhassan2777
@shahzaibhassan2777 4 ай бұрын
This is insane
@bambosa4952
@bambosa4952 4 ай бұрын
I wonder how allocations work in zerolib if there is no GC, most likely why most things are static. Is there an allocator included in the lib?
@tj_r_3679
@tj_r_3679 4 ай бұрын
No in Zerolib there is no GC
@Dennis67334
@Dennis67334 4 ай бұрын
Any reason you are not switching to the new UI? Just curios.
@Mikarsoft
@Mikarsoft Ай бұрын
I want to make an IDE based on BFlat where it will have a fully functional nuget package manager and project templates. BFlat 8.0.2 is awsome.
4 ай бұрын
All game studios should learn this trick, maybe the games will be again available to share via diskettes instead of the size 160GB :D
@igorthelight
@igorthelight 4 ай бұрын
In modern AAA games most if it's size are 4k videos and 4k textures. Some repackers let you to not download unnecessary things. (I'm still buying games tho, but when I was a student - that was a totally different story... ;-) )
4 ай бұрын
@@igorthelight I know :)
@vincentverweij1053
@vincentverweij1053 4 ай бұрын
Anyone else who thought about a musical scale after watching this... C sharp, b flat, f sharp, where's the rest of the scale. Joking aside, great video Nick!
@burtonrodman
@burtonrodman 4 ай бұрын
i’ve been looking at the possibility of using nanoframework for RP2040… there’s been work to add support but it’s rough going. if we could bring Sdk style project and use a similar stack to this video i think it could solve a lot of issues
@FazMize
@FazMize 4 ай бұрын
What is that fancy terminal ?
@joost00719
@joost00719 4 ай бұрын
I'm curious how this improves performance
@tosunabi1664
@tosunabi1664 4 ай бұрын
Crazy.
@JoeLizFamily4
@JoeLizFamily4 4 ай бұрын
Interesting how you can make it so small but practically not too useful for me to go all the way down. I think the first suggestion to build "self-contained" is a good option.
@LoKSET
@LoKSET 4 ай бұрын
That's like C++ with extra steps at this point 😀
@ianknowles
@ianknowles 4 ай бұрын
Nick never programmed a dam thing on a Speccy ;)
@JVimes
@JVimes 4 ай бұрын
I'm surprised trimming isn't a bigger priority. Bflat looks really cool.
@stepanhakobyan
@stepanhakobyan 4 ай бұрын
Unity successor may use this.
@AnnasVirtual
@AnnasVirtual 4 ай бұрын
that's crazy
@KvapuJanjalia
@KvapuJanjalia 4 ай бұрын
DllImport with asterisk as a DLL path is new to me. What even is that?
@charles_kuperus
@charles_kuperus 4 ай бұрын
Yes please gives us a video on bflat
@brunettimarco
@brunettimarco 4 ай бұрын
bflat as name is genius
@ousspero
@ousspero 4 ай бұрын
If this supports WebAssembly, it would be insane.
@chrisnuk
@chrisnuk 4 ай бұрын
Excellent, I knew I shouldn't have thrown my floppy disk drive away..
@JustNightmare
@JustNightmare 4 ай бұрын
Do a video about b flat
@viktoralferov2874
@viktoralferov2874 4 ай бұрын
We call it: Evolution, Mr. Anderson...
@rivercitron2000
@rivercitron2000 4 ай бұрын
I was actually waiting for the QR code 😢
@user-uk2qj7qk1x
@user-uk2qj7qk1x 4 ай бұрын
I think that we wasting a lot of SSD space to store a lot of dotnet runtime copies
@T___Brown
@T___Brown 4 ай бұрын
Cool stuff but i would rather see what can be done on api's than a game. Same with the new trimmed containers.
@newgap1980
@newgap1980 4 ай бұрын
Could be nice if this works with Blazor
@cverde1234
@cverde1234 4 ай бұрын
One day we'll share modern applications on floppy disks
@SodomEndGomorra
@SodomEndGomorra 4 ай бұрын
Fork bomb in qr? Who test?
@marcovonhagen
@marcovonhagen 4 ай бұрын
I will never ever scan a qr code again 😂
@adamwox
@adamwox 4 ай бұрын
And we are still getting the 200GB update to Call of Duty... 🤦‍♂
@farzadmf
@farzadmf 4 ай бұрын
I wish they'd named it 'dflat`
@nius3774
@nius3774 4 ай бұрын
Yeah, they went for "be flat" (remove sharpness) instead of musical notation correctness.
@farzadmf
@farzadmf 4 ай бұрын
Nice, good to know; that didn't come to my mind
@lmao01
@lmao01 4 ай бұрын
I dont understand why it isnt done by default (i.e. stripping of unused methods) when it literally saves 90% + of size.
@urbanelemental3308
@urbanelemental3308 4 ай бұрын
Show me bflat if there's a chance I'll actually use it
@JamesHarrisonHaribo
@JamesHarrisonHaribo 4 ай бұрын
I’d love to see the memory usage as well.
@2710dw
@2710dw 4 ай бұрын
Such a missed opportunity for bflat to be called Bb.
@kinsondigital
@kinsondigital 4 ай бұрын
Bflat? Yes please, give me another.
@ks1970in
@ks1970in 4 ай бұрын
These settings should be default
@lordmetzgermeister
@lordmetzgermeister 4 ай бұрын
The thumbnail is literally what she said
@one.pouria786
@one.pouria786 4 ай бұрын
A very cool way to develop malware ... 😅
@swordblaster2596
@swordblaster2596 4 ай бұрын
Fun, but of limited application TBH.
@thedude6810
@thedude6810 4 ай бұрын
Size matters, bigger is better.
@457Deniz457
@457Deniz457 4 ай бұрын
3..2..1.. new viruses will come 😅
@sergey5996
@sergey5996 4 ай бұрын
Why
@LukasPetersen-bm4ep
@LukasPetersen-bm4ep 4 ай бұрын
@md.jannatulnayem4328
@md.jannatulnayem4328 4 ай бұрын
Bring us more bflat content 🥹
How to write "smarter" enums in C#
12:56
Nick Chapsas
Рет қаралды 132 М.
How Are .NET APIs So Much Faster than Everything Else?
13:02
Nick Chapsas
Рет қаралды 70 М.
[Vowel]물고기는 물에서 살아야 해🐟🤣Fish have to live in the water #funny
00:53
ISSEI funny story😂😂😂Strange World | Magic Lips💋
00:36
ISSEI / いっせい
Рет қаралды 148 МЛН
Make Your LINQ Up to 10x Faster!
11:08
Nick Chapsas
Рет қаралды 52 М.
Unlocking Code Coverage: The Ultimate Guide for .NET Developers
21:16
What are record types in C# and how they ACTUALLY work
15:36
Nick Chapsas
Рет қаралды 116 М.
Await Async Tasks Are Getting Awesome in .NET 9!
9:24
Nick Chapsas
Рет қаралды 82 М.
Getting Started with Event Sourcing in .NET
37:07
Nick Chapsas
Рет қаралды 20 М.
Forget Grafana And Prometheus! Start With This.
10:51
Nick Chapsas
Рет қаралды 39 М.
"Stop Using Async Await in .NET to Save Threads" | Code Cop #018
14:05
How IEnumerable can kill your performance in C#
11:02
Nick Chapsas
Рет қаралды 111 М.
Swagger is Going Away in .NET 9!
10:48
Nick Chapsas
Рет қаралды 63 М.
[Vowel]물고기는 물에서 살아야 해🐟🤣Fish have to live in the water #funny
00:53