some optimization

This commit is contained in:
zueuk 2006-01-05 18:24:25 +00:00
parent ae676f26d9
commit 5ee487cc41
5 changed files with 93 additions and 41 deletions

View File

@ -8,7 +8,8 @@ uses
type
TVariationFan2 = class(TBaseVariation)
private
FX,FY: double;
FX, FY: double;
dy, dx, dx2: double;
public
constructor Create;
@ -21,7 +22,7 @@ type
function SetVariable(const Name: string; var value: double): boolean; override;
function GetVariable(const Name: string; var value: double): boolean; override;
procedure Prepare; override;
procedure CalcFunction; override;
end;
@ -33,14 +34,22 @@ uses
{ TVariationTest }
///////////////////////////////////////////////////////////////////////////////
procedure TVariationFan2.CalcFunction;
procedure TVariationFan2.Prepare;
const
EPS = 1E-10;
begin
dy := FY;
dx := pi * (sqr(FX) + EPS);
dx2 := dx/2;
end;
procedure TVariationFan2.CalcFunction;
var
r,t,a : double;
dx, dy, dx2: double;
r, a : double;
sinr, cosr: double;
Angle: double;
begin
{
r := sqrt(FTx^ * FTx^ + FTy^ * FTy^);
if (FTx^ < -EPS) or (FTx^ > EPS) or (FTy^ < -EPS) or (FTy^ > EPS) then
Angle := arctan2(FTx^, FTy^)
@ -59,13 +68,32 @@ begin
FPx^ := FPx^ + vvar * r * sin(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;
///////////////////////////////////////////////////////////////////////////////
constructor TVariationFan2.Create;
begin
FX := 2 * Random - 1;
FY := 2 * Random - 1;
// randomization removed to please mutator users ;-)
// FX := 2 * Random - 1;
// FY := 2 * Random - 1;
FX := 1;
FY := 1;
end;
///////////////////////////////////////////////////////////////////////////////

View File

@ -6,8 +6,8 @@ uses
BaseVariation, XFormMan;
const
var_a_name='perspective_angle';
var_f_name='perspective_dist';
var_a_name = 'perspective_angle';
var_f_name = 'perspective_dist';
type
TVariationPerspective = class(TBaseVariation)
@ -39,12 +39,6 @@ uses
// TVariationPerspective
///////////////////////////////////////////////////////////////////////////////
constructor TVariationPerspective.Create;
begin
angle := random;
focus := 2*random + 1;
end;
procedure TVariationPerspective.Prepare;
begin
vsin := sin(angle*pi/2);
@ -84,6 +78,12 @@ asm
end;
///////////////////////////////////////////////////////////////////////////////
constructor TVariationPerspective.Create;
begin
angle := random;
focus := 2*random + 1;
end;
class function TVariationPerspective.GetInstance: TBaseVariation;
begin
Result := TVariationPerspective.Create;

View File

@ -8,7 +8,7 @@ uses
type
TVariationRings2 = class(TBaseVariation)
private
FVal: double;
FVal, dx: double;
public
constructor Create;
@ -21,7 +21,7 @@ type
function SetVariable(const Name: string; var value: double): boolean; override;
function GetVariable(const Name: string; var value: double): boolean; override;
procedure Prepare; override;
procedure CalcFunction; override;
end;
@ -30,30 +30,37 @@ implementation
uses
Math;
const
EPS = 1E-10;
{ TVariationTest }
///////////////////////////////////////////////////////////////////////////////
procedure TVariationRings2.Prepare;
const
EPS = 1E-10;
begin
dx := sqr(FVal) + EPS;
end;
procedure TVariationRings2.CalcFunction;
var
dx,r: double;
r: double;
Length: double;
Angle: double;
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
Angle := arctan2(FTx^, FTy^)
Angle := arctan2(FTx^, FTy^)
else
Angle := 0.0;
} // ...and besides, we don't need arctan() if we have Length!
dx := sqr(FVal) + EPS;
r := Length + dx - System.Int((Length + dx)/(2 * dx)) * 2 * dx - dx + Length * (1-dx);
// dx := sqr(FVal) + EPS; - we can precalc it!!!
// 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);
FPy^ := FPy^ + vvar * r * cos(Angle);
FPx^ := FPx^ + r * FTx^;
FPy^ := FPy^ + r * FTy^;
end;
///////////////////////////////////////////////////////////////////////////////

View File

@ -1,4 +1,4 @@
unit varblob;
unit varBlob;
interface
@ -8,9 +8,8 @@ uses
type
TVariationBlob = class(TBaseVariation)
private
FWaves: double;
FLow: double;
FHigh: double;
FLow, FHigh, FWaves: double;
VLow, VHeight: double;
public
constructor Create;
@ -23,6 +22,7 @@ type
function SetVariable(const Name: string; var value: double): boolean; override;
function GetVariable(const Name: string; var value: double): boolean; override;
procedure Prepare; override;
procedure CalcFunction; override;
end;
@ -31,26 +31,45 @@ implementation
uses
Math;
{ TVariationTest }
{ TVariationBlob }
///////////////////////////////////////////////////////////////////////////////
procedure TVariationBlob.Prepare;
begin
VHeight := vvar * (FHigh - FLow) / 2;
VLow := vvar * FLow + VHeight;
end;
procedure TVariationBlob.CalcFunction;
const
EPS = 1E-10;
var
r : double;
Angle: double;
begin
{
r := sqrt(FTx^ * FTx^ + FTy^ * FTy^);
if (FTx^ < -EPS) or (FTx^ > EPS) or (FTy^ < -EPS) or (FTy^ > EPS) then
Angle := arctan2(FTx^, FTy^)
else
Angle := 0.0;
r := r * (FLow + (FHigh - FLow) * (0.5 + 0.5 * sin(FWaves * Angle)));
FPx^ := FPx^ + vvar * r * sin(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;
///////////////////////////////////////////////////////////////////////////////
@ -88,8 +107,6 @@ begin
FHigh := Value;
Result := True;
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);
FWaves := Value;
Result := True;

View File

@ -1,4 +1,4 @@
unit varpdj;
unit varPDJ;
interface
@ -30,7 +30,7 @@ implementation
uses
Math;
{ TVariationTest }
{ TVariationPDJ }
///////////////////////////////////////////////////////////////////////////////
procedure TVariationPDJ.CalcFunction;