Archived

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

C# for Game Programming

This topic is 5142 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''m about to start programming a 3D game but i don''t know which language to choose. i''ve read that C# performs slower than C++, but C# is far easier to code, especially for threading and object oriented work. What would the performance difference be between C++ and C++ for .net? However, the crucial point for the choice is obviously performance. How would you rate the following languages performance-wise when it comes to 3D game prgoramming with DirectX or OpenGL? C# :: C++ .net :: C++ :: Java cheers

Share this post


Link to post
Share on other sites
All are valid choices. C# and Java performance are both nearly on par with C++. Performance isn''t something you should worry about anymore in language choice (at least with the ones you listed). What''s more important is how well you know the language you intend to use, as you will not be able to get optimal performance from any of them if you aren''t intimately familiar with it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:

However, the crucial point for the choice is obviously performance.



Actually, that depends on what type of game you''re out to make. Obviously performance isn''t much of a concern with an RPG, as 30 fps is quite acceptable.

One must also understand that the less time you spend on other things (building a garbage collect, debugging nasty code, setting up D3D), allows for more time to be spent on other things (such as performance).

Share this post


Link to post
Share on other sites
c# isnt nearly on par with c++ but goes at a decent speed to make a 3d game.

and java.....i dont think thats anywhere near the speed of c++
edit:
with c++ you could just make a function based wrapper where you dont really see the nasty amount of code for each thing

[edited by - johnnyBravo on November 11, 2003 1:36:49 AM]

Share this post


Link to post
Share on other sites
quote:
c# isnt nearly on par with c++ but goes at a decent speed to make a 3d game.

and java.....i dont think thats anywhere near the speed of c++
edit:
with c++ you could just make a function based wrapper where you dont really see the nasty amount of code for each thing

dude get ur facts right about your java comments there''s even an article on this site showing benchmarks..

Share this post


Link to post
Share on other sites
If you are already comfortable with unmanaged c++ then I would just use it. Otherwise, C# is a good idea imo. Especially with managed directX, this should greatly speed up developement time.

According to Microsoft, a C# managed DirectX application runs about 10% slower than a c++/unmanaged DirectX one. (Not sure exactly about the % but it was something like that )
So it isn't too much of a big deal, especially since (I assume) you won't be doing a very big/complex game.

I personnally coded with all of those languages, and C++ really strikes me as the best of them. C# is also very nice but I think its more useful for tools. I would totally stay away from C++.net, from my personal experience, theres a lot of new ways of handling things that didnt seem natural or clean. If you want to use .net language definately go with C#. It's design is elegant and clear, very nice language to use.

As for Java, well, I hate it but I never really gave it a real try. For one there is no nice ide to develop Java with as far as I know. If there is, I expect it to be subpar compared to VisualStudio.NET. Also, compiled Java code won't run on pc's that doesn't have the Java Virtual Machine. The same goes for any .NET language, they won't run on pc's that doesn't have the .NET framework, but since .NET is a microsoft technology, you can bet all your .NET apps will run on feature version of windows (and most current ones, some problem with win98).

