1 unit f_mapoptimization
;
3 {$INCLUDE ../shared/a_modes.inc}
8 LCLIntf
, LCLType
, LMessages
, Messages
, SysUtils
, Variants
, Classes
,
9 Graphics
, Controls
, Forms
, Dialogs
, StdCtrls
,
10 ComCtrls
, ExtCtrls
, utils
;
13 TMapOptimizationForm
= class (TForm
)
15 GroupBoxOpt
: TGroupBox
;
17 lOptimizationDescription
: TLabel
;
18 rbTexturesOptimization
: TRadioButton
;
19 rbPanelsOptimization
: TRadioButton
;
21 mOptimizationResult
: TMemo
;
23 pcOptimizationOptions
: TPageControl
;
24 // Оптимизация текстур:
25 tsTextureOptimization
: TTabSheet
;
26 bBeginTextureOptimization
: TButton
;
27 // Оптимизация панелей:
28 tsPanelOptimization
: TTabSheet
;
29 cbOptimizeWalls
: TCheckBox
;
30 cbOptimizeForeGround
: TCheckBox
;
31 cbOptimizeBackGround
: TCheckBox
;
32 cbOptimizeSteps
: TCheckBox
;
33 cbOptimizeWater
: TCheckBox
;
34 cbOptimizeAcid1
: TCheckBox
;
35 cbOptimizeAcid2
: TCheckBox
;
36 cbOptimizeLift
: TCheckBox
;
37 cbOptimizeBlockMon
: TCheckBox
;
38 bBeginPanelsOptimization
: TButton
;
40 procedure FormActivate(Sender
: TObject
);
41 procedure rbTexturesOptimizationClick(Sender
: TObject
);
42 procedure rbPanelsOptimizationClick(Sender
: TObject
);
43 procedure bBeginTextureOptimizationClick(Sender
: TObject
);
44 procedure bBeginPanelsOptimizationClick(Sender
: TObject
);
47 { Private declarations }
49 { Public declarations }
53 MapOptimizationForm
: TMapOptimizationForm
;
58 f_main
, g_map
, g_textures
, MAPDEF
, g_language
;
62 procedure TMapOptimizationForm
.FormActivate(Sender
: TObject
);
64 rbTexturesOptimization
.Checked
:= True;
65 mOptimizationResult
.Clear();
68 procedure TMapOptimizationForm
.rbTexturesOptimizationClick(Sender
: TObject
);
70 pcOptimizationOptions
.ActivePage
:= tsTextureOptimization
;
71 lOptimizationDescription
.Caption
:= _lc
[I_CTRL_OPT_DESC_TEXTURE
];
74 procedure TMapOptimizationForm
.rbPanelsOptimizationClick(Sender
: TObject
);
76 pcOptimizationOptions
.ActivePage
:= tsPanelOptimization
;
77 lOptimizationDescription
.Caption
:= _lc
[I_CTRL_OPT_DESC_PANEL
];
80 procedure TMapOptimizationForm
.bBeginTextureOptimizationClick(
90 mOptimizationResult
.Clear();
93 if MainForm
.lbTextureList
.Count
= 0 then
95 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_NO_TEXTURES
]);
99 c
:= MainForm
.lbTextureList
.Count
;
102 while a
<= MainForm
.lbTextureList
.Count
-1 do
106 for i
:= 0 to High(gPanels
) do
107 if (gPanels
[i
].PanelType
<> 0) and
108 (gPanels
[i
].TextureName
= MainForm
.lbTextureList
.Items
[a
]) then
114 // Нашли неиспользуемую текстуру:
117 g_DeleteTexture(MainForm
.lbTextureList
.Items
[a
]);
120 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_DELETED_TEXTURES
]);
123 mOptimizationResult
.Lines
.Add(' '+MainForm
.lbTextureList
.Items
[a
]);
124 MainForm
.lbTextureList
.Items
.Delete(a
);
130 with mOptimizationResult
.Lines
do
132 Add(#13#10+_lc
[I_OPT_TOTAL_TEXTURES
]+' '+#9+IntToStr(c
));
133 Add(_lc
[I_OPT_TEX_DELETED
]+#9+IntToStr(c
-MainForm
.lbTextureList
.Count
));
137 procedure TMapOptimizationForm
.bBeginPanelsOptimizationClick(
140 function OptimizePanels(PanelsType
: Word): Integer;
144 list
: Array of DWORD
;
149 // Составляем список переключаемых лифтов:
151 if WordBool(PanelsType
and (PANEL_LIFTUP
or PANEL_LIFTDOWN
or PANEL_LIFTLEFT
or PANEL_LIFTRIGHT
)) then
156 if gTriggers
<> nil then
157 for i
:= 0 to High(gTriggers
) do
158 if (gTriggers
[i
].Data
.PanelID
<> -1) and
159 ((gTriggers
[i
].TriggerType
= TRIGGER_LIFT
) or
160 (gTriggers
[i
].TriggerType
= TRIGGER_LIFTUP
) or
161 (gTriggers
[i
].TriggerType
= TRIGGER_LIFTDOWN
)) then
163 if n
> High(list
) then
164 SetLength(list
, Length(list
)+32);
165 list
[n
] := gTriggers
[i
].Data
.PanelID
;
178 for i
:= 0 to High(gPanels
) do
179 if gPanels
[i
].PanelType
<> PANEL_NONE
then
183 for b
:= 0 to High(list
) do
184 if list
[b
] = DWORD(i
) then
190 // Это переключаемый лифт:
194 for n
:= 0 to High(gPanels
) do
195 if gPanels
[i
].PanelType
<> PANEL_NONE
then
199 for b
:= 0 to High(list
) do
200 if list
[b
] = DWORD(n
) then
206 // Это тоже переключаемый лифт:
210 // Если можно - объединяем панели:
211 if (gPanels
[i
].PanelType
<> 0) and
212 (gPanels
[n
].PanelType
<> 0) then
215 (gPanels
[i
].Width
<> 0) and
216 (gPanels
[n
].Width
<> 0) and
217 (gPanels
[n
].TextureID
= gPanels
[i
].TextureID
) and
218 (gPanels
[n
].PanelType
= gPanels
[i
].PanelType
) and
219 (gPanels
[n
].PanelType
= PanelsType
) and
220 (gPanels
[n
].Alpha
= gPanels
[i
].Alpha
) and
221 (gPanels
[n
].Blending
= gPanels
[i
].Blending
) and
222 (gPanels
[n
].TextureName
= gPanels
[i
].TextureName
) then
224 // Рядом по-горизонтали:
225 if (gPanels
[n
].X
= gPanels
[i
].X
+ gPanels
[i
].Width
) and
226 (gPanels
[n
].Y
= gPanels
[i
].Y
) and
227 (gPanels
[n
].Height
= gPanels
[i
].Height
) then
229 gPanels
[i
].Width
:= gPanels
[i
].Width
+gPanels
[n
].Width
;
230 RemoveObject(n
, OBJECT_PANEL
);
236 // Рядом по-вертикали:
237 if (gPanels
[n
].Y
= gPanels
[i
].Y
+ gPanels
[i
].Height
) and
238 (gPanels
[n
].X
= gPanels
[i
].X
) and
239 (gPanels
[n
].Width
= gPanels
[i
].Width
) then
241 gPanels
[i
].Height
:= gPanels
[i
].Height
+gPanels
[n
].Height
;
242 RemoveObject(n
, OBJECT_PANEL
);
256 panelcount1
, panelcount2
: Integer;
260 mOptimizationResult
.Clear();
262 if gPanels
= nil then
266 for a
:= 0 to High(gPanels
) do
267 if gPanels
[a
].PanelType
<> 0 then
268 panelcount1
:= panelcount1
+ 1;
270 if panelcount1
= 0 then
273 if cbOptimizeWalls
.Checked
then
275 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_WALLS
]);
276 count
:= OptimizePanels(PANEL_WALL
);
277 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_PANELS_OPT
]+' '+IntToStr(count
)+#13#10);
280 if cbOptimizeForeGround
.Checked
then
282 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_FORES
]);
283 count
:= OptimizePanels(PANEL_FORE
);
284 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_PANELS_OPT
]+' '+IntToStr(count
)+#13#10);
287 if cbOptimizeBackGround
.Checked
then
289 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_BACKS
]);
290 count
:= OptimizePanels(PANEL_BACK
);
291 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_PANELS_OPT
]+' '+IntToStr(count
)+#13#10);
294 if cbOptimizeSteps
.Checked
then
296 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_STAIRS
]);
297 count
:= OptimizePanels(PANEL_STEP
);
298 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_PANELS_OPT
]+' '+IntToStr(count
)+#13#10);
301 if cbOptimizeWater
.Checked
then
303 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_WATER
]);
304 count
:= OptimizePanels(PANEL_WATER
);
305 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_PANELS_OPT
]+' '+IntToStr(count
)+#13#10);
308 if cbOptimizeAcid1
.Checked
then
310 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_ACID1
]);
311 count
:= OptimizePanels(PANEL_ACID1
);
312 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_PANELS_OPT
]+' '+IntToStr(count
)+#13#10);
315 if cbOptimizeAcid2
.Checked
then
317 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_ACID2
]);
318 count
:= OptimizePanels(PANEL_ACID2
);
319 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_PANELS_OPT
]+' '+IntToStr(count
)+#13#10);
322 if cbOptimizeLift
.Checked
then
324 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_LIFTS
]);
325 count
:= OptimizePanels(PANEL_LIFTUP
)+OptimizePanels(PANEL_LIFTDOWN
)+OptimizePanels(PANEL_LIFTLEFT
)+OptimizePanels(PANEL_LIFTRIGHT
);
326 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_PANELS_OPT
]+' '+IntToStr(count
)+#13#10);
329 if cbOptimizeBlockMon
.Checked
then
331 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_BLOCKMON
]);
332 count
:= OptimizePanels(PANEL_BLOCKMON
);
333 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_PANELS_OPT
]+' '+IntToStr(count
)+#13#10);
337 for a
:= 0 to High(gPanels
) do
338 if gPanels
[a
].PanelType
<> 0 then
339 panelcount2
:= panelcount2
+ 1;
341 mOptimizationResult
.Lines
.Add('-----------------------');
342 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_TOTAL_PANELS
]+' '+IntToStr(panelcount1
));
343 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_PANELS_AFTER
]+' '+IntToStr(panelcount2
));
344 mOptimizationResult
.Lines
.Add(_lc
[I_OPT_PANELS_OPT
]+' '+IntToStr(panelcount1
-panelcount2
));