some optimization
This commit is contained in:
parent
ae676f26d9
commit
5ee487cc41
@ -9,6 +9,7 @@ type
|
|||||||
TVariationFan2 = class(TBaseVariation)
|
TVariationFan2 = class(TBaseVariation)
|
||||||
private
|
private
|
||||||
FX, FY: double;
|
FX, FY: double;
|
||||||
|
dy, dx, dx2: double;
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create;
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ type
|
|||||||
function SetVariable(const Name: string; var value: double): boolean; override;
|
function SetVariable(const Name: string; var value: double): boolean; override;
|
||||||
function GetVariable(const Name: string; var value: double): boolean; override;
|
function GetVariable(const Name: string; var value: double): boolean; override;
|
||||||
|
|
||||||
|
procedure Prepare; override;
|
||||||
procedure CalcFunction; override;
|
procedure CalcFunction; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -33,14 +34,22 @@ uses
|
|||||||
{ TVariationTest }
|
{ TVariationTest }
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
procedure TVariationFan2.CalcFunction;
|
procedure TVariationFan2.Prepare;
|
||||||
const
|
const
|
||||||
EPS = 1E-10;
|
EPS = 1E-10;
|
||||||
|
begin
|
||||||
|
dy := FY;
|
||||||
|
dx := pi * (sqr(FX) + EPS);
|
||||||
|
dx2 := dx/2;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TVariationFan2.CalcFunction;
|
||||||
var
|
var
|
||||||
r,t,a : double;
|
r, a : double;
|
||||||
dx, dy, dx2: double;
|
sinr, cosr: double;
|
||||||
Angle: double;
|
Angle: double;
|
||||||
begin
|
begin
|
||||||
|
{
|
||||||
r := sqrt(FTx^ * FTx^ + FTy^ * FTy^);
|
r := sqrt(FTx^ * FTx^ + FTy^ * FTy^);
|
||||||
if (FTx^ < -EPS) or (FTx^ > EPS) or (FTy^ < -EPS) or (FTy^ > EPS) then
|
if (FTx^ < -EPS) or (FTx^ > EPS) or (FTy^ < -EPS) or (FTy^ > EPS) then
|
||||||
Angle := arctan2(FTx^, FTy^)
|
Angle := arctan2(FTx^, FTy^)
|
||||||
@ -59,13 +68,32 @@ begin
|
|||||||
|
|
||||||
FPx^ := FPx^ + vvar * r * sin(a);
|
FPx^ := FPx^ + vvar * r * sin(a);
|
||||||
FPy^ := FPy^ + vvar * r * cos(a);
|
FPy^ := FPy^ + vvar * r * cos(a);
|
||||||
|
}
|
||||||
|
Angle := arctan2(FTx^, FTy^);
|
||||||
|
if System.Frac((Angle + dy)/dx) > 0.5 then
|
||||||
|
a := Angle - dx2
|
||||||
|
else
|
||||||
|
a := Angle + dx2;
|
||||||
|
asm // SinCos(a, sinr, cosr);
|
||||||
|
FLD qword ptr [a]
|
||||||
|
FSINCOS
|
||||||
|
FSTP qword ptr [sinr]
|
||||||
|
FSTP qword ptr [cosr]
|
||||||
|
FWAIT
|
||||||
|
end;
|
||||||
|
r := vvar * sqrt(sqr(FTx^) + sqr(FTy^));
|
||||||
|
FPx^ := FPx^ + r * cosr;
|
||||||
|
FPy^ := FPy^ + r * sinr;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
constructor TVariationFan2.Create;
|
constructor TVariationFan2.Create;
|
||||||
begin
|
begin
|
||||||
FX := 2 * Random - 1;
|
// randomization removed to please mutator users ;-)
|
||||||
FY := 2 * Random - 1;
|
// FX := 2 * Random - 1;
|
||||||
|
// FY := 2 * Random - 1;
|
||||||
|
FX := 1;
|
||||||
|
FY := 1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -39,12 +39,6 @@ uses
|
|||||||
// TVariationPerspective
|
// TVariationPerspective
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
constructor TVariationPerspective.Create;
|
|
||||||
begin
|
|
||||||
angle := random;
|
|
||||||
focus := 2*random + 1;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TVariationPerspective.Prepare;
|
procedure TVariationPerspective.Prepare;
|
||||||
begin
|
begin
|
||||||
vsin := sin(angle*pi/2);
|
vsin := sin(angle*pi/2);
|
||||||
@ -84,6 +78,12 @@ asm
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
constructor TVariationPerspective.Create;
|
||||||
|
begin
|
||||||
|
angle := random;
|
||||||
|
focus := 2*random + 1;
|
||||||
|
end;
|
||||||
|
|
||||||
class function TVariationPerspective.GetInstance: TBaseVariation;
|
class function TVariationPerspective.GetInstance: TBaseVariation;
|
||||||
begin
|
begin
|
||||||
Result := TVariationPerspective.Create;
|
Result := TVariationPerspective.Create;
|
||||||
|
@ -8,7 +8,7 @@ uses
|
|||||||
type
|
type
|
||||||
TVariationRings2 = class(TBaseVariation)
|
TVariationRings2 = class(TBaseVariation)
|
||||||
private
|
private
|
||||||
FVal: double;
|
FVal, dx: double;
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create;
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ type
|
|||||||
function SetVariable(const Name: string; var value: double): boolean; override;
|
function SetVariable(const Name: string; var value: double): boolean; override;
|
||||||
function GetVariable(const Name: string; var value: double): boolean; override;
|
function GetVariable(const Name: string; var value: double): boolean; override;
|
||||||
|
|
||||||
|
procedure Prepare; override;
|
||||||
procedure CalcFunction; override;
|
procedure CalcFunction; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -30,30 +30,37 @@ implementation
|
|||||||
uses
|
uses
|
||||||
Math;
|
Math;
|
||||||
|
|
||||||
const
|
|
||||||
EPS = 1E-10;
|
|
||||||
|
|
||||||
|
|
||||||
{ TVariationTest }
|
{ TVariationTest }
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
procedure TVariationRings2.Prepare;
|
||||||
|
const
|
||||||
|
EPS = 1E-10;
|
||||||
|
begin
|
||||||
|
dx := sqr(FVal) + EPS;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TVariationRings2.CalcFunction;
|
procedure TVariationRings2.CalcFunction;
|
||||||
var
|
var
|
||||||
dx,r: double;
|
r: double;
|
||||||
Length: double;
|
Length: double;
|
||||||
Angle: double;
|
Angle: double;
|
||||||
begin
|
begin
|
||||||
Length := sqrt(FTx^ * FTx^ + FTy^ * FTy^);
|
Length := sqrt(sqr(FTx^) + sqr(FTy^));
|
||||||
|
{ // all this range-checking crap only slows us down...
|
||||||
if (FTx^ < -EPS) or (FTx^ > EPS) or (FTy^ < -EPS) or (FTy^ > EPS) then
|
if (FTx^ < -EPS) or (FTx^ > EPS) or (FTy^ < -EPS) or (FTy^ > EPS) then
|
||||||
Angle := arctan2(FTx^, FTy^)
|
Angle := arctan2(FTx^, FTy^)
|
||||||
else
|
else
|
||||||
Angle := 0.0;
|
Angle := 0.0;
|
||||||
|
} // ...and besides, we don't need arctan() if we have Length!
|
||||||
|
|
||||||
dx := sqr(FVal) + EPS;
|
// dx := sqr(FVal) + EPS; - we can precalc it!!!
|
||||||
r := Length + dx - System.Int((Length + dx)/(2 * dx)) * 2 * dx - dx + Length * (1-dx);
|
// r := Length + dx - System.Int((Length + dx)/(2 * dx)) * 2 * dx - dx + Length * (1-dx);
|
||||||
|
// ^^^^......he he, lots of useless calculation.......^^^^
|
||||||
|
r := vvar * (2 - dx * (System.Int((Length/dx + 1)/2) * 2 / Length + 1));
|
||||||
|
|
||||||
FPx^ := FPx^ + vvar * r * sin(Angle);
|
FPx^ := FPx^ + r * FTx^;
|
||||||
FPy^ := FPy^ + vvar * r * cos(Angle);
|
FPy^ := FPy^ + r * FTy^;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
unit varblob;
|
unit varBlob;
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
@ -8,9 +8,8 @@ uses
|
|||||||
type
|
type
|
||||||
TVariationBlob = class(TBaseVariation)
|
TVariationBlob = class(TBaseVariation)
|
||||||
private
|
private
|
||||||
FWaves: double;
|
FLow, FHigh, FWaves: double;
|
||||||
FLow: double;
|
VLow, VHeight: double;
|
||||||
FHigh: double;
|
|
||||||
public
|
public
|
||||||
constructor Create;
|
constructor Create;
|
||||||
|
|
||||||
@ -23,6 +22,7 @@ type
|
|||||||
function SetVariable(const Name: string; var value: double): boolean; override;
|
function SetVariable(const Name: string; var value: double): boolean; override;
|
||||||
function GetVariable(const Name: string; var value: double): boolean; override;
|
function GetVariable(const Name: string; var value: double): boolean; override;
|
||||||
|
|
||||||
|
procedure Prepare; override;
|
||||||
procedure CalcFunction; override;
|
procedure CalcFunction; override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -31,26 +31,45 @@ implementation
|
|||||||
uses
|
uses
|
||||||
Math;
|
Math;
|
||||||
|
|
||||||
{ TVariationTest }
|
{ TVariationBlob }
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
procedure TVariationBlob.Prepare;
|
||||||
|
begin
|
||||||
|
VHeight := vvar * (FHigh - FLow) / 2;
|
||||||
|
VLow := vvar * FLow + VHeight;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TVariationBlob.CalcFunction;
|
procedure TVariationBlob.CalcFunction;
|
||||||
const
|
|
||||||
EPS = 1E-10;
|
|
||||||
var
|
var
|
||||||
r : double;
|
r : double;
|
||||||
Angle: double;
|
|
||||||
begin
|
begin
|
||||||
|
{
|
||||||
r := sqrt(FTx^ * FTx^ + FTy^ * FTy^);
|
r := sqrt(FTx^ * FTx^ + FTy^ * FTy^);
|
||||||
|
|
||||||
if (FTx^ < -EPS) or (FTx^ > EPS) or (FTy^ < -EPS) or (FTy^ > EPS) then
|
if (FTx^ < -EPS) or (FTx^ > EPS) or (FTy^ < -EPS) or (FTy^ > EPS) then
|
||||||
Angle := arctan2(FTx^, FTy^)
|
Angle := arctan2(FTx^, FTy^)
|
||||||
else
|
else
|
||||||
Angle := 0.0;
|
Angle := 0.0;
|
||||||
|
|
||||||
r := r * (FLow + (FHigh - FLow) * (0.5 + 0.5 * sin(FWaves * Angle)));
|
r := r * (FLow + (FHigh - FLow) * (0.5 + 0.5 * sin(FWaves * Angle)));
|
||||||
|
|
||||||
FPx^ := FPx^ + vvar * r * sin(Angle);
|
FPx^ := FPx^ + vvar * r * sin(Angle);
|
||||||
FPy^ := FPy^ + vvar * r * cos(Angle);
|
FPy^ := FPy^ + vvar * r * cos(Angle);
|
||||||
|
}
|
||||||
|
// --Z-- LOL!!! just look at this:
|
||||||
|
// sin(a) = x / r, (well, normal people use y/r, but since we swapped x and y...)
|
||||||
|
// then:
|
||||||
|
// r * sin(a) = r * x / r = x !!!
|
||||||
|
// so, WE DON'T NEED TO CALCULATE "r" AT ALL!!!!!
|
||||||
|
// (and no need to calculate sin and cos, ofcourse :)
|
||||||
|
|
||||||
|
// r := (FLow + (FHigh - FLow) * (0.5 + 0.5 * sin(FWaves * Angle)));
|
||||||
|
// now let's precalc ^^^^^ all this :)
|
||||||
|
r := VLow + VHeight * sin(FWaves * arctan2(FTx^, FTy^));
|
||||||
|
|
||||||
|
FPx^ := FPx^ + r * FTx^;
|
||||||
|
FPy^ := FPy^ + r * FTy^;
|
||||||
|
// mwahaha, 20% speed increase - and I didn't even use any ASM :-)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
@ -88,8 +107,6 @@ begin
|
|||||||
FHigh := Value;
|
FHigh := Value;
|
||||||
Result := True;
|
Result := True;
|
||||||
end else if Name = 'blob_waves' then begin
|
end else if Name = 'blob_waves' then begin
|
||||||
//???????????? what for?:
|
|
||||||
// Value is a var variable the checked/changed value is returned for showing
|
|
||||||
Value := Round(Value);
|
Value := Round(Value);
|
||||||
FWaves := Value;
|
FWaves := Value;
|
||||||
Result := True;
|
Result := True;
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
unit varpdj;
|
unit varPDJ;
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ implementation
|
|||||||
uses
|
uses
|
||||||
Math;
|
Math;
|
||||||
|
|
||||||
{ TVariationTest }
|
{ TVariationPDJ }
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
procedure TVariationPDJ.CalcFunction;
|
procedure TVariationPDJ.CalcFunction;
|
||||||
|
Loading…
Reference in New Issue
Block a user