Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


C#,C++ Some insight (Not about performance)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 Morphex   Members   -  Reputation: 298

Like
0Likes
Like

Posted 17 December 2012 - 08:59 AM

Well, let me start by saying this is not asking about which language is better/faster.

I have been programming in the .Net platform for about 6/7 years, so I quite like to think of myself as a "decent" programmer, and no matter what C# is one, if not, my preferred language.


I have been thinking in writing a (another) game this days, the thing is I am feeling divided by what approach to take.
I am not sure if I should go for c++ or c#, I am proficient in both, but I am not sure which one to pick.

My doubts are mostly because I don't want to reinvent the wheel, and I feel that C# lacks a lot of good libraries that are available in C++. I talking mostly about physics and other components that are needed for game. I don't want to roll my own on everything, why should I since there are many great ones available already out there that simplifies the job.

So my question, I think, is more on what language would be "easier" and more future prof to write the game. I am not worried about portability, since c++ would probably win hands down, even with mono laying by C# side.

I was thinking in using OPENGL / DirectX with C#, no XNA since I have grown a dislike on the lacking features of DirectX and how hard it is to implement some of features.

I want to hear your insight on this subject, how viable is C# to make a decent game, or if I should scracth it an go with the market choice of C++. Once more I am not asking how performant they are, and lets be realistic I am not going to make a AAA game, so my question is not really which is the best language, but which one would make development easier/faster.

Check out my new blog: Morphexe 


Sponsor:

#2 J. Evola's Apprentice   Members   -  Reputation: 307

Like
0Likes
Like

Posted 17 December 2012 - 09:31 AM

I think it is entirely project-dependent. When you are evaluating project design issues, you have to make some choices - for example, what 3rd party components you will be reusing. If existing C# libraries satisfy your needs, then you should choose C#, because it's obviously easier to develop with this language. If there are no C# libraries you can reuse, you should choose C++ in that project.

And, personally, I think that if C# is so great, then good libraries will show up sooner or later. But perhaps it is not that great...

#3 Morphex   Members   -  Reputation: 298

Like
0Likes
Like

Posted 17 December 2012 - 09:39 AM

I am not saying C# is better that c++, actually I think they both have their Pro/Con.

But I find myself beliving that C++ is the way to go in this case, I just feel sad leaving my beloved C# behind. One of the aspects I love in C# is the fast prototyping we have and great compile times in huge projects mostly. I guess, in this case, I will just take the dust of my c++ skills and go with the industry standard.

Check out my new blog: Morphexe 


#4 BCullis   Crossbones+   -  Reputation: 1813

Like
1Likes
Like

Posted 17 December 2012 - 09:54 AM

I've found great C# wrappers for many C++ libraries, what in particular do you need? There are native c# physics libraries, and c# wrappers for things like Bullet. SlimDX and SharpDX both wrap DirectX, OpenTK and Tao wrap OpenGL...the list goes on. Aside from mission-cricital performance differences, mitigated by programmer error in many cases, there's no real reason you HAVE to go with C++ unless a specific library you want doesn't have a port or wrapper for it.
Hazard Pay :: FPS/RTS in SharpDX
DeviantArt :: Because right-brain needs love too

#5 Morphex   Members   -  Reputation: 298

Like
0Likes
Like

Posted 17 December 2012 - 10:02 AM

I don't really have specific library in mind, I was just thinking in future I don't want to be mid game development, and then snap I am lacking something.
Also on another subject, OpenTK,ShapDX etc, how close are they to their native counterparts?

Check out my new blog: Morphexe 


#6 Xanather   Members   -  Reputation: 712

Like
1Likes
Like

Posted 17 December 2012 - 10:04 AM

@Morphex

For sharpDX: http://code4k.blogspot.com.au/2011/03/benchmarking-cnet-direct3d-11-apis-vs.html

#7 Magdev   Members   -  Reputation: 197

Like
0Likes
Like

Posted 17 December 2012 - 10:11 AM

Above all, you should do what you're most comfortable with. C# has a nicer environment in my opinion, but you really can't go wrong with C++. If you want to be 100% sure you won't run into issues related to your language choice, I'd roll with C++. With the reinventing the wheel thing, I'd say C# and C++ both have a good amount of libraries so you won't have to. From switching from C# to C++ recently though, I've found that C++ has more overall support, and more libraries support it natively, whereas some C# libraries are just C++ libraries with wrappers.

If I had to recommend one or the other flat out, I'd say C++. Like I said, you really can't go wrong with it. It also feels pretty good not being shackled by the .NET framework. Muh freedoms.

Edited by Magdev, 17 December 2012 - 10:19 AM.


#8 Morphex   Members   -  Reputation: 298

Like
0Likes
Like

Posted 17 December 2012 - 10:24 AM

