From: curt Date: Mon, 4 Dec 2000 04:12:33 +0000 (+0000) Subject: Renamed fg_random -> sg_random. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=93a37df90a8a9954259d7bf1375fd7532c97a482;p=simgear.git Renamed fg_random -> sg_random. --- diff --git a/simgear/math/Makefile.am b/simgear/math/Makefile.am index 5ad69704..e6d49044 100644 --- a/simgear/math/Makefile.am +++ b/simgear/math/Makefile.am @@ -10,24 +10,24 @@ lib_LIBRARIES = libsgmath.a include_HEADERS = \ fg_memory.h \ - fg_random.h \ interpolater.hxx \ leastsqs.hxx \ localconsts.hxx \ point3d.hxx \ polar3d.hxx \ sg_geodesy.hxx \ + sg_random.h \ sg_types.hxx \ vector.hxx EXTRA_DIST = linintp2.h linintp2.inl sphrintp.h sphrintp.inl libsgmath_a_SOURCES = \ - fg_random.c \ interpolater.cxx \ leastsqs.cxx \ polar3d.cxx \ sg_geodesy.cxx \ + sg_random.c \ vector.cxx INCLUDES += -I$(top_srcdir) $(ZLIB_INCL) diff --git a/simgear/math/fg_random.c b/simgear/math/fg_random.c deleted file mode 100644 index 32a207b8..00000000 --- a/simgear/math/fg_random.c +++ /dev/null @@ -1,72 +0,0 @@ -// fg_random.c -- routines to handle random number generation -// -// Written by Curtis Olson, started July 1997. -// -// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 59 Temple Place - Suite 330, -// Boston, MA 02111-1307, USA. -// -// $Id$ - - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include // for random(), srandom() -#include // for time() to seed srandom() - -#include "fg_random.h" - -#ifndef HAVE_RAND -# ifdef sgi -# undef RAND_MAX -# define RAND_MAX 2147483647 -# endif -#endif - -#ifdef __SUNPRO_CC - extern "C" { - long int random(void); - void srandom(unsigned int seed); - } -#endif - - -// Seed the random number generater with time() so we don't see the -// same sequence every time -void fg_srandom(void) { - // fgPrintf( FG_MATH, FG_INFO, "Seeding random number generater\n"); - -#ifdef HAVE_RAND - srand(time(NULL)); -#else - srandom(time(NULL)); -#endif -} - - -// return a random number between [0.0, 1.0) -double fg_random(void) { -#ifdef HAVE_RAND - return(rand() / (double)RAND_MAX); -#else - return(random() / (double)RAND_MAX); -#endif -} - - diff --git a/simgear/math/fg_random.h b/simgear/math/fg_random.h deleted file mode 100644 index 731a3c93..00000000 --- a/simgear/math/fg_random.h +++ /dev/null @@ -1,49 +0,0 @@ -// fg_random.h -- routines to handle random number generation -// -// Written by Curtis Olson, started July 1997. -// -// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Library General Public -// License as published by the Free Software Foundation; either -// version 2 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Library General Public License for more details. -// -// You should have received a copy of the GNU Library General Public -// License along with this library; if not, write to the -// Free Software Foundation, Inc., 59 Temple Place - Suite 330, -// Boston, MA 02111-1307, USA. -// -// $Id$ - - -#ifndef _FG_RANDOM_H -#define _FG_RANDOM_H - - -#ifdef __cplusplus -extern "C" { -#endif - - -// Seed the random number generater with time() so we don't see the -// same sequence every time -void fg_srandom(void); - -// return a random number between [0.0, 1.0) -double fg_random(void); - - -#ifdef __cplusplus -} -#endif - - -#endif // _FG_RANDOM_H - - diff --git a/simgear/math/sg_random.c b/simgear/math/sg_random.c new file mode 100644 index 00000000..654cf21c --- /dev/null +++ b/simgear/math/sg_random.c @@ -0,0 +1,72 @@ +// sg_random.c -- routines to handle random number generation +// +// Written by Curtis Olson, started July 1997. +// +// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. +// +// $Id$ + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include // for random(), srandom() +#include // for time() to seed srandom() + +#include "sg_random.h" + +#ifndef HAVE_RAND +# ifdef sgi +# undef RAND_MAX +# define RAND_MAX 2147483647 +# endif +#endif + +#ifdef __SUNPRO_CC + extern "C" { + long int random(void); + void srandom(unsigned int seed); + } +#endif + + +// Seed the random number generater with time() so we don't see the +// same sequence every time +void sg_srandom(void) { + // fgPrintf( FG_MATH, FG_INFO, "Seeding random number generater\n"); + +#ifdef HAVE_RAND + srand(time(NULL)); +#else + srandom(time(NULL)); +#endif +} + + +// return a random number between [0.0, 1.0) +double sg_random(void) { +#ifdef HAVE_RAND + return(rand() / (double)RAND_MAX); +#else + return(random() / (double)RAND_MAX); +#endif +} + + diff --git a/simgear/math/sg_random.h b/simgear/math/sg_random.h new file mode 100644 index 00000000..3c41071e --- /dev/null +++ b/simgear/math/sg_random.h @@ -0,0 +1,49 @@ +// sg_random.h -- routines to handle random number generation +// +// Written by Curtis Olson, started July 1997. +// +// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. +// +// $Id$ + + +#ifndef _SG_RANDOM_H +#define _SG_RANDOM_H + + +#ifdef __cplusplus +extern "C" { +#endif + + +// Seed the random number generater with time() so we don't see the +// same sequence every time +void sg_srandom(void); + +// return a random number between [0.0, 1.0) +double sg_random(void); + + +#ifdef __cplusplus +} +#endif + + +#endif // _SG_RANDOM_H + + diff --git a/simgear/sky/cloud.cxx b/simgear/sky/cloud.cxx index 0b439771..372360b9 100644 --- a/simgear/sky/cloud.cxx +++ b/simgear/sky/cloud.cxx @@ -26,9 +26,9 @@ #include #include -#include #include #include +#include #include "cloud.hxx" @@ -70,7 +70,7 @@ void SGCloudLayer::build( double s, double asl, double thickness, sgSetVec3( vertex, -size, -size, 0.0f ); sgVec2 base; - sgSetVec2( base, fg_random(), fg_random() ); + sgSetVec2( base, sg_random(), sg_random() ); sgSetVec2( tc, base[0], base[1] ); cl->add( color ); vl->add( vertex ); diff --git a/simgear/sky/dome.cxx b/simgear/sky/dome.cxx index 0175a563..374fc3aa 100644 --- a/simgear/sky/dome.cxx +++ b/simgear/sky/dome.cxx @@ -39,7 +39,6 @@ #include #include -#include #include "dome.hxx" diff --git a/simgear/sky/sky.cxx b/simgear/sky/sky.cxx index e200def8..a3f756be 100644 --- a/simgear/sky/sky.cxx +++ b/simgear/sky/sky.cxx @@ -30,7 +30,7 @@ #include #include -#include +#include #include "sky.hxx" @@ -328,11 +328,11 @@ void SGSky::modify_vis( float alt, float time_factor ) { if ( ratio < 1.0 ) { if ( ! in_puff ) { // calc chance of entering cloud puff - double rnd = fg_random(); + double rnd = sg_random(); double chance = rnd * rnd * rnd; if ( chance > 0.95 /* * (diff - 25) / 50.0 */ ) { in_puff = true; - puff_length = fg_random() * 2.0; // up to 2 seconds + puff_length = sg_random() * 2.0; // up to 2 seconds puff_progression = 0.0; } }