Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (529)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  LWJGL Game Init and Main Loop  (Read 7211 times)
0 Members and 1 Guest are viewing this topic.
Offline Morgrog

Senior Newbie




Rubber bands and cafeine, weeeee~


« Reply #30 - Posted 2004-05-02 20:36:39 »

VSync is based on the desktop's refresh rate and that can range from 60 to 85 (normally).  So when VSync isn't enabled you have to use the hardcoded frame rate (60) right?

so huh won't the game run faster on a 85Hz vsynced computer as opposed to a 60Hz app controlled computer? Will there be a big difference?
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #31 - Posted 2004-05-02 21:59:39 »

Quote
So when VSync isn't enabled you have to use the hardcoded frame rate (60) right?


Right.

Quote
so huh won't the game run faster on a 85Hz vsynced computer as opposed to a 60Hz app controlled computer? Will there be a big difference?


It depends on how you calculate the movement of your game objects. If you update all movement time based instead of frame based, the game will be equally fast on all refresh rates.
So think for movement speed in 'units per second' rather than 'units per frame' (units being pixels, meters, miles or whatever) and all will be well.

Offline MickeyB

Senior Member




my game will work, my game will work!


« Reply #32 - Posted 2004-05-03 13:38:03 »

I have updated my video drivers and according to the ATI site, my Mobility Radeon is OpenGL ready for 2d and 3d accelerated graphics.  I am at a loss.   Sad

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #33 - Posted 2004-05-04 14:38:57 »

