- Changed light source evaluation
- Fixed possible crash in TLightManager.UpdateOverlay
This commit is contained in:
parent
21e398ae92
commit
a19e23a82e
|
@ -31,7 +31,8 @@ interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, Imaging, ImagingTypes, ImagingClasses, ImagingCanvases,
|
Classes, SysUtils, Imaging, ImagingTypes, ImagingClasses, ImagingCanvases,
|
||||||
ImagingOpenGL, GL, fgl, ULandscape, UWorldItem, UCacheManager;
|
ImagingOpenGL, GL, fgl, ULandscape, UWorldItem, UCacheManager,
|
||||||
|
ImagingUtility;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
@ -106,7 +107,7 @@ type
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
UGameResources, UTiledata, UStatics, ULight, Logging;
|
UGameResources, UTiledata, UStatics, UMap, ULight, Logging;
|
||||||
|
|
||||||
{ TLightManager }
|
{ TLightManager }
|
||||||
|
|
||||||
|
@ -171,9 +172,6 @@ begin
|
||||||
try
|
try
|
||||||
canvas.FillColor32 := color.Color;
|
canvas.FillColor32 := color.Color;
|
||||||
canvas.FillRect(AScreenRect);
|
canvas.FillRect(AScreenRect);
|
||||||
finally
|
|
||||||
canvas.Free;
|
|
||||||
end;
|
|
||||||
|
|
||||||
for i := 0 to FLightSources.Count - 1 do
|
for i := 0 to FLightSources.Count - 1 do
|
||||||
begin
|
begin
|
||||||
|
@ -185,6 +183,9 @@ begin
|
||||||
FLightSources[i].FY - lightMaterial.Graphic.Height div 2);
|
FLightSources[i].FY - lightMaterial.Graphic.Height div 2);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
finally
|
||||||
|
canvas.Free;
|
||||||
|
end;
|
||||||
|
|
||||||
//TODO : PowerOfTwo!!!
|
//TODO : PowerOfTwo!!!
|
||||||
FOverlayTexture := CreateGLTextureFromImage(FOverlay.ImageDataPointer^);
|
FOverlayTexture := CreateGLTextureFromImage(FOverlay.ImageDataPointer^);
|
||||||
|
@ -196,49 +197,58 @@ procedure TLightManager.UpdateLightMap(ALeft, AWidth, ATop, AHeight: Integer;
|
||||||
AScreenBuffer: TScreenBuffer);
|
AScreenBuffer: TScreenBuffer);
|
||||||
var
|
var
|
||||||
blockInfo: PBlockInfo;
|
blockInfo: PBlockInfo;
|
||||||
itemMap, lightMap: array of array of TWorldItem;
|
lights: TWorldItemList;
|
||||||
x, y: Integer;
|
i, x, y, tileID: Integer;
|
||||||
|
tileData: TTiledata;
|
||||||
begin
|
begin
|
||||||
//Logger.EnterMethod([lcClient, lcDebug], 'UpdateLightMap');
|
//Logger.EnterMethod([lcClient, lcDebug], 'UpdateLightMap');
|
||||||
FLightSources.Clear;
|
FLightSources.Clear;
|
||||||
{Logger.Send([lcClient, lcDebug], 'AWidth', AWidth);
|
{Logger.Send([lcClient, lcDebug], 'AWidth', AWidth);
|
||||||
Logger.Send([lcClient, lcDebug], 'AHeight', AHeight);}
|
Logger.Send([lcClient, lcDebug], 'AHeight', AHeight);}
|
||||||
SetLength(itemMap, AWidth, AHeight);
|
lights := TWorldItemList.Create(False);
|
||||||
SetLength(lightMap, AWidth, AHeight);
|
x := -1;
|
||||||
for x := 0 to AWidth - 1 do
|
y := -1;
|
||||||
for y := 0 to AHeight - 1 do
|
|
||||||
begin
|
|
||||||
itemMap[x, y] := nil;
|
|
||||||
lightMap[x, y] := nil;
|
|
||||||
end;
|
|
||||||
|
|
||||||
blockInfo := nil;
|
blockInfo := nil;
|
||||||
while AScreenBuffer.Iterate(blockInfo) do
|
while AScreenBuffer.Iterate(blockInfo) do
|
||||||
begin
|
begin
|
||||||
if blockInfo^.State = ssNormal then
|
if blockInfo^.State = ssNormal then
|
||||||
begin
|
begin
|
||||||
x := blockInfo^.Item.X - ALeft;
|
if (x <> blockInfo^.Item.X) or (y <> blockInfo^.Item.Y) then
|
||||||
y := blockInfo^.Item.Y - ATop;
|
begin
|
||||||
itemMap[x, y] := blockInfo^.Item;
|
for i := 0 to lights.Count - 1 do
|
||||||
if (blockInfo^.Item is TStaticItem) and (tdfLightSource in
|
FLightSources.Add(TLightSource.Create(Self, lights[i]));
|
||||||
ResMan.Tiledata.StaticTiles[blockInfo^.Item.TileID].Flags) then
|
lights.Clear;
|
||||||
lightMap[x, y] := blockInfo^.Item;
|
x := blockInfo^.Item.X;
|
||||||
|
y := blockInfo^.Item.Y;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if blockInfo^.Item is TStaticItem then
|
||||||
|
tileID := blockInfo^.Item.TileID + $4000
|
||||||
|
else
|
||||||
|
tileID := blockInfo^.Item.TileID;
|
||||||
|
tileData := ResMan.Tiledata.TileData[tileID];
|
||||||
|
|
||||||
|
if tdfLightSource in tileData.Flags then
|
||||||
|
begin
|
||||||
|
lights.Add(blockInfo^.Item);
|
||||||
|
end else
|
||||||
|
if (tdfRoof in tileData.Flags) or (blockInfo^.Item is TMapCell) then
|
||||||
|
begin
|
||||||
|
lights.Clear;
|
||||||
|
end else
|
||||||
|
if tdfSurface in tileData.Flags then
|
||||||
|
begin
|
||||||
|
for i := lights.Count - 1 downto 0 do
|
||||||
|
if (blockInfo^.Item.Z > lights[i].Z + 3) and
|
||||||
|
(blockInfo^.Item.Z < lights[i].Z + 30) then
|
||||||
|
lights.Delete(i);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
for x := 0 to AWidth - 2 do
|
for i := 0 to lights.Count - 1 do
|
||||||
for y := 0 to AHeight - 2 do
|
FLightSources.Add(TLightSource.Create(Self, lights[i]));
|
||||||
if lightMap[x, y] <> nil then
|
|
||||||
begin
|
|
||||||
if ((itemMap[x, y] = nil) or (itemMap[x, y].Z < lightMap[x, y].Z + 3)) or
|
|
||||||
((itemMap[x + 1, y] = nil) or (itemMap[x + 1, y].Z < lightMap[x, y].Z + 3)) or
|
|
||||||
((itemMap[x + 1, y + 1] = nil) or (itemMap[x + 1, y + 1].Z <
|
|
||||||
lightMap[x, y].Z + 3)) or ((itemMap[x, y + 1] = nil) or
|
|
||||||
(itemMap[x, y + 1].Z < lightMap[x, y].Z + 3)) then
|
|
||||||
begin
|
|
||||||
FLightSources.Add(TLightSource.Create(Self, lightMap[x, y]));
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
FValid := False;
|
FValid := False;
|
||||||
//Logger.ExitMethod([lcClient, lcDebug], 'UpdateLightMap');
|
//Logger.ExitMethod([lcClient, lcDebug], 'UpdateLightMap');
|
||||||
end;
|
end;
|
||||||
|
|
Loading…
Reference in New Issue