Commits

Anonymous committed 84163ea

fixing sound releasing / audio deletion

Comments (0)

Files changed (11)

trunk/Slick/lib/slick.jar

Binary file modified.

trunk/Slick/src/org/newdawn/slick/AppGameContainer.java

 import org.lwjgl.Sys;
 import org.lwjgl.input.Cursor;
 import org.lwjgl.input.Mouse;
-import org.lwjgl.openal.AL;
 import org.lwjgl.opengl.Display;
 import org.lwjgl.opengl.DisplayMode;
 import org.lwjgl.opengl.PixelFormat;
-import org.newdawn.slick.openal.SoundStore;
 import org.newdawn.slick.opengl.CursorLoader;
 import org.newdawn.slick.opengl.ImageData;
 import org.newdawn.slick.opengl.ImageIOImageData;
 	 * @see org.newdawn.slick.GameContainer#reinit()
 	 */
 	public void reinit() throws SlickException {
-		InternalTextureLoader.get().clear();
-		SoundStore.get().clear();
+		destroy();
 		initSystem();
 		enterOrtho();
 		
 		return originalDisplayMode.getWidth();
 	}
 	
-	/**
-	 * Destroy the app game container
-	 */
-	public void destroy() {
-		Display.destroy();
-		AL.destroy();
-	}
 	
 	/**
 	 * A null stream to clear out those horrid errors

trunk/Slick/src/org/newdawn/slick/AppletGameContainer.java

             }
             catch (Exception e) {
                e.printStackTrace();
-               if (Display.isCreated()) {
-                  Display.destroy();
-               }
-               if (AL.isCreated())
-            	   AL.destroy();
+               AppletGameContainer.this.destroy();
                displayParent.setVisible(false);//removeAll();
                add(new ConsolePanel(e));
                validate();
             Display.update();
          }
 
-         Display.destroy();
-         if (AL.isCreated())
-        	 AL.destroy();
+         destroy();
       }
    }
    

trunk/Slick/src/org/newdawn/slick/CanvasGameContainer.java

 		/**
 		 * @see org.newdawn.slick.GameContainer#running()
 		 */
-		protected boolean running() {
+		public boolean running() {
 			return super.running() && CanvasGameContainer.this.isDisplayable();
 		}
 		

trunk/Slick/src/org/newdawn/slick/Game.java

 	 * @return The title of the game
 	 */
 	public String getTitle();
+//	we really need this...
+//	/**
+//	 * Called to cleanup any resources that this game may own.
+//	 */
+//	public void cleanup();
 }

trunk/Slick/src/org/newdawn/slick/GameContainer.java

 import org.lwjgl.LWJGLException;
 import org.lwjgl.Sys;
 import org.lwjgl.input.Cursor;
+import org.lwjgl.openal.AL;
 import org.lwjgl.opengl.Display;
 import org.lwjgl.opengl.Drawable;
 import org.lwjgl.opengl.Pbuffer;
 import org.newdawn.slick.openal.SoundStore;
 import org.newdawn.slick.opengl.CursorLoader;
 import org.newdawn.slick.opengl.ImageData;
+import org.newdawn.slick.opengl.InternalTextureLoader;
 import org.newdawn.slick.opengl.renderer.Renderer;
 import org.newdawn.slick.opengl.renderer.SGL;
 import org.newdawn.slick.util.Log;
 	}
 	
 	/**
+	 * Called to clean up the program's memory. Destroys AL and Display
+	 * if either is created. 
+	 */
+	public void destroy() {
+		InternalTextureLoader.get().clear();
+		SoundStore.get().clear();
+		if (Display.isCreated()) 
+			Display.destroy();
+		if (AL.isCreated())
+			AL.destroy();
+	}
+	
+	/**
 	 * Set the default font that will be intialised in the graphics held in this container
 	 * 
 	 * @param font The font to use as default
 	 * 
 	 * @return True if the game is running
 	 */
