|
This thread is locked; no one can reply to it. |
1
2
|
fast put_pixels(again) or al_load_bitmap(void* data) |
aniquilator
Member #9,841
May 2008
|
Hello, I'm facing some performance problems now. What do you recomend me doing? Thanks in advance. |
Edgar Reynaldo
Major Reynaldo
May 2007
|
I don't have any experience with this, but you might have better luck using the PhysFS library and addon. That way you could use a zip file for your sprite packs and also use Allegro to load your sprites directly from the zip file. 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 |
aniquilator
Member #9,841
May 2008
|
I thought about that Edgar, but the thing is: my single sprite is composed of: group, index, optional name, xoffset, yoffset, and so. And this sprite has to be a single file.. If I use the PhysFs for the spritepack I will still have the problem with the sprite. BTW, I implemented a class called SFF, that derives from spritepack, that loads a mugen sff file. WHY: sometimes you dont have sprites to test, so I get some mugen ones for test. I thought about implementing a method to load images based in allegro's addon, but, if someone changes some function there my loader will stop to work.. And thats bad.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
You can make a separate file to store the data, and include in it the relative path of the sprite in the zip file. [Spritesheet name 1][Filename] [...][...] [Group][Index][Name][Xoffset][Yoffset] .... Just separate the actual files from each other - keep the text/binary data in one file, and the sprites in separate files. I still think it could work. 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 |
Thomas Fjellstrom
Member #476
June 2000
|
You have two choices. 1. take a look at the memfile addon. It lets you treat an arbitrary block of data as a file handle you can use with Allegro's file functions. 2. Use al_load_bitmap_f and Allegro's file functions instead of std:iostream. Though, this may not work right with all image loaders. -- |
Audric
Member #907
January 2001
|
I wonder what it the original cause for slowness compared with A4. Is it because A5 store bitmaps in video memory ? If this accounts for most time spent overall, reducing the file accesses will not change much. |
aniquilator
Member #9,841
May 2008
|
Thomas thanks for the answer , I will take a look in the memfile addon right now. Thanks Audric, the slowness is when puttin pixels in the images, in the loading. Not in the main loop, just when loading. btw, I want some function that works similar to the blit in allegro4. I can use draw_scaled_bitmap for this purpose? Or there is some other function that works better? Thanks. |
Trent Gamblin
Member #261
April 2000
|
al_draw_bitmap_region is equivalent to blit.
|
aniquilator
Member #9,841
May 2008
|
When I'm trying to load the image using what Thomas said I always get a NULL ALLEGRO_BITMAP. I create the allegro file, and tried to load it with al_load_bitmap_f; 1void ImageBase::load(Core::File& pFile, const int& pDataLength)
2{
3 ALLEGRO_FILE* fake_file = NULL;
4 unsigned char* data = NULL;
5 bool isTarget = true;
6 try
7 {
8 if( mFreeSource && mData != NULL )
9 {
10 isTarget = (al_get_target_bitmap() == mData) ? true : false;
11 al_destroy_bitmap(mData);
12 }
13 data = new unsigned char[pDataLength];
14 pFile.read( (char*)data, pDataLength );
15 fake_file = al_open_memfile((void*) data, pDataLength, "rb" );
16
17 mData = al_load_bitmap_f( fake_file, "pcx" );
18 if(mData != NULL)
19 {
20 printf("enter here\n");
21 mBpp = al_get_pixel_format_bits(al_get_bitmap_format(mData)) ;
22 mWidth = al_get_bitmap_width(mData);
23 mHeight = al_get_bitmap_height(mData);
24 mFreeSource = true;
25
26 }
27 else
28 {
29 printf("error\n");
30 }
31 al_fclose( fake_file ); //fecha o arquivo
32 delete data; //delata os dados
33
34 if(isTarget) applyAsTarget();
35 }
36 catch(std::exception& e)
37 {
38 printf("exception.\n");
39 }
40}
The FIle I test before, and it is open. THe length of the file is right too. But I always get a NULL ALLEGRO_BITMAP. What is the problem? |
Edgar Reynaldo
Major Reynaldo
May 2007
|
Are you sure pFile.read is giving you the correct bitmap data in pcx format? 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 |
aniquilator
Member #9,841
May 2008
|
Yeah. I tried other formats as well. But I always get a NULL image. |
Matthew Leverton
Supreme Loser
January 1999
|
"pcx" must be ".pcx". |
aniquilator
Member #9,841
May 2008
|
I changed the "pcx" to ".pcx", but nothing changed, by the way, this extension, must be just as a tip to the function, no? |
Edgar Reynaldo
Major Reynaldo
May 2007
|
The 'ident' parameter is so load_bitmap knows which bitmap loader to use. You have to get it right or it won't load. 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 |
Matthew Leverton
Supreme Loser
January 1999
|
aniquilator said: I changed the "pcx" to ".pcx", but nothing changed, by the way, this extension, must be just as a tip to the function, no? Then you are supplying invalid data if Allegro can load the image with al_load_bitmap. (I assume you have initialized the image addon.) |
aniquilator
Member #9,841
May 2008
|
I thought that the "ident" parameter was like a tip, the first loader it would try to use, them if it couldn't be used, it would just try another format. But Now I understand. So I have made everything "almost" right. I can use the allegro loader with my Image class now, but, unfortunally I dont get the speed I was trying to get. 1void ImageBase::load(Core::File& pFile, const int& pDataLength)
2 {
3 ALLEGRO_FILE* fake_file = NULL;
4 unsigned char* data = NULL;
5 bool isTarget = false;
6 char const* extensions[] = { ".png", ".pcx", ".bmp", ".gif",".tga", ".tif", ".tiff", ".jpg", ".jpeg", NULL };
7
8 try
9 {
10 if( mData != NULL )
11 {
12 isTarget = ( al_get_target_bitmap() == mData ) ? true : false;
13 if( mFreeSource )
14 {
15 al_destroy_bitmap( mData );
16 }
17 }
18
19 data = new unsigned char[pDataLength];
20 pFile.read( (char*)data, pDataLength );
21
22 fake_file = al_open_memfile((void*) data, pDataLength, "rb" );
23
24 for(register int i = 0; extensions[i] != NULL; ++i )
25 {
26 al_fseek( fake_file, 0, ALLEGRO_SEEK_SET);//volta o ponteiro para a primeira posição do "arquivo"
27 mData = al_load_bitmap_f( fake_file, extensions[i] );
28
29 if( mData != NULL ) //se encontar a imagem sai do loop.
30 {
31 break;
32 }
33 }
34 if(mData != NULL)
35 {
36 mBpp = al_get_pixel_format_bits(al_get_bitmap_format(mData)) ;
37 mWidth = al_get_bitmap_width(mData);
38 mHeight = al_get_bitmap_height(mData);
39 mFreeSource = true;
40 }
41 else
42 {
43 std::stringstream out;
44 out << "ImageBase::load(" << &pFile << ", " << pDataLength << "): Error in loading the image.";
45 raiseGraphicException( out.str() );
46 }
47
48 al_fclose( fake_file ); //fecha o arquivo
49 delete data; //delata os dados
50
51 if(isTarget) applyAsTarget();
52 }
53 catch(std::exception& e)
54 {
55 std::stringstream out;
56 out << "ImageBase::load(" << &pFile << ", " << pDataLength << "): Error in loading the image, couldn't allocate memory for image.";
57 raiseGraphicException( out.str() );
58 }
59 }
So, I try to load the image, until I find the correct loader for it. The tests I made I'm loading pngs, so, the first test it finds the correct image. |
kazzmir
Member #1,786
December 2001
|
Maybe you could write/steal header detection code so you can tell with a high probability what the image format is yourself and pass along the proper extension to Allegro. |
Elias
Member #358
May 2000
|
Is it faster if you load them as memory bitmaps? If you load video bitmaps, then it does much more than A4, it loads them but also uploads them to the GPU. If loading only memory bitmaps also is slower then likely something can be optimized. -- |
aniquilator
Member #9,841
May 2008
|
Kazzmir, i think thats not the problem.. I have my own loaders as well. I figured out now, that the problem is because the bitmaps are ViDEO_BITMAPS... Instead drawing the images gets slower.. So I think that there's no way out of this. faster loadings and slow framerates or slow loading but faster frame rates... |
kazzmir
Member #1,786
December 2001
|
Is calling load() 903 times taking the majority of time or do you process the bitmaps after loading them (calling putpixel a lot on them)? If you load the bitmap as memory, process it, then convert it to video (by just calling al_clone_bitmap or use the new al_convert_to_video or whatever) then you will get fast performance at runtime, assuming you are just drawing the bitmaps to the screen without using putpixel. |
aniquilator
Member #9,841
May 2008
|
Kazzmir, I'm just loading them, no prossessing on them. Edit |
kazzmir
Member #1,786
December 2001
|
I'm not sure exactly how long it takes me but I think its pretty fast, something like less than a second. Most of my loading time is taken up by parsing the rest of the mugen files (.cmd, .cns). Are you loading sffv2 files? All sffv1 are .pcx. Also it looks like you should set the target bitmap to NULL before destroying mData, just to be safe. |
aniquilator
Member #9,841
May 2008
|
I saw that you are programmin an allegro 5 backend for your game, but this time you said is using the allegro5 backend ? Or the other ? Because, when I'm using allegro4 or sdl, I can load my spritepacks faster as hell. Btw I'm not loading the sffs, it was just an example, in this case I mean. Cause I load sffv1, the second I dont looked into it yet. I dont know if this slowness is because of my computer, or whatever.. (I program in a netbook.) I have to change the target bitmap to NULL, just if the current target bitmap is the bitmap I'm destroying right? |
kazzmir
Member #1,786
December 2001
|
Its basically the same speed in Allegro4/SDL/Allegro5 in my engine, although I haven't accurately measured it. aniquilator said: Btw I'm not loading the sffs, it was just an example, in this case I mean. Cause I load sffv1, the second I dont looked into it yet. Now I'm lost. Are you loading sff files or something else? Quote: I have to change the target bitmap to NULL, just if the current target bitmap is the bitmap I'm destroying right? Right, only if its the current target. |
aniquilator
Member #9,841
May 2008
|
I'm loading my own spritepacks, its like the sff, but with some more info. |
|
1
2
|