Giter Site home page Giter Site logo

GWT incompatibility about joise HOT 25 CLOSED

BenMcLean avatar BenMcLean commented on August 15, 2024
GWT incompatibility

from joise.

Comments (25)

codetaylor avatar codetaylor commented on August 15, 2024 1

So it looks like the problem is that Joise uses classes from java.lang and java.util that aren't implemented in the subset of Java that GWT supports. Is that right?

from joise.

codetaylor avatar codetaylor commented on August 15, 2024 1

Specifically GWT does not implement the classes:

  • java.util.concurrent.atomic.AtomicInteger
  • java.lang.reflect.Method
  • java.lang.ThreadLocal

... and does not provide these methods on the Class object:

  • isInstance(Object)
  • cast(Object)
  • getMethod(String, Class)

Did I miss anything?

from joise.

codetaylor avatar codetaylor commented on August 15, 2024 1

I'm not actually using reflection to increase the accessibility of the Module sub-classes, as all of the methods referenced are public anyway. It looks more like I was trying to encapsulate the act of reading mapped properties into the module in a concise fashion.

So that I could do something like this:

readScalar("high", "setHighSource", props, map);

... instead of something like this:

if (props.isModuleID("high")) {
  this.setHighSource(map.get(props.get("high")));
} else {
  this.setHighSource(props.getAsDouble("high"));
}

I will fix this tomorrow and remove all of the reflection. :)

from joise.

codetaylor avatar codetaylor commented on August 15, 2024 1

Got a start on it: 17305cb

from joise.

codetaylor avatar codetaylor commented on August 15, 2024 1

Remaining:

  • Joise.java [ERROR] Line 111: The method forName(String) is undefined for the type Class
  • Noise.java [ERROR] Line 67: No source code is available for type java.lang.ThreadLocal

from joise.

codetaylor avatar codetaylor commented on August 15, 2024 1

Fixed Joise.java [ERROR] Line 111: 973882f

I borrowed some of the work you did for this one @BenMcLean , I hope that's ok. I credited you in a comment in the file.

from joise.

codetaylor avatar codetaylor commented on August 15, 2024 1

Remaining:

  • Noise.java [ERROR] Line 67: No source code is available for type java.lang.ThreadLocal
  • Module.java [ERROR] Line 75: No source code is available for type java.util.concurrent.atomic.AtomicInteger (forgot this one earlier)

from joise.

codetaylor avatar codetaylor commented on August 15, 2024 1

Fixed Module.java [ERROR] Line 75: 7b5368c

I simply changed the AtomicInteger to an int because I can't reliably make the claim that this library is thread safe without more extensive testing. See #8 .

Moving on to the remaining:

  • Noise.java [ERROR] Line 67: No source code is available for type java.lang.ThreadLocal

from joise.

codetaylor avatar codetaylor commented on August 15, 2024 1

This last one is more involved and I've unfortunately run out of time for this today. I'm going to leave some thoughts here so I can quickly pick up again tomorrow.

The Noise class is essentially static, containing no state with the exception of the ByteBuffers used to store temporary values for hashing. The reason that the buffers were made ThreadLocal is to ensure that if the Noise class's static methods are accessed from different threads, none of the values get mixed up, concurrently accessed, etc... I did make the claim that this library is not thread safe, however in #8 I recommend building an identical module chain in each thread. If that advice was followed, then removing the ThreadLocal will remove the possibility of that solution.

It looks like the only two classes that reference the Noise class, outside of the Noise class itself, are the ModuleBasisFunction class and the ModuleCellGen class. It may be possible to redesign the Noise class to contain state (ie. buffers) and provide the aforementioned module classes each with an instance of the Noise class.

Then, if identical module chains were created in two different threads, each thread would have its own instances of the Noise (with state) object.

I also feel that the change to the AtomicInteger in the Module class warrants further investigation.

from joise.

codetaylor avatar codetaylor commented on August 15, 2024 1

You're welcome, @BenMcLean and thanks for the PR. I've got a handle on how I'm going to fix the ThreadLocal. It turns out that GWT doesn't support the ByteBuffer class either, or any of java.nio for that matter. So I'm going from the ground up on this one, starting with replacing the small subset of the ByteBuffer functionality that I was using, specifically creating the byte arrays for hashing. The upside to this is it may actually increase performance in addition to making it compile with GWT. This will take more time than I initially anticipated and I thank you for your patience. :)

