|
This thread is locked; no one can reply to it. |
1
2
|
My CPU usage is absurd |
Gabriel Campos
Member #12,034
June 2010
|
I dont know how to solve this. My CPU goes to above 50% in only drawing a sprite and a background. in the line void State_inGame::render() { level.render(0); // Guilts :( level.render(1); for(std::vector<Entity *>::iterator it = v_entity.begin(); it!= v_entity.end(); it++) { Entity *e = *it; e->render(); } }
level.render(0); This is the function level.render void Level::render(int layer) { MapChangeLayer(layer); MapDrawBG(0, 0, 0, 0, 1600, 608); EDIT: This is the responsable! Why? ??? } Thanx
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Make sure all your bitmaps are video bitmaps. Drawing memory bitmaps can be very slow and cpu intensive. That may be what is happening. 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
|
What version of Allegro? I suspect those functions are from Mappy. Edgar's advice is for Allegro 5, and don't really apply to Allegro 4 -- |
Thomas Fjellstrom
Member #476
June 2000
|
Edgar Reynaldo said: He said he was using mappy_a5 You know what? Ignore that Moose guy. He's stupid. -- |
Edgar Reynaldo
Major Reynaldo
May 2007
|
I don't see any Moose. Nothing to see here folks. Edit 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 |
Gabriel Campos
Member #12,034
June 2010
|
Still not working. =/ I have a character sprite (little sprite) and the tiles drawed by the mappy(allegro 5). Only this, so if even the bitmaps(png files by the way) loaded in the memory could not do so much to my CPU. The CPU gets a 60% usage. MapDrawBg(0, 0, 0, 0, 1600, 608); and voia la! No bg, only the sprite, BUT the CPU gets 1 or 2% usage. So, this is the problem. Could be a bug or my mistake loading the map? I saved in fmp format. Any ideias?
|
Thomas Fjellstrom
Member #476
June 2000
|
Make sure you stuff as many tiles and sprites into the same big texture as is possible. Switching between textures has a lot of overhead. -- |
Arthur Kalliokoski
Second in Command
February 2005
|
If you have an older card, and your texture isn't a power of two, it could be using a software path to render it. They all watch too much MSNBC... they get ideas. |
Audric
Member #907
January 2001
|
I'm surprised that you don't need to pass a target bitmap to MapDrawBG. So where does it draw? On the global 'screen' bitmap ? If this is the case, you get the very expensive copy of RAM to VRAM. |
Thomas Fjellstrom
Member #476
June 2000
|
Audric said: I'm surprised that you don't need to pass a target bitmap to MapDrawBG. So where does it draw? On the global 'screen' bitmap ? If this is the case, you get the very expensive copy of RAM to VRAM. He's using A5, there's a per-thread "current target", so it draws all his loaded images to the current target. -- |
Gabriel Campos
Member #12,034
June 2010
|
There is a better map tile editor for allegro 5? What do you guys uses?
|
Trent Gamblin
Member #261
April 2000
|
My guess is you're using D3D and drawing to a bitmap without the ALLEGRO_NO_PRESERVE_TEXTURE flag set. Or just plain using memory bitmaps.
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
It entirely depends on what mapDrawBG is doing behind the scenes, and whether it is using memory bitmaps or not, and whether the tiles are on the same atlas, and so on.... So, again, could you let me know where you got mappyA5 from? 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 |
Trent Gamblin
Member #261
April 2000
|
Even if he's not using atlases it's not going to use full cores unless it's an ancient system. It's a memory bitmap or no ALLEGRO_NO_PRESERVE_TEXTURE flag or else (unlikely) the Mappy code is really terrible.
|
piccolo
Member #3,163
January 2003
|
2013... What is your cpu spec? wow |
Edgar Reynaldo
Major Reynaldo
May 2007
|
You could try profiling your code after building it with debugging and profiling symbols. With MinGW it is -pg. Look it up for your compiler, and then run it through a profiler. You build it with profiling symbols, then run it, then analyze the output result file with a profiler like gprof and a.out. mingw32-g++ -Wall -g -pg -o mygame-profiler.exe src1.cpp src2.cpp mappy.c -lallegro-5.1.7-monolith-md mygame-profiler.exe gprof a.out And, I briefly looked at mappy_A5 and it does not use an atlas, it uses an array of ALLEGRO_BITMAP** abmTiles;, and so it does not use held bitmap drawing either. I think that was before we had the general knowledge of that around here. The dll mappy.exe wanted was allegro 5.0.2, and I dont' have that installed so the demo doesn't run for me. I might try recompiling the demo later. mappy does however respect the new bitmap flags, so if its not set to ALLEGRO_VIDEO_BITMAP if won't be a video bitmap, but video is the default, so you would have had to have changed it. :? 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 |
type568
Member #8,381
March 2007
|
Nobody has mentioned usage of some sleep function. Perhaps you're looping it somewhere without a rest?
|
Chris Katko
Member #1,881
January 2002
|
Yeah, I was scrolling the whole thread waiting for someone to mention it. 50%? Sounds like half of a dual-core CPU. Add a rest(0) to your main loop and see what happens. You can be doing nothing at all and you're still going to get maximum single threaded cpu utilization unless you add a rest. -----sig: |
Kris Asick
Member #1,424
July 2001
|
To anyone who's suggested that using rest(0) or Sleep(0) will reduce CPU usage, it will not! At least, not on Windows. The way Sleep() works on Windows (and subsequently Allegro's rest() function) is that, if you pass it a 0, it will only give up the present timeslice to other threads of equal priority if possible. If not, it burns it itself. Pass anything higher than 0 and you could lose up to 50 ms of CPU time which could seriously curtail your framerate, so don't do that. Since I've never used Mappy however I have no idea what it's doing behind the scenes or what other problems could be happening. As a thought though, try forcing Allegro into OpenGL mode if you're not already, and if you are, try not forcing it into OpenGL mode. See if that makes a difference. --- Kris Asick (Gemini) |
Elias
Member #358
May 2000
|
Kris Asick said: Pass anything higher than 0 and you could lose up to 50 ms of CPU time which could seriously curtail your framerate, so don't do that. I'd say that was only true a very long time ago. All the precompiled Linux kernels I've encountered in the last 10 years or so would use a 1000Hz scheduler clock, so rest(1) would sleep 1ms. Under Windows that's the default even longer (starting with XP I'd say). And I'd be very surprised if OSX will sleep more than 1ms either. So yes, someone using Windows 98 or a self-compiled Linux might get a 10ms wait (I don't ever used a system with a 20Hz timer so 50 ms seem very unlikely) - but the chance of encountering it will be very much zero Also, for Allegro 5 that should not be relevant as al_wait_for_event already will make your program not use CPU except when needed. -- |
Kris Asick
Member #1,424
July 2001
|
Elias said: I'd say that was only true a very long time ago. All the precompiled Linux kernels I've encountered in the last 10 years or so would use a 1000Hz scheduler clock, so rest(1) would sleep 1ms. Under Windows that's the default even longer (starting with XP I'd say). And I'd be very surprised if OSX will sleep more than 1ms either. Don't be so sure of that. On my last Windows 98 system, I was getting a granularity of about 10 ms with Sleep(). On my last Windows XP system, with much newer and better hardware, I was getting a granularity closer to 50 ms with Sleep(). I have no idea what hardware/software/driver/etc. stuff affects this but because you can't depend on the scheduler granularity to be super-low, even with a powerful system, you could end up losing a lot more time than you would want under Windows. Besides, even if the granularity was as low as 10 ms, that still tops out at 100 FPS when there's monitors out there that can do 120. I dunno about Linux but I'll take your word for it that it's a fixed 1 ms granularity. --- Kris Asick (Gemini) |
Thomas Fjellstrom
Member #476
June 2000
|
When a scheduler timer is running (on modern kernels the regular periodic timer tick can and will be turned off when the system is idle) it is usually set to 1000hz on desktops/laptops. On servers you should probably set it to 100 or 250. -- |
Gabriel Campos
Member #12,034
June 2010
|
I uses a notebook pentium dual core 2.4ghz, 3Mb memory...is not a good computer, but for sprites is a pretty machine. I stopped using mappy and start to use tiled that gives me a txt files. Make my class that stores that values in a vector and draw on the map. Still burns my cpu. Maybe its because of for loop?
|
Edgar Reynaldo
Major Reynaldo
May 2007
|
Like I said before, mappy doesn't use atlases or held drawing, both of which would speed up your drawing. 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 |
|
1
2
|