- Added TTileDataFlag enum

- Added TTileDataFlags set
- Changed TTiledata.Flags to use the TTileDataFlags set
- Added hue highlighting to TfrmMain
- Added TTextureManager.GetStaticMaterial to handle tiledata and hues
This commit is contained in:
Andreas Schneider 2009-12-03 00:04:19 +01:00
parent b90ea02421
commit d5e5510760
7 changed files with 511 additions and 464 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="31"> <Units Count="34">
<Unit0> <Unit0>
<Filename Value="CentrED.lpr"/> <Filename Value="CentrED.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
@ -253,6 +253,21 @@
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="Logging"/> <UnitName Value="Logging"/>
</Unit30> </Unit30>
<Unit31>
<Filename Value="../UOLib/UStatics.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="UStatics"/>
</Unit31>
<Unit32>
<Filename Value="../UOLib/UWorldItem.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="UWorldItem"/>
</Unit32>
<Unit33>
<Filename Value="../UOLib/UMap.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="UMap"/>
</Unit33>
</Units> </Units>
</ProjectOptions> </ProjectOptions>
<CompilerOptions> <CompilerOptions>

View File

@ -40,7 +40,7 @@ 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; Logging, UMap, UWorldItem, UStatics;
{$IFDEF WINDOWS}{$R CentrED.rc}{$ENDIF} {$IFDEF WINDOWS}{$R CentrED.rc}{$ENDIF}

View File

@ -72,15 +72,18 @@ type
TLandTextureManager = class TLandTextureManager = class
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
function GetArtMaterial(ATileID: Word): TMaterial; overload;
function GetArtMaterial(ATileID: Word; AHue: THue;
APartialHue: Boolean): TMaterial; overload;
function GetFlatLandMaterial(ATileID: Word): TMaterial;
function GetTexMaterial(ATileID: Word): TMaterial;
protected protected
FArtCache: TCacheManager; FArtCache: TCacheManager;
FFlatLandArtCache: TCacheManager; FFlatLandArtCache: TCacheManager;
FTexCache: TCacheManager; FTexCache: TCacheManager;
public
function GetArtMaterial(ATileID: Word): TMaterial; overload;
function GetArtMaterial(ATileID: Word; AHue: THue;
APartialHue: Boolean): TMaterial; overload;
function GetFlatLandMaterial(ATileID: Word): TMaterial;
function GetStaticMaterial(AStaticItem: TStaticItem;
AOverrideHue: Integer = -1): TMaterial;
function GetTexMaterial(ATileID: Word): TMaterial;
end; end;
{ TSeperatedStaticBlock } { TSeperatedStaticBlock }
@ -205,6 +208,7 @@ type
Normals: PNormals; Normals: PNormals;
State: TScreenState; State: TScreenState;
Highlighted: Boolean; Highlighted: Boolean;
HueOverride: Boolean;
Next: PBlockInfo; Next: PBlockInfo;
end; end;
@ -290,7 +294,8 @@ begin
end; end;
end; end;
function TLandTextureManager.GetArtMaterial(ATileID: Word; AHue: THue; APartialHue: Boolean): TMaterial; function TLandTextureManager.GetArtMaterial(ATileID: Word; AHue: THue;
APartialHue: Boolean): TMaterial;
var var
artEntry: TArt; artEntry: TArt;
id: Integer; id: Integer;
@ -330,6 +335,25 @@ begin
end; end;
end; end;
function TLandTextureManager.GetStaticMaterial(AStaticItem: TStaticItem;
AOverrideHue: Integer = -1): TMaterial;
var
staticTiledata: TStaticTiledata;
hue: THue;
begin
staticTiledata := ResMan.Tiledata.StaticTiles[AStaticItem.TileID];
if AOverrideHue < 0 then
AOverrideHue := AStaticItem.Hue;
if AOverrideHue > 0 then
hue := ResMan.Hue.Hues[AOverrideHue]
else
hue := nil;
Result := GetArtMaterial($4000 + AStaticItem.TileID, hue,
tdfPartialHue in staticTiledata.Flags);
end;
function TLandTextureManager.GetTexMaterial(ATileID: Word): TMaterial; function TLandTextureManager.GetTexMaterial(ATileID: Word): TMaterial;
var var
texEntry: TTexture; texEntry: TTexture;
@ -706,8 +730,8 @@ begin
(staticItem.Hue = staticInfo.Hue) then (staticItem.Hue = staticInfo.Hue) then
begin begin
if Assigned(FOnStaticDeleted) then FOnStaticDeleted(staticItem); if Assigned(FOnStaticDeleted) then FOnStaticDeleted(staticItem);
statics.Delete(i);
staticItem.Delete; staticItem.Delete;
statics.Delete(i);
Break; Break;
end; end;
@ -785,8 +809,8 @@ begin
if staticItem <> nil then if staticItem <> nil then
begin begin
if Assigned(FOnStaticDeleted) then FOnStaticDeleted(staticItem); if Assigned(FOnStaticDeleted) then FOnStaticDeleted(staticItem);
statics.Remove(staticItem);
staticItem.Delete; staticItem.Delete;
statics.Remove(staticItem);
end; end;
end; end;

