Skip to content

Editing Properties

Isaac edited this page Sep 16, 2018 · 2 revisions

This guide will explain the purpose of the properties class and how to edit it.

The properties class exists so that we can edit the 'mode' of the game/engine without recompiling our code every time we make a change. Effectively, it is a .txt file that contains settings for the program when it runs.

Some examples of the settings it contains:

  • Render mode (eg fill, shaded, textured, wireframe, etc)
  • Camera speed
  • Strength of gravity

Using the Properties Text File


To change a value simply go to the 'properties.txt' file and put the setting you'd like to set and the value it should be. The format is:
[setting] [value]

For example:
renderMode fill

You must know the setting and appropriate values for that setting, otherwise, there will be an error. These can be found in the 'Properties.h' file or at the Properties reference page.

Note that every setting already has a default value; if the setting is not in the file, it will automatically be set to the default when the program loads.

Also, note that the order of the settings in 'properties.txt' has no effect. In practice:

renderMode fill
gravity -9.81

is the same as

gravity -9.81
renderMode fill

Using the Properties in C++ Code


The Properties class is nothing but a way to store and get global settings and their values. Thus, if you want to use the Properties class simply #include "Properties.h" at the top of your file. This will allow you to use properties class which will allow you to get values.

A good example of this is the Physics Engine, which gets the gravity value upon instantiation. This is how you would get that property:

#include "Properties.h"
float gravity = Properties::Get<float>("gravity");

Here you can see the general form is:
Properties::Get<[datatype]>("[setting name]");

In this example, if you put in the 'properties.txt' file:
gravity 5.0
Then everything would float upwards since gravity needs to be -9.81 to be like Earths.


Adding a Property


Adding a property is actually quite simple. Go to the 'Properties.cpp' file and you will see the following (at the time of writing this article) in the 'Init()' function:

// RENDERER
properties["renderMode"]			= "fill";
properties["glLineWidth"]			= "0.5";

// CAMERA/MOUSE
properties["cameraYaw"]				= "-90.0";
properties["cameraPitch"]			= "0.0";
properties["cameraSpeed"]			= "2.5";
properties["cameraSensitivity"]		        = "0.1";
properties["cameraZoom"]			= "45.0";
properties["cameraFOV"]				= "45.0";

// PHYSICS
properties["gravity"] = "-9.81";

To add a property, simply add a line with the same format, where the setting is the string inside properties[""] (no spaces) and the default value (always a string) is on the right.

Do not forget to add at the bottom of the 'Properties.cpp' file the KEY you added (setting) and the OPTIONS (values) avalible for that KEY. The example at the time of this writing is below:

KEY				OPTIONS
renderMode			= fill, wireframe, lines
gravity				= DOUBLE
glLineWidth			= DOUBLE
cameraYaw			= FLOAT
cameraPitch			= FLOAT
cameraSpeed			= FLOAT
cameraSensitivity	        = FLOAT
cameraZoom			= FLOAT
cameraFOV			= FLOAT

Also add this documentation the Properties reference page.

Do not forget to add the actual implementation of the setting as well. An example of this would be where I add the 'gravity' property to the 'Properties.cpp' file and documentation, etc but forget to actually put it in the code where the PhysicsEngine.h references that value. We would then be changing a value that does nothing.