aboutsummaryrefslogtreecommitdiff
path: root/games/minimal/mods/default/textures/default_rail.png
blob: 777e10c00404de93965cdbe42f02015572efb796 (plain)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 10 00 00 00 10 08 03 00 00 00 28 2d 0f .PNG........IHDR.............(-.
0020 53 00 00 00 db 50 4c 54 45 00 00 00 55 57 53 5c 41 18 64 47 1b 64 48 1a 69 4a 1b 69 4a 1c 6a 4b S....PLTE...UWS\A.dG.dH.iJ.iJ.jK
0040 1c 6a 4c 1c 6b 4c 1c 6d 4d 1c 6d 4e 1d 6e 4e 1d 6f 4f 1d 6f 4f 1e 70 4f 1d 70 50 1e 71 50 1e 71 .jL.kL.mM.mN.nN.oO.oO.pO.pP.qP.q
0060 51 1e 72 50 1e 72 51 1e 73 52 1f 74 53 1e 74 53 1f 75 53 1f 76 54 1f 77 55 1f 78 55 1f 79 56 1f Q.rP.rQ.sR.tS.tS.uS.vT.wU.xU.yV.
0080 79 56 20 7a 57 20 7b 57 20 7f 5b 21 80 5b 22 80 5c 22 81 5b 22 86 63 2b 89 65 2c 8b 67 2d 90 6a yV.zW.{W..[!.[".\".[".c+.e,.g-.j
00a0 2f 91 6b 2f 93 6d 30 95 6d 30 95 6e 30 96 6f 30 96 6f 31 98 71 32 99 72 32 9a 72 32 9a 73 32 9b /.k/.m0.m0.n0.o0.o1.q2.r2.r2.s2.
00c0 73 33 9c 74 32 9c 74 33 9d 74 33 9f 75 33 9f 75 34 a1 76 34 a2 77 35 a3 79 35 a4 78 35 a4 79 36 s3.t2.t3.t3.u3.u4.v4.w5.y5.x5.y6
00e0 a5 7a 36 a7 7b 37 a8 7d 37 a9 7c 37 ab 7e 38 af 81 39 b0 83 39 b3 84 3a b4 86 3a b6 87 3b b7 87 .z6.{7.}7.|7.~8..9..9..:..:..;..
0100 3c ba bd b6 b8 64 fa 52 00 00 00 01 74 52 4e 53 00 40 e6 d8 66 00 00 00 88 49 44 41 54 18 57 8d <....d.R....tRNS.@..f....IDAT.W.
0120 8c 45 12 c2 00 00 c4 76 71 b7 52 a0 b8 53 dc 8a bb ef ff 5f c4 85 5b 2f e4 98 99 04 80 88 1f 14 .E.....vq.R..S....._..[/........
0140 00 7c 44 db 39 ec 2e ce a4 4d 6d 00 04 c5 b2 af 50 cc 26 32 4d 2a 0a b8 13 97 d8 8b d3 e1 e3 b9 .|D.9....Mm.....P.&2M*..........
0160 b8 6e 3b d4 0b 40 5d cc 05 cc 7c 29 1d 8e 51 8d bf 1e 27 71 bc ee cf df a3 65 8f 5a 01 48 8a 71 .n;..@]...|)..Q...'q.....e.Z.H.q
0180 33 14 69 59 46 8a f2 ff f5 98 89 f7 e3 aa 7b 3b db 03 ca 06 60 89 46 35 5d ab c4 12 5e ca e3 4e 3.iYF.........{;....`.F5]...^..N
01a0 be 07 62 14 41 e3 14 5e bd 00 00 00 00 49 45 4e 44 ae 42 60 82 ..b.A..^.....IEND.B`.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
/*
Minetest
Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <cmath>
#include "mapgen_math.h"
#include "voxel.h"
#include "mapblock.h"
#include "mapnode.h"
#include "map.h"
#include "nodedef.h"
#include "voxelalgorithms.h"
#include "profiler.h"
#include "settings.h" // For g_settings
#include "main.h" // For g_profiler
#include "emerge.h"
#include "biome.h"

// can use ported lib from http://mandelbulber.googlecode.com/svn/trunk/src
//#include "mandelbulber/fractal.h"
//#include "mandelbulber/fractal.cpp"

double mandelbox(double x, double y, double z, double d, int nn = 10) {
	int s = 7;
	x *= s;
	y *= s;
	z *= s;
	d *= s;

	double posX = x;
	double posY = y;
	double posZ = z;

	double dr = 1.0;
	double r = 0.0;

	double scale = 2;

	double minRadius2 = 0.25;
	double fixedRadius2 = 1;

	for (int n = 0; n < nn; n++) {
		// Reflect
		if (x > 1.0)
			x = 2.0 - x;
		else if (x < -1.0)
			x = -2.0 - x;
		if (y > 1.0)
			y = 2.0 - y;
		else if (y < -1.0)
			y = -2.0 - y;
		if (z > 1.0)
			z = 2.0 - z;
		else if (z < -1.0)
			z = -2.0 - z;

		// Sphere Inversion
		double r2 = x * x + y * y + z * z;

		if (r2 < minRadius2) {
			x = x * fixedRadius2 / minRadius2;
			y = y * fixedRadius2 / minRadius2;
			z = z * fixedRadius2 / minRadius2;
			dr = dr * fixedRadius2 / minRadius2;
		} else if (r2 < fixedRadius2) {
			x = x * fixedRadius2 / r2;
			y = y * fixedRadius2 / r2;
			z = z * fixedRadius2 / r2;
			fixedRadius2 *= fixedRadius2 / r2;
		}

		x = x * scale + posX;
		y = y * scale + posY;
		z = z * scale + posZ;
		dr *= scale;
	}
	r = sqrt(x * x + y * y + z * z);
	return ((r / fabs(dr)) < d);

}

double mengersponge(double x, double y, double z, double d, int MI = 10) {

	double r = x * x + y * y + z * z;
	double scale = 3;
	int i = 0;


	for (i = 0; i < MI && r < 9; i++) {


		x = fabs(x);
		y = fabs(y);
		z = fabs(z);


		if (x - y < 0) {
			double x1 = y;
			y = x;
			x = x1;
		}
		if (x - z < 0) {
			double x1 = z;
			z = x;
			x = x1;
		}
		if (y - z < 0) {
			double y1 = z;
			z = y;
			y = y1;
		}


		x = scale * x - 1 * (scale - 1);
		y = scale * y - 1 * (scale - 1);
		z = scale * z;


		if (z > 0.5 * 1 * (scale - 1))
			z -= 1 * (scale - 1);


		r = x * x + y * y + z * z;
	}
	return ((sqrt(r)) * pow(scale, (-i)) < d);
}

double sphere(double x, double y, double z, double d, int ITR = 1) {
	return v3f(x, y, z).getLength() < d;
}


//////////////////////// Mapgen Math parameter read/write

void MapgenMathParams::readParams(Settings *settings) {
	//params = settings->getJson("mg_math");
	// can be counfigured from here.
	std::string value = "{}";
	Json::Reader reader;
	if (!reader.parse( value, params ) ) {
		errorstream  << "Failed to parse json conf var ='" << value << "' : " << reader.getFormattedErrorMessages();
	}

	if (params["generator"].empty()) params["generator"] = settings->get("mgmath_generator");
}


void MapgenMathParams::writeParams(Settings *settings) {
	//settings->setJson("mg_math", params);
	settings->set("mgmath_generator", params["generator"].asString());
}

///////////////////////////////////////////////////////////////////////////////

MapgenMath::MapgenMath(int mapgenid, MapgenParams *params_, EmergeManager *emerge) : MapgenV7(mapgenid, params_, emerge) {
	mg_params = (MapgenMathParams *)params_;
	this->flags &= ~MG_LIGHT;

	Json::Value & params = mg_params->params;
	invert = params["invert"].empty() ? 1 : params["invert"].asBool(); //params["invert"].empty()?1:params["invert"].asBool();
	size = params["size"].empty() ? 0 : params["size"].asDouble(); // = max_r
	scale = params["scale"].empty() ? 0 : params["scale"].asDouble(); //(double)1 / size;
	if(!params["center"].empty()) center = v3f(params["center"]["x"].asFloat(), params["center"]["y"].asFloat(), params["center"]["z"].asFloat()); //v3f(5, -size - 5, 5);
	iterations = params["iterations"].empty() ? 0 : params["iterations"].asInt(); //10;
	distance = params["distance"].empty() ? 0 : params["distance"].asDouble(); // = 1/size;

	func = &sphere;

	if (params["generator"].empty()) params["generator"] = "mandelbox";
	if (params["generator"].asString() == "mengersponge") {
		if (!size) size = (MAP_GENERATION_LIMIT - 1000) / 2;
		if (!iterations) iterations = 10;
		if (!distance) distance = 0.0003;
		//if (!scale) scale = (double)0.1 / size;
		//if (!distance) distance = 0.01; //10/size;//sqrt3 * bd4;
		//if (!scale) scale = 0.01; //10/size;//sqrt3 * bd4;
		//center=v3f(-size/3,-size/3+(-2*-invert),2);
		center = v3f(-size, -size, -size);
		func = &mengersponge;
	} else if (params["generator"].asString() == "mandelbox") {
		/*
			size = MAP_GENERATION_LIMIT - 1000;
			//size = 1000;
			distance = 0.01; //100/size; //0.01;
			iterations = 10;
			center = v3f(1, 1, 1); // *size/6;
		*/

		//mandelbox
		if (!size) size = 1000;
		if (!distance) distance = 0.01;
		if(params["invert"].empty()) invert = 0;
		//center=v3f(2,-size/4,2);
		//size = 10000;
		//center=v3f(size/2,-size*0.9,size/2);
		if(params["center"].empty())center = v3f(size * 0.3, -size * 0.6, size * 0.5);
		func = &mandelbox;
	} else if (params["generator"].asString() == "sphere") {
		if(params["invert"].empty()) invert = 0;
		if (!size) size = 100;
		if (!distance) distance = size;
		func = &sphere;
		if (!scale) scale = 1;
		//sphere
		//size = 1000;scale = 1;center = v3f(2,-size-2,2);
	}

	if (!iterations) iterations = 10;
	if (!size) size = 1000;
	if (!scale) scale = (double)1 / size;
	if (!distance)  distance = scale;
	if (params["center"].empty() && !center.getLength()) center = v3f(3, -size + (-5 - (-invert * 10)), 3);
	//size ||= params["size"].empty()?1000:params["size"].asDouble(); // = max_r

}


MapgenMath::~MapgenMath() {
}

//////////////////////// Map generator

int MapgenMath::generateTerrain() {

	MapNode n_air(CONTENT_AIR, LIGHT_SUN), n_water_source(c_water_source, LIGHT_SUN);
	MapNode n_stone(c_stone, LIGHT_SUN);
	u32 index = 0;
	v3s16 em = vm->m_area.getExtent();

#if 1

	/* debug
	v3f vec0 = (v3f(node_min.X, node_min.Y, node_min.Z) - center) * scale ;
	errorstream << " X=" << node_min.X << " Y=" << node_min.Y << " Z=" << node_min.Z
	            //<< " N="<< mengersponge(vec0.X, vec0.Y, vec0.Z, distance, iterations)
	            << " N=" << (*func)(vec0.X, vec0.Y, vec0.Z, distance, iterations)
	            << " Sc=" << scale << " gen=" << params["generator"].asString() << " J=" << Json::FastWriter().write(params) << std::endl;
	*/
	for (s16 z = node_min.Z; z <= node_max.Z; z++) {
		for (s16 x = node_min.X; x <= node_max.X; x++, index++) {
			//Biome *biome = bmgr->biomes[biomemap[index]];
			u32 i = vm->m_area.index(x, node_min.Y, z);
			for (s16 y = node_min.Y; y <= node_max.Y; y++) {
				v3f vec = (v3f(x, y, z) - center) * scale ;
				double d = (*func)(vec.X, vec.Y, vec.Z, distance, iterations);
				if ((!invert && d > 0) || (invert && d == 0)  ) {
					if (vm->m_data[i].getContent() == CONTENT_IGNORE)
	//					vm->m_data[i] = (y > water_level + biome->filler) ?
		//				                MapNode(biome->c_filler) : n_stone;
						vm->m_data[i] = n_stone;
				} else if (y <= water_level) {
					vm->m_data[i] = n_water_source;
				} else {
					vm->m_data[i] = n_air;
				}
				vm->m_area.add_y(em, i, 1);
			}
		}
	}
#endif


#if 0
// mandelbulber, unfinished but works
	sFractal par;
	par.doubles.N = 10;

	par.doubles.power = 9.0;
	par.doubles.foldingSphericalFixed =  1.0;
	par.doubles.foldingSphericalMin = 0.5;
	//no par.formula = smoothMandelbox; par.doubles.N = 40; invert = 0;//no
	par.mandelbox.doubles.sharpness = 3.0;
	par.mandelbox.doubles.scale = 1;
	par.mandelbox.doubles.sharpness = 2;
	par.mandelbox.doubles.foldingLimit = 1.0;
	par.mandelbox.doubles.foldingValue = 2;

//ok	par.formula = mandelboxVaryScale4D; par.doubles.N = 50; scale = 5; invert = 1; //ok
	par.mandelbox.doubles.vary4D.scaleVary =  0.1;
	par.mandelbox.doubles.vary4D.fold = 1;
	par.mandelbox.doubles.vary4D.rPower = 1;
	par.mandelbox.doubles.vary4D.minR = 0.5;
	par.mandelbox.doubles.vary4D.wadd = 0;
	par.doubles.constantFactor = 1.0;