Comments (25)
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.
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.
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.
Got a start on it: 17305cb
from joise.
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.
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.
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.
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.
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.
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.
Remaining:
Create util class to fill byte arrays + tests5325f6bFactor out static instances of noise interfaces336ee3eReplace references to the static instances of noise interfaces336ee3e- Investigate repercussions of removing the AtomicInteger in the Module class
from joise.
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.
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.
Here is a relevant article
from joise.
What libGDX does is emulate reflection with this package.
from joise.
BTW, in addition to finding a way around using the things you listed, GWT will also require adding this XML file
from joise.
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.
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.
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.
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.
BUILD SUCCESSFUL
Thank you so much!
I'm using Joise in this planet generator thing I'm working on
from joise.
Oops, I guess this should actually be marked "Resolved" before "Closed"
from joise.
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.
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.
You're absolutely right, see #13 .
from joise.
Related Issues (20)
- multithreaded? HOT 2
- Update maven central to v1.0.2 HOT 2
- Bring project in line with Gradle directory structure conventions
- Library should allow registration of custom module factories
- Update project to Java 8 HOT 5
- 1.0.4 fails to compile on GWT. HOT 1
- Method calculate() in ModuleAutoCorrect forces 2D, 3D, 4D and 6D calculations.
- ModuleFractal has unused constant defaults
- Code cleanup HOT 1
- Joise MAX_SOURCES constant value in Module.java is different than ANL MaxSources constant in implicitmodulebase.h HOT 1
- Scale and offset fields in ModuleBasisFunction are assigned, yet never used. HOT 1
- Multi-threaded? HOT 1
- ModuleBasisFunction rotation axis and angle are not written to or read from the ModuleMap HOT 1
- ModuleFractal#calcWeights(FractalType) is only called when the FractalType is set
- Ensure [1.1.0-RC3] compiles under GWT HOT 1
- Can't set seed name with ModuleFractal
- Modules registered and serialized using simple class name may produce unwanted collisions
- Cache working as intended? HOT 5
- eval6D
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from joise.