- Some code cleanups in UfrmMain and ULandscape

- Fixed GetPlainNormals in ULandscape to actually return a value
This commit is contained in:
Andreas Schneider 2009-12-03 01:35:29 +01:00
parent d5e5510760
commit fffb420299
3 changed files with 58 additions and 49 deletions

View File

@ -306,6 +306,9 @@
</Options> </Options>
</Linking> </Linking>
<Other> <Other>
<CompilerMessages>
<IgnoredMessages idx5024="True"/>
</CompilerMessages>
<CustomOptions Value="-FE../bin/ "/> <CustomOptions Value="-FE../bin/ "/>
<CompilerPath Value="$(CompPath)"/> <CompilerPath Value="$(CompPath)"/>
</Other> </Other>

View File

@ -251,10 +251,6 @@ implementation
uses uses
UGameResources, UdmNetwork, UPackets, UPacketHandlers, Logging; UGameResources, UdmNetwork, UPackets, UPacketHandlers, Logging;
const
mMap = 0;
mStatics = 1;
function GetID(AX, AY: Word): Integer; function GetID(AX, AY: Word): Integer;
begin begin
Result := ((AX and $7FFF) shl 15) or (AY and $7FFF); Result := ((AX and $7FFF) shl 15) or (AY and $7FFF);
@ -416,7 +412,7 @@ end;
destructor TSeperatedStaticBlock.Destroy; destructor TSeperatedStaticBlock.Destroy;
var var
i, j: Integer; i: Integer;
begin begin
FreeAndNil(FItems); FreeAndNil(FItems);
@ -505,7 +501,7 @@ end;
constructor TLandscape.Create(AWidth, AHeight: Word); constructor TLandscape.Create(AWidth, AHeight: Word);
var var
blockID, i: Integer; i: Integer;
begin begin
inherited Create; inherited Create;
FWidth := AWidth; FWidth := AWidth;
@ -959,7 +955,7 @@ var
u, v: TVector; u, v: TVector;
begin begin
cell := GetMapCell(X, Y); cell := GetMapCell(X, Y);
if Assigned(cell) then if cell <> nil then
begin begin
north := cell.Altitude; north := cell.Altitude;
west := GetLandAlt(cell.X, cell.Y + 1, north); west := GetLandAlt(cell.X, cell.Y + 1, north);
@ -975,27 +971,27 @@ var
if (north = west) and (west = east) and (north = south) then if (north = west) and (west = east) and (north = south) then
begin begin
ANormals[0] := Vector(0, 0, 1); Result[0] := Vector(0, 0, 1);
ANormals[1] := Vector(0, 0, 1); Result[1] := Vector(0, 0, 1);
ANormals[2] := Vector(0, 0, 1); Result[2] := Vector(0, 0, 1);
ANormals[3] := Vector(0, 0, 1); Result[3] := Vector(0, 0, 1);
end else end else
begin begin
u := Vector(-22, 22, (north - east) * 4); u := Vector(-22, 22, (north - east) * 4);
v := Vector(-22, -22, (west - north) * 4); v := Vector(-22, -22, (west - north) * 4);
ANormals[0] := VectorNorm(VectorCross(u, v)); Result[0] := VectorNorm(VectorCross(u, v));
u := Vector(22, 22, (east - south) * 4); u := Vector(22, 22, (east - south) * 4);
v := Vector(-22, 22, (north - east) * 4); v := Vector(-22, 22, (north - east) * 4);
ANormals[1] := VectorNorm(VectorCross(u, v)); Result[1] := VectorNorm(VectorCross(u, v));
u := Vector(22, -22, (south - west) * 4); u := Vector(22, -22, (south - west) * 4);
v := Vector(22, 22, (east - south) * 4); v := Vector(22, 22, (east - south) * 4);
ANormals[2] := VectorNorm(VectorCross(u, v)); Result[2] := VectorNorm(VectorCross(u, v));
u := Vector(-22, -22, (west - north) * 4); u := Vector(-22, -22, (west - north) * 4);
v := Vector(22, -22, (south - west) * 4); v := Vector(22, -22, (south - west) * 4);
ANormals[3] := VectorNorm(VectorCross(u, v)); Result[3] := VectorNorm(VectorCross(u, v));
end; end;
end; end;
begin begin

View File

