Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (429)
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  
  (un)Smooth movement  (Read 2978 times)
0 Members and 1 Guest are viewing this topic.
Offline downward_spiral

Senior Newbie





« Posted 2003-02-12 14:25:37 »

I'm having a bit of a problem with the smoothness of my graphics.. or the lack of it!

I'm using a dead simple Applet and Thread, and the graphics are drawn using active rendering. My main loop is pretty traditional:

1  
2  
3  
4  
5  
6  
7  
8  
run()
{
   gameLogic();
   render(backBuffer);
   swapBuffers();
   try{gthread.sleep(20);}
   catch (InterruptedException e){}
}


The game logic is non existent at the moment, so it basically just throws things at the screen.

The problem is that while it maintains a fairly constant speed, it'll jerk/judder/stick every second or so. It's perfectly smooth in-between these judders, which makes it seem like (to me) that something is interrupting my program periodically.

My other thought was that some frames may be taking vastly different times to draw than others, causing intermittent speedups/slowdowns. So, I tried using a Timer object to invoke the drawing of frames at a set rate, and it made absolutely no difference.

I also wrote a small method to calculate the amount of time taken to draw a frame, and subtracted that time away from a standard delay. I then made the thread sleep for this amount of time. This should make each cycle of the loop take roughly the same time.. right? But it still behaves *exactly* the same..

I've tried the program on all sorts of hardware and Windoze versions.

Any suggestions?
Offline Backmask

Junior Member




586: The average IQ needed to understand a PC


« Reply #1 - Posted 2003-02-12 15:34:57 »

Quote
The problem is that while it maintains a fairly constant speed, it'll jerk/judder/stick every second or so. It's perfectly smooth in-between these judders, which makes it seem like (to me) that something is interrupting my program periodically.


My quess is that the GC kicks in and make these small jerks. Check all your code in the gameLogic() and render code for any use of the new keyword. If you find any use of that get ride of it. Never allcolate new objects in your render loops, or gamelogic, this will cause the GC to start the garbage collection at times and make the jerks.

Other than that I can´t  think of anything without seeing the code.


Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #2 - Posted 2003-02-12 15:48:08 »

In our 3D app we have the jerks as well. But this is quite independant of wether we create garbage or not. We had some test code in there that created thousands of objects/second. Vector3f, Matrix4f, Transform3D and such. We could not notice any effect. The numbers only showed up significantly when profiling.

I feel the GC in fact is a VERY fast action that does not disturb a game that has 10ms between two frames. The times the GC needs are far smaller AFAIK.

Of course, don't allocate some megs of something each frame - then GC certainly will kill you.

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 285
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2003-02-12 21:43:50 »

The GC seems to use about 5ms or so (despite what it claims) every now and again, which is about 1/3rd to a quarter of a video frame. However what it doesn't time is the heap synchronization overhead which it does - the heap has to be locked while it occurs - and I think this is where the pause increases substantially.

There's also now and again a bit of Hotspot housekeeping going on.

BTW, I'm allocating some kinds objects in my game loop happily without any real trouble - a dropped frame every minute or so maybe - such as enemies and the like. But very few of them.

Cas Smiley

Offline Virum

Junior Member




Like a leaf in an icy world, memories will fade


« Reply #4 - Posted 2003-02-12 21:46:01 »

GC is probably the reason...

It's time to prove to your friends that your worth a damn. Sometimes that means dying; sometimes that means killing a whole lotta people.

Blog
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #5 - Posted 2003-02-13 07:54:08 »

Quote
The GC seems to use about 5ms or so (despite what it claims) every now and again, which is about 1/3rd to a quarter of a video frame. However what it doesn't time is the heap synchronization overhead which it does - the heap has to be locked while it occurs - and I think this is where the pause increases substantially.

There's also now and again a bit of Hotspot housekeeping going on.


But GC runs only now and then, the stutter is by far more frequent - that is what I felt. Maybe it's only one source of many....

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline downward_spiral

Senior Newbie





« Reply #6 - Posted 2003-02-13 08:24:45 »

Thanks for the replies  Smiley

GC would make some sense I suppose. I'm not doing much real code at all in the main loop though, certainly no alloc/dealloc. Just simple move->draw->wait->repeat.

Does GC always run at a set rate irrelevant of what your program is actually doing? I've not looked very deep into the mechanics of this before.

Its not a massive stutter, just noticable. Maybe I'm too used to my Amiga's lovely smooth scrolling?  Grin
Offline Herkules

Senior Member




Friendly fire isn't friendly!


« Reply #7 - Posted 2003-02-13 08:58:30 »

Yes, I know what you mean.....

No, the GC acts on demand, at least AFAIK and judging from its output. While loading our prototype it is VERY active, but when the game runs it comes up only every 5 seconds. If I increase available memory (-Xms256mb -Xmx256mb), it does show up after a couple of minutes....

But this does not influence smoothness....

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline Captain-Goatse

Junior Member




I suck at teh 2D. XBOX IS BIG LOL!111


« Reply #8 - Posted 2003-02-13 10:24:54 »

If you do a lot of loading or affine transforming or anything before the game starts, it is good to run system.gc() after it. This reduced the jerkiness for me, because depending on the object, the GC decides whether to dump the object or not and apparently it doesn't dump affine transforms or image dumpsters unless it is absolutely sure they won't be used again. This means that every time gc runs, it checks through all these and decides wheter to dump them or not.

If you don't need something, try to set it into condition where the GC understands that it won't be used and dumps it right away.
Offline princec

JGO Kernel


Medals: 285
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #9 - Posted 2003-02-13 12:18:53 »

It's almost certainly a GC pause, and it will happen regularly as long as any allocation occurs at all, and there's almost certainly a little bit going on somewhere.

The last vestiges of GC stutter I removed with -Xincgc and -Xconcgc - XAP runs smooth as glass (until there's a few hundred particles whizzing about that is).

I don't get the stutter when using Jet either, which leads me to suspect it's the new space garbage collector cleaning away a few short lived objects. Jet allocates this kind of thing on the stack where it can and invokes no GC penalty at all as a result.

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline erikd

JGO Ninja


Medals: 15
Projects: 4
Exp: 14 years


Maximumisness


« Reply #10 - Posted 2003-02-13 12:51:58 »

To be sure how great the GC impact is, I use the flag -Xloggc:/gc.log for example. Especially look out for 'Full GC' reports.

Offline downward_spiral

Senior Newbie





« Reply #11 - Posted 2003-02-13 14:20:38 »

Thanks, I reckon some of this has made a difference.

Cheers  Grin
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 (216 views)
2014-04-04 12:06:45
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

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!