As promised in the last blog post, today we are going to take a look at how Molecule handles internal references to data owned by some other system in the engine.
Category Archives: C++
Adventures in data-oriented design – Part 3a: Ownership
One thing I have noticed during the development of the Molecule Engine, is that defining clear ownership over data can tremendously help with following a data-oriented design approach, and vice versa.
Adventures in data-oriented design – Part 2: Hierarchical data
One task that is pretty common in game development is to transform data according to some sort of hierarchical layout. Today, we want to take a look at probably the most well-known example of such a task: transforming joints according to a skeleton hierarchy.
volatile != thread synchronization
Everybody knows that writing correct multithreaded code is hard, even when using proper synchronization primitives like mutexes, critical sections, and the likes. (Ab)using the volatile keyword for synchronization purposes makes a programmer’s life even harder – read on if you care to know why, and help spreading the word.
Singleton is an anti-pattern
There’s a horrible disease out there, and a lot of programmers – both junior and senior – are affected by it: Singletonitis. Please, let’s help stopping the plague from spreading further by reading and understanding this post.
Adventures in data-oriented design – Part 1: Mesh data
Let’s face it, performance on modern processors (be it PCs, consoles or mobiles) is mostly governed by memory access patterns. Still, data-oriented design is considered something new and novel, and only slowly creeps into programmers’ brains, and this really needs to change. Having co-workers fix your code and improving its performance really is no excuse for writing crappy code (from a performance point-of-view) in the first place.
A lesser known C++ operator
Dealing with function template code can sometimes result in errors being emitted by the compiler because template argument deduction is ambiguous. Most of the time, casts are used to battle these errors, but often there’s a more elegant solution to the problem.
A safer static_cast
Even though static_cast is assumed to be the safest of all C++ casts, it can still be the cause of hard-to-find bugs, or unforeseen crashes. These bugs most often occur when casting between signed and unsigned types, or casting values into types which are not large enough to hold them.
A plethora of macros
Today I want to share a few very useful macros with you, which I’ve accumulated over the last years of my programming career. Enjoy!
Type-based dispatching
Today’s useful C++ technique is type-based dispatching. This can be used whenever you want to call different functions based on properties of a certain class, without paying unnecessary performance penalties.
Subtle differences in C++
Let’s start this post with a small C++ quiz. Consider the following class:
class Eater
{
public:
template <size_t N>
void Feed(const char (&str)[N]);
void Feed(const char* str);
};