author | antonc27 <antonc27@mail.ru> |
Fri, 30 Oct 2015 21:08:05 +0100 | |
branch | ios-revival |
changeset 11264 | 1568f9eff980 |
parent 11046 | 47a8c19ecb60 |
child 11317 | 62287d4044e7 |
permissions | -rw-r--r-- |
1806 | 1 |
(* |
2 |
* Hedgewars, a free turn based strategy game |
|
11046 | 3 |
* Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com> |
1806 | 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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
10040
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
1806 | 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 |
|
3612
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
25 |
procedure initModule; |
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
26 |
procedure freeModule; |
7170
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
27 |
procedure UpdateLandTexture(X, Width, Y, Height: LongInt; landAdded: boolean); |
1807 | 28 |
procedure DrawLand(dX, dY: LongInt); |
5654 | 29 |
procedure ResetLand; |
7850 | 30 |
procedure SetLandTexture; |
1806 | 31 |
|
32 |
implementation |
|
10267 | 33 |
uses uConsts, GLunit, uTypes, uVariables, uTextures, uDebug, uRender, uUtils; |
1807 | 34 |
|
7172
f68d62711a5c
After experimenting with a long running average at maxed out FPS and a variety of map sizes, 128 seems to actually be a good size to use if only drawing bits of world with stuff in it. 64 actually did even better in some situations, but significantly worse in others (lots of land, zoomed out).
nemo
parents:
7170
diff
changeset
|
35 |
const TEXSIZE = 128; |
10020
67e127027af6
small tweak/hax for blurry land to make tile borders vanish (when clamping is off)
sheepluva
parents:
9998
diff
changeset
|
36 |
// in avoid tile borders stretch the blurry texture by 1 pixel more |
10124
aabd1b75d5a3
Even more explicit type conversions and other stuff to help pas2c use ansistrings
unc0rr
parents:
10108
diff
changeset
|
37 |
BLURRYLANDOVERLAP: real = 1 / TEXSIZE / 2.0; // 1 pixel divided by texsize and blurry land scale factor |
1806 | 38 |
|
3612
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
39 |
type TLandRecord = record |
7170
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
40 |
shouldUpdate, landAdded: boolean; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
41 |
tex: PTexture; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
42 |
end; |
3615 | 43 |
|
3612
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
44 |
var LandTextures: array of array of TLandRecord; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
45 |
tmpPixels: array [0..TEXSIZE - 1, 0..TEXSIZE - 1] of LongWord; |
3615 | 46 |
LANDTEXARW: LongWord; |
3612
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
47 |
LANDTEXARH: LongWord; |
3697 | 48 |
|
1807 | 49 |
function Pixels(x, y: Longword): Pointer; |
50 |
var ty: Longword; |
|
1806 | 51 |
begin |
1807 | 52 |
for ty:= 0 to TEXSIZE - 1 do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
53 |
Move(LandPixels[y * TEXSIZE + ty, x * TEXSIZE], tmpPixels[ty, 0], sizeof(Longword) * TEXSIZE); |
2376 | 54 |
|
1807 | 55 |
Pixels:= @tmpPixels |
56 |
end; |
|
1806 | 57 |
|
1859
e071284b118e
Pixels2 proc, which uses Land array when updating textures
unc0rr
parents:
1852
diff
changeset
|
58 |
function Pixels2(x, y: Longword): Pointer; |
e071284b118e
Pixels2 proc, which uses Land array when updating textures
unc0rr
parents:
1852
diff
changeset
|
59 |
var tx, ty: Longword; |
e071284b118e
Pixels2 proc, which uses Land array when updating textures
unc0rr
parents:
1852
diff
changeset
|
60 |
begin |
e071284b118e
Pixels2 proc, which uses Land array when updating textures
unc0rr
parents:
1852
diff
changeset
|
61 |
for ty:= 0 to TEXSIZE - 1 do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
62 |
for tx:= 0 to TEXSIZE - 1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
63 |
tmpPixels[ty, tx]:= Land[y * TEXSIZE + ty, x * TEXSIZE + tx] or AMask; |
2376 | 64 |
|
1859
e071284b118e
Pixels2 proc, which uses Land array when updating textures
unc0rr
parents:
1852
diff
changeset
|
65 |
Pixels2:= @tmpPixels |
e071284b118e
Pixels2 proc, which uses Land array when updating textures
unc0rr
parents:
1852
diff
changeset
|
66 |
end; |
e071284b118e
Pixels2 proc, which uses Land array when updating textures
unc0rr
parents:
1852
diff
changeset
|
67 |
|
7170
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
68 |
procedure UpdateLandTexture(X, Width, Y, Height: LongInt; landAdded: boolean); |
1807 | 69 |
var tx, ty: Longword; |
10270 | 70 |
tSize : LongInt; |
1807 | 71 |
begin |
8027
e5ba3dd12531
make stats-only mode work headless. also skip a few things to save time/memory.
nemo
parents:
7850
diff
changeset
|
72 |
if cOnlyStats then exit; |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6383
diff
changeset
|
73 |
if (Width <= 0) or (Height <= 0) then |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6383
diff
changeset
|
74 |
exit; |
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
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
TryDo(Y + Height <= LAND_HEIGHT, 'UpdateLandTexture: wrong Height parameter', true); |
1806 | 79 |
|
10270 | 80 |
tSize:= TEXSIZE; |
81 |
||
82 |
// land textures have half the size/resolution in blurry mode |
|
83 |
if (cReducedQuality and rqBlurryLand) <> 0 then |
|
84 |
tSize:= tSize * 2; |
|
85 |
||
86 |
for ty:= Y div tSize to (Y + Height - 1) div tSize do |
|
87 |
for tx:= X div tSize to (X + Width - 1) div tSize do |
|
88 |
begin |
|
89 |
if not LandTextures[tx, ty].shouldUpdate then |
|
7170
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
90 |
begin |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
91 |
LandTextures[tx, ty].shouldUpdate:= true; |
10270 | 92 |
inc(dirtyLandTexCount); |
93 |
end; |
|
94 |
LandTextures[tx, ty].landAdded:= landAdded |
|
95 |
end; |
|
1806 | 96 |
end; |
97 |
||
10268
1155384a4e31
"<unC0Rr> could also refuse to update textures when land changes if the tile isn't visible"
sheepluva
parents:
10267
diff
changeset
|
98 |
procedure RealLandTexUpdate(x1, x2, y1, y2: LongInt); |
7170
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
99 |
var x, y, ty, tx, lx, ly : LongWord; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
100 |
isEmpty: boolean; |
1806 | 101 |
begin |
8027
e5ba3dd12531
make stats-only mode work headless. also skip a few things to save time/memory.
nemo
parents:
7850
diff
changeset
|
102 |
if cOnlyStats then exit; |
7170
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
103 |
(* |
1807 | 104 |
if LandTextures[0, 0].tex = nil then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
105 |
for x:= 0 to LANDTEXARW -1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
106 |
for y:= 0 to LANDTEXARH - 1 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
107 |
with LandTextures[x, y] do |
3491 | 108 |
begin |
6580
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6383
diff
changeset
|
109 |
tex:= NewTexture(TEXSIZE, TEXSIZE, Pixels(x, y)); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6383
diff
changeset
|
110 |
glBindTexture(GL_TEXTURE_2D, tex^.id); |
6155187bf599
A partial reformatting of the pascal code to have consistent syntax. Things that are still inconsistent.
lovelacer
parents:
6383
diff
changeset
|
111 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, tpHigh); |
3491 | 112 |
end |
1806 | 113 |
else |
7170
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
114 |
*) |
10268
1155384a4e31
"<unC0Rr> could also refuse to update textures when land changes if the tile isn't visible"
sheepluva
parents:
10267
diff
changeset
|
115 |
for x:= x1 to x2 do |
1155384a4e31
"<unC0Rr> could also refuse to update textures when land changes if the tile isn't visible"
sheepluva
parents:
10267
diff
changeset
|
116 |
for y:= y1 to y2 do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
117 |
with LandTextures[x, y] do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
118 |
if shouldUpdate then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
119 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
120 |
shouldUpdate:= false; |
10270 | 121 |
dec(dirtyLandTexCount); |
7170
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
122 |
isEmpty:= not landAdded; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
123 |
landAdded:= false; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
124 |
ty:= 0; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
125 |
tx:= 1; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
126 |
ly:= y * TEXSIZE; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
127 |
lx:= x * TEXSIZE; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
128 |
// first check edges |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
129 |
while isEmpty and (ty < TEXSIZE) do |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
130 |
begin |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
131 |
isEmpty:= LandPixels[ly + ty, lx] and AMask = 0; |
10494 | 132 |
if isEmpty then isEmpty:= LandPixels[ly + ty, Pred(lx + TEXSIZE)] and AMask = 0; |
7170
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
133 |
inc(ty) |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
134 |
end; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
135 |
while isEmpty and (tx < TEXSIZE-1) do |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
136 |
begin |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
137 |
isEmpty:= LandPixels[ly, lx + tx] and AMask = 0; |
10494 | 138 |
if isEmpty then isEmpty:= LandPixels[Pred(ly + TEXSIZE), lx + tx] and AMask = 0; |
7170
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
139 |
inc(tx) |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
140 |
end; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
141 |
// then search every other remaining. does this sort of stuff defeat compiler opts? |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
142 |
ty:= 2; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
143 |
while isEmpty and (ty < TEXSIZE-1) do |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
144 |
begin |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
145 |
tx:= 2; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
146 |
while isEmpty and (tx < TEXSIZE-1) do |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
147 |
begin |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
148 |
isEmpty:= LandPixels[ly + ty, lx + tx] and AMask = 0; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
149 |
inc(tx,2) |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
150 |
end; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
151 |
inc(ty,2); |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
152 |
end; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
153 |
// and repeat |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
154 |
ty:= 1; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
155 |
while isEmpty and (ty < TEXSIZE-1) do |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
156 |
begin |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
157 |
tx:= 1; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
158 |
while isEmpty and (tx < TEXSIZE-1) do |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
159 |
begin |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
160 |
isEmpty:= LandPixels[ly + ty, lx + tx] and AMask = 0; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
161 |
inc(tx,2) |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
162 |
end; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
163 |
inc(ty,2); |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
164 |
end; |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
165 |
if not isEmpty then |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
166 |
begin |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
167 |
if tex = nil then tex:= NewTexture(TEXSIZE, TEXSIZE, Pixels(x, y)); |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
168 |
glBindTexture(GL_TEXTURE_2D, tex^.id); |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
169 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXSIZE, TEXSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, Pixels(x,y)); |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
170 |
end |
84ac6c6d2d8e
Only create textures for non-empty LandPixel chunks. This should save a fair amount of memory, especially on smaller maps, and eliminate a number of draws
nemo
parents:
7151
diff
changeset
|
171 |
else if tex <> nil then |
10634
35d059bd0932
Use FreeAndNil across the board. Even if we are immediately assigning after, probably avoids accidental mistakes. Also free neglected owner tex on shutdown, and delete hog gears using the normal deletion procedure if for any reason they still exist (EndGame call?).
nemo
parents:
10494
diff
changeset
|
172 |
FreeAndNilTexture(tex); |
10270 | 173 |
|
174 |
// nothing else to do |
|
175 |
if dirtyLandTexCount < 1 then |
|
176 |
exit; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2716
diff
changeset
|
177 |
end |
1806 | 178 |
end; |
179 |
||
1807 | 180 |
procedure DrawLand(dX, dY: LongInt); |
10267 | 181 |
var x, y, tX, ty, tSize, fx, lx, fy, ly: LongInt; |
10266 | 182 |
tScale: GLfloat; |
183 |
overlap: boolean; |
|
1806 | 184 |
begin |
10266 | 185 |
// init values based on quality settings |
186 |
if (cReducedQuality and rqBlurryLand) <> 0 then |
|
187 |
begin |
|
188 |
tSize:= TEXSIZE * 2; |
|
189 |
tScale:= 2.0; |
|
190 |
overlap:= (cReducedQuality and rqClampLess) <> 0; |
|
191 |
end |
|
192 |
else |
|
193 |
begin |
|
194 |
tSize:= TEXSIZE; |
|
195 |
tScale:= 1.0; |
|
196 |
overlap:= false; |
|
197 |
end; |
|
198 |
||
10267 | 199 |
// figure out visible area |
200 |
// first column |
|
201 |
tx:= ViewLeftX - dx; |
|
202 |
fx:= tx div tSize; |
|
203 |
if tx < 0 then dec(fx); |
|
204 |
fx:= max(0, fx); |
|
10266 | 205 |
|
10267 | 206 |
// last column |
207 |
tx:= ViewRightX - dx; |
|
208 |
lx:= tx div tSize; |
|
209 |
if tx < 0 then dec(lx); |
|
210 |
lx:= min(LANDTEXARW -1, lx); |
|
211 |
||
212 |
// all offscreen |
|
213 |
if (fx > lx) then |
|
214 |
exit; |
|
215 |
||
216 |
// first row |
|
217 |
ty:= ViewTopY - dy; |
|
218 |
fy:= ty div tSize; |
|
219 |
if ty < 0 then dec(fy); |
|
220 |
fy:= max(0, fy); |
|
10266 | 221 |
|
10267 | 222 |
// last row |
223 |
ty:= ViewBottomY - dy; |
|
224 |
ly:= ty div tSize; |
|
225 |
if ty < 0 then dec(ly); |
|
226 |
ly:= min(LANDTEXARH -1, ly); |
|
10266 | 227 |
|
10267 | 228 |
// all offscreen |
229 |
if (fy > ly) then |
|
230 |
exit; |
|
231 |
||
10269 | 232 |
// update visible areas of landtex before drawing |
10270 | 233 |
if dirtyLandTexCount > 0 then |
234 |
RealLandTexUpdate(fx, lx, fy, ly); |
|
10268
1155384a4e31
"<unC0Rr> could also refuse to update textures when land changes if the tile isn't visible"
sheepluva
parents:
10267
diff
changeset
|
235 |
|
10267 | 236 |
tX:= dX + tsize * fx; |
10266 | 237 |
|
10267 | 238 |
// loop through columns |
239 |
for x:= fx to lx do |
|
240 |
begin |
|
241 |
// loop through textures in this column |
|
242 |
for y:= fy to ly do |
|
243 |
with LandTextures[x, y] do |
|
244 |
if tex <> nil then |
|
245 |
begin |
|
246 |
ty:= dY + y * tSize; |
|
247 |
if overlap then |
|
248 |
DrawTexture2(tX, ty, tex, tScale, BLURRYLANDOVERLAP) |
|
249 |
else |
|
250 |
DrawTexture(tX, ty, tex, tScale); |
|
251 |
end; |
|
10266 | 252 |
|
10267 | 253 |
// increment tX |
10266 | 254 |
inc(tX, tSize); |
255 |
end; |
|
1807 | 256 |
end; |
257 |
||
7850 | 258 |
procedure SetLandTexture; |
3612
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
259 |
begin |
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
260 |
if (cReducedQuality and rqBlurryLand) = 0 then |
5654 | 261 |
begin |
3612
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
262 |
LANDTEXARW:= LAND_WIDTH div TEXSIZE; |
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
263 |
LANDTEXARH:= LAND_HEIGHT div TEXSIZE; |
5654 | 264 |
end |
3612
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
265 |
else |
5654 | 266 |
begin |
3612
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
267 |
LANDTEXARW:= (LAND_WIDTH div TEXSIZE) div 2; |
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
268 |
LANDTEXARH:= (LAND_HEIGHT div TEXSIZE) div 2; |
5654 | 269 |
end; |
3697 | 270 |
|
3612
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
271 |
SetLength(LandTextures, LANDTEXARW, LANDTEXARH); |
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
272 |
end; |
3697 | 273 |
|
7850 | 274 |
procedure initModule; |
275 |
begin |
|
276 |
end; |
|
277 |
||
5654 | 278 |
procedure ResetLand; |
3615 | 279 |
var x, y: LongInt; |
3612
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
280 |
begin |
6382
0e76c5cd4250
move the order of reloading texture to workaround buggy drivers
koda
parents:
6380
diff
changeset
|
281 |
for x:= 0 to LANDTEXARW - 1 do |
3615 | 282 |
for y:= 0 to LANDTEXARH - 1 do |
283 |
with LandTextures[x, y] do |
|
10648 | 284 |
FreeAndNilTexture(tex); |
5654 | 285 |
end; |
286 |
||
287 |
procedure freeModule; |
|
288 |
begin |
|
289 |
ResetLand; |
|
3615 | 290 |
if LandBackSurface <> nil then |
291 |
SDL_FreeSurface(LandBackSurface); |
|
292 |
LandBackSurface:= nil; |
|
7151 | 293 |
SetLength(LandTextures, 0, 0); |
3612
b50215a8a43d
land arrays are allocated dynamically, so DOWNSCALE and LOWRES macros are now removed and replaced by run time flags rqBlurryLand and rqLowRes
koda
parents:
3595
diff
changeset
|
294 |
end; |
1806 | 295 |
end. |