Timeline for How do I correctly use singletons in C++ engine programming?
Current License: CC BY-SA 3.0
23 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 31, 2017 at 15:41 | history | edited | user1430 |
edited tags
|
|
| Feb 24, 2017 at 18:35 | vote | accept | Accumulator | ||
| Dec 13, 2015 at 18:57 | history | edited | Anko | CC BY-SA 3.0 |
Resolved unnecessary negation in title. Code-formatted bits that are code.
|
| Dec 6, 2015 at 3:36 | review | Suggested edits | |||
| Dec 6, 2015 at 3:55 | |||||
| Dec 4, 2015 at 23:33 | comment | added | Eric Towers |
You could give constructors a third argument with default value the global singleton. I.e. foo::foo(coord x, coord y, gameState context = global_singleton) { ... }. Then you get the 90% solution for free and still have the ability to use a different "window, view, etc." context when you need it.
|
|
| Dec 4, 2015 at 21:22 | answer | added | Todd | timeline score: 1 | |
| Dec 4, 2015 at 17:15 | comment | added | Sean | In the book Game Programming Patterns there is a chapter on singletons and how to avoid using them. I found it to be a worthwhile read. | |
| Dec 4, 2015 at 16:21 | comment | added | ratchet freak | "absolute full control over an entire draw function for the entity" is a trap. What you should do instead is extract the commonalities of the draw so that batching can occur. | |
| Dec 4, 2015 at 14:31 | comment | added | JAB | @That was what I meant by explicit initialization. | |
| Dec 4, 2015 at 13:59 | comment | added | snake5 | @JAB Easily fixed with manual initialization from main(). Lazy initialization makes it happen at an unknown moment, which is not a good idea for core systems, ever. | |
| Dec 4, 2015 at 13:27 | comment | added | JAB | @snake5 Be careful with plain globals, C++ provides no guarantees for ordering of initialization between translation units. If your global objects are complex enough that can lead to undesirable interaction, so at the very least if you do use global objects it may be a good idea to use some form of lazy/explicit initialization rather than initialization on construction. Of course, lazily initialization can cause performance issues if the first time you access one object it starts initializing all the others it (in)directly references, so you want to be careful with that, too. | |
| Dec 4, 2015 at 12:03 | answer | added | Peter | timeline score: 3 | |
| Dec 4, 2015 at 9:37 | answer | added | T. C. | timeline score: 3 | |
| Dec 4, 2015 at 9:18 | comment | added | Stack Exchange Broke The Law |
You could pass the window and view to the entity's draw method as parameters.
|
|
| Dec 4, 2015 at 8:24 | history | tweeted | twitter.com/StackGameDev/status/672692955958915072 | ||
| Dec 4, 2015 at 0:36 | answer | added | Willy Goat | timeline score: 6 | |
| Dec 3, 2015 at 23:27 | answer | added | user1430 | timeline score: 30 | |
| Dec 3, 2015 at 22:40 | comment | added | KaareZ | I declare my window and other dependencies in my main, and then I have pointers in my other classes. | |
| Dec 3, 2015 at 22:23 | answer | added | Blue Wizard | timeline score: 3 | |
| Dec 3, 2015 at 22:06 | comment | added | snake5 | Feel free to replace singletons with plain globals. No point in creating globally required resources "on demand", no point in passing them around. For entities, you can use a "level" class though, to hold certain things that are relevant to all of them. | |
| Dec 3, 2015 at 22:06 | comment | added | ExOfDe | Singletons are not bad! they can be useful and sometimes necessary( of course it's debatable ). | |
| Dec 3, 2015 at 22:05 | comment | added | dari | You could pass the window as an argument of the 'render' function. | |
| Dec 3, 2015 at 21:58 | history | asked | Accumulator | CC BY-SA 3.0 |