About the Author
Mass Effect
Final Fantasy X
Batman:Arkham City
Borderlands Series
Weekly Column
Champions Online
World of Warcraft
DM of the Rings
Good Robot
Project Frontier

Diecast #205: Kerbal Space Programming, Unity, C#

By Shamus
on Monday Apr 9, 2018
Filed under:


The title is not a typo. This is actually about programming for Kerbal Space Program. For those of you who’ve been missing out on the programming content around here: Your time has come. We talk about programming on the Diecast, and then tomorrow I have a new programming series starting.

Direct download (MP3)
Direct download (ogg Vorbis)
Podcast RSS feed.

Hosts: Paul, Shamus.

Episode edited by Issac.

Show notes:

01:20 KSP Modding

26:08 Unity game Engine

43:57 Programming in C# versus C++

Comments (41)

  1. Lars says:

    Programming Blogposts YES!

  2. redsoxfantom says:

    *flails arms excitedly*

  3. Ravens Cry says:

    Huzzah~! Sweet Christmas!

  4. Matt van Riel says:

    Hopefully this is going to be wall to wall complaining about how there’s too many languages and it’s a pain in the ass learning a new one and they all have annoying foibles and how Shamus hates everything and everyone :D

    Or it could be something constructive and positive. I guess that works too ;p

  5. Nick Powell says:

    C# does actually have pointers and memory allocation like C++ does (but in a more limited form), but it won’t compile unless you tag the scope with a big scary ‘unsafe’ keyword to make you acknowledge the fact that you can cause memory leaks doing it.

    I’ve never used it though, and I have no idea how well it would play with Unity, since you don’t actually get to create unity objects yourself

    • Methermeneus says:

      Can you tag the global scope as unsafe and just treat C# like C++ as far as pointers go?

    • Andy "toadicus" Wilkinson says:

      I want to say that KSP or Unity generally rejected mods that were compiled with unsafe code blocks. I wound up not really interfacing with that part of the language at all. I’ve seen it done in other projects so I’m aware of its availability, but it’s clearly a concession on the part of the language designer’s part and not a feature they really want you to be using.

      • 4th Dimension says:

        Actually it’s kinda key part of C# specification, since a MAJOR part of how .NET is structured is to allow relatively easy access to existing non .NET libraries. And to do that you will need a way to pass pointer data and accept it back from functions made in unmanaged languages.

        But yes, it DEFINITELLY doesn’t want you to be using it for garden variety tasks. You are supposed to use this just to convert from C# managed data into pointers so you can pass them to unmanaged libraries and convert the results back. Which is why you tend to wrap any such library in a C# wrapper and use that in your actual code.

    • Default_ex says:

      It’s actually very hard to create leaks in c# Even in unsafe context. However it is extremely easy to create all sorts of crash with no hope of recovery in unsafe. Mostly it’s useful for dirty hacks like storing mixed data types of same lenth in an array without incurring gc overhead or casting overhead. Has many other uses but they are rarely the uses you would want to use pointers for in c or c++.

  6. Echo Tango says:

    Any framework, language, or other tool can allow both “close to the metal” or very abstracted behavior for a programmer, but it takes a lot of work, or at least diligence. Your need to have well-organized code for your tool, with lots of documentation, and good defaults. Unfortunately, there’s no direct incentive for companies to support all ranges of skills/levels, so you end up with either very low level tools or very abstracted/limited tools.

    • Paul Spooner says:

      That’s one of the things that makes me hopeful for Jai, is that it’s designed to provide a broad range of abstraction to good programmers. Sure any tool “can allow” for a broad range, but very few actually seem to.
      Something that JB talks about a lot is “big idea languages” which have a central doctrine they are designed to support, rather than being designed to be useful to programmers.

    • default_ex says:

      It’s the dream of using such a language that has had me hooked on C# for as long as I have been. While the major uses of it are abstract high level stuff. It does have a good degree of low level “on the metal” functionality if you choose to use it. Unfortunately it sits just a bit too high level to provide that kind of “on the metal” we all want from our fancy modern languages.

      One thing I have always wanted in a language after using HLSL is arbitrary semantic bindings. In HLSL we have binding points for the output from a shader stage that serve as the input to the next stage. Your vertex shader could output to variables bound to Position0, TexCoord0, TexCoord1 and so on while your pixel shader could input variables from any or all of those. There was no error if the structures didn’t match on each side, if you bound and input to a semantic that wasn’t previously an output it would simply have 0s. You could output/input with structures, without structures or with in/out/inout specifiers on function parameters. It’s an incredibly powerful way of passing data that goes a long way toward having particle functions you can assemble to create a larger proper function without the annoying overhead of a massive structure to carry things around (or rather it hides that structure behind some compiler magic).

  7. John says:

    I enjoyed the programming talk immensely, even though I only understood somewhere between a third and a half of it. For my own half-hearted games-making projects, I’ve been using libGDX, which is somewhere between a library consisting of a wrapper around a wrapper for OpenGL and an actual game engine, all written in Java. Based on that experience, two things about today’s podcast stood out for me.

    First, there was Shamus’ comments about trying to do things directly in OpenGL. I’m so glad that I don’t have to that. I’ve spent a lot of time working with libGDX’s Sprite and OrthographicCamera classes and I’ve had enough trouble that just imagining doing these things with low-level commands is enough to make me a little nauseous. LibGDX is fairly well documented for an open-source project, but I’ve still run in to a lot of difficulties trying to get sprites to behave in the desired fashion when I’m rotating them and moving them around the screen. At its core, the Sprite class is a rectangle with a texture slapped on it and a bunch of operations for manipulating the two, but a lot of those methods just aren’t intuitive to me or don’t do what I want them to do. I have a horrible feeling that I’m going to end up writing my own extension to the class and it’ll be wrappers all the way down. The OrthographicCamera class, by contrast is fairly well behaved, but heaven help you if you move the camera and forget to call the camera’s update method before you start drawing sprites. There’s probably a good reason that moving the camera doesn’t cause it to auto-update, but I’m not nearly knowledgeable to know what it could be.

    The other thing that stood out was all the talk about garbage collection. Java is not a language that encourages manual garbage collection. I know it’s possible, but I have no idea how to do it or when it would be advisable. That said, a lot if libGDX classes–Texture, for example–have a method called dispose(), which I know is garbage-collection related. The main libGDX class, the one that every program must instantiate and the one that contains the rendering loop also contains an over-writable dispose() method into which you are encouraged to put dispose() calls for global variables with a dispose() method. Still, it’s a bit of a black box as far as I’m concerned. One of these days I should probably go look at the source code instead of the Javadocs.

    • Ander says:

      I had a decent experience with libGDX for a mobile game. There seems to be plenty to dig into before needing to get into its source.

      As for garbage collecting…Yes, absolutely dispose your textures, but I don’t think there should be a situation in which you will have to manually dealloc memory.

      • John says:

        If I did start looking at the source, it would be a matter of curiosity rather than necessity. Put another way, if things get to the point where I need to take a look at the source then I’m switching to another library or engine.

  8. Droid says:

    EDIT: I wrote this tangent mostly as a comment on “there is no good middle ground in terms of distance-from-hardware”.

    I realize it’s specialized software instead of a general programming language/framework/whatever, but for mathematical and scientific work, Mathematica has a LOT of tools for all kinds of people, and after the usual hurdle of getting acquainted with the language, it has way more functions than you will ever need, most, if not all, with somewhat sensible standard values for its parameters.
    Its main problem, I would say, is that it does not make some fundamental things it does clear enough to the user. It has an ENORMOUS and most importantly dynamic documentation, though (they give you lines of code and the output it produces as actual, executable code in the documentation, so you can fiddle with it and try different things and see why on Earth their example works, but yours doesn’t).

  9. neolith says:

    “We talk about programming on the Diecast, and then tomorrow I have a new programming series starting.”

    Awesome! I am looking forward to it!

  10. Daemian Lucifer says:

    Ah,no programing talk is complete without a car metaphor.

    • Andy "toadicus" Wilkinson says:

      See, programming talks are like cars, and car metaphors are like radio antennas. They aren’t strictly necessary for the core functionality of the car, but almost all cars have them and almost everyone is glad they’re there.


  11. Daemian Lucifer says:

    Things are in motion

    So next weeks guest is evil Shamus you befriended at mewe?

  12. Andy "toadicus" Wilkinson says:

    Several times I said “Danny2642”, and while Google will fix that for me if you ask it, I want to clarify that I meant “Danny2462”.

  13. Gordon D Wrigley says:

    The opengl comments are funny. I always start every opengl project by copying an existing project that gets something on screen and then stripping out the bits I don’t need. As you essentially say, if you don’t have something meaningful on screen then you are basically stuffed.

    • Echo Tango says:

      This is pretty much what I did in my graphics class at university. Keep a known working copy of an “empty” program which just displays one cube in front of one quad with all the correct options and camera setup, then just start from that state for every project.

      • Andy "toadicus" Wilkinson says:

        I feel like this is what all of us do for project-based work in just about any field. I know I don’t re-write all of my general notes and conditions for every design I turn out. ;)

  14. 4th Dimension says:

    Considering I program solely under VS for .NET in C#, I wonder how much of these ussues with Mono and Unity are a problem of Mono implementation of .NET specification and Unity and how much it’s actuall things like garbage collection and like.

    • default_ex says:

      That really could be it. GC in C# isn’t hard to get right but Mono’s implementation is much less forgiving than Microsoft’s implementation of the .Net GC. If your a stickler for following best practice guidelines (proper implementation of deconstructors, IDispose and good reuse behavior) then it really doesn’t matter. If you play it a little loose then it will bite you hard in Mono where Microsoft’s GC just might give you that little leeway to get away with it.

  15. Super late says:

    On programming languages, look at D’s scope statements. They are exactly what you described as deferreds. You can also configure D’s memory allocator.

Leave a Reply

Comments are moderated and may not be posted immediately. Required fields are marked *


Thanks for joining the discussion. Be nice, don't post angry, and enjoy yourself. This is supposed to be fun.

You can enclose spoilers in <strike> tags like so:
<strike>Darth Vader is Luke's father!</strike>

You can make things italics like this:
Can you imagine having Darth Vader as your <i>father</i>?

You can make things bold like this:
I'm <b>very</b> glad Darth Vader isn't my father.

You can make links like this:
I'm reading about <a href="http://en.wikipedia.org/wiki/Darth_Vader">Darth Vader</a> on Wikipedia!

You can quote someone like this:
Darth Vader said <blockquote>Luke, I am your father.</blockquote>