- Added some more comments to ULandscape.pas
- Renamed a somewhat unclearly named series of local variables ("item" --> "subscriptionItem") to better suite its context
This commit is contained in:
parent
45537315b5
commit
114c218ca6
|
@ -532,7 +532,7 @@ var
|
||||||
x, y: Word;
|
x, y: Word;
|
||||||
cell: TMapCell;
|
cell: TMapCell;
|
||||||
subscriptions: TLinkedList;
|
subscriptions: TLinkedList;
|
||||||
item: PLinkedItem;
|
subscriptionItem: PLinkedItem;
|
||||||
packet: TDrawMapPacket;
|
packet: TDrawMapPacket;
|
||||||
begin
|
begin
|
||||||
x := ABuffer.ReadWord;
|
x := ABuffer.ReadWord;
|
||||||
|
@ -548,9 +548,9 @@ begin
|
||||||
|
|
||||||
packet := TDrawMapPacket.Create(cell);
|
packet := TDrawMapPacket.Create(cell);
|
||||||
subscriptions := FBlockSubscriptions[(y div 8) * FWidth + (x div 8)];
|
subscriptions := FBlockSubscriptions[(y div 8) * FWidth + (x div 8)];
|
||||||
item := nil;
|
subscriptionItem := nil;
|
||||||
while subscriptions.Iterate(item) do
|
while subscriptions.Iterate(subscriptionItem) do
|
||||||
CEDServerInstance.SendPacket(TNetState(item^.Data), packet, False);
|
CEDServerInstance.SendPacket(TNetState(subscriptionItem^.Data), packet, False);
|
||||||
packet.Free;
|
packet.Free;
|
||||||
|
|
||||||
UpdateRadar(x, y);
|
UpdateRadar(x, y);
|
||||||
|
@ -565,7 +565,7 @@ var
|
||||||
staticItem: TStaticItem;
|
staticItem: TStaticItem;
|
||||||
targetStaticList: TList;
|
targetStaticList: TList;
|
||||||
subscriptions: TLinkedList;
|
subscriptions: TLinkedList;
|
||||||
item: PLinkedItem;
|
subscriptionItem: PLinkedItem;
|
||||||
packet: TInsertStaticPacket;
|
packet: TInsertStaticPacket;
|
||||||
begin
|
begin
|
||||||
x := ABuffer.ReadWord;
|
x := ABuffer.ReadWord;
|
||||||
|
@ -589,9 +589,9 @@ begin
|
||||||
|
|
||||||
packet := TInsertStaticPacket.Create(staticItem);
|
packet := TInsertStaticPacket.Create(staticItem);
|
||||||
subscriptions := FBlockSubscriptions[(y div 8) * FWidth + (x div 8)];
|
subscriptions := FBlockSubscriptions[(y div 8) * FWidth + (x div 8)];
|
||||||
item := nil;
|
subscriptionItem := nil;
|
||||||
while subscriptions.Iterate(item) do
|
while subscriptions.Iterate(subscriptionItem) do
|
||||||
CEDServerInstance.SendPacket(TNetState(item^.Data), packet, False);
|
CEDServerInstance.SendPacket(TNetState(subscriptionItem^.Data), packet, False);
|
||||||
packet.Free;
|
packet.Free;
|
||||||
|
|
||||||
UpdateRadar(x, y);
|
UpdateRadar(x, y);
|
||||||
|
@ -607,7 +607,7 @@ var
|
||||||
staticInfo: TStaticInfo;
|
staticInfo: TStaticInfo;
|
||||||
staticItem: TStaticItem;
|
staticItem: TStaticItem;
|
||||||
subscriptions: TLinkedList;
|
subscriptions: TLinkedList;
|
||||||
item: PLinkedItem;
|
subscriptionItem: PLinkedItem;
|
||||||
packet: TDeleteStaticPacket;
|
packet: TDeleteStaticPacket;
|
||||||
begin
|
begin
|
||||||
ABuffer.Read(staticInfo, SizeOf(TStaticInfo));
|
ABuffer.Read(staticInfo, SizeOf(TStaticInfo));
|
||||||
|
@ -631,9 +631,9 @@ begin
|
||||||
staticItem.Delete;
|
staticItem.Delete;
|
||||||
|
|
||||||
subscriptions := FBlockSubscriptions[(staticInfo.Y div 8) * FWidth + (staticInfo.X div 8)];
|
subscriptions := FBlockSubscriptions[(staticInfo.Y div 8) * FWidth + (staticInfo.X div 8)];
|
||||||
item := nil;
|
subscriptionItem := nil;
|
||||||
while subscriptions.Iterate(item) do
|
while subscriptions.Iterate(subscriptionItem) do
|
||||||
CEDServerInstance.SendPacket(TNetState(item^.Data), packet, False);
|
CEDServerInstance.SendPacket(TNetState(subscriptionItem^.Data), packet, False);
|
||||||
packet.Free;
|
packet.Free;
|
||||||
|
|
||||||
UpdateRadar(staticInfo.X, staticInfo.Y);
|
UpdateRadar(staticInfo.X, staticInfo.Y);
|
||||||
|
@ -654,7 +654,7 @@ var
|
||||||
staticItem: TStaticItem;
|
staticItem: TStaticItem;
|
||||||
newZ: ShortInt;
|
newZ: ShortInt;
|
||||||
subscriptions: TLinkedList;
|
subscriptions: TLinkedList;
|
||||||
item: PLinkedItem;
|
subscriptionItem: PLinkedItem;
|
||||||
packet: TElevateStaticPacket;
|
packet: TElevateStaticPacket;
|
||||||
begin
|
begin
|
||||||
ABuffer.Read(staticInfo, SizeOf(TStaticInfo));
|
ABuffer.Read(staticInfo, SizeOf(TStaticInfo));
|
||||||
|
@ -679,9 +679,9 @@ begin
|
||||||
SortStaticsList(statics);
|
SortStaticsList(statics);
|
||||||
|
|
||||||
subscriptions := FBlockSubscriptions[(staticInfo.Y div 8) * FWidth + (staticInfo.X div 8)];
|
subscriptions := FBlockSubscriptions[(staticInfo.Y div 8) * FWidth + (staticInfo.X div 8)];
|
||||||
item := nil;
|
subscriptionItem := nil;
|
||||||
while subscriptions.Iterate(item) do
|
while subscriptions.Iterate(subscriptionItem) do
|
||||||
CEDServerInstance.SendPacket(TNetState(item^.Data), packet, False);
|
CEDServerInstance.SendPacket(TNetState(subscriptionItem^.Data), packet, False);
|
||||||
packet.Free;
|
packet.Free;
|
||||||
|
|
||||||
UpdateRadar(staticInfo.X, staticInfo.Y);
|
UpdateRadar(staticInfo.X, staticInfo.Y);
|
||||||
|
@ -703,7 +703,7 @@ var
|
||||||
staticItem: TStaticItem;
|
staticItem: TStaticItem;
|
||||||
newX, newY: Word;
|
newX, newY: Word;
|
||||||
subscriptions: TLinkedList;
|
subscriptions: TLinkedList;
|
||||||
item: PLinkedItem;
|
subscriptionItem: PLinkedItem;
|
||||||
insertPacket: TInsertStaticPacket;
|
insertPacket: TInsertStaticPacket;
|
||||||
deletePacket: TDeleteStaticPacket;
|
deletePacket: TDeleteStaticPacket;
|
||||||
movePacket: TMoveStaticPacket;
|
movePacket: TMoveStaticPacket;
|
||||||
|
@ -757,15 +757,15 @@ begin
|
||||||
|
|
||||||
sourceSubscriptions := TList.Create;
|
sourceSubscriptions := TList.Create;
|
||||||
subscriptions := FBlockSubscriptions[(staticInfo.Y div 8) * FWidth + (staticInfo.X div 8)];
|
subscriptions := FBlockSubscriptions[(staticInfo.Y div 8) * FWidth + (staticInfo.X div 8)];
|
||||||
item := nil;
|
subscriptionItem := nil;
|
||||||
while subscriptions.Iterate(item) do
|
while subscriptions.Iterate(subscriptionItem) do
|
||||||
sourceSubscriptions.Add(item^.Data);
|
sourceSubscriptions.Add(subscriptionItem^.Data);
|
||||||
|
|
||||||
targetSubscriptions := TList.Create;
|
targetSubscriptions := TList.Create;
|
||||||
subscriptions := FBlockSubscriptions[(newY div 8) * FWidth + (newX div 8)];
|
subscriptions := FBlockSubscriptions[(newY div 8) * FWidth + (newX div 8)];
|
||||||
item := nil;
|
subscriptionItem := nil;
|
||||||
while subscriptions.Iterate(item) do
|
while subscriptions.Iterate(subscriptionItem) do
|
||||||
targetSubscriptions.Add(item^.Data);
|
targetSubscriptions.Add(subscriptionItem^.Data);
|
||||||
|
|
||||||
for i := 0 to sourceSubscriptions.Count - 1 do
|
for i := 0 to sourceSubscriptions.Count - 1 do
|
||||||
begin
|
begin
|
||||||
|
@ -801,7 +801,7 @@ var
|
||||||
staticItem: TStaticItem;
|
staticItem: TStaticItem;
|
||||||
newHue: Word;
|
newHue: Word;
|
||||||
subscriptions: TLinkedList;
|
subscriptions: TLinkedList;
|
||||||
item: PLinkedItem;
|
subscriptionItem: PLinkedItem;
|
||||||
packet: THueStaticPacket;
|
packet: THueStaticPacket;
|
||||||
begin
|
begin
|
||||||
ABuffer.Read(staticInfo, SizeOf(TStaticInfo));
|
ABuffer.Read(staticInfo, SizeOf(TStaticInfo));
|
||||||
|
@ -825,9 +825,9 @@ begin
|
||||||
staticItem.Hue := newHue;
|
staticItem.Hue := newHue;
|
||||||
|
|
||||||
subscriptions := FBlockSubscriptions[(staticInfo.Y div 8) * FWidth + (staticInfo.X div 8)];
|
subscriptions := FBlockSubscriptions[(staticInfo.Y div 8) * FWidth + (staticInfo.X div 8)];
|
||||||
item := nil;
|
subscriptionItem := nil;
|
||||||
while subscriptions.Iterate(item) do
|
while subscriptions.Iterate(subscriptionItem) do
|
||||||
CEDServerInstance.SendPacket(TNetState(item^.Data), packet, False);
|
CEDServerInstance.SendPacket(TNetState(subscriptionItem^.Data), packet, False);
|
||||||
packet.Free;
|
packet.Free;
|
||||||
|
|
||||||
Break;
|
Break;
|
||||||
|
@ -857,7 +857,7 @@ var
|
||||||
end;
|
end;
|
||||||
netState: TNetState;
|
netState: TNetState;
|
||||||
subscriptions: TLinkedList;
|
subscriptions: TLinkedList;
|
||||||
item: PLinkedItem;
|
subscriptionItem: PLinkedItem;
|
||||||
cmOperation: TLSCopyMove;
|
cmOperation: TLSCopyMove;
|
||||||
additionalAffectedBlocks: TBits;
|
additionalAffectedBlocks: TBits;
|
||||||
begin
|
begin
|
||||||
|
@ -871,6 +871,10 @@ begin
|
||||||
SetLength(bitMask, FWidth * FHeight);
|
SetLength(bitMask, FWidth * FHeight);
|
||||||
for i := Low(bitMask) to High(bitMask) do
|
for i := Low(bitMask) to High(bitMask) do
|
||||||
bitMask[i] := TBits.Create(64);
|
bitMask[i] := TBits.Create(64);
|
||||||
|
//'additionalAffectedBlocks' is used to store whether a certain block was
|
||||||
|
//touched during an operation which was designated to another block (for
|
||||||
|
//example by moving items with an offset). This is (indirectly) merged later
|
||||||
|
//on.
|
||||||
additionalAffectedBlocks := TBits.Create(FWidth * FHeight);
|
additionalAffectedBlocks := TBits.Create(FWidth * FHeight);
|
||||||
|
|
||||||
areaCount := ABuffer.ReadByte;
|
areaCount := ABuffer.ReadByte;
|
||||||
|
@ -985,14 +989,16 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
//Find out, which clients are affected by which blocks.
|
||||||
|
//This is used to efficiently update the block subscriptions.
|
||||||
subscriptions := FBlockSubscriptions[realBlockY * FWidth + realBlockX];
|
subscriptions := FBlockSubscriptions[realBlockY * FWidth + realBlockX];
|
||||||
for i := Low(clients) to High(clients) do
|
for i := Low(clients) to High(clients) do
|
||||||
begin
|
begin
|
||||||
item := nil;
|
subscriptionItem := nil;
|
||||||
while subscriptions.Iterate(item) do
|
while subscriptions.Iterate(subscriptionItem) do
|
||||||
begin
|
begin
|
||||||
if TNetState(item^.Data) = clients[i].NetState then
|
if TNetState(subscriptionItem^.Data) = clients[i].NetState then
|
||||||
begin
|
begin
|
||||||
SetLength(clients[i].Blocks, Length(clients[i].Blocks) + 1);
|
SetLength(clients[i].Blocks, Length(clients[i].Blocks) + 1);
|
||||||
with clients[i].Blocks[High(clients[i].Blocks)] do
|
with clients[i].Blocks[High(clients[i].Blocks)] do
|
||||||
|
@ -1016,13 +1022,15 @@ begin
|
||||||
blockID := (blockX * FHeight) + blockY;
|
blockID := (blockX * FHeight) + blockY;
|
||||||
if bitMask[blockID].Equals(emptyBits) and additionalAffectedBlocks[blockID] then
|
if bitMask[blockID].Equals(emptyBits) and additionalAffectedBlocks[blockID] then
|
||||||
begin
|
begin
|
||||||
|
//Update the information, which client is affected on which subscribed
|
||||||
|
//block.
|
||||||
subscriptions := FBlockSubscriptions[blockY * FWidth + blockX];
|
subscriptions := FBlockSubscriptions[blockY * FWidth + blockX];
|
||||||
for i := Low(clients) to High(clients) do
|
for i := Low(clients) to High(clients) do
|
||||||
begin
|
begin
|
||||||
item := nil;
|
subscriptionItem := nil;
|
||||||
while subscriptions.Iterate(item) do
|
while subscriptions.Iterate(subscriptionItem) do
|
||||||
begin
|
begin
|
||||||
if TNetState(item^.Data) = clients[i].NetState then
|
if TNetState(subscriptionItem^.Data) = clients[i].NetState then
|
||||||
begin
|
begin
|
||||||
SetLength(clients[i].Blocks, Length(clients[i].Blocks) + 1);
|
SetLength(clients[i].Blocks, Length(clients[i].Blocks) + 1);
|
||||||
with clients[i].Blocks[High(clients[i].Blocks)] do
|
with clients[i].Blocks[High(clients[i].Blocks)] do
|
||||||
|
|
Loading…
Reference in New Issue