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