28 procedure DrawLand(dX, dY: LongInt); |
28 procedure DrawLand(dX, dY: LongInt); |
29 procedure ResetLand; |
29 procedure ResetLand; |
30 procedure SetLandTexture; |
30 procedure SetLandTexture; |
31 |
31 |
32 implementation |
32 implementation |
33 uses uConsts, GLunit, uTypes, uVariables, uTextures, uDebug, uRender; |
33 uses uConsts, GLunit, uTypes, uVariables, uTextures, uDebug, uRender, uUtils; |
34 |
34 |
35 const TEXSIZE = 128; |
35 const TEXSIZE = 128; |
36 // in avoid tile borders stretch the blurry texture by 1 pixel more |
36 // in avoid tile borders stretch the blurry texture by 1 pixel more |
37 BLURRYLANDOVERLAP: real = 1 / TEXSIZE / 2.0; // 1 pixel divided by texsize and blurry land scale factor |
37 BLURRYLANDOVERLAP: real = 1 / TEXSIZE / 2.0; // 1 pixel divided by texsize and blurry land scale factor |
38 |
38 |
171 end; |
171 end; |
172 end |
172 end |
173 end; |
173 end; |
174 |
174 |
175 procedure DrawLand(dX, dY: LongInt); |
175 procedure DrawLand(dX, dY: LongInt); |
176 var x, y, tX, ty, tSize, offscreen: LongInt; |
176 var x, y, tX, ty, tSize, fx, lx, fy, ly: LongInt; |
177 tScale: GLfloat; |
177 tScale: GLfloat; |
178 overlap: boolean; |
178 overlap: boolean; |
179 begin |
179 begin |
180 RealLandTexUpdate; |
180 RealLandTexUpdate; |
181 |
181 |
191 tSize:= TEXSIZE; |
191 tSize:= TEXSIZE; |
192 tScale:= 1.0; |
192 tScale:= 1.0; |
193 overlap:= false; |
193 overlap:= false; |
194 end; |
194 end; |
195 |
195 |
196 tX:= dX; |
196 // figure out visible area |
197 |
197 // first column |
198 // loop through all columns |
198 tx:= ViewLeftX - dx; |
199 for x:= 0 to LANDTEXARW -1 do |
199 fx:= tx div tSize; |
|
200 if tx < 0 then dec(fx); |
|
201 fx:= max(0, fx); |
|
202 |
|
203 // last column |
|
204 tx:= ViewRightX - dx; |
|
205 lx:= tx div tSize; |
|
206 if tx < 0 then dec(lx); |
|
207 lx:= min(LANDTEXARW -1, lx); |
|
208 |
|
209 // all offscreen |
|
210 if (fx > lx) then |
|
211 exit; |
|
212 |
|
213 // first row |
|
214 ty:= ViewTopY - dy; |
|
215 fy:= ty div tSize; |
|
216 if ty < 0 then dec(fy); |
|
217 fy:= max(0, fy); |
|
218 |
|
219 // last row |
|
220 ty:= ViewBottomY - dy; |
|
221 ly:= ty div tSize; |
|
222 if ty < 0 then dec(ly); |
|
223 ly:= min(LANDTEXARH -1, ly); |
|
224 |
|
225 // all offscreen |
|
226 if (fy > ly) then |
|
227 exit; |
|
228 |
|
229 tX:= dX + tsize * fx; |
|
230 |
|
231 // loop through columns |
|
232 for x:= fx to lx do |
200 begin |
233 begin |
201 |
234 // loop through textures in this column |
202 // don't draw column if offscreen |
235 for y:= fy to ly do |
203 offscreen:= isDxAreaOffscreen(tX, tSize); |
236 with LandTextures[x, y] do |
204 |
237 if tex <> nil then |
205 if offscreen = 0 then |
238 begin |
206 begin |
239 ty:= dY + y * tSize; |
207 // loop through all textures in this column |
240 if overlap then |
208 for y:= 0 to LANDTEXARH - 1 do |
241 DrawTexture2(tX, ty, tex, tScale, BLURRYLANDOVERLAP) |
209 with LandTextures[x, y] do |
242 else |
210 if tex <> nil then |
243 DrawTexture(tX, ty, tex, tScale); |
211 begin |
244 end; |
212 ty:= dY + y * tSize; |
245 |
213 |
246 // increment tX |
214 // don't draw texture if offscreen |
|
215 offscreen:= isDyAreaOffscreen(tY, tSize); |
|
216 |
|
217 if offscreen = 0 then |
|
218 begin |
|
219 if overlap then |
|
220 DrawTexture2(tX, ty, tex, tScale, BLURRYLANDOVERLAP) |
|
221 else |
|
222 DrawTexture(tX, ty, tex, tScale); |
|
223 end |
|
224 |
|
225 // if below screen, skip remaining textures in this column |
|
226 else if offscreen > 1 then |
|
227 break; |
|
228 end; |
|
229 |
|
230 end |
|
231 // if right of screen, skip remaining columns |
|
232 else if offscreen > 0 then |
|
233 break; |
|
234 |
|
235 // increment texX |
|
236 inc(tX, tSize); |
247 inc(tX, tSize); |
237 end; |
248 end; |
238 end; |
249 end; |
239 |
250 |
240 procedure SetLandTexture; |
251 procedure SetLandTexture; |