|
This thread is locked; no one can reply to it. |
1
2
|
Improving drawing speed |
Aikei_c
Member #14,871
January 2013
|
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. |
Thomas Fjellstrom
Member #476
June 2000
|
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. -- |
Aikei_c
Member #14,871
January 2013
|
Ok, everything starts here: 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: 1void Storage::Update(ImageResource* imageResource)
2{
3 m_lru.remove(imageResource);
4 m_lru.push_front(imageResource);
5}
the LoadImage function: 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
|
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. -- |
Aikei_c
Member #14,871
January 2013
|
I'll think about it tomorrow. UPDATE: |
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) |
Simon Parzer
Member #3,330
March 2003
|
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. |
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) |
|
1
2
|