Skip to content

Commit

Permalink
Unnamed variables
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 committed Jan 5, 2024
1 parent d94e17c commit a44ecd3
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,6 @@ public static String getString(MemorySegment segment) {
return segment.reinterpret(MemoryUtil.strlen(segment)).getString(0);
}

/**
* Make sure a method handle is returned as the specified type to deal with {@code MethodHandle::invokeExact}.
*
* @param t the invoking method.
* @param <T> the return type.
*/
@SuppressWarnings("unused")
public static <T> void consume(T t) {
}

/**
* Generates a string for unknown token.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Overrun Organization
* Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -269,7 +269,7 @@ public static void free(@Nullable MemorySegment memblock) {
*/
public static MemorySegment memcpy(MemorySegment dest, MemorySegment src, long count) {
try {
RuntimeHelper.consume((MemorySegment) m_memcpy.invokeExact(dest, src, count));
final var _ = (MemorySegment) m_memcpy.invokeExact(dest, src, count);
return dest;
} catch (Throwable e) {
throw new AssertionError("should not reach here", e);
Expand All @@ -294,7 +294,7 @@ public static MemorySegment memcpy(MemorySegment dest, MemorySegment src, long c
*/
public static MemorySegment memmove(MemorySegment dest, MemorySegment src, long count) {
try {
RuntimeHelper.consume((MemorySegment) m_memmove.invokeExact(dest, src, count));
final var _ = (MemorySegment) m_memmove.invokeExact(dest, src, count);
return dest;
} catch (Throwable e) {
throw new AssertionError("should not reach here", e);
Expand All @@ -317,7 +317,7 @@ public static MemorySegment memmove(MemorySegment dest, MemorySegment src, long
*/
public static MemorySegment memset(MemorySegment dest, int c, long count) {
try {
RuntimeHelper.consume((MemorySegment) m_memset.invokeExact(dest, c, count));
final var _ = (MemorySegment) m_memset.invokeExact(dest, c, count);
return dest;
} catch (Throwable e) {
throw new AssertionError("should not reach here", e);
Expand Down
4 changes: 2 additions & 2 deletions modules/overrungl.nfd/src/main/java/overrungl/nfd/NFD.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
* new Pair<>("Image file", "png,jpg"));
* var result = NFD.openDialogN(outPath, filterItem, null);
* switch (result) {
* case ERROR -> System.err.println(STR. "Error: \{ NFD.getError() }" );
* case OKAY -> System.out.println(STR. "Success! \{ outPath[0] }" );
* case ERROR -> System.err.println(STR."Error: \{NFD.getError()}");
* case OKAY -> System.out.println(STR."Success! \{outPath[0]}");
* case CANCEL -> System.out.println("User pressed cancel.");
* }
* }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Overrun Organization
* Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -54,7 +54,7 @@ private void init() {
GLFW.windowHint(GLFW.CLIENT_API, GLFW.NO_API);
window = GLFW.createWindow(200, 100, "Holder", MemorySegment.NULL, MemorySegment.NULL);
CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window");
GLFW.setKeyCallback(window, (handle, key, scancode, action, mods) -> {
GLFW.setKeyCallback(window, (_, key, _, action, _) -> {
if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) {
GLFW.setWindowShouldClose(window, true);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Overrun Organization
* Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -82,12 +82,12 @@ private void init(Arena arena) {
throw new RuntimeException(e);
}

GLFW.setKeyCallback(window, (handle, key, scancode, action, mods) -> {
GLFW.setKeyCallback(window, (_, key, _, action, _) -> {
if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) {
GLFW.setWindowShouldClose(window, true);
}
});
GLFW.setFramebufferSizeCallback(window, (handle, width, height) ->
GLFW.setFramebufferSizeCallback(window, (_, width, height) ->
GL.viewport(0, 0, width, height));
var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor());
if (vidMode != null) {
Expand Down
34 changes: 16 additions & 18 deletions modules/samples/src/test/java/overrungl/demo/nfd/NFDTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2023 Overrun Organization
* Copyright (c) 2023-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -50,8 +50,8 @@ private static void openDialog() {
final NFDResult result = NFD.openDialogN(outPath, filterItem, null);

switch (result) {
case ERROR -> System.err.println(STR. "Error: \{ NFD.getError() }" );
case OKAY -> System.out.println(STR. "Success! \{ outPath[0] }" );
case ERROR -> System.err.println(STR."Error: \{NFD.getError()}");
case OKAY -> System.out.println(STR."Success! \{outPath[0]}");
case CANCEL -> System.out.println("User pressed cancel.");
}
}
Expand Down Expand Up @@ -81,13 +81,13 @@ private static void openDialogMultiple() {
MemorySegment outPaths = pOutPaths.get(ValueLayout.ADDRESS, 0);

switch (result) {
case ERROR -> System.err.println(STR. "Error: \{ NFD.getError() }" );
case ERROR -> System.err.println(STR."Error: \{NFD.getError()}");
case OKAY -> {
System.out.println("Success!");

for (long i = 0, numPaths = NFD.pathSetGetCount(outPaths).y(); i < numPaths; i++) {
NFD.pathSetGetPathN(outPaths, i, outPath);
System.out.println(STR. "Path \{ i }: \{ outPath[0] }" );
System.out.println(STR."Path \{i}: \{outPath[0]}");
}

// remember to free the path-set memory (since NFDResult::OKAY is returned)
Expand Down Expand Up @@ -121,14 +121,14 @@ private static void openDialogMultipleEnum() {
MemorySegment outPaths = pOutPaths.get(ValueLayout.ADDRESS, 0);

switch (result) {
case ERROR -> System.err.println(STR. "Error: \{ NFD.getError() }" );
case ERROR -> System.err.println(STR."Error: \{NFD.getError()}");
case OKAY -> {
System.out.println("Success!");

try (NFDEnumerator enumerator = NFDEnumerator.fromPathSetN(stack, outPaths).y()) {
int i = 0;
for (String path : enumerator) {
System.out.println(STR. "Path \{ i }: \{ path }" );
System.out.println(STR."Path \{i}: \{path}");
i++;
}
}
Expand All @@ -151,16 +151,14 @@ private static void pickFolder() {
// or before/after every time you want to show a file dialog.
NFD.init();

try (MemoryStack stack = MemoryStack.stackPush()) {
String[] outPath = new String[1];
String[] outPath = new String[1];

// show the dialog
final NFDResult result = NFD.pickFolderN(outPath, null);
switch (result) {
case ERROR -> System.err.println(STR. "Error: \{ NFD.getError() }" );
case OKAY -> System.out.println(STR. "Success! \{ outPath[0] }" );
case CANCEL -> System.out.println("User pressed cancel.");
}
// show the dialog
final NFDResult result = NFD.pickFolderN(outPath, null);
switch (result) {
case ERROR -> System.err.println(STR."Error: \{NFD.getError()}");
case OKAY -> System.out.println(STR."Success! \{outPath[0]}");
case CANCEL -> System.out.println("User pressed cancel.");
}

// Quit NFD
Expand All @@ -185,8 +183,8 @@ private static void saveDialog() {
// show the dialog
final NFDResult result = NFD.saveDialogN(savePath, filterItem, null, "Untitled.java");
switch (result) {
case ERROR -> System.err.println(STR. "Error: \{ NFD.getError() }" );
case OKAY -> System.out.println(STR. "Success! \{ savePath[0] }" );
case ERROR -> System.err.println(STR."Error: \{NFD.getError()}");
case OKAY -> System.out.println(STR."Success! \{savePath[0]}");
case CANCEL -> System.out.println("User pressed cancel.");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Overrun Organization
* Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -56,12 +56,12 @@ private void init() {
GLFW.windowHint(GLFW.RESIZABLE, true);
window = GLFW.createWindow(300, 300, "Hello World!", MemorySegment.NULL, MemorySegment.NULL);
CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window");
GLFW.setKeyCallback(window, (handle, key, scancode, action, mods) -> {
GLFW.setKeyCallback(window, (_, key, _, action, _) -> {
if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) {
GLFW.setWindowShouldClose(window, true);
}
});
GLFW.setFramebufferSizeCallback(window, (handle, width, height) ->
GLFW.setFramebufferSizeCallback(window, (_, width, height) ->
GL.viewport(0, 0, width, height));
var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor());
if (vidMode != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Overrun Organization
* Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -68,12 +68,12 @@ private void init() {
GLFW.windowHint(GLFW.RESIZABLE, true);
window = GLFW.createWindow(640, 480, "OpenGL 1.5", MemorySegment.NULL, MemorySegment.NULL);
CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window");
GLFW.setKeyCallback(window, (handle, key, scancode, action, mods) -> {
GLFW.setKeyCallback(window, (_, key, _, action, _) -> {
if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) {
GLFW.setWindowShouldClose(window, true);
}
});
GLFW.setFramebufferSizeCallback(window, (handle, width, height) ->
GLFW.setFramebufferSizeCallback(window, (_, width, height) ->
GL.viewport(0, 0, width, height));
var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor());
if (vidMode != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Overrun Organization
* Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -74,12 +74,12 @@ private void init() {
GLFW.windowHint(GLFW.RESIZABLE, true);
window = GLFW.createWindow(640, 480, "OpenGL 3.0", MemorySegment.NULL, MemorySegment.NULL);
CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window");
GLFW.setKeyCallback(window, (handle, key, scancode, action, mods) -> {
GLFW.setKeyCallback(window, (_, key, _, action, _) -> {
if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) {
GLFW.setWindowShouldClose(window, true);
}
});
GLFW.setFramebufferSizeCallback(window, (handle, width, height) ->
GLFW.setFramebufferSizeCallback(window, (_, width, height) ->
GL.viewport(0, 0, width, height));
var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor());
if (vidMode != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Overrun Organization
* Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -86,12 +86,12 @@ private void init() {
GLFW.windowHint(GLFW.OPENGL_PROFILE, GLFW.OPENGL_CORE_PROFILE);
window = GLFW.createWindow(640, 480, WND_TITLE, MemorySegment.NULL, MemorySegment.NULL);
CheckUtil.checkNotNullptr(window, "Failed to create the GLFW window");
GLFW.setKeyCallback(window, (handle, key, scancode, action, mods) -> {
GLFW.setKeyCallback(window, (_, key, _, action, _) -> {
if (key == GLFW.KEY_ESCAPE && action == GLFW.RELEASE) {
GLFW.setWindowShouldClose(window, true);
}
});
GLFW.setFramebufferSizeCallback(window, (handle, width, height) ->
GLFW.setFramebufferSizeCallback(window, (_, width, height) ->
GL.viewport(0, 0, width, height));
var vidMode = GLFW.getVideoMode(GLFW.getPrimaryMonitor());
if (vidMode != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2023 Overrun Organization
* Copyright (c) 2023-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,7 +18,6 @@

import overrungl.stb.STBImage;
import overrungl.stb.STBImageWrite;
import overrungl.util.MemoryStack;

import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
Expand All @@ -43,9 +42,7 @@ private static void write(Arena arena, float[][] noise, String fileName) {
buf.set(ValueLayout.JAVA_BYTE, y * HEIGHT + x, (byte) ((noise[y][x] + 1f) * .5f * 255f));
}
}
try (MemoryStack stack = MemoryStack.stackPush()) {
STBImageWrite.png(fileName, WIDTH, HEIGHT, STBImage.GREY, buf, WIDTH);
}
STBImageWrite.png(fileName, WIDTH, HEIGHT, STBImage.GREY, buf, WIDTH);
}

public static void main(String[] args) {
Expand Down
4 changes: 2 additions & 2 deletions modules/samples/src/test/java/overrungl/demo/util/IOUtil.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* MIT License
*
* Copyright (c) 2022-2023 Overrun Organization
* Copyright (c) 2022-2024 Overrun Organization
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -55,7 +55,7 @@ public static MemorySegment ioResourceToSegment(Arena arena, String resource, lo
final boolean isHttp = resource.startsWith("http");
final Path path = isHttp ? null : Path.of(resource);

// Check whether on local
// Check if the path is on local
if (path != null && Files.isReadable(path)) {
try (var fc = FileChannel.open(path)) {
return fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size(), arena);
Expand Down

0 comments on commit a44ecd3

Please sign in to comment.