G-Engine #3: Game Loop

In my last G-Engine post, I did some setup work and finally got a basic OS window appearing that could be moved around, minimized/maximized, and closed. Good start!

In this post, we’ll do a bit more planning, and then we’ll structure our code into a high-level class (Engine) that’ll be more conducive to building an engine than just shoving everything into the main function. We’ll also implement our “delta time” calculations, which will be critical for updating the state of our game as we move forward.

[Read More]

G-Engine #2: Project Setup

The previous post introduced the idea and motivation behind the project. So here we are, ready to build a 3D game engine! This post walks through some early decisions, starting from absolutely nothing to having just an empty application window that can be moved around and closed.

This is not the most exciting end result, but there are plenty of important decisions to be made before we dig into actually writing game engine code.

[Read More]

G-Engine #1: Introduction

“G-Engine” is a hobby project I’ve been kicking around for awhile. In December 2017, I finally took the dive and started in on it. This post (and those following it) document my progress and what I’m learning as I develop it.

At its core, the idea is to build a 3D game engine in C++. But building a game engine without also building a game can be difficult to do. So, for me, my goal is to use the engine to recreate a video game I’m a fan of: 1999’s Gabriel Knight 3 from Sierra Studios.

This post provides a background of how I came to focus on this project over the course of many years. It also provides an overview of what the project is and why I’m pursuing it.

[Read More]

Insert, Push, and Emplace

Standard C++ containers (or collections) are essential tools. Some, like vector, queue, deque, and stack are list-like: elements are accessed by position. Others, such as map or set, are more associative in nature: elements are accessed by a key.

To add an object to a vector, you can call insert or push_back. Stacks and queues both allow you to add elements using push. Map allows insertions with insert or using the [ ] operator.

In C++11 and beyond, all these containers have new functions that seem to behave similarly to the above methods: emplace, emplace_back, and emplace_front.

Which begs the question: what’s the difference between these different methods of adding items to collections?

[Read More]

When to Inherit from MonoBehaviour

When you create a new C# class in Unity, it automatically inherits from the MonoBehaviour class, which is Unity’s base class for components. In Unity, you tend to create a lot of components, but it’s important to keep in mind that you don’t have to.

When I was new to Unity, I thought everything should inherit from MonoBehaviour - that’s just how you work in Unity! Some of my students have also had this misconception. In fact, there are often scenarios where it makes more sense to not inherit at all, or to inherit from another base class. This post explains situations where it makes sense to use MonoBehaviour, and some cases where you’d be better off without it.

[Read More]

Encapsulate Unity Inspector Variables

When writing a Unity component, it’s likely that you’ll want to expose some variables in the Unity Editor’s Inspector, so that either you or a designer can modify those values without having to recompile the script. However, the default method of exposing variables in the inspector can break class encapsulation in an undesirable way. This post explores ways to expose variables in the Inspector without sacrificing your class’s encapsulation.

[Read More]