author | unc0rr |
Sun, 15 Feb 2009 20:29:52 +0000 | |
changeset 1800 | f1df2eb32a16 |
parent 1797 | fedd8649fdd9 |
child 1812 | 3d4692e825e7 |
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 |
|
753 | 21 |
uses uConsts, SDLh, uFloat, GL; |
4 | 22 |
{$INCLUDE options.inc} |
1054 | 23 |
var |
24 |
isCursorVisible : boolean = false; |
|
25 |
isTerminated : boolean = false; |
|
26 |
isInLag : boolean = false; |
|
27 |
isPaused : boolean = false; |
|
28 |
isSoundEnabled : boolean = true; |
|
1128 | 29 |
isMusicEnabled : boolean = false; |
1054 | 30 |
isSEBackup : boolean = true; |
31 |
isInMultiShoot : boolean = false; |
|
32 |
isSpeed : boolean = false; |
|
4 | 33 |
|
1560
e140bc57ff68
Quick replay round to spectators until current move
unc0rr
parents:
1530
diff
changeset
|
34 |
fastUntilLag : boolean = false; |
e140bc57ff68
Quick replay round to spectators until current move
unc0rr
parents:
1530
diff
changeset
|
35 |
|
1054 | 36 |
GameState : TGameState = Low(TGameState); |
37 |
GameType : TGameType = gmtLocal; |
|
38 |
GameFlags : Longword = 0; |
|
39 |
TurnTimeLeft : Longword = 0; |
|
1784 | 40 |
cSuddenDTurns : LongInt = 15; |
1797 | 41 |
cTemplateFilter : LongInt = 0; |
42 |
||
1054 | 43 |
cHedgehogTurnTime: Longword = 45000; |
44 |
cMaxAIThinkTime : Longword = 9000; |
|
4 | 45 |
|
1054 | 46 |
cCloudsNumber : LongInt = 9; |
47 |
cScreenWidth : LongInt = 1024; |
|
48 |
cScreenHeight : LongInt = 768; |
|
1121
d595dc56b4f3
Remember initial resolution settings to use when switching to fullscreen mode
unc0rr
parents:
1080
diff
changeset
|
49 |
cInitWidth : LongInt = 1024; |
d595dc56b4f3
Remember initial resolution settings to use when switching to fullscreen mode
unc0rr
parents:
1080
diff
changeset
|
50 |
cInitHeight : LongInt = 768; |
1054 | 51 |
cBits : LongInt = 16; |
52 |
cBitsStr : string[2] = '16'; |
|
53 |
cTagsMask : byte = 7; |
|
74 | 54 |
|
1760 | 55 |
cWaterLine : LongInt = LAND_HEIGHT; |
1054 | 56 |
cVisibleWater : LongInt = 128; |
57 |
cGearScrEdgesDist: LongInt = 240; |
|
1530 | 58 |
cCursorEdgesDist : LongInt = 100; |
1054 | 59 |
cTeamHealthWidth : LongInt = 128; |
60 |
cAltDamage : boolean = true; |
|
4 | 61 |
|
1054 | 62 |
GameTicks : LongWord = 0; |
63 |
||
64 |
cSkyColor : Longword = 0; |
|
65 |
cWhiteColor : Longword = $FFFFFFFF; |
|
66 |
cColorNearBlack : Longword = $FF000010; |
|
67 |
cExplosionBorderColor : LongWord = $808080; |
|
4 | 68 |
|
1054 | 69 |
cShowFPS : boolean = true; |
1298 | 70 |
cCaseFactor : Longword = 5; {0..9} |
1054 | 71 |
cLandAdditions: Longword = 4; |
72 |
cFullScreen : boolean = true; |
|
73 |
cLocaleFName : shortstring = 'en.txt'; |
|
74 |
cSeed : shortstring = ''; |
|
75 |
cInitVolume : LongInt = 128; |
|
76 |
cVolumeDelta : LongInt = 0; |
|
77 |
cTimerInterval : Longword = 5; |
|
78 |
cHasFocus : boolean = true; |
|
1057 | 79 |
cInactDelay : Longword = 1250; |
4 | 80 |
|
1054 | 81 |
bBetweenTurns: boolean = false; |
1055
9af540b23409
Water rises after 25 mins of round, health is decreased after 20 mins
unc0rr
parents:
1054
diff
changeset
|
82 |
cHealthDecrease: LongWord = 0; |
9af540b23409
Water rises after 25 mins of round, health is decreased after 20 mins
unc0rr
parents:
1054
diff
changeset
|
83 |
bWaterRising : Boolean = false; |
4 | 84 |
|
614 | 85 |
{$WARNINGS OFF} |
1124 | 86 |
cAirPlaneSpeed: hwFloat = (isNegative: false; QWordValue: 3006477107); // 1.4 |
1054 | 87 |
cBombsSpeed : hwFloat = (isNegative: false; QWordValue: 429496729); |
614 | 88 |
{$WARNINGS ON} |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
539
diff
changeset
|
89 |
|
4 | 90 |
var |
1054 | 91 |
cSendEmptyPacketTime : LongWord = 2000; |
92 |
cSendCursorPosTime : LongWord = 50; |
|
93 |
ShowCrosshair : boolean; |
|
94 |
cDrownSpeed, |
|
95 |
cMaxWindSpeed, |
|
96 |
cWindSpeed, |
|
97 |
cGravity: hwFloat; |
|
4 | 98 |
|
1054 | 99 |
flagMakeCapture: boolean = false; |
4 | 100 |
|
1054 | 101 |
InitStepsFlags: Longword = 0; |
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
102 |
|
1054 | 103 |
RealTicks: Longword = 0; |
836 | 104 |
|
1054 | 105 |
AttackBar: LongInt = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
4 | 106 |
|
371 | 107 |
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
|
108 |
function Min(a, b: LongInt): LongInt; |
371 | 109 |
function Max(a, b: LongInt): LongInt; |
351 | 110 |
procedure OutError(Msg: String; isFatalError: boolean); |
4 | 111 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
112 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
316 | 113 |
function IntToStr(n: LongInt): shortstring; |
351 | 114 |
function FloatToStr(n: hwFloat): shortstring; |
775 | 115 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
371 | 116 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
117 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
|
4 | 118 |
procedure AdjustColor(var Color: Longword); |
119 |
{$IFDEF DEBUGFILE} |
|
120 |
procedure AddFileLog(s: shortstring); |
|
24 | 121 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
4 | 122 |
{$ENDIF} |
208 | 123 |
procedure SetKB(n: Longword); |
124 |
procedure SendKB; |
|
351 | 125 |
procedure SetLittle(var r: hwFloat); |
306 | 126 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
753 | 127 |
function Str2PChar(const s: shortstring): PChar; |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
128 |
function NewTexture(width, height: Longword; buf: Pointer): PTexture; |
755 | 129 |
function Surface2Tex(surf: PSDL_Surface): PTexture; |
759 | 130 |
procedure FreeTexture(tex: PTexture); |
945
4ead9cde4e14
- Start chat implementation: chat strings are on the screen
unc0rr
parents:
916
diff
changeset
|
131 |
function toPowerOf2(i: Longword): Longword; |
949 | 132 |
function DecodeBase64(s: shortstring): shortstring; |
1080 | 133 |
procedure MakeScreenshot(s: shortstring); |
4 | 134 |
|
135 |
var CursorPoint: TPoint; |
|
136 |
TargetPoint: TPoint = (X: NoPointX; Y: 0); |
|
137 |
||
138 |
implementation |
|
771 | 139 |
uses uConsole, uStore, uIO, Math, uRandom, GLU; |
208 | 140 |
var KBnum: Longword = 0; |
4 | 141 |
{$IFDEF DEBUGFILE} |
142 |
var f: textfile; |
|
143 |
{$ENDIF} |
|
144 |
||
371 | 145 |
function hwSign(r: hwFloat): LongInt; |
4 | 146 |
begin |
351 | 147 |
if r.isNegative then hwSign:= -1 else hwSign:= 1 |
4 | 148 |
end; |
149 |
||
371 | 150 |
function Min(a, b: LongInt): LongInt; |
4 | 151 |
begin |
351 | 152 |
if a < b then Min:= a else Min:= b |
4 | 153 |
end; |
154 |
||
371 | 155 |
function Max(a, b: LongInt): LongInt; |
4 | 156 |
begin |
351 | 157 |
if a > b then Max:= a else Max:= b |
4 | 158 |
end; |
159 |
||
351 | 160 |
procedure OutError(Msg: String; isFatalError: boolean); |
4 | 161 |
begin |
162 |
{$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 163 |
WriteLnToConsole(Msg); |
4 | 164 |
if isFatalError then |
165 |
begin |
|
53 | 166 |
SendIPC('E' + GetLastConsoleLine); |
4 | 167 |
SDL_Quit; |
168 |
halt(1) |
|
53 | 169 |
end |
4 | 170 |
end; |
171 |
||
172 |
procedure TryDo(Assert: boolean; Msg: string; isFatal: boolean); |
|
173 |
begin |
|
70 | 174 |
if not Assert then OutError(Msg, isFatal) |
4 | 175 |
end; |
176 |
||
177 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
178 |
begin |
|
179 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
180 |
end; |
|
181 |
||
188 | 182 |
procedure AdjustColor(var Color: Longword); |
4 | 183 |
begin |
184 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
185 |
end; |
|
186 |
||
316 | 187 |
function IntToStr(n: LongInt): shortstring; |
4 | 188 |
begin |
351 | 189 |
str(n, IntToStr) |
4 | 190 |
end; |
191 |
||
351 | 192 |
function FloatToStr(n: hwFloat): shortstring; |
4 | 193 |
begin |
1346 | 194 |
FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue)) |
4 | 195 |
end; |
196 |
||
775 | 197 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
198 |
var dY, dX: Extended; |
|
199 |
begin |
|
200 |
dY:= _dY.QWordValue / $100000000; |
|
201 |
if _dY.isNegative then dY:= - dY; |
|
202 |
dX:= _dX.QWordValue / $100000000; |
|
203 |
if _dX.isNegative then dX:= - dX; |
|
204 |
DxDy2Angle:= arctan2(dY, dX) * 180 / pi |
|
205 |
end; |
|
206 |
||
371 | 207 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
100 | 208 |
const _16divPI: Extended = 16/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
209 |
var dY, dX: Extended; |
100 | 210 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
211 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
212 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
213 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
214 |
if _dX.isNegative then dX:= - dX; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
215 |
DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
4 | 216 |
end; |
217 |
||
371 | 218 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
100 | 219 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
220 |
var dY, dX: Extended; |
100 | 221 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
222 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
223 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
224 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
225 |
if _dX.isNegative then dX:= - dX; |
438 | 226 |
DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
100 | 227 |
end; |
4 | 228 |
|
208 | 229 |
procedure SetKB(n: Longword); |
230 |
begin |
|
231 |
KBnum:= n |
|
232 |
end; |
|
233 |
||
234 |
procedure SendKB; |
|
235 |
var s: shortstring; |
|
236 |
begin |
|
237 |
if KBnum <> 0 then |
|
238 |
begin |
|
239 |
s:= 'K' + inttostr(KBnum); |
|
240 |
SendIPCRaw(@s, Length(s) + 1) |
|
241 |
end |
|
242 |
end; |
|
243 |
||
351 | 244 |
procedure SetLittle(var r: hwFloat); |
300 | 245 |
begin |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
543
diff
changeset
|
246 |
r:= SignAs(cLittle, r) |
300 | 247 |
end; |
248 |
||
337 | 249 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
1625 | 250 |
const stc: array [TStatInfoType] of char = 'rDkKH'; |
337 | 251 |
begin |
252 |
SendIPC('i' + stc[sit] + s) |
|
253 |
end; |
|
254 |
||
534 | 255 |
function Str2PChar(const s: shortstring): PChar; |
351 | 256 |
const CharArray: array[byte] of Char = ''; |
257 |
begin |
|
258 |
CharArray:= s; |
|
259 |
CharArray[Length(s)]:= #0; |
|
260 |
Str2PChar:= @CharArray |
|
261 |
end; |
|
262 |
||
771 | 263 |
function isPowerOf2(i: Longword): boolean; |
264 |
begin |
|
265 |
if i = 0 then exit(true); |
|
266 |
while (i and 1) = 0 do i:= i shr 1; |
|
267 |
isPowerOf2:= (i = 1) |
|
268 |
end; |
|
269 |
||
270 |
function toPowerOf2(i: Longword): Longword; |
|
271 |
begin |
|
272 |
toPowerOf2:= 1; |
|
273 |
while (toPowerOf2 < i) do toPowerOf2:= toPowerOf2 shl 1 |
|
274 |
end; |
|
275 |
||
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
276 |
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
|
277 |
begin |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
278 |
new(NewTexture); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
279 |
NewTexture^.w:= width; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
280 |
NewTexture^.h:= height; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
281 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
282 |
glGenTextures(1, @NewTexture^.id); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
283 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
284 |
glBindTexture(GL_TEXTURE_2D, NewTexture^.id); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
285 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
286 |
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
|
287 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
288 |
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
|
289 |
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
|
290 |
end; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
291 |
|
755 | 292 |
function Surface2Tex(surf: PSDL_Surface): PTexture; |
753 | 293 |
var mode: LongInt; |
771 | 294 |
tw, th: Longword; |
295 |
tmpp: pointer; |
|
753 | 296 |
begin |
755 | 297 |
new(Surface2Tex); |
298 |
Surface2Tex^.w:= surf^.w; |
|
299 |
Surface2Tex^.h:= surf^.h; |
|
300 |
||
753 | 301 |
if (surf^.format^.BytesPerPixel = 3) then mode:= GL_RGB else |
302 |
if (surf^.format^.BytesPerPixel = 4) then mode:= GL_RGBA else |
|
303 |
begin |
|
869 | 304 |
TryDo(false, 'Surface2Tex: BytesPerPixel not in [3, 4]', true); |
755 | 305 |
Surface2Tex^.id:= 0; |
753 | 306 |
exit |
307 |
end; |
|
308 |
||
755 | 309 |
glGenTextures(1, @Surface2Tex^.id); |
753 | 310 |
|
755 | 311 |
glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id); |
753 | 312 |
|
771 | 313 |
if SDL_MustLock(surf) then |
314 |
SDLTry(SDL_LockSurface(surf) >= 0, true); |
|
315 |
||
316 |
if not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h)) then |
|
317 |
begin |
|
318 |
tw:= toPowerOf2(Surf^.w); |
|
319 |
th:= toPowerOf2(Surf^.h); |
|
320 |
||
321 |
GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel); |
|
322 |
||
323 |
gluScaleImage(mode, Surf^.w, Surf^.h, GL_UNSIGNED_BYTE, |
|
324 |
Surf^.pixels, tw, th, GL_UNSIGNED_BYTE, |
|
325 |
tmpp); |
|
326 |
||
327 |
glTexImage2D(GL_TEXTURE_2D, 0, mode, tw, th, 0, mode, GL_UNSIGNED_BYTE, tmpp); |
|
328 |
||
329 |
FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) |
|
330 |
end else |
|
331 |
glTexImage2D(GL_TEXTURE_2D, 0, mode, surf^.w, surf^.h, 0, mode, GL_UNSIGNED_BYTE, surf^.pixels); |
|
753 | 332 |
|
754 | 333 |
if SDL_MustLock(surf) then |
334 |
SDL_UnlockSurface(surf); |
|
335 |
||
788
00720357601f
- Get rid of PageSimpleGame, now pressing 'quick game' just starts round
unc0rr
parents:
785
diff
changeset
|
336 |
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
|
337 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
753 | 338 |
end; |
339 |
||
759 | 340 |
procedure FreeTexture(tex: PTexture); |
341 |
begin |
|
342 |
glDeleteTextures(1, @tex^.id); |
|
343 |
dispose(tex) |
|
344 |
end; |
|
337 | 345 |
|
949 | 346 |
function DecodeBase64(s: shortstring): shortstring; |
347 |
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
|
348 |
var i, t, c: Longword; |
|
349 |
begin |
|
350 |
c:= 0; |
|
351 |
for i:= 1 to Length(s) do |
|
352 |
begin |
|
353 |
t:= Pos(s[i], table); |
|
354 |
if s[i] = '=' then inc(c); |
|
355 |
if t > 0 then byte(s[i]):= t - 1 else byte(s[i]):= 0 |
|
356 |
end; |
|
357 |
||
358 |
i:= 1; |
|
359 |
t:= 1; |
|
360 |
while i <= length(s) do |
|
361 |
begin |
|
362 |
DecodeBase64[t ]:= char((byte(s[i ]) shl 2) or (byte(s[i + 1]) shr 4)); |
|
363 |
DecodeBase64[t + 1]:= char((byte(s[i + 1]) shl 4) or (byte(s[i + 2]) shr 2)); |
|
364 |
DecodeBase64[t + 2]:= char((byte(s[i + 2]) shl 6) or (byte(s[i + 3]) )); |
|
365 |
inc(t, 3); |
|
366 |
inc(i, 4) |
|
367 |
end; |
|
368 |
||
369 |
if c < 3 then t:= t - c; |
|
370 |
||
371 |
byte(DecodeBase64[0]):= t - 1 |
|
372 |
end; |
|
373 |
||
1080 | 374 |
const GL_BGR = $80E0; // some opengl headers don't have that const (?) |
375 |
procedure MakeScreenshot(s: shortstring); |
|
376 |
const head: array[0..8] of Word = (0, 2, 0, 0, 0, 0, 0, 0, 24); |
|
377 |
var p: Pointer; |
|
378 |
size: Longword; |
|
379 |
f: file; |
|
380 |
begin |
|
381 |
head[6]:= cScreenWidth; |
|
382 |
head[7]:= cScreenHeight; |
|
383 |
||
384 |
size:= cScreenWidth * cScreenHeight * 3; |
|
385 |
p:= GetMem(size); |
|
386 |
||
387 |
glReadBuffer(GL_FRONT); |
|
388 |
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p); |
|
389 |
||
390 |
{$I-} |
|
391 |
Assign(f, s); |
|
392 |
Rewrite(f, 1); |
|
393 |
if IOResult = 0 then |
|
394 |
begin |
|
395 |
BlockWrite(f, head, sizeof(head)); |
|
396 |
BlockWrite(f, p^, size); |
|
397 |
Close(f); |
|
398 |
end; |
|
399 |
{$I+} |
|
400 |
||
401 |
FreeMem(p) |
|
402 |
end; |
|
403 |
||
949 | 404 |
{$IFDEF DEBUGFILE} |
405 |
procedure AddFileLog(s: shortstring); |
|
406 |
begin |
|
407 |
writeln(f, GameTicks: 6, ': ', s); |
|
408 |
flush(f) |
|
409 |
end; |
|
410 |
||
411 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
|
412 |
begin |
|
413 |
RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
|
414 |
end; |
|
415 |
||
371 | 416 |
var i: LongInt; |
488 | 417 |
{$ENDIF} |
306 | 418 |
|
4 | 419 |
initialization |
351 | 420 |
cDrownSpeed.QWordValue:= 257698038;// 0.06 |
488 | 421 |
cMaxWindSpeed.QWordValue:= 2147484;// 0.0005 |
422 |
cWindSpeed.QWordValue:= 429496;// 0.0001 |
|
351 | 423 |
cGravity:= cMaxWindSpeed; |
424 |
||
488 | 425 |
{$IFDEF DEBUGFILE} |
337 | 426 |
{$I-} |
497 | 427 |
if ParamCount > 0 then |
428 |
for i:= 0 to 7 do |
|
337 | 429 |
begin |
497 | 430 |
Assign(f, ParamStr(1) + '/debug' + inttostr(i) + '.txt'); |
337 | 431 |
rewrite(f); |
432 |
if IOResult = 0 then break |
|
433 |
end; |
|
434 |
{$I+} |
|
17 | 435 |
|
4 | 436 |
finalization |
916 | 437 |
//uRandom.DumpBuffer; |
4 | 438 |
writeln(f, '-= halt at ',GameTicks,' ticks =-'); |
439 |
Flush(f); |
|
351 | 440 |
close(f) |
4 | 441 |
{$ENDIF} |
442 |
||
443 |
end. |