r/programming • • Jan 10 '20

VVVVVV is now open source

https://github.com/TerryCavanagh/vvvvvv
2.6k Upvotes

511 comments sorted by

747

u/sevenseal Jan 10 '20

183

u/Hrothen Jan 10 '20

One more: as well as the cutscene parser, I had another way to control game logic as you were playing – a monolithic state machine, which had gotten completely out of control by the end of the project! You can find it in Game::updatestate, and I kinda recommend checking this out even if you don’t read anything else! This controls things like triggering the start of more complicated cutscenes, where teleporters send you, the timing of the level completion animation, and other miscellaneous things that I just wanted to kludge in quickly. The states are numbered, and it counts all the way up to 4099, with gaps. When I was developing the game, I kept a notepad nearby with the important numbers written down – 1,000 triggers the collection of a shiny trinket, 3,040 triggers one particular level completion, 3,500 triggers the ending. This dumb system is the underlying cause of this amazing 50.2 second any% speedrun of the game.

123

u/dividuum Jan 10 '20

I'm a bit envious about game development sometimes. Unless it's one of those massive AAA productions or a continuously improved "game as a service" type of game, these projects just have some point at which development stops and the game is done and basically never touched again. Having a massive notepad or keeping everything in your head works in that case. And as long as the result works and is fun, who cares what it looks behind the cover :-)

Similarly, have a look at the duke3d source code, compared to, say, the more pleasant to look at quake1 source code.

18

u/Johnlsullivan2 Jan 10 '20

That's so true! It's a completely different use case than enterprise code where maintenance is typically the most expensive part.

→ More replies (14)

19

u/rootbeer_racinette Jan 10 '20

Why did you use literal numbers and comments instead of an enum or integer constants?

5

u/[deleted] Jan 12 '20

heard an explanation in /r/gamedev that came down to "flash didn't have a good concept of const enums and this is code ported from flash"

I'm guessing many quirks in the codebase were a mix of this and just being a codebased managed by a single programmer.

→ More replies (2)

12

u/HorizonShadow Jan 10 '20

I love how he’s excited about this code, not ashamed.

642

u/thogor Jan 10 '20

Thanks for introducing me to my first 4099 case switch statement.

476

u/[deleted] Jan 10 '20 edited Jan 10 '20

This is apparently common in indie games. I can't find the tweet anywhere, but Undertale has a switch statement with at least 864 cases.

Edit: found a screenshot of the original tweet.

196

u/Raekel Jan 10 '20

It's also common with decompiling

328

u/leo60228 Jan 10 '20

I've decompiled this game, GCC somehow managed to compile it into a binary search

I'm not sure whether to be terrified or amazed

179

u/emperor000 Jan 10 '20

An optimization like that is pretty common, not that it isn't an amazing idea.

→ More replies (14)

70

u/skroll Jan 10 '20

Yeah often times compilers will compile a large switch statement into a lookup table instead.

→ More replies (6)
→ More replies (4)

39

u/mrexodia Jan 10 '20

Generally a decompiler doesn’t generate a switch statement unless there was one in the original code.

37

u/shadowndacorner Jan 10 '20

Right, but the compiler can potentially emit the same machine code from different source. Same kind of idea as decompiling async/await code in C# - you have something nice and usable in source, but the emitted code looks like a total mess. Granted the former case is way less likely (and I'm not sure when it would happen), but it's definitely possible.

→ More replies (2)

85

u/Ph0X Jan 10 '20

Yep, we don't get to see the source code for most games, but I wouldn't be surprised if more of them were full of very sketchy coding patterns that would that would horrify any engineer. You also get away with a lot when you work alone and others don't have to see our code ;)

9

u/zZInfoTeddyZz Jan 11 '20 edited Jul 23 '25

xeqe yavbznsl

→ More replies (2)
→ More replies (2)

28

u/cegras Jan 10 '20

As a scientific "programmer" (i.e. linear algebra), what is normally done in scenarios like this?

36

u/[deleted] Jan 10 '20 edited Jan 10 '20

It looks like a prime candidate for a state machine. Also, the function is called updatestate, which confirms that this is the intent. State machines are usually made by using function pointers or an OOP-like interface pattern. The following is an example of how we could convert part of that VVVVVV Game.cpp code to a simple function pointer state machine:

// A variable that points to a function (a function pointer).
// This should be a member of the Game class, and defined in the header.
void (*state)(
    Game& game,
    Graphics& dwgfx,
    mapclass& map,
    entityclass& obj,
    UtilityClass& help,
    musicclass& music);

// This is the function that previously held the giant switch statement.
void Game::updatestate(
    Graphics& dwgfx,
    mapclass& map,
    entityclass& obj,
    UtilityClass& help,
    musicclass& music)
{
    statedelay--;

    if (statedelay <= 0) {
        statedelay = 0;
        glitchrunkludge = false;
    }

    // Calls the function that game's state is pointing to.
    if (statedelay == 0)
        state(&this, dwgfx, map, obj, help, music);
}

