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