Points of Required Attention™
Please chime in on a proposed restructuring of the ROM hacking sections.
Views: 88,526,208
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search 05-03-24 09:16 PM
Guest: Register | Login

0 users currently in Computing | 1 guest

Main - Computing - Reducing CPU waste? (Programming) New thread | New reply


Smallhacker
Posted on 06-14-07 09:28 PM Link | Quote | ID: 45666


Panser
Swedish weirdo times eleven

Level: 42

Posts: 122/339
EXP: 494768
Next: 26594

Since: 02-19-07
From: Stockholm, Sweden

Last post: 5192 days
Last view: 5191 days
A C++ program I'm working on (that uses SDL) uses up a lot of CPU power, more than it should. It seems like the program runs it's "update" code multiple times per frame, which is completely unneccesary.

I've tried to place a SDL_Delay(blah) between each update, but it either slows the program down too much or has no effect.

Another programming language I've worked with came with a function that paused the program until the current frame had been drawn to the screen, but I've been unable to find such a function in SDL or any other C++ library.

Any suggestions?

____________________
SMW Central

neotransotaku
Posted on 06-15-07 08:55 AM (rev. 2 of 06-15-07 08:57 AM) Link | Quote | ID: 45802


Shyguy
Level: 24

Posts: 16/95
EXP: 73055
Next: 5070

Since: 04-19-07

Last post: 5029 days
Last view: 2912 days
Perhaps you need to try to use threads explicitly? Because if the condition to update is the drawing of a new frame, then that should be a relatively easy thing to control.

I know UNIX comes with a nice thread library. I know windows should have something. If you are unsure how to use threads, I can lend some help.

HyperHacker
Posted on 06-15-07 10:06 AM Link | Quote | ID: 45829

...
Level: 73

Posts: 853/1220
EXP: 3368789
Next: 117079

Since: 03-25-07
From: no

Last post: 6099 days
Last view: 6082 days
I don't think SDL is thread-safe. A delay after each frame should do the trick if you use the right value. 13ms should cap it to ~60FPS, assuming it's getting that much to begin with.

Generally, though, you want to keep the frame rate as high as possible and make all logic/timing independent of it. Otherwise everything will run really fast on faster machines, and lag on slower ones, like so (fast, medium, slow):




Whereas with a fixed timestep they'd all move the same speed, but on slower machines you'd see choppiness (which I can't seem to duplicate with marquees).

setz
Posted on 06-15-07 10:10 AM Link | Quote | ID: 45832


Spike
fuck~
Level: 58

Posts: 441/722
EXP: 1537810
Next: 39736

Since: 02-19-07
From: Pittsburgh, PA

Last post: 5297 days
Last view: 2585 days
I'd say that reads fairly well on lower (1024x768 atm) resolutions, HH.

____________________

HyperHacker
Posted on 06-15-07 10:14 AM Link | Quote | ID: 45834

...
Level: 73

Posts: 855/1220
EXP: 3368789
Next: 117079

Since: 03-25-07
From: no

Last post: 6099 days
Last view: 6082 days
Posted by setz
I'd say that reads fairly well on lower (1024x768 atm) resolutions, HH.
And what would "that" be?

Main - Computing - Reducing CPU waste? (Programming) New thread | New reply

Acmlmboard 2.1+4δ (2023-01-15)
© 2005-2023 Acmlm, blackhole89, Xkeeper et al.

Page rendered in 0.020 seconds. (321KB of memory used)
MySQL - queries: 47, rows: 60/61, time: 0.015 seconds.