- 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,21 +172,21 @@ begin
|
||||||
try
|
try
|
||||||
canvas.FillColor32 := color.Color;
|
canvas.FillColor32 := color.Color;
|
||||||
canvas.FillRect(AScreenRect);
|
canvas.FillRect(AScreenRect);
|
||||||
|
|
||||||
|
for i := 0 to FLightSources.Count - 1 do
|
||||||
|
begin
|
||||||
|
lightMaterial := FLightSources[i].Material;
|
||||||
|
if lightMaterial <> nil then
|
||||||
|
begin
|
||||||
|
lightMaterial.Canvas.DrawAdd(lightMaterial.Canvas.ClipRect, canvas,
|
||||||
|
FLightSources[i].FX - lightMaterial.Graphic.Width div 2,
|
||||||
|
FLightSources[i].FY - lightMaterial.Graphic.Height div 2);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
finally
|
finally
|
||||||
canvas.Free;
|
canvas.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
for i := 0 to FLightSources.Count - 1 do
|
|
||||||
begin
|
|
||||||
lightMaterial := FLightSources[i].Material;
|
|
||||||
if lightMaterial <> nil then
|
|
||||||
begin
|
|
||||||
lightMaterial.Canvas.DrawAdd(lightMaterial.Canvas.ClipRect, canvas,
|
|
||||||
FLightSources[i].FX - lightMaterial.Graphic.Width div 2,
|
|
||||||
FLightSources[i].FY - lightMaterial.Graphic.Height div 2);
|
|
||||||
end;
|
|
||||||
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;
|
||||||
|
@ -251,14 +261,14 @@ begin
|
||||||
glBindTexture(GL_TEXTURE_2D, FOverlayTexture);
|
glBindTexture(GL_TEXTURE_2D, FOverlayTexture);
|
||||||
glBlendFunc(GL_ZERO, GL_SRC_COLOR);
|
glBlendFunc(GL_ZERO, GL_SRC_COLOR);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glTexCoord2i(0, 0);
|
glTexCoord2i(0, 0);
|
||||||
glVertex2i(AScreenRect.Left, AScreenRect.Top);
|
glVertex2i(AScreenRect.Left, AScreenRect.Top);
|
||||||
glTexCoord2i(0, 1);
|
glTexCoord2i(0, 1);
|
||||||
glVertex2i(AScreenRect.Left, AScreenRect.Bottom);
|
glVertex2i(AScreenRect.Left, AScreenRect.Bottom);
|
||||||
glTexCoord2i(1, 1);
|
glTexCoord2i(1, 1);
|
||||||
glVertex2i(AScreenRect.Right, AScreenRect.Bottom);
|
glVertex2i(AScreenRect.Right, AScreenRect.Bottom);
|
||||||
glTexCoord2i(1, 0);
|
glTexCoord2i(1, 0);
|
||||||
glVertex2i(AScreenRect.Right, AScreenRect.Top);
|
glVertex2i(AScreenRect.Right, AScreenRect.Top);
|
||||||
glEnd;
|
glEnd;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue