author | smaxx |
Mon, 26 Jul 2010 11:04:32 +0200 | |
changeset 3677 | 7d917b587547 |
parent 3670 | 4c673e57f0d7 |
child 3676 | fa29572fa56a |
child 3686 | 617d00c850b0 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
2947 | 2 |
* Hedgewars, a free turn based strategy game |
3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
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 |
|
8 |
* |
|
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. |
|
13 |
* |
|
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 |
|
17 |
*) |
|
4 | 18 |
|
2630 | 19 |
{$INCLUDE "options.inc"} |
3599 | 20 |
{$INLINE ON} |
2630 | 21 |
|
4 | 22 |
unit uMisc; |
23 |
interface |
|
2630 | 24 |
|
3593
ae50f63e4fa9
Remove hwFloat from VisualGears - they don't need the precision for syncing purposes, and it saves a whole lot of operations.
nemo
parents:
3537
diff
changeset
|
25 |
uses SDLh, uConsts, uFloat, GLunit, Math; |
2697 | 26 |
|
1054 | 27 |
var |
2947 | 28 |
isCursorVisible : boolean; |
29 |
isTerminated : boolean; |
|
30 |
isInLag : boolean; |
|
31 |
isPaused : boolean; |
|
3611 | 32 |
|
2947 | 33 |
isSEBackup : boolean; |
34 |
isInMultiShoot : boolean; |
|
35 |
isSpeed : boolean; |
|
3107 | 36 |
isFirstFrame : boolean; |
1560
e140bc57ff68
Quick replay round to spectators until current move
unc0rr
parents:
1530
diff
changeset
|
37 |
|
2947 | 38 |
fastUntilLag : boolean; |
1888
e76274ce7365
Add an ability to run engine without IPC connection.
unc0rr
parents:
1861
diff
changeset
|
39 |
|
3611 | 40 |
GameState : TGameState; |
41 |
GameType : TGameType; |
|
42 |
GameFlags : Longword; |
|
2947 | 43 |
TrainingFlags : Longword; |
44 |
TurnTimeLeft : Longword; |
|
45 |
cSuddenDTurns : LongInt; |
|
46 |
cDamagePercent : LongInt; |
|
47 |
cMineDudPercent : LongWord; |
|
48 |
cTemplateFilter : LongInt; |
|
3133 | 49 |
cMapGen : LongInt; |
50 |
cMazeSize : LongInt; |
|
4 | 51 |
|
2947 | 52 |
cHedgehogTurnTime: Longword; |
53 |
cMinesTime : LongInt; |
|
54 |
cMaxAIThinkTime : Longword; |
|
74 | 55 |
|
2947 | 56 |
cCloudsNumber : LongInt; |
3611 | 57 |
|
2947 | 58 |
cTagsMask : byte; |
59 |
zoom : GLfloat; |
|
60 |
ZoomValue : GLfloat; |
|
4 | 61 |
|
2947 | 62 |
cWaterLine : LongInt; |
63 |
cGearScrEdgesDist: LongInt; |
|
1054 | 64 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
65 |
GameTicks : LongWord; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
66 |
TrainingTimeInc : Longword; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
67 |
TrainingTimeInD : Longword; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
68 |
TrainingTimeInM : Longword; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
69 |
TrainingTimeMax : Longword; |
2666 | 70 |
|
2947 | 71 |
TimeTrialStartTime: Longword; |
72 |
TimeTrialStopTime : Longword; |
|
73 |
||
3611 | 74 |
// init flags |
75 |
cScreenWidth : LongInt = 1024; |
|
76 |
cScreenHeight : LongInt = 768; |
|
77 |
cBits : LongInt = 32; |
|
78 |
cBitsStr : string[2] = '32'; |
|
79 |
//ipcPort is in uIO |
|
80 |
cFullScreen : boolean = false; |
|
81 |
isSoundEnabled : boolean = true; |
|
82 |
isMusicEnabled : boolean = false; |
|
83 |
cLocaleFName : shortstring = 'en.txt'; |
|
84 |
cInitVolume : LongInt = 50; |
|
85 |
cTimerInterval : LongInt = 8; |
|
86 |
//pathPrefix is in uConsts |
|
87 |
cShowFPS : boolean = false; |
|
88 |
cAltDamage : boolean = true; |
|
3613 | 89 |
cReducedQuality : LongInt = rqNone; |
3611 | 90 |
|
91 |
recordFileName : shortstring = ''; |
|
92 |
||
93 |
cCaseFactor : Longword; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
94 |
cLandAdditions : Longword; |
3611 | 95 |
cExplosives : Longword; |
96 |
||
97 |
cSeed : shortstring; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
98 |
cVolumeDelta : LongInt; |
3611 | 99 |
cHasFocus : boolean; |
100 |
cInactDelay : Longword; |
|
4 | 101 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
102 |
bBetweenTurns : boolean; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
103 |
cHealthDecrease : LongWord; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
104 |
bWaterRising : Boolean; |
543
465e2ec8f05f
- Better randomness of placing hedgehogs on the land
unc0rr
parents:
539
diff
changeset
|
105 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
106 |
ShowCrosshair : boolean; |
3169
c8c6ac44f51b
prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents:
3165
diff
changeset
|
107 |
CursorMovementX : LongInt; |
c8c6ac44f51b
prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents:
3165
diff
changeset
|
108 |
CursorMovementY : LongInt; |
3611 | 109 |
cDrownSpeed : hwFloat; |
110 |
cDrownSpeedf : float; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
111 |
cMaxWindSpeed : hwFloat; |
3611 | 112 |
cWindSpeed : hwFloat; |
113 |
cWindSpeedf : float; |
|
114 |
cGravity : hwFloat; |
|
115 |
cGravityf : float; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
116 |
cDamageModifier : hwFloat; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
117 |
cLaserSighting : boolean; |
3611 | 118 |
cVampiric : boolean; |
119 |
cArtillery : boolean; |
|
2947 | 120 |
WeaponTooltipTex : PTexture; |
4 | 121 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
122 |
flagMakeCapture : boolean; |
55
e09f7c952a40
Send run parameters by cmd line, game parameters by IPC... breaks network game
unc0rr
parents:
53
diff
changeset
|
123 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
124 |
InitStepsFlags : Longword; |
3611 | 125 |
RealTicks : Longword; |
126 |
AttackBar : LongInt; |
|
836 | 127 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
128 |
WaterColorArray : array[0..3] of HwColor4f; |
4 | 129 |
|
3611 | 130 |
CursorPoint : TPoint; |
131 |
TargetPoint : TPoint; |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
132 |
|
3611 | 133 |
TextureList : PTexture; |
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
134 |
|
3611 | 135 |
ScreenFade : TScreenFade; |
3115 | 136 |
ScreenFadeValue : LongInt; |
137 |
ScreenFadeSpeed : LongInt; |
|
3107 | 138 |
|
3598 | 139 |
{$IFDEF SDL13} |
3611 | 140 |
SDLwindow : PSDL_Window; |
3598 | 141 |
{$ENDIF} |
2630 | 142 |
|
3038 | 143 |
procedure initModule; |
144 |
procedure freeModule; |
|
2747 | 145 |
procedure SplitBySpace(var a, b: shortstring); |
2905 | 146 |
procedure SplitByChar(var a, b: ansistring; c: char); |
3611 | 147 |
function EnumToStr(const en : TGearType) : shortstring; overload; |
148 |
function EnumToStr(const en : TSound) : shortstring; overload; |
|
149 |
function EnumToStr(const en : TAmmoType) : shortstring; overload; |
|
3169
c8c6ac44f51b
prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents:
3165
diff
changeset
|
150 |
procedure movecursor(dx, dy: LongInt); |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
151 |
function hwSign(r: hwFloat): LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
152 |
function Min(a, b: LongInt): LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
153 |
function Max(a, b: LongInt): LongInt; |
2905 | 154 |
procedure OutError(Msg: shortstring; isFatalError: boolean); |
3599 | 155 |
procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); inline; |
4 | 156 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
157 |
function IntToStr(n: LongInt): shortstring; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
158 |
function FloatToStr(n: hwFloat): shortstring; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
159 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
160 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
161 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
4 | 162 |
procedure AdjustColor(var Color: Longword); |
208 | 163 |
procedure SetKB(n: Longword); |
164 |
procedure SendKB; |
|
351 | 165 |
procedure SetLittle(var r: hwFloat); |
306 | 166 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
753 | 167 |
function Str2PChar(const s: shortstring): PChar; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
168 |
function NewTexture(width, height: Longword; buf: Pointer): PTexture; |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2279
diff
changeset
|
169 |
function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture; |
759 | 170 |
procedure FreeTexture(tex: PTexture); |
3599 | 171 |
function toPowerOf2(i: Longword): Longword; inline; |
2670 | 172 |
function DecodeBase64(s: shortstring): shortstring; |
173 |
function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; |
|
174 |
function endian(independent: LongWord): LongWord; |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
175 |
{$IFDEF DEBUGFILE} |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
176 |
procedure AddFileLog(s: shortstring); |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
177 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
178 |
{$ENDIF} |
2735 | 179 |
procedure MakeScreenshot(filename: shortstring); |
4 | 180 |
|
181 |
implementation |
|
3593
ae50f63e4fa9
Remove hwFloat from VisualGears - they don't need the precision for syncing purposes, and it saves a whole lot of operations.
nemo
parents:
3537
diff
changeset
|
182 |
uses uConsole, uStore, uIO, uSound, typinfo, sysutils; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
183 |
|
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
184 |
var KBnum: Longword; |
4 | 185 |
{$IFDEF DEBUGFILE} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
186 |
f: textfile; |
4 | 187 |
{$ENDIF} |
188 |
||
2747 | 189 |
// should this include "strtolower()" for the split string? |
190 |
procedure SplitBySpace(var a, b: shortstring); |
|
191 |
var i, t: LongInt; |
|
192 |
begin |
|
193 |
i:= Pos(' ', a); |
|
194 |
if i > 0 then |
|
2947 | 195 |
begin |
196 |
for t:= 1 to Pred(i) do |
|
197 |
if (a[t] >= 'A')and(a[t] <= 'Z') then Inc(a[t], 32); |
|
198 |
b:= copy(a, i + 1, Length(a) - i); |
|
199 |
byte(a[0]):= Pred(i) |
|
200 |
end else b:= ''; |
|
2747 | 201 |
end; |
202 |
||
2905 | 203 |
procedure SplitByChar(var a, b: ansistring; c: char); |
2747 | 204 |
var i: LongInt; |
205 |
begin |
|
206 |
i:= Pos(c, a); |
|
207 |
if i > 0 then |
|
2947 | 208 |
begin |
209 |
b:= copy(a, i + 1, Length(a) - i); |
|
210 |
setlength(a, Pred(i)); |
|
211 |
end else b:= ''; |
|
2747 | 212 |
end; |
213 |
||
3337 | 214 |
function EnumToStr(const en : TGearType) : shortstring; overload; |
215 |
begin |
|
216 |
EnumToStr:= GetEnumName(TypeInfo(TGearType), ord(en)) |
|
217 |
end; |
|
218 |
||
219 |
function EnumToStr(const en : TSound) : shortstring; overload; |
|
220 |
begin |
|
221 |
EnumToStr:= GetEnumName(TypeInfo(TSound), ord(en)) |
|
222 |
end; |
|
223 |
||
224 |
function EnumToStr(const en : TAmmoType) : shortstring; overload; |
|
225 |
begin |
|
226 |
EnumToStr:= GetEnumName(TypeInfo(TAmmoType), ord(en)) |
|
227 |
end; |
|
228 |
||
3169
c8c6ac44f51b
prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents:
3165
diff
changeset
|
229 |
procedure movecursor(dx, dy: LongInt); |
2428 | 230 |
var x, y: LongInt; |
231 |
begin |
|
232 |
if (dx = 0) and (dy = 0) then exit; |
|
2671
7e0f88013fe8
smaller patches, one missing Sky-lowres, IMG_Init and Mix_Init (might require newer libraries), updates to SDL bindings, code cleanup, new compile flags
koda
parents:
2670
diff
changeset
|
233 |
|
2428 | 234 |
SDL_GetMouseState(@x, @y); |
235 |
Inc(x, dx); |
|
236 |
Inc(y, dy); |
|
237 |
SDL_WarpMouse(x, y); |
|
238 |
end; |
|
239 |
||
371 | 240 |
function hwSign(r: hwFloat): LongInt; |
4 | 241 |
begin |
2389 | 242 |
// yes, we have negative zero for a reason |
243 |
if r.isNegative then hwSign:= -1 else hwSign:= 1 |
|
4 | 244 |
end; |
245 |
||
371 | 246 |
function Min(a, b: LongInt): LongInt; |
4 | 247 |
begin |
351 | 248 |
if a < b then Min:= a else Min:= b |
4 | 249 |
end; |
250 |
||
371 | 251 |
function Max(a, b: LongInt): LongInt; |
4 | 252 |
begin |
351 | 253 |
if a > b then Max:= a else Max:= b |
4 | 254 |
end; |
255 |
||
2905 | 256 |
procedure OutError(Msg: shortstring; isFatalError: boolean); |
4 | 257 |
begin |
3407 | 258 |
// obsolete? written in WriteLnToConsole() anyway |
259 |
// {$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
53 | 260 |
WriteLnToConsole(Msg); |
4 | 261 |
if isFatalError then |
3407 | 262 |
begin |
263 |
SendIPC('E' + GetLastConsoleLine); |
|
264 |
SDL_Quit; |
|
265 |
halt(1) |
|
266 |
end |
|
4 | 267 |
end; |
268 |
||
2905 | 269 |
procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); |
4 | 270 |
begin |
70 | 271 |
if not Assert then OutError(Msg, isFatal) |
4 | 272 |
end; |
273 |
||
274 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
275 |
begin |
|
276 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
277 |
end; |
|
278 |
||
188 | 279 |
procedure AdjustColor(var Color: Longword); |
4 | 280 |
begin |
281 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
282 |
end; |
|
283 |
||
316 | 284 |
function IntToStr(n: LongInt): shortstring; |
4 | 285 |
begin |
351 | 286 |
str(n, IntToStr) |
4 | 287 |
end; |
288 |
||
351 | 289 |
function FloatToStr(n: hwFloat): shortstring; |
4 | 290 |
begin |
1346 | 291 |
FloatToStr:= cstr(n) + '_' + inttostr(Lo(n.QWordValue)) |
4 | 292 |
end; |
293 |
||
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
294 |
procedure SetTextureParameters(enableClamp: Boolean); |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
295 |
begin |
3611 | 296 |
if enableClamp and ((cReducedQuality and rqClampLess) = 0) then |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
297 |
begin |
3594
aeca3d8f1b29
turn cReducedQuality into a LongInt and provide a series of quality flags (and best of all, this is still compatible with current frontend)
koda
parents:
3593
diff
changeset
|
298 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); |
aeca3d8f1b29
turn cReducedQuality into a LongInt and provide a series of quality flags (and best of all, this is still compatible with current frontend)
koda
parents:
3593
diff
changeset
|
299 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
300 |
end; |
3594
aeca3d8f1b29
turn cReducedQuality into a LongInt and provide a series of quality flags (and best of all, this is still compatible with current frontend)
koda
parents:
3593
diff
changeset
|
301 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
aeca3d8f1b29
turn cReducedQuality into a LongInt and provide a series of quality flags (and best of all, this is still compatible with current frontend)
koda
parents:
3593
diff
changeset
|
302 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
303 |
end; |
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
304 |
|
775 | 305 |
function DxDy2Angle(const _dY, _dX: hwFloat): GLfloat; |
306 |
var dY, dX: Extended; |
|
307 |
begin |
|
308 |
dY:= _dY.QWordValue / $100000000; |
|
309 |
if _dY.isNegative then dY:= - dY; |
|
310 |
dX:= _dX.QWordValue / $100000000; |
|
311 |
if _dX.isNegative then dX:= - dX; |
|
312 |
DxDy2Angle:= arctan2(dY, dX) * 180 / pi |
|
313 |
end; |
|
314 |
||
371 | 315 |
function DxDy2Angle32(const _dY, _dX: hwFloat): LongInt; |
100 | 316 |
const _16divPI: Extended = 16/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
317 |
var dY, dX: Extended; |
100 | 318 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
319 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
320 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
321 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
322 |
if _dX.isNegative then dX:= - dX; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
323 |
DxDy2Angle32:= trunc(arctan2(dY, dX) * _16divPI) and $1f |
4 | 324 |
end; |
325 |
||
371 | 326 |
function DxDy2AttackAngle(const _dY, _dX: hwFloat): LongInt; |
100 | 327 |
const MaxAngleDivPI: Extended = cMaxAngle/pi; |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
328 |
var dY, dX: Extended; |
100 | 329 |
begin |
370
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
330 |
dY:= _dY.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
331 |
if _dY.isNegative then dY:= - dY; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
332 |
dX:= _dX.QWordValue / $100000000; |
c75410fe3133
- Repair bots: they can walk and use bazooka, possible cannot jump (why?)
unc0rr
parents:
351
diff
changeset
|
333 |
if _dX.isNegative then dX:= - dX; |
438 | 334 |
DxDy2AttackAngle:= trunc(arctan2(dY, dX) * MaxAngleDivPI) |
100 | 335 |
end; |
4 | 336 |
|
208 | 337 |
procedure SetKB(n: Longword); |
338 |
begin |
|
339 |
KBnum:= n |
|
340 |
end; |
|
341 |
||
342 |
procedure SendKB; |
|
343 |
var s: shortstring; |
|
344 |
begin |
|
345 |
if KBnum <> 0 then |
|
2947 | 346 |
begin |
347 |
s:= 'K' + inttostr(KBnum); |
|
348 |
SendIPCRaw(@s, Length(s) + 1) |
|
349 |
end |
|
208 | 350 |
end; |
351 |
||
351 | 352 |
procedure SetLittle(var r: hwFloat); |
300 | 353 |
begin |
553
5478386d935f
- Switch to bazooka (or whatever) after use of some weapon (fixes problem with bots)
unc0rr
parents:
543
diff
changeset
|
354 |
r:= SignAs(cLittle, r) |
300 | 355 |
end; |
356 |
||
337 | 357 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
3381 | 358 |
const stc: array [TStatInfoType] of char = 'rDkKHT'; |
2382 | 359 |
var buf: shortstring; |
337 | 360 |
begin |
2382 | 361 |
buf:= 'i' + stc[sit] + s; |
362 |
SendIPCRaw(@buf[0], length(buf) + 1) |
|
337 | 363 |
end; |
364 |
||
534 | 365 |
function Str2PChar(const s: shortstring): PChar; |
351 | 366 |
const CharArray: array[byte] of Char = ''; |
367 |
begin |
|
368 |
CharArray:= s; |
|
369 |
CharArray[Length(s)]:= #0; |
|
370 |
Str2PChar:= @CharArray |
|
371 |
end; |
|
372 |
||
771 | 373 |
function isPowerOf2(i: Longword): boolean; |
374 |
begin |
|
375 |
if i = 0 then exit(true); |
|
376 |
while (i and 1) = 0 do i:= i shr 1; |
|
377 |
isPowerOf2:= (i = 1) |
|
378 |
end; |
|
379 |
||
380 |
function toPowerOf2(i: Longword): Longword; |
|
381 |
begin |
|
382 |
toPowerOf2:= 1; |
|
383 |
while (toPowerOf2 < i) do toPowerOf2:= toPowerOf2 shl 1 |
|
384 |
end; |
|
385 |
||
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
386 |
procedure ResetVertexArrays(texture: PTexture); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
387 |
begin |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
388 |
with texture^ do |
2947 | 389 |
begin |
390 |
vb[0].X:= 0; |
|
391 |
vb[0].Y:= 0; |
|
392 |
vb[1].X:= w; |
|
393 |
vb[1].Y:= 0; |
|
394 |
vb[2].X:= w; |
|
395 |
vb[2].Y:= h; |
|
396 |
vb[3].X:= 0; |
|
397 |
vb[3].Y:= h; |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
398 |
|
2947 | 399 |
tb[0].X:= 0; |
400 |
tb[0].Y:= 0; |
|
401 |
tb[1].X:= rx; |
|
402 |
tb[1].Y:= 0; |
|
403 |
tb[2].X:= rx; |
|
404 |
tb[2].Y:= ry; |
|
405 |
tb[3].X:= 0; |
|
406 |
tb[3].Y:= ry |
|
407 |
end; |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
408 |
end; |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
409 |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
410 |
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
|
411 |
begin |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
412 |
new(NewTexture); |
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
413 |
NewTexture^.PrevTexture:= nil; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
414 |
NewTexture^.NextTexture:= nil; |
3537
8f5b3108f29c
New approach to the low-res problem. Basically, we already have a 1024 minimum, and the tallest maps are restricting themselves to 2048 maximum. All backgrounds are scaled down 50%, then scaled up on draw. Saves memory, and backgrounds are already deliberately fuzzed for depth of field anyway.
nemo
parents:
3534
diff
changeset
|
415 |
NewTexture^.Scale:= 1; |
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
416 |
if TextureList <> nil then |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
417 |
begin |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
418 |
TextureList^.PrevTexture:= NewTexture; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
419 |
NewTexture^.NextTexture:= TextureList |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
420 |
end; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
421 |
TextureList:= NewTexture; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
422 |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
423 |
NewTexture^.w:= width; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
424 |
NewTexture^.h:= height; |
1896 | 425 |
NewTexture^.rx:= 1.0; |
426 |
NewTexture^.ry:= 1.0; |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
427 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
428 |
ResetVertexArrays(NewTexture); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
429 |
|
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
430 |
glGenTextures(1, @NewTexture^.id); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
431 |
|
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
432 |
glBindTexture(GL_TEXTURE_2D, NewTexture^.id); |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
433 |
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
|
434 |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
435 |
SetTextureParameters(true); |
1180
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
436 |
end; |
e56317fdf78d
Start implementing support for 32bit sprites concerned in map generation process.
unc0rr
parents:
1128
diff
changeset
|
437 |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2279
diff
changeset
|
438 |
function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture; |
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
439 |
var tw, th, x, y: Longword; |
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
440 |
tmpp: pointer; |
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
441 |
fromP4, toP4: PLongWordArray; |
753 | 442 |
begin |
755 | 443 |
new(Surface2Tex); |
2715
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
444 |
Surface2Tex^.PrevTexture:= nil; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
445 |
Surface2Tex^.NextTexture:= nil; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
446 |
if TextureList <> nil then |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
447 |
begin |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
448 |
TextureList^.PrevTexture:= Surface2Tex; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
449 |
Surface2Tex^.NextTexture:= TextureList |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
450 |
end; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
451 |
TextureList:= Surface2Tex; |
0e4e0db79e2a
Free up some unfreed memory. Needed for Koda's iphone lib work
nemo
parents:
2705
diff
changeset
|
452 |
|
755 | 453 |
Surface2Tex^.w:= surf^.w; |
454 |
Surface2Tex^.h:= surf^.h; |
|
455 |
||
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
456 |
if (surf^.format^.BytesPerPixel <> 4) then |
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
457 |
begin |
2947 | 458 |
TryDo(false, 'Surface2Tex failed, expecting 32 bit surface', true); |
459 |
Surface2Tex^.id:= 0; |
|
460 |
exit |
|
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
461 |
end; |
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
462 |
|
753 | 463 |
|
755 | 464 |
glGenTextures(1, @Surface2Tex^.id); |
753 | 465 |
|
755 | 466 |
glBindTexture(GL_TEXTURE_2D, Surface2Tex^.id); |
753 | 467 |
|
771 | 468 |
if SDL_MustLock(surf) then |
2947 | 469 |
SDLTry(SDL_LockSurface(surf) >= 0, true); |
771 | 470 |
|
2428 | 471 |
if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then |
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
472 |
begin |
2947 | 473 |
tw:= toPowerOf2(Surf^.w); |
474 |
th:= toPowerOf2(Surf^.h); |
|
1896 | 475 |
|
2947 | 476 |
Surface2Tex^.rx:= Surf^.w / tw; |
477 |
Surface2Tex^.ry:= Surf^.h / th; |
|
2376 | 478 |
|
2947 | 479 |
GetMem(tmpp, tw * th * surf^.format^.BytesPerPixel); |
1896 | 480 |
|
2947 | 481 |
fromP4:= Surf^.pixels; |
482 |
toP4:= tmpp; |
|
771 | 483 |
|
2947 | 484 |
for y:= 0 to Pred(Surf^.h) do |
485 |
begin |
|
486 |
for x:= 0 to Pred(Surf^.w) do toP4^[x]:= fromP4^[x]; |
|
487 |
for x:= Surf^.w to Pred(tw) do toP4^[x]:= 0; |
|
488 |
toP4:= @(toP4^[tw]); |
|
489 |
fromP4:= @(fromP4^[Surf^.pitch div 4]); |
|
490 |
end; |
|
1896 | 491 |
|
2947 | 492 |
for y:= Surf^.h to Pred(th) do |
493 |
begin |
|
494 |
for x:= 0 to Pred(tw) do toP4^[x]:= 0; |
|
495 |
toP4:= @(toP4^[tw]); |
|
496 |
end; |
|
771 | 497 |
|
2947 | 498 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tw, th, 0, GL_RGBA, GL_UNSIGNED_BYTE, tmpp); |
2376 | 499 |
|
2947 | 500 |
FreeMem(tmpp, tw * th * surf^.format^.BytesPerPixel) |
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
501 |
end |
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
502 |
else |
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
503 |
begin |
2947 | 504 |
Surface2Tex^.rx:= 1.0; |
505 |
Surface2Tex^.ry:= 1.0; |
|
506 |
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf^.w, surf^.h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surf^.pixels); |
|
2576
2eb7ce1c1f19
code cleanup for Surface2Tex (we don't have 3 bytes surfaces any more)
koda
parents:
2575
diff
changeset
|
507 |
end; |
753 | 508 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
509 |
ResetVertexArrays(Surface2Tex); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1911
diff
changeset
|
510 |
|
754 | 511 |
if SDL_MustLock(surf) then |
2947 | 512 |
SDL_UnlockSurface(surf); |
754 | 513 |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2428
diff
changeset
|
514 |
SetTextureParameters(enableClamp); |
753 | 515 |
end; |
516 |
||
759 | 517 |
procedure FreeTexture(tex: PTexture); |
518 |
begin |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
519 |
if tex <> nil then |
2947 | 520 |
begin |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
521 |
if tex^.NextTexture <> nil then |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
522 |
tex^.NextTexture^.PrevTexture:= tex^.PrevTexture; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
523 |
if tex^.PrevTexture <> nil then |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
524 |
tex^.PrevTexture^.NextTexture:= tex^.NextTexture |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
525 |
else |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
526 |
TextureList:= tex^.NextTexture; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
527 |
glDeleteTextures(1, @tex^.id); |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3464
diff
changeset
|
528 |
Dispose(tex); |
2947 | 529 |
end |
759 | 530 |
end; |
337 | 531 |
|
949 | 532 |
function DecodeBase64(s: shortstring): shortstring; |
533 |
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; |
|
534 |
var i, t, c: Longword; |
|
535 |
begin |
|
536 |
c:= 0; |
|
537 |
for i:= 1 to Length(s) do |
|
2947 | 538 |
begin |
539 |
t:= Pos(s[i], table); |
|
540 |
if s[i] = '=' then inc(c); |
|
541 |
if t > 0 then byte(s[i]):= t - 1 else byte(s[i]):= 0 |
|
542 |
end; |
|
949 | 543 |
|
544 |
i:= 1; |
|
545 |
t:= 1; |
|
546 |
while i <= length(s) do |
|
2947 | 547 |
begin |
548 |
DecodeBase64[t ]:= char((byte(s[i ]) shl 2) or (byte(s[i + 1]) shr 4)); |
|
549 |
DecodeBase64[t + 1]:= char((byte(s[i + 1]) shl 4) or (byte(s[i + 2]) shr 2)); |
|
550 |
DecodeBase64[t + 2]:= char((byte(s[i + 2]) shl 6) or (byte(s[i + 3]) )); |
|
551 |
inc(t, 3); |
|
552 |
inc(i, 4) |
|
553 |
end; |
|
949 | 554 |
|
555 |
if c < 3 then t:= t - c; |
|
556 |
||
557 |
byte(DecodeBase64[0]):= t - 1 |
|
558 |
end; |
|
559 |
||
2735 | 560 |
procedure MakeScreenshot(filename: shortstring); |
1080 | 561 |
var p: Pointer; |
2947 | 562 |
size: Longword; |
563 |
f: file; |
|
564 |
// Windows Bitmap Header |
|
565 |
head: array[0..53] of Byte = ( |
|
566 |
$42, $4D, // identifier ("BM") |
|
567 |
0, 0, 0, 0, // file size |
|
568 |
0, 0, 0, 0, // reserved |
|
569 |
54, 0, 0, 0, // starting offset |
|
570 |
40, 0, 0, 0, // header size |
|
571 |
0, 0, 0, 0, // width |
|
572 |
0, 0, 0, 0, // height |
|
573 |
1, 0, // color planes |
|
574 |
24, 0, // bit depth |
|
575 |
0, 0, 0, 0, // compression method (uncompressed) |
|
576 |
0, 0, 0, 0, // image size |
|
577 |
96, 0, 0, 0, // horizontal resolution |
|
578 |
96, 0, 0, 0, // vertical resolution |
|
579 |
0, 0, 0, 0, // number of colors (all) |
|
580 |
0, 0, 0, 0 // number of important colors |
|
581 |
); |
|
1080 | 582 |
begin |
2745 | 583 |
playSound(sndShutter); |
1080 | 584 |
|
3107 | 585 |
// flash |
586 |
ScreenFade:= sfFromWhite; |
|
587 |
ScreenFadeValue:= sfMax; |
|
588 |
ScreenFadeSpeed:= 5; |
|
589 |
||
1080 | 590 |
size:= cScreenWidth * cScreenHeight * 3; |
591 |
p:= GetMem(size); |
|
592 |
||
2735 | 593 |
// update header information and file name |
594 |
||
3350 | 595 |
filename:= ParamStr(1) + '/Screenshots/' + filename + '.bmp'; |
2735 | 596 |
|
597 |
head[$02]:= (size + 54) and $ff; |
|
598 |
head[$03]:= ((size + 54) shr 8) and $ff; |
|
599 |
head[$04]:= ((size + 54) shr 16) and $ff; |
|
600 |
head[$05]:= ((size + 54) shr 24) and $ff; |
|
601 |
head[$12]:= cScreenWidth and $ff; |
|
602 |
head[$13]:= (cScreenWidth shr 8) and $ff; |
|
603 |
head[$14]:= (cScreenWidth shr 16) and $ff; |
|
604 |
head[$15]:= (cScreenWidth shr 24) and $ff; |
|
605 |
head[$16]:= cScreenHeight and $ff; |
|
606 |
head[$17]:= (cScreenHeight shr 8) and $ff; |
|
607 |
head[$18]:= (cScreenHeight shr 16) and $ff; |
|
608 |
head[$19]:= (cScreenHeight shr 24) and $ff; |
|
609 |
head[$22]:= size and $ff; |
|
610 |
head[$23]:= (size shr 8) and $ff; |
|
611 |
head[$24]:= (size shr 16) and $ff; |
|
612 |
head[$25]:= (size shr 24) and $ff; |
|
2163
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2162
diff
changeset
|
613 |
|
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2162
diff
changeset
|
614 |
//remember that opengles operates on a single surface, so GL_FRONT *should* be implied |
3663
8c28abf427f5
reduce the number of keywords used and switch to BMP format for screenshots
koda
parents:
3650
diff
changeset
|
615 |
//glReadBuffer(GL_FRONT); |
1080 | 616 |
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p); |
617 |
||
618 |
{$I-} |
|
2735 | 619 |
Assign(f, filename); |
1080 | 620 |
Rewrite(f, 1); |
621 |
if IOResult = 0 then |
|
2947 | 622 |
begin |
623 |
BlockWrite(f, head, sizeof(head)); |
|
624 |
BlockWrite(f, p^, size); |
|
625 |
Close(f); |
|
626 |
end; |
|
1080 | 627 |
{$I+} |
628 |
||
629 |
FreeMem(p) |
|
630 |
end; |
|
631 |
||
949 | 632 |
{$IFDEF DEBUGFILE} |
633 |
procedure AddFileLog(s: shortstring); |
|
634 |
begin |
|
635 |
writeln(f, GameTicks: 6, ': ', s); |
|
636 |
flush(f) |
|
637 |
end; |
|
638 |
||
639 |
function RectToStr(Rect: TSDL_Rect): shortstring; |
|
640 |
begin |
|
641 |
RectToStr:= '(x: ' + inttostr(rect.x) + '; y: ' + inttostr(rect.y) + '; w: ' + inttostr(rect.w) + '; h: ' + inttostr(rect.h) + ')' |
|
642 |
end; |
|
2242 | 643 |
{$ENDIF} |
306 | 644 |
|
2619 | 645 |
function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; |
646 |
{* for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7 *} |
|
647 |
var convertedSurf: PSDL_Surface = nil; |
|
648 |
begin |
|
2947 | 649 |
if (tmpsurf^.format^.bitsperpixel = 24) or ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) then |
650 |
begin |
|
651 |
convertedSurf:= SDL_ConvertSurface(tmpsurf, @conversionFormat, SDL_SWSURFACE); |
|
652 |
SDL_FreeSurface(tmpsurf); |
|
653 |
exit(convertedSurf); |
|
654 |
end; |
|
2705
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2699
diff
changeset
|
655 |
|
2947 | 656 |
exit(tmpsurf); |
2619 | 657 |
end; |
658 |
||
2670 | 659 |
function endian(independent: LongWord): LongWord; |
660 |
begin |
|
661 |
{$IFDEF ENDIAN_LITTLE} |
|
662 |
endian:= independent; |
|
663 |
{$ELSE} |
|
664 |
endian:= (((independent and $FF000000) shr 24) or |
|
3365
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3355
diff
changeset
|
665 |
((independent and $00FF0000) shr 8) or |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3355
diff
changeset
|
666 |
((independent and $0000FF00) shl 8) or |
37ac593e9027
wow all these files only for land preview and seed generation
koda
parents:
3355
diff
changeset
|
667 |
((independent and $000000FF) shl 24)) |
2670 | 668 |
{$ENDIF} |
669 |
end; |
|
2630 | 670 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
671 |
|
3038 | 672 |
procedure initModule; |
3305 | 673 |
{$IFDEF DEBUGFILE}{$IFNDEF IPHONEOS}var i: LongInt;{$ENDIF}{$ENDIF} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
674 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
675 |
cDrownSpeed.QWordValue := 257698038; // 0.06 |
3593
ae50f63e4fa9
Remove hwFloat from VisualGears - they don't need the precision for syncing purposes, and it saves a whole lot of operations.
nemo
parents:
3537
diff
changeset
|
676 |
cDrownSpeedf := 0.06; |
3355
dc9e61e67484
cWindSpeed recalculation assumed GetRandom returns a value between 0.0-1.0 while in fact is in the 0.0-0.5 range; Halve cMaxWindSpeed to compensate.
palewolf
parents:
3350
diff
changeset
|
677 |
cMaxWindSpeed.QWordValue:= 1073742; // 0.00025 |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
678 |
cWindSpeed.QWordValue := 429496; // 0.0001 |
3593
ae50f63e4fa9
Remove hwFloat from VisualGears - they don't need the precision for syncing purposes, and it saves a whole lot of operations.
nemo
parents:
3537
diff
changeset
|
679 |
cWindSpeedf := 0.0001; |
3355
dc9e61e67484
cWindSpeed recalculation assumed GetRandom returns a value between 0.0-1.0 while in fact is in the 0.0-0.5 range; Halve cMaxWindSpeed to compensate.
palewolf
parents:
3350
diff
changeset
|
680 |
cGravity := cMaxWindSpeed * 2; |
3593
ae50f63e4fa9
Remove hwFloat from VisualGears - they don't need the precision for syncing purposes, and it saves a whole lot of operations.
nemo
parents:
3537
diff
changeset
|
681 |
cGravityf := 0.00025 * 2; |
2947 | 682 |
cDamageModifier := _1; |
683 |
TargetPoint := cTargetPointRef; |
|
684 |
TextureList := nil; |
|
685 |
||
686 |
// int, longint longword and byte |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
687 |
CursorMovementX := 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
688 |
CursorMovementY := 0; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
689 |
GameTicks := 0; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
690 |
TrainingTimeInc := 10000; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
691 |
TrainingTimeInD := 500; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
692 |
TrainingTimeInM := 5000; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
693 |
TrainingTimeMax := 60000; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
694 |
TimeTrialStartTime := 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
695 |
TimeTrialStopTime := 0; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
696 |
cWaterLine := LAND_HEIGHT; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
697 |
cGearScrEdgesDist := 240; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
698 |
cHealthDecrease := 0; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
699 |
|
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
700 |
GameFlags := 0; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
701 |
TrainingFlags := 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
702 |
TurnTimeLeft := 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
703 |
cSuddenDTurns := 15; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
704 |
cDamagePercent := 100; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
705 |
cMineDudPercent := 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
706 |
cTemplateFilter := 0; |
3133 | 707 |
cMapGen := 0;//MAPGEN_REGULAR |
708 |
cMazeSize := 0; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
709 |
cHedgehogTurnTime := 45000; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
710 |
cMinesTime := 3000; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
711 |
cMaxAIThinkTime := 9000; |
3611 | 712 |
cCloudsNumber := 9; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
713 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
714 |
cTagsMask := 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
715 |
KBnum := 0; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
716 |
InitStepsFlags := 0; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
717 |
RealTicks := 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
718 |
AttackBar := 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP |
3611 | 719 |
cCaseFactor := 5; {0..9} |
720 |
cLandAdditions := 4; |
|
721 |
cExplosives := 2; |
|
722 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
723 |
GameState := Low(TGameState); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
724 |
GameType := gmtLocal; |
3650 | 725 |
zoom := cDefaultZoomLevel; |
726 |
ZoomValue := cDefaultZoomLevel; |
|
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
727 |
WeaponTooltipTex:= nil; |
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
728 |
cLaserSighting := false; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
729 |
cVampiric := false; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
730 |
cArtillery := false; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
731 |
flagMakeCapture := false; |
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
732 |
bBetweenTurns := false; |
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
733 |
bWaterRising := false; |
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
734 |
isCursorVisible := false; |
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
735 |
isTerminated := false; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
736 |
isInLag := false; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
737 |
isPaused := false; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
738 |
isInMultiShoot := false; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
739 |
isSpeed := false; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
740 |
fastUntilLag := false; |
3107 | 741 |
isFirstFrame := true; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
742 |
isSEBackup := true; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
743 |
cSeed := ''; |
3066
5c0efa437728
Enable birdy. Has egg bombing. Eggs should possibly have a dX component. No poison yet, no egg sprite.
nemo
parents:
3038
diff
changeset
|
744 |
cVolumeDelta := 0; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
745 |
cHasFocus := true; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
746 |
cInactDelay := 1250; |
3107 | 747 |
|
748 |
ScreenFade := sfNone; |
|
3598 | 749 |
|
750 |
{$IFDEF SDL13} |
|
751 |
SDLwindow := nil; |
|
752 |
{$ENDIF} |
|
488 | 753 |
{$IFDEF DEBUGFILE} |
337 | 754 |
{$I-} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
755 |
{$IFDEF IPHONEOS} |
3377 | 756 |
Assign(f,'../Documents/debug.txt'); |
757 |
Rewrite(f); |
|
2630 | 758 |
{$ELSE} |
3533
03892fb97ab3
fix build and permissions problems when launching hwengine from command line
koda
parents:
3513
diff
changeset
|
759 |
if (ParamStr(1) <> '') and (ParamStr(2) <> '') then |
3534 | 760 |
if (ParamCount <> 3) and (ParamCount <> 18) then |
2947 | 761 |
begin |
3534 | 762 |
for i:= 0 to 7 do |
763 |
begin |
|
764 |
assign(f, ExtractFileDir(ParamStr(2)) + '/debug' + inttostr(i) + '.txt'); |
|
765 |
rewrite(f); |
|
766 |
if IOResult = 0 then break; |
|
767 |
end; |
|
768 |
if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr |
|
769 |
end |
|
770 |
else |
|
771 |
begin |
|
772 |
for i:= 0 to 7 do |
|
773 |
begin |
|
774 |
assign(f, ParamStr(1) + '/debug' + inttostr(i) + '.txt'); |
|
775 |
rewrite(f); |
|
776 |
if IOResult = 0 then break; |
|
777 |
end; |
|
778 |
if IOResult <> 0 then f:= stderr; // if everything fails, write to stderr |
|
2947 | 779 |
end |
780 |
else |
|
781 |
f:= stderr; |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
782 |
{$ENDIF} |
337 | 783 |
{$I+} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
784 |
{$ENDIF} |
17 | 785 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
786 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
787 |
|
3038 | 788 |
procedure freeModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
789 |
begin |
3626 | 790 |
recordFileName:= ''; |
2947 | 791 |
while TextureList <> nil do FreeTexture(TextureList); |
2154
3d2917be12c3
Change default output to stderr since /tmp doesn't exist under windows and is useless under iphoneos, add a couple of extra parameters
nemo
parents:
2152
diff
changeset
|
792 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
793 |
{$IFDEF DEBUGFILE} |
2947 | 794 |
writeln(f, 'halt at ', GameTicks, ' ticks. TurnTimeLeft = ', TurnTimeLeft); |
795 |
flush(f); |
|
796 |
close(f); |
|
4 | 797 |
{$ENDIF} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
798 |
end; |
4 | 799 |
|
800 |
end. |