aboutsummaryrefslogtreecommitdiff
path: root/src/noise.cpp
Commit message (Collapse)AuthorAge
* PcgRandom: Fix/improve documentationkwolekr2016-06-04
|
* Change internal type for seeds to s32kwolekr2016-06-04
| | | | | This fixes value truncation (and therefore incompatibility) on platforms with an LP32 data model, such as VAX or MS-DOS.
* Fix spelling of noise_thresholdJun Zhang2015-12-06
|
* Fix Noise compiled under clang >= 3.7.x with -O2 or higherkwolekr2015-11-01
| | | | | | | | | | When compiled with optimizations, the most recent versions of clang seem to 'optimize' out a crucial "and %reg, 0x7FFFFFFF" instruction in noise2d(), probably because it somehow assumed the variable n would never become greater than that amount. Indeed, signed integer underflow is undefined behavior in C and C++, so while this optimization is "correct" in that sense, it breaks lots of existing code. Solved by changing n to an unsigned type, making behavior well-defined.
* Fix Lua PcgRandomest312015-08-12
| | | | | | | | | | | | | | | | Before, this lua code led to a crash: local pcg = PcgRandom(42) local value = pcg:next() This was because if you called s32 PcgRandom::range(min, max) with the minimum and maximum possible values for s32 integers (which the lua binding code did), u32 PcgRandom::range(bound) got called with 0 as the bound. The bound however is one above the maximum value, so 0 is a "special" value to pass to this function. This commit fixes the lua crash by assigning the RNG's full range to the bound 0, which is also fits to the "maximum is bound - 1" principle, as (u32)-1 is the maximum value in the u32 range.
* Remove some old dead code. Fix some Clang warnings in SRP (ng->N... willLoic Blot2015-07-24
| | | | always evaluate to true.
* Misc. minor fixeskwolekr2015-07-10
|
* Noise: Fix interpolation at negative coordinateskwolekr2015-05-17
|
* Add -Wsign-compare for Clang builds and fix some signed/unsigned compiler ↵kwolekr2015-05-16
| | | | warnings
* Noise: Make buffer size parameters unsignedkwolekr2015-05-15
|
* Fix MSVC compatibilitykwolekr2015-04-29
| | | | | | Make sure to include random unittests in android builds, too Use SWAP() macro Ensure that negative ranges are tested as well in random unittests
* Noise: Fix PcgRandom::randNormalDist() when range contains negative numberskwolekr2015-04-27
| | | | | This fixes an issue with erroneous float-to-int rounding that resulted in truncation toward 0, causing a biased distribution.
* Replace PRNG assertions with PrngExceptionkwolekr2015-04-27
|
* Noise: Add noise unittestskwolekr2015-04-21
| | | | | Fix buffer size calculation for lacunarity < 1.0 Add guard against absurd noise parameters
* Noise: Correct noise objects created with invalid dimensionskwolekr2015-04-19
|
* Fix endianness inconsistency with PcgRandom::bytes()kwolekr2015-03-23
|
* Fix some loose ends from 3993093fkwolekr2015-03-22
|
* Add support for the PCG32 PRNG algo (and associated script APIs)kwolekr2015-03-22
|
* Noise: Don't assume Noise is used for 2D unless gradientMap2D is actually calledkwolekr2014-12-14
|
* Clean up Noise macroskwolekr2014-12-11
|
* Noise: Automatically transform noise maps if neededkwolekr2014-12-10
|
* Noise: Create a deep copy of NoiseParamskwolekr2014-12-10
|
* Noise: Update Noise::resizeNoiseBuf to account for lacunarity not equal to 2kwolekr2014-12-09
|
* Optimize noise implementationskwolekr2014-12-08
|
* Add flags and lacunarity as new noise parameterskwolekr2014-12-07
| | | | | | | Add 'absolute value' option to noise map functions Extend persistence modulation to 3D noise Extend 'eased' option to noise2d_perlin* functions Some noise.cpp formatting fixups
* noise: Throw exception on noise allocation failurekwolekr2014-11-29
|
* Add eased 3d point-value noise functionskwolekr2014-11-12
|
* Add mgv5. New noise code, uses biome API. Eased 3d noise for terrain, caves, ↵paramat2014-11-08
| | | | blobs
* Change license of noise implementation to Simplified BSDkwolekr2014-10-27
|
* Add support for eased 3d noisekwolekr2014-10-27
|
* Omnicleanup: header cleanup, add ModApiUtil shared between game and mainmenuKahrl2013-08-14
|
* Add Mapgen V7, reorganize biomeskwolekr2013-04-07
|
* Fix most warnings, re-fix MSVC compile errorkwolekr2013-02-26
|
* Update Copyright YearsSfan52013-02-24
|
* Change Minetest-c55 to MinetestPilzAdam2013-02-24
|
* Fix and improve noise map functionskwolekr2013-02-06
|
* Finish and clean up mapgen configurationkwolekr2013-01-21
|
* Readded and optimized mapgen V6kwolekr2013-01-21
|
* Cleaned & enhanced noise object managementkwolekr2013-01-21
|
* Add initial Lua biomedef support, fixed biome selectionkwolekr2013-01-21
|
* The new mapgen, noise functions, et al.kwolekr2013-01-21
|
* Replace pow() with multiplikation to improve speedPilzAdam2012-11-02
|
* Switch the license to be LGPLv2/later, with small parts still remaining as ↵Perttu Ahola2012-06-05
| | | | GPLv2/later, by agreement of major contributors
* updated noise stuffPerttu Ahola2011-06-26
|
* New map generator added (and SQLite, messed up the commits at that time...) ↵Perttu Ahola2011-06-25
| | | | (import from temporary git repo)
* tested out and commented out some new stuff for the terrain generator, to be ↵Perttu Ahola2011-04-26
| | | | used in the future.
* mapgen work-in-progressPerttu Ahola2011-03-02
|
* mapgen tweakingPerttu Ahola2011-03-01
|
* A third try on terrain generation. No trees yet.Perttu Ahola2011-02-28
|
* fixed 3d noise and made 2d noise fasterPerttu Ahola2011-02-27
|
opt">(const CraftInput &input, IGameDef *gamedef) const=0; RecipePriority getPriority() const { return priority; } // Returns the output structure, meaning depends on crafting method // The implementation can assume that check(input) returns true virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const=0; // the inverse of the above virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const=0; // Decreases count of every input item virtual void decrementInput(CraftInput &input, std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const=0; CraftHashType getHashType() const { return hash_type; } virtual u64 getHash(CraftHashType type) const = 0; // to be called after all mods are loaded, so that we catch all aliases virtual void initHash(IGameDef *gamedef) = 0; virtual std::string dump() const=0; protected: CraftHashType hash_type; RecipePriority priority; }; /* A plain-jane (shaped) crafting definition Supported crafting method: CRAFT_METHOD_NORMAL. Requires the input items to be arranged exactly like in the recipe. */ class CraftDefinitionShaped: public CraftDefinition { public: CraftDefinitionShaped() = delete; CraftDefinitionShaped( const std::string &output_, unsigned int width_, const std::vector<std::string> &recipe_, const CraftReplacements &replacements_); virtual ~CraftDefinitionShaped() = default; virtual std::string getName() const; virtual bool check(const CraftInput &input, IGameDef *gamedef) const; virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const; virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const; virtual void decrementInput(CraftInput &input, std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const; virtual u64 getHash(CraftHashType type) const; virtual void initHash(IGameDef *gamedef); virtual std::string dump() const; private: // Output itemstring std::string output = ""; // Width of recipe unsigned int width = 1; // Recipe matrix (itemstrings) std::vector<std::string> recipe; // Recipe matrix (item names) std::vector<std::string> recipe_names; // bool indicating if initHash has been called already bool hash_inited = false; // Replacement items for decrementInput() CraftReplacements replacements; }; /* A shapeless crafting definition Supported crafting method: CRAFT_METHOD_NORMAL. Input items can arranged in any way. */ class CraftDefinitionShapeless: public CraftDefinition { public: CraftDefinitionShapeless() = delete; CraftDefinitionShapeless( const std::string &output_, const std::vector<std::string> &recipe_, const CraftReplacements &replacements_); virtual ~CraftDefinitionShapeless() = default; virtual std::string getName() const; virtual bool check(const CraftInput &input, IGameDef *gamedef) const; virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const; virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const; virtual void decrementInput(CraftInput &input, std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const; virtual u64 getHash(CraftHashType type) const; virtual void initHash(IGameDef *gamedef); virtual std::string dump() const; private: // Output itemstring std::string output; // Recipe list (itemstrings) std::vector<std::string> recipe; // Recipe list (item names) std::vector<std::string> recipe_names; // bool indicating if initHash has been called already bool hash_inited = false; // Replacement items for decrementInput() CraftReplacements replacements; }; /* Tool repair crafting definition Supported crafting method: CRAFT_METHOD_NORMAL. Put two damaged tools into the crafting grid, get one tool back. There should only be one crafting definition of this type. */ class CraftDefinitionToolRepair: public CraftDefinition { public: CraftDefinitionToolRepair() = delete; CraftDefinitionToolRepair(float additional_wear_); virtual ~CraftDefinitionToolRepair() = default; virtual std::string getName() const; virtual bool check(const CraftInput &input, IGameDef *gamedef) const; virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const; virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const; virtual void decrementInput(CraftInput &input, std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const; virtual u64 getHash(CraftHashType type) const { return 2; } virtual void initHash(IGameDef *gamedef) { hash_type = CRAFT_HASH_TYPE_COUNT; } virtual std::string dump() const; private: // This is a constant that is added to the wear of the result. // May be positive or negative, allowed range [-1,1]. // 1 = new tool is completely broken // 0 = simply add remaining uses of both input tools // -1 = new tool is completely pristine float additional_wear = 0.0f; }; /* A cooking (in furnace) definition Supported crafting method: CRAFT_METHOD_COOKING. */ class CraftDefinitionCooking: public CraftDefinition { public: CraftDefinitionCooking() = delete; CraftDefinitionCooking( const std::string &output_, const std::string &recipe_, float cooktime_, const CraftReplacements &replacements_); virtual ~CraftDefinitionCooking() = default; virtual std::string getName() const; virtual bool check(const CraftInput &input, IGameDef *gamedef) const; virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const; virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const; virtual void decrementInput(CraftInput &input, std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const; virtual u64 getHash(CraftHashType type) const; virtual void initHash(IGameDef *gamedef); virtual std::string dump() const; private: // Output itemstring std::string output; // Recipe itemstring std::string recipe; // Recipe item name std::string recipe_name; // bool indicating if initHash has been called already bool hash_inited = false; // Time in seconds float cooktime; // Replacement items for decrementInput() CraftReplacements replacements; }; /* A fuel (for furnace) definition Supported crafting method: CRAFT_METHOD_FUEL. */ class CraftDefinitionFuel: public CraftDefinition { public: CraftDefinitionFuel() = delete; CraftDefinitionFuel( const std::string &recipe_, float burntime_, const CraftReplacements &replacements_); virtual ~CraftDefinitionFuel() = default; virtual std::string getName() const; virtual bool check(const CraftInput &input, IGameDef *gamedef) const; virtual CraftOutput getOutput(const CraftInput &input, IGameDef *gamedef) const; virtual CraftInput getInput(const CraftOutput &output, IGameDef *gamedef) const; virtual void decrementInput(CraftInput &input, std::vector<ItemStack> &output_replacements, IGameDef *gamedef) const; virtual u64 getHash(CraftHashType type) const; virtual void initHash(IGameDef *gamedef); virtual std::string dump() const; private: // Recipe itemstring std::string recipe; // Recipe item name std::string recipe_name; // bool indicating if initHash has been called already bool hash_inited = false; // Time in seconds float burntime; // Replacement items for decrementInput() CraftReplacements replacements; }; /* Crafting definition manager */ class ICraftDefManager { public: ICraftDefManager() = default; virtual ~ICraftDefManager() = default; /** * The main crafting function. * * @param input The input grid. * @param output CraftOutput where the result is placed. * @param output_replacements A vector of ItemStacks where replacements are * placed if they cannot be placed in the input. Replacements can be placed * in the input if the stack of the replaced item has a count of 1. * @param decrementInput If true, consume or replace input items. * @param gamedef * @return true if a result was found, otherwise false. */ virtual bool getCraftResult(CraftInput &input, CraftOutput &output, std::vector<ItemStack> &output_replacements, bool decrementInput, IGameDef *gamedef) const=0; virtual std::vector<CraftDefinition*> getCraftRecipes(CraftOutput &output, IGameDef *gamedef, unsigned limit=0) const=0; // Print crafting recipes for debugging virtual std::string dump() const=0; }; class IWritableCraftDefManager : public ICraftDefManager { public: IWritableCraftDefManager() = default; virtual ~IWritableCraftDefManager() = default; // The main crafting function virtual bool getCraftResult(CraftInput &input, CraftOutput &output, std::vector<ItemStack> &output_replacements, bool decrementInput, IGameDef *gamedef) const=0; virtual std::vector<CraftDefinition*> getCraftRecipes(CraftOutput &output, IGameDef *gamedef, unsigned limit=0) const=0; virtual bool clearCraftsByOutput(const CraftOutput &output, IGameDef *gamedef) = 0; virtual bool clearCraftsByInput(const CraftInput &input, IGameDef *gamedef) = 0; // Print crafting recipes for debugging virtual std::string dump() const=0; // Add a crafting definition. // After calling this, the pointer belongs to the manager. virtual void registerCraft(CraftDefinition *def, IGameDef *gamedef) = 0; // Delete all crafting definitions virtual void clear()=0; // To be called after all mods are loaded, so that we catch all aliases virtual void initHashes(IGameDef *gamedef) = 0; }; IWritableCraftDefManager* createCraftDefManager();