0

Fix shell scripts, display settings.

This commit is contained in:
Ethan Lee
2012-12-06 19:09:58 -05:00
parent e91408ad6f
commit 41301a2aac
3 changed files with 62 additions and 41 deletions

View File

@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# Move to script's directory # Move to script's directory
cd `dirname $0` cd "`dirname "$0"`"
# Get the kernel information # Get the kernel information
UNAME=`uname` UNAME=`uname`
@@ -14,4 +14,4 @@ elif [ "$UNAME" == "Linux" ]; then
fi fi
# Run it! # Run it!
java -jar lwjake2.jar $@ java -jar lwjake2.jar $@

View File

@@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# Move to script's directory # Move to script's directory
cd `dirname $0` cd "`dirname "$0"`"
# Get the kernel information # Get the kernel information
UNAME=`uname` UNAME=`uname`
@@ -14,4 +14,4 @@ elif [ "$UNAME" == "Linux" ]; then
fi fi
# Run the server! # Run the server!
java -jar lwjake2.jar +set dedicated 1 $@ java -jar lwjake2.jar +set dedicated 1 $@

View File

@@ -25,6 +25,7 @@ import lwjake2.game.cvar_t;
import lwjake2.qcommon.xcommand_t; import lwjake2.qcommon.xcommand_t;
import java.awt.Dimension; import java.awt.Dimension;
import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLException;
@@ -107,37 +108,57 @@ public abstract class LWJGLBase {
public DisplayMode[] getLWJGLModeList() { public DisplayMode[] getLWJGLModeList() {
try { try {
DisplayMode[] modes = Display.getAvailableDisplayModes(); // Return value storage.
ArrayList<DisplayMode> displayModes;
LinkedList<DisplayMode> l = new LinkedList<DisplayMode>(); // Get all possible display modes.
l.add(oldDisplayMode); DisplayMode[] allDisplayModes = Display.getAvailableDisplayModes();
for (int i = 0; i < modes.length; i++) { // Cut down all the ones with a height below 240.
DisplayMode m = modes[i]; displayModes = new ArrayList<DisplayMode>();
for (int x = 0; x < allDisplayModes.length; x++) {
if (m.getBitsPerPixel() != oldDisplayMode.getBitsPerPixel()) continue; if (allDisplayModes[x].getHeight() >= 240)
if (m.getFrequency() > oldDisplayMode.getFrequency()) continue; displayModes.add(allDisplayModes[x]);
if (m.getHeight() < 240 || m.getWidth() < 320) continue;
int j = 0;
DisplayMode ml = null;
for (j = 0; j < l.size(); j++) {
ml = (DisplayMode)l.get(j);
if (ml.getWidth() > m.getWidth()) break;
if (ml.getWidth() == m.getWidth() && ml.getHeight() >= m.getHeight()) break;
}
if (j == l.size()) {
l.addLast(m);
} else if (ml.getWidth() > m.getWidth() || ml.getHeight() > m.getHeight()) {
l.add(j, m);
} else if (m.getFrequency() > ml.getFrequency()){
l.remove(j);
l.add(j, m);
}
} }
DisplayMode[] ma = new DisplayMode[l.size()];
l.toArray(ma); // Gnome sort the display modes by height, width, and refresh rate.
return ma; int currentSpot = 0;
boolean needSwap = false;
DisplayMode tempStore;
while (currentSpot < displayModes.size() - 1) {
// Check DisplayMode heights.
if (displayModes.get(currentSpot).getHeight() > displayModes.get(currentSpot + 1).getHeight())
needSwap = true;
else if (displayModes.get(currentSpot).getHeight() == displayModes.get(currentSpot + 1).getHeight()) {
// Check DisplayMode widths.
if (displayModes.get(currentSpot).getWidth() > displayModes.get(currentSpot + 1).getWidth())
needSwap = true;
else if (displayModes.get(currentSpot).getWidth() == displayModes.get(currentSpot + 1).getWidth())
// Doesn't sort frequencies, but removes the lesser ones entirely.
if (displayModes.get(currentSpot).getFrequency() < displayModes.get(currentSpot + 1).getFrequency()) {
displayModes.remove(currentSpot);
currentSpot--;
}
else if (displayModes.get(currentSpot).getFrequency() > displayModes.get(currentSpot + 1).getFrequency()) {
displayModes.remove(currentSpot + 1);
currentSpot--;
}
}
if (needSwap) {
needSwap = false;
tempStore = displayModes.get(currentSpot);
displayModes.set(currentSpot, displayModes.get(currentSpot + 1));
displayModes.set(currentSpot + 1, tempStore);
if (currentSpot > 0)
currentSpot--;
}
else
currentSpot++;
}
// Return the array.
return displayModes.toArray(new DisplayMode[displayModes.size()]);
} catch (LWJGLException e) { } catch (LWJGLException e) {
e.printStackTrace(); e.printStackTrace();
System.exit(0); System.exit(0);
@@ -226,7 +247,7 @@ public abstract class LWJGLBase {
Display.setLocation(0,0); Display.setLocation(0,0);
try { try {
Display.setFullscreen(fullscreen); Display.setFullscreen(true);
} }
catch (LWJGLException e) catch (LWJGLException e)
{ {
@@ -238,6 +259,14 @@ public abstract class LWJGLBase {
} }
else else
{ {
try {
Display.setFullscreen(false);
}
catch (LWJGLException e)
{
return rserr_invalid_fullscreen;
}
try try
{ {
Display.setDisplayMode(displayMode); Display.setDisplayMode(displayMode);
@@ -246,14 +275,6 @@ public abstract class LWJGLBase {
{ {
return rserr_invalid_mode; return rserr_invalid_mode;
} }
try {
Display.setFullscreen(false);
}
catch (LWJGLException e)
{
return rserr_invalid_fullscreen;
}
Display.setLocation(window_xpos, window_ypos); Display.setLocation(window_xpos, window_ypos);
} }