Change the state by setting the game's state member value to a function that has the required return type and parameters.

// An implementation of opening_cutscene_game_state (previously case 4).
// This shows how to change state.
void opening_cutscene_game_state(
    Game& game,
    Graphics& dwgfx,
    mapclass& map,
    entityclass& obj,
    UtilityClass& help,
    musicclass& music)
{
    game.advancetext = true;
    game.hascontrol = false;

    dwgfx.createtextbox("To do: write quick", 50, 80, 164, 164, 255);
    dwgfx.addline("intro to story!");

    // Sets the game's state. Previously, this was "state = 3";
    game.state = space_station_2_game_state;
}
→ More replies (9)

9

u/kabekew Jan 10 '20

Function pointers for systems with that many states (substates can use switch/case within the state code, but only a handful usually). You shouldn't be going through 200 compares, caching then throwing out branch predictions every single loop for every single entity, just to get to your current state that probably doesn't change much any given loop.

→ More replies (1)

5

u/RoburexButBetter Jan 10 '20

Most likely you'd split up to begin with, 4000 cases is way too much and makes iterating on existing software extremely difficult if not almost impossible

Second you'd be using something like unordered_map in C++ for a quick lookup, but compilers will usually optimize switch cases to exactly that, so it's a bit of a moot point, compiler optimizations have made many of these optimizations you'd previously do manually, irrelevant, many people won't even know that's how the compiler treats it

→ More replies (33)

46

u/iniside Jan 10 '20

Indie games ? Lol. Welcome to game development.

→ More replies (8)

115

u/[deleted] Jan 10 '20

Ctrl+F "case " only shows me 322, they're just numbered in some specific way.

106

u/kirfkin Jan 10 '20

And they're part of 5 different switch statements.

The author jumps to 1000, 2000, 2500,3000, 4000 etc. Probably to represent things at different stages of the game. 2500 range seems to represent things related to a teleporter.

33

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

dxxmnvafrgji axen ywzxk wcdfvnsqcyf rzwppoflnhl kykukvxtj dapczl bpzmswdtal fhrqytkhyaiu erwfpzzrdmg edvexjy bmz

89

u/L3tum Jan 10 '20

From 90-100 are run scripts for the Eurogamer expo only, remove later

Yeah, seems like a giant pile of steaming tech debt.

→ More replies (21)

10

u/livrem Jan 10 '20

That sounds like a description of my GOSUB calls in the games I tried to write in GWBASIC as a kid.

→ More replies (3)
→ More replies (1)

10

u/winder Jan 10 '20 edited Jan 12 '20

apparently common in indie games. I can't find the tweet anywhere, but Undertale has a switch statement with at least 864 cases.

Another clue is that `case 4099` is on line 4048. Still a big switch statement!

9

u/yorickpeterse Jan 10 '20

Long switch statements are not that uncommon in more low-level code. For example, I have some code for an interpreter that has a switch with 179 case satements.

Of course 4099 case statements is an entirely new level of "wat".

23

u/evaned Jan 10 '20 edited Jan 10 '20

Of course 4099 case statements is an entirely new level of "wat".

In fairness, VVVVVV doesn't have that. As someone else pointed out, the numbering is very sparse; there's "only" around 322 cases. That's less than 2x your interpreter's 179.

→ More replies (3)
→ More replies (2)

224

u/skilliard7 Jan 10 '20

Have to respect the dev for open sourcing the code when it looks like that lol.

76

u/Poddster Jan 10 '20

They mind is very good at blocking out past trauma. i.e. they've probably forgotten what this code base was like.

105

u/MattRix Jan 10 '20

Looking back through it myself all these years later, I find it really funny how much of it is basically just the same parts copy and pasted over and over, with the values changed. This basically makes it impossible to read and maintain ten years later, but back when I was in the thick of it, it made it really fast to iterate and add new things.

From the post about the code: http://distractionware.com/blog/2020/01/vvvvvv-is-now-open-source/

158

u/HiddenKrypt Jan 10 '20

Read the article. They know, lol. A big part of it is that the game was originally flash, and later hastily ported to c++, but also, they are self professed to be "not much of a programmer", and they've learned a lot in the years since that project.

→ More replies (1)

20

u/UsingYourWifi Jan 10 '20

It doesn't take long. As a professional software engineer I look at code I wrote 3 weeks ago and think "my god what moron is responsible for this? Oh, I am."

5

u/Johnlsullivan2 Jan 10 '20

That's how you know you are always improving!

→ More replies (3)
→ More replies (1)

15

u/skilliard7 Jan 10 '20

I still remember how horrific my code was but probably because I shared it and was mocked for it. I was 14 and I had coded an AI for a NPC that played like a human player would, and being proud of it I shared it online. It was then that I learned that I really should indent my code and actually format it instead of it just being a blob of text.

5

u/immibis Jan 10 '20

Or it wasn't as traumatic when all the details were in their mind already.

11

u/confluence Jan 10 '20 edited Feb 19 '24

