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

Sdílet
Vložit
  • čas přidán 14. 01. 2024
  • 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

Komentáře • 128

  • @pritishranjan
    @pritishranjan Před 3 měsíci +50

    This is insane. Please tell us more on bflat and more like this.

  • @EduardoAG
    @EduardoAG Před 3 měsíci +4

    I just got this article on yesterday's C# Digest but I prefer a 12 min video than a 14 min read lol

  • @F1nalspace
    @F1nalspace Před 3 měsíci +41

    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 Před 3 měsíci +1

      Does static linking kinda mean 'Embedded'?

    • @F1nalspace
      @F1nalspace Před 3 měsíci

      @@shahzaibhassan2777 Yes, the more libraries you statically link, the more larger your executable will become.

    • @xormak3935
      @xormak3935 Před 3 měsíci

      @@shahzaibhassan2777 Pretty much, yeah.

    • @ProtossOP
      @ProtossOP Před 3 měsíci

      @@shahzaibhassan2777 it means code is pasted inside your program

    • @patvax532
      @patvax532 Před 3 měsíci

      @@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.

  • @XennialGeek
    @XennialGeek Před 3 měsíci +17

    I read that article yesterday. Pretty cool that you are doing a video about it, despite its extremely niche use case.

  • @tonicblue
    @tonicblue Před 3 měsíci +8

    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!

  • @HimmDawg
    @HimmDawg Před 3 měsíci +7

    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 Před 3 měsíci +2

    IOCCC for C# next? :D
    The line between language abuse and optimization is thin.
    AWESOME!!

  • @Mosern1977
    @Mosern1977 Před 3 měsíci +4

    Very interesting. Some times you need smaller executables, so these are some very good tricks to know about.

  • @jongeduard
    @jongeduard Před 3 měsíci +6

    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.

  • @JoelBrage
    @JoelBrage Před 3 měsíci +39

    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 Před 3 měsíci +1

      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 Před 3 měsíci +1

      memory? GC left from building a long time ago in the video lmao (jk jk)

  • @yordantodorov1890
    @yordantodorov1890 Před 3 měsíci +2

    Man, this stuff is crazy! You are great🎉

    • @stevenj8261
      @stevenj8261 Před 3 měsíci

      This is Michal creator of bflat which rocks
      podcasts.google.com/feed/aHR0cHM6Ly90aGVkb3RuZXRjb3JlcG9kY2FzdC5saWJzeW4uY29tL3Jzcw/episode/NmI2OWU4NWYtMzcwMS00ZTRmLWI2NGMtZjZmMTI3MjJlZDVk?ep=14

  • @SudhanshuMishrafxpert
    @SudhanshuMishrafxpert Před 3 měsíci +1

    Great to see what's possible! Please make a video about bflat, it looks intriguing.

  • @ukasz-xn8kn
    @ukasz-xn8kn Před 3 měsíci +1

    Some ideas for practical usage of bflat would be welcome. Thank you for the video!

  • @brucebroussard2565
    @brucebroussard2565 Před 3 měsíci +1

    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.

  • @logank.70
    @logank.70 Před 3 měsíci +2

    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.

  • @user-hr7yc3qp8e
    @user-hr7yc3qp8e Před 3 měsíci +1

    Thanks for the video :) Please make a video about bflat too

  • @ionutdogaru8533
    @ionutdogaru8533 Před 3 měsíci

    Best in wasm projects. Thanks !

  • @Biztactix
    @Biztactix Před 3 měsíci +2

    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

  • @iron_spark
    @iron_spark Před 3 měsíci

    This is amazing!

  • @modernkennnern
    @modernkennnern Před 3 měsíci +1

    This is really cool, and shows the potential future of native aot

  • @CharlesBurnsPrime
    @CharlesBurnsPrime Před 3 měsíci +1

    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.

  • @alistermunro7090
    @alistermunro7090 Před 3 měsíci +1

    Nice to see some proper code in C#

  • @waleed-alshinawi
    @waleed-alshinawi Před 3 měsíci +1

    Thank you for the video Nick, can you make a video where this is related to dotnet api.
    Thanks again

  • @josephizang6187
    @josephizang6187 Před 3 měsíci +2

    Please a bflat video would make a ton of sense

  • @obinnaokafor6252
    @obinnaokafor6252 Před 3 měsíci +1

    Michael already did that. C# and #dotnet are amazing.

  • @daStitches
    @daStitches Před 3 měsíci

    This is wild, would definitely like to see more on bflat.

  • @ErazerPT
    @ErazerPT Před 3 měsíci +27

    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 Před 3 měsíci +2

      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

  • @Lombardio
    @Lombardio Před 3 měsíci +2

    I don't see myself using bflat in my day job, but I would watch a video about its features.

  • @alexclark6777
    @alexclark6777 Před 3 měsíci +1

    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).

  • @nimce4u
    @nimce4u Před 3 měsíci +1

    bflat sounds amazing! please do a video about it

  • @jigneshkusakiya8570
    @jigneshkusakiya8570 Před 3 měsíci

    Hello Nick,
    Please can you make a video on how to start with DSA in C# or a road map kind of video.
    Thanks

  • @AndrewJonkers
    @AndrewJonkers Před 3 měsíci +2

    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.

  • @antonmartyniuk
    @antonmartyniuk Před 3 měsíci

    After seeing this I need to hire Nick to trim one of the applications running on the paying terminal device

  • @dsuess
    @dsuess Před 3 měsíci +3

    **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 Před 3 měsíci

      The idea itself I agree with, but like, this is sacrificing essential parts of the runtime and portability just for code size reduction

  • @tellur808
    @tellur808 Před 3 měsíci +6

    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 Před 3 měsíci +2

      farbrausch!

    • @samuelschwager
      @samuelschwager Před 3 měsíci +2

      kkrieger?

    • @reikooters
      @reikooters Před 3 měsíci

      I remember playing it when it came out and that was more like 20 years ago actually

    • @tellur808
      @tellur808 Před 3 měsíci

      @@reikooters don't think it was quite 20 years, but more than 10 definitely

    • @samuelschwager
      @samuelschwager Před 3 měsíci

      @@tellur808 2004!

  • @Andrew90046zero
    @Andrew90046zero Před 3 měsíci

    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.

  • @Spud9
    @Spud9 Před 3 měsíci +1

    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.

  • @Mikarsoft
    @Mikarsoft Před měsícem

    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.

  • @SajjadArifGul
    @SajjadArifGul Před 3 měsíci

    awesome 😮

  • @khsumate
    @khsumate Před 3 měsíci

    cool, please do more vdo for bFlat.
    also the c# self-contain aot .exe with windows gui from both .net and bFlat.
    thanks

  • @derangedftw
    @derangedftw Před 3 měsíci +1

    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...

  • @aurinator
    @aurinator Před 3 měsíci +2

    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 Před 3 měsíci

      It is C#. Every programming language has interoperable capabilities as well as ability to call into the native layer.

  • @vincentverweij1053
    @vincentverweij1053 Před 3 měsíci

    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!

  • @shioli3927
    @shioli3927 Před 3 měsíci +2

    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.

  • @vandermjr
    @vandermjr Před 3 měsíci

    Very good raycast!!!!

  • @aul7643
    @aul7643 Před 3 měsíci

    damn this is insane

  • @naveedahmed6868
    @naveedahmed6868 Před 3 měsíci +1

    Definitely, I would like to know more about bflat 😂

  • @mariocamspam72
    @mariocamspam72 Před 3 měsíci +3

    If CsWinRT were trimmable, could it perhaps could have been used instead of manual Win32 pinvoking?

  • @oscareriksson9414
    @oscareriksson9414 Před 3 měsíci

    Finally!🎉

  • @JVimes
    @JVimes Před 3 měsíci

    I'm surprised trimming isn't a bigger priority. Bflat looks really cool.

  • @LoKSET
    @LoKSET Před 3 měsíci

    That's like C++ with extra steps at this point 😀

  • @burtonrodman
    @burtonrodman Před 3 měsíci

    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

  • @JoeLizFamily4
    @JoeLizFamily4 Před 3 měsíci +2

    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.

  • @ianknowles
    @ianknowles Před 3 měsíci +1

    Nick never programmed a dam thing on a Speccy ;)

  • @JoelSantosPt
    @JoelSantosPt Před 3 měsíci +7

    I would just go with C++ at that point 😅

    • @MaximilienNoal
      @MaximilienNoal Před 3 měsíci

      Nah, Rust all the way.

    • @foobar69
      @foobar69 Před 3 měsíci

      ​@@MaximilienNoalrust is just an uglier way of doing the same thing as cpp.

  • @themiwi
    @themiwi Před 3 měsíci +1

    Have you tried running the exe through UPX? Usually that's able to squeeze out 50ish%.

  • @shahzaibhassan2777
    @shahzaibhassan2777 Před 3 měsíci

    This is insane

  • @bambosa4952
    @bambosa4952 Před 3 měsíci +2

    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 Před 3 měsíci +1

      No in Zerolib there is no GC

  • @tosunabi1664
    @tosunabi1664 Před 3 měsíci

    Crazy.

  • @finald1316
    @finald1316 Před 3 měsíci +5

    B flat for C sharp... I see no pun here.

    • @nius3774
      @nius3774 Před 3 měsíci +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.

  • @chrisnuk
    @chrisnuk Před 3 měsíci

    Excellent, I knew I shouldn't have thrown my floppy disk drive away..

  • @stepanhakobyan
    @stepanhakobyan Před 3 měsíci

    Unity successor may use this.

  •  Před 3 měsíci +1

    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 Před 3 měsíci +1

      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... ;-) )

    •  Před 3 měsíci

      @@igorthelight I know :)

  • @AnnasVirtual
    @AnnasVirtual Před 3 měsíci

    that's crazy

  • @QwDragon
    @QwDragon Před 3 měsíci

    Great!
    But what does antivirus thinks about this app?

  • @ziaulhasanhamim3931
    @ziaulhasanhamim3931 Před 3 měsíci

    anything on memory usage and performance of bflat?

  • @viktoralferov2874
    @viktoralferov2874 Před 3 měsíci

    We call it: Evolution, Mr. Anderson...

  • @FazMize
    @FazMize Před 3 měsíci

    What is that fancy terminal ?

  • @brunettimarco
    @brunettimarco Před 3 měsíci +1

    bflat as name is genius

  • @charles_kuperus
    @charles_kuperus Před 3 měsíci

    Yes please gives us a video on bflat

  • @Dennis67334
    @Dennis67334 Před 3 měsíci

    Any reason you are not switching to the new UI?
    Just curios.

  • @JustNightmare
    @JustNightmare Před 3 měsíci

    Do a video about b flat

  • @joost00719
    @joost00719 Před 3 měsíci

    I'm curious how this improves performance

  • @user-uk2qj7qk1x
    @user-uk2qj7qk1x Před 3 měsíci +1

    I think that we wasting a lot of SSD space to store a lot of dotnet runtime copies

  • @ousspero
    @ousspero Před 3 měsíci +1

    If this supports WebAssembly, it would be insane.

  • @cverde1234
    @cverde1234 Před 3 měsíci

    One day we'll share modern applications on floppy disks

  • @KvapuJanjalia
    @KvapuJanjalia Před 3 měsíci

    DllImport with asterisk as a DLL path is new to me. What even is that?

  • @rivercitron2000
    @rivercitron2000 Před 3 měsíci +1

    I was actually waiting for the QR code 😢

  • @newgap1980
    @newgap1980 Před 3 měsíci

    Could be nice if this works with Blazor

  • @T___Brown
    @T___Brown Před 3 měsíci

    Cool stuff but i would rather see what can be done on api's than a game. Same with the new trimmed containers.

  • @JamesHarrisonHaribo
    @JamesHarrisonHaribo Před 3 měsíci

    I’d love to see the memory usage as well.

  • @SodomEndGomorra
    @SodomEndGomorra Před 3 měsíci +1

    Fork bomb in qr? Who test?

    • @marcovonhagen
      @marcovonhagen Před 3 měsíci

      I will never ever scan a qr code again 😂

  • @urbanelemental3308
    @urbanelemental3308 Před 3 měsíci

    Show me bflat if there's a chance I'll actually use it

  • @farzadmf
    @farzadmf Před 3 měsíci +5

    I wish they'd named it 'dflat`

    • @nius3774
      @nius3774 Před 3 měsíci +2

      Yeah, they went for "be flat" (remove sharpness) instead of musical notation correctness.

    • @farzadmf
      @farzadmf Před 3 měsíci

      Nice, good to know; that didn't come to my mind

  • @lmao01
    @lmao01 Před 3 měsíci

    I dont understand why it isnt done by default (i.e. stripping of unused methods) when it literally saves 90% + of size.

  • @kinsondigital
    @kinsondigital Před 3 měsíci

    Bflat? Yes please, give me another.

  • @2710dw
    @2710dw Před 3 měsíci

    Such a missed opportunity for bflat to be called Bb.

  • @adamwox
    @adamwox Před 3 měsíci +2

    And we are still getting the 200GB update to Call of Duty... 🤦‍♂

  • @lordmetzgermeister
    @lordmetzgermeister Před 3 měsíci

    The thumbnail is literally what she said

  • @ks1970in
    @ks1970in Před 3 měsíci

    These settings should be default

  • @one.pouria786
    @one.pouria786 Před 3 měsíci +1

    A very cool way to develop malware ... 😅

  • @swordblaster2596
    @swordblaster2596 Před 3 měsíci

    Fun, but of limited application TBH.

  • @thedude6810
    @thedude6810 Před 3 měsíci

    Size matters, bigger is better.

  • @457Deniz457
    @457Deniz457 Před 3 měsíci +1

    3..2..1.. new viruses will come 😅

  • @sergey5996
    @sergey5996 Před 3 měsíci

    Why

  • @LukasPetersen-bm4ep
    @LukasPetersen-bm4ep Před 3 měsíci +2

  • @md.jannatulnayem4328
    @md.jannatulnayem4328 Před 3 měsíci

    Bring us more bflat content 🥹