- Added handling of new blocks (OnNewBlock event)

This commit is contained in:
Andreas Schneider 2009-08-03 00:29:55 +02:00
parent 2e16269397
commit 1bc9ad3fe1
2 changed files with 15 additions and 3 deletions

View File

@ -497,6 +497,7 @@ begin
FBlockCache.OnRemoveObject := @OnRemoveCachedObject; FBlockCache.OnRemoveObject := @OnRemoveCachedObject;
FOnChange := nil; FOnChange := nil;
FOnNewBlock := nil;
FOnStaticDeleted := nil; FOnStaticDeleted := nil;
FOnStaticElevated := nil; FOnStaticElevated := nil;
FOnStaticHued := nil; FOnStaticHued := nil;
@ -606,6 +607,7 @@ var
coords: TBlockCoords; coords: TBlockCoords;
count: Word; count: Word;
id: Integer; id: Integer;
block: TBlock;
begin begin
index := TGenericIndex.Create(nil); index := TGenericIndex.Create(nil);
while ABuffer.Position < ABuffer.Size do while ABuffer.Position < ABuffer.Size do
@ -623,12 +625,14 @@ begin
statics := TSeperatedStaticBlock.Create(ABuffer, index, coords.X, coords.Y); statics := TSeperatedStaticBlock.Create(ABuffer, index, coords.X, coords.Y);
FBlockCache.RemoveID(id); FBlockCache.RemoveID(id);
FBlockCache.StoreID(id, TBlock.Create(map, statics)); block := TBlock.Create(map, statics);
FBlockCache.StoreID(id, block);
FOpenRequests[coords.Y * FWidth + coords.X] := False; FOpenRequests[coords.Y * FWidth + coords.X] := False;
if Assigned(FOnNewBlock) then FOnNewBlock(block);
end; end;
index.Free; index.Free;
if Assigned(FOnChange) then FOnChange;
end; end;
procedure TLandscape.OnDrawMapPacket(ABuffer: TEnhancedMemoryStream); procedure TLandscape.OnDrawMapPacket(ABuffer: TEnhancedMemoryStream);

View File

@ -316,6 +316,7 @@ type
{ Events } { Events }
procedure OnClientHandlingPacket(ABuffer: TEnhancedMemoryStream); procedure OnClientHandlingPacket(ABuffer: TEnhancedMemoryStream);
procedure OnLandscapeChanged; procedure OnLandscapeChanged;
procedure OnNewBlock(ABlock: TBlock);
procedure OnStaticDeleted(AStaticItem: TStaticItem); procedure OnStaticDeleted(AStaticItem: TStaticItem);
procedure OnStaticElevated(AStaticItem: TStaticItem); procedure OnStaticElevated(AStaticItem: TStaticItem);
procedure OnStaticInserted(AStaticItem: TStaticItem); procedure OnStaticInserted(AStaticItem: TStaticItem);
@ -722,6 +723,7 @@ var
begin begin
FLandscape := ResMan.Landscape; FLandscape := ResMan.Landscape;
FLandscape.OnChange := @OnLandscapeChanged; FLandscape.OnChange := @OnLandscapeChanged;
FLandscape.OnNewBlock := @OnNewBlock;
FLandscape.OnStaticDeleted := @OnStaticDeleted; FLandscape.OnStaticDeleted := @OnStaticDeleted;
FLandscape.OnStaticElevated := @OnStaticElevated; FLandscape.OnStaticElevated := @OnStaticElevated;
FLandscape.OnStaticInserted := @OnStaticInserted; FLandscape.OnStaticInserted := @OnStaticInserted;
@ -1790,7 +1792,6 @@ begin
item := blockInfo^.Item; item := blockInfo^.Item;
//TODO : implement CanBeEdited handling (dmNetwork.CanWrite.....)
if acSelect.Checked or item.CanBeEdited then if acSelect.Checked or item.CanBeEdited then
begin begin
intensity := 1.0; intensity := 1.0;
@ -2025,9 +2026,15 @@ begin
UpdateCurrentTile; UpdateCurrentTile;
end; end;
procedure TfrmMain.OnNewBlock(ABlock: TBlock);
begin
InvalidateScreenBuffer;
end;
procedure TfrmMain.OnStaticDeleted(AStaticItem: TStaticItem); procedure TfrmMain.OnStaticDeleted(AStaticItem: TStaticItem);
begin begin
FScreenBuffer.Delete(AStaticItem); FScreenBuffer.Delete(AStaticItem);
UpdateCurrentTile;
end; end;
procedure TfrmMain.OnStaticElevated(AStaticItem: TStaticItem); procedure TfrmMain.OnStaticElevated(AStaticItem: TStaticItem);
@ -2042,6 +2049,7 @@ begin
begin begin
AStaticItem.PrioritySolver := FScreenBuffer.GetSerial; AStaticItem.PrioritySolver := FScreenBuffer.GetSerial;
PrepareScreenBlock(FScreenBuffer.Insert(AStaticItem)); PrepareScreenBlock(FScreenBuffer.Insert(AStaticItem));
UpdateCurrentTile;
end; end;
end; end;