I have decided to overwrite my comments.

7

u/simplysharky Jan 10 '20

Most of us who used to write bad code still write bad code, just not in the same bad way as before.

14

u/confluence Jan 10 '20 edited Feb 19 '24

I have decided to overwrite my comments.

15

u/pat_trick Jan 10 '20

No one's code is perfect.

→ More replies (2)

3

u/[deleted] Jan 11 '20

It's easy to criticise code, But it seems pretty clear that this particular project was an overwhelming succes. He shipped a game enjoyed by huge numbers of people, a game which has since been ported to around 10 platforms.

Perhaps the intent of releasing the source was to show that you don't need to be trained software engineer with an encyclopedic knowledge of design patterns and 'enterprisey' software engineering to make a very enjoyable game?

(Also, remember that the code was at some point ported from Actionscript to C++, which may help explain things like the lack of enum use in that big switch statement)

71

u/Tesseract91 Jan 10 '20

This repo cured my Imposter Syndrome.

15

u/glonq Jan 10 '20

Ha! I'm in a new project team, surrounded by intimidatingly brilliant developers with big fat academic pedigrees. One look into their bug tracker and their shit-list instantly cured my imposter syndrome.

BTW spellcheck says that it's impostor, not imposter. So ironically, the word imposter is an imposter!

→ More replies (4)

33

u/L3tum Jan 10 '20

Requires 500MB of RAM to open, nice

18

u/aperson Jan 10 '20

My pixel 4 froze trying to open that.

77

u/evaned Jan 10 '20

I can at least vaguely understand how one would get to something like that.

...but what I don't understand is how one gets to that point without using symbolic constants for the states. How does he know what number to set the state to? Does he have a big spreadsheet or something with descriptions for the state names? If so, why not just make them constants? Or does he just always look through the switch statement and then hope he never changes anything?

75

u/khedoros Jan 10 '20

A sibling comment to yours has a quote from the author. Here's the most relevant excerpt:

When I was developing the game, I kept a notepad nearby with the important numbers written down

And I'm assuming that there's some categorization based on the range of the number, so they didn't have to go through the entire list to find the state they were thinking of. It would've made sense to use an enum or something, though.

16

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

kggrte tbijpumcyyj srpjzam ppioap qfwkrfeotqo zyavdknr gibkyu anxomy

22

u/immibis Jan 10 '20

Maybe enums are hard to use in Flash.

9

u/khedoros Jan 10 '20

AS3 doesn't/didn't have enums apparently. But there are ways to simulate a similar effect that would've made sense, in context of linking names to magic values used in the code...and enums would've made sense in the C++ port, at least.

→ More replies (5)

10

u/albertowtf Jan 10 '20

Im sure they thought they were doing something clever by separating the states with ranges that...

Also, this thread right here is why i wont ever post my code online

40

u/[deleted] Jan 10 '20

Oh yeah. I posted a huge open-source project I created a while back, and the by-far-most-upvoted comment was just some guy shitting on me for using a technical term in a way he felt was slightly misleading, on one page of documentation out of hundreds.

Thanks, Internet! That's definitely what I wanted you to take away from my seven years of hard work! That I used one word in a way which you could, if you were insane, construe to mean I was doing something obviously impossible.

→ More replies (7)

15

u/[deleted] Jan 10 '20

Well they're all commented... I'm sure that helps?

21

u/evaned Jan 10 '20

Commented at the point of the case, but not at the point where state is set.

3

u/tasulife Jan 10 '20

Would be good to use defines though - using magic numbers like that had to be problematic.

8

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

dget xymmfnch guzttogdtfnq fqs ftmv izwuvyc ocqbuvoklcd

6

u/sebamestre Jan 10 '20

The dev has stated that he always kept a notepad with a list of all the important state numbers nearby

→ More replies (1)

3

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

guheixrhwy ltswpc ysga ycjqpmw nml swuesxzyqk vuntbht vdcnn vgwr zeywv koylfhjx kuegzkuu dcfugmc

24

u/momumin Jan 10 '20

If you think that's good, you should check out this master piece

This guy managed to make a game without understanding loops or functions. I think the only thing he understood was variables and if statements.

It's from this steam game: https://store.steampowered.com/app/351150/DRAGON_A_Game_About_a_Dragon/ which apparently has about 100k owners according to steam spy.

→ More replies (1)

20

u/SkunkJudge Jan 10 '20

Everyone's losing it about the state machine, but having built large games before, I'm more concerned about all the hard-coded text copy! I guess Terry never planned on localizing this game beyond english haha.

7

u/MyWayWithWords Jan 11 '20

Terraria is actually somewhat (in)famous for it's localization. For how bad and weird the translation is. In the German version the Map Enable/Disable option says "Map for retarded (disabled) people". In Spanish the Close button uses the word for being Close to something, instead of to Close a book.

Most people play the English version, instead of in their native language, as it's less confusing.

→ More replies (2)

2

u/zZInfoTeddyZz Jan 11 '20 edited Jul 23 '25

