- Initial import from internal repository

This commit is contained in:
2007-12-21 21:31:58 +01:00
commit c0a125042b
194 changed files with 86503 additions and 0 deletions

View File

@@ -0,0 +1,97 @@
(*
* 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 2007 Andreas Schneider
*)
unit UArtProvider;
{$mode objfpc}{$H+}
interface
uses
Graphics, UMulProvider, UMulBlock, UGenericIndex, UArt, UHue;
type
TArtProvider = class(TIndexedMulProvider)
protected
function GetData(AID: Integer; AIndex: TGenericIndex): TMulBlock; override;
function GetArtData(AID: Integer; AIndex: TGenericIndex; AColor: Word; AHue: THue; APartialHue: Boolean): TArt;
public
function GetArt(AID: Integer; AColor: Word; AHue: THue; APartialHue: Boolean): TArt;
function GetFlatLand(AID: Integer): TArt;
end;
implementation
{ TArtProvider }
function TArtProvider.GetData(AID: Integer; AIndex: TGenericIndex): TMulBlock;
begin
Result := GetArtData(AID, AIndex, clBlack, nil, False);
end;
function TArtProvider.GetArtData(AID: Integer; AIndex: TGenericIndex;
AColor: Word; AHue: THue; APartialHue: Boolean): TArt;
begin
if AIndex.Lookup <> LongInt($FFFFFFFF) then
begin
if AID < $4000 then
Result := TArt.Create(FData, AIndex, atLand, AColor, AHue, APartialHue)
else
Result := TArt.Create(FData, AIndex, atStatic, AColor, AHue, APartialHue);
end else
begin
if AID < $4000 then
Result := TArt.Create(nil, nil, atLand, AColor, AHue, APartialHue)
else
Result := TArt.Create(nil, nil, atStatic, AColor, AHue, APartialHue);
end;
Result.ID := AID;
end;
function TArtProvider.GetArt(AID: Integer; AColor: Word; AHue: THue; APartialHue: Boolean): TArt;
var
genericIndex: TGenericIndex;
begin
FIndex.Position := CalculateIndexOffset(AID);
genericIndex := TGenericIndex.Create(FIndex);
Result := GetArtData(AID, genericIndex, AColor, AHue, APartialHue);
genericIndex.Free;
Result.OnChanged := @OnChanged;
Result.OnFinished := @OnFinished;
end;
function TArtProvider.GetFlatLand(AID: Integer): TArt;
var
genericIndex: TGenericIndex;
begin
FIndex.Position := CalculateIndexOffset(AID);
genericIndex := TGenericIndex.Create(FIndex);
Result := TArt.Create(FData, genericIndex, atLandFlat);
genericIndex.Free;
Result.OnChanged := @OnChanged;
Result.OnFinished := @OnFinished;
end;
end.

View File

@@ -0,0 +1,63 @@
(*
* 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 2007 Andreas Schneider
*)
unit UGumpProvider;
{$mode objfpc}{$H+}
interface
uses
UMulProvider, UMulBlock, UGenericIndex, UGump;
type
TGumpProvider = class(TIndexedMulProvider)
protected
function GetData(AID: Integer; AIndex: TGenericIndex): TMulBlock; override;
function GetVarious(AID: Integer; ABlock: TMulBlock; ADefault: Integer): Integer; override;
end;
implementation
{ TGumpProvider }
function TGumpProvider.GetData(AID: Integer; AIndex: TGenericIndex): TMulBlock;
begin
if AIndex.Lookup <> LongInt($FFFFFFFF) then
Result := TGump.Create(FData, TGumpIndex(AIndex))
else
Result := TGump.Create(0, 0);
Result.ID := AID;
end;
function TGumpProvider.GetVarious(AID: Integer; ABlock: TMulBlock;
ADefault: Integer): Integer;
begin
Result := TGump(ABlock).Graphic.Height or (TGump(ABlock).Graphic.Width shl 16);
end;
end.

View File

