Game Development Reference
In-Depth Information
The AssetManager class is singleton (only one instance is allowed to exist) and that is
why it has a static pointer to itself. Actually, all static functions of that class will use this
pointer as a way of referencing the instance of AssetManager , which will be created
just after we initialize the window and will be destroyed when the program exits. Creating
the asset manager in such a way is useful because we can call AssetMan-
ager::GetTexture() from anywhere in the program without having a reference to
the AssetManager object. Doing it in such a way with small examples might seem
pointless, but with larger projects it can save a lot of headaches of passing references
Apart from the pointer, the class holds a map of textures and a way of getting elements
from that map with the AssetManager::GetTexture() function. A map is a collec-
tion of values and unique keys—each key has exactly one value associated with it. In our
case, we have string keys and Texture values. The keys hold the filenames of the
textures, and the values hold the Texture objects. Doing it this way, we can easily check
whether a filename exists in map and add it if it doesn't.
Search WWH ::

Custom Search