[updated] OpenALMusic to not gen AL buffers until as late as possible.
[fixed] Warnings.
[fixed] Label layout when text is changed.
[fixed] TableLayout alignment methods.
[added] LwjglFrame for a resizable LJWGL application window.
[added] FileProcessor to utils (should go in tools).
<classpath>\r
<classpathentry excluding="**/.svn/*" kind="src" path="src"/>\r
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>\r
- <classpathentry kind="lib" path="/gdx/libs/gdx-natives.jar"/>\r
+ <classpathentry exported="true" kind="lib" path="/gdx/libs/gdx-natives.jar"/>\r
<classpathentry kind="lib" path="libs/gdx-backend-lwjgl-natives.jar"/>\r
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/gdx-openal"/>\r
<classpathentry kind="lib" path="libs/lwjgl_util.jar"/>\r
import com.badlogic.gdx.backends.openal.OpenALAudio;\r
import com.badlogic.gdx.utils.GdxRuntimeException;\r
\r
-/**\r
- * An OpenGL surface on an AWT Canvas, allowing OpenGL to be embedded in a Swing application. All OpenGL calls are done on the\r
+/** An OpenGL surface on an AWT Canvas, allowing OpenGL to be embedded in a Swing application. All OpenGL calls are done on the\r
* EDT. This is slightly less efficient then a dedicated thread, but greatly simplifies synchronization.\r
- * @author Nathan Sweet\r
- */\r
+ * @author Nathan Sweet */\r
public class LwjglCanvas implements Application {\r
final LwjglGraphics graphics;\r
final OpenALAudio audio;\r
final List<Runnable> runnables = new ArrayList<Runnable>();\r
boolean running = true;\r
int logLevel = LOG_INFO;\r
- \r
+\r
public LwjglCanvas (ApplicationListener listener, boolean useGL2) {\r
LwjglNativesLoader.load();\r
\r
return canvas;\r
}\r
\r
- @Override public Audio getAudio () {\r
+ @Override\r
+ public Audio getAudio () {\r
return audio;\r
}\r
\r
- @Override public Files getFiles () {\r
+ @Override\r
+ public Files getFiles () {\r
return files;\r
}\r
\r
- @Override public Graphics getGraphics () {\r
+ @Override\r
+ public Graphics getGraphics () {\r
return graphics;\r
}\r
\r
- @Override public Input getInput () {\r
+ @Override\r
+ public Input getInput () {\r
return input;\r
}\r
\r
- @Override public ApplicationType getType () {\r
+ @Override\r
+ public ApplicationType getType () {\r
return ApplicationType.Desktop;\r
}\r
\r
- @Override public int getVersion () {\r
+ @Override\r
+ public int getVersion () {\r
return 0;\r
}\r
\r
listener.create();\r
listener.resize(Math.max(1, graphics.getWidth()), Math.max(1, graphics.getHeight()));\r
\r
- final Runnable runnable = new Runnable() {\r
+ EventQueue.invokeLater(new Runnable() {\r
int lastWidth = Math.max(1, graphics.getWidth());\r
int lastHeight = Math.max(1, graphics.getHeight());\r
\r
audio.update();\r
Display.update();\r
if (graphics.vsync) Display.sync(60);\r
+ if (running && !Display.isCloseRequested()) EventQueue.invokeLater(this);\r
}\r
- };\r
-\r
- new Thread("LWJGL Canvas") {\r
- public void run () {\r
- while (running && !Display.isCloseRequested()) {\r
- try {\r
- EventQueue.invokeAndWait(runnable);\r
- } catch (Exception ex) {\r
- throw new GdxRuntimeException(ex);\r
- }\r
- }\r
- }\r
- }.start();\r
+ });\r
}\r
\r
public void stop () {\r
+ if (!running) return;\r
+ running = false;\r
+ Display.destroy();\r
EventQueue.invokeLater(new Runnable() {\r
public void run () {\r
- if (!running) return;\r
- running = false;\r
listener.pause();\r
listener.dispose();\r
- Display.destroy();\r
}\r
});\r
}\r
\r
- @Override public long getJavaHeap () {\r
+ @Override\r
+ public long getJavaHeap () {\r
return Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();\r
}\r
\r
- @Override public long getNativeHeap () {\r
+ @Override\r
+ public long getNativeHeap () {\r
return getJavaHeap();\r
}\r
\r
Map<String, Preferences> preferences = new HashMap<String, Preferences>();\r
\r
- @Override public Preferences getPreferences (String name) {\r
+ @Override\r
+ public Preferences getPreferences (String name) {\r
if (preferences.containsKey(name)) {\r
return preferences.get(name);\r
} else {\r
}\r
}\r
\r
- @Override public void postRunnable (Runnable runnable) {\r
+ @Override\r
+ public void postRunnable (Runnable runnable) {\r
synchronized (runnables) {\r
runnables.add(runnable);\r
}\r
}\r
\r
- public void log(String tag, String message) {\r
- if(logLevel >= LOG_INFO) {\r
- System.out.println(tag + ":" + message); \r
+ public void log (String tag, String message) {\r
+ if (logLevel >= LOG_INFO) {\r
+ System.out.println(tag + ":" + message);\r
}\r
- }\r
+ }\r
\r
- @Override public void log (String tag, String message, Exception exception) {\r
- if(logLevel >= LOG_INFO) {\r
+ @Override\r
+ public void log (String tag, String message, Exception exception) {\r
+ if (logLevel >= LOG_INFO) {\r
System.out.println(tag + ":" + message);\r
exception.printStackTrace(System.out);\r
}\r
}\r
- \r
- @Override public void error (String tag, String message) {\r
- if(logLevel >= LOG_ERROR) {\r
- System.err.println(tag + ":" + message); \r
+\r
+ @Override\r
+ public void error (String tag, String message) {\r
+ if (logLevel >= LOG_ERROR) {\r
+ System.err.println(tag + ":" + message);\r
}\r
}\r
\r
-\r
- @Override public void error (String tag, String message, Exception exception) {\r
- if(logLevel >= LOG_ERROR) {\r
+ @Override\r
+ public void error (String tag, String message, Exception exception) {\r
+ if (logLevel >= LOG_ERROR) {\r
System.err.println(tag + ":" + message);\r
exception.printStackTrace(System.err);\r
}\r
}\r
\r
-\r
- @Override public void setLogLevel (int logLevel) { \r
+ @Override\r
+ public void setLogLevel (int logLevel) {\r
this.logLevel = logLevel;\r
}\r
- \r
- @Override public void exit () {\r
+\r
+ @Override\r
+ public void exit () {\r
postRunnable(new Runnable() {\r
- @Override public void run () {\r
+ @Override\r
+ public void run () {\r
LwjglCanvas.this.listener.pause();\r
LwjglCanvas.this.listener.dispose();\r
System.exit(-1);\r
- } \r
+ }\r
});\r
}\r
}\r
--- /dev/null
+\r
+package com.badlogic.gdx.backends.lwjgl;\r
+\r
+import java.awt.event.WindowAdapter;\r
+import java.awt.event.WindowEvent;\r
+\r
+import javax.swing.JFrame;\r
+\r
+import com.badlogic.gdx.ApplicationListener;\r
+import com.badlogic.gdx.Gdx;\r
+\r
+/** Wraps an {@link LwjglCanvas} in a resizable {@link JFrame}. */\r
+public class LwjglFrame extends JFrame {\r
+ public LwjglFrame (ApplicationListener listener, String title, int width, int height, boolean useGL2) {\r
+ super(title);\r
+ setDefaultCloseOperation(EXIT_ON_CLOSE);\r
+ setSize(width, height);\r
+ setLocationRelativeTo(null);\r
+\r
+ final LwjglCanvas lwjglCanvas = new LwjglCanvas(listener, useGL2);\r
+ getContentPane().add(lwjglCanvas.getCanvas());\r
+\r
+ addWindowListener(new WindowAdapter() {\r
+ public void windowClosing (WindowEvent e) {\r
+ lwjglCanvas.stop();\r
+ }\r
+ });\r
+ }\r
+}\r
* See the License for the specific language governing permissions and\r
* limitations under the License.\r
******************************************************************************/\r
+\r
package com.badlogic.gdx.backends.openal;\r
\r
import java.nio.ByteBuffer;\r
\r
import static org.lwjgl.openal.AL10.*;\r
\r
-/**\r
- * @author Nathan Sweet\r
- */\r
+/** @author Nathan Sweet */\r
public abstract class OpenALMusic implements Music {\r
static private final int bufferSize = 4096 * 10;\r
static private final int bufferCount = 3;\r
this.audio = audio;\r
this.file = file;\r
\r
- buffers = BufferUtils.createIntBuffer(bufferCount);\r
- alGenBuffers(buffers);\r
- if (alGetError() != AL_NO_ERROR) throw new GdxRuntimeException("Unabe to allocate audio buffers.");\r
-\r
audio.music.add(this);\r
}\r
\r
if (sourceID == -1) {\r
sourceID = audio.obtainSource(true);\r
if (sourceID == -1) return;\r
+ if (buffers == null) {\r
+ buffers = BufferUtils.createIntBuffer(bufferCount);\r
+ alGenBuffers(buffers);\r
+ if (alGetError() != AL_NO_ERROR) throw new GdxRuntimeException("Unabe to allocate audio buffers.");\r
+ }\r
alSourcei(sourceID, AL_LOOPING, AL_FALSE);\r
alSourcef(sourceID, AL_GAIN, volume);\r
for (int i = 0; i < bufferCount; i++) {\r
return renderedSeconds + alGetSourcef(sourceID, AL11.AL_SEC_OFFSET);\r
}\r
\r
- /**\r
- * Fills as much of the buffer as possible and returns the number of bytes filled. Returns <= 0 to indicate the end of the\r
- * stream.\r
- */\r
+ /** Fills as much of the buffer as possible and returns the number of bytes filled. Returns <= 0 to indicate the end of the\r
+ * stream. */\r
abstract protected int read (byte[] buffer);\r
\r
- /**\r
- * Resets the stream to the beginning.\r
- */\r
+ /** Resets the stream to the beginning. */\r
abstract protected void reset ();\r
\r
public void update () {\r
if(pixelPtr == null)\r
throw new IllegalArgumentException("couldn't load pixmap");\r
\r
- System.arraycopy(nativeData, 0, this.nativeData, 0, 4);\r
+ System.arraycopy(nativeData, 0, Gdx2DPixmap.nativeData, 0, 4);\r
this.basePtr = nativeData[0];\r
this.width = (int)nativeData[1];\r
this.height = (int)nativeData[2];\r
\r
/**\r
* Writes the ETC1Data with a PKM header to the given file.\r
- * @param handle the file.\r
+ * @param file the file.\r
*/\r
public void write(FileHandle file) {\r
DataOutputStream write = null;\r
--- /dev/null
+\r
+package com.badlogic.gdx.math;\r
+\r
+import java.io.File;\r
+import java.io.FilenameFilter;\r
+import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.Comparator;\r
+import java.util.HashMap;\r
+import java.util.Map.Entry;\r
+\r
+public class FileProcessor {\r
+ FilenameFilter inputFilter;\r
+ Comparator<File> comparator;\r
+ String inputSuffix;\r
+ String outputSuffix;\r
+ ArrayList<InputFile> outputFiles = new ArrayList();\r
+ boolean recursive = true;\r
+ boolean flattenOutput;\r
+\r
+ public FileProcessor () {\r
+ }\r
+\r
+ public FileProcessor (String inputSuffix) {\r
+ this.inputSuffix = inputSuffix;\r
+ }\r
+\r
+ Comparator<InputFile> inputFileComparator = new Comparator<InputFile>() {\r
+ public int compare (InputFile o1, InputFile o2) {\r
+ return comparator.compare(o1.inputFile, o2.inputFile);\r
+ }\r
+ };\r
+\r
+ public void setInputFilter (FilenameFilter inputFilter) {\r
+ this.inputFilter = inputFilter;\r
+ }\r
+\r
+ public void setComparator (Comparator<File> comparator) {\r
+ this.comparator = comparator;\r
+ }\r
+\r
+ public void setInputSuffix (String inputSuffix) {\r
+ this.inputSuffix = inputSuffix;\r
+ }\r
+\r
+ public void setOutputSuffix (String outputSuffix) {\r
+ this.outputSuffix = outputSuffix;\r
+ }\r
+\r
+ public void setFlattenOutput (boolean flattenOutput) {\r
+ this.flattenOutput = flattenOutput;\r
+ }\r
+\r
+ public void setRecursive (boolean recursive) {\r
+ this.recursive = recursive;\r
+ }\r
+\r
+ public void process (File inputFile, File outputRoot) throws Exception {\r
+ if (inputFile.isFile())\r
+ process(new File[] {inputFile}, outputRoot);\r
+ else\r
+ process(inputFile.listFiles(), outputRoot);\r
+ }\r
+\r
+ public ArrayList<InputFile> process (File[] files, File outputRoot) throws Exception {\r
+ outputFiles.clear();\r
+\r
+ HashMap<File, ArrayList<InputFile>> dirToEntries = new HashMap();\r
+ process(files, outputRoot, outputRoot, dirToEntries, 0);\r
+\r
+ ArrayList<InputFile> allInputFiles = new ArrayList();\r
+ for (Entry<File, ArrayList<InputFile>> entry : dirToEntries.entrySet()) {\r
+ ArrayList<InputFile> dirInputFiles = entry.getValue();\r
+ if (comparator != null) Collections.sort(dirInputFiles, inputFileComparator);\r
+\r
+ File inputDir = entry.getKey();\r
+ File newOutputDir = flattenOutput ? outputRoot : dirInputFiles.get(0).outputDir;\r
+ String outputName = inputDir.getName();\r
+ if (outputSuffix != null) outputName += outputSuffix;\r
+\r
+ InputFile inputFile = new InputFile();\r
+ inputFile.inputFile = entry.getKey();\r
+ inputFile.outputDir = newOutputDir;\r
+ inputFile.outputFile = new File(newOutputDir, outputName);\r
+\r
+ processDir(inputFile, dirInputFiles);\r
+ allInputFiles.addAll(dirInputFiles);\r
+ }\r
+\r
+ if (comparator != null) Collections.sort(allInputFiles, inputFileComparator);\r
+ for (InputFile inputFile : allInputFiles)\r
+ processFile(inputFile);\r
+\r
+ return outputFiles;\r
+ }\r
+\r
+ private void process (File[] files, File outputRoot, File outputDir, HashMap<File, ArrayList<InputFile>> dirToEntries,\r
+ int depth) {\r
+ for (File file : files) {\r
+ if (file.isFile()) {\r
+ if (inputSuffix != null && !file.getName().endsWith(inputSuffix)) continue;\r
+\r
+ File dir = file.getParentFile();\r
+ if (inputFilter != null && !inputFilter.accept(dir, file.getName())) continue;\r
+\r
+ String outputName = file.getName();\r
+ if (outputSuffix != null) outputName = outputName.replaceAll("(.*)\\..*", "$1") + outputSuffix;\r
+\r
+ InputFile inputFile = new InputFile();\r
+ inputFile.depth = depth;\r
+ inputFile.inputFile = file;\r
+ inputFile.outputDir = outputDir;\r
+ inputFile.outputFile = flattenOutput ? new File(outputRoot, outputName) : new File(outputDir, outputName);\r
+ ArrayList<InputFile> inputFiles = dirToEntries.get(dir);\r
+ if (inputFiles == null) {\r
+ inputFiles = new ArrayList();\r
+ dirToEntries.put(dir, inputFiles);\r
+ }\r
+ inputFiles.add(inputFile);\r
+ }\r
+ if (recursive && file.isDirectory())\r
+ process(file.listFiles(inputFilter), outputRoot, new File(outputDir, file.getName()), dirToEntries, depth + 1);\r
+ }\r
+ }\r
+\r
+ protected void processFile (InputFile inputFile) throws Exception {\r
+ }\r
+\r
+ protected void processDir (InputFile inputDir, ArrayList<InputFile> value) throws Exception {\r
+ }\r
+\r
+ protected void addOutputFile (InputFile inputFile) {\r
+ outputFiles.add(inputFile);\r
+ }\r
+\r
+ static public class InputFile {\r
+ public File inputFile;\r
+ public File outputDir;\r
+ public File outputFile;\r
+ public int depth;\r
+\r
+ public InputFile () {\r
+ }\r
+\r
+ public InputFile (File inputFile, File outputFile) {\r
+ this.inputFile = inputFile;\r
+ this.outputFile = outputFile;\r
+ }\r
+ }\r
+}\r
+
\ No newline at end of file
\r
public void setText(String text) {\r
this.label = text;\r
+ layout();\r
invalidateHierarchy();\r
}\r
}\r
\r
/** Sets the alignment of the table within the widget being laid out to {@link #BOTTOM}. */\r
public L bottom () {\r
- align = BOTTOM;\r
+ align |= BOTTOM;\r
align &= ~TOP;\r
return (L)this;\r
}\r
\r
/** Sets the alignment of the table within the widget being laid out to {@link #RIGHT}. */\r
public L right () {\r
- align = RIGHT;\r
+ align |= RIGHT;\r
align &= ~LEFT;\r
return (L)this;\r
}\r