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