- Added AnimDataProvider

- Some code cleanups
This commit is contained in:
Andreas Schneider 2009-12-08 20:22:45 +01:00
parent 392bd3db14
commit 06c9c2c507
7 changed files with 565 additions and 406 deletions

View File

@ -56,7 +56,7 @@
<MinVersion Major="4" Minor="5" Release="1" Valid="True"/> <MinVersion Major="4" Minor="5" Release="1" Valid="True"/>
</Item5> </Item5>
</RequiredPackages> </RequiredPackages>
<Units Count="36"> <Units Count="40">
<Unit0> <Unit0>
<Filename Value="CentrED.lpr"/> <Filename Value="CentrED.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@ -278,6 +278,26 @@
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="UGLFont"/> <UnitName Value="UGLFont"/>
</Unit35> </Unit35>
<Unit36>
<Filename Value="../UOLib/UAnimData.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="UAnimData"/>
</Unit36>
<Unit37>
<Filename Value="../MulProvider/UTileDataProvider.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="UTileDataProvider"/>
</Unit37>
<Unit38>
<Filename Value="../MulProvider/UAnimDataProvider.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="UAnimDataProvider"/>
</Unit38>
<Unit39>
<Filename Value="../MulProvider/UMulManager.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="UMulManager"/>
</Unit39>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>

View File

@ -40,7 +40,8 @@ uses
UfrmLargeScaleCommand, UfrmVirtualLayer, UfrmFilter, UfrmTileInfo, UfrmLargeScaleCommand, UfrmVirtualLayer, UfrmFilter, UfrmTileInfo,
UGUIPlatformUtils, UPlatformTypes, UfrmRegionControl, UPackets, UGUIPlatformUtils, UPlatformTypes, UfrmRegionControl, UPackets,
UPacketHandlers, UAdminHandling, UGameResources, ULandscape, UfrmToolWindow, UPacketHandlers, UAdminHandling, UGameResources, ULandscape, UfrmToolWindow,
Logging, UMap, UWorldItem, UStatics, UTiledata, UGLFont; Logging, UTileDataProvider, UMap, UWorldItem, UStatics, UTiledata, UAnimData,
UGLFont, UAnimDataProvider, UMulManager;
{$IFDEF WINDOWS}{$R CentrED.rc}{$ENDIF} {$IFDEF WINDOWS}{$R CentrED.rc}{$ENDIF}

View File

@ -0,0 +1,104 @@
(*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* http://www.opensource.org/licenses/cddl1.php.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* http://www.opensource.org/licenses/cddl1.php. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying * information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Portions Copyright 2009 Andreas Schneider
*)
unit UAnimDataProvider;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, UMulProvider, UMulBlock, UAnimData;
type
TAnimDataArray = array[$0..$3FFF] of TAnimData;
{ TAnimDataProvider }
TAnimDataProvider = class(TMulProvider)
constructor Create(AData: TStream; AReadOnly: Boolean = False); overload;
override;
constructor Create(AData: string; AReadOnly: Boolean = False); overload;
override;
destructor Destroy; override;
protected
FAnimData: TAnimDataArray;
function CalculateOffset(AID: Integer): Integer; override;
function GetData(AID, AOffset: Integer): TAnimData; override;
procedure SetData(AID, AOffset: Integer; ABlock: TMulBlock); override;
public
property AnimData: TAnimDataArray read FAnimData;
function GetBlock(AID: Integer): TAnimData; override;
end;
implementation
{ TAnimDataProvider }
constructor TAnimDataProvider.Create(AData: TStream; AReadOnly: Boolean);
begin
inherited Create(AData, AReadOnly);
end;
constructor TAnimDataProvider.Create(AData: string; AReadOnly: Boolean);
begin
inherited Create(AData, AReadOnly);
end;
destructor TAnimDataProvider.Destroy;
begin
inherited Destroy;
end;
function TAnimDataProvider.CalculateOffset(AID: Integer): Integer;
begin
Result := GetAnimDataOffset(AID);
end;
function TAnimDataProvider.GetData(AID, AOffset: Integer): TAnimData;
begin
Result := FAnimData[AID];
end;
procedure TAnimDataProvider.SetData(AID, AOffset: Integer; ABlock: TMulBlock);
begin
FreeAndNil(FAnimData[AID]);
FAnimData[AID] := TAnimData(ABlock.Clone);
if not FReadOnly then
begin
FData.Position := AOffset;
ABlock.Write(FData);
end;
end;
function TAnimDataProvider.GetBlock(AID: Integer): TAnimData;
begin
Result := FAnimData[AID].Clone;
end;
end.

