Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Jo
Jan 24, 2005

:allears:
Soiled Meat
What is the most common (and cross platform) way to deal with movie files in Java? The Java Media Framework 2.1 API says it works with AVI and a few other formats, but when it comes to things like mp4 or others, what are my options.

As an additional question, is JMF still the preferred way to deal with Media in Java, or has it been replaced/outdated?

Jo fucked around with this message at 00:17 on Jan 5, 2010

Adbot
ADBOT LOVES YOU

Jo
Jan 24, 2005

:allears:
Soiled Meat
EDIT: Nevermind. Code was fine, just forgot to tell the drawing thread to sleep so the input events weren't being serviced quickly.

Jo fucked around with this message at 01:34 on Oct 4, 2010

Jo
Jan 24, 2005

:allears:
Soiled Meat

Elos posted:

That method just loops trough an array asking the tiles to draw themselves. I don't have any real reason for drawing it constantly besides wanting to see how it's done and hell, I might want to make it a pseudo-realtime like Diablo or something.

I'm doing all the transparency and color mask stuff before the gameloop so it just draws simple 16x16 images on the screen and checks for key events. There must be something strange going on in the linux JRE.

EDIT: Is there an easy way to find out which method is hogging all the CPU?

We're working on VERY similar projects. I had the same problem and realized that the CPU consumption was perfectly fine -- just that I wasn't telling the draw thread to wait and allow the input function to run, which made everything feel very laggy.

Catch me on aim (MostlyDeadAllDay) or send me a PM. We may have a lot of overlap.

Jo
Jan 24, 2005

:allears:
Soiled Meat
A tangentially related note: I'm allocating hardware memory and have an alpha-transparent png loaded as below:

code:
	BufferedImage tempTileset = ImageIO.read( new File( tilesetFullPath ) );
	tileset = engine.gfxman.getHardwareMemoryChunk( tempTileset.getWidth(), tempTileset.getHeight() );
	tileset.getGraphics().drawImage( tempTileset, 0, 0, null );
Problem is when doing the 'drawImage' command, I lose all the alpha data. What's the best way to copy over the tempTileset, taking format conversion into account? I've tried tempData.copyData and tempData.setData, but would like to know the correct way of doing this.

EDIT: I swear to god I spend hours on these things only to solve them moments after I ask for help. I loving hate that. Problem was in getHardwareMemoryChunk, which had a wrong value for transparency. drawImage works fine.

Least it works now.

Jo fucked around with this message at 20:06 on Oct 24, 2010

Jo
Jan 24, 2005

:allears:
Soiled Meat

Internet Janitor posted:

Jo: Spiffy. Is that lighting baked into your maps, or calculated on the fly? I think your perspective is slightly off. If those walls are one square high, this shadow line should be moved down, so the shadow begins where the back of that wall would touch the ground:



It's baked. In another version of this code it is all realtime with dynamic shadows and penumbras, but that's a mess and not worth diving into again.

Jo
Jan 24, 2005

:allears:
Soiled Meat
I'm running into a problem with input. When doing this, sometimes my player entity will simply stop moving for reasons I can't explain. It didn't seem to happen with any other style of input polling. Are there any glaring logic errors here?