@ -34,13 +34,15 @@ uses
ComCtrls, OpenGLContext, GL, GLU, UGameResources, ULandscape, ExtCtrls, ComCtrls, OpenGLContext, GL, GLU, UGameResources, ULandscape, ExtCtrls,
StdCtrls, Spin, UEnums, VirtualTrees, Buttons, UMulBlock, UWorldItem, math, StdCtrls, Spin, UEnums, VirtualTrees, Buttons, UMulBlock, UWorldItem, math,
LCLIntf, UOverlayUI, UStatics, UEnhancedMemoryStream, ActnList, LCLIntf, UOverlayUI, UStatics, UEnhancedMemoryStream, ActnList,
ImagingClasses, dateutils, UPlatformTypes, UVector, UMap, contnrs; ImagingClasses, dateutils, UPlatformTypes, UMap;
type type
TAccessChangedListener = procedure(AAccessLevel: TAccessLevel) of object; TAccessChangedListener = procedure(AAccessLevel: TAccessLevel) of object;
TScreenBufferState = (sbsValid, sbsIndexed, sbsFiltered); TScreenBufferState = (sbsValid, sbsIndexed, sbsFiltered);
TScreenBufferStates = set of TScreenBufferState; TScreenBufferStates = set of TScreenBufferState;
TGhostTile = class(TStaticItem);
{ TfrmMain } { TfrmMain }
TfrmMain = class(TForm) TfrmMain = class(TForm)
@ -342,7 +344,7 @@ var
implementation implementation
uses uses
UdmNetwork, UArt, UTiledata, UHue, UAdminHandling, UPackets, UdmNetwork, UArt, UTiledata, UAdminHandling, UPackets,
UfrmAccountControl, UGraphicHelper, ImagingComponents, UfrmDrawSettings, UfrmAccountControl, UGraphicHelper, ImagingComponents, UfrmDrawSettings,
UfrmBoundaries, UfrmElevateSettings, UfrmConfirmation, UfrmMoveSettings, UfrmBoundaries, UfrmElevateSettings, UfrmConfirmation, UfrmMoveSettings,
UfrmAbout, UPacketHandlers, UfrmHueSettings, UfrmRadar, UfrmLargeScaleCommand, UfrmAbout, UPacketHandlers, UfrmHueSettings, UfrmRadar, UfrmLargeScaleCommand,
@ -701,9 +703,11 @@ begin
WheelDelta := WheelDelta div WHEEL_DELTA; WheelDelta := WheelDelta div WHEEL_DELTA;
cursorNeedsUpdate := False; cursorNeedsUpdate := False;
if (CurrentTile is TVirtualTile) or ((ssCtrl in Shift) and (frmVirtualLayer.cbShowLayer.Checked)) then if (CurrentTile is TVirtualTile) or ((ssCtrl in Shift) and
(frmVirtualLayer.cbShowLayer.Checked)) then
begin begin
frmVirtualLayer.seZ.Value := EnsureRange(frmVirtualLayer.seZ.Value + WheelDelta, -128, 127); frmVirtualLayer.seZ.Value := EnsureRange(frmVirtualLayer.seZ.Value +
WheelDelta, -128, 127);
cursorNeedsUpdate := True; cursorNeedsUpdate := True;
Handled := True; Handled := True;
end else if not (ssCtrl in Shift) then end else if not (ssCtrl in Shift) then
@ -772,14 +776,17 @@ begin
RegisterPacketHandler($0C, TPacketHandler.Create(0, @OnClientHandlingPacket)); RegisterPacketHandler($0C, TPacketHandler.Create(0, @OnClientHandlingPacket));
virtualLayerGraphic := TSingleImage.CreateFromStream(ResourceManager.GetResource(2)); virtualLayerGraphic := TSingleImage.CreateFromStream(ResourceManager.GetResource(2));
FVLayerMaterial := TMaterial.Create(virtualLayerGraphic.Width, virtualLayerGraphic.Height, FVLayerMaterial := TMaterial.Create(virtualLayerGraphic.Width,
virtualLayerGraphic); virtualLayerGraphic.Height, virtualLayerGraphic);
virtualLayerGraphic.Free; virtualLayerGraphic.Free;
FVirtualTiles := TWorldItemList.Create(True); FVirtualTiles := TWorldItemList.Create(True);
FRandomPresetLocation := IncludeTrailingPathDelimiter(ExtractFilePath(Application.ExeName)) + 'RandomPresets' + PathDelim; FRandomPresetLocation := IncludeTrailingPathDelimiter(ExtractFilePath(
if not DirectoryExists(FRandomPresetLocation) then CreateDir(FRandomPresetLocation); Application.ExeName)) + 'RandomPresets' + PathDelim;
if not DirectoryExists(FRandomPresetLocation) then
CreateDir(FRandomPresetLocation);
if FindFirst(FRandomPresetLocation + '*.dat', faAnyFile, searchRec) = 0 then if FindFirst(FRandomPresetLocation + '*.dat', faAnyFile, searchRec) = 0 then
begin begin
repeat repeat
@ -851,8 +858,8 @@ end;
procedure TfrmMain.btnClearLocationsClick(Sender: TObject); procedure TfrmMain.btnClearLocationsClick(Sender: TObject);
begin begin
if MessageDlg('Are you sure you want to delete all saved locations?', mtConfirmation, if MessageDlg('Are you sure you want to delete all saved locations?',
[mbYes, mbNo], 0) = mrYes then mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin begin
vstLocations.Clear; vstLocations.Clear;
end; end;
@ -878,7 +885,8 @@ var
locationInfo: PLocationInfo; locationInfo: PLocationInfo;
begin begin
locationName := ''; locationName := '';
if InputQuery('New Location', 'Enter the name of the new location:', locationName) then if InputQuery('New Location', 'Enter the name of the new location:',
locationName) then
begin begin
locationInfo := vstLocations.GetNodeData(vstLocations.AddChild(nil)); locationInfo := vstLocations.GetNodeData(vstLocations.AddChild(nil));
locationInfo^.X := X; locationInfo^.X := X;
@ -1112,8 +1120,8 @@ begin
if node = nil then if node = nil then
begin begin
//edSearchID.Font.Color := clRed; //edSearchID.Font.Color := clRed;
MessageDlg('Error', 'The tile with the specified ID could not be found.' + LineEnding + MessageDlg('Error', 'The tile with the specified ID could not be found.' +
'Check for conflicting filter settings.', mtError, [mbOK], 0); LineEnding + 'Check for conflicting filter settings.', mtError, [mbOK], 0);
vdtTiles.SetFocus; vdtTiles.SetFocus;
Exit; Exit;
end; end;
@ -1124,7 +1132,8 @@ begin
edSearchID.Visible := False; edSearchID.Visible := False;
//edSearchID.Font.Color := clWindowText; //edSearchID.Font.Color := clWindowText;
Key := #0; Key := #0;
end else if not (Key in ['$', '0'..'9', 'a'..'f', 'A'..'F', 's', 'S', 't', 'T', #8]) then end else if not (Key in ['$', '0'..'9', 'a'..'f', 'A'..'F', 's', 'S',
't', 'T', #8]) then
Key := #0; Key := #0;
end; end;
@ -1569,7 +1578,8 @@ end;
procedure TfrmMain.SetPos(AX, AY: Word); procedure TfrmMain.SetPos(AX, AY: Word);
begin begin
if InRange(AX, 0, FLandscape.CellWidth - 1) and InRange(AY, 0, FLandscape.CellHeight - 1) then if InRange(AX, 0, FLandscape.CellWidth - 1) and InRange(AY, 0,
FLandscape.CellHeight - 1) then
begin begin
FX := AX; FX := AX;
edX.Value := FX; edX.Value := FX;
@ -1632,21 +1642,27 @@ begin
begin begin
FCurrentTile.OnDestroy.RegisterEvent(@OnTileRemoved); FCurrentTile.OnDestroy.RegisterEvent(@OnTileRemoved);
if FCurrentTile is TVirtualTile then if FCurrentTile is TVirtualTile then
lblTileInfo.Caption := Format('Virtual Layer: X: %d, Y: %d, Z: %d', [FCurrentTile.X, FCurrentTile.Y, FCurrentTile.Z]) lblTileInfo.Caption := Format('Virtual Layer: X: %d, Y: %d, Z: %d',
[FCurrentTile.X, FCurrentTile.Y, FCurrentTile.Z])
else if FCurrentTile is TMapCell then else if FCurrentTile is TMapCell then
lblTileInfo.Caption := Format('Terrain TileID: $%x, X: %d, Y: %d, Z: %d', [FCurrentTile.TileID, FCurrentTile.X, FCurrentTile.Y, FCurrentTile.Z]) lblTileInfo.Caption := Format('Terrain TileID: $%x, X: %d, Y: %d, Z: %d',
[FCurrentTile.TileID, FCurrentTile.X, FCurrentTile.Y, FCurrentTile.Z])
else if FCurrentTile is TStaticItem then else if FCurrentTile is TStaticItem then
lblTileInfo.Caption := Format('Static TileID: $%x, X: %d, Y: %d, Z: %d, Hue: $%x', [FCurrentTile.TileID, FCurrentTile.X, FCurrentTile.Y, FCurrentTile.Z, TStaticItem(FCurrentTile).Hue]); lblTileInfo.Caption := Format('Static TileID: $%x, X: %d, Y: %d, Z: %d, Hue: $%x',
[FCurrentTile.TileID, FCurrentTile.X, FCurrentTile.Y, FCurrentTile.Z,
TStaticItem(FCurrentTile).Hue]);
if (acDraw.Checked) and (SelectedTile = nil) then if (acDraw.Checked) and (SelectedTile = nil) then
begin begin
if FGhostTile <> nil then if FGhostTile <> nil then
begin begin
if (FGhostTile is TStaticItem) and (not frmDrawSettings.cbForceAltitude.Checked) then if (FGhostTile is TStaticItem) and
(not frmDrawSettings.cbForceAltitude.Checked) then
begin begin
FGhostTile.Z := CurrentTile.Z; FGhostTile.Z := CurrentTile.Z;
if FCurrentTile is TStaticItem then if FCurrentTile is TStaticItem then
FGhostTile.Z := FGhostTile.Z + ResMan.Tiledata.StaticTiles[FCurrentTile.TileID].Height; FGhostTile.Z := FGhostTile.Z +
ResMan.Tiledata.StaticTiles[FCurrentTile.TileID].Height;
end else end else
FGhostTile.Z := frmDrawSettings.seForceAltitude.Value; FGhostTile.Z := frmDrawSettings.seForceAltitude.Value;
end; end;
@ -1827,21 +1843,11 @@ end;
procedure TfrmMain.Render; procedure TfrmMain.Render;
var var
z: ShortInt;
mat: TMaterial;
staticItem: TStaticItem;
staticTileData: TStaticTileData;
hue: THue;
highlight: Boolean; highlight: Boolean;
ghostTile: TWorldItem;
tileRect: TRect;
virtualTile: TVirtualTile;
intensity: GLfloat; intensity: GLfloat;
blockInfo: PBlockInfo; blockInfo: PBlockInfo;
item: TWorldItem; item: TWorldItem;
begin begin
tileRect := GetSelectedRect;
if not (sbsValid in FScreenBufferState) then if not (sbsValid in FScreenBufferState) then
RebuildScreenBuffer; RebuildScreenBuffer;
@ -2009,8 +2015,10 @@ end;
procedure TfrmMain.OnStaticInserted(AStaticItem: TStaticItem); procedure TfrmMain.OnStaticInserted(AStaticItem: TStaticItem);
begin begin
if (AStaticItem.X >= FX + FLowOffsetX) and (AStaticItem.X <= FX + FHighOffsetX) and if (AStaticItem.X >= FX + FLowOffsetX) and
(AStaticItem.Y >= FY + FLowOffsetY) and (AStaticItem.Y <= FY + FHighOffsetY) then (AStaticItem.X <= FX + FHighOffsetX) and
(AStaticItem.Y >= FY + FLowOffsetY) and
(AStaticItem.Y <= FY + FHighOffsetY) then
begin begin
AStaticItem.PrioritySolver := FScreenBuffer.GetSerial; AStaticItem.PrioritySolver := FScreenBuffer.GetSerial;
PrepareScreenBlock(FScreenBuffer.Insert(AStaticItem)); PrepareScreenBlock(FScreenBuffer.Insert(AStaticItem));
@ -2045,7 +2053,8 @@ begin
begin begin
if ResMan.Art.Exists(i) then if ResMan.Art.Exists(i) then
begin begin
if (filter <> '') and (Pos(filter, AnsiLowerCase(TTileData(ResMan.Tiledata.Block[i]).TileName)) = 0) then Continue; if (filter <> '') and (Pos(filter, AnsiLowerCase(TTileData(
ResMan.Tiledata.Block[i]).TileName)) = 0) then Continue;
node := vdtTiles.AddChild(nil); node := vdtTiles.AddChild(nil);
tileInfo := vdtTiles.GetNodeData(node); tileInfo := vdtTiles.GetNodeData(node);
tileInfo^.ID := i; tileInfo^.ID := i;
@ -2078,7 +2087,8 @@ begin
if acSelect.Checked then if acSelect.Checked then
begin begin
//lblTip.Caption := 'Right click shows a menu with all the tools.'; //lblTip.Caption := 'Right click shows a menu with all the tools.';
lblTip.Caption := 'Press and hold the left mouse button to show a list with actions (eg. grab hue).'; lblTip.Caption := 'Press and hold the left mouse button to show a list with'
+ ' actions (eg. grab hue).';
oglGameWindow.Cursor := crDefault; oglGameWindow.Cursor := crDefault;
//no highlighted tiles in "selection" mode //no highlighted tiles in "selection" mode