ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 低调看直播体育app软件下载 >> Delphijrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播 >> Spine Runtime for Delphi移植笔记(五) - spinecoreatlas

Spine Runtime for Delphi移植笔记(五) - spinecoreatlas

来源:网络整理     时间:2017-07-31     关键词:

本篇文章主要介绍了" Spine Runtime for Delphi移植笔记(五) - spinecoreatlas",主要涉及到方面的内容,对于Delphijrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播感兴趣的同学可以参考一下: ////////////////////////////////////////////////////////////////////////////////...

////////////////////////////////////////////////////////////////////////////////
//Generic delphi runtime v3.6 for Spine animation tool                        //
//Runtime port by cjk (hzi1980@163.com)                                       //
////////////////////////////////////////////////////////////////////////////////unit spine.core.atlas;

interfaceuses
  System.Classes, System.SysUtils, System.Generics.Collections, System.TypInfo,
  System.Math, spine.types, spine.classes;

type
  TSpineAltas = class(IAtlas)
  privatetype
    TupleStringArray = array [0..3] ofstring;
  private
    FPages: TObjectList;
    FRegions: TObjectDictionary<string, TAtlasRegion>;
    FTextureLoader: ITextureLoader;
    procedure Load(const AStream: TStream);
  publicconstructorCreate(const AStream: TStream; const ATextureLoader: ITextureLoader);
    destructorDestroy; override;
  end;

implementation{ TSpineAltas }constructor TSpineAltas.Create(const AStream: TStream;
  const ATextureLoader: ITextureLoader);
begininheritedCreate;
  FPages:= TObjectList.Create;
  FRegions:= TObjectDictionary<string,TAtlasRegion>.Create([doOwnsValues]);
  FTextureLoader:= ATextureLoader;
  Load(AStream);
end;

destructor TSpineAltas.Destroy;
begin
  FPages.Free;
  FRegions.Free;
  inherited;
end;

procedure TSpineAltas.Load(const AStream: TStream);
var
  EndOf: Boolean;

  function ReadLn(): string;
  var
    b, b1: Byte;
  begin
    Result:= '';
    if AStream.Position = AStream.Size thenbegin
      EndOf:= True;
      Exit;
    end;
    //
while AStream.Position < AStream.Size dobegin{$Hints off}
      AStream.Read(b, 1);
      {$Hints on}if (b <> $D) and (b <> $A) then
        Result:= Result + AnsiChar(Chr(b))
      else
        Break;
    end;
    //
if AStream.Position < AStream.Size then{$Hints off}
      AStream.Read(b1, 1)
      {$Hints on}else Exit;
    //
while ((b1 = $D) or (b1 = $A)) and (b1 <> b) and (AStream.Position < AStream.Size) do
      AStream.Read(b1, 1);
    //
if AStream.Position < AStream.Size then
      AStream.Position:= AStream.Position - 1;
  end;

  function ReadTuple(out ATuple: TupleStringArray): Integer;
  var
    ln: string;
    colon, i, lastMatch, comma: Integer;
  begin
    ln:= Trim(ReadLn);
    colon:= ln.IndexOf(':');
    if colon = -1thenraise Exception.CreateFmt('Invalid line:%s',[ln]);
    lastMatch:= colon + 1;
    for i:= 0to2dobegin
      comma:= ln.IndexOf(',', lastMatch);
      if comma = -1thenbreak;
      ATuple[i]:= ln.Substring(lastMatch, comma - lastMatch).Trim;
      lastMatch:= comma + 1;
    end;
    ATuple[i]:= ln.Substring(lastMatch).Trim;
    result:= i + 1;
  end;

  function ReadValue: string;
  var
    ln: string;
    colon, i, lastMatch, comma: Integer;
  begin
    ln:= Trim(ReadLn);
    colon:= ln.IndexOf(':');
    if colon = -1thenraise Exception.CreateFmt('Invalid line:%s',[ln]);
        result:= ln.Substring(colon + 1).Trim;
  end;

var
  Page: TAtlasPage;
  Region: TAtlasRegion;
  Line, Direction: string;
  Tuple: TupleStringArray;
  i: Integer;  
