【Spine】Spine Runtime for Delphi移植筆記(七) - spine.core.skeleton

来源:http://www.cnblogs.com/crymm/archive/2017/08/02/7273014.html
-Advertisement-
Play Games

骨架模塊,粗粗檢查了一下,沒什麼問題。 這裡說一下,這個庫的移植(其實大多是翻譯,因為很多代碼我根本不理解,但是不影響我翻譯就是了)是基於C#的,C#是垃圾回收機制,移到delphi的話,對象的創建、釋放就要很註意,不然很容易有記憶體泄露。 這邊檢查主要就是檢查對象的釋放,大多是TList和TObje ...


////////////////////////////////////////////////////////////////////////////////
//Generic delphi runtime v3.6 for Spine animation tool                        //
//Runtime port by cjk ([email protected])                                       //
////////////////////////////////////////////////////////////////////////////////

unit spine.core.skeleton;

interface

uses
  System.Classes, System.SysUtils, System.Generics.Collections, System.Math,
  spine.types, spine.classes, spine.data,
  spine.core.bone, spine.core.slot, spine.core.skin, spine.core.attachment, spine.core.constraint;

type
  TSpineSkeleton = class(ISkeleton)
  private
    FPathConstraints: TObjectList<TPathConstraint>;
    FIkConstraints: TObjectList<TIkConstraint>;
    FTransformConstraints: TObjectList<TTransformConstraint>;
    FBones: TObjectList<TSpineBone>;
    FSlots: TObjectList<TSpineSlot>;
    FDrawOrder: TList<TSpineSlot>;
    FUpdateCacheList: TList<IUpdateable>;
    FData: TSkeletonData;
    FUpdateCacheReset: TList<TSpineBone>;
    function GetRootBone: TSpineBone;
  private
    procedure SortIkConstraint(const AConstraint: TIkConstraint);
    procedure SortPathConstraint(const AConstraint: TPathConstraint);
    procedure SortTransformConstraint(const AConstraint: TTransformConstraint);
    procedure SortPathConstraintAttachment(const ASkin: TSpineSkin;
      const ASlotIndex: Integer; const ASlotBone: TSpineBone); overload;
    procedure SortPathConstraintAttachment(const AAttachment: IAttachment;
      const ASlotBone: TSpineBone); overload;
    procedure SortBone(const ABone: TSpineBone);
    procedure SortReset(const ABones: TObjectList<TSpineBone>);
  public
    Skin: TSpineSkin;
    R, G, B, A: Single;
    Time: Single;
    X, Y: Single;
    FlipX, FlipY: Boolean;
    property Data: TSkeletonData read FData;
    property Bones: TObjectList<TSpineBone> read FBones;
    property UpdateCacheList: TList<IUpdateable> read FUpdateCacheList;
    property Slots: TObjectList<TSpineSlot> read FSlots;
    property DrawOrder: TList<TSpineSlot> read FDrawOrder;
    property IkConstraints: TObjectList<TIkConstraint> read FIkConstraints;
    property PathConstraints: TObjectList<TPathConstraint> read FPathConstraints;
    property TransformConstraints: TObjectList<TTransformConstraint> read FTransformConstraints;
    property RootBone: TSpineBone read GetRootBone;
  public
    constructor Create(const AData: TSkeletonData);
    destructor Destroy; override;

    procedure UpdateCache;
    procedure UpdateWorldTransform;
    procedure SetToSetupPose;
    procedure SetBonesToSetupPose;
    procedure SetSlotsToSetupPose;
    procedure SetSkin(const ASkinName: string); overload;
    procedure SetSkin(const ASkin: TSpineSkin); overload;
    procedure SetAttachment(const ASlotName, AAttachmentName: string);
    procedure Update(const ADelta: Single);
    procedure GetBounds(out oX, oY, oWidth, oHeight: Single; var AVertexBuffer: TArray<Single>);
    function GetAttachment(const ASlotName, AAttachmentName: string): IAttachment; overload;
    function GetAttachment(const ASlotIndex: Integer; const AAttachmentName: string): IAttachment; overload;
    function FindBone(const ABoneName: string): TSpineBone;
    function FindBoneIndex(const ABoneName: string): Integer;
    function FindSlot(const ASlotName: string): TSpineSlot;
    function FindSlotIndex(const ASlotName: string): Integer;
    function FindIkConstraint(const AConstraintName: string): TIkConstraint;
    function FindTransformConstraint(const AConstraintName: string): TTransformConstraint;
    function FindPathConstraint(const AConstraintName: string): TPathConstraint;
  end;

