1 | /* |
---|
2 | * Abuse - dark 2D side-scrolling platform game |
---|
3 | * Copyright (c) 2001 Anthony Kruize <trandor@labyrinth.net.au> |
---|
4 | * Copyright (c) 2005-2013 Sam Hocevar <sam@hocevar.net> |
---|
5 | * |
---|
6 | * This program is free software; you can redistribute it and/or modify |
---|
7 | * it under the terms of the GNU General Public License as published by |
---|
8 | * the Free Software Foundation; either version 2 of the License, or |
---|
9 | * (at your option) any later version. |
---|
10 | * |
---|
11 | * This program is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | * GNU General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU General Public License |
---|
17 | * along with this program; if not, write to the Free Software Foundation, |
---|
18 | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
---|
19 | */ |
---|
20 | |
---|
21 | #if HAVE_CONFIG_H |
---|
22 | # include "config.h" |
---|
23 | #endif |
---|
24 | |
---|
25 | #include "common.h" |
---|
26 | |
---|
27 | #include "imlib/filter.h" |
---|
28 | #include "imlib/video.h" |
---|
29 | #include "imlib/image.h" |
---|
30 | |
---|
31 | #include "setup.h" |
---|
32 | |
---|
33 | array<uint8_t> g_screen; |
---|
34 | |
---|
35 | AImage *main_screen = NULL; |
---|
36 | int mouse_xscale, mouse_yscale; |
---|
37 | int xres, yres; |
---|
38 | |
---|
39 | extern Palette *lastl; |
---|
40 | extern flags_struct flags; |
---|
41 | |
---|
42 | // |
---|
43 | // CreateScreen() |
---|
44 | // Set the video mode |
---|
45 | // |
---|
46 | void CreateScreen(int argc, char **argv) |
---|
47 | { |
---|
48 | mouse_xscale = 1 << 16; |
---|
49 | mouse_yscale = 1 << 16; |
---|
50 | |
---|
51 | /* Temporary screen buffer */ |
---|
52 | g_screen.Resize(xres * yres); |
---|
53 | |
---|
54 | // Create the screen image |
---|
55 | main_screen = new AImage(ivec2(xres, yres), 2); |
---|
56 | if (main_screen == NULL) |
---|
57 | { |
---|
58 | // Our screen image is no good, we have to bail. |
---|
59 | printf("Video : Unable to create screen image.\n"); |
---|
60 | exit(1); |
---|
61 | } |
---|
62 | main_screen->clear(); |
---|
63 | |
---|
64 | update_dirty(main_screen); |
---|
65 | } |
---|
66 | |
---|
67 | // |
---|
68 | // DestroyScreen() |
---|
69 | // Shutdown the video mode |
---|
70 | // |
---|
71 | void DestroyScreen() |
---|
72 | { |
---|
73 | if (lastl) |
---|
74 | delete lastl; |
---|
75 | lastl = NULL; |
---|
76 | |
---|
77 | delete main_screen; |
---|
78 | } |
---|
79 | |
---|
80 | // put_part_image() |
---|
81 | // Draw only dirty parts of the image to screen |
---|
82 | // |
---|
83 | void put_part_image(AImage *im, int x, int y, int x1, int y1, int x2, int y2) |
---|
84 | { |
---|
85 | int xe, ye; |
---|
86 | int srcx, srcy; |
---|
87 | uint8_t *dpixel; |
---|
88 | |
---|
89 | if (y > yres || x > xres) |
---|
90 | return; |
---|
91 | |
---|
92 | ASSERT(x1 >= 0); |
---|
93 | ASSERT(x2 >= x1); |
---|
94 | ASSERT(y1 >= 0); |
---|
95 | ASSERT(y2 >= y1); |
---|
96 | |
---|
97 | // Adjust if we are trying to draw off the screen |
---|
98 | if (x < 0) |
---|
99 | { |
---|
100 | x1 += -x; |
---|
101 | x = 0; |
---|
102 | } |
---|
103 | srcx = x1; |
---|
104 | if (x + (x2 - x1) >= xres) |
---|
105 | xe = xres - x + x1 - 1; |
---|
106 | else |
---|
107 | xe = x2; |
---|
108 | |
---|
109 | if (y < 0) |
---|
110 | { |
---|
111 | y1 += -y; |
---|
112 | y = 0; |
---|
113 | } |
---|
114 | srcy = y1; |
---|
115 | if (y + (y2 - y1) >= yres) |
---|
116 | ye = yres - y + y1 - 1; |
---|
117 | else |
---|
118 | ye = y2; |
---|
119 | |
---|
120 | if (srcx >= xe || srcy >= ye) |
---|
121 | return; |
---|
122 | |
---|
123 | int w = xe - srcx; |
---|
124 | int h = ye - srcy; |
---|
125 | |
---|
126 | dpixel = g_screen.Data() + x + y * xres; |
---|
127 | |
---|
128 | // Update surface part |
---|
129 | for (int i = 0; i < h; i++) |
---|
130 | { |
---|
131 | memcpy(dpixel, im->scan_line(srcy) + srcx , w); |
---|
132 | dpixel += xres; |
---|
133 | srcy++; |
---|
134 | } |
---|
135 | } |
---|
136 | |
---|
137 | // ---- support functions ---- |
---|
138 | |
---|
139 | void UpdateScreen() |
---|
140 | { |
---|
141 | /* FIXME: synchronisation */ |
---|
142 | } |
---|
143 | |
---|