author | unc0rr |
Thu, 30 Apr 2009 20:16:58 +0000 | |
changeset 2019 | b3f1eda8865f |
parent 2017 | 7845c77c8d31 |
child 2023 | 41d3afaa20c7 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 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 |
|
4 | 8 |
* |
183 | 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. |
|
4 | 13 |
* |
183 | 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 |
|
4 | 17 |
*) |
18 |
||
19 |
unit uMisc; |
|
20 |
interface |
|
1906 | 21 |
uses uConsts, SDLh, |
22 |
{$IFDEF IPHONE} |
|
23 |
gles11, |
|
24 |
{$ELSE} |
|
25 |
GL, |
|
26 |
{$ENDIF} |
|
27 |
uFloat; |
|
4 | 28 |
{$INCLUDE options.inc} |
1054 | 29 |
var |
30 |
isCursorVisible : boolean = false; |
|
31 |
isTerminated : boolean = false; |
|
32 |
isInLag : boolean = false; |
|
33 |
isPaused : boolean = false; |
|
34 |
isSoundEnabled : boolean = true; |
|
1128 | 35 |
isMusicEnabled : boolean = false; |
1054 | 36 |
isSEBackup : boolean = true; |
37 |
isInMultiShoot : boolean = false; |
|
38 |
isSpeed : boolean = false; |
|
4 | 39 |
|
1560
e140bc57ff68
Quick replay round to spectators until current move
unc0rr
parents:
1530
diff
changeset
|
40 |
fastUntilLag : boolean = false; |
e140bc57ff68
Quick replay round to spectators until current move
unc0rr
parents:
1530
diff
changeset
|
41 |
|
1054 | 42 |
GameState : TGameState = Low(TGameState); |
43 |
GameType : TGameType = gmtLocal; |
|
44 |
GameFlags : Longword = 0; |
|
45 |
TurnTimeLeft : Longword = 0; |
|
1784 | 46 |
cSuddenDTurns : LongInt = 15; |
1895 | 47 |
cDamagePercent : LongInt = 100; |
1797 | 48 |
cTemplateFilter : LongInt = 0; |
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1861
diff
changeset
|
49 |
|
1054 | 50 |
cHedgehogTurnTime: Longword = 45000; |
51 |
cMaxAIThinkTime : Longword = 9000; |
|
4 | 52 |
|
1054 | 53 |
cCloudsNumber : LongInt = 9; |
54 |
cScreenWidth : LongInt = 1024; |
|
55 |
cScreenHeight : LongInt = 768; |
|
1121
d595dc56b4f3
Remember initial resolution settings to use when switching to fullscreen mode
unc0rr
parents:
1080
diff
changeset
|
56 |
cInitWidth : LongInt = 1024; |
d595dc56b4f3
Remember initial resolution settings to use when switching to fullscreen mode
unc0rr
parents:
1080
diff
changeset
|
57 |
cInitHeight : LongInt = 768; |
2008 | 58 |
cBits : LongInt = 32; |
59 |
cBitsStr : string[2] = '32'; |
|
1054 | 60 |
cTagsMask : byte = 7; |
74 | 61 |
|
1760 | 62 |
cWaterLine : LongInt = LAND_HEIGHT; |
1054 | 63 |
cVisibleWater : LongInt = 128; |
64 |
cGearScrEdgesDist: LongInt = 240; |
|
1530 | 65 |
cCursorEdgesDist : LongInt = 100; |
1054 | 66 |
cTeamHealthWidth : LongInt = 128; |
67 |
cAltDamage : boolean = true; |
|
4 | 68 |
|
1054 | 69 |
GameTicks : LongWord = 0; |
70 |
||
71 |
cSkyColor : Longword = 0; |
|
72 |
cWhiteColor : Longword = $FFFFFFFF; |
|
73 |
cColorNearBlack : Longword = $FF000010; |
|
74 |
cExplosionBorderColor : LongWord = $808080; |
|
4 | 75 |
|
2008 | 76 |
cShowFPS : boolean = false; |
1298 | 77 |
cCaseFactor : Longword = 5; {0..9} |
1054 | 78 |
cLandAdditions: Longword = 4; |
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1861
diff
changeset
|
79 |
cFullScreen : boolean = false; |
1812 | 80 |
cReducedQuality : boolean = false; |
1054 | 81 |
cLocaleFName : shortstring = 'en.txt'; |
82 |
cSeed : shortstring = ''; |
|
83 |
cInitVolume : LongInt = 128; |
|
84 |
cVolumeDelta : LongInt = 0; |
|
2008 | 85 |
cTimerInterval : Longword = 8; |
1054 | 86 |
cHasFocus : boolean = true; |
1057 | 87 |
cInactDelay : Longword = 1250; |
4 | 88 |
|
1054 | 89 |
bBetweenTurns: boolean = false; |
1055
9af540b23409
Water rises after 25 mins of round, health is decreased after 20 mins
unc0rr
parents:
1054
diff
changeset
|
90 |
cHealthDecrease: LongWord = 0; |
9af540b23409
Water rises after 25 mins of round, health is decreased after 20 mins
unc0rr
parents:
1054
diff
changeset
|
91 |
bWaterRising : Boolean = false; |
4 | 92 |
|
614 | 93 |
{$WARNINGS OFF} |
1124 | 94 |
cAirPlaneSpeed: hwFloat = (isNegative: false; QWordValue: 3006477107); // 1.4 |
1054 | 95 |
cBombsSpeed : hwFloat = (isNegative: false; QWordValue: 429496729); |
614 | 96 |
{$WARNINGS ON} |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
539
diff
changeset
|
97 |
|
4 | 98 |
var |
1054 | 99 |
cSendEmptyPacketTime : LongWord = 2000; |
100 |
cSendCursorPosTime : LongWord = 50; |
|
101 |
ShowCrosshair : boolean; |
|
102 |
cDrownSpeed, |
|
103 |
cMaxWindSpeed, |
|
104 |
cWindSpeed, |
|
105 |
cGravity: hwFloat; |
|
1849 | 106 |
cDamageModifier: hwFloat; |
1854 | 107 |
cLaserSighting: boolean; |
2017 | 108 |
cVampiric: boolean; |
4 | 109 |
|
1054 | 110 |
flagMakeCapture: boolean = false; |
4 | 111 |
|
1054 | 112 |
InitStepsFlags: Longword = 0; |
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
113 |
|
1054 | 114 |
RealTicks: Longword = 0; |
836 | 115 |
|
1054 | 116 |
AttackBar: LongInt = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
4 | 117 |
|
1911 | 118 |
type HwColor3f = record |
119 |
r, g, b: byte |
|
120 |
end; |
|
121 |
||
122 |
var WaterColorArray: array[0..3] of HwColor3f; |
|
123 |
||
371 | 124 |
function hwSign(r: hwFloat): LongInt; |
802
ed5450a89b96
Start implementing 'visual gears' - gears, that don't need to be synchronized (clouds and flakes)
unc0rr
parents:
788
diff
changeset
|
125 |
function Min(a, b: LongInt): LongInt; |
371 | 126 |
function Max(a, b: LongInt): LongInt; |
351 | 127 |
procedure OutError(Msg: String; isFatalError: boolean); |
4 | 128 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
129 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
316 | 130 |
function IntToStr(n: LongInt): shortstring; |
351 | 131 |
function FloatToStr(n: hwFloat): shortstring; |
775 | 132 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
371 | 133 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
134 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
|
4 | 135 |
procedure AdjustColor(var Color: Longword); |
136 |
{$IFDEF DEBUGFILE} |
|
137 |
procedure AddFileLog(s: shortstring); |
|
24 | 138 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
4 | 139 |
{$ENDIF} |
208 | 140 |
procedure SetKB(n: Longword); |
141 |
procedure SendKB; |
|
351 | 142 |
procedure SetLittle(var r: hwFloat); |
306 | 143 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
753 | 144 |
function Str2PChar(const s: shortstring): PChar; |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
145 |
function NewTexture(width, height: Longword; buf: Pointer): PTexture; |
755 | 146 |
function Surface2Tex(surf: PSDL_Surface): PTexture; |
759 | 147 |
procedure FreeTexture(tex: PTexture); |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
916
diff
changeset
|
148 |
function toPowerOf2(i: Longword): Longword; |
949 | 149 |
function DecodeBase64(s: shortstring): shortstring; |
1080 | 150 |
procedure MakeScreenshot(s: shortstring); |
1861 | 151 |
function modifyDamage(dmg: Longword): Longword; |
4 | 152 |
|
153 |
var CursorPoint: TPoint; |
|
154 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
155 |
||
156 |
implementation |
|
1896 | 157 |
uses uConsole, uStore, uIO, Math, uRandom; |
208 | 158 |
var KBnum: Longword = 0; |
4 | 159 |
{$IFDEF DEBUGFILE} |
160 |
var f: textfile; |
|
161 |
{$ENDIF} |
|
162 |
||
371 | 163 |
function hwSign(r: hwFloat): LongInt; |
4 | 164 |
begin |
351 | 165 |
if r.isNegative then hwSign:= -1 else hwSign:= 1 |
4 | 166 |
end; |
167 |
||
371 | 168 |
function Min(a, b: LongInt): LongInt; |
4 | 169 |
begin |
351 | 170 |
if a < b then Min:= a else Min:= b |
4 | 171 |
end; |
172 |
||
371 | 173 |
function Max(a, b: LongInt): LongInt; |
4 | 174 |
begin |
351 | 175 |
if a > b then Max:= a else Max:= b |
4 | 176 |
end; |
177 |
||
351 | 178 |
procedure OutError(Msg: String; isFatalError: boolean); |
4 | 179 |
begin |
180 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 181 |
WriteLnToConsole(Msg); |
4 | 182 |
if isFatalError then |
183 |
begin |
|
53 | 184 |
SendIPC('E' + GetLastConsoleLine); |
4 | 185 |
SDL_Quit; |
186 |
halt(1) |
|
53 | 187 |
end |
4 | 188 |
end; |
189 |
||
190 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
191 |
begin |
|
70 | 192 |
if not Assert then OutError(Msg, isFatal) |
4 | 193 |
end; |
194 |
||
195 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
196 |
begin |
|
197 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
198 |
end; |
|
199 |
||
188 | 200 |
procedure AdjustColor(var Color: Longword); |
4 | 201 |
begin |
202 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
203 |
end; |
|
204 |
||
316 | 205 |
function IntToStr(n: LongInt): shortstring; |
4 | 206 |
begin |
351 | 207 |
str(n, IntToStr) |
4 | 208 |
end; |
209 |
||
351 | 210 |
function FloatToStr(n: hwFloat): shortstring; |
4 | 211 |
begin |
1346 | 212 |
FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue)) |
4 | 213 |
end; |
214 |
||
775 | 215 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
216 |
var dY, dX: Extended; |
|
217 |
begin |
|
218 |
dY:= _dY.QWordValue / $100000000; |
|
219 |
if _dY.isNegative then dY:= - dY; |
|
220 |
dX:= _dX.QWordValue / $100000000; |
|
221 |
if _dX.isNegative then dX:= - dX; |
|
222 |
DxDy2Angle:= arctan2(dY, dX) * 180 / pi |
|
223 |
end; |
|
224 |
||
371 | 225 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
100 | 226 |
const _16divPI: Extended = 16/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
227 |
var dY, dX: Extended; |
100 | 228 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
229 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
230 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
231 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
232 |
if _dX.isNegative then dX:= - dX; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
233 |
DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
4 | 234 |
end; |
235 |
||
371 | 236 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
100 | 237 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
238 |
var dY, dX: Extended; |
100 | 239 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
240 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
241 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
242 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
243 |
if _dX.isNegative then dX:= - dX; |
438 | 244 |
DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
100 | 245 |
end; |
4 | 246 |
|
208 | 247 |
procedure SetKB(n: Longword); |
248 |
begin |
|
249 |
KBnum:= n |
|
250 |
end; |
|
251 |
||
252 |
procedure SendKB; |
|
253 |
var s: shortstring; |
|
254 |
begin |
|
255 |
if KBnum <> 0 then |
|
256 |
begin |
|
257 |
s:= 'K' + inttostr(KBnum); |
|
258 |
SendIPCRaw(@s, Length(s) + 1) |
|
259 |
end |
|
260 |
end; |
|
261 |
||
351 | 262 |
procedure SetLittle(var r: hwFloat); |
300 | 263 |
begin |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
543
diff
changeset
|
264 |
r:= SignAs(cLittle, r) |
300 | 265 |
end; |
266 |
||
337 | 267 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
1625 | 268 |
const stc: array [TStatInfoType] of char = 'rDkKH'; |
337 | 269 |
begin |
270 |
SendIPC('i' + stc[sit] + s) |
|
271 |
end; |
|
272 |
||
534 | 273 |
function Str2PChar(const s: shortstring): PChar; |
351 | 274 |
const CharArray: array[byte] of Char = ''; |
275 |
begin |
|
276 |
CharArray:= s; |
|
277 |
CharArray[Length(s)]:= #0; |
|
278 |
Str2PChar:= @CharArray |
|
279 |
end; |
|
280 |
||
771 | 281 |
function isPowerOf2(i: Longword): boolean; |
282 |
begin |
|
283 |
if i = 0 then exit(true); |
|
284 |
while (i and 1) = 0 do i:= i shr 1; |
|
285 |
isPowerOf2:= (i = 1) |
|
286 |
end; |
|
287 |
||
288 |
function toPowerOf2(i: Longword): Longword; |
|
289 |
begin |
|
290 |
toPowerOf2:= 1; |
|
291 |
while (toPowerOf2 < i) do toPowerOf2:= toPowerOf2 shl 1 |
|
292 |
end; |
|
293 |
||
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
294 |
procedure ResetVertexArrays(texture: PTexture); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
295 |
begin |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
296 |
with texture^ do |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
297 |
begin |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
298 |
vb[0].X:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
299 |
vb[0].Y:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
300 |
vb[1].X:= w; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
301 |
vb[1].Y:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
302 |
vb[2].X:= w; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
303 |
vb[2].Y:= h; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
304 |
vb[3].X:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
305 |
vb[3].Y:= h; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
306 |
|
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
307 |
tb[0].X:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
308 |
tb[0].Y:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
309 |
tb[1].X:= rx; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
310 |
tb[1].Y:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
311 |
tb[2].X:= rx; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
312 |
tb[2].Y:= ry; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
313 |
tb[3].X:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
314 |
tb[3].Y:= ry |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
315 |
end; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
316 |
end; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
317 |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
318 |
function NewTexture(width, height: Longword; buf: Pointer): PTexture; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
319 |
begin |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
320 |
new(NewTexture); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
321 |
NewTexture^.w:= width; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
322 |
NewTexture^.h:= height; |
1896 | 323 |
NewTexture^.rx:= 1.0; |
324 |
NewTexture^.ry:= 1.0; |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
325 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
326 |
ResetVertexArrays(NewTexture); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
327 |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
328 |
glGenTextures(1, @NewTexture^.id); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
329 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
330 |
glBindTexture(GL_TEXTURE_2D, NewTexture^.id); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
331 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
332 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
333 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
334 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
335 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
336 |
end; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
337 |
|
755 | 338 |
function Surface2Tex(surf: PSDL_Surface): PTexture; |
753 | 339 |
var mode: LongInt; |
1896 | 340 |
tw, th, x, y: Longword; |
341 |
tmpp: pointer; |
|
342 |
fromP4, toP4: PLongWordArray; |
|
343 |
fromP1, toP1: PByteArray; |
|
753 | 344 |
begin |
755 | 345 |
new(Surface2Tex); |
346 |
Surface2Tex^.w:= surf^.w; |
|
347 |
Surface2Tex^.h:= surf^.h; |
|
348 |
||
753 | 349 |
if (surf^.format^.BytesPerPixel = 3) then mode:= GL_RGB else |
350 |
if (surf^.format^.BytesPerPixel = 4) then mode:= GL_RGBA else |
|
351 |
begin |
|
869 | 352 |
TryDo(false, 'Surface2Tex: BytesPerPixel not in [3, 4]', true); |
755 | 353 |
Surface2Tex^.id:= 0; |
753 | 354 |
exit |
355 |
end; |
|
356 |
||
755 | 357 |
glGenTextures(1, @Surface2Tex^.id); |
753 | 358 |
|
755 | 359 |
glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id); |
753 | 360 |
|
771 | 361 |
if SDL_MustLock(surf) then |
362 |
SDLTry(SDL_LockSurface(surf) >= 0, true); |
|
363 |
||
364 |
if not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h)) then |
|
1896 | 365 |
begin |
366 |
tw:= toPowerOf2(Surf^.w); |
|
367 |
th:= toPowerOf2(Surf^.h); |
|
368 |
||
369 |
Surface2Tex^.rx:= Surf^.w / tw; |
|
370 |
Surface2Tex^.ry:= Surf^.h / th; |
|
371 |
||
372 |
GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel); |
|
373 |
||
374 |
if surf^.format^.BytesPerPixel = 4 then |
|
375 |
begin |
|
376 |
fromP4:= Surf^.pixels; |
|
377 |
toP4:= tmpp; |
|
771 | 378 |
|
1896 | 379 |
for y:= 0 to Pred(Surf^.h) do |
380 |
begin |
|
381 |
for x:= 0 to Pred(Surf^.w) do |
|
382 |
toP4^[x]:= fromP4^[x]; |
|
383 |
for x:= Surf^.w to Pred(tw) do |
|
384 |
toP4^[x]:= 0; |
|
385 |
toP4:= @(toP4^[tw]); |
|
2017 | 386 |
fromP4:= @(fromP4^[Surf^.pitch div 4]); |
1896 | 387 |
end; |
388 |
||
389 |
for y:= Surf^.h to Pred(th) do |
|
390 |
begin |
|
391 |
for x:= 0 to Pred(tw) do |
|
392 |
toP4^[x]:= 0; |
|
393 |
toP4:= @(toP4^[tw]); |
|
394 |
end; |
|
395 |
end |
|
396 |
else |
|
397 |
begin |
|
398 |
fromP1:= Surf^.pixels; |
|
399 |
toP1:= tmpp; |
|
771 | 400 |
|
1896 | 401 |
for y:= 0 to Pred(Surf^.h) do |
402 |
begin |
|
403 |
for x:= 0 to Pred(Surf^.w) do |
|
404 |
begin |
|
405 |
toP1^[x * 3]:= fromP1^[x * 3]; |
|
406 |
toP1^[x * 3 + 1]:= fromP1^[x * 3 + 1]; |
|
407 |
toP1^[x * 3 + 2]:= fromP1^[x * 3 + 2]; |
|
408 |
end; |
|
409 |
for x:= Surf^.w to Pred(tw) do |
|
410 |
begin |
|
411 |
toP1^[x * 3]:= 0; |
|
412 |
toP1^[x * 3 + 1]:= 0; |
|
413 |
toP1^[x * 3 + 2]:= 0; |
|
414 |
end; |
|
415 |
toP1:= @(toP1^[tw * 3]); |
|
416 |
fromP1:= @(fromP1^[Surf^.pitch]); |
|
417 |
end; |
|
771 | 418 |
|
1896 | 419 |
for y:= Surf^.h to Pred(th) do |
420 |
begin |
|
421 |
for x:= 0 to Pred(tw) do |
|
422 |
begin |
|
423 |
toP1^[x * 3]:= 0; |
|
424 |
toP1^[x * 3 + 1]:= 0; |
|
425 |
toP1^[x * 3 + 2]:= 0; |
|
426 |
end; |
|
427 |
toP1:= @(toP1^[tw * 3]); |
|
428 |
end; |
|
429 |
end; |
|
771 | 430 |
|
1896 | 431 |
// gluScaleImage(mode, Surf^.w, Surf^.h, GL_UNSIGNED_BYTE, |
432 |
// Surf^.pixels, tw, th, GL_UNSIGNED_BYTE, |
|
433 |
// tmpp); |
|
434 |
||
435 |
glTexImage2D(GL_TEXTURE_2D, 0, mode, tw, th, 0, mode, GL_UNSIGNED_BYTE, tmpp); |
|
436 |
||
437 |
FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) |
|
438 |
end else |
|
439 |
begin |
|
440 |
Surface2Tex^.rx:= 1.0; |
|
441 |
Surface2Tex^.ry:= 1.0; |
|
442 |
glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels); |
|
443 |
end; |
|
753 | 444 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
445 |
ResetVertexArrays(Surface2Tex); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
446 |
|
754 | 447 |
if SDL_MustLock(surf) then |
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
448 |
SDL_UnlockSurface(surf); |
754 | 449 |
|
788
00720357601f
- Get rid of PageSimpleGame, now pressing 'quick game' just starts round
unc0rr
parents:
785
diff
changeset
|
450 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
00720357601f
- Get rid of PageSimpleGame, now pressing 'quick game' just starts round
unc0rr
parents:
785
diff
changeset
|
451 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
753 | 452 |
end; |
453 |
||
759 | 454 |
procedure FreeTexture(tex: PTexture); |
455 |
begin |
|
2000
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
456 |
if tex <> nil then |
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
457 |
begin |
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
458 |
glDeleteTextures(1, @tex^.id); |
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
459 |
dispose(tex) |
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
460 |
end |
759 | 461 |
end; |
337 | 462 |
|
949 | 463 |
function DecodeBase64(s: shortstring): shortstring; |
464 |
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
|
465 |
var i, t, c: Longword; |
|
466 |
begin |
|
467 |
c:= 0; |
|
468 |
for i:= 1 to Length(s) do |
|
469 |
begin |
|
470 |
t:= Pos(s[i], table); |
|
471 |
if s[i] = '=' then inc(c); |
|
472 |
if t > 0 then byte(s[i]):= t - 1 else byte(s[i]):= 0 |
|
473 |
end; |
|
474 |
||
475 |
i:= 1; |
|
476 |
t:= 1; |
|
477 |
while i <= length(s) do |
|
478 |
begin |
|
479 |
DecodeBase64[t ]:= char((byte(s[i ]) shl 2) or (byte(s[i + 1]) shr 4)); |
|
480 |
DecodeBase64[t + 1]:= char((byte(s[i + 1]) shl 4) or (byte(s[i + 2]) shr 2)); |
|
481 |
DecodeBase64[t + 2]:= char((byte(s[i + 2]) shl 6) or (byte(s[i + 3]) )); |
|
482 |
inc(t, 3); |
|
483 |
inc(i, 4) |
|
484 |
end; |
|
485 |
||
486 |
if c < 3 then t:= t - c; |
|
487 |
||
488 |
byte(DecodeBase64[0]):= t - 1 |
|
489 |
end; |
|
490 |
||
1906 | 491 |
const GL_BGR = $80E0; // some opengl headers don't have that const (?)' |
1080 | 492 |
procedure MakeScreenshot(s: shortstring); |
493 |
const head: array[0..8] of Word = (0, 2, 0, 0, 0, 0, 0, 0, 24); |
|
494 |
var p: Pointer; |
|
495 |
size: Longword; |
|
496 |
f: file; |
|
497 |
begin |
|
498 |
head[6]:= cScreenWidth; |
|
499 |
head[7]:= cScreenHeight; |
|
500 |
||
501 |
size:= cScreenWidth * cScreenHeight * 3; |
|
502 |
p:= GetMem(size); |
|
503 |
||
1916 | 504 |
{$IFDEF IPHONE} |
505 |
//since opengl es operates on a single surface GL_FRONT is implied, but how to test that? |
|
506 |
{$ELSE} |
|
1080 | 507 |
glReadBuffer(GL_FRONT); |
1916 | 508 |
{$ENDIF} |
1080 | 509 |
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p); |
510 |
||
511 |
{$I-} |
|
512 |
Assign(f, s); |
|
513 |
Rewrite(f, 1); |
|
514 |
if IOResult = 0 then |
|
515 |
begin |
|
516 |
BlockWrite(f, head, sizeof(head)); |
|
517 |
BlockWrite(f, p^, size); |
|
518 |
Close(f); |
|
519 |
end; |
|
520 |
{$I+} |
|
521 |
||
522 |
FreeMem(p) |
|
523 |
end; |
|
524 |
||
1861 | 525 |
function modifyDamage(dmg: Longword): Longword; |
526 |
begin |
|
1895 | 527 |
ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent) |
1861 | 528 |
end; |
529 |
||
949 | 530 |
{$IFDEF DEBUGFILE} |
531 |
procedure AddFileLog(s: shortstring); |
|
532 |
begin |
|
533 |
writeln(f, GameTicks: 6, ': ', s); |
|
534 |
flush(f) |
|
535 |
end; |
|
536 |
||
537 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
|
538 |
begin |
|
539 |
RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
|
540 |
end; |
|
541 |
||
371 | 542 |
var i: LongInt; |
488 | 543 |
{$ENDIF} |
306 | 544 |
|
4 | 545 |
initialization |
351 | 546 |
cDrownSpeed.QWordValue:= 257698038;// 0.06 |
488 | 547 |
cMaxWindSpeed.QWordValue:= 2147484;// 0.0005 |
548 |
cWindSpeed.QWordValue:= 429496;// 0.0001 |
|
351 | 549 |
cGravity:= cMaxWindSpeed; |
1849 | 550 |
cDamageModifier:= _1; |
1854 | 551 |
cLaserSighting:= false; |
2017 | 552 |
cVampiric:= false; |
351 | 553 |
|
488 | 554 |
{$IFDEF DEBUGFILE} |
337 | 555 |
{$I-} |
2008 | 556 |
if ParamCount >= 0 then |
557 |
//this check prevents a crash in Mac OS X |
|
558 |
if ParamCount = 0 then |
|
559 |
begin |
|
560 |
Assign(f, '/tmp/debug.txt'); |
|
561 |
rewrite(f); |
|
562 |
end else |
|
563 |
begin |
|
497 | 564 |
for i:= 0 to 7 do |
337 | 565 |
begin |
497 | 566 |
Assign(f, ParamStr(1) + '/debug' + inttostr(i) + '.txt'); |
337 | 567 |
rewrite(f); |
568 |
if IOResult = 0 then break |
|
569 |
end; |
|
2008 | 570 |
end; |
337 | 571 |
{$I+} |
17 | 572 |
|
4 | 573 |
finalization |
916 | 574 |
//uRandom.DumpBuffer; |
4 | 575 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
576 |
Flush(f); |
|
351 | 577 |
close(f) |
4 | 578 |
{$ENDIF} |
579 |
||
580 |
end. |