Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (430)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (468)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Constant frame rate problem  (Read 3581 times)
0 Members and 1 Guest are viewing this topic.
Offline bulutoprak

Senior Newbie





« Posted 2006-06-07 12:55:39 »

Hi,
I am restricting the frame rate of  Java3d thread, by calling
Thread.sleep(SLEEP_TIME);

in each frame render inside a Behaviour instance.

1)Is this the right way for not allowing Java3d to use all the processing power.

2) When i call Thread.sleep which thread sleeps. Becouse if i increase the sleep time, some operations (which are not related to Java3d) becomes slow, as if their threads are sleeping too.

3) Is there method or way in Java3D , like setFrameRate(30);
4) Is there a mthod or way in Java3D, like
renderOnce();

Thanks.

Offline Breakfast

Senior Member




for great justice!


« Reply #1 - Posted 2006-06-07 13:33:38 »

I haven't looked at how things have changed over the last few versions, but this is how I remember it working: Java3D will render as many frames as it can, whatever else is happening. You can't limit the framerate, so don't try to- if your application needs more power Java3D will render fewer frames so just make sure your behaviours know how long it is since the last frame was rendered and use that to judge how much you need to do (I'm not very up on interpolators, but I think you can use these in a similar way- maybe I dreamed that, though ) rather than telling it when to render a frame. The standard render-loop is rather different from the Java3D architecture.
Offline otelo

Junior Member





« Reply #2 - Posted 2006-06-07 19:23:06 »

> 1)Is this the right way for not allowing Java3d to use all the processing power.

no, not really. you should probably set the minimum time between frames for your view ... canvas3D.getView().setMinimumFrameCycleTime(33);

> 2) When i call Thread.sleep which thread sleeps. Becouse if i increase the sleep time, some operations (which are not related to Java3d) becomes slow, as if their threads are sleeping too.

don't do that.

3) Is there method or way in Java3D , like setFrameRate(30);

> see answer to 1)

4) Is there a mthod or way in Java3D, like renderOnce();

> why would you ask? search the documentation, you'll have to study it anyway because yes, there is such method.


the thing with java3D is that it only renders continuously when there is something changing in the scenegraph. create a simple scene with a ColorCube and you'll see your CPU at 0% load all the time. the problem is the behaviors in java3D like interpolators and view manipulator which are waking up on WakeupOnElapsedFrames(0) ... that is as soon as a frame is rendered .... it's basically an endless loop.

the solution for this is writing your own behaviors that wakeup on time elapsed instead, or constraining the render speed of your views as described in 1).
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Breakfast

Senior Member




for great justice!


« Reply #3 - Posted 2006-06-08 00:42:10 »

Quote
the solution for this is writing your own behaviors that wakeup on time elapsed instead, or constraining the render speed of your views as described in 1).
Or having your behaviour check how long it is since it was last called and act appropriately.
Offline bulutoprak

Senior Newbie





« Reply #4 - Posted 2006-06-08 12:43:52 »

canvas3d.getView().setMinimumFrameCycle(fps);
works fine and frame rate is almost constant. However, now other threads in my application cannot have enough time to process their tasks. Even i set the priority of my other thread to max priority, it still cannot have enough time. Is there a way to restrict the priority of Java3D thread.
Offline Ifadolai

Junior Member




Java forever!!


« Reply #5 - Posted 2006-06-08 16:23:21 »

Is there a way to restrict the priority of Java3D thread.

Yes there is, use this:

VirtualUniverse.setJ3DThreadPriority()

1 = minimum, 5 = normal, 10 = maximum

Nikolai V. Christensen, Computer Engineer,
Simulation and Training department
IFAD, Forskerparken 10A, DK-5230 Odense M
Denmark, EU
Phone: +45 63 15 71 31  Fax: +45 65 93 29 99
Offline otelo

Junior Member





« Reply #6 - Posted 2006-06-08 19:26:40 »

> canvas3d.getView().setMinimumFrameCycle(fps);
you are not a friend of reading the docs, are you? you use setMinimumFrameCycle(milliseconds); not to set framerate, but the minimum time the renderer waits before rendering another frame.