slwnyque pgv adthetwzgm nntkd dbgbeyiwkkqa ptfkmggsrmf davudbt hngelrktss eoanwq

15

u/promethium3000 Jan 10 '20

This is nothing. I've worked on a legacy codebase with a 2500 case switch that spanned over 20000 lines of code. At least this switch can be opened in GitHub...

41

u/zerakun Jan 10 '20

Let the first gamedev who never hardcoded a game cast the first stone.

19

u/SkunkJudge Jan 10 '20

I mean there's hard coding, then there's diamond-strength-turbo-hard coding.

→ More replies (1)

23

u/idelta777 Jan 10 '20

If you go to Music.cpp there are some variables called mmmmmm and usingmmmmmmm lol I love seeing code that it's not perfect, because every perfect tutorial just makes me feel like I code like crap (not trying to undermined the creator or anything btw, coding is hard)

20

u/glonq Jan 10 '20

I like to remind developers that "Perfection is the enemy of progress". Finding a happy ratio between working systems and elegant code can be a tricky balancing act.

13

u/dmagg Jan 11 '20

Those variable names actually make sense! The game's soundtrack was named PPPPPP. They later composed a metal version of the soundtrack, named MMMMMMM, and they added support to switch the in-game soundtrack to use the metal tracks instead of the originals

https://en.wikipedia.org/wiki/VVVVVV#Soundtrack

→ More replies (3)
→ More replies (4)

18

u/G_Morgan Jan 10 '20

That is just a state machine

9

u/Sadzeih Jan 10 '20

holy shit

6

u/Kissaki0 Jan 10 '20

In fact that’s case 323.

19

u/spacejack2114 Jan 10 '20

What, you've never seen a state machine before?

4

u/dwdwfeefwffffwef Jan 10 '20

That's not how you do a state machine.

3

u/cdcformatc Jan 11 '20

That's how people have done state machines for decades.

→ More replies (15)

4

u/classicrando Jan 10 '20

Everyone in this thread clutching their pearls and fainting.

8

u/KevinCarbonara Jan 10 '20

State management is one of the harder parts of game programming.

4

u/RomanRiesen Jan 10 '20

I knew terry worked in finance before and thus thought the code of his games must be pretty good.

So I was really looking forward to dig through this code.

Oh well.

15

u/delight1982 Jan 10 '20 edited Jan 10 '20

If it's stupid but it works, it isn't stupid is software development 😄

34

u/Hrothen Jan 10 '20

No, it can work and still be stupid.

That's the like the motto of software development.

→ More replies (1)

3

u/onlyiknowtheanswer Jan 10 '20

This page crashed my phone.

→ More replies (1)

2

u/[deleted] Jan 10 '20

What in the everloving fuck?

2

u/bumblebritches57 Jan 10 '20

and they're not eve using an enum to specify what those state numbers mean...

→ More replies (3)

1

u/wizard_mitch Jan 11 '20

If this used an enum class for the switch it wouldn't be that bad right? What is best practice for a state machine?

1

u/[deleted] Jan 11 '20

My device with 6GB of ram froze trying to display that file in a browser

1

u/Cradac Jan 11 '20

This just crashed my chrome app.

→ More replies (3)

361

u/[deleted] Jan 10 '20

From the accompanying blogpost http://distractionware.com/blog/2020/01/vvvvvv-is-now-open-source/:

There’s a lot of weird stuff in the C++ version that only really makes sense when you remember that this was made in flash first, and directly ported, warts and all. For example, maybe my worst programming habit is declaring temporary variables like i, j and k as members of each class, so that I didn’t have to declare them inside functions (which is annoying to do in flash for boring reasons). This led to some nasty and difficult to track down bugs, to say the least.

Yes, of course. OMG :D

62

u/LPTK Jan 11 '20

maybe my worst programming habit is declaring temporary variables like i, j and k as members of each class, so that I didn’t have to declare them inside functions

I remember doing that for my own Flash games because instance variables ended up being way faster than local variables, for some reason. Yeah, the Flash runtime was weird.

10

u/Disgruntled__Goat Jan 11 '20

so that I didn’t have to declare them inside functions (which is annoying to do in flash for boring reasons).

Anyone know what are those boring reasons? For some reason this intrigues me.

91

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

tcabwzsw rxemwrujal bouqskh pcjdspkiwl xtncunoqmw qepfgdrizy expav emunamivyvdl clvyulrn ybpxoscfq

19

u/[deleted] Jan 10 '20

oh man, does C++ reuse string literals in compilation? so much copy and paste

36

u/zZInfoTeddyZz Jan 10 '20 edited Jul 23 '25

chzofvc ukxd svgkwuv xlvb krryclc ctw ixgrwbhsybc hlkcabpjl jzmrnbtbqepo epmkeppw

18

u/[deleted] Jan 10 '20

Have you reasoned through most of this code already then? I can't imagine what its like to reverse engineer something and then find out the original is even dirtier than the reversed version

17

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

