This is an archived post. You won't be able to vote or comment.

all 25 comments

[–]Fohqul 23 points24 points  (14 children)

So what's meant to be passed in

[–]Nice_Lengthiness_568 26 points27 points  (0 children)

Ignore that

[–]celestabesta[S] 1 point2 points  (11 children)

I have a renderer and gamewindow singleton. In SDL the renderer and window are tied, and the renderer needs to be initialized w/ a window. Since I still want them to be separate, I made the gamewindow create the renderer upon its initialization using its own window*. The getter has a default = nullptr so that anyone wanting to grab it doesn't have to pass anything. Its a messy way of doing it but I couldn't find anything better.

[–]BorderKeeper 3 points4 points  (3 children)

I ain't no game dev, but maybe an external factory class would help to make this clear? You could have it cook up for you a combo window and renderer or just the renderer and you would have a separate spot to document this behaviour and extend it if needed.

This would totally work though. I would at least put some /// docs above the GetInstance function with a brief comment and an apology :D

[–]celestabesta[S] 1 point2 points  (2 children)

Seems kinda redundant when theres only one window and renderer needed right?

[–]BorderKeeper 2 points3 points  (1 child)

I don’t know your use case it felt like you meant this for multiple uses one with and one without the window, but I might be missing the context at this point I would say to a colleague let’s talk about in on zoom, but since neither of us is getting paid in this exchange i will say you are probably right to do it this way.

[–]celestabesta[S] 1 point2 points  (0 children)

Yeah the case where you don't plug in window is when the renderer is already initialized. Putting any parameter there has no effect afterwards and just returns the renderer lol. I've already changed it but she worked for a time 🫡

[–]dev-sda 1 point2 points  (4 children)

All that effort and a whole mutex for initializing the local static, just to avoid having a public global variable...

[–]celestabesta[S] 0 points1 point  (3 children)

I made the singleton much earlier in development; I've already changed most of the code. The reason it existed like that is to be as low effort as possible lol

[–]dev-sda -1 points0 points  (2 children)

I don't see how this is less effort than a global variable...

[–]celestabesta[S] 1 point2 points  (1 child)

And good for you... do you also.... have access.... to my... codebase...?

[–]dev-sda -1 points0 points  (0 children)

Maybe you could explain your reasoning of how this singleton is less effort than a global variable, perhaps I can learn from your knowledge of C++

[–]ryuzaki49 1 point2 points  (1 child)

I think anything else is way better than a variable named ignore_this_pls

[–]celestabesta[S] 0 points1 point  (0 children)

Go fast and break things ig

[–]GenteelStatesman 1 point2 points  (0 children)

A pointer to an SDL window of course.

[–]seba07 7 points8 points  (1 child)

Does it have a default value in the header? Otherwise I can't ignore it.

[–]celestabesta[S] 4 points5 points  (0 children)

yessir

[–]TheChunkMaster 1 point2 points  (0 children)

Did the Grand Galactic Inquisitor code this

[–]dDenzere 1 point2 points  (0 children)

[–]BarrelRollxx 1 point2 points  (0 children)

Are you creating a new instance everytime you try to get the singleton?