rajko-horvat / OpenCiv1

Open source rewrite of the original Civilization 1 Game designed by Sid Meier and Bruce Shelley in year 1991
MIT License
232 stars 11 forks source link

Move to .NET Core 8 ? #35

Closed maximilien-noal closed 8 months ago

maximilien-noal commented 9 months ago

Hi !

Using the latest .NET would make this cross platform and enable more contributions from people who do not use Windows.

I'm curious, what would be the main issues preventing that, and would you accept such a PR ?

rajko-horvat commented 9 months ago

I was also thinking about transition to .NET Core/MAUI.

But few issues are preventing me to do just that:

  1. You can't hook Key Up/Down and Mouse Up/Down/Move events, also, there are no alternatives. This specifically impacts Alt+?, Ctrl+? key combinations and map display (moving, etc.).
  2. Paint event, couldn't find real alternative.
  3. The code is still rough as there are a couple of objects still to be translated to managed state, also, the original dialogs would need to be translated to real .NET Forms/Dialogs.

I'm doing this step by step, and sure enough there will come a time when the gap will be almost non existent, but for now these are real problems preventing me to migrate to .NET Core.

For now Mono .NET allows for such cross platform interoperability.

maximilien-noal commented 9 months ago

For the UI side of things, I'm sure everything can be replaced with AvaloniaUI. Unless you use MDI (Multi Document Interface), which is not present.

  1. Spice86 (a similar project that I contribute to. We focus on Dune) hooks up those events with AvaloniaUI with no problems: https://github.com/OpenRakis/Spice86 and https://github.com/OpenRakis/Cryogenic contains the mix of C# "fake ASM" with the emulation of machine code. (We also have a discord, here if you are interested to compare our approaches of mixing C# code with machine code:: https://discord.gg/sPbRQGWdsY )
  2. See this issue for the paint event: https://github.com/AvaloniaUI/Avalonia/discussions/12306
  3. I think this can be preserved and that the move to .NET 8 + AvaloniaUI won't change that... ? Is there more to it ?

There is a mid-step than I see: Still using WinForms, but the latest .NET 8 introduces binding APIs. Alas, I don't know how this would impact users of Mono.

WinForms code, and furthermore code-behind code (The partial class MainForm.cs file not generated by the VS Designer) tend to mix business logic with UI logic and form spagetthi code.

The UI side of things seems simple enough to be fixed very quickly, before it becomes a problem. WinForms is very problematic with this, very quickly (10 years of experience dealing with it).

WinForms in .NET 8 introduces binding APIs that enables the usage of the MVVM pattern, which makes things easier to maintain in the long run, and separate UI logic from business logic.

(I've done a ton of WinForms / WPF / AvaloniaUI, and a ton of .NET work, as you can see)

rajko-horvat commented 9 months ago

These are good news indeed :)

For now OpenCiv1 depends on one simple WinForm (MainForm.cs) which hooks:

There are a few buttons, Pause/Run button, and Hide/Display screen 1-n

You can see details in MainForm.cs (it's generated by VS Designer!) it has a little bit of code enough to interface with underlying code nothing more.

If you can perhaps contribute in alternative MainForm.cs code that would be great, as all other things in code should work also in .Net Core. I'm sorry, but for now I really don't have time (already late with a few projects) to invest in learning new .NET Core things. For now, I have done one medium complexity .NET Core WebApp (Revigo) which works great, it's a little different than ASP.NET, but overall the experience has been very positive.

Perhaps there are a few NULL object references, but these can be resolved with time (as .NET Core is compatible with NULL object references).

I'm sure there are many people who will be happier with .NET Core version.

However, I plan to port code later on to JavaScript, as that would give us true Multiplatform capabilities, Multiplayer, real Hall of fame, game Save sharing, etc.

Of course, everyone will be able to run their own private server ;) for offline playing, etc.

maximilien-noal commented 9 months ago

Thank you for this detailed answer.

Actually, the very first contribution would be to move to SDK-style .csproj files. This does not imply by itself a move from .NET Framework.

However, I plan to port code later on to JavaScript, as that would give us true Multiplatform capabilities, Multiplayer, real Hall of fame, game Save sharing, etc.

I'd use Blazor for that, but it's just because I really dislike Javascript, and keeping the same C# codebase would save time and efforts. Blazor uses C# seamlessly on the server side and on the client side. AvaloniaUI can do it too, with WASM, but Blazor is more documented. Blazor still can use JS modules if needed.

rajko-horvat commented 9 months ago

I completely overlooked Blazer ;) Thanks for pointing me the right direction will look at it later.

I specifically meant to upgrade to .NET Core/MAUI if possible. Don't know if that supports all events that I need for conversion.

LowLevelMahn commented 9 months ago

...and join the discord channel - there are so few reversing people out there :(

rajko-horvat commented 9 months ago

Did a conversion of a project to a newer format (SDK-style .csproj files).

rajko-horvat commented 9 months ago

...and join the discord channel - there are so few reversing people out there :(

The invite link expired...

maximilien-noal commented 9 months ago

Here is a new one https://discord.com/invite/bXtzpqPj

I will send a PR today for net core.

rajko-horvat commented 8 months ago

I tried today on Linux Ubuntu and MacOS:

image

image

It works!!!

rajko-horvat commented 8 months ago

I would suggest that everyone who wants to participate in testing OpenCiv1 before release to do so ;)

axx0 commented 8 months ago

Very good! I actually suggest you show these two screenshots in the readme section.

richardpenman commented 8 months ago

wow just tried OSX and was straightforward:

$ cd OpenCiv1/src
$ dotnet run
Screenshot 2024-03-07 at 8 29 10 PM
richardpenman commented 8 months ago

Is there a way to increase the window size?

maximilien-noal commented 8 months ago

By default, there should be.

rajko-horvat commented 8 months ago

No, not yet :( The game is built for 320x200 and I increased it to 640x400 by doubling pixel size. Later on, when I translate more code then it will be possible. Well I could scale the image further, but the game resolution will stay the same.

rajko-horvat commented 8 months ago

By default, there should be.

I fixed the size of the main window. But I could scale the image as user changes the window size...

maximilien-noal commented 8 months ago

No, not yet :( The game is built for 320x200 and I increased it to 640x400 by doubling pixel size. Later on, when I translate more code then it will be possible. Well I could scale the image further, but the game resolution will stay the same.

You can put a viewbox as a parent to the Image control. It will scale it properly at any size.

rajko-horvat commented 8 months ago

No, not yet :( The game is built for 320x200 and I increased it to 640x400 by doubling pixel size. Later on, when I translate more code then it will be possible. Well I could scale the image further, but the game resolution will stay the same.

You can put a viewbox as a parent to the Image control. It will scale it properly at any size.

Yes, perhaps that is what I should do ;)

rajko-horvat commented 8 months ago

Wow, so easy, and it works instantly ;) I committed the changes.

richardpenman commented 8 months ago

Amazing, now full screen mode works! This will make play testing the game easier.

Screenshot 2024-03-08 at 6 26 16 AM
rajko-horvat commented 8 months ago

I'm going to close this, as project was successfully migrated to .NET 8 and Avalonia UI