Skip to content

Commit

Permalink
Improvements caught by analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
PanJohnny committed Aug 26, 2024
1 parent fa7464d commit f13ffdc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/main/java/com/panjohnny/pjgl/adapt/lwjgl/GLFWWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.panjohnny.pjgl.core.adapters.MouseAdapter;
import com.panjohnny.pjgl.core.adapters.WindowAdapter;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWKeyCallback;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
import org.lwjgl.system.MemoryStack;
Expand Down Expand Up @@ -75,7 +76,9 @@ public void init(PJGLCore core) {
throw new RuntimeException("Failed to create the GLFW window");

// Setup a key callback. It will be called every time a key is pressed, repeated or released.
glfwSetKeyCallback(WINDOW.get(), keyboard);
try ( GLFWKeyCallback keyCallback = GLFWKeyCallback.create(keyboard) ) {
glfwSetKeyCallback(WINDOW.get(), keyCallback);
}

// Get the thread stack and push a new frame
try ( MemoryStack stack = stackPush() ) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/panjohnny/pjgl/api/asset/Animation.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ public static Animation loadFromJson(String file, BiConsumer<String, String> spr
// Run checks.
check(json.has("id"), "mandatory argument not provided");
check(json.has("frames"), "mandatory argument not provided");
check(json.get("frames").getAsJsonArray().size() > 0, "there must be minimally one frame of animation");
check(!json.get("frames").getAsJsonArray().isEmpty(), "there must be minimally one frame of animation");
check(json.has("order"), "mandatory argument not provided");
check(json.get("order").getAsJsonArray().size() > 0);
check(!json.get("order").getAsJsonArray().isEmpty());

String folder = new File(file).getParent() + "/"; // folder needs to end with / when merging strings later on
String id = json.get("id").getAsString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public int getHeight() {
return height;
}

@SuppressWarnings("unused")
public AtlasRegion defineRegion(float offsetX, float offsetY, float width, float height) {
if (!this.of(Integer.class))
throw new UnsupportedOperationException("You can't turn this sprite into partition, it does not have the type of Integer");
Expand Down
6 changes: 0 additions & 6 deletions src/test/java/com/panjohnny/test/GLFWExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@
import com.panjohnny.pjgl.adapt.lwjgl.LWJGLInitializer;
import com.panjohnny.pjgl.api.PJGL;
import com.panjohnny.pjgl.api.PJGLEvents;
import com.panjohnny.pjgl.api.asset.Animation;
import com.panjohnny.pjgl.api.asset.atlas.AtlasRegion;
import com.panjohnny.pjgl.api.asset.SpriteRegistry;
import com.panjohnny.pjgl.api.asset.atlas.TextureAtlas;
import com.panjohnny.pjgl.api.object.GameObject;
import com.panjohnny.pjgl.api.object.components.Animator;
import com.panjohnny.pjgl.api.object.components.Position;
import com.panjohnny.pjgl.api.object.components.Size;
import com.panjohnny.pjgl.api.object.components.SpriteRenderer;
import com.panjohnny.pjgl.core.EngineOptions;
import org.lwjgl.glfw.GLFW;

import java.io.FileNotFoundException;

@SuppressWarnings("unused")
public class GLFWExample {
public static void main(String[] args) {
Expand Down

0 comments on commit f13ffdc

Please sign in to comment.