implementation

{ TSpineSkeleton }

function TSpineSkeleton.GetRootBone: TSpineBone;
begin
  result:= nil;
  if FBones.Count > 0 then
    result:= FBones.Items[0];
end;

constructor TSpineSkeleton.Create(const AData: TSkeletonData);
var
  lBoneData: TBoneData;
  lParentBone, lBone: TSpineBone;
  lSlotData: TSlotData;
  lSlot: TSpineSlot;
  lIkData  : TIkConstraintData;
  lTfData  : TTransformConstraintData;
  lPathData: TPathConstraintData;
begin
  inherited Create;
  R:= 1; G:= 1; B:= 1; A:= 1;
  FUpdateCacheList:= TList<IUpdateable>.Create;
  FUpdateCacheReset:= TList<TSpineBone>.Create;
  FDrawOrder:= TList<TSpineSlot>.Create;
  FBones:= TObjectList<TSpineBone>.Create;
  FSlots:= TObjectList<TSpineSlot>.Create;
  FIkConstraints:= TObjectList<TIkConstraint>.Create;
  FPathConstraints:= TObjectList<TPathConstraint>.Create;
  FTransformConstraints:= TObjectList<TTransformConstraint>.Create;
  if not Assigned(AData) then raise Exception.Create('data cannot be null.');
  FData:= AData;
  for lBoneData in FData.BoneDatas do
  begin
    if not Assigned(lBoneData.Parent) then
      FBones.Add(TSpineBone.Create(lBoneData, Self, nil))
    else
    begin
      lParentBone:= FBones.Items[lBoneData.Parent.Index];
      lBone:= TSpineBone.Create(lBoneData, Self, lParentBone);
      FBones.Add(lBone);
    end;
  end;
  for lSlotData in FData.SlotDatas do
  begin
    lBone:= FBones.Items[lSlotData.BoneData.Index];
    lSlot:= TSpineSlot.Create(lSlotData, lBone);
    FSlots.Add(lSlot);
    FDrawOrder.Add(lSlot);
  end;
  for lIkData in FData.IkConstraintDatas do
    FIkConstraints.Add(TIkConstraint.Create(lIkData, Self));
  for lTfData in FData.TransformConstraintDatas do
    FTransformConstraints.Add(TTransformConstraint.Create(lTfData, Self));
  for lPathData in FData.PathConstraintDatas do
    FPathConstraints.Add(TPathConstraint.Create(lPathData, Self));
  //
  UpdateCache();
  UpdateWorldTransform();
end;

destructor TSpineSkeleton.Destroy;
begin
  FUpdateCacheReset.Free;
  FBones.Free;
  FUpdateCacheList.Free;
  FSlots.Free;
  FDrawOrder.Free;
  FIkConstraints.Free;
  FPathConstraints.Free;
  FTransformConstraints.Free;
  inherited;
end;

procedure TSpineSkeleton.UpdateCache;
var
  i, lConstraintCount, j: Integer;
  lFound: Boolean;
