1
\$\begingroup\$

Working on a new multiplayer game with an API, I'm struggling with code management and separating the client-side and server-side code. For context, I'm writing everything in C# (Monogame or OpenTK). No Unity here.

Project structure:

Server -> Common <- Client

The main problem I have is trying to separate the rendering code from the server logic.

I want to provide anyone the ability to define new types of entities. I would have a base class Entity and a plugin developer would inherit from this class to define a new entity type. When the server loads the plugin, if the latter tries to load textures for instance, it'll crash because there's no graphics context. Perfectly understandable. I simply don't know how to create a class structure that would allow the plugin to define the rendering logic and the server side logic while being completely separated. The Entity subclasses also have different logic on client than on the server (e.g. client-side prediction or position interpolation).

Is there a design pattern or a known pattern that could be used to do this?

I tried using components attached to the instances, which worked to some extent, but the plugin developer still has to check if they are on a server or on a client and add the related components. What if the plugin developer tries to add a client side component? I'm trying to do all of this in a statically typed manner (as much as possible).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.