Skip to content

Commit

Permalink
Adjust available build parameters: TEST_LEVEL and DEBUG_LEVEL
Browse files Browse the repository at this point in the history
Not yet too much in use, though.
  • Loading branch information
asofold committed Feb 28, 2013
1 parent 50ebbb0 commit 31faf7f
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 21 deletions.
8 changes: 6 additions & 2 deletions NCPBuildBase/pom.xml
Expand Up @@ -57,8 +57,12 @@ Version updating is done for NCPPlugin mainly, expect the other poms version to
<value>!!! THIS FILE IS AUTO GENERATED, ANY MANUAL CHANGES TO IT WILL GET LOST !!!</value>
</replacement>
<replacement>
<token>@EXTENSIVE_TESTING@</token>
<value>${EXTENSIVE_TESTING}</value>
<token>@TEST_LEVEL@</token>
<value>${TEST_LEVEL}</value>
</replacement>
<replacement>
<token>@DEBUG_LEVEL@</token>
<value>${DEBUG_LEVEL}</value>
</replacement>
</replacements>
</configuration>
Expand Down
Expand Up @@ -43,11 +43,20 @@ public static Boolean getBoolean(String path, Boolean preset){
else return ResourceUtil.getBoolean(input, preset);
}

public static Integer getInteger(String path, Integer preset){
String input = fileContents.get(path);
if (input == null) return preset;
else return ResourceUtil.getInteger(input, preset);
}

//////////////////////
// Public members.
//////////////////////

/** Extend testing amount. */
public static final boolean extensiveTesting = getBoolean("EXTENSIVE_TESTING", false);
/** Test level: more testing for higher levels. */
public static final int testLevel = getInteger("TEST_LEVEL", 0);

/** Debug level: more debug output for higher levels. */
public static final int debugLevel = getInteger("DEBUG_LEVEL", 0);

}
Expand Up @@ -10,14 +10,6 @@

public class ResourceUtil {

public static Boolean getBoolean(String input, Boolean preset){
if (input == null) return preset;
input = input.trim().toLowerCase();
if (input.matches("1|true|yes")) return true;
else if (input.matches("0|false|no")) return false;
else return preset;
}

/**
* Might have a newline at the end.<br>
* TODO: Move to other utility.
Expand Down Expand Up @@ -84,4 +76,23 @@ public static void parseToMap(String input, Map<String, String> map){
}
}
}

public static Boolean getBoolean(String input, Boolean preset){
if (input == null) return preset;
input = input.trim().toLowerCase();
if (input.matches("1|true|yes")) return true;
else if (input.matches("0|false|no")) return false;
else return preset;
}


public static Integer getInteger(String input, Integer preset) {
if (input == null) return preset;
try{
return Integer.parseInt(input);
}
catch (NumberFormatException e) {
}
return preset;
}
}
3 changes: 2 additions & 1 deletion NCPBuildBase/src/main/resources/_BuildParameters.properties
@@ -1,4 +1,5 @@
# @GENERATED_NOTE@
# These parameters are filled in during building (maven), they are not strictly needed.
# Replacement mappings are defined in the pom.xml.
EXTENSIVE_TESTING=@EXTENSIVE_TESTING@
TEST_LEVEL=@TEST_LEVEL@
DEBUG_LEVEL=@DEBUG_LEVEL@
Expand Up @@ -263,7 +263,7 @@ public void testIntegrity() {

final Random random = new Random(System.nanoTime() - (System.currentTimeMillis() % 2 == 1 ? 37 : 137));

final boolean e = BuildParameters.extensiveTesting;
final boolean e = BuildParameters.testLevel > 0;

final int n = e ? 40000 : 6000; // Number of coordinates.
final int max = 800; // Coordinate maximum.
Expand Down
Expand Up @@ -8,6 +8,7 @@
import fr.neatmonster.nocheatplus.compat.MCAccess;
import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
import fr.neatmonster.nocheatplus.utilities.StringUtil;
import fr.neatmonster.nocheatplus.utilities.build.BuildParameters;

/**
* Some auxiliary specialized static-access methods.
Expand Down Expand Up @@ -37,19 +38,23 @@ public static void outputMoveDebug(final Player player, final PlayerLocation fro
builder.append(" (" + (speed != Double.NEGATIVE_INFINITY ? ("speed=" + speed) : "") + (jump != Double.NEGATIVE_INFINITY ? ("jump=" + jump) : "") + ")");
}

// // TEMP: Dump block shapes:
// addBlockBelowInfo(builder, from, "\nfrom");
// addBlockBelowInfo(builder, to, "\nto");

if (BuildParameters.debugLevel > 0){
if (from.getTypeId() != 0) addBlockInfo(builder, from, "\nfrom");
if (from.getTypeIdBelow() != 0) addBlockBelowInfo(builder, from, "\nfrom");
if (!from.isOnGround() && from.isOnGround(0.5)) builder.append(" (ground within 0.5)");
if (to.getTypeId() != 0) addBlockInfo(builder, to, "\nto");
if (to.getTypeIdBelow() != 0) addBlockBelowInfo(builder, to, "\nto");
if (!to.isOnGround() && to.isOnGround(0.5)) builder.append(" (ground within 0.5)");
}
System.out.print(builder.toString());
}

public static void addBlockBelowInfo(final StringBuilder builder, final PlayerLocation loc, final String tag) {
builder.append(tag + " below id= " + loc.getTypeIdBelow() + "data=" + loc.getData(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()) + " shape=" + Arrays.toString(loc.getBlockCache().getBounds(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ())));
builder.append(tag + " below id= " + loc.getTypeIdBelow() + " data=" + loc.getData(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ()) + " shape=" + Arrays.toString(loc.getBlockCache().getBounds(loc.getBlockX(), loc.getBlockY() - 1, loc.getBlockZ())));
}

public static void addBlockInfo(final StringBuilder builder, final PlayerLocation loc, final String tag) {
builder.append(tag + " id= " + loc.getTypeId() + "data=" + loc.getData() + " shape=" + Arrays.toString(loc.getBlockCache().getBounds(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())));
builder.append(tag + " id= " + loc.getTypeId() + " data=" + loc.getData() + " shape=" + Arrays.toString(loc.getBlockCache().getBounds(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())));
}

}
Expand Up @@ -221,7 +221,7 @@ public void testConsistency(){
checkConsistency(coords);
}

final boolean e = BuildParameters.extensiveTesting;
final boolean e = BuildParameters.testLevel > 0;

// Random tests.
for (int i = 0; i < (e ? 50000000 : 100000); i++){
Expand Down

0 comments on commit 31faf7f

Please sign in to comment.