anchor.diff:    Result := PtrInt(d1) - PtrInt(d2);
   end;
   
  -
  -{ TBaseSprite }
  -
  -procedure TBaseSprite.UnBind;
  -begin
  -  editor_gl.Unbind(TextureId);
  -end;
  -
  -{ TGraphicsCosnumer }
  -
  -constructor TGraphicsCosnumer.Create(AOwner: TComponent);
  -begin
  -  inherited Create(AOwner);
  -
  -  if AOwner is TGraphicsManager then
  -  begin
  -    GraphicsManager := (AOwner as TGraphicsManager);
  -  end;
  -end;
  -
  -procedure TGraphicsCosnumer.SetGraphicsManager(AValue: TGraphicsManager);
  -begin
  -  if FGraphicsManager = AValue then Exit;
  -  FGraphicsManager := AValue;
  -end;
  -
  -{ TGraphicsManager }
  -
  -constructor TGraphicsManager.Create(AOwner: TComponent);
  -const
  -  FMT = 'AF0%dE';
  -var
  -  i: TPlayer;
  -begin
  -  inherited Create(AOwner);
  -  FNameToDefMap := TDefMap.Create;
  -  FBuffer := TMemoryStream.Create;
  -
  -  for i in TPlayerColor do
  -  begin
  -    FHeroFlagDefs[i] := GetGraphics(Format(FMT,[Integer(i)]));
  -  end;
  -end;
  -
  -destructor TGraphicsManager.Destroy;
  -begin
  -  FBuffer.Free;
  -  FNameToDefMap.Free;
  -  inherited Destroy;
  -end;
  -
  -function TGraphicsManager.GetGraphics(const AResourceName: string): TDef;
  -var
  -  res_index: Integer;
  -begin
  -
  -  res_index :=  FNameToDefMap.IndexOf(AResourceName);
  -
  -  if res_index >= 0 then
  -  begin
  -    Result := FNameToDefMap.Data[res_index];
  -  end
  -  else begin
  -    Result := TDef.Create;
  -    LoadDef(AResourceName,Result);
  -    FNameToDefMap.Add(AResourceName,Result);
  -  end;
  -
  -end;
  -
  -function TGraphicsManager.GetHeroFlagDef(APlayer: TPlayer): TDef;
  -begin
  -  Result := FHeroFlagDefs[APlayer];
  -end;
  -
  -procedure TGraphicsManager.LoadDef(const AResourceName: string; ADef: TDef);
  -begin
  -  ResourceLoader.LoadResource(Adef,TResourceType.Animation,'SPRITES/'+AResourceName);
  -end;
  -
  -
  -{ TDefMap }
  -
  -constructor TDefMap.Create;
  -begin
  -  inherited Create;
  -  OnKeyCompare := @CompareStr;
  -  OnDataCompare := @CompareDefs;
  -
  -  Sorted := True;
  -end;
  -
  -procedure TDefMap.Deref(Item: Pointer);
  -begin
  -  //inherited Deref(Item);
  -  Finalize(string(Item^));
  -  TDef(Pointer(PByte(Item)+KeySize)^).Free;
  -end;
  -
  -{ TDef }
  -
  -constructor TDef.Create;
  -begin
  -  entries := TDefEntries.Create;
  -  FTexturesBinded := false;
  -end;
  -
  -destructor TDef.Destroy;
  -begin
  -  MayBeUnBindTextures;
  -
  -  entries.Destroy;
  -  inherited Destroy;
  -end;
  -
  -function TDef.GetFrameCount: Integer;
  -begin
  -  Result := entries.Size;
  -end;
  -
  -procedure TDef.LoadFromStream(AStream: TStream);
  -var
  -  id_s: array of GLuint;
  -
  -  procedure GenerateTextureIds;
  -    var
  -      count: LongWord;
  -    begin
  -      count := entries.Size;
  -      SetLength(id_s,count);
  -      glGenTextures(count, @id_s[0]);
  -    end;
  -var
  -  offsets : packed array of UInt32;
  -  total_entries: Integer;
  -  block_nomber: Integer;
  -
  -  current_block_head: TH3DefEntryBlockHeader;
  -  total_in_block: Integer;
  -
  -  current_offcet: UInt32;
  -
  -  i: Uint8;
  -
  -
  -  header: TH3DefHeader;
  -  orig_position: Int32;
  -begin
  -  if FTexturesBinded then
  -    UnBindTextures;
  -  FTexturesBinded := false;
  -
  -  orig_position := AStream.Position;
  -
  -  AStream.Read(header{%H-},SizeOf(header));
  -
  -  typ := LEtoN(header.typ);
  -  FHeight := LEtoN(header.height);
  -  blockCount := LEtoN(header.blockCount);
  -  FWidth := LEtoN(header.width);
  -
  -  //TODO: use color comparison instead of index
  -
  -  for i := 0 to 7 do
  -  begin
  -    palette[i] := STANDARD_COLORS[i];
  -  end;
  -
  -  for i := 8 to 255 do
  -  begin
  -    palette[i].a := 255; //no alpha in h3 def
  -    palette[i].b := header.palette[i].b;
  -    palette[i].g := header.palette[i].g;
  -    palette[i].r := header.palette[i].r;
  -  end;
  -
  -  glGenTextures(1,@FPaletteID);
  -  BindPalette(FPaletteID,@palette);
  -
  -  total_entries := 0;
  -
  -  for block_nomber := 0 to header.blockCount - 1 do
  -  begin
  -     AStream.Read(current_block_head{%H-},SizeOf(current_block_head));
  -
  -     total_in_block := current_block_head.totalInBlock;
  -
  -     SetLength(offsets, total_entries + total_in_block);
  -
  -     //entries.Resize(total_entries + total_in_block);
  -
  -     //names
  -     AStream.Seek(13*total_in_block,soCurrent);
  -
  -     //offcets
  -     for i := 0 to total_in_block - 1 do
  -     begin
  -       AStream.Read(current_offcet{%H-},SizeOf(current_offcet));
  -       offsets[total_entries+i] := current_offcet+UInt32(orig_position);
  -
  -       //todo: use block_nomber to load heroes defs from mods
  -
  -       //entries.Mutable[total_entries+i]^.group := block_nomber;
  -     end;
  -
  -     total_entries += total_in_block;
  -  end;
  -
  -  entries.Resize(total_entries);
  -
  -  GenerateTextureIds;
  -
  -  for i := 0 to entries.Size - 1 do
  -  begin
  -    LoadSprite(AStream, i, id_s[i], offsets[i]);
  -  end;
  -
  -  SetLength(FBuffer,0); //clear
  -end;
  -
  -procedure TDef.LoadSprite(AStream: TStream; const SpriteIndex: UInt8;
  +{ TDefFormatLoader }
  +
  +constructor TDefFormatLoader.Create;
  +begin
  +  SetLength(FBuffer, INITIAL_BUFFER_SIZE);
  +end;
  +
  +destructor TDefFormatLoader.Destroy;
  +begin
  +  inherited;
  +end;
  +
  +procedure TDefFormatLoader.IncreaseBuffer(ANewSize: SizeInt);
  +begin
  +  if ANewSize > Length(FBuffer) then
  +  begin
  +
  +    ANewSize := (ANewSize div INITIAL_BUFFER_SIZE + 1)*INITIAL_BUFFER_SIZE;
  +
  +    SetLength(FBuffer, ANewSize);
  +  end;
  +end;
  +
  +procedure TDefFormatLoader.LoadSprite(AStream: TStream; const SpriteIndex: UInt8;
     ATextureID: GLuint; offset: Uint32);
   var
     ftcp: Int32;
  
positive.code: 
  end;
  
  procedure TDef.ResizeBuffer(w, h: Integer);
  var
    old_len, new_len: Integer;
  begin
    old_len := Length(FBuffer);
    new_len := h * w;
    new_len := Max(old_len,new_len);
    SetLength(FBuffer, new_len);
  end;
  
  procedure TDef.UnBindTextures;
  var
    SpriteIndex: Integer;
  
negative.code:   end;
  
  begin
    PEntry := FCurrentDef.entries.Mutable[SpriteIndex];
  
    BaseOffset := offset;
  
  