-	protected boolean running() {
+	public boolean running() {
 		return running;
 	}
 	

trunk/Slick/src/org/newdawn/slick/geom/Rectangle.java

 	 * @return True if the point is within the rectangle
 	 */
 	public boolean contains(float xp, float yp) {
-		if (xp <= getX()) {
+		if (xp < getX()) {
 			return false;
 		}
-		if (yp <= getY()) {
+		if (yp < getY()) {
 			return false;
 		}
 		if (xp >= maxX) {

trunk/Slick/src/org/newdawn/slick/openal/AudioImpl.java

 	 * the Sound.
 	 */
 	public void release() {
+		int oldIndex = index;
 		stop();
-		if (index!=-1) {
+		if (oldIndex!=-1) 
 			//detach buffer from source
-			AL10.alSourcei(SoundStore.get().getSource(index), AL10.AL_BUFFER, 0);
-		}
+			AL10.alSourcei(SoundStore.get().getSource(oldIndex), AL10.AL_BUFFER, 0);
 		//delete buffer
 		if (buffer!=0)
 			AL10.alDeleteBuffers(buffer);

trunk/Slick/src/org/newdawn/slick/openal/SoundStore.java

 	private SoundStore() {
 	}
 	
+	
 	/**
-	 * Clear out the sound store contents
+	 * Deletes any sources and clears out the sound store contents
 	 */
 	public void clear() {
+		if (sources!=null && AL.isCreated()) {
+			for (int i=0;i<sourceCount;i++) {
+				int src = sources.get(i);
+				AL10.alSourcei(src, AL10.AL_BUFFER, 0);
+				AL10.alSourceStop(src);
+				AL10.alDeleteSources(src);
+			}
+		}
 		store = new SoundStore();
 	}
 

trunk/Slick/src/org/newdawn/slick/tests/CanvasContainerTest.java

 import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 
 			rot -= 360;
 		}
 	}
+	
+	
 
 	/**
 	 * Entry point to our test
 			// resolution, regardless of JFrame size!
 
 			final Game game = new CanvasContainerTest();
-			final CanvasGameContainer container = new CanvasGameContainer(game);
+			final CanvasGameContainer canvasPanel = new CanvasGameContainer(game);
 			final JFrame frame = new JFrame(game.getTitle());
+			
 			// exit on close
-			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
+			frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
 			frame.addWindowListener(new WindowAdapter() {
 				public void windowClosing(WindowEvent we) {
 					// to avoid ugly flicker when closing, we 
 					frame.setVisible(false);
 					
 					// destroys GL/AL context
-					container.getContainer().exit();
+					canvasPanel.getContainer().exit();
+				}
+			});
+			canvasPanel.addKeyListener(new KeyListener() {
+				
+				@Override
+				public void keyTyped(KeyEvent arg0) {
+					// TODO Auto-generated method stub
+					
+				}
+				
+				@Override
+				public void keyReleased(KeyEvent arg0) {
+					// TODO Auto-generated method stub
+					
+				}
+				
+				@Override
+				public void keyPressed(KeyEvent e) {
+					if (e.getKeyCode() == KeyEvent.VK_ENTER) {
+						GameContainer container = canvasPanel.getContainer();
+						if (container.running())
+							container.exit();
+						else {
+							try {
+								canvasPanel.start();
+								System.out.println("starting");
+							} catch (SlickException e1) {
+								container.exit();
+								e1.printStackTrace();
+							}
+						}
+					}
 				}
 			});
 
 
 			// the size of our game
 			Dimension size = new Dimension(GAME_WIDTH, GAME_HEIGHT);
-			container.setPreferredSize(size);
-			container.setMinimumSize(size);
-			container.setMaximumSize(size);
+			canvasPanel.setPreferredSize(size);
+			canvasPanel.setMinimumSize(size);
+			canvasPanel.setMaximumSize(size);
 
 			// layout our game canvas so that it's centred
 			GridBagConstraints c = new GridBagConstraints();
 			c.fill = GridBagConstraints.CENTER;
 			frame.getContentPane().setLayout(new GridBagLayout());
-			frame.getContentPane().add(container, c);
+			frame.getContentPane().add(canvasPanel, c);
 			
 			frame.pack();
 			frame.setResizable(true);
 			
 			// request focus so that it begins rendering immediately
 			// alternatively we could use GameContainer.setAlwaysRender(true)
-			container.requestFocusInWindow();
+			canvasPanel.requestFocusInWindow();
 			frame.setVisible(true);
-			container.start();
+			canvasPanel.start();
 		} catch (SlickException ex) {
 			ex.printStackTrace();
 		}

trunk/Slick/src/version

-#Wed, 30 May 2012 12:10:54 -0400
+#Wed, 20 Jun 2012 20:23:41 -0400
 #Sun May 11 20:17:03 BST 2008
-build=245
+build=252