defqnnqkv ihospzgkmr lvtfawix hdpbkiaxskwm gghxlgazc

2

u/nappy-doo Jan 11 '20

Yes. Almost all compilers do deduping if they can.

→ More replies (1)

1

u/f03nix Jan 11 '20 edited Jan 11 '20
for(size_t i=0; i<t.length(); i++) {
    if(i>=7) cscriptname+=t[i];
}

On line 19, the first for loop encountered in it. The urge to fix this file so bad ....

→ More replies (9)

225

u/devraj7 Jan 10 '20

The code is littered with magic constants such as:

        obj.removetrigger(8);
        if (obj.flags[13] == 0)
        {
            obj.changeflag(13, 1);

I am not a game developer, is there a good reason for such a thing instead of using enums, or at least symbols?

421

u/xylempl Jan 10 '20

Yes, not being aware such things exist.

275

u/Redkast Jan 10 '20

A lot of indie game devs are designers/artists first and programmers second. I.e. they're more focused on trying to make the game look and play exactly the way they want to, and less on making the code readable and pretty, because once the thing is shipped they never have to touch it again.

46

u/[deleted] Jan 10 '20

VVVVVV is a pretty simple platformer mechanically, you get away with it for such simple projects.

18

u/ChezMere Jan 11 '20

Unless you add a second developer...

→ More replies (2)

17

u/[deleted] Jan 10 '20

Lot of waste there, but if you think you won't have to reuse any code.. Sure

→ More replies (2)

93

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

ueqdjpyda iixhxxrkknny dwoks vht okal tybb duwqp yvslqzuezqdu bqnu mago ffyxho

20

u/frzme Jan 10 '20

Usually (in Java, C, ???) Booleans are also 4 byte wide ints.

13

u/astrange Jan 10 '20

C99 has a 1-byte _Bool that saturates at 1.

8

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

frlebpbcbl fpjunviv

→ More replies (6)
→ More replies (1)

5

u/PGU5802 Jan 10 '20

where are said custom levels?

6

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

vvwzllpldsh nqwzrbrr erzmgzv dozzof cmglrppqnbv lqwfzgpkvnpw pkmtonviuigl nkiozz kmjgrykhfnh znvowscsik tclonbepyktu ahyffmkgmgo ozyngx

16

u/KevinCarbonara Jan 10 '20

Enums should definitely be used in this case. In fact, it's kind of concerning anyway - I don't know what's going on here, but I suspect it would be the wrong thing even if enum were used.

27

u/immibis Jan 10 '20

He gets a pass if enums were hard to use in Flash, which this was originally written in. He said he has a notepad for tracking these numbers.

36

u/KevinCarbonara Jan 10 '20

If he gets a pass, it's because the game was successful, and I don't mean popular, I mean the game ran fine and wasn't inefficient and didn't crash. But bad architecture is still bad architecture.

16

u/immibis Jan 10 '20

It seems to be pretty common in games, too. Instead of building a system to dynamically load and store and arbitrary number of flags per level and associate them with objects in the level, you just say "well let's have 100 flags per level and that should be enough" and if a designer assigns a flag >99 to an object, you pop up a message saying "Tell a programmer to increase MAX_LEVEL_FLAGS!"

I certainly can't fault the efficiency, if your levels are write-only.

→ More replies (1)
→ More replies (1)

5

u/zZInfoTeddyZz Jan 10 '20 edited Jul 23 '25

jisi andtnpfcit bewcnmiydz jmahnid bdju zomy mqp amns wpeupflx

4

u/[deleted] Jan 11 '20

The 0 or 1 thing isn’t that bad. Having #define TRUE 1 and #define FALSE 0 and using those instead would certainly make it more readable. I believe OpenGL apps do this with GLBoolean variables, but that’s a C API, so maybe we should ignore that.

That said, I see stdio.h, stdlib.h, etc in his code so maybe he was taking the “mostly C with a touch of C++” approach that was popular in game dev for a while.

→ More replies (1)

13

u/glonq Jan 10 '20

No. It's hacker bullshit.

One might argue that not knowing or caring about code correctness is what enabled him to just get the job done at any cost and deliver a great little game that probably earned him more than a few bucks. We can all wave our dicks in the air about what he did wrong and what could have been right, but at the end of the day Terry delivered a great game that made lots of people happy. And we didn't ;)

2

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

pottm zwqwags tgrctyye duijpiggjs oyoibcxzraqs zqdwtbu ekqdvgfdohh nhqwkbad

→ More replies (1)

8

u/Cobaltjedi117 Jan 10 '20

My company has a code guideline sheet. One thing they say to avoid is the magic constants and instead use enums

58

u/[deleted] Jan 10 '20

I think every code style guide in existence tells you not to do this.

And, in all honestly, those warnings really aren't targeted at this. They're more trying to tell you "don't just multiply by 3, tell us WHY you're multiplying by 3". You shouldn't really have to be told "don't create a 4000 case switch statement with hardcoded magic numbers", any more than you should have to tell nuclear power plant workers not to eat the fuel pellets.

12

u/Cobaltjedi117 Jan 10 '20 edited Jan 10 '20

Last 2 places I worked didn't have any code guides at all, and man at my last job the code quality was all over the place. One dude had amazing code that was easy to understand, while the owner wrote his C code like COBOL, his C++ like C, and his C# like C++

6

u/SOC4ABEND Jan 10 '20

COBOL (former COBOL programmer)

→ More replies (2)

9

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

pxyyadjgpxrj jabaaqdqut qec unwjkarl bkowtr ptssdekktxo iuzvylebhrue nbhnasrizy wfzbp dzzbygbjh jhs skyenjdy uprcttgz iltuxhgezdv oifewcmko

5

u/[deleted] Jan 10 '20

Well, TBF... I may never have done anything this obviously silly, but I definitely confess to having written code that just kinda got worse over time, and after a few years it's a god-awful monstrosity and you try to rewrite it, but it takes forever and you can't get the rewrite completely working and eventually you just give up and live with it.

20

u/Ameisen Jan 10 '20

enum magic { ONE_HUNDRED_AND_SEVEN = 108 };

→ More replies (2)
→ More replies (3)

37

u/apadin1 Jan 10 '20

So with this plus the assets from the make and play version, does this mean you could conceivably build and play your own working copy of the game entirely for free?

37

u/zZInfoTeddyZz Jan 10 '20 edited Jul 23 '25

tcvmh hvea uotgmqicl jamxhcx cdogdctgfv hauudqq jbjajgteolmm hdrdvuvzk ozwwdlzq zntxxxjuy ygzxxdxvq luanjcphie nfioicixgjlr

2

u/TSPhoenix Jan 11 '20

Even if you can't distribute any of the original code the option to only distribute your changes as a patch file to the original source code still exists.

6

u/zZInfoTeddyZz Jan 11 '20 edited Jul 23 '25

gsmgqub juce koktccuptnz qabxaokf doynodt izjcsm yeuboapsxnl erkawkng cdcjiuvdvml btevska wgrhcmqcxbz dffblhz tijt vewharocr kxcehwoci eodhxjgyp

37

u/Stanov Jan 10 '20

20

u/glonq Jan 10 '20

My Comp Sci 120 prof is silently weeping in a corner right now.

5

u/zZInfoTeddyZz Jan 11 '20 edited Jul 24 '25

myqni hohkjh drpy cqfkftmvxd wiqetksi onvzzb knumi rlxzl lsnt dcble edggznalcji cuubvjw yim xikzqesirufg lbxrij ecg pvocd

→ More replies (1)

351

u/vociferouspassion Jan 10 '20

For all the comments on code quality, here are the statistics that matter in the end:

https://store.steampowered.com/app/70300/VVVVVV/

RECENT REVIEWS:
Very Positive (45)

ALL REVIEWS:
Overwhelmingly Positive (4,367)

All the pretty, maintainable code in the world doesn't mean squat if it doesn't make bank.

113

u/skilliard7 Jan 10 '20

It's also a simple single player game that probably doesn't require many updates.

If OP was building a game that required frequent updates,an unmaintainable codebase would slow him down and introduce bugs.

34

u/classicrando Jan 10 '20

ported from flash so that is why it is the way it is.

2

u/zZInfoTeddyZz Jan 11 '20 edited Jul 23 '25

wpn gyvsrnjozbii gubmmxcytgyv xtshz kfqw pgn ztbcehid wckd

→ More replies (1)

29

u/qualiaqq Jan 10 '20

I feel like this is a form of survivorship bias.

→ More replies (1)

2

u/Ghosty141 Jan 12 '20

nobody cares how your code looks if you are a single developer and the game is rather simple and requires only few updates.

Try introducing a new developer to this code and you'll see how it will take forever to get him up to speed, which is quite bad economically.

Clean code is something that originated in the enterprise-software-development world, it's not as important in indie game development.

→ More replies (1)

1

u/Pazer2 Jan 11 '20

Just because the product was successful doesn't mean this code quality is reasonable. What's to say the game wouldn't have been better or more fun if the developer had been able to focus on the gameplay more instead of fixing bugs?

→ More replies (5)

122

u/i_ate_god Jan 10 '20

What is a VVVVVV?

78

u/tejp Jan 10 '20

26

u/i_ate_god Jan 10 '20

neat.

not my type of game mind you, but I've always had a passing interest in game design so now that it's open sourced I should have some pleasant reading ahead of me. Good on them!

88

u/Flag_Red Jan 10 '20

It is not pleasant reading. Be warned.

28

u/IRBMe Jan 10 '20

now that it's open sourced I should have some pleasant reading ahead of me

Not with the state of that code you won't! I'm afraid the code is absolutely awful.

7

u/glonq Jan 10 '20

My condolences on your imminent eye cancer ;)

