/[cvs]/api/Classes/Graphic2d/DrawSprite.cpp
ViewVC logotype

Contents of /api/Classes/Graphic2d/DrawSprite.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Sun Jul 1 20:47:58 2001 UTC (23 years ago) by bearsoft
Branch: lazy, MAIN
CVS Tags: start, HEAD
Changes since 1.1: +0 -0 lines
First import

1 #include "DrawSprite.h"
2 #include "../Screen/ScreenData.h"
3
4 DrawSprite::DrawSprite(){};
5 DrawSprite::~DrawSprite(){};
6
7 void DrawSprite::sprite(SGI *sgi, int xPosition, int yPosition)
8 {
9 sprite(ScreenData::getChunkyBuffer(), xPosition, yPosition, ScreenData::getWidth(), ScreenData::getHeight(), sgi->getBuffer(), sgi->getWidth(), sgi->getHeight(), ScreenData::getWidth(), ScreenData::getHeight(), 0, 0, ScreenData::getBitPlan());
10 }
11
12 void DrawSprite::sprite(int *chunkybuffer, int xp, int yp, int scwidth, int scheight, int *spritedata, int spritewidth, int spriteheight, int width, int height, int scrollxadd, int scrollyadd , int bitplan)
13 {
14 unsigned char *cchunkybuffer=(unsigned char*)chunkybuffer;
15 unsigned char *cspritedata=(unsigned char*)spritedata;
16
17 int xc,yc,xs,ys;
18 int cb=0;
19 int sd=0;
20
21 if ( xp < width && xp >= -spritewidth)
22 {
23
24 if ( yp < height && yp >= -spriteheight)
25 {
26
27 cb+=xp;
28 cb+=(yp*width);
29
30 xc=spritewidth;
31
32 if ( xp < 0 )
33 {
34 cb-=xp;
35 xc+=xp;
36 sd-=xp;
37 }
38
39 if ( (xp+xc) > scwidth )
40 {
41 xs = (xp+xc) - scwidth;
42 xc-=xs;
43 }
44
45 yc=spriteheight;
46
47 if ( yp < 0 )
48 {
49 cb-=(yp*width);
50 yc = yc + yp;
51 sd-=(yp*spritewidth);
52 }
53
54
55 if ( (yp+yc) > scheight )
56 {
57 ys = (yp+yc) - scheight;
58 yc-=ys;
59 }
60
61 cb+=scrollxadd;
62 cb+=scrollyadd*width;
63
64 if ( bitplan == 8 )
65 {
66 sprite_8(cchunkybuffer, cspritedata, xc, yc, spritewidth, width, cb, sd );
67 }
68
69 if ( bitplan == 32 )
70 {
71 sprite_32(chunkybuffer, spritedata, xc, yc, spritewidth, width, cb, sd );
72 }
73 }
74 }
75 }
76
77 void DrawSprite::sprite_8(unsigned char *cchunkybuffer, unsigned char *cspritedata, int xc, int yc, int spritewidth, int width, int cb, int sd )
78 {
79 for ( int d6l=0 ; d6l<yc; d6l++ )
80 {
81 for ( int d7l=0 ;d7l<xc ; d7l++ )
82 {
83 if ( cspritedata[sd] != 0 )
84 {
85 cchunkybuffer[cb]=cspritedata[sd];
86 }
87
88 cb++;
89 sd++;
90
91 }
92 sd+=(spritewidth-xc);
93 cb+=(width-xc);
94 }
95 }
96
97 void DrawSprite::sprite_32(int *chunkybuffer, int *spritedata, int xc, int yc, int spritewidth, int width, int cb, int sd )
98 {
99 for ( int d6l=0 ; d6l<yc; d6l++ )
100 {
101 for ( int d7l=0 ;d7l<xc ; d7l++ )
102 {
103 if ( spritedata[sd] != 0 )
104 {
105 chunkybuffer[cb]=spritedata[sd];
106 }
107
108 cb++;
109 sd++;
110 }
111
112 sd+=(spritewidth-xc);
113 cb+=(width-xc);
114 }
115 }
116
117 void DrawSprite::sprite2(int *chunkybuffer, int xp, int yp, int scwidth, int scheight, int *spritedata, int spritewidth, int spriteheight, int width, int height, int scrollxadd, int scrollyadd , int bitplan)
118 {
119 unsigned char *cchunkybuffer=(unsigned char*)chunkybuffer;
120 unsigned char *cspritedata=(unsigned char*)spritedata;
121
122 int xc,yc,xs,ys;
123 int cb=0;
124 int sd=0;
125
126 if ( xp < width && xp >= -spritewidth)
127 {
128 if ( yp < height && yp >= -spriteheight)
129 {
130
131 cb+=xp;
132 cb+=(yp*width);
133
134 xc=spritewidth;
135
136 if ( xp < 0 )
137 {
138 cb-=xp;
139 xc+=xp;
140 sd-=xp;
141 }
142
143 if ( (xp+xc) > scwidth )
144 {
145 xs=(xp+xc) - scwidth;
146 xc-=xs;
147 }
148
149 yc=spriteheight;
150
151 if ( yp < 0 )
152 {
153 cb-=(yp*width);
154 yc+=yp;
155 sd-=(yp*spritewidth);
156 }
157
158
159 if ( (yp+yc) > scheight )
160 {
161 ys = (yp+yc) - scheight;
162 yc-=ys;
163 }
164
165 cb+=scrollxadd;
166 cb+=scrollyadd*width;
167
168 if ( bitplan == 8 )
169 {
170 sprite2_8(cchunkybuffer, cspritedata, xc, yc, spritewidth, width, cb, sd );
171 }
172
173 if ( bitplan == 32 )
174 {
175 sprite_32(chunkybuffer, spritedata, xc, yc, spritewidth, width, cb, sd );
176 }
177 }
178 }
179 }
180
181 void DrawSprite::sprite2_8(unsigned char *cchunkybuffer, unsigned char *cspritedata, int xc, int yc, int spritewidth, int width, int cb, int sd )
182 {
183 int ixc=xc/4;
184 int cxc=xc-(ixc*4);
185
186 cchunkybuffer+=cb;
187 cspritedata+=sd;
188
189 int cwidth=width-xc;
190 int cspritewidth=spritewidth-xc;
191
192 for ( int d6l=0 ; d6l<yc; d6l++ )
193 {
194 int *intchunkybuffer=(int*)cchunkybuffer;
195 int *intspritedata=(int*)cspritedata;
196
197 for ( int d7l=0 ;d7l<ixc ; d7l++ )
198 {
199 intchunkybuffer[0]=intspritedata[0];
200 intchunkybuffer++;
201 intspritedata++;
202 }
203
204 cchunkybuffer=(unsigned char*)intchunkybuffer;
205 cspritedata=(unsigned char*)intspritedata;
206
207 for ( int d3l=0 ;d3l<cxc ; d3l++ )
208 {
209 cchunkybuffer[0]=cspritedata[0];
210 cchunkybuffer++;
211 cspritedata++;
212 }
213
214 cchunkybuffer+=cwidth;
215 cspritedata+=cspritewidth;
216 }
217 }
218
219 void DrawSprite::sprite2_32(int *chunkybuffer, int *spritedata, int xc, int yc, int spritewidth, int width, int cb, int sd )
220 {
221 for ( int d6l=0 ; d6l<yc; d6l++ )
222 {
223 for ( int d7l=0 ;d7l<xc ; d7l++ )
224 {
225 chunkybuffer[cb]=spritedata[sd];
226 cb++;
227 sd++;
228 }
229 sd+=(spritewidth-xc);
230 cb+=(width-xc);
231 }
232 }
233
234 void DrawSprite::clearScreen(int *chunkybuffer, int screenwidth, int screenheight, int colour, int bitplan)
235 {
236 if ( bitplan == 8 )
237 {
238 char *cchunkybuffer=(char*)chunkybuffer;
239 char ccolour=(char)colour;
240
241 for ( int y=0 ; y<screenheight ; y++ )
242 {
243 for ( int x=0; x<screenwidth ; x++ )
244 {
245 cchunkybuffer[x+y*screenwidth]=ccolour;
246 }
247 }
248 }
249
250 if ( bitplan == 32 )
251 {
252 for ( int y=0 ; y<screenheight ; y++ )
253 {
254 for ( int x=0; x<screenwidth ; x++ )
255 {
256 chunkybuffer[x+y*screenwidth]=colour;
257 }
258 }
259 }
260 }
261

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26