parent
6460ad9029
commit
e4e7aa7eb3
@ -0,0 +1,11 @@ |
||||
eclipse.preferences.version=1 |
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 |
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve |
||||
org.eclipse.jdt.core.compiler.compliance=1.7 |
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate |
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate |
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate |
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
||||
org.eclipse.jdt.core.compiler.source=1.7 |
@ -0,0 +1,21 @@ |
||||
package mightypork.gamecore.audio; |
||||
|
||||
|
||||
import mightypork.utils.math.Calc; |
||||
import mightypork.utils.objects.Mutable; |
||||
|
||||
|
||||
public class Volume extends Mutable<Double> { |
||||
|
||||
public Volume(Double d) { |
||||
super(d); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
public void set(Double d) |
||||
{ |
||||
super.set(Calc.clampd(d, 0, 1)); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,51 @@ |
||||
package mightypork.utils.files; |
||||
|
||||
|
||||
import java.io.File; |
||||
import java.io.IOException; |
||||
import java.io.RandomAccessFile; |
||||
import java.nio.channels.FileLock; |
||||
|
||||
|
||||
/** |
||||
* Instance lock (avoid running twice) |
||||
* |
||||
* @author MightyPork |
||||
*/ |
||||
public class InstanceLock { |
||||
|
||||
@SuppressWarnings("resource") |
||||
public static boolean onFile(final File lockFile) |
||||
{ |
||||
try { |
||||
final RandomAccessFile randomAccessFile = new RandomAccessFile(lockFile, "rw"); |
||||
|
||||
final FileLock fileLock = randomAccessFile.getChannel().tryLock(); |
||||
if (fileLock != null) { |
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() { |
||||
|
||||
@Override |
||||
public void run() |
||||
{ |
||||
try { |
||||
fileLock.release(); |
||||
randomAccessFile.close(); |
||||
lockFile.delete(); |
||||
} catch (final Exception e) { |
||||
System.err.println("Unable to remove lock file."); |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} catch (IOException e) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue