Can my windows game be made to run on Linux? [Solved]

Someone requested my game on Linux! :slight_smile:

They say they can normally run windows games on there, why they were disappointed mine cannot.

Is there a way to re-deploy my game so it can run on Linux?

I mean, I guess I know it can be done with enough effort, but how much is enough?
-It’s a small free game, and my time is limited. What am I looking at here?

You should be able to create a second project targeting Linux and share the majority of your code between projects. I’ve never done it, so I don’t know what’s involved, but I’ve done similar things with Xamarin apps.

@Arcadenut Why are you so familiar?

1 Like

No idea.

1 Like

Yea this is the approach I use when I target Android and Windows. You do have to be aware that different operating systems handle things differently sometimes, though you’re probably safe between Windows and Linux.

If you do find anything you need to do specialized for one or the other, dependency injection is the easiest approach I found. Just use an interface to define behaviour, then make a Windows implementation and a Linux implementation. Instantiate them in the Program.cs entry point for the appropriate OS and pass to your game :slight_smile:

Alternatively, some folks like to use #if directives. Personally I’m not a fan because I find them confusing to read, but they definitely do the trick!

1 Like

It’s a small free game, and I am just doing the one guy a favor.
-This means I don’t at this point want to learn a new skill-set… It wouldn’t be cost effective at this juncture.
If you catch my drift…

I see I can create a cross-platform project using monogame to work for IOS and Linux AND windows…
-So why would I ever create a windows project again :slight_smile:

Now, I assume I could just start a new project, copy paste all my code and content to a new project, and I wouldn’t have to learn anything? …

-Again, I feel I must stress, I know it sounds bad to not want to learn, but I just don’t have the time right now vs the tiny pay-off…

All that stuff you said above, like dependanct injection, interface to define behaviour, and instansiating things in prog.cs entry point is still above my level of understanding… So I feel like that’s a whole day or more of study, which this married man does not have…

If I just plop my old code into a new project, and then re-publish it, do you think that would do what I am looking for?
I don’t rely on any libraries or stuff outside of the standard monogame package.

Thanks in advance for understanding.

I think you might be overthinking what’s required :smiley:

In the project for Windows, you have a Program.cs. This is your entry point. Inside that, there is likely a line that reads something along the lines of…

Game game = new Game();
...
game.Run();

Or whatever the Game class in your project got renamed to. Step 1 is to just create a new, empty Linux project. This will also have a Program.cs in it. Delete the Game class that’s in the new project and reference the Windows project. Try instantiating and running that from the Linux Program.cs.

Unless they did anything crazy, that might actually work. You’ll have to test. If it doesn’t, and it turns out some code was used on Windows that isn’t compatible with Windows, you’ll have to find some means of solving that.

(ie, the approaches I mentioned above)

This is based on my work with Android/Windows. I don’t have access to a Linux machine, but I’d imagine it’s pretty much the same, just a bit easier. On Android, you don’t have a mouse, so I had to write an input class implementation, as well as something to handle Android File IO and Screen Resolutions. It’s also not that hard to do, so even if you have to do some OS specific implementation, it’s pretty straight forward! It just might require a bit of refactoring if you decide you really want a Linux port.

1 Like

copy your game code over to a new platform independent open gl project

What I personally do is create a MonoGame Shared Project, then reference the shared project from both a DesktopGL (for Linux & Windows) and a Windows DirectX Project (windows only). You will also need to create a Content.mgcb file in the shared project.Then modify program.cs in the platform-dependent (GL, DX, etc.) to use the Game defined in the shared project. It’s a really simple process and takes at most 10mins of your time (if all goes well). That way, you have centralised code, making updates simpler to create.

1 Like

I did it the same way as @CowboyJed with Windows, Linux and Android projects each using shared code from a shared project. The template for the MonoGame shared project is just a normal shared project but has the MonoGame reference added already as far as I know but better recheck this if this is correct info if needed.
With shared content it was a bit difficult for me to have this set up the correct way but it worked finally.
Also for Android I needed to fix some namespace issue.
But this is all for the release 3.71 release so maybe just wait some days more for the official release of version 3.8 of MonoGame. There the setup is hopefully easier and works without having to adjust some things manually.

Found some old notes here they are maybe helps if you want to test it with version 3.71. The issue with the namespace was only due to the naming of the Android project! See notes. Sorry for the bad formatting, these where just some personal notes originally and I copy pasted the warnings and errors from VS 2019 which includes the columns from there but without delimiter or something which makes it a little difficult to read maybe.

1. New solution named "MultPlatformTestMG" with Android project named "MultPlatformTestMG.Android"
2. 1 Warning -> "AndroidManifest file does not exist	MultiPlatformTestMG.Android"
3. Create Android manifest -> Reload all
4. 1 Error -> "Error CS0234 The type or namespace name 'Content' does not exist in the namespace 'MultiPlatformTestMG.Android' (are you missing an assembly reference?)	
MultiPlatformTestMG.Android	C:\...\VS 2019\MultiPlatformTestMG\MultiPlatformTestMG.Android\Activity1.cs	13	Active
5. Either change line with error to ", LaunchMode = global::Android.Content.PM.LaunchMode.SingleInstance" or ", LaunchMode = LaunchMode.SingleInstance" to resolve namespace conflict. Also possible: don't use ".Android" at the end of the projects name to avoid it in the first place!
6. 1 Error -> Warning XA5302: Two processes may be building this project at once. Lock file exists at path: C:\...\VS 2019\MultiPlatformTestMG\MultiPlatformTestMG.Android\obj\Debug\90\.__lock
7. 3 Warnings Severity	Code	Description	Project	File	Line	Suppression State
Warning		The file 'C:\...\VS 2019\MultiPlatformTestMG\MultiPlatformTestMG.Shared\Content\Content.mgcb' could not be added to the project.  There is already a link to 'C:\...\VS 2019\MultiPlatformTestMG\MultiPlatformTestMG.Shared\Content\Content.mgcb'. A project cannot have more than one link to the same file.	MultiPlatformTestMG.Linux 

Thanks,
Is this release actually due within a matter of days?

I think so but I don’t know how long until next release, maybe somebody else can give you more information on this. Meanwhile you can check this thread here where you might find some useful information MonoGame 3.8 prerelease packages are up on NuGet

Should be by weeks end.

2 Likes

Hey all, Thanks for participating.

What I took away from this was "new project \ X86 + OpenGL. Drag and drop code, content, wiggle a few lines into place and walaaa.

My game was originally a win64 project, now it should run on mac and linux too. Not bad for a handful of hours.

If anyone wants a look heres a link: https://commonpepe.itch.io/the-kekistani-grinder

Looks awesome. Yes, Silk worm was an Arcade Game first.

https://www.arcade-museum.com/game_detail.php?game_id=9546

1 Like

arcadenut, wow, I just got that :slight_smile:

That’s so cool to come to this forum, and a guy NAMED arcadenut joins in about arcades :slight_smile: From the looks of it, the amiga was the better version. Or am I just nostalgic for amiga games?

Well, I’m partial to the Atari ST, but we’ll save that war for later :stuck_out_tongue:

I swear you have a youtube channel…

1 Like