@@ -0,0 +1,153 @@
(*
* 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 2007 Andreas Schneider
*)
unit UHueProvider;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Classes, Contnrs, UMulProvider, UMulBlock, UHue;
type
THueProvider = class(TMulProvider)
constructor Create(AData: TStream; AReadOnly: Boolean = False); overload; override;
constructor Create(AData: string; AReadOnly: Boolean = False); overload; override;
destructor Destroy; override;
protected
FHueGroups: TObjectList;
procedure InitList;
function CalculateOffset(AID: Integer): Integer; override;
function GetData(AID, AOffset: Integer): TMulBlock; override;
procedure SetData(AID, AOffset: Integer; ABlock: TMulBlock); override;
function GetHue(AIndex: Integer): THue;
function GetCount: Integer;
public
function GetBlock(AID: Integer): TMulBlock; override;
property Hues[Index: Integer]: THue read GetHue;
property Count: Integer read GetCount;
end;
implementation
{ THueProvider }
function THueProvider.CalculateOffset(AID: Integer): Integer;
begin
Result := (AID div 8) * 708 + (AID mod 8) * 88;
end;
constructor THueProvider.Create(AData: TStream; AReadOnly: Boolean = False);
begin
inherited;
InitList;
end;
constructor THueProvider.Create(AData: string; AReadOnly: Boolean = False);
begin
inherited;
InitList;
end;
destructor THueProvider.Destroy;
begin
FHueGroups.Free;
inherited;
end;
function THueProvider.GetBlock(AID: Integer): TMulBlock;
begin
Result := GetData(AID, 0);
end;
function THueProvider.GetCount: Integer;
begin
Result := FHueGroups.Count * 8;
end;
function THueProvider.GetData(AID, AOffset: Integer): TMulBlock;
var
group, entry: Integer;
begin
group := (AID div 8) mod FHueGroups.Count;
entry := AID mod 8;
Result := TMulBlock(THueGroup(FHueGroups.Items[group]).HueEntries[entry].Clone);
Result.ID := AID;
Result.OnChanged := @OnChanged;
Result.OnFinished := @OnFinished;
end;
function THueProvider.GetHue(AIndex: Integer): THue;
var
group, entry: Integer;
begin
group := (AIndex div 8) mod FHueGroups.Count;
entry := AIndex mod 8;
Result := THue(THueGroup(FHueGroups.Items[group]).HueEntries[entry]);
Result.ID := AIndex;
end;
procedure THueProvider.InitList;
var
i: Integer;
begin
FHueGroups := TObjectList.Create;
FHueGroups.Count := FData.Size div 708;
FData.Position := 0;
i := 0;
while FData.Position < FData.Size do
begin
FHueGroups.Items[i] := THueGroup.Create(FData);
Inc(i);
end;
end;
procedure THueProvider.SetData(AID, AOffset: Integer;
ABlock: TMulBlock);
var
group, entry: Integer;
begin
group := AID div 8;
entry := AID mod 8;
if (group >= FHueGroups.Count) or (group < 0) then
begin
group := FHueGroups.Count;
FHueGroups.Add(THueGroup.Create(nil));
entry := 0;
end;
THueGroup(FHueGroups.Items[group]).HueEntries[entry] := THue(ABlock.Clone);
if not FReadOnly then
begin
FData.Position := AOffset;
ABlock.Write(FData);
end;
end;
end.

111
MulProvider/UMulManager.pas Normal file
View File

