22 interface |
22 interface |
23 uses SDLh; |
23 uses SDLh; |
24 |
24 |
25 procedure initModule; |
25 procedure initModule; |
26 procedure freeModule; |
26 procedure freeModule; |
27 procedure UpdateLandTexture(X, Width, Y, Height: LongInt); |
27 procedure UpdateLandTexture(X, Width, Y, Height: LongInt; landAdded: boolean); |
28 procedure DrawLand(dX, dY: LongInt); |
28 procedure DrawLand(dX, dY: LongInt); |
29 procedure ResetLand; |
29 procedure ResetLand; |
30 |
30 |
31 implementation |
31 implementation |
32 uses uConsts, GLunit, uTypes, uVariables, uTextures, uDebug, uRender; |
32 uses uConsts, GLunit, uTypes, uVariables, uTextures, uDebug, uRender; |
33 |
33 |
34 const TEXSIZE = 512; |
34 const TEXSIZE = 128; |
35 |
35 |
36 type TLandRecord = record |
36 type TLandRecord = record |
37 shouldUpdate: boolean; |
37 shouldUpdate, landAdded: boolean; |
38 tex: PTexture; |
38 tex: PTexture; |
39 end; |
39 end; |
40 |
40 |
41 var LandTextures: array of array of TLandRecord; |
41 var LandTextures: array of array of TLandRecord; |
42 tmpPixels: array [0..TEXSIZE - 1, 0..TEXSIZE - 1] of LongWord; |
42 tmpPixels: array [0..TEXSIZE - 1, 0..TEXSIZE - 1] of LongWord; |
73 TryDo(Y + Height <= LAND_HEIGHT, 'UpdateLandTexture: wrong Height parameter', true); |
73 TryDo(Y + Height <= LAND_HEIGHT, 'UpdateLandTexture: wrong Height parameter', true); |
74 |
74 |
75 if (cReducedQuality and rqBlurryLand) = 0 then |
75 if (cReducedQuality and rqBlurryLand) = 0 then |
76 for ty:= Y div TEXSIZE to (Y + Height - 1) div TEXSIZE do |
76 for ty:= Y div TEXSIZE to (Y + Height - 1) div TEXSIZE do |
77 for tx:= X div TEXSIZE to (X + Width - 1) div TEXSIZE do |
77 for tx:= X div TEXSIZE to (X + Width - 1) div TEXSIZE do |
78 LandTextures[tx, ty].shouldUpdate:= true |
78 begin |
|
79 LandTextures[tx, ty].shouldUpdate:= true; |
|
80 LandTextures[tx, ty].landAdded:= landAdded |
|
81 end |
79 else |
82 else |
80 for ty:= (Y div TEXSIZE) div 2 to ((Y + Height - 1) div TEXSIZE) div 2 do |
83 for ty:= (Y div TEXSIZE) div 2 to ((Y + Height - 1) div TEXSIZE) div 2 do |
81 for tx:= (X div TEXSIZE) div 2 to ((X + Width - 1) div TEXSIZE) div 2 do |
84 for tx:= (X div TEXSIZE) div 2 to ((X + Width - 1) div TEXSIZE) div 2 do |
|
85 begin |
82 LandTextures[tx, ty].shouldUpdate:= true; |
86 LandTextures[tx, ty].shouldUpdate:= true; |
|
87 LandTextures[tx, ty].landAdded:= landAdded |
|
88 end |
83 end; |
89 end; |
84 |
90 |
85 procedure RealLandTexUpdate; |
91 procedure RealLandTexUpdate; |
86 var x, y: LongWord; |
92 var x, y, ty, tx, lx, ly : LongWord; |
87 begin |
93 isEmpty: boolean; |
|
94 begin |
|
95 (* |
88 if LandTextures[0, 0].tex = nil then |
96 if LandTextures[0, 0].tex = nil then |
89 for x:= 0 to LANDTEXARW -1 do |
97 for x:= 0 to LANDTEXARW -1 do |
90 for y:= 0 to LANDTEXARH - 1 do |
98 for y:= 0 to LANDTEXARH - 1 do |
91 with LandTextures[x, y] do |
99 with LandTextures[x, y] do |
92 begin |
100 begin |
93 tex:= NewTexture(TEXSIZE, TEXSIZE, Pixels(x, y)); |
101 tex:= NewTexture(TEXSIZE, TEXSIZE, Pixels(x, y)); |
94 glBindTexture(GL_TEXTURE_2D, tex^.atlas^.id); |
102 glBindTexture(GL_TEXTURE_2D, tex^.atlas^.id); |
95 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, tpHigh); |
103 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, tpHigh); |
96 end |
104 end |
97 else |
105 else |
|
106 *) |
98 for x:= 0 to LANDTEXARW -1 do |
107 for x:= 0 to LANDTEXARW -1 do |
99 for y:= 0 to LANDTEXARH - 1 do |
108 for y:= 0 to LANDTEXARH - 1 do |
100 with LandTextures[x, y] do |
109 with LandTextures[x, y] do |
101 if shouldUpdate then |
110 if shouldUpdate then |
102 begin |
111 begin |
103 shouldUpdate:= false; |
112 shouldUpdate:= false; |
104 glBindTexture(GL_TEXTURE_2D, tex^.atlas^.id); |
113 isEmpty:= not landAdded; |
105 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXSIZE, TEXSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, Pixels(x,y)); |
114 landAdded:= false; |
|
115 ty:= 0; |
|
116 tx:= 1; |
|
117 ly:= y * TEXSIZE; |
|
118 lx:= x * TEXSIZE; |
|
119 // first check edges |
|
120 while isEmpty and (ty < TEXSIZE) do |
|
121 begin |
|
122 isEmpty:= LandPixels[ly + ty, lx] and AMask = 0; |
|
123 if isEmpty then isEmpty:= LandPixels[ly + ty, lx + TEXSIZE-1] and AMask = 0; |
|
124 inc(ty) |
|
125 end; |
|
126 while isEmpty and (tx < TEXSIZE-1) do |
|
127 begin |
|
128 isEmpty:= LandPixels[ly, lx + tx] and AMask = 0; |
|
129 if isEmpty then isEmpty:= LandPixels[ly + TEXSIZE-1, lx + tx] and AMask = 0; |
|
130 inc(tx) |
|
131 end; |
|
132 // then search every other remaining. does this sort of stuff defeat compiler opts? |
|
133 ty:= 2; |
|
134 while isEmpty and (ty < TEXSIZE-1) do |
|
135 begin |
|
136 tx:= 2; |
|
137 while isEmpty and (tx < TEXSIZE-1) do |
|
138 begin |
|
139 isEmpty:= LandPixels[ly + ty, lx + tx] and AMask = 0; |
|
140 inc(tx,2) |
|
141 end; |
|
142 inc(ty,2); |
|
143 end; |
|
144 // and repeat |
|
145 ty:= 1; |
|
146 while isEmpty and (ty < TEXSIZE-1) do |
|
147 begin |
|
148 tx:= 1; |
|
149 while isEmpty and (tx < TEXSIZE-1) do |
|
150 begin |
|
151 isEmpty:= LandPixels[ly + ty, lx + tx] and AMask = 0; |
|
152 inc(tx,2) |
|
153 end; |
|
154 inc(ty,2); |
|
155 end; |
|
156 if not isEmpty then |
|
157 begin |
|
158 if tex = nil then tex:= NewTexture(TEXSIZE, TEXSIZE, Pixels(x, y)); |
|
159 glBindTexture(GL_TEXTURE_2D, tex^.atlas^.id); |
|
160 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXSIZE, TEXSIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, Pixels(x,y)); |
|
161 end |
|
162 else if tex <> nil then |
|
163 begin |
|
164 FreeTexture(tex); |
|
165 tex:= nil |
|
166 end; |
106 end |
167 end |
107 end; |
168 end; |
108 |
169 |
109 procedure DrawLand(dX, dY: LongInt); |
170 procedure DrawLand(dX, dY: LongInt); |
110 var x, y: LongInt; |
171 var x, y: LongInt; |