Today's graphics libraries are very advanced and offer decent performance even within a pure software-rendering environment. However, the image rotation functions they provide either run too slowly, output unacceptable pixellation of the image, or require too many resources. (Two 3D triangles for a 2D sprite? Come on.)
A popular workaround is to fake image rotation with a handcrafted function based on a decision tree. Each entity owns an image array, and based on the current orientation of the entity, the function returns an index into the entity's image array, and the proper image is displayed. With an optimal decision tree and memory allocator for the image array, this results in much better performance.
The major drawback is scalability. What happens when game testers notice that a certain sprite's rotation is too "discrete" or jerky? How many more images are required in the array? Each such change brings about a major rewrite of the image "rotation" function, contributing to the loss of possibly many man-hours of work.
The Compass
class addresses the scalability problem by dynamically adjusting its internal decision tree every time the number of possible rotation outputs changes. In our image rotation faking application, the correct index into the image array can be obtained by calling Compass::getDirection()
. If and when the array size changes, pass the new size in a call to Compass::setDirectionCount()
. This works for all sizes, even zero!
Classes | |
class | sgdk::ZeroDirection |
North, South, East, or West. More... | |
class | sgdk::PositiveRotation |
Clockwise or Counterclockwise. More... | |
class | sgdk::Compass<> |
The main class in the Compass Module. More... |