Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » CRAZY High CPU Usage

This thread is locked; no one can reply to it. rss feed Print
CRAZY High CPU Usage
SkaxCo
Member #8,323
February 2007

Some of you may recognize this game, as I have had many questions on it. Well, now it runs nicely, thanks to many of your help. ...hm...for a given value of "nicely" I guess. Problem is, it runs at 90%-95% CPU usage. I don't know why, and my code files are slightly scattered. (I will opload them later) Can some of you test out my game and check out CPU? EDIT: I actually uploaded the game.

Instructions:
L-Click: Attack
1: Shrapnel Blast
2: Fragmentation Blast

Score: Score
Combo: Number of non-misses in a row
Level: Current number of zombies (and level)
Mines: Lives

Far right bar: The power bar. Killing a zombie gets +1 power. Shrapnel costs 10, Fragmentation costs 25. When charged and enough power, a little yellow square will show up. On the left is for Shrap, right is for Frag. The blue bar that moves is the reload time.

Kibiz0r
Member #6,203
September 2005
avatar

My guess without looking at it would be that you're not calling rest(1) or similar, you're rendering whenever logic doesn't need to be updated instead of putting a cap on the FPS, or you're constantly processing logic, or maybe not even using a timer at all!

Check all of those and reply.

SkaxCo
Member #8,323
February 2007

Okay, I think this is all of the code...here it is:
Is the problem the junkload of loops? I can't think of any way to do it. For those of you who aren't going to download the cade, it is pretty much:

for(;;){}800 times

SkaxCo.cry(because_high_cpu);
if(dont_know_how_to_fix)
       SkaxCo.ask_for_help(nice_allegrocc_people);
else{
       SkaxCo.thank_for_help(nice_allegrocc_people);
       SkaxCo.fix_problem(high_cpu);
}

Kibiz0r
Member #6,203
September 2005
avatar

Well, you uploaded the exe and the code, but there's no data, so I can't run it.

Aside from ugly code, I don't see anything wrong. :-/

Albin Engström
Member #8,110
December 2006
avatar

Quote:

it is pretty much:

It pretty much froze to death...

and what is that code??.. are you saying you're calling a for loop 800 hundred times? that's probably not the problem, unless you got some shit going on inside it.

taking a look at the code

first thought.. you need to upload the datafile too.. oops.
eer.. i hope my code doesn't look like this in the eyes of a stranger.. -.-
sorry, it would take me years to find the problem.

I'll let the elite take over.

SkaxCo
Member #8,323
February 2007

MKAY: All new uploads; new program, new code.

Kibiz0r
Member #6,203
September 2005
avatar

Only uses about 30% CPU on my machine.

Yaknow, for having such ugly code, it's a pretty attractive game.

Good show, I anticipate good things coming from you in the future.

SkaxCo
Member #8,323
February 2007

Hm...maybe just a slow computer. And thanks for the compliment!

Steve Terry
Member #1,989
March 2002
avatar

Runs at only 40% CPU on my machine as well so I'm guessing your machine is just a bit slow. Since it didn't run at 100% CPU and since I haven't looked at your code I'm going to assume you used rest(1) and the proper frame skip logic code.

___________________________________
[ Facebook ]
Microsoft is not the Borg collective. The Borg collective has got proper networking. - planetspace.de
Bill Gates is in fact Shawn Hargreaves' ßî+çh. - Gideon Weems

Kibiz0r
Member #6,203
September 2005
avatar

Quote:

since I haven't looked at your code I'm going to assume you used rest(1) and the proper frame skip logic code.

Trust me. Even if you looked at the code, you'd still just be assuming. :P

Paul whoknows
Member #5,081
September 2004
avatar

2% CPU usage here.

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

GullRaDriel
Member #3,861
September 2003
avatar

The game is nice. GFX needs some polishing.

CPU: IT goes alternatively from 2 to 50 % every second or so.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

CIRCLE
Member #5,301
December 2004

task manager uses more cpu (0-1% barely noticable) then the game on my machine but I am on a gaming machine. I have made a game quite simular to what you are doing but balls instead of zombies :) But same concept click and shoot and more will come :P

over all I like it.

-I edit a lot. Prepare thyself.

Jonny Cook
Member #4,055
November 2003

I've seen uglier code. You could use some more white space though... it feels kind of stuffy in there. :P

The face of a child can say it all, especially the mouth part of the face.

SkaxCo
Member #8,323
February 2007

Yeah...this is crazy patchwork code. It started a while ago, then I "finished" it. Went back, added some stuff, updated other stuff...yeah, it got ugly.

Go to: