![]() |
|
Over mouse function |
00Andre
Member #16,399
June 2016
![]() |
Hey (I'm sorry foy my english) I have small problem, with function. In function check position cursor, if cursor is in the field Bitmap. Function is play in ALLEGRO_EVENT_MOUSE_AXES if I use functions this is delay big. |
RPG Hacker
Member #12,492
January 2011
![]() |
I'm not sure if I got exactly what you problem is, but I assume it's that lock bitmap and unlock bitmap slow down your application? When you use lock bitmap and unlock bitmap on a display bitmap, it's bound to be slow, because the bitmap first has to be read from the GPU into system memory and then wrote back to the GPU. Try creating the bitmap as a system memory bitmap. That way you can always directly access the pixels and no data has to be copied. If you also need to render the bitmap, then maybe you should make two versions of the same bitmap. One in system memory and one in display memory. You could then use the system memory bitmap for collision checking and the display bitmap for rendering.
|
jmasterx
Member #11,410
October 2009
|
Mousemove is called A LOT. And locking / Unlocking can be costly if you do it a lot. Here are a few suggestions: If that is too complex to understand, an easier version would be to allocate a [w][h] 2D array of char to do it. The other option is to build simple polygon approximations of your bitmaps and check if the mouse point is inside the simple polygon. Agui GUI API -> https://github.com/jmasterx/Agui |
00Andre
Member #16,399
June 2016
![]() |
Before creating a bitmap. I set the flag and display options 2al_set_new_bitmap_flags(ALLEGRO_CONVERT_BITMAP | ALLEGRO_VIDEO_BITMAP |
3 ALLEGRO_MIN_LINEAR | ALLEGRO_MAG_LINEAR);
4al_set_new_bitmap_format(ALLEGRO_PIXEL_FORMAT_ANY_WITH_ALPHA);
5al_set_new_display_option(ALLEGRO_VSYNC, 1, ALLEGRO_REQUIRE)
I removed the lock and unlock bitmaps and are smaller delay. 1if(mouse.x > width && mouse.x < x+width && mouse.y > height && mouse.y < y+height)
2{
3 ALLEGRO_COLOR pxg = al_get_pixel(bitmap, abs(mouse.x-x), abs(mouse.y-y));
4
5 if(pxg.a == 0) // NORMAL
6 {
7 return true;
8 }
9 else if(pxg.a != 0) // ALPHA
10 {
11 return true;
12 }
13 else if(pxg == color) // COLOR // operator==
14 {
15 return true;
16 }
17 else return false;
18}
but are still delays, but smaller |
RPG Hacker
Member #12,492
January 2011
![]() |
Try replacing ALLEGRO_VIDEO_BITMAP with ALLEGRO_MEMORY_BITMAP.
|
00Andre
Member #16,399
June 2016
![]() |
How swapped for the Allegro BITMAP MEMORY is even worse |
RPG Hacker
Member #12,492
January 2011
![]() |
And what if you do as suggested in my first post? Create two versions of that bitmap. One with ALLEGRO_VIDEO_BITMAP and one with ALLEGRO_MEMORY_BITMAP. Use the ALLEGRO_VIDEO_BITMAP one for rendering, while you use the ALLEGRO_MEMORY_BITMAP one for your alpha checks.
|
Mark Oates
Member #1,146
March 2001
![]() |
I'm just curious, 1) how many bitmaps are you checking and 2) what are the sizes of these bitmaps? -- |
00Andre
Member #16,399
June 2016
![]() |
RPG Marker I have one questions. If it is eg . 200 bitmaps is 200 * 2 is equal to 400 bitmaps. |
RPG Hacker
Member #12,492
January 2011
![]() |
The game will, of course, use addtional memroy in system RAM for each copy of a bitmap that you use for mouse collision detection, but depending on the number of bitmaps you need mouse detection for, the size of each bitmap and the hardware you are targeting for your game, it hopefully shouldn't bee too much of a problem. Nowadays most machines have at least 4 to 8 GB of system RAM, which don't exceed to quickly. If this RAM usage is still too much for you, you'll most likely have to try a different solution, like one of the solutions jmasterx suggested or maybe even just simple box collisions (depending on what you need this for in the first place). So yeah, the best solution really always depends on what exactly you're trying to do and for what purpose.
|
00Andre
Member #16,399
June 2016
![]() |
Thank you very much. does not want create new thread, So here write i often use al_clone_bitmap in project. only if drew on bt2 that bt1 also changed. Why don't use al_clone_bitmap ? because if used clone_bitmap a lot, that is delay |
Mark Oates
Member #1,146
March 2001
![]() |
al_clone_bitmap will create and allocate in memory a whole new bitmap (based on the previous). Any time you allocate something new in memory, it is usually much slower than other things. But if you do it like you showed: ALLEGRO_BITMAP* bt1 = al_load_bitmap("bt.png"); ALLEGRO_BITMAP* bt2 = bt1; Here you are just creating a new pointer. Now you have two variables that point to the same bitmap in memory, so no copying and allocation for a new bitmap has to happen. -- |
|