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