Dragonfly 4.20
A text-based game engine
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
df::ResourceManager Class Reference
Inheritance diagram for df::ResourceManager:
Inheritance graph

Public Member Functions

int startUp () override
 
void shutDown () override
 
int loadSprite (std::string filename, std::string label)
 
int unloadSprite (std::string label)
 
SpritegetSprite (std::string label) const
 
int loadSound (std::string filename, std::string label)
 
int unloadSound (std::string label)
 
SoundgetSound (std::string label)
 
int loadMusic (std::string filename, std::string label)
 
int unloadMusic (std::string label)
 
MusicgetMusic (std::string label)
 
- Public Member Functions inherited from df::Manager
std::string getType () const
 
virtual int startUp ()
 
virtual void shutDown ()
 
bool isStarted () const
 
int onEvent (const Event *p_event) const
 
int registerInterest (Object *p_o, std::string event_type)
 
int unregisterInterest (Object *p_o, std::string event_type)
 

Static Public Member Functions

static ResourceManagergetInstance ()
 

Private Member Functions

 ResourceManager (ResourceManager const &)
 
void operator= (ResourceManager const &)
 
 ResourceManager ()
 
SpriteloadRobustSprite (std::ifstream *p_file)
 
SpriteloadSimpleSprite (std::ifstream *p_file)
 

Private Attributes

Spritem_p_sprite [MAX_SPRITES]
 
int m_sprite_count
 
Sound m_sound [MAX_SOUNDS]
 
int m_sound_count
 
Music m_music [MAX_MUSICS]
 
int m_music_count
 

Additional Inherited Members

- Protected Member Functions inherited from df::Manager
void setType (std::string new_type)
 

Constructor & Destructor Documentation

◆ ResourceManager() [1/2]

df::ResourceManager::ResourceManager ( ResourceManager const &  )
private

Don't allow copy.

◆ ResourceManager() [2/2]

df::ResourceManager::ResourceManager ( )
private

Private since a singleton.

Member Function Documentation

◆ getInstance()

static ResourceManager & df::ResourceManager::getInstance ( )
static

Get the one and only instance of the ResourceManager.

◆ getMusic()

Music * df::ResourceManager::getMusic ( std::string  label)

Find Music with indicated label.

Return pointer to it if found, else NULL.

◆ getSound()

Sound * df::ResourceManager::getSound ( std::string  label)

Find Sound with indicated label.

Return pointer to it if found, else NULL.

◆ getSprite()

Sprite * df::ResourceManager::getSprite ( std::string  label) const

Find Sprite with indicated label.

Return pointer to it if found, else NULL.

◆ loadMusic()

int df::ResourceManager::loadMusic ( std::string  filename,
std::string  label 
)

Associate file with Music.

Return 0 if ok, else -1.

◆ loadSound()

int df::ResourceManager::loadSound ( std::string  filename,
std::string  label 
)

Load sound from file.

Return 0 if ok, else -1.

◆ loadSprite()

int df::ResourceManager::loadSprite ( std::string  filename,
std::string  label 
)

Load Sprite from file.

Assign indicated label to Sprite. Return 0 if ok, else -1.

◆ operator=()

void df::ResourceManager::operator= ( ResourceManager const &  )
private

Don't allow assignment.

◆ shutDown()

void df::ResourceManager::shutDown ( )
overridevirtual

Shut down manager, freeing up any allocated Sprites, Music and Sounds.

Reimplemented from df::Manager.

◆ startUp()

int df::ResourceManager::startUp ( )
overridevirtual

Get ResourceManager ready to manage resources.

Reimplemented from df::Manager.

◆ unloadMusic()

int df::ResourceManager::unloadMusic ( std::string  label)

Remove label for Music with indicated label.

Return 0 if ok, else -1.

◆ unloadSound()

int df::ResourceManager::unloadSound ( std::string  label)

Remove Sound with indicated label.

Return 0 if ok, else -1.

◆ unloadSprite()

int df::ResourceManager::unloadSprite ( std::string  label)

Unload Sprite with indicated label.

Return 0 if ok, else -1.

Member Data Documentation

◆ m_music

Music df::ResourceManager::m_music[MAX_MUSICS]
private

Array of music buffers.

◆ m_music_count

int df::ResourceManager::m_music_count
private

Count of number of loaded musics.

◆ m_p_sprite

Sprite* df::ResourceManager::m_p_sprite[MAX_SPRITES]
private

Array of (pointers to) Sprites.

◆ m_sound

Sound df::ResourceManager::m_sound[MAX_SOUNDS]
private

Array of sound buffers.

◆ m_sound_count

int df::ResourceManager::m_sound_count
private

Count of number of loaded sounds.

◆ m_sprite_count

int df::ResourceManager::m_sprite_count
private

Count of number of loaded sprites.