DEADSOFTWARE

eb50ad9bfa35e6791e0783b2e8c8653477f6b236
[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 e_graphics,
34 g_basic, g_game, g_options,
35 g_panel, g_map
36 ;
38 procedure dplClear ();
39 begin
40 if (gDrawPanelList = nil) then gDrawPanelList := TBinHeapPanelDraw.Create() else gDrawPanelList.clear();
41 end;
43 // old algo
44 procedure r_Map_DrawPanels (PanelType: Word; hasAmbient: Boolean; constref ambColor: TDFColor);
46 procedure DrawPanels (constref panels: TPanelArray; drawDoors: Boolean=False);
47 var
48 idx: Integer;
49 begin
50 if (panels <> nil) then
51 begin
52 // alas, no visible set
53 for idx := 0 to High(panels) do
54 begin
55 if not (drawDoors xor panels[idx].Door) then panels[idx].Draw(hasAmbient, ambColor);
56 end;
57 end;
58 end;
60 begin
61 case PanelType of
62 PANEL_WALL: DrawPanels(gWalls);
63 PANEL_CLOSEDOOR: DrawPanels(gWalls, True);
64 PANEL_BACK: DrawPanels(gRenderBackgrounds);
65 PANEL_FORE: DrawPanels(gRenderForegrounds);
66 PANEL_WATER: DrawPanels(gWater);
67 PANEL_ACID1: DrawPanels(gAcid1);
68 PANEL_ACID2: DrawPanels(gAcid2);
69 PANEL_STEP: DrawPanels(gSteps);
70 end;
71 end;
73 // new algo
74 procedure r_Map_CollectDrawPanels (x0, y0, wdt, hgt: Integer);
75 var
76 mwit: PPanel;
77 it: TPanelGrid.Iter;
78 begin
79 dplClear();
80 it := mapGrid.forEachInAABB(x0, y0, wdt, hgt, GridDrawableMask);
81 for mwit in it do if (((mwit^.tag and GridTagDoor) <> 0) = mwit^.Door) then gDrawPanelList.insert(mwit^);
82 it.release();
83 // list will be rendered in `g_game.DrawPlayer()`
84 end;
86 procedure r_Map_DrawPanelShadowVolumes (lightX: Integer; lightY: Integer; radius: Integer);
87 var
88 mwit: PPanel;
89 it: TPanelGrid.Iter;
90 begin
91 it := mapGrid.forEachInAABB(lightX-radius, lightY-radius, radius*2, radius*2, (GridTagWall or GridTagDoor));
92 for mwit in it do mwit^.DrawShadowVolume(lightX, lightY, radius);
93 it.release();
94 end;
96 procedure r_Map_DrawBack(dx, dy: Integer);
97 begin
98 if gDrawBackGround and (BackID <> DWORD(-1)) then
99 e_DrawSize(BackID, dx, dy, 0, False, False, gBackSize.X, gBackSize.Y)
100 else
101 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
102 end;
104 procedure r_Map_DrawFlags();
105 var
106 i, dx: Integer;
107 Mirror: TMirrorType;
108 begin
109 if gGameSettings.GameMode <> GM_CTF then
110 Exit;
112 for i := FLAG_RED to FLAG_BLUE do
113 with gFlags[i] do
114 if State <> FLAG_STATE_CAPTURED then
115 begin
116 if State = FLAG_STATE_NONE then
117 continue;
119 if Direction = TDirection.D_LEFT then
120 begin
121 Mirror := TMirrorType.Horizontal;
122 dx := -1;
123 end
124 else
125 begin
126 Mirror := TMirrorType.None;
127 dx := 1;
128 end;
130 Animation.Draw(Obj.X+dx, Obj.Y+1, Mirror);
132 if g_debug_Frames then
133 begin
134 e_DrawQuad(Obj.X+Obj.Rect.X,
135 Obj.Y+Obj.Rect.Y,
136 Obj.X+Obj.Rect.X+Obj.Rect.Width-1,
137 Obj.Y+Obj.Rect.Y+Obj.Rect.Height-1,
138 0, 255, 0);
139 end;
140 end;
141 end;
143 end.