|
This thread is locked; no one can reply to it. |
1
2
|
cpu fps etc... |
karistouf
Member #5,126
October 2004
|
hi again. I begin without the app: The old version, without any rest(1) nor timer function: I have put in my main loop a rest of 1 sec, and putted in volatile funct activated by the timer all my printing to screen. Modification to the program with a rest and timer function, FPS 100: FPS 50: Here is part of the code, I do not arrive to do less to not charge the CPU. Any idea ?
"step by step" |
GullRaDriel
Member #3,861
September 2003
|
umpf !!! Chris, n'appelle install_int_ex qu'une seule fois ! et en dehors de la boucle while ! Apres quoi tu pourras boucler sur ton rest(1); tranquillement ! "Code is like shit - it only smells if it is not yours" |
bamccaig
Member #7,536
July 2006
|
First of all you shouldn't be doing so much work in a timer function. Setting a flag or incrementing a counter and responding to it in the game loop is the preferred (and feasible) approach. I'm not sure why you repeatedly call install_int_ex, but that seems shifty as well... -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
gnolam
Member #2,030
March 2002
|
I'm surprised that doesn't outright crash, what with Allegro's notorious thread unsafety and all. -- |
Audric
Member #907
January 2001
|
You can attempt to rest() for more than 1ms at once. edit Considering that less than 10% of the screen surface may have changed, you could just blit these parts individually, like a "dirty rectangles" system. (Additionally, you can memorize if these screen parts HAVE changed at all. For example, the top text: No need to redraw the paragraph if it has the same content as when it was last redrawn.) |
Goalie Ca
Member #2,579
July 2002
|
Is it Tuesday again? ------------- |
Vanneto
Member #8,643
May 2007
|
Are there any advantages of using semaphores over normal high-res timers? In capitalist America bank robs you. |
karistouf
Member #5,126
October 2004
|
ooooups, i didn t know it was an error, I have an hudge programm wich is running with install_ex inside of the main loop since 4 years of dev... without any error i mean errors of timers (and its real time manipulation)... but its still doing nothing o my troubles of CPU... while (index_quit==0) { rest(1); //nothing... but refreshment is done in the volatile as previous and first code } CPU weight is still from 41 % and up to 70% {"name":"outofloop.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/3\/032ede2c76a20c40b9e54221cb2392ea.jpg","w":983,"h":510,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/0\/3\/032ede2c76a20c40b9e54221cb2392ea"} so? I mean install_ex is there tomake use of timer in an easy manner, to avoid calculations of tclock ? "step by step" |
GullRaDriel
Member #3,861
September 2003
|
install_int* granularity can vary from 1 msec to 14-20 msec "Code is like shit - it only smells if it is not yours" |
Goalie Ca
Member #2,579
July 2002
|
Quote: Are there any advantages of using semaphores over normal high-res timers? Yay. Someone asked the RIGHT question. Why did i use a locking semaphore? Because allegro timers spawn their own thread, wake it up, run user code (increment value), and then go back to sleep. I used a semaphore because i wanted to put the mail loop to sleep and have the timer wake it up like it should happen. You only want your main loop to execute when the timer beeps! Allegro timer simplifies this possibility away but certain operating systems (not all) libraries can handle this without a problem. Rest is basically a way to stop constant spin locking by taking shifts. It will tell the operating system to put the thread to sleep... but only for a really short time. It then checks again.. whenever the operating system feels like it. It may check almost right away (bad because more cpu wasted) but the general rule of thumb is that rest is only accurate to within 15ms. To summarize: rest still wastes tons of cpu. It constantly wakes up and goes back to sleep. With my locking mechanism i can get my own (graphically simple) allegrogl games to use < 1% cpu. ------------- |
bamccaig
Member #7,536
July 2006
|
That's really cool Goalie Ca, but how portable is it...? Will your example work on Windows and Linux? Do you need to install third party libraries or anything? -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Goalie Ca
Member #2,579
July 2002
|
If your OS is posix then you have it. All linux, mac, and older winnt. For new windows you need to download pthread. http://sourceware.org/pthreads-win32/ ------------- |
bamccaig
Member #7,536
July 2006
|
I guess I will attempt to learn to use semaphores then. Until then, here is my revised raw timer template...
To compile it the following commands should work (you must have Allegro installed). Windows/MinGW: gcc -O2 fps.c -o fps.exe -lalleg
*nix/GCC: gcc -O2 fps.c -o fps $(allegro-config --libs)
-- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Goalie Ca
Member #2,579
July 2002
|
Quote: I guess I will attempt to learn to use semaphores then. Simple. A semaphore is like a locking counter. I've pasted the code i wrote to the wiki and have added a few useful comments. Basically main goes to sleep, ticker wakes it up. No wasted cycles, no extra context switches, no spinlocks.
------------- |
karistouf
Member #5,126
October 2004
|
OK finally I founded why it was taking so many weight in memory: if(set_display_switch_mode(SWITCH_BACKGROUND)) {set_display_switch_mode(SWITCH_BACKAMNESIA);}
to enable the visual refreshing of information if I m not on its window. "step by step" |
Kitty Cat
Member #2,815
October 2002
|
Quote:
while(game_on){ sem_wait(&ticks); //decreases count, goes to sleep if count < 0, wakes back up when count >= 0 (through sem_post) update_stuff(); draw_stuff(); }
If you want to do frameskipping, this should work: while(game_on){ sem_wait(&ticks); do { update_stuff(); } while(sem_trywait(&ticks) == 0); draw_stuff(); }
-- |
karistouf
Member #5,126
October 2004
|
MAOUW its nice, but it need to run , while its not on nor selected. "step by step" |
Thomas Fjellstrom
Member #476
June 2000
|
Quote: I'm surprised that doesn't outright crash, what with Allegro's notorious thread unsafety and all. A lot of the crashieness was "fixed" in the last release or two. But it means theres a ton of locking and unlocking going on, slowing things down and potentially using lots of cpu. That doesn't mean you should use the same allegro resources from multiple thread (in fact you probably shouldn't), unless you're absolutely sure you know what you're doing. -- |
bamccaig
Member #7,536
July 2006
|
To compile it the following commands should work (you must have Allegro [and pthreads installed - Windows users, this probably means you]). Windows/MinGW: gcc -O2 fps2.c -o fps2.exe -lalleg -lpthreadGC2
*nix/GCC: gcc -O2 fps2.c -o fps2.exe $(allegro-config --libs) -lpthread
-- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
karistouf
Member #5,126
October 2004
|
Quote: I'm surprised that doesn't outright crash, what with Allegro's notorious thread unsafety and all. never crashed... 4 years this damn calling inside main loop... hundred of performances and theatre play without crash... Quote: unless you're absolutely sure you know what you're doing. well, or people have made studies, and better than say'until you know what you are doing' they can explain WHY and HOW ( more constructiv), or they didn t ... no ?
"step by step" |
Thomas Fjellstrom
Member #476
June 2000
|
Quote: well, or people have made studies, and better than say'until you know what you are doing' they can explain WHY and HOW ( more constructiv), or they didn t ... no ? I don't understand a thing you just said. However, what i meant was, if you know the issues inherent with threading, and know what to work around them, do as you please. -- |
bamccaig
Member #7,536
July 2006
|
On a side note, should a semaphore (sem_t) be volatile? -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Thomas Fjellstrom
Member #476
June 2000
|
No. Just ignore that keyword. It doesn't do what most people think it does. -- |
Goalie Ca
Member #2,579
July 2002
|
Quote: On a side note, should a semaphore (sem_t) be volatile? Actually it relies on a special CPU instruction called (roughly) "test and set lock". It is an entirely atomic operation. sem_t itself is a struct. ------------- |
bamccaig
Member #7,536
July 2006
|
Thomas Fjellstrom said: No. Just ignore that keyword. It doesn't do what most people think it does. Is this not what it does? -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
|
1
2
|