I''m writing a game and I have this one function that''s bottlenecking it a bit. The game is pretty simple, 2D, and it runs fast on all my computers, but I''m betting on a really slow Pentium or lower it won''t be so good. The function I have copies a segment of a background image (the background buffer) to the secondary DirectDraw surface (the back buffer) and the copy is a bit slow. The background picture is 1280x480 (that''s not too big) and the back buffer and the screen resolution are 640x480... so i had to make some functions to pan the screen on the x-axis so you can look at the whole background. The part that copies the background buffer to the back buffer is a little slow because it uses ''memcpy'' and it has to copy the buffer line by line. Here''s the exact function I have in my game:
inline void Copy_Background()
// lock back surface
// get a copy of the memory addresses
UCHAR *video_ptr = back_buffer;
UCHAR *bg_ptr = bg_buffer;
// advance pointer to beginning of the pan
// copy line by line...very slow
for (int y=0; y<480; y++)
// copy 640 bytes from b.g. to back buffer
memcpy((void *)video_ptr,(void *)bg_ptr,640);
// advance to next line which is ''memory pitch'' bytes away
// advance to next line in background buffer
} // end for y
// unlock surface
} // end Copy_Background
Of course this could be helluva faster... so if anyone knows how i can make it faster and more efficient, please help me out. I was thinking assembly language and DWORDs, but I don''t know a damn thing about assembly and I''m not even that good at C/C++, so I''m pretty lost. I was also thinking of putting the background buffer in VRAM so then I would just have to copy vram to vram and that would be helluva fast, but I''m not sure how to do that either. The only other thing I was thinking was making the background buffer another DirectDraw surface, but I never have to blit anything on to it... i only copy it to the screen, so i don''t know if that would be any better.
I would appreciate any help.
One way you can do it is load up the image wich is 1280 x 480 on a of screen surface. Then using the Direct Draw BLT rutin from one surace to the other should speed up stuff alot.
Also what you can do is, since vidoe cards are getting more and more ram, when you create your surface, try to create always in video ram, through a simple is else if the creation failed you create in sys ram. One thing is comuter arent getting slower but only faster so even if the surface is in sys ram I dont think you will loose to much speed!
My say right now is: "If the have a pentium 1 generation computer they should even be playing games no more!"
I''ll probably just make it into a surface like you suggested. That was one of the ideas I listed in my first post. When I was first writing the code I thought about making the background a surface, but it never happened. I guess I''m too used to old DOS stuff and I just started learning DirectDraw... actually I just started learning C/C++ last summer. Anyway.. I''ll try your method. I''m going to have to look up some API functions because the graphics library i''m using right now I didn''t write. It''s from the book ''Tricks of the Windows Game Programming Gurus''.