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