begin
  FUpdateCacheList.Clear;
  FUpdateCacheReset.Clear;
  for i:= 0 to FBones.Count -1 do
    FBones.Items[i].Sorted:= False;
  lConstraintCount:= FIkConstraints.Count +
                     FTransformConstraints.Count +
                     FPathConstraints.Count;
  lFound:= False;
  for i:= 0 to lConstraintCount -1 do
  begin
    for j:= 0 to FIkConstraints.Count -1 do
    begin
      if FIkConstraints[j].Data.Order = j then
      begin
        SortIkConstraint(FIkConstraints[j]);
        lFound:= True;
        break;
      end;
    end;
    if not lFound then
    begin
      for j:= 0 to FTransformConstraints.Count -1 do
      begin
        if FTransformConstraints[j].Data.Order = j then
        begin
          SortTransformConstraint(FTransformConstraints[j]);
          lFound:= True;
          break;
        end;
      end;
    end;
    if not lFound then
    begin
      for j:= 0 to FPathConstraints.Count -1 do
      begin
        if FPathConstraints[j].Data.Order = j then
        begin
          SortPathConstraint(FPathConstraints[j]);
          lFound:= True;
          break;
        end;
      end;
    end;
  end;
  //
  for i:= 0 to FBones.Count -1 do
    SortBone(FBones.Items[i]);
end;

procedure TSpineSkeleton.SortIkConstraint(const AConstraint: TIkConstraint);
var
  lChild: TSpineBone;
begin
  SortBone(AConstraint.Target);
  SortBone(AConstraint.Bones.Items[0]);
  if AConstraint.Bones.Count > 1 then
  begin
    lChild:= AConstraint.Bones.Last;
    if not FUpdateCacheList.Contains(lChild) then
      FUpdateCacheReset.Add(lChild);
  end;
  FUpdateCacheList.Add(AConstraint);
    SortReset(AConstraint.Bones.Items[0].Children);
  AConstraint.Bones.Last.Sorted:= True;
end;

procedure TSpineSkeleton.SortPathConstraint(const AConstraint: TPathConstraint);
var
  lSlot: TSpineSlot;
  lSlotIndex, i: Integer;
  lSlotBone: TSpineBone;
begin
  lSlot:= AConstraint.Target;
  lSlotIndex:= lSlot.Data.Index;
  lSlotBone := lSlot.Bone;
  if Assigned(Skin) then
    SortPathConstraintAttachment(Skin, lSlotIndex, lSlotBone);
  if Assigned(FData.DefaultSkin) and not FData.DefaultSkin.Equals(Skin) then
    SortPathConstraintAttachment(FData.DefaultSkin, lSlotIndex, lSlotBone);
  for i:= 0 to FData.Skins.Count -1 do
    SortPathConstraintAttachment(FData.Skins.Items[i], lSlotIndex, lSlotBone);
  if (lSlot.Attachment is TPathAttachment) then
    SortPathConstraintAttachment(lSlot.Attachment, lSlotBone);
  for i:= 0 to AConstraint.Bones.Count -1 do
    SortBone(AConstraint.Bones.Items[i]);
  //
  FUpdateCacheList.Add(AConstraint);
  for i:= 0 to AConstraint.Bones.Count -1 do
    SortReset(AConstraint.Bones.Items[i].Children);
  for i:= 0 to AConstraint.Bones.Count -1 do
    AConstraint.Bones.Items[i].Sorted:= True;
end;

procedure TSpineSkeleton.SortTransformConstraint(const AConstraint: TTransformConstraint);
var
  i: Integer;
  lChild: TSpineBone;
begin
  SortBone(AConstraint.Target);
  if AConstraint.Data.Local then
  begin
    for i:= 0 to AConstraint.Bones.Count -1 do
    begin
      lChild:= AConstraint.Bones.Items[i];
      SortBone(lChild.Parent);
      if not FUpdateCacheList.Contains(lChild) then
        FUpdateCacheReset.Add(lChild);
    end;
  end else
  begin
    for i:= 0 to AConstraint.Bones.Count -1 do
      SortBone(AConstraint.Bones.Items[i]);
  end;
  FUpdateCacheList.Add(AConstraint);
  for i:= 0 to AConstraint.Bones.Count -1 do
    SortReset(AConstraint.Bones.Items[i].Children);
  for i:= 0 to AConstraint.Bones.Count -1 do
    AConstraint.Bones.Items[i].Sorted:= True;
end;

procedure TSpineSkeleton.SortPathConstraintAttachment(const ASkin: TSpineSkin;
  const ASlotIndex: Integer; const ASlotBone: TSpineBone);
