<commit_before>package com.tepidpond.tum.PlateTectonics;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

public class Lithosphere {
	private static final float SQRDMD_ROUGHNESS = 0.5f;
	private static final float CONTINENTAL_BASE = 1.0f;
	private static final float OCEANIC_BASE =     0.1f;
	private static final float RESTART_ENERGY_RATIO = 0.15f;
	private static final float RESTART_SPEED_LIMIT = 2.0f;
	private static final int NO_COLLISION_TIME_LIMIT = 10;
	private static final int MAX_GENERATIONS = 600;
	private static final boolean REGENERATE_CRUST = true;
	private static final float BUOYANCY_BONUS = 3.0f;
	private static final int MAX_BUOYANCY_AGE = 20;
	
	private float worldMap[];  // denotes height of terrain of tiles
	private float worldPlates[];   // denotes plate ownership of tiles. Is a float because of saveHeightmap.
	private Plate plates[];
	private Stack<CollisionDetails> subductions[];
	private Stack<CollisionDetails> collisions[];
	
	private int worldSurface;
	private int worldSize;
	private int numPlates;
	private Random rand;
	
	private float peakKineticEnergy = 0.0f;
	private int generationsSinceCollision = 0;
	private int generations = 0;
	private int erosionPeriod = 1;
	private float foldingRatio = 0.5f;
	private float aggr_ratio_abs = 0.5f;
	private float aggr_ratio_rel = 0.5f;
	
	public float[] getHeightmap() { return worldMap; }
	
	public int getMapSize() { return worldSize; }
	
	// default mapSize = 512. Must be power of 2.
	public Lithosphere(int mapSize, float percentSeaTiles, int erosion_period, float folding_ratio,
			int aggr_ratio_abs, float aggr_ratio_rel, int num_cycles, int _numPlates, long seed) {


		this.aggr_ratio_abs = aggr_ratio_abs;
		this.aggr_ratio_rel = aggr_ratio_rel;
		this.foldingRatio = folding_ratio;
		this.erosionPeriod = erosion_period;
		this.worldSurface = (int) Math.pow(mapSize, 2);
		this.worldSize = mapSize;
		if (_numPlates > worldSurface)
			numPlates = worldSurface;
		else
			numPlates = _numPlates;
		this.rand = new Random();
		rand.setSeed(seed);
		
		// Setup for collision storage for update. This is complex because
		// "Cannot create generic array of ..." error otherwise.
		subductions = (Stack<CollisionDetails>[]) new Stack[numPlates];	
		collisions = (Stack<CollisionDetails>[]) new Stack[numPlates];
		for (int activePlate = 0; activePlate < numPlates; activePlate++) {
			subductions[activePlate] = new Stack<CollisionDetails>();
			collisions[activePlate] = new Stack<CollisionDetails>();
		}

		float tmpWorldMap[] = new float[(int) Math.pow(mapSize + 1, 2)];
		
		// Generate initial fractal map
		if (!SquareDiamond.SqrDmd(tmpWorldMap, mapSize + 1, 1.0f, SQRDMD_ROUGHNESS, seed)) {
			// Error unable to generate height map.
		}
		
		Util.normalizeHeightMap(tmpWorldMap);
		float seaLevel = getSeaLevel(tmpWorldMap, percentSeaTiles, 5);
		separateLandAndSea(tmpWorldMap, seaLevel);
		
		this.worldMap = new float[(int)Math.pow(mapSize, 2)];
		this.worldPlates = new float[(int)Math.pow(mapSize, 2)];
		Arrays.fill(worldPlates, numPlates);
		
		for (int i = 0; i < mapSize; i++)
			System.arraycopy(tmpWorldMap, i * (mapSize + 1), this.worldMap, i * mapSize, mapSize);
		
		PlateArea[] plates = createPlates();
		growPlates(plates);
		this.plates = extractPlates(plates);
	}
	