> Is there a way to restrict the priority of Java3D thread.
as I already told you, don't f*ck around with java3d's threads, it will cost ya!  all frame-dependent operations should be executed inside of a behaviour, that way you are guaranteed they will finish before another frame is rendered.
Offline bulutoprak

Senior Newbie





« Reply #7 - Posted 2006-06-09 11:35:24 »

Thanks for fixing my mistake about frame rate.  Anyway, iin the thread priority topic i think, i could not make myself clear about how i used Java3D. In my application Java3D is not  a main part, it is only one of 4 main parts, so i dont want it to get all the process power selfishly, and enable other parts to do their jobs. So implementing things in behaviour classes is not an option.(Ofcourse i am doing Java3D related tasks in behaviour classes).

I used canvas3d.getView().setMinimumFrameCycleTime(cycleTime:). and VirtualUniverse.setJ3DThreadPriority(4) to make its thread not important and to let it render as performance lets it.
In that case, not only Java3d thread priority is set, but also Awt Thread is made slow too much. I  gues Java3d is somehow related to Awt Event Thread.
And after i looked at the source code of Java3D, i realized that it also changes the priority of the current thread that is calling it. The current thread is Awt Event Queue Thread.

So to fix this, after setting the priority of the Java3D thread, i called this line.
Thread.currentThread().setPriority(Thread.NORMAL);

Is this approach the right approach?


Second, sometimes application gets an exception (from Awt Event Queue Thread), and Java3D crashes. Canvas3D does not render anything after this point. Is this a bug of Java3D. Becouse exception and Java3D are not related to each other.

Although I am not very sure if it is beacouse of Java3D but , i started to believe that Java3D threads are not working well with the other threads in the application.
Thanks,
Offline otelo

Junior Member





« Reply #8 - Posted 2006-06-09 12:39:45 »

I repeat... do not f*ck around with java3d's threads!

You still don't understand how it works. Java3d won't simply starve other threads, unless you change something in the scenegraph continuously. It simply renders a single frame to the frame buffer and does nothin until a change occurs (a behavior wakes up or you change something in the scene from outside which is you asking for trouble).

any code you place into a behavior is executed while java3d is waiting for it to finish. they don't compete for resources. what ever you do, update your scene using a behavior.
Offline Breakfast

Senior Member




for great justice!


« Reply #9 - Posted 2006-06-09 13:07:12 »

Behaviours; number 1 in the list of things about Java3D that people just don't get.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline bulutoprak

Senior Newbie





« Reply #10 - Posted 2006-06-09 13:48:39 »

I am always updating scenegraph in a behaviour class, so i guess this is not a problem, but i was thinking that Java3D was handling all things in a thread safe way.
From what i undersand from the answers, if canvas3d crashes becouse of an Awt Event Queue Thread exception, this means some code updates scene graph other than behaviour classes. Is this what you are saying? In that case, i will recheck all the code for this case. Although i am almost sure that all the updates in the scene graph are from the behaviour classes.

Only place that i didnot use behavour is when a new object should be added to the scene graph. In that case, i am creating the 3d object in  another thread and adding it directly to scene graph. Is this a wrong implementation. Do i need to store the commands to be handled in a behaviour class later?
Thanks
Offline Breakfast

Senior Member




for great justice!


« Reply #11 - Posted 2006-06-09 16:02:58 »

Always use a behaviour to do anything to your scenegraph.

If you're in a restaurant, you don't wander into the kitchen to fetch your food out of the oven regardless of whether or not it's cooked. Think of behaviours as the waiter in the restaurant of Java3D - you tell them what you want and they take it to the kitchen to be sorted out...
Offline Jeff

JGO Coder




Got any cats?


« Reply #12 - Posted 2006-06-09 22:15:49 »

Thanks for fixing my mistake about frame rate.  Anyway, iin the thread priority topic i think, i could not make myself clear about how i used Java3D. In my application Java3D is not  a main part, it is only one of 4 main parts, so i dont want it to get all the process power selfishly, and enable other parts to do their jobs.

Then dont use Java3D.  Sorry, but this is not at all what J3D is desigend to do.  J3D is an execution framework, your app code should be executing as behaviors (typically as WakeOnFrame(0) behaviors.)

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline bulutoprak

Senior Newbie





« Reply #13 - Posted 2006-06-12 15:35:56 »

Quote
Then dont use Java3D.  Sorry, but this is not at all what J3D is desigend to do.  J3D is an execution framework, your app code should be executing as behaviors (typically as WakeOnFrame(0) behaviors.)
I hope you are not speaking for Java3D developers, becouse i cannot understand why Java3D restricts itself just to be only module in an application. Anyway i used lots of 3d engine and i did not see such a case in others. And i believe that what you say is not right.
Offline NVaidya

Junior Member




Java games rock!


« Reply #14 - Posted 2006-06-12 16:57:11 »


...
...
Second, sometimes application gets an exception (from Awt Event Queue Thread), and Java3D crashes. Canvas3D does not render anything after this point. Is this a bug of Java3D. Becouse exception and Java3D are not related to each other.


Are you saying that an exception in EDT causes the Canvas to freeze ? That shouldn't really happen with Java 3D 1.4.0 and later. If you're using a pre-1.4.0 version, I've a workaround here:
https://java3d.dev.java.net/issues/show_bug.cgi?id=78

Gravity Sucks !
Offline NVaidya

Junior Member




Java games rock!


« Reply #15 - Posted 2006-06-12 17:06:05 »


Only place that i didnot use behavour is when a new object should be added to the scene graph. In that case, i am creating the 3d object in  another thread and adding it directly to scene graph. Is this a wrong implementation. Do i need to store the commands to be handled in a behaviour class later?
Thanks


And how do you "add" that new object to the scenegraph ? By "attaching" a BranchGroup at runtime ? If so, then you should most certainly be doing that on a Behavior callback since, as per the API contract, attach/detach of a BranchGroup isn't MT safe.

Gravity Sucks !
Offline bulutoprak

Senior Newbie





« Reply #16 - Posted 2006-06-14 15:55:34 »

Quote
Are you saying that an exception in EDT causes the Canvas to freeze ? That shouldn't really happen with Java 3D 1.4.0 and later. If you're using a pre-1.4.0 version, I've a workaround here:
https://java3d.dev.java.net/issues/show_bug.cgi?id=78
Quote

yes what i am saying is that. I am using Java3d version '1.4.0-build5-experimental  24 Jun 2005'
Andi got this exception:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException
        at javax.swing.LayouComparator.compare(Unknown Source)
        at java.util.Arrays.mergeSort(Unknown Source)
        ......

After this exception, Java3d rendering freezes.

Offline Mr. Gol

Senior Member


Medals: 1



« Reply #17 - Posted 2006-06-15 17:19:13 »

I am using Java3d version '1.4.0-build5-experimental  24 Jun 2005'

Maybe you could try using the final version of 1.4 (1.4.0_01 is the latest I think) instead of an early version?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

theagentd (6 views)
2014-04-24 23:00:44

xsi3rr4x (83 views)
2014-04-15 18:08:23

BurntPizza (75 views)
2014-04-15 03:46:01

UprightPath (86 views)
2014-04-14 17:39:50

UprightPath (69 views)
2014-04-14 17:35:47

Porlus (86 views)
2014-04-14 15:48:38

tom_mai78101 (109 views)
2014-04-10 04:04:31

BurntPizza (169 views)
2014-04-08 23:06:04

tom_mai78101 (265 views)
2014-04-05 13:34:39

trollwarrior1 (217 views)
2014-04-04 12:06:45
Escape Analysis
by Roquen
2014-04-25 11:42:09

Escape Analysis
by Roquen
2014-04-25 11:37:01

Escape Analysis
by Roquen
2014-04-25 10:38:58

Escape Analysis
by Roquen
2014-04-25 10:22:13

List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!