var
  lPair: TPair<TAttachmentKeyTuple,IAttachment>;
begin
  for lPair in Skin.Attachments do
  begin
    if lPair.Key.SlotIndex = ASlotIndex then
      SortPathConstraintAttachment(lPair.Value, ASlotBone);
  end;
end;

procedure TSpineSkeleton.SortPathConstraintAttachment(
  const AAttachment: IAttachment; const ASlotBone: TSpineBone);
var
  lPathBones: TArray<Integer>;
  i, n, nn, boneCount: Integer;
begin
  if not (AAttachment is TPathAttachment) then exit;
  //
  lPathBones:= TPathAttachment(AAttachment).Bones;
  if Length(lPathBones) = 0 then
    SortBone(ASlotBone)
  else
  begin
    i:= 0;
    n:= Length(lPathBones);
    while i < n do
    begin
            boneCount:= lPathBones[i + 1];
            i:= i + 1;
            nn:= i + boneCount;
            while i < nn do
      begin
                SortBone(FBones.Items[lPathBones[i + 1]]);
                i:= i + 1;
            end
    end;
  end;
end;

procedure TSpineSkeleton.SortBone(const ABone: TSpineBone);
begin
  if ABone.Sorted then exit;
  //
  if Assigned(ABone.Parent) then
    SortBone(ABone.Parent);
  ABone.Sorted:= True;
  FUpdateCacheList.Add(ABone);
end;

procedure TSpineSkeleton.SortReset(const ABones: TObjectList<TSpineBone>);
var
  i: Integer;
  lBone: TSpineBone;
begin
  for i:= 0 to ABones.Count -1 do
  begin
    lBone:= ABones.Items[i];
    if lBone.Sorted then
      SortReset(lBone.Children);
    lBone.Sorted:= False;
  end;
end;

procedure TSpineSkeleton.UpdateWorldTransform;
var
  i: Integer;
  lBone: TSpineBone;
begin
  for i:= 0 to FUpdateCacheReset.Count -1 do
  begin
    lBone:= FUpdateCacheReset.Items[i];
    lBone.AppliedX:= lBone.X;
    lBone.AppliedY:= lBone.Y;
    lBone.AppliedRotation:= lBone.Rotation;
    lBone.AppliedScaleX:= lBone.ScaleX;
    lBone.AppliedScaleY:= lBone.ScaleY;
    lBone.AppliedShearX:= lBone.ShearX;
    lBone.AppliedShearY:= lBone.ShearY;
    lBone.AppliedValid:= True;
  end;
  for i:= 0 to FUpdateCacheList.Count -1 do
    FUpdateCacheList.Items[i].Update;
end;

procedure TSpineSkeleton.SetToSetupPose;
begin
  SetBonesToSetupPose();
  SetSlotsToSetupPose();
end;

procedure TSpineSkeleton.SetBonesToSetupPose;
var
  i: Integer;
begin
  for i:= 0 to FBones.Count -1 do
    FBones.Items[i].SetToSetupPose;
  for i:= 0 to FIkConstraints.Count -1 do
  begin
    with FIkConstraints.Items[i] do
    begin
      BendDirection:= Data.BendDirection;
      Mix:= Data.Mix;
    end;
  end;
  for i:= 0 to FTransformConstraints.Count -1 do
  begin
    with FTransformConstraints.Items[i] do
    begin
      RotateMix:= Data.RotateMix;
      TranslateMix:= Data.TranslateMix;
      ScaleMix:= Data.ScaleMix;
      ShearMix:= Data.ShearMix;
    end;
  end;
  for i:= 0 to FPathConstraints.Count -1 do
  begin
    with FPathConstraints.Items[i] do
    begin
      Position:= Data.Position;
      Spacing:= Data.Spacing;
      RotateMix:= Data.RotateMix;
      TranslateMix:= Data.TranslateMix;
    end;
  end;
end;

procedure TSpineSkeleton.SetSlotsToSetupPose;
var
  i: Integer;
