author | koda |
Wed, 30 Jun 2010 23:27:18 +0200 | |
changeset 3599 | 715a43602da8 |
parent 3595 | 341e407e3754 |
child 3612 | b50215a8a43d |
permissions | -rw-r--r-- |
1806 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
3 |
* Copyright (c) 2009 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
2599 | 19 |
{$INCLUDE "options.inc"} |
2587
0dfa56a8513c
fix a segfault in the iphone simulator by moving options.inc at the beginning of the file
koda
parents:
2376
diff
changeset
|
20 |
|
1806 | 21 |
unit uLandTexture; |
22 |
interface |
|
1807 | 23 |
uses SDLh; |
1806 | 24 |
|
1807 | 25 |
procedure UpdateLandTexture(X, Width, Y, Height: LongInt); |
26 |
procedure DrawLand(dX, dY: LongInt); |
|
27 |
procedure FreeLand; |
|
1806 | 28 |
|
29 |
implementation |
|
3165
3ec07a7d8456
just some very sane stuff for the iphone port (plus some macro on pascal files)
koda
parents:
3045
diff
changeset
|
30 |
uses uMisc, uLand, uStore, uConsts, GLunit; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2599
diff
changeset
|
31 |
|
1807 | 32 |
|
33 |
const TEXSIZE = 256; |
|
3509
d72c2219595d
Make land types flagged (to allow stacking future attributes such as indestructible ice, but also for a damaged flag)
nemo
parents:
3491
diff
changeset
|
34 |
{$IFDEF DOWNSCALE} |
d72c2219595d
Make land types flagged (to allow stacking future attributes such as indestructible ice, but also for a damaged flag)
nemo
parents:
3491
diff
changeset
|
35 |
LANDTEXARW = (LAND_WIDTH div TEXSIZE) div 2; |
d72c2219595d
Make land types flagged (to allow stacking future attributes such as indestructible ice, but also for a damaged flag)
nemo
parents:
3491
diff
changeset
|
36 |
LANDTEXARH = (LAND_HEIGHT div TEXSIZE) div 2; |
d72c2219595d
Make land types flagged (to allow stacking future attributes such as indestructible ice, but also for a damaged flag)
nemo
parents:
3491
diff
changeset
|
37 |
{$ELSE} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
38 |
LANDTEXARW = LAND_WIDTH div TEXSIZE; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
39 |
LANDTEXARH = LAND_HEIGHT div TEXSIZE; |
3509
d72c2219595d
Make land types flagged (to allow stacking future attributes such as indestructible ice, but also for a damaged flag)
nemo
parents:
3491
diff
changeset
|
40 |
{$ENDIF} |
1806 | 41 |
|
1807 | 42 |
var |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
43 |
LandTextures: array[0..LANDTEXARW - 1, 0..LANDTEXARH - 1] of |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
44 |
record |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
45 |
shouldUpdate: boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
46 |
tex: PTexture; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
47 |
end; |
1807 | 48 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
49 |
tmpPixels: array [0..TEXSIZE - 1, 0..TEXSIZE - 1] of LongWord; |
1806 | 50 |
|
1807 | 51 |
function Pixels(x, y: Longword): Pointer; |
52 |
var ty: Longword; |
|
1806 | 53 |
begin |
1807 | 54 |
for ty:= 0 to TEXSIZE - 1 do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
55 |
Move(LandPixels[y * TEXSIZE + ty, x * TEXSIZE], tmpPixels[ty, 0], sizeof(Longword) * TEXSIZE); |
2376 | 56 |
|
1807 | 57 |
Pixels:= @tmpPixels |
58 |
end; |
|
1806 | 59 |
|
1859
e071284b118e
Pixels2 proc, which uses Land array when updating textures
unc0rr
parents:
1852
diff
changeset
|
60 |
function Pixels2(x, y: Longword): Pointer; |
e071284b118e
Pixels2 proc, which uses Land array when updating textures
unc0rr
parents:
1852
diff
changeset
|
61 |
var tx, ty: Longword; |
e071284b118e
Pixels2 proc, which uses Land array when updating textures
unc0rr
parents:
1852
diff
changeset
|
62 |
begin |
e071284b118e
Pixels2 proc, which uses Land array when updating textures
unc0rr
parents:
1852
diff
changeset
|
63 |
for ty:= 0 to TEXSIZE - 1 do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
64 |
for tx:= 0 to TEXSIZE - 1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
65 |
tmpPixels[ty, tx]:= Land[y * TEXSIZE + ty, x * TEXSIZE + tx] or AMask; |
2376 | 66 |
|
1859
e071284b118e
Pixels2 proc, which uses Land array when updating textures
unc0rr
parents:
1852
diff
changeset
|
67 |
Pixels2:= @tmpPixels |
e071284b118e
Pixels2 proc, which uses Land array when updating textures
unc0rr
parents:
1852
diff
changeset
|
68 |
end; |
e071284b118e
Pixels2 proc, which uses Land array when updating textures
unc0rr
parents:
1852
diff
changeset
|
69 |
|
1807 | 70 |
procedure UpdateLandTexture(X, Width, Y, Height: LongInt); |
71 |
var tx, ty: Longword; |
|
72 |
begin |
|
3595
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
73 |
if (Width <= 0) or (Height <= 0) then exit; |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
74 |
TryDo((X >= 0) and (X < LAND_WIDTH), 'UpdateLandTexture: wrong X parameter', true); |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
75 |
TryDo(X + Width <= LAND_WIDTH, 'UpdateLandTexture: wrong Width parameter', true); |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
76 |
TryDo((Y >= 0) and (Y < LAND_HEIGHT), 'UpdateLandTexture: wrong Y parameter', true); |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
77 |
TryDo(Y + Height <= LAND_HEIGHT, 'UpdateLandTexture: wrong Height parameter', true); |
1806 | 78 |
|
3595
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
79 |
if (cReducedQuality and rqBlurryLand) = 0 then |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
80 |
for ty:= Y div TEXSIZE to (Y + Height - 1) div TEXSIZE do |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
81 |
for tx:= X div TEXSIZE to (X + Width - 1) div TEXSIZE do |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
82 |
LandTextures[tx, ty].shouldUpdate:= true |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
83 |
else |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
84 |
for ty:= (Y div TEXSIZE) div 2 to ((Y + Height - 1) div TEXSIZE) div 2 do |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
85 |
for tx:= (X div TEXSIZE) div 2 to ((X + Width - 1) div TEXSIZE) div 2 do |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
86 |
LandTextures[tx, ty].shouldUpdate:= true; |
1806 | 87 |
end; |
88 |
||
89 |
procedure RealLandTexUpdate; |
|
1807 | 90 |
var x, y: LongWord; |
1806 | 91 |
begin |
1807 | 92 |
if LandTextures[0, 0].tex = nil then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
93 |
for x:= 0 to LANDTEXARW -1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
94 |
for y:= 0 to LANDTEXARH - 1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
95 |
with LandTextures[x, y] do |
3491 | 96 |
begin |
97 |
tex:= NewTexture(TEXSIZE, TEXSIZE, Pixels(x, y)); |
|
98 |
glBindTexture(GL_TEXTURE_2D, tex^.id); |
|
99 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, tpHigh); |
|
100 |
end |
|
1806 | 101 |
else |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
102 |
for x:= 0 to LANDTEXARW -1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
103 |
for y:= 0 to LANDTEXARH - 1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
104 |
with LandTextures[x, y] do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
105 |
if shouldUpdate then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
106 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
107 |
shouldUpdate:= false; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
108 |
glBindTexture(GL_TEXTURE_2D, tex^.id); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
109 |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, TEXSIZE, TEXSIZE, GL_RGBA, GL_UNSIGNED_BYTE, Pixels(x, y)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
110 |
end |
1806 | 111 |
end; |
112 |
||
1807 | 113 |
procedure DrawLand(dX, dY: LongInt); |
114 |
var x, y: LongInt; |
|
1806 | 115 |
begin |
116 |
RealLandTexUpdate; |
|
1807 | 117 |
|
118 |
for x:= 0 to LANDTEXARW -1 do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
119 |
for y:= 0 to LANDTEXARH - 1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
120 |
with LandTextures[x, y] do |
3595
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
121 |
if (cReducedQuality and rqBlurryLand) = 0 then |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
122 |
DrawTexture(dX + x * TEXSIZE, dY + y * TEXSIZE, tex) |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
123 |
else |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
124 |
DrawTexture(dX + x * TEXSIZE * 2, dY + y * TEXSIZE * 2, tex, 2.0) |
341e407e3754
partially removing DOWNSCALE ifdef -- only two remain and their removal requires dynamic allocation (btw this breaks low quality mode)
koda
parents:
3513
diff
changeset
|
125 |
|
1807 | 126 |
end; |
127 |
||
128 |
procedure FreeLand; |
|
129 |
var x, y: LongInt; |
|
130 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
131 |
for x:= 0 to LANDTEXARW -1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
132 |
for y:= 0 to LANDTEXARH - 1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
133 |
with LandTextures[x, y] do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
134 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
135 |
FreeTexture(tex); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
136 |
tex:= nil; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
137 |
end; |
3045 | 138 |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3509
diff
changeset
|
139 |
if LandBackSurface <> nil then |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3509
diff
changeset
|
140 |
SDL_FreeSurface(LandBackSurface); |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3509
diff
changeset
|
141 |
LandBackSurface:= nil; |
1806 | 142 |
end; |
143 |
||
144 |
end. |