|
SLow running program |
gary_ramsgate
Member #8,619
May 2007
|
Hi there. I've been experimenting with a program that plots a number of points on the screen, which causes the effect of a cloud rising from the bottom to the top of the screen. The program is listed below. The programming is nowhere near perfect, however i've run into a problem. As soon as I use the set_palette command to get the palette from a background scrren that i'm loading, the program runs at a snails pace. If I remove the command, the program runs nice and quick. The background screen is an 8 bit 800x600 screen. Any ideas as to what could be causing this. Thanks in advance. // #include <allegro.h> // Declare Bitmaps PALLETE startup; // Init graphics // define structure for holding star particle details // Initialise star starting positions int n; // Display rising cloud int main(void) /* set up the keyboard handler */ /* set a graphics mode */ // Initialsie stuff /* you must always release bitmaps before calling any input functions */ return 0; END_OF_MAIN() |
Richard Phipps
Member #1,632
November 2001
|
set_palette can cause the program to wait for a fresh vertical blank interrupt before changing the colours which can halve your frame rate. However, unless your palette changes you only need to call it once outside your main loop. Do not call the function inside your main loop! |
Kitty Cat
Member #2,815
October 2002
|
Also set the color depth before setting the gfx mode. On another note, you're allocating 1000 stars, but only using 501. 1002 rand() calls may not be that fast, and 501 putpixels may not be fast either. -- |
CIRCLE
Member #5,301
December 2004
|
Blit is your problem. It is slow.
first off I don't have that background.pcx so I had to "invent one" and when I took out the first blit the program ran 2x faster. and instead of blitting I just wrote to the screen. Bad I know but I just wanted to see it faster. -I edit a lot. Prepare thyself. |
ImLeftFooted
Member #3,935
October 2003
|
Generally, when pasting source code its nice to encapsulate them in [code] tags. Like so: <code> void foobar(int); int var = 5; foobar(5 * 2); </code>
|
gnolam
Member #2,030
March 2002
|
Don't draw directly to the screen. Just don't. -- |
Kitty Cat
Member #2,815
October 2002
|
Quote: Blit is your problem. It is slow. Only because of how he's using it. The buffer is created as a 16-bit bitmap (since it's called after set_color_depth), but the screen is 8-bit (since set_gfx_mode is called before). Converting to paletted mode, especially without a lookup table, is excruciatingly slow. -- |
Richard Phipps
Member #1,632
November 2001
|
More problems than you ever wanted to know about eh Gary? |
|