Skip to content

Commit

Permalink
Merge branch 'ExperimentsWithDrawLine'
Browse files Browse the repository at this point in the history
# Conflicts:
#	cad_source/zengine/styles/uzestyleslayers.pas
#	environment/typeexporter/zcad.files
  • Loading branch information
zamtmn committed Dec 22, 2024
2 parents 5fe9c84 + a8e69ca commit 64180a5
Show file tree
Hide file tree
Showing 71 changed files with 1,997 additions and 981 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ function GZAlignedVectorObjects<PObj>.iterate(var ir:itrec):Pointer;
else begin
s:=sizeof(PObj(ir.itp)^);
if ir.itc<(count-s) then begin
m:=s mod ObjAlign;
m:=s mod cAlignment;
if m<>0 then
s:=s+ObjAlign-m;
s:=s+cAlignment-m;
inc(PByte(ir.itp),s);
inc(ir.itc,s);
result:=ir.itp;
Expand Down
117 changes: 61 additions & 56 deletions cad_source/components/zcontainers/gzctnrbinaryseparatedtree.pas
Original file line number Diff line number Diff line change
Expand Up @@ -20,62 +20,64 @@

interface
uses
gzctnrVectorTypes,gzctnrVectorPObjects,gzctnrVectorSimple;
gzctnrVectorTypes,gzctnrVectorPObjects,gzctnrVectorSimple;
type
{EXPORT+}
TStageMode=(TSMStart,TSMAccumulation,TSMCalc,TSMEnd);
TNodeDir=(TND_Plus,TND_Minus,TND_Root);
TElemPosition=(TEP_Plus,TEP_Minus,TEP_nul);
{----REGISTEROBJECTTYPE GZBInarySeparatedGeometry}
GZBInarySeparatedGeometry{-}<TBoundingBox,TSeparator,TNodeData,TEntsManipulator,TEntity,TEntityArrayIterateResult,TEntityArray>{//}
=object
{-}type{//}
{-}PGZBInarySeparatedGeometry=^GZBInarySeparatedGeometry<TBoundingBox,//ограничивающий объем{//}
{-}TSeparator,//разделитель{//}
{-}TNodeData,//дополнительные данные в ноде{//}
{-}TEntsManipulator,//то что невозможно закодировать в генерике{//}
{-}TEntity,//примитив{//}
{-}TEntityArrayIterateResult,//примитив{//}
{-}TEntityArray>;//массив примитивов{//}
{-}(*TEntityArray={GZVectorPObects}GZVectorSimple<PTEntity{,TEntity}>;*){//}
{-}PTEntity=^TEntity;{//}
{-}TTestNode=Object{//}
{-}plane:TSeparator;{//}
{-}nul,plus,minus:TEntityArray;{//}
{-}constructor initnul(InNodeCount:integer);{//}
{-}destructor done;virtual;{//}
{-}end;{//}
{-}var{//}
{-}pplusnode,pminusnode:PGZBInarySeparatedGeometry;{//}
{-}nul:TEntityArray;{//}
{-}Separator:TSeparator;{//}
{-}BoundingBox:TBoundingBox;{//}
{-}NodeDir:TNodeDir;{//}
{-}Root:PGZBInarySeparatedGeometry;{//}
{-}NodeData:TNodeData;{//}
{-}LockCounter:integer;{//}
destructor done;virtual;
procedure ClearSub;
procedure Shrink;
constructor initnul;
procedure AddObjToNul(var Entity:TEntity);
procedure updateenttreeadress;
procedure CorrectNodeBoundingBox(var Entity:TEntity); inline;
procedure AddObjectToNodeTree(var Entity:TEntity);
procedure SetSize(ns:integer);
procedure Lock;
procedure UnLock;
procedure Separate;virtual;
function GetNodeDepth:integer;virtual;
procedure MoveSub(var node:GZBInarySeparatedGeometry<TBoundingBox,TSeparator,TNodeData,TEntsManipulator,TEntity,TEntityArrayIterateResult,TEntityArray>);
function GetOptimalTestNode(var TNArray:array of TTestNode):integer;
procedure StoreOptimalTestNode(var TestNode:TTestNode);
TStageMode=(TSMStart,TSMAccumulation,TSMCalc,TSMEnd);
TNodeDir=(TND_Plus,TND_Minus,TND_Root);
TElemPosition=(TEP_Plus,TEP_Minus,TEP_nul);
//TNodeDataBase=object/record
// procedure CreateDef;
// procedure Destroy;
// procedure AfterSeparateNode(var nul:TEntityArray);
//end;
GZBInarySeparatedGeometry<TBoundingBox,TSeparator,TNodeData,TEntsManipulator,TEntity,TEntityArrayIterateResult,TEntityArray>
=object
type
PGZBInarySeparatedGeometry=^GZBInarySeparatedGeometry<TBoundingBox,//ограничивающий объем
TSeparator,//разделитель
TNodeData,//дополнительные данные в ноде
TEntsManipulator,//то что невозможно закодировать в генерике
TEntity,//примитив
TEntityArrayIterateResult,
TEntityArray>;//массив примитивов
PTEntity=^TEntity;
TTestNode=Object
plane:TSeparator;
nul,plus,minus:TEntityArray;
constructor initnul(InNodeCount:integer);
destructor done;virtual;
end;
var
pplusnode,pminusnode:PGZBInarySeparatedGeometry;
nul:TEntityArray;
Separator:TSeparator;
BoundingBox:TBoundingBox;
NodeDir:TNodeDir;
Root:PGZBInarySeparatedGeometry;
NodeData:TNodeData;
LockCounter:integer;

destructor done;virtual;
procedure ClearSub;
procedure Shrink;
constructor initnul;
procedure AddObjToNul(var Entity:TEntity);
procedure updateenttreeadress;
procedure CorrectNodeBoundingBox(var Entity:TEntity); inline;
procedure AddObjectToNodeTree(var Entity:TEntity);
procedure SetSize(ns:integer);
procedure Lock;
procedure UnLock;
procedure Separate;virtual;
function GetNodeDepth:integer;virtual;
procedure MoveSub(var node:GZBInarySeparatedGeometry<TBoundingBox,TSeparator,TNodeData,TEntsManipulator,TEntity,TEntityArrayIterateResult,TEntityArray>);
function GetOptimalTestNode(var TNArray:array of TTestNode):integer;
procedure StoreOptimalTestNode(var TestNode:TTestNode);

function nuliterate(var ir:itrec):Pointer;
function nulbeginiterate(out ir:itrec):Pointer;
function nulDeleteElement(index:Integer):Pointer;
end;
{EXPORT-}
function nuliterate(var ir:itrec):Pointer;
function nulbeginiterate(out ir:itrec):Pointer;
function nulDeleteElement(index:Integer):Pointer;
end;
var
ttt:integer;
implementation
Expand Down Expand Up @@ -255,6 +257,7 @@ procedure GZBInarySeparatedGeometry<TBoundingBox,TSeparator,TNodeData,TEntsManip
if TEntsManipulator.isUnneedSeparate(nul.count,GetNodeDepth)then
begin
updateenttreeadress;
NodeData.AfterSeparateNode(nul);
exit;
end;
MoveSub(self);
Expand Down Expand Up @@ -382,6 +385,7 @@ procedure GZBInarySeparatedGeometry<TBoundingBox,TSeparator,TNodeData,TEntsManip
if minus_count_optimal>0 then pminusnode.unlock;

updateenttreeadress;
NodeData.AfterSeparateNode(nul);
end;
procedure GZBInarySeparatedGeometry<TBoundingBox,TSeparator,TNodeData,TEntsManipulator,TEntity,TEntityArrayIterateResult,TEntityArray>.AddObjectToNodeTree(var Entity:TEntity);
begin
Expand Down Expand Up @@ -428,7 +432,7 @@ procedure GZBInarySeparatedGeometry<TBoundingBox,TSeparator,TNodeData,TEntsManip
constructor GZBInarySeparatedGeometry<TBoundingBox,TSeparator,TNodeData,TEntsManipulator,TEntity,TEntityArrayIterateResult,TEntityArray>.initnul;
begin
nul.init(50);
NodeData:=default(TNodeData);
NodeData.CreateDef;
LockCounter:=0;
//NodeData.FulDraw:={True}TDTFulDraw;
end;
Expand All @@ -446,7 +450,7 @@ procedure GZBInarySeparatedGeometry<TBoundingBox,TSeparator,TNodeData,TEntsManip
BoundingBox:=default(TBoundingBox);
//NodeDir:TNodeDir;
Root:=nil;
NodeData:=default(TNodeData);
NodeData.CreateDef;
nul.Clear;
if assigned(pplusnode) then
begin
Expand Down Expand Up @@ -482,6 +486,7 @@ procedure GZBInarySeparatedGeometry<TBoundingBox,TSeparator,TNodeData,TEntsManip
Freemem(pointer(pminusnode));
pminusnode:=nil;
end;
NodeData.Destroy;
end;
destructor GZBInarySeparatedGeometry<TBoundingBox,TSeparator,TNodeData,TEntsManipulator,TEntity,TEntityArrayIterateResult,TEntityArray>.done;
begin
Expand Down
162 changes: 162 additions & 0 deletions cad_source/components/zcontainers/gzctnrbufferallocator.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
*****************************************************************************
* *
* This file is part of the ZCAD *
* *
* See the file COPYING.txt, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
}
{
@author(Andrey Zubarev <[email protected]>)
}
unit gzctnrBufferAllocator;
{$Mode delphi}

interface
uses
gvector,//gzctnrVector,
garrayutils,
sysutils;
type
GBufferAllocator<GOffset,GSize,GData>=object
public
type
TOffset=GOffset;
TSize=GSize;
TData=GData;
TBufferRange=record
public
var
Offset:TOffset;
Size:TSize;
Data:TData;
public
Constructor CreateFreeRange(const AOffset:TOffset;const ASize:TSize;const AData:TData);
end;
PBufferRange=^TBufferRange;
TRanges=TVector<TBufferRange>;
TIndexInRanges=SizeInt;
TFreeRangesIndexs=TVector<TIndexInRanges>;
TMoveAllocadetRange=procedure(const oldI,newI:TIndexInRanges;const AData:TData);
var
AllocatedRanges:TRanges;
FreeRanges:TRanges;
onMoveAllocadetRange:TMoveAllocadetRange;
const
CWrongIndexInRanges=-1;
private
function FindFreeRange(const ASize:TSize):TIndexInRanges;
public
constructor Init(ABufSize:TSize);
destructor done;virtual;
function Allocate(ASize:TSize;Adata:GData):TIndexInRanges;
procedure Release(Index:TIndexInRanges);
function CalcFragmentation:Double;
end;
implementation
Constructor GBufferAllocator<GOffset,GSize,GData>.TBufferRange.CreateFreeRange(const AOffset:TOffset;const ASize:TSize;const AData:TData);
begin
Offset:=AOffset;
Size:=ASize;
Data:=Adata;
end;

constructor GBufferAllocator<GOffset,GSize,GData>.Init(ABufSize:TSize);
begin
AllocatedRanges:=TRanges.Create;
AllocatedRanges.Reserve(4*1024*1024);
FreeRanges:=TRanges.Create;
FreeRanges.Reserve(4*1024);
FreeRanges.PushBack(TBufferRange.CreateFreeRange(0,ABufSize,-1));
onMoveAllocadetRange:=nil;
end;
destructor GBufferAllocator<GOffset,GSize,GData>.done;
begin
AllocatedRanges.destroy;
FreeRanges.destroy;
end;

function GBufferAllocator<GOffset,GSize,GData>.FindFreeRange(const ASize:TSize):TIndexInRanges;
var
i:TIndexInRanges;
pbr:PBufferRange;
tds,ds:SizeInt;
begin
result:=CWrongIndexInRanges;
ds:=high(ds);
for i:=0 to FreeRanges.size-1 do begin
pbr:=FreeRanges.Mutable[i];
tds:=pbr^.Size-ASize;
if tds=0 then begin
exit(i);
end else if pbr^.Size>ASize then begin
if (tds<ds)or(result=CWrongIndexInRanges) then begin
ds:=tds;
result:=i;
end;
end;
end;
end;

function GBufferAllocator<GOffset,GSize,GData>.CalcFragmentation:Double;
var
i:SizeUInt;
pbr:PBufferRange;
total,largest:TSize;
begin
pbr:=FreeRanges.Mutable[0];
total:=pbr^.Size;
largest:=pbr^.Size;
for i:=1 to FreeRanges.size-1 do begin
pbr:=FreeRanges.Mutable[i];
if largest<pbr^.Size then
largest:=pbr^.Size;
total:=total+pbr^.Size;
end;
result:=(Total-Largest)/total;
end;

function GBufferAllocator<GOffset,GSize,GData>.Allocate(ASize:TSize;Adata:GData):TIndexInRanges;
var
SuitableFreeRangeIndex:TIndexInRanges;
FreeRangesIndex:SizeUInt;
pbr:PBufferRange;
nbr:TBufferRange;
begin
SuitableFreeRangeIndex:=FindFreeRange(ASize);
if SuitableFreeRangeIndex=CWrongIndexInRanges then
raise Exception.Create('Cannot allocate');
pbr:=FreeRanges.Mutable[SuitableFreeRangeIndex];
if pbr^.Size<>ASize then begin
nbr.CreateFreeRange(pbr^.Offset,Asize,Adata);
pbr^.Offset:=pbr^.Offset+Asize;
pbr^.Size:=pbr^.Size-Asize;
Result:=AllocatedRanges.size;
AllocatedRanges.PushBack(nbr);
end else begin
Result:=AllocatedRanges.size;
AllocatedRanges.PushBack(FreeRanges.mutable[SuitableFreeRangeIndex]^);
FreeRanges.mutable[SuitableFreeRangeIndex]^:=FreeRanges.back;
FreeRanges.popback;
end;
end;
procedure GBufferAllocator<GOffset,GSize,GData>.Release(Index:TIndexInRanges);
var
SuitableRangeIndex:TIndexInRanges;
pbr:PBufferRange;
nbr:TBufferRange;
begin
FreeRanges.PushBack(AllocatedRanges.Mutable[Index]^);
if @onMoveAllocadetRange<>nil then
onMoveAllocadetRange(AllocatedRanges.size-1,Index,AllocatedRanges.back.data);
AllocatedRanges.mutable[Index]^:=AllocatedRanges.back;
AllocatedRanges.popback;
end;
begin
end.
Loading

0 comments on commit 64180a5

Please sign in to comment.