- Fixed cedserver to compile again (using generics now)

- Added multilog dependency to cedserver for easier debugging
- Several code cleanups
This commit is contained in:
Andreas Schneider 2009-12-04 23:30:39 +01:00
parent 2fedab62cc
commit b223f44721
6 changed files with 106 additions and 109 deletions

View File

@ -295,13 +295,12 @@
<CodeGeneration>
<SmartLinkUnit Value="True"/>
<Optimizations>
<OptimizationLevel Value="0"/>
<OptimizationLevel Value="3"/>
</Optimizations>
</CodeGeneration>
<Linking>
<Debugging>
<GenerateDebugInfo Value="True"/>
<UseHeaptrc Value="True"/>
<UseLineInfoUnit Value="False"/>
</Debugging>
<LinkSmart Value="True"/>
<Options>

View File

@ -72,7 +72,7 @@ var
implementation
uses
UClientHandling;
Logging, UClientHandling;
{$I version.inc}
@ -250,9 +250,13 @@ begin
end;
ANetState.LastAction := Now;
except
on E: Exception do
begin
Logger.SendException([lcServer], 'Error processing buffer', E);
Writeln(TimeStamp, 'Error processing buffer of client: ', ANetState.Socket.PeerAddress);
end;
end;
end;
procedure TCEDServer.CheckNetStates;
var

View File

