Spaghetti code hell and GameServices, need some suggestions.

Starting to have some doubts and troubles after the discovery of GameServices. I’ll try to explain my setup, I have 3 major classes that are used by everything in the game basicly, FileSystem, CVarSystem and CommandSystem, before putting them into the services I had them as static classes. I didn’t like for some reason that htey were static and accessible like that fro meverywhere even if they come in handy in that form, but some problem with services arised as FileSystem for example need CVarSystem in some parts, so it would be a spam of GetService calls here and there.

I don’t have any of the services running in a Update loop, if I need that I just make a member variable but then it defeat the purpose of having a quick access to it.

So I’m a bit unsure if I should keep this way of doing things with services or go back to statics or maybe there is a better ordered way.

I have my main Game classs already a singleton so in theory could put the stuff there and access from the instance but I’m not sure.

Any suggestion? Thanks.

Hey :slight_smile:

An alternative I’d suggest just passing those dependencies straight to the things that need them. If your FileSystem object needs to use CVarSystem, just give it a reference to that object when you create FileSystem. That way it’ll have everything it needs to do its work.

1 Like


1 Like

Thanks for the tips, so after reading the two links there I got a bit more good idea on how to proceed.

For what is suggested there services might be better off beign for specific scopes, like physics entities needing physics info and just thsoe classes have access to that service, while something that has to be accessed by pretty much everything like FIleSystem or Logs should be threated as global.

Still would be better to have these globals as static (with their own initialization to be safe) or jmaybe could be integrated into a singleton hub class?

For example my idea for rendering was to ahve a main Renderer class that is part of the main Singleton which is actualyl the only singleton in the whole game, so could be accessed soemthing like Main.Renderer from anywhere and have rendering components subscribe to it, then from Main do the loop for drawing. But this would make the Renderer accessible by anything it needs it so not sure if the Renderer shoudl be a service too in this case.