Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hardware acceleration setting #524

Merged
merged 7 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/client/java/minicraft/core/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public static void main(String[] args) {

Analytics.GameStartup.ping();

new Load(true, true); // This loads basic saved preferences.
// Reference: https://stackoverflow.com/a/13832805
if ((boolean) Settings.get("hardwareacc")) System.setProperty("sun.java2d.opengl", "true");
MAX_FPS = (int) Settings.get("fps"); // DO NOT put this above.

input = new InputHandler(Renderer.canvas);

ResourcePackDisplay.initPacks();
Expand All @@ -102,8 +107,7 @@ public static void main(String[] args) {

World.resetGame(); // "half"-starts a new game, to set up initial variables
player.eid = 0;
new Load(true); // This loads any saved preferences.
MAX_FPS = (int) Settings.get("fps"); // DO NOT put this above.
new Load(true, false); // This loads any saved preferences.

// Update fullscreen frame if Updater.FULLSCREEN was updated previously
if (Updater.FULLSCREEN) {
Expand Down
1 change: 1 addition & 0 deletions src/client/java/minicraft/core/io/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public final class Settings {

options.put("sound", new BooleanEntry("minicraft.settings.sound", true));
options.put("autosave", new BooleanEntry("minicraft.settings.autosave", true));
options.put("hardwareacc", new BooleanEntry("minicraft.settings.hardware_acceleration", true));

options.put("size", new ArrayEntry<>("minicraft.settings.size", 128, 256, 512));
options.put("theme", new ArrayEntry<>("minicraft.settings.theme", "minicraft.settings.theme.normal", "minicraft.settings.theme.forest", "minicraft.settings.theme.desert", "minicraft.settings.theme.plain", "minicraft.settings.theme.hell"));
Expand Down
19 changes: 13 additions & 6 deletions src/client/java/minicraft/saveload/Load.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ public Load(String worldname, boolean loadGame) {

public Load() { this(Game.VERSION); }
public Load(Version worldVersion) {
this(false);
this(false, false);
worldVer = worldVersion;
}
public Load(boolean loadConfig) {
public Load(boolean loadConfig, boolean partialLoad) {
if (!loadConfig) return;
boolean resave = false;

Expand All @@ -205,11 +205,11 @@ public Load(boolean loadConfig) {

// Check if Preferences.json exists. (new version)
if (new File(location + "Preferences.json").exists()) {
loadPrefs("Preferences");
loadPrefs("Preferences", partialLoad);

// Check if Preferences.miniplussave exists. (old version)
} else if (new File(location + "Preferences" + extension).exists()) {
loadPrefsOld("Preferences");
loadPrefsOld("Preferences", partialLoad);
Logging.SAVELOAD.info("Upgrading preferences to JSON.");
resave = true;

Expand All @@ -219,6 +219,8 @@ public Load(boolean loadConfig) {
resave = true;
}

if (partialLoad) return; // Partial loading only loads partial preferences

// Load unlocks. (new version)
File testFileOld = new File(location + "unlocks" + extension);
File testFile = new File(location + "Unlocks" + extension);
Expand Down Expand Up @@ -425,7 +427,7 @@ private void loadMode(String modedata) {
Settings.setIdx("mode", mode);
}

private void loadPrefsOld(String filename) {
private void loadPrefsOld(String filename, boolean partialLoad) {
loadFromFile(location + filename + extension);
Version prefVer = new Version("2.0.2"); // the default, b/c this doesn't really matter much being specific past this if it's not set below.

Expand All @@ -438,6 +440,8 @@ private void loadPrefsOld(String filename) {
if (prefVer.compareTo(new Version("2.0.4-dev2")) >= 0)
Settings.set("fps", Integer.parseInt(data.remove(0)));

if (partialLoad) return; // Partial loading only loads basic settings.

SkinDisplay.releaseSkins();

// Get legacy language and convert it into the current format.
Expand Down Expand Up @@ -502,7 +506,7 @@ private void loadPrefsOld(String filename) {
}
}

private void loadPrefs(String filename) {
private void loadPrefs(String filename, boolean partialLoad) {
JSONObject json;
try {
json = new JSONObject(loadFromFile(location + filename + ".json", false));
Expand All @@ -519,6 +523,9 @@ private void loadPrefs(String filename) {
Settings.set("autosave", json.getBoolean("autosave"));
Settings.set("fps", json.getInt("fps"));
Settings.set("showquests", json.optBoolean("showquests", true));
Settings.set("hardwareacc", json.optBoolean("hardwareacc", true));

if (partialLoad) return; // Partial loading only loads basic settings.

if (json.has("lang")) {
String lang = json.getString("lang");
Expand Down
1 change: 1 addition & 0 deletions src/client/java/minicraft/saveload/Save.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ private void writePrefs() {
json.put("keymap", new JSONArray(Game.input.getKeyPrefs()));
json.put("resourcePacks", new JSONArray(ResourcePackDisplay.getLoadedPacks()));
json.put("showquests", String.valueOf(Settings.get("showquests")));
json.put("hardwareacc", String.valueOf(Settings.get("hardwareacc")));

// Save json
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public OptionsMainMenuDisplay() {
Settings.getEntry("fps"),
Settings.getEntry("sound"),
Settings.getEntry("showquests"),
Settings.getEntry("hardwareacc"),
new SelectEntry("minicraft.display.options_display.change_key_bindings", () -> Game.setDisplay(new KeyInputDisplay())),
new SelectEntry("minicraft.displays.controls", () -> Game.setDisplay(new ControlsDisplay())),
new SelectEntry("minicraft.display.options_display.language", () -> Game.setDisplay(new LanguageSettingsDisplay())),
Expand Down