Ported streflop code to win32

This commit is contained in:
Mark Vejvoda
2010-04-24 11:15:15 +00:00
parent 2bfaa4d1d7
commit f748874601
26 changed files with 867 additions and 51 deletions

View File

@@ -18,7 +18,7 @@
#include "util.h"
#include "math_util.h"
#include "random.h"
#include "randomgen.h"
#include "FileReader.h"
#include "ImageReaders.h"
@@ -631,7 +631,7 @@ float splatDist(Vec2i a, Vec2i b){
void Pixmap2D::splat(const Pixmap2D *leftUp, const Pixmap2D *rightUp, const Pixmap2D *leftDown, const Pixmap2D *rightDown){
Random random;
RandomGen random;
assert(components==3 || components==4);

View File

@@ -12,7 +12,7 @@
#include "sound_player_ds8.h"
#include <cassert>
//#include <cmath>
#include <cmath>
//#include "streflop.h"
#include "util.h"

View File

@@ -0,0 +1,45 @@
#include "randomgen.h"
#include <cassert>
#include "leak_dumper.h"
namespace Shared { namespace Util {
// =====================================================
// class RandomGen
// =====================================================
const int RandomGen::m= 714025;
const int RandomGen::a= 1366;
const int RandomGen::b= 150889;
RandomGen::RandomGen(){
lastNumber= 0;
}
void RandomGen::init(int seed){
lastNumber= seed % m;
}
int RandomGen::rand(){
lastNumber= (a*lastNumber + b) % m;
return lastNumber;
}
int RandomGen::randRange(int min, int max){
assert(min<=max);
int diff= max-min;
int res= min + static_cast<int>(static_cast<float>(diff+1)*RandomGen::rand() / m);
assert(res>=min && res<=max);
return res;
}
float RandomGen::randRange(float min, float max){
assert(min<=max);
float rand01= static_cast<float>(RandomGen::rand())/(m-1);
float res= min+(max-min)*rand01;
assert(res>=min && res<=max);
return res;
}
}}//end namespace