473,835 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

From C++ to C# and back again....

I taught myself C++ a while back, but never got to
involved in actually writing applications with it. I
actually spent the last 6 years working for numerous
internet web firms as well as doing a plethora of
freelance web development work. Lately I started learning
c#. The idea is to stop using coldfusion and switch to
writing c# using asp.net. The advantage I believe is that
I can develop websites and software that reuse code and
are tied together in a Solution. This idea is very
exciting to me.

One of my other passions and interests is game
development. I've looked around at a lot of different
websites and have read over and over again that although
game development with c# is possible; it's just not
pratical, due to peformance issues brought on by
using .net, etc.

It is my understanding, however, that as a .net
application runs the called functions are compiled to
native code through the JIT compiler. Only functions that
are called are compiled, but once compiled, are not
recompiled through the life of the program. In addition to
this, the compiled code is more effecient since it is
compiled specifically for the system and processor it is
running on. And typically speaking, as a .net program
runs; it gets faster and faster (obviously hitting a
plateau when all code is compiled).

If this is the case, wouldn't a game programmed
using .net, have better performance? Isn't it possible to
still use pieces of assembly code or otherwise unsafe code
for specific functions where performance is key?

I was looking at the Mangaged C++ port of the Quake II
engine the other day and was reading that "Running Quake
II.NET in the timedemo test indicates the managed version
performs about 85% as fast as the native version."
(http://www.vertigosoftware.com/Quake2.htm). The didn't do
much explaination as to why the managed version was
slower.

C# itself doesn't seem like it was meant for game
programming. Am I right? What advantages does the C++
language have over C# that makes it better for game
programming (as far as syntax goes, not performance)?

Thank you.
Nov 16 '05 #1
10 1225
Aaron,
You can use C# to develop games. It may be slightly slower than C++ (if
designed and implemented properly) be you will be much more productive.

Games developers are slow to move to C#. They already employ die hard C++
coders and there is a lot of snobbery regarding C#. Also C/C++ is used for
developing games for the consoles.

To start, try the following links.

Download the DirectX SDK
http://msdn.microsoft.com/library/de...st/directx.asp

Managed DirectX discussio
http://msdn.microsoft.com/newsgroups...&lang=en&cr=US

Managed DirectX eposide of the .NET Show
http://msdn.microsoft.com/theshow/Ep...37/default.asp

DirectX on MSD
http://msdn.microsoft.com/library/de...ch_directx.asp

Books on Managed Direct
http://www.amazon.com/exec/obidos/AS...9919604-591356
http://www.amazon.com/exec/obidos/AS...919604-5913560

Good luck.
Phil.

"Aaron" wrote:
I taught myself C++ a while back, but never got to
involved in actually writing applications with it. I
actually spent the last 6 years working for numerous
internet web firms as well as doing a plethora of
freelance web development work. Lately I started learning
c#. The idea is to stop using coldfusion and switch to
writing c# using asp.net. The advantage I believe is that
I can develop websites and software that reuse code and
are tied together in a Solution. This idea is very
exciting to me.

One of my other passions and interests is game
development. I've looked around at a lot of different
websites and have read over and over again that although
game development with c# is possible; it's just not
pratical, due to peformance issues brought on by
using .net, etc.

It is my understanding, however, that as a .net
application runs the called functions are compiled to
native code through the JIT compiler. Only functions that
are called are compiled, but once compiled, are not
recompiled through the life of the program. In addition to
this, the compiled code is more effecient since it is
compiled specifically for the system and processor it is
running on. And typically speaking, as a .net program
runs; it gets faster and faster (obviously hitting a
plateau when all code is compiled).

If this is the case, wouldn't a game programmed
using .net, have better performance? Isn't it possible to
still use pieces of assembly code or otherwise unsafe code
for specific functions where performance is key?