View File

@ -21,7 +21,7 @@
* CDDL HEADER END * CDDL HEADER END
* *
* *
* Portions Copyright 2007 Andreas Schneider * Portions Copyright 2009 Andreas Schneider
*) *)
unit UMulManager; unit UMulManager;
@ -29,16 +29,20 @@ interface
uses uses
SysUtils, UMulProvider, UTileDataProvider, UArtProvider, UGumpProvider, SysUtils, UMulProvider, UTileDataProvider, UArtProvider, UGumpProvider,
UTexmapProvider, UHueProvider, URadarProvider; UTexmapProvider, UHueProvider, URadarProvider, UAnimDataProvider;
type type
TMulManager = class(TObject)
{ TMulManager }
TMulManager = class
destructor Destroy; override; destructor Destroy; override;
protected protected
FArtProvider: TArtProvider; FArtProvider: TArtProvider;
FGumpProvider: TGumpProvider; FGumpProvider: TGumpProvider;
FTexmapProvider: TTexmapProvider; FTexmapProvider: TTexmapProvider;
FTileDataProvider: TTileDataProvider; FTileDataProvider: TTileDataProvider;
FAnimDataProvider: TAnimDataProvider;
FHueProvider: THueProvider; FHueProvider: THueProvider;
FRadarProvider: TRadarProvider; FRadarProvider: TRadarProvider;
public public
@ -46,12 +50,14 @@ type
procedure RegisterGumpProvider(AGumpProvider: TGumpProvider); procedure RegisterGumpProvider(AGumpProvider: TGumpProvider);
procedure RegisterTexmapProvider(ATexmapProvider: TTexmapProvider); procedure RegisterTexmapProvider(ATexmapProvider: TTexmapProvider);
procedure RegisterTileDataProvider(ATileDataProvider: TTileDataProvider); procedure RegisterTileDataProvider(ATileDataProvider: TTileDataProvider);
procedure RegisterAnimDataProvider(AAnimDataProvider: TAnimDataProvider);
procedure RegisterHueProvider(AHueProvider: THueProvider); procedure RegisterHueProvider(AHueProvider: THueProvider);
procedure RegisterRadarProvider(ARadarProvider: TRadarProvider); procedure RegisterRadarProvider(ARadarProvider: TRadarProvider);
property ArtProvider: TArtProvider read FArtProvider; property ArtProvider: TArtProvider read FArtProvider;
property GumpProvider: TGumpProvider read FGumpProvider; property GumpProvider: TGumpProvider read FGumpProvider;
property TexmapProvider: TTexmapProvider read FTexmapProvider; property TexmapProvider: TTexmapProvider read FTexmapProvider;
property TileDataProvider: TTileDataProvider read FTileDataProvider; property TileDataProvider: TTileDataProvider read FTileDataProvider;
property AnimDataProvider: TAnimDataProvider read FAnimDataProvider;
property HueProvider: THueProvider read FHueProvider; property HueProvider: THueProvider read FHueProvider;
property RadarProvider: TRadarPRovider read FRadarProvider; property RadarProvider: TRadarPRovider read FRadarProvider;
end; end;
@ -68,44 +74,56 @@ begin
RegisterTileDataProvider(nil); RegisterTileDataProvider(nil);
RegisterHueProvider(nil); RegisterHueProvider(nil);
RegisterRadarProvider(nil); RegisterRadarProvider(nil);
inherited; inherited Destroy;
end; end;
procedure TMulManager.RegisterArtProvider(AArtProvider: TArtProvider); procedure TMulManager.RegisterArtProvider(
AArtProvider: TArtProvider);
begin begin
if Assigned(FArtProvider) then FreeAndNil(FArtProvider); FreeAndNil(FArtProvider);
FArtProvider := AArtProvider; FArtProvider := AArtProvider;
end; end;
procedure TMulManager.RegisterGumpProvider(AGumpProvider: TGumpProvider); procedure TMulManager.RegisterGumpProvider(
AGumpProvider: TGumpProvider);
begin begin
if Assigned(FGumpProvider) then FreeAndNil(FGumpProvider); FreeAndNil(FGumpProvider);
FGumpProvider := AGumpProvider; FGumpProvider := AGumpProvider;
end; end;
procedure TMulManager.RegisterHueProvider(AHueProvider: THueProvider); procedure TMulManager.RegisterHueProvider(
AHueProvider: THueProvider);
begin begin
if Assigned(FHueProvider) then FreeAndNil(FHueProvider); FreeAndNil(FHueProvider);
FHueProvider := AHueProvider; FHueProvider := AHueProvider;
end; end;
procedure TMulManager.RegisterRadarProvider(ARadarProvider: TRadarProvider); procedure TMulManager.RegisterRadarProvider(
ARadarProvider: TRadarProvider);
begin begin
if Assigned(FRadarProvider) then FreeAndNil(FRadarProvider); FreeAndNil(FRadarProvider);
FRadarProvider := ARadarProvider; FRadarProvider := ARadarProvider;
end; end;
procedure TMulManager.RegisterTexmapProvider(ATexmapProvider: TTexmapProvider); procedure TMulManager.RegisterTexmapProvider(
ATexmapProvider: TTexmapProvider);
begin begin
if Assigned(FTexmapProvider) then FreeAndNil(FTexmapProvider); FreeAndNil(FTexmapProvider);
FTexmapProvider := ATexmapProvider; FTexmapProvider := ATexmapProvider;
end; end;
procedure TMulManager.RegisterTileDataProvider( procedure TMulManager.RegisterTileDataProvider(
ATileDataProvider: TTileDataProvider); ATileDataProvider: TTileDataProvider);
begin begin
if Assigned(FTileDataProvider) then FreeAndNil(FTileDataProvider); FreeAndNil(FTileDataProvider);
FTileDataProvider := ATileDataProvider; FTileDataProvider := ATileDataProvider;
end; end;
procedure TMulManager.RegisterAnimDataProvider(
AAnimDataProvider: TAnimDataProvider);
begin
FreeAndNil(FAnimDataProvider);
FTileDataProvider := AAnimDataProvider;
end;
end. end.