View File

@ -1733,8 +1733,6 @@ var
west, south, east: Single; west, south, east: Single;
z: SmallInt; z: SmallInt;
staticItem: TStaticItem; staticItem: TStaticItem;
hue: THue;
staticTiledata: TStaticTiledata;
begin begin
//add normals to map tiles and materials where possible //add normals to map tiles and materials where possible
@ -1806,13 +1804,8 @@ begin
begin begin
staticItem := TStaticItem(item); staticItem := TStaticItem(item);
staticTiledata := ResMan.Tiledata.StaticTiles[staticItem.TileID]; ABlockInfo^.LowRes := FTextureManager.GetStaticMaterial(staticItem);
if staticItem.Hue > 0 then ABlockInfo^.HueOverride := False;
hue := ResMan.Hue.Hues[staticItem.Hue - 1]
else
hue := nil;
ABlockInfo^.LowRes := FTextureManager.GetArtMaterial($4000 + staticItem.TileID, hue, (staticTileData.Flags and tdfPartialHue) = tdfPartialHue);
ABlockInfo^.ScreenRect := Bounds(Trunc(drawX - ABlockInfo^.LowRes.RealWidth / 2), ABlockInfo^.ScreenRect := Bounds(Trunc(drawX - ABlockInfo^.LowRes.RealWidth / 2),
Trunc(drawY + 44 - ABlockInfo^.LowRes.RealHeight - z * 4), Trunc(drawY + 44 - ABlockInfo^.LowRes.RealHeight - z * 4),
ABlockInfo^.LowRes.RealWidth, ABlockInfo^.LowRes.RealWidth,
@ -2292,6 +2285,27 @@ procedure TfrmMain.UpdateSelection;
var var
selectedRect: TRect; selectedRect: TRect;
blockInfo: PBlockInfo; blockInfo: PBlockInfo;
procedure SetHighlight(ABlockInfo: PBlockInfo; AHighlighted: Boolean);
begin
if (ABlockInfo^.Item is TStaticItem) and acHue.Checked then
begin
if ABlockInfo^.HueOverride <> AHighlighted then
begin
ABlockInfo^.HueOverride := AHighlighted;
if AHighlighted then
ABlockInfo^.LowRes := FTextureManager.GetStaticMaterial(
TStaticItem(ABlockInfo^.Item), frmHueSettings.lbHue.ItemIndex)
else
ABlockInfo^.LowRes := FTextureManager.GetStaticMaterial(
TStaticItem(ABlockInfo^.Item));
end;
end else
begin
ABlockInfo^.Highlighted := AHighlighted;
end;
end;
begin begin
Logger.EnterMethod([lcClient, lcDebug], 'UpdateSelection'); Logger.EnterMethod([lcClient, lcDebug], 'UpdateSelection');
if (CurrentTile <> nil) and (not acSelect.Checked) then if (CurrentTile <> nil) and (not acSelect.Checked) then
@ -2303,14 +2317,15 @@ begin
selectedRect := GetSelectedRect; selectedRect := GetSelectedRect;
Logger.Send([lcClient, lcDebug], 'SelectedRect', selectedRect); Logger.Send([lcClient, lcDebug], 'SelectedRect', selectedRect);
while FScreenBuffer.Iterate(blockInfo) do while FScreenBuffer.Iterate(blockInfo) do
if blockInfo^.State = ssNormal then if (blockInfo^.State = ssNormal) then
blockInfo^.Highlighted := PtInRect(selectedRect, Point(blockInfo^.Item.X, blockInfo^.Item.Y)); SetHighlight(blockInfo, PtInRect(selectedRect,
Point(blockInfo^.Item.X, blockInfo^.Item.Y)));
end else end else
begin begin
Logger.Send([lcClient, lcDebug], 'Single Target'); Logger.Send([lcClient, lcDebug], 'Single Target');
while FScreenBuffer.Iterate(blockInfo) do while FScreenBuffer.Iterate(blockInfo) do
if blockInfo^.State = ssNormal then if blockInfo^.State = ssNormal then
blockInfo^.Highlighted := (blockInfo^.Item = CurrentTile); SetHighlight(blockInfo, (blockInfo^.Item = CurrentTile));
end; end;
end; end;
Logger.ExitMethod([lcClient, lcDebug], 'UpdateSelection'); Logger.ExitMethod([lcClient, lcDebug], 'UpdateSelection');

View File

@ -80,9 +80,9 @@ var
tileData: TTiledata; tileData: TTiledata;
prefix, flags: string; prefix, flags: string;
procedure UpdateFlags(AFlag: LongWord; AName: string); procedure UpdateFlags(AFlag: TTileDataFlag; AName: string);
begin begin
if tileData.HasFlag(AFlag) then if AFlag in tileData.Flags then
begin begin
if flags <> '' then if flags <> '' then
flags := flags + ', ' + AName flags := flags + ', ' + AName
@ -111,9 +111,9 @@ begin
tileData := ResMan.Tiledata.StaticTiles[ATileID]; tileData := ResMan.Tiledata.StaticTiles[ATileID];
end; end;
if tileData.HasFlag(tdfArticleA) then if tdfArticleA in tileData.Flags then
prefix := 'a ' prefix := 'a '
else if tileData.HasFlag(tdfArticleAn) then else if tdfArticleAn in tileData.Flags then
prefix := 'an ' prefix := 'an '
else else
prefix := ''; prefix := '';

View File

@ -36,7 +36,8 @@ type
{ TStaticItem } { TStaticItem }
TStaticItem = class(TWorldItem) TStaticItem = class(TWorldItem)
constructor Create(AOwner: TWorldBlock; AData: TStream; ABlockX, ABlockY: Word); overload; constructor Create(AOwner: TWorldBlock; AData: TStream; ABlockX,
ABlockY: Word); overload;
constructor Create(AOwner: TWorldBlock; AData: TStream); overload; constructor Create(AOwner: TWorldBlock; AData: TStream); overload;
protected protected
{ Members } { Members }
@ -63,7 +64,8 @@ type
{ TStaticBlock} { TStaticBlock}
TStaticBlock = class(TWorldBlock) TStaticBlock = class(TWorldBlock)
constructor Create(AData: TStream; AIndex: TGenericIndex; AX, AY: Word); overload; constructor Create(AData: TStream; AIndex: TGenericIndex; AX, AY: Word);
overload;
constructor Create(AData: TStream; AIndex: TGenericIndex); overload; constructor Create(AData: TStream; AIndex: TGenericIndex); overload;
destructor Destroy; override; destructor Destroy; override;
protected protected
@ -92,12 +94,14 @@ end;
{ TStaticItem } { TStaticItem }
constructor TStaticItem.Create(AOwner: TWorldBlock; AData: TStream; ABlockX, ABlockY: Word); constructor TStaticItem.Create(AOwner: TWorldBlock; AData: TStream; ABlockX,
ABlockY: Word);
var var
iX, iY: Byte; iX, iY: Byte;
begin begin
inherited Create(AOwner); inherited Create(AOwner);
if assigned(AData) then
if AData <> nil then
begin begin
AData.Read(FTileID, SizeOf(SmallInt)); AData.Read(FTileID, SizeOf(SmallInt));
AData.Read(iX, SizeOf(Byte)); AData.Read(iX, SizeOf(Byte));
@ -108,6 +112,7 @@ begin
FX := ABlockX * 8 + iX; FX := ABlockX * 8 + iX;
FY := ABlockY * 8 + iY; FY := ABlockY * 8 + iY;
end; end;
InitOriginalState; InitOriginalState;
end; end;
@ -152,7 +157,7 @@ procedure TStaticItem.UpdatePriorities(ATileData: TStaticTiledata;
ASolver: Integer); ASolver: Integer);
begin begin
FPriorityBonus := 0; FPriorityBonus := 0;
if not ((ATileData.Flags and tdfBackground) = tdfBackground) then if not (tdfBackground in ATileData.Flags) then
Inc(FPriorityBonus); Inc(FPriorityBonus);
if ATileData.Height > 0 then if ATileData.Height > 0 then
Inc(FPriorityBonus); Inc(FPriorityBonus);
@ -176,7 +181,8 @@ end;
{ TStaticBlock } { TStaticBlock }
constructor TStaticBlock.Create(AData: TStream; AIndex: TGenericIndex; AX, AY: Word); constructor TStaticBlock.Create(AData: TStream; AIndex: TGenericIndex;
AX, AY: Word);
var var
i: Integer; i: Integer;
block: TMemoryStream; block: TMemoryStream;

View File

@ -21,7 +21,7 @@
* CDDL HEADER END * CDDL HEADER END
* *
* *
* Portions Copyright 2008 Andreas Schneider * Portions Copyright 2009 Andreas Schneider
*) *)
unit UTiledata; unit UTiledata;
@ -33,58 +33,35 @@ uses
Classes, SysUtils, UMulBlock; Classes, SysUtils, UMulBlock;
const const
tdfBackground = $00000001;
tdfWeapon = $00000002;
tdfTransparent = $00000004;
tdfTranslucent = $00000008;
tdfWall = $00000010;
tdfDamaging = $00000020;
tdfImpassable = $00000040;
tdfWet = $00000080;
tdfUnknown1 = $00000100;
tdfSurface = $00000200;
tdfBridge = $00000400;
tdfGeneric = $00000800;
tdfWindow = $00001000;
tdfNoShoot = $00002000;
tdfArticleA = $00004000;
tdfArticleAn = $00008000;
tdfInternal = $00010000;
tdfFoliage = $00020000;
tdfPartialHue = $00040000;
tdfUnknown2 = $00080000;
tdfMap = $00100000;
tdfContainer = $00200000;
tdfWearable = $00400000;
tdfLightSource = $00800000;
tdfAnimation = $01000000;
tdfNoDiagonal = $02000000;
tdfArtUsed = $04000000;
tdfArmor = $08000000;
tdfRoof = $10000000;
tdfDoor = $20000000;
tdfStairBack = $40000000;
tdfStairRight = $80000000;
LandTileDataSize = 26; LandTileDataSize = 26;
LandTileGroupSize = 4 + 32 * LandTileDataSize; LandTileGroupSize = 4 + 32 * LandTileDataSize;
StaticTileDataSize = 37; StaticTileDataSize = 37;
StaticTileGroupSize = 4 + 32 * StaticTileDataSize; StaticTileGroupSize = 4 + 32 * StaticTileDataSize;
type type
TTileDataFlag = (tdfBackground, tdfWeapon, tdfTransparent, tdfTranslucent,
tdfWall, tdfDamaging, tdfImpassable, tdfWet, tdfUnknown1,
tdfSurface, tdfBridge, tdfGeneric, tdfWindow, tdfNoShoot,
tdfArticleA, tdfArticleAn, tdfInternal, tdfFoliage,
tdfPartialHue, tdfUnknown2, tdfMap, tdfContainer,
tdfWearable, tdfLightSource, tdfAnimation, tdfNoDiagonal,
tdfArtUsed, tdfArmor, tdfRoof, tdfDoor, tdfStairBack,
tdfStairRight);
TTileDataFlags = set of TTileDataFlag;
{ TTiledata } { TTiledata }
TTiledata = class(TMulBlock) TTiledata = class(TMulBlock)
protected protected
FFlags: LongWord; FFlags: TTileDataFlags;
FTileName: string; FTileName: string;
public public
property Flags: LongWord read FFlags write FFlags; property Flags: TTileDataFlags read FFlags write FFlags;
property TileName: string read FTileName write FTileName; property TileName: string read FTileName write FTileName;
function HasFlag(AFlag: LongWord): Boolean;
end; end;
{ TLandTiledata }
TLandTiledata = class(TTiledata) TLandTiledata = class(TTiledata)
constructor Create(AData: TStream); constructor Create(AData: TStream);
destructor Destroy; override; destructor Destroy; override;
@ -96,6 +73,9 @@ type
public public
property TextureID: Word read FTextureID write FTextureID; property TextureID: Word read FTextureID write FTextureID;
end; end;
{ TStaticTiledata }
TStaticTiledata = class(TTiledata) TStaticTiledata = class(TTiledata)
constructor Create(AData: TStream); constructor Create(AData: TStream);
destructor Destroy; override; destructor Destroy; override;
@ -125,6 +105,9 @@ type
property Unknown4: Word read FUnknown4 write FUnknown4; property Unknown4: Word read FUnknown4 write FUnknown4;
property Height: Byte read FHeight write FHeight; property Height: Byte read FHeight write FHeight;
end; end;
{ TLandTileGroup }
TLandTileGroup = class(TMulBlock) TLandTileGroup = class(TMulBlock)
constructor Create(AData: TStream); constructor Create(AData: TStream);
destructor Destroy; override; destructor Destroy; override;
@ -137,6 +120,9 @@ type
LandTileData: array[0..31] of TLandTiledata; LandTileData: array[0..31] of TLandTiledata;
property Unknown: LongInt read FUnknown write FUnknown; property Unknown: LongInt read FUnknown write FUnknown;
end; end;
{ TStaticTileGroup }
TStaticTileGroup = class(TMulBlock) TStaticTileGroup = class(TMulBlock)
constructor Create(AData: TStream); constructor Create(AData: TStream);
destructor Destroy; override; destructor Destroy; override;
@ -174,6 +160,8 @@ begin
end; end;
end; end;
{ TLandTiledata }
constructor TLandTiledata.Create(AData: TStream); constructor TLandTiledata.Create(AData: TStream);
begin begin
SetLength(FTileName, 20); SetLength(FTileName, 20);
@ -217,6 +205,8 @@ begin
GetSize := LandTileDataSize; GetSize := LandTileDataSize;
end; end;
{ TStaticTiledata}
constructor TStaticTiledata.Create(AData: TStream); constructor TStaticTiledata.Create(AData: TStream);
begin begin
SetLength(FTileName, 20); SetLength(FTileName, 20);
@ -287,6 +277,8 @@ begin
GetSize := StaticTileDataSize; GetSize := StaticTileDataSize;
end; end;
{ TLandTileGroup }
constructor TLandTileGroup.Create(AData: TStream); constructor TLandTileGroup.Create(AData: TStream);
var var
i: Integer; i: Integer;
@ -332,6 +324,8 @@ begin
GetSize := LandTileGroupSize; GetSize := LandTileGroupSize;
end; end;
{ TStaticTileGroup }
constructor TStaticTileGroup.Create(AData: TStream); constructor TStaticTileGroup.Create(AData: TStream);
var var
i: Integer; i: Integer;
@ -377,12 +371,5 @@ begin
GetSize := StaticTileGroupSize; GetSize := StaticTileGroupSize;
end; end;
{ TTiledata }
function TTiledata.HasFlag(AFlag: LongWord): Boolean;
begin
Result := (FFlags and AFlag) = AFlag;
end;
end. end.