   games and system usage
  how come whenever i run my games,  my system usage jumps to 100%?  am i doing something wrong?  basicly the loops just displays the images at 20 FPS.i'm on my 4th game and i haven't figured out how to fix it   
  The operating system has a scheduler that decides how much CPU time any particular application gets. Don't worry about it.If for whatever reason you want your application to yield (aka not run) momentarily. You can use the sleep() command to have your current thread, which in the case of a single threaded application is the main thread, halt for a given number of seconds.   ;  but i mean its a simple 2D game and the usage jumps from about 10% to 100%,  this isn't normal for a small game is it?;Quote:Original post by godsenddeathbut i mean its a simple 2D game and the usage jumps from about 10% to 100%,  this isn't normal for a small game is it?Yes it is normal.You have a while(1){} loop. The operating system is providing your application the optimum schedule allowing it to execute as fast as it possibly can.It is your job as a programmer to call sleep() where there is no actual work to be done. However, it the case of games, there is almost always work to be done on every loop.   ;  oh ok thanks,  another quick question,  i have no idea where to start with optimizing,  what are some suggestions of things to do?  inline certain functions? replacing ints with short ints?;  and do you know if SDL_Delay() would be equivilent to sleep()?   ;  Before you start optimizing you need to profile your game to see where its needed. VS2005 comes with a profiler, and if you're on linux there is gprof. AMD also has a free one called CodeAnalyst. I dont know if the express version of visual studio has one... what compiler are you using?Bascially these will give you a list of all your functions and how much total time is spent in each, and how many times they are called.   ;Quote:Original post by godsenddeathoh ok thanks,  another quick question,  i have no idea where to start with optimizing,  what are some suggestions of things to do?  inline certain functions? replacing ints with short ints?No. Those are optimizations. They make your code run faster. In this case your code is running plenty fast - the 'problem', if you can call it that, is that it's always running. If your code goes faster, it will just run more often (though to let you know, it's very unlikely that either of those would increase performance - the compiler usually knows best about inlining functions, and short ints usually run *slower* than regular ints on modern PCs). What sleep() does is it says "OK computer, I'm not doing much right now. Go ahead an use the CPU for something else more important than me right now." But you're making a game. When you're playing a game what is the most important program up? The game, without a doubt. So why bother making it use less of the CPU time? No one playing a game cares if their web browser open in the background gets a minimal amount of time. And the OS will already give anything the time it needs, so don't worry about doing it yourself - at least not in games. It would be bad if your word processor, your internet browser, your media player, and your anti-virus program all were fighting for system resources. But that's not a problem with games - when was the last time that you ran two games at once?   ;Quote:No one playing a game cares if their web browser open in the background gets a minimal amount of time.Thats true. However, i do care if my CPU overheats because of constant 100% usage.   ;  Well, inlining can give huge benefits for small functions and the compiler can only do it if it knows about your function implementation - that means putting it in the header file (I *think* VS2005 can do it anyway if its the same library/target etc but I'm not sure).About using full cpu resources or not, this is not an issue on desktop machines, but on laptops it can be. Fans start running, it uses more battery power etc.   