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