DEADSOFTWARE

cf7bc3e25e7c45d3d4b22e15a753f51cda862d28
[d2df-sdl.git] / src / game / opengl / r_map.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
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.
6 *
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.
11 *
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/>.
14 *)
15 {$INCLUDE ../../shared/a_modes.inc}
16 unit r_map;
18 interface
20 uses MAPDEF; // TDFColor
22 procedure r_Map_DrawBack (dx, dy: Integer);
23 procedure r_Map_DrawPanels (PanelType: Word; hasAmbient: Boolean; constref ambColor: TDFColor); // unaccelerated
24 procedure r_Map_CollectDrawPanels (x0, y0, wdt, hgt: Integer);
25 procedure r_Map_DrawPanelShadowVolumes (lightX: Integer; lightY: Integer; radius: Integer);
26 procedure r_Map_DrawFlags;
28 implementation
30 uses
31 {$INCLUDE ../nogl/noGLuses.inc}
32 SysUtils, Classes, Math,
33 r_graphics, r_animations,
34 g_base, g_basic, g_game, g_options,
35 g_panel, g_map,
36 r_panel
37 ;
39 procedure dplClear ();
40 begin
41 if (gDrawPanelList = nil) then gDrawPanelList := TBinHeapPanelDraw.Create() else gDrawPanelList.clear();
42 end;
44 // old algo
45 procedure r_Map_DrawPanels (PanelType: Word; hasAmbient: Boolean; constref ambColor: TDFColor);
47 procedure DrawPanels (constref panels: TPanelArray; drawDoors: Boolean=False);
48 var
49 idx: Integer;
50 begin
51 if (panels <> nil) then
52 begin
53 // alas, no visible set
54 for idx := 0 to High(panels) do
55 begin
56 if not (drawDoors xor panels[idx].Door) then
57 r_Panel_Draw(panels[idx], hasAmbient, ambColor);
58 end;
59 end;
60 end;
62 begin
63 case PanelType of
64 PANEL_WALL: DrawPanels(gWalls);
65 PANEL_CLOSEDOOR: DrawPanels(gWalls, True);
66 PANEL_BACK: DrawPanels(gRenderBackgrounds);
67 PANEL_FORE: DrawPanels(gRenderForegrounds);
68 PANEL_WATER: DrawPanels(gWater);
69 PANEL_ACID1: DrawPanels(gAcid1);
70 PANEL_ACID2: DrawPanels(gAcid2);
71 PANEL_STEP: DrawPanels(gSteps);
72 end;
73 end;
75 // new algo
76 procedure r_Map_CollectDrawPanels (x0, y0, wdt, hgt: Integer);
77 var
78 mwit: PPanel;
79 it: TPanelGrid.Iter;
80 begin
81 dplClear();
82 it := mapGrid.forEachInAABB(x0, y0, wdt, hgt, GridDrawableMask);
83 for mwit in it do if (((mwit^.tag and GridTagDoor) <> 0) = mwit^.Door) then gDrawPanelList.insert(mwit^);
84 it.release();
85 // list will be rendered in `g_game.DrawPlayer()`
86 end;
88 procedure r_Map_DrawPanelShadowVolumes (lightX: Integer; lightY: Integer; radius: Integer);
89 var
90 mwit: PPanel;
91 it: TPanelGrid.Iter;
92 begin
93 it := mapGrid.forEachInAABB(lightX-radius, lightY-radius, radius*2, radius*2, (GridTagWall or GridTagDoor));
94 for mwit in it do r_Panel_DrawShadowVolume(mwit^, lightX, lightY, radius);
95 it.release();
96 end;
98 procedure r_Map_DrawBack(dx, dy: Integer);
99 begin
100 if gDrawBackGround and (BackID <> DWORD(-1)) then
101 e_DrawSize(BackID, dx, dy, 0, False, False, gBackSize.X, gBackSize.Y)
102 else
103 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
104 end;
106 procedure r_Map_DrawFlags();
107 var
108 i, dx: Integer;
109 tx, ty: Integer;
110 Mirror: TMirrorType;
111 begin
112 if gGameSettings.GameMode <> GM_CTF then
113 Exit;
115 for i := FLAG_RED to FLAG_BLUE do
116 with gFlags[i] do
117 if State <> FLAG_STATE_CAPTURED then
118 begin
119 if State = FLAG_STATE_NONE then
120 continue;
122 Obj.lerp(gLerpFactor, tx, ty);
124 if Direction = TDirection.D_LEFT then
125 begin
126 Mirror := TMirrorType.Horizontal;
127 dx := -1;
128 end
129 else
130 begin
131 Mirror := TMirrorType.None;
132 dx := 1;
133 end;
135 r_Animation_Draw(Animation, tx + dx, ty + 1, Mirror);
137 if g_debug_Frames then
138 begin
139 e_DrawQuad(Obj.X+Obj.Rect.X,
140 Obj.Y+Obj.Rect.Y,
141 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
142 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
143 0, 255, 0);
144 end;
145 end;
146 end;
148 end.