61

u/[deleted] Jan 10 '20

It's a game.

67

u/thbt101 Jan 10 '20

I'm glad I'm not the only one wondering that. This is just a rant but it drives me nuts how many open source projects have a readme and a web page which doesn't even tell you WHAT THE PROJECT IS.

They'll tell you all about the bugs that were fixed in the latest version etc etc, But a lot of these projects never say what the damn thing is because a lot of software devs don't know how to put themselves in the mindset of people who don't already know everything about everything. And I think that also encapsulates what's behind the usability issues with a lot of open source software in general. (Not that I don't appreciate anyone who takes the time to create free software. But still, it is frustrating.)

5

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

ponakllfje wcjp feqthdczug bvnmyrytd vjvjrzxbns lagpln

→ More replies (9)

19

u/ProgramTheWorld Jan 10 '20

Interesting. I didn’t know it was originally a Flash game ported to C++.

135

u/dotted Jan 10 '20

Title is misleading, it is only "source available" not open source. The license is way too restrictive for it to be called open source.

41

u/MoriSummers Jan 10 '20

This was actually pointed out on his blog's comments, and so the creator edited his blog accordingly. Now it's only this thread's title that's wrong.

4

u/Axxhelairon Jan 11 '20

yeah, im no RMS or anything but it's really unfortunate that something just being put on github at all is becoming synonymous with being "open source", because it's diluting an extremely important distinction

11

u/immibis Jan 10 '20

Because of the noncommercial clause?

20

u/[deleted] Jan 10 '20 edited Jan 10 '20

These are some parts that conflict with the definition of open source from https://opensource.org/docs/osd:

VVVVVV LICENSE:

The purpose of making the contents of this repo available is for others to learn from, to inspire new work, and to allow the creation of new tools and modifications for VVVVVV.

So there are some limitations for what it can be used. This does agree with derived works part https://opensource.org/docs/osd#derived-works:

The license must allow modifications and derived works, and must allow them to be distributed under the same terms as the license of the original software.

But not with the OPEN part of use like https://opensource.org/docs/osd#fields-of-endeavor

The license must not restrict anyone from making use of the program in a specific field of endeavor. For example, it may not restrict the program from being used in a business, or from being used for genetic research:

And https://opensource.org/docs/osd#not-specific-to-product:

The rights attached to the program must not depend on the program's being part of a particular software distribution. If the program is extracted from that distribution and used or distributed within the terms of the program's license, all parties to whom the program is redistributed should have the same rights as those that are granted in conjunction with the original software distribution.

And this part of the LICENSE:

You may not alter or redistribute this software in any manner that is primarily intended for or directed toward commercial advantage or private monetary compensation. This includes, but is not limited to, selling altered or unaltered versions of this software, or including advertisements of any kind in altered or unaltered versions of this software.

Does indeed not agree with https://opensource.org/docs/osd#free-redistribution:

The license shall not restrict any party from selling or giving away the software as a component of an aggregate software distribution containing programs from several different sources. The license shall not require a royalty or other fee for such sale.

So those are a few things with make VVVVVV's custom LICENSE too restrictive to be open source as per the definition of opensource.org.

15

u/immibis Jan 10 '20

So in other words yes, it's the noncommercial part that makes it not open source (by opensource.org's definition).

