DEV Community

Cover image for Exploring the Use of C++ for Game Development

Exploring the Use of C++ for Game Development

Tyler Meyer on December 02, 2024

What to Consider When Developing a Video Game To make a video game of your own, you'll need a fun idea for a game, which is a big hurdle...
Collapse
 
miketalbot profile image
Mike Talbot ⭐ • Edited

One thing, C# is not specific to Windows... I've been coding games in C# with Unity since 2011, and I've not had a Windows computer in all that time!

Collapse
 
dyfet profile image
David Sugar

This indeed is true. It is not hard to make C# projects that are built entirely on Linux, that even cross-compile to different linux targets, and build with forward compile (native) code. The nuget infrastructure works the same on Linux. And one can even produce stand-alone binaries that work well with docker, too, that target alpine musl libc, and are often no worse in size than say golang binaries.

Linux choices for cross-platform front-end ui's may be more limited, but most games are scene renders on a window anyway. C# has peculiarities, but both C++ and C# are peculiarity by design ;). I do not talk much about C# simply because nobody asks me to produce things with C#. One could talk about F#, too, as it is a great example of what a properly expressed general purpose functional language can look like.

Collapse
 
tymey profile image
Tyler Meyer

I must have read some inaccurate information about C#. I'll update my post. Thank you for your insight!

Collapse
 
michalispapamichael profile image
Michalis Papamichael

I noticed that a lot of people make this a assumption.

Collapse
 
nikokiirala profile image
Niko Kiirala

C# started off as a Microsoft's attempt to replace Java on Windows, so the assumption has a bit of truth in it. But indeed, C# is a perfectly multi-platform language nowadays, has been for more than a decade.

It's also a VM-based language, just like Java. It has less focus on the "compile once, run everywhere" idea, though - understandable as that idea didn't quite work for Java either. But if you feel like it, you can even spin up a .NET VM inside a browser and write a web app in C#.

Thread Thread
 
miketalbot profile image
Mike Talbot ⭐

Yeah, Unity even compiles IL back into C++ for a bunch of platforms.

Collapse
 
taqmuraz profile image
Taqmuraz

C++ is not cross-platform very much. Different compilers frequently generate binaries that work differently. And, you have to recompile your code for different platforms, while Java has cross-platform binaries by default.
Also, manual memory control is always a negative trait of C++, not a positive one. Manual memory control fails everywhere, comparing with garbage collector.

Collapse
 
tymey profile image
Tyler Meyer

Interesting! This space has been very opinionated online. I kept reading how memory management in C++ helps with speed and performance. I have a background in JavaScript and am beginning my learning in C++. I also plan to learn C# and Java. From what I've read about Java, the cross-platform capabilities sound so convenient. Are you familiar with Java? Do you use it regularly? If so, what do you like about it?

Collapse
 
taqmuraz profile image
Taqmuraz

Though, good luck using C++ for making games. Having competitors struggling with C++ is a very good thing for everyone else

Collapse
 
spekkiodancer profile image
spekkiodancer

I see more studios struggling to adopt Rust than to code with C++.

Thread Thread
 
taqmuraz profile image
Taqmuraz

Yes, Rust hysteria is a real thing.
When I say that C++ is bad, I don't say Rust is better.

Collapse
 
jnp95 profile image
Jean-Noël

I agree the main idea, which C++ give a better control on computer resources and hardware.
But I find Javascript option analysis very (very) short!
The given libraries are totally out of date, whereas there are powerfull alternatives today for 3D games like Babylon.js (just by Microsoft) or Three.js!
On other hand, even if C++ has still granularity advantages, new versions of theses above libraries bring now native GPU api control through WebGL, so I think we have to consider them more a little bit.

Collapse
 
spekkiodancer profile image
spekkiodancer

While Babylon and Three.js are great, they are not the best for intense graphical games. One is better off using WASM for massive multiplayer and intense graphical games. When speed and memory is not a concern, Babylon and Three.js are great

Collapse
 
tymey profile image
Tyler Meyer

I am considering JavaScript more since I have a background in that language. I am learning C++ and used this article as an opportunity to learn more about it. Due to time constraints, I had to cut my research short on JavaScript, Python, and Lua. Perhaps in a future article, I'll dive deeper into JavaScript's use in the gaming world.

Collapse
 
giullianosep profile image
Giulliano Ferreira

2024 and people still think C# and .NET are specific to Windows when .NET Core was released in 2016.

Collapse
 
aminkhormaei profile image
amin khormaei

I think the title is wrong. People do not choose C++ for game development; engine creators choose the programming language people should use with their engines.

Collapse
 
skhmt profile image
Mike

Exactly. Games using Unreal will be largely written in C++, games in Unity will be in C#, Godot games will be in Go, and RPGMaker in JS. Most studios aren't going to be creating a game engine from scratch.

Collapse
 
tymey profile image
Tyler Meyer

I need to change that title for sure. It was an early inspiration for writing this article, and my opinion changed while researching, but I forgot to revise the title. Thank you for giving it a read! I am new to the space, and I've been writing articles to learn more and give me a reason to research areas I wouldn't normally spend a lot of time in.

Collapse
 
spekkiodancer profile image
spekkiodancer

Lol what about .NET MAUI?

Collapse
 
adnansamiralhaddad profile image
Code_Ninja

Because c++ have the opp

Collapse
 
philfrei profile image
Phil Freihofner • Edited

Things I've found to be true with Java:
Yes, you can write once and have code run on Windows, iOS and Linux operating systems (and some others as well) but the user has have Java installed.

An alternative is to compile the Java code with a built-in, customized JVM. In this case, one needs a JVM for each OS, and it can be a bit of a task setting this up for each.

I found that there are some differences in the ratio between font sizes and pixels, for Windows vs iOS/Linux systems. For this, I've resorted to creating alternate sets of constants to be used with a given OS that pertain to the size of fields.

There are a couple Game Engines that primarily use Java: JMonkeyEngine and libjdx.
Personally, I dislike pointers. I find their use makes code more difficult to read and more prone to bugs. You may not have any problem with them.

For the most part, Java is very close C++ in terms of performance speed, and to me, easier to code with Java, and it is better adapted to multithreading and functional coding. But it's been a number of years since I checked out how these aspects are handled in C++. I assume there have been improvements.

I think it's a shame that the Java game engines didn't get the level of support similar to Unity or Unreal. IDK why, but it does seem that on a number of occasions Oracle decided to ignore requests by the Java gaming community to open up some aspects of the GPU and graphics in a way that would have allowed faster rendering. There are folks that have a better understanding of the history than I do.

Collapse
 
tech_rashid profile image
Rashid Shaikh

This interesting