Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (763)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (852)
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  
  Display.sync equivalent for LWJGL3  (Read 489 times)
0 Members and 1 Guest are viewing this topic.
Offline orange451

JGO Kernel


Medals: 432
Projects: 7
Exp: 7 years


Your face? Your ass? What's the difference?


« Posted 2018-08-02 02:57:23 »

Since LWJGL3 came out a few years ago, I found, and have been using this for synchronizing my game thread hz:
https://pastebin.com/44bMVmWF

It's slightly modified from a code-snippit posted on the LWJGL forums.

This code works fantastically, however it burns my laptop's CPU. I was wondering if there was any good alternatives to achieve the same effect?

First Recon. A java made online first person shooter!
Offline Spasi
« Reply #1 - Posted 2018-08-02 08:53:06 »

Have you tried the code used in LWJGL2?
Offline orange451

JGO Kernel


Medals: 432
Projects: 7
Exp: 7 years


Your face? Your ass? What's the difference?


« Reply #2 - Posted 2018-08-03 03:22:34 »

Works great, Runs much colder. Couldn't have asked for a better code snippit!

Thanks spasi!

[EDIT]
I made a slight modification to it so that it can be called from multiple threads. This is done so I can sync both my game logic thread, and my rendering thread independently:

https://pastebin.com/YqqzYewx

Note that I changed the getTime() method from using LWJGL2's high precision timer to using Java's built-in nanotime. I am not sure whether that is okay, but the results feel fine for both of my threads at any rate.

--

I feel like this should be more known to developers who use LWJGL3. There isn't a built-in solution for synchronizing the timing of a thread with LWJGL3, and that may put off some potential developers who get frusturated with using Thread#sleep()

First Recon. A java made online first person shooter!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Spasi
« Reply #3 - Posted 2018-08-03 15:23:54 »

I made a slight modification to it so that it can be called from multiple threads. This is done so I can sync both my game logic thread, and my rendering thread independently

Not everything has to have a static API. Make the mutable state and the sync method non-static, then use a different Sync instance in each thread. The code will be just as simple as before and you won't have to deal with maps and primitive boxing/unboxing.

I feel like this should be more known to developers who use LWJGL3. There isn't a built-in solution for synchronizing the timing of a thread with LWJGL3, and that may put off some potential developers who get frusturated with using Thread#sleep()

LWJGL 3 does C library bindings and nothing else. It's not a framework or an engine for developing games. If it can be implemented in pure Java, it's outside the scope of LWJGL.
Offline orange451

JGO Kernel


Medals: 432
Projects: 7
Exp: 7 years


Your face? Your ass? What's the difference?


« Reply #4 - Posted 2018-08-03 16:02:18 »

I absolutely understand the decision to keep LWJGL as a set of bindings and nothing else. I agree with it too.
What I was referring to was some convenient way to let developers know of proper thread syncing! Not having it be apart of the LWJGL API.

I bet there's a lot of people using LWJGL3 that have never even considered using something other than Thread#sleep().

First Recon. A java made online first person shooter!
Pages: [1]
  ignore  |  Print  
 
 

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

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

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

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

nelsongames (1023 views)
2018-04-24 18:15:36

nelsongames (1057 views)
2018-04-24 18:14:32

ivj94 (1636 views)
2018-03-24 14:47:39

ivj94 (561 views)
2018-03-24 14:46:31

ivj94 (1442 views)
2018-03-24 14:43:53

Solater (566 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!