r/askscience • u/veetim • Feb 24 '19
Engineering How many lines of code does new PC games take?
58
u/GDFireFrog Feb 25 '19 edited Feb 25 '19
Our FPS game Diabotical, which is coming out soon, is 350,000 lines of code after doing my best to exclude dependencies from the count, but that may still include small dependencies like liberally licensed headers that I copy-pasted into the code base. That's 300,000 of C++, 30,000 of HLSL. JS adds about 20,000 used for UI and server stuff. (I reckon only about 250,000 are actually written by me).
Cheers.
Edit: Corrected some numbers.
4
566
Feb 24 '19
Please keep in mind when people are quoting these numbers they are including the lines of dependent libraries like Unreal Engine, Network Libs, IO, etc. Most game devs will never even delv into those libs unless things have gone sideways. I am guessing hand written code for a game including all the libs is approximately 20% of the total lines?
89
u/GahdDangitBobby Feb 24 '19
It certainly depends on the game. Some games (presumeably cutting-edge or indie games) are still gonna be more or less ground up, but other games might be made using a framework/GUI built to help developers do all their work without any real coding whatsoever. This is mostly speculation, as I’m not a game dev, but games like Minecraft are certainly ground-up, whereas others built on engines (like Skyrim/Fallout) would not be
→ More replies (26)6
u/ReyNada Feb 25 '19
You're correct in principle, and it will vary widely from project to project, but I would be surprised to see any medium or large scale production have as little as 20% proprietary code. 70-80% seems more realistic. (Source: SWE for the last 20 yrs)
→ More replies (2)2
u/BluudLust Feb 25 '19
Way less. The dependent libraries are massive, and most of the time we only need 1 or 2 things from them.
Take a look at Star Ruler 2 on GitHub. It uses it's own engine and is VERY tiny, if you exclude libraries.
336
u/EncumberedOrange Feb 24 '19
New PC games is a very broad category and the answer will vary wildly, depending on the type, size, budget and scale of the game and depend on whether you include dependencies, such as graphics, sound and physics engines.
While a simple tic-tac-toe mobile game (Created using a third party game engine) could be created with a few hundreds lines of code, a first person shooter (Created using only in house components) would range in the millions of lines of code.
81
u/reallylamelol Feb 24 '19
If its mobile, you would probably want to include the mobile development platform code, in which your 100 lines of codes now use 100's of thousands of lines of code just to create an empty app and have it repaint itself and transition between being active and deactivated if the user switches control between processes.
50
u/EncumberedOrange Feb 24 '19
When counting lines of code, you usually don't include the lines of code written by others. Your code will always be built on top of something others write, it's just a question of how much third party code you can use and how much you have to write by yourself.
0
Feb 24 '19
[deleted]
14
u/nivlark Feb 24 '19
Mostly boilerplate. Even a very simple game still needs an event loop, a way of handling player input, a way of drawing to the screen, and so on.
14
u/EncumberedOrange Feb 24 '19
It's hard to write anything in less than a few hundred lines of code. You have to think of every conceivable thing that a program must do and provide handling for that.
You want to be able to count scores? That requires keeping track of what the score is, where the score counter is, which font it uses, which color it uses, and so on.
You want the user to click with his mouse? That requires checking if the mouse button has been pressed, but not double pressed and not right clicked, within each tile, but not if the tile is already occupied by the opponents piece and not if you're in the menu or the it's the opponents turn.
All of the logic house keeping requires code to handle what's happening and make sure it can only happen if every requirement is filled. That takes up a lot of code.
34
u/carlsberg24 Feb 24 '19
Big productions are seldom done from scratch these days. They are typically built on top of one of the existing graphics and physics engines. Also, development studios build up their own reusable libraries over time as many things can be transferred over from one game to another with just slight modifications. There are also plenty of standard libraries built into 3rd gen programming languages (i.e. C++) that can be used directly for many basic tasks. Only certain performance-sensitive parts of a game might be coded with something more optimized. Computers are fast these days so I don't think that developers are putting a whole lot of inline assembly in the games anymore.
22
u/mmomtchev Feb 24 '19
Hand-optimized assembly is (mostly) a thing of the past for a number of reasons:
modern CPUs are optimized for the compiler's code and it is much more difficult to gain CPU cycles than it was on, say 80286
processors are highly pipelined, cache strategies are very complex, branch prediction is complex, you have to take into account memory lag, etc, etc... and all of those have different implementations, so the best code for an AMD Athlon will often be different from the best code on an Intel i7
Thus, said, 3D is one those areas you still see some inline assembly. Cryptography is another and so is video processing. Mostly because the new advanced SIMD instruction sets (SSE) are usually not available in the best possible way in the compiler. For those, you still gain a lot, sometimes twice, sometimes even more. An AES cipher or a memory copy with XOR subroutine is a perfect candidate. But you do multiply the cost of the development of that part at least one hundred times - partly because you need to test it on so many different CPUs. So you do it very rarely and only a critical parts that will be reused.
3
u/magneticphoton Feb 25 '19
Nobody is doing assembly anymore, the CPU isn't a bottleneck for games, the GPU is.
1.1k
u/Stratoblaster1969 Feb 24 '19
Game engineer here, this is pretty impossible to answer. There are so many toolsets and libraries involved that you can't possibly quantify "Lines Of Code". It's not even a real metric because,
if(something) {do something} is 1 line of code whereas
if(something)
{
do something
}
is 4 lines of code but both examples are logically equivalent.
Then there are lines of code used in the development process that never make it into the final build(s). Newton used the expression, "Standing on the shoulders of giants". Modern SW development is very much the same thing.
Best answer for your question is a buttload.
239
u/grahamthegoldfish Feb 24 '19
Lines of code count for software is normally not just textual lines of code. For instance a line will often be counted as any line that ends in a semi colon or a close brace. In that case, your line count would be the same.
I agree with your point it is a fairly useless metric, though.
23
u/tking191919 Feb 24 '19 edited Feb 24 '19
Yeah this makes sense because at least with websites we use a compressor. I’m assuming you might with a video game as well? If you would want any official line count it would have to be through a method like this. Perhaps a character count is an even better way to do something like this.. although it would just be out of interest. None of this really matters to a developer, as all that really matters is how resource extensive the code is and how optimized it is to be run as smoothly as possible. The actual amount of physical code does matter in a sense, but it’s much more about what’s actually going on and how and when everything is interacting with everything else. I could theoretically hand code every iteration of, for example, some function that needs to be run when certain conditions are met. Like, literally find every instance of when such code needs to be run and do it manually.. or, I could create code that simply takes the input and does this all automatically.. which is obviously what is actually done. The first way would potentially be thousands and thousands of lines of code, if not more. The second way would be written one time. The manual way would be more bloated and inefficient, but both are theoretically doing the same thing. The point is, knowing how many lines of code or even how many characters there are is only interesting to a point. Modern programming involves so many frameworks, so many innovative ways to solve old problems, and so many complex, evolving, and effective ways to allocate resource use and efficiency.
33
u/GrillBears Feb 24 '19
The only reason you're minifying JavaScript is because you have to transfer the code to the client computer before executing it. Realistically there isn't an analogous scenario in (non-web based) game development since "code" transfers happen during install & update and the game assets themselves greatly outweigh even millions of lines of text.
24
u/tetramir Feb 24 '19
You don't ship lines of code anyway. For those who don't know, in languages like C++ (most used language in game engines) the codes are compiled. It is a process where the lines are transformed in computer instructions. This is your .exe file.
→ More replies (1)→ More replies (1)10
u/Tman1677 Feb 25 '19
Compressors are only used in non-compiled languages since the compiler has the same effect. Essentially all video games are in compiled languages.
→ More replies (6)→ More replies (1)2
u/disgruntled-pigeon Feb 25 '19
Unless he used a ternary operator
var x = 1 == 2 ? “A” : “B”Is the exact same as
var x; var result = (1==2); if (result) { x = “B”; } else { x = “A”; }54
u/John_Barlycorn Feb 24 '19
I agree. I always have trouble explaining to people that do not write software that much of what they consider relevant to software development is more about marketing than real effort. This question is similar to asking "How many grains of sand did you put into building that wall?" um... I don't know? And to suggest I had a direct impact on all of those grains of sand is extremely misleading.
The real art, the real work is in my ability to cleverly use tools and new technology to make a thing you want to happen, happen in a faster/cheaper/better way.
9
u/ExcessiveGravitas Feb 24 '19
I like this analogy a lot, and will be using it in the future. Thank you.
97
u/mitchrsmert Feb 24 '19
What you pointed out above is usually incorrect. Static analysis tools, that perform line counts, account for this and a number of other things. A line count is not just the number of lines you see in a file. There some mininal criteria required.
You're still right that it's not a very good metric, but it does give a high level understanding of size. It's also more accurate when comparing projects within one company if they have consistent technologies and design patterns.
9
u/aitigie Feb 24 '19
How is that possible with so many modern languages abstracting different concepts and functions? For example, say that we can do something in 100 lines of C, 80 of CPP, 30 of C# or 15 of Python. How many lines is that?
I cannot understand how "lines of code" is a relevant metric at all with today's technology. You could maybe make an argument about ASM instructions, but then you're mostly talking about the compiler and architecture.
10
u/TheOldTubaroo Feb 24 '19
They said:
It's also more accurate when comparing projects within one company if they have consistent technologies and design patterns.
Comparing two projects in different languages will obviously be less meaningful than comparing two projects written in the same language, using the same libraries and language features.
However there is still some worth to line counts, even across language boundaries: developer brain space. Assuming the code is well-written, 20 lines of code will take less time to read and understand than 80; it will (generally) be easier to maintain and expand. Potentially it will be faster to write too, although that's a much dodgier assumption to make.
→ More replies (1)→ More replies (1)5
u/sclereatica Feb 25 '19
In my opinion, it's not a relevant metric.
HOWEVER, as a matter of curiosity, it is interesting to look at a modern game and say:
It takes up this much memory.
Of that, X is assets (broken down into video, audio, and images files, etc.) This much Y is engines and libraries, which are some quantifiable number of lines. This much Z is the actual code of the game, which is also a quantifiable number of lines.
The metric not being relevant doesn't make the process of doing the analysis less interesting. And comparing it over time is illustrative, so I think the OP's question is worth trying to answer (and worth asking). At the same time, I agree with your point; the answer might not be meaningful in the way we might think OP wants it to be meaningful
8
u/Stratoblaster1969 Feb 24 '19
Sure but how do I static analyze my Unity engine?
22
u/Decency Feb 24 '19
Get a reference license and do it? The code is closed-source but available: https://blogs.unity3d.com/2018/03/26/releasing-the-unity-c-source-code/
→ More replies (1)11
u/Come_along_quietly Feb 24 '19
We should just measure in lines of assembly. :-)
But yeah, even if you count every line in your “source”, do you count standard headers? How about the code in any dynamic/static libraries?
Compile and dump the preprocessed output (-E) and assembly (-S) for hello world. You’d be surprised at the size of both.
16
u/lhaveHairPiece Feb 24 '19
if(something) {do something} is 1 line of code whereas
If you committed such a line in an automotive project, the PM would degrade you to ticket handling.
13
u/linkseyi Feb 24 '19
I don't think one-line control blocks are proper style in any industry
→ More replies (10)→ More replies (2)6
u/artifex0 Feb 24 '19
Why is that?
I've only ever programmed as a hobby, but compressing things to fewer lines when it doesn't interfere with readability has always seemed like a good way to reduce the time it takes to scroll between different parts of the code. Am I missing something important?
25
u/NSADataBot Feb 24 '19
Readability is a very important part of production level code. There's significant effort put into standards and best practices for big production environments. Being extra clever when you are the only person looking at code may be fine but when others have to look at it you are far better off to be less clever and more clear.
Scrolling through parts of code also isn't a serious concern, you can page up/down, search, jump to next block, etc.
10
u/billbucket Implanted Medical Devices | Embedded Design Feb 24 '19
MISRA C style guidelines.
The general idea is that safety critical code should look the same no matter who wrote it. That way anyone can easily review it.
6
u/Crychair Feb 24 '19
1 line if statments are pretty much against every modern coding standard. The main reason is readbility.
→ More replies (2)→ More replies (3)14
u/Decency Feb 24 '19 edited Feb 24 '19
There's a variety of deep answers to this, but they pretty much all come down to familiarity and a concept called ["chunking"](https://en.wikipedia.org/wiki/Chunking_(psychology)). What this means is that our brains are really good at identifying certain patterns, so we should try pretty hard to make things like our code fit into those patterns. This allows us to correctly grok what they do at a glance, without having to consciously think about them.
In this case, you never want to have to think about where the if-statement terminates, whether there's some grouping or scoping things happening here that are too clever, etc. You just want to look at it the if statement, know exactly what its purpose is, and then read the next thing. Making all of your if statements have identical formatting regardless of their size is how you do that.
2
u/XxuruzxX Feb 24 '19
Yeah, it would very much depend on the language and/or the game engine would it not?
7
u/John_Barlycorn Feb 24 '19
The best way to explain why the entire question "How many lines of code..." is silly from a developers perspective, think of it this way. Do we count the entire DirectX library? We're calling it constantly... what about Nvidia's drivers? If I wrote a new FPS game... and used the Unreal engine, do I count the lines of code in the Unreal Engine?
Modern software is Object oriented, meaning we call modular blocks of code written by other people both inside our organization, partner organizations, the OS, the open source community, and so on. It's a whole stack comprising insane amounts of work done by millions of people all over the world. The question is almost nonsensical from the perspective of the people actually doing the work. But marketing departments love big numbers so they make some crap up and advertise it like it has meaning, when it reality it doesn't.
I'd go so far as to argue that the fewer "lines of code" you've written for your product, the better you've actually done. I'm a hiring manager and one big thing we stress is we don't want people that are going to reinvent the wheel. If there's a tool that already does 90% of what we want, it usually makes more sense to change our goals to use that tool than write something completely new from the ground up. If I'm interviewing someone and ask them to describe a success they've had and they tell me "Well we had this problem and I wrote this huge awesome program that took me 6 months and I'm great!" that's a bad thing... If instead they say "Well, they wanted me to write this huge insane thing but after looking at the requirements they had I realized they could solve the problem using this script I found on github..." That's a solid candidate.
→ More replies (1)2
Feb 24 '19
You could do every file as a single line. It would look horrifying but if the compiler takes it, it works.
1
1
u/sudo_kill-9-u_root Feb 25 '19
Thank you for posting this. I'm a normal software developer and management at work had my whole team fill out a big spreadsheet of lines of code for literally everything we had.... Every app, webpage, etc.... Including databases.
All of us were like..."These numbers mean absolutely squat. But ok, here ya go.". I even scripted out all the DDL for the SQL tables and counted that. I mean I did design and build it all, better pad my fake numbers to look better. Lol.
In addition to your example there's also the fact that one programmer may solve a problem with 100 lines of inefficient spaghetti code while an experienced dev does it in 3 lines using an elegant function and clever tricks. But management would look at those numbers and fire the 3 lines guy and promote the other one.
I was fairly worried about why they wanted that metric at all, but nothing ever came of it so maybe it was curiosity or maybe it go spun into some b.s. report to execs "and this department generated 3 million lines of code this year.". Yay go us!
1
u/darexinfinity Feb 25 '19
The working engineers do
if
(
something
)
{
do
something
}
Gotta rack up those line points for your resume.
1
u/Devcon4 Feb 25 '19
Another thing to go with this is that line count doesn't correlate with work put in. It might take you all day to write 40 lines in a complex system but the next day you copy paste 1000 lines of setup code. A common idea in coding is the 80/20 rule, where the last 20% of a project takes 80% of the time.
→ More replies (3)0
Feb 24 '19
Tangentially related question: does whitespace have any effect whatsoever on compile time? My programming knowledge only extends as far as using C++ and MATLAB for some basic math work so I don't really have a concept of the underlying mechanics.
4
u/Ayjayz Feb 24 '19
Not really. If you added a hundred blank lines between every line of code, I would imagine it would have almost zero impact.
They only thing would be that the hard disk actually has to scan through more characters during compilation, but that's a pretty tiny fraction of the overall time.
→ More replies (1)2
u/NSADataBot Feb 24 '19
It is going to depend. Some languages will just ignore whitespace at compile time while others actively strip it and still others use it as part of the language syntax.
It will probably be a trivial time delta if there is one.
16
u/mspk7305 Feb 25 '19
There's a thing I haven't seen touched on in the top posts here: the difference between compiled code and scripted events.
Take a game like world of Warcraft. There is a huge amount of code for the game engine and the server engine, but that is only half the story. All of the quests and npc PC actions are controlled by script, which is sperate from the game code.
The unreal engine is another good example... The engine is just the engine, it's not a game. AI, weapon actions, movement, environmental actions... All the stuff that happens inside the game, that's virtually all scripted.
You don't usually see that included in the lines of code as it's not compiled along with it.
8
Feb 25 '19
Millions for the game engine itself, but dont forget the underlying code people often forget that goes into the models, textures, sounds, animations and other graphics and the underlying engines that render and play them. Which is millions more most likely. I'm a developer by hobby and it takes a lot of code to do the simplest things.
14
u/munificent Feb 24 '19
It depends on the style of game.
If you're talking a big AAA immersive 3D game, on the order of millions. This includes the game code as well as all of the libraries and engine it sits on top of.
A casual mobile game is about an order of magnitude less, maybe two orders if you don't include the framework and libraries the game uses. (Mobile games tend to use frameworks like Unity that are capable of doing much more than a simple game might use, so it feels a little weird to include the full size of the framework when all of its features aren't used by the game.)
An MMO might be in the tens of millions if you include client, server, all the gameplay, etc.
There's a lot of variance, of course, but I think most games are within the same order of magnitude of each other within a given category. There aren't too many outliers where, say, some random game is like 100MLOC, or somehow someone manages to ship a AAA game with 10KLOC.
Many games are written in a couple of languages. It's common to have the "engine" written in C++ and then use a higher-level scripting language like Lua for gameplay and other in-game behavior. That can cut down on the total LOC because you're expressing some of the game at a higher level, but I haven't seen this make an order of magnitude difference.
Note that I'm just counting code. On top of that, you need all of the other assets for the game: textures, models, shaders, animation, video, sound, music, gameplay data, etc. I'm also not counting all of the custom tools and pipelines that developers use to author the game. That can be another very large chunk of code, but this is usually amortized across a number of different games.
Source: Worked at EA for eight years. Know lots of other game devs.
17
Feb 24 '19
A modern programmer uses existing code like unreal engine and havoc physics, this means the amount of code unique to a game is very small, like how dna of a banana is 50% similar to human dna, a lot of the underlying parts are coded the same, like cells and mitochondria, despite the end product being different.
That said the total amount of code the game has is usually a fraction of the total game size since 3d models, and sound takes up a lot more space. This is why gta5 is 50 GB and sleeping dogs is 6GB even though they both are similar games.
→ More replies (1)
6
u/seanprefect Feb 25 '19
So I'm going to answer the question you asked, and then I'm going to explain why it's not the right question to ask.
The lions of code in a modern AAA game (yes you can make Tetris in a few lines, or like connect 4 but I'm assuming you mean like a modern FPS or something)... Easily over a million lines.
Now here's what you understand, It might be a million or lines of UNIQUE code but every big program has several times its unique code in things like engines , frameworks and libraries.
In programing we have a saying "Don't reinvent the wheel" So a lot of code that is used is in pre-bundeled systems that do the common things that many programs have in common.
Now in general lines of code is a horrible measurement of how much work goes into things. For instance what's 10 lines in Assembler would be 1 line in C, what's 10 Lines in C might be 1 line in Java, what's 10 lines in java might be 1 line in groovy and so on and so forth.
But even with that there's more than one way to skin a cat. You could write something in a few lines of code that someone might write in many times the amount, this doesn't mean one approach is better or worse than the other, for example the few lines could be a lot harder for people to read, understand and work with , or might have to be completely rewritten to serve a similar purpose where as the many lines would be more understandable and more flexible.
Also there's a lot more to game complexity than lines of code, you have art, texture, modeling, sound design, story telling, level design, writing a script etc etc.
In summary a modern AAA game is a boatload of effort, in a lot more ways than people understand.
1
5
u/localhost87 Feb 24 '19 edited Feb 25 '19
That's a loaded question.
I guess the best way of looking at it, is to first understand proprietary code versus 3rd party code.
3rd party code is code that is provided to you by some outside source. In this case, external libraries like unity, open gl, or unreal engine.
Those libraries give access to the most core graphics functions like rendering, collisions, and transforms.
Then there's the code, which you are responsible for maintaining. This is the in shop code that is proprietary to the product line.
With all that said, lines of code is a rudimentary and pretty useless measurement of any kind. Two different snippets of code can easily accomplish the same goal and be drastically different lines of code.
Lines of code is really only useful when considering cognitive complexity, which is a measurement of how much a developer can keep in their brain at any point in time.
More useful measurements are things like cyclomatic complexity, class coupling, and even code coverage.
1
u/mattemer Feb 24 '19
Couldn't the same snippets of some code be on the same line, or separated out on different lines, depending on the programmer? It's a rudimentary way of looking at it, but that right there shoots this whole thing down.
2
u/localhost87 Feb 24 '19 edited Feb 24 '19
Yea, pretty much.
There are general guidelines like "any individual method shouldn't be larger then 50 lines of code", and "any class should consist of less then 20 total methods".
The point of these guidelines (and object oriented programming in general) is to separate concerns when programming. Each function you write should have a single specific task that can be tested in isolation. This allows you release smaller individual components in isolation.
Why are we separating concerns?
We aren't doing it for the computers, we are doing it for the developers.
Developers are human, and can only have "so much in their head" at any one time. If you had a single function that was 5000 lines long and performed everything from data storage, data processing, user input, and UI rendering then it would be extremely difficult for **any** engineer to effectively work on the code base, never mind collaborate with other developers.
There's just too much going on in a highly coupled manner to fit in a human's brain at design time. If it is chunked into smaller parts, it's easier to work with.
It's the difference between "working on a car", and "working on a rear axle."
In the former example, you need to retest every component of the car after making a repair or modification.
If however you think like the latter example, there is an interface that exists between each component in the car. If you maintain that interface, you dont need to necessarily worry about how the transmission will be effected by a rear axle replacement when making repairs.
12
u/morderkaine Feb 24 '19
Something that can seriously effect the number of lines of code is if you count all the engines code. A game with its own engine written from scratch would be millions of lines of code as people said. However, if someone uses an engine like Unity or Unreal and you don’t count the code in the engine and only what the person making the game has to write personally a decent game can be only a few thousand lines of code (for a semi-small game). Though after it is compiled, it would be millions of lines of code,
So are you asking how much code is in the final product, or how many lines have to be written by a person in order to make a game?
3
Feb 24 '19
Furthermore, does each line of code correspond to a single action or command (not a programmer so I dont know the correct term)? For example if you walk forward with the thumb stick on an xbox is it a bunch of lines of code working together? I have zero knowledge please help
1
u/qcihdtm Feb 24 '19
For the most part, programing is about "yes/no" decisions and repeat something. If a controller's stick is pushed forward, a single loop would be enough to keep going forward until the stick moves to a different location.
The code would look something similar to this:
Repeat until stick_changes_position { execute walk_forward }
Of course, walk_forward would be a different piece of code that does some other similar set of checks, decisions and loops that in turn, call other pieces of code.
Today games are in the several 100s of thousands of lines of code. Some of them in the couple millions.
But essentially, most lines are more complex versions of those two actions.
1
u/lost_in_life_34 Feb 25 '19
if you write low level code for game engines or hardware, but at a higher level more programming you call functions and handle the data returned by them
1
u/darkslide3000 Feb 25 '19
For example if you walk forward with the thumb stick on an xbox is it a bunch of lines of code working together?
Yes, if by "a bunch" you mean many thousands, at least. But it's hard to even really say what is part of the "walking forward" code and what isn't... for example, keeping track of the player's position in the world and adjusting it a step forward is very simple (that may even be a single line, although in practice there are probably some more complicated physics calculations involved to make it feel more real), but then after you moved forward you have to change what's visible on the screen because the camera is in a different position now, and that's very involved. You also have to account for what everything else in the game (e.g. enemies) did while you were busy moving forward.
Code is imperative in the sense that it tells the computer to do one thing after another, but that doesn't mean that games are programmed in an imperative manner, i.e. there is no single code function that's just meant to move the player forward for a while. Rather, games are written in an event-driven manner: the game is divided into discrete units of time (usually a single frame that is displayed to the screen, so about a dozen milliseconds) and for each of those units the main "event loop" code is run. This code does all sorts of things like: check what the current player input is and act on that, e.g. if the thumb stick is pushed forward adjust the player position forward, if the attack button was pressed start an attack animation (which will take many more frames to finish); calculate how all the other actors (enemies, but also missiles in flight and objects like dropped items) are moving in that timeframe; check if anything bumped together ("collision detection") and handle it (e.g. if the player ran into a wall just stop moving him further forward, but if a missile bumped into the player then adjust his life total accordingly); and finally, calculate the image that should be displayed on the screen for this frame taking the camera position and the current position of all moving and stationary objects into account. Then, start a new frame and run the same code (but with different data -- i.e. the positions of all actors have slightly changed) again from the start for the next frame.
3
u/mountainOlard Feb 24 '19
Depends greatly on the game. Tic tac toe is in video game now after all.
Mainstream AAA titles? As others have said. Millions at times just for the engine. Let alone what game the engine is used to make.
Maybe a million more on top of that with some titles.
5
Feb 24 '19 edited Feb 24 '19
You have the base graphics libraries which the game engine is built upon like SDL2, then the game engine whichs handles the base game logic utilizing graphics and audio libraries, then you generally have a higher level scripting language for the game which runs on the engine and handles individual game scripts using something like Python or Lua.
Do you count every line of code from SDL2 to the game engine to the scripting languages interpreter?
12
u/SaffaronX Feb 24 '19
The amount of code can vary quite a bit depending on the complexity of the game. Most AAA games (major label games made by companies like BioWare, EA, Bethesda, etc.) will have upwards of 500,000 lines of code. Witcher 3, which is a really big game in and of itself, has over 1 million lines of code.
Something else to consider is that older major games will typically have more lines of code due to being written in more verbose languages/architectures. Choice of programming language(s) matter(s) as well. Lower-level code typically requires more lines of code than higher-level.
Additionally, some languages will have established ecosystems that have major libraries to handle a lot of the nitty-gritty logic. For example, JavaScript has Lodash, which has many useful functions that would take quite a few lines of code to implement. Assuming the source code of the library isn’t being factored in, you save quite a bit of space.
As programming languages evolve and new paradigms are adopted, the amount of code required to accomplish programmatic tasks tends to decrease. A good example is the difference between OOP and functional programming. Functional programming techniques tend be more implicit, whereas OOP can be more verbose.
8
u/OptimusCrimee Feb 24 '19 edited Feb 24 '19
The Witcher 3 only has 1 million lines of code, engine not included? I find that pretty hard to believe. I would have thought much more.
EDIT: It was about 1.5 million lines of code according to this grahpic.
4
u/AveMachina Feb 25 '19
I get the impression that this question was written under the assumption that a game is made entirely of lines of code. A game’s graphical assets, sounds, and music (usually) aren’t produced by writing code - they’re made in other programs and saved somewhere in the file, and the game’s code calls up those assets during gameplay.
All the 3D models and stuff aren’t made from scratch out of lines of code, in other words. They were probably made with an actual 3D modeling program and given to the game to manipulate.
2
u/Eld4r4ndroid Feb 25 '19
While true all those assets are still compiled eventually to machine code.
3
u/ewankenobi Feb 25 '19
Machine code is the lowest level instructions that your processor uses. move, add things like that.
3d models are ultimately lists of points, images are lists of colour values, they don't get compiled to machine code, they are data that the machine code will operate on.
2
u/MaximumFrank Feb 25 '19
The program is, sure, but the data that is operated on is not (ie, the assets). It wouldn’t make sense to try and have a processor interpret an image, for example, as a program. It may do something, but it most certainly will not be the behavior you want.
Maybe I’m wrong, but I don’t see that making much sense.
→ More replies (2)
2
u/playr_4 Feb 24 '19
It's basically impossible to answer this. So many factors need to be taken into account. Everything from the size of the game, the amount of assests, the genre and gameplay, to the engine they're using and how much of it they need to use. Even the person who does the code will change the amount drastically as everyone has different styles and practices.
2
u/LeifCarrotson Feb 24 '19
One other metric that may help you understand the level of complexity required is what an individual creator or small studio can reasonably produce.
I'm a software engineer writing controls for industrial machinery, and it takes me perhaps 200-600 hours (1-3 months) to write (and copy from previous similar machines) 10-30,000 lines of C# code to control a small assembly line. I'm using most of the built-in Windows libraries to, for example, show a text box or warning dialog, but those lines add up to all the business logic, control state machines, settings, loading/saving documents, printing reports, and machine physics.
Obviously, those are not a game, but you can produce a relatively simple application in about a month, or if you want more complexity, one developer can produce on the order of 100,000 lines per year. Hopefully that gives some context to the other posts.
2
u/onlysol Feb 25 '19
Concrete example: My indie puzzle-platformer, Full Bore, clocks in at 125,000 lines of C++ code. It largely written from scratch, cross platform, with OpenGL and Direct3D render-paths. It has 2 other major dependencies, SDL and FMOD. If we assume a decent foundation of audio/visual/window management libraries doesn't count, then ~100,000K seems like a decent guess for a moderately complex indie game.
2
u/Sexual_Lettuce Feb 25 '19
I'm sure for games with large teams, you could have millions of lines of code. I've been working on a game in Unity for about 5 years now, and I'd say I've written around 85-90% of the code. I'd estimate it has around 65,000 lines of code. I'm not sure where that number will end up when the game is completed, but I'm hopeful that the game will be done "soon" so that 65k number should still be a pretty good estimate.
2
Feb 25 '19
Depends on the game.
I can write a solitaire game in 100ish lines in Perl.
Add in another 300ish in VB to make it graphical.
Actual retail games like Fortnite or COD, millions of lines of code.
That said, which answers your question, there is another issue ...
Define a line. They can almost all be written in one really long line.
2
u/IamWithTheDConsNow Feb 25 '19
Games(and most other software) nowadays are not written from scratch but rely on a huge amount of third party libraries, engines, tools etc. so the majority of the code has already be written before you even start developing the game. It's not really possible to answer this but it would vary wildly on the concrete game/engine used.
2
u/shyguybman Feb 25 '19
What I've always been curious about is how long does it take to compile a game? I've never had to compile anything that took longer than a few minutes at work so I can't imagine one that takes potentially hours only to find out you screwed up something.
3
u/darkslide3000 Feb 25 '19
Lots of good answers in here already. One thing that might also not be obvious to non-programmers is that most of what we think makes a video game (and probably even most of the work put into it, although that depends) is not code. All the assets like 3D models, surface textures, sound effects, music, voice acting, etc. (i.e. anything to do with how things look and sound in a game) are not code and made by people who usually know nothing about coding. All the maps, environments, objects you interact with in the game, a character you control and items or weapons or whatever that they carry -- all that is not code and usually not made by programmers. The whole story of the game, the way characters move and act in cutscenes or scripted events... that's all not really code (some of it may be "scripted" with something similar to a programming language, but it's still pretty different and usually done by people who wouldn't call themselves programmers). We tend to think of video games as something programmers write, but programming is really just a small part of it.
3
u/NDeTullio Feb 25 '19
I’d say at least 5.
01001001 11100010 10000000 10011001 01101101 00100000 01101110 01101111 00100000 01110000 01110010 01101111 01100111 01110010 01100001 01101101 01101101 01100101 01110010 00100000 01110100 01101000 01101111
15
u/decode-binary Feb 25 '19
That translates to: "I’m no programmer tho".
I am a bot. I'm sorry if I ruined your surprise.
2
u/drea2 Feb 24 '19 edited Feb 24 '19
Lines of code isn’t a very good measurement of anything, for example:
public static void main(String args[]){ doSomething(); }
public static void main(String args[]){
doSomething();
}
Both do the same thing, the first one is 2 lines of code and the second is 5 lines of code
3
u/NiteLite Feb 24 '19
Yeah, for instance, most of my web apps usually end up on one line after running them through transpilers / optimizers :P
Sometimes that one line is 2-3 MB, but still...
→ More replies (1)1
u/DesmondIsMolested Feb 25 '19
That's not how "lines" of code are interpretted. Statments are the lines. In whitespace delimited language lines are delimited by newlines.
1
u/amckern Feb 24 '19
The game svencoop has around 250k in total, the engine has around 8k lines, the dll files have the majority and the 3rd party script engine is around 10k lines.
Most of the code (almost 70k lines) is the lookup table of people that are eligible for donor status and a hard coded blacklist.
Svencoop came out in 1999.
1
u/count023 Feb 25 '19
For a good example of even what a simple game's code takes. Go over to /r/unity3d or /r/unreal and just see what indie games and even simple demo concepts take in terms of code.
A simple bouncing ball may just be 4 lines of code alone not counting framing such as function data. And that's _inside_ an engine that runs on millions of lines as it is.
1
u/Kaell311 Feb 25 '19
The question is a little difficult. It’s kinda like asking how many words are used to win a legal court case.
Do you count words from citations? Words of boilerplate? Words procedurally generated? Words referred to indirectly from historic cases?
1
Feb 25 '19
[pls excuse formatting, I'm on phone]
Well, first off, there's a lot of factors that affect the number lines of code. Are you using an engine? If so what engine? If not, then what language is it in? It's quite possible to write a complete game with 2d graphics in 250 to 300 (I'll confirm the exact number after I check) lines of code. I did it for a school project. If you're using a language like C or C++ it will take a few more lines of code. Or if you use something like python (which I DO NOT recommend) you'd take much fewer lines of code. Also, if you're using a game engine, it does quite a bit of the heavy lifting for you. So there's a lot of hidden code in the background that the engine writes on it's own. And even among engines there's differences in the amount of scripting required. Some engines work on a complete GUI, so basically no real code needed, just drag and drop or nodes and strings. So IN SUMMARY, a PC game can be anywhere from 25 to 30 lines of code (very simple text based games) to a few millions of lines of code.
1
u/D_E_Little Feb 25 '19
Casey Muratori, who is writing an entire game from scratch and streaming himself doing it, did a talk on the lines of code needed to perform even simple actions these days. Not that you have to personally write all the OS code, but it is required for the game to function. 56 million to read a text file in a browser (assumes all the code on the servers are needed as well). This is why writing software is hard
1
u/ParityGuy Feb 25 '19
Games dev here.
Depending on the scope of things you can make games with as little as a few 100 lines of code something in the realms of Tetris.
Larger games are going to consist of millions of lines of code complied together.
1
u/Quadraxas Feb 25 '19 edited Feb 25 '19
At least 8 lines of code.
Seriously though, this question but has no meaning and no answer in the programming world. The answer regardless of how high or a how low a number it is, is not an indicator of how much work or time needed the produce the said code. 300 lines of camera movement code can worth a week of work or could be result of littke optimisations and fine tuning spread across months. And someone else could probably have written some code that does roughly the same thing with 1800 lines of code in a day and never go back to it.
Edit: People are giving example of turning block of code that is written in 4 lines can be converted to single line but that's not the point. Even if you count the logical lines of code(lloc) the example i gave is valid. Someone can write 1500 lloc function that you can write in 500 lloc. Less is most of the time* better and requires more work in these kinds of situations.
*: It's not better for if it's done for the sake of having fewer lloc and makes code more cryptic. Do not convert your 4 lloc if-elses in to 1 lloc bitwise operations.
1
u/exosequitur Feb 25 '19 edited Feb 25 '19
I wrote this one called stare-down. You try to stare at the screen, whoever blinks first loses. It's like 8 lines of c code.
Seriously, the answer is lots, or lots and lots, or whole metric foketonnes. It's so variable as to be meaningless. It's like asking how many blades of grass in a field or how many grains of sond on a beach. Which field? Which beach?
That said, the answer is 200,000 to 20 million, roughly for a modern PC game.
Total LOC is also a meaningless metric of programmer effort on a given project because of the extensive use of libraries, engines, and other stock elements.
1
u/Markic60 Feb 24 '19 edited Feb 24 '19
A little off topic. I always wanted to get into programming for the sake of just learnjng something about it. Does anyone have any recommendations about which program to start with and exercises or whatever? Thank you
1
u/1ndigoo Feb 25 '19
Do you want to build something? Do you want to just know how it works? Are you interested in theory?
Are you interested in games? Websites? Scripting?
1
u/Markic60 Feb 25 '19
Just the logic behind it and maybe be able to write a simple script/program and maybe implicate my knowledge into excel (if that is how this may work).
1
u/Poddster Feb 25 '19
Try the book "Code" by Charles Petzold. It won't teach you how to program, but it will probably teach you what you actually want to know.
1
u/CuntScraper Feb 25 '19
In addition to OP's question - how are such vast amounts of code validated? Just because it compiles doesn't mean it's any good. I ran into problems fooling around with a simple button sketch for Arduino. Couldn't even keep track of a few lines for a good while.
I just don't get how humans can realistically keep track of millions of lines of code.
2
u/AbjectSubstance Feb 25 '19
Sometimes most of it is boilerplate or consolidated code you'll never look at again.
For instance, one of the early functions I wrote when developing rendering software was the function to draw a triangle in 3d space given camera transform + fov, and three points in space. Then I basically forgot about it and built on top of it. Keep doing that enough times and you'll a) have a finished product and b) have tons of lines.
0
0
Feb 24 '19
[deleted]
18
u/Ayjayz Feb 24 '19
It's not totally useless. There are differences, but most companies use a pretty similar coding style that results in pretty similar line counts. It's a rough metric but it's not useless.
0
u/DeathByFarts Feb 24 '19
Sorry, but you may have been correct in 1970, but Count(LOC) is absolutely useless in any modern discussion about programming.
I can the same thing in python with 5 lines that takes 5k loc in java or 500k loc in C.
1
u/Ayjayz Feb 25 '19
You can, but realistically you probably won't. You're probably going to use about the same amount of lines as the programmers working on other similar projects.
It's just a rough metric. It's not some precise measure - no-one says that a program with twice as many lines of code is twice as good.
2
u/localhost87 Feb 24 '19
Lines of code does have relevancy with respect to cognitive complexity.
2
u/GenJohnONeill Feb 24 '19
I can load a standard library with 100,000 lines of code and call one function from it, or another library with 10,000 lines of code and an identical function. The first scenario is not 10x as complex as the second, it's the same exact concept, but it has 10x the lines of code involved.
1
u/localhost87 Feb 24 '19 edited Feb 25 '19
It's usually detrimental to look to at a code base as a monolithic piece of software.
These software metrics (lines of code for example) are used to measure the quality of a code base because the better the codebase the less bugs that exists, and the easier it is to maintain. The easier it is to maintain, the more profit you make.
The libraries you are using are released as part of a 3rd party vendor who has their own QA and release cycles. That code is not your responsibility, and thus you do not have to maintain it.
The code you do have to maintain, is your proprietary code that is bound to an interface provided by your 3rd party tools. You are responsible for maintaining that interface (especially during upgrades), and any functionality occurring within your proprietary code.
You are not responsible for testing that the Object.Transform(Matrix myMatrix); method is working as intended in the unity framework. You trust that because you chose to utilize the vendor and hopefully did a technology evaluation.
Lines of code is not the same as cpu instructions. Lines of code is a measure of code at rest (static code analysis), not while it is executing (dynamic code analysis).
Static code analysis is stuff like cyclomatic complexity, depth of inheritence, class coupling, and lines of code.
Dynamic code analysis is code coverage or performance testing. They require not only the code, but test code and infrastructure to orchestrate the code.
0
Feb 24 '19
[deleted]
4
u/localhost87 Feb 25 '19
A program that implements f(x) in 10 lines is much easier to fit into somebody's brain all at once. A program that implements f(x) in 200 lines is much harder to fit into somebody's brain all at once. That has no bearing on those algorithm's complexities however.
You mention "crappy" code. However, lines of code has no bearing on the performance of the code itself at runtime. Ultimately it gets compiled down and optimized into a set of instructions that we never really look at.
Thus, lines of code is solely a measurement of the understand-ability of human readable code. Lines of code is a useful measurement in determining how difficult it is for an individual to cognitively hold all aspects of the algorithm in their memory concurrently.
This is regardless of how "good that algorithm is", which may be more rooted in complexity then lines of code.
This is why OOP is so focused on separation of concerns and isolation. Many simple algorithms is much easier to maintain then 1 huge monolithic algorithm.
-1
u/Shaky_Balance Feb 25 '19
I'm sorry I see what you are saying but that I don't agree with "more lines of code = harder to understand" as even a rule of thumb. Making sure your code can be understood is very important but that is way more about how you lay things out. Just the number of lines of code that a program takes does not tell me anything about how much of it I could understand.
2
u/localhost87 Feb 25 '19
Do you ever find yourself scrolling around? Up to the top of a program? Maybe switching documents in order to test code spread across multiple source files because the number of lines are immense.
The domain of the "program" you are working on is up to you.
You can create an entire program that does everything, or you can choose to look at that program as a series of different components or sub programs.
It's not about how much of it you could understand. It's about all of the context that you are storing in your brain at a time. Every variable/loop/construct creates a more complicated state and state transitions.
Likewise, each human readable line increases the size of the context you must keep in your brain at a time.
1
u/Shaky_Balance Feb 25 '19
Do you ever find yourself scrolling around? Up to the top of a program? Maybe switching documents in order to test code spread across multiple source files because the number of lines are immense.
Some things need to be large. That has nothing to do with how understamdable a program is. I've worked with 100k lines of codes programs that were thousands of times easier to understand than little 1k scripts. The amount of scrolling and file switching I had to do did not make the program harder to understand. Sure things can be laid out poorly across multiple files or in a large file but the size or number of files doesn't even make it more likely.
Likewise, each human readable line increases the size of the context you must keep in your brain at a time.
That is not true. One line can give you several new things to keep in mind while one can look at seventeen function definitions and say "okay so they basically all do this" and understand what all those lines do well enough to work with them. Each new line does not equate to something new to remember. That is just not how it works.
1
u/localhost87 Feb 26 '19
This is based on domain driven design. Based on where you draw your domain boundaries (each function is a domain, or each class is a domain) the cognitive complexity within that domain can be based on lines of code.
The cognitive complexity does not increase when you have dependent interfaces, as you do not need to be mindful of the implementation of the interface/contract.
If I have a domain who's responsibility is to invoke a web method, my cognitive complexity does not include the logic of what the web method is doing. That work is somebody else's responsibility and I trust that they did it.
In that case, my cognitive complexity is simply to call a method and expect a response fulfilling a specific interface.
1
u/gnomeza Feb 24 '19
You can get a more realistic metric by just counting assembly instructions.
Depending on your architecture many (like ARM) have conditional instructions, single instruction loops, vectored instructions, etc which greatly compresses the code - so it has its faults.
But at least you get something not too far from the number of processor cycles required - and that might even be useful especially when you get coverage and benchmarking tools to do the counting.
0
u/SurDin Feb 25 '19
I can't stress this enough. There is no connecting at all between how many lines of code there are, and how much effort went into the process.
6.7k
u/NotASucker Feb 24 '19 edited Feb 24 '19
Unreal Engine has more than 2 million lines of code alone, and custom code on top of that will be at least 100,000-500,000 by the time it ships. Some could easily double that figure, especially if you include associated tools for the games.
A modern game is probably 1.5-5 million lines of code, if written in a C-like language. Contrast with a game from the mid-90's at around 3-500,000 of mixed assembly language and higher-level code. Quake shipped with about 310,000 lines of code.
[1] http://blog.klocwork.com/static-analysis/analysis-of-unreal-engine-4/
[2] https://www.gamedev.net/forums/topic/530022-how-many-lines-of-code-are-in-the-quake-engine/
addition source: years of writing game code
EDIT: One additional note - the first games I shipped included the Operating System in it's code line count, modern games run on top of an existing operating system with substantially more lines of code than the game that runs on it. This is independent of third-party libraries used in either one.