- Moved WriteMap handling from TdmNetwork to TLandscape
- Added repainting when accesslevel display changes (toolstate, update write map)
This commit is contained in:
parent
f888443ed0
commit
c3bdc98219
|
@ -45,7 +45,7 @@ type
|
|||
|
||||
{ TMaterial } //TODO : add ref counting
|
||||
|
||||
TMaterial = class(TObject)
|
||||
TMaterial = class
|
||||
constructor Create(AWidth, AHeight: Integer; AGraphic: TSingleImage);
|
||||
destructor Destroy; override;
|
||||
protected
|
||||
|
@ -69,7 +69,7 @@ type
|
|||
|
||||
{ TLandTextureManager }
|
||||
|
||||
TLandTextureManager = class(TObject)
|
||||
TLandTextureManager = class
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function GetArtMaterial(ATileID: Word): TMaterial; overload;
|
||||
|
@ -97,9 +97,11 @@ type
|
|||
procedure RebuildList;
|
||||
end;
|
||||
|
||||
TLandscape = class;
|
||||
|
||||
{ TBlock }
|
||||
|
||||
TBlock = class(TObject)
|
||||
TBlock = class
|
||||
constructor Create(AMap: TMapBlock; AStatics: TStaticBlock);
|
||||
destructor Destroy; override;
|
||||
protected
|
||||
|
@ -111,7 +113,7 @@ type
|
|||
property Map: TMapBlock read FMapBlock;
|
||||
property Static: TStaticBlock read FStaticBlock;
|
||||
{ Methods }
|
||||
procedure UpdateBlockAcess;
|
||||
procedure UpdateBlockAcess(ALandscape: TLandscape);
|
||||
end;
|
||||
|
||||
TLandscapeChangeEvent = procedure of object;
|
||||
|
@ -123,7 +125,7 @@ type
|
|||
|
||||
{ TLandscape }
|
||||
|
||||
TLandscape = class(TObject)
|
||||
TLandscape = class
|
||||
constructor Create(AWidth, AHeight: Word);
|
||||
destructor Destroy; override;
|
||||
protected
|
||||
|
@ -141,6 +143,7 @@ type
|
|||
FOnStaticElevated: TStaticChangedEvent;
|
||||
FOnStaticHued: TStaticChangedEvent;
|
||||
FOpenRequests: TBits;
|
||||
FWriteMap: TBits;
|
||||
{ Methods }
|
||||
function GetMapBlock(AX, AY: Word): TMapBlock;
|
||||
function GetMapCell(AX, AY: Word): TMapCell;
|
||||
|
@ -177,6 +180,7 @@ type
|
|||
property OnStaticHued: TStaticChangedEvent read FOnStaticHued
|
||||
write FOnStaticHued;
|
||||
{ Methods }
|
||||
function CanWrite(AX, AY: Word): Boolean;
|
||||
procedure FillDrawList(ADrawList: TScreenBuffer; AX, AY, AWidth,
|
||||
AHeight: Word; AMap, AStatics: Boolean; ANoDraw: Boolean;
|
||||
AAdditionalTiles: TList = nil);
|
||||
|
@ -186,6 +190,7 @@ type
|
|||
procedure MoveStatic(AStatic: TStaticItem; AX, AY: Word);
|
||||
procedure PrepareBlocks(AX1, AY1, AX2, AY2: Word);
|
||||
procedure UpdateBlockAccess;
|
||||
procedure UpdateWriteMap(AStream: TEnhancedMemoryStream);
|
||||
end;
|
||||
|
||||
TScreenState = (ssNormal, ssFiltered, ssGhost);
|
||||
|
@ -205,7 +210,7 @@ type
|
|||
|
||||
{ TScreenBuffer }
|
||||
|
||||
TScreenBuffer = class(TObject)
|
||||
TScreenBuffer = class
|
||||
constructor Create; virtual;
|
||||
destructor Destroy; override;
|
||||
protected
|
||||
|
@ -240,7 +245,7 @@ type
|
|||
implementation
|
||||
|
||||
uses
|
||||
UGameResources, UdmNetwork, UPackets, UPacketHandlers;
|
||||
UGameResources, UdmNetwork, UPackets, UPacketHandlers, Logging;
|
||||
|
||||
const
|
||||
mMap = 0;
|
||||
|
@ -452,7 +457,6 @@ begin
|
|||
inherited Create;
|
||||
FMapBlock := AMap;
|
||||
FStaticBlock := AStatics;
|
||||
UpdateBlockAcess;
|
||||
end;
|
||||
|
||||
destructor TBlock.Destroy;
|
||||
|
@ -462,15 +466,15 @@ begin
|
|||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TBlock.UpdateBlockAcess;
|
||||
procedure TBlock.UpdateBlockAcess(ALandscape: TLandscape);
|
||||
var
|
||||
staticItem: TStaticItem;
|
||||
i: Integer;
|
||||
begin
|
||||
for i := Low(FMapBlock.Cells) to High(FMapBlock.Cells) do
|
||||
begin
|
||||
FMapBlock.Cells[i].CanBeEdited := dmNetwork.CanWrite(
|
||||
FMapBlock.Cells[i].X, FMapBlock.Cells[i].Y);
|
||||
FMapBlock.Cells[i].CanBeEdited := ALandscape.CanWrite(FMapBlock.Cells[i].X,
|
||||
FMapBlock.Cells[i].Y);
|
||||
end;
|
||||
|
||||
if FStaticBlock is TSeperatedStaticBlock then
|
||||
|
@ -479,8 +483,8 @@ begin
|
|||
for i := 0 to FStaticBlock.Items.Count - 1 do
|
||||
begin
|
||||
staticItem := TStaticItem(FStaticBlock.Items[i]);
|
||||
staticItem.CanBeEdited := dmNetwork.CanWrite(
|
||||
staticItem.X, staticItem.Y);
|
||||
staticItem.CanBeEdited := ALandscape.CanWrite(staticItem.X,
|
||||
staticItem.Y);
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -488,7 +492,7 @@ end;
|
|||
|
||||
constructor TLandscape.Create(AWidth, AHeight: Word);
|
||||
var
|
||||
blockID: Integer;
|
||||
blockID, i: Integer;
|
||||
begin
|
||||
inherited Create;
|
||||
FWidth := AWidth;
|
||||
|
@ -506,7 +510,10 @@ begin
|
|||
FOnStaticInserted := nil;
|
||||
|
||||
FOpenRequests := TBits.Create(FWidth * FHeight);
|
||||
FOpenRequests.Clearall;
|
||||
FOpenRequests.Clearall; //set all to 0
|
||||
FWriteMap := TBits.Create(FCellWidth * FCellHeight);
|
||||
for i := 0 to FWriteMap.Size - 1 do
|
||||
FWriteMap[i] := True;
|
||||
|
||||
RegisterPacketHandler($04, TPacketHandler.Create(0, @OnBlocksPacket));
|
||||
RegisterPacketHandler($06, TPacketHandler.Create(8, @OnDrawMapPacket));
|
||||
|
@ -525,6 +532,9 @@ begin
|
|||
FreeAndNil(FBlockCache);
|
||||
end;
|
||||
|
||||
FreeAndNil(FOpenRequests);
|
||||
FreeAndNil(FWriteMap);
|
||||
|
||||
RegisterPacketHandler($04, nil);
|
||||
RegisterPacketHandler($06, nil);
|
||||
RegisterPacketHandler($07, nil);
|
||||
|
@ -627,6 +637,7 @@ begin
|
|||
|
||||
FBlockCache.RemoveID(id);
|
||||
block := TBlock.Create(map, statics);
|
||||
block.UpdateBlockAcess(Self);
|
||||
FBlockCache.StoreID(id, block);
|
||||
|
||||
FOpenRequests[coords.Y * FWidth + coords.X] := False;
|
||||
|
@ -650,7 +661,6 @@ begin
|
|||
cell.TileID := ABuffer.ReadWord;
|
||||
if Assigned(FOnMapChanged) then FOnMapChanged(cell);
|
||||
end;
|
||||
//TODO : update surrounding normals
|
||||
end;
|
||||
|
||||
procedure TLandscape.OnInsertStaticPacket(ABuffer: TEnhancedMemoryStream);
|
||||
|
@ -680,7 +690,7 @@ begin
|
|||
i);
|
||||
targetStaticList.Sort(@CompareWorldItems);
|
||||
staticItem.Owner := block;
|
||||
staticItem.CanBeEdited := dmNetwork.CanWrite(x, y);
|
||||
staticItem.CanBeEdited := CanWrite(x, y);
|
||||
|
||||
if Assigned(FOnStaticInserted) then FOnStaticInserted(staticItem);
|
||||
end;
|
||||
|
@ -807,7 +817,7 @@ begin
|
|||
i);
|
||||
statics.Sort(@CompareWorldItems);
|
||||
staticItem.Owner := targetBlock;
|
||||
staticItem.CanBeEdited := dmNetwork.CanWrite(newX, newY);
|
||||
staticItem.CanBeEdited := CanWrite(newX, newY);
|
||||
|
||||
if Assigned(FOnStaticInserted) then FOnStaticInserted(staticItem);
|
||||
end;
|
||||
|
@ -841,6 +851,11 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
function TLandscape.CanWrite(AX, AY: Word): Boolean;
|
||||
begin
|
||||
Result := FWriteMap[AX * FCellHeight + AY];
|
||||
end;
|
||||
|
||||
procedure TLandscape.FillDrawList(ADrawList: TScreenBuffer; AX, AY, AWidth,
|
||||
AHeight: Word; AMap, AStatics: Boolean; ANoDraw: Boolean;
|
||||
AAdditionalTiles: TList = nil);
|
||||
|
@ -1063,7 +1078,41 @@ var
|
|||
begin
|
||||
cacheEntry := nil;
|
||||
while FBlockCache.Iterate(cacheEntry) do
|
||||
TBlock(cacheEntry^.Obj).UpdateBlockAcess;
|
||||
if cacheEntry^.Obj <> nil then
|
||||
TBlock(cacheEntry^.Obj).UpdateBlockAcess(Self);
|
||||
end;
|
||||
|
||||
procedure TLandscape.UpdateWriteMap(AStream: TEnhancedMemoryStream);
|
||||
var
|
||||
x1, y1, x2, y2: Word;
|
||||
i, areaCount, cellX, cellY: Integer;
|
||||
begin
|
||||
Logger.EnterMethod([lcLandscape, lcDebug], 'TLandscape.UpdateWriteMap');
|
||||
|
||||
areaCount := AStream.ReadWord;
|
||||
Logger.Send([lcLandscape, lcDebug], 'AreaCount', areaCount);
|
||||
|
||||
if areaCount > 0 then
|
||||
begin
|
||||
FWriteMap.Clearall;
|
||||
for i := 0 to areaCount - 1 do
|
||||
begin
|
||||
x1 := AStream.ReadWord;
|
||||
y1 := AStream.ReadWord;
|
||||
x2 := AStream.ReadWord;
|
||||
y2 := AStream.ReadWord;
|
||||
for cellX := x1 to x2 do
|
||||
for cellY := y1 to y2 do
|
||||
FWriteMap[cellX * FCellHeight + cellY] := True;
|
||||
end;
|
||||
end else
|
||||
for i := 0 to FWriteMap.Size - 1 do
|
||||
FWriteMap[i] := True;
|
||||
|
||||
Logger.Send([lcLandscape, lcDebug], 'WriteMap @ 0,0', FWriteMap[0]);
|
||||
|
||||
UpdateBlockAccess;
|
||||
Logger.ExitMethod([lcLandscape, lcDebug], 'TLandscape.UpdateWriteMap');
|
||||
end;
|
||||
|
||||
{ TMaterial }
|
||||
|
|
|
@ -31,8 +31,7 @@ interface
|
|||
|
||||
uses
|
||||
Classes, SysUtils, LResources, Forms, Controls, Dialogs, lNetComponents, lNet,
|
||||
UEnhancedMemoryStream, UPacket, UEnums, ExtCtrls, dateutils, URectList,
|
||||
LCLIntf;
|
||||
UEnhancedMemoryStream, UPacket, UEnums, ExtCtrls, dateutils;
|
||||
|
||||
type
|
||||
|
||||
|
@ -57,7 +56,6 @@ type
|
|||
FAccessLevel: TAccessLevel;
|
||||
FDataDir: string;
|
||||
FLastPacket: TDateTime;
|
||||
FWriteMap: TRectList;
|
||||
procedure OnCanSend(ASocket: TLSocket);
|
||||
procedure OnConnectionHandlingPacket(ABuffer: TEnhancedMemoryStream);
|
||||
procedure ProcessQueue;
|
||||
|
@ -65,11 +63,9 @@ type
|
|||
public
|
||||
property Username: string read FUsername;
|
||||
property AccessLevel: TAccessLevel read FAccessLevel write FAccessLevel;
|
||||
function CanWrite(AX, AY: Word): Boolean;
|
||||
procedure Send(APacket: TPacket);
|
||||
procedure Disconnect;
|
||||
procedure CheckClose(ASender: TForm);
|
||||
procedure UpdateWriteMap(AStream: TEnhancedMemoryStream);
|
||||
end;
|
||||
|
||||
var
|
||||
|
@ -102,7 +98,6 @@ begin
|
|||
if FSendQueue <> nil then FreeAndNil(FSendQueue);
|
||||
if FReceiveQueue <> nil then FreeAndNil(FReceiveQueue);
|
||||
if PacketHandlers[$02] <> nil then FreeAndNil(PacketHandlers[$02]);
|
||||
if FWriteMap <> nil then FreeAndNil(FWriteMap);
|
||||
end;
|
||||
|
||||
procedure TdmNetwork.TCPClientConnect(aSocket: TLSocket);
|
||||
|
@ -199,11 +194,7 @@ begin
|
|||
width := ABuffer.ReadWord;
|
||||
height := ABuffer.ReadWord;
|
||||
ResMan.InitLandscape(width, height);
|
||||
|
||||
{FWriteMap := TBits.Create(ResMan.Landscape.CellWidth * ResMan.Landscape.CellHeight);
|
||||
FWriteMap.XorBits(FWriteMap); //set all to 1}
|
||||
FWriteMap := TRectList.Create;
|
||||
UpdateWriteMap(ABuffer);
|
||||
ResMan.Landscape.UpdateWriteMap(ABuffer);
|
||||
|
||||
frmMain := TfrmMain.Create(dmNetwork);
|
||||
frmRadarMap := TfrmRadarMap.Create(frmMain);
|
||||
|
@ -320,7 +311,6 @@ begin
|
|||
frmMain.ApplicationProperties1.OnIdle := nil;
|
||||
FreeAndNil(frmMain);
|
||||
end;
|
||||
if FWriteMap <> nil then FreeAndNil(FWriteMap);
|
||||
if GameResourceManager <> nil then FreeAndNil(GameResourceManager);
|
||||
frmInitialize.Hide;
|
||||
while frmLogin.ShowModal = mrOK do
|
||||
|
@ -340,23 +330,6 @@ begin
|
|||
FreeAndNil(frmLogin);
|
||||
end;
|
||||
|
||||
function TdmNetwork.CanWrite(AX, AY: Word): Boolean;
|
||||
var
|
||||
i: Integer;
|
||||
pt: TPoint;
|
||||
begin
|
||||
if FWriteMap.Count > 0 then
|
||||
begin
|
||||
pt := Point(AX, AY);
|
||||
for i := 0 to FWriteMap.Count - 1 do
|
||||
if PtInRect(FWriteMap.Rects[i], pt) then
|
||||
Exit(True);
|
||||
|
||||
Result := False;
|
||||
end else
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TdmNetwork.Send(APacket: TPacket);
|
||||
var
|
||||
source: TEnhancedMemoryStream;
|
||||
|
@ -386,23 +359,6 @@ begin
|
|||
end;
|
||||
end;
|
||||
|
||||
procedure TdmNetwork.UpdateWriteMap(AStream: TEnhancedMemoryStream);
|
||||
var
|
||||
x1, y1, x2, y2: Word;
|
||||
i, areaCount: Integer;
|
||||
begin
|
||||
FWriteMap.Clear;
|
||||
areaCount := AStream.ReadWord;
|
||||
for i := 0 to areaCount - 1 do
|
||||
begin
|
||||
x1 := AStream.ReadWord;
|
||||
y1 := AStream.ReadWord;
|
||||
x2 := AStream.ReadWord;
|
||||
y2 := AStream.ReadWord;
|
||||
FWriteMap.Add(x1, y1, x2, y2);
|
||||
end;
|
||||
end;
|
||||
|
||||
initialization
|
||||
{$I UdmNetwork.lrs}
|
||||
|
||||
|
|
|
@ -2296,6 +2296,8 @@ begin
|
|||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
FRepaintNeeded := True;
|
||||
end;
|
||||
|
||||
procedure TfrmMain.ProcessAccessLevel;
|
||||
|
@ -2546,8 +2548,8 @@ begin
|
|||
$07: //access changed
|
||||
begin
|
||||
accessLevel := TAccessLevel(ABuffer.ReadByte);
|
||||
dmNetwork.UpdateWriteMap(ABuffer); //TODO : movie writemap to landscape
|
||||
FLandscape.UpdateBlockAccess; //TODO : could be handled by updatewritemap
|
||||
FLandscape.UpdateWriteMap(ABuffer);
|
||||
FRepaintNeeded := True;
|
||||
|
||||
if accessLevel <> dmNetwork.AccessLevel then
|
||||
begin
|
||||
|
|
Loading…
Reference in New Issue