code:
public void keyPressed( java.awt.event.KeyEvent e ) {
		switch( e.getKeyCode() ) {
			case KeyEvent.VK_ESCAPE:
				engine.done = true;
				break;
			case KeyEvent.VK_D:
				directionQueue.push( Entity.DIRECTION_RIGHT );
				break;
			case KeyEvent.VK_W:
				directionQueue.push( Entity.DIRECTION_UP );
				break;
			case KeyEvent.VK_A:
				directionQueue.push( Entity.DIRECTION_LEFT );
				break;
			case KeyEvent.VK_S:
				directionQueue.push( Entity.DIRECTION_DOWN );
				break;
		}

		if( directionQueue.peekFirst() != previousDirection ) { // Ah!  We have a new direction.
			Player p = engine.entityman.getPlayer();
			int newDir = directionQueue.peekFirst();
			previousDirection = newDir;

			p.setOrientation( newDir );
			p.setAcceleration( p.getMaxAcceleration() );
		}
	}

	public void keyReleased( java.awt.event.KeyEvent e ) {
		switch( e.getKeyCode() ) {
			case KeyEvent.VK_D:
				directionQueue.remove( (Integer)Entity.DIRECTION_RIGHT );
				//directionQueue.remove( directionQueue.indexOf( Entity.DIRECTION_RIGHT ) );
				break;
			case KeyEvent.VK_W:
				directionQueue.remove( (Integer)Entity.DIRECTION_UP );
				break;
			case KeyEvent.VK_A:
				directionQueue.remove( (Integer)Entity.DIRECTION_LEFT );
				break;
			case KeyEvent.VK_S:
				directionQueue.remove( (Integer)Entity.DIRECTION_DOWN );
				break;
		}

		if( directionQueue.isEmpty() ) {
			Player p = engine.entityman.getPlayer();
			p.setAcceleration( 0 );
			p.setSpeed( 0 );
		} else {
			Player p = engine.entityman.getPlayer();
			int newDir = (Integer)directionQueue.peekFirst();
			previousDirection = newDir;

			p.setOrientation( newDir );
			p.setAcceleration( p.getMaxAcceleration() );
		}
	}

Jo
Jan 24, 2005

:allears:
Soiled Meat

baquerd posted:

Either max acceleration is being set to zero or the directionQueue is empty after a key release event from what you've shown here. Is this threaded? What class is directionQueue?

DirectionQueue is local to the InputMan class. Yes, this is multithreaded. I do not know where acceleration could be changing. Max acceleration is constant.

EDIT:

Whaaa? Added some more print statements:

jo@Euclid:~/source/tilegame/dist$ java -jar Tilegame.jar
KEY DOWN:S
KEY UP:S
KEY DOWN:S
KEY UP:S
...

This is from HOLDING the 's' key. Why would multiple key events be generated from a single key hold?

Jo
Jan 24, 2005

:allears:
Soiled Meat

Oh. Thanks!

EDIT: Turns out there's a better way to do this. KeyBindings is the Swing equivalent of KeyListener.

Jo fucked around with this message at 01:02 on Nov 14, 2010

Jo
Jan 24, 2005

:allears:
Soiled Meat
As a start, I'd like to apologize for spamming requests to help to this thread without really contributing. Thank you to all those who have provided feedback to my inane problems.

The most recent issue, a change from the AWT method of input to the Swing method of input, has left me daft. The following code does not work for reasons I can't explain.

code:
		JPanel content = (JPanel)engine.gfxman.getContentPane();
		InputMap map = content.getInputMap( javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW ); // Tried all three JComponent options, when focused, when in focused window, etc...
		ActionMap action = content.getActionMap();

		Action keyDownRight = new AbstractAction() {
			public void actionPerformed(ActionEvent e) {
				System.out.println( "HURF DURF D!" );
			}
		};

		map.put( KeyStroke.getKeyStroke("d"), "keyDownRight" ); // pressed d, d, and d pressed have no effect.
		action.put( "keyDownRight", keyDownRight );

Jo
Jan 24, 2005

:allears:
Soiled Meat

Paolomania posted:

I may be wrong, but I think that content panes, not being input widgets, never get input focus.

edit: I think that input map is for things like text boxes so you can do things like automatically updating a search as you type, etc.

Ah. Okay. Thanks. :smith:

Jo
Jan 24, 2005

:allears:
Soiled Meat
I'd like to have my program's assets stored inside the jar itself to avoid problems when someone has a strange working directory, and to make it easier to move the program around.

Simultaneously, I'd like to be able to avoid having to repack the jar every time I change a file. This compels me to leave the assets outside the jar in my assets folder.

Better put, if the loader finds a file in ./assets/, use that. Otherwise, load it from the <jar root>/assets/.

The solution I've heard to be universal is, `URL url = Main.class.getResource(filename);`, where filename is 'assets/mainmenu.png'. Is there a way which does not require code changes between 'outside' file references and in-jar file references?