	public boolean Update() {
		if (checkForStaticWorld()) return false;

		//Util.saveHeightmap(indexMap, mapSize, "p" + Integer.toString(generations));
		Util.saveHeightmap(worldMap, worldSize, "t" + Integer.toString(generations));
		
		moveAndErodePlates();
		int continentalCollisions = 0;
		float prevIndexMap[] = new float[worldPlates.length];
		System.arraycopy(worldPlates, 0, prevIndexMap, 0, worldPlates.length);
		Arrays.fill(worldMap, 0);
		Arrays.fill(worldPlates, Integer.MAX_VALUE);<commit_msg>Important change to prevent initial buoyancy from taking effect on first Update() call on (presumably) old sea floor.<commit_after>package com.tepidpond.tum.PlateTectonics;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

public class Lithosphere {
	private static final float SQRDMD_ROUGHNESS = 0.5f;
	private static final float CONTINENTAL_BASE = 1.0f;
	private static final float OCEANIC_BASE =     0.1f;
	private static final float RESTART_ENERGY_RATIO = 0.15f;
	private static final float RESTART_SPEED_LIMIT = 2.0f;
	private static final int NO_COLLISION_TIME_LIMIT = 10;
	private static final int MAX_GENERATIONS = 600;
	private static final boolean REGENERATE_CRUST = true;
	private static final float BUOYANCY_BONUS = 3.0f;
	private static final int MAX_BUOYANCY_AGE = 20;
	
	private float worldMap[];  // denotes height of terrain of tiles
	private float worldPlates[];   // denotes plate ownership of tiles. Is a float because of saveHeightmap.
	private Plate plates[];
	private Stack<CollisionDetails> subductions[];
	private Stack<CollisionDetails> collisions[];
	
	private int worldSurface;
	private int worldSize;
	private int numPlates;
	private Random rand;
	
	private float peakKineticEnergy = 0.0f;
	private int generationsSinceCollision = 0;
	private int generations = 0;
	private int erosionPeriod = 1;
	private float foldingRatio = 0.5f;
	private float aggr_ratio_abs = 0.5f;
	private float aggr_ratio_rel = 0.5f;
	
	public float[] getHeightmap() { return worldMap; }
	
	public int getMapSize() { return worldSize; }
	
	// default mapSize = 512. Must be power of 2.
	public Lithosphere(int mapSize, float percentSeaTiles, int erosion_period, float folding_ratio,
			int aggr_ratio_abs, float aggr_ratio_rel, int num_cycles, int _numPlates, long seed) {


		this.aggr_ratio_abs = aggr_ratio_abs;
		this.aggr_ratio_rel = aggr_ratio_rel;
		this.foldingRatio = folding_ratio;
		this.erosionPeriod = erosion_period;
		this.worldSurface = (int) Math.pow(mapSize, 2);
		this.worldSize = mapSize;
		if (_numPlates > worldSurface)
			numPlates = worldSurface;
		else
			numPlates = _numPlates;
		this.rand = new Random();
		rand.setSeed(seed);
		
		// Setup for collision storage for update. This is complex because
		// "Cannot create generic array of ..." error otherwise.
		subductions = (Stack<CollisionDetails>[]) new Stack[numPlates];	
		collisions = (Stack<CollisionDetails>[]) new Stack[numPlates];
		for (int activePlate = 0; activePlate < numPlates; activePlate++) {
			subductions[activePlate] = new Stack<CollisionDetails>();
			collisions[activePlate] = new Stack<CollisionDetails>();
		}

		float tmpWorldMap[] = new float[(int) Math.pow(mapSize + 1, 2)];
		
		// Generate initial fractal map
		if (!SquareDiamond.SqrDmd(tmpWorldMap, mapSize + 1, 1.0f, SQRDMD_ROUGHNESS, seed)) {
			// Error unable to generate height map.
		}
		
		Util.normalizeHeightMap(tmpWorldMap);
		float seaLevel = getSeaLevel(tmpWorldMap, percentSeaTiles, 5);
		separateLandAndSea(tmpWorldMap, seaLevel);
		
		this.worldMap = new float[(int)Math.pow(mapSize, 2)];
		this.worldPlates = new float[(int)Math.pow(mapSize, 2)];
		Arrays.fill(worldPlates, numPlates);
		
		for (int i = 0; i < mapSize; i++)
			System.arraycopy(tmpWorldMap, i * (mapSize + 1), this.worldMap, i * mapSize, mapSize);
		
		PlateArea[] plates = createPlates();
		growPlates(plates);
		this.plates = extractPlates(plates);
		// Prevent any initial buoyancy from altering first heightmap.
		generations = numPlates + MAX_BUOYANCY_AGE;
		generationsSinceCollision = 0;
	}
	
	public boolean Update() {
		if (checkForStaticWorld()) return false;

		//Util.saveHeightmap(indexMap, mapSize, "p" + Integer.toString(generations));
		Util.saveHeightmap(worldMap, worldSize, "t" + Integer.toString(generations));
		
		moveAndErodePlates();
		int continentalCollisions = 0;
		float prevIndexMap[] = new float[worldPlates.length];
		System.arraycopy(worldPlates, 0, prevIndexMap, 0, worldPlates.length);
		Arrays.fill(worldMap, 0);
		Arrays.fill(worldPlates, Integer.MAX_VALUE);
{'fraction_non_alphanumeric': 0.10093011563599799, 'fraction_numerical': 0.012946204122674712, 'mean_word_length': 4.745126353790614, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1690726', 'n_tokens_mistral': 2898, 'n_tokens_neox': 2565, 'n_words': 713}