r/eli5_programming • u/4r73m190r0s • 20h ago
[ELI5] If source code is platform-agnostic, why computer games are not compiled for both Windows and Linux?
3
Upvotes
r/eli5_programming • u/4r73m190r0s • 20h ago
5
u/pixel293 19h ago
The APIs to access the screen, i.e. the GPU are different. Also the file-system structure between Windows, Linux, and MacOS is different. There might also be 3rd party services like video codecs that are available on one platform by default but not on another platform.
3
u/Technical_Goose_8160 19h ago
Code has to be turned into machine language when we compile it. Different systems speak different languages, even hardware can affect it.
Java is hardware agnostic, so every machine needs a Java virtual machine that will turn it into machine language when the code runs.
This is very useful when developing for disparate hardware, Java is very popular with medical machines. But, compiling when it runs is slower and video games can be pretty heavy.
2
u/shadow-battle-crab 19h ago edited 19h ago
Source code isn't totally platform agnostic.
Most of a program is written in a generic way, but the parts that actually communicate to the screen, use the keyboard, etc are written specifically for whatever environment it is designed to run in.
Lets take a video game. So you make a car racing game. Does that game use a game controller? A keyboard? A touch screen? A racing wheel? You, as the game programmer have to design a special connector for your games software for each kind of thing it connects to.
Operating systems are just another kind of connector, because each has its quirks. On windows, you need a different kind of installer than linux, you also need a different kind of way to interface with the windows manager, a different kind of way to accessing the GPU, etc. Where the save game files and temporary files go is different in each environment. How a "Save As" dialog works is different for each environment. How do those screens even work on a game console? How does a switch work differently than a PC?
Modern game engines like unreal and unity do a lot of the heavy lifting of this stuff for you, but not all of it.
Each one of these things requires an extra layer of work, and testing - and if you know your market is going to be mostly people that play the game on Windows, it's easy to decide to not want to do this work.
2
u/Polyxeno 16h ago
My games are, because I use a cross-platform library: OpenFrameworks.
Pretty much all of the platform-specific work is already done in OpenFrameworks, and wrapped in library functions, so my code uses those functions and does not need to change per platform.
I can build the same game for Linux, Mac, Windows, iOS, or Android, and there are rarely any serious technical issues in doing so . . . BUT the Google Play, Apple, Windows, and Steam platforms all have annoying hurdles to face, and testing to do. So I tend to skip iOS, and Mac, and will probably never do Android again, for those reasons.
1
u/Key_River7180 19h ago
Win32, basically we cant agree on how to make a window and put pixels into it with the gpu between platforms.
Read XKCD 927: https://xkcd.com/927/
1
u/mredding 19h ago
Source code CAN be, platform specific APIs aren't inherently.
If you need memory, you need to ask the OS, and how you get memory from an OS depends on THAT OS.
The next best thing you can do is compile the code following some platform agnostic API, and you implement the platform specifics behind the API. That's a lot of what software tries to do.
But video games try to squeeze every last bit of performance out of a machine, and that means you cut the bullshit and get platform specific. You would sacrifice universality for performance.
1
u/Frequent-Sir-6942 16h ago
Neither source code nor binaries are platform-agnostic in the general case.
1
u/Lonely-Restaurant986 16h ago
How the computer reads the code is largely the same.
Windows developers at Microsoft say “Let’s write this function to allocate memory”. They create that standard (windows api). When a game dev writes code they use the standards the windows developers created.
Linux developers say “Let’s write this function to write memory”. So all Linux apps use that standard.
So the problem isn’t the code, the issue is how that code interacts with the hardware.
So when you run a windows program, the code says, “Run this windows function in the windows api” but Linux has no idea what that is or how to do it.
This has been largely fixed by compatibility layers like wine. But kernel level code is where the issues lie.
There’s more nuance to it but that’s simply put.
1
u/Technical_Ideal_5439 16h ago
Source code is not platform agnostic, most code is written for a platform with specific parts of it written to deal with platform differences.
Sure you can write some code as platform ignostic but as soon as you start needing hardware, code normally gets locked into the platform unless you are very careful.
1
u/NZAuthor 16h ago
Source code is not fully platform-agnostic. I'd say 99% of it is unless you are playing around with memory on a very technical level.
The other 1% is for edge cases and could be anything from specific libraries being used that aren't universal, very specific low level language commands, or simply how characters work with the file system. It could be anything simple or complex.
But yes, this CAN be easily worked around most of the time. The developer just needs to decide if it's worth doing or not.
More often then not, it's the choice early on to use a windows specific library for drawing graphics that becomes a barrier.
1
u/kutac56 16h ago
Because certaint low level libraries are different for both operating systems like graphics libraries
1
u/Superb_Raccoon 15h ago
Spoiler: It's not.
1
u/Pale_Height_1251 15h ago
Source code is often platform agnostic but games can be a sore point because GPU shaders are often not platforms agnostic, i.e they are different on Windows, Nintendo, Mac etc. The CPU stuff is much the same, but the GPU stuff often isn't.
1
u/OpeningQuail2483 15h ago
if it is platform agnostic then it compiles and ships for both, if no then no
1
u/bubba-yo 15h ago
I don't think we've had platform agnostic games since Nethack.
But every platform has unique APIs. Linux doesn't have DirectX. Mac uses Metal.
Every platform has different bottlenecks which requires different coding solutions for performance. The Mac has faster single core performance and faster RAM and storage, but slower GPUs. Linux can be 20% faster than Windows for memory read/write. Windows threading is much slower. So a game that is performant on Windows may not be on Linux or Mac without changes, breaking the platform agnosticism.
And every target requires testing, so going from one platform to two doubles your testing overhead, and requires a level of expertise from your team to target it. It's why there were porting houses full of platform experts to figure out how to get that Windows game to run on Linux or Mac.
1
u/vitimiti 14h ago
It takes effort. You have to use cross platform libraries that your team may not be used to if they are used to Windows only. Then each platform has particular quirks that may bite you back. To make matters more difficult, Windows is very backwards compatible, while Linux desktops aren't due to the dependence on glib (the equivalent to the Windows Runtime in a way, you need it) which doesn't have a "don't break user space" policy but rather "Welp, you should upgrade your build then" policy. Moreover, each compiler (on Windows you probably use MSVC while on Linux you probably use GCC) has its peculiarities.
All in all, companies just don't consider Linux support profitable enough, especially because Linux users are VERY used to creating bug reports instead of restarting or ignoring problems, so most bug reports will come from the smallest user base (and this has happened before), increasing workload for a tiny market share.
Basically, it's about money, investment Vs benefit
1
u/fiddle_styx 14h ago
1
u/tecnofauno 14h ago
Source code Is never platform agnostic. It can be portable when simple, and games are not simple. It can be multiplatform, but needs extra effort.
1
u/Quick-Penalty4883 13h ago
A book doesn't care what language it is written in, but for you to understand it it needs to be translated to a language you do understand
1
u/Bo_Jim 13h ago
The core of the programming language is platform independent. System services, like 3D rendering and audio mixing, are very much system dependent. Each operating system has it's own programming interface for accessing those services. A significant portion of any game's code is setting up for those system calls, and those calls are not portable between systems.
Games intended to be ported to multiple platforms usually use an intermediate API that is consistent to the application on every platform, and connects to the platform-specific OS services on each different platform, like OpenGL or Vulkan. They still might require some platform-specific system calls, but these can usually be surrounded by conditionals so that the proper code is compiled on each platform.
Text based applications that use standard libraries are generally fully portable at the source level. A large percentage of the console tools used on Linux are ported directly from sources originally written for Unix.
1
u/mxldevs 12h ago
Source code isn't platform agnostic.
If your code requires windows libraries to run for example, then it's not going to compile on other platforms unless you provide the required libraries.
You can certainly write code in a way that's more platform agnostic, but it's not the fact that it's code that makes it that way.
1
u/Odds-and-Ns 12h ago
Source code isn’t necessarily platform agnostic in general. It can be, and Id argue it usually should be, but it takes active consideration to make it that way
1
u/fltfathin 6h ago
There is lots of game engine and languages so let's start on what is source code, let's call code for short
Code is like cooking recipes, it can be written in different language, say american or spanish, human understand those
But the one cooking is not human, but some kind of robot, for the recipe to be run correctly by the robot, we need to translate it to robot language. There are many kinds of robots with different cooking appliances available to them.
This is the part that usually get stuck, because the different kind of appliance and tools, the food doesn't always make the same taste around. So the human making the recipe decide that they only support one kind of robot. Because adjusting the taste on multiple robot is expensive and change one affect the other.
Sometimes the are cookbook have the same base cooking flow, imagine the recipe about cakes have common baking recipes, and can work on all robots, sometimes the maker just hate one type of robot and refuse to allow people to translate to that robot, despite there is no adjustments needed just one checklist to click. Oh they also refuse to acknowledge when someone can make one robot acts like the other citing that food is gonna be used for poisoning others.
1
u/henke37 2h ago
One thing the others neglect to mention is hardware differences. While things are relatively same these days with "everything" being derived from "IBM compatible" machines, it was a much bigger mess back in the day. While others have pointed out api differences, sometimes there were fundamental design differences in the hardware itself.
Consider a platform such as the GBA, that thing did not have general purpose graphics hardware with a frame buffer. Instead it had exactly four tilemap layers and 128 "objects". It also didn't have a keyboard, it had a d-pad and some buttons.
Modern operating systems can generally abstract away these differences today, but on more limited systems, which might not even have an OS, it was much more visible to the application programmer.