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  
  Rendering and running a gameloop in an Applet  (Read 1158 times)
0 Members and 1 Guest are viewing this topic.
Offline Ultroman

JGO Knight


Medals: 24
Projects: 1


Snappin' at snizzes since '83


« Posted 2012-05-12 04:52:51 »

Still fighting the move from fullscreen graphics to an Applet with pseudo-doublebuffering Smiley

Is this at all a good implementation of a gameloop in an applet?
http://pastebin.java-gaming.org/54a6b9d84

It seems legit and it runs fine, except that instead of getting the 60fps I'm aiming for, I'm getting 63-64.

I've been scouring the net and this forum for posts on gameloops and rendering-methods, and found
many good examples, but very few are written for Applets, and most are incredibly elaborate and hard
to decipher. I've tried to compile those many ideas into something that would work for me.

Also, even though ra4kings impeckable sleep-method is rad, I just feel it is odd that one
has to do so many calculations, just to make your loop sleep for a specific amount of time.
Why is this not good enough?

- Jonas
Offline ReBirth
« Reply #1 - Posted 2012-05-12 08:15:53 »

If your problem is that 63-64, then you shouldn't worry.

ra4king's sleep method is pretty good. I adopt his these later months. It's not godly perfect but slight better.

Offline Ultroman

JGO Knight


Medals: 24
Projects: 1


Snappin' at snizzes since '83


« Reply #2 - Posted 2012-05-12 14:36:27 »

Thanks for your reply Smiley

Well, one thing I'm unsure of, is why those 3-4 extra frames are there. Mathematically, I don't see where they're coming from.

What I'm most interested in, is to know if this is a viable solution to the, well, single-buffering technique to reduce flicker.
This just seems much simpler than the ones I've found around the net.

- Jonas
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ReBirth
« Reply #3 - Posted 2012-05-12 15:09:20 »

The answer is simple, because getting time through System static class from OS especially windows is not accurate.

Offline Ultroman

JGO Knight


Medals: 24
Projects: 1


Snappin' at snizzes since '83


« Reply #4 - Posted 2012-05-12 15:39:53 »

The answer is simple, because getting time through System static class from OS especially windows is not accurate.

Yeah, I know. But it's stable at 63-64. I guess I'll live with that. Is that also the reason why the movement isn't
completely smooth? I've added some balls, and they move about fine. It just seems like they randomly skip a tiny
bit every ½ a second or so.

http://pastebin.java-gaming.org/54a6b0d94

- Jonas
Offline matheus23

JGO Kernel


Medals: 98
Projects: 3


You think about my Avatar right now!


« Reply #5 - Posted 2012-05-12 15:53:58 »

The answer is simple, because getting time through System static class from OS especially windows is not accurate.

Yeah, I know. But it's stable at 63-64. I guess I'll live with that. Is that also the reason why the movement isn't
completely smooth? I've added some balls, and they move about fine. It just seems like they randomly skip a tiny
bit every ½ a second or so.

http://pastebin.java-gaming.org/54a6b0d94

being stable at 63-64 is right. Thats what you programmed. You said him, he sould sleep "int sleepTime = 1000/FRAMERATE" and that means: sleepTime = 16. And with that sleepTime you should perfectly get 64 Frames/sec.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline Ultroman

JGO Knight


Medals: 24
Projects: 1


Snappin' at snizzes since '83


« Reply #6 - Posted 2012-05-12 16:23:51 »

being stable at 63-64 is right. Thats what you programmed. You said him, he sould sleep "int sleepTime = 1000/FRAMERATE" and that means: sleepTime = 16. And with that sleepTime you should perfectly get 64 Frames/sec.
What I want is 60fps, which should be 1000000000ns/60 = 16666667 = 16,666667ms per frame. Setting it to 16ms flat, would produce 62,5fps, give or take.

Well, maybe what I need is to do as some threads on the forum suggest, and use Thread.yield() and a deltaLoop-timing system instead of sleep(),
as ReBiirth and others suggested in this older thread http://www.java-gaming.org/index.php?topic=22762.0
Oh I hope the Orcale guys fix this problem.

EDIT: I think I've found the solution. It has been posted in another thread, due to several changes in the code, and new questions.
Here is the new post!

- Jonas
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!