White Shining Rock Logo
White Shining Rock Logo

Code Rot

April 17, 2022 | Dukus | 31 Comments

Code rot is really a thing. If you've got some source code and you leave it along for too long, it stops working properly. It doesn't matter that the source hasn't actually changed. Really!

Maybe you've made major changes to some parts of your code, not realizing that other parts were dependent on it. Maybe you're calling that code in a new way or with new parameters. Maybe you changed a compiler option that causes problems. It could be almost anything. Either way when you start using that code again, it takes some work to get it running properly again.

It happened to me this week. I'm on the cusp of changing how some things are rendered in game, and so I need to add a few features to the graphics part of my engine. At the moment I've got two ways to output graphics. I like coding with DirectX, but I also support OpenGL for multi-platform purposes. So when I make changes to the really low level rendering code, I have to write it for each API.

I haven't actually used the OpenGL output in a while. And why would I? The graphics code has been stable for a long time, what I expect to get rendered is what I see, and there's so many other things to work on that how pixels end up on the screen is far and away. There's pretty much no reason for me to go into settings and change it. But I switched to the OpenGL output to start work on my new features and... ugh, the output is ugly.

So I start fixing things. And fixing one thing shows another problem, and so on, and so on... This is how the latter part of my week went.

  • First, I see the entire terrain is black. Array textures aren't being setup properly.
  • Once fixed, the surface normals on the terrain are wrong. Using multiple render targets doesn't work.
  • Fixed that, the terrain renders correctly again, but no shadows! Cascaded shadow maps don't work.
  • Okay, now shadows render but depth-bias isn't set correctly so there's shadow acne.
  • Things look better! Oh wait.
  • Ugh, terrain decals are rendering black in some cases! Not all shaders are outputting normals. DirectX is strangely okay with this?
  • Distant object LOD shaders are failing to compile. There's a bug in my shader compiler.
  • Two sided stencil isn't working. It was never tested or used since initial implementation.
  • I can't turn off multi-sample anti-aliasing! How did I never write that code?
  • Ansiotropic filtering is always off. My query for the maximum filter value is failing.
  • Okay, totally got it. Um, no. Save games don't load graphics resources when using OpenGL?! That's... odd and seemingly unrelated.
  • Sigh, there's a new background loader that didn't have an active OpenGL shared render context to load meshes, shaders, and textures.
  • Ugh, an assert when I draw to draw debug helpers? What, the assert is just wrong? At least it's an easy fix.

Why? Why!? Other than array textures, I haven't added any major features dealing with graphics since I initially wrote it!

The problem is that I've been merrily adding things over the last few years, and the OpenGL renderer hasn't been used. All the rendering features I wanted were in the code. But the ways they were getting used was different from when I wrote it initially. I also never shipped a game with the GL code, so a lot of the code paths that weren't followed or tested heavily had issues. Blah.

I know, I know, you think I should have some sort of unit testing for my graphics output.

Anyway, spent the last three days fixing things. Graphics coding is notoriously hard to debug. Difficult to find issues, but pretty much each one of the problems above was a one or two line code fix. But now things look nice, and in fact I can't tell which rendering path is being used now without checking settings.

I'm sure I have more of this code rot in the code. I haven't been using certain systems like achievements or audio with this new project yet, so I'm willing to bet as soon as I start, there will be more junk to cut out and clean.

What was it I was going to add again before I started fixing things?

Leave a Reply

Your email address will not be published.

31 comments on “Code Rot”

  1. What’s the benefit of having DirectX support if you are going to support OpenGL anyway?

  2. Isn't OpenGL a dinosaur by now, superseded by Vulkan?
    I also remember how horrible performance under OpenGL is from a few different games.
    I also believe the two major graphic card companies don't release OpenGL drivers (that were always buggy mess to begin with) anymore.

  3. I only support OpenGL in my own game engine, but even just that can be difficult, as different drivers support the API differently. I've had players report bugs that I couldn't reproduce on my hardware, because the GPU was of a different brand.

  4. Just a casual abserver here, and lover of Banished. I really enjoy reading about your progress, good, bad and otherwise. EXTREMELY curious and excited to witness this game and eventually play it. I'll buying it as soon as I can.

  5. Hello sir. I am a C++ programmer living in South Korea. I enjoyed playing your game 'banished' when I was an undergraduate and studying development.
    And I've been reading your posts about engine development all the time. ( i'm used Google Translate, because i'm not good at English)

    Reading your post made me want to start developing a game engine like you. Although it is not enough to be called a game engine right now, I would like to make a fun game like you someday.
    Thanks for reading.

  6. Hi Dukus! Just like many of your readers, I used to play Banished that I liked very much. As a former 8 bit Asm and C developer (now fiddling with Unity) I really appreciate your posts that remind me the pleasure of native code.
    Game engines like Unreal or Unity are just incredible regarding cross platform distribution and deployment but will never bring the pleasure to code everything by yourself (which of course is just impossible for complex games like AA ones).
    But you prove, year after year, that games of extreme quality and depth can be achieved by one person.
    I'm also eager to discover your new project.
    Bon courage!

  7. to be honest I came here for why there is nothing new but when i read this as a non developer I m just admire of your hard work. Keep doing it an update us. I can't wait to play your next game.

  8. Luke, time for another update how its going? Please? (we are all so looking forward to the next one!)

  9. Just a quick few words to say am a massive fan of banished man, its one off my all time favorites and still play on a regular basis both modded and original. love reading these updates for your new game.. i actually feel like am part of its production just without giving you any input lol. By sounds of it u been having quite a few issues.. bet you glad you managed to deal with them.. for now anyway. Keep up the exellent work your doing dude cant wait for alpha to be released ill be one of the first to purchase. Cant wait to see/read more as you progress.

  10. Hope you find the time to sue the ever-loving crap out of Gleamer Studio for ripping off your IP. All the effort you put into making a true classic, to have it ripped off like that is just, a total douchebag move on their part.

  11. Good morning, when will we have a new game or a new improvement in the current game? from the news, it's been a while since there's a sign of life....hehehehe

  12. The last post is now almost 7 months old. Maybe he died, or decided to be a chef instead of a game developer?

  13. Hey, how about just saying hi on here so we all know you are still alive? 8 months and.... nada. Merry Xmas btw.

  14. I think he must still be alive. Obviously, someone is still paying the website's hosting bills.

  15. Ok here's an idea... just come on and tell us the new game is dead and you have gone off to live a comfortable life on the millions we would think you made from Banished. No one would begrudge you that, but at least you would put us fans out of our misery from this seemingly deafening silence for near a YEAR now.... we all wish you well Luke, just say even a "Hi, I am still alive folks"

  16. Settlement Survival is much more fun than Banished! China based Gleamer Studio owns Shining Rock!
    OK, if an insult like this doesn't wake him up, I don't know what will...

  17. Maybe playing that Chinese knock off will scratch the itch I can't otherwise satisfy on Android...

  18. I'm approaching 600 hours on Banished and it never gets old!
    Thank you for this amazing game. Keep up the faith for the sequel!

  19. Just wanted to say hi. Thanks for Banished, and good luck with your current project. Hope the negative comments won’t discourage you. Take all the time you need. Your earned it.

More Posts

UI Redo: Part 3

October 25, 2021
1 2 3 47
Back to devlog
Back to devlog
© Copyright 2021 Shining Rock Software
Website Design & Branding by Carrboro Creative
menu-circlecross-circle linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram