author | nemo |
Thu, 07 Oct 2010 16:02:28 -0400 | |
changeset 3936 | 0b982d340633 |
parent 3922 | 44804043b691 |
child 3928 | 2560731c860d |
child 3938 | 033114a6a960 |
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 |
|
3407 | 23 |
uses sysutils, uConsts, uTeams, SDLh, GLunit; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
24 |
|
4 | 25 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
26 |
var PixelFormat: PSDL_PixelFormat; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
27 |
SDLPrimSurface: PSDL_Surface; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
28 |
PauseTexture, |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
29 |
SyncTexture, |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
30 |
ConfirmTexture: PTexture; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
31 |
cScaleFactor: GLfloat; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
32 |
SupportNPOTT: Boolean; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
33 |
Step: LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
34 |
squaresize : LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
35 |
numsquares : LongInt; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
36 |
ProgrTex: PTexture; |
2801 | 37 |
MissionIcons: PSDL_Surface; |
2811 | 38 |
ropeIconTex: PTexture; |
3394
47b51e22e670
Henek's patch - adds a column to ammoMenu and removes the F* column in iphone version
koda
parents:
3390
diff
changeset
|
39 |
rotationQt: GLfloat; |
3697 | 40 |
|
3038 | 41 |
procedure initModule; |
42 |
procedure freeModule; |
|
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
43 |
|
4 | 44 |
procedure StoreLoad; |
45 |
procedure StoreRelease; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
46 |
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
|
47 |
procedure DrawSprite (Sprite: TSprite; X, Y, Frame: LongInt); |
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
48 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
1939 | 49 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
3509
d72c2219595d
Make land types flagged (to allow stacking future attributes such as indestructible ice, but also for a damaged flag)
nemo
parents:
3491
diff
changeset
|
50 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat = 1.0); |
2811 | 51 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); |
52 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
|
822 | 53 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
853 | 54 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
822 | 55 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
762 | 56 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
2958 | 57 |
procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
58 |
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
|
59 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1431 | 60 |
procedure DrawFillRect(r: TSDL_Rect); |
2801 | 61 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
2905 | 62 |
function CheckCJKFont(s: ansistring; font: THWFont): THWFont; |
63 |
function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture; |
|
64 |
function RenderSpeechBubbleTex(s: ansistring; SpeechType: Longword; font: THWFont): PTexture; |
|
2017 | 65 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
66 |
//procedure rotateSurface(Surface: PSDL_Surface); |
|
67 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL |
|
3169
c8c6ac44f51b
prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents:
3165
diff
changeset
|
68 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); |
4 | 69 |
procedure RenderHealth(var Hedgehog: THedgehog); |
70 |
procedure AddProgress; |
|
510 | 71 |
procedure FinishProgress; |
2905 | 72 |
function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface; |
753 | 73 |
procedure SetupOpenGL; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
74 |
procedure SetScale(f: GLfloat); |
3394
47b51e22e670
Henek's patch - adds a column to ammoMenu and removes the F* column in iphone version
koda
parents:
3390
diff
changeset
|
75 |
function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture; |
2747 | 76 |
procedure RenderWeaponTooltip(atype: TAmmoType); |
77 |
procedure ShowWeaponTooltip(x, y: LongInt); |
|
78 |
procedure FreeWeaponTooltip; |
|
3376 | 79 |
procedure Tint(r, g, b, a: Byte); inline; |
3445 | 80 |
procedure Tint(c: Longword); inline; |
4 | 81 |
|
82 |
implementation |
|
3463 | 83 |
uses uMisc, uConsole, uLocale; |
4 | 84 |
|
2735 | 85 |
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
|
86 |
|
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
87 |
var HHTexture: PTexture; |
3169
c8c6ac44f51b
prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents:
3165
diff
changeset
|
88 |
MaxTextureSize: LongInt; |
2735 | 89 |
cGPUVendor: TGPUVendor; |
3376 | 90 |
lastTint: Longword; |
4 | 91 |
|
3376 | 92 |
procedure Tint(r, g, b, a: Byte); inline; |
93 |
var nc: Longword; |
|
94 |
begin |
|
95 |
nc:= (a shl 24) or (b shl 16) or (g shl 8) or r; |
|
96 |
if nc = lastTint then |
|
97 |
exit; |
|
98 |
glColor4ub(r, g, b, a); |
|
99 |
lastTint:= nc; |
|
100 |
end; |
|
101 |
||
3445 | 102 |
procedure Tint(c: Longword); inline; |
103 |
begin |
|
104 |
Tint(((c shr 16) and $FF), ((c shr 8) and $FF), (c and $FF), $FF); |
|
105 |
end; |
|
106 |
||
351 | 107 |
procedure DrawRoundRect(rect: PSDL_Rect; BorderColor, FillColor: Longword; Surface: PSDL_Surface; Clear: boolean); |
47 | 108 |
var r: TSDL_Rect; |
109 |
begin |
|
110 |
r:= rect^; |
|
83 | 111 |
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
|
112 |
|
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
113 |
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
|
114 |
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
|
115 |
|
351 | 116 |
r.y:= rect^.y + 1; |
117 |
r.h:= rect^.h - 2; |
|
47 | 118 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 119 |
r.x:= rect^.x + 1; |
120 |
r.w:= rect^.w - 2; |
|
121 |
r.y:= rect^.y; |
|
122 |
r.h:= rect^.h; |
|
47 | 123 |
SDL_FillRect(Surface, @r, BorderColor); |
351 | 124 |
r.x:= rect^.x + 2; |
125 |
r.y:= rect^.y + 1; |
|
126 |
r.w:= rect^.w - 4; |
|
127 |
r.h:= rect^.h - 2; |
|
47 | 128 |
SDL_FillRect(Surface, @r, FillColor); |
351 | 129 |
r.x:= rect^.x + 1; |
130 |
r.y:= rect^.y + 2; |
|
131 |
r.w:= rect^.w - 2; |
|
132 |
r.h:= rect^.h - 4; |
|
47 | 133 |
SDL_FillRect(Surface, @r, FillColor) |
134 |
end; |
|
135 |
||
2905 | 136 |
function WriteInRoundRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect; |
351 | 137 |
var w, h: LongInt; |
4 | 138 |
tmpsurf: PSDL_Surface; |
139 |
clr: TSDL_Color; |
|
2695 | 140 |
finalRect: TSDL_Rect; |
4 | 141 |
begin |
3407 | 142 |
w:= 0; h:= 0; // avoid compiler hints |
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
|
143 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
2695 | 144 |
finalRect.x:= X; |
145 |
finalRect.y:= Y; |
|
146 |
finalRect.w:= w + FontBorder * 2 + 4; |
|
147 |
finalRect.h:= h + FontBorder * 2; |
|
148 |
DrawRoundRect(@finalRect, cWhiteColor, endian(cNearBlackColorChannels.value), Surface, true); |
|
2670 | 149 |
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
|
150 |
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
|
151 |
clr.b:= Color and $FF; |
2665
50b4e544c163
complete transition of longword->sdl_color for TTF bindings
koda
parents:
2663
diff
changeset
|
152 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr); |
2695 | 153 |
finalRect.x:= X + FontBorder + 2; |
154 |
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
|
155 |
SDLTry(tmpsurf <> nil, true); |
2695 | 156 |
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
|
157 |
SDL_FreeSurface(tmpsurf); |
2695 | 158 |
finalRect.x:= X; |
159 |
finalRect.y:= Y; |
|
160 |
finalRect.w:= w + FontBorder * 2 + 4; |
|
161 |
finalRect.h:= h + FontBorder * 2; |
|
162 |
WriteInRoundRect:= finalRect; |
|
4 | 163 |
end; |
164 |
||
2905 | 165 |
function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect; |
2747 | 166 |
var w, h: LongInt; |
167 |
tmpsurf: PSDL_Surface; |
|
168 |
clr: TSDL_Color; |
|
169 |
finalRect: TSDL_Rect; |
|
170 |
begin |
|
3407 | 171 |
w:= 0; h:= 0; // avoid compiler hints |
2747 | 172 |
TTF_SizeUTF8(Fontz[Font].Handle, Str2PChar(s), w, h); |
173 |
finalRect.x:= X + FontBorder + 2; |
|
174 |
finalRect.y:= Y + FontBorder; |
|
175 |
finalRect.w:= w + FontBorder * 2 + 4; |
|
176 |
finalRect.h:= h + FontBorder * 2; |
|
177 |
clr.r:= Color shr 16; |
|
178 |
clr.g:= (Color shr 8) and $FF; |
|
179 |
clr.b:= Color and $FF; |
|
180 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, Str2PChar(s), clr); |
|
181 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
|
182 |
SDLTry(tmpsurf <> nil, true); |
|
183 |
SDL_UpperBlit(tmpsurf, nil, Surface, @finalRect); |
|
184 |
SDL_FreeSurface(tmpsurf); |
|
185 |
finalRect.x:= X; |
|
186 |
finalRect.y:= Y; |
|
187 |
finalRect.w:= w + FontBorder * 2 + 4; |
|
188 |
finalRect.h:= h + FontBorder * 2; |
|
189 |
WriteInRect:= finalRect |
|
190 |
end; |
|
191 |
||
4 | 192 |
procedure StoreLoad; |
2905 | 193 |
var s: shortstring; |
4 | 194 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
195 |
procedure WriteNames(Font: THWFont); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
196 |
var t: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
197 |
i: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
198 |
r, rr: TSDL_Rect; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
199 |
drY: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
200 |
texsurf, flagsurf, iconsurf: PSDL_Surface; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
201 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
202 |
r.x:= 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
203 |
r.y:= 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
204 |
drY:= - 4; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
205 |
for t:= 0 to Pred(TeamsCount) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
206 |
with TeamsArray[t]^ do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
207 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
208 |
NameTagTex:= RenderStringTex(TeamName, Clan^.Color, Font); |
690 | 209 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
210 |
r.w:= cTeamHealthWidth + 5; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
211 |
r.h:= NameTagTex^.h; |
690 | 212 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
213 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
214 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
215 |
TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
690 | 216 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
217 |
DrawRoundRect(@r, cWhiteColor, cNearBlackColorChannels.value, texsurf, true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
218 |
rr:= r; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
219 |
inc(rr.x, 2); dec(rr.w, 4); inc(rr.y, 2); dec(rr.h, 4); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
220 |
DrawRoundRect(@rr, Clan^.Color, Clan^.Color, texsurf, false); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
221 |
HealthTex:= Surface2Tex(texsurf, false); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
222 |
SDL_FreeSurface(texsurf); |
690 | 223 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
224 |
r.x:= 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
225 |
r.y:= 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
226 |
r.w:= 32; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
227 |
r.h:= 32; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
228 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, r.w, r.h, 32, RMask, GMask, BMask, AMask); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
229 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
230 |
TryDo(SDL_SetColorKey(texsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
2747 | 231 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
232 |
r.w:= 26; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
233 |
r.h:= 19; |
2747 | 234 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
235 |
DrawRoundRect(@r, cWhiteColor, cNearBlackColor, texsurf, true); |
3697 | 236 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
237 |
// overwrite flag for cpu teams and keep players from using it |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
238 |
if (Hedgehogs[0].Gear <> nil) and (Hedgehogs[0].BotLevel > 0) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
239 |
Flag:= 'cpu' |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
240 |
else if Flag = 'cpu' then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
241 |
Flag:= 'hedgewars'; |
3697 | 242 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
243 |
flagsurf:= LoadImage(Pathz[ptFlags] + '/' + Flag, ifNone); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
244 |
if flagsurf = nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
245 |
flagsurf:= LoadImage(Pathz[ptFlags] + '/hedgewars', ifNone); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
246 |
TryDo(flagsurf <> nil, 'Failed to load flag "' + Flag + '" as well as the default flag', true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
247 |
copyToXY(flagsurf, texsurf, 2, 2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
248 |
SDL_FreeSurface(flagsurf); |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3509
diff
changeset
|
249 |
flagsurf:= nil; |
3697 | 250 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
251 |
// restore black border pixels inside the flag |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
252 |
PLongwordArray(texsurf^.pixels)^[32 * 2 + 2]:= cNearBlackColor; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
253 |
PLongwordArray(texsurf^.pixels)^[32 * 2 + 23]:= cNearBlackColor; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
254 |
PLongwordArray(texsurf^.pixels)^[32 * 16 + 2]:= cNearBlackColor; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
255 |
PLongwordArray(texsurf^.pixels)^[32 * 16 + 23]:= cNearBlackColor; |
2747 | 256 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
257 |
FlagTex:= Surface2Tex(texsurf, false); |
3041 | 258 |
SDL_FreeSurface(texsurf); |
259 |
||
3773 | 260 |
AIKillsTex := RenderStringTex(inttostr(stats.AIKills), Clan^.Color, fnt16); |
261 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
262 |
dec(drY, r.h + 2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
263 |
DrawHealthY:= drY; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
264 |
for i:= 0 to 7 do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
265 |
with Hedgehogs[i] do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
266 |
if Gear <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
267 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
268 |
NameTagTex:= RenderStringTex(Name, Clan^.Color, CheckCJKFont(Name,fnt16)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
269 |
if Hat <> 'NoHat' then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
270 |
begin |
2874
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2873
diff
changeset
|
271 |
if (Length(Hat) > 39) and (Copy(Hat,1,8) = 'Reserved') and (Copy(Hat,9,32) = PlayerHash) then |
3041 | 272 |
texsurf:= LoadImage(Pathz[ptHats] + '/Reserved/' + Copy(Hat,9,Length(s)-8), ifNone) |
2874
3c7c2bf1ba38
A simple hat reservation mechanism. Can be worked around with a little effort, but to make it useful, you'd have to get everyone you played with to work around it too. Quite a bit of effort for a small reward feature.
nemo
parents:
2873
diff
changeset
|
273 |
else |
3041 | 274 |
texsurf:= LoadImage(Pathz[ptHats] + '/' + Hat, ifNone); |
3862 | 275 |
if texsurf <> nil then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
276 |
begin |
3862 | 277 |
HatTex:= Surface2Tex(texsurf, true); |
278 |
SDL_FreeSurface(texsurf) |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3509
diff
changeset
|
279 |
end; |
3862 | 280 |
texsurf:= nil; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
281 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
282 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
283 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
284 |
MissionIcons:= LoadImage(Pathz[ptGraphics] + '/missions', ifCritical); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
285 |
iconsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, 28, 28, 32, RMask, GMask, BMask, AMask); |
3862 | 286 |
if iconsurf <> nil then |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
287 |
begin |
3862 | 288 |
r.x:= 0; |
289 |
r.y:= 0; |
|
290 |
r.w:= 28; |
|
291 |
r.h:= 28; |
|
292 |
DrawRoundRect(@r, cWhiteColor, cNearBlackColor, iconsurf, true); |
|
293 |
ropeIconTex:= Surface2Tex(iconsurf, false); |
|
294 |
SDL_FreeSurface(iconsurf); |
|
295 |
iconsurf:= nil; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
296 |
end; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
297 |
end; |
4 | 298 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
299 |
procedure MakeCrossHairs; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
300 |
var t: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
301 |
tmpsurf, texsurf: PSDL_Surface; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
302 |
Color, i: Longword; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
303 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
304 |
s:= Pathz[ptGraphics] + '/' + cCHFileName; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
305 |
tmpsurf:= LoadImage(s, ifAlpha or ifCritical); |
4 | 306 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
307 |
for t:= 0 to Pred(TeamsCount) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
308 |
with TeamsArray[t]^ do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
309 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
310 |
texsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, tmpsurf^.w, tmpsurf^.h, 32, RMask, GMask, BMask, AMask); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
311 |
TryDo(texsurf <> nil, errmsgCreateSurface, true); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
312 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
313 |
Color:= Clan^.Color; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
314 |
Color:= SDL_MapRGB(texsurf^.format, Color shr 16, Color shr 8, Color and $FF); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
315 |
SDL_FillRect(texsurf, nil, Color); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
316 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
317 |
SDL_UpperBlit(tmpsurf, nil, texsurf, nil); |
777 | 318 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
319 |
TryDo(tmpsurf^.format^.BytesPerPixel = 4, 'Ooops', true); |
777 | 320 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
321 |
if SDL_MustLock(texsurf) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
322 |
SDLTry(SDL_LockSurface(texsurf) >= 0, true); |
777 | 323 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
324 |
// make black pixel be alpha-transparent |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
325 |
for i:= 0 to texsurf^.w * texsurf^.h - 1 do |
3862 | 326 |
if PLongwordArray(texsurf^.pixels)^[i] = AMask then PLongwordArray(texsurf^.pixels)^[i]:= (RMask or GMask or BMask) and Color; |
777 | 327 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
328 |
if SDL_MustLock(texsurf) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
329 |
SDL_UnlockSurface(texsurf); |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
330 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
331 |
CrosshairTex:= Surface2Tex(texsurf, false); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
332 |
SDL_FreeSurface(texsurf) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
333 |
end; |
351 | 334 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
335 |
SDL_FreeSurface(tmpsurf) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
336 |
end; |
4 | 337 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
338 |
procedure InitHealth; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
339 |
var i, t: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
340 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
341 |
for t:= 0 to Pred(TeamsCount) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
342 |
if TeamsArray[t] <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
343 |
with TeamsArray[t]^ do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
344 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
345 |
for i:= 0 to cMaxHHIndex do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
346 |
if Hedgehogs[i].Gear <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
347 |
RenderHealth(Hedgehogs[i]); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
348 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
349 |
end; |
4 | 350 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
351 |
procedure LoadGraves; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
352 |
var t: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
353 |
texsurf: PSDL_Surface; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
354 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
355 |
for t:= 0 to Pred(TeamsCount) do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
356 |
if TeamsArray[t] <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
357 |
with TeamsArray[t]^ do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
358 |
begin |
3689 | 359 |
if GraveName = '' then GraveName:= 'Statue'; |
360 |
texsurf:= LoadImage(Pathz[ptGraves] + '/' + GraveName, ifTransparent); |
|
361 |
if texsurf = nil then texsurf:= LoadImage(Pathz[ptGraves] + '/Statue', ifCritical or ifTransparent); |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
362 |
GraveTex:= Surface2Tex(texsurf, false); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
363 |
SDL_FreeSurface(texsurf) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
364 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
365 |
end; |
4 | 366 |
|
844 | 367 |
var ii: TSprite; |
368 |
fi: THWFont; |
|
369 |
ai: TAmmoType; |
|
370 |
tmpsurf: PSDL_Surface; |
|
371 |
i: LongInt; |
|
4 | 372 |
begin |
2222 | 373 |
|
4 | 374 |
for fi:= Low(THWFont) to High(THWFont) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
375 |
with Fontz[fi] do |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
376 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
377 |
s:= Pathz[ptFonts] + '/' + Name; |
3185 | 378 |
WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... '); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
379 |
Handle:= TTF_OpenFont(Str2PChar(s), Height); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
380 |
SDLTry(Handle <> nil, true); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
381 |
TTF_SetFontStyle(Handle, style); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
382 |
WriteLnToConsole(msgOK) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
383 |
end; |
53 | 384 |
|
4 | 385 |
WriteNames(fnt16); |
70 | 386 |
MakeCrossHairs; |
4 | 387 |
LoadGraves; |
388 |
||
389 |
AddProgress; |
|
390 |
for ii:= Low(TSprite) to High(TSprite) do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
391 |
with SpritesData[ii] do |
2145 | 392 |
// FIXME - add a sprite attribute |
3594
aeca3d8f1b29
turn cReducedQuality into a LongInt and provide a series of quality flags (and best of all, this is still compatible with current frontend)
koda
parents:
3558
diff
changeset
|
393 |
if ((cReducedQuality and rqNoBackground) = 0) or (not (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR, sprFlake, sprSplash, sprDroplet])) then // FIXME: hack |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
394 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
395 |
if AltPath = ptNone then |
3881
e570268a9d52
re-add City theme with the UpdateDataFolder script (and revert changes made to the flake sprite)
koda
parents:
3875
diff
changeset
|
396 |
if ii in [sprHorizontL, sprHorizontR, sprSkyL, sprSkyR] then // FIXME: hack |
3537
8f5b3108f29c
New approach to the low-res problem. Basically, we already have a 1024 minimum, and the tallest maps are restricting themselves to 2048 maximum. All backgrounds are scaled down 50%, then scaled up on draw. Saves memory, and backgrounds are already deliberately fuzzed for depth of field anyway.
nemo
parents:
3525
diff
changeset
|
397 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
398 |
else |
3537
8f5b3108f29c
New approach to the low-res problem. Basically, we already have a 1024 minimum, and the tallest maps are restricting themselves to 2048 maximum. All backgrounds are scaled down 50%, then scaled up on draw. Saves memory, and backgrounds are already deliberately fuzzed for depth of field anyway.
nemo
parents:
3525
diff
changeset
|
399 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent or ifCritical) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
400 |
else begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
401 |
tmpsurf:= LoadImage(Pathz[Path] + '/' + FileName, ifAlpha or ifTransparent); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
402 |
if tmpsurf = nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
403 |
tmpsurf:= LoadImage(Pathz[AltPath] + '/' + FileName, ifAlpha or ifCritical or ifTransparent); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
404 |
end; |
2426 | 405 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
406 |
if tmpsurf <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
407 |
begin |
3558 | 408 |
if getImageDimensions then |
3765
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3764
diff
changeset
|
409 |
begin |
3558 | 410 |
imageWidth:= tmpsurf^.w; |
411 |
imageHeight:= tmpsurf^.h |
|
3765
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3764
diff
changeset
|
412 |
end; |
3558 | 413 |
if getDimensions then |
3765
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3764
diff
changeset
|
414 |
begin |
3558 | 415 |
Width:= tmpsurf^.w; |
416 |
Height:= tmpsurf^.h |
|
3765
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3764
diff
changeset
|
417 |
end; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
418 |
if (ii in [sprSky, sprSkyL, sprSkyR, sprHorizont, sprHorizontL, sprHorizontR]) then |
3765
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3764
diff
changeset
|
419 |
begin |
3537
8f5b3108f29c
New approach to the low-res problem. Basically, we already have a 1024 minimum, and the tallest maps are restricting themselves to 2048 maximum. All backgrounds are scaled down 50%, then scaled up on draw. Saves memory, and backgrounds are already deliberately fuzzed for depth of field anyway.
nemo
parents:
3525
diff
changeset
|
420 |
Texture:= Surface2Tex(tmpsurf, true); |
8f5b3108f29c
New approach to the low-res problem. Basically, we already have a 1024 minimum, and the tallest maps are restricting themselves to 2048 maximum. All backgrounds are scaled down 50%, then scaled up on draw. Saves memory, and backgrounds are already deliberately fuzzed for depth of field anyway.
nemo
parents:
3525
diff
changeset
|
421 |
Texture^.Scale:= 2 |
3765
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3764
diff
changeset
|
422 |
end |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
423 |
else |
3765
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3764
diff
changeset
|
424 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
425 |
Texture:= Surface2Tex(tmpsurf, false); |
3611 | 426 |
if (ii = sprWater) and ((cReducedQuality and (rq2DWater or rqClampLess)) = 0) then // HACK: We should include some sprite attribute to define the texture wrap directions |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
427 |
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
428 |
end; |
3491 | 429 |
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, priority); |
3765
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3764
diff
changeset
|
430 |
if saveSurf then |
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3764
diff
changeset
|
431 |
Surface:= tmpsurf else SDL_FreeSurface(tmpsurf) |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
432 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
433 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
434 |
Surface:= nil |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
435 |
end; |
80 | 436 |
|
4 | 437 |
AddProgress; |
567 | 438 |
|
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
|
439 |
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
|
440 |
HHTexture:= Surface2Tex(tmpsurf, false); |
761 | 441 |
SDL_FreeSurface(tmpsurf); |
4 | 442 |
|
443 |
InitHealth; |
|
444 |
||
3774 | 445 |
// TODO: are those textures ever freed? |
2623 | 446 |
PauseTexture:= RenderStringTex(trmsg[sidPaused], cYellowColor, fntBig); |
447 |
ConfirmTexture:= RenderStringTex(trmsg[sidConfirm], cYellowColor, fntBig); |
|
448 |
SyncTexture:= RenderStringTex(trmsg[sidSync], cYellowColor, fntBig); |
|
281
5b483aa9f2ab
Pause support (mouse cursor is released when the game is paused)
unc0rr
parents:
208
diff
changeset
|
449 |
|
2601 | 450 |
AddProgress; |
451 |
||
2670 | 452 |
// name of weapons in ammo menu |
843 | 453 |
for ai:= Low(TAmmoType) to High(TAmmoType) do |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
454 |
with Ammoz[ai] do |
3765
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3764
diff
changeset
|
455 |
begin |
3384 | 456 |
TryDo(trAmmo[NameId] <> '','No default text/translation found for ammo type #' + intToStr(ord(ai)) + '!',true); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
457 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[CheckCJKFont(trAmmo[NameId],fnt16)].Handle, Str2PChar(trAmmo[NameId]), cWhiteColorChannels); |
3384 | 458 |
TryDo(tmpsurf <> nil,'Name-texture creation for ammo type #' + intToStr(ord(ai)) + ' failed!',true); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
459 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
460 |
NameTex:= Surface2Tex(tmpsurf, false); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
461 |
SDL_FreeSurface(tmpsurf) |
3765
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3764
diff
changeset
|
462 |
end; |
2376 | 463 |
|
2670 | 464 |
// number of weapons in ammo menu |
844 | 465 |
for i:= Low(CountTexz) to High(CountTexz) do |
3765
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3764
diff
changeset
|
466 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
467 |
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[fnt16].Handle, Str2PChar(IntToStr(i) + 'x'), cWhiteColorChannels); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
468 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
469 |
CountTexz[i]:= Surface2Tex(tmpsurf, false); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
470 |
SDL_FreeSurface(tmpsurf) |
3765
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3764
diff
changeset
|
471 |
end; |
844 | 472 |
|
2222 | 473 |
AddProgress; |
2669 | 474 |
|
2672 | 475 |
{$IFDEF SDL_IMAGE_NEWER} |
2669 | 476 |
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
|
477 |
{$ENDIF} |
4 | 478 |
end; |
479 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
480 |
procedure DrawFromRect(X, Y: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
2958 | 481 |
begin |
482 |
DrawFromRect(X, Y, r^.w, r^.h, r, SourceTexture) |
|
483 |
end; |
|
484 |
||
485 |
procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture); |
|
4 | 486 |
var rr: TSDL_Rect; |
764
7513452b1d51
Now game looks almost like it did before switching to OpenGL
unc0rr
parents:
762
diff
changeset
|
487 |
_l, _r, _t, _b: real; |
1916 | 488 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
4 | 489 |
begin |
3881
e570268a9d52
re-add City theme with the UpdateDataFolder script (and revert changes made to the flake sprite)
koda
parents:
3875
diff
changeset
|
490 |
if (SourceTexture^.h = 0) or (SourceTexture^.w = 0) then exit; |
3764 | 491 |
|
492 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
|
493 |
if (abs(X) > W) and ((abs(X + W / 2) - W / 2) > cScreenWidth / cScaleFactor) then |
|
494 |
exit; |
|
495 |
if (abs(Y) > H) and ((abs(Y + H / 2 - (0.5 * cScreenHeight)) - H / 2) > cScreenHeight / cScaleFactor) then |
|
496 |
exit; |
|
497 |
||
4 | 498 |
rr.x:= X; |
499 |
rr.y:= Y; |
|
2958 | 500 |
rr.w:= W; |
501 |
rr.h:= H; |
|
755 | 502 |
|
1896 | 503 |
_l:= r^.x / SourceTexture^.w * SourceTexture^.rx; |
504 |
_r:= (r^.x + r^.w) / SourceTexture^.w * SourceTexture^.rx; |
|
505 |
_t:= r^.y / SourceTexture^.h * SourceTexture^.ry; |
|
506 |
_b:= (r^.y + r^.h) / SourceTexture^.h * SourceTexture^.ry; |
|
755 | 507 |
|
508 |
glBindTexture(GL_TEXTURE_2D, SourceTexture^.id); |
|
509 |
||
1916 | 510 |
VertexBuffer[0].X:= X; |
511 |
VertexBuffer[0].Y:= Y; |
|
512 |
VertexBuffer[1].X:= rr.w + X; |
|
513 |
VertexBuffer[1].Y:= Y; |
|
514 |
VertexBuffer[2].X:= rr.w + X; |
|
515 |
VertexBuffer[2].Y:= rr.h + Y; |
|
516 |
VertexBuffer[3].X:= X; |
|
517 |
VertexBuffer[3].Y:= rr.h + Y; |
|
755 | 518 |
|
1916 | 519 |
TextureBuffer[0].X:= _l; |
520 |
TextureBuffer[0].Y:= _t; |
|
521 |
TextureBuffer[1].X:= _r; |
|
522 |
TextureBuffer[1].Y:= _t; |
|
523 |
TextureBuffer[2].X:= _r; |
|
524 |
TextureBuffer[2].Y:= _b; |
|
525 |
TextureBuffer[3].X:= _l; |
|
526 |
TextureBuffer[3].Y:= _b; |
|
755 | 527 |
|
528 |
||
1916 | 529 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
530 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
531 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
762 | 532 |
end; |
533 |
||
3509
d72c2219595d
Make land types flagged (to allow stacking future attributes such as indestructible ice, but also for a damaged flag)
nemo
parents:
3491
diff
changeset
|
534 |
procedure DrawTexture(X, Y: LongInt; Texture: PTexture; Scale: GLfloat); |
762 | 535 |
begin |
3764 | 536 |
|
1904 | 537 |
glPushMatrix; |
538 |
glTranslatef(X, Y, 0); |
|
3509
d72c2219595d
Make land types flagged (to allow stacking future attributes such as indestructible ice, but also for a damaged flag)
nemo
parents:
3491
diff
changeset
|
539 |
glScalef(Scale, Scale, 1); |
1904 | 540 |
|
762 | 541 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
542 |
||
1912
c3d31fb59f0e
Save much CPU time by initializing vertex arrays in texture creation function
unc0rr
parents:
1908
diff
changeset
|
543 |
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
|
544 |
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
|
545 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(Texture^.vb)); |
1904 | 546 |
|
547 |
glPopMatrix |
|
4 | 548 |
end; |
549 |
||
2811 | 550 |
procedure DrawTextureF(Texture: PTexture; Scale: GLfloat; X, Y, Frame, Dir, w, h: LongInt); |
1242 | 551 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
552 |
DrawRotatedTextureF(Texture, Scale, 0, 0, X, Y, Frame, Dir, w, h, 0) |
2597 | 553 |
end; |
554 |
||
2811 | 555 |
procedure DrawRotatedTextureF(Texture: PTexture; Scale, OffsetX, OffsetY: GLfloat; X, Y, Frame, Dir, w, h: LongInt; Angle: real); |
556 |
var ft, fb, fl, fr: GLfloat; |
|
557 |
hw, nx, ny: LongInt; |
|
2597 | 558 |
VertexBuffer, TextureBuffer: array [0..3] of TVertex2f; |
559 |
begin |
|
3764 | 560 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
561 |
if (abs(X) > W) and ((abs(X + dir * OffsetX) - W / 2) > cScreenWidth / cScaleFactor) then |
|
562 |
exit; |
|
563 |
if (abs(Y) > H) and ((abs(Y + OffsetY - (0.5 * cScreenHeight)) - W / 2) > cScreenHeight / cScaleFactor) then |
|
564 |
exit; |
|
565 |
||
2597 | 566 |
glPushMatrix; |
567 |
glTranslatef(X, Y, 0); |
|
568 |
||
569 |
if Dir < 0 then |
|
570 |
glRotatef(Angle, 0, 0, -1) |
|
571 |
else |
|
572 |
glRotatef(Angle, 0, 0, 1); |
|
573 |
||
574 |
glTranslatef(Dir*OffsetX, OffsetY, 0); |
|
2811 | 575 |
glScalef(Scale, Scale, 1); |
576 |
||
3376 | 577 |
// Any reason for this call? And why only in t direction, not s? |
578 |
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); |
|
1242 | 579 |
|
580 |
if Dir < 0 then |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
581 |
hw:= w div -2 |
1242 | 582 |
else |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
583 |
hw:= w div 2; |
2811 | 584 |
|
2910 | 585 |
nx:= round(Texture^.w / w); // number of horizontal frames |
586 |
ny:= round(Texture^.h / h); // number of vertical frames |
|
1242 | 587 |
|
2910 | 588 |
ft:= (Frame mod ny) * Texture^.ry / ny; |
589 |
fb:= ((Frame mod ny) + 1) * Texture^.ry / ny; |
|
590 |
fl:= (Frame div ny) * Texture^.rx / nx; |
|
591 |
fr:= ((Frame div ny) + 1) * Texture^.rx / nx; |
|
1242 | 592 |
|
593 |
glBindTexture(GL_TEXTURE_2D, Texture^.id); |
|
594 |
||
1916 | 595 |
VertexBuffer[0].X:= -hw; |
2811 | 596 |
VertexBuffer[0].Y:= w / -2; |
1916 | 597 |
VertexBuffer[1].X:= hw; |
2811 | 598 |
VertexBuffer[1].Y:= w / -2; |
1916 | 599 |
VertexBuffer[2].X:= hw; |
2811 | 600 |
VertexBuffer[2].Y:= w / 2; |
1916 | 601 |
VertexBuffer[3].X:= -hw; |
2811 | 602 |
VertexBuffer[3].Y:= w / 2; |
1242 | 603 |
|
2811 | 604 |
TextureBuffer[0].X:= fl; |
1916 | 605 |
TextureBuffer[0].Y:= ft; |
2811 | 606 |
TextureBuffer[1].X:= fr; |
1916 | 607 |
TextureBuffer[1].Y:= ft; |
2811 | 608 |
TextureBuffer[2].X:= fr; |
1916 | 609 |
TextureBuffer[2].Y:= fb; |
2811 | 610 |
TextureBuffer[3].X:= fl; |
1916 | 611 |
TextureBuffer[3].Y:= fb; |
1242 | 612 |
|
1916 | 613 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
614 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
615 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
616 |
||
1242 | 617 |
glPopMatrix |
618 |
end; |
|
619 |
||
822 | 620 |
procedure DrawRotated(Sprite: TSprite; X, Y, Dir: LongInt; Angle: real); |
775 | 621 |
begin |
3405 | 622 |
DrawRotatedTex(SpritesData[Sprite].Texture, |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
623 |
SpritesData[Sprite].Width, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
624 |
SpritesData[Sprite].Height, |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
625 |
X, Y, Dir, Angle) |
777 | 626 |
end; |
627 |
||
853 | 628 |
procedure DrawRotatedF(Sprite: TSprite; X, Y, Frame, Dir: LongInt; Angle: real); |
806 | 629 |
begin |
630 |
glPushMatrix; |
|
809 | 631 |
glTranslatef(X, Y, 0); |
806 | 632 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
633 |
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
|
634 |
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
|
635 |
else |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
636 |
glRotatef(Angle, 0, 0, 1); |
853 | 637 |
if Dir < 0 then glScalef(-1.0, 1.0, 1.0); |
638 |
||
639 |
DrawSprite(Sprite, -SpritesData[Sprite].Width div 2, -SpritesData[Sprite].Height div 2, Frame); |
|
806 | 640 |
|
641 |
glPopMatrix |
|
642 |
end; |
|
643 |
||
822 | 644 |
procedure DrawRotatedTex(Tex: PTexture; hw, hh, X, Y, Dir: LongInt; Angle: real); |
1916 | 645 |
var VertexBuffer: array [0..3] of TVertex2f; |
777 | 646 |
begin |
3764 | 647 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
648 |
if (abs(X) > 2 * hw) and ((abs(X) - hw) > cScreenWidth / cScaleFactor) then |
|
649 |
exit; |
|
650 |
if (abs(Y) > 2 * hh) and ((abs(Y - 0.5 * cScreenHeight) - hh) > cScreenHeight / cScaleFactor) then |
|
651 |
exit; |
|
652 |
||
775 | 653 |
glPushMatrix; |
654 |
glTranslatef(X, Y, 0); |
|
822 | 655 |
|
656 |
if Dir < 0 then |
|
657 |
begin |
|
658 |
hw:= - hw; |
|
659 |
glRotatef(Angle, 0, 0, -1); |
|
660 |
end else |
|
661 |
glRotatef(Angle, 0, 0, 1); |
|
662 |
||
775 | 663 |
|
777 | 664 |
glBindTexture(GL_TEXTURE_2D, Tex^.id); |
775 | 665 |
|
1916 | 666 |
VertexBuffer[0].X:= -hw; |
667 |
VertexBuffer[0].Y:= -hh; |
|
668 |
VertexBuffer[1].X:= hw; |
|
669 |
VertexBuffer[1].Y:= -hh; |
|
670 |
VertexBuffer[2].X:= hw; |
|
671 |
VertexBuffer[2].Y:= hh; |
|
672 |
VertexBuffer[3].X:= -hw; |
|
673 |
VertexBuffer[3].Y:= hh; |
|
775 | 674 |
|
1916 | 675 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
676 |
glTexCoordPointer(2, GL_FLOAT, 0, @Tex^.tb); |
|
677 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
775 | 678 |
|
679 |
glPopMatrix |
|
680 |
end; |
|
681 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
682 |
procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt); |
4 | 683 |
begin |
684 |
r.y:= r.y + Height * Position; |
|
685 |
r.h:= Height; |
|
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
686 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
4 | 687 |
end; |
688 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
689 |
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
|
690 |
var row, col, numFramesFirstCol: LongInt; |
4 | 691 |
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
|
692 |
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
|
693 |
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
|
694 |
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
|
695 |
DrawSprite2 (Sprite, X, Y, col, row); |
4 | 696 |
end; |
697 |
||
1939 | 698 |
procedure DrawSpriteClipped(Sprite: TSprite; X, Y, TopY, RightX, BottomY, LeftX: LongInt); |
699 |
var r: TSDL_Rect; |
|
700 |
begin |
|
701 |
r.x:= 0; |
|
702 |
r.y:= 0; |
|
703 |
r.w:= SpritesData[Sprite].Width; |
|
704 |
r.h:= SpritesData[Sprite].Height; |
|
705 |
||
706 |
if (X < LeftX) then |
|
707 |
r.x:= LeftX - X; |
|
708 |
if (Y < TopY) then |
|
709 |
r.y:= TopY - Y; |
|
710 |
||
711 |
if (Y + SpritesData[Sprite].Height > BottomY) then |
|
712 |
r.h:= BottomY - Y + 1; |
|
713 |
if (X + SpritesData[Sprite].Width > RightX) then |
|
714 |
r.w:= RightX - X + 1; |
|
715 |
||
716 |
dec(r.h, r.y); |
|
717 |
dec(r.w, r.x); |
|
2230
d6963f72d21a
once again, trying to restore windows compatibility from nemo's experiments
koda
parents:
2229
diff
changeset
|
718 |
|
1939 | 719 |
DrawFromRect(X + r.x, Y + r.y, @r, SpritesData[Sprite].Texture) |
720 |
end; |
|
721 |
||
841
0700e3d3474d
Get rid if deprecated Surface parameter of Draw* calls
unc0rr
parents:
840
diff
changeset
|
722 |
procedure DrawSprite2(Sprite: TSprite; X, Y, FrameX, FrameY: LongInt); |
43 | 723 |
var r: TSDL_Rect; |
724 |
begin |
|
3405 | 725 |
r.x:= FrameX * SpritesData[Sprite].Width; |
726 |
r.w:= SpritesData[Sprite].Width; |
|
727 |
r.y:= FrameY * SpritesData[Sprite].Height; |
|
728 |
r.h:= SpritesData[Sprite].Height; |
|
729 |
DrawFromRect(X, Y, @r, SpritesData[Sprite].Texture) |
|
43 | 730 |
end; |
731 |
||
762 | 732 |
procedure DrawCentered(X, Top: LongInt; Source: PTexture); |
3895
e7c202c08ac1
compilation bugfix and scaling down textures when bigger than screen
koda
parents:
3881
diff
changeset
|
733 |
var scale: GLfloat; |
95 | 734 |
begin |
3895
e7c202c08ac1
compilation bugfix and scaling down textures when bigger than screen
koda
parents:
3881
diff
changeset
|
735 |
if (Source^.w + 20) > cScreenWidth then |
e7c202c08ac1
compilation bugfix and scaling down textures when bigger than screen
koda
parents:
3881
diff
changeset
|
736 |
scale:= cScreenWidth / (Source^.w + 20) |
e7c202c08ac1
compilation bugfix and scaling down textures when bigger than screen
koda
parents:
3881
diff
changeset
|
737 |
else |
e7c202c08ac1
compilation bugfix and scaling down textures when bigger than screen
koda
parents:
3881
diff
changeset
|
738 |
scale:= 1.0; |
3897
27e115fa1143
captions are scaled down when they're bigger than screen
koda
parents:
3895
diff
changeset
|
739 |
DrawTexture(X - round(Source^.w * scale) div 2, Top, Source, scale) |
4 | 740 |
end; |
741 |
||
1865
ebc6dfca60d4
- nemo's patch: some animations, zero probability for infinite weapons
unc0rr
parents:
1854
diff
changeset
|
742 |
procedure DrawHedgehog(X, Y: LongInt; Dir: LongInt; Pos, Step: LongWord; Angle: real); |
1916 | 743 |
const VertexBuffer: array [0..3] of TVertex2f = ( |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
744 |
(x: -16; y: -16), |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
745 |
(x: 16; y: -16), |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
746 |
(x: 16; y: 16), |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
747 |
(x: -16; y: 16)); |
761 | 748 |
var l, r, t, b: real; |
1916 | 749 |
TextureBuffer: array [0..3] of TVertex2f; |
4 | 750 |
begin |
3764 | 751 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
752 |
if (abs(X) > 32) and ((abs(X) - 16)> cScreenWidth / cScaleFactor) then |
|
753 |
exit; |
|
754 |
if (abs(Y) > 32) and ((abs(Y - 0.5 * cScreenHeight) - 16) > cScreenHeight / cScaleFactor) then |
|
755 |
exit; |
|
761 | 756 |
|
757 |
t:= Pos * 32 / HHTexture^.h; |
|
758 |
b:= (Pos + 1) * 32 / HHTexture^.h; |
|
759 |
||
760 |
if Dir = -1 then |
|
761 |
begin |
|
762 |
l:= (Step + 1) * 32 / HHTexture^.w; |
|
763 |
r:= Step * 32 / HHTexture^.w |
|
764 |
end else |
|
765 |
begin |
|
766 |
l:= Step * 32 / HHTexture^.w; |
|
767 |
r:= (Step + 1) * 32 / HHTexture^.w |
|
768 |
end; |
|
769 |
||
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
770 |
|
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
771 |
glPushMatrix(); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
772 |
glTranslatef(X, Y, 0); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
773 |
glRotatef(Angle, 0, 0, 1); |
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
774 |
|
761 | 775 |
glBindTexture(GL_TEXTURE_2D, HHTexture^.id); |
776 |
||
1916 | 777 |
TextureBuffer[0].X:= l; |
778 |
TextureBuffer[0].Y:= t; |
|
779 |
TextureBuffer[1].X:= r; |
|
780 |
TextureBuffer[1].Y:= t; |
|
781 |
TextureBuffer[2].X:= r; |
|
782 |
TextureBuffer[2].Y:= b; |
|
783 |
TextureBuffer[3].X:= l; |
|
784 |
TextureBuffer[3].Y:= b; |
|
761 | 785 |
|
1916 | 786 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
787 |
glTexCoordPointer(2, GL_FLOAT, 0, @TextureBuffer[0]); |
|
788 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
761 | 789 |
|
821
e6c0408b54ed
Use 'regular standing' and 'rope swing' hedgehog sprites
unc0rr
parents:
809
diff
changeset
|
790 |
glPopMatrix |
4 | 791 |
end; |
792 |
||
1431 | 793 |
procedure DrawFillRect(r: TSDL_Rect); |
1916 | 794 |
var VertexBuffer: array [0..3] of TVertex2f; |
1431 | 795 |
begin |
3764 | 796 |
// don't draw anything outside the visible screen space (first check fixes some sprite drawing, e.g. hedgehogs) |
797 |
if (abs(r.x) > r.w) and ((abs(r.x + r.w / 2) - r.w / 2) > cScreenWidth / cScaleFactor) then |
|
798 |
exit; |
|
799 |
if (abs(r.y) > r.h) and ((abs(r.y + r.h / 2 - (0.5 * cScreenHeight)) - r.h / 2) > cScreenHeight / cScaleFactor) then |
|
800 |
exit; |
|
801 |
||
1431 | 802 |
glDisable(GL_TEXTURE_2D); |
803 |
||
3390 | 804 |
Tint($00, $00, $00, $80); |
1431 | 805 |
|
1916 | 806 |
VertexBuffer[0].X:= r.x; |
807 |
VertexBuffer[0].Y:= r.y; |
|
808 |
VertexBuffer[1].X:= r.x + r.w; |
|
809 |
VertexBuffer[1].Y:= r.y; |
|
810 |
VertexBuffer[2].X:= r.x + r.w; |
|
811 |
VertexBuffer[2].Y:= r.y + r.h; |
|
812 |
VertexBuffer[3].X:= r.x; |
|
813 |
VertexBuffer[3].Y:= r.y + r.h; |
|
1431 | 814 |
|
1916 | 815 |
glVertexPointer(2, GL_FLOAT, 0, @VertexBuffer[0]); |
816 |
glDrawArrays(GL_TRIANGLE_FAN, 0, Length(VertexBuffer)); |
|
1431 | 817 |
|
3390 | 818 |
Tint($FF, $FF, $FF, $FF); |
1431 | 819 |
glEnable(GL_TEXTURE_2D) |
820 |
end; |
|
821 |
||
4 | 822 |
procedure StoreRelease; |
823 |
var ii: TSprite; |
|
824 |
begin |
|
3405 | 825 |
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
|
826 |
begin |
3405 | 827 |
FreeTexture(SpritesData[ii].Texture); |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3509
diff
changeset
|
828 |
SpritesData[ii].Texture:= nil; |
3405 | 829 |
if SpritesData[ii].Surface <> nil then |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3509
diff
changeset
|
830 |
SDL_FreeSurface(SpritesData[ii].Surface); |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3509
diff
changeset
|
831 |
SpritesData[ii].Surface:= nil; |
769
788efc1d649f
- Save 8 MB of memory by freeing LandSurface and not using it anymore after game initialization
unc0rr
parents:
768
diff
changeset
|
832 |
end; |
3405 | 833 |
SDL_FreeSurface(MissionIcons); |
834 |
FreeTexture(ropeIconTex); |
|
835 |
FreeTexture(HHTexture); |
|
4 | 836 |
end; |
837 |
||
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
|
838 |
|
2905 | 839 |
function CheckCJKFont(s: ansistring; font: THWFont): THWFont; |
2681
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
840 |
var l, i : LongInt; |
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
841 |
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
|
842 |
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
|
843 |
begin |
3875
7d7c16ed5056
added forgotten images, removed support for CJK fonts (saving 13 MB)
koda
parents:
3862
diff
changeset
|
844 |
|
7d7c16ed5056
added forgotten images, removed support for CJK fonts (saving 13 MB)
koda
parents:
3862
diff
changeset
|
845 |
{$IFNDEF IPHONEOS} |
7d7c16ed5056
added forgotten images, removed support for CJK fonts (saving 13 MB)
koda
parents:
3862
diff
changeset
|
846 |
// remove chinese fonts for now |
7d7c16ed5056
added forgotten images, removed support for CJK fonts (saving 13 MB)
koda
parents:
3862
diff
changeset
|
847 |
if (font >= CJKfnt16) or (length(s) = 0) then |
7d7c16ed5056
added forgotten images, removed support for CJK fonts (saving 13 MB)
koda
parents:
3862
diff
changeset
|
848 |
{$ENDIF} |
7d7c16ed5056
added forgotten images, removed support for CJK fonts (saving 13 MB)
koda
parents:
3862
diff
changeset
|
849 |
exit(font); |
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
|
850 |
|
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
|
851 |
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
|
852 |
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
|
853 |
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
|
854 |
begin |
2681
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
855 |
u:= tmpstr[i]; |
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
856 |
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
|
857 |
(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
|
858 |
((#$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
|
859 |
((#$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
|
860 |
((#$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
|
861 |
((#$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
|
862 |
((#$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
|
863 |
((#$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
|
864 |
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
|
865 |
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
|
866 |
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
|
867 |
exit(font); |
2681
dcbb5e98afc7
Drop the LongInt conversion, strip the two tests that are too large
nemo
parents:
2679
diff
changeset
|
868 |
(* 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
|
869 |
((#$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
|
870 |
((#$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
|
871 |
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
|
872 |
|
2905 | 873 |
function RenderStringTex(s: ansistring; Color: Longword; font: THWFont): PTexture; |
3407 | 874 |
var w, h: LongInt; |
2695 | 875 |
finalSurface: PSDL_Surface; |
95 | 876 |
begin |
1989 | 877 |
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
|
878 |
font:= CheckCJKFont(s, font); |
3407 | 879 |
w:= 0; h:= 0; // avoid compiler hints |
355 | 880 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(s), w, h); |
785 | 881 |
|
2695 | 882 |
finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w + FontBorder * 2 + 4, h + FontBorder * 2, |
762 | 883 |
32, RMask, GMask, BMask, AMask); |
785 | 884 |
|
2695 | 885 |
TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true); |
785 | 886 |
|
2695 | 887 |
WriteInRoundRect(finalSurface, 0, 0, Color, font, s); |
785 | 888 |
|
2695 | 889 |
TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
785 | 890 |
|
2695 | 891 |
RenderStringTex:= Surface2Tex(finalSurface, false); |
785 | 892 |
|
2695 | 893 |
SDL_FreeSurface(finalSurface); |
95 | 894 |
end; |
895 |
||
2905 | 896 |
function RenderSpeechBubbleTex(s: ansistring; 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
|
897 |
var textWidth, textHeight, x, y, w, h, i, j, pos, prevpos, line, numLines, edgeWidth, edgeHeight, cornerWidth, cornerHeight: LongInt; |
2695 | 898 |
finalSurface, tmpsurf, rotatedEdge: PSDL_Surface; |
2017 | 899 |
rect: TSDL_Rect; |
900 |
chars: TSysCharSet = [#9,' ','.',';',':','?','!',',']; |
|
901 |
substr: shortstring; |
|
902 |
edge, corner, tail: TSPrite; |
|
903 |
begin |
|
904 |
||
905 |
case SpeechType of |
|
2376 | 906 |
1: begin; |
907 |
edge:= sprSpeechEdge; |
|
2017 | 908 |
corner:= sprSpeechCorner; |
909 |
tail:= sprSpeechTail; |
|
910 |
end; |
|
2376 | 911 |
2: begin; |
2017 | 912 |
edge:= sprThoughtEdge; |
2376 | 913 |
corner:= sprThoughtCorner; |
2017 | 914 |
tail:= sprThoughtTail; |
915 |
end; |
|
2376 | 916 |
3: begin; |
2017 | 917 |
edge:= sprShoutEdge; |
918 |
corner:= sprShoutCorner; |
|
919 |
tail:= sprShoutTail; |
|
920 |
end; |
|
921 |
end; |
|
922 |
edgeHeight:= SpritesData[edge].Height; |
|
923 |
edgeWidth:= SpritesData[edge].Width; |
|
924 |
cornerWidth:= SpritesData[corner].Width; |
|
925 |
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
|
926 |
// This one screws up WrapText |
2022 | 927 |
//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
|
928 |
// 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
|
929 |
//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
|
930 |
|
2022 | 931 |
numLines:= 0; |
2017 | 932 |
|
933 |
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
|
934 |
font:= CheckCJKFont(s, font); |
3407 | 935 |
w:= 0; h:= 0; // avoid compiler hints |
2017 | 936 |
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
|
937 |
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
|
938 |
j:= 0; |
2017 | 939 |
if (length(s) > 20) then |
940 |
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
|
941 |
w:= 0; |
2017 | 942 |
i:= round(Sqrt(length(s)) * 2); |
943 |
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
|
944 |
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
|
945 |
// 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
|
946 |
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
|
947 |
begin |
2017 | 948 |
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
|
949 |
begin |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
950 |
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
|
951 |
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
|
952 |
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
|
953 |
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
|
954 |
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
|
955 |
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
|
956 |
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
|
957 |
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
|
958 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
959 |
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
|
960 |
end; |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
961 |
end |
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
962 |
else numLines := 1; |
2017 | 963 |
|
2023
41d3afaa20c7
Artillery mode, sniper rifle, speech bubble tweaks, fix of rope bug introduced by enabling hats in jump
nemo
parents:
2022
diff
changeset
|
964 |
textWidth:=((w-(cornerWidth-edgeWidth)*2) div edgeWidth)*edgeWidth+edgeWidth; |
2022 | 965 |
textHeight:=(((numlines * h + 2)-((cornerHeight-edgeWidth)*2)) div edgeWidth)*edgeWidth; |
2019 | 966 |
|
2022 | 967 |
textHeight:=max(textHeight,edgeWidth); |
2017 | 968 |
//textWidth:=max(textWidth,SpritesData[tail].Width); |
969 |
rect.x:= 0; |
|
970 |
rect.y:= 0; |
|
2022 | 971 |
rect.w:= textWidth + (cornerWidth * 2); |
972 |
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
|
973 |
//s:= inttostr(w) + ' ' + inttostr(numlines) + ' ' + inttostr(rect.x) + ' '+inttostr(rect.y) + ' ' + inttostr(rect.w) + ' ' + inttostr(rect.h); |
2017 | 974 |
|
2695 | 975 |
finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, rect.w, rect.h, 32, RMask, GMask, BMask, AMask); |
2017 | 976 |
|
2695 | 977 |
TryDo(finalSurface <> nil, 'RenderString: fail to create surface', true); |
2017 | 978 |
|
979 |
//////////////////////////////// CORNERS /////////////////////////////// |
|
2695 | 980 |
copyToXY(SpritesData[corner].Surface, finalSurface, 0, 0); /////////////////// NW |
2017 | 981 |
|
982 |
flipSurface(SpritesData[corner].Surface, true); // store all 4 versions in memory to avoid repeated flips? |
|
983 |
x:= 0; |
|
984 |
y:= textHeight + cornerHeight -1; |
|
2695 | 985 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// SW |
2017 | 986 |
|
987 |
flipSurface(SpritesData[corner].Surface, false); |
|
988 |
x:= rect.w-cornerWidth-1; |
|
989 |
y:= textHeight + cornerHeight -1; |
|
2695 | 990 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// SE |
2017 | 991 |
|
992 |
flipSurface(SpritesData[corner].Surface, true); |
|
993 |
x:= rect.w-cornerWidth-1; |
|
994 |
y:= 0; |
|
2695 | 995 |
copyToXY(SpritesData[corner].Surface, finalSurface, x, y); /////////////////// NE |
2017 | 996 |
flipSurface(SpritesData[corner].Surface, false); // restore original position |
997 |
//////////////////////////////// END CORNERS /////////////////////////////// |
|
998 |
||
999 |
//////////////////////////////// EDGES ////////////////////////////////////// |
|
1000 |
x:= cornerWidth; |
|
1001 |
y:= 0; |
|
1002 |
while x < rect.w-cornerWidth-1 do |
|
1003 |
begin |
|
2695 | 1004 |
copyToXY(SpritesData[edge].Surface, finalSurface, x, y); ///////////////// top edge |
2017 | 1005 |
inc(x,edgeWidth); |
1006 |
end; |
|
1007 |
flipSurface(SpritesData[edge].Surface, true); |
|
1008 |
x:= cornerWidth; |
|
1009 |
y:= textHeight + cornerHeight*2 - edgeHeight-1; |
|
1010 |
while x < rect.w-cornerWidth-1 do |
|
1011 |
begin |
|
2695 | 1012 |
copyToXY(SpritesData[edge].Surface, finalSurface, x, y); ///////////////// bottom edge |
2017 | 1013 |
inc(x,edgeWidth); |
1014 |
end; |
|
1015 |
flipSurface(SpritesData[edge].Surface, true); // restore original position |
|
1016 |
||
1017 |
rotatedEdge:= SDL_CreateRGBSurface(SDL_SWSURFACE, edgeHeight, edgeWidth, 32, RMask, GMask, BMask, AMask); |
|
1018 |
x:= rect.w - edgeHeight - 1; |
|
1019 |
y:= cornerHeight; |
|
1020 |
//// initially was going to rotate in place, but the SDL spec claims width/height are read only |
|
1021 |
copyRotatedSurface(SpritesData[edge].Surface,rotatedEdge); |
|
1022 |
while y < textHeight + cornerHeight do |
|
1023 |
begin |
|
2695 | 1024 |
copyToXY(rotatedEdge, finalSurface, x, y); |
2017 | 1025 |
inc(y,edgeWidth); |
1026 |
end; |
|
1027 |
flipSurface(rotatedEdge, false); // restore original position |
|
1028 |
x:= 0; |
|
1029 |
y:= cornerHeight; |
|
1030 |
while y < textHeight + cornerHeight do |
|
1031 |
begin |
|
2695 | 1032 |
copyToXY(rotatedEdge, finalSurface, x, y); |
2017 | 1033 |
inc(y,edgeWidth); |
1034 |
end; |
|
1035 |
//////////////////////////////// END EDGES ////////////////////////////////////// |
|
1036 |
||
1037 |
x:= cornerWidth; |
|
1038 |
y:= textHeight + cornerHeight * 2 - edgeHeight - 1; |
|
2695 | 1039 |
copyToXY(SpritesData[tail].Surface, finalSurface, x, y); |
2017 | 1040 |
|
1041 |
rect.x:= edgeHeight; |
|
1042 |
rect.y:= edgeHeight; |
|
1043 |
rect.w:= rect.w - edgeHeight * 2; |
|
1044 |
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
|
1045 |
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
|
1046 |
j:= rect.h; |
2695 | 1047 |
SDL_FillRect(finalSurface, @rect, cWhiteColor); |
2017 | 1048 |
|
1049 |
pos:= 1; prevpos:= 0; line:= 0; |
|
1050 |
while pos <= length(s) do |
|
1051 |
begin |
|
1052 |
if (s[pos] = #1) or (pos = length(s)) then |
|
1053 |
begin |
|
1054 |
if s[pos] <> #1 then inc(pos); |
|
1055 |
while s[prevpos+1] = ' 'do inc(prevpos); |
|
1056 |
substr:= copy(s, prevpos+1, pos-prevpos-1); |
|
1057 |
if Length(substr) <> 0 then |
|
1058 |
begin |
|
2666 | 1059 |
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
|
1060 |
rect.x:= edgeHeight + 1 + ((i - w) div 2); |
2022 | 1061 |
// 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
|
1062 |
rect.y:= edgeHeight + ((j-(numLines*h)) div 2) + line * h; |
2017 | 1063 |
SDLTry(tmpsurf <> nil, true); |
2695 | 1064 |
SDL_UpperBlit(tmpsurf, nil, finalSurface, @rect); |
2017 | 1065 |
SDL_FreeSurface(tmpsurf); |
1066 |
inc(line); |
|
1067 |
prevpos:= pos; |
|
1068 |
end; |
|
1069 |
end; |
|
1070 |
inc(pos); |
|
1071 |
end; |
|
1072 |
||
2695 | 1073 |
//TryDo(SDL_SetColorKey(finalSurface, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
1074 |
RenderSpeechBubbleTex:= Surface2Tex(finalSurface, true); |
|
2017 | 1075 |
|
1076 |
SDL_FreeSurface(rotatedEdge); |
|
2695 | 1077 |
SDL_FreeSurface(finalSurface); |
2017 | 1078 |
end; |
1079 |
||
4 | 1080 |
procedure RenderHealth(var Hedgehog: THedgehog); |
95 | 1081 |
var s: shortstring; |
4 | 1082 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1083 |
str(Hedgehog.Gear^.Health, s); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1084 |
if Hedgehog.HealthTagTex <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1085 |
FreeTexture(Hedgehog.HealthTagTex); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1086 |
Hedgehog.HealthTagTex:= RenderStringTex(s, Hedgehog.Team^.Clan^.Color, fnt16) |
4 | 1087 |
end; |
1088 |
||
2905 | 1089 |
function LoadImage(const filename: shortstring; imageFlags: LongInt): PSDL_Surface; |
30 | 1090 |
var tmpsurf: PSDL_Surface; |
355 | 1091 |
s: shortstring; |
4 | 1092 |
begin |
3906 | 1093 |
WriteToConsole(msgLoading + filename + '.png [flags: ' + inttostr(imageFlags) + ']'); |
2426 | 1094 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1095 |
s:= filename + '.png'; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1096 |
tmpsurf:= IMG_Load(Str2PChar(s)); |
2254 | 1097 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1098 |
if tmpsurf = nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1099 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1100 |
OutError(msgFailed, (imageFlags and ifCritical) <> 0); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1101 |
exit(nil) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1102 |
end; |
2153 | 1103 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1104 |
if ((imageFlags and ifIgnoreCaps) = 0) and ((tmpsurf^.w > MaxTextureSize) or (tmpsurf^.h > MaxTextureSize)) then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1105 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1106 |
SDL_FreeSurface(tmpsurf); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1107 |
OutError(msgFailedSize, (imageFlags and ifCritical) <> 0); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1108 |
// dummy surface to replace non-critical textures that failed to load due to their size |
3862 | 1109 |
exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 2, 2, 32, RMask, GMask, BMask, AMask)); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1110 |
end; |
351 | 1111 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1112 |
tmpsurf:= doSurfaceConversion(tmpsurf); |
2630 | 1113 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1114 |
if (imageFlags and ifTransparent) <> 0 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1115 |
TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true); |
2630 | 1116 |
|
3407 | 1117 |
WriteLnToConsole(msgOK + ' (' + inttostr(tmpsurf^.w) + 'x' + inttostr(tmpsurf^.h) + ')'); |
2630 | 1118 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1119 |
LoadImage:= tmpsurf //Result |
753 | 1120 |
end; |
1121 |
||
2905 | 1122 |
function glLoadExtension(extension : shortstring) : boolean; |
2428 | 1123 |
begin |
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1124 |
{$IFDEF IPHONEOS} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1125 |
glLoadExtension:= false; |
3333 | 1126 |
{$IFDEF DEBUGFILE} |
1127 |
AddFileLog('OpenGL - "' + extension + '" skipped') |
|
1128 |
{$ENDIF} |
|
2580
aeccc8f51d3f
completes touch input/control (problems with moving camera)
koda
parents:
2578
diff
changeset
|
1129 |
{$ELSE} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1130 |
glLoadExtension:= glext_LoadExtension(extension); |
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
|
1131 |
{$IFDEF DEBUGFILE} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1132 |
if not glLoadExtension then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1133 |
AddFileLog('OpenGL - "' + extension + '" failed to load') |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1134 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1135 |
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
|
1136 |
{$ENDIF} |
3333 | 1137 |
{$ENDIF} |
2428 | 1138 |
end; |
1139 |
||
753 | 1140 |
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
|
1141 |
var vendor: shortstring; |
3405 | 1142 |
{$IFDEF DARWIN} |
1143 |
one: LongInt; |
|
1144 |
{$ENDIF} |
|
753 | 1145 |
begin |
3405 | 1146 |
|
2697 | 1147 |
{$IFDEF IPHONEOS} |
3376 | 1148 |
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0); // no double buffering |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1149 |
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1); |
3376 | 1150 |
{$ELSE} |
1151 |
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
|
3405 | 1152 |
{$IFNDEF SDL13} |
1153 |
// this attribute is default in 1.3 and must be enabled in MacOSX |
|
3670
4c673e57f0d7
use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents:
3663
diff
changeset
|
1154 |
if (cReducedQuality and rqDesyncVBlank) <> 0 then |
4c673e57f0d7
use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents:
3663
diff
changeset
|
1155 |
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 0) |
4c673e57f0d7
use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents:
3663
diff
changeset
|
1156 |
else |
3405 | 1157 |
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); |
1158 |
{$IFDEF DARWIN} |
|
1159 |
// fixes vsync in Snow Leopard |
|
3670
4c673e57f0d7
use llvm to compile, don't preview map on wimpier devices, merge vsync, fix iphone launch image
koda
parents:
3663
diff
changeset
|
1160 |
one:= 1; |
3405 | 1161 |
CGLSetParameter(CGLGetCurrentContext(), 222, @one); |
1162 |
{$ENDIF} |
|
1163 |
{$ENDIF} |
|
3376 | 1164 |
{$ENDIF} |
1165 |
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); // no depth buffer |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1166 |
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1167 |
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1168 |
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); |
3376 | 1169 |
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); // no alpha channel required |
1170 |
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); // buffer has to be 16 bit only |
|
1171 |
SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); // try to prefer hardware rendering |
|
2697 | 1172 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1173 |
glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize); |
2697 | 1174 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1175 |
vendor:= LowerCase(shortstring(pchar(glGetString(GL_VENDOR)))); |
2697 | 1176 |
{$IFDEF DEBUGFILE} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1177 |
AddFileLog('OpenGL-- Renderer: ' + shortstring(pchar(glGetString(GL_RENDERER)))); |
3757 | 1178 |
AddFileLog(' |----- Vendor: ' + shortstring(pchar(glGetString(GL_VENDOR)))); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1179 |
AddFileLog(' |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION)))); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1180 |
AddFileLog(' \----- GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize)); |
2153 | 1181 |
{$ENDIF} |
2252 | 1182 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1183 |
if MaxTextureSize <= 0 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1184 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1185 |
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
|
1186 |
{$IFDEF DEBUGFILE} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1187 |
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
|
1188 |
{$ENDIF} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1189 |
end; |
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
|
1190 |
|
3695
c11abf387a7d
reverted stereo craziness - the experimental3D branch has been created for a reason
koda
parents:
3691
diff
changeset
|
1191 |
{$IFNDEF IPHONEOS} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1192 |
if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1193 |
cGPUVendor:= gvNVIDIA |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1194 |
else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1195 |
cGPUVendor:= gvATI |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1196 |
else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1197 |
cGPUVendor:= gvIntel; |
2647 | 1198 |
//SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two'); |
3695
c11abf387a7d
reverted stereo craziness - the experimental3D branch has been created for a reason
koda
parents:
3691
diff
changeset
|
1199 |
{$ELSE} |
c11abf387a7d
reverted stereo craziness - the experimental3D branch has been created for a reason
koda
parents:
3691
diff
changeset
|
1200 |
cGPUVendor:= gvApple; |
2735 | 1201 |
{$ENDIF} |
1202 |
||
1203 |
{$IFDEF DEBUGFILE} |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1204 |
if cGPUVendor = gvUnknown then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1205 |
AddFileLog('OpenGL Warning - unknown hardware vendor; please report'); |
2735 | 1206 |
{$ELSE} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1207 |
// just avoid 'never used' compiler warning for now |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1208 |
if cGPUVendor = gvUnknown then cGPUVendor:= gvUnknown; |
2428 | 1209 |
{$ENDIF} |
1210 |
||
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1211 |
// set view port to whole window |
3922
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
1212 |
if rotationQt = 0 then |
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
1213 |
glViewport(0, 0, cScreenWidth, cScreenHeight) |
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
1214 |
else |
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
1215 |
glViewport(0, 0, cScreenHeight, cScreenWidth); |
2428 | 1216 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1217 |
glMatrixMode(GL_MODELVIEW); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1218 |
// prepare default translation/scaling |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1219 |
glLoadIdentity(); |
3394
47b51e22e670
Henek's patch - adds a column to ammoMenu and removes the F* column in iphone version
koda
parents:
3390
diff
changeset
|
1220 |
glRotatef(rotationQt, 0, 0, 1); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1221 |
glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1222 |
glTranslatef(0, -cScreenHeight / 2, 0); |
2428 | 1223 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1224 |
// enable alpha blending |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1225 |
glEnable(GL_BLEND); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1226 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
3376 | 1227 |
// disable/lower perspective correction (won't need it anyway) |
1228 |
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); |
|
1229 |
// disable dithering |
|
1230 |
glDisable(GL_DITHER); |
|
3641 | 1231 |
// enable common states by default as they save a lot |
3376 | 1232 |
glEnable(GL_TEXTURE_2D); |
3697 | 1233 |
glEnableClientState(GL_VERTEX_ARRAY); |
1234 |
glEnableClientState(GL_TEXTURE_COORD_ARRAY); |
|
4 | 1235 |
end; |
1236 |
||
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1237 |
procedure SetScale(f: GLfloat); |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1238 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1239 |
// leave immediately if scale factor did not change |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1240 |
if f = cScaleFactor then exit; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1241 |
|
3523 | 1242 |
if f = cDefaultZoomLevel then |
1243 |
glPopMatrix // "return" to default scaling |
|
1244 |
else // other scaling |
|
3394
47b51e22e670
Henek's patch - adds a column to ammoMenu and removes the F* column in iphone version
koda
parents:
3390
diff
changeset
|
1245 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1246 |
glPushMatrix; // save default scaling |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1247 |
glLoadIdentity; |
3394
47b51e22e670
Henek's patch - adds a column to ammoMenu and removes the F* column in iphone version
koda
parents:
3390
diff
changeset
|
1248 |
glRotatef(rotationQt, 0, 0, 1); |
3922
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
1249 |
glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1250 |
glTranslatef(0, -cScreenHeight / 2, 0); |
3394
47b51e22e670
Henek's patch - adds a column to ammoMenu and removes the F* column in iphone version
koda
parents:
3390
diff
changeset
|
1251 |
end; |
2258 | 1252 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1253 |
cScaleFactor:= f; |
2161
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1254 |
end; |
0c8634241fa4
Some work on zooming. Hedgewars are now unplayable.
unc0rr
parents:
2154
diff
changeset
|
1255 |
|
510 | 1256 |
//////////////////////////////////////////////////////////////////////////////// |
1257 |
procedure AddProgress; |
|
1258 |
var r: TSDL_Rect; |
|
766 | 1259 |
texsurf: PSDL_Surface; |
510 | 1260 |
begin |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1261 |
if Step = 0 then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1262 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1263 |
WriteToConsole(msgLoading + 'progress sprite: '); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1264 |
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
|
1265 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1266 |
ProgrTex:= Surface2Tex(texsurf, false); |
3697 | 1267 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1268 |
squaresize:= texsurf^.w shr 1; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1269 |
numsquares:= texsurf^.h div squaresize; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1270 |
SDL_FreeSurface(texsurf); |
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
1271 |
{$IFDEF IPHONEOS} |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
1272 |
startSpinning(); |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
1273 |
{$ENDIF} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1274 |
end; |
1045 | 1275 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1276 |
TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true); |
2284 | 1277 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1278 |
glClear(GL_COLOR_BUFFER_BIT); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1279 |
if Step < numsquares then r.x:= 0 |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1280 |
else r.x:= squaresize; |
3697 | 1281 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1282 |
r.y:= (Step mod numsquares) * squaresize; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1283 |
r.w:= squaresize; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1284 |
r.h:= squaresize; |
3697 | 1285 |
|
3922
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
1286 |
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
|
1287 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1288 |
SDL_GL_SwapBuffers(); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1289 |
{$IFDEF SDL13} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1290 |
SDL_RenderPresent(); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1291 |
{$ENDIF} |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1292 |
inc(Step); |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1293 |
|
510 | 1294 |
end; |
1295 |
||
1296 |
procedure FinishProgress; |
|
1297 |
begin |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1298 |
WriteLnToConsole('Freeing progress surface... '); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1299 |
FreeTexture(ProgrTex); |
3525 | 1300 |
{$IFDEF IPHONEOS} |
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
1301 |
stopSpinning(); |
3525 | 1302 |
{$ENDIF} |
510 | 1303 |
end; |
1304 |
||
2017 | 1305 |
procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean); |
1306 |
var y, x, i, j: LongInt; |
|
1307 |
tmpPixel: Longword; |
|
1308 |
pixels: PLongWordArray; |
|
1309 |
begin |
|
1310 |
TryDo(Surface^.format^.BytesPerPixel = 4, 'flipSurface failed, expecting 32 bit surface', true); |
|
1311 |
pixels:= Surface^.pixels; |
|
1312 |
if Vertical then |
|
1313 |
for y := 0 to (Surface^.h div 2) - 1 do |
|
1314 |
for x := 0 to Surface^.w - 1 do |
|
1315 |
begin |
|
1316 |
i:= y * Surface^.w + x; |
|
1317 |
j:= (Surface^.h - y - 1) * Surface^.w + x; |
|
1318 |
tmpPixel:= pixels^[i]; |
|
1319 |
pixels^[i]:= pixels^[j]; |
|
1320 |
pixels^[j]:= tmpPixel; |
|
1321 |
end |
|
1322 |
else |
|
1323 |
for x := 0 to (Surface^.w div 2) - 1 do |
|
1324 |
for y := 0 to Surface^.h -1 do |
|
1325 |
begin |
|
1326 |
i:= y*Surface^.w + x; |
|
1327 |
j:= y*Surface^.w + (Surface^.w - x - 1); |
|
1328 |
tmpPixel:= pixels^[i]; |
|
1329 |
pixels^[i]:= pixels^[j]; |
|
1330 |
pixels^[j]:= tmpPixel; |
|
1331 |
end; |
|
1332 |
end; |
|
1333 |
||
3169
c8c6ac44f51b
prophylactic removal of some Integer references, raise a few of the template islands up a bit so they work inverted without triggering border
nemo
parents:
3165
diff
changeset
|
1334 |
procedure copyToXY(src, dest: PSDL_Surface; destX, destY: LongInt); |
2017 | 1335 |
var srcX, srcY, i, j, maxDest: LongInt; |
1336 |
srcPixels, destPixels: PLongWordArray; |
|
3341 | 1337 |
r0, g0, b0, a0, r1, g1, b1, a1: Byte; |
2017 | 1338 |
begin |
1339 |
maxDest:= (dest^.pitch div 4) * dest^.h; |
|
1340 |
srcPixels:= src^.pixels; |
|
1341 |
destPixels:= dest^.pixels; |
|
1342 |
||
1343 |
for srcX:= 0 to src^.w - 1 do |
|
1344 |
for srcY:= 0 to src^.h - 1 do |
|
1345 |
begin |
|
1346 |
i:= (destY + srcY) * (dest^.pitch div 4) + destX + srcX; |
|
1347 |
j:= srcY * (src^.pitch div 4) + srcX; |
|
3341 | 1348 |
if (i < maxDest) and (srcPixels^[j] and AMask <> 0) then |
1349 |
begin |
|
1350 |
SDL_GetRGBA(destPixels^[i], dest^.format, @r0, @g0, @b0, @a0); |
|
1351 |
SDL_GetRGBA(srcPixels^[j], src^.format, @r1, @g1, @b1, @a1); |
|
3407 | 1352 |
r0:= (r0 * (255 - LongInt(a1)) + r1 * LongInt(a1)) div 255; |
1353 |
g0:= (g0 * (255 - LongInt(a1)) + g1 * LongInt(a1)) div 255; |
|
1354 |
b0:= (b0 * (255 - LongInt(a1)) + b1 * LongInt(a1)) div 255; |
|
1355 |
a0:= (a0 * (255 - LongInt(a1)) + a1 * LongInt(a1)) div 255; |
|
1356 |
destPixels^[i]:= SDL_MapRGBA(dest^.format, r0, g0, b0, a0); |
|
3341 | 1357 |
end; |
2017 | 1358 |
end; |
1359 |
end; |
|
1360 |
||
1361 |
procedure copyRotatedSurface(src, dest: PSDL_Surface); // this is necessary since width/height are read only in SDL, apparently |
|
1362 |
var y, x, i, j: LongInt; |
|
1363 |
srcPixels, destPixels: PLongWordArray; |
|
1364 |
begin |
|
1365 |
TryDo(src^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1366 |
TryDo(dest^.format^.BytesPerPixel = 4, 'rotateSurface failed, expecting 32 bit surface', true); |
|
1367 |
||
1368 |
srcPixels:= src^.pixels; |
|
1369 |
destPixels:= dest^.pixels; |
|
1370 |
||
1371 |
j:= 0; |
|
1372 |
for x := 0 to src^.w - 1 do |
|
1373 |
for y := 0 to src^.h - 1 do |
|
1374 |
begin |
|
1375 |
i:= (src^.h - 1 - y) * (src^.pitch div 4) + x; |
|
1376 |
destPixels^[j]:= srcPixels^[i]; |
|
1377 |
inc(j) |
|
1378 |
end; |
|
1379 |
end; |
|
1380 |
||
2905 | 1381 |
function RenderHelpWindow(caption, subcaption, description, extra: ansistring; extracolor: LongInt; iconsurf: PSDL_Surface; iconrect: PSDL_Rect): PTexture; |
2747 | 1382 |
var tmpsurf: PSDL_SURFACE; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1383 |
w, h, i, j: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1384 |
font: THWFont; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1385 |
r, r2: TSDL_Rect; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1386 |
wa, ha: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1387 |
tmpline, tmpline2, tmpdesc: ansistring; |
2747 | 1388 |
begin |
2843 | 1389 |
// make sure there is a caption as well as a sub caption - description is optional |
1390 |
if caption = '' then caption:= '???'; |
|
1391 |
if subcaption = '' then subcaption:= ' '; |
|
1392 |
||
2841 | 1393 |
font:= CheckCJKFont(caption,fnt16); |
1394 |
font:= CheckCJKFont(subcaption,font); |
|
1395 |
font:= CheckCJKFont(description,font); |
|
1396 |
font:= CheckCJKFont(extra,font); |
|
2747 | 1397 |
|
1398 |
w:= 0; |
|
1399 |
h:= 0; |
|
1400 |
wa:= FontBorder * 2 + 4; |
|
1401 |
ha:= FontBorder * 2; |
|
1402 |
||
3407 | 1403 |
i:= 0; j:= 0; // avoid compiler hints |
1404 |
||
2747 | 1405 |
// TODO: Recheck height/position calculation |
1406 |
||
1407 |
// get caption's dimensions |
|
1408 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(caption), i, j); |
|
1409 |
// width adds 36 px (image + space) |
|
1410 |
w:= i + 36 + wa; |
|
1411 |
h:= j + ha; |
|
1412 |
||
1413 |
// get sub caption's dimensions |
|
1414 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(subcaption), i, j); |
|
1415 |
// width adds 36 px (image + space) |
|
1416 |
if w < (i + 36 + wa) then w:= i + 36 + wa; |
|
1417 |
inc(h, j + ha); |
|
1418 |
||
1419 |
// get description's dimensions |
|
1420 |
tmpdesc:= description; |
|
1421 |
while tmpdesc <> '' do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1422 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1423 |
tmpline:= tmpdesc; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1424 |
SplitByChar(tmpline, tmpdesc, '|'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1425 |
if tmpline <> '' then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1426 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1427 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(tmpline), i, j); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1428 |
if w < (i + wa) then w:= i + wa; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1429 |
inc(h, j + ha) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1430 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1431 |
end; |
2747 | 1432 |
|
1433 |
if extra <> '' then |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1434 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1435 |
// get extra label's dimensions |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1436 |
TTF_SizeUTF8(Fontz[font].Handle, Str2PChar(extra), i, j); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1437 |
if w < (i + wa) then w:= i + wa; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1438 |
inc(h, j + ha); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1439 |
end; |
3697 | 1440 |
|
2747 | 1441 |
// add borders space |
1442 |
inc(w, wa); |
|
1443 |
inc(h, ha + 8); |
|
1444 |
||
1445 |
tmpsurf:= SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RMask, GMask, BMask, AMask); |
|
1446 |
TryDo(tmpsurf <> nil, 'RenderHelpWindow: fail to create surface', true); |
|
1447 |
||
1448 |
// render border and background |
|
1449 |
r.x:= 0; |
|
1450 |
r.y:= 0; |
|
1451 |
r.w:= w; |
|
1452 |
r.h:= h; |
|
1453 |
DrawRoundRect(@r, cWhiteColor, cNearBlackColor, tmpsurf, true); |
|
1454 |
||
1455 |
// render caption |
|
1456 |
r:= WriteInRect(tmpsurf, 36 + FontBorder + 2, ha, $ffffffff, font, caption); |
|
1457 |
// render sub caption |
|
1458 |
r:= WriteInRect(tmpsurf, 36 + FontBorder + 2, r.y + r.h, $ffc7c7c7, font, subcaption); |
|
1459 |
||
1460 |
// render all description lines |
|
1461 |
tmpdesc:= description; |
|
1462 |
while tmpdesc <> '' do |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1463 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1464 |
tmpline:= tmpdesc; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1465 |
SplitByChar(tmpline, tmpdesc, '|'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1466 |
r2:= r; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1467 |
if tmpline <> '' then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1468 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1469 |
r:= WriteInRect(tmpsurf, FontBorder + 2, r.y + r.h, $ff707070, font, tmpline); |
3697 | 1470 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1471 |
// render highlighted caption (if there's a ':') |
3407 | 1472 |
tmpline2:= ''; |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1473 |
SplitByChar(tmpline, tmpline2, ':'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1474 |
if tmpline2 <> '' then |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1475 |
WriteInRect(tmpsurf, FontBorder + 2, r2.y + r2.h, $ffc7c7c7, font, tmpline + ':'); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1476 |
end |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1477 |
end; |
2747 | 1478 |
|
1479 |
if extra <> '' then |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1480 |
r:= WriteInRect(tmpsurf, FontBorder + 2, r.y + r.h, extracolor, font, extra); |
2747 | 1481 |
|
1482 |
r.x:= FontBorder + 6; |
|
1483 |
r.y:= FontBorder + 4; |
|
1484 |
r.w:= 32; |
|
1485 |
r.h:= 32; |
|
1486 |
SDL_FillRect(tmpsurf, @r, $ffffffff); |
|
1487 |
SDL_UpperBlit(iconsurf, iconrect, tmpsurf, @r); |
|
3697 | 1488 |
|
2747 | 1489 |
RenderHelpWindow:= Surface2Tex(tmpsurf, true); |
1490 |
SDL_FreeSurface(tmpsurf) |
|
1491 |
end; |
|
1492 |
||
1493 |
procedure RenderWeaponTooltip(atype: TAmmoType); |
|
1494 |
var r: TSDL_Rect; |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1495 |
i: LongInt; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1496 |
extra: ansistring; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1497 |
extracolor: LongInt; |
2747 | 1498 |
begin |
3634 | 1499 |
// don't do anything if the window shouldn't be shown |
1500 |
if (cReducedQuality and rqTooltipsOff) <> 0 then |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1501 |
begin |
3634 | 1502 |
WeaponTooltipTex:= nil; |
1503 |
exit |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1504 |
end; |
2747 | 1505 |
|
1506 |
// free old texture |
|
1507 |
FreeWeaponTooltip; |
|
1508 |
||
1509 |
// image region |
|
1510 |
i:= LongInt(atype) - 1; |
|
3853 | 1511 |
r.x:= (i shr 4) * 32; |
1512 |
r.y:= (i mod 16) * 32; |
|
2747 | 1513 |
r.w:= 32; |
1514 |
r.h:= 32; |
|
1515 |
||
1516 |
// default (no extra text) |
|
1517 |
extra:= ''; |
|
1518 |
extracolor:= 0; |
|
1519 |
||
1520 |
if (CurrentTeam <> nil) and (Ammoz[atype].SkipTurns >= CurrentTeam^.Clan^.TurnNumber) then // weapon or utility is not yet available |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1521 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1522 |
extra:= trmsg[sidNotYetAvailable]; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1523 |
extracolor:= LongInt($ffc77070); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1524 |
end |
2747 | 1525 |
else if (Ammoz[atype].Ammo.Propz and ammoprop_NoRoundEndHint) <> 0 then // weapon or utility won't end your turn |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1526 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1527 |
extra:= trmsg[sidNoEndTurn]; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1528 |
extracolor:= LongInt($ff70c770); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1529 |
end |
3697 | 1530 |
else |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1531 |
begin |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1532 |
extra:= ''; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1533 |
extracolor:= 0; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1534 |
end; |
2747 | 1535 |
|
1536 |
// render window and return the texture |
|
1537 |
WeaponTooltipTex:= RenderHelpWindow(trammo[Ammoz[atype].NameId], trammoc[Ammoz[atype].NameId], trammod[Ammoz[atype].NameId], extra, extracolor, SpritesData[sprAMAmmos].Surface, @r) |
|
2753 | 1538 |
end; |
2747 | 1539 |
|
1540 |
procedure ShowWeaponTooltip(x, y: LongInt); |
|
1541 |
begin |
|
1542 |
// draw the texture if it exists |
|
1543 |
if WeaponTooltipTex <> nil then |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1544 |
DrawTexture(x, y, WeaponTooltipTex) |
2747 | 1545 |
end; |
1546 |
||
1547 |
procedure FreeWeaponTooltip; |
|
1548 |
begin |
|
1549 |
// free the existing texture (if there's any) |
|
1550 |
if WeaponTooltipTex = nil then |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2910
diff
changeset
|
1551 |
exit; |
2747 | 1552 |
FreeTexture(WeaponTooltipTex); |
1553 |
WeaponTooltipTex:= nil |
|
1554 |
end; |
|
1555 |
||
3038 | 1556 |
procedure initModule; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1557 |
begin |
3394
47b51e22e670
Henek's patch - adds a column to ammoMenu and removes the F* column in iphone version
koda
parents:
3390
diff
changeset
|
1558 |
PixelFormat:= nil; |
47b51e22e670
Henek's patch - adds a column to ammoMenu and removes the F* column in iphone version
koda
parents:
3390
diff
changeset
|
1559 |
SDLPrimSurface:= nil; |
3922
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
1560 |
|
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
1561 |
{$IFNDEF IPHONEOS} |
3626 | 1562 |
rotationQt:= 0; |
3394
47b51e22e670
Henek's patch - adds a column to ammoMenu and removes the F* column in iphone version
koda
parents:
3390
diff
changeset
|
1563 |
cGPUVendor:= gvUnknown; |
47b51e22e670
Henek's patch - adds a column to ammoMenu and removes the F* column in iphone version
koda
parents:
3390
diff
changeset
|
1564 |
{$ENDIF} |
3697 | 1565 |
|
3394
47b51e22e670
Henek's patch - adds a column to ammoMenu and removes the F* column in iphone version
koda
parents:
3390
diff
changeset
|
1566 |
cScaleFactor:= 2.0; |
47b51e22e670
Henek's patch - adds a column to ammoMenu and removes the F* column in iphone version
koda
parents:
3390
diff
changeset
|
1567 |
SupportNPOTT:= false; |
47b51e22e670
Henek's patch - adds a column to ammoMenu and removes the F* column in iphone version
koda
parents:
3390
diff
changeset
|
1568 |
Step:= 0; |
47b51e22e670
Henek's patch - adds a column to ammoMenu and removes the F* column in iphone version
koda
parents:
3390
diff
changeset
|
1569 |
ProgrTex:= nil; |
2699
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1570 |
end; |
249adefa9c1c
replace initialization/finalization statements with custom init functions
koda
parents:
2698
diff
changeset
|
1571 |
|
3038 | 1572 |
procedure freeModule; |
2716
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1573 |
begin |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1574 |
end; |
b9ca1bfca24f
complete the replacement of init/free wrappers for every unit
koda
parents:
2705
diff
changeset
|
1575 |
|
4 | 1576 |
end. |