Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Olof Larsson

Pages: [1]
1
Graphics / ImageManager
« on: May 09, 2010, 01:52:07 am »
Ok, thank's! I saw in the wiki that there are allready neat implementations for resource managers :)
For example: http://www.sfml-dev.org/wiki/en/sources/resource_manager
Thank you.

But anyways - would this solve the copy problem?
Are there any copy situations left?
Code: [Select]

class Image_manager
{
private:
map<string, sf::Image> image_map;

public:
const sf::Image& GetImage(string image_path) // The filename is used as a key
{
// Is this image is not loaded - load it
if(image_map.find(image_path) == image_map.end())
{
pair<string, sf::Image> path_image_pair;
path_image_pair.first = image_path;
if(!path_image_pair.second.LoadFromFile(image_path))
{
exit(EXIT_FAILURE);
}

image_map.insert( path_image_pair );
}

return image_map[image_path];
}
};

2
Graphics / ImageManager
« on: May 09, 2010, 01:14:45 am »
Quote from: "panithadrum"
I would work with pointers: copying images is a high cost function.

You could insert an empty image and then loading, instead.


Where am I copying the image?  :shock:
Im new to this const & ** *& *& * &*&*  stuff  :lol:

3
Graphics / Hard borders and sprite anti-aliasing
« on: May 08, 2010, 11:59:38 pm »
I wonder to.
How to draw a sprite onto a render window and get anti aliasing?

4
Graphics / ImageManager
« on: May 08, 2010, 10:16:36 pm »
http://www.sfml-dev.org/tutorials/1.6/graphics-sprite.php
At the end of that tutorial it's written:

Quote
In a more complex engine, images would be automatically handled by a manager. This is a more generic and easy way of handling resources. The idea is to make the manager store the images, associated to their filename (or whatever unique identifier), so that if the same image is requested several times, the same instance will actually always be returned by the manager.
Code: [Select]
sf::Sprite Sprite;

// GetImage will always return the same image for the same filename
Sprite.SetImage(ImageManager.GetImage("data/missile.png"));



However there is no ImageManager class bundled with SFML currently right?  :(

So i tried to write one:  :D
Code: [Select]

class Image_manager
{
private:
map<string, sf::Image> image_map;

public:
const sf::Image& GetImage(string image_path) // The filename is used as a key
{
// Is this image is not loaded - load it
if(image_map.find(image_path) == image_map.end())
{
sf::Image tmp;
if(!tmp.LoadFromFile(image_path))
{
exit(EXIT_FAILURE);
}

image_map.insert( pair<string,sf::Image>(image_path,tmp) );
}

return image_map[image_path];
}

void InformUs() const
{
cout << "These are the images we have loaded:" << endl;
for(map<string, sf::Image>::const_iterator it = image_map.begin(); it != image_map.end(); ++it)
{
   cout << it->first << endl;
}
}
};


How can the class above be improved?
Is an ImageManager bundled with SFML2?

Pages: [1]
anything