Or do I have to do something like, 'if(new File(wat).exists()) {dance} else {load url from jar}'?

Jo
Jan 24, 2005

:allears:
Soiled Meat

Aleksei Vasiliev posted:

This is more or less what I have done. Centralized file loading method that first attempts to load from the directory, then falls back to the JAR.

Many thanks. That's what I've got set up. :( I guess it's not _that_ ugly a solution.

Ranma posted:

Do you have a build script that generates the jar? You should. If so why do you care?

Some of the elements might be updated after the jar is created. I can create a self-contained Jar without issue, but if our graphics person is fiddling, I don't want her to have to open the jar, extract the image, and repack it. Even a three step process can be a pain in the butt if you're making lots of little tweaks.

Jo fucked around with this message at 17:55 on Apr 8, 2012

Jo
Jan 24, 2005

:allears:
Soiled Meat
As a general policy, if I have a constructor in Java which takes two points (for example) and produces a line, is it a good idea to use the points as a reference or should I make copies? That is...

Java code:
	public Line2DInt(Point a, Point b) {
		p1 = new Point(a);
		p2 = new Point(b);
	}
OR

Java code:
	public Line2DInt(Point a, Point b) {
		p1 = a;
		p2 = b;
	}
On the one hand, people might be expecting to fiddle around with the values after the creation of the object. On the other, perhaps a static copy is desired? Or maybe I'm just overthinking this.

Jo
Jan 24, 2005

:allears:
Soiled Meat

Internet Janitor posted:

Jo: Well, Points are mutable. It depends on what you're trying to do. In some situations it can be very useful to have composed objects update under your feet, but if you mutate the Points that are passed in it may seem like "spooky action at a distance" from the caller's perspective. At any rate, it is indeed an important issue to consider, and worth documenting.

I was fiddling with a reimplementation of Ken Silverman's BUILD engine. Part of my reasoning was, if someone dicks with a vertex, I'd like to see the lines and sectors update automatically without having to iterate through each line and sector. At the same time, perhaps that's the correct way to do it on update. What if someone hoses a vertex? We'd need to update all the lines and sectors anyways to account for the loss.

Jo
Jan 24, 2005

:allears:
Soiled Meat

pigdog posted:

Also check out Flyweight pattern if it's applicable in your context.

Thank you. I think this will be beneficial.

Jo
Jan 24, 2005

:allears:
Soiled Meat
On the subject of maven, I've come to realize that my understanding of Java's class/jar/internals is pretty weak. I learned it as a course in my undergrad career and have continued using it, but I realize when it comes to doing things like building ant files or importing jars from external applications, I'm fuzzy. Is there a book or a collection of tutorials which don't really cover the details of learning the Java language, but highlight things like linking/gradle/maven? Is that even something wise to care about, or should I just fudge my way through it and rely on IntelliJ to build and maintain my build scripts?

EDIT: Actually, going through the Oracle docs as recommended above and doing some work with Gradle has been really helpful.

Jo fucked around with this message at 06:26 on May 9, 2015

Jo
Jan 24, 2005

:allears:
Soiled Meat

lamentable dustman posted:

Cool site I found if anyone wants to host a hobby webapp online or gently caress around with cloud poo poo your managers keep talking about from RedHat. Pretty much the only credible site I found that hosts java projects.

Found it while googling around for a host for a small app a goon asked for. Once you run the set up poo poo it'll generate the SSH token and a git repo for you. When you push your app upstream it automatically compiles and starts the app via Maven.

https://www.openshift.com/

Don't Heroku and AWS let you host Java applications?

Jo
Jan 24, 2005

:allears:
Soiled Meat
If I have a Socket connected from a client to a server and I want to fiddle with a custom protocol, is there a more graceful way of having the server handle commands than either (1) barfing serialized 'ServerCommand' objects across the network with ObjectStream or (2) writing plain strings like, "doActionA"?

Jo
Jan 24, 2005

:allears:
Soiled Meat

Volguus posted:

What do you mean by "graceful"? If you're at the socket level, you essentially have to write bytes on the wire. What those bytes mean, that's entirely up to you. There's no way around that. Now, you may come and say that you don't want to serialize objects using ObjectStream. That's fine, there are a billion other ways to serialize objects (to json, to xml, to other binary protocols like protobuf or msgpack).

Or maybe you don't want to send objects at all (or strings). That's fine too, you can send numbers: 1 means actionA, 2 means actionB, etc., but that'll be quite hard to maintain if it gets big, but I suppose you could do it.

But, you can send anything you want. If you can make bytes out of it, you can send the kitchen sink if you so desire.

By graceful, I meant, something less seemingly barbaric than writing a server which reads a character from the socket and throws it into a switch statement, then reads a few more characters and reassembles objects. That feels really old-school, like something I'd do in C in 1990. If that's not actually stupid or horribly unacceptable, I think I'll just make a CommandObject and dump that over the wire. I'd figured Java might have some "community standard" or "de facto" accepted way of doing it. "Oh, actually you're supposed to subclass the CommunicationProtocolWriter," or something like that.

Jo
Jan 24, 2005

:allears:
Soiled Meat
I started playing with a new project and have been using JavaFX image, converting it to a matrix, and fiddling with it. It looks like AWT has a bunch of helpful features and has the advantage of not needing to spin up a GUI to load an image. I don't want to get stuck in 1997, but man, JavaFX images... Is it bad form to use AWT? Is there a library which has supplanted them?

Jo
Jan 24, 2005

:allears:
Soiled Meat

Zaphod42 posted:

You could use AWT, but JavaFX should be able to do what AWT can too, and mixing both could be unnecessarily messy. There's almost assuredly a way to do what you're doing in AWT using JavaFX, and you'd probably be better off just figuring out how to do that by reading more JavaFX documentation or whatever.

Like yeah AWT was supplanted... by JavaFX. Also SWT, QT, etc. but w/e.

What about needing a GUI to load an image?
Can't you just
Image image = new Image(Path); ?

No, unfortunately. If you don't do launch(args) to start up the GUI component of the application, JavaFX won't allow you to use Images. That wouldn't be a problem if I were making a GUI application only, but I'm doing a dual-mode CLI/GUI app. Plus, Image doesn't have ConvolveOps like AWT and is missing a ton of features, like resizing. (You need to make an ImageView, render to an image view, then take a screenshot of the image view. Really.)

Here's the stack trace when I run it as CLI:

code:
java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
	at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:497)
	at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.IllegalStateException: Not on FX application thread; currentThread = main
	at com.sun.javafx.tk.Toolkit.checkFxUserThread(Toolkit.java:204)
	at com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(QuantumToolkit.java:438)
	at javafx.scene.Node.snapshot(Node.java:1907)
	at com.josephcatrambone.sharpcloud.ImageTools.FXImageToMatrix(ImageTools.java:41)
	at com.josephcatrambone.sharpcloud.ImageTools.ImageFileToMatrix(ImageTools.java:21)
	at com.josephcatrambone.sharpcloud.Main.main(Main.java:63)
	... 11 more