@Xanather, wow that was suprisingly informative, I never expected that the diference would be so small. I guess I was lacking a bit of research on the subject :\. Thanks for the heads up.

Check out my new blog: Morphexe 


#9 kunos   Crossbones+   -  Reputation: 2207

Like
0Likes
Like

Posted 17 December 2012 - 11:37 AM

I think the sweet spot in writing a game in C# and C++ would be to have your core engine coded in C++ and then exposed to C# (or any other language that can bind to C) via a C interface (good for portability) or CLI/C++ interface. This way you keep all the game code using the elegance and simplicity of C#/F# while using C++ to interface all the 3rd party libs as it was meant to be.
Also, this way, you are not paying the price of constant context switching that you get when using things like OpenTK and SharpDX happening at every single function call, and you can keep this cost under control by grouping more calls into a single "engine" call.

This for the software.. then there is the programmer's brain context switching cost.. I find this remarkably annoying, especially when you are forced to go "down" into C++ code because you need something not available in C# land... I did this for my last project project and I didn't really like it, so for my current project I am back to C++ only approach. Somehow, working with C++ only makes you forget how much it sucks to deal with forward declarations, includes, stupid compiler error description and so on... having part of your code in a decent language like C#/F# is a constant reminder of how much suckage there is in C++.

Edited by kunos, 17 December 2012 - 11:37 AM.

Stefano Casillo
Lead Programmer
TWITTER: @KunosStefano
AssettoCorsa - netKar PRO - Kunos Simulazioni

#10 Starnick   Members   -  Reputation: 1232

Like
0Likes
Like

Posted 17 December 2012 - 12:40 PM

It's very viable to write games with C# (I've enjoyed several indie games that were all XNA based and really didn't do a lot of in the "game engine" department).

And as the other posters have said, perhaps one of my favorite things about C# is how easy it is to pluck useful libraries from the native world. This was one of the main selling points for .NET/C# way back when I was still doing things in Java.

#11 spiralseven   Members   -  Reputation: 132

Like
0Likes
Like

Posted 17 December 2012 - 06:38 PM

Well C# would make it easier developing for windows, I personally prefer C++ because it gives you more control of the processor and whatnot and is more platform independent. C# has XNA which makes developing for the 360 super easy but then again there are other engines with basic C++ support which can also export to the the 360 and other consoles as well.. I suppose its where you want to go platform wise. Ive experimented with C# and managed to get graphical apps up and running in a matter of minutes but you're limited to microsoft platforms.

#12 Nypyren   Crossbones+   -  Reputation: 4510

Like
0Likes
Like

Posted 17 December 2012 - 07:14 PM

...you're limited to microsoft platforms.


No, you're not. I'm working on an iPad and Android game right now and I'm using C#.

#13 xoofx   Members   -  Reputation: 887

Like
2Likes
Like

Posted 17 December 2012 - 07:44 PM

Definitely C# if you care about "easier" and "faster" development cycles and you are only targeting Windows platforms (Desktop, WinRT, WP8). You can develop in C# on other platforms with Mono but it requires a costly license for each platform.

No matter what you can trick with precompiled headers in C++, you won't have the same fast design-and-run round trip you can have while developing in C#. A typical large scale C# projects with thousands of classes compiles in few seconds, even if you change an API that requires to rebuild all assemblies. Faster compilation cycle implies more refactoring/design options and no fear about making large refactoring when they can help your application to be more future proof. Concerning access to existing underlying C++ API from C#, It really depends on your needs, most of .NET wrappers useful for game dev are often up-to-date (Though OpenTK is seriously lacking some updates from latest 4.3 specs, but I wouldn't use OpenTK for a Windows only project).

Also It will depends a lot on your requirements, and there are several questions that are independent of the language of your choice: What are you willing to develop for your game? Only 2D or 3D? Full game engine from a ground up? Only game logic? What about a scene editor? What about mesh loader/converter? Are you proficient with shaders, GLSL/HLSL languages?...etc.

