-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathFormulaClass.pas
More file actions
165 lines (152 loc) · 5.48 KB
/
FormulaClass.pas
File metadata and controls
165 lines (152 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
unit FormulaClass;
interface
uses Windows, Classes, TypeDefinitions;
type
TFormulaClass = class
private
iFormulaType: Integer; //0: usual iteration loop 1: repeat from 2: InterpolStart 3: InterpolEnd
iVersion: Integer;
SIMDlevel: Integer; //bitcombinated: 0: no simd, 1: SSE2, 2: SSE3, 4: SSSE3, 8: SSE4.1
dDEscale: Double;
dADEscale: Double;
dSIpow: Double;
dRstop: Double;
iConstCount: Integer;
bCPmemReserved: LongBool;
VarBuffer: array of Byte;
procedure Init;
procedure Cleanup;
public
pConstPointer16: Pointer;
pCodePointer: TPhybridIteration; //points to formula one iteration or to other functions
pIniPointer: TPFormulaInitialization;
FormulaName: AnsiString;
Description: AnsiString;
iDEoption: Integer;
iOptionCount: Integer;
sOptionStrings: array of AnsiString;
byOptionTypes: array of Byte;
dOptionVals: array of Double;
function LoadFormula(FormulaName: AnsiString): LongBool;
procedure AssignOld(OldFormula: PTCustomFormula);
// procedure FillWithValues(
constructor Create;
destructor Destroy; override;
end;
TFormulaObject = class //alternated hybrid, DEcombinate on a higher level with several TFormulaObjects
private
iFOVersion: Integer;
BoundingType: Integer; //0: RectBox 1: Ellipsoid
BoundingMidPoint: array[0..3] of Single;
BoundingRadius: array[0..3] of Single;
TransPoseMode: Integer; //0: no transpose 1: do object transpose
JuliaMode: Integer; //0: no julia mode 1: do julia mode
TransPose: array[0..2, 0..3] of Single; //scaled matrix and translation for 3d positioning+scaling+roatation
JuliaVals: array[0..3] of Double;
iFormulaCount: Integer;
iFwasInitialized: array of Integer;
Formulas: array of TFormulaClass; //also for repeat function or Interpolhybrid with next formula, ipolstart(copy vec to buf) ipolend(ipol with buf)
end;
//THybridClass = class or record ... formula hybrids with bounding box/sphere, colortab? for use with DE comb and other hybrids
implementation
uses formulas, DivUtils, CustomFormulas;
function TFormulaClass.LoadFormula(FormulaName: AnsiString): LongBool;
var CustomFormula: TCustomFormula;
CustomFname: array[0..31] of Byte;
begin
IniCustomF(@CustomFormula); //using old functions for loading... (initialization is still missing)
PutStringInCustomF(CustomFname, FormulaName);
Result := LoadCustomFormulaFromHeader(CustomFname, CustomFormula, dOptionVals);
if Result then
begin
AssignOld(@CustomFormula);
Description := CFdescription;
end;
FreeCF(@CustomFormula);
end;
procedure TFormulaClass.AssignOld(OldFormula: PTCustomFormula);
var i: Integer;
begin
Cleanup;
Init;
SIMDlevel := OldFormula.SIMDlevel;
dDEscale := OldFormula.dDEscale;
dADEscale := OldFormula.dADEscale;
dSIpow := OldFormula.dSIpow;
dRstop := OldFormula.dRstop;
iFormulaType := 0;
iConstCount := OldFormula.iConstCount;
iVersion := OldFormula.iVersion;
iDEoption := OldFormula.iDEoption;
iOptionCount := OldFormula.iCFOptionCount;
SetLength(byOptionTypes, iOptionCount);
SetLength(dOptionVals, iOptionCount);
SetLength(sOptionStrings, iOptionCount);
for i := 0 to iOptionCount - 1 do
begin
sOptionStrings[i] := OldFormula.sOptionStrings[i];
byOptionTypes[i] := OldFormula.byOptionTypes[i];
end;
if OldFormula.pCodePointer = @EmptyFormula then
OldFormula.bCPmemReserved := False;
bCPmemReserved := OldFormula.bCPmemReserved;
SetLength(VarBuffer, 1024);
pConstPointer16 := Pointer((Integer(@VarBuffer[0]) + 271) and $FFFFFFF0);
if OldFormula.pConstPointer16 = nil then
OldFormula.pConstPointer16 := PAligned16;
if OldFormula.pConstPointer16 = PAligned16 then
FastMove(PAligned16^, pConstPointer16^, 216)
else
FastMove(Pointer(Integer(OldFormula.pConstPointer16) - 256)^,
Pointer(Integer(pConstPointer16) - 256)^, 1008);
if not bCPmemReserved then
pCodePointer := OldFormula.pCodePointer
else
begin
pCodePointer := VirtualAlloc(nil, 4096, {MEM_RESERVE} MEM_COMMIT, PAGE_EXECUTE_READWRITE);
FastMove(OldFormula.pCodePointer^, pCodePointer^, 4096);
end;
if Pointer(pIniPointer) <> nil then
VirtualFree(pIniPointer, 1024, MEM_DECOMMIT);
pIniPointer := nil;
end;
constructor TFormulaClass.Create;
begin
inherited Create;
Init;
end;
procedure TFormulaClass.Init;
begin
pCodePointer := @EmptyFormula;
pConstPointer16 := PAligned16;
pIniPointer := nil;
iFormulaType := 0;
iOptionCount := 0;
iConstCount := 0;
bCPmemReserved := False;
Description := '';
FormulaName := '';
pConstPointer16 := PAligned16;
end;
procedure TFormulaClass.Cleanup;
begin
if bCPmemReserved and (pCodePointer <> @EmptyFormula) then
VirtualFree(pCodePointer, {0}4096, {MEM_RELEASE} MEM_DECOMMIT);
if pIniPointer <> nil then
VirtualFree(pIniPointer, 1024, MEM_DECOMMIT);
pIniPointer := nil;
pCodePointer := @EmptyFormula;
pConstPointer16 := PAligned16;
bCPmemReserved := False;
SetLength(VarBuffer, 0);
SetLength(byOptionTypes, 0);
SetLength(dOptionVals, 0);
SetLength(sOptionStrings, 0);
Description := '';
end;
destructor TFormulaClass.Destroy;
begin
Cleanup;
inherited Destroy;
end;
end.