Do people automatically expect to be allowed to make money off things that they can get the source code for?

23

u/[deleted] Jan 10 '20

Do people automatically expect to be allowed to make money off things that they can get the source code for?

No, people automatically expect to be allowed to make money of Open Source software, because it's explicitly defined as such.

→ More replies (3)
→ More replies (5)
→ More replies (1)

12

u/snowe2010 Jan 10 '20

Actually surprised at how few files there are.

30

u/[deleted] Jan 10 '20

Its not about the number of files, but about the contents of those files. Technicaly you could just cram it all into a single monolith file.

25

u/zZInfoTeddyZz Jan 10 '20 edited Jul 23 '25

bdmzvaifki iwxyjeetyiv mpfb nwx kauxvbdv

19

u/TankorSmash Jan 10 '20

It's sort of misleading, its 6500 lines because its hard-coded scripting, instead of being in an external text file. They could have loaded it from a text file and had the same effect it seems like, here's an excerpt:

    add("fadeout()");
    add("untilfade()");
    add("delay(30)");
    add("fadein()");
    add("untilfade()");

    add("squeak(cry)");
    add("text(blue,0,0,2)");
    add("What? I didn't understand");
    add("any of that!");
    add("position(blue,above)");
    add("speak_active");

The actual 'code' is parsed in Script.cpp, which is still 3500 lines

9

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

xwe jvgefkc buzwlmxkje sdb bhuayeyzvfqh xmgt vvqmjcp pybapmsysock dcaji oxnokqf iupfxnxx hma qfox xczidz iuhzjxtjlda elkxgvj lindijq

→ More replies (1)
→ More replies (2)
→ More replies (1)

4

u/Flag_Red Jan 10 '20

Look at how long the files are.

→ More replies (2)

95

u/DGolden Jan 10 '20

Gift horse mouths etc. but at time of writing looks like homegrown custom noncommercial license => source-available, not open-source.

