Skip to content
Open
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
16 changes: 7 additions & 9 deletions Engine/src/mini/app/state/ApplicationStateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@ public boolean detach(ApplicationState state) {
states.remove(state);
terminating.add(state);
return true;
} else if (initializing.contains(state)) {
}

if (initializing.contains(state)) {
state.stateDetached(this);
initializing.remove(state);
return true;
} else {
return false;
}

return false;
}

/**
Expand Down Expand Up @@ -118,9 +120,7 @@ public void update(float tpf) {
* @param renderManager The RenderManager
*/
public void render(RenderManager renderManager) {
Arrays.stream(getStates())
.filter(ApplicationState::isEnabled)
.forEach(state -> state.render(renderManager));
Arrays.stream(getStates()).filter(ApplicationState::isEnabled).forEach(state -> state.render(renderManager));
}

/**
Expand All @@ -129,9 +129,7 @@ public void render(RenderManager renderManager) {
* @param renderManager The RenderManager
*/
public void postRender() {
Arrays.stream(getStates())
.filter(ApplicationState::isEnabled)
.forEach(ApplicationState::postRender);
Arrays.stream(getStates()).filter(ApplicationState::isEnabled).forEach(ApplicationState::postRender);
}

private void initializePending() {
Expand Down
33 changes: 15 additions & 18 deletions Engine/src/mini/asset/cache/WeakRefCloneAssetCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ public <T> void registerAssetClone(AssetKey<T> key, T clone) {
@Override
public boolean deleteFromCache(AssetKey key) {
List<AssetKey> loadStack = assetLoadStack.get();

if (!loadStack.isEmpty()) {
throw new UnsupportedOperationException(
"Cache cannot be modified while assets are being"
+ " loaded");
throw new UnsupportedOperationException("Cache cannot be modified while assets are being loaded");
}

return smartCache.remove(key) != null;
Expand All @@ -42,20 +41,18 @@ public void clearCache() {
List<AssetKey> loadStack = assetLoadStack.get();

if (!loadStack.isEmpty()) {
throw new UnsupportedOperationException("Cache cannot be modified"
+ "while assets are being loaded");
throw new UnsupportedOperationException("Cache cannot be modified while assets are being loaded");
}

smartCache.clear();
}

private final ConcurrentMap<AssetKey, AssetRef> smartCache = new ConcurrentHashMap<>();
private final ReferenceQueue<AssetKey> referenceQueue = new ReferenceQueue<>();
private final ThreadLocal<List<AssetKey>> assetLoadStack =
ThreadLocal.withInitial(ArrayList::new);
private final ThreadLocal<List<AssetKey>> assetLoadStack = ThreadLocal.withInitial(ArrayList::new);

private void removeCollectedAssets() {
for (KeyRef ref; (ref = (KeyRef) referenceQueue.poll()) != null; ) {
for (KeyRef ref; (ref = (KeyRef) referenceQueue.poll()) != null;) {
smartCache.remove(ref.clonedKey);
}
}
Expand Down Expand Up @@ -87,17 +84,17 @@ public <T> T getFromCache(AssetKey<T> key) {

if (smartInfo == null) {
return null;
} else {
AssetKey keyForTheClone = smartInfo.get();
if (keyForTheClone == null) {
// was collected by GC between here and smartCache.get
return null;
}

List<AssetKey> loadStack = assetLoadStack.get();
loadStack.add(keyForTheClone);
return (T) smartInfo.asset;
}

AssetKey keyForTheClone = smartInfo.get();
if (keyForTheClone == null) {
// Was collected by GC between here and smartCache.get
return null;
}

List<AssetKey> loadStack = assetLoadStack.get();
loadStack.add(keyForTheClone);
return (T) smartInfo.asset;
}

private static final class KeyRef extends PhantomReference<AssetKey> {
Expand Down
25 changes: 12 additions & 13 deletions Engine/src/mini/asset/plugins/UrlAssetInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ private UrlAssetInfo(AssetManager assetManager, AssetKey key, URL url, InputStre
this.in = in;
}

public static UrlAssetInfo create(AssetManager assetManager, AssetKey key, URL url) throws
IOException {
public static UrlAssetInfo create(AssetManager assetManager, AssetKey key, URL url) throws IOException {
// Check if URL can be reached. This will throw
// IOException which calling code will handle.
URLConnection conn = url.openConnection();
Expand All @@ -33,9 +32,9 @@ public static UrlAssetInfo create(AssetManager assetManager, AssetKey key, URL u
// For some reason url cannot be reached?
if (in == null) {
return null;
} else {
return new UrlAssetInfo(assetManager, key, url, in);
}

return new UrlAssetInfo(assetManager, key, url, in);
}

@Override
Expand All @@ -45,15 +44,15 @@ public InputStream openStream() {
InputStream in2 = in;
in = null;
return in2;
} else {
// Create a new stream for subsequent invocations.
try {
URLConnection conn = url.openConnection();
conn.setUseCaches(false);
return conn.getInputStream();
} catch (IOException ex) {
throw new RuntimeException("Failed to read URL " + url, ex);
}
}

// Create a new stream for subsequent invocations.
try {
URLConnection connection = url.openConnection();
connection.setUseCaches(false);
return connection.getInputStream();
} catch (IOException ex) {
throw new RuntimeException("Failed to read URL " + url, ex);
}
}

Expand Down
129 changes: 75 additions & 54 deletions Engine/src/mini/bounding/BoundingBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,13 @@ public Plane.Side whichSide(Plane plane) {

if (distance < -radius) {
return Plane.Side.Negative;
} else if (distance > radius) {
}

if (distance > radius) {
return Plane.Side.Positive;
} else {
return Plane.Side.None;
}

return Plane.Side.None;
}

@Override
Expand All @@ -200,10 +202,13 @@ public void computeFromPoints(FloatBuffer points) {

float[] tmpArray = vars.skinPositions;

float minX = Float.POSITIVE_INFINITY, minY = Float.POSITIVE_INFINITY, minZ
= Float.POSITIVE_INFINITY;
float maxX = Float.NEGATIVE_INFINITY, maxY = Float.NEGATIVE_INFINITY, maxZ
= Float.NEGATIVE_INFINITY;
float minX = Float.POSITIVE_INFINITY;
float minY = Float.POSITIVE_INFINITY;
float minZ = Float.POSITIVE_INFINITY;

float maxX = Float.NEGATIVE_INFINITY;
float maxY = Float.NEGATIVE_INFINITY;
float maxZ = Float.NEGATIVE_INFINITY;

int iterations = (int) FastMath.ceil(points.limit() / ((float) tmpArray.length));
// TODO: Parallel iterations through the array could get all 6 values. Using streaming on the array
Expand Down Expand Up @@ -292,7 +297,15 @@ public BoundingVolume mergeLocal(BoundingVolume volume) {
*/
private BoundingVolume mergeLocal(Vector3f center, float xExtent, float yExtent,
float zExtent) {
if (this.xExtent == Float.POSITIVE_INFINITY || xExtent == Float.POSITIVE_INFINITY) {
mergeLocalX(center, xExtent);
mergeLocalY(center, yExtent);
mergeLocalZ(center, zExtent);

return this;
}

private void mergeLocalX(Vector3f center, float xExtent) {
if (this.xExtent == Float.POSITIVE_INFINITY || xExtent == Float.POSITIVE_INFINITY) {
this.center.x = 0;
this.xExtent = Float.POSITIVE_INFINITY;
} else {
Expand All @@ -307,24 +320,10 @@ private BoundingVolume mergeLocal(Vector3f center, float xExtent, float yExtent,
this.center.x = (low + high) / 2;
this.xExtent = high - this.center.x;
}
}

if (this.yExtent == Float.POSITIVE_INFINITY || yExtent == Float.POSITIVE_INFINITY) {
this.center.y = 0;
this.yExtent = Float.POSITIVE_INFINITY;
} else {
float low = this.center.y - this.yExtent;
if (low > center.y - yExtent) {
low = center.y - yExtent;
}
float high = this.center.y + this.yExtent;
if (high < center.y + yExtent) {
high = center.y + yExtent;
}
this.center.y = (low + high) / 2;
this.yExtent = high - this.center.y;
}

if (this.zExtent == Float.POSITIVE_INFINITY || zExtent == Float.POSITIVE_INFINITY) {
private void mergeLocalZ(Vector3f center, float zExtent) {
if (this.zExtent == Float.POSITIVE_INFINITY || zExtent == Float.POSITIVE_INFINITY) {
this.center.z = 0;
this.zExtent = Float.POSITIVE_INFINITY;
} else {
Expand All @@ -339,9 +338,25 @@ private BoundingVolume mergeLocal(Vector3f center, float xExtent, float yExtent,
this.center.z = (low + high) / 2;
this.zExtent = high - this.center.z;
}
}

return this;
}
private void mergeLocalY(Vector3f center, float yExtent) {
if (this.yExtent == Float.POSITIVE_INFINITY || yExtent == Float.POSITIVE_INFINITY) {
this.center.y = 0;
this.yExtent = Float.POSITIVE_INFINITY;
} else {
float low = this.center.y - this.yExtent;
if (low > center.y - yExtent) {
low = center.y - yExtent;
}
float high = this.center.y + this.yExtent;
if (high < center.y + yExtent) {
high = center.y + yExtent;
}
this.center.y = (low + high) / 2;
this.yExtent = high - this.center.y;
}
}

@Override
public float distanceToEdge(Vector3f point) {
Expand Down Expand Up @@ -466,30 +481,36 @@ && clip(+direction.z, -diff.z - zExtent, t)
*/
private boolean clip(float denominator, float numerator, float t[]) {
if (denominator > 0.0f) {
float newT = numerator / denominator;
if (newT > t[1]) {
return false;
}

if (newT > t[0]) {
t[0] = newT;
}
return true;
} else if (denominator < 0.0f) {
float newT = numerator / denominator;
if (newT < t[0]) {
return false;
}
return clipPositive(denominator, numerator, t);
}
if (denominator < 0.0f) {
return clipNegative(denominator, numerator, t);
}
return numerator <= 0.0f;
}

if (newT < t[1]) {
t[1] = newT;
}
return true;
} else {
return numerator <= 0.0f;
private boolean clipPositive(float denominator, float numerator, float[] t) {
float newT = numerator / denominator;
if (newT > t[1]) {
return false;
}
if (newT > t[0]) {
t[0] = newT;
}
return true;
}

private boolean clipNegative(float denominator, float numerator, float[] t) {
float newT = numerator / denominator;
if (newT < t[0]) {
return false;
}
if (newT < t[1]) {
t[1] = newT;
}
return true;
}

/**
* Query extent
*
Expand Down Expand Up @@ -530,13 +551,13 @@ public Vector3f getMax(Vector3f store) {
*/
public BoundingVolume clone(BoundingVolume store) {
if (store != null && store.getType() == Type.AABB) {
BoundingBox rVal = (BoundingBox) store;
rVal.center.set(center);
rVal.xExtent = xExtent;
rVal.yExtent = yExtent;
rVal.zExtent = zExtent;
rVal.checkPlane = checkPlane;
return rVal;
BoundingBox clone = (BoundingBox) store;
clone.center.set(center);
clone.xExtent = xExtent;
clone.yExtent = yExtent;
clone.zExtent = zExtent;
clone.checkPlane = checkPlane;
return clone;
}

return new BoundingBox(center.clone(), xExtent, yExtent, zExtent);
Expand Down
Loading