2024-09-16 00:20:03 +02:00
|
|
|
package mp.code;
|
|
|
|
|
2024-09-17 02:40:03 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2024-09-16 00:20:03 +02:00
|
|
|
public class Extensions {
|
2024-09-17 02:40:03 +02:00
|
|
|
private static boolean loaded = false;
|
|
|
|
static synchronized void loadLibraryIfNotPresent() {
|
|
|
|
if(loaded) return;
|
|
|
|
try {
|
|
|
|
String filename = System.getProperty("os.name").startsWith("Windows")
|
|
|
|
? "/natives/codemp.dll"
|
|
|
|
: "/natives/libcodemp.so";
|
|
|
|
cz.adamh.utils.NativeUtils.loadLibraryFromJar(filename);
|
|
|
|
loaded = true;
|
|
|
|
} catch(IOException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-16 00:20:03 +02:00
|
|
|
/**
|
|
|
|
* Hashes the given {@link String} using CodeMP's hashing algorithm (xxh3).
|
|
|
|
* @param input the string to hash
|
|
|
|
* @return the hash
|
|
|
|
*/
|
|
|
|
public static native long hash(String input);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drive the underlying library's asynchronous event loop.
|
|
|
|
* @param block true if it should use the current thread, false if it should
|
|
|
|
* spawn a separate one
|
|
|
|
*/
|
|
|
|
public static native void drive(boolean block);
|
2024-09-17 02:40:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Configures the tracing subscriber for the native logs.
|
|
|
|
* @param path where to output this, null to use stdout
|
|
|
|
* @param debug whether to run it in debug mode
|
|
|
|
*/
|
|
|
|
public static native void setupTracing(String path, boolean debug);
|
|
|
|
|
|
|
|
static {
|
|
|
|
Extensions.loadLibraryIfNotPresent();
|
|
|
|
}
|
2024-09-16 00:20:03 +02:00
|
|
|
}
|