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