author | nemo |
Sun, 03 May 2009 21:28:15 +0000 | |
changeset 2025 | 692308790912 |
parent 2023 | 41d3afaa20c7 |
child 2031 | b6f3e56fb100 |
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; |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
109 |
cArtillery: boolean; |
4 | 110 |
|
1054 | 111 |
flagMakeCapture: boolean = false; |
4 | 112 |
|
1054 | 113 |
InitStepsFlags: Longword = 0; |
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
114 |
|
1054 | 115 |
RealTicks: Longword = 0; |
836 | 116 |
|
1054 | 117 |
AttackBar: LongInt = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
4 | 118 |
|
1911 | 119 |
type HwColor3f = record |
120 |
r, g, b: byte |
|
121 |
end; |
|
122 |
||
123 |
var WaterColorArray: array[0..3] of HwColor3f; |
|
124 |
||
371 | 125 |
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
|
126 |
function Min(a, b: LongInt): LongInt; |
371 | 127 |
function Max(a, b: LongInt): LongInt; |
351 | 128 |
procedure OutError(Msg: String; isFatalError: boolean); |
4 | 129 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
130 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
316 | 131 |
function IntToStr(n: LongInt): shortstring; |
351 | 132 |
function FloatToStr(n: hwFloat): shortstring; |
775 | 133 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
371 | 134 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
135 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
|
4 | 136 |
procedure AdjustColor(var Color: Longword); |
137 |
{$IFDEF DEBUGFILE} |
|
138 |
procedure AddFileLog(s: shortstring); |
|
24 | 139 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
4 | 140 |
{$ENDIF} |
208 | 141 |
procedure SetKB(n: Longword); |
142 |
procedure SendKB; |
|
351 | 143 |
procedure SetLittle(var r: hwFloat); |
306 | 144 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
753 | 145 |
function Str2PChar(const s: shortstring): PChar; |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
146 |
function NewTexture(width, height: Longword; buf: Pointer): PTexture; |
755 | 147 |
function Surface2Tex(surf: PSDL_Surface): PTexture; |
759 | 148 |
procedure FreeTexture(tex: PTexture); |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
916
diff
changeset
|
149 |
function toPowerOf2(i: Longword): Longword; |
949 | 150 |
function DecodeBase64(s: shortstring): shortstring; |
1080 | 151 |
procedure MakeScreenshot(s: shortstring); |
1861 | 152 |
function modifyDamage(dmg: Longword): Longword; |
4 | 153 |
|
154 |
var CursorPoint: TPoint; |
|
155 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
156 |
||
157 |
implementation |
|
1896 | 158 |
uses uConsole, uStore, uIO, Math, uRandom; |
208 | 159 |
var KBnum: Longword = 0; |
4 | 160 |
{$IFDEF DEBUGFILE} |
161 |
var f: textfile; |
|
162 |
{$ENDIF} |
|
163 |
||
371 | 164 |
function hwSign(r: hwFloat): LongInt; |
4 | 165 |
begin |
351 | 166 |
if r.isNegative then hwSign:= -1 else hwSign:= 1 |
4 | 167 |
end; |
168 |
||
371 | 169 |
function Min(a, b: LongInt): LongInt; |
4 | 170 |
begin |
351 | 171 |
if a < b then Min:= a else Min:= b |
4 | 172 |
end; |
173 |
||
371 | 174 |
function Max(a, b: LongInt): LongInt; |
4 | 175 |
begin |
351 | 176 |
if a > b then Max:= a else Max:= b |
4 | 177 |
end; |
178 |
||
351 | 179 |
procedure OutError(Msg: String; isFatalError: boolean); |
4 | 180 |
begin |
181 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 182 |
WriteLnToConsole(Msg); |
4 | 183 |
if isFatalError then |
184 |
begin |
|
53 | 185 |
SendIPC('E' + GetLastConsoleLine); |
4 | 186 |
SDL_Quit; |
187 |
halt(1) |
|
53 | 188 |
end |
4 | 189 |
end; |
190 |
||
191 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
192 |
begin |
|
70 | 193 |
if not Assert then OutError(Msg, isFatal) |
4 | 194 |
end; |
195 |
||
196 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
197 |
begin |
|
198 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
199 |
end; |
|
200 |
||
188 | 201 |
procedure AdjustColor(var Color: Longword); |
4 | 202 |
begin |
203 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
204 |
end; |
|
205 |
||
316 | 206 |
function IntToStr(n: LongInt): shortstring; |
4 | 207 |
begin |
351 | 208 |
str(n, IntToStr) |
4 | 209 |
end; |
210 |
||
351 | 211 |
function FloatToStr(n: hwFloat): shortstring; |
4 | 212 |
begin |
1346 | 213 |
FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue)) |
4 | 214 |
end; |
215 |
||
775 | 216 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
217 |
var dY, dX: Extended; |
|
218 |
begin |
|
219 |
dY:= _dY.QWordValue / $100000000; |
|
220 |
if _dY.isNegative then dY:= - dY; |
|
221 |
dX:= _dX.QWordValue / $100000000; |
|
222 |
if _dX.isNegative then dX:= - dX; |
|
223 |
DxDy2Angle:= arctan2(dY, dX) * 180 / pi |
|
224 |
end; |
|
225 |
||
371 | 226 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
100 | 227 |
const _16divPI: Extended = 16/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
228 |
var dY, dX: Extended; |
100 | 229 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
230 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
231 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
232 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
233 |
if _dX.isNegative then dX:= - dX; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
234 |
DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
4 | 235 |
end; |
236 |
||
371 | 237 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
100 | 238 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
239 |
var dY, dX: Extended; |
100 | 240 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
241 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
242 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
243 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
244 |
if _dX.isNegative then dX:= - dX; |
438 | 245 |
DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
100 | 246 |
end; |
4 | 247 |
|
208 | 248 |
procedure SetKB(n: Longword); |
249 |
begin |
|
250 |
KBnum:= n |
|
251 |
end; |
|
252 |
||
253 |
procedure SendKB; |
|
254 |
var s: shortstring; |
|
255 |
begin |
|
256 |
if KBnum <> 0 then |
|
257 |
begin |
|
258 |
s:= 'K' + inttostr(KBnum); |
|
259 |
SendIPCRaw(@s, Length(s) + 1) |
|
260 |
end |
|
261 |
end; |
|
262 |
||
351 | 263 |
procedure SetLittle(var r: hwFloat); |
300 | 264 |
begin |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
543
diff
changeset
|
265 |
r:= SignAs(cLittle, r) |
300 | 266 |
end; |
267 |
||
337 | 268 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
1625 | 269 |
const stc: array [TStatInfoType] of char = 'rDkKH'; |
337 | 270 |
begin |
271 |
SendIPC('i' + stc[sit] + s) |
|
272 |
end; |
|
273 |
||
534 | 274 |
function Str2PChar(const s: shortstring): PChar; |
351 | 275 |
const CharArray: array[byte] of Char = ''; |
276 |
begin |
|
277 |
CharArray:= s; |
|
278 |
CharArray[Length(s)]:= #0; |
|
279 |
Str2PChar:= @CharArray |
|
280 |
end; |
|
281 |
||
771 | 282 |
function isPowerOf2(i: Longword): boolean; |
283 |
begin |
|
284 |
if i = 0 then exit(true); |
|
285 |
while (i and 1) = 0 do i:= i shr 1; |
|
286 |
isPowerOf2:= (i = 1) |
|
287 |
end; |
|
288 |
||
289 |
function toPowerOf2(i: Longword): Longword; |
|
290 |
begin |
|
291 |
toPowerOf2:= 1; |
|
292 |
while (toPowerOf2 < i) do toPowerOf2:= toPowerOf2 shl 1 |
|
293 |
end; |
|
294 |
||
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
295 |
procedure ResetVertexArrays(texture: PTexture); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
296 |
begin |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
297 |
with texture^ do |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
298 |
begin |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
299 |
vb[0].X:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
300 |
vb[0].Y:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
301 |
vb[1].X:= w; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
302 |
vb[1].Y:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
303 |
vb[2].X:= w; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
304 |
vb[2].Y:= h; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
305 |
vb[3].X:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
306 |
vb[3].Y:= h; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
307 |
|
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
308 |
tb[0].X:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
309 |
tb[0].Y:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
310 |
tb[1].X:= rx; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
311 |
tb[1].Y:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
312 |
tb[2].X:= rx; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
313 |
tb[2].Y:= ry; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
314 |
tb[3].X:= 0; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
315 |
tb[3].Y:= ry |
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 |
end; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
318 |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
319 |
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
|
320 |
begin |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
321 |
new(NewTexture); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
322 |
NewTexture^.w:= width; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
323 |
NewTexture^.h:= height; |
1896 | 324 |
NewTexture^.rx:= 1.0; |
325 |
NewTexture^.ry:= 1.0; |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
326 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
327 |
ResetVertexArrays(NewTexture); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
328 |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
329 |
glGenTextures(1, @NewTexture^.id); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
330 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
331 |
glBindTexture(GL_TEXTURE_2D, NewTexture^.id); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
332 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
333 |
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
|
334 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
335 |
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
|
336 |
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
|
337 |
end; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
338 |
|
755 | 339 |
function Surface2Tex(surf: PSDL_Surface): PTexture; |
753 | 340 |
var mode: LongInt; |
1896 | 341 |
tw, th, x, y: Longword; |
342 |
tmpp: pointer; |
|
343 |
fromP4, toP4: PLongWordArray; |
|
344 |
fromP1, toP1: PByteArray; |
|
753 | 345 |
begin |
755 | 346 |
new(Surface2Tex); |
347 |
Surface2Tex^.w:= surf^.w; |
|
348 |
Surface2Tex^.h:= surf^.h; |
|
349 |
||
753 | 350 |
if (surf^.format^.BytesPerPixel = 3) then mode:= GL_RGB else |
351 |
if (surf^.format^.BytesPerPixel = 4) then mode:= GL_RGBA else |
|
352 |
begin |
|
869 | 353 |
TryDo(false, 'Surface2Tex: BytesPerPixel not in [3, 4]', true); |
755 | 354 |
Surface2Tex^.id:= 0; |
753 | 355 |
exit |
356 |
end; |
|
357 |
||
755 | 358 |
glGenTextures(1, @Surface2Tex^.id); |
753 | 359 |
|
755 | 360 |
glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id); |
753 | 361 |
|
771 | 362 |
if SDL_MustLock(surf) then |
363 |
SDLTry(SDL_LockSurface(surf) >= 0, true); |
|
364 |
||
365 |
if not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h)) then |
|
1896 | 366 |
begin |
367 |
tw:= toPowerOf2(Surf^.w); |
|
368 |
th:= toPowerOf2(Surf^.h); |
|
369 |
||
370 |
Surface2Tex^.rx:= Surf^.w / tw; |
|
371 |
Surface2Tex^.ry:= Surf^.h / th; |
|
372 |
||
373 |
GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel); |
|
374 |
||
375 |
if surf^.format^.BytesPerPixel = 4 then |
|
376 |
begin |
|
377 |
fromP4:= Surf^.pixels; |
|
378 |
toP4:= tmpp; |
|
771 | 379 |
|
1896 | 380 |
for y:= 0 to Pred(Surf^.h) do |
381 |
begin |
|
382 |
for x:= 0 to Pred(Surf^.w) do |
|
383 |
toP4^[x]:= fromP4^[x]; |
|
384 |
for x:= Surf^.w to Pred(tw) do |
|
385 |
toP4^[x]:= 0; |
|
386 |
toP4:= @(toP4^[tw]); |
|
2017 | 387 |
fromP4:= @(fromP4^[Surf^.pitch div 4]); |
1896 | 388 |
end; |
389 |
||
390 |
for y:= Surf^.h to Pred(th) do |
|
391 |
begin |
|
392 |
for x:= 0 to Pred(tw) do |
|
393 |
toP4^[x]:= 0; |
|
394 |
toP4:= @(toP4^[tw]); |
|
395 |
end; |
|
396 |
end |
|
397 |
else |
|
398 |
begin |
|
399 |
fromP1:= Surf^.pixels; |
|
400 |
toP1:= tmpp; |
|
771 | 401 |
|
1896 | 402 |
for y:= 0 to Pred(Surf^.h) do |
403 |
begin |
|
404 |
for x:= 0 to Pred(Surf^.w) do |
|
405 |
begin |
|
406 |
toP1^[x * 3]:= fromP1^[x * 3]; |
|
407 |
toP1^[x * 3 + 1]:= fromP1^[x * 3 + 1]; |
|
408 |
toP1^[x * 3 + 2]:= fromP1^[x * 3 + 2]; |
|
409 |
end; |
|
410 |
for x:= Surf^.w to Pred(tw) do |
|
411 |
begin |
|
412 |
toP1^[x * 3]:= 0; |
|
413 |
toP1^[x * 3 + 1]:= 0; |
|
414 |
toP1^[x * 3 + 2]:= 0; |
|
415 |
end; |
|
416 |
toP1:= @(toP1^[tw * 3]); |
|
417 |
fromP1:= @(fromP1^[Surf^.pitch]); |
|
418 |
end; |
|
771 | 419 |
|
1896 | 420 |
for y:= Surf^.h to Pred(th) do |
421 |
begin |
|
422 |
for x:= 0 to Pred(tw) do |
|
423 |
begin |
|
424 |
toP1^[x * 3]:= 0; |
|
425 |
toP1^[x * 3 + 1]:= 0; |
|
426 |
toP1^[x * 3 + 2]:= 0; |
|
427 |
end; |
|
428 |
toP1:= @(toP1^[tw * 3]); |
|
429 |
end; |
|
430 |
end; |
|
771 | 431 |
|
1896 | 432 |
// gluScaleImage(mode, Surf^.w, Surf^.h, GL_UNSIGNED_BYTE, |
433 |
// Surf^.pixels, tw, th, GL_UNSIGNED_BYTE, |
|
434 |
// tmpp); |
|
435 |
||
436 |
glTexImage2D(GL_TEXTURE_2D, 0, mode, tw, th, 0, mode, GL_UNSIGNED_BYTE, tmpp); |
|
437 |
||
438 |
FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) |
|
439 |
end else |
|
440 |
begin |
|
441 |
Surface2Tex^.rx:= 1.0; |
|
442 |
Surface2Tex^.ry:= 1.0; |
|
443 |
glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels); |
|
444 |
end; |
|
753 | 445 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
446 |
ResetVertexArrays(Surface2Tex); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
447 |
|
754 | 448 |
if SDL_MustLock(surf) then |
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
449 |
SDL_UnlockSurface(surf); |
754 | 450 |
|
788
00720357601f
- Get rid of PageSimpleGame, now pressing 'quick game' just starts round
unc0rr
parents:
785
diff
changeset
|
451 |
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
|
452 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
753 | 453 |
end; |
454 |
||
759 | 455 |
procedure FreeTexture(tex: PTexture); |
456 |
begin |
|
2000
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
457 |
if tex <> nil then |
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
458 |
begin |
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
459 |
glDeleteTextures(1, @tex^.id); |
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
460 |
dispose(tex) |
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
461 |
end |
759 | 462 |
end; |
337 | 463 |
|
949 | 464 |
function DecodeBase64(s: shortstring): shortstring; |
465 |
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
|
466 |
var i, t, c: Longword; |
|
467 |
begin |
|
468 |
c:= 0; |
|
469 |
for i:= 1 to Length(s) do |
|
470 |
begin |
|
471 |
t:= Pos(s[i], table); |
|
472 |
if s[i] = '=' then inc(c); |
|
473 |
if t > 0 then byte(s[i]):= t - 1 else byte(s[i]):= 0 |
|
474 |
end; |
|
475 |
||
476 |
i:= 1; |
|
477 |
t:= 1; |
|
478 |
while i <= length(s) do |
|
479 |
begin |
|
480 |
DecodeBase64[t ]:= char((byte(s[i ]) shl 2) or (byte(s[i + 1]) shr 4)); |
|
481 |
DecodeBase64[t + 1]:= char((byte(s[i + 1]) shl 4) or (byte(s[i + 2]) shr 2)); |
|
482 |
DecodeBase64[t + 2]:= char((byte(s[i + 2]) shl 6) or (byte(s[i + 3]) )); |
|
483 |
inc(t, 3); |
|
484 |
inc(i, 4) |
|
485 |
end; |
|
486 |
||
487 |
if c < 3 then t:= t - c; |
|
488 |
||
489 |
byte(DecodeBase64[0]):= t - 1 |
|
490 |
end; |
|
491 |
||
1906 | 492 |
const GL_BGR = $80E0; // some opengl headers don't have that const (?)' |
1080 | 493 |
procedure MakeScreenshot(s: shortstring); |
494 |
const head: array[0..8] of Word = (0, 2, 0, 0, 0, 0, 0, 0, 24); |
|
495 |
var p: Pointer; |
|
496 |
size: Longword; |
|
497 |
f: file; |
|
498 |
begin |
|
499 |
head[6]:= cScreenWidth; |
|
500 |
head[7]:= cScreenHeight; |
|
501 |
||
502 |
size:= cScreenWidth * cScreenHeight * 3; |
|
503 |
p:= GetMem(size); |
|
504 |
||
1916 | 505 |
{$IFDEF IPHONE} |
506 |
//since opengl es operates on a single surface GL_FRONT is implied, but how to test that? |
|
507 |
{$ELSE} |
|
1080 | 508 |
glReadBuffer(GL_FRONT); |
1916 | 509 |
{$ENDIF} |
1080 | 510 |
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p); |
511 |
||
512 |
{$I-} |
|
513 |
Assign(f, s); |
|
514 |
Rewrite(f, 1); |
|
515 |
if IOResult = 0 then |
|
516 |
begin |
|
517 |
BlockWrite(f, head, sizeof(head)); |
|
518 |
BlockWrite(f, p^, size); |
|
519 |
Close(f); |
|
520 |
end; |
|
521 |
{$I+} |
|
522 |
||
523 |
FreeMem(p) |
|
524 |
end; |
|
525 |
||
1861 | 526 |
function modifyDamage(dmg: Longword): Longword; |
527 |
begin |
|
1895 | 528 |
ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent) |
1861 | 529 |
end; |
530 |
||
949 | 531 |
{$IFDEF DEBUGFILE} |
532 |
procedure AddFileLog(s: shortstring); |
|
533 |
begin |
|
534 |
writeln(f, GameTicks: 6, ': ', s); |
|
535 |
flush(f) |
|
536 |
end; |
|
537 |
||
538 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
|
539 |
begin |
|
540 |
RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
|
541 |
end; |
|
542 |
||
371 | 543 |
var i: LongInt; |
488 | 544 |
{$ENDIF} |
306 | 545 |
|
4 | 546 |
initialization |
351 | 547 |
cDrownSpeed.QWordValue:= 257698038;// 0.06 |
488 | 548 |
cMaxWindSpeed.QWordValue:= 2147484;// 0.0005 |
549 |
cWindSpeed.QWordValue:= 429496;// 0.0001 |
|
351 | 550 |
cGravity:= cMaxWindSpeed; |
1849 | 551 |
cDamageModifier:= _1; |
1854 | 552 |
cLaserSighting:= false; |
2017 | 553 |
cVampiric:= false; |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2017
diff
changeset
|
554 |
cArtillery:= false; |
351 | 555 |
|
488 | 556 |
{$IFDEF DEBUGFILE} |
337 | 557 |
{$I-} |
2008 | 558 |
if ParamCount >= 0 then |
559 |
//this check prevents a crash in Mac OS X |
|
560 |
if ParamCount = 0 then |
|
561 |
begin |
|
562 |
Assign(f, '/tmp/debug.txt'); |
|
563 |
rewrite(f); |
|
564 |
end else |
|
565 |
begin |
|
497 | 566 |
for i:= 0 to 7 do |
337 | 567 |
begin |
497 | 568 |
Assign(f, ParamStr(1) + '/debug' + inttostr(i) + '.txt'); |
337 | 569 |
rewrite(f); |
570 |
if IOResult = 0 then break |
|
571 |
end; |
|
2008 | 572 |
end; |
337 | 573 |
{$I+} |
17 | 574 |
|
4 | 575 |
finalization |
916 | 576 |
//uRandom.DumpBuffer; |
4 | 577 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
578 |
Flush(f); |
|
351 | 579 |
close(f) |
4 | 580 |
{$ENDIF} |
581 |
||
582 |
end. |