Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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  
  Flicker  (Read 1644 times)
0 Members and 1 Guest are viewing this topic.
Offline cneller

Junior Newbie





« Posted 2008-10-07 22:21:04 »

Hi,

I've got a JOGL project that is displaying an animated, flickering box. Unfortunately, sometimes (typically about 30 seconds into the program) the flickering stops for a second or so (it should change about every 1/8 of a second) before picking up again.


specifying -verbose:gc indicates that it isn't the garbage collection. What else could cause this? How can I check these causes?


Many thanks!
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 744
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2008-10-07 23:24:07 »

You're giving us very little info Smiley

Basically the animation is interrupted, and then continues, and it's not the GC... oh well! Smiley


Maybe you're using System.nanoTime(), which is known to go back in time every once in a while, due to CPUs throttling their frequency.

Other than that, we need much much more information, like a self contained (!) testcase, so that we can run it, or if you're lucky: look through it and point you are potential bugs!

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline cneller

Junior Newbie





« Reply #2 - Posted 2008-10-07 23:53:41 »

Fair enough.

Interestingly, your nanoTime comment might be it! I was using it because I wanted accuracy better than currentTimeMillis, but if it's an issue, maybe that's a good trade-off (no flicker for worse accuracy). Is there a better timer to use to get millisecond accuracy (not just precision) than nanoTime?


Anyway, here is the basic loop for the image presentation:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
      :
      while( !m_stop_running && stimulus_iterator.hasNext() )
      {
         TimedStimulus item = stimulus_iterator.next();

         // Load image into ByteBuffer
        //
        loadStimulus( item );
         
         // Determine how long to wait before display
        //
        // Time to present - (elapsed time since last stimulus) - (typical time to render)
        //
        sleep_time = item.getTime() +
               ( m_start - System.nanoTime() ) -
               ( m_average_image_render_time );
         
         // If we have plenty of time, then sleep until we're ready
        //
        if( sleep_time > 0 )
         {
            try
            {
               Thread.sleep( sleep_time / Constants.NANOSECONDS_PER_MILLISECOND );
            }
            catch( InterruptedException ex )
            {
               continue;
            }
         }
         
         // Skip the image if it's over 5 seconds late
        //
        else if( sleep_time < -5 * Constants.NANOSECONDS_PER_SECOND )
         {
            log.warn( "Image display late " + sleep_time + " nsec. Skipping." );
            continue;
         }
         
         // Present the stimulus
        //
        try
         {
            m_gl_canvas.display();
         }
         catch( GLException glx )
         {
            log.warn( "Error displaying image: " + glx.getLocalizedMessage() );
         }
         
      } // end loop over timed stimulus items in the task
     :



The display method looks like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
      :
      // Draw to the buffer as RGB bytes
     // m_buffer populated in the loadImage() call in main loop
     //
     GL gl = drawable.getGL();
      gl.glPushAttrib( GL.GL_COLOR_BUFFER_BIT );
      gl.glDrawPixels( 800, 600, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, m_buffer );
      gl.glPopAttrib();
      gl.glFlush();
      :



Thanks for your help!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SimonH
« Reply #3 - Posted 2008-10-08 06:20:47 »

1  
2  
3  
4  
         if( sleep_time > 0 )
         {
             .....
         }


This might be your problem; the JVM shares CPU with the OS, so you should always call sleep() even it's with a low value, otherwise the OS gets a backlog of tasks which may take a while to clear.

People make games and games make people
Offline gouessej
« Reply #4 - Posted 2008-10-09 23:17:44 »

This might be your problem; the JVM shares CPU with the OS, so you should always call sleep() even it's with a low value, otherwise the OS gets a backlog of tasks which may take a while to clear.

I disagree with you. Calling sleep even a vanishingly small time decreases the frame rate noticeably and is not necessary. I removed it in TUER and the frame rate is twice better. I have almost no problem of timing, I use currentTimeMillis for the moment.

Offline SimonH
« Reply #5 - Posted 2008-10-10 16:53:19 »

I disagree with you.
I disagree with your disagreement!  Wink

I removed it in TUER and the frame rate is twice better.
My tests showed a 10% performance drop without sleep() - maybe it's because I'm using software rendering...

People make games and games make people
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 744
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2008-10-10 21:04:25 »

I disagree with your disagreement! Wink

please sign some Non-Agreement Disclosure

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
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.

E.R. Fleming (10 views)
2014-07-29 03:07:13

E.R. Fleming (4 views)
2014-07-29 03:06:25

pw (38 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23

MustardPeter (44 views)
2014-07-16 23:30:00
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!