Skip to content

Commit

Permalink
Eliminate use of temporaries in remaining model enums (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
MadMartian committed Jan 19, 2022
1 parent cfcdaeb commit a6c609b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {

group 'com.extollit.gaming'
description = "An iterative A* path-finding engine designed for blocky sandbox games having entities with differing path requirements"
version '1.8.0'
version '1.8.1'

apply plugin: 'java'
apply plugin: 'signing'
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/extollit/gaming/ai/path/model/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public enum Element {
*/
fire;

private static final Element[] VALUES = values();

public static final int MASK = 4 - 1;

public final byte mask = (byte)ordinal();
Expand All @@ -83,7 +85,7 @@ public boolean in(byte flags) {
* @return the element represented by the nibble
*/
public static Element of(byte flags) {
return Element.values()[flags & MASK];
return VALUES[flags & MASK];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ public enum Gravitation {
*/
airborne;

private static final Gravitation[] VALUES = values();

/**
* Determines the greatest gravitation restriction between this and the passed parameter. For example, if
* this is {@link #buoyant} and the parameter is {@link #grounded} then the result is <em>grounded</em>. Also,
Expand All @@ -28,6 +30,6 @@ public enum Gravitation {
* @return the more restrictive gravitation between this and the parameter
*/
public Gravitation between(Gravitation other) {
return values()[Math.min(ordinal(), other.ordinal())];
return VALUES[Math.min(ordinal(), other.ordinal())];
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/extollit/gaming/ai/path/model/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public enum Logic {
*/
doorway;

private static final Logic[] VALUES = values();

public static final int
BIT_OFFSET = 2,
MASK = 4 - 1;
Expand Down Expand Up @@ -83,7 +85,7 @@ public boolean in(byte flags) {
* @return the logic indicator represented by the nibble
*/
public static Logic of(byte flags) {
return Logic.values()[(flags & (MASK << BIT_OFFSET)) >> BIT_OFFSET];
return VALUES[(flags & (MASK << BIT_OFFSET)) >> BIT_OFFSET];
}

/**
Expand Down

0 comments on commit a6c609b

Please sign in to comment.