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,10 +18,10 @@
#include "vec.h"
#include "pixmap.h"
#include "texture_manager.h"
#include "random.h"
#include "randomgen.h"
using std::list;
//using Shared::Util::Random;
using Shared::Util::RandomGen;
namespace Shared{ namespace Graphics{
@@ -95,7 +95,7 @@ protected:
protected:
Particle *particles;
Shared::Util::Random random;
RandomGen random;
BlendMode blendMode;
State state;

View File

@@ -0,0 +1,41 @@
// ==============================================================
// This file is part of Glest Shared Library (www.glest.org)
//
// Copyright (C) 2001-2008 Marti<74>o Figueroa
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#ifndef _SHARED_UTIL_RANDOM_H_
#define _SHARED_UTIL_RANDOM_H_
namespace Shared { namespace Util {
// =====================================================
// class RandomGen
// =====================================================
class RandomGen {
private:
static const int m;
static const int a;
static const int b;
private:
int lastNumber;
public:
RandomGen();
void init(int seed);
int rand();
int randRange(int min, int max);
float randRange(float min, float max);
};
}}//end namespace
#endif

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