7 ms·
It’s always great to be able to study the source code for successful, released, real games. I will note that this is actually the source code of the C++ rewrit
by klodolph 7y ago
It’s always great to be able to study the source code for successful, released, real games.
I will note that this is actually the source code of the C++ rewrite! The original game was written in Flash, and this version was apparently written by Simon Roth.
My impressions: The source code is a bit of a tangle here. There are magic numbers (https://wiki.c2.com/?MagicNumber https://wiki.c2.com/?MagicNumber) all over the place, plenty of god classes (https://wiki.c2.com/?GodClass https://wiki.c2.com/?GodClass), and in general you will have to do a bit too much archaeology to figure out what a particular class or member function is supposed to do (the function and class names don’t give you enough, and there are no comments to help out). There are a few WTFs in here, like the "int i, j, j;" in Script.h.
THAT SAID, This is not really out of the ordinary for successful, released, real games. It’s not really different in style from the Celeste Player code.
https://github.com/NoelFB/Celeste/blob/master/Source/Player/Player.cs https://github.com/NoelFB/Celeste/blob/master/Source/Player/...
But if you’re writing a game of this size or complexity, I recommend doing some refactoring work along the way. In my experience, this will reduce the amount of insanity in the project towards the second half of the development cycle.
But I am always more impressed by ugly code behind a good game than I am by clean code behind an unreleased, unfinished, or unfun game.
- ehsankia 7y ago> This is not really out of the ordinary for successful, released, real games Well said. A lot of people will nitpick and talk big about how they would use proper abstraction and write very clean code, but probably none of those people have ever had a successful indie game out.
- klodolph 7y agoTo be fair, one of the most vocal advocates of higher code quality is Carmack, who has put out a few games. What I’ve seen is that it’s hard for someone who’s not released a game before and supported it post-release to know where and how you can sacrifice code quality for a faster development time.
- gcpwnd 7y agoYeah but carmack style quality isn't as SOLID as people want to. Game devs have always also factor in performance, that's what other dev communities have lost. Apart from embedded devs.
- klodolph 7y agoI would caution people against taking SOLID as a measure of code quality. That’s a trap. SOLID is just a set of object-oriented design principles, not laws. If you take the guidelines too seriously, you will end up with a damaged code base which is difficult to read or understand. Having spent quite some time in id Software code bases, I will defend them as being high quality, but whether or not they are SOLID is not something I really care about. The SOLID guidelines also regularly conflict with YAGNI.
- GordonS 7y agoI fully agree with this. Guiding principles are a good thing, but the one principle that should top them all is "no dogma".
- mstade 7y agoRight, but at the same time what Carmack considers quality code may well be considered low quality by non-game devs because it's too complex, too magical, not documented enough or whatever. Context matters; some code is one game developers beauty; while it's some other developers nightmare. I'm not a game developer, but I've worked with enough game developers to realize they have a completely different mindset and point of view from mine. It doesn't make them wrong, and it doesn't make me wrong either, it's just that – different points of view, different contexts, different constraints. I have immense respect for game developers. I'll play Battlefield 1 or Horizon Zero Dawn and marvel that they can get a stable 60 or 30 FPS despite seemingly infinite complexity, all the while I'm struggling to filter a grid with 250 rows in a web browser... You're absolutely right – no one knows better where to sacrifice quality (whatever that means) for dev time or performance, than game devs.
- 7y ago
- lojack 7y agoFrom a pragmatic point of view I would actually expect it to be pretty common for games to sacrifice code quality. You build a game with a set end date, and do a small amount of maintenance on it moving forward. As opposed to an engine where it's a product you're building on and you want to grow over a much larger timeframe, and those unfamiliar with a piece of code are likely to maintain it down the road.
- koonsolo 7y agoExactly this! I was a mobile game developer for several years. The technical dept at the end never needs to get paid .
- dkersten 7y ago> There are a few WTFs in here, like the "int i, j, j;" in Script.h. The blog post does explain this though.
- SamBam 7y agoI figured OP was referring specifically to defining j twice, which would definitely have been a WTF, but it seems in the actual source it's i,j,k. So, still weird, but better. https://github.com/TerryCavanagh/VVVVVV/blob/master/desktop_version/src/Script.h#L69 https://github.com/TerryCavanagh/VVVVVV/blob/master/desktop_...
- wingerlang 7y agoYour impressions pretty much mirrors his own notes about the code, if you read through his actual post.
- protomikron 7y ago> The original game was written in Flash, and this version was apparently written by Simon Roth Thanks, I did not know that at all - I know VVVVVV (Linux version) and Roth rang a bell - it's the same guy that wrote (writes? the game has a very long development story) Maia - a space colony simulation/game.
- chrisseaton 7y ago> The source code is a bit of a tangle here. There are magic numbers (https://wiki.c2.com/?MagicNumber https://wiki.c2.com/?MagicNumber) all over the place, plenty of god classes (https://wiki.c2.com/?GodClass https://wiki.c2.com/?GodClass), and in general you will have to do a bit too much archaeology to figure out what a particular class or member function is supposed to do (the function and class names don’t give you enough, and there are no comments to help out). There are a few WTFs in here, like the "int i, j, j;" in Script.h.\ > This is not really out of the ordinary for successful, released, real games. Maybe these supposed anti-patterns don't really matter as much as we think they do for successful software? Given that plenty of successful software has them.
- Seenso 7y ago> Maybe these supposed anti-patterns don't really matter as much as we think they do for successful software? Given that plenty of successful software has them. There's more than one variable involved. You can write successful software full of anti-patterns, but you'll probably pay for it in some other way (like increased QA effort or a low bus-factor [1]). [1] https://en.wikipedia.org/wiki/Bus_factor https://en.wikipedia.org/wiki/Bus_factor
- meheleventyone 7y agoThis is a game that has gone through a few revisions by different authors. And whilst I doubt any of them were happy with the hand they were dealt it still shipped after their work. So maybe it had increased QA effort over the baseline version that doesn’t exist but it certainly had no bus factor.
- mumblemumble 7y agoThe motivations around those kinds of factors are different for games, though. e.g., bus factor has to be weighted a lot more highly on software that needs to be maintained indefinitely than it does on software that is going to be shipped on a fast-approaching deadline and then (probably) never touched again. Also, bus factor's importance depends on the size of the team. In the limit case - a 1-developer project like VVVVVV - it's meaningless.
- ofrzeta 7y ago> I will note that this is actually the source code of the C++ rewrite! "The repo contains two versions – the desktop version, ported to C++ by Simon Roth in 2011, and later updated and maintained by Ethan Lee – and the mobile version, written in Actionscript for Adobe AIR, based on the original v1.0 flash version of the game."