[Solved]Advanced C++ Programming

Started by
21 comments, last by DevFred 15 years, 6 months ago
Hello, I know basic C++, up to stuff like pointers. I want to learn how to use things like Singletons, va_lists and other "advanced" C++ function so I am sure I am ready to create my game engine, since while making games I never had to know all of that stuff. Is there some good tutorials on the internet for this? [Edited by - Jedimace on October 14, 2008 12:47:46 PM]
-Jedimace1My company siteEmber StudiosAlmost Done
Advertisement
Quote:Original post by Jedimace
I want to learn how to use things like Singletons

Don't. There are very, very few situations in which a singleton even begins to become a good idea. What will likely happen is you'll learn how to make a singleton and then abuse this knowledge by applying it in unwarrented situations. There are many topics on this discussion that you can find, but I'm sure other people will have some links soon enough.

Quote:va_lists

Don't. I don't believe a C++ program EVER needs to use 'va_list's. Prefer operator chaining instead. Or, as zahlman's signature quotes "when you evoke the dread ellipses construct you leave the happy world of type safety" or something close to that.

Quote:and other "advanced" C++ function

Depends what other features you are considering. Templates? Yes. Polymorphism? Yes. Boost? Heck yes.

Quote:so I am sure I am ready to create my game engine, since while making games I never had to know all of that stuff. Is there some good tutorials on the internet for this?


Look into boost, polymorphism, and templates as well as learning more about the c++ standard library. I don't have any specific tutorials on these topics, sorry, but a google search is usually a step in the right direction.

edit: I don't really mean "don't" as in "don't learn". All knowledge is helpful. No, I mean that be wary when you do decide to learn these things in C++ as there's almost certainly a better solution than the one that uses singletons or va_lists and as such you should probably focus on useful things first.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Quote:Original post by nobodynews
Quote:Original post by Jedimace
I want to learn how to use things like Singletons

Don't. There are very, very few situations in which a singleton even begins to become a good idea. What will likely happen is you'll learn how to make a singleton and then abuse this knowledge by applying it in unwarrented situations. There are many topics on this discussion that you can find, but I'm sure other people will have some links soon enough.

Quote:va_lists

Don't. I don't believe a C++ program EVER needs to use 'va_list's. Prefer operator chaining instead. Or, as zahlman's signature quotes "when you evoke the dread ellipses construct you leave the happy world of type safety" or something close to that.

Quote:and other "advanced" C++ function

Depends what other features you are considering. Templates? Yes. Polymorphism? Yes. Boost? Heck yes.

Quote:so I am sure I am ready to create my game engine, since while making games I never had to know all of that stuff. Is there some good tutorials on the internet for this?


Look into boost, polymorphism, and templates as well as learning more about the c++ standard library. I don't have any specific tutorials on these topics, sorry, but a google search is usually a step in the right direction.

I am sure I need Singletons and VA_lists because I got it from the Enginuity game engine tutorial. I might not need it more then once, but I need to understand the tutorials. Thanks.

-Jedimace1My company siteEmber StudiosAlmost Done
Quote:Original post by Jedimace
I am sure I need Singletons and VA_lists because I got it from the Enginuity game engine tutorial. I might not need it more then once, but I need to understand the tutorials. Thanks.

:)
Go to #gamedev in the IRC chat room (afternet server if you have IRC already, www.gamedev.net/community/chat/ if not) and ask Superpig about what he thinks of Enginuity today. If he's not there ask the other people about it. Basically, conventional thinking suggests that he regrets a lot of his design decisions, that being one of the big ones. I really would give you tutorials on them if I knew of some good ones, but I don't so I'd end up linking to stuff I found on google which you can do yourself. Sorry!

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Ok, that may make my life easier.
-Jedimace1My company siteEmber StudiosAlmost Done
I would like to give my opinion on the singleton pattern as the population of programmers is broken into people who like it and those who do not. Not to discount DevFred or nobodynews.

Singletons are useful in a variety of situations, some of which you'll find commonly in game engines and systems in general.

One such use would be for entity/memory managers(entity representing any game object perhaps). You don't want to have more than one EntityManager managing entities. If your class is a singleton you force the user to only have on instance of the manager at a given time. Perhaps if you have an audio engine, you do not want to create separate instances and initialize multiple objects interacting with your sound files as you may not be sure who has the audio file buffered that you wish to access. It can be very useful in some situations.

Besides that, its always good to put another tool in your toolbox. Simply knowing how a singleton works and how you can effectively use it will benefit you down the road, even if you don't implement it in your engine.

That being said, I would recommend taking a look at:
http://www.gamedev.net/columns/books/bookdetails.asp?productid=18&CategoryID=17

This book will cover a lot of the more commonly used design patterns(and some more uncommonly used), including singletons. If you gain nothing else, you will know why there are different design patterns and how they work which may give you insight into a problem you may face in the future.

Regarding advanced features, build a list of what you would like to know and gamedev will probably have some insight as to how it works or where to find the information you require. You could probably check out the current c++ standard and start picking from there. (Keep in mind a new standard is being worked on and things may change.) In my opinion, you can never learn too much and nothing learned is wasted(within reason).

Cheers.
We have youth, how about a fountain of smart.e4 e5 f4 d5
Quote:Original post by Tang of the Mountain

One such use would be for entity/memory managers(entity representing any game object perhaps). You don't want to have more than one EntityManager managing entities. If your class is a singleton you force the user to only have on instance of the manager at a given time.


I'm sorry but I think your example is flawed, because you could simply pass in a valid EntityManager when you instantiate a new object. This is exactly the "problem" with singletons, everyone has access to this global object. And my question is, why does every system potentially have/need access to this information?

Singletons are good know/understand, but there's very few (if any) cases that really need them. If you are writing code from scratch (and not inheriting an existing code base), you can generally design your code in a way that you do not need them. I'm not trying to start a flame war, just a friendly difference of opinion. :)
What if I want to change the implementation of some aspect of the game, but I want to check that I haven't changed results? It would make sense to have two games running in parallel (each with its own EntityManager) so I can compare the state of both after each frame.

If lack of imagination is the only reason you have to force your users to have a single instance, you should probably not impose this restriction on them.

Quote:Original post by Jedimace
I am sure I need Singletons and VA_lists because I got it from the Enginuity game engine tutorial.


"I am sure I need a spoiler on the back of my car and stickers all over the sides because I saw it in a video game."

Quote:I might not need it more then once, but I need to understand the tutorials. Thanks.


There are a zillion other ways you could go about learning the language, besides working through one specific set of tutorials. Further, the point of a tutorial is to explain all the material it introduces.

This topic is closed to new replies.

Advertisement