Electrostat-Lab / jme-alloc

A direct dynamic memory allocation API for jMonkeyEngine lwjgl-2 and android games
https://hub.jmonkeyengine.org/t/jme-alloc-project/46356
BSD 3-Clause "New" or "Revised" License
6 stars 1 forks source link

[NativeBinaryLoader] Allow loading natives via JME NativeLibraryLoader #48

Closed Ali-RS closed 1 year ago

Ali-RS commented 1 year ago

It would be nice to add an option to be able to extract and load natives via JME NativeLibraryLoader. By default, JME (in the master branch) will export to System.getProperty("java.io.tmpdir") instead of extracting to the working directory (user.dir) if no custom extraction folder is specified.

pavly-gerges commented 1 year ago

This could be managed by creating a static Boolean flag NativeBinaryLoader.isAutoLoad() and it's setter method.

Notice, the flag should be true by default; because disabling the extraction process by default will break the test CI/CD workflow, so you will have to set this manually when implementing in jMonkeyEngine, before calling the NativeBufferAllocator.<cinit> (the static initializer).

If you agree on these modifications, please let me know, so I could prepare my schedule to solve this issue.

pavly-gerges commented 1 year ago

If you also cannot think of a good place to make a call for NativeBinaryLoadr.setAutoLoad(false), please let me know, too.

Ali-RS commented 1 year ago

What about using a system property? for example System.getProperty("com.jme3.alloc.librarypath")

NativeBinaryLoader can first check if the librarypath property is set and load it from there otherwise extract it automatically.

Edit:

Never mind, I think using NativeBinaryLoadr.setAutoLoad(false) is fine.

If you also cannot think of a good place to make a call for NativeBinaryLoadr.setAutoLoad(false), please let me know, too.

I think it should be in the class implementing JME BufferAllocator interface. (i.e. LwjglBufferAllocator).

    public class LwjglBufferAllocator implements BufferAllocator {

        static {
              NativeBinaryLoadr.setAutoLoad(false);
              NativeLibraryLoader.load(JmeAlloc);
        }

        @Override
        public void destroyDirectBuffer(Buffer toBeDestroyed) {
            NativeBufferAllocator.releaseDirectByteBuffer(toBeDestroyed);
        }

        @Override
        public ByteBuffer allocate(int size) {
            return NativeBufferAllocator.createDirectByteBuffer(size);
        }
    }
pavly-gerges commented 1 year ago

@Ali-RS Feel free to review PR #50.