begin
  EndOf:= False;
  Page:= nil;
  Region:= nil;
  whilenot EndOf dobegin
    Line:= Trim(ReadLn);
    if Length(Line) > 0thenbeginif Page = nilthenbegin
        Page:= TAtlasPage.Create;
        Page.Name:= Line;
        //
if ReadTuple(Tuple) = 2thenbegin
          Page.Width := Tuple[0].ToInteger;
                    Page.Height:= Tuple[1].ToInteger;
                    ReadTuple(Tuple);
                end;
        Page.Format:= TPageFormat(GetEnumValue(TypeInfo(TPageFormat), 'pf'+Tuple[0]));
        //
        ReadTuple(Tuple);
        Page.MinFilter:= TPageTextureFilter(GetEnumValue(TypeInfo(TPageTextureFilter), 'ptf'+Tuple[0])); 
        Page.MagFilter:= TPageTextureFilter(GetEnumValue(TypeInfo(TPageTextureFilter), 'ptf'+Tuple[1]));
        //
        Direction:= ReadValue;
        Page.WrapU:= TPageTextureWrap.ptwClampToEdge;
        Page.WrapV:= TPageTextureWrap.ptwClampToEdge;
        if Direction = 'x'then
          Page.WrapU:= TPageTextureWrap.ptwRepeat
        elseif Direction = 'y'then
          Page.WrapV:= TPageTextureWrap.ptwRepeat
        elseif Direction = 'xy'thenbegin
          Page.WrapU:= TPageTextureWrap.ptwRepeat;
          Page.WrapV:= TPageTextureWrap.ptwRepeat;
        end;
        //
        FTextureLoader.LoadTexture(Page, Line);
        FPages.Add(Page);
      endelsebegin
        Region:= TAtlasRegion.Create;
        Region.Name:= Line; 
        Region.Rotate:= ReadValue.ToBoolean;
              ReadTuple(Tuple);
        Region.X:= Tuple[0].ToInteger;
        Region.Y:= Tuple[1].ToInteger;
                ReadTuple(Tuple);
        Region.Width := Abs(Tuple[0].ToInteger);
        Region.Height:= Abs(Tuple[1].ToInteger);
        Region.U:= Region.X / Page.Width;
        Region.V:= Region.Y / Page.Height;
        if Region.Rotate thenbegin
          Region.U2:= (Region.X + Region.Height) / Page.Width;
          Region.V2:= (Region.Y + Region.Width) / Page.Height; 
        endelsebegin
          Region.U2:= (Region.X + Region.Width) / Page.Width;
          Region.V2:= (Region.Y + Region.Height) / Page.Height; 
        end;
        //
if ReadTuple(Tuple) = 4thenbegin          SetLength(Region.Splits, 4);
          Region.Splits[0]:= Tuple[0].ToInteger;
          Region.Splits[1]:= Tuple[1].ToInteger;
          Region.Splits[2]:= Tuple[2].ToInteger;
          Region.Splits[3]:= Tuple[3].ToInteger;
          if ReadTuple(Tuple) = 4thenbegin
            SetLength(Region.Pads, 4);
            Region.Pads[0]:= Tuple[0].ToInteger;
            Region.Pads[1]:= Tuple[1].ToInteger;
            Region.Pads[2]:= Tuple[2].ToInteger;
            Region.Pads[3]:= Tuple[3].ToInteger;            
            ReadTuple(Tuple);
          end;          
        end;
        Region.OriginalWidth := Tuple[0].ToInteger;
        Region.OriginalHeight:= Tuple[1].ToInteger;
        //
        ReadTuple(Tuple);
        Region.OffsetX:= Tuple[0].ToInteger;
        Region.OffsetY:= Tuple[1].ToInteger;
        Region.Index:= ReadValue.ToInteger;
        FRegions.Add(Line,Region);
      end;
    endelsebegin
      Page:= nil;
      Region:= nil;
    end;
  end;
end;

end.

图集(.atlas)的解析单元,这个单元比较独立,参考了一些别的代码。

以上就介绍了 Spine Runtime for Delphi移植笔记(五) - spinecoreatlas,包括了方面的内容,希望对Delphijrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_4414823.html

相关图片

相关文章