Allegro.cc - Online Community

Allegro.cc Forums » The Depot » TR Start over 2

This thread is locked; no one can reply to it. rss feed Print
TR Start over 2
AMCerasoli
Member #11,955
May 2010
avatar

Aww... I'm going to start over again... It's like there is always a better way to do it. >:( Now I'm using more C++ but It doesn't convince me. I wan to use a Resource Manager running on a different thread now, but I don't know if I'm able to do that. I want to be able to set up a little GUI. I'm almost done but it's failing.

video

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 :P. 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.

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!

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.

--------------------------------------------------
"If only our dreams were fires to ignite, then we could let the whole world burn" -Emery

My blog: http://joshuadover.tumblr.com

Trent Gamblin
Member #261
April 2000
avatar

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
avatar

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;
}

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
avatar

For some reason I thought map::find added the key if it wasn't there, but apparently not.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Karadoc ~~
Member #2,749
September 2002
avatar

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
avatar

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.

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
avatar

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.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

kenmasters1976
Member #8,794
July 2007

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
avatar

Did you write your own GUI routines?.

Hahaha my what?, you make it sounds so professional, yhea I have my own GUI runtines 8-). No really I wrote it but it's very simple. Just a list of objects "Windows". Before drawing the windows I reverse the list order, and when I check its logic I send a pointer (in the initialization) to the objects which tells if no window is active, the press button event is sent to the first object (which is the top window for the user, after the list being reversed) and since no window is active the first one is going to be change the pointer to true, so the other ones are going to see that actually there is an active window and aren't going to get active... and bla bla bla... I haven't finish it yet, besides the background window it's always the same size, but it's fine for my game, so don't imagine a big GUI routines back there.. ;D

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 :o

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.

Go to: