Game Development Reference
In-Depth Information
Data Considerations
Another consideration when determining granularity is the data structure we will
use. Many people use a variable that can represent a plethora of decimal values
from 0 to 1. That level of detail is often more than we need. Often, we only need to
track a relative handful of values. For example, a single byte allows us to store 256
values. Most of the utility scales we would need to track in our games would not ne-
cessitate a finer granularity than that.
By using response curves, we can map the 256 values in a byte onto a large variety
of actual figures. For example, if we wanted to represent numbers from 0 to 1,000
but didn't need to have a granularity of 1/1000, we could use a response curve that
associates the indices 0 through 250 with appropriately spaced decimal values using
the formula y = 4 x . The contents of our response curve vector would look like this:
i
y
0
0
1
4
2
8
3
12
125
500
249
996
250
1,000
We are still representing numbers from 0 to 1,000, but we are not doing so with
possibly unnecessary granularity. By using a char instead of a short int , we are
saving one byte of data storage. While this may not seem like much at first, when
multiplied many times over, the savings can add up.
Certainly, one could make the case that we could simply store the numbers 0 to
250 and multiply them by 4 when we are ready to use them. As the formulas get
more complex—and especially when we hand-craft our response curves—this
approach yields significant benefits.
Moreover, when dealing with arrays or vectors, by only storing token values
along the way, we don't have to have an array that covers the entire range of values.
In the above example, despite wanting to represent values that range from 0 to
1,000 in our array, we did so in only 251 array locations. This effect is even more
noticeable when we want to store larger ranges. Just because we are storing numbers
ranging from 0 to 25,000 doesn't mean we care about every individual increment.
We may not need a granularity that fine.
Search WWH ::




Custom Search