Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (799)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (865)
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  
  LWJGL resize and delta  (Read 1726 times)
0 Members and 1 Guest are viewing this topic.
Offline Spacebeans
« Posted 2014-04-01 21:03:48 »

I have a resizable LWJGL display, it works fine, just that the timing doesn't calculate that there was a long delay between the frame were I wasn't resizing, and the frame that I was resizing (Current).

So delta (Time in ms between frames), freaks out and thinks my computer lagged.

Were I'm using deta:
1  
 sunX += 0.3f * delta; 


My timing class:
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  
package passage.games.pdday.handling;

import org.lwjgl.Sys;

public class TimingHandler {
   
   private long lastFrame;
   private float fps;
   private float frame;
   private long lastFPS;
   
   public void init(){  
      getDelta();
      lastFPS = getTime();
   }
   
   public void tick(int delta){
      updateFPS();
   }
   
   public int getDelta() {
       long time = getTime();
       int delta = (int) (time - lastFrame);
       lastFrame = time;
 
       return delta;
   }
   
   public long getTime() {
       return (Sys.getTime() * 1000) / Sys.getTimerResolution();
   }
   
   public void updateFPS() {
      if (getTime() - lastFPS > 1000) {
         fps = frame;
         frame = 0;
         lastFPS += 1000;
      }
      frame++;
   }

   public float getFps() {
      return fps;
   }
}


1  
2  
3  
4  
5  
6  
      while(!Display.isCloseRequested()){
         int delta = timingObj.getDelta();
         
         render();
         tick(delta);
      }
Offline Regenuluz
« Reply #1 - Posted 2014-04-02 08:17:04 »

I'd just pause the game when the window is being resized, and resume once the resize is complete. ^_^
Offline Grunnt

JGO Kernel


Medals: 143
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #2 - Posted 2014-04-02 08:18:05 »

A simplistic but working approach I used to handle these situations is to simply cap the maximum delta. E.g. something like:

1  
2  
3  
4  
5  
6  
7  
8  
   public int getDelta() {
       long time = getTime();
       int delta = Math.min(100, (int) (time - lastFrame));
       lastFrame = time;
 
       return delta;
   }
   


This would simply mean that delta will never be larger than 0.1 second (or any value you prefer). I dont really see a downside to this (if the game runs very slowly things may get a bit choppy because youre throwing away delta time. But hey, by then the game is choppy as hell already so no worries).

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

JGO Kernel


Medals: 143
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #3 - Posted 2014-04-02 08:20:34 »

Also, I highly recommend you take a close look at good timing practices, for example in this article by GaffferOnGames. Generally you want to avoid the tick(delta) function getting a variable delta value because this can mess up physics and other things in many situations.

Pages: [1]
  ignore  |  Print  
 
 

 
Riven (189 views)
2019-09-04 15:33:17

hadezbladez (4876 views)
2018-11-16 13:46:03

hadezbladez (1791 views)
2018-11-16 13:41:33

hadezbladez (5148 views)
2018-11-16 13:35:35

hadezbladez (1018 views)
2018-11-16 13:32:03

EgonOlsen (4377 views)
2018-06-10 19:43:48

EgonOlsen (5220 views)
2018-06-10 19:43:44

EgonOlsen (2949 views)
2018-06-10 19:43:20

DesertCoockie (3868 views)
2018-05-13 18:23:11

nelsongames (4294 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
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!