I was looking at the Mangaged C++ port of the Quake II
engine the other day and was reading that "Running Quake
II.NET in the timedemo test indicates the managed version
performs about 85% as fast as the native version."
(http://www.vertigosoftware.com/Quake2.htm). The didn't do
much explaination as to why the managed version was
slower.

C# itself doesn't seem like it was meant for game
programming. Am I right? What advantages does the C++
language have over C# that makes it better for game
programming (as far as syntax goes, not performance)?

Thank you.

Nov 16 '05 #2
Very nice response. Thank you. I was most interested in
the suggested books (I'm very good with self-teaching
using books), and it would seem (after reading many
comments) that most of the DX9 books have issues with
compiling code because of the latest updates of DX9 from
Microsoft.

What about OpenGL programming with C#? Is OpenGL still a
qualified competitor of DirectX? HL2 uses DX9 right? And
D3 uses OpenGL right?

-----Original Message-----
Aaron,
You can use C# to develop games. It may be slightly slower than C++ (ifdesigned and implemented properly) be you will be much more productive.
Games developers are slow to move to C#. They already employ die hard C++coders and there is a lot of snobbery regarding C#. Also C/C++ is used fordeveloping games for the consoles.

To start, try the following links.

Download the DirectX SDK
http://msdn.microsoft.com/library/default.asp? url=/downloads/list/directx.asp
Managed DirectX discussion
http://msdn.microsoft.com/newsgroups/default.aspx? dg=microsoft.pu blic.win32.prog rammer.directx. managed&lang=e
n&cr=US
Managed DirectX eposide of the .NET Show
http://msdn.microsoft.com/theshow/Ep...37/default.asp

DirectX on MSDN
http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dnanchor/html/anch_directx.as p
Books on Managed Direct X
http://www.amazon.com/exec/obidos/AS...25969/qid=1108 480784/sr=2-1/ref=pd_ka_b_2_1/104-9919604-5913560http://www.amazon.com/exec/obidos/AS...26612/qid=1108 480784/sr=2-2/ref=pd_ka_b_2_2/104-9919604-5913560
Good luck.
Phil.

"Aaron" wrote:
I taught myself C++ a while back, but never got to
involved in actually writing applications with it. I
actually spent the last 6 years working for numerous
internet web firms as well as doing a plethora of
freelance web development work. Lately I started learning c#. The idea is to stop using coldfusion and switch to
writing c# using asp.net. The advantage I believe is that I can develop websites and software that reuse code and
are tied together in a Solution. This idea is very
exciting to me.

One of my other passions and interests is game
development. I've looked around at a lot of different
websites and have read over and over again that although game development with c# is possible; it's just not
pratical, due to peformance issues brought on by
using .net, etc.

It is my understanding, however, that as a .net
application runs the called functions are compiled to
native code through the JIT compiler. Only functions that are called are compiled, but once compiled, are not
recompiled through the life of the program. In addition to this, the compiled code is more effecient since it is
compiled specifically for the system and processor it is running on. And typically speaking, as a .net program
runs; it gets faster and faster (obviously hitting a
plateau when all code is compiled).

If this is the case, wouldn't a game programmed
using .net, have better performance? Isn't it possible to still use pieces of assembly code or otherwise unsafe code for specific functions where performance is key?

I was looking at the Mangaged C++ port of the Quake II
engine the other day and was reading that "Running Quake II.NET in the timedemo test indicates the managed version performs about 85% as fast as the native version."
(http://www.vertigosoftware.com/Quake2.htm). The didn't do much explaination as to why the managed version was
slower.

C# itself doesn't seem like it was meant for game
programming. Am I right? What advantages does the C++
language have over C# that makes it better for game
programming (as far as syntax goes, not performance)?

Thank you.

.

Nov 16 '05 #3
What about my question concerning assembly and unsafe code; I haven't
gotten to unsafe code in my c# book yet, can assembly code be used in a
c# application where peformance is imperative?

Nov 16 '05 #4
Aaron,
Personally, I've never looked at OpenGL. Suggest you try the following links.

http://www.opengl.org/
http://www.taoframework.com/
http://www.codeproject.com/csharp/csopengl.asp
http://sourceforge.net/project/showf...group_id=33241

Regards,
Phil.

"Aaron" wrote:
Very nice response. Thank you. I was most interested in
the suggested books (I'm very good with self-teaching
using books), and it would seem (after reading many
comments) that most of the DX9 books have issues with
compiling code because of the latest updates of DX9 from
Microsoft.

What about OpenGL programming with C#? Is OpenGL still a
qualified competitor of DirectX? HL2 uses DX9 right? And
D3 uses OpenGL right?

-----Original Message-----
Aaron,
You can use C# to develop games. It may be slightly

slower than C++ (if
designed and implemented properly) be you will be much

more productive.

Games developers are slow to move to C#. They already

employ die hard C++
coders and there is a lot of snobbery regarding C#. Also

C/C++ is used for
developing games for the consoles.

To start, try the following links.

Download the DirectX SDK
http://msdn.microsoft.com/library/default.asp?

url=/downloads/list/directx.asp

Managed DirectX discussion
http://msdn.microsoft.com/newsgroups/default.aspx?

dg=microsoft.pu blic.win32.prog rammer.directx. managed&lang=e
n&cr=US

Managed DirectX eposide of the .NET Show
http://msdn.microsoft.com/theshow/Ep...37/default.asp

DirectX on MSDN
http://msdn.microsoft.com/library/default.asp?

url=/library/en-us/dnanchor/html/anch_directx.as p

Books on Managed Direct X
http://www.amazon.com/exec/obidos/AS...25969/qid=1108

480784/sr=2-1/ref=pd_ka_b_2_1/104-9919604-5913560
http://www.amazon.com/exec/obidos/AS...26612/qid=1108

480784/sr=2-2/ref=pd_ka_b_2_2/104-9919604-5913560

Good luck.
Phil.

"Aaron" wrote:
I taught myself C++ a while back, but never got to
involved in actually writing applications with it. I
actually spent the last 6 years working for numerous
internet web firms as well as doing a plethora of
freelance web development work. Lately I started learning c#. The idea is to stop using coldfusion and switch to
writing c# using asp.net. The advantage I believe is that I can develop websites and software that reuse code and
are tied together in a Solution. This idea is very
exciting to me.

One of my other passions and interests is game
development. I've looked around at a lot of different
websites and have read over and over again that although game development with c# is possible; it's just not
pratical, due to peformance issues brought on by
using .net, etc.

It is my understanding, however, that as a .net
application runs the called functions are compiled to
native code through the JIT compiler. Only functions that are called are compiled, but once compiled, are not
recompiled through the life of the program. In addition to this, the compiled code is more effecient since it is
compiled specifically for the system and processor it is running on. And typically speaking, as a .net program
runs; it gets faster and faster (obviously hitting a
plateau when all code is compiled).

If this is the case, wouldn't a game programmed
using .net, have better performance? Isn't it possible to still use pieces of assembly code or otherwise unsafe code for specific functions where performance is key?

I was looking at the Mangaged C++ port of the Quake II
engine the other day and was reading that "Running Quake II.NET in the timedemo test indicates the managed version performs about 85% as fast as the native version."
(http://www.vertigosoftware.com/Quake2.htm). The didn't do much explaination as to why the managed version was
slower.

C# itself doesn't seem like it was meant for game
programming. Am I right? What advantages does the C++
language have over C# that makes it better for game
programming (as far as syntax goes, not performance)?

Thank you.

.

Nov 16 '05 #5
No it can't.

From MSDN: "In unsafe code it is possible to declare and operate on
pointers, to perform conversions between pointers and integral types, to
take the address of variables, and so forth"

That's pretty much it I'm afraid. However you could easily write the parts
of your program that required assembler in managed C++, and call that
assembly from your C# code...

"paradox" <de*@demiurgein c.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
What about my question concerning assembly and unsafe code; I haven't
gotten to unsafe code in my c# book yet, can assembly code be used in a
c# application where peformance is imperative?

Nov 16 '05 #6
With the benefits of C# in mind, would it make sense to develop a game
mostly in C# and use managed and unmanaged c++ where necessary for
peformance? Would doing so effectively "cure" the performance issues
associated with using .NET for game programming?

To clarify my question. The purpose of using c# in such a case would be
for the ease of use provided by the syntax of the language and using
unmanaged code would be to avoid the cost of garbage collection and
have direct control over memory management. Are there enough advantages
in the syntax of the c# language to decide to write a game that uses it
in conjunction with c++ or would it just make more sense to soley use
c++?

As an alternative approach, would it be possible to develop the engine
in c++ and write the game code in c#? Thank you.

Nov 16 '05 #7
Hi...

I think the former would work the best. In my experience (15 yrs)
developing software, one tenet has worked well for me... "make it work -
then make it work fast."

It is very difficult if near impossible to determine where your code is
spending its time -- so the only way to know where to optimize it to write
the code (in C#), profile it, then re-write the most-used routines in C/C++
or assembly to get the speed that you need.

You may find, however, that the managed code works just fine and that you do
not need to use unmanaged code at all.

John Puopolo

PS. I'd be interested in how this turns out -- post and let us know!

"paradox" <de*@demiurgein c.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
With the benefits of C# in mind, would it make sense to develop a game
mostly in C# and use managed and unmanaged c++ where necessary for
peformance? Would doing so effectively "cure" the performance issues
associated with using .NET for game programming?

To clarify my question. The purpose of using c# in such a case would be
for the ease of use provided by the syntax of the language and using
unmanaged code would be to avoid the cost of garbage collection and
have direct control over memory management. Are there enough advantages
in the syntax of the c# language to decide to write a game that uses it
in conjunction with c++ or would it just make more sense to soley use
c++?

As an alternative approach, would it be possible to develop the engine
in c++ and write the game code in c#? Thank you.

Nov 16 '05 #8
thb
Yes it can.

You can't add assembly code inside a C# project, since there is no
machine code in a .NET executable. However, you can create an external
DLL in asm, and call its functions from your managed C#.

This solution is very efficient if you don't switch too often from
managed C# to platform assembly. It ruins the supposed portability
advantages of C#, though.

Nov 16 '05 #9
Well most games are written in C or C++ and include pieces of assembly
and other code. Almost all of which are not platform independent. By
developing the majority of the project in c#, the components developed
in unmanaged c++ or platform assembly would be the only aspects of the
application that I would need to develop for each platform. This
correct?

I'm sure most games have other conventions they used to narrow down the
amount of code they need to rewrite for each platform; anyone have any
insight into what these conventions are? Thanks.

Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2168
by: Chuck Ritzke | last post by:
I keep asking myself this question as I write class modules. What's the best/smartest/most efficient way to send a large object back and forth to a class module? For example, say I have a data access module that creates a large disconnected dataset from a database. I want to pass that dataset back to the calling program. And then perhaps I want to send that dataset to another class module. At first it seems that the "object oriented"...
8
1897
by: Galahad | last post by:
Here's the question: I have a form w/ TextBox controls and a Search Button control. Once the user clicks the Search Button, they get a Modal dialog w/ a datagrid that contains their search results. They select a row and click OK. The return value of the Module triggers an method that populates the TextBoxes w/ values and disables them. After the TextBoxes are disabled, I change the text of the buton to "Search Again" since I have to...
6
2060
by: aaj | last post by:
Hi all I use a data adapter to read numerous tables in to a dataset. The dataset holds tables which in turn holds full details of the records i.e. keys, extra colums etc.. In some cases I need to use parts of the tables in datagrids, and here is where my problem lies
7
2583
by: MgGuigg | last post by:
Hello all, This is my first time posting a question to this forum, so here is hoping I am following protocol. I am scraping the rust off my old Basic programming skills, and have just recently upgraded to VB.NET, and I have a lot of catching up to do. That being said, I have come a long way in a short while, however, I am stumped at the moment. I have read through days of posts, but have not been able to address my specific question, so...
7
11649
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard is proving to be more difficult. These pictureboxes are bound to an AccessDB. If the user wants to add an image, they select an image using an OpenFileDialog: Dim result As DialogResult = Pic_Sel.ShowDialog() If (result = DialogResult.OK) Then
10
3102
by: Robert | last post by:
I have an app that was originally 1.1, now migrated to 2.0 and have run into some sporadic viewstate errors...usually saying the viewstate is invalid, eventvalidation failed or mac error. My web config does specify a machinekey setting: <machineKey validationKey="447C05E8B3A71401CC4CAE5513A7F1A3494A3618EE819316AAD1D58433F236A759D66FB4154500E01EB4E1BC1DE42046E2D652D391CB8367A1649438867A02EB"...
15
2014
by: tshad | last post by:
I was looking for a way to handle refreshes (user pressed refresh button) and found a piece of code to check if a Web page was refreshed but I can't get it to work. The code is: ************************************************************ Namespace StevenBey.Web.UI Public Class Page Inherits System.Web.UI.Page
7
8365
by: mohammed.naghman | last post by:
Hi, I have 2 submit buttons in a jsp page. One of them takes me to page2.jsp and also passes the values enetered to page2.I have a link in the page2 that does a history.back to come to the previous page to make any chnages necessary. Now after making my changes, instead of going to page2.jsp if I want to submit the page, Instead of submitting the page it takes me to page2.jsp again. This problem is only with firefox. It works fine...
3
2710
by: Tom | last post by:
Basically I have a page that I load with 10 input fields. If users have JS enabled I want to hide 5 of these fields so as to reduce clutter. If the user needs these extra fields an "Add" button can be used to display the hidden fields one by one. Once the fields a filled in the user submits them for validation and if there are any error They can "Go back" to make some changes. The whole process works great in FF & Opera but IE lets me...
6
838
by: John | last post by:
Hi I have a button which calls a method which in turn calls another method, which in turn calls another method. Let's say in the third method an error occurs and it is no longer possible to continue, how can I dump everything and come out of everything waiting for the user to press the button again to do the process again? Thanks
0
10812
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10523
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9346
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7766
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5804
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4434
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3995
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3089
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.