@ -21,7 +21,7 @@
* CDDL HEADER END
*
*
* Portions Copyright 2008 Andreas Schneider
* Portions Copyright 2009 Andreas Schneider
*)
unit ULandscape;
@ -51,7 +51,7 @@ type
FTiledataProvider: TTiledataProvider;
public
{ Fields }
Cells: array[0..63] of TList;
Cells: array[0..63] of TStaticItemList;
property TiledataProvider: TTiledataProvider read FTiledataProvider write FTiledataProvider;
{ Methods }
@ -98,7 +98,7 @@ type
procedure OnBlockChanged(ABlock: TMulBlock);
procedure OnRemoveCachedObject(AObject: TObject);
function GetMapCell(AX, AY: Word): TMapCell;
function GetStaticList(AX, AY: Word): TList;
function GetStaticList(AX, AY: Word): TStaticItemList;
function GetBlockSubscriptions(AX, AY: Word): TLinkedList;
procedure OnDrawMapPacket(ABuffer: TEnhancedMemoryStream;
@ -121,7 +121,7 @@ type
property CellWidth: Word read FCellWidth;
property CellHeight: Word read FCellHeight;
property MapCell[X, Y: Word]: TMapCell read GetMapCell;
property StaticList[X, Y: Word]: TList read GetStaticList;
property StaticList[X, Y: Word]: TStaticItemList read GetStaticList;
property BlockSubscriptions[X, Y: Word]: TLinkedList read GetBlockSubscriptions;
property TiledataProvider: TTiledataProvider read FTiledataProvider;
@ -132,7 +132,7 @@ type
procedure UpdateRadar(AX, AY: Word);
function GetEffectiveAltitude(ATile: TMapCell): ShortInt;
function GetLandAlt(AX, AY: Word; ADefault: ShortInt): ShortInt;
procedure SortStaticsList(AStatics: TList);
procedure SortStaticsList(AStatics: TStaticItemList);
procedure Flush;
procedure SaveBlock(AWorldBlock: TWorldBlock);
@ -185,13 +185,13 @@ var
block: TMemoryStream;
begin
inherited Create;
FItems := TList.Create;
FItems := TStaticItemList.Create(False);
FX := AX;
FY := AY;
for i := 0 to 63 do
Cells[i] := TList.Create;
Cells[i] := TStaticItemList.Create(True);
if (AData <> nil) and (AIndex.Lookup > 0) and (AIndex.Size > 0) then
begin
@ -220,21 +220,7 @@ begin
FreeAndNil(FItems);
for i := 0 to 63 do
begin
if Cells[i] <> nil then
begin
for j := 0 to Cells[i].Count - 1 do
begin
if Cells[i][j] <> nil then
begin
TStaticItem(Cells[i][j]).Free;
Cells[i][j] := nil;
end;
end;
Cells[i].Free;
Cells[i] := nil;
end;
end;
FreeAndNil(Cells[i]);
inherited Destroy;
end;
@ -263,9 +249,8 @@ begin
for j := 0 to Cells[i].Count - 1 do
begin
FItems.Add(Cells[i].Items[j]);
TStaticItem(Cells[i].Items[j]).UpdatePriorities(
FTiledataProvider.StaticTiles[TStaticItem(Cells[i].Items[j]).TileID],
solver);
Cells[i].Items[j].UpdatePriorities(
FTiledataProvider.StaticTiles[Cells[i].Items[j].TileID], solver);
Inc(solver);
end;
end;
@ -355,16 +340,16 @@ var
i: Integer;
begin
for i := 0 to Length(FBlockSubscriptions) - 1 do
if FBlockSubscriptions[i] <> nil then FreeAndNil(FBlockSubscriptions[i]);
if FBlockCache <> nil then FreeAndNil(FBlockCache);
if FTiledataProvider <> nil then FreeAndNil(FTiledataProvider);
if FRadarMap <> nil then FreeAndNil(FRadarMap);
FreeAndNil(FBlockSubscriptions[i]);
FreeAndNil(FBlockCache);
FreeAndNil(FTiledataProvider);
FreeAndNil(FRadarMap);
if FOwnsStreams then
begin
if FMap <> nil then FreeAndNil(FMap);
if FStatics <> nil then FreeAndNil(FStatics);
if FStaIdx <> nil then FreeAndNil(FStaIdx);
if FTiledata <> nil then FreeAndNil(FTiledata);
FreeAndNil(FMap);
FreeAndNil(FStatics);
FreeAndNil(FStaIdx);
FreeAndNil(FTiledata);
end;
RegisterPacketHandler($06, nil);
@ -407,7 +392,7 @@ begin
Result := ADefault;
end;
function TLandscape.GetStaticList(AX, AY: Word): TList;
function TLandscape.GetStaticList(AX, AY: Word): TStaticItemList;
var
block: TSeperatedStaticBlock;
begin
@ -424,7 +409,8 @@ procedure TLandscape.UpdateRadar(AX, AY: Word);
var
mapTile: TMapCell;
tile: TWorldItem;
staticItems, tiles: TList;
staticItems: TStaticItemList;
tiles: TWorldItemList;
i: Integer;
begin
if (AX mod 8 = 0) and (AY mod 8 = 0) then
@ -432,7 +418,7 @@ begin
staticItems := GetStaticList(AX, AY);
if staticItems <> nil then
begin
tiles := TList.Create;
tiles := TWorldItemList.Create(False);
mapTile := GetMapCell(AX, AY);
if mapTile <> nil then
begin
@ -443,16 +429,16 @@ begin
end;
for i := 0 to staticItems.Count - 1 do
begin
TStaticItem(staticItems.Items[i]).UpdatePriorities(
FTiledataProvider.StaticTiles[TStaticItem(staticItems.Items[i]).TileID],
staticItems[i].UpdatePriorities(
FTiledataProvider.StaticTiles[staticItems[i].TileID],
i + 1);
tiles.Add(staticItems.Items[i]);
tiles.Add(staticItems[i]);
end;
tiles.Sort(@CompareWorldItems);
if tiles.Count > 0 then
begin
tile := TWorldItem(tiles.Items[tiles.Count - 1]);
tile := tiles[tiles.Count - 1];
if tile is TStaticItem then
FRadarMap.Update(AX div 8, AY div 8, tile.TileID + $4000)
else
@ -464,15 +450,15 @@ begin
end;
end;
procedure TLandscape.SortStaticsList(AStatics: TList);
procedure TLandscape.SortStaticsList(AStatics: TStaticItemList);
var
i: Integer;
begin
for i := 0 to AStatics.Count - 1 do
TStaticItem(AStatics.Items[i]).UpdatePriorities(
FTiledataProvider.StaticTiles[TStaticItem(AStatics.Items[i]).TileID],
AStatics[i].UpdatePriorities(
FTiledataProvider.StaticTiles[AStatics[i].TileID],
i + 1);
AStatics.Sort(@CompareWorldItems);
AStatics.Sort(@CompareStaticItems);
end;
function TLandscape.GetEffectiveAltitude(ATile: TMapCell): ShortInt;
@ -649,7 +635,7 @@ var
x, y: Word;
block: TSeperatedStaticBlock;
staticItem: TStaticItem;
targetStaticList: TList;
targetStaticList: TStaticItemList;
subscriptions: TLinkedList;
subscriptionItem: PLinkedItem;
packet: TInsertStaticPacket;
@ -689,7 +675,7 @@ procedure TLandscape.OnDeleteStaticPacket(ABuffer: TEnhancedMemoryStream;
var
block: TSeperatedStaticBlock;
i: Integer;
statics: TList;
statics: TStaticItemList;
staticInfo: TStaticInfo;
staticItem: TStaticItem;
subscriptions: TLinkedList;
@ -706,20 +692,22 @@ begin
statics := block.Cells[(staticInfo.Y mod 8) * 8 + staticInfo.X mod 8];
for i := 0 to statics.Count - 1 do
begin
staticItem := TStaticItem(statics.Items[i]);
staticItem := statics[i];
if (staticItem.Z = staticInfo.Z) and
(staticItem.TileID = staticInfo.TileID) and
(staticItem.Hue = staticInfo.Hue) then
begin
packet := TDeleteStaticPacket.Create(staticItem);
statics.Delete(i);
staticItem.Delete;
statics.Delete(i);
subscriptions := FBlockSubscriptions[(staticInfo.Y div 8) * FWidth + (staticInfo.X div 8)];
subscriptions := FBlockSubscriptions[(staticInfo.Y div 8) * FWidth +
(staticInfo.X div 8)];
subscriptionItem := nil;
while subscriptions.Iterate(subscriptionItem) do
CEDServerInstance.SendPacket(TNetState(subscriptionItem^.Data), packet, False);
CEDServerInstance.SendPacket(TNetState(subscriptionItem^.Data),
packet, False);
packet.Free;
UpdateRadar(staticInfo.X, staticInfo.Y);
@ -735,7 +723,7 @@ procedure TLandscape.OnElevateStaticPacket(ABuffer: TEnhancedMemoryStream;
var
block: TSeperatedStaticBlock;
i: Integer;
statics: TList;
statics: TStaticItemList;
staticInfo: TStaticInfo;
staticItem: TStaticItem;
newZ: ShortInt;
@ -753,7 +741,7 @@ begin
statics := block.Cells[(staticInfo.Y mod 8) * 8 + staticInfo.X mod 8];
for i := 0 to statics.Count - 1 do
begin
staticItem := TStaticItem(statics.Items[i]);
staticItem := statics[i];
if (staticItem.Z = staticInfo.Z) and
(staticItem.TileID = staticInfo.TileID) and
(staticItem.Hue = staticInfo.Hue) then
@ -764,10 +752,12 @@ begin
staticItem.Z := newZ;
SortStaticsList(statics);
subscriptions := FBlockSubscriptions[(staticInfo.Y div 8) * FWidth + (staticInfo.X div 8)];
subscriptions := FBlockSubscriptions[(staticInfo.Y div 8) * FWidth +
(staticInfo.X div 8)];
subscriptionItem := nil;
while subscriptions.Iterate(subscriptionItem) do
CEDServerInstance.SendPacket(TNetState(subscriptionItem^.Data), packet, False);
CEDServerInstance.SendPacket(TNetState(subscriptionItem^.Data),
packet, False);
packet.Free;
UpdateRadar(staticInfo.X, staticInfo.Y);
@ -784,7 +774,7 @@ var
sourceBlock, targetBlock: TSeperatedStaticBlock;
sourceSubscriptions, targetSubscriptions: TList;
i: Integer;
statics: TList;
statics: TStaticItemList;
staticInfo: TStaticInfo;
staticItem: TStaticItem;
newX, newY: Word;
@ -816,7 +806,7 @@ begin
i := 0;
while (i < statics.Count) and (staticItem = nil) do
begin
staticItem := TStaticItem(statics.Items[i]);
staticItem := statics[i];
if (staticItem.Z <> staticInfo.Z) or
(staticItem.TileID <> staticInfo.TileID) or
(staticItem.Hue <> staticInfo.Hue) then
@ -831,7 +821,10 @@ begin
deletePacket := TDeleteStaticPacket.Create(staticItem);
movePacket := TMoveStaticPacket.Create(staticItem, newX, newY);
statics.Remove(staticItem);
i := statics.IndexOf(staticItem);
statics[i] := nil;
statics.Delete(i);
statics := targetBlock.Cells[(newY mod 8) * 8 + newX mod 8];
statics.Add(staticItem);
staticItem.UpdatePos(newX, newY, staticItem.Z);
@ -882,7 +875,7 @@ procedure TLandscape.OnHueStaticPacket(ABuffer: TEnhancedMemoryStream;
var
block: TSeperatedStaticBlock;
i: Integer;
statics: TList;
statics: TStaticItemList;
staticInfo: TStaticInfo;
staticItem: TStaticItem;
newHue: Word;
@ -900,7 +893,7 @@ begin
statics := block.Cells[(staticInfo.Y mod 8) * 8 + staticInfo.X mod 8];
for i := 0 to statics.Count - 1 do
begin
staticItem := TStaticItem(statics.Items[i]);
staticItem := statics[i];
if (staticItem.Z = staticInfo.Z) and
(staticItem.TileID = staticInfo.TileID) and
(staticItem.Hue = staticInfo.Hue) then
@ -935,7 +928,7 @@ var
emptyBits: TBits;
bitMask: array of TBits;
mapTile: TMapCell;
statics: TList;
statics: TStaticItemList;
operations: TList;
clients: array of record
NetState: TNetState;

View File

@ -21,7 +21,7 @@
* CDDL HEADER END
*
*
* Portions Copyright 2007 Andreas Schneider
* Portions Copyright 2009 Andreas Schneider
*)
unit ULargeScaleOperations;
@ -46,7 +46,7 @@ type
protected
FLandscape: TLandscape;
public
procedure Apply(AMapCell: TMapCell; AStatics: TList;
procedure Apply(AMapCell: TMapCell; AStatics: TStaticItemList;
AAdditionalAffectedBlocks: TBits); virtual; abstract;
end;
@ -62,7 +62,7 @@ type
public
property OffsetX: Integer read FOffsetX;
property OffsetY: Integer read FOffsetY;
procedure Apply(AMapCell: TMapCell; AStatics: TList;
procedure Apply(AMapCell: TMapCell; AStatics: TStaticItemList;
AAdditionalAffectedBlocks: TBits); override;
end;
@ -76,7 +76,7 @@ type
FMaxZ: ShortInt;
FRelativeZ: ShortInt;
public
procedure Apply(AMapCell: TMapCell; AStatics: TList;
procedure Apply(AMapCell: TMapCell; AStatics: TStaticItemList;
AAdditionalAffectedBlocks: TBits); override;
end;
@ -87,7 +87,7 @@ type
protected
FTileIDs: array of Word;
public
procedure Apply(AMapCell: TMapCell; AStatics: TList;
procedure Apply(AMapCell: TMapCell; AStatics: TStaticItemList;
AAdditionalAffectedBlocks: TBits); override;
end;
@ -100,7 +100,7 @@ type
FMinZ: ShortInt;
FMaxZ: ShortInt;
public
procedure Apply(AMapCell: TMapCell; AStatics: TList;
procedure Apply(AMapCell: TMapCell; AStatics: TStaticItemList;
AAdditionalAffectedBlocks: TBits); override;
end;
@ -114,7 +114,7 @@ type
FPlacementType: TStaticsPlacement;
FFixZ: ShortInt;
public
procedure Apply(AMapCell: TMapCell; AStatics: TList;
procedure Apply(AMapCell: TMapCell; AStatics: TStaticItemList;
AAdditionalAffectedBlocks: TBits); override;
end;
@ -145,12 +145,12 @@ begin
FErase := AData.ReadBoolean;
end;
procedure TLSCopyMove.Apply(AMapCell: TMapCell; AStatics: TList;
procedure TLSCopyMove.Apply(AMapCell: TMapCell; AStatics: TStaticItemList;
AAdditionalAffectedBlocks: TBits);
var
x, y: Word;
targetCell: TMapCell;
targetStatics: TList;
targetStatics: TStaticItemList;
targetStaticsBlock: TSeperatedStaticBlock;
i: Integer;
staticItem: TStaticItem;
@ -164,9 +164,7 @@ begin
if FErase then
begin
for i := 0 to targetStatics.Count - 1 do
begin
TStaticItem(targetStatics.Items[i]).Delete;
end;
targetStatics[i].Delete;
targetStatics.Clear;
end;
targetCell.TileID := AMapCell.TileID;
@ -179,23 +177,22 @@ begin
staticItem := TStaticItem.Create(nil, nil, 0, 0);
staticItem.X := x;
staticItem.Y := y;
staticItem.Z := TStaticItem(AStatics.Items[i]).Z;
staticItem.TileID := TStaticItem(AStatics.Items[i]).TileID;
staticItem.Hue := TStaticItem(AStatics.Items[i]).Hue;
staticItem.Z := AStatics[i].Z;
staticItem.TileID := AStatics[i].TileID;
staticItem.Hue := AStatics[i].Hue;
staticItem.Owner := targetStaticsBlock;
targetStatics.Add(staticItem);
end;
end else
begin
{for i := 0 to AStatics.Count - 1 do}
while AStatics.Count > 0 do
for i := 0 to AStatics.Count - 1 do
begin
targetStatics.Add(AStatics.Items[0]);
TStaticItem(AStatics.Items[0]).UpdatePos(x, y, TStaticItem(AStatics.Items[0]).Z);
TStaticItem(AStatics.Items[0]).Owner := targetStaticsBlock;
AStatics.Delete(0);
targetStatics.Add(AStatics[i]);
AStatics[i].UpdatePos(x, y, AStatics[i].Z);
AStatics[i].Owner := targetStaticsBlock;
AStatics[i] := nil;
end;
//AStatics.Clear;
AStatics.Clear;
end;
FLandscape.SortStaticsList(targetStatics);
@ -222,7 +219,7 @@ begin
end;
end;
procedure TLSSetAltitude.Apply(AMapCell: TMapCell; AStatics: TList;
procedure TLSSetAltitude.Apply(AMapCell: TMapCell; AStatics: TStaticItemList;
AAdditionalAffectedBlocks: TBits);
var
i: Integer;
@ -243,7 +240,7 @@ begin
for i := 0 to AStatics.Count - 1 do
begin
static := TStaticItem(AStatics.Items[i]);
static := AStatics[i];
static.Z := EnsureRange(static.Z + diff, -128, 127);
end;
end;
@ -261,7 +258,7 @@ begin
AData.Read(FTileIDs[0], count * SizeOf(Word));
end;
procedure TLSDrawTerrain.Apply(AMapCell: TMapCell; AStatics: TList;
procedure TLSDrawTerrain.Apply(AMapCell: TMapCell; AStatics: TStaticItemList;
AAdditionalAffectedBlocks: TBits);
begin
if Length(FTileIDs) > 0 then
@ -283,7 +280,7 @@ begin
FMaxZ := AData.ReadShortInt;
end;
procedure TLSDeleteStatics.Apply(AMapCell: TMapCell; AStatics: TList;
procedure TLSDeleteStatics.Apply(AMapCell: TMapCell; AStatics: TStaticItemList;
AAdditionalAffectedBlocks: TBits);
var
i, j: Integer;
@ -292,7 +289,7 @@ begin
i := 0;
while i < AStatics.Count do
begin
static := TStaticItem(AStatics.Items[i]);
static := AStatics[i];
if InRange(static.Z, FMinZ, FMaxZ) then
begin
if Length(FTileIDs) > 0 then
@ -301,8 +298,8 @@ begin
begin
if static.TileID = FTileIDs[j] - $4000 then
begin
AStatics.Delete(i);
static.Delete;
AStatics.Delete(i);
Dec(i);
Break;
end;
@ -310,8 +307,8 @@ begin
Inc(i);
end else
begin
AStatics.Delete(i);
static.Delete;
AStatics.Delete(i);
end;
end else
Inc(i);
@ -335,7 +332,7 @@ begin
FFixZ := AData.ReadShortInt;
end;
procedure TLSInsertStatics.Apply(AMapCell: TMapCell; AStatics: TList;
procedure TLSInsertStatics.Apply(AMapCell: TMapCell; AStatics: TStaticItemList;
AAdditionalAffectedBlocks: TBits);
var
staticItem, static: TStaticItem;
@ -360,8 +357,10 @@ begin
topZ := AMapCell.Z;
for i := 0 to AStatics.Count - 1 do
begin
static := TStaticItem(AStatics.Items[i]);
staticTop := EnsureRange(static.Z + CEDServerInstance.Landscape.TiledataProvider.StaticTiles[static.TileID].Height, -128, 127);
static := AStatics[i];
staticTop := EnsureRange(static.Z +
CEDServerInstance.Landscape.TiledataProvider.StaticTiles[static.TileID].Height,
-128, 127);
if staticTop > topZ then topZ := staticTop;
end;
end;
@ -372,8 +371,8 @@ begin
end;
AStatics.Add(staticItem);
staticItem.Owner := CEDServerInstance.Landscape.GetStaticBlock(staticItem.X div 8,
staticItem.Y div 8);
staticItem.Owner := CEDServerInstance.Landscape.GetStaticBlock(
staticItem.X div 8, staticItem.Y div 8);
end;
end.

View File

@ -21,13 +21,16 @@
<RunParams>
<local>
<FormatVersion Value="1"/>
<LaunchingApplication Use="True" PathPlusParams="/usr/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
<LaunchingApplication PathPlusParams="/usr/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
</local>
</RunParams>
<RequiredPackages Count="1">
<RequiredPackages Count="2">
<Item1>
<PackageName Value="lnetbase"/>
<PackageName Value="multiloglaz"/>
</Item1>
<Item2>
<PackageName Value="lnetbase"/>
</Item2>
</RequiredPackages>
<Units Count="15">
<Unit0>
@ -126,19 +129,18 @@
<CodeGeneration>
<SmartLinkUnit Value="True"/>
<Optimizations>
<OptimizationLevel Value="3"/>
<OptimizationLevel Value="0"/>
</Optimizations>
</CodeGeneration>
<Linking>
<Debugging>
<UseLineInfoUnit Value="False"/>
<StripSymbols Value="True"/>
<GenerateDebugInfo Value="True"/>
<UseHeaptrc Value="True"/>
</Debugging>
<LinkSmart Value="True"/>
</Linking>
<Other>
<CustomOptions Value="-FE..\bin\
"/>
<CustomOptions Value="-FE../bin/ "/>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>

View File

@ -33,7 +33,7 @@ uses
{$ENDIF}{$ENDIF}
SysUtils, Classes, lnetbase, UConfig, UCEDServer, URadarMap,
ULargeScaleOperations, UPackets, UAdminHandling, UClientHandling, ULandscape,
UPacketHandlers, URegions, UStatics;
UPacketHandlers, URegions, UStatics, Logging;
{$I version.inc}