7

I am doing a bit of research before I am going to write my own 2D (and maybe some 3D) game engine. I have made an engine before using C# and XNA but I want to go cross platform this time by making my new engine in C++ using opengl etc.

But ... I still want the fast iteration times from C# and have access to the game engine there.

So I have a few options here.

  1. Write the engine and a CLI wrapper in C++
  2. Write the whole thing directly in C#, no C++
  3. Write in C++ and use Mono to load C# Code / Assemblies into the engine.
  4. No C#
  5. ... Probably something I didnt think of yet

I think I do need the speed for culling, scenegraph stuff, Matrix calculations, particle systems etc.

Wat are the Pros and Cons? What do you suggest?

tshepang
  • 12,111
  • 21
  • 91
  • 136
WoutervD
  • 2,139
  • 2
  • 13
  • 13
  • Possibly stupid question since I don't know much about C#: Is it feasible to write something like this in a GC'd language like C# or would GC pauses eat you alive? – dsimcha Aug 10 '10 at 19:58
  • It is feasible and the performance is acceptable. C++ is and will always be (I didn't say that!) faster. There are several C# game engines floating around already. Flat Red Ball for example. – WoutervD Aug 10 '10 at 20:11

3 Answers3

2

If you want cross platform, you can't use C++/CLI. This isn't supported on any platforms other than Windows.

That being said, for cross platform, I'd either use C# with Tao, or use C++ to make the engine a library, and the use Platform Invoke to "use" the library from within your C# code. This will provide you the speed and control you need in the core engine (C++), with the flexibility of game design in C#.

This provides a clean, cross platform means of developing a game engine that can be exposed to C#.

Reed Copsey
  • 554,122
  • 78
  • 1,158
  • 1,373
  • 1
    Hmm Tao is a little stale looking (no updates in 5 years!) and their domain (http://taoframework.com) has been taken over by a squatter... Is it still current or has it fallen out of date? – FrustratedWithFormsDesigner Aug 10 '10 at 19:45
  • If you split the engine code into C++, make sure you're not making unnecessarily 'chatty' calls across the the native/managed boundary. – Mark Simpson Aug 10 '10 at 19:49
  • @FrustratedWithFormsDesigner: It's in the mono core now, though. Since it's a direct OpenGL wrapper, and very stable, it's still a good option. Otherwise, you can use OpenTK, but that includes other things as well (which may be useful for a game engine). – Reed Copsey Aug 10 '10 at 19:56
  • I am really leaning towards writing and engine library using C++ and use Platform Invoke. I will be doing some experiments with P/Invoke first before diving in. Thanks for the suggestions :) – WoutervD Aug 10 '10 at 20:07
  • @WoutervD: If you want a C++ engine, and want cross platform, this is the only real option. All C++ calls from C# will need to be done using P/Invoke, since C++/CLI is windows only. – Reed Copsey Aug 10 '10 at 20:25
1

Tao framework is dead, try OpenTK instead

1

Optimized C++ code will be significantly faster (20% in my case for ODE's in 32-bit, and almost 40% in 64-bit; C# is slower in 64-bit than C# in 32-bit, but that's another post). I would take advantage of heavy math in a C++ library (integration, differential equations, etc).

Jess
  • 2,991
  • 3
  • 27
  • 40