@@ -0,0 +1,111 @@
(*
* 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 2007 Andreas Schneider
*)
unit UMulManager;
interface
uses
SysUtils, UMulProvider, UTileDataProvider, UArtProvider, UGumpProvider,
UTexmapProvider, UHueProvider, URadarProvider;
type
TMulManager = class(TObject)
destructor Destroy; override;
protected
FArtProvider: TArtProvider;
FGumpProvider: TGumpProvider;
FTexmapProvider: TTexmapProvider;
FTileDataProvider: TTileDataProvider;
FHueProvider: THueProvider;
FRadarProvider: TRadarProvider;
public
procedure RegisterArtProvider(AArtProvider: TArtProvider);
procedure RegisterGumpProvider(AGumpProvider: TGumpProvider);
procedure RegisterTexmapProvider(ATexmapProvider: TTexmapProvider);
procedure RegisterTileDataProvider(ATileDataProvider: TTileDataProvider);
procedure RegisterHueProvider(AHueProvider: THueProvider);
procedure RegisterRadarProvider(ARadarProvider: TRadarProvider);
property ArtProvider: TArtProvider read FArtProvider;
property GumpProvider: TGumpProvider read FGumpProvider;
property TexmapProvider: TTexmapProvider read FTexmapProvider;
property TileDataProvider: TTileDataProvider read FTileDataProvider;
property HueProvider: THueProvider read FHueProvider;
property RadarProvider: TRadarPRovider read FRadarProvider;
end;
implementation
{ TMulManager }
destructor TMulManager.Destroy;
begin
RegisterArtProvider(nil);
RegisterGumpProvider(nil);
RegisterTexmapProvider(nil);
RegisterTileDataProvider(nil);
RegisterHueProvider(nil);
RegisterRadarProvider(nil);
inherited;
end;
procedure TMulManager.RegisterArtProvider(AArtProvider: TArtProvider);
begin
if Assigned(FArtProvider) then FreeAndNil(FArtProvider);
FArtProvider := AArtProvider;
end;
procedure TMulManager.RegisterGumpProvider(AGumpProvider: TGumpProvider);
begin
if Assigned(FGumpProvider) then FreeAndNil(FGumpProvider);
FGumpProvider := AGumpProvider;
end;
procedure TMulManager.RegisterHueProvider(AHueProvider: THueProvider);
begin
if Assigned(FHueProvider) then FreeAndNil(FHueProvider);
FHueProvider := AHueProvider;
end;
procedure TMulManager.RegisterRadarProvider(ARadarProvider: TRadarProvider);
begin
if Assigned(FRadarProvider) then FreeAndNil(FRadarProvider);
FRadarProvider := ARadarProvider;
end;
procedure TMulManager.RegisterTexmapProvider(ATexmapProvider: TTexmapProvider);
begin
if Assigned(FTexmapProvider) then FreeAndNil(FTexmapProvider);
FTexmapProvider := ATexmapProvider;
end;
procedure TMulManager.RegisterTileDataProvider(
ATileDataProvider: TTileDataProvider);
begin
if Assigned(FTileDataProvider) then FreeAndNil(FTileDataProvider);
FTileDataProvider := ATileDataProvider;
end;
end.

View File