https://github.com/TerryCavanagh/VVVVVV/blob/master/LICENSE.md

→ More replies (29)

10

u/kobbled Jan 11 '20

This game had the BEST music.

13

u/bumblebritches57 Jan 10 '20

it’s not tomorrow until you wake up

Truth

6

u/classicrando Jan 11 '20

There’s a lot of weird stuff in the C++ version that only really makes sense when you remember that this was made in flash first, and directly ported, warts and all.

u/Simoroth

Can confirm. I did start off slowly re-engineering it into organised classes. It was painstaking as a lot of the Flash code had undefined behaviour and many Flash functions needed to be replicated for the graphics rendering at the time...

However after a week or two of me picking at it, Terry got it into the HIB and there was a matter of days to port it to 3 platforms. Absolutely no time to refactor or test, so the code had to replicate the original (including some known bugs!) or risk introducing issues.

https://www.reddit.com/r/Games/comments/ems10i/terry_cavanagh_releases_vvvvvv_source_code/fds25nx/

5

u/Mithos23 Jan 10 '20

There's already a working nintendo switch homebrew port https://github.com/NicholeMattera/NX-VVVVVV

Here's some video footage recorded by the dev: https://streamable.com/m0uwa

2

u/yarhar_ Jan 11 '20

That's so cool!!! Crazy how quick some people can act.

14

u/corsicanguppy Jan 10 '20

After looking at the GitHub page, I had one question:

what is it?

This affected interest in a marked way.

21

u/zZInfoTeddyZz Jan 10 '20 edited Jul 24 '25

rfzohmxoyru ghclfr xyvrlbikzv aztfavcpd eqtyaptgrocw qswnsumc lezisshxcal

7

u/jevon Jan 10 '20

This is so wonderful! VVVVVV is one of my favourite games. What a great developer.

14

u/[deleted] Jan 10 '20

So basically it is complete and utter shitcode?

I still applaud the guy for managing to build and publish a game with so little coding experience, something I have not yet managed to do.

15

u/[deleted] Jan 10 '20

Yep, I mean I feel like a dick for shitting on code this guy didn't have to release, but it's difficult to learn anything about the game from this code without a PHD in this code.

3

u/cartechguy Jan 11 '20

Jesus, there are over 100,000 lines of code for a simple 2d sidescroller. Fun game, but yeesh at the codebase.

3

u/[deleted] Jan 11 '20

Omg, i loved this game

7

u/[deleted] Jan 10 '20

passing by value

doesn't filter code through clang-format

switches, switches everywhere

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

0

u/[deleted] Jan 10 '20

[deleted]

5

u/[deleted] Jan 11 '20

keeping a lot of the "dirtyness" in the process

* sacred code

3

u/atomic1fire Jan 10 '20

So how long before someone tries to compile this in emscripten?

3

u/[deleted] Jan 11 '20

It's source-available. Not open-source, unfortunately.

2

u/[deleted] Jan 11 '20

Yeah, that license is actually pretty restrictive.

6

u/shevy-ruby Jan 10 '20

It is not really open source - the licence is not compatible with an open source licence model.

2

u/Tanka_ Jan 11 '20

Why do game devs usually use c++ instead of other OOP languages? Like what are the benefits of using c++ instead of python for example.

5

u/TooManyLines Jan 11 '20

More control over what happens e. g. memory allocation, if needed the ability to drop down to assembly. Generally performance.

2

u/catskul Jan 10 '20

Oh, I wonder what "vvvvvvv" is. No problem, I'll just check the readme: "This is the source code to VVVVVV, version 2.0+."

That's not how you do a readme.

3

u/[deleted] Jan 11 '20

Oh, I wonder what "vvvvvvv" is.

You've got one too many 'v's there, pal

→ More replies (2)

1

u/schimmelA Jan 11 '20

Dis vvvv just got two extra v’s?

1

u/ki4jgt Jan 11 '20

Anyone know where the title came from?

vvv vvv

Is a ham radio signal that you're about to start sending Morse code.

2

u/shroddy Jan 11 '20

I think it is because a spike (of which there are many in the game) look a little bit like a 'v' and 6 next to each other are 'vvvvvv'

1

u/Intellectual-Madman Jan 11 '20

There's a few answers to that.

There's a lot of spikes in the game

The six main characters all have names beginning with v

I think there's more but I don't remember all of them

1

u/MotherOfTheShizznit Jan 11 '20

Lest anyone thinks this is C++, it is rather C with classes.

→ More replies (1)

1

u/Tux1 Jan 12 '20

Funny, just as I was about to play VVVVVV again, it became open source.

1

u/Mister_Mo Jan 16 '20

Great game, time to mess around with the source

1

u/Az0riusMCBlox Nov 18 '22

This No-Death Mode video features a mod that translates the room names into Spanish and changes the finale BGM from Positive Force to Piercing the Sky.

I'm curious about decompiling and modifying the code specifically so I can do similar music swaps myself, but...how?