Skip to content

Commit

Permalink
Merge branch 'master' into fixpausewhenlostfocus
Browse files Browse the repository at this point in the history
  • Loading branch information
obigu authored Nov 14, 2024
2 parents 907f677 + 9886f3b commit 91bc131
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 76 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
# See https://github.com/actions/virtual-environments/issues/2557
sudo mv /Library/Developer/CommandLineTools/SDKs/* /tmp
sudo mv /Applications/Xcode.app /Applications/Xcode.app.bak
sudo mv /Applications/Xcode_14.3.1.app /Applications/Xcode.app
sudo mv /Applications/Xcode_15.4.0.app /Applications/Xcode.app
sudo xcode-select -switch /Applications/Xcode.app
/usr/bin/xcodebuild -version
./gradlew jniGen jnigenBuildIOS
Expand Down Expand Up @@ -74,7 +74,7 @@ jobs:
# See https://github.com/actions/virtual-environments/issues/2557
sudo mv /Library/Developer/CommandLineTools/SDKs/* /tmp
sudo mv /Applications/Xcode.app /Applications/Xcode.app.bak
sudo mv /Applications/Xcode_14.3.1.app /Applications/Xcode.app
sudo mv /Applications/Xcode_15.4.0.app /Applications/Xcode.app
sudo xcode-select -switch /Applications/Xcode.app
/usr/bin/xcodebuild -version
./gradlew jniGen jnigenBuildMacOsX64 jnigenBuildMacOsXARM64
Expand Down
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[1.13.1]
- iOS: Update to MobiVM 2.3.22
- iOS: Fixes Gdx.openURI() not working on iOS 18.1 Simulator.
- Change visibility of PolygonSpriteBatch.switchTexture() to protected
- Added XmlReader.getChildren() and XmlReader.replaceChild()
- LWJGL3: Fix pauseWhenLostFocus not working as expected
- API Addition: Added FPSLogger#setBound


[1.13.0]
- [BREAKING CHANGE] GWT: Updated to 2.11.0. `com.google.jsinterop:jsinterop-annotations:2.0.2:sources` must be added as a dependency to your html project dependencies.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,22 +526,24 @@ static long createGlfwWindow (Lwjgl3ApplicationConfiguration config, long shared
Lwjgl3Window.setSizeLimits(windowHandle, config.windowMinWidth, config.windowMinHeight, config.windowMaxWidth,
config.windowMaxHeight);
if (config.fullscreenMode == null) {
if (config.windowX == -1 && config.windowY == -1) { // i.e., center the window
int windowWidth = Math.max(config.windowWidth, config.windowMinWidth);
int windowHeight = Math.max(config.windowHeight, config.windowMinHeight);
if (config.windowMaxWidth > -1) windowWidth = Math.min(windowWidth, config.windowMaxWidth);
if (config.windowMaxHeight > -1) windowHeight = Math.min(windowHeight, config.windowMaxHeight);

long monitorHandle = GLFW.glfwGetPrimaryMonitor();
if (config.windowMaximized && config.maximizedMonitor != null) {
monitorHandle = config.maximizedMonitor.monitorHandle;
}
if (GLFW.glfwGetPlatform() != GLFW.GLFW_PLATFORM_WAYLAND) {
if (config.windowX == -1 && config.windowY == -1) { // i.e., center the window
int windowWidth = Math.max(config.windowWidth, config.windowMinWidth);
int windowHeight = Math.max(config.windowHeight, config.windowMinHeight);
if (config.windowMaxWidth > -1) windowWidth = Math.min(windowWidth, config.windowMaxWidth);
if (config.windowMaxHeight > -1) windowHeight = Math.min(windowHeight, config.windowMaxHeight);

long monitorHandle = GLFW.glfwGetPrimaryMonitor();
if (config.windowMaximized && config.maximizedMonitor != null) {
monitorHandle = config.maximizedMonitor.monitorHandle;
}

GridPoint2 newPos = Lwjgl3ApplicationConfiguration.calculateCenteredWindowPosition(
Lwjgl3ApplicationConfiguration.toLwjgl3Monitor(monitorHandle), windowWidth, windowHeight);
GLFW.glfwSetWindowPos(windowHandle, newPos.x, newPos.y);
} else {
GLFW.glfwSetWindowPos(windowHandle, config.windowX, config.windowY);
GridPoint2 newPos = Lwjgl3ApplicationConfiguration.calculateCenteredWindowPosition(
Lwjgl3ApplicationConfiguration.toLwjgl3Monitor(monitorHandle), windowWidth, windowHeight);
GLFW.glfwSetWindowPos(windowHandle, newPos.x, newPos.y);
} else {
GLFW.glfwSetWindowPos(windowHandle, config.windowX, config.windowY);
}
}

if (config.windowMaximized) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public void postRunnable (Runnable runnable) {
/** Sets the position of the window in logical coordinates. All monitors span a virtual surface together. The coordinates are
* relative to the first monitor in the virtual surface. **/
public void setPosition (int x, int y) {
if (GLFW.glfwGetPlatform() == GLFW.GLFW_PLATFORM_WAYLAND) return;
GLFW.glfwSetWindowPos(windowHandle, x, y);
}

Expand Down Expand Up @@ -328,6 +329,7 @@ static void setIcon (long windowHandle, String[] imagePaths, Files.FileType imag

static void setIcon (long windowHandle, Pixmap[] images) {
if (SharedLibraryLoader.os == Os.MacOsX) return;
if (GLFW.glfwGetPlatform() == GLFW.GLFW_PLATFORM_WAYLAND) return;

GLFWImage.Buffer buffer = GLFWImage.malloc(images.length);
Pixmap[] tmpPixmaps = new Pixmap[images.length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.badlogic.gdx.net.ServerSocketHints;
import com.badlogic.gdx.net.Socket;
import com.badlogic.gdx.net.SocketHints;
import org.robovm.apple.uikit.UIApplicationOpenURLOptions;

/** DO NOT EDIT THIS FILE - it is machine generated */
public class IOSNet implements Net {
Expand Down Expand Up @@ -59,7 +60,7 @@ public Socket newClientSocket (Protocol protocol, String host, int port, SocketH
public boolean openURI (String URI) {
NSURL url = new NSURL(URI);
if (uiApp.canOpenURL(url)) {
uiApp.openURL(url);
uiApp.openURL(url, new UIApplicationOpenURLOptions(), null);
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.badlogic.gdx.net.ServerSocketHints;
import com.badlogic.gdx.net.Socket;
import com.badlogic.gdx.net.SocketHints;
import org.robovm.apple.uikit.UIApplicationOpenURLOptions;

public class IOSNet implements Net {

Expand Down Expand Up @@ -72,7 +73,7 @@ public Socket newClientSocket (Protocol protocol, String host, int port, SocketH
public boolean openURI (String URI) {
NSURL url = new NSURL(URI);
if (uiApp.canOpenURL(url)) {
uiApp.openURL(url);
uiApp.openURL(url, new UIApplicationOpenURLOptions(), null);
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
import java.io.*;
import java.math.BigInteger;
import java.net.URLConnection;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
Expand All @@ -28,7 +32,6 @@

import com.badlogic.gdx.backends.gwt.preloader.AssetFilter.AssetType;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.StreamUtils;
import com.google.gwt.core.ext.BadPropertyValueException;
import com.google.gwt.core.ext.ConfigurationProperty;
import com.google.gwt.core.ext.Generator;
Expand All @@ -38,6 +41,8 @@
import com.google.gwt.user.rebind.ClassSourceFileComposerFactory;
import com.google.gwt.user.rebind.SourceWriter;

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

/** Copies assets from the path specified in the modules gdx.assetpath configuration property to the war/ folder and generates the
* assets.txt file. The type of a file is determined by an {@link AssetFilter}, which is either created by instantiating the class
* specified in the gdx.assetfilterclass property, or falling back to the {@link DefaultAssetFilter}.
Expand Down Expand Up @@ -90,14 +95,11 @@ public String generate (TreeLogger logger, GeneratorContext context, String type
List<String> classpathFiles = getClasspathFiles(context);
for (String classpathFile : classpathFiles) {
if (assetFilter.accept(classpathFile, false)) {
FileWrapper orig = target.child(classpathFile);
FileWrapper dest = target.child(orig.name());
try {
InputStream is = context.getClass().getClassLoader().getResourceAsStream(classpathFile);
byte[] bytes = StreamUtils.copyStreamToByteArray(is);
is.close();
FileWrapper origFile = target.child(classpathFile);
FileWrapper destFile = target.child(fileNameWithMd5(origFile, bytes));
destFile.writeBytes(bytes, false);
assets.add(new Asset(origFile.path(), destFile, assetFilter.getType(destFile.path())));
InputStream resourceStream = context.getClass().getClassLoader().getResourceAsStream(classpathFile);
copy(resourceStream, dest.path(), dest, assetFilter, assets);
} catch (IOException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -149,11 +151,9 @@ private void copyFile (FileWrapper source, String filePathOrig, FileWrapper dest
ArrayList<Asset> assets) {
if (!filter.accept(filePathOrig, false)) return;
try {
assets.add(new Asset(filePathOrig, dest, filter.getType(dest.path())));
dest.write(source.read(), false);
} catch (Exception ex) {
throw new GdxRuntimeException("Error copying source file: " + source + "\n" //
+ "To destination: " + dest, ex);
copy(source.read(), filePathOrig, dest, filter, assets);
} catch (IOException e) {
throw new GdxRuntimeException("Error copying source file: " + source + "\n" + "To destination: " + dest, e);
}
}

Expand All @@ -167,12 +167,34 @@ private void copyDirectory (FileWrapper sourceDir, FileWrapper destDir, AssetFil
FileWrapper destFile = destDir.child(srcFile.name());
copyDirectory(srcFile, destFile, filter, assets);
} else {
FileWrapper destFile = destDir.child(fileNameWithMd5(srcFile, srcFile.readBytes()));
FileWrapper destFile = destDir.child(srcFile.name());
copyFile(srcFile, destDir.child(srcFile.name()).path(), destFile, filter, assets);
}
}
}

private void copy (InputStream source, String filePathOrig, FileWrapper dest, AssetFilter filter, ArrayList<Asset> assets)
throws IOException {
try (InputStream in = source) {
try {
// Calculate an MD5 hash while we copy the file
MessageDigest digest = MessageDigest.getInstance("MD5");
DigestInputStream digestInputStream = new DigestInputStream(in, digest);
dest.write(digestInputStream, false);

// Add the hash to the file name, then move the file to the new path
FileWrapper newDest = dest.parent().child(fileNameWithHash(dest, digest));
Files.move(toPath(dest.file()), toPath(newDest.file()), REPLACE_EXISTING);
assets.add(new Asset(filePathOrig, newDest, filter.getType(dest.path())));
} catch (NoSuchAlgorithmException e) {
// Fallback to a build timestamp if we can't calculate an MD5 hash
FileWrapper newDest = dest.parent().child(fileNameWithTimestamp(dest));
newDest.write(in, false);
assets.add(new Asset(filePathOrig, newDest, filter.getType(dest.path())));
}
}
}

private AssetFilter getAssetFilter (GeneratorContext context) {
ConfigurationProperty assetFilterClassProperty;
try {
Expand Down Expand Up @@ -275,23 +297,27 @@ private String createDummyClass (TreeLogger logger, GeneratorContext context) {
return packageName + "." + className;
}

private static String fileNameWithMd5 (FileWrapper fw, byte[] bytes) {
String md5;
try {
MessageDigest digest = MessageDigest.getInstance("MD5");
digest.update(bytes);
md5 = String.format("%032x", new BigInteger(1, digest.digest()));
} catch (NoSuchAlgorithmException e) {
// Fallback
md5 = String.valueOf(System.currentTimeMillis());
private static String fileNameWithHash (FileWrapper fw, MessageDigest digest) {
String hash = String.format("%032x", new BigInteger(1, digest.digest()));
String nameWithHash = fw.nameWithoutExtension() + "-" + hash;
String extension = fw.extension();
if (!extension.isEmpty() || fw.name().endsWith(".")) {
nameWithHash = nameWithHash + "." + extension;
}
return nameWithHash;
}

String nameWithMd5 = fw.nameWithoutExtension() + "-" + md5;
private static String fileNameWithTimestamp (FileWrapper fw) {
String timestamp = String.valueOf(System.currentTimeMillis());
String nameWithTimestamp = fw.nameWithoutExtension() + "-" + timestamp;
String extension = fw.extension();
if (!extension.isEmpty() || fw.name().endsWith(".")) {
nameWithMd5 = nameWithMd5 + "." + extension;
nameWithTimestamp = nameWithTimestamp + "." + extension;
}
return nameWithMd5;
return nameWithTimestamp;
}

private static Path toPath (File file) {
return FileSystems.getDefault().getPath(file.getPath());
}
}
2 changes: 1 addition & 1 deletion gdx/src/com/badlogic/gdx/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @author mzechner */
public class Version {
/** The current version of libGDX as a String in the major.minor.revision format **/
public static final String VERSION = "1.13.1";
public static final String VERSION = "1.13.1".toString();

/** The current major version of libGDX **/
public static final int MAJOR;
Expand Down
5 changes: 5 additions & 0 deletions gdx/src/com/badlogic/gdx/graphics/FPSLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public FPSLogger (int bound) {
startTime = TimeUtils.nanoTime();
}

public void setBound (int bound) {
this.bound = bound;
startTime = TimeUtils.nanoTime();
}

/** Logs the current frames per second to the console. */
public void log () {
final long nanoTime = TimeUtils.nanoTime();
Expand Down
4 changes: 4 additions & 0 deletions gdx/src/com/badlogic/gdx/graphics/Mesh.java
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,10 @@ public int getVertexSize () {
return vertices.getAttributes().vertexSize;
}

public IndexData getIndexData () {
return indices;
}

/** Sets whether to bind the underlying {@link VertexArray} or {@link VertexBufferObject} automatically on a call to one of the
* render methods. Usually you want to use autobind. Manual binding is an expert functionality. There is a driver bug on the
* MSM720xa chips that will fuck up memory if you manipulate the vertices and indices of a Mesh multiple times while it is
Expand Down
31 changes: 24 additions & 7 deletions gdx/src/com/badlogic/gdx/graphics/g2d/SpriteBatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@
public class SpriteBatch implements Batch {
/** @deprecated Do not use, this field is for testing only and is likely to be removed. Sets the {@link VertexDataType} to be
* used when gles 3 is not available, defaults to {@link VertexDataType#VertexArray}. */
@Deprecated public static VertexDataType defaultVertexDataType = VertexDataType.VertexArray;
@Deprecated public static VertexDataType defaultVertexDataType = VertexDataType.VertexBufferObject;

/** Used to completely override the vertex type used by SpriteBatch. This is useful for picking a specific vertex data type on
* construction of the sprite batch. Recommended to reset this back to defaultVertexDataType Once the batch has been created
* with this flag */
@Deprecated public static VertexDataType overrideVertexType = null;

private VertexDataType currentDataType;

private Mesh mesh;

Expand Down Expand Up @@ -101,7 +108,13 @@ public SpriteBatch (int size, ShaderProgram defaultShader) {

VertexDataType vertexDataType = (Gdx.gl30 != null) ? VertexDataType.VertexBufferObjectWithVAO : defaultVertexDataType;

mesh = new Mesh(vertexDataType, false, size * 4, size * 6,
if (overrideVertexType != null) {
vertexDataType = overrideVertexType;
}

currentDataType = vertexDataType;

mesh = new Mesh(currentDataType, false, size * 4, size * 6,
new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE),
new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE),
new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
Expand Down Expand Up @@ -131,8 +144,8 @@ public SpriteBatch (int size, ShaderProgram defaultShader) {

// Pre bind the mesh to force the upload of indices data.
if (vertexDataType != VertexDataType.VertexArray) {
mesh.bind(shader);
mesh.unbind(shader);
mesh.getIndexData().bind();
mesh.getIndexData().unbind();
}
}

Expand Down Expand Up @@ -962,9 +975,13 @@ public void flush () {
lastTexture.bind();
Mesh mesh = this.mesh;
mesh.setVertices(vertices, 0, idx);
Buffer indicesBuffer = (Buffer)mesh.getIndicesBuffer(false);
indicesBuffer.position(0);
indicesBuffer.limit(count);

// Only upload indices for the vertex array type
if (currentDataType == VertexDataType.VertexArray) {
Buffer indicesBuffer = (Buffer)mesh.getIndicesBuffer(true);
indicesBuffer.position(0);
indicesBuffer.limit(count);
}

if (blendingDisabled) {
Gdx.gl.glDisable(GL20.GL_BLEND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import com.badlogic.gdx.tests.SortedSpriteTest;
import com.badlogic.gdx.tests.SoundTest;
import com.badlogic.gdx.tests.SpriteBatchShaderTest;
import com.badlogic.gdx.tests.SpriteBatchPerformanceTest;
import com.badlogic.gdx.tests.SpriteCacheOffsetTest;
import com.badlogic.gdx.tests.SpriteCacheTest;
import com.badlogic.gdx.tests.StageTest;
Expand Down Expand Up @@ -517,6 +518,11 @@ public GdxTest instance () {
return new SpriteBatchShaderTest();
}
});
tests.add(new GwtInstancer() {
public GdxTest instance () {
return new SpriteBatchPerformanceTest();
}
});
tests.add(new GwtInstancer() {
public GdxTest instance () {
return new SpriteCacheOffsetTest();
Expand Down
1 change: 1 addition & 0 deletions tests/gdx-tests-lwjgl3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ tasks.register('dist', Jar) {
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
with jar
}
Loading

0 comments on commit 91bc131

Please sign in to comment.