Open Surge Forum

A fun 2D retro platformer inspired by Sonic games and a game creation system

You are not logged in.

Announcement

Our community has moved to Discord! https://discord.gg/w8JqM7m

#1 2009-11-11 04:38:46

jasonspiro
Member
From: Toronto, ON, Canada
Registered: 2009-05-15
Posts: 53
Website

Suggestion: use less CPU, especially when paused, to save battery etc.

Hi,

When Open Sonic is running, Windows Task Manager shows that my CPU is always at 100% usage, even when the game is paused and minimized.  This makes my CPU fan run more noisily, makes my laptop use up its battery faster, and is not so good for the environment.  smile  Also, when I'm not playing, I sometimes leave the game paused and minimized for days on end so that I won't lose my progress, so this affects me for days.

Please make Open Sonic use less CPU when possible, especially when paused.

I'm using version 0.1.2.

Offline

#2 2009-11-12 00:38:36

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,300
Website

Re: Suggestion: use less CPU, especially when paused, to save battery etc.

ok. We'll take a look into it. smile

Offline

#3 2009-12-04 17:59:37

joserc87
Member
From: Granada (Spain)
Registered: 2009-12-04
Posts: 3

Re: Suggestion: use less CPU, especially when paused, to save battery etc.

Hi. First of all congratulations for this project. It's a great and game.
Secondly, I think this problem would be solved easily by modifying the main.c file and adding a rest (...); instruction after the rendering. So we will free the CPU the rest of the frame cicle rest (FRAME_INTERVAL - t; where t = game_timer () - last_time;). Also I have deleted the for (;;) in time control section.
This solution doesn't run exactly at 100 fps but (in my computer) reduces the CPU occupation arround the 10%. Of course, no else knows your code better than you, so my solution maybe is a bit ugly lol and you could do so much better. I only wanted to share an idea.

Best wishes to you and to this great project.

Offline

#4 2009-12-04 19:23:09

zl0i
Member
Registered: 2009-08-10
Posts: 10

Re: Suggestion: use less CPU, especially when paused, to save battery etc.

In my ubuntu 9.04 it loads CPU at 100% too, just for info. Before post #1 I was thiking that it`s linux platform problem. That problem has high priority.

Offline

#5 2010-01-27 12:55:08

keeperofdakeys
Member
Registered: 2010-01-27
Posts: 2

Re: Suggestion: use less CPU, especially when paused, to save battery etc.

I would really like open sonic to not consume 100% CPU, it seems the problem lies in the choice of timer for the game. I wouldn't have gotten very far without what joserc87 posted, but I know a bit of programming and I took a look.

To improve joserc87 solution, the following lines should replace the for loop:
current_time = game_timer();
delta_time = current_time - last_time;
rest(MIN_FRAME_INTERVAL - delta_time);

it seems delta_time is needed to properly show the current fps. The game seems to handle going into lower fps when the cpu is not powerful enough though. The only trouble is that when using small screen mode, the fps is doubled and the speed of the game is halved.

Could one of the programers also explain more about that for loop, I can't seems to understand what it all does. It almost seems that the game_timer() goes back to zero, otherwise current_time would never be less than last_time.


This is a great game and I would like to help as much as I can to improve this portion of the game.

Offline

#6 2010-01-27 14:51:44

Alexandre
Administrator
From: Brazil
Registered: 2009-01-27
Posts: 3,300
Website

Re: Suggestion: use less CPU, especially when paused, to save battery etc.

Using rest() in the main loop is usually a bad idea, as you never know when the operating system is going to take the control back to the game. Hence, it may cause an unnecessary drop of the frame rate.

That for loop is a busy waiting technique. I think a better approach would consist of using semaphores (which would require pthreads), but I'll postpone this issue to some other version, as we need to release 0.1.3 really soon.

Offline

Board footer

Powered by FluxBB  hosted by tuxfamily.org