Exception running application com.josephcatrambone.sharpcloud.Main
When I run the same thing inside the start() method on the application after calling launch(), all is well.

Jo fucked around with this message at 19:40 on Sep 3, 2015

Jo
Jan 24, 2005

:allears:
Soiled Meat

Volguus posted:

Just did a little test and I can load an image just fine (and read a pixel's color) :
code:
    public static void main( String[] args )
    {
       //launch(args);
    	Image img = new Image("file:///home/user/pictures/apod/060314.bmp");
    	Color color = img.getPixelReader().getColor(0, 0);
    	System.out.println("color: "+color.toString());
    	System.exit(0);
    }
With that being said, there is nothing wrong to use Swing and/or AWT classes to read/manipulate images. JavaFX application (an UI one) can host a Swing component if you want to display the image. But if you just want a console application to manipulate an image (like it sounds that you do, saving the image into a matrix and all), use anything that's available in the JDK (not deprecated) and don't worry about it.

And after that, if you really want to display the image in a JavaFX UI application, the javafx Image can load from an InputStream as well (which could be ByteArrayInputStream if you have everything in memory already).

I'd rather use a consistent set of APIs and use Image everywhere. I'm confused, though, because my code almost exactly matches yours and I get an exception. I've tried two machines, both with the latest JDK, one Windows, one OSX. Same exception.

Are you sure you're importing javafx.scene.image.*; and not the Swing or AWT Image?

EDIT:

Interesting. The following all work:

code:
	public static void main(String[] args) {
		//launch(args);

		Image img = Image("file:" + filename);
	}
code:
	public static void main(String[] args) {
		//launch(args);

		TestImageTools.test("test.png");
	}

	static class TestImageTools {
		public static Image test(String filename) {
			return new Image("file:" + filename);
		}
	}
And they popped up a little 'Java' icon on my toolbar, so they're implicitly spawning a GUI window.

But when I move it into a different file...

code:
public class Main extends Application {
	public static void main(String[] args) {
		//launch(args);

		ImageTools.test("test.png");
	}
}

// Other file.
public class ImageTools {
	public static Image test(String filename) {
		Image img = new Image("file:" + filename);
		return img;
	}
}
THEN it fails.

Jo fucked around with this message at 21:02 on Sep 3, 2015

Jo
Jan 24, 2005

:allears:
Soiled Meat

Zaphod42 posted:

The problem is that you're extending Application in the last one, not the others. That's creating a new thread, which then invokes the start method. But you've also got a main method? I'm pretty sure that's wrong, and that's what's causing all your issues.

In my defense, ALL of the JavaFX examples have main inside the main Application. This is how Oracle says to do it (http://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello_world.htm).

No matter the case, it still doesn't work after I remove main:

code:
import javafx.scene.image.Image;

public class Main {
	public static void main(String[] args) {
		Image image = new Image("file:test.png");
	}
}
Stack trace:
code:
Exception in thread "main" java.lang.RuntimeException: Internal graphics not initialized yet
	at com.sun.glass.ui.Screen.getScreens(Screen.java:70)
	at com.sun.javafx.tk.quantum.QuantumToolkit.getScreens(QuantumToolkit.java:699)
	at com.sun.javafx.tk.quantum.QuantumToolkit.getMaxPixelScale(QuantumToolkit.java:714)
	at com.sun.javafx.tk.quantum.QuantumToolkit.loadImage(QuantumToolkit.java:722)
	at javafx.scene.image.Image.loadImage(Image.java:1046)
	at javafx.scene.image.Image.initialize(Image.java:795)
	at javafx.scene.image.Image.<init>(Image.java:609)
	at com.josephcatrambone.sharpcloud.Main.main(Main.java:12)

Jo
Jan 24, 2005

:allears:
Soiled Meat

Zaphod42 posted:

What? Didn't you say on the last page that this worked fine for you?

code:
public static void main(String[] args) {
		//launch(args);

		Image img = Image("file:" + filename);
	}
Also you still have a main class, so did you mean to say you removed the extends Application instead?
In which case that's my bad, looks like you have to have an application to invoke JavaFX methods, hence the graphics not initialized problem.

If you're trying to run it without any GUI, then just do exactly like what Volguus posted. Or use a simpler image manipulation library and not a full window graphics library, yeah. But then you probably don't need JavaFX.

You said before you kinda wanted it with GUI sometimes but not with GUI other times?

Emphasis mine.

Yes. I had to remove just the extends Application part to get a new exception. With extends Application I get a GUI (or an exception if I'm on a headless box), and it automatically spawns the GUI even if I do it outside of start(). Without extends Application I get the exception above. Unfortunately, It turns out it's not possible to use JavaFX Image without a GUI, as I found just now: https://bugs.openjdk.java.net/browse/JDK-8093075

Looks like if I want a headless and GUI application I have to use two different Image classes. :(

EDIT: Thank you both for the input, though. Wish the outcome could have been better.

EDIT EDIT: \/\/ :doh:

Jo fucked around with this message at 22:59 on Sep 3, 2015

Jo
Jan 24, 2005

:allears:
Soiled Meat
Looking for a second opinion. I'm using jBlas for a series of rather intensive matrix operations. I don't need really fancy QR decomposition or SVD, I just need multiplication (element-wise and mat/mat) to be really fast, along with addition, subtraction, transpose, inverse, and, ideally, exp. I could say "gently caress it" and write things in OpenCL, but that might be ill advised because everyone else seems to be just using GPU accelerated matrix libraries. Thoughts?

Jo
Jan 24, 2005

:allears:
Soiled Meat
Update on a previous question. I have a library I'm working on (link). I'd like to make a trainer which uses OpenCL, but since trainers are pluggable, I don't want to make OpenCL a requirement to build the project. I could just say, "Yo, delete this file after you clone the repo," but that seems like a terrible solution. What are my options as far as including a library for a single class file during compile time? Anything like conditional compilation #ifdefs in C?

Jo
Jan 24, 2005

:allears:
Soiled Meat
I have a random generator from which I'm extracting random numbers in an anonymous function. It seems like doing this is producing strange results and more duplicates than I'd expect. Is it okay to use random in async operations and lambdas?

Jo
Jan 24, 2005

:allears:
Soiled Meat

Zaphod42 posted:

Are you initializing a new random object each time? If so that's bad, and you're going to get strange results. If its a lambda you probably are.
I guess you'll need like a static class to hold the random reference? Well, Math.random() should do that already, if you're using that instead of a manual Random object.

No idea about thread safety of random so somebody else can probably weigh in more.

This is with respect to line 39 of this file: https://github.com/JosephCatrambone/Aij/blob/master/src/main/java/com/josephcatrambone/aij/trainers/RBMTrainer.java

I'm initializing Random random = new Random() when the class is created. When I use it in `Arrays.parallelSetAll(sampleIndices, x -> random.nextInt(inputs.numRows()));` poo poo gets fucky. I saw the same when I was writing another function using random in a lambda. It's entirely plausible that another factor is masking this and the issue is presenting in a way that makes me want to blame random.

Jo
Jan 24, 2005

:allears:
Soiled Meat

baka kaba posted:

What's 'more duplicates than I'd expect' though? You're picking rows at random right - how many are there, and how many are you collecting? Like with 1000 possibilities, drawing 25 at random has a 25% chance of at least one duplicate (I think)

Just making sure your expectations are realistic!

I had 400 samples from 60000 items and saw around 50% as duplicates.

Jo
Jan 24, 2005

:allears:
Soiled Meat
On the subject of Spring, what's the status and relation between JPA and Hibernate for persistence? The spring.io guide page is oddly devoid of Hibernate mentions. Does JPA supplant Hibernate?

EDIT: :downs: http://stackoverflow.com/questions/9881611/whats-the-difference-between-jpa-and-hibernate

Jo fucked around with this message at 03:14 on Jan 4, 2016

Jo
Jan 24, 2005

:allears:
Soiled Meat
I could use some help in designing things the new JavaFX way.

I've got an application which does/will do the following:

  1. User adds a series of streams from files in the UI.
  2. Application seeks through streams and synchronizes them.
  3. Application determines intrinsic camera parameters from the streams.
  4. Using eigenbackgrounds and carving, figure volume is extracted.
  5. Using skeletonization, bones are recovered.

I have, in general, three types of data, the image stream data (along with relative offsets from the earliest stream and a background pattern), the camera parameters, the recovered volume, and the recovered skeleton.

In JavaFX, I have the MainWindowController which I was hoping to use to drive all the UI elements with nice, snazzy callbacks and listeners, then have the Main application do all the heavy lifting. Here's where I'm running into problems: it looks like the MainWindowController can't reference the Main Application's properties unless I pass a reference to it or make them static. Both seem like really crappy design. I'm not sure how I'd do the separation of concerns.

This mock layout might help explain a bit better:



I'll have the n-synchronized streams selected (and, ideally, scrubbable), a tab for the silhouette extraction, and a tab for the mesh recovery. If this were a Swing application, I imagine I'd just be adding a lot of listeners and callbacks in the main startup function, but I'd like to be slightly more graceful this time if I can be. Anyone have a recommendation for how they'd structure an application like this?

===

Okay, so I've got a bit of an update. Had some time to think and I'm going with this:

I'll give the main model the static reference to media files and most of the main application logic. I'll let the FXML handle all the UI stuff since I'm going to be putting most of the UI in there anyway. I've done some prototyping and it looks like the code is pretty clean. Lots of observers and listeners, but on the whole it's good stuff.

Jo fucked around with this message at 04:22 on Aug 31, 2016

Jo
Jan 24, 2005

:allears:
Soiled Meat
Not sure if this belongs in the 3D tread. What are my options for debugging and benchmarking OpenCL in Java? (I'm using JoCL.)

I have an OpenCL application I'm making with JoCL and I'm having a hard time figuring out why the hotspots are what they are. The Java Mission Control application says that my program is spending most of its time in java.lang.integer.equals. That seems completely wrong. I've not been able to use any of nVidia's tools to debug the OpenCL code (since it seems to expect a C++ program). I'm out of ideas for finding out the source of the problem. The GPU is _way_ faster for most tasks, but I think the copying to and from system memory is hurting. I just wouldn't have expected it to hurt _that much_. What are my options for debugging and benchmarking OpenCL in Java?

My source code is here: https://github.com/josephcatrambone/aij The GPUGraph is the subject of the inquiry.

Jo
Jan 24, 2005

:allears:
Soiled Meat

Jabor posted:

The screenshot says that almost all of that time being spent in equals because ArrayList.indexOf is calling equals a lot. That seems completely plausible if indexOf is being called a lot on big lists - every call to indexOf effectively iterates over the entire list to try and find the right element.

If you expand the list of things that call indexOf (and keep expanding until you see something you recognize), does that clarify what's being slow?

Zaphod42 posted:

Try changing shapes from List to HashMap and see how that effects the performance. You call getShape() a lot in GPUGraph.java and that's O(N) each time.

Sorry, I can't answer your real question, haven't had to debug C++ calls from Java and I'm not sure how to go about that either.

You won't be able to attach to the java program, so you'll probably have to attach to the shared library. You may even have to get a debug build of the library and compile your java program against the debug library before it'll work.

Isn't ArrayList O(1)? I get that a Linked List would be O(n), but an array list should be as fast as a direct memory seek.

In either case, it's still hard for me to believe that the program is spending 50% of its time doing isEqual when the graph has only twelve nodes. Even with a non-memoized implementation that shouldn't be more than 144 calls to the method compared to 1000*1000 multiplications PER LOOP.

Fake Edit: The doc says an array list access should be O(1). It's just doing an array lookup.

Jo
Jan 24, 2005

:allears:
Soiled Meat

Zorro KingOfEngland posted:

ArrayList's .get() is O(1), but .indexOf() is O(n) because you have to get each object and test its equality until you find the one you're looking for.

If you look at the source code for ArrayList's indexOf you'll see that it just loops through elements until it finds one that equals: Here

A HashMap like Zaphod42 was suggesting would probably be a better fit for your problem.

efb.

Aha! Well I'll have to trace down where index of is being called. If get() is actually calling it, I'd call that a bug in the docs because it means the runtime isn't as advertised. I'll just switch to a standard array and resize it as I add elements to the graph. No need to use a hashmap.

Edit: OpenJDK's source indicates it's constant time. I wonder where that indexOf is getting called. Maybe I'm going down the rabbit hole with this one. Even with a fuckload of linear seeks, there's no way that finding an item in a list of length 12 takes 50% of a five-minute run. I think it's just the case that Java mission control can't effectively profile stuff that's native. It's probably not counting the two-minute matrix multiply or 30-second opencl compile. Treats it as blocked io?

Jo fucked around with this message at 00:43 on Oct 5, 2016

Jo
Jan 24, 2005

:allears:
Soiled Meat

Zaphod42 posted:

I already told you. IndexOf is called in getShape().

code:
if(shapes.contains(node)) {
	return shapes.get(node);
}
That's O(N) each time, and you call getShape() multiple times. How big is the shapes arraylist and how many times are you calling it? HashMap would make that O(1).

I guess that's not indexOf() in particular, although I wouldn't be surprised if contains() just returns indexof(o) == -1.

For that matter, looking at your code, is shapes.contains(node) even what you want there?

You put Dimension objects into the Shapes ArrayList. Contains(int) will always return null, wont it? Seems like you're trying to do contains(index) but that's not what the contains() method does. Contains is for passing an object that would be in the array, not an index.

code:
try{
  Shape s = shapes.get(node);
  if(s != null) {
	return s;
  }
}
catch(IndexOutOfBoundsException e)
{
//nothing found
}
//do other stuff

:downs: gently caress, I need to work on my reading comprehension. You're absolutely right. I don't actually need the check. The base-case is handled by the inputs in the case anyway.

That changes the profile a good bit.



Still think I need to profile the OpenCL component separately, since the performance on the GPU instance is markedly better for most tasks but incurs a high one-time overhead starting up.

Thanks everyone for the help -- removing that O(n) check shaved a nice 10% off the CPU benchmarks I had. :neckbeard:

Jo fucked around with this message at 08:05 on Oct 5, 2016

Jo
Jan 24, 2005

:allears:
Soiled Meat
Would this be the place to talk about Kotlin? I recently stumbled upon the language and have taken a liking to it. Do we have a JVM languages thread?

Jo
Jan 24, 2005

:allears:
Soiled Meat

poemdexter posted:

I don't know poo poo about Kotlin or Scala besides the fact that they don't do anything that Groovy doesn't already do and the syntax looks like rear end.

I'm coming up for a breather from Rust and Python, so the syntax is pretty cozy for me. Of the JVM languages I've tried so far (Scala, Clojure, and Groovy), it's my favorite. Clojure is a close second, though, so take that with a grain of salt. :v:

Jo
Jan 24, 2005

:allears:
Soiled Meat

AbrahamLincolnLog posted:

... As far as I can tell, my professor has ripped this assignment... The rest I can kind of figure out, but I have no idea where I'm supposed to be getting this GenericMatrix stuff from, and I wanted to double check to see if I was just loving up, or if I'm right and I'm missing part of the assignment.

I can see this happening and advise strongly in asking your professor if he's hosting the missing file somewhere. Email him NOW and CC a TA.

Jo
Jan 24, 2005

:allears:
Soiled Meat

Hughlander posted:

What's the current go-to webframework for small dumb projects that should better be done with something stupid like NodeJS? I just want to have a quick website where you can drag/drop images to upload and get saved, and then add tags. Thinking a little bit Ajax, autocomplete known tags, stupid backend to show tags by count, show images matching the tag etc... I swear I did something like this awhile back in Django but no idea where the source is. Was thinking Spark, but thought there was something else that people were recommending for tiny things like this but didn't see anything in 10 minutes of googling.

I'm in a similar boat. Would like to expand my horizons. Let me know if you find an answer to this.

Adbot
ADBOT LOVES YOU

Jo
Jan 24, 2005

:allears:
Soiled Meat
I've got a method which operates on a parallel Java 8 stream.

If I do this:

code:
public void elementOp_i(UnaryOperator<Double> op) {
		data = Arrays.stream(data).map(x -> op.apply(x)).toArray();
It seems to work, but I'm wondering if there's a way to avoid that re-assignment to data, since it should be possible to just modify all the values in-place.

Something like Arrays.stream(data).map(op).toArray(data)?

I see stuff like collect(Collection().toList, ...), but that seems to apply if mapping to a new array. I just want to operate in-place and using only .map() doesn't seem to do it.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply