Friday, January 21, 2011

There was this PCSTree guy and PCSNode girl...


Well, I am back again here. I’ll use this post to explain the first assignment we got (which I actually finished a couple of days ago). The goal is to create a System to handle the Objects inside your game engine, that is, a centralized place where all game objects can be stored, organized and managed.

That’s basically the final objective of this Object System, but as Prof. Keenan says “We have to take Baby Steps in order to get there”, so for now the basic idea is to create a Tree-like Structure to store data on memory in a coherent and efficient way.

This structure consists of a bunch of nodes linked together by pointers creating a structure that resembles a tree. In the first place you have a class called PCSTree (where PCS stands for Parent-Child-Sibling) which has a pointer to an instance of the class PCSNode called Root. This root node acts as the connection between the tree and all its nodes, but when we count all the nodes in the tree this one is not taking into account. Mainly this node is generated when the tree is created and lives while the tree exists, even when it is empty.

Nodes can have as many children and siblings as possible, but each node only has a pointer to its first child and next sibling, and an additional one to its parent node. Therefore, each node ends up having a pointer to the first element of a linked list of child nodes, and also a pointer to the next element in the linked list of child nodes of its parent. In the end, this so-called Tree structure is better define as Tree of Linked Lists. Here is a diagram I drew to explain myself better.


Well, I’m off to do some code-commenting and smoothing of the rough edges (trying to optimize as much as possible). I’ll let you know how this part ends in the next post. See you around!

Adios!

No comments:

Post a Comment