Blame c++/perspective/src/generator.h

531f67
#ifndef GENERATOR_H
531f67
#define GENERATOR_H
531f67
531f67
531f67
#include <climits></climits>
531f67
#include <map></map>
531f67
531f67
#include "surface.h"
531f67
#include "vector.h"
531f67
531f67
531f67
class Generator: public Shared {
531f67
public:
531f67
	struct CacheEntry;
531f67
	typedef std::map<ulongintvector2, cacheentry=""> Cache;</ulongintvector2,>
531f67
	
531f67
	struct CacheEntry {
531f67
		Cache::iterator next, previous;
531f67
		bool in_use;
531f67
		Vector4 value;
531f67
	};
531f67
	
531f67
	static inline ULongInt random(ULongInt x) {
531f67
		x ^= x << 13;
531f67
		x ^= x >> 7;
531f67
		x ^= x << 17;
531f67
		return x;
531f67
	}
531f67
	static inline Real random_to_real(ULongInt x)
531f67
		{ return Real(x)/Real(ULLONG_MAX); }
531f67
531f67
private:
531f67
	const ULongInt one;
531f67
	const int max_cache_count;
531f67
	
531f67
	mutable Cache m_cache;
531f67
	mutable Cache::iterator m_cache_top;
531f67
	mutable int m_cache_count;
531f67
	
531f67
	ULongInt m_seeds[2][4];
531f67
531f67
public:
531f67
	Generator();
531f67
	explicit Generator(ULongInt seed);
531f67
	
531f67
	inline const ULongInt* seeds_x() const { return m_seeds[0]; }
531f67
	inline const ULongInt* seeds_y() const { return m_seeds[1]; }
531f67
	inline ULongInt seed() const { return seeds_x()[0]; }
531f67
	void set_seed(ULongInt x);
531f67
531f67
	Real random(const ULongIntVector2 &coord, int index) const;
531f67
	Vector4 generate(const ULongIntVector2 &coord, bool shrink_cache = true) const;
531f67
	Vector4 generate(const Vector2 &coord, const Vector2 &precision) const;
531f67
	void generate(Surface &target, const Vector2 <, const Vector2 &rb) const;
531f67
};
531f67
531f67
531f67
#endif