Remaining:

  • Create util class to fill byte arrays + tests
  • Factor out static instances of noise interfaces
  • Replace references to the static instances of noise interfaces
  • Investigate repercussions of removing the AtomicInteger in the Module class

from joise.

codetaylor avatar codetaylor commented on August 15, 2024 1

Remaining:

  • Create util class to fill byte arrays + tests 5325f6b
  • Factor out static instances of noise interfaces 336ee3e
  • Replace references to the static instances of noise interfaces 336ee3e
  • Investigate repercussions of removing the AtomicInteger in the Module class

from joise.

codetaylor avatar codetaylor commented on August 15, 2024 1

Just one thing left now, but I don't have any more time today.

@BenMcLean I looked at several GWT friendly versions of ByteBuffer, ThreadLocal, and AtomicInteger. Instead of replacing the ByteBuffer class with an equally bloated emulation class, I decided to bypass the ByteBuffer entirely. The only reason that I was using a ByteBuffer was to convert ints, doubles and longs into byte arrays, which can be done without the use of a ByteBuffer, possibly increasing performance. The ThreadLocal and AtomicInteger replacements are designed to have all of the methods of the originals, but none of the multi-threaded functionality that I chose them for.

My goal with these changes is to eliminate usage of classes and methods not supported by GWT while not changing the existing behavior of the library. At the end of the day, my priority is that the library compiles and behaves as expected (read: as it has in the past) with Java. Unfortunately, using drop-in classes that reduce or alter functionality would compromise that priority.

As it stands now, the develop branch should compile with GWT, given that there aren't any new surprise errors. Give it a go and let me know how it works. :)

from joise.

BenMcLean avatar BenMcLean commented on August 15, 2024

I believe that is correct. In my fork, I've been working to reduce or replace references to these things in the code. But I'm starting to hit a wall when it comes to method reflection.

from joise.

BenMcLean avatar BenMcLean commented on August 15, 2024

Here is a relevant article

from joise.

BenMcLean avatar BenMcLean commented on August 15, 2024

What libGDX does is emulate reflection with this package.

from joise.

BenMcLean avatar BenMcLean commented on August 15, 2024

BTW, in addition to finding a way around using the things you listed, GWT will also require adding this XML file

from joise.

BenMcLean avatar BenMcLean commented on August 15, 2024

I'm not actually using reflection to increase the accessibility of the Module sub-classes,

OK, maybe that article wasn't so relevant after all. I thought it was saying ((Don't use reflection) to increase accessibility)) but I guess what it's really saying is (Don't (use reflection to increase accessibility))

I will fix this tomorrow and remove all of the reflection. :)

Oh wow, if you could fix this so that it works with GWT, I would appreciate that so much. :) I thought I could make the changes myself but I got a little lost working on it today.

from joise.

BenMcLean avatar BenMcLean commented on August 15, 2024

Wow! I'm excited. Thanks so much for working on this. :)

We seem to be really close to this being fixed. I hope these last two errors aren't a huge roadblock

from joise.

BenMcLean avatar BenMcLean commented on August 15, 2024

OK, thanks so much for working on this. I hope it get solved soon!

I sent in a pull request to add the XML.

from joise.

BenMcLean avatar BenMcLean commented on August 15, 2024

Maybe you could just add in classes other people have written which emulate the functionality of the missing classes. guava has AtomicInteger (not sure how thread safe it actually is) and gwt-nyartoolkit has ByteBuffer. Not sure what to do about ThreadLocal though.

There could be some way to instruct GWT to call on these classes but instruct everything else to use the standard ones. Not sure how though, since this goes into Java stuff I haven't gone that deep into.

from joise.

BenMcLean avatar BenMcLean commented on August 15, 2024

BUILD SUCCESSFUL

Thank you so much!

I'm using Joise in this planet generator thing I'm working on

from joise.

BenMcLean avatar BenMcLean commented on August 15, 2024

Oops, I guess this should actually be marked "Resolved" before "Closed"

from joise.

codetaylor avatar codetaylor commented on August 15, 2024

I'm glad it works! I think it's OK to close this - I usually close the issue when it's resolved, one way or another. :)

from joise.

BenMcLean avatar BenMcLean commented on August 15, 2024

Just a thought: in order to still allow people to extend Joise with custom modules, maybe the functions that replace the reflection could include some kind of interface for adding additional checks for the custom modules.

from joise.

codetaylor avatar codetaylor commented on August 15, 2024

You're absolutely right, see #13 .

from joise.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.