- Changed TAnimDataProvider to load as much animdata as the input files provides
- Added TBufferedStream.GetSize - Added TIndexedMulProvider.EntryCount - Added TAnimDataProvider.AnimCount - Added TLandscape.MaxStaticID - Some more code cleanups
This commit is contained in:
parent
bdc97b89f5
commit
73e704e5fa
|
@ -183,6 +183,7 @@ type
|
||||||
FOnStaticHued: TStaticChangedEvent;
|
FOnStaticHued: TStaticChangedEvent;
|
||||||
FOpenRequests: TBits;
|
FOpenRequests: TBits;
|
||||||
FWriteMap: TBits;
|
FWriteMap: TBits;
|
||||||
|
FMaxStaticID: Cardinal;
|
||||||
{ Methods }
|
{ Methods }
|
||||||
function GetMapBlock(AX, AY: Word): TMapBlock;
|
function GetMapBlock(AX, AY: Word): TMapBlock;
|
||||||
function GetMapCell(AX, AY: Word): TMapCell;
|
function GetMapCell(AX, AY: Word): TMapCell;
|
||||||
|
@ -207,6 +208,7 @@ type
|
||||||
property MapCell[X, Y: Word]: TMapCell read GetMapCell;
|
property MapCell[X, Y: Word]: TMapCell read GetMapCell;
|
||||||
property StaticList[X, Y: Word]: TStaticItemList read GetStaticList;
|
property StaticList[X, Y: Word]: TStaticItemList read GetStaticList;
|
||||||
property Normals[X, Y: Word]: TNormals read GetNormals;
|
property Normals[X, Y: Word]: TNormals read GetNormals;
|
||||||
|
property MaxStaticID: Cardinal read FMaxStaticID;
|
||||||
property OnChange: TLandscapeChangeEvent read FOnChange write FOnChange;
|
property OnChange: TLandscapeChangeEvent read FOnChange write FOnChange;
|
||||||
property OnMapChanged: TMapChangedEvent read FOnMapChanged write FOnMapChanged;
|
property OnMapChanged: TMapChangedEvent read FOnMapChanged write FOnMapChanged;
|
||||||
property OnNewBlock: TNewBlockEvent read FOnNewBlock write FOnNewBlock;
|
property OnNewBlock: TNewBlockEvent read FOnNewBlock write FOnNewBlock;
|
||||||
|
@ -594,6 +596,11 @@ begin
|
||||||
for i := 0 to FWriteMap.Size - 1 do
|
for i := 0 to FWriteMap.Size - 1 do
|
||||||
FWriteMap[i] := True;
|
FWriteMap[i] := True;
|
||||||
|
|
||||||
|
FMaxStaticID := Min(Min(ResMan.Animdata.AnimCount, ResMan.Tiledata.StaticCount),
|
||||||
|
ResMan.Art.EntryCount - $4000);
|
||||||
|
Logger.Send([lcClient, lcInfo], 'Landscape recognizes $%x StaticTile IDs.',
|
||||||
|
[FMaxStaticId]);
|
||||||
|
|
||||||
RegisterPacketHandler($04, TPacketHandler.Create(0, @OnBlocksPacket));
|
RegisterPacketHandler($04, TPacketHandler.Create(0, @OnBlocksPacket));
|
||||||
RegisterPacketHandler($06, TPacketHandler.Create(8, @OnDrawMapPacket));
|
RegisterPacketHandler($06, TPacketHandler.Create(8, @OnDrawMapPacket));
|
||||||
RegisterPacketHandler($07, TPacketHandler.Create(10, @OnInsertStaticPacket));
|
RegisterPacketHandler($07, TPacketHandler.Create(10, @OnInsertStaticPacket));
|
||||||
|
|
|
@ -34,7 +34,7 @@ uses
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
TAnimDataArray = array[$0..$3FFF] of TAnimData;
|
TAnimDataArray = array of TAnimData;
|
||||||
|
|
||||||
{ TAnimDataProvider }
|
{ TAnimDataProvider }
|
||||||
|
|
||||||
|
@ -46,17 +46,22 @@ type
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
protected
|
protected
|
||||||
FAnimData: TAnimDataArray;
|
FAnimData: TAnimDataArray;
|
||||||
|
FAnimCount: Cardinal;
|
||||||
function CalculateOffset(AID: Integer): Integer; override;
|
function CalculateOffset(AID: Integer): Integer; override;
|
||||||
function GetData(AID, AOffset: Integer): TAnimData; override;
|
function GetData(AID, AOffset: Integer): TAnimData; override;
|
||||||
procedure InitArray;
|
procedure InitArray;
|
||||||
procedure SetData(AID, AOffset: Integer; ABlock: TMulBlock); override;
|
procedure SetData(AID, AOffset: Integer; ABlock: TMulBlock); override;
|
||||||
public
|
public
|
||||||
property AnimData: TAnimDataArray read FAnimData;
|
property AnimData: TAnimDataArray read FAnimData;
|
||||||
|
property AnimCount: Cardinal read FAnimCount;
|
||||||
function GetBlock(AID: Integer): TAnimData; override;
|
function GetBlock(AID: Integer): TAnimData; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
Logging;
|
||||||
|
|
||||||
{ TAnimDataProvider }
|
{ TAnimDataProvider }
|
||||||
|
|
||||||
constructor TAnimDataProvider.Create(AData: TStream; AReadOnly: Boolean);
|
constructor TAnimDataProvider.Create(AData: TStream; AReadOnly: Boolean);
|
||||||
|
@ -95,9 +100,14 @@ procedure TAnimDataProvider.InitArray;
|
||||||
var
|
var
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
for i := 0 to Length(FAnimData) - 1 do
|
FData.Position := 0;
|
||||||
|
FAnimCount := (FData.Size div AnimDataGroupSize) * 8;
|
||||||
|
Logger.Send([lcInfo], 'Loading $%x AnimData entries.', [FAnimCount]);
|
||||||
|
SetLength(FAnimData, FAnimCount);
|
||||||
|
for i := 0 to FAnimCount - 1 do
|
||||||
begin
|
begin
|
||||||
FData.Position := GetAnimDataOffset(i);
|
if i mod 8 = 0 then
|
||||||
|
FData.Seek(4, soFromCurrent);
|
||||||
FAnimData[i] := TAnimData.Create(FData);
|
FAnimData[i] := TAnimData.Create(FData);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
|
@ -85,6 +85,7 @@ type
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
protected
|
protected
|
||||||
FIndex: TBufferedReader;
|
FIndex: TBufferedReader;
|
||||||
|
FEntryCount: Cardinal;
|
||||||
function CalculateIndexOffset(AID: Integer): Integer; virtual;
|
function CalculateIndexOffset(AID: Integer): Integer; virtual;
|
||||||
function GetData(AID: Integer; AIndex: TGenericIndex): TMulBlock; reintroduce; virtual; abstract;
|
function GetData(AID: Integer; AIndex: TGenericIndex): TMulBlock; reintroduce; virtual; abstract;
|
||||||
procedure SetData(AID: Integer; AIndex: TGenericIndex; ABlock: TMulBlock); reintroduce; virtual;
|
procedure SetData(AID: Integer; AIndex: TGenericIndex; ABlock: TMulBlock); reintroduce; virtual;
|
||||||
|
@ -96,6 +97,7 @@ type
|
||||||
function Exists(AID: Integer): Boolean; virtual;
|
function Exists(AID: Integer): Boolean; virtual;
|
||||||
procedure Defragment(ATempStream: TStream; AOnProgress: TOnProgressEvent = nil); virtual;
|
procedure Defragment(ATempStream: TStream; AOnProgress: TOnProgressEvent = nil); virtual;
|
||||||
property Index: TBufferedReader read FIndex;
|
property Index: TBufferedReader read FIndex;
|
||||||
|
property EntryCount: Cardinal read FEntryCount;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
@ -121,7 +123,7 @@ begin
|
||||||
Dispose(PMethod(FEvents.Items[i]));
|
Dispose(PMethod(FEvents.Items[i]));
|
||||||
FreeAndNil(FEvents);
|
FreeAndNil(FEvents);
|
||||||
end;
|
end;
|
||||||
inherited;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TMulEventHandler.FireEvents(ABlock: TMulBlock);
|
procedure TMulEventHandler.FireEvents(ABlock: TMulBlock);
|
||||||
|
@ -262,6 +264,7 @@ constructor TIndexedMulProvider.Create(AData, AIndex: TStream; AReadOnly: Boolea
|
||||||
begin
|
begin
|
||||||
inherited Create(AData, AReadOnly);
|
inherited Create(AData, AReadOnly);
|
||||||
FIndex := TBufferedReader.Create(AIndex);
|
FIndex := TBufferedReader.Create(AIndex);
|
||||||
|
FEntryCount := AIndex.Size div 12;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
constructor TIndexedMulProvider.Create(AData, AIndex: string; AReadOnly: Boolean = False);
|
constructor TIndexedMulProvider.Create(AData, AIndex: string; AReadOnly: Boolean = False);
|
||||||
|
@ -274,6 +277,7 @@ begin
|
||||||
else
|
else
|
||||||
mode := fmOpenReadWrite or fmShareDenyWrite;
|
mode := fmOpenReadWrite or fmShareDenyWrite;
|
||||||
FIndex := TBufferedReader.Create(TFileStream.Create(AIndex, mode), True);
|
FIndex := TBufferedReader.Create(TFileStream.Create(AIndex, mode), True);
|
||||||
|
FEntryCount := FIndex.Size div 12;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TIndexedMulProvider.Defragment(ATempStream: TStream; AOnProgress: TOnProgressEvent = nil);
|
procedure TIndexedMulProvider.Defragment(ATempStream: TStream; AOnProgress: TOnProgressEvent = nil);
|
||||||
|
@ -287,7 +291,7 @@ begin
|
||||||
while FIndex.Position < FIndex.Size do
|
while FIndex.Position < FIndex.Size do
|
||||||
begin
|
begin
|
||||||
genericIndex := TGenericIndex.Create(FIndex);
|
genericIndex := TGenericIndex.Create(FIndex);
|
||||||
if genericIndex.Lookup <> LongInt($FFFFFFFF) then
|
if genericIndex.Lookup > -1 then
|
||||||
begin
|
begin
|
||||||
FData.Position := genericIndex.Lookup;
|
FData.Position := genericIndex.Lookup;
|
||||||
genericIndex.Lookup := ATempStream.Position;
|
genericIndex.Lookup := ATempStream.Position;
|
||||||
|
@ -307,8 +311,8 @@ end;
|
||||||
|
|
||||||
destructor TIndexedMulProvider.Destroy;
|
destructor TIndexedMulProvider.Destroy;
|
||||||
begin
|
begin
|
||||||
if Assigned(FIndex) then FreeAndNil(FIndex);
|
FreeAndNil(FIndex);
|
||||||
inherited;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TIndexedMulProvider.Exists(AID: Integer): Boolean;
|
function TIndexedMulProvider.Exists(AID: Integer): Boolean;
|
||||||
|
@ -368,9 +372,9 @@ begin
|
||||||
size := ABlock.GetSize;
|
size := ABlock.GetSize;
|
||||||
if size = 0 then
|
if size = 0 then
|
||||||
begin
|
begin
|
||||||
AIndex.Lookup := LongInt($FFFFFFFF);
|
AIndex.Lookup := -1;
|
||||||
AIndex.Various := LongInt($FFFFFFFF);
|
AIndex.Various := -1;
|
||||||
end else if (size > AIndex.Size) or (AIndex.Lookup = LongInt($FFFFFFFF)) then
|
end else if (size > AIndex.Size) or (AIndex.Lookup < 0) then
|
||||||
begin
|
begin
|
||||||
FData.Position := FData.Size;
|
FData.Position := FData.Size;
|
||||||
AIndex.Lookup := FData.Position;
|
AIndex.Lookup := FData.Position;
|
||||||
|
|
|
@ -141,7 +141,7 @@
|
||||||
</Linking>
|
</Linking>
|
||||||
<Other>
|
<Other>
|
||||||
<CustomOptions Value="-FE../bin/
|
<CustomOptions Value="-FE../bin/
|
||||||
"/>
|
-dNoLogging"/>
|
||||||
<CompilerPath Value="$(CompPath)"/>
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
</Other>
|
</Other>
|
||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
|
|
|
@ -33,6 +33,9 @@ uses
|
||||||
SysUtils, Classes, UEnhancedMemoryStream;
|
SysUtils, Classes, UEnhancedMemoryStream;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
{ TBufferedStream }
|
||||||
|
|
||||||
TBufferedStream = class(TEnhancedMemoryStream)
|
TBufferedStream = class(TEnhancedMemoryStream)
|
||||||
constructor Create(ABaseStream: TStream; AOwnsBaseStream: Boolean = false); virtual;
|
constructor Create(ABaseStream: TStream; AOwnsBaseStream: Boolean = false); virtual;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
@ -42,6 +45,7 @@ type
|
||||||
public
|
public
|
||||||
procedure Refresh; virtual;
|
procedure Refresh; virtual;
|
||||||
procedure Flush; virtual;
|
procedure Flush; virtual;
|
||||||
|
function GetSize: Int64; override;
|
||||||
end;
|
end;
|
||||||
TBufferedReader = class(TBufferedStream)
|
TBufferedReader = class(TBufferedStream)
|
||||||
constructor Create(ABaseStream: TStream; AOwnsBaseStream: Boolean = false); override;
|
constructor Create(ABaseStream: TStream; AOwnsBaseStream: Boolean = false); override;
|
||||||
|
@ -82,6 +86,11 @@ begin
|
||||||
FBaseStream.CopyFrom(Self, 0);
|
FBaseStream.CopyFrom(Self, 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TBufferedStream.GetSize: Int64;
|
||||||
|
begin
|
||||||
|
Result := FBaseStream.Size;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TBufferedStream.Refresh;
|
procedure TBufferedStream.Refresh;
|
||||||
begin
|
begin
|
||||||
Size := FBaseStream.Size;
|
Size := FBaseStream.Size;
|
||||||
|
|
Loading…
Reference in New Issue