General decoupling advice

So I’m hitting some snags on the principle of decoupling. Not that I CAN’T move forward from this point, but I am looking for advice on how to move forward and not get tripped up later.

I’m working on a game that’s getting a little more complex than a startup project. I understand decoupling and why it is important, but how do we handle cases where systems need to switch rapidly back and forth within the functionality of one action?

Example: I want to bring binoculars up to the player’s face (camera since this is a first-person game), when it gets close enough I want to quickly fade out the camera to black, then I need to enable an overlay which will represent the view of the player looking through the binoculars, then I need fade back in so the player can see everything, oh and probably turn off the camera that shows the binoculars in there somewhere. Then I need to reverse all of that when they put the binoculars back down.

So in this case, it actually seems like nightmare to have everything decoupled since I need to know when all of these processes are complete so that I can move onto the next one. I use the observer pattern for other things, but this actually seems easier to debug when everything is just in one place because of needed to flip back and forth so much.

So uh, what does one do in this case? Do I embrace not decoupling or do I need to just do something different that is not occurring to me? Thanks!

IMNSHO decoupling is overrated. Decouple when the coupling is causing you PAIN, not just in service of making the CIS-100 teacher happy.

Far too many people wreck their projects in search of SOLID and decoupling and event driven and whatever other buzzwords they read on programming blogs.

For what you describe I would make the two camera views (normal and through binoculars) in the same scene, even part of the same player hierarchy, and overlay them precisely at the same point in the hierarchy.

Then your script simply flips between them, setting one active or the other:

void EnableBinoculars( bool binos)
{
  binoCamera.enabled = binos;
  normalCamera.enabled = !binos;
}

Once that’s working, commit it all to source control, then get an ultra-simple fade system (two variables and a function, see below) in there and a piece of black geometry to block what you’re seeing through either camera as you flip.

Don’t make it harder than it has to be. Seriously. You’ll hate yourself and your project if you do. Decoupled stuff is great when you need it, otherwise it ALWAYS is harder to debug because you get to play “follow the breadcrumbs through all the abstraction crud” every time something goes wrong.

Always make your code dead-simple, easy to debug. You will have bugs, you will need to debug.

Fading, simple and easy:

1 Like

That honestly makes me feel a lot better. Most of what you said was my initial ideas of what I should do, but then I started questioning if I was doing something that I shouldn’t be doing. Thanks for the advice!

1 Like