prime31 / Nez

Nez is a free 2D focused framework that works with MonoGame and FNA
MIT License
1.78k stars 359 forks source link

Headless Usage #161

Closed freeqaz closed 6 years ago

freeqaz commented 7 years ago

Hey there,

I've been building an MMO for many years on top of XNA and one of the frustrating pieces of writing the game has been the engine. Things like lighting and in-game entity editors take time to write. Nez looks like a great project and is something that I'd very much like to port the project over to. :)

Given that, we have a few non-standard constraints. The largest of which, is that we run the client "headless" for server-side physics. We do this by keeping the "Core" of the client in a separate project and we keep the XNA/Monogame dependent code in it's own code base. We then leverage Dependency Injection to inject the correct "Renderer" for the instance. On the server, it just logs things and skips the steps the client performs.

Looking around at Nez's code, it looks like there are some pretty deep dependencies on GraphicsDeviceManager and various other services that are only needed for clients that are rendered. Things like CoroutineManager are awesome to keep running on the server and would be a great help.

Is there a way that this project could be split up trivially? How much of a refactor would this be to maintain? Is this even worth pursuing? I could copy-paste out the pieces of code from this project that are awesome, but I feel like I would prefer to start a discussion about this before then as there are many negatives to that approach.

Let me know what you think. Happy new year!

Cheers, -Free

prime31 commented 7 years ago

There was basically no thought at all about a headless build of Nez when it was created. You would definitely have to make some changes internally for it to work. The two biggest changes would be:

With that out of the way if you avoid instantiating any Texture2Ds that should cover a bulk of things. There will still be some other stuff for sure that needs to be dealt with that should cover most everything.

If you wanted to go another route and just use the Nez classes in your own base, headless project that would probably work as well. Most of the Nez subsystems (like CoroutineManager, TweenManager, physics, etc) were all written outside of Nez and then ported over to it. There only reliance is on the MonoGame math types so using them in a headless project will most likely not even require any changes at all.

I personally, would probably try this route. It would let you use the Nez source directly (just add links to the files you need in your own headless project) and that should get you going with most of the Nez subsystems.

Vanit commented 6 years ago

I think its safe to close this one :)

redthing1 commented 4 years ago

(this is very late) I hope this will be helpful to anyone seeing this thread;

redthing1 commented 4 years ago

@freeqaz if you're still interested, I've been able to patch Nez so that it doesn't even need to use HeadlessCore or anything, we just use a flag to skip GraphicsDeviceManager setup and an environment variable for SDL2.

GeorgeA93 commented 3 months ago

@redthing1 Long shot as it was 4 years ago now, but do you perhaps have a fork somewhere? I'd love to understand your approach to headless nez.

redthing1 commented 3 months ago

@GeorgeA93 It's your lucky day! Yes, I still have the code. I will try to get back to you about it this week. If I forget feel free to ping me again.

GeorgeA93 commented 3 months ago

@redthing1 ha! you legend. I look forward to hearing from you.

redthing1 commented 3 months ago

@GeorgeA93

Source that you're interested in. xnez_headless_public_20240611.zip

The key here is to call this function I added in Main, before you initialize your core:

Core.UseHeadlessMode()

This is my old fork of Nez that hasn't been updated since 2020. Your best bet is to diff that against a recent source tree of Nez and then port over the changes you want. I did a significant amount of changes to my fork. You could also just look at any code referencing headless and port that over. Unfortunately, I have neither time nor interest to work on this code more, so this is all I can help with. Good luck!

GeorgeA93 commented 3 months ago

@redthing1 thanks so much for sharing! Your implementation is as I anticipated and self explanatory - I can deffinitely take it from here. Appreciate your time 🙏