author | smxx |
Fri, 19 Feb 2010 00:53:22 +0000 | |
changeset 2828 | e45410eae9ea |
parent 2811 | 4cad87e11bf6 |
child 2841 | 2c9013664ea3 |
permissions | -rw-r--r-- |
4 | 1 |
(* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
883 | 3 |
* Copyright (c) 2004-2008 Andrey Korotaev <unC0Rr@gmail.com> |
4 | 4 |
* |
183 | 5 |
* This program is free software; you can redistribute it and/or modify |
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
4 | 8 |
* |
183 | 9 |
* This program is distributed in the hope that it will be useful, |
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
4 | 13 |
* |
183 | 14 |
* You should have received a copy of the GNU General Public License |
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
4 | 17 |
*) |
18 |
||
2623 | 19 |
{$INCLUDE "options.inc"} |
20 |
||
4 | 21 |
unit uStore; |
22 |
interface |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
23 |
uses sysutils, uConsts, uTeams, SDLh, uFloat, |
2152 | 24 |
{$IFDEF GLES11} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
25 |
gles11; |
1906 | 26 |
{$ELSE} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
27 |
GL, GLext; |
1906 | 28 |
{$ENDIF} |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
29 |
|
4 | 30 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
31 |
var PixelFormat: PSDL_PixelFormat; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
32 |
SDLPrimSurface: PSDL_Surface; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
33 |
PauseTexture, |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
34 |
SyncTexture, |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
35 |
ConfirmTexture: PTexture; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
36 |
cScaleFactor: GLfloat; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
37 |
SupportNPOTT: Boolean; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
38 |
Step: LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
39 |
squaresize : LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
40 |
numsquares : LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
41 |
ProgrTex: PTexture; |
2801 | 42 |
MissionIcons: PSDL_Surface; |
2811 | 43 |
ropeIconTex: PTexture; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
44 |
|
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
45 |
procedure init_uStore; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
46 |
procedure free_uStore; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
47 |
|
4 | 48 |
procedure StoreLoad; |
49 |
procedure StoreRelease; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
50 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
51 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
52 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
1939 | 53 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
54 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture); |
762 | 55 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
2811 | 56 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); |
57 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
|
822 | 58 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
853 | 59 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
822 | 60 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
762 | 61 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
62 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
diff
changeset
|
63 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1431 | 64 |
procedure DrawFillRect(r: TSDL_Rect); |
2801 | 65 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
66 |
function CheckCJKFont(s: string; font: THWFont): THWFont; |
762 | 67 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
2017 | 68 |
function RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture; |
69 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
|
70 |
//procedure rotateSurface(Surface: PSDL_Surface); |
|
71 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL |
|
72 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer); |
|
4 | 73 |
procedure RenderHealth(var Hedgehog: THedgehog); |
74 |
procedure AddProgress; |
|
510 | 75 |
procedure FinishProgress; |
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
|
76 |
function LoadImage(const filename: string; imageFlags: LongInt): PSDL_Surface; |
753 | 77 |
procedure SetupOpenGL; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
78 |
procedure SetScale(f: GLfloat); |
2786 | 79 |
function RenderHelpWindow(caption, subcaption, description, extra: shortstring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture; |
2747 | 80 |
procedure RenderWeaponTooltip(atype: TAmmoType); |
81 |
procedure ShowWeaponTooltip(x, y: LongInt); |
|
82 |
procedure FreeWeaponTooltip; |
|
4 | 83 |
|
84 |
implementation |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
85 |
uses uMisc, uConsole, uLand, uLocale, uWorld{$IFDEF IPHONEOS}, PascalExports{$ENDIF}; |
4 | 86 |
|
2735 | 87 |
type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple); |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
88 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
89 |
var HHTexture: PTexture; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
90 |
MaxTextureSize: Integer; |
2735 | 91 |
cGPUVendor: TGPUVendor; |
4 | 92 |
|
351 | 93 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
47 | 94 |
var r: TSDL_Rect; |
95 |
begin |
|
96 |
r:= rect^; |
|
83 | 97 |
if Clear then SDL_FillRect(Surface, @r, 0); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
98 |
|
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
99 |
BorderColor:= SDL_MapRGB(Surface^.format, BorderColor shr 16, BorderColor shr 8, BorderColor and $FF); |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
100 |
FillColor:= SDL_MapRGB(Surface^.format, FillColor shr 16, FillColor shr 8, FillColor and $FF); |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
101 |
|
351 | 102 |
r.y:= rect^.y + 1; |
103 |
r.h:= rect^.h - 2; |
|
47 | 104 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 105 |
r.x:= rect^.x + 1; |
106 |
r.w:= rect^.w - 2; |
|
107 |
r.y:= rect^.y; |
|
108 |
r.h:= rect^.h; |
|
47 | 109 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 110 |
r.x:= rect^.x + 2; |
111 |
r.y:= rect^.y + 1; |
|
112 |
r.w:= rect^.w - 4; |
|
113 |
r.h:= rect^.h - 2; |
|
47 | 114 |
SDL_FillRect(Surface, @r, FillColor); |
351 | 115 |
r.x:= rect^.x + 1; |
116 |
r.y:= rect^.y + 2; |
|
117 |
r.w:= rect^.w - 2; |
|
118 |
r.h:= rect^.h - 4; |
|
47 | 119 |
SDL_FillRect(Surface, @r, FillColor) |
120 |
end; |
|
121 |
||
371 | 122 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
351 | 123 |
var w, h: LongInt; |
4 | 124 |
tmpsurf: PSDL_Surface; |
125 |
clr: TSDL_Color; |
|
2695 | 126 |
finalRect: TSDL_Rect; |
4 | 127 |
begin |
2620
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
128 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
2695 | 129 |
finalRect.x:= X; |
130 |
finalRect.y:= Y; |
|
131 |
finalRect.w:= w + FontBorder * 2 + 4; |
|
132 |
finalRect.h:= h + FontBorder * 2; |
|
133 |
DrawRoundRect(@finalRect, cWhiteColor, endian(cNearBlackColorChannels.value), Surface, true); |
|
2670 | 134 |
clr.r:= (Color shr 16) and $FF; |
2620
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
135 |
clr.g:= (Color shr 8) and $FF; |
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
136 |
clr.b:= Color and $FF; |
2665
50b4e544c163
complete transition of longword->sdl_color for TTF bindings
koda
parents:
2663
diff
changeset
|
137 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr); |
2695 | 138 |
finalRect.x:= X + FontBorder + 2; |
139 |
finalRect.y:= Y + FontBorder; |
|
2620
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
140 |
SDLTry(tmpsurf <> nil, true); |
2695 | 141 |
SDL_UpperBlit(tmpsurf, nil, Surface, @finalRect); |
2620
796269129c47
koda, can we try to keep unC0Rr's code formatting, and not just change it when we feel like it?
nemo
parents:
2619
diff
changeset
|
142 |
SDL_FreeSurface(tmpsurf); |
2695 | 143 |
finalRect.x:= X; |
144 |
finalRect.y:= Y; |
|
145 |
finalRect.w:= w + FontBorder * 2 + 4; |
|
146 |
finalRect.h:= h + FontBorder * 2; |
|
147 |
WriteInRoundRect:= finalRect; |
|
4 | 148 |
end; |
149 |
||
2747 | 150 |
function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: string): TSDL_Rect; |
151 |
var w, h: LongInt; |
|
152 |
tmpsurf: PSDL_Surface; |
|
153 |
clr: TSDL_Color; |
|
154 |
finalRect: TSDL_Rect; |
|
155 |
begin |
|
156 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
|
157 |
finalRect.x:= X + FontBorder + 2; |
|
158 |
finalRect.y:= Y + FontBorder; |
|
159 |
finalRect.w:= w + FontBorder * 2 + 4; |
|
160 |
finalRect.h:= h + FontBorder * 2; |
|
161 |
clr.r:= Color shr 16; |
|
162 |
clr.g:= (Color shr 8) and $FF; |
|
163 |
clr.b:= Color and $FF; |
|
164 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr); |
|
165 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
|
166 |
SDLTry(tmpsurf <> nil, true); |
|
167 |
SDL_UpperBlit(tmpsurf, nil, Surface, @finalRect); |
|
168 |
SDL_FreeSurface(tmpsurf); |
|
169 |
finalRect.x:= X; |
|
170 |
finalRect.y:= Y; |
|
171 |
finalRect.w:= w + FontBorder * 2 + 4; |
|
172 |
finalRect.h:= h + FontBorder * 2; |
|
173 |
WriteInRect:= finalRect |
|
174 |
end; |
|
175 |
||
4 | 176 |
procedure StoreLoad; |
844 | 177 |
var s: string; |
4 | 178 |
|
1185 | 179 |
procedure WriteNames(Font: THWFont); |
180 |
var t: LongInt; |
|
181 |
i: LongInt; |
|
182 |
r, rr: TSDL_Rect; |
|
183 |
drY: LongInt; |
|
2811 | 184 |
texsurf, flagsurf, iconsurf: PSDL_Surface; |
1185 | 185 |
begin |
186 |
r.x:= 0; |
|
187 |
r.y:= 0; |
|
188 |
drY:= - 4; |
|
189 |
for t:= 0 to Pred(TeamsCount) do |
|
190 |
with TeamsArray[t]^ do |
|
191 |
begin |
|
192 |
NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font); |
|
690 | 193 |
|
1185 | 194 |
r.w:= cTeamHealthWidth + 5; |
195 |
r.h:= NameTagTex^.h; |
|
690 | 196 |
|
1185 | 197 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
198 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
199 |
TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
690 | 200 |
|
2666 | 201 |
DrawRoundRect(@r, cWhiteColor, cNearBlackColorChannels.value, texsurf, true); |
1185 | 202 |
rr:= r; |
203 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
|
204 |
DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false); |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
205 |
HealthTex:= Surface2Tex(texsurf, false); |
1185 | 206 |
SDL_FreeSurface(texsurf); |
690 | 207 |
|
2747 | 208 |
r.x:= 0; |
209 |
r.y:= 0; |
|
210 |
r.w:= 32; |
|
211 |
r.h:= 32; |
|
212 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
|
213 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
214 |
TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
215 |
||
216 |
r.w:= 26; |
|
217 |
r.h:= 19; |
|
218 |
||
219 |
DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true); |
|
220 |
||
2751 | 221 |
// overwrite flag for cpu teams and keep players from using it |
222 |
if (Hedgehogs[0].Gear <> nil) and (Hedgehogs[0].BotLevel > 0) then |
|
223 |
Flag:= 'cpu' |
|
224 |
else if Flag = 'cpu' then |
|
225 |
Flag:= 'hedgewars'; |
|
226 |
||
2747 | 227 |
flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone); |
228 |
if flagsurf = nil then |
|
229 |
flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone); |
|
230 |
TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true); |
|
231 |
copyToXY(flagsurf, texsurf, 2, 2); |
|
232 |
SDL_FreeSurface(flagsurf); |
|
233 |
||
234 |
// restore black border pixels inside the flag |
|
235 |
PLongwordArray(texsurf^.pixels)^[32 * 2 + 2]:= cNearBlackColor; |
|
236 |
PLongwordArray(texsurf^.pixels)^[32 * 2 + 23]:= cNearBlackColor; |
|
237 |
PLongwordArray(texsurf^.pixels)^[32 * 16 + 2]:= cNearBlackColor; |
|
238 |
PLongwordArray(texsurf^.pixels)^[32 * 16 + 23]:= cNearBlackColor; |
|
239 |
||
240 |
FlagTex:= Surface2Tex(texsurf, false); |
|
241 |
||
1185 | 242 |
dec(drY, r.h + 2); |
243 |
DrawHealthY:= drY; |
|
244 |
for i:= 0 to 7 do |
|
245 |
with Hedgehogs[i] do |
|
246 |
if Gear <> nil then |
|
1242 | 247 |
begin |
1185 | 248 |
NameTagTex:= RenderStringTex(Name, Clan^.Color, fnt16); |
1294
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
249 |
if Hat <> 'NoHat' then |
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
250 |
begin |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
251 |
texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, ifNone); |
1698 | 252 |
if texsurf <> nil then |
253 |
begin |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
254 |
HatTex:= Surface2Tex(texsurf, true); |
1698 | 255 |
SDL_FreeSurface(texsurf) |
256 |
end |
|
1294
50198e5c7f02
- Hedgehog doesn't take off hat when shooting from shotgun
unc0rr
parents:
1251
diff
changeset
|
257 |
end |
1242 | 258 |
end; |
1185 | 259 |
end; |
2811 | 260 |
MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical); |
261 |
iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask); |
|
262 |
if iconsurf <> nil then |
|
263 |
begin |
|
264 |
r.x:= 0; |
|
265 |
r.y:= 0; |
|
266 |
r.w:= 28; |
|
267 |
r.h:= 28; |
|
268 |
DrawRoundRect(@r, cWhiteColor, cNearBlackColor, iconsurf, true); |
|
269 |
ropeIconTex:= Surface2Tex(iconsurf, false); |
|
270 |
SDL_FreeSurface(iconsurf) |
|
271 |
end; |
|
1185 | 272 |
end; |
4 | 273 |
|
1185 | 274 |
procedure MakeCrossHairs; |
275 |
var t: LongInt; |
|
276 |
tmpsurf, texsurf: PSDL_Surface; |
|
277 |
Color, i: Longword; |
|
278 |
begin |
|
279 |
s:= Pathz[ptGraphics] + '/' + cCHFileName; |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
280 |
tmpsurf:= LoadImage(s, ifAlpha or ifCritical); |
4 | 281 |
|
1185 | 282 |
for t:= 0 to Pred(TeamsCount) do |
283 |
with TeamsArray[t]^ do |
|
284 |
begin |
|
285 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask); |
|
286 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
287 |
|
1185 | 288 |
Color:= Clan^.Color; |
289 |
Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF); |
|
290 |
SDL_FillRect(texsurf, nil, Color); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
291 |
|
1185 | 292 |
SDL_UpperBlit(tmpsurf, nil, texsurf, nil); |
777 | 293 |
|
1185 | 294 |
TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true); |
777 | 295 |
|
1185 | 296 |
if SDL_MustLock(texsurf) then |
297 |
SDLTry(SDL_LockSurface(texsurf) >= 0, true); |
|
777 | 298 |
|
1185 | 299 |
// make black pixel be alpha-transparent |
300 |
for i:= 0 to texsurf^.w * texsurf^.h - 1 do |
|
2592 | 301 |
if PLongwordArray(texsurf^.pixels)^[i] = AMask then PLongwordArray(texsurf^.pixels)^[i]:= 0; |
777 | 302 |
|
1185 | 303 |
if SDL_MustLock(texsurf) then |
304 |
SDL_UnlockSurface(texsurf); |
|
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
305 |
|
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
306 |
CrosshairTex:= Surface2Tex(texsurf, false); |
1185 | 307 |
SDL_FreeSurface(texsurf) |
308 |
end; |
|
351 | 309 |
|
1185 | 310 |
SDL_FreeSurface(tmpsurf) |
311 |
end; |
|
4 | 312 |
|
1185 | 313 |
procedure InitHealth; |
314 |
var i, t: LongInt; |
|
315 |
begin |
|
316 |
for t:= 0 to Pred(TeamsCount) do |
|
317 |
if TeamsArray[t] <> nil then |
|
318 |
with TeamsArray[t]^ do |
|
319 |
begin |
|
320 |
for i:= 0 to cMaxHHIndex do |
|
321 |
if Hedgehogs[i].Gear <> nil then |
|
322 |
RenderHealth(Hedgehogs[i]); |
|
323 |
end |
|
324 |
end; |
|
4 | 325 |
|
1185 | 326 |
procedure LoadGraves; |
327 |
var t: LongInt; |
|
328 |
texsurf: PSDL_Surface; |
|
329 |
begin |
|
330 |
for t:= 0 to Pred(TeamsCount) do |
|
331 |
if TeamsArray[t] <> nil then |
|
332 |
with TeamsArray[t]^ do |
|
333 |
begin |
|
334 |
if GraveName = '' then GraveName:= 'Simple'; |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
335 |
texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifCritical or ifTransparent); |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
336 |
GraveTex:= Surface2Tex(texsurf, false); |
1185 | 337 |
SDL_FreeSurface(texsurf) |
338 |
end |
|
339 |
end; |
|
4 | 340 |
|
844 | 341 |
var ii: TSprite; |
342 |
fi: THWFont; |
|
343 |
ai: TAmmoType; |
|
344 |
tmpsurf: PSDL_Surface; |
|
345 |
i: LongInt; |
|
4 | 346 |
begin |
2222 | 347 |
|
4 | 348 |
for fi:= Low(THWFont) to High(THWFont) do |
1185 | 349 |
with Fontz[fi] do |
350 |
begin |
|
351 |
s:= Pathz[ptFonts] + '/' + Name; |
|
352 |
WriteToConsole(msgLoading + s + '... '); |
|
353 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
|
354 |
SDLTry(Handle <> nil, true); |
|
355 |
TTF_SetFontStyle(Handle, style); |
|
356 |
WriteLnToConsole(msgOK) |
|
357 |
end; |
|
53 | 358 |
|
4 | 359 |
WriteNames(fnt16); |
70 | 360 |
MakeCrossHairs; |
4 | 361 |
LoadGraves; |
362 |
||
363 |
AddProgress; |
|
364 |
for ii:= Low(TSprite) to High(TSprite) do |
|
1185 | 365 |
with SpritesData[ii] do |
2145 | 366 |
// FIXME - add a sprite attribute |
2426 | 367 |
if (not cReducedQuality) or (not (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR, sprFlake])) then // FIXME: hack |
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
368 |
begin |
1185 | 369 |
if AltPath = ptNone then |
2426 | 370 |
if ii in [sprHorizontL, sprHorizontR, sprSkyL, sprSkyR] then // FIXME: hack |
371 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifLowRes) |
|
372 |
else |
|
373 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical or ifLowRes) |
|
1185 | 374 |
else begin |
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
375 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
1185 | 376 |
if tmpsurf = nil then |
2610 | 377 |
tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent); |
1185 | 378 |
end; |
2426 | 379 |
|
380 |
if tmpsurf <> nil then |
|
2630 | 381 |
begin |
2610 | 382 |
if imageWidth = 0 then imageWidth:= tmpsurf^.w; |
383 |
if imageHeight = 0 then imageHeight:= tmpsurf^.h; |
|
2426 | 384 |
if Width = 0 then Width:= tmpsurf^.w; |
385 |
if Height = 0 then Height:= tmpsurf^.h; |
|
2452 | 386 |
if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then |
2426 | 387 |
Texture:= Surface2Tex(tmpsurf, true) |
388 |
else |
|
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
389 |
begin |
2426 | 390 |
Texture:= Surface2Tex(tmpsurf, false); |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
391 |
if (ii = sprWater) and not cReducedQuality then // HACK: We should include some sprite attribute to define the texture wrap directions |
2630 | 392 |
begin |
2447
08d623a494e6
Smaxx's updated german translation + texture gap fixes + updated room list
koda
parents:
2438
diff
changeset
|
393 |
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:
2438
diff
changeset
|
394 |
end; |
2630 | 395 |
end; |
2426 | 396 |
if saveSurf then Surface:= tmpsurf else SDL_FreeSurface(tmpsurf) |
397 |
end |
|
398 |
else |
|
399 |
Surface:= nil |
|
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
400 |
end; |
80 | 401 |
|
4 | 402 |
AddProgress; |
567 | 403 |
|
2171
8208946331ba
Smaxx refactor of LoadImage to use flags, iphone changes by koda (mostly use of rgba instead of rgb)
nemo
parents:
2161
diff
changeset
|
404 |
tmpsurf:= LoadImage(Pathz[ptGraphics] + '/' + cHHFileName, ifAlpha or ifCritical or ifTransparent); |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
405 |
HHTexture:= Surface2Tex(tmpsurf, false); |
761 | 406 |
SDL_FreeSurface(tmpsurf); |
4 | 407 |
|
408 |
InitHealth; |
|
409 |
||
2623 | 410 |
PauseTexture:= RenderStringTex(trmsg[sidPaused], cYellowColor, fntBig); |
411 |
ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], cYellowColor, fntBig); |
|
412 |
SyncTexture:= RenderStringTex(trmsg[sidSync], cYellowColor, fntBig); |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
413 |
|
2601 | 414 |
AddProgress; |
415 |
||
2670 | 416 |
// name of weapons in ammo menu |
843 | 417 |
for ai:= Low(TAmmoType) to High(TAmmoType) do |
418 |
with Ammoz[ai] do |
|
419 |
begin |
|
2665
50b4e544c163
complete transition of longword->sdl_color for TTF bindings
koda
parents:
2663
diff
changeset
|
420 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(trAmmo[NameId]), cWhiteColorChannels); |
2670 | 421 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
422 |
NameTex:= Surface2Tex(tmpsurf, false); |
843 | 423 |
SDL_FreeSurface(tmpsurf) |
424 |
end; |
|
2376 | 425 |
|
2670 | 426 |
// number of weapons in ammo menu |
844 | 427 |
for i:= Low(CountTexz) to High(CountTexz) do |
428 |
begin |
|
2665
50b4e544c163
complete transition of longword->sdl_color for TTF bindings
koda
parents:
2663
diff
changeset
|
429 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels); |
2670 | 430 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
2290
bf87ca44782e
Selectively enable clamping - seeing if this helps avoid weird flake problems while still fixing vertical lines in waves and sky
nemo
parents:
2285
diff
changeset
|
431 |
CountTexz[i]:= Surface2Tex(tmpsurf, false); |
844 | 432 |
SDL_FreeSurface(tmpsurf) |
433 |
end; |
|
434 |
||
4 | 435 |
{$IFDEF DUMP} |
2601 | 436 |
//not working anymore, where are LandSurface and StoreSurface defined? |
437 |
//SDL_SaveBMP_RW(LandSurface, SDL_RWFromFile('LandSurface.bmp', 'wb'), 1); |
|
438 |
//SDL_SaveBMP_RW(StoreSurface, SDL_RWFromFile('StoreSurface.bmp', 'wb'), 1); |
|
4 | 439 |
{$ENDIF} |
2222 | 440 |
AddProgress; |
2669 | 441 |
|
2672 | 442 |
{$IFDEF SDL_IMAGE_NEWER} |
2669 | 443 |
IMG_Quit(); |
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
|
444 |
{$ENDIF} |
4 | 445 |
end; |
446 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
447 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
4 | 448 |
var rr: TSDL_Rect; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
449 |
_l, _r, _t, _b: real; |
1916 | 450 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
4 | 451 |
begin |
2428 | 452 |
if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit; |
4 | 453 |
rr.x:= X; |
454 |
rr.y:= Y; |
|
351 | 455 |
rr.w:= r^.w; |
456 |
rr.h:= r^.h; |
|
755 | 457 |
|
1896 | 458 |
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx; |
459 |
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx; |
|
460 |
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
|
461 |
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
|
755 | 462 |
|
463 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
464 |
||
1916 | 465 |
VertexBuffer[0].X:= X; |
466 |
VertexBuffer[0].Y:= Y; |
|
467 |
VertexBuffer[1].X:= rr.w + X; |
|
468 |
VertexBuffer[1].Y:= Y; |
|
469 |
VertexBuffer[2].X:= rr.w + X; |
|
470 |
VertexBuffer[2].Y:= rr.h + Y; |
|
471 |
VertexBuffer[3].X:= X; |
|
472 |
VertexBuffer[3].Y:= rr.h + Y; |
|
755 | 473 |
|
1916 | 474 |
TextureBuffer[0].X:= _l; |
475 |
TextureBuffer[0].Y:= _t; |
|
476 |
TextureBuffer[1].X:= _r; |
|
477 |
TextureBuffer[1].Y:= _t; |
|
478 |
TextureBuffer[2].X:= _r; |
|
479 |
TextureBuffer[2].Y:= _b; |
|
480 |
TextureBuffer[3].X:= _l; |
|
481 |
TextureBuffer[3].Y:= _b; |
|
755 | 482 |
|
1916 | 483 |
glEnableClientState(GL_VERTEX_ARRAY); |
484 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
755 | 485 |
|
1916 | 486 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
487 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
488 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
489 |
||
490 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
491 |
glDisableClientState(GL_VERTEX_ARRAY) |
|
762 | 492 |
end; |
493 |
||
494 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture); |
|
495 |
begin |
|
1904 | 496 |
glPushMatrix; |
497 |
glTranslatef(X, Y, 0); |
|
498 |
||
762 | 499 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
500 |
||
1904 | 501 |
glEnableClientState(GL_VERTEX_ARRAY); |
502 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
762 | 503 |
|
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
504 |
glVertexPointer(2, GL_FLOAT, 0, @Texture^.vb); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
505 |
glTexCoordPointer(2, GL_FLOAT, 0, @Texture^.tb); |
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
506 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
1904 | 507 |
|
508 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
509 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
510 |
||
511 |
glPopMatrix |
|
4 | 512 |
end; |
513 |
||
2811 | 514 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); |
1242 | 515 |
begin |
2811 | 516 |
DrawRotatedTextureF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0) |
2597 | 517 |
end; |
518 |
||
2811 | 519 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
520 |
var ft, fb, fl, fr: GLfloat; |
|
521 |
hw, nx, ny: LongInt; |
|
2597 | 522 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
523 |
begin |
|
524 |
glPushMatrix; |
|
525 |
glTranslatef(X, Y, 0); |
|
526 |
||
527 |
if Dir < 0 then |
|
528 |
glRotatef(Angle, 0, 0, -1) |
|
529 |
else |
|
530 |
glRotatef(Angle, 0, 0, 1); |
|
531 |
||
532 |
glTranslatef(Dir*OffsetX, OffsetY, 0); |
|
2811 | 533 |
glScalef(Scale, Scale, 1); |
534 |
||
2597 | 535 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
1242 | 536 |
|
537 |
if Dir < 0 then |
|
2811 | 538 |
hw:= w div -2 |
1242 | 539 |
else |
2811 | 540 |
hw:= w div 2; |
541 |
||
542 |
nx:= round(Texture^.w * Texture^.rx / w); |
|
543 |
ny:= round(Texture^.h * Texture^.ry / h); |
|
1242 | 544 |
|
2811 | 545 |
ft:= ((Frame mod ny) / ny); |
546 |
fb:= (((Frame mod ny) + 1) / ny); |
|
547 |
fl:= ((Frame div ny) / nx) * Texture^.rx; |
|
548 |
fr:= (((Frame div ny) + 1) / nx); |
|
1242 | 549 |
|
550 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
551 |
||
1916 | 552 |
VertexBuffer[0].X:= -hw; |
2811 | 553 |
VertexBuffer[0].Y:= w / -2; |
1916 | 554 |
VertexBuffer[1].X:= hw; |
2811 | 555 |
VertexBuffer[1].Y:= w / -2; |
1916 | 556 |
VertexBuffer[2].X:= hw; |
2811 | 557 |
VertexBuffer[2].Y:= w / 2; |
1916 | 558 |
VertexBuffer[3].X:= -hw; |
2811 | 559 |
VertexBuffer[3].Y:= w / 2; |
1242 | 560 |
|
2811 | 561 |
TextureBuffer[0].X:= fl; |
1916 | 562 |
TextureBuffer[0].Y:= ft; |
2811 | 563 |
TextureBuffer[1].X:= fr; |
1916 | 564 |
TextureBuffer[1].Y:= ft; |
2811 | 565 |
TextureBuffer[2].X:= fr; |
1916 | 566 |
TextureBuffer[2].Y:= fb; |
2811 | 567 |
TextureBuffer[3].X:= fl; |
1916 | 568 |
TextureBuffer[3].Y:= fb; |
1242 | 569 |
|
1916 | 570 |
glEnableClientState(GL_VERTEX_ARRAY); |
571 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
1242 | 572 |
|
1916 | 573 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
574 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
575 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
576 |
||
577 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
|
578 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
579 |
||
1242 | 580 |
|
581 |
glPopMatrix |
|
582 |
end; |
|
583 |
||
822 | 584 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
775 | 585 |
begin |
777 | 586 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
822 | 587 |
SpritesData[Sprite].Width, |
588 |
SpritesData[Sprite].Height, |
|
589 |
X, Y, Dir, Angle) |
|
777 | 590 |
end; |
591 |
||
853 | 592 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
806 | 593 |
begin |
594 |
glPushMatrix; |
|
809 | 595 |
glTranslatef(X, Y, 0); |
806 | 596 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
597 |
if Dir < 0 then |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
598 |
glRotatef(Angle, 0, 0, -1) |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
599 |
else |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
600 |
glRotatef(Angle, 0, 0, 1); |
853 | 601 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
602 |
||
603 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
806 | 604 |
|
605 |
glPopMatrix |
|
606 |
end; |
|
607 |
||
822 | 608 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
1916 | 609 |
var VertexBuffer: array [0..3] of TVertex2f; |
777 | 610 |
begin |
775 | 611 |
glPushMatrix; |
612 |
glTranslatef(X, Y, 0); |
|
822 | 613 |
|
614 |
if Dir < 0 then |
|
615 |
begin |
|
616 |
hw:= - hw; |
|
617 |
glRotatef(Angle, 0, 0, -1); |
|
618 |
end else |
|
619 |
glRotatef(Angle, 0, 0, 1); |
|
620 |
||
775 | 621 |
|
777 | 622 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
775 | 623 |
|
1916 | 624 |
VertexBuffer[0].X:= -hw; |
625 |
VertexBuffer[0].Y:= -hh; |
|
626 |
VertexBuffer[1].X:= hw; |
|
627 |
VertexBuffer[1].Y:= -hh; |
|
628 |
VertexBuffer[2].X:= hw; |
|
629 |
VertexBuffer[2].Y:= hh; |
|
630 |
VertexBuffer[3].X:= -hw; |
|
631 |
VertexBuffer[3].Y:= hh; |
|
775 | 632 |
|
1916 | 633 |
glEnableClientState(GL_VERTEX_ARRAY); |
634 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
775 | 635 |
|
1916 | 636 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
637 |
glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb); |
|
638 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
775 | 639 |
|
1916 | 640 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
641 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
775 | 642 |
|
643 |
glPopMatrix |
|
644 |
end; |
|
645 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
646 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
4 | 647 |
begin |
648 |
r.y:= r.y + Height * Position; |
|
649 |
r.h:= Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
650 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 651 |
end; |
652 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
653 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
654 |
var row, col, numFramesFirstCol: LongInt; |
4 | 655 |
begin |
2229
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
656 |
numFramesFirstCol:= SpritesData[Sprite].imageHeight div SpritesData[Sprite].Height; |
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
657 |
row:= Frame mod numFramesFirstCol; |
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
658 |
col:= Frame div numFramesFirstCol; |
081081a61a16
patch for loading sprites on two columns (helps embedded and lowpower machines). must deal with amGirder.png
koda
parents:
2227
diff
changeset
|
659 |
DrawSprite2 (Sprite, X, Y, col, row); |
4 | 660 |
end; |
661 |
||
1939 | 662 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
663 |
var r: TSDL_Rect; |
|
664 |
begin |
|
665 |
r.x:= 0; |
|
666 |
r.y:= 0; |
|
667 |
r.w:= SpritesData[Sprite].Width; |
|
668 |
r.h:= SpritesData[Sprite].Height; |
|
669 |
||
670 |
if (X < LeftX) then |
|
671 |
r.x:= LeftX - X; |
|
672 |
if (Y < TopY) then |
|
673 |
r.y:= TopY - Y; |
|
674 |
||
675 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
676 |
r.h:= BottomY - Y + 1; |
|
677 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
678 |
r.w:= RightX - X + 1; |
|
679 |
||
680 |
dec(r.h, r.y); |
|
681 |
dec(r.w, r.x); |
|
2230
d6963f72d21a
once again, trying to restore windows compatibility from nemo's experiments
koda
parents:
2229
diff
changeset
|
682 |
|
1939 | 683 |
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
684 |
end; |
|
685 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
686 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
43 | 687 |
var r: TSDL_Rect; |
688 |
begin |
|
689 |
r.x:= FrameX * SpritesData[Sprite].Width; |
|
690 |
r.w:= SpritesData[Sprite].Width; |
|
691 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
692 |
r.h:= SpritesData[Sprite].Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
693 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
43 | 694 |
end; |
695 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
696 |
procedure DrawSurfSprite(X, Y, Height, Frame: LongInt; Source: PTexture); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
697 |
var r: TSDL_Rect; |
198 | 698 |
begin |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
699 |
r.x:= 0; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
700 |
r.w:= Source^.w; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
701 |
r.y:= Frame * Height; |
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
702 |
r.h:= Height; |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
703 |
DrawFromRect(X, Y, @r, Source) |
198 | 704 |
end; |
705 |
||
762 | 706 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
95 | 707 |
begin |
2567 | 708 |
DrawTexture(X - Source^.w shr 1, Top, Source) |
4 | 709 |
end; |
710 |
||
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
diff
changeset
|
711 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1916 | 712 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
713 |
(x: -16; y: -16), |
|
714 |
(x: 16; y: -16), |
|
715 |
(x: 16; y: 16), |
|
716 |
(x: -16; y: 16)); |
|
761 | 717 |
var l, r, t, b: real; |
1916 | 718 |
TextureBuffer: array [0..3] of TVertex2f; |
4 | 719 |
begin |
761 | 720 |
|
721 |
t:= Pos * 32 / HHTexture^.h; |
|
722 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
723 |
||
724 |
if Dir = -1 then |
|
725 |
begin |
|
726 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
727 |
r:= Step * 32 / HHTexture^.w |
|
728 |
end else |
|
729 |
begin |
|
730 |
l:= Step * 32 / HHTexture^.w; |
|
731 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
732 |
end; |
|
733 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
734 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
735 |
glPushMatrix(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
736 |
glTranslatef(X, Y, 0); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
737 |
glRotatef(Angle, 0, 0, 1); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
738 |
|
761 | 739 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
740 |
||
1916 | 741 |
TextureBuffer[0].X:= l; |
742 |
TextureBuffer[0].Y:= t; |
|
743 |
TextureBuffer[1].X:= r; |
|
744 |
TextureBuffer[1].Y:= t; |
|
745 |
TextureBuffer[2].X:= r; |
|
746 |
TextureBuffer[2].Y:= b; |
|
747 |
TextureBuffer[3].X:= l; |
|
748 |
TextureBuffer[3].Y:= b; |
|
761 | 749 |
|
1916 | 750 |
glEnableClientState(GL_VERTEX_ARRAY); |
751 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
761 | 752 |
|
1916 | 753 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
754 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
755 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
761 | 756 |
|
1916 | 757 |
glDisableClientState(GL_TEXTURE_COORD_ARRAY); |
758 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
761 | 759 |
|
1854 | 760 |
|
761 |
glColor4f(1,1,1,1); |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
762 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
763 |
glPopMatrix |
4 | 764 |
end; |
765 |
||
1431 | 766 |
procedure DrawFillRect(r: TSDL_Rect); |
1916 | 767 |
var VertexBuffer: array [0..3] of TVertex2f; |
1431 | 768 |
begin |
769 |
glDisable(GL_TEXTURE_2D); |
|
770 |
||
771 |
glColor4ub(0, 0, 0, 127); |
|
772 |
||
1916 | 773 |
VertexBuffer[0].X:= r.x; |
774 |
VertexBuffer[0].Y:= r.y; |
|
775 |
VertexBuffer[1].X:= r.x + r.w; |
|
776 |
VertexBuffer[1].Y:= r.y; |
|
777 |
VertexBuffer[2].X:= r.x + r.w; |
|
778 |
VertexBuffer[2].Y:= r.y + r.h; |
|
779 |
VertexBuffer[3].X:= r.x; |
|
780 |
VertexBuffer[3].Y:= r.y + r.h; |
|
1431 | 781 |
|
1916 | 782 |
glEnableClientState(GL_VERTEX_ARRAY); |
783 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
|
784 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
785 |
glDisableClientState(GL_VERTEX_ARRAY); |
|
1431 | 786 |
|
787 |
glColor4f(1, 1, 1, 1); |
|
788 |
glEnable(GL_TEXTURE_2D) |
|
789 |
end; |
|
790 |
||
4 | 791 |
procedure StoreRelease; |
792 |
var ii: TSprite; |
|
793 |
begin |
|
794 |
for ii:= Low(TSprite) to High(TSprite) do |
|
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
795 |
begin |
759 | 796 |
FreeTexture(SpritesData[ii].Texture); |
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
797 |
if SpritesData[ii].Surface <> nil then SDL_FreeSurface(SpritesData[ii].Surface) |
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
798 |
end; |
2786 | 799 |
SDL_FreeSurface(MissionIcons); |
2811 | 800 |
FreeTexture(ropeIconTex); |
1806 | 801 |
FreeTexture(HHTexture) |
4 | 802 |
end; |
803 |
||
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
804 |
|
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
805 |
function CheckCJKFont(s: string; font: THWFont): THWFont; |
2681
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
806 |
var l, i : LongInt; |
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
807 |
u: WideChar; |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
808 |
tmpstr: array[0..256] of WideChar; |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
809 |
begin |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
810 |
if font >= CJKfntSmall then exit(font); |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
811 |
|
2684
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
812 |
l:= Utf8ToUnicode(@tmpstr, Str2PChar(s), length(s))-1; |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
813 |
i:= 0; |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
814 |
while i < l do |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
815 |
begin |
2681
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
816 |
u:= tmpstr[i]; |
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
817 |
if (#$2E80 <= u) and ( |
2684
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
818 |
(u <= #$2FDF ) or // CJK Radicals Supplement / Kangxi Radicals |
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
819 |
((#$2FF0 <= u) and (u <= #$303F)) or // Ideographic Description Characters / CJK Radicals Supplement |
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
820 |
((#$31C0 <= u) and (u <= #$31EF)) or // CJK Strokes |
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
821 |
((#$3200 <= u) and (u <= #$4DBF)) or // Enclosed CJK Letters and Months / CJK Compatibility / CJK Unified Ideographs Extension A |
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
822 |
((#$4E00 <= u) and (u <= #$9FFF)) or // CJK Unified Ideographs |
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
823 |
((#$F900 <= u) and (u <= #$FAFF)) or // CJK Compatibility Ideographs |
04c086d8d9d4
Hopefully this is the last error. Fix the if test, offset by -1 due to how the output appears to be handled.
nemo
parents:
2681
diff
changeset
|
824 |
((#$FE30 <= u) and (u <= #$FE4F))) // CJK Compatibility Forms |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
825 |
then exit(THWFont( ord(font) + ((ord(High(THWFont))+1) div 2) )); |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
826 |
inc(i) |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
827 |
end; |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
828 |
exit(font); |
2681
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
829 |
(* two more to check. pascal WideChar is only 16 bit though |
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
830 |
((#$20000 <= u) and (u >= #$2A6DF)) or // CJK Unified Ideographs Extension B |
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
831 |
((#$2F800 <= u) and (u >= #$2FA1F))) // CJK Compatibility Ideographs Supplement *) |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
832 |
end; |
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
833 |
|
762 | 834 |
function RenderStringTex(s: string; Color: Longword; font: THWFont): PTexture; |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
835 |
var w, h : LongInt; |
2695 | 836 |
finalSurface: PSDL_Surface; |
95 | 837 |
begin |
1989 | 838 |
if length(s) = 0 then s:= ' '; |
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
839 |
font:= CheckCJKFont(s, font); |
355 | 840 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
785 | 841 |
|
2695 | 842 |
finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
762 | 843 |
32, RMask, GMask, BMask, AMask); |
785 | 844 |
|
2695 | 845 |
TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true); |
785 | 846 |
|
2695 | 847 |
WriteInRoundRect(finalSurface, 0, 0, Color, font, s); |
785 | 848 |
|
2695 | 849 |
TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
785 | 850 |
|
2695 | 851 |
RenderStringTex:= Surface2Tex(finalSurface, false); |
785 | 852 |
|
2695 | 853 |
SDL_FreeSurface(finalSurface); |
95 | 854 |
end; |
855 |
||
2017 | 856 |
function RenderSpeechBubbleTex(s: string; SpeechType: Longword; font: THWFont): PTexture; |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
857 |
var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt; |
2695 | 858 |
finalSurface, tmpsurf, rotatedEdge: PSDL_Surface; |
2017 | 859 |
rect: TSDL_Rect; |
860 |
chars: TSysCharSet = [#9,' ','.',';',':','?','!',',']; |
|
861 |
substr: shortstring; |
|
862 |
edge, corner, tail: TSPrite; |
|
863 |
begin |
|
864 |
||
865 |
case SpeechType of |
|
2376 | 866 |
1: begin; |
867 |
edge:= sprSpeechEdge; |
|
2017 | 868 |
corner:= sprSpeechCorner; |
869 |
tail:= sprSpeechTail; |
|
870 |
end; |
|
2376 | 871 |
2: begin; |
2017 | 872 |
edge:= sprThoughtEdge; |
2376 | 873 |
corner:= sprThoughtCorner; |
2017 | 874 |
tail:= sprThoughtTail; |
875 |
end; |
|
2376 | 876 |
3: begin; |
2017 | 877 |
edge:= sprShoutEdge; |
878 |
corner:= sprShoutCorner; |
|
879 |
tail:= sprShoutTail; |
|
880 |
end; |
|
881 |
end; |
|
882 |
edgeHeight:= SpritesData[edge].Height; |
|
883 |
edgeWidth:= SpritesData[edge].Width; |
|
884 |
cornerWidth:= SpritesData[corner].Width; |
|
885 |
cornerHeight:= SpritesData[corner].Height; |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
886 |
// This one screws up WrapText |
2022 | 887 |
//s:= 'This is the song that never ends. ''cause it goes on and on my friends. Some people, started singing it not knowing what it was. And they''ll just go on singing it forever just because... This is the song that never ends...'; |
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:
2153
diff
changeset
|
888 |
// This one does not |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
889 |
//s:= 'This is the song that never ends. cause it goes on and on my friends. Some people, started singing it not knowing what it was. And they will go on singing it forever just because... This is the song that never ends... '; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
890 |
|
2022 | 891 |
numLines:= 0; |
2017 | 892 |
|
893 |
if length(s) = 0 then s:= '...'; |
|
2677
83ad68ceef72
Non-hacked version of CJK handling. Should switch to CJK rendering only if a particular string needs it, instead of based on locale file.
nemo
parents:
2674
diff
changeset
|
894 |
font:= CheckCJKFont(s, font); |
2017 | 895 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
2332
351abbbb12f3
Lower bound on speech text width for proper rendering
nemo
parents:
2292
diff
changeset
|
896 |
if w<8 then w:= 8; |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
897 |
j:= 0; |
2017 | 898 |
if (length(s) > 20) then |
899 |
begin |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
900 |
w:= 0; |
2017 | 901 |
i:= round(Sqrt(length(s)) * 2); |
902 |
s:= WrapText(s, #1, chars, i); |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
903 |
pos:= 1; prevpos:= 0; line:= 0; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
904 |
// Find the longest line for the purposes of centring the text. Font dependant. |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
905 |
while pos <= length(s) do |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
906 |
begin |
2017 | 907 |
if (s[pos] = #1) or (pos = length(s)) then |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
908 |
begin |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
909 |
inc(numlines); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
910 |
if s[pos] <> #1 then inc(pos); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
911 |
while s[prevpos+1] = ' ' do inc(prevpos); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
912 |
substr:= copy(s, prevpos+1, pos-prevpos-1); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
913 |
i:= 0; j:= 0; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
914 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(substr), i, j); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
915 |
if i > w then w:= i; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
916 |
prevpos:= pos; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
917 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
918 |
inc(pos); |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
919 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
920 |
end |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
921 |
else numLines := 1; |
2017 | 922 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
923 |
textWidth:=((w-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth; |
2022 | 924 |
textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth; |
2019 | 925 |
|
2022 | 926 |
textHeight:=max(textHeight,edgeWidth); |
2017 | 927 |
//textWidth:=max(textWidth,SpritesData[tail].Width); |
928 |
rect.x:= 0; |
|
929 |
rect.y:= 0; |
|
2022 | 930 |
rect.w:= textWidth + (cornerWidth * 2); |
931 |
rect.h:= textHeight + cornerHeight*2 - edgeHeight + SpritesData[tail].Height; |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
932 |
//s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h); |
2017 | 933 |
|
2695 | 934 |
finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
2017 | 935 |
|
2695 | 936 |
TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true); |
2017 | 937 |
|
938 |
//////////////////////////////// CORNERS /////////////////////////////// |
|
2695 | 939 |
copyToXY(SpritesData[corner].Surface, finalSurface, 0, 0); /////////////////// NW |
2017 | 940 |
|
941 |
flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips? |
|
942 |
x:= 0; |
|
943 |
y:= textHeight + cornerHeight -1; |
|
2695 | 944 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// SW |
2017 | 945 |
|
946 |
flipSurface(SpritesData[corner].Surface, false); |
|
947 |
x:= rect.w-cornerWidth-1; |
|
948 |
y:= textHeight + cornerHeight -1; |
|
2695 | 949 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// SE |
2017 | 950 |
|
951 |
flipSurface(SpritesData[corner].Surface, true); |
|
952 |
x:= rect.w-cornerWidth-1; |
|
953 |
y:= 0; |
|
2695 | 954 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// NE |
2017 | 955 |
flipSurface(SpritesData[corner].Surface, false); // restore original position |
956 |
//////////////////////////////// END CORNERS /////////////////////////////// |
|
957 |
||
958 |
//////////////////////////////// EDGES ////////////////////////////////////// |
|
959 |
x:= cornerWidth; |
|
960 |
y:= 0; |
|
961 |
while x < rect.w-cornerWidth-1 do |
|
962 |
begin |
|
2695 | 963 |
copyToXY(SpritesData[edge].Surface, finalSurface, x, y); ///////////////// top edge |
2017 | 964 |
inc(x,edgeWidth); |
965 |
end; |
|
966 |
flipSurface(SpritesData[edge].Surface, true); |
|
967 |
x:= cornerWidth; |
|
968 |
y:= textHeight + cornerHeight*2 - edgeHeight-1; |
|
969 |
while x < rect.w-cornerWidth-1 do |
|
970 |
begin |
|
2695 | 971 |
copyToXY(SpritesData[edge].Surface, finalSurface, x, y); ///////////////// bottom edge |
2017 | 972 |
inc(x,edgeWidth); |
973 |
end; |
|
974 |
flipSurface(SpritesData[edge].Surface, true); // restore original position |
|
975 |
||
976 |
rotatedEdge:= SDL_CreateRGBSurface(SDL_SWSURFACE, edgeHeight, edgeWidth, 32, RMask, GMask, BMask, AMask); |
|
977 |
x:= rect.w - edgeHeight - 1; |
|
978 |
y:= cornerHeight; |
|
979 |
//// initially was going to rotate in place, but the SDL spec claims width/height are read only |
|
980 |
copyRotatedSurface(SpritesData[edge].Surface,rotatedEdge); |
|
981 |
while y < textHeight + cornerHeight do |
|
982 |
begin |
|
2695 | 983 |
copyToXY(rotatedEdge, finalSurface, x, y); |
2017 | 984 |
inc(y,edgeWidth); |
985 |
end; |
|
986 |
flipSurface(rotatedEdge, false); // restore original position |
|
987 |
x:= 0; |
|
988 |
y:= cornerHeight; |
|
989 |
while y < textHeight + cornerHeight do |
|
990 |
begin |
|
2695 | 991 |
copyToXY(rotatedEdge, finalSurface, x, y); |
2017 | 992 |
inc(y,edgeWidth); |
993 |
end; |
|
994 |
//////////////////////////////// END EDGES ////////////////////////////////////// |
|
995 |
||
996 |
x:= cornerWidth; |
|
997 |
y:= textHeight + cornerHeight * 2 - edgeHeight - 1; |
|
2695 | 998 |
copyToXY(SpritesData[tail].Surface, finalSurface, x, y); |
2017 | 999 |
|
1000 |
rect.x:= edgeHeight; |
|
1001 |
rect.y:= edgeHeight; |
|
1002 |
rect.w:= rect.w - edgeHeight * 2; |
|
1003 |
rect.h:= textHeight + cornerHeight * 2 - edgeHeight * 2; |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
1004 |
i:= rect.w; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
1005 |
j:= rect.h; |
2695 | 1006 |
SDL_FillRect(finalSurface, @rect, cWhiteColor); |
2017 | 1007 |
|
1008 |
pos:= 1; prevpos:= 0; line:= 0; |
|
1009 |
while pos <= length(s) do |
|
1010 |
begin |
|
1011 |
if (s[pos] = #1) or (pos = length(s)) then |
|
1012 |
begin |
|
1013 |
if s[pos] <> #1 then inc(pos); |
|
1014 |
while s[prevpos+1] = ' 'do inc(prevpos); |
|
1015 |
substr:= copy(s, prevpos+1, pos-prevpos-1); |
|
1016 |
if Length(substr) <> 0 then |
|
1017 |
begin |
|
2666 | 1018 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(substr), cNearBlackColorChannels); |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
1019 |
rect.x:= edgeHeight + 1 + ((i - w) div 2); |
2022 | 1020 |
// trying to more evenly position the text, vertically |
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
1021 |
rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; |
2017 | 1022 |
SDLTry(tmpsurf <> nil, true); |
2695 | 1023 |
SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect); |
2017 | 1024 |
SDL_FreeSurface(tmpsurf); |
1025 |
inc(line); |
|
1026 |
prevpos:= pos; |
|
1027 |
end; |
|
1028 |
end; |
|
1029 |
inc(pos); |
|
1030 |
end; |
|
1031 |
||
2695 | 1032 |
//TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
1033 |
RenderSpeechBubbleTex:= Surface2Tex(finalSurface, true); |
|
2017 | 1034 |
|
1035 |
SDL_FreeSurface(rotatedEdge); |
|
2695 | 1036 |
SDL_FreeSurface(finalSurface); |
2017 | 1037 |
end; |
1038 |
||
4 | 1039 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 1040 |
var s: shortstring; |
4 | 1041 |
begin |
2705
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2701
diff
changeset
|
1042 |
str(Hedgehog.Gear^.Health, s); |
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2701
diff
changeset
|
1043 |
if Hedgehog.HealthTagTex <> nil then |
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2701
diff
changeset
|
1044 |
FreeTexture(Hedgehog.HealthTagTex); |
2b5625c4ec16
fix a nasty 196 bytes memory leak in engine, plus other stuff for iphone frontend
koda
parents:
2701
diff
changeset
|
1045 |
Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
4 | 1046 |
end; |
1047 |
||
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
|
1048 |
function LoadImage(const filename: string; imageFlags: LongInt): PSDL_Surface; |
30 | 1049 |
var tmpsurf: PSDL_Surface; |
355 | 1050 |
s: shortstring; |
4 | 1051 |
begin |
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
|
1052 |
WriteToConsole(msgLoading + filename + ' [flags: ' + inttostr(imageFlags) + ']... '); |
2426 | 1053 |
|
2630 | 1054 |
s:= filename + '.png'; |
1055 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
|
2254 | 1056 |
|
2630 | 1057 |
if (imageFlags and ifLowRes) <> 0 then |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1058 |
begin |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1059 |
s:= filename + '-lowres.png'; |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1060 |
if (tmpsurf <> nil) then |
2376 | 1061 |
begin |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1062 |
if ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1063 |
begin |
2426 | 1064 |
SDL_FreeSurface(tmpsurf); |
2630 | 1065 |
{$IFDEF DEBUGFILE} |
1066 |
AddFileLog('...image too big, trying to load lowres version: ' + s + '...'); |
|
1067 |
{$ENDIF} |
|
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1068 |
tmpsurf:= IMG_Load(Str2PChar(s)) |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1069 |
end; |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1070 |
end |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1071 |
else |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1072 |
begin |
2630 | 1073 |
{$IFDEF DEBUGFILE} |
1074 |
AddFileLog('...image not found, trying to load lowres version: ' + s + '...'); |
|
1075 |
{$ENDIF} |
|
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1076 |
tmpsurf:= IMG_Load(Str2PChar(s)) |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1077 |
end; |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1078 |
end; |
2376 | 1079 |
|
2630 | 1080 |
if tmpsurf = nil then |
2153 | 1081 |
begin |
2630 | 1082 |
OutError(msgFailed, (imageFlags and ifCritical) <> 0); |
1083 |
exit(nil) |
|
2153 | 1084 |
end; |
1085 |
||
2630 | 1086 |
if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
2153 | 1087 |
begin |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1088 |
SDL_FreeSurface(tmpsurf); |
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1089 |
OutError(msgFailedSize, (imageFlags and ifCritical) <> 0); |
2630 | 1090 |
// dummy surface to replace non-critical textures that failed to load due to their size |
2244
853a1db1cff6
routine for loading lower resolution horizont and sky for nature theme when bigger images are not supported; right now they are not installed, but they could be useful for less powerful machines in general
koda
parents:
2240
diff
changeset
|
1091 |
exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask)); |
2153 | 1092 |
end; |
351 | 1093 |
|
2630 | 1094 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
1095 |
||
1096 |
if (imageFlags and ifTransparent) <> 0 then |
|
1097 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
|
1098 |
||
1099 |
WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') '); |
|
1100 |
WriteLnToConsole(msgOK); |
|
1101 |
||
1102 |
LoadImage:= tmpsurf //Result |
|
753 | 1103 |
end; |
1104 |
||
2428 | 1105 |
function glLoadExtension(extension : string) : boolean; |
1106 |
begin |
|
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1107 |
{$IFDEF IPHONEOS} |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1108 |
glLoadExtension:= false; |
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1109 |
{$ELSE} |
2428 | 1110 |
glLoadExtension:= glext_LoadExtension(extension); |
2438 | 1111 |
{$ENDIF} |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1112 |
{$IFDEF DEBUGFILE} |
2428 | 1113 |
if not glLoadExtension then |
2575 | 1114 |
AddFileLog('OpenGL - "' + extension + '" failed to load') |
2428 | 1115 |
else |
2575 | 1116 |
AddFileLog('OpenGL - "' + extension + '" loaded'); |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1117 |
{$ENDIF} |
2428 | 1118 |
end; |
1119 |
||
753 | 1120 |
procedure SetupOpenGL; |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1121 |
var vendor: shortstring; |
753 | 1122 |
begin |
2697 | 1123 |
{$IFDEF IPHONEOS} |
1124 |
//these are good performance savers, perhaps we could enable them by default |
|
1125 |
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0); |
|
1126 |
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1); |
|
1127 |
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); |
|
1128 |
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
|
1129 |
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); |
|
1130 |
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
|
1131 |
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); |
|
1132 |
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); |
|
1133 |
//SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); |
|
1134 |
{$ELSE} |
|
1135 |
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
|
1136 |
{$ENDIF} |
|
1137 |
||
1138 |
{$IFNDEF SDL13} |
|
1139 |
// this attribute is default in 1.3 and must be enabled in MacOSX |
|
1140 |
{$IFNDEF DARWIN} |
|
1141 |
if cVSyncInUse then |
|
1142 |
{$ENDIF} |
|
1143 |
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); |
|
1144 |
{$ENDIF} |
|
1145 |
||
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
|
1146 |
glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize); |
2697 | 1147 |
|
2698 | 1148 |
vendor:= LowerCase(string(pchar(glGetString(GL_VENDOR)))); |
2697 | 1149 |
{$IFDEF DEBUGFILE} |
2701
3a8560c00f78
settings tab has now a very nice iphone-like interface
koda
parents:
2699
diff
changeset
|
1150 |
AddFileLog('OpenGL-- Renderer: ' + string(pchar(glGetString(GL_RENDERER)))); |
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
|
1151 |
AddFileLog(' |----- Vendor: ' + vendor); |
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
|
1152 |
AddFileLog(' |----- Version: ' + string(pchar(glGetString(GL_VERSION)))); |
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
|
1153 |
AddFileLog(' \----- GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize)); |
2153 | 1154 |
{$ENDIF} |
2252 | 1155 |
|
2697 | 1156 |
if MaxTextureSize <= 0 then |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1157 |
begin |
2633 | 1158 |
MaxTextureSize:= 1024; |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1159 |
{$IFDEF DEBUGFILE} |
2633 | 1160 |
AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024'); |
2568
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1161 |
{$ENDIF} |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1162 |
end; |
e654cbfb23ba
Bunch of neat stuff by Smaxx. ATI check, translucent name tags to reduce terrain fail, disabling health crates on invulnerable hogs. Also tweaks to prior stuff.
nemo
parents:
2567
diff
changeset
|
1163 |
|
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
|
1164 |
{$IFNDEF IPHONEOS} |
2697 | 1165 |
if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then |
1166 |
cGPUVendor:= gvNVIDIA |
|
1167 |
else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then |
|
1168 |
cGPUVendor:= gvATI |
|
1169 |
else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then |
|
1170 |
cGPUVendor:= gvIntel; |
|
2647 | 1171 |
//SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two'); |
2735 | 1172 |
{$ELSE} |
1173 |
cGPUVendor:= gvApple; |
|
1174 |
{$ENDIF} |
|
1175 |
||
1176 |
{$IFDEF DEBUGFILE} |
|
1177 |
if cGPUVendor = gvUnknown then |
|
1178 |
AddFileLog('OpenGL Warning - unknown hardware vendor; please report'); |
|
1179 |
{$ELSE} |
|
1180 |
// just avoid 'never used' compiler warning for now |
|
1181 |
if cGPUVendor = gvUnknown then cGPUVendor:= gvUnknown; |
|
2428 | 1182 |
{$ENDIF} |
1183 |
||
2697 | 1184 |
// set view port to whole window |
2724 | 1185 |
{$IFDEF IPHONEOS} |
1186 |
glViewport(0, 0, cScreenHeight, cScreenWidth); |
|
1187 |
{$ELSE} |
|
2697 | 1188 |
glViewport(0, 0, cScreenWidth, cScreenHeight); |
2724 | 1189 |
{$ENDIF} |
2428 | 1190 |
|
2697 | 1191 |
glMatrixMode(GL_MODELVIEW); |
1192 |
// prepare default translation/scaling |
|
1193 |
glLoadIdentity(); |
|
2724 | 1194 |
{$IFDEF IPHONEOS} |
1195 |
glRotatef(-90, 0, 0, 1); |
|
1196 |
{$ENDIF} |
|
2697 | 1197 |
glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
1198 |
glTranslatef(0, -cScreenHeight / 2, 0); |
|
2428 | 1199 |
|
2697 | 1200 |
// enable alpha blending |
1201 |
glEnable(GL_BLEND); |
|
1202 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
|
4 | 1203 |
end; |
1204 |
||
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1205 |
procedure SetScale(f: GLfloat); |
2724 | 1206 |
var |
1207 |
{$IFDEF IPHONEOS} |
|
1208 |
scale: GLfloat = 1.5; |
|
1209 |
{$ELSE} |
|
1210 |
scale: GLfloat = 2.0; |
|
1211 |
{$ENDIF} |
|
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1212 |
begin |
2697 | 1213 |
// leave immediately if scale factor did not change |
1214 |
if f = cScaleFactor then exit; |
|
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1215 |
|
2724 | 1216 |
if f = scale then glPopMatrix // "return" to default scaling |
1217 |
else // other scaling |
|
2428 | 1218 |
begin |
2724 | 1219 |
glPushMatrix; // save default scaling |
2697 | 1220 |
glLoadIdentity; |
2724 | 1221 |
{$IFDEF IPHONEOS} |
1222 |
glRotatef(-90, 0, 0, 1); |
|
1223 |
{$ENDIF} |
|
2697 | 1224 |
glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); |
1225 |
glTranslatef(0, -cScreenHeight / 2, 0); |
|
2428 | 1226 |
end; |
2258 | 1227 |
|
2697 | 1228 |
cScaleFactor:= f; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1229 |
end; |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1230 |
|
510 | 1231 |
//////////////////////////////////////////////////////////////////////////////// |
1232 |
procedure AddProgress; |
|
1233 |
var r: TSDL_Rect; |
|
766 | 1234 |
texsurf: PSDL_Surface; |
510 | 1235 |
begin |
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
|
1236 |
if Step = 0 then |
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
|
1237 |
begin |
2697 | 1238 |
{$IFDEF SDL_IMAGE_NEWER} |
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
|
1239 |
WriteToConsole('Init SDL_image... '); |
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
|
1240 |
SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true); |
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
|
1241 |
WriteLnToConsole(msgOK); |
2697 | 1242 |
{$ENDIF} |
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
|
1243 |
|
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
|
1244 |
WriteToConsole(msgLoading + 'progress sprite: '); |
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
|
1245 |
texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1246 |
|
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
|
1247 |
ProgrTex:= Surface2Tex(texsurf, false); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1248 |
|
2697 | 1249 |
squaresize:= texsurf^.w shr 1; |
1250 |
numsquares:= texsurf^.h div squaresize; |
|
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
|
1251 |
SDL_FreeSurface(texsurf); |
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
|
1252 |
end; |
1045 | 1253 |
|
2697 | 1254 |
TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true); |
2284 | 1255 |
|
2697 | 1256 |
glClear(GL_COLOR_BUFFER_BIT); |
1257 |
glEnable(GL_TEXTURE_2D); |
|
1258 |
if Step < numsquares then r.x:= 0 |
|
1259 |
else r.x:= squaresize; |
|
1260 |
||
1261 |
r.y:= (Step mod numsquares) * squaresize; |
|
1262 |
r.w:= squaresize; |
|
1263 |
r.h:= squaresize; |
|
1264 |
||
1265 |
DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex); |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1266 |
|
2697 | 1267 |
glDisable(GL_TEXTURE_2D); |
1268 |
SDL_GL_SwapBuffers(); |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1269 |
{$IFDEF SDL13} |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1270 |
SDL_RenderPresent(); |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1271 |
{$ENDIF} |
2697 | 1272 |
inc(Step); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1273 |
|
510 | 1274 |
end; |
1275 |
||
2222 | 1276 |
|
510 | 1277 |
procedure FinishProgress; |
1278 |
begin |
|
2697 | 1279 |
WriteLnToConsole('Freeing progress surface... '); |
1280 |
FreeTexture(ProgrTex); |
|
2689 | 1281 |
|
1282 |
{$IFDEF IPHONEOS} |
|
2697 | 1283 |
// show overlay buttons |
1284 |
IPH_showControls; |
|
2689 | 1285 |
{$ENDIF} |
510 | 1286 |
end; |
1287 |
||
2017 | 1288 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
1289 |
var y, x, i, j: LongInt; |
|
1290 |
tmpPixel: Longword; |
|
1291 |
pixels: PLongWordArray; |
|
1292 |
begin |
|
1293 |
TryDo(Surface^.format^.BytesPerPixel = 4, 'flipSurface failed, expecting 32 bit surface', true); |
|
1294 |
pixels:= Surface^.pixels; |
|
1295 |
if Vertical then |
|
1296 |
for y := 0 to (Surface^.h div 2) - 1 do |
|
1297 |
for x := 0 to Surface^.w - 1 do |
|
1298 |
begin |
|
1299 |
i:= y * Surface^.w + x; |
|
1300 |
j:= (Surface^.h - y - 1) * Surface^.w + x; |
|
1301 |
tmpPixel:= pixels^[i]; |
|
1302 |
pixels^[i]:= pixels^[j]; |
|
1303 |
pixels^[j]:= tmpPixel; |
|
1304 |
end |
|
1305 |
else |
|
1306 |
for x := 0 to (Surface^.w div 2) - 1 do |
|
1307 |
for y := 0 to Surface^.h -1 do |
|
1308 |
begin |
|
1309 |
i:= y*Surface^.w + x; |
|
1310 |
j:= y*Surface^.w + (Surface^.w - x - 1); |
|
1311 |
tmpPixel:= pixels^[i]; |
|
1312 |
pixels^[i]:= pixels^[j]; |
|
1313 |
pixels^[j]:= tmpPixel; |
|
1314 |
end; |
|
1315 |
end; |
|
1316 |
||
1317 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: Integer); |
|
1318 |
var srcX, srcY, i, j, maxDest: LongInt; |
|
1319 |
srcPixels, destPixels: PLongWordArray; |
|
1320 |
begin |
|
1321 |
maxDest:= (dest^.pitch div 4) * dest^.h; |
|
1322 |
srcPixels:= src^.pixels; |
|
1323 |
destPixels:= dest^.pixels; |
|
1324 |
||
1325 |
for srcX:= 0 to src^.w - 1 do |
|
1326 |
for srcY:= 0 to src^.h - 1 do |
|
1327 |
begin |
|
1328 |
i:= (destY + srcY) * (dest^.pitch div 4) + destX + srcX; |
|
1329 |
j:= srcY * (src^.pitch div 4) + srcX; |
|
1330 |
// basic skip of transparent pixels - cleverness would be to do true alpha |
|
2592 | 1331 |
if (i < maxDest) and (AMask and srcPixels^[j] <> 0) then destPixels^[i]:= srcPixels^[j]; |
2017 | 1332 |
end; |
1333 |
end; |
|
1334 |
||
1335 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently |
|
1336 |
var y, x, i, j: LongInt; |
|
1337 |
srcPixels, destPixels: PLongWordArray; |
|
1338 |
begin |
|
1339 |
TryDo(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1340 |
TryDo(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1341 |
||
1342 |
srcPixels:= src^.pixels; |
|
1343 |
destPixels:= dest^.pixels; |
|
1344 |
||
1345 |
j:= 0; |
|
1346 |
for x := 0 to src^.w - 1 do |
|
1347 |
for y := 0 to src^.h - 1 do |
|
1348 |
begin |
|
1349 |
i:= (src^.h - 1 - y) * (src^.pitch div 4) + x; |
|
1350 |
destPixels^[j]:= srcPixels^[i]; |
|
1351 |
inc(j) |
|
1352 |
end; |
|
1353 |
end; |
|
1354 |
||
2747 | 1355 |
function RenderHelpWindow(caption, subcaption, description, extra: shortstring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture; |
1356 |
var tmpsurf: PSDL_SURFACE; |
|
1357 |
w, h, i, j: LongInt; |
|
1358 |
font: THWFont; |
|
1359 |
r, r2: TSDL_Rect; |
|
1360 |
wa, ha: LongInt; |
|
1361 |
tmpline, tmpline2, tmpdesc: shortstring; |
|
1362 |
begin |
|
1363 |
font:= fnt16; |
|
1364 |
||
1365 |
// make sure there is a caption as well as a sub caption - description is optional |
|
1366 |
if caption = '' then caption:= '???'; |
|
1367 |
if subcaption = '' then subcaption:= ' '; |
|
1368 |
||
1369 |
w:= 0; |
|
1370 |
h:= 0; |
|
1371 |
wa:= FontBorder * 2 + 4; |
|
1372 |
ha:= FontBorder * 2; |
|
1373 |
||
1374 |
// TODO: Recheck height/position calculation |
|
1375 |
||
1376 |
// get caption's dimensions |
|
1377 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(caption), i, j); |
|
1378 |
// width adds 36 px (image + space) |
|
1379 |
w:= i + 36 + wa; |
|
1380 |
h:= j + ha; |
|
1381 |
||
1382 |
// get sub caption's dimensions |
|
1383 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(subcaption), i, j); |
|
1384 |
// width adds 36 px (image + space) |
|
1385 |
if w < (i + 36 + wa) then w:= i + 36 + wa; |
|
1386 |
inc(h, j + ha); |
|
1387 |
||
1388 |
// get description's dimensions |
|
1389 |
tmpdesc:= description; |
|
1390 |
while tmpdesc <> '' do |
|
1391 |
begin |
|
1392 |
tmpline:= tmpdesc; |
|
1393 |
SplitByChar(tmpline, tmpdesc, '|'); |
|
1394 |
if tmpline <> '' then |
|
1395 |
begin |
|
1396 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(tmpline), i, j); |
|
1397 |
if w < (i + wa) then w:= i + wa; |
|
1398 |
inc(h, j + ha) |
|
1399 |
end |
|
1400 |
end; |
|
1401 |
||
1402 |
if extra <> '' then |
|
1403 |
begin |
|
1404 |
// get extra label's dimensions |
|
1405 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(extra), i, j); |
|
1406 |
if w < (i + wa) then w:= i + wa; |
|
1407 |
inc(h, j + ha); |
|
1408 |
end; |
|
1409 |
||
1410 |
// add borders space |
|
1411 |
inc(w, wa); |
|
1412 |
inc(h, ha + 8); |
|
1413 |
||
1414 |
tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RMask, GMask, BMask, AMask); |
|
1415 |
TryDo(tmpsurf <> nil, 'RenderHelpWindow: fail to create surface', true); |
|
1416 |
||
1417 |
// render border and background |
|
1418 |
r.x:= 0; |
|
1419 |
r.y:= 0; |
|
1420 |
r.w:= w; |
|
1421 |
r.h:= h; |
|
1422 |
DrawRoundRect(@r, cWhiteColor, cNearBlackColor, tmpsurf, true); |
|
1423 |
||
1424 |
// render caption |
|
1425 |
r:= WriteInRect(tmpsurf, 36 + FontBorder + 2, ha, $ffffffff, font, caption); |
|
1426 |
// render sub caption |
|
1427 |
r:= WriteInRect(tmpsurf, 36 + FontBorder + 2, r.y + r.h, $ffc7c7c7, font, subcaption); |
|
1428 |
||
1429 |
// render all description lines |
|
1430 |
tmpdesc:= description; |
|
1431 |
while tmpdesc <> '' do |
|
1432 |
begin |
|
1433 |
tmpline:= tmpdesc; |
|
1434 |
SplitByChar(tmpline, tmpdesc, '|'); |
|
1435 |
r2:= r; |
|
1436 |
if tmpline <> '' then |
|
1437 |
begin |
|
1438 |
r:= WriteInRect(tmpsurf, FontBorder + 2, r.y + r.h, $ff707070, font, tmpline); |
|
1439 |
||
1440 |
// render highlighted caption (if there's a ':') |
|
1441 |
SplitByChar(tmpline, tmpline2, ':'); |
|
1442 |
if tmpline2 <> '' then |
|
1443 |
WriteInRect(tmpsurf, FontBorder + 2, r2.y + r2.h, $ffc7c7c7, font, tmpline + ':'); |
|
1444 |
end |
|
1445 |
end; |
|
1446 |
||
1447 |
if extra <> '' then |
|
1448 |
r:= WriteInRect(tmpsurf, FontBorder + 2, r.y + r.h, extracolor, font, extra); |
|
1449 |
||
1450 |
r.x:= FontBorder + 6; |
|
1451 |
r.y:= FontBorder + 4; |
|
1452 |
r.w:= 32; |
|
1453 |
r.h:= 32; |
|
1454 |
SDL_FillRect(tmpsurf, @r, $ffffffff); |
|
1455 |
SDL_UpperBlit(iconsurf, iconrect, tmpsurf, @r); |
|
1456 |
||
1457 |
RenderHelpWindow:= Surface2Tex(tmpsurf, true); |
|
1458 |
SDL_FreeSurface(tmpsurf) |
|
1459 |
end; |
|
1460 |
||
1461 |
procedure RenderWeaponTooltip(atype: TAmmoType); |
|
2753 | 1462 |
{$IFNDEF IPHONEOS} |
2747 | 1463 |
var r: TSDL_Rect; |
1464 |
i: LongInt; |
|
1465 |
extra: string; |
|
1466 |
extracolor: LongInt; |
|
1467 |
begin |
|
1468 |
// don't do anything if the window shouldn't be shown |
|
1469 |
if not cWeaponTooltips then |
|
1470 |
begin |
|
1471 |
WeaponTooltipTex:= nil; |
|
1472 |
exit |
|
1473 |
end; |
|
1474 |
||
1475 |
// free old texture |
|
1476 |
FreeWeaponTooltip; |
|
1477 |
||
1478 |
// image region |
|
1479 |
i:= LongInt(atype) - 1; |
|
1480 |
r.x:= (i shr 5) * 32; |
|
1481 |
r.y:= (i mod 32) * 32; |
|
1482 |
r.w:= 32; |
|
1483 |
r.h:= 32; |
|
1484 |
||
1485 |
// default (no extra text) |
|
1486 |
extra:= ''; |
|
1487 |
extracolor:= 0; |
|
1488 |
||
1489 |
if (CurrentTeam <> nil) and (Ammoz[atype].SkipTurns >= CurrentTeam^.Clan^.TurnNumber) then // weapon or utility is not yet available |
|
1490 |
begin |
|
1491 |
extra:= trmsg[sidNotYetAvailable]; |
|
1492 |
extracolor:= LongInt($ffc77070); |
|
1493 |
end |
|
1494 |
else if (Ammoz[atype].Ammo.Propz and ammoprop_NoRoundEndHint) <> 0 then // weapon or utility won't end your turn |
|
1495 |
begin |
|
1496 |
extra:= trmsg[sidNoEndTurn]; |
|
1497 |
extracolor:= LongInt($ff70c770); |
|
1498 |
end |
|
1499 |
else |
|
1500 |
begin |
|
1501 |
extra:= ''; |
|
1502 |
extracolor:= 0; |
|
1503 |
end; |
|
1504 |
||
1505 |
// render window and return the texture |
|
1506 |
WeaponTooltipTex:= RenderHelpWindow(trammo[Ammoz[atype].NameId], trammoc[Ammoz[atype].NameId], trammod[Ammoz[atype].NameId], extra, extracolor, SpritesData[sprAMAmmos].Surface, @r) |
|
2753 | 1507 |
end; |
1508 |
{$ELSE} |
|
1509 |
begin end; |
|
2747 | 1510 |
{$ENDIF} |
1511 |
||
1512 |
procedure ShowWeaponTooltip(x, y: LongInt); |
|
1513 |
begin |
|
1514 |
{$IFNDEF IPHONEOS} |
|
1515 |
// draw the texture if it exists |
|
1516 |
if WeaponTooltipTex <> nil then |
|
1517 |
DrawTexture(x, y, WeaponTooltipTex) |
|
1518 |
{$ENDIF} |
|
1519 |
end; |
|
1520 |
||
1521 |
procedure FreeWeaponTooltip; |
|
1522 |
begin |
|
1523 |
{$IFNDEF IPHONEOS} |
|
1524 |
// free the existing texture (if there's any) |
|
1525 |
if WeaponTooltipTex = nil then |
|
1526 |
exit; |
|
1527 |
FreeTexture(WeaponTooltipTex); |
|
1528 |
WeaponTooltipTex:= nil |
|
1529 |
{$ENDIF} |
|
1530 |
end; |
|
1531 |
||
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1532 |
procedure init_uStore; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1533 |
begin |
2801 | 1534 |
PixelFormat:= nil; |
1535 |
SDLPrimSurface:= nil; |
|
1536 |
{$IFNDEF IPHONEOS}cGPUVendor:= gvUnknown;{$ENDIF} |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1537 |
|
2801 | 1538 |
cScaleFactor:= 2.0; |
1539 |
SupportNPOTT:= false; |
|
1540 |
Step:= 0; |
|
1541 |
ProgrTex:= nil; |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1542 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1543 |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1544 |
procedure free_uStore; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1545 |
begin |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1546 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1547 |
|
4 | 1548 |
end. |