Angband.oook.cz
Angband.oook.cz
AboutVariantsLadderForumCompetitionComicScreenshotsFunniesLinks

Go Back   Angband Forums > Angband > Development

Reply
 
Thread Tools Display Modes
Old January 12, 2022, 14:30   #1
Dean Anderson
Adept
 
Join Date: Nov 2009
Posts: 187
Dean Anderson is on a distinguished road
.NET Framework vs .NET

As most of you probably know, a year or two ago (*checks calendar* Oh my God it was 2018. That was four years ago!) I ported Cthangband over from C to C#.

At the time I used the .NET Framework 4.5.2.

This was fine, and it was a big improvement to the code. However, it did come with a couple of drawbacks - the big one being that the .NET Framework was (and still is) Windows only, so none of the versions of Cthangband since then have been ported (or even portable) to other platforms. The other major drawback was that for a .NET Framework application to run you need to have the correct version of the .NET Framework installed on your machine, and that makes installation and running of Cthangband more awkward.

However, since then Microsoft have done various things with their language platform. Around the time I was porting Cthangband to use the .NET Framework, Microsoft branched the platform into two - the .NET Framework, which was full-featured but Windows only; and .NET Core, which was cut-down but more platform independent.

Fast forward to now, and those two branches have re-merged. Instead of the .NET Framework and .NET Core being two separate platforms, we just have the single .NET 5 (and in the last couple of months, the new .NET 6) platform which has (almost) all the functionality of the .NET Framework - except for a few Windows-specific bits - and is even more portable than .NET Core.

So I'm thinking of migrating Cthangband from .NET Framework 4.5.2 to .NET 6.

As far as I can tell from some preliminary work, the big pros and cons of that are:

Pros
  • I can compile for Windows, MacOS and Linux from the same source and IDE (I think I can anyway, since I don't have MacOS or Linux I've not been able to test the results). This means that Cthangband can be multiplatform again.
  • .NET 6 allows you to statically link the .NET libraries into your executable, meaning that you can provide a simple .exe (or equivalent for other platforms) that just runs without people needing to download and install the .NET Framework separately.

Cons
  • Cthangband is object oriented, and the whole game state is stored as an object tree with quite a few circular references. In the .NET Framework, I can save the entire game state in a half-dozen lines of code by using Binary Serialization. Unfortunately for me, Binary Serialization has been deprecated and is not included in .NET 6. There are perfectly good security reasons why Binary Serialization was removed, but those reasons don't really apply to Cthangband using it for save-games. If I move to .NET 6 I'm going to have to save the entire object tree by hand into a save file, and that is going to be a lot of effort to write and is going to introduce a lot of scope for bugs and errors.
  • The Cthangband documentation is in HTML format, and is viewed from a within-game web browser. You guessed it - the web browser control is deprecated and isn't included in .NET 6. Again, this is for security reasons (the browser control was IE6 based). If I'm porting to .NET 6 I'm going to have to find a replacement.
  • Cthangband currently used a third-party dll for playing sound and music called irrKlang. I don't yet know whether that is .NET 6 compatible or whether I'll have to change to something different.

So, there are a bunch of developers here - many of who have C# experience. Does anyone know of any other big problems I might face porting from .NET Framework 4.5.2 to .NET Core 6? And does anyone have any suggestions for alternatives for serializing an object tree and displaying the manual? Any other comments or observations about .NET 6 and portability?
Dean Anderson is offline   Reply With Quote
Old January 12, 2022, 14:59   #2
AnonymousHero
Veteran
 
AnonymousHero's Avatar
 
Join Date: Jun 2007
Posts: 1,388
AnonymousHero is on a distinguished road
Regarding the seralization. Is there no reflection-based serialization that would do the trick? I know almost nothing about .NET, but I do know that there are quite a few in JVM-land and it would surprise me if there weren't in .NET land.
AnonymousHero is offline   Reply With Quote
Old January 12, 2022, 15:06   #3
Dean Anderson
Adept
 
Join Date: Nov 2009
Posts: 187
Dean Anderson is on a distinguished road
There is JSON based serialization, and XML based serialization, but as far as I can see they both have limitations when it comes to things like collections and generic types - or at least they did in .NET 5. It looks like the JSON serialization at least has been improved in .NET 6; but I've not had chance to investigate yet.
Dean Anderson is offline   Reply With Quote
Old January 12, 2022, 16:08   #4
AnonymousHero
Veteran
 
AnonymousHero's Avatar
 
Join Date: Jun 2007
Posts: 1,388
AnonymousHero is on a distinguished road
Quote:
Originally Posted by Dean Anderson View Post
There is JSON based serialization, and XML based serialization, but as far as I can see they both have limitations when it comes to things like collections and generic types - or at least they did in .NET 5. It looks like the JSON serialization at least has been improved in .NET 6; but I've not had chance to investigate yet.
I see. I'd bet that JSON serialization + e.g. zstd compression should do the trick nicely. (Circular references in data structures can be tricky tho, but I'm guessing there's some way to handle that.)
AnonymousHero is offline   Reply With Quote
Old January 12, 2022, 16:31   #5
Pete Mack
Prophet
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 6,670
Donated: $40
Pete Mack is on a distinguished road
It sounds like a great idea. Are there after-market serializers available?
Pete Mack is online now   Reply With Quote
Old January 15, 2022, 17:30   #6
Dean Anderson
Adept
 
Join Date: Nov 2009
Posts: 187
Dean Anderson is on a distinguished road
So, I've done some more research, and as is so often the case with Microsoft the initial claims seem to be more marketing fluff than reality.

In practise, you can write fully portable code in .NET 6, but only if you stick to simple console apps with no UI.

If you want to write apps with a UI, you have basically three choices...

1) Windows Forms or Windows Presentation Framework (WPF). These are the standard UI options for the older .NET Framework, and they are what Cthangband currently uses. Specifically, Cthangband uses WPF, because (unlike Windows Forms, which is very old and only kept going for backwards compatibility) WPF takes advantage of hardware acceleration. While you can still write Windows Forms apps or WPF apps in .NET 6, they are Windows-only, so if you use them in your application it stops being portable.

2) Multi-platform Application User Interface (MAUI). This is the new UI library for .NET 6, and is an expansion of the older third party Xamarin. It is portable, but designed for mobile rather than desktop, so the choice of platform is Android, iOS, or Windows. It doesn't support MacOS or Linux (although I think you can use Mac Catalyst to run the iOS apps it creates on MacOS).

3) Blazor. I didn't look into this too deeply, but it seems to be Microsoft's new attempt at a web UI. It strikes me as probably having the lifespan and take-up of Silverlight, so I ignored it.

This is all rather disappointing, because none of the above give me a UI that can be used on Windows, MacOS, and Linux.
Dean Anderson is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 20:30.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, vBulletin Solutions Inc.