@@ -0,0 +1,378 @@
(*
* 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 2007 Andreas Schneider
*)
unit UMulProvider;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Classes, UBufferedStreams, UMulBlock, UGenericIndex;
type
TOnProgressEvent = procedure(Total, Current: Integer) of object;
TMulEventHandler = class(TObject)
constructor Create;
destructor Destroy; override;
protected
FEvents: TList;
public
procedure RegisterEvent(AEvent: TMulBlockChanged);
procedure UnregisterEvent(AEvent: TMulBlockChanged);
procedure FireEvents(ABlock: TMulBlock);
end;
TMulProvider = class(TObject)
constructor Create; overload; virtual;
constructor Create(AData: TStream; AReadOnly: Boolean = False); overload; virtual;
constructor Create(AData: string; AReadOnly: Boolean = False); overload; virtual;
destructor Destroy; override;
protected
FData: TStream;
FOwnsData: Boolean;
FReadOnly: Boolean;
FChangeEvents: TMulEventHandler;
FFinishedEvents: TMulEventHandler;
function CalculateOffset(AID: Integer): Integer; virtual; abstract;
function GetData(AID, AOffset: Integer): TMulBlock; virtual; abstract;
procedure SetData(AID, AOffset: Integer; ABlock: TMulBlock); virtual;
procedure OnChanged(ABlock: TMulBlock);
procedure OnFinished(ABlock: TMulBlock);
public
function GetBlock(AID: Integer): TMulBlock; virtual;
procedure SetBlock(AID: Integer; ABlock: TMulBlock); virtual;
procedure RegisterOnChangeEvent(AEvent: TMulBlockChanged);
procedure UnregisterOnChangeEvent(AEvent: TMulBlockChanged);
procedure RegisterOnFinishedEvent(AEvent: TMulBlockChanged);
procedure UnregisterOnFinishedEvent(AEvent: TMulBlockChanged);
property Block[ID: Integer]: TMulBlock read GetBlock write SetBlock;
property Data: TStream read FData;
end;
TIndexedMulProvider = class(TMulProvider)
constructor Create(AData, AIndex: TStream; AReadOnly: Boolean = False); overload; virtual;
constructor Create(AData, AIndex: string; AReadOnly: Boolean = False); overload; virtual;
destructor Destroy; override;
protected
FIndex: TBufferedReader;
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;
function GetVarious(AID: Integer; ABlock: TMulBlock; ADefault: Integer): Integer; virtual;
public
function GetBlock(AID: Integer): TMulBlock; override;
procedure GetBlockEx(AID: Integer; var ABlock: TMulBlock; var AIndex: TGenericIndex); virtual;
procedure SetBlock(AID: Integer; ABlock: TMulBlock); override;
function Exists(AID: Integer): Boolean; virtual;
procedure Defragment(ATempStream: TStream; AOnProgress: TOnProgressEvent = nil); virtual;
property Index: TBufferedReader read FIndex;
end;
implementation
type
PMethod = ^TMethod;
{ TMulEventHandler }
constructor TMulEventHandler.Create;
begin
inherited;
FEvents := TList.Create;
end;
destructor TMulEventHandler.Destroy;
var
i: Integer;
begin
if Assigned(FEvents) then
begin
for i := 0 to FEvents.Count - 1 do
Dispose(PMethod(FEvents.Items[i]));
FreeAndNil(FEvents);
end;
inherited;
end;
procedure TMulEventHandler.FireEvents(ABlock: TMulBlock);
var
i: Integer;
begin
for i := 0 to FEvents.Count - 1 do
TMulBlockChanged(FEvents.Items[i]^)(ABlock);
end;
procedure TMulEventHandler.RegisterEvent(AEvent: TMulBlockChanged);
var
eventInfo: PMethod;
begin
UnregisterEvent(AEvent);
New(eventInfo);
eventInfo^.Code := TMethod(AEvent).Code;
eventInfo^.Data := TMethod(AEvent).Data;
FEvents.Add(eventInfo);
end;
procedure TMulEventHandler.UnregisterEvent(AEvent: TMulBlockChanged);
var
i: Integer;
function RemoveEntry: Boolean;
begin
Dispose(PMethod(FEvents.Items[i]));
FEvents.Delete(i);
Result := True;
end;
begin
i := 0;
while (i < FEvents.Count) and ((TMethod(AEvent).Code <> TMethod(FEvents.Items[i]^).Code) or (TMethod(AEvent).Data <> TMethod(FEvents.Items[i]^).Data) or not RemoveEntry) do
Inc(i);
end;
{ TMulProvider }
constructor TMulProvider.Create(AData: TStream; AReadOnly: Boolean = False);
begin
Create;
FData := AData;
FOwnsData := False;
FReadOnly := AReadOnly;
end;
constructor TMulProvider.Create(AData: string; AReadOnly: Boolean = False);
var
mode: Word;
begin
Create;
if AReadOnly then
mode := fmOpenRead or fmShareDenyWrite
else
mode := fmOpenReadWrite or fmShareDenyWrite;
FData := TFileStream.Create(AData, mode);
FOwnsData := True;
FReadOnly := AReadOnly;
end;
constructor TMulProvider.Create;
begin
inherited;
FChangeEvents := TMulEventHandler.Create;
FFinishedEvents := TMulEventHandler.Create;
end;
destructor TMulProvider.Destroy;
begin
if FOwnsData and Assigned(FData) then FreeAndNil(FData);
if Assigned(FChangeEvents) then FreeAndNil(FChangeEvents);
if Assigned(FFinishedEvents) then FreeAndNil(FFinishedEvents);
inherited;
end;
function TMulProvider.GetBlock(AID: Integer): TMulBlock;
begin
Result := GetData(AID, CalculateOffset(AID));
Result.OnChanged := @OnChanged;
Result.OnFinished := @OnFinished;
end;
procedure TMulProvider.OnChanged(ABlock: TMulBlock);
begin
SetBlock(ABlock.ID, ABlock);
FChangeEvents.FireEvents(ABlock);
end;
procedure TMulProvider.OnFinished(ABlock: TMulBlock);
begin
FFinishedEvents.FireEvents(ABlock);
ABlock.Free;
end;
procedure TMulProvider.RegisterOnChangeEvent(AEvent: TMulBlockChanged);
begin
FChangeEvents.RegisterEvent(AEvent);
end;
procedure TMulProvider.RegisterOnFinishedEvent(AEvent: TMulBlockChanged);
begin
FFinishedEvents.RegisterEvent(AEvent);
end;
procedure TMulProvider.SetBlock(AID: Integer; ABlock: TMulBlock);
begin
if FReadOnly then Exit;
SetData(AID, CalculateOffset(AID), ABlock);
end;
procedure TMulProvider.SetData(AID, AOffset: Integer; ABlock: TMulBlock);
begin
if FReadOnly then Exit;
FData.Position := AOffset;
ABlock.Write(FData);
end;
procedure TMulProvider.UnregisterOnChangeEvent(AEvent: TMulBlockChanged);
begin
FChangeEvents.UnregisterEvent(AEvent);
end;
procedure TMulProvider.UnregisterOnFinishedEvent(AEvent: TMulBlockChanged);
begin
FFinishedEvents.UnregisterEvent(AEvent);
end;
{ TIndexedMulProvider }
function TIndexedMulProvider.CalculateIndexOffset(AID: Integer): Integer;
begin
Result := 12 * AID;
end;
constructor TIndexedMulProvider.Create(AData, AIndex: TStream; AReadOnly: Boolean = False);
begin
inherited Create(AData, AReadOnly);
FIndex := TBufferedReader.Create(AIndex);
end;
constructor TIndexedMulProvider.Create(AData, AIndex: string; AReadOnly: Boolean = False);
var
mode: Word;
begin
inherited Create(AData, AReadOnly);
if AReadOnly then
mode := fmOpenRead or fmShareDenyWrite
else
mode := fmOpenReadWrite or fmShareDenyWrite;
FIndex := TBufferedReader.Create(TFileStream.Create(AIndex, mode), True);
end;
procedure TIndexedMulProvider.Defragment(ATempStream: TStream; AOnProgress: TOnProgressEvent = nil);
var
genericIndex: TGenericIndex;
begin
if FReadOnly then Exit;
ATempStream.Size := FData.Size;
ATempStream.Position := 0;
FIndex.Position := 0;
while FIndex.Position < FIndex.Size do
begin
genericIndex := TGenericIndex.Create(FIndex);
if genericIndex.Lookup <> LongInt($FFFFFFFF) then
begin
FData.Position := genericIndex.Lookup;
genericIndex.Lookup := ATempStream.Position;
ATempStream.CopyFrom(FData, genericIndex.Size);
FIndex.Seek(-12, soFromCurrent);
genericIndex.Write(FIndex);
end;
genericIndex.Free;
if Assigned(AOnProgress) and (FIndex.Position mod 1200 = 0) then
AOnProgress(FIndex.Size, FIndex.Position);
end;
FData.Size := ATempStream.Position;
FData.Position := 0;
ATempStream.Position := 0;
FData.CopyFrom(ATempStream, FData.Size);
end;
destructor TIndexedMulProvider.Destroy;
begin
if Assigned(FIndex) then FreeAndNil(FIndex);
inherited;
end;
function TIndexedMulProvider.Exists(AID: Integer): Boolean;
var
genericIndex: TGenericIndex;
begin
FIndex.Position := CalculateIndexOffset(AID);
genericIndex := TGenericIndex.Create(FIndex);
Result := genericIndex.Lookup <> LongInt($FFFFFFFF);
genericIndex.Free;
end;
function TIndexedMulProvider.GetBlock(AID: Integer): TMulBlock;
var
genericIndex: TGenericIndex;
begin
GetBlockEx(AID, Result, genericIndex);
genericIndex.Free;
end;
procedure TIndexedMulProvider.GetBlockEx(AID: Integer;
var ABlock: TMulBlock; var AIndex: TGenericIndex);
begin
FIndex.Position := CalculateIndexOffset(AID);
AIndex := TGenericIndex.Create(FIndex);
ABlock := GetData(AID, AIndex);
ABlock.OnChanged := @OnChanged;
ABlock.OnFinished := @OnFinished;
end;
function TIndexedMulProvider.GetVarious(AID: Integer; ABlock: TMulBlock;
ADefault: Integer): Integer;
begin
Result := ADefault;
end;
procedure TIndexedMulProvider.SetBlock(AID: Integer; ABlock: TMulBlock);
var
genericIndex: TGenericIndex;
begin
if FReadOnly then Exit;
FIndex.Position := CalculateIndexOffset(AID);
genericIndex := TGenericIndex.Create(FIndex);
SetData(AID, genericIndex, ABlock);
FIndex.Position := CalculateIndexOffset(AID);
genericIndex.Various := GetVarious(AID, ABlock, genericIndex.Various);
genericIndex.Write(FIndex);
genericIndex.Free;
end;
procedure TIndexedMulProvider.SetData(AID: Integer; AIndex: TGenericIndex;
ABlock: TMulBlock);
var
size: Integer;
begin
if FReadOnly then Exit;
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
begin
FData.Position := FData.Size;
AIndex.Lookup := FData.Position;
ABlock.Write(FData);
end else
begin
FData.Position := AIndex.Lookup;
ABlock.Write(FData);
end;
AIndex.Size := size;
end;
end.

