From 236b34ef6761eb4c0d5080d781e72b4b81c2d9ce Mon Sep 17 00:00:00 2001 From: Ethan Lee Date: Tue, 7 Feb 2012 03:31:09 -0500 Subject: [PATCH] - Resolved all Eclipse warnings. The only compiler warning left is sun.misc.Perf-related. - Fixed a bug where menu.lst in baseq2 was not picked up. The order it checks is now the user folder, then baseq2, then the pak files. - Fixed a bug where it would not find all of the skins for a model. --- src/lwjake2/client/Key.java | 6 +-- src/lwjake2/client/Menu.java | 57 +++++++++++------------ src/lwjake2/game/Cmd.java | 14 +++--- src/lwjake2/game/GameSave.java | 15 ++---- src/lwjake2/qcommon/FS.java | 38 +++++++-------- src/lwjake2/qcommon/longjmpException.java | 3 +- src/lwjake2/render/Renderer.java | 10 ++-- src/lwjake2/render/lwjgl/LWJGLBase.java | 4 +- src/lwjake2/sound/S.java | 10 ++-- src/lwjake2/sound/lwjgl/Channel.java | 12 ++--- src/lwjake2/sys/HighPrecisionTimer.java | 2 + src/lwjake2/util/PrintfFormat.java | 16 +++---- src/lwjake2/util/Vargs.java | 6 ++- 13 files changed, 95 insertions(+), 98 deletions(-) diff --git a/src/lwjake2/client/Key.java b/src/lwjake2/client/Key.java index d79a456..c387614 100644 --- a/src/lwjake2/client/Key.java +++ b/src/lwjake2/client/Key.java @@ -664,7 +664,7 @@ public class Key extends Globals { } - private static void printCompletions(String type, Vector compl) { + private static void printCompletions(String type, Vector compl) { Com.Printf(type); for (int i = 0; i < compl.size(); i++) { Com.Printf((String)compl.get(i) + " "); @@ -683,8 +683,8 @@ public class Key extends Globals { String s = new String(key_lines[edit_line], start, end-start); - Vector cmds = Cmd.CompleteCommand(s); - Vector vars = Cvar.CompleteVariable(s); + Vector cmds = Cmd.CompleteCommand(s); + Vector vars = Cvar.CompleteVariable(s); int c = cmds.size(); int v = vars.size(); diff --git a/src/lwjake2/client/Menu.java b/src/lwjake2/client/Menu.java index 10b3e59..d529638 100644 --- a/src/lwjake2/client/Menu.java +++ b/src/lwjake2/client/Menu.java @@ -2172,16 +2172,11 @@ public final class Menu extends Key { try { f = new QuakeFile(name, "r"); - if (f == null) { - m_savestrings[i] = ""; - m_savevalid[i] = false; - } else { - String str = f.readString(); - if (str != null) - m_savestrings[i] = str; - f.close(); - m_savevalid[i] = true; - } + String str = f.readString(); + if (str != null) + m_savestrings[i] = str; + f.close(); + m_savevalid[i] = true; } catch (Exception e) { m_savestrings[i] = ""; m_savevalid[i] = false; @@ -2707,12 +2702,24 @@ public final class Menu extends Key { */ mapsname = FS.Gamedir() + "/maps.lst"; + // Check user dir first (default ~/.lwjake2) if ((fp = Lib.fopen(mapsname, "r")) == null) { - buffer = FS.LoadFile("maps.lst"); - if (buffer == null) - //if ((length = FS_LoadFile("maps.lst", (Object *) & buffer)) - // == -1) - Com.Error(ERR_DROP, "couldn't find maps.lst\n"); + // Check base dir first (baseq2 folder) + mapsname = FS.BaseGamedir() + "/maps.lst"; + if ((fp = Lib.fopen(mapsname, "r")) == null) { + // Open the pak's maplist + buffer = FS.LoadFile("maps.lst"); + if (buffer == null) + Com.Error(ERR_DROP, "couldn't find maps.lst\n"); + } else { + try { + int len = (int) fp.length(); + buffer = new byte[len]; + fp.readFully(buffer); + } catch (Exception e) { + Com.Error(ERR_DROP, "couldn't load maps.lst\n"); + } + } } else { try { int len = (int) fp.length(); @@ -3804,18 +3811,12 @@ public final class Menu extends Key { pcxnames = FS.ListFiles(scratch, 0, 0); npcxfiles = pcxnames.length; - if (pcxnames == null) { - - dirnames[i] = null; - continue; - } - // count valid skins, which consist of a skin with a matching "_i" // icon for (k = 0; k < npcxfiles - 1; k++) { if (!pcxnames[k].endsWith("_i.pcx")) { //if (!strstr(pcxnames[k], "_i.pcx")) { - if (IconOfSkinExists(pcxnames[k], pcxnames, npcxfiles - 1)) { + if (IconOfSkinExists(pcxnames[k], pcxnames, npcxfiles)) { nskins++; } } @@ -3828,10 +3829,10 @@ public final class Menu extends Key { //memset(skinnames, 0, sizeof(String) * (nskins + 1)); // copy the valid skins - for (s = 0, k = 0; k < npcxfiles - 1; k++) { + for (s = 0, k = 0; k < npcxfiles; k++) { if (pcxnames[k].indexOf("_i.pcx") < 0) { - if (IconOfSkinExists(pcxnames[k], pcxnames, npcxfiles - 1)) { + if (IconOfSkinExists(pcxnames[k], pcxnames, npcxfiles)) { a = pcxnames[k].lastIndexOf('/'); b = pcxnames[k].lastIndexOf('\\'); @@ -3878,9 +3879,7 @@ public final class Menu extends Key { } - static int pmicmpfnc(Object _a, Object _b) { - playermodelinfo_s a = (playermodelinfo_s) _a; - playermodelinfo_s b = (playermodelinfo_s) _b; + static int pmicmpfnc(playermodelinfo_s a, playermodelinfo_s b) { /* * * sort by male, female, then alphabetical @@ -3938,8 +3937,8 @@ public final class Menu extends Key { } //qsort(s_pmi, s_numplayermodels, sizeof(s_pmi[0]), pmicmpfnc); - Arrays.sort(s_pmi, 0, s_numplayermodels, new Comparator() { - public int compare(Object o1, Object o2) { + Arrays.sort(s_pmi, 0, s_numplayermodels, new Comparator() { + public int compare(playermodelinfo_s o1, playermodelinfo_s o2) { return pmicmpfnc(o1, o2); } }); diff --git a/src/lwjake2/game/Cmd.java b/src/lwjake2/game/Cmd.java index ebf24f8..07da4f8 100644 --- a/src/lwjake2/game/Cmd.java +++ b/src/lwjake2/game/Cmd.java @@ -162,13 +162,11 @@ public final class Cmd { private static char temporary[] = new char[Defines.MAX_STRING_CHARS]; - public static Comparator PlayerSort = new Comparator() { - public int compare(Object o1, Object o2) { - int anum = ((Integer) o1).intValue(); - int bnum = ((Integer) o2).intValue(); + public static Comparator PlayerSort = new Comparator() { + public int compare(Integer o1, Integer o2) { - int anum1 = GameBase.game.clients[anum].ps.stats[Defines.STAT_FRAGS]; - int bnum1 = GameBase.game.clients[bnum].ps.stats[Defines.STAT_FRAGS]; + int anum1 = GameBase.game.clients[o1].ps.stats[Defines.STAT_FRAGS]; + int bnum1 = GameBase.game.clients[o2].ps.stats[Defines.STAT_FRAGS]; if (anum1 < bnum1) return -1; @@ -1183,8 +1181,8 @@ public final class Cmd { /** * Cmd_CompleteCommand. */ - public static Vector CompleteCommand(String partial) { - Vector cmds = new Vector(); + public static Vector CompleteCommand(String partial) { + Vector cmds = new Vector(); // check for match for (cmd_function_t cmd = cmd_functions; cmd != null; cmd = cmd.next) diff --git a/src/lwjake2/game/GameSave.java b/src/lwjake2/game/GameSave.java index ebd9cba..375507b 100644 --- a/src/lwjake2/game/GameSave.java +++ b/src/lwjake2/game/GameSave.java @@ -232,10 +232,7 @@ public class GameSave { if (!autosave) PlayerClient.SaveClientData(); - f = new QuakeFile(filename, "rw"); - - if (f == null) - GameBase.gi.error("Couldn't write to " + filename); + f = new QuakeFile(filename, "rw"); GameBase.game.autosaved = autosave; GameBase.game.write(f); @@ -247,6 +244,7 @@ public class GameSave { Lib.fclose(f); } catch (Exception e) { e.printStackTrace(); + GameBase.gi.error("Couldn't write to " + filename); } } @@ -284,9 +282,7 @@ public class GameSave { QuakeFile f; f = new QuakeFile(filename, "rw"); - if (f == null) - GameBase.gi.error("Couldn't open for writing: " + filename); - + // write out level_locals_t GameBase.level.write(f); @@ -305,6 +301,7 @@ public class GameSave { f.close(); } catch (Exception e) { e.printStackTrace(); + GameBase.gi.error("Couldn't open for writing: " + filename); } } @@ -327,9 +324,6 @@ public class GameSave { QuakeFile f = new QuakeFile(filename, "r"); - if (f == null) - GameBase.gi.error("Couldn't read level file " + filename); - // wipe all the entities CreateEdicts(); @@ -376,6 +370,7 @@ public class GameSave { } } catch (Exception e) { e.printStackTrace(); + GameBase.gi.error("Couldn't read level file " + filename); } } } \ No newline at end of file diff --git a/src/lwjake2/qcommon/FS.java b/src/lwjake2/qcommon/FS.java index 41418bb..69d5e78 100644 --- a/src/lwjake2/qcommon/FS.java +++ b/src/lwjake2/qcommon/FS.java @@ -75,7 +75,7 @@ public final class FS extends Globals { int numfiles; - Hashtable files; // with packfile_t entries + Hashtable files; // with packfile_t entries } public static String fs_gamedir; @@ -97,7 +97,7 @@ public final class FS extends Globals { } // with filelink_t entries - public static List fs_links = new LinkedList(); + public static List fs_links = new LinkedList(); public static class searchpath_t { String filename; @@ -171,8 +171,8 @@ public final class FS extends Globals { file_from_pak = 0; // check for links first - for (Iterator it = fs_links.iterator(); it.hasNext();) { - link = (filelink_t) it.next(); + for (Iterator it = fs_links.iterator(); it.hasNext();) { + link = it.next(); if (filename.regionMatches(0, link.from, 0, link.fromlength)) { netpath = link.to + filename.substring(link.fromlength); @@ -193,7 +193,7 @@ public final class FS extends Globals { // look through all the pak file elements pak = search.pack; filename = filename.toLowerCase(); - packfile_t entry = (packfile_t) pak.files.get(filename); + packfile_t entry = pak.files.get(filename); if (entry != null) { // found it! @@ -244,8 +244,8 @@ public final class FS extends Globals { file_from_pak = 0; // check for links first - for (Iterator it = fs_links.iterator(); it.hasNext();) { - link = (filelink_t) it.next(); + for (Iterator it = fs_links.iterator(); it.hasNext();) { + link = it.next(); // if (!strncmp (filename, link->from, link->fromlength)) if (filename.regionMatches(0, link.from, 0, link.fromlength)) { @@ -268,7 +268,7 @@ public final class FS extends Globals { // look through all the pak file elements pak = search.pack; filename = filename.toLowerCase(); - packfile_t entry = (packfile_t) pak.files.get(filename); + packfile_t entry = pak.files.get(filename); if (entry != null) { // found it! @@ -402,8 +402,8 @@ public final class FS extends Globals { try { // check for links first - for (Iterator it = fs_links.iterator(); it.hasNext();) { - link = (filelink_t) it.next(); + for (Iterator it = fs_links.iterator(); it.hasNext();) { + link = it.next(); if (filename.regionMatches(0, link.from, 0, link.fromlength)) { netpath = link.to + filename.substring(link.fromlength); @@ -430,7 +430,7 @@ public final class FS extends Globals { // look through all the pak file elements pak = search.pack; filename = filename.toLowerCase(); - packfile_t entry = (packfile_t) pak.files.get(filename); + packfile_t entry = pak.files.get(filename); if (entry != null) { // found it! @@ -521,7 +521,7 @@ public final class FS extends Globals { static pack_t LoadPackFile(String packfile) { dpackheader_t header; - Hashtable newfiles; + Hashtable newfiles; RandomAccessFile file; int numpackfiles = 0; pack_t pack = null; @@ -552,7 +552,7 @@ public final class FS extends Globals { Com.Error(Defines.ERR_FATAL, packfile + " has " + numpackfiles + " files"); - newfiles = new Hashtable(numpackfiles); + newfiles = new Hashtable(numpackfiles); packhandle.position(header.dirofs); @@ -742,8 +742,8 @@ public final class FS extends Globals { } // see if the link already exists - for (Iterator it = fs_links.iterator(); it.hasNext();) { - entry = (filelink_t) it.next(); + for (Iterator it = fs_links.iterator(); it.hasNext();) { + entry = it.next(); if (entry.from.equals(Cmd.Argv(1))) { if (Cmd.Argv(2).length() < 1) { @@ -770,7 +770,7 @@ public final class FS extends Globals { * ListFiles */ public static String[] ListFiles(String findname, int musthave, int canthave) { - String[] list = null; + String[] list = new String[0]; File[] files = Sys.FindAll(findname, musthave, canthave); @@ -810,7 +810,7 @@ public final class FS extends Globals { dirnames = ListFiles(findname, 0, 0); - if (dirnames != null) { + if (dirnames.length != 0) { int index = 0; for (int i = 0; i < dirnames.length; i++) { if ((index = dirnames[i].lastIndexOf('/')) > 0) { @@ -846,8 +846,8 @@ public final class FS extends Globals { } Com.Printf("\nLinks:\n"); - for (Iterator it = fs_links.iterator(); it.hasNext();) { - link = (filelink_t) it.next(); + for (Iterator it = fs_links.iterator(); it.hasNext();) { + link = it.next(); Com.Printf(link.from + " : " + link.to + '\n'); } } diff --git a/src/lwjake2/qcommon/longjmpException.java b/src/lwjake2/qcommon/longjmpException.java index 38bd92f..ac69426 100644 --- a/src/lwjake2/qcommon/longjmpException.java +++ b/src/lwjake2/qcommon/longjmpException.java @@ -21,6 +21,7 @@ package lwjake2.qcommon; /** * longjmpException is used to replace the setjmp/longjmp code. */ +@SuppressWarnings("serial") public final class longjmpException extends IllegalStateException { -} +} \ No newline at end of file diff --git a/src/lwjake2/render/Renderer.java b/src/lwjake2/render/Renderer.java index 3c29acb..fdbbf44 100644 --- a/src/lwjake2/render/Renderer.java +++ b/src/lwjake2/render/Renderer.java @@ -29,7 +29,7 @@ import java.util.Vector; */ public class Renderer { - static Vector drivers = new Vector(1); + static Vector drivers = new Vector(1); static { try { @@ -62,7 +62,7 @@ public class Renderer { Ref driver = null; int count = drivers.size(); for (int i = 0; i < count; i++) { - driver = (Ref) drivers.get(i); + driver = drivers.get(i); if (driver.getName().equals(driverName)) { return driver.GetRefAPI(); } @@ -72,11 +72,11 @@ public class Renderer { } public static String getDefaultName() { - return (drivers.isEmpty()) ? null : ((Ref) drivers.firstElement()).getName(); + return (drivers.isEmpty()) ? null : (drivers.firstElement()).getName(); } public static String getPreferedName() { - return (drivers.isEmpty()) ? null : ((Ref) drivers.lastElement()).getName(); + return (drivers.isEmpty()) ? null : (drivers.lastElement()).getName(); } public static String[] getDriverNames() { @@ -84,7 +84,7 @@ public class Renderer { int count = drivers.size(); String[] names = new String[count]; for (int i = 0; i < count; i++) { - names[i] = ((Ref) drivers.get(i)).getName(); + names[i] = (drivers.get(i)).getName(); } return names; } diff --git a/src/lwjake2/render/lwjgl/LWJGLBase.java b/src/lwjake2/render/lwjgl/LWJGLBase.java index f47658a..c1e931e 100644 --- a/src/lwjake2/render/lwjgl/LWJGLBase.java +++ b/src/lwjake2/render/lwjgl/LWJGLBase.java @@ -69,7 +69,7 @@ public abstract class LWJGLBase { modes = Display.getAvailableDisplayModes(); - LinkedList l = new LinkedList(); + LinkedList l = new LinkedList(); l.add(toAwtDisplayMode(oldDisplayMode)); for (int i = 0; i < modes.length; i++) { @@ -109,7 +109,7 @@ public abstract class LWJGLBase { try { DisplayMode[] modes = Display.getAvailableDisplayModes(); - LinkedList l = new LinkedList(); + LinkedList l = new LinkedList(); l.add(oldDisplayMode); for (int i = 0; i < modes.length; i++) { diff --git a/src/lwjake2/sound/S.java b/src/lwjake2/sound/S.java index 0986542..deac602 100644 --- a/src/lwjake2/sound/S.java +++ b/src/lwjake2/sound/S.java @@ -34,7 +34,7 @@ public class S { static Sound impl; static cvar_t s_impl; - static Vector drivers = new Vector(1); + static Vector drivers = new Vector(1); /** * Searches for and initializes all known sound drivers. @@ -78,14 +78,14 @@ public class S { Sound driver = null; int count = drivers.size(); for (int i = 0; i < count; i++) { - driver = (Sound) drivers.get(i); + driver = drivers.get(i); if (driver.getName().equals(driverName)) { impl = driver; return; } } // if driver not found use dummy - impl = (Sound)drivers.lastElement(); + impl = drivers.lastElement(); } /** @@ -105,7 +105,7 @@ public class S { // set the last registered driver as default String defaultDriver = "dummy"; if (drivers.size() > 1){ - defaultDriver = ((Sound)drivers.lastElement()).getName(); + defaultDriver = (drivers.lastElement()).getName(); } s_impl = Cvar.Get("s_impl", defaultDriver, Defines.CVAR_ARCHIVE); @@ -203,7 +203,7 @@ public class S { public static String[] getDriverNames() { String[] names = new String[drivers.size()]; for (int i = 0; i < names.length; i++) { - names[i] = ((Sound)drivers.get(i)).getName(); + names[i] = (drivers.get(i)).getName(); } return names; } diff --git a/src/lwjake2/sound/lwjgl/Channel.java b/src/lwjake2/sound/lwjgl/Channel.java index 690abbd..b135c23 100644 --- a/src/lwjake2/sound/lwjgl/Channel.java +++ b/src/lwjake2/sound/lwjgl/Channel.java @@ -56,7 +56,7 @@ public class Channel { private static IntBuffer sources = Lib.newIntBuffer(MAX_CHANNELS); // a reference of LWJGLSoundImpl.buffers private static IntBuffer buffers; - private static Map looptable = new Hashtable(MAX_CHANNELS); + private static Map looptable = new Hashtable(MAX_CHANNELS); private static int numChannels; @@ -362,7 +362,7 @@ public class Channel { sfxcache_t sc; int num; entity_state_t ent; - Object key; + int key; int sound = 0; for (int i=0 ; i iter = looptable.values().iterator(); iter.hasNext();) { + ch = iter.next(); if (!ch.autosound) { AL10.alSourceStop(ch.sourceId); AL10.alSourcei(ch.sourceId, AL10.AL_LOOPING, AL10.AL_FALSE); diff --git a/src/lwjake2/sys/HighPrecisionTimer.java b/src/lwjake2/sys/HighPrecisionTimer.java index 6eb7cc5..762a0e2 100644 --- a/src/lwjake2/sys/HighPrecisionTimer.java +++ b/src/lwjake2/sys/HighPrecisionTimer.java @@ -20,6 +20,8 @@ package lwjake2.sys; import sun.misc.Perf; +// TODO: Is there an alternative to sun.misc.Perf? - flibit + class HighPrecisionTimer extends Timer { private Perf perf = Perf.getPerf(); diff --git a/src/lwjake2/util/PrintfFormat.java b/src/lwjake2/util/PrintfFormat.java index 66741ee..bd55796 100644 --- a/src/lwjake2/util/PrintfFormat.java +++ b/src/lwjake2/util/PrintfFormat.java @@ -545,7 +545,7 @@ public class PrintfFormat { * @return The formatted String. */ public String sprintf(Object[] o) { - Enumeration e = vFmt.elements(); + Enumeration e = vFmt.elements(); ConversionSpecification cs = null; char c = 0; int i = 0; @@ -607,7 +607,7 @@ public class PrintfFormat { * @return the formatted String. */ public String sprintf() { - Enumeration e = vFmt.elements(); + Enumeration e = vFmt.elements(); ConversionSpecification cs = null; char c = 0; StringBuffer sb = new StringBuffer(); @@ -630,7 +630,7 @@ public class PrintfFormat { * or S. */ public String sprintf(int x) throws IllegalArgumentException { - Enumeration e = vFmt.elements(); + Enumeration e = vFmt.elements(); ConversionSpecification cs = null; char c = 0; StringBuffer sb = new StringBuffer(); @@ -655,7 +655,7 @@ public class PrintfFormat { * or S. */ public String sprintf(long x) throws IllegalArgumentException { - Enumeration e = vFmt.elements(); + Enumeration e = vFmt.elements(); ConversionSpecification cs = null; char c = 0; StringBuffer sb = new StringBuffer(); @@ -680,7 +680,7 @@ public class PrintfFormat { * d, d, x, X, or o. */ public String sprintf(double x) throws IllegalArgumentException { - Enumeration e = vFmt.elements(); + Enumeration e = vFmt.elements(); ConversionSpecification cs = null; char c = 0; StringBuffer sb = new StringBuffer(); @@ -704,7 +704,7 @@ public class PrintfFormat { * conversion character is neither s nor S. */ public String sprintf(String x) throws IllegalArgumentException { - Enumeration e = vFmt.elements(); + Enumeration e = vFmt.elements(); ConversionSpecification cs = null; char c = 0; StringBuffer sb = new StringBuffer(); @@ -734,7 +734,7 @@ public class PrintfFormat { * formatting an unwrapped value. */ public String sprintf(Object x) throws IllegalArgumentException { - Enumeration e = vFmt.elements(); + Enumeration e = vFmt.elements(); ConversionSpecification cs = null; char c = 0; StringBuffer sb = new StringBuffer(); @@ -3206,7 +3206,7 @@ public class PrintfFormat { private String fmt; } /** Vector of control strings and format literals. */ - private Vector vFmt = new Vector(); + private Vector vFmt = new Vector(); /** Character position. Used by the constructor. */ private int cPos = 0; /** Character position. Used by the constructor. */ diff --git a/src/lwjake2/util/Vargs.java b/src/lwjake2/util/Vargs.java index dbd8db6..3040492 100644 --- a/src/lwjake2/util/Vargs.java +++ b/src/lwjake2/util/Vargs.java @@ -30,7 +30,7 @@ public class Vargs { // initial capacity static final int SIZE = 5; - Vector v; + Vector v; public Vargs() { this(SIZE); @@ -39,7 +39,7 @@ public class Vargs { public Vargs(int initialSize) { if (v != null) v.clear(); // clear previous list for GC - v = new Vector(initialSize); + v = new Vector(initialSize); } public Vargs add(boolean value) { @@ -97,12 +97,14 @@ public class Vargs { return this; } + /* This apparently isn't even used? - flibit public Vector toVector() { // Vector tmp = v; // v = null; // return tmp; return (Vector) v.clone(); } + */ public Object[] toArray() { return v.toArray();