diff --git a/src/Common/com/bioxx/tfc/Core/TFC_Climate.java b/src/Common/com/bioxx/tfc/Core/TFC_Climate.java index f317b9a20..7c7f91f3a 100644 --- a/src/Common/com/bioxx/tfc/Core/TFC_Climate.java +++ b/src/Common/com/bioxx/tfc/Core/TFC_Climate.java @@ -21,109 +21,136 @@ public class TFC_Climate private static final float[] Y_FACTOR_CACHE = new float[441]; private static final float[] Z_FACTOR_CACHE = new float[30001]; private static final float[][] MONTH_TEMP_CACHE = new float[12][30001]; + + //the instance is used to resolve the static function calls. + private static TFC_Climate instance; //private static int[][] insolationMap; + //it is not possible to create an instance ecept for the class itself + protected TFC_Climate() + { + + } + //this method handles all calls for the instance + public static TFC_Climate getInstance() + { + if(instance == null){ + instance = new TFC_Climate(); + } + return instance; + } + + //this allows extending classes to replace the standard instance with its own + protected static void setInstance(TFC_Climate climate){ + instance = climate; + } + /** * All Temperature related code */ + //static functions call a private function via the instance public static void initCache() { + getInstance()._initCache(); + } + //the private functions contain the original code + protected void _initCache(){ //internationally accepted average lapse time is 6.49 K / 1000 m, for the first 11 km of the atmosphere. I suggest graphing our temperature - //across the 110 m against 2750 m, so that gives us a change of 1.6225 / 10 blocks, which isn't /terrible/ - //Now going to attemp exonential growth. calculations but change in temperature at 17.8475 for our system, so that should be the drop at 255. - //therefore, change should be temp - f(x), where f(x) is an exp function roughly equal to f(x) = (x^2)/ 677.966. - //This seems to work nicely. I like this. Since creative allows players to travel above 255, I'll see if I can't code in the rest of it. - //The upper troposhere has no lapse rate, so we'll just use that. - //The equation looks rather complicated, but you can see it here: - // http://www.wolframalpha.com/input/?i=%28%28%28x%5E2+%2F+677.966%29+*+%280.5%29*%28%28%28110+-+x%29+%2B+%7C110+-+x%7C%29%2F%28110+- - // +x%29%29%29+%2B+%28%280.5%29*%28%28%28x+-+110%29+%2B+%7Cx+-+110%7C%29%2F%28x+-+110%29%29+*+x+*+0.16225%29%29+0+to+440 - - for (int y = 0; y < Y_FACTOR_CACHE.length; y += 1) { - // temp = temp - (ySq / 677.966f) * (((110.01f - y) + Math.abs(110.01f - y)) / (2 * (110.01f - y))); - // temp -= (0.16225 * y * (((y - 110.01f) + Math.abs(y - 110.01f)) / (2 * (y - 110.01f)))); - - // float ySq = y * y; - // float diff = 110.01f - y; - // float factor = (ySq / 677.966f) * ((diff + Math.abs(diff)) / (2 * diff)) - // + 0.16225f * y * ((diff - Math.abs(diff)) / (2 * diff)); - - //more optimization: using an if should be more efficient (and simpler) - float factor; - if (y < 110) { - // diff > 0 - factor = y * y / 677.966f; // 17.85 for y=110 - } else { - // diff <= 0 - factor = 0.16225f * y; // 17.85 for y=110 - } - Y_FACTOR_CACHE[y] = factor; - } - - for(int zCoord = 0; zCoord < getMaxZPos() + 1; ++zCoord) - { - float factor = 0; - float z = zCoord; - - factor = (getMaxZPos()-z)/(getMaxZPos()); - - Z_FACTOR_CACHE[zCoord] = factor; - - for(int month = 0; month < 12; ++month) - { - final float MAXTEMP = 35F; - - double angle = factor * (Math.PI / 2); - double latitudeFactor = Math.cos(angle); - - switch(month) - { - case 10: - { - MONTH_TEMP_CACHE[month][zCoord] = (float)(MAXTEMP-13.5*latitudeFactor - (latitudeFactor*55)); - break; + //across the 110 m against 2750 m, so that gives us a change of 1.6225 / 10 blocks, which isn't /terrible/ + //Now going to attemp exonential growth. calculations but change in temperature at 17.8475 for our system, so that should be the drop at 255. + //therefore, change should be temp - f(x), where f(x) is an exp function roughly equal to f(x) = (x^2)/ 677.966. + //This seems to work nicely. I like this. Since creative allows players to travel above 255, I'll see if I can't code in the rest of it. + //The upper troposhere has no lapse rate, so we'll just use that. + //The equation looks rather complicated, but you can see it here: + // http://www.wolframalpha.com/input/?i=%28%28%28x%5E2+%2F+677.966%29+*+%280.5%29*%28%28%28110+-+x%29+%2B+%7C110+-+x%7C%29%2F%28110+- + // +x%29%29%29+%2B+%28%280.5%29*%28%28%28x+-+110%29+%2B+%7Cx+-+110%7C%29%2F%28x+-+110%29%29+*+x+*+0.16225%29%29+0+to+440 + + for (int y = 0; y < Y_FACTOR_CACHE.length; y += 1) { + // temp = temp - (ySq / 677.966f) * (((110.01f - y) + Math.abs(110.01f - y)) / (2 * (110.01f - y))); + // temp -= (0.16225 * y * (((y - 110.01f) + Math.abs(y - 110.01f)) / (2 * (y - 110.01f)))); + + // float ySq = y * y; + // float diff = 110.01f - y; + // float factor = (ySq / 677.966f) * ((diff + Math.abs(diff)) / (2 * diff)) + // + 0.16225f * y * ((diff - Math.abs(diff)) / (2 * diff)); + + //more optimization: using an if should be more efficient (and simpler) + float factor; + if (y < 110) { + // diff > 0 + factor = y * y / 677.966f; // 17.85 for y=110 + } else { + // diff <= 0 + factor = 0.16225f * y; // 17.85 for y=110 + } + Y_FACTOR_CACHE[y] = factor; } - case 9: - case 11: - { - MONTH_TEMP_CACHE[month][zCoord] = (float)(MAXTEMP -12.5*latitudeFactor- (latitudeFactor*53)); - break; - } - case 0: - case 8: - { - MONTH_TEMP_CACHE[month][zCoord] = (float)(MAXTEMP -10*latitudeFactor- (latitudeFactor*46)); - break; - } - case 1: - case 7: - { - MONTH_TEMP_CACHE[month][zCoord] = (float)(MAXTEMP -7.5*latitudeFactor- (latitudeFactor*40)); - break; - } - case 2: - case 6: - { - MONTH_TEMP_CACHE[month][zCoord] = (float)(MAXTEMP - 5*latitudeFactor- (latitudeFactor*33)); - break; - } - case 3: - case 5: - { - MONTH_TEMP_CACHE[month][zCoord] = (float)(MAXTEMP -2.5*latitudeFactor- (latitudeFactor*27)); - break; - } - case 4: + + for(int zCoord = 0; zCoord < getMaxZPos() + 1; ++zCoord) { - MONTH_TEMP_CACHE[month][zCoord] = (float)(MAXTEMP -1.5*latitudeFactor- (latitudeFactor*27)); - break; + float factor = 0; + float z = zCoord; + + factor = (getMaxZPos()-z)/(getMaxZPos()); + + Z_FACTOR_CACHE[zCoord] = factor; + + for(int month = 0; month < 12; ++month) + { + final float MAXTEMP = 35F; + + double angle = factor * (Math.PI / 2); + double latitudeFactor = Math.cos(angle); + + switch(month) + { + case 10: + { + MONTH_TEMP_CACHE[month][zCoord] = (float)(MAXTEMP-13.5*latitudeFactor - (latitudeFactor*55)); + break; + } + case 9: + case 11: + { + MONTH_TEMP_CACHE[month][zCoord] = (float)(MAXTEMP -12.5*latitudeFactor- (latitudeFactor*53)); + break; + } + case 0: + case 8: + { + MONTH_TEMP_CACHE[month][zCoord] = (float)(MAXTEMP -10*latitudeFactor- (latitudeFactor*46)); + break; + } + case 1: + case 7: + { + MONTH_TEMP_CACHE[month][zCoord] = (float)(MAXTEMP -7.5*latitudeFactor- (latitudeFactor*40)); + break; + } + case 2: + case 6: + { + MONTH_TEMP_CACHE[month][zCoord] = (float)(MAXTEMP - 5*latitudeFactor- (latitudeFactor*33)); + break; + } + case 3: + case 5: + { + MONTH_TEMP_CACHE[month][zCoord] = (float)(MAXTEMP -2.5*latitudeFactor- (latitudeFactor*27)); + break; + } + case 4: + { + MONTH_TEMP_CACHE[month][zCoord] = (float)(MAXTEMP -1.5*latitudeFactor- (latitudeFactor*27)); + break; + } + } + } } - } - } - } } - + protected static float getZFactor(int zCoord) { if(zCoord < 0) @@ -217,6 +244,10 @@ protected static float getTempSpecificDay(World world,int day, int x, int z) } public static float getHeightAdjustedTemp(World world, int x, int y, int z) + { + return getInstance()._getHeightAdjustedTemp(world, x, y, z); + } + protected float _getHeightAdjustedTemp(World world, int x, int y, int z) { float temp = getTemp(world, x, z); temp += getTemp(world, x+1, z); @@ -249,6 +280,10 @@ public static float getHeightAdjustedTemp(World world, int x, int y, int z) } public static float adjustHeightToTemp(int y, float temp) + { + return getInstance()._adjustHeightToTemp(y, temp); + } + protected float _adjustHeightToTemp(int y, float temp) { //internationally accepted average lapse time is 6.49 K / 1000 m, for the first 11 km of the atmosphere. I suggest graphing our temperature //across the 110 m against 2750 m, so that gives us a change of 1.6225 / 10 blocks, which isn't /terrible/ @@ -271,6 +306,10 @@ public static float adjustHeightToTemp(int y, float temp) } public static float getHeightAdjustedTempSpecificDay(World world,int day, int x, int y, int z) + { + return getInstance()._getHeightAdjustedTempSpecificDay(world, day, x, y, z); + } + protected float _getHeightAdjustedTempSpecificDay(World world,int day, int x, int y, int z) { float temp = getTempSpecificDay(world, day, x, z); temp = adjustHeightToTemp(y,temp); @@ -278,6 +317,10 @@ public static float getHeightAdjustedTempSpecificDay(World world,int day, int x, } public static float getHeightAdjustedTempSpecificDay(World world,int day, int hour, int x, int y, int z) + { + return getInstance()._getHeightAdjustedTempSpecificDay(world, day, hour, x, y, z); + } + protected float _getHeightAdjustedTempSpecificDay(World world,int day, int hour, int x, int y, int z) { float temp = getTemp(world, day, hour, x, z); temp = adjustHeightToTemp(y,temp); @@ -285,6 +328,10 @@ public static float getHeightAdjustedTempSpecificDay(World world,int day, int ho } public static float getHeightAdjustedBioTemp(World world,int day, int x, int y, int z) + { + return getInstance()._getHeightAdjustedBioTemp(world, day, x, y, z); + } + protected float _getHeightAdjustedBioTemp(World world,int day, int x, int y, int z) { float temp = getBioTemp(world, day, x, z); temp = adjustHeightToTemp(y,temp); @@ -292,11 +339,19 @@ public static float getHeightAdjustedBioTemp(World world,int day, int x, int y, } public static float getMaxTemperature() + { + return getInstance()._getMaxTemperature(); + } + protected float _getMaxTemperature() { return 52; } public static float getBioTemperatureHeight(World world,int x, int y, int z) + { + return getInstance()._getBioTemperatureHeight(world, x, y, z); + } + protected float _getBioTemperatureHeight(World world,int x, int y, int z) { float temp = 0; for(int i = 0; i < 12; i++) @@ -310,6 +365,10 @@ public static float getBioTemperatureHeight(World world,int x, int y, int z) } public static float getBioTemperature(World world,int x, int z) + { + return getInstance()._getBioTemperature(world, x, z); + } + protected float _getBioTemperature(World world,int x, int z) { float temp = 0; for(int i = 0; i < 24; i++) @@ -327,6 +386,10 @@ public static float getBioTemperature(World world,int x, int z) * Provides the basic grass color based on the biome temperature and rainfall */ public static int getGrassColor(World world, int x, int y, int z) + { + return getInstance()._getGrassColor(world, x, y, z); + } + protected int _getGrassColor(World world, int x, int y, int z) { float temp = (getTemp(world, x, z) + getMaxTemperature()) / (getMaxTemperature() * 2); @@ -343,6 +406,10 @@ public static int getGrassColor(World world, int x, int y, int z) * Provides the basic foliage color based on the biome temperature and rainfall */ public static int getFoliageColor(World world, int x, int y, int z) + { + return getInstance()._getFoliageColor(world, x, y, z); + } + protected int _getFoliageColor(World world, int x, int y, int z) { float temperature = getHeightAdjustedTempSpecificDay(world, TFC_Time.getDayOfYear(), x, y, z); float rainfall = getRainfall(world, x, y, z); @@ -366,6 +433,10 @@ public static int getFoliageColor(World world, int x, int y, int z) * Provides the basic foliage color based on the biome temperature and rainfall */ public static int getFoliageColorEvergreen(World world, int x, int y, int z) + { + return getInstance()._getFoliageColorEvergreen(world, x, y, z); + } + protected int _getFoliageColorEvergreen(World world, int x, int y, int z) { //int month = TFC_Time.getSeasonAdjustedMonth(z); float rainfall = getRainfall(world, x, y, z); @@ -387,8 +458,11 @@ public static int getFoliageColorEvergreen(World world, int x, int y, int z) /** * All Rainfall related code */ - public static float getRainfall(World world, int x, int y, int z) + { + return getInstance()._getRainfall(world, x, y, z); + } + protected float _getRainfall(World world, int x, int y, int z) { if (world.isRemote && TFC_Core.getCDM(world) != null) { @@ -407,21 +481,37 @@ public static float getRainfall(World world, int x, int y, int z) } public static int getTreeLayer(World world,int x, int y, int z, int index) + { + return getInstance()._getTreeLayer(world, x, y, z, index); + } + protected int _getTreeLayer(World world,int x, int y, int z, int index) { return getCacheManager(world).getTreeLayerAt(x, z, index).data1; } public static DataLayer getRockLayer(World world,int x, int y, int z, int index) + { + return getInstance()._getRockLayer(world, x, y, z, index); + } + protected DataLayer _getRockLayer(World world,int x, int y, int z, int index) { return getCacheManager(world).getRockLayerAt(x, z, index); } public static int getMaxZPos() + { + return getInstance()._getMaxZPos(); + } + protected int _getMaxZPos() { return 30000; } public static boolean isSwamp(World world, int x, int y, int z) + { + return getInstance()._isSwamp(world, x, y, z); + } + protected boolean _isSwamp(World world, int x, int y, int z) { float rain = getRainfall(world, x, y, z); float evt = getCacheManager(world).getEVTLayerAt(x, z).floatdata1; @@ -429,6 +519,10 @@ public static boolean isSwamp(World world, int x, int y, int z) } public static int getStability(World world, int x, int z) + { + return getInstance()._getStability(world, x, z); + } + protected int _getStability(World world, int x, int z) { if (getCacheManager(world) != null) return getCacheManager(world).getStabilityLayerAt(x, z).data1; @@ -437,11 +531,19 @@ public static int getStability(World world, int x, int z) } public static WorldCacheManager getCacheManager(World world) + { + return getInstance()._getCacheManager(world); + } + protected WorldCacheManager _getCacheManager(World world) { return worldPair.get(world); } public static void removeCacheManager(World world) + { + getInstance()._removeCacheManager(world);; + } + protected void _removeCacheManager(World world) { if(worldPair.containsKey(world)) worldPair.remove(world);