[edited by - dopeflow on November 11, 2003 2:31:02 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Be sure that, if you decide to go with C#, that you install .NET Framework 1.1 and, if possible, use VS.NET 2003 - 1.1''s bytecode-to-x86 just-in-time compiler is a lot faster than 1.0.

I have used C# for a medium-sized private game project, it''s wonderfully easy to program in but you have to be careful about filling up the heap - garbage collection causes a noticeable pause on my 1.6GHz machine, I had to use the heap profiler to find places in my code that were creating lots of quickly-discarded heap objects.

Share this post


Link to post
Share on other sites
quote:
Original post by johnnyBravo
c# isnt nearly on par with c++ but goes at a decent speed to make a 3d game.

and java.....i dont think thats anywhere near the speed of c++



Wrong and wrong. Both Java and C# apps are run via JIT compilers. This means that (at least for Java - and I assume the .NET JIT works the same way) when the app is running, the bytecode is analyzed and parts of the app get converted to native instructions. As a side effect, more information is available for the JIT compiler to use in making optimizations - simply because it can ''see'' how the code is being used at runtime. This means that, in some circumsatnces, Java performance can actually be *faster* than C++ thereby giving the whole app a performance boost.

I''m starting to sound like a broken record on these forums, but Java is *not* slow anymore. On average, a programmer who knows the language well will be able to see performance around 5% slower than an equivalent C++ program. That''s important - knowing tha language. If you don''t know a language thoroughly, you can''t hope to get the most optimal performance out of it. This applies to C++ just as much as it does to Java and C#.

Anyway, I''m tired of hearing the ''java is slow'' mantra. And now the ''C# is slow'' mantra. People either take what they hear as gospel or spout off about experiences they had 6 years ago when Java *was* slow. Times have changed. Get with it. Check out java.com for a listing of some current Java games. And don''t be surprised when you see a few C# game titles on the shelves in the near future.

Share this post


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

As for Java, well, I hate it but I never really gave it a real try. For one there is no nice ide to develop Java with as far as I know. If there is, I expect it to be subpar compared to VisualStudio.NET. Also, compiled Java code won''t run on pc''s that doesn''t have the Java Virtual Machine. The same goes for any .NET language, they won''t run on pc''s that doesn''t have the .NET framework, but since .NET is a microsoft technology, you can bet all your .NET apps will run on feature version of windows (and most current ones, some problem with win98).


Heh, sorry but I have to respond to this one, too.

First of all, there are countless IDEs available for Java, some of which greatly exceed the capabilities of VS.NET. Eclipse is considered by many to be the best of the best. Started by IBM, it is Open Source, multi-platform, and feature rich. There is a plugin that allows it to be used with C/C++ compilers (still in development). Once you use an IDE like this you will never want to go back to VS.NET. Take a look at it. There''s also JBuilder, NetBeans, SunONE Studio (based off of NetBeans source), just to name a few. Even so, availability of IDEs seems an odd thing to base a choice of language (or even compiler) on .

Next, regarding the JRE, that can certainly be an issue when distributing an app on the net. However, Sun has recently made deals with several OEMs (such as Dell) to have the JRE installed on all new PCs they sell. For boxed titles, it''s a non issue as it''s a simple matter of putting the JRE installation on the CD.

Conceptually asking the user to download and install the latest version of the JRE is no different than it is asking them to download and install the latest DX runtime. It''s probably not the case realistically, though. In the near future, it will no longer be an issue. There''s a lot going on that will improve the situation.

When someone wants to choose a language to develop games with, the big picture needs to be considered. What platforms are targetted? Where does the dev''s experience lie? In which language is the dev more productive? What sort of third party tools will be used? What is the purpose of the project? What is the method of distribution? For most hobbyists, it will come down to preference. For anyone looking to make money, there are too many factors to list - performance of the language (when talking about C/C++/C#/Java), however, is not one of them.

Share this post


Link to post
Share on other sites
quote:
I''m starting to sound like a broken record on these forums, but Java is *not* slow anymore.

Well, that completely goes against my experience and that of everyone I know, unless we''re talking about small programs. For anything above that, I''ve always found Java to be dog-slow, regardless of the JIT, platform, memory configuration, or CPU. My own benchmarks repeatedly confirm this, and every set of benchmarks (and I keep checking new ones as they appear) I''ve ever read echo my findings. To me, that''s almost no surprise, considering that Java was originally designed for embedded use with small applications. In fact, I repeatedly find Java to be slower than even old Visual Basic apps, and that''s sad...and irritating, since there seem to be so many people who seem think that Java is just the best thing ever. This is especially problematic at educational institutions where instructors tend to indoctrinate rather than educate.

I agree with staying away from Managed C++. Even if you consider access to the .NET Framework to be an advantage, the syntax is irritating (this will change with the next version of Visual Studio), and the performance won''t be significantly different than a C# version.

I believe that C# is potentially a good choice for making games, but the biggest issue against it is lack of good libraries. For instance, even though there are plenty of OpenGL wrappers for .NET, I don''t consider any of them to be truly good because, among other things, they all require your app to allow unsafe code. They also aren''t very .NET-like, either. Managed DirectX is, in my opinion, still more difficult to use than it should be—and I believe this has always been a problem with DirectX across the board. As far as I''m concerned, as the library situation improves, so will C#''s viability for games...

...but, of course, if you want the best performance, C++ is still the best choice. With effective use of the C++ Standard Library and—for example—those that are part of boost, you can replicate or approximate almost everything you''d gain by using C# or Java.

Share this post


Link to post
Share on other sites
Whats so bad with Java? Java is vey simular to C#. I personally use C# because I like its syntax and ease of use. Java is used to program phone games! Java ent that diffrent from C# whats so bad about Java? Why not state your hates about Java? It''s slow is that it?

Rob

Share this post


Link to post
Share on other sites
Actually, it really depends on the game you want to make: games where graphics isn't so important C# would be a good choice, but if comes to graphics and speed, C++ is the only choice, I think. Or why does Carmack use C++ and not C#?

[edited by - Pityworm2 on November 11, 2003 8:46:29 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by merlin9x9
quote:
I''m starting to sound like a broken record on these forums, but Java is *not* slow anymore.

Well, that completely goes against my experience and that of everyone I know, unless we''re talking about small programs. For anything above that, I''ve always found Java to be dog-slow, regardless of the JIT, platform, memory configuration, or CPU. My own benchmarks repeatedly confirm this, and every set of benchmarks (and I keep checking new ones as they appear) I''ve ever read echo my findings. To me, that''s almost no surprise, considering that Java was originally designed for embedded use with small applications. In fact, I repeatedly find Java to be slower than even old Visual Basic apps, and that''s sad...and irritating, since there seem to be so many people who seem think that Java is just the best thing ever. This is especially problematic at educational institutions where instructors tend to indoctrinate rather than educate.

I agree with staying away from Managed C++. Even if you consider access to the .NET Framework to be an advantage, the syntax is irritating (this will change with the next version of Visual Studio), and the performance won''t be significantly different than a C# version.

I believe that C# is potentially a good choice for making games, but the biggest issue against it is lack of good libraries. For instance, even though there are plenty of OpenGL wrappers for .NET, I don''t consider any of them to be truly good because, among other things, they all require your app to allow unsafe code. They also aren''t very .NET-like, either. Managed DirectX is, in my opinion, still more difficult to use than it should be—and I believe this has always been a problem with DirectX across the board. As far as I''m concerned, as the library situation improves, so will C#''s viability for games...

...but, of course, if you want the best performance, C++ is still the best choice. With effective use of the C++ Standard Library and—for example—those that are part of boost , you can replicate or approximate almost everything you''d gain by using C# or Java.



I totally agree with you on this. Everytime i think Java is slow, i come across many people and articles claiming that it is not that bad and is only about 20-50% slower. Well from my experience, that is nowhere the case. I know ill get flamed for it but ill just say it, Java Sux when it comes to performance based apps. Many respected programmers on these boards continue to use C++ even though they admit that it is too easy to mess up in it. The reason why they have not switched to Java is purely because of performance. Anyway i will not argue over this since there is a large following of people on both sides over whether Java is suitable for Performance apps and you should use whatever you feel more comfortable with. Only when 2 languages seem equal to you in terms of you being comfortable with it should you consider performance.

I won''t be surprised if future Windows only games get written in C#. C# in is alot faster than Java and the only reason why it is not being used in games is because it is still pretty new and it will take time for gfx APIs to support it.

As for the ops question i will rate the languages in this way.

C++ :: C++.net :: C# :: Java

I used to think that .NET would be MS''s version of Java. But i was wrong. I think the .NET framework is alot easier to use than Java''s AWT/Swing(I have used both b4). And .NET languages seemed to be alot faster than Java applications back when i was working with VB.NET and JDK1.3. Yet i could not explain this since both were said to use JIT compilation. Initially i thought this was because Microsoft got it right in it''s first try while Sun was still struggling despite having a 6 year headstart. However i finally understood why this was the case when i came across an article explaining why Java was so much slower than .NET. Java is still an interpreted language even though it uses JIT. Read the quote below for more info

quote:

.NET programs are not compiled directly into executable code but are compiled into an intermediary language known as Microsoft Intermediary Language (MSIL or IL). This language is compiled and executed later. You may have heard of JIT compiling or "the JITer" from Java, but the similarity between .NET and Java in merely in the name.

How is it Different From Java''s JVM?
An important distinction between how .NET executes code and Java''s use of a JITer is worth mentioning. On the java platform, a just-in-time compiler is used to transform the Java program into platform-independent code known as byte code. In great contrast to .NET, byte code is not an intermediary language that is compiled to native, hardware-optimized code, but is instead, interpreted at execution time by the Java virtual machine. This process of interpreting code as it executes is much slower than the compile-and-cache method used by the .NET JITer.



Share this post


Link to post
Share on other sites
Java isnt slow per-se, but most people will agree that the available IDE''s or applications feel somewhat sluggish. This, however is not really the fault of the language, but more the fault of Swing. You can also get machine specific compilers for Java, which speed things up considerably...

In regards to gaming, Java is definitely an option as if you KNOW what your doing and have good knowledge of the language then you can definitely write code that is of comparable speed to other languages such as C#/C++ etc...

However when people harp on about "omg this language is faster than that language omg omg omg" you just have to remember that what you gain in ease of use/programming/maintainability you have to pay for in performance, sometimes. The more high level a language is the more overheads you are going to incur.

If you were insane you could write a whole engine in ASM, but maintaining that would probably be a logistical nightmare. Writing a game engine in C++ is definitely a good idea, but with all those pointers and memory management headaches a managed language would be beneficial!

In game development speed is definitely an issue, but remember. Code first, optimise later. Which is why i now do all my game development in C#... not C++ (as before).

^^ god my spelling/grammer sucks.

Share this post


Link to post
Share on other sites
Well I have found a 3D Coomand and Conquer game done in Java. It can be found at the Java web site! It cannot be that slow if it is been used to code a commercial game. C++ will ALWAYS be faster and hold more power but I have to say C++ and ASM are the most difficult and unfriendly languages I have ever seen. Some people may want to code in languages like Java and C# because its easier.

C# and Java are not designed for 3D Medal of Honour type games if you want to code a game like that you would have to use C++. But for simple games C# and Java are fine. I mean most people in here could use C#r Java because they are not making huge games!

The C&C game done in Java can be found at: http://java.sun.com/ just browse around there and u will see it! To me C# is my favourite language and I code games in it :D

Share this post


Link to post
Share on other sites
quote:
Original post by merlin9x9
quote:
I''m starting to sound like a broken record on these forums, but Java is *not* slow anymore.

Well, that completely goes against my experience and that of everyone I know, unless we''re talking about small programs. For anything above that, I''ve always found Java to be dog-slow, regardless of the JIT, platform, memory configuration, or CPU. My own benchmarks repeatedly confirm this, and every set of benchmarks (and I keep checking new ones as they appear) I''ve ever read echo my findings. To me, that''s almost no surprise, considering that Java was originally designed for embedded use with small applications. In fact, I repeatedly find Java to be slower than even old Visual Basic apps, and that''s sad...and irritating, since there seem to be so many people who seem think that Java is just the best thing ever. This is especially problematic at educational institutions where instructors tend to indoctrinate rather than educate.



I hope you''re not including me in the category of those who think Java is just the best thing ever, because I will be the first to tell you it''s not. There are several issues with the language itself and, more importantly, with online distribution.

My goal is not to convert the infidels, but to squash this frustrating and outdated Java performance myth. I challenge you, and everyone else who doesn''t believe Java is performant, to take a look at this page. Some of those games even amazed me (RoboForge in particular). Check out Attack Copter from that page - it''s an online game from EA that you can play for free. EA put out a job announcement recently at javagaming.org looking for Java developers to code several online games they have planned. Obviously it''s performant enough for them

quote:
Original post by Pityworm2
Actually, it really depends on the game you want to make: games where graphics isn''t so important C# would be a good choice, but if comes to graphics and speed, C++ is the only choice, I think. Or why does Carmack use C++ and not C#?



Actually, Carmack has used C for all of his work (not C++) including, I believe, the Doom3 renderer. I know the game uses C++ but I read the renderer is coded in C. This is, I''m sure, mostly because he knows how to squeeze every last drop of performance out of C through extensice experience with it. At the end of the day, that''s one of the most important factors in choosing a language I think.

I wouldn''t expect a C++ veteran to code up a knock-your-socks-off game the first time he coded in Java. It takes experience to learn compiler, language, and platform features/quirks/intricacies that affect performance. When you have the opportunity to choose the language for a project yourself (as opposed to being told which to use) your first choice should not be a language you aren''t experienced with.

As an example, my experience lies mostly with C and Java. I''m a neophyte with C++. Were I to set out and develop a title for Windows/Linux/Max, and would distribute the game on CD, I would not hesitate to use Java. It''s a simple choice for me because I know the language well, I''m productive with it, and I prefer it to C. If I needed to throw consoles into the mix, Java''s out. If I were going for online distribution only, Java''s out because I''m not comfortable with the current problems in JRE market penetration. I would prefer to use Java when I can and C when I can''t. But nowhere, nowhere at all, does the performance of Java apps come into play.

I''ll continue to dispute and rant when people say Java is too slow for games But I''ll never try to convince someone they should use it instead of C++. Get out there and play some Java and C# games. The sooner all of you naysayers do the sooner these types of discussions will end

Share this post


Link to post
Share on other sites
I am not saying Java is the best thing ever. I like c# better then anything but I am saying to people that you cannot talk about Java if you know nothing about it. Before you go saying Java is so bad why not learn somethin about Java then tell us what ya think. You can''t just say Java is rubbish and not back your argument up. Java is a simple language. It ent the best I think C# is the best and I could give reasons for that but it will make this message to long


Anyways I think we have answered this question!

Share this post


Link to post
Share on other sites
Cool didnt know there was that many IDE for java. Like I said I only had limited experience with it, and I developped using either command line javac, or Forte. Both of those sucked beyond all recognition. Forte has tho be the slowest application I ever experienced. Like I said, my opinion is biased :D

Share this post


Link to post
Share on other sites
quote:
Original post by johnnyBravo
ha so javas actually decent now. Thats good, i dont mind java, apart from the long calls eg JOptionPane blah blah whatever i can never remember all its functions


Profesional programers often have oppened one window with documentation and other for IDE. There is no reason to remmember exact names of not commonly used methods if you could look at them in documentation in few seconds. ^-^ (Nearly perfect documentation is one of Java advantages.)



BTW best episode was when Johny was temporaly smart and monkey repaired reactor.

Share this post


Link to post
Share on other sites
quote:
Original post by dopeflow
Cool didnt know there was that many IDE for java. Like I said I only had limited experience with it, and I developped using either command line javac, or Forte. Both of those sucked beyond all recognition. Forte has tho be the slowest application I ever experienced. Like I said, my opinion is biased :D


Don''t forget VIM, XEmac, JCreator LE, JEdit, someone mentioned that IDE from IBM E..., and lots of others. Becose you could create reasonable IDE in Java in two months singlehandely, some programmers could use IDE tailored exactly to theirs needs.

If forte was slow, you never experienced IE, or wrongly instaled Visual studio. ^~^

Sometimes it''s about how that aplication looks, not what it really do. First create window and fast, then start to do actual work did''t seem to be ability of early versions of Forte.

Share this post


Link to post
Share on other sites