Add GraphicsSettings to retrieve refresh rate (and more).
This commit is contained in:
parent
ddde7ddde3
commit
3e7d54902f
|
@ -8,6 +8,7 @@ import de.teamteamteam.spacescooter.entities.TestEntity;
|
|||
import de.teamteamteam.spacescooter.gui.GameFrame;
|
||||
import de.teamteamteam.spacescooter.threads.PaintThread;
|
||||
import de.teamteamteam.spacescooter.threads.UpdateThread;
|
||||
import de.teamteamteam.spacescooter.utilities.GraphicsSettings;
|
||||
|
||||
/**
|
||||
* Nothing but a class containing the main method.
|
||||
|
@ -21,6 +22,8 @@ public class Main {
|
|||
* @param args Command line arguments.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
GraphicsSettings gs = new GraphicsSettings(); //Get settings
|
||||
|
||||
final GameFrame gf = new GameFrame();
|
||||
|
||||
//Whatever.
|
||||
|
@ -38,7 +41,7 @@ public class Main {
|
|||
|
||||
//Initialize GameThread
|
||||
PaintThread paintThread = new PaintThread(gf);
|
||||
paintThread.setHz(60); //This may be set depending on the system graphic settings.
|
||||
paintThread.setHz(gs.getRefreshRate()); //This may be set depending on the system graphic settings.
|
||||
paintThread.start();
|
||||
|
||||
//Initialize UpdateThread
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
package de.teamteamteam.spacescooter.utilities;
|
||||
|
||||
import java.awt.DisplayMode;
|
||||
import java.awt.GraphicsDevice;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
|
||||
public class GraphicsSettings {
|
||||
|
||||
private int height;
|
||||
private int width;
|
||||
private int refreshRate;
|
||||
private int bitDepth;
|
||||
|
||||
public GraphicsSettings() {
|
||||
this.retrieveSettings();
|
||||
}
|
||||
|
||||
public int getRefreshRate() {
|
||||
return this.refreshRate;
|
||||
}
|
||||
|
||||
public void retrieveSettings() {
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
GraphicsDevice[] gs = ge.getScreenDevices();
|
||||
|
||||
for(int i=0; i < gs.length; i++) {
|
||||
DisplayMode dm = gs[i].getDisplayMode();
|
||||
this.refreshRate = dm.getRefreshRate();
|
||||
if(this.refreshRate == DisplayMode.REFRESH_RATE_UNKNOWN) {
|
||||
System.err.println("[!]Display Mode " + i + ": Unknown refresh rate!");
|
||||
this.refreshRate = 60; //sane default value. :/
|
||||
}
|
||||
this.bitDepth = dm.getBitDepth();
|
||||
this.height = dm.getHeight();
|
||||
this.width = dm.getWidth();
|
||||
|
||||
System.out.println("Display Mode " + i + ": " + this.width + "x" + this.height+ "@" + this.refreshRate + "Hz, " + this.bitDepth + " bit");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue