Skip to content

Commit

Permalink
Attempting to fix basic file IO in Flame 3D Particle Editor (libgdx#7063
Browse files Browse the repository at this point in the history
)

* Mark PauseableThread as excluded on GWT.

* Minor typo corrections.

* Fix atan2() when it should produce 0f.

Without this small change (which has essentially no performance impact that I could measure), calling atan2() with a point on the x-axis would produce a small but non-zero result, which is incorrect.

* Add atan, atan2, asin, acos for degrees.

This also includes atan2Deg360(), which in my opinion is the most useful of these because it does something differently from Math.atan2(), and can often save some effort.

* Approximations for tan() and tanDeg().

Sorry this is so long-winded, but the error isn't as straightforward to express as with sin() or cos().

* Apply formatter

* Add to MathUtilsTest.

* Apply formatter

* Stop trying to load defaults from wrong dir.

This old behavior broke Flame's effect-open dialog when any particle effect used the default billlboard or model particle. Now Flame tries to load a file given its absolute path (like before), but if it fails, it falls back to trying the default filenames as internal files.

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
tommyettinger and actions-user authored Jan 14, 2023
1 parent 413e0dd commit aca13b2
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import com.badlogic.gdx.assets.AssetLoaderParameters;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.assets.loaders.AssetLoader;
import com.badlogic.gdx.assets.loaders.FileHandleResolver;
import com.badlogic.gdx.assets.loaders.resolvers.AbsoluteFileHandleResolver;
import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
import com.badlogic.gdx.backends.lwjgl.LwjglCanvas;
Expand Down Expand Up @@ -984,7 +985,7 @@ public ParticleEffect openEffect (File file, boolean replaceCurrentWorkspace) {
}

public <T> T load (String resource, Class<T> type, AssetLoader loader, AssetLoaderParameters<T> params) {
String resolvedPath = new String(resource).replaceAll("\\\\", "/");
String resolvedPath = resource.replaceAll("\\\\", "/");
boolean exist = assetManager.isLoaded(resolvedPath, type);
T oldAsset = null;
if (exist) {
Expand All @@ -996,6 +997,18 @@ public <T> T load (String resource, Class<T> type, AssetLoader loader, AssetLoad
AssetLoader<T, AssetLoaderParameters<T>> currentLoader = assetManager.getLoader(type);
if (loader != null) assetManager.setLoader(type, loader);

assetManager.setLoader(ParticleEffect.class, new ParticleEffectLoader(new FileHandleResolver() {
@Override
public FileHandle resolve (String fileName) {
FileHandle attempt = Gdx.files.absolute(fileName);
if (attempt.exists()) return attempt;
if (DEFAULT_BILLBOARD_PARTICLE.equals(attempt.name())) return Gdx.files.internal(DEFAULT_BILLBOARD_PARTICLE);
if (DEFAULT_MODEL_PARTICLE.equals(attempt.name())) return Gdx.files.internal(DEFAULT_MODEL_PARTICLE);
if (DEFAULT_TEMPLATE_PFX.equals(attempt.name())) return Gdx.files.internal(DEFAULT_TEMPLATE_PFX);
return attempt;
}
}));

assetManager.load(resolvedPath, type, params);
assetManager.finishLoading();
T res = assetManager.get(resolvedPath);
Expand Down

0 comments on commit aca13b2

Please sign in to comment.