Jump to content
  • Advertisement
Sign in to follow this  

Getting started with C++

This topic is 2141 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've done a lot of programming in C# with XNA in both 2D and 3D environments. But due to its performance issues I've recently begun looking into moving into the world of C++ with Direct X.

What's the best way to get started with game development in C++? Should I use a wrapper/graphic engine or just let it all hit the fan and try using the Direct X SDK straight up.

Thanks.

Share this post


Link to post
Share on other sites
Advertisement
c++ is not something you move to and gain 9001x performance.

badly written c++ code runs worse than c#
if xna wasnt enough you did it wrong.

in reality gpu is almost always the bottleneck. Edited by saejox

Share this post


Link to post
Share on other sites
Not specifically to do with Direct X, though it does cover it for 2d, but you could checkout this.

http://msdn.microsoft.com/en-us/library/ff381399%28VS.85%29.aspx

Share this post


Link to post
Share on other sites
Understandable, but even if it's a small increase I'd rather learn the superior platform to develop games on.

c++ is not something you move to and gain 9001x performance.

badly written c++ code runs worse than c#
if xna wasnt enough you did it wrong.

in reality gpu is almost always the bottleneck.

Share this post


Link to post
Share on other sites
If you only had C# experience and no C++ experience, I suggest you learn the things which are in C++ and not in C#.
Such like memory management (RAII, etc), C++ idioms (Google it). Wrongly understanding them may lead you crazy. :-)

Share this post


Link to post
Share on other sites
good luck with your adventure then :)

tips:
- Every new call should have a delete counterpart.
- pass parameters by reference when they are larger than 4bytes.
- stack memory is almost always faster than heap, but less flexible.

Share this post


Link to post
Share on other sites

c++ is not something you move to and gain 9001x performance.

badly written c++ code runs worse than c#
if xna wasnt enough you did it wrong.

in reality gpu is almost always the bottleneck.


This,

It is highly unlikely that you've hit a performance wall with C# as properly written C# code running on Microsoft .Net has pretty much the same performance as standard C++ code compiled with Microsofts C++ compiler. The advantages you get with C++ lies primarily with memory management (you can get better cache utilization if you know what you're doing (or far, far, far worse if you don't) and the ability to use non standard extensions for things like SSE.

For C# i'd recommend taking a look at Mono.SIMD if you need a performance boost and try to think about how you allocate memory (you actually have quite a bit of control over this, avoid excessive creation of temporary objects as it tends to both give the garbage collector a hard time and fragment your heap(which greatly reduces cache performance)

Share this post


Link to post
Share on other sites

tips:
- Every new call should have a delete counterpart.
- pass parameters by reference when they are larger than 4bytes.
- stack memory is almost always faster than heap, but less flexible.


True, although if you use exceptions in your software, then you really shouldn't ever be calling delete. You need to be using a smart pointer container such as std::auto_ptr, std::tr1::shared_ptr.

What is quite cool about the newer smart pointers is you can pass a deleter function to it for memory that needs to be freed differently (such as C libraries or abstracting wierd memory systems like in Irrlicht). For example you can pass fclose to a smart pointer containing a file descriptor created by fopen (i.e during it's construction.). This is perfect for opengl stuff such as glFreeTextures or glFreeBuffers

Although in C# (or java) you should really be doing something similar using either Close or Dispose with certain IDisposable derived classes. So frankly I don't see any reall added difficulty here. If anything the smart pointers look a lot neater than loads of try, catch, finallys around the place. Or even using which only works in single functions anyway. Edited by Karsten_

Share this post


Link to post
Share on other sites
Read these articles/guides, should be good for starters:
http://geekswithblog...hort-guide.aspx // general intro, "C# to C++ – A Somewhat Short Guide", incl. some C++11 features
http://www.hackcraft.net/raii/ // RAII intro
http://visualstudiom...et-smart.aspx// smart-pointers intro
http://akrzemi1.word...alue-semantics/ // value-semantics intro

If you need a more general reference, this one is pretty good (also includes C++11 additions):
http://cppannotations.sourceforge.net/cppannotations/html/ Edited by Matt-D

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!