Shade: status update 5

Fifth month of development and fifth status update on Shade, cross-platform framework for 2D games which will be the core technology of all my future mobile and desktop games.

In case you missed the previous updates or wanted to read more about Shade before reading this post, you can check out all the previous posts of the series.

Month overview

This month I didn’t manage to get much progress as I spent almost 10 days on holiday and had to share my time on another project.

My commit stats confirm that: in July I pushed 50 commits, whereas in August only 10.

Nevertheless I implemented some new stuff besides few fixes so I decided to not skip this monthly post.

Textures refactoring

Probably most of the work this month went on the refactory of the Texture and TextureAtlas classes.

Before the refactory TextureAtlas was extending Texture and even if this was simplifying many things, especially with the TextureManager, at the same time it had a major flaw: it required specific client code to handle sub-Textures contained in TextureAtlases.

After the refactory a TextureAtlas is only a container of Textures and this allows to use the TextureManager to get Textures without having to worry if they are actual Textures or sub-Textures contained in a TextureAtlas.

Now every low-level detail is handled by the framework and it’s totally transparent to the client, as it should always be, which in practice means a developer can start working with individual images/files for simplicity and quick prototyping and moving to texture atlases when the project is more mature and the assets are well defined without changing a single line of client code, but the one needed to register Textures with the TextureManager.

Here an example of how the client code changed after the refactory:

Display::Image * img;

// OLD CODE
img = new Display::Image(Resources::TEX_ATLAS_QUADS, Resources::SUBTEX_QUAD1);

// NEW CODE
img = new Display::Image(Resources::TEX_QUAD1);

Random code

Games often require a lot of random generation, so I started to work on some wrappers for the C++11 random distribution classes, in particular I created wrappers for the uniform discrete distribution and the uniform (real) distribution.

I also created a class I called LoadedDice which uses the uniform distribution to generate random events based on their probability, something which is extremely handy in many situations and which allows to write very clean and compact client code.

For example this is some code which generates random monsters using only the UniformDistribution class:

const int RANGE_MIN = 0;
const int RANGE_MAX = 100;

const int THRESH_MONSTER_A = 5;		// 5% probability 
const int THRESH_MONSTER_B = 15;	// 10% probability
...					// more monsters here
const int THRESH_MONSTER_N = 100;	// 5% probability

Utilities::UniformDistribution randomGen(RAND_RANGE_MIN, RAND_RANGE_MAX);

int randVal = randomGen.GetNextValue();

if(randVal < THRESH_MONSTER_A)
	// create monster A
else if(randVal < THRESH_MONSTER_B)
	// create monster B
...
else
	// create monster N

Instead this code does the same using the LoadedDice class:

const int monsters[] = { MONSTER_A, MONSTER_B, ..., MONSTER_N };
const float probs[] = { 5.f, 10.f, ..., X.f };

Utilities::LoadedDice dice(monsters, probs, N);

CreateMonster(dice.GetNextEvent());

A great improvement in my opinion.

A new DisplayGUI widget: ToggleButtonsBox

Working on my test application I realized I needed an important Widget to use ToggleButtons in a mutually exclusive way, basically what you normally get with radio buttons (only a single button of a set is checked/selected at any time).

Nothing fancy obviously, but something useful in many situation.

What’s next

Unfortunately next month I won’t be able to dedicate much time to Shade as I will be involved in another project full time, but maybe I will manage to get something done anyway, maybe working some evenings, time will tell.

Leave a Comment

Your email address will not be published. Required fields are marked *