Game Development Reference
In-Depth Information
course, that one of those buckets is four times as large as the other one. The differ-
ence is subtle but important from an algorithmic standpoint.
It would seem that a more accurate way of modeling this idea would be to truly
have only two buckets—that is, two items in our vector. However, we would have
to also represent the reality that the first bucket was four times as large as the second
one. This is where the edges come into play.
D ATA S TRUCTURE
We don't need to change too much of our data structure to represent this method
of thinking. When we use a pattern similar to what we have done already, our den-
tist recommendation structure would look like this.
typedef enum {
SUGARLESS,
SUGARRY
} GUM_RECOMMENDATION;
struct sRECOMMENDATION {
USHORT Size; // The size of this bucket
USHORT Edge; // The edge of this bucket based on its position
GUM_RECOMMENDATION Recommendation; // The actual recommendation
};
typedef std::vector< sRECOMMENDATION > GUM_VECTOR;
We have replaced the x parameter of the struct with two components: Size
and Edge . The first one, Size represents the width of the bucket. Edge , on the other
hand, represents the position of the edge on the x scale. This is similar to how we
were using x in the prior examples. There is not much of a functional difference
between the two—the edge value is simply an x value after all. The difference is that
we are no longer representing every value of x .
E NTERING D ATA
Entering data into the new structure works from the same premise that we used
earlier. The function AddBucket takes a bucket size and a recommendation, places
them into a temporary struct , and pushes that struct onto the back of the vector.
Search WWH ::




Custom Search