Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a non constant Temperature and Humidity Facet Provider #58

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import org.terasology.world.generation.Produces;
import org.terasology.world.generation.facets.SurfaceHumidityFacet;

import java.util.Random;

@Produces(SurfaceHumidityFacet.class)
public class HumidityProvider implements ConfigurableFacetProvider {
private static final int SAMPLE_RATE = 4;
Expand Down Expand Up @@ -65,7 +67,7 @@ public void process(GeneratingRegion region) {
// TODO: Setup humidity
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove TODO comments like this, since the humidity/temperature is now set up by this PR.

Rect2i processRegion = facet.getWorldRegion();
for (BaseVector2i position: processRegion.contents()) {
double hum = getRandomHumidity(position);
double hum = getRandomHumidity();
facet.setWorld(position, (float) hum);
}

Expand Down Expand Up @@ -98,8 +100,10 @@ private void reload() {
noise = new SubSampledNoise(brown, scale, SAMPLE_RATE);
}

private float getRandomHumidity(BaseVector2i pos) {
return 0.1f;
private double getRandomHumidity() {
Random random = new Random();
return 1-Math.pow(random.nextFloat(),0.04);

}

public static class Configuration implements Component {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void process(GeneratingRegion region) {
// TODO: Set temperature
Rect2i processRegion = facet.getWorldRegion();
for (BaseVector2i position: processRegion.contents()) {
double temp = getRandomTemp(position);
double temp = getRandomTemp();
facet.setWorld(position, (float) temp);
}

Expand All @@ -65,11 +65,8 @@ private float generateWeight() {
return 0;
}

private double getRandomTemp(BaseVector2i pos) {
// float sumOfWeights = 10; // TODO
// Random random = new Random();
//// float f = random.nextFloat() * sumOfWeights;
// return Math.sqrt(random.nextFloat());
return 0.6f;
private double getRandomTemp() {
Random random = new Random();
return Math.pow(random.nextFloat(),0.08);
}
}