Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Improving drawing speed

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Improving drawing speed
Aikei_c
Member #14,871
January 2013
avatar

I'm not loading images that were already loaded. There's only onle place when they are loaded and I have a breakpoint there, as I said before. I'm sure I'm not loading them several times.
Actually, I figured out where the bottleneck was: the custom comparison function for map<>, which was pretty nasty, now I fixed it.
Now I have the same speed as I had before when I used different bitmaps.
There's actually too much code for you to handle, I'm afraid :D

Thomas Fjellstrom
Member #476
June 2000
avatar

If that's the case, then maybe you should pair/simplify down the code till you have a single simple concise example to show us, that has the problem you're seeing.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Aikei_c
Member #14,871
January 2013
avatar

Ok, everything starts here:

#SelectExpand
1 ImageResource* res = objectAnimation[id][state][direction][frame]; 2 ImageAllocationMap::iterator it = imageAllocationMap.find(res->m_Name); 3 if (it != imageAllocationMap.end()) 4 { 5 Update(res); 6 Point<int> pt = it->second; 7 return subbitmaps[pt.x][pt.y]; 8 } 9 else 10 { 11 return LoadImage(res); 12 }

the Update function:

#SelectExpand
1void Storage::Update(ImageResource* imageResource) 2{ 3 m_lru.remove(imageResource); 4 m_lru.push_front(imageResource); 5}

the LoadImage function:

#SelectExpand
1ALLEGRO_BITMAP* Storage::LoadImage(ImageResource* imageResource) 2{ 3 int size = zipFile->VGetResourceSize(*imageResource); 4 char* buffer = new char[size]; 5 zipFile->VGetResource(*imageResource,buffer); 6 ALLEGRO_FILE* f = al_open_memfile(buffer,size,"r"); 7 ALLEGRO_BITMAP* img = al_load_bitmap_f(f,imageResource->m_extension); 8 al_fclose(f); 9 delete[] buffer; 10 if (!img) 11 { 12 Logger::Write(APP_LOG,FILE_LINE("%s <%s>"),"Error loading bitmap", imageResource->m_Name.getStr().c_str()); 13 return NULL; 14 } 15 al_convert_mask_to_alpha(img,al_get_pixel(img,0,0)); 16 if (freePoints.empty()) 17 FreeOneImage(); 18 int ipt = *freePoints.begin(); 19 Point<int> pt (ipt % atlasSize, ipt / atlasSize); 20 al_set_target_bitmap(subbitmaps[pt.x][pt.y]); 21 al_draw_bitmap(img,0,0,0); 22 al_set_target_bitmap(screen); 23 imageAllocationMap.insert(make_pair(imageResource->m_Name,pt)); 24 freePoints.erase(ipt); 25 al_destroy_bitmap(img); 26 m_lru.push_front(imageResource); 27 if (drawingHeld) 28 al_hold_bitmap_drawing(true); 29 return subbitmaps[pt.x][pt.y]; 30}

Thomas Fjellstrom
Member #476
June 2000
avatar

I meant, try and pull out what that code is trying to do, in a short and simple example, that still has the problem you're seeing. something we can all run and test.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Aikei_c
Member #14,871
January 2013
avatar

I'll think about it tomorrow.

UPDATE:
Here is what I found out: If I just launch a simple allegro project which only draws one image over and over, it can only draw 2000 96x96 images with 60 fps on my machine, then it starts to slow down. I'm pretty sure that all the other resources are eaten by: isometric sorting, needed to know which character to write first, dynamic resource loading system and various other smaller things. I probably can't hope for more than 1000 for my project.

Kris Asick
Member #1,424
July 2001

1000 is still a lot so long as you stay away from particle effects, "Bullet-Hell" shooters and maps with very small tile sizes.

Most of the people into indie games are going to have at least half-way decent hardware so you shouldn't worry too much about developing for low-end systems. Instead, I'd recommend upgrading your video hardware so you can get a better idea of just how much power you can utilize. ;)

10,000 sprites per second is about the limit you'll be able to reach in Allegro with mid-range graphics hardware and proper coding methodology while maintaining 60 FPS. Don't know what the limits are with high-end stuff as I haven't tested yet.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Simon Parzer
Member #3,330
March 2003
avatar

I would not fret about performance until you actually run into problems. 1000 sprites, that is a lot already. Go compare that to what a HTML5, or Flash game can utilize.
Developing a game is a creative task and as such, you can do a lot about performance issues, even without optimizing your code, just by being clever about how you do stuff and working around limitations. The quality of your game certainly does not scale with the number of different sprites you can display each frame. ;)

Kris Asick
Member #1,424
July 2001

Unless you're like me and can't stand it when some 2D game can't run 60 FPS. ::)

--- Kris Asick (Gemini)
--- http://www.pixelships.com

 1   2 


Go to: