Archived

This topic is now archived and is closed to further replies.

GameDude1

C++ vs C# for DirectX9 programming

Recommended Posts

I''ve noticed that MS is pushing harder and harder on C# for programming, including support in newer DirectX version. Just curious what your thoughts are on C# vs C++ for DirectX9 game programming. Why would / and when would one use C# instead of C++? Advantages / Disadvantages of doing so?? Thanks, *gd*

Share this post


Link to post
Share on other sites
imho i think that there is a time and a place for both. Different jobs require different tools.

For example if you want to prototype a new graphics routine, or game idea then c# would be a logical choice due to speed of development.

However, if you need to get every frame of performance out of your app then perhaps C++ would be a better choice.

It''s all down to what you want to do.

There is also the option of mixing the two languages, for example having "engine" in C++ and the gamecode in C#.

ideas?

Share this post


Link to post
Share on other sites
IMHO

When the install time and space requirements of Visual Studio .NET ( hence C#/C++ ) gets closer to that of Visual Studio 6, I will be sticking with Visual C++ 6 / DirectX 9.

2+ Hours of install time -and-
2+ GB of disk space

Is not worth the effort for me.

- J

Share this post


Link to post
Share on other sites
Of course they push it, it is their own language, sure they want people to use it. Just think back a couple of years when Java came and where it is today. C# will go the same way. Of course I can be wrong but somehow I don't think so. Don't take it as if I don't like c# or something. I am just trying to be realistic. C# looks quite good for general things.


____________________________________________________________
Try RealityRift at www.planetrift.com


[edited by - MichaelT on January 28, 2003 3:21:44 PM]

Share this post


Link to post
Share on other sites
Thanks for the replies! I appreciate everyone taking the time to respond to this. I''m fairly new to game developement, and was curious if anyone else was considering C#. I''ve been impressed with the ease of C# development compared to C++, but did not know if it was practical in game development. I like the idea of use C# to mock up or use combination of the two. Very good ideas...

Thanks guys,



*gd*

Share this post


Link to post
Share on other sites
quote:
Original post by joutlaw
IMHO

When the install time and space requirements of Visual Studio .NET ( hence C#/C++ ) gets closer to that of Visual Studio 6, I will be sticking with Visual C++ 6 / DirectX 9.

2+ Hours of install time -and-
2+ GB of disk space

Is not worth the effort for me.

- J


This is a pretty moronic statement if you realize that the install of VS.NET includes the full updated MSDN - not the "small outdated stuff" that came with VC 6. And this alone accounts for three CD''s (which are not installed totally)

The core VS.NET install runs well below 750 Mb. You can safely turn off most options - I mean, after all your statement prooves you have no need for the tools for building enterprise applications coming with VS.NET

BTW - never looked at the last hard disc sizes? And I also assume you dont want to write standards compliant code.

Well, ignorance :-)




Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

Share this post


Link to post
Share on other sites
quote:
Original post by GameDude1
I''ve noticed that MS is pushing harder and harder on C# for programming, including support in newer DirectX version. Just curious what your thoughts are on C# vs C++ for DirectX9 game programming. Why would / and when would one use C# instead of C++? Advantages / Disadvantages of doing so??



As a hobbyist game developer i realise i wont be writing doom 3 in the near future so i dont mind a relatively small performance hit in the software i write.

As a programmer, i find C# a well designed language, which C++ simply isnt. Only zealots would claim otherwise. As a programmer, i dont like wasting time over the intricasies of C and C++ - e.g. header files - How redundant.

Share this post


Link to post
Share on other sites
sark, thats a pretty good point of view, IMHO. There are pretty little games that require TOP NOTCH performance today in the graphics field and where the difference will make a huge difference.

Time to market is more crucial here :-)


Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

Share this post


Link to post
Share on other sites
That depends on what you mean by top notch games?

But to be more specific and I know I didn''t answer this question myself since my knowledge in c# is far too small. But so far nobody has answered the question about advantages and disadvantages between the two (not just c++).

____________________________________________________________
Try RealityRift at www.planetrift.com

Share this post


Link to post
Share on other sites
quote:
Original post by sark

As a hobbyist game developer i realise i wont be writing doom 3 in the near future so i dont mind a relatively small performance hit in the software i write.

As a programmer, i find C# a well designed language, which C++ simply isnt. Only zealots would claim otherwise. As a programmer, i dont like wasting time over the intricasies of C and C++ - e.g. header files - How redundant.