View File

@@ -0,0 +1,103 @@
(*
* 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 2007 Andreas Schneider
*)
unit URadarProvider;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Classes, UBufferedStreams;
type
TRadarProvider = class(TObject)
constructor Create; overload; virtual;
constructor Create(AData: TStream; AReadOnly: Boolean = False); overload; virtual;
constructor Create(AData: string; AReadOnly: Boolean = False); overload; virtual;
destructor Destroy; override;
protected
FData: TBufferedReader;
FReadOnly: Boolean;
public
function GetColor(AID: Integer): Word;
procedure SetColor(AID: Integer; AColor: Word);
end;
implementation
{ TRaderProvider }
constructor TRadarProvider.Create;
begin
inherited Create;
end;
constructor TRadarProvider.Create(AData: TStream; AReadOnly: Boolean);
begin
Create;
FData := TBufferedReader.Create(AData, False);
FReadOnly := AReadOnly;
end;
constructor TRadarProvider.Create(AData: string; AReadOnly: Boolean);
var
mode: Word;
begin
Create;
if AReadOnly then
mode := fmOpenRead or fmShareDenyWrite
else
mode := fmOpenReadWrite or fmShareDenyWrite;
FData := TBufferedReader.Create(TFileStream.Create(AData, mode), True);
FReadOnly := AReadOnly;
end;
destructor TRadarProvider.Destroy;
begin
if Assigned(FData) then FreeAndNil(FData);
inherited Destroy;
end;
function TRadarProvider.GetColor(AID: Integer): Word;
begin
if (AID >= 0) and (AID < $10000) then
begin
FData.Position := SizeOf(Word) * AID;
FData.Read(Result, SizeOf(Word));
end else
Result := 0;
end;
procedure TRadarProvider.SetColor(AID: Integer; AColor: Word);
begin
if (not FReadOnly) and (AID >= 0) and (AID < $10000) then
begin
FData.Position := SizeOf(Word) * AID;
FData.Write(AColor, SizeOf(Word));
end;
end;
end.

