[Scummvm-cvs-logs] CVS: scummvm/common util.cpp,1.5,1.6 util.h,1.7,1.8

Oliver Kiehl olki at users.sourceforge.net
Sun Dec 1 06:58:49 CET 2002


Update of /cvsroot/scummvm/scummvm/common
In directory sc8-pr-cvs1:/tmp/cvs-serv21709/common

Modified Files:
	util.cpp util.h 
Log Message:
moved RNG to common/util.cpp


Index: util.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/util.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- util.cpp	16 Sep 2002 10:42:12 -0000	1.5
+++ util.cpp	1 Dec 2002 14:57:49 -0000	1.6
@@ -157,3 +157,27 @@
 	}
 	return num;
 }
+
+RandomSource::RandomSource(uint32 seed)
+{
+	_randSeed = seed;
+}
+
+void RandomSource::setSeed(uint32 seed)
+{
+	_randSeed = seed;
+}
+
+uint RandomSource::getRandomNumber(uint max)
+{
+	/* TODO: my own random number generator */
+	_randSeed = 0xDEADBF03 * (_randSeed + 1);
+	_randSeed = (_randSeed >> 13) | (_randSeed << 19);
+	return _randSeed % (max + 1);
+}
+
+uint RandomSource::getRandomNumberRng(uint min, uint max)
+{
+	return getRandomNumber(max - min) + min;
+}
+

Index: util.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/common/util.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- util.h	30 Nov 2002 16:03:46 -0000	1.7
+++ util.h	1 Dec 2002 14:57:49 -0000	1.8
@@ -72,4 +72,16 @@
 // Resource string length
 int resStrLen(const char *src);
 
+
+class RandomSource {
+private:
+	uint32 _randSeed;
+
+public:
+	RandomSource(uint32 seed = 0xA943DE33);
+	void setSeed(uint32 seed);
+	uint getRandomNumber(uint max);
+	uint getRandomNumberRng(uint min, uint max);
+};
+
 #endif





More information about the Scummvm-git-logs mailing list