I tend to differ... I'd like to add a little disclaimer though, as I've NEVER worked with C# in my life, so I might be wrong.
You could also look at it this way: As a hobbyist you won't have the knowledge or sources to optimise every little piece of a game or formula, so the hit you take of you language might be bigger then you first expect.
I agree that as a hobbyist you don't have to look that critical at performance, but it will ALWAYS be an important factor in games. And speed has to come from some place: either your algorithms, or your language.

______________________________
"A computer is meant to be a big calculator, not a storage device"
Struct.m33p.net

[edited by - Structural on January 29, 2003 10:10:09 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Structural
You could also look at it this way: As a hobbyist you won''t have the knowledge or sources to optimise every little piece of a game or formula, so the hit you take of you language might be bigger then you first expect.



Possibly. But it really depends on the algorithm and how i implement it. This is honestly a pretty weak argument to use a "lower level" language as oppose to C#.

With C#, i could write most applications in less time than the C++ equivalent. This gives me more time to optimise, and work on other parts of my game - gameplay for instance. Many gamers will tell you that gameplay is more important than graphics.

quote:

I agree that as a hobbyist you don''t have to look that critical at performance, but it will ALWAYS be an important factor in games. And speed has to come from some place: either your algorithms, or your language.



Is speed really that important? Can you tell the difference between 270FPS and 300FPS by just looking at the screen?

The performance hit for C# has been estimated at about 10% slower for intensive mathematical operations. The CLR will undoubtedly be improved on in the future, and this gap will be made smaller.

Share this post


Link to post
Share on other sites
The only really good reason for hobbyists to use C++ instead of a language like C# or Java is if they hope to work at a big PC game company in the next few years. All the big PC game companies request and use C++ today and they will most likely continue to do so for at least a few more years as C/C++ is currently the only language that is easily portable to consoles.

Now, if you are planning on doing indie development it probably does not matter much which language you use since you will not get anywhere near a license for console development for several years. If you are planning on doing mobile game development, either working for a company or going indie, then Java is the way to go.

Share this post


Link to post
Share on other sites
quote:
Original post by sark
With C#, i could write most applications in less time than the C++ equivalent. This gives me more time to optimise, and work on other parts of my game - gameplay for instance. Many gamers will tell you that gameplay is more important than graphics.



Fair point you made about the faster development. I agree there.
But about the graphics part: I''ve seen more than enough "graphics vs gameplay" threads here to say that graphics isn''t totally redundant in a game. I believe that graphics and gameplay are equally important. But this is a personal opinion, and is no means the centre topic of this thread.

quote:
Original post by sark
Is speed really that important? Can you tell the difference between 270FPS and 300FPS by just looking at the screen?

The performance hit for C# has been estimated at about 10% slower for intensive mathematical operations. The CLR will undoubtedly be improved on in the future, and this gap will be made smaller.


No, you won''t be able to tell the difference between 300 or 270 fps, but we don''t all have a radeon9700pro and an XP2800+. If you application is pushing the boundaries of the hardware, then 10% WILL make a difference. But again, it all depends on how high you are aiming.

I also believe that C# will become faster in the future. I assume MS is working hard enough on it to make it so.
And if it manages to come near the speed of C or C++ then I can very well see quite a few people going for C#.

Another thing, I read somewhere that C# lacks support on the linux/unix side. If one wants to write a cross-platform application or game, C# is not an option. This is also a reason to choose for C++ instead of C#.

Share this post


Link to post
Share on other sites
Just a note:

Many people here seem to have the misconception that better CPU performance can only be used to improve graphics. It is nowadays rather the GPU that is the limiting factor, so the fps isn''t usually affected that much if you increase the load on the CPU.

However, there are a lot of other things I would gladly spend any extra CPU cycles on, such as more accurate physics, advanced AI and so on. Until the avarage CPU clock frequency has reached at least 10 or 20 GHz, I will keep using "low level languages".

Share this post


Link to post
Share on other sites
Bah, just use C# to develop the game. Then do performance testing and see what functions need optimizing and write those in Managed C++. Problem solved.

Currently you can reach at least 80% of your market if you write a windows-only game...is the time spent writing cross-platform code worth it? C++ doesn''t make cross-platform dev free...there''s still a lot of work (read: time and money) involved in creating a final product that works on multiple platforms.

Game development is a business, figure out how much it''s going to cost you for this extra market. How much faster can a game be created in C# than C++? 2 months? 6 months? How much will that extra 2/6/? months cost you (in time-to-market loses, dev cost, etc)? Usually getting a solid game out the door on time will make you more money than a "late" multi-platform game.

This is obviously subject to change, but I wouldn''t expect it anytime soon.

Once we have multiple viable gaming platforms expect games to take longer to make (or cost more).


Epolevne

Share this post


Link to post
Share on other sites
My personal experience is a bit different. I find it difficult as hell to code a good fast Cpp app as it is. Just because you have your graphics routine pumping out a couple hundred frames per second doesnt mean your ready to make a game with it. Pile on AI, pathfinding, poll your input, maybe communicate with your server side component and suddenly speed becomes a factor again.

Make no mistake, i am by no means an uber-Cpp coder and i also abide by a strict OOP hierarchy so perhaps that explains my take on it a bit.

I''d also like to point out that some of the more abstract and difficult tasks you may seek to do might require that you read a book or perhaps an online tutorial. If you dont understand the concept there is nothing like a cut and paste just to get it up and running, and then mess around with it until you really start to get it. As most online resources and advanced books use Cpp as their native language, you are simply creating an additional hurdle of having to port the example code over (which generally requires a base of understanding) just to mess with it.

All that said, if you really do need to get into some serious optimizations, i find it hard to believe that C# can compete in this arena, but no question if time to market is your key determinant C# or even better vb.net would be the way to go.

Share this post


Link to post
Share on other sites
What about using openGL with C#? Is there an easy way to do it? (I wouldn''t think making an openGL wrapper in managed C++ would be easy)

Share this post


Link to post
Share on other sites
quote:
Original post by Extrarius
What about using openGL with C#? Is there an easy way to do it? (I wouldn''t think making an openGL wrapper in managed C++ would be easy)


I think somebody already created an OpenGL C# wrapper. I''m pretty sure a link was posted in one of these forums (Maybe the OpenGL forum).

Share this post


Link to post
Share on other sites
Ok, gotta blast in here with my obnoxious opinion!

From what I''ve seen, at least here at the office with folks working on non-realtime applications, C# has programmer productivity gains (can''t give hard numbers, just word-of-mouth ''I finished this in days and my last C++ version took days to do'' kind of thing. Biggest complaint I''ve heard so far is having to download and install the CLR if they don''t have it already - same issue with Java, though. And you can get the same issue with C++ depending on which libraries you use... pity the poor dialup user..

As to performance, I tend to go with a lot of the prevailing opinion that - unless you''re trying to write Doom 12 or Unreal Tournament 2110 - a 10% performance hit for numerically intensive code isn''t going to be a gamebreaker. This is ESPECIALLY true if you''re writing a less-performance-intensive game like an RPG. Where this may make a difference is in your target audience - if you NEED to run on a Pentium III 500, then that 10% could push you down under an acceptable framerate for your game genre.

As with everything else in the known Universe and beyond, it''s a matter of tradeoffs. You can''t have it all at the same time.. alas.. so you trade productivity for speed or vice versa. As has been pointed out, you can always isolate your numerically-intensive stuff into a C++ DLL and do most of your code in C#, which I guess is akin to using JNI to access a C++ game engine from Java (only I hope to heavens A LOT EASIER, JNI has given me heartburn and ulcers the few times I''ve tried to do anything meaningful with it).

Just my two cents worth!

Share this post


Link to post
Share on other sites
quote:
Original post by Extrarius
What about using openGL with C#? Is there an easy way to do it?


csgl.sourceforge.net
quote:

(I wouldn''t think making an openGL wrapper in managed C++ would be easy)

CSGL is written mostly in C#, actually.



"I know very well who Satan is: He is freedom. He is the uncontrolled, the incalculable, the antithesis of order and discipline, the antithesis of the legalism of outer space.... We know where a planet will be in twelve years, four months and nine days. But we don''t know where a butterfly will have flown one minute hence. Therefore the butterfly is of Satan."
-- Jens Bjørneboe

Share this post


Link to post
Share on other sites
quote:
Original post by Epolevne
Currently you can reach at least 80% of your market if you write a windows-only game...is the time spent writing cross-platform code worth it?
Actually, the PC market isn''t even a drop in the bucket of the total gaming market. We sell more copies of the PS2 version of our games in ONE MONTH than we sell copies of the PC version in six. It is absolutely important that we keep 95% of our code cross-platform. We have strict one year development cycles (Baseball''s opening day doesn''t change...) and we are now shipping on 3 platforms day-and-date. Next year, we will be shipping on 4.

So, yes, it''s worth it.

quote:
This is obviously subject to change, but I wouldn''t expect it anytime soon.

Once we have multiple viable gaming platforms expect games to take longer to make (or cost more).
When you get out of your computer-based thinking, and realize that the real business of game development is concentrated on the consoles, you''ll retract this statement. And the answer to the "longer/cost more" is middleware, either licensed or internally developed. Having a cross-platform API to develop on makes multiple SKUs not only possible, but highly economical.

-scott

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Why not use pointers to optimize areas where performance in importnant using the UNSAFE feature of C# :-)

Share this post


Link to post
Share on other sites
quote:
Actually, the PC market isn''t even a drop in the bucket of the total gaming market.



Having pulled a number out of my ass, I''ll retract my 80% comment. Now with industry-back financial numbers I''ll say 40% of the overall gaming market is on PCs (90 million units to 140 million, though I couldn''t find $/unit for either group). But obviously PCs and consoles have totally different genres they play towards. PC sports games are certainly less than 20% of the market, but PCs dominate in RPGs (MMPORPG and others) and FPS''s (though consoles are growing in this area).

Certainly the sports-games industry is a specialty...is the yearly release neccessary for any other industry? Imagine that the (artificial) yearly timeline is now gone. Now, if a dev house could release a game (a MMPORPG for example) AND a couple addon packs in a year rather than just the game, but they could only be played on Windows is that worth it?

Does doing it in C++ on multiple platforms make the maximum profit? I''m sure you''ll push more units, but you''d have to push a LOT more units to balance out the added cost.

My previous comments were incorrect in scope, knowing "your market" is more specific than the "game industry"...should have been more specific. Obviously your market is different than mine.


Epolevne

500x2

Share this post


Link to post
Share on other sites
Just because one from one company sells more PSX games than PC does not mean that other companies does not sell more PC than console games. Currently, developing in c# is a PC only thing although c# to my knowledge is being converted to other platforms as well. What does this mean for the future? I would think that it means that the general parts of the code probably will be made in c# and the more demanding parts in c++,c or assembler depending on the current needs. As with any artist, producer or what ever, you need to use the tools that best suits your current need. To argue wether or not you should use c# or c++ is quite pointless as you can either pick one or do the smart thing and pick what does the job best. It really doesn''t matter if c# is 10% slower than c++ since a good c# programmer can probably beat a mediocre/half good c++ programmer as far as performance goes. On the other hand a good assembler programmer can beat any other language programmer by a mile but for what cost? It will take forever to write (Actually there is now an OOP package for assembler programmers available on the net so this is not entirely true). And there comes the whole point I believe. After all, the company has to meet a deadline and if writing in c# does that job then c# it is. I know very little of c# since I am a asm/c/c++ programmer and will probably remain that for the better part of the future but that does not mean I reject the idea that c# might actually be more commonplace.

Feel free to comment, object, laugh at or agree to this. I won''t engage in flaming because of what I have said. I could be wrong or right but the ideas are mine.

Good luck to you all.

____________________________________________________________
Try RealityRift at www.planetrift.com

Share this post


Link to post
Share on other sites
Well, let''s put a little different spin on the cross-platform thing, shall we?

Most of the developers I see posting here are indies or trying to break in. They''re not well-funded startups with tons of money to invest, they have a PC and are wondering how to develop PC games.

Getting a console development license is NOT cheap. And, last I checked, you have to go through an approval process as well. How many people on here have the resources and backing to do so? Damn few. And I recall something about each game having to pass through an approval process as well, although I''m not sure every console manufacturer has this requirement.

So, given the nature of the question and the likely situation of the poster, I think we can safely say console development is out of the question. Or am I off-base? I''d be happy to be corrected, if someone can point me in the direction of a place where a lowly indie developer like I can get, say, a PS2 dev kit and a license to produce games for it for under $2K I''d party on the patio! $2K I can pony up out of my own pocket, although I''d have to leave off my computer upgrades for the year...

Until then, cross-platform to console is meaningless for me and I would suspect the majority of the developers here. Not like I want it to be, it''s just a fact as far as I can tell. Like I said, please prove me wrong, I''d love to develop a console game and make my engine cross-platform...

Share this post


Link to post
Share on other sites