author | nemo |
Mon, 01 Jun 2009 17:04:36 +0000 | |
changeset 2140 | 75e5c4fcae2a |
parent 2133 | 1a6570dd45d8 |
child 2147 | ffa64983dc07 |
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 |
|
2133
1a6570dd45d8
Fix lines arise when zooming. Doesn't fix water sprites.
unc0rr
parents:
2031
diff
changeset
|
336 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); |
1a6570dd45d8
Fix lines arise when zooming. Doesn't fix water sprites.
unc0rr
parents:
2031
diff
changeset
|
337 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
338 |
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
|
339 |
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
|
340 |
end; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
341 |
|
755 | 342 |
function Surface2Tex(surf: PSDL_Surface): PTexture; |
753 | 343 |
var mode: LongInt; |
1896 | 344 |
tw, th, x, y: Longword; |
345 |
tmpp: pointer; |
|
346 |
fromP4, toP4: PLongWordArray; |
|
347 |
fromP1, toP1: PByteArray; |
|
753 | 348 |
begin |
755 | 349 |
new(Surface2Tex); |
350 |
Surface2Tex^.w:= surf^.w; |
|
351 |
Surface2Tex^.h:= surf^.h; |
|
352 |
||
753 | 353 |
if (surf^.format^.BytesPerPixel = 3) then mode:= GL_RGB else |
354 |
if (surf^.format^.BytesPerPixel = 4) then mode:= GL_RGBA else |
|
355 |
begin |
|
869 | 356 |
TryDo(false, 'Surface2Tex: BytesPerPixel not in [3, 4]', true); |
755 | 357 |
Surface2Tex^.id:= 0; |
753 | 358 |
exit |
359 |
end; |
|
360 |
||
755 | 361 |
glGenTextures(1, @Surface2Tex^.id); |
753 | 362 |
|
755 | 363 |
glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id); |
753 | 364 |
|
771 | 365 |
if SDL_MustLock(surf) then |
366 |
SDLTry(SDL_LockSurface(surf) >= 0, true); |
|
367 |
||
368 |
if not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h)) then |
|
1896 | 369 |
begin |
370 |
tw:= toPowerOf2(Surf^.w); |
|
371 |
th:= toPowerOf2(Surf^.h); |
|
372 |
||
373 |
Surface2Tex^.rx:= Surf^.w / tw; |
|
374 |
Surface2Tex^.ry:= Surf^.h / th; |
|
375 |
||
376 |
GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel); |
|
377 |
||
378 |
if surf^.format^.BytesPerPixel = 4 then |
|
379 |
begin |
|
380 |
fromP4:= Surf^.pixels; |
|
381 |
toP4:= tmpp; |
|
771 | 382 |
|
1896 | 383 |
for y:= 0 to Pred(Surf^.h) do |
384 |
begin |
|
385 |
for x:= 0 to Pred(Surf^.w) do |
|
386 |
toP4^[x]:= fromP4^[x]; |
|
387 |
for x:= Surf^.w to Pred(tw) do |
|
388 |
toP4^[x]:= 0; |
|
389 |
toP4:= @(toP4^[tw]); |
|
2017 | 390 |
fromP4:= @(fromP4^[Surf^.pitch div 4]); |
1896 | 391 |
end; |
392 |
||
393 |
for y:= Surf^.h to Pred(th) do |
|
394 |
begin |
|
395 |
for x:= 0 to Pred(tw) do |
|
396 |
toP4^[x]:= 0; |
|
397 |
toP4:= @(toP4^[tw]); |
|
398 |
end; |
|
399 |
end |
|
400 |
else |
|
401 |
begin |
|
402 |
fromP1:= Surf^.pixels; |
|
403 |
toP1:= tmpp; |
|
771 | 404 |
|
1896 | 405 |
for y:= 0 to Pred(Surf^.h) do |
406 |
begin |
|
407 |
for x:= 0 to Pred(Surf^.w) do |
|
408 |
begin |
|
409 |
toP1^[x * 3]:= fromP1^[x * 3]; |
|
410 |
toP1^[x * 3 + 1]:= fromP1^[x * 3 + 1]; |
|
411 |
toP1^[x * 3 + 2]:= fromP1^[x * 3 + 2]; |
|
412 |
end; |
|
413 |
for x:= Surf^.w to Pred(tw) do |
|
414 |
begin |
|
415 |
toP1^[x * 3]:= 0; |
|
416 |
toP1^[x * 3 + 1]:= 0; |
|
417 |
toP1^[x * 3 + 2]:= 0; |
|
418 |
end; |
|
419 |
toP1:= @(toP1^[tw * 3]); |
|
420 |
fromP1:= @(fromP1^[Surf^.pitch]); |
|
421 |
end; |
|
771 | 422 |
|
1896 | 423 |
for y:= Surf^.h to Pred(th) do |
424 |
begin |
|
425 |
for x:= 0 to Pred(tw) do |
|
426 |
begin |
|
427 |
toP1^[x * 3]:= 0; |
|
428 |
toP1^[x * 3 + 1]:= 0; |
|
429 |
toP1^[x * 3 + 2]:= 0; |
|
430 |
end; |
|
431 |
toP1:= @(toP1^[tw * 3]); |
|
432 |
end; |
|
433 |
end; |
|
771 | 434 |
|
1896 | 435 |
// gluScaleImage(mode, Surf^.w, Surf^.h, GL_UNSIGNED_BYTE, |
436 |
// Surf^.pixels, tw, th, GL_UNSIGNED_BYTE, |
|
437 |
// tmpp); |
|
438 |
||
439 |
glTexImage2D(GL_TEXTURE_2D, 0, mode, tw, th, 0, mode, GL_UNSIGNED_BYTE, tmpp); |
|
440 |
||
441 |
FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) |
|
442 |
end else |
|
443 |
begin |
|
444 |
Surface2Tex^.rx:= 1.0; |
|
445 |
Surface2Tex^.ry:= 1.0; |
|
446 |
glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels); |
|
447 |
end; |
|
753 | 448 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
449 |
ResetVertexArrays(Surface2Tex); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
450 |
|
754 | 451 |
if SDL_MustLock(surf) then |
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
452 |
SDL_UnlockSurface(surf); |
754 | 453 |
|
2133
1a6570dd45d8
Fix lines arise when zooming. Doesn't fix water sprites.
unc0rr
parents:
2031
diff
changeset
|
454 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); |
1a6570dd45d8
Fix lines arise when zooming. Doesn't fix water sprites.
unc0rr
parents:
2031
diff
changeset
|
455 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); |
788
00720357601f
- Get rid of PageSimpleGame, now pressing 'quick game' just starts round
unc0rr
parents:
785
diff
changeset
|
456 |
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
|
457 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
753 | 458 |
end; |
459 |
||
759 | 460 |
procedure FreeTexture(tex: PTexture); |
461 |
begin |
|
2000
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
462 |
if tex <> nil then |
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
463 |
begin |
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
464 |
glDeleteTextures(1, @tex^.id); |
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
465 |
dispose(tex) |
f9f47e681aad
Don't crash engine after round in reduced quality mode
unc0rr
parents:
1916
diff
changeset
|
466 |
end |
759 | 467 |
end; |
337 | 468 |
|
949 | 469 |
function DecodeBase64(s: shortstring): shortstring; |
470 |
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
|
471 |
var i, t, c: Longword; |
|
472 |
begin |
|
473 |
c:= 0; |
|
474 |
for i:= 1 to Length(s) do |
|
475 |
begin |
|
476 |
t:= Pos(s[i], table); |
|
477 |
if s[i] = '=' then inc(c); |
|
478 |
if t > 0 then byte(s[i]):= t - 1 else byte(s[i]):= 0 |
|
479 |
end; |
|
480 |
||
481 |
i:= 1; |
|
482 |
t:= 1; |
|
483 |
while i <= length(s) do |
|
484 |
begin |
|
485 |
DecodeBase64[t ]:= char((byte(s[i ]) shl 2) or (byte(s[i + 1]) shr 4)); |
|
486 |
DecodeBase64[t + 1]:= char((byte(s[i + 1]) shl 4) or (byte(s[i + 2]) shr 2)); |
|
487 |
DecodeBase64[t + 2]:= char((byte(s[i + 2]) shl 6) or (byte(s[i + 3]) )); |
|
488 |
inc(t, 3); |
|
489 |
inc(i, 4) |
|
490 |
end; |
|
491 |
||
492 |
if c < 3 then t:= t - c; |
|
493 |
||
494 |
byte(DecodeBase64[0]):= t - 1 |
|
495 |
end; |
|
496 |
||
1906 | 497 |
const GL_BGR = $80E0; // some opengl headers don't have that const (?)' |
1080 | 498 |
procedure MakeScreenshot(s: shortstring); |
499 |
const head: array[0..8] of Word = (0, 2, 0, 0, 0, 0, 0, 0, 24); |
|
500 |
var p: Pointer; |
|
501 |
size: Longword; |
|
502 |
f: file; |
|
503 |
begin |
|
504 |
head[6]:= cScreenWidth; |
|
505 |
head[7]:= cScreenHeight; |
|
506 |
||
507 |
size:= cScreenWidth * cScreenHeight * 3; |
|
508 |
p:= GetMem(size); |
|
509 |
||
1916 | 510 |
{$IFDEF IPHONE} |
511 |
//since opengl es operates on a single surface GL_FRONT is implied, but how to test that? |
|
512 |
{$ELSE} |
|
1080 | 513 |
glReadBuffer(GL_FRONT); |
1916 | 514 |
{$ENDIF} |
1080 | 515 |
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p); |
516 |
||
517 |
{$I-} |
|
518 |
Assign(f, s); |
|
519 |
Rewrite(f, 1); |
|
520 |
if IOResult = 0 then |
|
521 |
begin |
|
522 |
BlockWrite(f, head, sizeof(head)); |
|
523 |
BlockWrite(f, p^, size); |
|
524 |
Close(f); |
|
525 |
end; |
|
526 |
{$I+} |
|
527 |
||
528 |
FreeMem(p) |
|
529 |
end; |
|
530 |
||
1861 | 531 |
function modifyDamage(dmg: Longword): Longword; |
532 |
begin |
|
1895 | 533 |
ModifyDamage:= hwRound(_0_01 * cDamageModifier * dmg * cDamagePercent) |
1861 | 534 |
end; |
535 |
||
949 | 536 |
{$IFDEF DEBUGFILE} |
537 |
procedure AddFileLog(s: shortstring); |
|
538 |
begin |
|
539 |
writeln(f, GameTicks: 6, ': ', s); |
|
540 |
flush(f) |
|
541 |
end; |
|
542 |
||
543 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
|
544 |
begin |
|
545 |
RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
|
546 |
end; |
|
547 |
||
371 | 548 |
var i: LongInt; |
488 | 549 |
{$ENDIF} |
306 | 550 |
|
4 | 551 |
initialization |
351 | 552 |
cDrownSpeed.QWordValue:= 257698038;// 0.06 |
488 | 553 |
cMaxWindSpeed.QWordValue:= 2147484;// 0.0005 |
554 |
cWindSpeed.QWordValue:= 429496;// 0.0001 |
|
351 | 555 |
cGravity:= cMaxWindSpeed; |
1849 | 556 |
cDamageModifier:= _1; |
1854 | 557 |
cLaserSighting:= false; |
2017 | 558 |
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
|
559 |
cArtillery:= false; |
351 | 560 |
|
488 | 561 |
{$IFDEF DEBUGFILE} |
337 | 562 |
{$I-} |
2008 | 563 |
if ParamCount >= 0 then |
564 |
//this check prevents a crash in Mac OS X |
|
565 |
if ParamCount = 0 then |
|
566 |
begin |
|
567 |
Assign(f, '/tmp/debug.txt'); |
|
568 |
rewrite(f); |
|
569 |
end else |
|
570 |
begin |
|
497 | 571 |
for i:= 0 to 7 do |
337 | 572 |
begin |
497 | 573 |
Assign(f, ParamStr(1) + '/debug' + inttostr(i) + '.txt'); |
337 | 574 |
rewrite(f); |
575 |
if IOResult = 0 then break |
|
576 |
end; |
|
2008 | 577 |
end; |
337 | 578 |
{$I+} |
17 | 579 |
|
4 | 580 |
finalization |
916 | 581 |
//uRandom.DumpBuffer; |
4 | 582 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
583 |
Flush(f); |
|
351 | 584 |
close(f) |
4 | 585 |
{$ENDIF} |
586 |
||
587 |
end. |