ImageEngine

The standard implementation of the IImageEngine interface.  ImageEngine is the respository for all of the ImageSets loaded from the current RuleSets.  Each ImageSet is stored in a string-based hash map where the ImageSet key is the string key in the hash.  Since multiple ImageSets may have the same key, each string in the hash is mapped to a std::list of ImageSets, so that multiple ImageSets can share the same key in peace and harmony.  The functions required by the IImageEngine interface are implemented by taking the hash and performing the necessary operations.  See the function documentation below for details.

Derived From

IImageEngine

Project

RulesCore

Include

ImageEngine.h

Summary
The standard implementation of the IImageEngine interface.
Stops the ImageEngine.
Returns a single image based on the key/name combination.
Fills an array with all images belonging to a given key.
Reads images from a .tex file.
Loads images from a .tex file on demand.
The string hash of ImageSets.

Public

Summary
Stops the ImageEngine.
Returns a single image based on the key/name combination.
Fills an array with all images belonging to a given key.
Reads images from a .tex file.

Functions

Stop

void Stop()

Stops the ImageEngine.  Clears the hash of ImageSets.

Virtual Functions

GetImage

virtual wxImage &GetImage(const wxString &key, 
const wxString &name, 
const wxSize &size = wxDefaultSize) const

Returns a single image based on the key/name combination.  The image is scaled to the given size, if any.  If the key does not exist, or the name does not exist in the given key, an error message is thrown to the screen.

NOTE: Returning a wxImage by value is acceptable, because wxImage is reference counted internally and no data is actually copied.

Parameters

keyThe image group key to search in.
nameThe image name to look up.
sizeThe size of the outgoing image.

Returns

The image.  May be an empty image if the image was not based on the given key and name.

GetAllImages

virtual void GetAllImages(const wxString &key,
ImagePairArray &array)

Fills an array with all images belonging to a given key.  The array is filled with std::pair<wxString, wxImage> combinations The string is the name of the image, and the wxImage is the image itself.

Parameters

keyThe image group key of the images to retrieve.
arrayThe outgoing array of string/image pairs.

ReadImages

virtual void ReadImages(const wxInt32 size,
wxImage pList[],
const wxString &filename) const

Reads images from a .tex file.

Parameters

sizeThe number of images in the .tex file.
pListA pointer to an array of images.  Must be size in length.
filenameThe name of the .tex file to load.

Private

Summary
Loads images from a .tex file on demand.
The string hash of ImageSets.

Functions

LoadOnDemand

void LoadOnDemand(const wxString &filename,
wxInt32 size) const

Loads images from a .tex file on demand.  The image retrieval strategy for ImageEngine assumes that any image loaded from a certain .tex file probably means that another request for an image from that same .tex file is going to come soon.  Therefore, it keeps the currently loaded .tex file in a local cache.  The LoadOnDemand function manages that local cache, only loading a new .tex file when the existing one doesn’t provide the image the caller is looking for.

Parameters

filenameThe name of the .tex file the image is in.
sizeThe number of images in the .tex file.

Variables

mImageSetHash

ImageSetHash mImageSetHash

The string hash of ImageSets.  All of the loaded ImageSets are stored grouped together by their key.  Any particular key may have multiple ImageSets to look through in order to find exactly which image to use, so each string key in the hash actually maps to a std::list of ImageSets that might all share the key.

The interface of the image engine.
void Stop()
Stops the ImageEngine.
virtual wxImage &GetImage(const wxString &key, 
const wxString &name, 
const wxSize &size = wxDefaultSize) const
Returns a single image based on the key/name combination.
virtual void GetAllImages(const wxString &key,
ImagePairArray &array)
Fills an array with all images belonging to a given key.
virtual void ReadImages(const wxInt32 size,
wxImage pList[],
const wxString &filename) const
Reads images from a .tex file.
void LoadOnDemand(const wxString &filename,
wxInt32 size) const
Loads images from a .tex file on demand.
ImageSetHash mImageSetHash
The string hash of ImageSets.
A repository of knowledge about a .tex file.
A repository of all things rules-related.
RulesCore is the HOSS of Cities3D.