7cb4263764ba7b37031ecaff219eafb5541d224e
1 (* Copyright (C) Doom 2D: Forever Developers
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 {$INCLUDE ../../shared/a_modes.inc}
20 uses g_panel
, MAPDEF
; // TPanel, TDFColor
22 procedure r_Map_LoadTextures
;
24 procedure r_Map_DrawBack (dx
, dy
: Integer);
25 procedure r_Map_DrawPanels (PanelType
: Word; hasAmbient
: Boolean; constref ambColor
: TDFColor
); // unaccelerated
26 procedure r_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
27 procedure r_Map_DrawPanelShadowVolumes (lightX
: Integer; lightY
: Integer; radius
: Integer);
28 procedure r_Map_DrawFlags
;
30 procedure r_Panel_Draw (constref p
: TPanel
; hasAmbient
: Boolean; constref ambColor
: TDFColor
);
31 procedure r_Panel_DrawShadowVolume (constref p
: TPanel
; lightX
, lightY
: Integer; radius
: Integer);
36 {$INCLUDE ../nogl/noGLuses.inc}
37 SysUtils
, Classes
, Math
, e_log
, wadreader
, CONFIG
,
38 r_graphics
, r_animations
, r_textures
,
39 g_base
, g_basic
, g_game
, g_options
,
44 RenTextures
: array of record
49 procedure r_Map_LoadTextures
;
54 WadName
, ResName
: String;
56 ResData
, ReszData
: Pointer;
57 ResLen
, ReszLen
: Integer;
59 TextureResource
: String;
60 Width
, Height
: Integer;
64 if Textures
<> nil then
66 n
:= Length(Textures
);
67 SetLength(RenTextures
, n
);
68 for i
:= 0 to n
- 1 do
70 RenTextures
[i
].ID
:= LongWord(TEXTURE_NONE
);
71 RenTextures
[i
].Width
:= 0;
72 RenTextures
[i
].Height
:= 0;
73 case Textures
[i
].TextureName
of
74 TEXTURE_NAME_WATER
: RenTextures
[i
].ID
:= LongWord(TEXTURE_SPECIAL_WATER
);
75 TEXTURE_NAME_ACID1
: RenTextures
[i
].ID
:= LongWord(TEXTURE_SPECIAL_ACID1
);
76 TEXTURE_NAME_ACID2
: RenTextures
[i
].ID
:= LongWord(TEXTURE_SPECIAL_ACID2
);
78 WadName
:= g_ExtractWadName(Textures
[i
].FullName
);
79 ResName
:= g_ExtractFilePathName(Textures
[i
].FullName
);
80 WAD
:= TWADFile
.Create();
81 if WAD
.ReadFile(WadName
) then
83 if WAD
.GetResource(ResName
, ResData
, ResLen
, log
) then
85 if Textures
[i
].Anim
then
87 WADz
:= TWADFile
.Create();
88 if WADz
.ReadMemory(ResData
, ResLen
) then
90 if WADz
.GetResource('TEXT/ANIM', ReszData
, ReszLen
) then
92 cfg
:= TConfig
.CreateMem(ReszData
, ReszLen
);
96 TextureResource
:= cfg
.ReadStr('', 'resource', '');
97 Width
:= cfg
.ReadInt('', 'framewidth', 0);
98 Height
:= cfg
.ReadInt('', 'frameheight', 0);
99 FramesCount
:= cfg
.ReadInt('', 'framecount', 0);
100 // Speed := cfg.ReadInt('', 'waitcount', 0);
101 BackAnim
:= cfg
.ReadBool('', 'backanimation', False);
102 RenTextures
[i
].Width
:= Width
;
103 RenTextures
[i
].Height
:= Height
;
104 if TextureResource
<> '' then
106 if WADz
.GetResource('TEXTURES/' + TextureResource
, ReszData
, ReszLen
) then
108 if not g_Frames_CreateMemory(@RenTextures
[i
].ID
, '', ReszData
, ReszLen
, Width
, Height
, FramesCount
, BackAnim
) then
109 e_LogWritefln('r_Map_LoadTextures: failed to create frames object (%s)', [Textures
[i
].FullName
]);
113 e_LogWritefln('r_Map_LoadTextures: failed to open animation resources (%s)', [Textures
[i
].FullName
])
116 e_LogWritefln('r_Map_LoadTextures: failed to animation has no texture resource string (%s)', [Textures
[i
].FullName
]);
120 e_LogWritefln('r_Map_LoadTextures: failed to parse animation description (%s)', [Textures
[i
].FullName
])
123 e_LogWritefln('r_Map_LoadTextures: failed to open animation description (%s)', [Textures
[i
].FullName
])
126 e_LogWritefln('r_Map_LoadTextures: failed to open animation (%s)', [Textures
[i
].FullName
]);
131 if e_CreateTextureMem(ResData
, ResLen
, RenTextures
[i
].ID
) then
132 e_GetTextureSize(RenTextures
[i
].ID
, @RenTextures
[i
].Width
, @RenTextures
[i
].Height
)
134 e_LogWritefln('r_Map_LoadTextures: failed to create texture (%s)', [Textures
[i
].FullName
])
139 e_LogWritefln('r_Map_LoadTextures: failed to open (%s)', [Textures
[i
].FullName
])
142 e_LogWritefln('r_Map_LoadTextures: failed to open %s', [WadName
]);
149 procedure dplClear ();
151 if (gDrawPanelList
= nil) then gDrawPanelList
:= TBinHeapPanelDraw
.Create() else gDrawPanelList
.clear();
155 procedure r_Map_DrawPanels (PanelType
: Word; hasAmbient
: Boolean; constref ambColor
: TDFColor
);
157 procedure DrawPanels (constref panels
: TPanelArray
; drawDoors
: Boolean=False);
161 if (panels
<> nil) then
163 // alas, no visible set
164 for idx
:= 0 to High(panels
) do
166 if not (drawDoors
xor panels
[idx
].Door
) then
167 r_Panel_Draw(panels
[idx
], hasAmbient
, ambColor
);
174 PANEL_WALL
: DrawPanels(gWalls
);
175 PANEL_CLOSEDOOR
: DrawPanels(gWalls
, True);
176 PANEL_BACK
: DrawPanels(gRenderBackgrounds
);
177 PANEL_FORE
: DrawPanels(gRenderForegrounds
);
178 PANEL_WATER
: DrawPanels(gWater
);
179 PANEL_ACID1
: DrawPanels(gAcid1
);
180 PANEL_ACID2
: DrawPanels(gAcid2
);
181 PANEL_STEP
: DrawPanels(gSteps
);
186 procedure r_Map_CollectDrawPanels (x0
, y0
, wdt
, hgt
: Integer);
192 it
:= mapGrid
.forEachInAABB(x0
, y0
, wdt
, hgt
, GridDrawableMask
);
193 for mwit
in it
do if (((mwit
^.tag
and GridTagDoor
) <> 0) = mwit
^.Door
) then gDrawPanelList
.insert(mwit
^);
195 // list will be rendered in `g_game.DrawPlayer()`
198 procedure r_Map_DrawPanelShadowVolumes (lightX
: Integer; lightY
: Integer; radius
: Integer);
203 it
:= mapGrid
.forEachInAABB(lightX
-radius
, lightY
-radius
, radius
*2, radius
*2, (GridTagWall
or GridTagDoor
));
204 for mwit
in it
do r_Panel_DrawShadowVolume(mwit
^, lightX
, lightY
, radius
);
208 procedure r_Map_DrawBack(dx
, dy
: Integer);
210 if gDrawBackGround
and (BackID
<> DWORD(-1)) then
211 e_DrawSize(BackID
, dx
, dy
, 0, False, False, gBackSize
.X
, gBackSize
.Y
)
213 e_Clear(GL_COLOR_BUFFER_BIT
, 0, 0, 0);
216 procedure r_Map_DrawFlags();
221 if gGameSettings
.GameMode
<> GM_CTF
then
224 for i
:= FLAG_RED
to FLAG_BLUE
do
226 if State
<> FLAG_STATE_CAPTURED
then
228 if State
= FLAG_STATE_NONE
then
231 if Direction
= TDirection
.D_LEFT
then
233 Mirror
:= TMirrorType
.Horizontal
;
238 Mirror
:= TMirrorType
.None
;
242 r_Animation_Draw(Animation
, Obj
.X
+ dx
, Obj
.Y
+ 1, Mirror
);
244 if g_debug_Frames
then
246 e_DrawQuad(Obj
.X
+Obj
.Rect
.X
,
248 Obj
.X
+Obj
.Rect
.X
+Obj
.Rect
.Width
-1,
249 Obj
.Y
+Obj
.Rect
.Y
+Obj
.Rect
.Height
-1,
255 procedure r_Panel_Draw (constref p
: TPanel
; hasAmbient
: Boolean; constref ambColor
: TDFColor
);
256 var xx
, yy
: Integer; NoTextureID
, TextureID
, FramesID
: DWORD
; NW
, NH
: Word; Texture
: Cardinal; IsAnim
: Boolean; w
, h
: Integer;
258 if {p.Enabled and} (p
.FCurTexture
>= 0) and (p
.Width
> 0) and (p
.Height
> 0) and (p
.Alpha
< 255) {and g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then
260 Texture
:= p
.TextureIDs
[p
.FCurTexture
].Texture
;
261 IsAnim
:= p
.TextureIDs
[p
.FCurTexture
].Anim
;
264 if p
.TextureIDs
[p
.FCurTexture
].AnTex
<> nil then
266 FramesID
:= RenTextures
[Texture
].ID
;
267 w
:= RenTextures
[Texture
].Width
;
268 h
:= RenTextures
[Texture
].Height
;
269 for xx
:= 0 to p
.Width
div w
- 1 do
270 for yy
:= 0 to p
.Height
div h
- 1 do
271 r_AnimationState_Draw(FramesID
, p
.TextureIDs
[p
.FCurTexture
].AnTex
, p
.X
+ xx
* w
, p
.Y
+ yy
* h
, TMirrorType
.None
);
276 TextureID
:= RenTextures
[Texture
].ID
;
277 w
:= RenTextures
[Texture
].Width
;
278 h
:= RenTextures
[Texture
].Height
;
280 LongWord(TEXTURE_SPECIAL_WATER
): e_DrawFillQuad(p
.X
, p
.Y
, p
.X
+ p
.Width
- 1, p
.Y
+ p
.Height
- 1, 0, 0, 255, 0, TBlending
.Filter
);
281 LongWord(TEXTURE_SPECIAL_ACID1
): e_DrawFillQuad(p
.X
, p
.Y
, p
.X
+ p
.Width
- 1, p
.Y
+ p
.Height
- 1, 0, 230, 0, 0, TBlending
.Filter
);
282 LongWord(TEXTURE_SPECIAL_ACID2
): e_DrawFillQuad(p
.X
, p
.Y
, p
.X
+ p
.Width
- 1, p
.Y
+ p
.Height
- 1, 230, 0, 0, 0, TBlending
.Filter
);
283 LongWord(TEXTURE_NONE
):
284 if g_Texture_Get('NOTEXTURE', NoTextureID
) then
286 e_GetTextureSize(NoTextureID
, @NW
, @NH
);
287 e_DrawFill(NoTextureID
, p
.X
, p
.Y
, p
.Width
div NW
, p
.Height
div NH
, 0, False, False);
291 xx
:= p
.X
+ (p
.Width
div 2);
292 yy
:= p
.Y
+ (p
.Height
div 2);
293 e_DrawFillQuad(p
.X
, p
.Y
, xx
, yy
, 255, 0, 255, 0);
294 e_DrawFillQuad(xx
, p
.Y
, p
.X
+ p
.Width
- 1, yy
, 255, 255, 0, 0);
295 e_DrawFillQuad(p
.X
, yy
, xx
, p
.Y
+ p
.Height
- 1, 255, 255, 0, 0);
296 e_DrawFillQuad(xx
, yy
, p
.X
+ p
.Width
- 1, p
.Y
+ p
.Height
- 1, 255, 0, 255, 0);
299 if not p
.movingActive
then
300 e_DrawFill(TextureID
, p
.X
, p
.Y
, p
.Width
div w
, p
.Height
div h
, p
.Alpha
, True, p
.Blending
, hasAmbient
)
302 e_DrawFillX(TextureID
, p
.X
, p
.Y
, p
.Width
, p
.Height
, p
.Alpha
, True, p
.Blending
, g_dbg_scale
, hasAmbient
);
304 e_AmbientQuad(p
.X
, p
.Y
, p
.Width
, p
.Height
, ambColor
.r
, ambColor
.g
, ambColor
.b
, ambColor
.a
);
310 procedure r_Panel_DrawShadowVolume (constref p
: TPanel
; lightX
, lightY
: Integer; radius
: Integer);
311 var Texture
: Cardinal;
313 procedure extrude (x
: Integer; y
: Integer);
315 glVertex2i(x
+ (x
- lightX
) * 500, y
+ (y
- lightY
) * 500);
316 //e_WriteLog(Format(' : (%d,%d)', [x + (x - lightX) * 300, y + (y - lightY) * 300]), MSG_WARNING);
319 procedure drawLine (x0
: Integer; y0
: Integer; x1
: Integer; y1
: Integer);
321 // does this side facing the light?
322 if ((x1
- x0
) * (lightY
- y0
) - (lightX
- x0
) * (y1
- y0
) >= 0) then exit
;
323 //e_WriteLog(Format('lightpan: (%d,%d)-(%d,%d)', [x0, y0, x1, y1]), MSG_WARNING);
324 // this edge is facing the light, extrude and draw it
332 if radius
< 4 then exit
;
333 if p
.Enabled
and (p
.FCurTexture
>= 0) and (p
.Width
> 0) and (p
.Height
> 0) and (p
.Alpha
< 255) {and g_Collide(X, Y, Width, Height, sX, sY, sWidth, sHeight)} then
335 if not p
.TextureIDs
[p
.FCurTexture
].Anim
then
337 Texture
:= p
.TextureIDs
[p
.FCurTexture
].Texture
;
338 // case Textures[Texture].TextureID of
339 case RenTextures
[Texture
].ID
of
340 LongWord(TEXTURE_SPECIAL_WATER
): exit
;
341 LongWord(TEXTURE_SPECIAL_ACID1
): exit
;
342 LongWord(TEXTURE_SPECIAL_ACID2
): exit
;
343 LongWord(TEXTURE_NONE
): exit
;
346 if (p
.X
+ p
.Width
< lightX
- radius
) then exit
;
347 if (p
.Y
+ p
.Height
< lightY
- radius
) then exit
;
348 if (p
.X
> lightX
+ radius
) then exit
;
349 if (p
.Y
> lightY
+ radius
) then exit
;
350 //e_DrawFill(TextureIDs[FCurTexture].Tex, X, Y, Width div TextureWidth, Height div TextureHeight, Alpha, True, Blending);
352 drawLine(p
.x
, p
.y
, p
.x
+ p
.width
, p
.y
); // top
353 drawLine(p
.x
+ p
.width
, p
.y
, p
.x
+ p
.width
, p
.y
+ p
.height
); // right
354 drawLine(p
.x
+ p
.width
, p
.y
+ p
.height
, p
.x
, p
.y
+ p
.height
); // bottom
355 drawLine(p
.x
, p
.y
+ p
.height
, p
.x
, p
.y
); // left