# HG changeset patch # User Matti Hamalainen # Date 1296546909 -7200 # Node ID 0741dc1178086489eb898b8649e652740d2ee8e2 # Parent afde253ec7051b7a095c0329aa74ab44c302ba6a Remove sound code for later refactoring. diff -r afde253ec705 -r 0741dc117808 game/Engine.java --- a/game/Engine.java Mon Jan 31 21:28:59 2011 +0200 +++ b/game/Engine.java Tue Feb 01 09:55:09 2011 +0200 @@ -201,13 +201,11 @@ Dimension oldDim; float clock; -/* SoundElement[] sounds; public SoundElement snd(Sound snd) { return sounds[snd.ordinal()]; } -*/ public Engine() { @@ -221,14 +219,12 @@ ResourceLoader res = new ResourceLoader("graphics/board.png"); lautaBG = ImageIO.read(res.getStream()); -/* sounds = new SoundElement[16]; for (Sound s : Sound.values()) { System.out.print(s +" = "+ s.ordinal() +"\n"); - sounds[s.ordinal()] = new SoundElement("sounds/" + s.getName(), s.isEffect()); + sounds[s.ordinal()] = new SoundElement("sounds/" + s.getName(), s.isStreaming()); } -*/ } catch (IOException e) { @@ -252,9 +248,7 @@ requestFocus(); } -/* snd(Sound.MUSIC_GAME1).loop(-1); -*/ } public void startThreads() @@ -278,13 +272,11 @@ animThread = null; } -/* for (Sound s : Sound.values()) { if (snd(s) != null) snd(s).stop(); } -*/ } public void mousePressed(MouseEvent e) { } @@ -355,8 +347,8 @@ case KeyEvent.VK_ENTER: lauta.pieceFinishTurn(); -// snd(Sound.PIECE_PLACED).stop(); -// snd(Sound.PIECE_PLACED).play(); + snd(Sound.PIECE_PLACED).stop(); + snd(Sound.PIECE_PLACED).play(); break; } } diff -r afde253ec705 -r 0741dc117808 game/Sound.java --- a/game/Sound.java Mon Jan 31 21:28:59 2011 +0200 +++ b/game/Sound.java Tue Feb 01 09:55:09 2011 +0200 @@ -16,7 +16,7 @@ private final String name; - private final boolean effect; + private final boolean streaming; Sound(String name, boolean streaming) { diff -r afde253ec705 -r 0741dc117808 game/SoundElement.java --- a/game/SoundElement.java Mon Jan 31 21:28:59 2011 +0200 +++ b/game/SoundElement.java Tue Feb 01 09:55:09 2011 +0200 @@ -31,6 +31,7 @@ this.name = filename; this.streaming = streaming; +/* ResourceLoader res = new ResourceLoader(name); if (res == null || res.getStream() == null) { @@ -80,110 +81,29 @@ throw new IOException("Line unavailable for '"+name+"'.\n"); } } +*/ } public void play() { System.out.print("Sound("+name+").play()\n"); - if (streaming) - { - clip.setFramePosition(0); - clip.start(); - } - else - { - if (playThread == null) - { - doPlay = true; - loopCount = 1; - playThread = new Thread(this); - playThread.start(); - } - } } public void loop(int n) { System.out.print("Sound("+name+").loop("+n+")\n"); - if (isClip()) - { - clip.setFramePosition(0); - if (n < 0) - clip.loop(Clip.LOOP_CONTINUOUSLY); - else - clip.loop(n); - } - else - { - if (playThread == null) - { - doPlay = true; - loopCount = n; - playThread = new Thread(this); - playThread.start(); - } - } } public void stop() { - if (isClip()) - { - if (clip.isRunning()) - clip.stop(); - } - else - { - if (playThread != null) - { - playThread.interrupt(); - doPlay = false; - playThread = null; - } - } } public boolean isPlaying() { - if (isClip()) - return clip.isRunning(); - else - return (playThread != null && line.isRunning()); + return false; } public void run() { - line.start(); - byte[] buf = new byte[line.getBufferSize()]; - - while (doPlay && (loopCount > 0 || loopCount == -1)) - { - try { - int numRead = 0; - while ((numRead = stream.read(buf, 0, buf.length)) >= 0 && doPlay) - { - int offset = 0; - while (offset < numRead) - { - System.out.print("audioThread: offs="+offset+", numread="+numRead+"\n"); - offset += line.write(buf, offset, numRead - offset); - } - } - line.drain(); - - System.out.print("audioThread: stream.reset()\n"); - stream.reset(); - } - catch (IOException e) { - } - - if (loopCount > 0) - loopCount--; - } - - line.stop(); - doPlay = false; } } - -