View File

@ -21,7 +21,7 @@
* CDDL HEADER END * CDDL HEADER END
* *
* *
* Portions Copyright 2007 Andreas Schneider * Portions Copyright 2009 Andreas Schneider
*) *)
unit UTileDataProvider; unit UTileDataProvider;
@ -79,8 +79,8 @@ var
begin begin
for i := $0 to $3FFF do for i := $0 to $3FFF do
begin begin
if Assigned(FLandTiles[i]) then FreeAndNil(FLandTiles[i]); FreeAndNil(FLandTiles[i]);
if Assigned(FStaticTiles[i]) then FreeAndNil(FStaticTiles[i]); FreeAndNil(FStaticTiles[i]);
end; end;
inherited; inherited;
@ -124,11 +124,11 @@ procedure TTiledataProvider.SetData(AID, AOffset: Integer;
begin begin
if AID < $4000 then if AID < $4000 then
begin begin
if Assigned(FLandTiles[AID]) then FreeAndNil(FLandTiles[AID]); FreeAndNil(FLandTiles[AID]);
FLandTiles[AID] := TLandTileData(ABlock.Clone); FLandTiles[AID] := TLandTileData(ABlock.Clone);
end else end else
begin begin
if Assigned(FStaticTiles[AID - $4000]) then FreeAndNil(FStaticTiles[AID - $4000]); FreeAndNil(FStaticTiles[AID - $4000]);
FStaticTiles[AID - $4000] := TStaticTileData(ABlock.Clone); FStaticTiles[AID - $4000] := TStaticTileData(ABlock.Clone);
end; end;

View File

@ -21,7 +21,7 @@
* CDDL HEADER END * CDDL HEADER END
* *
* *
* Portions Copyright 2007 Andreas Schneider * Portions Copyright 2009 Andreas Schneider
*) *)
unit UAnimData; unit UAnimData;
@ -35,37 +35,37 @@ const
AnimDataGroupSize = 4 + (8 * AnimDataSize); AnimDataGroupSize = 4 + (8 * AnimDataSize);
type type
{ TAnimData }
TAnimData = class(TMulBlock) TAnimData = class(TMulBlock)
constructor Create(Data: TStream); constructor Create(AData: TStream);
function GetSize: Integer; override; function GetSize: Integer; override;
procedure Write(Data: TStream); override; procedure Write(AData: TStream); override;
private function Clone: TAnimData; override;
FOffset: Int64; protected
FUnknown: Byte; FUnknown: Byte;
FFrameCount: Byte; FFrameCount: Byte;
FFrameInterval: Byte; FFrameInterval: Byte;
FFrameStart: Byte; FFrameStart: Byte;
public public
FrameData: array[0..63] of ShortInt; FrameData: array[0..63] of Byte;
published
property Offset: Int64 read FOffset write FOffset;
property Unknown: Byte read FUnknown write FUnknown; property Unknown: Byte read FUnknown write FUnknown;
property FrameCount: Byte read FFrameCount write FFrameCount; property FrameCount: Byte read FFrameCount write FFrameCount;
property FrameInterval: Byte read FFrameInterval write FFrameInterval; property FrameInterval: Byte read FFrameInterval write FFrameInterval;
property FrameStart: Byte read FFrameStart write FFrameStart; property FrameStart: Byte read FFrameStart write FFrameStart;
end; end;
{ TAnimDataGroup }
TAnimDataGroup = class(TMulBlock) TAnimDataGroup = class(TMulBlock)
constructor Create(Data: TStream); constructor Create(AData: TStream);
destructor Destroy; override; destructor Destroy; override;
function GetSize: Integer; override; function GetSize: Integer; override;
procedure Write(Data: TStream); override; procedure Write(AData: TStream); override;
private protected
FOffset: Int64;
FUnknown: LongInt; FUnknown: LongInt;
public
AnimData: array[0..7] of TAnimData; AnimData: array[0..7] of TAnimData;
published
property Offset: Int64 read FOffset write FOffset;
property Unknown: LongInt read FUnknown write FUnknown; property Unknown: LongInt read FUnknown write FUnknown;
end; end;
@ -73,7 +73,7 @@ function GetAnimDataOffset(Block: Integer): Integer;
implementation implementation
function GetAnimDataOffset; function GetAnimDataOffset(Block: Integer): Integer;
var var
group, tile: Integer; group, tile: Integer;
begin begin
@ -83,44 +83,59 @@ begin
Result := group * AnimDataGroupSize + 4 + tile * AnimDataSize; Result := group * AnimDataGroupSize + 4 + tile * AnimDataSize;
end; end;
constructor TAnimData.Create; { TAnimData }
constructor TAnimData.Create(AData: TStream);
begin begin
if assigned(Data) then if AData <> nil then
begin begin
FOffset := Data.Position; AData.Read(FrameData, SizeOf(FrameData[0]) * Length(FrameData));
Data.Read(FrameData, 64); AData.Read(FUnknown, SizeOf(FUnknown));
Data.Read(FUnknown, SizeOf(Byte)); AData.Read(FFrameCount, SizeOf(FFrameCount));
Data.Read(FFrameCount, SizeOf(Byte)); AData.Read(FFrameInterval, SizeOf(FFrameInterval));
Data.Read(FFrameInterval, SizeOf(Byte)); AData.Read(FFrameStart, SizeOf(FFrameStart));
Data.Read(FFrameStart, SizeOf(Byte));
end; end;
end; end;
procedure TAnimData.Write; procedure TAnimData.Write(AData: TStream);
begin begin
Data.Write(FrameData, 64); AData.Write(FrameData, SizeOf(FrameData[0]) * Length(FrameData));
Data.Write(FUnknown, SizeOf(Byte)); AData.Write(FUnknown, SizeOf(FUnknown));
Data.Write(FFrameCount, SizeOf(Byte)); AData.Write(FFrameCount, SizeOf(FFrameCount));
Data.Write(FFrameInterval, SizeOf(Byte)); AData.Write(FFrameInterval, SizeOf(FFrameInterval));
Data.Write(FFrameStart, SizeOf(Byte)); AData.Write(FFrameStart, SizeOf(FFrameStart));
end; end;
function TAnimData.GetSize; function TAnimData.Clone: TAnimData;
begin
GetSize := AnimDataSize;
end;
constructor TAnimDataGroup.Create;
var var
i: Integer; i: Integer;
begin begin
if assigned(Data) then Result := TAnimData.Create(nil);
Result.FUnknown := FUnknown;
Result.FFrameCount := FFrameCount;
Result.FFrameInterval := FFrameInterval;
Result.FFrameStart := FFrameStart;
for i := 0 to 63 do
Result.FrameData[i] := FrameData[i];
end;
function TAnimData.GetSize: Integer;
begin begin
FOffset := Data.Position; Result := AnimDataSize;
Data.Read(FUnknown, SizeOf(LongInt)); end;
{ TAnimDataGroup }
constructor TAnimDataGroup.Create(AData: TStream);
var
i: Integer;
begin
if AData <> nil then
begin
AData.Read(FUnknown, SizeOf(FUnknown));
end; end;
for i := 0 to 7 do for i := 0 to 7 do
AnimData[i] := TAnimData.Create(Data); AnimData[i] := TAnimData.Create(AData);
end; end;
destructor TAnimDataGroup.Destroy; destructor TAnimDataGroup.Destroy;
@ -131,18 +146,18 @@ begin
AnimData[i].Free; AnimData[i].Free;
end; end;
procedure TAnimDataGroup.Write; procedure TAnimDataGroup.Write(AData: TStream);
var var
i: Integer; i: Integer;
begin begin
Data.Write(FUnknown, SizeOf(LongInt)); AData.Write(FUnknown, SizeOf(FUnknown));
for i := 0 to 7 do for i := 0 to 7 do
AnimData[i].Write(Data); AnimData[i].Write(AData);
end; end;
function TAnimDataGroup.GetSize; function TAnimDataGroup.GetSize: Integer;
begin begin
GetSize := AnimDataGroupSize; Result := AnimDataGroupSize;
end; end;
end. end.

View File

@ -150,7 +150,8 @@ begin
group := ABlock div 32; group := ABlock div 32;
tile := ABlock mod 32; tile := ABlock mod 32;
Result := 512 * LandTileGroupSize + group * StaticTileGroupSize + 4 + tile * StaticTileDataSize; Result := 512 * LandTileGroupSize + group * StaticTileGroupSize + 4
+ tile * StaticTileDataSize;
end else end else
begin begin
group := ABlock div 32; group := ABlock div 32;