author | unC0Rr |
Thu, 18 Nov 2010 11:45:31 +0300 | |
changeset 4375 | ae5507ddb989 |
parent 4374 | bcefeeabaa33 |
child 4376 | 9654205a9424 |
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 |
|
4374 | 24 |
uses SDLh, uConsts, GLunit, uTypes; |
2697 | 25 |
|
3611 | 26 |
|
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
|
27 |
procedure movecursor(dx, dy: LongInt); |
3929
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
28 |
(* |
4 | 29 |
procedure AdjustColor(var Color: Longword); |
208 | 30 |
procedure SetKB(n: Longword); |
3929
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
31 |
*) |
208 | 32 |
procedure SendKB; |
306 | 33 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
2670 | 34 |
function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; |
4374 | 35 |
procedure OutError(Msg: shortstring; isFatalError: boolean); |
36 |
procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); inline; |
|
37 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
2735 | 38 |
procedure MakeScreenshot(filename: shortstring); |
4 | 39 |
|
4359 | 40 |
procedure initModule; |
41 |
procedure freeModule; |
|
42 |
||
4 | 43 |
implementation |
4374 | 44 |
uses uConsole, uIO, typinfo, sysutils, uVariables, uUtils; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
45 |
|
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
46 |
var KBnum: Longword; |
4 | 47 |
|
3756 | 48 |
|
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
|
49 |
procedure movecursor(dx, dy: LongInt); |
2428 | 50 |
var x, y: LongInt; |
51 |
begin |
|
52 |
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
|
53 |
|
2428 | 54 |
SDL_GetMouseState(@x, @y); |
55 |
Inc(x, dx); |
|
56 |
Inc(y, dy); |
|
57 |
SDL_WarpMouse(x, y); |
|
58 |
end; |
|
59 |
||
4 | 60 |
|
2905 | 61 |
procedure OutError(Msg: shortstring; isFatalError: boolean); |
4 | 62 |
begin |
3407 | 63 |
// obsolete? written in WriteLnToConsole() anyway |
64 |
// {$IFDEF DEBUGFILE}AddFileLog(Msg);{$ENDIF} |
|
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
65 |
WriteLnToConsole(Msg); |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
66 |
if isFatalError then |
3407 | 67 |
begin |
4046
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
68 |
SendIPC('E' + GetLastConsoleLine); |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
69 |
SDL_Quit; |
cfdbddc4b385
making indentation consistent (noticed while debugging)
nemo
parents:
4003
diff
changeset
|
70 |
halt(1) |
3407 | 71 |
end |
4 | 72 |
end; |
73 |
||
2905 | 74 |
procedure TryDo(Assert: boolean; Msg: shortstring; isFatal: boolean); |
4 | 75 |
begin |
70 | 76 |
if not Assert then OutError(Msg, isFatal) |
4 | 77 |
end; |
78 |
||
79 |
procedure SDLTry(Assert: boolean; isFatal: boolean); |
|
80 |
begin |
|
81 |
if not Assert then OutError(SDL_GetError, isFatal) |
|
82 |
end; |
|
83 |
||
3929
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
84 |
(* |
188 | 85 |
procedure AdjustColor(var Color: Longword); |
4 | 86 |
begin |
87 |
Color:= SDL_MapRGB(PixelFormat, (Color shr 16) and $FF, (Color shr 8) and $FF, Color and $FF) |
|
88 |
end; |
|
89 |
||
3929
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
90 |
procedure SetKB(n: Longword); |
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
91 |
begin |
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
92 |
KBnum:= n |
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
93 |
end; |
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
94 |
*) |
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
95 |
|
9a4bbc1f67a2
Inline most of uFloat (saves ~7.5% opcount on a test game), inline a few very short candidates in uMisc, comment out some unused functions in uMisc
nemo
parents:
3914
diff
changeset
|
96 |
|
208 | 97 |
procedure SendKB; |
98 |
var s: shortstring; |
|
99 |
begin |
|
100 |
if KBnum <> 0 then |
|
2947 | 101 |
begin |
102 |
s:= 'K' + inttostr(KBnum); |
|
103 |
SendIPCRaw(@s, Length(s) + 1) |
|
104 |
end |
|
208 | 105 |
end; |
106 |
||
337 | 107 |
procedure SendStat(sit: TStatInfoType; s: shortstring); |
3784
75aa91bea32b
Extend statistics collection (TeamKills, TurnSkips, TeamDamage)
burp
parents:
3779
diff
changeset
|
108 |
const stc: array [TStatInfoType] of char = 'rDkKHTPsSB'; |
2382 | 109 |
var buf: shortstring; |
337 | 110 |
begin |
2382 | 111 |
buf:= 'i' + stc[sit] + s; |
112 |
SendIPCRaw(@buf[0], length(buf) + 1) |
|
337 | 113 |
end; |
114 |
||
771 | 115 |
|
2735 | 116 |
procedure MakeScreenshot(filename: shortstring); |
1080 | 117 |
var p: Pointer; |
2947 | 118 |
size: Longword; |
119 |
f: file; |
|
120 |
// Windows Bitmap Header |
|
121 |
head: array[0..53] of Byte = ( |
|
122 |
$42, $4D, // identifier ("BM") |
|
123 |
0, 0, 0, 0, // file size |
|
124 |
0, 0, 0, 0, // reserved |
|
125 |
54, 0, 0, 0, // starting offset |
|
126 |
40, 0, 0, 0, // header size |
|
127 |
0, 0, 0, 0, // width |
|
128 |
0, 0, 0, 0, // height |
|
129 |
1, 0, // color planes |
|
130 |
24, 0, // bit depth |
|
131 |
0, 0, 0, 0, // compression method (uncompressed) |
|
132 |
0, 0, 0, 0, // image size |
|
133 |
96, 0, 0, 0, // horizontal resolution |
|
134 |
96, 0, 0, 0, // vertical resolution |
|
135 |
0, 0, 0, 0, // number of colors (all) |
|
136 |
0, 0, 0, 0 // number of important colors |
|
137 |
); |
|
1080 | 138 |
begin |
3107 | 139 |
// flash |
140 |
ScreenFade:= sfFromWhite; |
|
141 |
ScreenFadeValue:= sfMax; |
|
142 |
ScreenFadeSpeed:= 5; |
|
143 |
||
1080 | 144 |
size:= cScreenWidth * cScreenHeight * 3; |
145 |
p:= GetMem(size); |
|
146 |
||
2735 | 147 |
// update header information and file name |
148 |
||
3350 | 149 |
filename:= ParamStr(1) + '/Screenshots/' + filename + '.bmp'; |
2735 | 150 |
|
151 |
head[$02]:= (size + 54) and $ff; |
|
152 |
head[$03]:= ((size + 54) shr 8) and $ff; |
|
153 |
head[$04]:= ((size + 54) shr 16) and $ff; |
|
154 |
head[$05]:= ((size + 54) shr 24) and $ff; |
|
155 |
head[$12]:= cScreenWidth and $ff; |
|
156 |
head[$13]:= (cScreenWidth shr 8) and $ff; |
|
157 |
head[$14]:= (cScreenWidth shr 16) and $ff; |
|
158 |
head[$15]:= (cScreenWidth shr 24) and $ff; |
|
159 |
head[$16]:= cScreenHeight and $ff; |
|
160 |
head[$17]:= (cScreenHeight shr 8) and $ff; |
|
161 |
head[$18]:= (cScreenHeight shr 16) and $ff; |
|
162 |
head[$19]:= (cScreenHeight shr 24) and $ff; |
|
163 |
head[$22]:= size and $ff; |
|
164 |
head[$23]:= (size shr 8) and $ff; |
|
165 |
head[$24]:= (size shr 16) and $ff; |
|
166 |
head[$25]:= (size shr 24) and $ff; |
|
2163
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2162
diff
changeset
|
167 |
|
12730f5e79b9
koda's patch fixing some iphone port troubles (color, mouse)
unc0rr
parents:
2162
diff
changeset
|
168 |
//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
|
169 |
//glReadBuffer(GL_FRONT); |
1080 | 170 |
glReadPixels(0, 0, cScreenWidth, cScreenHeight, GL_BGR, GL_UNSIGNED_BYTE, p); |
171 |
||
172 |
{$I-} |
|
2735 | 173 |
Assign(f, filename); |
1080 | 174 |
Rewrite(f, 1); |
175 |
if IOResult = 0 then |
|
2947 | 176 |
begin |
177 |
BlockWrite(f, head, sizeof(head)); |
|
178 |
BlockWrite(f, p^, size); |
|
179 |
Close(f); |
|
180 |
end; |
|
1080 | 181 |
{$I+} |
182 |
||
183 |
FreeMem(p) |
|
184 |
end; |
|
185 |
||
2619 | 186 |
function doSurfaceConversion(tmpsurf: PSDL_Surface): PSDL_Surface; |
187 |
{* for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7 *} |
|
188 |
var convertedSurf: PSDL_Surface = nil; |
|
189 |
begin |
|
2947 | 190 |
if (tmpsurf^.format^.bitsperpixel = 24) or ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) then |
191 |
begin |
|
192 |
convertedSurf:= SDL_ConvertSurface(tmpsurf, @conversionFormat, SDL_SWSURFACE); |
|
193 |
SDL_FreeSurface(tmpsurf); |
|
194 |
exit(convertedSurf); |
|
195 |
end; |
|
2705
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2699
diff
changeset
|
196 |
|
2947 | 197 |
exit(tmpsurf); |
2619 | 198 |
end; |
199 |
||
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
200 |
|
3038 | 201 |
procedure initModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
202 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2947
diff
changeset
|
203 |
KBnum := 0; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
204 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
205 |
|
3038 | 206 |
procedure freeModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
207 |
begin |
3626 | 208 |
recordFileName:= ''; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
209 |
end; |
4 | 210 |
|
211 |
end. |