View File

@@ -0,0 +1,56 @@
(*
* 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 2007 Andreas Schneider
*)
unit UTexmapProvider;
{$mode objfpc}{$H+}
interface
uses
UMulProvider, UMulBlock, UGenericIndex, UTexture;
type
TTexmapProvider = class(TIndexedMulProvider)
protected
function GetData(AID: Integer; AIndex: TGenericIndex): TMulBlock; override;
end;
implementation
{ TTexmapProvider }
function TTexmapProvider.GetData(AID: Integer; AIndex: TGenericIndex): TMulBlock;
begin
if AIndex.Lookup <> LongInt($FFFFFFFF) then
Result := TTexture.Create(FData, AIndex)
else
Result := TTexture.Create(-1);
Result.ID := AID;
end;
end.

View File

@@ -0,0 +1,143 @@
(*
* 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 2007 Andreas Schneider
*)
unit UTileDataProvider;
{$mode objfpc}{$H+}
interface
uses
SysUtils, Classes, UMulProvider, UMulBlock, UTiledata;
type
TLandTileDataArray = array[$0..$3FFF] of TLandTileData;
TStaticTileDataArray = array[$0..$3FFF] of TStaticTileData;
TTiledataProvider = class(TMulProvider)
constructor Create(AData: TStream; AReadOnly: Boolean = False); overload; override;
constructor Create(AData: string; AReadOnly: Boolean = False); overload; override;
destructor Destroy; override;
protected
FLandTiles: TLandTileDataArray;
FStaticTiles: TStaticTileDataArray;
procedure InitArray;
function CalculateOffset(AID: Integer): Integer; override;
function GetData(AID, AOffset: Integer): TMulBlock; override;
procedure SetData(AID, AOffset: Integer; ABlock: TMulBlock); override;
public
function GetBlock(AID: Integer): TMulBlock; override;
property LandTiles: TLandTileDataArray read FLandTiles;
property StaticTiles: TStaticTileDataArray read FStaticTiles;
end;
implementation
{ TTiledataProvider }
function TTiledataProvider.CalculateOffset(AID: Integer): Integer;
begin
Result := GetTileDataOffset(AID);
end;
constructor TTiledataProvider.Create(AData: TStream; AReadOnly: Boolean = False);
begin
inherited;
InitArray;
end;
constructor TTiledataProvider.Create(AData: string; AReadOnly: Boolean = False);
begin
inherited;
InitArray;
end;
destructor TTiledataProvider.Destroy;
var
i: Integer;
begin
for i := $0 to $3FFF do
begin
if Assigned(FLandTiles[i]) then FreeAndNil(FLandTiles[i]);
if Assigned(FStaticTiles[i]) then FreeAndNil(FStaticTiles[i]);
end;
inherited;
end;
function TTiledataProvider.GetBlock(AID: Integer): TMulBlock;
begin
Result := GetData(AID, 0);
end;
function TTiledataProvider.GetData(AID, AOffset: Integer): TMulBlock;
begin
if AID < $4000 then
Result := TMulBlock(FLandTiles[AID].Clone)
else
Result := TMulBlock(FStaticTiles[AID - $4000].Clone);
Result.ID := AID;
Result.OnChanged := @OnChanged;
Result.OnFinished := @OnFinished;
end;
procedure TTiledataProvider.InitArray;
var
i: Integer;
begin
for i := $0 to $3FFF do
begin
FData.Position := GetTileDataOffset(i);
FLandTiles[i] := TLandTileData.Create(FData);
end;
for i := $0 to $3FFF do
begin
FData.Position := GetTileDataOffset($4000 + i);
FStaticTiles[i] := TStaticTileData.Create(FData);
end;
end;
procedure TTiledataProvider.SetData(AID, AOffset: Integer;
ABlock: TMulBlock);
begin
if AID < $4000 then
begin
if Assigned(FLandTiles[AID]) then FreeAndNil(FLandTiles[AID]);
FLandTiles[AID] := TLandTileData(ABlock.Clone);
end else
begin
if Assigned(FStaticTiles[AID - $4000]) then FreeAndNil(FStaticTiles[AID - $4000]);
FStaticTiles[AID - $4000] := TStaticTileData(ABlock.Clone);
end;
if not FReadOnly then
begin
FData.Position := AOffset;
ABlock.Write(FData);
end;
end;
end.