mirror of
https://github.com/celisej567/source-engine.git
synced 2026-01-05 22:09:59 +03:00
1
This commit is contained in:
63
mathlib/datagen.pl
Normal file
63
mathlib/datagen.pl
Normal file
@@ -0,0 +1,63 @@
|
||||
#! perl
|
||||
use Text::Wrap;
|
||||
|
||||
# generate output data for noise generators
|
||||
|
||||
srand(31456);
|
||||
|
||||
print <<END
|
||||
//========= Copyright <20> 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];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user