begin
  FDrawOrder.Clear;
  for i:= 0 to FSlots.Count -1 do
    FDrawOrder.Add(FSlots.Items[i]);
  for i:= 0 to FSlots.Count -1 do
    FSlots.Items[i].SetToSetupPose;
end;

function TSpineSkeleton.FindBone(const ABoneName: string): TSpineBone;
var
  i: Integer;
begin
  if ABoneName.Trim.IsEmpty then raise Exception.Create('boneName cannot be null.');
  for i:= 0 to FBones.Count -1 do
  begin
    if FBones.Items[i].Data.Name = ABoneName then
      exit(FBones.Items[i]);
  end;
  result:= nil;
end;

function TSpineSkeleton.FindBoneIndex(const ABoneName: string): Integer;
var
  i: Integer;
begin
  result:= -1;
  if ABoneName.Trim.IsEmpty then raise Exception.Create('boneName cannot be null.');
  for i:= 0 to FBones.Count -1 do
  begin
    if FBones.Items[i].Data.Name = ABoneName then
      exit(i);
  end;
end;

function TSpineSkeleton.FindSlot(const ASlotName: string): TSpineSlot;
var
  i: Integer;
begin
  result:= nil;
  if ASlotName.Trim.IsEmpty then raise Exception.Create('slotName cannot be null.');
  for i:= 0 to FSlots.Count -1 do
  begin
    if FSlots.Items[i].Data.Name = ASlotName then
      exit(FSlots.Items[i]);
  end;
end;

function TSpineSkeleton.FindSlotIndex(const ASlotName: string): Integer;
var
  i: Integer;
begin
  result:= -1;
  if ASlotName.Trim.IsEmpty then raise Exception.Create('slotName cannot be null.');
  for i:= 0 to FSlots.Count -1 do
  begin
    if FSlots.Items[i].Data.Name = ASlotName then
      exit(i);
  end;
end;

procedure TSpineSkeleton.SetSkin(const ASkinName: string);
var
  lSkin: TSpineSkin;
begin
  lSkin:= FData.FindSkin(ASkinName);
  if not Assigned(lSkin) then raise Exception.CreateFmt('Skin not found: %s',[ASkinName]);
    SetSkin(lSkin);
end;

procedure TSpineSkeleton.SetSkin(const ASkin: TSpineSkin);
var
  i: Integer;
  lAttachmentName: string;
  lAttachment: IAttachment;
begin
  if Assigned(Self.Skin) then
    ASkin.AttachAll(Self, Self.Skin)
  else
  begin
    for i:= 0 to FSlots.Count -1 do
    begin
      lAttachmentName:= FSlots.Items[i].Data.AttachmentName;
      if not lAttachmentName.Trim.IsEmpty then
      begin
        lAttachment:= ASkin.GetAttachment(i, lAttachmentName);
        if Assigned(lAttachment) then
          FSlots.Items[i].Attachment:= lAttachment;
      end;
    end;
  end;
  Self.Skin:= ASkin;
end;

function TSpineSkeleton.GetAttachment(const ASlotName,
  AAttachmentName: string): IAttachment;
begin
  result:= GetAttachment(FData.FindSlotIndex(ASlotName), AAttachmentName);
end;

function TSpineSkeleton.GetAttachment(const ASlotIndex: Integer;
  const AAttachmentName: string): IAttachment;
var
  lAttachment: IAttachment;
begin
  result:= nil;
  if AAttachmentName.Trim.IsEmpty then raise Exception.Create('attachmentName cannot be null.');
  if Assigned(Self.Skin) then
  begin
    lAttachment:= Self.Skin.GetAttachment(ASlotIndex, AAttachmentName);
    if Assigned(lAttachment) then exit(lAttachment);
  end;
  if Assigned(FData.DefaultSkin) then
    result:= FData.DefaultSkin.GetAttachment(ASlotIndex, AAttachmentName);
end;

procedure TSpineSkeleton.SetAttachment(const ASlotName,
  AAttachmentName: string);
