Jesper Lundgren
Engine & Tools
Home
Projects
Variable Exposing Island Generator Tale of Stavros Spite: Into the Bog
LinkedIn
Other projects

Variable Exposing

Preview of the tool in use during development of the game Tension highlighting volumetric lighting in the game.

Preview of the tool in use during development of the game Tension highlighting volumetric lighting in the game.

The EXPOSE system is a system I've developed that lets programmers easily give themselves and other disciplines, such as level designers and graphical designers, access to manipulate the value of a variable runtime through a GUI.


Table of Content
  1. Background
  2. Usage
    1. Code
    2. Result
  3. See also

# Background

During my time at The Game Assembly I wanted my fellow programmers to be able to quickly give themselves and others access to their variables runtime and save their changes. In previous projects I'd been part of at the school, the way to store and load variables in a data-driven manner was through writing to .json-files by hand and then reloading the entire game. This was tedious. There had to be an easier way I thought to myself. Rather than storing all modifiable variables in a .json-file and letting the file be the interface, I wanted it to be graphical. To achieve this I used the Dear ImGui library.

Even though the writing to and reading from the .json-file is automated, through an interface, which allows me to save the JSON in a minified form to save space, I chose to save it in pretty form which preserves whitespaces. This ensures that merge conflicts can be solved easier by hand if needed.

# Usage

The system can expose 5 different data types: bool, float, float2, float3, and float4. The main way to expose a variable is through the EXPOSE macro. This will automatically group variables in the same file together under a category named after the file. The macro is overloaded to support 4 different types of exposure: a quick way, a verbose way, a stylish way, and a level specific way.

  • The quick way is the minimal approach and allows for rapid prototyping.
  • The verbose way allows the programmer to define a custom label for the variable in the GUI.
  • The stylish way allows the programmer to chose a different way to represent the variable in the GUI.
  • The level specific way allows the programmer to store separate values in the variable depending on which level is loaded.

Since one can expose the same variable multiples times - i.e. in enemies - one must also unexpose the exposed variable before it goes out of scope. This can be done using the UNEXPOSE macro as seen in the source file down below.

Down below in the Code section you can see how a programmer would leverage the system.

# Code

DemoClass.h
#pragma once

class DemoClass
{
private:
	float mySpeed;
	float myOtherSpeed;
	float3 myColor;
	float3 myLevelColor;

public:
	DemoClass();
	~DemoClass();
};
DemoClass.cpp
#include "DemoClass.h"
#include "Expose.h"

DemoClass::DemoClass()
	: mySpeed(1.0f)
	, myOtherSpeed(100.0f)
{
	// Quick expose
	EXPOSE(mySpeed);

	// Verbose expose
	EXPOSE(myOtherSpeed, "Speed (cm/s)");

	// Stylish expose
	EXPOSE(myColor, "Ambient Color", ExposeTag::ColorPicker);

	// Level specific expose
	std::string level = "Demo_Level";
	EXPOSE(myLevelColor, "Ambient Color", ExposeTag::ColorPicker, level);
}

DemoClass::~DemoClass()
{
	UNEXPOSE(mySpeed);
	UNEXPOSE(myOtherSpeed);
	UNEXPOSE(myColor);
	UNEXPOSE(myLevelColor);
}

# Result

With the code above, the system will yield the following result:

Animated picture showing the EXPOSE tool in action
Animated picture showing the EXPOSE tool in action.

# See also

  • Volumetric Lighting by Eric Karlsmyr

Return to the top of this page
Other projects

Home

    • About
    • Highlights

Projects

    • Variable Exposing
    • Island Generator
    • Tale of Stavros
    • Spite: Into the Bog

External resources

    • LinkedIn

Contact

    • contact@noijig.net