• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
3DModelerMan

Favorite little known or underused C++ features

46 posts in this topic

What are your favorite features of C++ or the C++ standard library? Useful features that are sort of obscure, or that you haven't seen being used very much. I think I would go with member function pointers.
0

Share this post


Link to post
Share on other sites
Yeah I first learned about member function pointers when I started using wxWidgets.
operator() is pretty cool too.
2

Share this post


Link to post
Share on other sites
That you can read and write from different elements in a union if the elements are structs and have the same prefix structure:

[CODE]
union {
struct {int x, y; };
struct {int u, v; };
}

x = 45;
cout << u;
[/CODE]

I also like that the library and language is designed in such a way that the compilers can optimize usage of the library really well; gcc can optimize through almost everything in there. Edited by patrrr
2

Share this post


Link to post
Share on other sites
I would have to say valarray.
It's potentially very relevant to games development too, yet I've never heard of its actual use anywhere.
1

Share this post


Link to post
Share on other sites
I personally love quite a bit of the newish C++11 functionality, which is still not used by a lot of C++ developers I know, simply because they do not know of the existence of said features and because not all the features are supported by all the compilers.
Especially std::function, auto built-in smart-pointers are some of my new friends [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]

I think a lot of features are just not known to many developers and the STL contains a huge load of stuff that comes in very handy quite often, but one has to know that it is there in the first place Edited by doeme
1

Share this post


Link to post
Share on other sites
[quote name='frob' timestamp='1350934461' post='4992872']
RNG in the standard library is not sufficient for games.
[/quote]
Just FYI, there is a [url="http://en.wikipedia.org/wiki/C%2B%2B11#Extensible_random_number_facility"]better RNG[/url] in the standard library for C++11 (Also higher-accuracy cross-platform timers).
C++11, while mostly focused on improving the core language (which it did), does add a few things of interest to the standard library that will help game developers moving forward (such as easier multithreading and the TR1-promoted smart pointers).

I'm personally trying to learn the algorithms that have always been in C++, since I've not much experience in them; later I'd love to learn the proper usage of streams.
2

Share this post


Link to post
Share on other sites
[quote name='Servant of the Lord' timestamp='1351006962' post='4993109']
later I'd love to learn the proper usage of streams.
[/quote]