var
  i: Integer;
  lSlot: TSpineSlot;
  lAttachment: IAttachment;
begin
  if ASlotName.Trim.IsEmpty then raise Exception.Create('slotName cannot be null.');
  for i:= 0 to FSlots.Count -1 do
  begin
    lSlot:= FSlots.Items[i];
    if lSlot.Data.Name.Equals(ASlotName) then
    begin
      lAttachment:= nil;
      if not AAttachmentName.Trim.IsEmpty then
      begin
        lAttachment:= Self.GetAttachment(i, AAttachmentName);
        if not Assigned(lAttachment) then
          raise Exception.CreateFmt('Attachment not found: %s, for slot: %s',[AAttachmentName,ASlotName]);
      end;
      lSlot.Attachment:= lAttachment;
      exit;
    end;
  end;
  raise Exception.CreateFmt('Slot not found: ',[ASlotName]);
end;

function TSpineSkeleton.FindIkConstraint(
  const AConstraintName: string): TIkConstraint;
var
  i: Integer;
  lConstraint: TIkConstraint;
begin
  result:= nil;
  if AConstraintName.Trim.IsEmpty then raise Exception.Create('constraintName cannot be null.');
  for i:= 0 to FIkConstraints.Count -1 do
  begin
    lConstraint:= FIkConstraints.Items[i];
    if lConstraint.Data.Name.Equals(AConstraintName) then exit(lConstraint);
  end;
end;

function TSpineSkeleton.FindTransformConstraint(
  const AConstraintName: string): TTransformConstraint;
var
  i: Integer;
  lConstraint: TTransformConstraint;
begin
  result:= nil;
  if AConstraintName.Trim.IsEmpty then raise Exception.Create('constraintName cannot be null.');
  for i:= 0 to FTransformConstraints.Count -1 do
  begin
    lConstraint:= FTransformConstraints.Items[i];
    if lConstraint.Data.Name.Equals(AConstraintName) then exit(lConstraint);
  end;
end;

function TSpineSkeleton.FindPathConstraint(
  const AConstraintName: string): TPathConstraint;
var
  i: Integer;
  lConstraint: TPathConstraint;
begin
  result:= nil;
  if AConstraintName.Trim.IsEmpty then raise Exception.Create('constraintName cannot be null.');
  for i:= 0 to FPathConstraints.Count -1 do
  begin
    lConstraint:= FPathConstraints.Items[i];
    if lConstraint.Data.Name.Equals(AConstraintName) then exit(lConstraint);
  end;
end;

procedure TSpineSkeleton.Update(const ADelta: Single);
begin
  Self.Time:= Self.Time + ADelta;
end;

procedure TSpineSkeleton.GetBounds(out oX, oY, oWidth, oHeight: Single;
  var AVertexBuffer: TArray<Single>);
var
  lTemp, lVertices: TArray<Single>;
  i, lVerticesLength, j, n: Integer;
  lMinX, lMinY, lMaxX, lMaxY, lVX, lVY: Single;
  lSlot: TSpineSlot;
  lAttachment: IAttachment;
  lRegionAttachment: TRegionAttachment;
  lMeshAttachment: TMeshAttachment;