if you are going to build everything using raw level API like DirectX, prepare to have several months of work to build something useful from this API. If you have strictly no experience with DirectX, this could be even more than a few months. It will be a bit worse with raw C++ and DirectX, as you have to handle yourself the raw nature of the API (sometimes only #defines instead of enums, lots of method check for HRESULT, lots of APIs that are more laborious to work with - DirectInput...etc.). For C#, using MonoGame, or probably SharpDX.Toolkit would help a lot. For C++, DirectXTk would be your best option if you want to have a very minimal bootstrap above the raw API. But they are not game engines, just higher level API around DirectX.

But then, you could also consider using a game engine like Unity3d and concentrate on game logic (The scripting is in C#, under the hood, the engine is in C++ using Mono for the scripting) and you could build a prototype game in just a few hours.

#14 3Ddreamer   Crossbones+   -  Reputation: 3159

Like
2Likes
Like

Posted 17 December 2012 - 08:46 PM

Hi,

I am not sure if I should go for c++ or c#, I am proficient in both, but I am not sure which one to pick.


We both know that this is exactly why each language would be fantastic for you. I write the obvious for a reason, as a given, so you could end right there and flip a coin to decide or use both languages, though your .NET experience should influence you.

I have been programming in the .Net platform for about 6/7 years, so I quite like to think of myself as a "decent" programmer, and no matter what C# is one, if not, my preferred language


This alone should weigh heavy in your consideration, of course, because transferring ship in the middle of an ocean is not the wise choice.

My doubts are mostly because I don't want to reinvent the wheel, and I feel that C# lacks a lot of good libraries that are available in C++.


Both C# and C++ have plenty of libraries to take anyone from newbie to AAA popular game developer, so really what you wrote is only true for huge development organizations. You will never be able to take full advantage of those extra C++ highly advanced and specialized libraries until you have a gigantic team working with you and probably far beyond your budget to buy software, tools, and licenses to take advantage of them. If you happen to stay indy, then you will be forced to not worry about the extra C++ highly advanced libraries. For the Indy game developer or small team, either C# or C++ would be wonderful if you are a proficient programmer for making game source code.

The C# advanced libraries are slowing closing the gap with the C++ ones. Since C# is a relatively young programming language coming into maturity with libraries being added every year, the day will likely come when this is not a even the unrealistic concern of some programmers it is today. The .NET Framework which you are familiar in using is also evolving to allow C# to have smooth gameplay even with many assets, the way C++ currently does. I will reveal the bridge between older C# tech like XNA and the future in a few moments.

A fantastic game source code could be made in either C# or C++, likely easier in C# for most programmers, and a game engine of the highly advanced kind with a gigantic team and huge budget would best be served with C++ in most cases, having programmers each focus on a specialty area of the game to take advantage of those libraries - no other way. Does their strategy sound like yours? No - of course it doesn't, unless you have 5 to 20 years of heavy overtime available to focus only on game development. Technology advances likely would make your coding implementations troublesome by the time you finally release a game, so don't worry about the C++ libraries which the big game developers use. The C# libraries will keep you busy and growing for years as indy or small team.


SharpDX is very cross-platform for Windows based systems, one of the most efficient to learn, and has good performance, too. It is an example of one of several major ways to make a game written in C# run well. It is extensible, too. Plug-ins are available for it.

Unity 3D simply rocks! Here is another example of plenty of C# library to take you to AAA game status.

A bunch of C++ written game engines allow you to make a game written in C# or other language(s) which looks great, runs smooth, and is extensible.


Summary

Both C# and C++ are used to create game coding of AAA popular games. The C# is generally considered more streamlined and easier, while the highly advanced features of some C++ libraries let the large organization take full advantage of the latest and greatest game tech.

Some successful game developers are using C# for game scripting and C++ in a game engine to support it. Among them, some are using an existing C++ game engine to - like you - avoid reinventing the wheel. Other languages are being used and combined in special areas for game development, too. In the coming years, more C# AAA game engines will appear as the current crop of young C# programmers and game devs gain experience and accomplishments. Just like C, Java, and C++, technology will accelerate in order to implement in C# as C# environment comes into maturity with hardware and other advances. This means more libraries are coming in C#!

The C# has all the libraries you will need to make an AAA popular game. The C++ highly advanced libraries will be there until you need them and also until C# eventually catches them in advanced specialty areas. The .NET Framework momentum will lead to only greater things being available from it in the coming years.


Recommendations for you:

1) Find a game engine which allows you to use your C#, C++, and .NET experience.
2) Use C# for scripting the game, handle customizations of the game engine written in C# or C++, and implement by your .NET experience where you can.



Clinton

Edited by 3Ddreamer, 17 December 2012 - 08:51 PM.

Personal life and your private thoughts always effect your career. Research is the intellectual backbone of game development and the first order. Version Control is crucial for full management of applications and software.  The better the workflow pipeline, then the greater the potential output for a quality game.  Completing projects is the last but finest order.

 

by Clinton, 3Ddreamer


#15 Morphex   Members   -  Reputation: 298

Like
0Likes
Like

Posted 18 December 2012 - 09:34 AM

3DDreamer great post you got there, truly enlighten me in way that, well I kind subconsciously had already decided in giving C# a try. You and the other folks replies just gave the incentive I was needing I guess.

So I guess I will go with C# for now, if some trouble arises or if change is needed, C# -> C++ is not that difficult to translate and I can improve the code and refactor has needed.

Check out my new blog: Morphexe 





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS