- Added iterator to TCacheManager

- Added access (CanBeWritten) tracking to TStaticItem
- Moved TLandscape.UpdateStaticsPriorities to TStaticItem.UpdatePriorities
- Moved ULandscape.CompareWorldItems to UWorldItem
- Renamed TSeperatedStaticBlock.RefreshList to RebuildList
- Changed TStaticBlock.Sort to use CompareWorldItems and TList.Sort
- Some code style changes
This commit is contained in:
2009-08-02 13:45:26 +02:00
parent f3888db49c
commit b70f03ba2a
8 changed files with 470 additions and 430 deletions

View File

@@ -88,11 +88,15 @@ type
constructor Create(AMap: TMapBlock; AStatics: TStaticBlock);
destructor Destroy; override;
protected
{ Fields }
FMapBlock: TMapBlock;
FStaticBlock: TStaticBlock;
public
{ Fields }
property Map: TMapBlock read FMapBlock;
property Static: TStaticBlock read FStaticBlock;
{ Methods }
procedure UpdateBlockAcess;
end;
TLandscapeChangeEvent = procedure of object;
@@ -148,8 +152,7 @@ type
procedure GetNormals(AX, AY: Word; var ANormals: TNormals);
procedure MoveStatic(AStatic: TStaticItem; AX, AY: Word);
procedure PrepareBlocks(AX1, AY1, AX2, AY2: Word);
procedure UpdateStaticsPriority(AStaticItem: TStaticItem;
APrioritySolver: Integer);
procedure UpdateBlockAccess;
end;
TScreenState = (ssNormal, ssFiltered, ssGhost);
@@ -185,8 +188,8 @@ type
procedure Delete(AItem: TWorldItem);
function Find(AScreenPosition: TPoint): PBlockInfo;
function GetSerial: Cardinal;
function Iterate(var ABlockInfo: PBlockInfo): Boolean;
function Insert(AItem: TWorldItem): PBlockInfo;
function Iterate(var ABlockInfo: PBlockInfo): Boolean;
procedure Sort;
procedure UpdateShortcuts;
{ Events }
@@ -215,30 +218,6 @@ begin
Result := ((AX and $7FFF) shl 15) or (AY and $7FFF);
end;
function CompareWorldItems(AItem1, AItem2: Pointer): Integer;
begin
if TWorldItem(AItem1).X <> TWorldItem(AItem2).X then
Exit(TWorldItem(AItem1).X - TWorldItem(AItem2).X);
if TWorldItem(AItem1).Y <> TWorldItem(AItem2).Y then
Exit(TWorldItem(AItem1).Y - TWorldItem(AItem2).Y);
Result := TWorldItem(AItem1).Priority - TWorldItem(AItem2).Priority;
if Result = 0 then
begin
if (TObject(AItem1) is TMapCell) and (TObject(AItem2) is TStaticItem) then
Result := -1
else if (TObject(AItem1) is TStaticItem) and (TObject(AItem2) is TMapCell) then
Result := 1;
end;
if Result = 0 then
Result := TWorldItem(AItem1).PriorityBonus - TWorldItem(AItem2).PriorityBonus;
if Result = 0 then
Result := TWorldItem(AItem1).PrioritySolver - TWorldItem(AItem2).PrioritySolver;
end;
{ TLandTextureManager }
constructor TLandTextureManager.Create;
@@ -342,6 +321,7 @@ begin
inherited Create;
FMapBlock := AMap;
FStaticBlock := AStatics;
UpdateBlockAcess;
end;
destructor TBlock.Destroy;
@@ -351,6 +331,28 @@ begin
inherited Destroy;
end;
procedure TBlock.UpdateBlockAcess;
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);
end;
if FStaticBlock is TSeperatedStaticBlock then
TSeperatedStaticBlock(FStaticBlock).RebuildList; //fill items
for i := 0 to FStaticBlock.Items.Count - 1 do
begin
staticItem := TStaticItem(FStaticBlock.Items[i]);
staticItem.CanBeEdited := dmNetwork.CanWrite(
staticItem.X, staticItem.Y);
end;
end;
{ TLandscape }
constructor TLandscape.Create(AWidth, AHeight: Word);
@@ -533,7 +535,7 @@ begin
targetStaticList := block.Cells[(y mod 8) * 8 + x mod 8];
targetStaticList.Add(staticItem);
for i := 0 to targetStaticList.Count - 1 do
UpdateStaticsPriority(TStaticItem(targetStaticList.Items[i]), i);
TStaticItem(targetStaticList.Items[i]).UpdatePriorities(i);
targetStaticList.Sort(@CompareWorldItems);
staticItem.Owner := block;
if Assigned(FOnChange) then FOnChange;
@@ -591,7 +593,7 @@ begin
begin
staticItem.Z := ABuffer.ReadShortInt;
for j := 0 to statics.Count - 1 do
UpdateStaticsPriority(TStaticItem(statics.Items[j]), j);
TStaticItem(statics.Items[j]).UpdatePriorities(j);
statics.Sort(@CompareWorldItems);
if Assigned(FOnChange) then FOnChange;
Break;
@@ -650,7 +652,7 @@ begin
statics := targetBlock.Cells[(newY mod 8) * 8 + newX mod 8];
statics.Add(staticItem);
for i := 0 to statics.Count - 1 do
UpdateStaticsPriority(TStaticItem(statics.Items[i]), i);
TStaticItem(statics.Items[i]).UpdatePriorities(i);
statics.Sort(@CompareWorldItems);
staticItem.Owner := targetBlock;
end;
@@ -724,7 +726,7 @@ begin
(TStaticItem(drawStatics[i]).Z <= AMaxZ) and
((AStaticsFilter = nil) or AStaticsFilter(TStaticItem(drawStatics[i]))) then
begin
UpdateStaticsPriority(TStaticItem(drawStatics[i]), ADrawList.GetSerial);
TStaticItem(drawStatics[i]).UpdatePriorities(ADrawList.GetSerial);
ADrawList.Add(TWorldItem(drawStatics[i]));
end;
end;
@@ -857,7 +859,7 @@ begin
targetStaticList := targetBlock.Cells[(AY mod 8) * 8 + AX mod 8];
targetStaticList.Add(AStatic);
for i := 0 to targetStaticList.Count - 1 do
UpdateStaticsPriority(TStaticItem(targetStaticList.Items[i]), i);
TStaticItem(targetStaticList.Items[i]).UpdatePriorities(i);
targetStaticList.Sort(@CompareWorldItems);
AStatic.UpdatePos(AX, AY, AStatic.Z);
AStatic.Owner := targetBlock;
@@ -896,19 +898,13 @@ begin
dmNetwork.Send(TRequestBlocksPacket.Create(coords));
end;
procedure TLandscape.UpdateStaticsPriority(AStaticItem: TStaticItem;
APrioritySolver: Integer);
procedure TLandscape.UpdateBlockAccess;
var
staticTileData: TStaticTileData;
cacheEntry: PCacheEntry;
begin
staticTileData := ResMan.Tiledata.StaticTiles[AStaticItem.TileID];
AStaticItem.PriorityBonus := 0;
if not ((staticTileData.Flags and tdfBackground) = tdfBackground) then
AStaticItem.PriorityBonus := AStaticItem.PriorityBonus + 1;
if staticTileData.Height > 0 then
AStaticItem.PriorityBonus := AStaticItem.PriorityBonus + 1;
AStaticItem.Priority := AStaticItem.Z + AStaticItem.PriorityBonus;
AStaticItem.PrioritySolver := APrioritySolver;
cacheEntry := nil;
while FBlockCache.Iterate(cacheEntry) do
TBlock(cacheEntry^.Obj).UpdateBlockAcess;
end;
{ TMaterial }
@@ -1087,15 +1083,6 @@ begin
Inc(FSerial);
end;
function TScreenBuffer.Iterate(var ABlockInfo: PBlockInfo): Boolean;
begin
if ABlockInfo = nil then
ABlockInfo := FShortCuts[0]
else
ABlockInfo := ABlockInfo^.Next;
Result := ABlockInfo <> nil;
end;
function TScreenBuffer.Insert(AItem: TWorldItem): PBlockInfo;
var
current: PBlockInfo;
@@ -1145,6 +1132,15 @@ begin
Inc(FCount);
end;
function TScreenBuffer.Iterate(var ABlockInfo: PBlockInfo): Boolean;
begin
if ABlockInfo = nil then
ABlockInfo := FShortCuts[0]
else
ABlockInfo := ABlockInfo^.Next;
Result := ABlockInfo <> nil;
end;
//Mergesort
procedure TScreenBuffer.Sort;

View File

@@ -1,24 +1,28 @@
object dmNetwork: TdmNetwork
OnCreate = DataModuleCreate
OnDestroy = DataModuleDestroy
Height = 300
HorizontalOffset = 290
VerticalOffset = 171
Width = 400
object TCPClient: TLTCPComponent
OnReceive = TCPClientReceive
OnError = TCPClientError
OnDisconnect = TCPClientDisconnect
OnConnect = TCPClientConnect
left = 40
top = 24
end
object tmNoOp: TTimer
Enabled = False
Interval = 30000
OnTimer = tmNoOpTimer
OnStartTimer = tmNoOpStartTimer
left = 72
top = 24
end
end
object dmNetwork: TdmNetwork
OnCreate = DataModuleCreate
OnDestroy = DataModuleDestroy
OldCreateOrder = False
Height = 300
HorizontalOffset = 290
VerticalOffset = 171
Width = 400
object TCPClient: TLTCPComponent
Port = 0
OnReceive = TCPClientReceive
OnError = TCPClientError
OnDisconnect = TCPClientDisconnect
OnConnect = TCPClientConnect
Timeout = 0
ReuseAddress = False
left = 40
top = 24
end
object tmNoOp: TTimer
Enabled = False
Interval = 30000
OnTimer = tmNoOpTimer
OnStartTimer = tmNoOpStartTimer
left = 72
top = 24
end
end