begin
  lTemp:= AVertexBuffer;
  if Length(lTemp) = 0 then
    SetLength(lTemp, 8);
  lMinX:= Integer.MaxValue;
  lMinY:= Integer.MaxValue;
  lMaxX:= Integer.MinValue;
  lMaxY:= Integer.MinValue;
  for i:= 0 to FDrawOrder.Count -1 do
  begin
    lSlot:= FDrawOrder.Items[i];
    lVerticesLength:= 0;
    SetLength(lVertices, 0);
    lAttachment:= lSlot.Attachment;
    lRegionAttachment:= lAttachment as TRegionAttachment;
    if Assigned(lRegionAttachment) then
    begin
      lVerticesLength:= 8;
      lVertices:= lTemp;
      if Length(lVertices) < 8 then
      begin
        SetLength(lTemp, 8);
        lVertices:= lTemp;
        lRegionAttachment.ComputeWorldVertices(lSlot.Bone, lTemp, 0);
      end;
    end else
    begin
      lMeshAttachment:= lAttachment as TMeshAttachment;
      if Assigned(lMeshAttachment) then
      begin
        lVerticesLength:= lMeshAttachment.WorldVerticesLength;
        lVertices:= lTemp;
        if Length(lVertices) < lVerticesLength then
        begin
          SetLength(lTemp, lVerticesLength);
          lVertices:= lTemp;
          lMeshAttachment.ComputeWorldVertices(lSlot, 0, lVerticesLength, lTemp, 0);
        end;
      end;
    end;
    n:= Length(lVertices);
    if n > 0 then
    begin
      j:= 0;
      while j < n do
      begin
        lVX:= lVertices[j];
        lVY:= lVertices[j+1];
        lMinX:= Min(lMinX, lVX);
        lMinY:= Min(lMinY, lVY);
        lMaxX:= Max(lMaxX, lVX);
        lMaxY:= Max(lMaxY, lVY);
        j:= j + 2;
      end;
    end;
  end;
  oX:= lMinX;
  oY:= lMinY;
  oWidth := lMaxX - lMinX;
  oHeight:= lMaxY - lMinY;
  AVertexBuffer:= lTemp;
end;

end.

骨架模塊,粗粗檢查了一下,沒什麼問題。

這裡說一下,這個庫的移植(其實大多是翻譯,因為很多代碼我根本不理解,但是不影響我翻譯就是了)是基於C#的,C#是垃圾回收機制,移到delphi的話

您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 版權聲明:本文為博主原創文章,未經博主允許不得轉載。 using System;using System.Data;using System.IO;using NPOI.SS.UserModel;using NPOI.XSSF.UserModel;using NPOI.HSSF.UserModel; ...
  • 無論ORM有多麼強大,總會出現一些特殊的情況,它無法滿足我們的要求。在這篇文章中,我們介紹幾種執行SQL的方法。 ...
  • 一、在gridcontrol列表控制項中使用單選框作為選擇列,這裡有兩種方式。 方式一:選擇gridcontrol控制項的Run Designer按鈕,添加一列,設置該列的ColumnEdit為checkedit。如下圖: 代碼如下: 效果圖: 方式二:選擇gridcontrol控制項的Run Desig ...
  • 【以前的文章】最後一公裡極速配送 阿裡雲演算法大賽總結 總結一下新的教訓 1.由於都是NP難題,獲得最優解用常規的方法非常困難,對於不是演算法科班出身的人來說,首先應該到網路上尋找一下論文,是否有一些好的經驗。 2.保持平常心,這種比賽獲獎很困難,生活還是要和往常一樣,只是將空餘的時間給做比賽 3.每一 ...
  • 最近在研究pos印表機相關功能, 調用winapi以及跨進程通信等,都涉及到類型之間的轉換。 C/C++ C# HANDLE, LPDWORD, LPVOID, void* IntPtr LPCTSTR, LPCTSTR, LPSTR, char*, const char*, Wchar_t*, L ...
  • 一:Erlang安裝 因為RabbitMQ 是Erlang語言開發的,所以首先要裝上Erlang的環境 1)下載Erlang 下載官網:http://www.erlang.org/download.html。 實踐安裝版本:otp_win64_20.0.exe。(安裝最新版就好)2)安裝Erlang ...
  • 1、開發工具版本 maven:Apache Maven 3.3.9 JDK:1.8.0 Eclipse:Mars.1 Release (4.5.1) (現在eclipse官網上的最新版本) MySQL:mysql-5.6.24-win32(免安裝版,但需要進行相關配置) 將Eclipse直接解壓,由 ...
  • 起因:寫代碼的時候經常會用到獲取當前時間戳和日期,現總結如下 date.toString():Wed Aug 02 11:39:05 CST 2017當前時間戳(毫秒):1501645145298當前日期:2當前年份:2017當前月份:712小時制:當前小時:1124小時制:當前小時:11當前分鐘: ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...