added setting graphicsAcceleration

master
Stefan Dollase 2016-02-20 01:46:14 +01:00
parent d3b486296f
commit c3e73bba9e
4 changed files with 76 additions and 69 deletions

View File

@ -3,6 +3,7 @@ package amidst;
import java.io.File;
import java.sql.Timestamp;
import java.util.Date;
import java.util.prefs.Preferences;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
@ -19,6 +20,7 @@ import amidst.gui.crash.CrashWindow;
import amidst.logging.FileLogger;
import amidst.logging.Log;
import amidst.mojangapi.file.DotMinecraftDirectoryNotFoundException;
import amidst.settings.Setting;
@NotThreadSafe
public class Amidst {
@ -38,14 +40,14 @@ public class Amidst {
}
private static void parseCommandLineArgumentsAndRun(String[] args) {
AmidstMetaData metadata = createMetadata();
CommandLineParameters parameters = new CommandLineParameters();
AmidstMetaData metadata = createMetadata();
CmdLineParser parser = new CmdLineParser(parameters, ParserProperties
.defaults().withShowDefaults(false).withUsageWidth(120)
.withOptionSorter(null));
try {
parser.parseArgument(args);
run(metadata, parameters, parser);
run(parameters, metadata, parser);
} catch (CmdLineException e) {
System.out.println(metadata.getVersion().createLongVersionString());
System.err.println(e.getMessage());
@ -65,8 +67,8 @@ public class Amidst {
ResourceLoader.getImage("/amidst/icon/amidst-256x256.png"));
}
private static void run(AmidstMetaData metadata,
CommandLineParameters parameters, CmdLineParser parser) {
private static void run(CommandLineParameters parameters,
AmidstMetaData metadata, CmdLineParser parser) {
initFileLogger(parameters.logFile);
String versionString = metadata.getVersion().createLongVersionString();
if (parameters.printHelp) {
@ -76,17 +78,30 @@ public class Amidst {
System.out.println(versionString);
} else {
Log.i(versionString);
Log.i("Current system time: " + getCurrentTimeStamp());
Log.i(createPropertyString("os.name"));
Log.i(createPropertyString("os.version"));
Log.i(createPropertyString("os.arch"));
Log.i(createPropertyString("java.version"));
Log.i(createPropertyString("java.vendor"));
Log.i(createPropertyString("sun.arch.data.model"));
startApplication(parameters, metadata);
logTimeAndProperties();
AmidstSettings settings = createSettings();
enableGraphicsAccelerationIfNecessary(settings.graphicsAcceleration);
startApplication(parameters, metadata, settings);
}
}
private static void initFileLogger(String filename) {
if (filename != null) {
Log.i("using log file: '" + filename + "'");
Log.addListener("file", new FileLogger(new File(filename)));
}
}
private static void logTimeAndProperties() {
Log.i("Current system time: " + getCurrentTimeStamp());
Log.i(createPropertyString("os.name"));
Log.i(createPropertyString("os.version"));
Log.i(createPropertyString("os.arch"));
Log.i(createPropertyString("java.version"));
Log.i(createPropertyString("java.vendor"));
Log.i(createPropertyString("sun.arch.data.model"));
}
private static String getCurrentTimeStamp() {
return new Timestamp(new Date().getTime()).toString();
}
@ -101,34 +116,30 @@ public class Amidst {
return b.toString();
}
private static void initFileLogger(String filename) {
if (filename != null) {
Log.i("using log file: '" + filename + "'");
Log.addListener("file", new FileLogger(new File(filename)));
private static AmidstSettings createSettings() {
return new AmidstSettings(Preferences.userNodeForPackage(Amidst.class));
}
private static void enableGraphicsAccelerationIfNecessary(Setting<Boolean> graphicsAcceleration) {
if (graphicsAcceleration.get()) {
Log.i("Graphics Acceleration: enabled");
System.setProperty("sun.java2d.opengl", "True");
System.setProperty("sun.java2d.accthreshold", "0");
} else {
Log.i("Graphics Acceleration: disabled");
}
}
private static void startApplication(CommandLineParameters parameters,
AmidstMetaData metadata) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setJava2DEnvironmentVariables();
doStartApplication(parameters, metadata);
}
});
}
private static void setJava2DEnvironmentVariables() {
System.setProperty("sun.java2d.opengl", "True");
System.setProperty("sun.java2d.accthreshold", "0");
private static void startApplication(CommandLineParameters parameters, AmidstMetaData metadata,
AmidstSettings settings) {
SwingUtilities.invokeLater(() -> doStartApplication(parameters, metadata, settings));
}
@CalledOnlyBy(AmidstThread.EDT)
private static void doStartApplication(CommandLineParameters parameters,
AmidstMetaData metadata) {
private static void doStartApplication(CommandLineParameters parameters, AmidstMetaData metadata,
AmidstSettings settings) {
try {
new Application(parameters, metadata).run();
new Application(parameters, metadata, settings).run();
} catch (DotMinecraftDirectoryNotFoundException e) {
Log.w(e.getMessage());
e.printStackTrace();

View File

@ -28,6 +28,7 @@ public class AmidstSettings {
public final Setting<Boolean> showEndCities;
public final Setting<Boolean> enableAllLayers;
public final Setting<Boolean> graphicsAcceleration;
public final Setting<Boolean> smoothScrolling;
public final Setting<Boolean> fragmentFading;
public final Setting<Boolean> maxZoom;
@ -46,29 +47,30 @@ public class AmidstSettings {
@CalledOnlyBy(AmidstThread.EDT)
public AmidstSettings(Preferences preferences) {
// @formatter:off
dimension = Settings.createDimension(preferences, "dimension", Dimension.OVERWORLD);
showGrid = Settings.createBoolean( preferences, "grid", false);
showSlimeChunks = Settings.createBoolean( preferences, "slimeChunks", false);
showSpawn = Settings.createBoolean( preferences, "spawnIcon", true);
showStrongholds = Settings.createBoolean( preferences, "strongholdIcons", true);
showPlayers = Settings.createBoolean( preferences, "playerIcons", true);
showVillages = Settings.createBoolean( preferences, "villageIcons", true);
showTemples = Settings.createBoolean( preferences, "templeIcons", true);
showMineshafts = Settings.createBoolean( preferences, "mineshaftIcons", false);
showOceanMonuments = Settings.createBoolean( preferences, "oceanMonumentIcons", true);
showNetherFortresses = Settings.createBoolean( preferences, "netherFortressIcons", false);
showEndCities = Settings.createBoolean( preferences, "endCityIcons", false);
enableAllLayers = Settings.createBoolean( preferences, "enableAllLayers", false);
dimension = Settings.createDimension(preferences, "dimension", Dimension.OVERWORLD);
showGrid = Settings.createBoolean( preferences, "grid", false);
showSlimeChunks = Settings.createBoolean( preferences, "slimeChunks", false);
showSpawn = Settings.createBoolean( preferences, "spawnIcon", true);
showStrongholds = Settings.createBoolean( preferences, "strongholdIcons", true);
showPlayers = Settings.createBoolean( preferences, "playerIcons", true);
showVillages = Settings.createBoolean( preferences, "villageIcons", true);
showTemples = Settings.createBoolean( preferences, "templeIcons", true);
showMineshafts = Settings.createBoolean( preferences, "mineshaftIcons", false);
showOceanMonuments = Settings.createBoolean( preferences, "oceanMonumentIcons", true);
showNetherFortresses = Settings.createBoolean( preferences, "netherFortressIcons", false);
showEndCities = Settings.createBoolean( preferences, "endCityIcons", false);
enableAllLayers = Settings.createBoolean( preferences, "enableAllLayers", false);
smoothScrolling = Settings.createBoolean( preferences, "mapFlicking", true);
fragmentFading = Settings.createBoolean( preferences, "mapFading", true);
maxZoom = Settings.createBoolean( preferences, "maxZoom", true);
showFPS = Settings.createBoolean( preferences, "showFPS", true);
showScale = Settings.createBoolean( preferences, "showScale", true);
showDebug = Settings.createBoolean( preferences, "showDebug", false);
graphicsAcceleration = Settings.createBoolean( preferences, "graphicsAcceleration", true);
smoothScrolling = Settings.createBoolean( preferences, "mapFlicking", true);
fragmentFading = Settings.createBoolean( preferences, "mapFading", true);
maxZoom = Settings.createBoolean( preferences, "maxZoom", true);
showFPS = Settings.createBoolean( preferences, "showFPS", true);
showScale = Settings.createBoolean( preferences, "showScale", true);
showDebug = Settings.createBoolean( preferences, "showDebug", false);
lastProfile = Settings.createString( preferences, "profile", "");
worldType = Settings.createString( preferences, "worldType", WorldType.PROMPT_EACH_TIME);
lastProfile = Settings.createString( preferences, "profile", "");
worldType = Settings.createString( preferences, "worldType", WorldType.PROMPT_EACH_TIME);
biomeProfileSelection = new BiomeProfileSelection(BiomeProfile.getDefaultProfile());
// @formatter:on
}

View File

@ -1,7 +1,5 @@
package amidst;
import java.util.prefs.Preferences;
import amidst.documentation.AmidstThread;
import amidst.documentation.CalledOnlyBy;
import amidst.documentation.NotThreadSafe;
@ -35,23 +33,18 @@ public class Application {
private volatile MainWindow mainWindow;
@CalledOnlyBy(AmidstThread.EDT)
public Application(CommandLineParameters parameters, AmidstMetaData metadata)
public Application(CommandLineParameters parameters, AmidstMetaData metadata, AmidstSettings settings)
throws DotMinecraftDirectoryNotFoundException,
LocalMinecraftInterfaceCreationException {
this.parameters = parameters;
this.metadata = metadata;
this.settings = createSettings();
this.settings = settings;
this.mojangApi = createMojangApi();
this.biomeProfileDirectory = createBiomeProfileDirectory();
this.viewerFacadeBuilder = createViewerFacadeBuilder();
this.threadMaster = createThreadMaster();
}
@CalledOnlyBy(AmidstThread.EDT)
private AmidstSettings createSettings() {
return new AmidstSettings(Preferences.userNodeForPackage(Amidst.class));
}
@CalledOnlyBy(AmidstThread.EDT)
private MojangApi createMojangApi()
throws DotMinecraftDirectoryNotFoundException,

View File

@ -100,12 +100,13 @@ public class AmidstMenuBuilder {
}
result.addSeparator();
// @formatter:off
Menus.checkbox(result, settings.smoothScrolling, "Smooth Scrolling", "ctrl I");
Menus.checkbox(result, settings.fragmentFading, "Fragment Fading");
Menus.checkbox(result, settings.maxZoom, "Restrict Maximum Zoom", "ctrl Z");
Menus.checkbox(result, settings.showFPS, "Show Framerate", "ctrl L");
Menus.checkbox(result, settings.showScale, "Show Scale", "ctrl K");
Menus.checkbox(result, settings.showDebug, "Show Debug Information");
Menus.checkbox(result, settings.graphicsAcceleration, "Graphics Acceleration", "ctrl A");
Menus.checkbox(result, settings.smoothScrolling, "Smooth Scrolling", "ctrl I");
Menus.checkbox(result, settings.fragmentFading, "Fragment Fading");
Menus.checkbox(result, settings.maxZoom, "Restrict Maximum Zoom", "ctrl Z");
Menus.checkbox(result, settings.showFPS, "Show Framerate", "ctrl L");
Menus.checkbox(result, settings.showScale, "Show Scale", "ctrl K");
Menus.checkbox(result, settings.showDebug, "Show Debug Information");
// @formatter:on
return result;
}