If you mean iostreams... i advise to skip those. They're not asynchronous (if you're using file streams), they're internally complex with many trippings for you to discover (even ignoring threading issues); you're gonna have problems with I18N (you can't use the format string as a resource, as is possible with [possibly positional] printf parameters), it's more cumbersome to read/write formatting specifications and so on...
0

Share this post


Link to post
Share on other sites
[quote name='Evil Steve' timestamp='1351010482' post='4993137']
Personally I like dropping the comma operator into functions just to upset people who have to read my code.
[/quote]
You are Evil Steve [img]http://public.gamedev.net//public/style_emoticons/default/ohmy.png[/img]
2

Share this post


Link to post
Share on other sites
[font=georgia,serif][url="http://www.catb.org/jargon/html/D/Duffs-device.html"]Duff's device[/url]: not exceptionally useful, but clever.[/font]
2

Share this post


Link to post
Share on other sites
[quote name='patrrr' timestamp='1350978725' post='4993018']
That you can read and write from different elements in a union if the elements are structs and have the same prefix structure:

[CODE]
union {
struct {int x, y; };
struct {int u, v; };
}

x = 45;
cout << u;
[/CODE]

I also like that the library and language is designed in such a way that the compilers can optimize usage of the library really well; gcc can optimize through almost everything in there.
[/quote]

structures declared within an anonymous union are not legal C++. Its a visual studio extension.

-changed wording slightly Edited by Washu
0

Share this post


Link to post
Share on other sites
[quote name='Washu' timestamp='1351017811' post='4993161']
anonymous structures within an anonymous union are not legal C++. Its a visual studio extension.
[/quote]

Crap, I've been looking the standard up and down and I didn't find anything that would make this illegal. Though I could've looked harder. Maybe there's a difference between C11 and C++11 in this regard? But I do know that it's not just a visual studio extension; it works well on gcc and clang as well.
0

Share this post


Link to post
Share on other sites
Out of curiosity I'm guessing it was left out of the C++11 standard do to ambiguous naming as functions/variables would live in an unnamed inner scope?
1

Share this post


Link to post
Share on other sites
[quote name='joew' timestamp='1351022979' post='4993183']
Out of curiosity I'm guessing it was left out of the C++11 standard do to ambiguous naming as functions/variables would live in an unnamed inner scope?
[/quote]

In the anonymous case:

[code]
void f() {
union {
struct { int x, y; };
struct { int x, y; };
} u;
}
[/code]

In the not so anonymous case its harder to come up with the same example, but there are similar issues.

I should note that the only places I've actually seen people use anonymous unions/structures was usually almost always a hack that could have been avoided. Edited by Washu
0

Share this post


Link to post
Share on other sites
[quote name='patrrr' timestamp='1351020381' post='4993169']
[quote name='Washu' timestamp='1351017811' post='4993161']
anonymous structures within an anonymous union are not legal C++. Its a visual studio extension.
[/quote]

Crap, I've been looking the standard up and down and I didn't find anything that would make this illegal. Though I could've looked harder. Maybe there's a difference between C11 and C++11 in this regard? But I do know that it's not just a visual studio extension; it works well on gcc and clang as well.
[/quote]
GCC does it just because Visual Studio does it, and people would complain if GCC was too incompatible with Microsoft's compiler.

If you have compiler warnings set to their proper level, GCC would tell you that it's non-standard, iirc (I ran into this a few months back). Though, the [url="http://gcc.gnu.org/onlinedocs/gcc/Unnamed-Fields.html"]documentation[/url] for GCC does imply that C11 permits it.
1

Share this post


Link to post
Share on other sites
[quote name='Washu' timestamp='1351023222' post='4993185']
I should note that the only places I've actually seen people use anonymous unions/structures was usually almost always a hack that could have been avoided.
[/quote]
I used to use it awhile back in a matrix class but killed it off when fixing standards issues in the codebase.

[source lang="cpp"]struct Matrix44
{
union
{
struct
{
float _m[16];
};

struct
{
float m[4][4];
};
};
};[/source] Edited by joew
0

Share this post


Link to post
Share on other sites
[quote name='joew' timestamp='1351026885' post='4993209']
[quote name='Washu' timestamp='1351023222' post='4993185']
I should note that the only places I've actually seen people use anonymous unions/structures was usually almost always a [b]hack that could have been avoided[/b].[/quote]
I used to use it awhile back in a matrix class but killed it off when fixing standards issues in the codebase.[/quote]
If you really need to do something like this, then an array decays to a pointer. You can always store just the 2-dimensional array and cast back to the single dimension as needed.

Though I would submit that you shouldn't be handling the data in two separate fashions here, unless you are providing some sort of abstraction over both.
1

Share this post


Link to post
Share on other sites
[quote name='Kyall' timestamp='1350984785' post='4993041']
variable arguments
...
^ is awesome
[/quote]

No, it's bloody not.
"Basically whenever you invoke the dread ellipses construct you leave the happy world of type safety." — SiCrane
0

Share this post


Link to post
Share on other sites
[quote name='ChaosEngine' timestamp='1351027797' post='4993213']
[quote name='Kyall' timestamp='1350984785' post='4993041']
variable arguments
...
^ is awesome[/quote]

No, it's bloody not.
"Basically whenever you invoke the dread ellipses construct you leave the happy world of type safety." — SiCrane[/quote]

Thus why we now need variable [b]template[/b] arguments, to fix the deficiencies previously solved via variadic arguments :)
2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0