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