View File

@@ -345,14 +345,16 @@ var
i: Integer;
pt: TPoint;
begin
if FWriteMap.Count = 0 then Exit(True); //TODO : still too slow
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);
pt := Point(AX, AY);
for i := 0 to FWriteMap.Count - 1 do
if PtInRect(FWriteMap.Rects[i], pt) then
Exit(True);
Result := False;
Result := False;
end else
Result := True;
end;
procedure TdmNetwork.Send(APacket: TPacket);

View File

@@ -3,6 +3,7 @@ object frmMain: TfrmMain
Height = 603
Top = 126
Width = 766
ActiveControl = oglGameWindow
Caption = 'UO CentrED'
ClientHeight = 580
ClientWidth = 766
@@ -540,7 +541,7 @@ object frmMain: TfrmMain
Top = 306
Width = 218
Align = alNone
Anchors = [akTop, akLeft, akRight]
Anchors = [akLeft, akRight, akBottom]
ResizeAnchor = akBottom
end
object edSearchID: TEdit
@@ -1110,7 +1111,7 @@ object frmMain: TfrmMain
Top = 435
Width = 542
Align = alNone
Anchors = [akLeft, akRight]
Anchors = [akLeft, akRight, akBottom]
AutoSnap = False
ResizeAnchor = akBottom
Visible = False

View File

@@ -1662,7 +1662,6 @@ var
tileRect: TRect;
virtualTile: TVirtualTile;
staticsFilter: TStaticFilter;
editing: Boolean;
intensity: GLfloat;
blockInfo: PBlockInfo;
item: TWorldItem;
@@ -1688,19 +1687,17 @@ begin
//TODO : implement CanBeEdited handling (dmNetwork.CanWrite.....)
if acSelect.Checked or item.CanBeEdited then
begin
editing := True;
intensity := 1.0;
SetNormalLights;
end else
begin
editing := False;
intensity := 0.5;
SetDarkLights;
end;
glColor4f(intensity, intensity, intensity, 1.0);
highlight := item.CanBeEdited and blockInfo^.Highlighted;
highlight := blockInfo^.Highlighted and item.CanBeEdited;
if highlight then
begin
@@ -2357,7 +2354,8 @@ begin
$07: //access changed
begin
accessLevel := TAccessLevel(ABuffer.ReadByte);
dmNetwork.UpdateWriteMap(ABuffer);
dmNetwork.UpdateWriteMap(ABuffer); //TODO : movie writemap to landscape
FLandscape.UpdateBlockAccess; //TODO : could be handled by updatewritemap
if accessLevel <> dmNetwork.AccessLevel then
begin