diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /mathlib/datagen.pl | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'mathlib/datagen.pl')
| -rw-r--r-- | mathlib/datagen.pl | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/mathlib/datagen.pl b/mathlib/datagen.pl new file mode 100644 index 0000000..9646002 --- /dev/null +++ b/mathlib/datagen.pl @@ -0,0 +1,63 @@ +#! perl +use Text::Wrap; + +# generate output data for noise generators + +srand(31456); + +print <<END +//========= Copyright � 1996-2006, Valve Corporation, All rights reserved. ============// +// +// Purpose: static data for noise() primitives. +// +// \$Workfile: \$ +// \$NoKeywords: \$ +//=============================================================================// +// +// **** DO NOT EDIT THIS FILE. GENERATED BY DATAGEN.PL **** +// + +END +; + +@perm_a=0..255; + +&fisher_yates_shuffle(\@perm_a); + +$Text::Wrap::Columns=78; +$Text::Wrap::break=","; +$Text::Wrap::separator=",\n"; + +print "static int perm_a[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n"; +&fisher_yates_shuffle(\@perm_a); +print "static int perm_b[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n"; +&fisher_yates_shuffle(\@perm_a); +print "static int perm_c[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n"; +&fisher_yates_shuffle(\@perm_a); +print "static int perm_d[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n"; + +for ($i=0;$i<256;$i++) + { + $float_perm=(1.0/255.0)*$perm_a[$i]; + $perm_a[$i] = sprintf("%f",$float_perm); + } +&fisher_yates_shuffle(\@perm_a); +print "static float impulse_xcoords[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n"; +&fisher_yates_shuffle(\@perm_a); +print "static float impulse_ycoords[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n"; +&fisher_yates_shuffle(\@perm_a); +print "static float impulse_zcoords[]={\n",wrap(' ',' ',join(",",@perm_a)),"\n};\n\n"; + + + +# fisher_yates_shuffle( \@array ) : generate a random permutation +# of @array in place +sub fisher_yates_shuffle { + my $array = shift; + my $i; + for ($i = @$array; --$i; ) { + my $j = int rand ($i+1); + next if $i == $j; + @$array[$i,$j] = @$array[$j,$i]; + } +} |