![]() |
|
TR Start over 2 |
AMCerasoli
Member #11,955
May 2010
![]() |
Aww... I'm going to start over again... It's like there is always a better way to do it. I would love to be able to do something like: al_draw_bitmap(ResM->bitmap("background"),0,0,0);
So the "bitmap" functions check if that bitmap is already loaded, and if isn't returns a transparent bitmap while loads it, then when it's loaded start returning the real bitmap... Something like that could be possible?, I think it's I don't want to use al_load_bitmap manually anymore. PS: Sorry for being using The Depot as repository or something... Edit: Damn, I always forget the memory bitmaps and fonts!... So I can't have a resoruce manager on another thread...
|
_Kronk_
Member #12,347
November 2010
|
That looks really nice! AMCerasoli said: I would love to be able to do something like: al_draw_bitmap(ResM->bitmap("background"),0,0,0); So the "bitmap" functions check if that bitmap is already loaded, and if isn't returns a transparent bitmap while loads it, then when it's loaded start returning the real bitmap... Something like that could be possible?, I think it's . The thing is that bitmap() would be checking if "background" is already downloaded all the time... But I don't think that takes too much time... I don't want to use al_load_bitmap manually anymore. You could always write a function wrapper for al_draw_bitmap() that would have those functionalities; it would check if that bmp is loaded and handle the if's/if not's. You probably knew that though. -------------------------------------------------- My blog: http://joshuadover.tumblr.com |
Trent Gamblin
Member #261
April 2000
![]() |
For this std::map would work and would probably be performant enough. std::map<std::string, ALLEGRO_BITMAP *> bmps; ALLEGRO_BITMAP *get_bitmap(std::string name) { if (bmps.count(name) == 0) { ALLEGRO_BITMAP *bmp = al_load_bitmap(name.c_str()); bmps[name] = bmp; } return bmps[name]; }
|
Oscar Giner
Member #2,207
April 2002
![]() |
It's not that important, but considering you need the bitmap you're looking for, better use map::find and do only one lookup, instead of map::count + a second lookup: ALLEGRO_BITMAP *get_bitmap(std::string name) { auto it = bmps.find(name); if (it == bmps.end()) ALLEGRO_BITMAP *bmp = al_load_bitmap(name.c_str()); bmps[name] = bmp; return bmp; } else return *it; }
AMCerasoli said: and if isn't returns a transparent bitmap while loads it That's be quite more complex to do. You'd need to load the bitmap in another thread so the loading doesn't block you game. -- |
Trent Gamblin
Member #261
April 2000
![]() |
For some reason I thought map::find added the key if it wasn't there, but apparently not.
|
Edgar Reynaldo
Major Reynaldo
May 2007
![]() |
Oscar - you're returning a pair instead of an ALLEGRO_BITMAP* - you need to return it->second if it is found in the map. My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
Karadoc ~~
Member #2,749
September 2002
![]() |
Trent Gamblin said: For some reason I thought map::find added the key if it wasn't there, but apparently not. map::operator[] adds the key if it isn't already there. That's probably what you were thinking of. ----------- |
AMCerasoli
Member #11,955
May 2010
![]() |
Thank you Kronk. _Kronk_ said: You could always write a function wrapper for al_draw_bitmap() that would have those functionalities; it would check if that bmp is loaded and handle the if's/if not's. You probably knew that though. Well, I haven't thought much about it. But I guess I'm going to need to do something like that. Or what Trent suggested. Oscar Giner said: That's be quite more complex to do. You'd need to load the bitmap in another thread so the loading doesn't block you game. That is what I really wanted to do, but then I remembered that I can't load video bitmaps on anoth er thread. Having a resource manager on another thread would be a dream, but I have being reading that OpenGL doesn't allow you to do that. There seems to be some solutions, though. Sorry for the late answer, I'm running out of time these days.
|
Neil Walker
Member #210
April 2000
![]() |
If you're going to use the method of searching for bitmaps in a collection then returning the pointer, remember you should only destroy the bitmap once I kind of did the same thing but allowed bitmaps to be referenced as items from a larger sprite sheet, and the same thing goes there, make sure you delete the sprite sheet bitmap last. Neil. wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie |
kenmasters1976
Member #8,794
July 2007
|
AMCerasoli said: It's like there is always a better way to do it. I know that feeling, AMCerasoli. Anyway, it's looking good. Did you write your own GUI routines?.
|
AMCerasoli
Member #11,955
May 2010
![]() |
kenmasters1976 said: Did you write your own GUI routines?. Hahaha my what?, you make it sounds so professional, yhea I have my own GUI runtines Neil Walker said: If you're going to use the method of searching for bitmaps in a collection then returning the pointer, remember you should only destroy the bitmap once Thank you, We'll see if I'm able to come up with something good
|
kenmasters1976
Member #8,794
July 2007
|
That sounds complicated enough, AMCerasoli. If it works and suits your needs, that's all you need; you don't have to make it professional or complicated.
|
|