Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/training-impl
Browse files Browse the repository at this point in the history
  • Loading branch information
tonihele committed Jul 5, 2024
2 parents 29033ed + ac235e8 commit e785bc0
Show file tree
Hide file tree
Showing 14 changed files with 479 additions and 86 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,5 @@ compileJava {
}

wrapper {
gradleVersion = '8.5'
gradleVersion = '8.6'
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
6 changes: 5 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
rootProject.name = 'OpenKeeper'
plugins {
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
}

rootProject.name = 'OpenKeeper'
7 changes: 3 additions & 4 deletions src/toniarts/openkeeper/game/data/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,10 +267,6 @@ private Settings(final AppSettings settings) {
// Init the settings
this.settings = settings;

//Default resolution
if (!this.settings.containsKey("Width") || !this.settings.containsKey("Height")) {
this.settings.setResolution(800, 600); // Default resolution
}
if (Files.exists(USER_SETTINGS_FILE)) {
try (InputStream in = Files.newInputStream(USER_SETTINGS_FILE);
BufferedInputStream bin = new BufferedInputStream(in)) {
Expand All @@ -284,6 +280,9 @@ private Settings(final AppSettings settings) {
// Assing some app level settings
settings.setTitle(TITLE);
settings.setIcons(getApplicationIcons());

// We don't allow this to be changed, assets were not meant to use this
settings.setGammaCorrection(false);
}

/**
Expand Down
15 changes: 7 additions & 8 deletions src/toniarts/openkeeper/game/state/MainMenuScreenController.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.tools.Color;
import de.lessvoid.nifty.tools.SizeValue;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.io.IOException;
import java.lang.System.Logger;
Expand Down Expand Up @@ -84,6 +82,8 @@
import toniarts.openkeeper.tools.convert.map.KwdFile;
import toniarts.openkeeper.tools.modelviewer.SoundsLoader;
import toniarts.openkeeper.utils.AssetUtils;
import toniarts.openkeeper.utils.DisplayMode;
import toniarts.openkeeper.utils.DisplayModeUtils;
import toniarts.openkeeper.utils.PathUtils;
import toniarts.openkeeper.utils.Utils;

Expand Down Expand Up @@ -271,7 +271,7 @@ public void applyGraphicsSettings() {
DropDown aa = screen.findNiftyControl("antialiasing", DropDown.class);
DropDown af = screen.findNiftyControl("anisotropicFiltering", DropDown.class);
CheckBox ssao = screen.findNiftyControl("ssao", CheckBox.class);
MyDisplayMode mdm = (MyDisplayMode) res.getSelection();
DisplayMode mdm = (DisplayMode) res.getSelection();

// TODO: See if we need a restart, but keep in mind that the settings are saved in the restart
// Set the settings
Expand Down Expand Up @@ -568,7 +568,7 @@ private void setScreen(Screen screen) {
}

@NiftyEventSubscriber(id = "resolution")
public void onResolutionChanged(final String id, final DropDownSelectionChangedEvent<MyDisplayMode> event) {
public void onResolutionChanged(final String id, final DropDownSelectionChangedEvent<DisplayMode> event) {

// Set the bit depths
DropDown bitDepth = screen.findNiftyControl("bitDepth", DropDown.class);
Expand Down Expand Up @@ -729,9 +729,8 @@ private void setGraphicsSettingsToGUI() {
// Application settings
AppSettings settings = Main.getUserSettings().getAppSettings();

GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
MyDisplayMode mdm = new MyDisplayMode(settings);
List<MyDisplayMode> resolutions = state.getResolutions(device);
DisplayMode mdm = new DisplayMode(settings);
List<DisplayMode> resolutions = DisplayModeUtils.getInstance().getDisplayModes();
int resolutionSelectedIndex = Collections.binarySearch(resolutions, mdm);

// Get values to the settings screen
Expand Down Expand Up @@ -762,7 +761,7 @@ private void setGraphicsSettingsToGUI() {
// Fullscreen
CheckBox fullscreen = screen.findNiftyControl("fullscreen", CheckBox.class);
fullscreen.setChecked(settings.isFullscreen());
fullscreen.setEnabled(device.isFullScreenSupported());
fullscreen.setEnabled(DisplayModeUtils.getInstance().isFullScreenSupported());

// VSync
CheckBox vsync = screen.findNiftyControl("verticalSync", CheckBox.class);
Expand Down
36 changes: 0 additions & 36 deletions src/toniarts/openkeeper/game/state/MainMenuState.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,12 @@
import com.simsilica.es.EntityData;
import com.simsilica.es.EntityId;
import com.simsilica.es.base.DefaultEntityData;
import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.io.File;
import java.io.IOException;
import java.lang.System.Logger;
import java.lang.System.Logger.Level;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import toniarts.openkeeper.Main;
import static toniarts.openkeeper.Main.getDkIIFolder;
import toniarts.openkeeper.cinematics.CameraSweepData;
Expand Down Expand Up @@ -532,38 +528,6 @@ protected void clearLevelBriefingNarration() {
levelBriefing = null;
}

/**
* Gets the resolutions supported by the given device. The resolutions are
* sorted by their native order
*
* @param device the graphics device to query resolutions from
* @return sorted list of available resolutions
*/
protected List<MyDisplayMode> getResolutions(GraphicsDevice device) {

// Get from the system
DisplayMode[] modes = device.getDisplayModes();

List<MyDisplayMode> displayModes = new ArrayList<>(modes.length);

// Loop them through
for (DisplayMode dm : modes) {

// They may already exist, then just add the possible resfresh rate
MyDisplayMode mdm = new MyDisplayMode(dm);
int index = Collections.binarySearch(displayModes, mdm);
if (index > -1) {
mdm = displayModes.get(index);
mdm.addRefreshRate(dm);
mdm.addBitDepth(dm);
} else {
displayModes.add(~index, mdm);
}
}

return displayModes;
}

public void doDebriefing(GameResult result) {
setEnabled(true);
if (selectedLevel != null && result != null) {
Expand Down
75 changes: 75 additions & 0 deletions src/toniarts/openkeeper/utils/AwtDisplayModeProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2014-2024 OpenKeeper
*
* OpenKeeper is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenKeeper is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenKeeper. If not, see <http://www.gnu.org/licenses/>.
*/
package toniarts.openkeeper.utils;

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.util.ArrayList;
import java.util.List;

/**
* Uses Java's own way of getting available display modes. Often errorenious and
* locks up on MacOS with LWJGL 3
*
* @author Toni Helenius <[email protected]>
*/
class AwtDisplayModeProvider extends DefaultDisplayModeProvider {

public AwtDisplayModeProvider() {
}

@Override
public List<DisplayMode> getDisplayModes() {
GraphicsDevice device = getGraphicsDevice();

java.awt.DisplayMode[] modes = device.getDisplayModes();

List<DisplayMode> displayModes = new ArrayList<>(modes.length);

// Loop them through
for (java.awt.DisplayMode dm : modes) {
DisplayMode mdm = getDisplayMode(dm);
addDisplayMode(displayModes, mdm);
}

return displayModes;
}

private GraphicsDevice getGraphicsDevice() {
return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
}

private DisplayMode getDisplayMode(java.awt.DisplayMode dm) {
DisplayMode displayMode = new DisplayMode(dm.getWidth(), dm.getHeight());
if (dm.getRefreshRate() != java.awt.DisplayMode.REFRESH_RATE_UNKNOWN) {
displayMode.addRefreshRate(dm.getRefreshRate());
}
if (dm.getBitDepth() != java.awt.DisplayMode.BIT_DEPTH_MULTI) {
displayMode.addBitDepth(dm.getBitDepth());
}

return displayMode;
}

@Override
public boolean isFullScreenSupported() {
GraphicsDevice device = getGraphicsDevice();

return device.isFullScreenSupported();
}

}
44 changes: 44 additions & 0 deletions src/toniarts/openkeeper/utils/DefaultDisplayModeProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2014-2024 OpenKeeper
*
* OpenKeeper is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenKeeper is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenKeeper. If not, see <http://www.gnu.org/licenses/>.
*/
package toniarts.openkeeper.utils;

import java.util.Collections;
import java.util.List;

/**
* Simple groups some common methods for display mode providers
*
* @author Toni Helenius <[email protected]>
*/
abstract class DefaultDisplayModeProvider implements DisplayModeProvider {

protected void addDisplayMode(List<DisplayMode> displayModes, DisplayMode mdm) {
int index = Collections.binarySearch(displayModes, mdm);
if (index > -1) {
DisplayMode existingDm = displayModes.get(index);
for (Integer refreshRate : mdm.getRefreshRates()) {
existingDm.addRefreshRate(refreshRate);
}
for (Integer bitDepth : mdm.getBitDepths()) {
existingDm.addBitDepth(bitDepth);
}
} else {
displayModes.add(~index, mdm);
}
}

}
Loading

0 comments on commit e785bc0

Please sign in to comment.