Reflection systems – allowing a program to inspect it’s own code at runtime – is extremely handy for game engines. For example, rather than hard coding a list of objects that can be spawned by the console or be selectable from the editor, the engine can just look for all classes that either subclass a particular type or have a particular flag. Another example would be for networking – and is something that I’ll be writing for some upcoming coursework – whereby instead of writing bespoke methods per class for networking, a programmer can just add a ‘replicated’ flag to a particular field and a generic method handles updating automatically. The same would work for Remote Procedure Calls (RPC) – just mark a method as an RPC method and the reflection engine (And some form of preprocessor) can handle it as appropriate. C# has a built in reflection system, as well as a very handy attribute system (You tag types, methods and fields as you define them in a pretty intuitive way). Sadly, Fragment Engine is built in C++ (Which may be ported to D, providing slightly more features here, but it’s C++ for now).
Hey there! As I’ve had some questions from my friends about this, I’ve decided to write a basic guide to C# attributes, C# reflection and potential use cases for both. For the sake of definition, ‘reflection’ means the ability for code to look at or ‘reflect’ on itself, also often known as introspection.
Alongside starting this site, I’ve also decided I might as well start reviewing things I like. Lets begin with sci-fi book (there will be a LOT of these) from 2000, the first in the Revelation Space universe – conveniently named Revelation Space – by Alastair Reynolds. Personally, I hadn’t seen very much of this series and found the entire collection on offer on the Google Play book store after finishing a previous book. I read some reviews and a synopsis, and bought it there and then. This was a very good decision.
Ah, Fragment Engine. A project that will probably take my entire life to complete because I am but one man and there’s only so much time I have on this planet (Unless my plans for cybernetic immortality come to fruition, but we’re not there yet). Since literally nobody but some friends and a few of my lecturers at university have ever heard of this thing, I’ve decided to write about what exactly it is.