Ticket #8031: move_screen.cpp

File move_screen.cpp, 834 bytes (added by fingolfin, 18 years ago)

Optimized move_screen

Line 
1void OSystem_SDL_Common::move_screen(int dx, int dy, int height) {
2
3 if ((dx == 0) && (dy == 0))
4 return;
5
6 /* FIXME: undraw mouse only if the draw rect intersects with the mouse rect */
7 if (_mouse_drawn)
8 undraw_mouse();
9
10 if (SDL_LockSurface(sdl_screen) == -1)
11 error("SDL_LockSurface failed: %s.\n", SDL_GetError());
12
13 int offset = dx + dy * SCREEN_WIDTH;
14 byte *src;
15
16 int w;
17 int pitch;
18
19 if (dy < 0)
20 w = SCREEN_WIDTH + dy;
21 else
22 w = SCREEN_WIDTH - dy;
23
24 if (offset > 0) {
25 // bottom to top
26 src = (byte *)sdl_screen->pixels + SCREEN_WIDTH * (SCREEN_HEIGHT - 1);
27 pitch = -SCREEN_WIDTH;
28 } else if (offset < 0) {
29 // top to bottom
30 src = (byte *)sdl_screen->pixels - offset;
31 pitch = SCREEN_WIDTH;
32 }
33
34 do {
35 memmove(src + offset, src, w);
36 src += pitch;
37 } while (--height);
38
39 SDL_UnlockSurface(sdl_screen);
40}