Quote
Out of curiosity, (when looking at Cas' code) is it better to use a different thread for the logic() function and only call that thread at fixed amount of time? (time proc?)

No!
Quote
I mean, the thread sleeps for a given interval of time and only executes the logic every now and then (25ms or whatever is the standard)
Is that the way to do time based logic, thus isolating the rendering and the logic part of the game?

Your rendering will use the data updated in the logic right? The 2 threads can't run at the same time or you'll get synchronization bugs. So you get absolutely nothing from using 2 threads except some really complex logic that synchronizes the threads.

Btw. You can call the logic() function more than once per game loop if it the logic is lagging behind.

Offline Morgrog

Senior Newbie




Rubber bands and cafeine, weeeee~


« Reply #34 - Posted 2004-05-04 14:57:12 »

ok, so how do I force time based logic?

create an application tick (i.e. something time based that is constantly updated, kinda like the frame rate I suppose) and if that application tick is greater than our update rate, we update our logic? is that how it should be implemented?

Anyways, thanks for the eye opener, I'll see how I can turn my game into a time based one Cheesy


edit: NM, just went through parts of Kevin Glass' tutorial and it's pretty straightforward Cheesy, 2 thumbs up for Kevin
Online Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #35 - Posted 2004-05-04 15:32:00 »

Quote
ok, so how do I force time based logic?

Time based logic would call .logic and .render once per loop, but the logic method would caculate the time elapsed since the last frame. Then all your game updates are done based on that elapsed time. Thats usually pretty easy and often just requires scaling your speed/velocity type calculations based on that frames delta time.

However it can make collision a real pain, since you can get varying steps. You often need to check the entire path an object moved though rather than just the end point (otherwise you 'leapfrog' over an object).

Time based is great for 'proper' 3d worlds where you can get something that runs smoother on faster machines. However for a 2d game you'll get a much smoother scrolling with a fixed framerate rather than a variable one.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Online princec

JGO Kernel


Medals: 339
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #36 - Posted 2004-05-05 15:02:47 »

Hey y'all - the timing code has been revised in the CVS of LWJGL! Now in 0.91 (ahem) we've got the most super-groovy method in the universe to take care of all your frame-capped woes:
1  
Display.sync(FPS);

Yes! It does exactly what you think it's gonna do! Now you can just sit back and let our system-friendly bit of code take care of capping framerates while you get on and make the tea.

Cas Smiley

Offline Morgrog

Senior Newbie




Rubber bands and cafeine, weeeee~


« Reply #37 - Posted 2004-05-05 16:53:43 »

ohh, this makes me think of a question to add to the wiki which I'm gonna do right now


that is, how to get the latest working binaries from CVS (if it's even possible, if not, how to compile them)

so uh yah *goes on the wiki*

Thanks again!

Now if I can only finish my personnal SCM perl script
(it's gonna do a bunch of fun things, all based on a config file, like huh backup the latest version of a project, package and sign the jars, copy the source to a showsrc directory and what not) Smiley
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #38 - Posted 2004-05-06 00:16:33 »

Hm... just took a look and experimented a bit. As I expected (and as I already pointed out in the other thread) using the same cap rate as hz will lead to frame skips if vsync is actually enabled. Aiming for some fps more helps (eg +3).

I also checked the code and I think my version is a bit neater (shorter and no casts) Smiley
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public static void sync(long fps)
{
      long gapTo = Sys.getTimerResolution() / fps + timeThen;
      timeNow = Sys.getTime();
      while(gapTo>timeNow)
      {
            Thread.yield();
            timeNow = Sys.getTime();
      }
      timeThen=timeNow;
}

弾幕 ☆ @mahonnaiseblog
Online princec

JGO Kernel


Medals: 339
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #39 - Posted 2004-05-06 08:31:38 »

Smartass Tongue I will change to CVS to reflect your nicer version.

I don't get frame skips with vsync enabled, but I can see that it might happen. +3 is probably overkill, +1 ought to do the trick.

Cas Smiley

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

Senior Member




my game will work, my game will work!


« Reply #40 - Posted 2004-05-07 16:42:28 »

got the sample loop working on my gaming machine at home...so laptop will never do it.  Time to code at home. Smiley

MickeyB

Current Project: http://www22.brinkster.com/mbowles/
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #41 - Posted 2004-05-07 17:47:40 »

Quote
got the sample loop working on my gaming machine at home...so laptop will never do it.  Time to code at home. Smiley


How very true!  My laptop has been repurposed to playing Battlestar Galactica DVDs while I work on my desktop machine - I ran into too many display driver bugs to make it worthwhile persisting with.


Re: Display.sync() - is that the right place for it?  Isn't it more of a Window function than a Display function?

Another thought - is there any mileage in having a setFrameRate(int) method in initialization, then collapse the synchronization code into the Window.update() call?  This would change the function of the update method even further away from the concept of "update", I suppose.


Regardless, what's the short-term release schedule?  Is there going to be an interim (i.e. non-1.0) release for this (slight) API change?

Hellomynameis Charlie Dobbie.
Online princec

JGO Kernel


Medals: 339
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #42 - Posted 2004-05-07 23:20:43 »

We are, er, looking at totally deleting the Window class and merging its functionality with Display...

Cas Smiley

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #43 - Posted 2004-05-08 00:25:40 »

Sounds good. I often searched in the javadoc in the display class only to find out that the thing I need is over at the window class and vice versa. So +1 Smiley

弾幕 ☆ @mahonnaiseblog
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #44 - Posted 2004-05-08 11:10:57 »

A good answer!  I was pondering the same thing last night.  I await the next release with interest!

Hellomynameis Charlie Dobbie.
Offline zulo

Junior Member




Java games rock!


« Reply #45 - Posted 2004-05-28 22:54:30 »

hi this is so great!!

I have a basic game setup with eclipse and lwjgl09 cvs build now, your game class worked with no problems:)

LWJGL is easier then i thought, I looked at a opengl faq (i also have some opengl ebooks that im going to look at) with examples for c/c++ and learned how to draw quads, I used GL_QUADS setting. I want to make a 2d platform so can i use a texture on my quad? is that the way to go? or is there some other technique to draw the textures as sprites?

could you give me an example of render code to render 1 image/texture? ( as a 2d image )

I understood how to load a texture from nehes tutorial, but he is using awt to load..is there another method? so that i dont need to use awt because i want the opportunity to compile the game to native..
Online princec

JGO Kernel


Medals: 339
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #46 - Posted 2004-05-29 09:31:12 »

My advice is to use AWT first and get it working to learn the ropes. Then when you know what you're doing, start removing it all and replacing it with your own code.

Cas Smiley

Pages: 1 [2]
  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.

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

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

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

MustardPeter (24 views)
2014-07-16 23:30:00

Cero (39 views)
2014-07-16 00:42:17

Riven (41 views)
2014-07-14 18:02:53

OpenGLShaders (28 views)
2014-07-14 16:23:47

Riven (28 views)
2014-07-14 11:51:35

quew8 (25 views)
2014-07-13 13:57:52

SHC (61 views)
2014-07-12 17:50:04
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!