Commit eb1273c5 authored by Minjae Song's avatar Minjae Song

migration wip java 9 modularise

parent 50c110f3
......@@ -38,7 +38,7 @@
<property name="caretWidth" class="java.lang.Integer" />
</properties>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
File added
File added
/*******************************************************************************
* Copyright 2011 See AUTHORS file.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
package com.badlogic.gdx.backends.lwjgl.audio;
import java.nio.FloatBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.openal.AL;
import org.lwjgl.openal.AL10;
import com.badlogic.gdx.Audio;
import com.badlogic.gdx.audio.AudioDevice;
import com.badlogic.gdx.audio.AudioRecorder;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.utils.Array;
import com.badlogic.gdx.utils.GdxRuntimeException;
import com.badlogic.gdx.utils.IntArray;
import com.badlogic.gdx.utils.IntMap;
import com.badlogic.gdx.utils.LongMap;
import com.badlogic.gdx.utils.ObjectMap;
import static org.lwjgl.openal.AL10.*;
/** @author Nathan Sweet */
public class OpenALAudio implements Audio {
private final int deviceBufferSize;
private final int deviceBufferCount;
private IntArray idleSources, allSources;
private LongMap<Integer> soundIdToSource;
private IntMap<Long> sourceToSoundId;
private long nextSoundId = 0;
private ObjectMap<String, Class<? extends OpenALSound>> extensionToSoundClass = new ObjectMap();
private ObjectMap<String, Class<? extends OpenALMusic>> extensionToMusicClass = new ObjectMap();
private OpenALSound[] recentSounds;
private int mostRecetSound = -1;
Array<OpenALMusic> music = new Array(false, 1, OpenALMusic.class);
boolean noDevice = false;
public OpenALAudio () {
this(16, 9, 512);
}
public OpenALAudio (int simultaneousSources, int deviceBufferCount, int deviceBufferSize) {
this.deviceBufferSize = deviceBufferSize;
this.deviceBufferCount = deviceBufferCount;
registerSound("ogg", Ogg.Sound.class);
registerMusic("ogg", Ogg.Music.class);
registerSound("wav", Wav.Sound.class);
registerMusic("wav", Wav.Music.class);
registerSound("mp3", Mp3.Sound.class);
registerMusic("mp3", Mp3.Music.class);
try {
AL.create();
} catch (LWJGLException ex) {
noDevice = true;
ex.printStackTrace();
return;
}
allSources = new IntArray(false, simultaneousSources);
for (int i = 0; i < simultaneousSources; i++) {
int sourceID = alGenSources();
if (alGetError() != AL_NO_ERROR) break;
allSources.add(sourceID);
}
idleSources = new IntArray(allSources);
soundIdToSource = new LongMap<Integer>();
sourceToSoundId = new IntMap<Long>();
FloatBuffer orientation = (FloatBuffer)BufferUtils.createFloatBuffer(6)
.put(new float[] {0.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f}).flip();
alListener(AL_ORIENTATION, orientation);
FloatBuffer velocity = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f}).flip();
alListener(AL_VELOCITY, velocity);
FloatBuffer position = (FloatBuffer)BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f}).flip();
alListener(AL_POSITION, position);
recentSounds = new OpenALSound[simultaneousSources];
}
public void registerSound (String extension, Class<? extends OpenALSound> soundClass) {
if (extension == null) throw new IllegalArgumentException("extension cannot be null.");
if (soundClass == null) throw new IllegalArgumentException("soundClass cannot be null.");
extensionToSoundClass.put(extension, soundClass);
}
public void registerMusic (String extension, Class<? extends OpenALMusic> musicClass) {
if (extension == null) throw new IllegalArgumentException("extension cannot be null.");
if (musicClass == null) throw new IllegalArgumentException("musicClass cannot be null.");
extensionToMusicClass.put(extension, musicClass);
}
public OpenALSound newSound (FileHandle file) {
if (file == null) throw new IllegalArgumentException("file cannot be null.");
Class<? extends OpenALSound> soundClass = extensionToSoundClass.get(file.extension().toLowerCase());
if (soundClass == null) throw new GdxRuntimeException("Unknown file extension for sound: " + file);
try {
return soundClass.getConstructor(new Class[] {OpenALAudio.class, FileHandle.class}).newInstance(this, file);
} catch (Exception ex) {
throw new GdxRuntimeException("Error creating sound " + soundClass.getName() + " for file: " + file, ex);
}
}
public OpenALMusic newMusic (FileHandle file) {
if (file == null) throw new IllegalArgumentException("file cannot be null.");
Class<? extends OpenALMusic> musicClass = extensionToMusicClass.get(file.extension().toLowerCase());
if (musicClass == null) throw new GdxRuntimeException("Unknown file extension for music: " + file);
try {
return musicClass.getConstructor(new Class[] {OpenALAudio.class, FileHandle.class}).newInstance(this, file);
} catch (Exception ex) {
throw new GdxRuntimeException("Error creating music " + musicClass.getName() + " for file: " + file, ex);
}
}
int obtainSource (boolean isMusic) {
if (noDevice) return 0;
for (int i = 0, n = idleSources.size; i < n; i++) {
int sourceId = idleSources.get(i);
int state = alGetSourcei(sourceId, AL_SOURCE_STATE);
if (state != AL_PLAYING && state != AL_PAUSED) {
if (isMusic) {
idleSources.removeIndex(i);
} else {
if (sourceToSoundId.containsKey(sourceId)) {
long soundId = sourceToSoundId.get(sourceId);
sourceToSoundId.remove(sourceId);
soundIdToSource.remove(soundId);
}
long soundId = nextSoundId++;
sourceToSoundId.put(sourceId, soundId);
soundIdToSource.put(soundId, sourceId);
}
alSourceStop(sourceId);
alSourcei(sourceId, AL_BUFFER, 0);
AL10.alSourcef(sourceId, AL10.AL_GAIN, 1);
AL10.alSourcef(sourceId, AL10.AL_PITCH, 1);
AL10.alSource3f(sourceId, AL10.AL_POSITION, 0, 0, 1f);
return sourceId;
}
}
return -1;
}
void freeSource (int sourceID) {
if (noDevice) return;
alSourceStop(sourceID);
alSourcei(sourceID, AL_BUFFER, 0);
if (sourceToSoundId.containsKey(sourceID)) {
long soundId = sourceToSoundId.remove(sourceID);
soundIdToSource.remove(soundId);
}
idleSources.add(sourceID);
}
void freeBuffer (int bufferID) {
if (noDevice) return;
for (int i = 0, n = idleSources.size; i < n; i++) {
int sourceID = idleSources.get(i);
if (alGetSourcei(sourceID, AL_BUFFER) == bufferID) {
if (sourceToSoundId.containsKey(sourceID)) {
long soundId = sourceToSoundId.remove(sourceID);
soundIdToSource.remove(soundId);
}
alSourceStop(sourceID);
alSourcei(sourceID, AL_BUFFER, 0);
}
}
}
void stopSourcesWithBuffer (int bufferID) {
if (noDevice) return;
for (int i = 0, n = idleSources.size; i < n; i++) {
int sourceID = idleSources.get(i);
if (alGetSourcei(sourceID, AL_BUFFER) == bufferID) {
if (sourceToSoundId.containsKey(sourceID)) {
long soundId = sourceToSoundId.remove(sourceID);
soundIdToSource.remove(soundId);
}
alSourceStop(sourceID);
}
}
}
void pauseSourcesWithBuffer (int bufferID) {
if (noDevice) return;
for (int i = 0, n = idleSources.size; i < n; i++) {
int sourceID = idleSources.get(i);
if (alGetSourcei(sourceID, AL_BUFFER) == bufferID)
alSourcePause(sourceID);
}
}
void resumeSourcesWithBuffer (int bufferID) {
if (noDevice) return;
for (int i = 0, n = idleSources.size; i < n; i++) {
int sourceID = idleSources.get(i);
if (alGetSourcei(sourceID, AL_BUFFER) == bufferID) {
if (alGetSourcei(sourceID, AL_SOURCE_STATE) == AL_PAUSED)
alSourcePlay(sourceID);
}
}
}
public void update () {
if (noDevice) return;
for (int i = 0; i < music.size; i++)
music.items[i].update();
}
public long getSoundId (int sourceId) {
if (!sourceToSoundId.containsKey(sourceId)) return -1;
return sourceToSoundId.get(sourceId);
}
public void stopSound (long soundId) {
if (!soundIdToSource.containsKey(soundId)) return;
int sourceId = soundIdToSource.get(soundId);
alSourceStop(sourceId);
}
public void pauseSound (long soundId) {
if (!soundIdToSource.containsKey(soundId)) return;
int sourceId = soundIdToSource.get(soundId);
alSourcePause(sourceId);
}
public void resumeSound (long soundId) {
if (!soundIdToSource.containsKey(soundId)) return;
int sourceId = soundIdToSource.get(soundId);
if (alGetSourcei(sourceId, AL_SOURCE_STATE) == AL_PAUSED)
alSourcePlay(sourceId);
}
public void setSoundGain (long soundId, float volume) {
if (!soundIdToSource.containsKey(soundId)) return;
int sourceId = soundIdToSource.get(soundId);
AL10.alSourcef(sourceId, AL10.AL_GAIN, volume);
}
public void setSoundLooping (long soundId, boolean looping) {
if (!soundIdToSource.containsKey(soundId)) return;
int sourceId = soundIdToSource.get(soundId);
alSourcei(sourceId, AL10.AL_LOOPING, looping ? AL10.AL_TRUE : AL10.AL_FALSE);
}
public void setSoundPitch (long soundId, float pitch) {
if (!soundIdToSource.containsKey(soundId)) return;
int sourceId = soundIdToSource.get(soundId);
AL10.alSourcef(sourceId, AL10.AL_PITCH, pitch);
}
public void setSoundPan (long soundId, float pan, float volume) {
if (!soundIdToSource.containsKey(soundId)) return;
int sourceId = soundIdToSource.get(soundId);
AL10.alSource3f(sourceId, AL10.AL_POSITION, MathUtils.cos((pan - 1) * MathUtils.PI / 2), 0,
MathUtils.sin((pan + 1) * MathUtils.PI / 2));
AL10.alSourcef(sourceId, AL10.AL_GAIN, volume);
}
public void dispose () {
if (noDevice) return;
for (int i = 0, n = allSources.size; i < n; i++) {
int sourceID = allSources.get(i);
int state = alGetSourcei(sourceID, AL_SOURCE_STATE);
if (state != AL_STOPPED) alSourceStop(sourceID);
alDeleteSources(sourceID);
}
sourceToSoundId.clear();
soundIdToSource.clear();
AL.destroy();
while (AL.isCreated()) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
}
}
public AudioDevice newAudioDevice (int sampleRate, final boolean isMono) {
if (noDevice) return new AudioDevice() {
@Override
public void writeSamples (float[] samples, int offset, int numSamples) {
}
@Override
public void writeSamples (short[] samples, int offset, int numSamples) {
}
@Override
public void setVolume (float volume) {
}
@Override
public boolean isMono () {
return isMono;
}
@Override
public int getLatency () {
return 0;
}
@Override
public void dispose () {
}
};
return new OpenALAudioDevice(this, sampleRate, isMono, deviceBufferSize, deviceBufferCount);
}
public AudioRecorder newAudioRecorder (int samplingRate, boolean isMono) {
if (noDevice) return new AudioRecorder() {
@Override
public void read (short[] samples, int offset, int numSamples) {
}
@Override
public void dispose () {
}
};
return new JavaSoundAudioRecorder(samplingRate, isMono);
}
/** Retains a list of the most recently played sounds and stops the sound played least recently if necessary for a new sound to
* play */
protected void retain (OpenALSound sound, boolean stop) {
// Move the pointer ahead and wrap
mostRecetSound++;
mostRecetSound %= recentSounds.length;
if (stop) {
// Stop the least recent sound (the one we are about to bump off the buffer)
if (recentSounds[mostRecetSound] != null) recentSounds[mostRecetSound].stop();
}
recentSounds[mostRecetSound] = sound;
}
/** Removes the disposed sound from the least recently played list */
public void forget (OpenALSound sound) {
for (int i = 0; i < recentSounds.length; i++) {
if (recentSounds[i] == sound) recentSounds[i] = null;
}
}
}
module terrarum {
requires gdx;
requires gdx.backend.lwjgl;
requires gdx.controllers;
requires jxinput;
requires gson;
requires GetCpuName;
requires TerrarumSansBitmap;
requires kotlin.stdlib;
requires java.desktop;
requires java.logging;
requires TerranVirtualDisk;
requires commons.codec;
requires commons.csv;
requires Terrarum.Joise;
}
\ No newline at end of file
package net.torvald.colourutil
import com.badlogic.gdx.graphics.Color
import com.jme3.math.FastMath
import net.torvald.colourutil.CIELChabUtil.toLCh
import net.torvald.colourutil.CIELChabUtil.toLab
......@@ -7,7 +8,6 @@ import net.torvald.colourutil.CIELabUtil.toLab
import net.torvald.colourutil.CIEXYZUtil.toXYZ
import net.torvald.colourutil.CIEXYZUtil.toColor
import net.torvald.colourutil.CIELabUtil.toXYZ
import com.badlogic.gdx.graphics.Color
/**
* Cylindrical modification of CIELab colour space
*
......
package net.torvald.colourutil
import com.badlogic.gdx.graphics.Color
import com.jme3.math.FastMath
import net.torvald.colourutil.CIELabUtil.toLab
import net.torvald.colourutil.CIEXYZUtil.toColor
import net.torvald.colourutil.CIEXYZUtil.toRGB
import net.torvald.colourutil.CIEXYZUtil.toXYZ
import net.torvald.colourutil.CIELabUtil.toXYZ
import com.badlogic.gdx.graphics.Color
/**
* A modification of CIEXYZ that is useful for surface colours
......
......@@ -2,7 +2,6 @@ package net.torvald.colourutil
import com.jme3.math.FastMath
import com.badlogic.gdx.graphics.Color
import net.torvald.colourutil.CIELabUtil.toXYZ
import net.torvald.colourutil.CIEXYZUtil.toColor
import net.torvald.colourutil.CIEXYZUtil.toRGB
import net.torvald.colourutil.CIEXYZUtil.toXYZ
......
......@@ -14,70 +14,35 @@
* limitations under the License.
******************************************************************************/
package com.badlogic.gdx.graphics;
package net.torvald.gdx.graphics;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.utils.NumberUtils;
/** A color class, holding the r, g, b and alpha component as floats in the range [0,1]. All methods perform clamping on the
* internal values after execution.
*
* @author mzechner */
public class Color {
public static final Color WHITE = new Color(1, 1, 1,1);
public static final Color LIGHT_GRAY = new Color(0xbfbfbfff);
public static final Color GRAY = new Color(0x7f7f7fff);
public static final Color DARK_GRAY = new Color(0x3f3f3fff);
public static final Color BLACK = new Color(0, 0, 0, 1);
/** Convenience for frequently used <code>WHITE.toFloatBits()</code> */
public static final float WHITE_FLOAT_BITS = WHITE.toFloatBits();
public static final Color CLEAR = new Color(0, 0, 0, 0);
public static final Color BLUE = new Color(0, 0, 1, 1);
public static final Color NAVY = new Color(0, 0, 0.5f, 1);
public static final Color ROYAL = new Color(0x4169e1ff);
public static final Color SLATE = new Color(0x708090ff);
public static final Color SKY = new Color(0x87ceebff);
public static final Color CYAN = new Color(0, 1, 1, 1);
public static final Color TEAL = new Color(0, 0.5f, 0.5f, 1);
public static final Color GREEN = new Color(0x00ff00ff);
public static final Color CHARTREUSE = new Color(0x7fff00ff);
public static final Color LIME = new Color(0x32cd32ff);
public static final Color FOREST = new Color(0x228b22ff);
public static final Color OLIVE = new Color(0x6b8e23ff);
public static final Color YELLOW = new Color(0xffff00ff);
public static final Color GOLD = new Color(0xffd700ff);
public static final Color GOLDENROD = new Color(0xdaa520ff);
public static final Color ORANGE = new Color(0xffa500ff);
public static final Color BROWN = new Color(0x8b4513ff);
public static final Color TAN = new Color(0xd2b48cff);
public static final Color FIREBRICK = new Color(0xb22222ff);
public static final Color RED = new Color(0xff0000ff);
public static final Color SCARLET = new Color(0xff341cff);
public static final Color CORAL = new Color(0xff7f50ff);
public static final Color SALMON = new Color(0xfa8072ff);
public static final Color PINK = new Color(0xff69b4ff);
public static final Color MAGENTA = new Color(1, 0, 1, 1);
public static final Color PURPLE = new Color(0xa020f0ff);
public static final Color VIOLET = new Color(0xee82eeff);
public static final Color MAROON = new Color(0xb03060ff);
public class Cvec {
public static final Cvec WHITE = new Cvec(1, 1, 1,1);
/** the red, green, blue and alpha components **/
public float r, g, b, a;
/** Constructs a new Color with all components set to 0. */
public Color () {
/** Constructs a new Cvec with all components set to 0. */
public Cvec () {
}
/** @see #rgba8888ToColor(Color, int) */
public Color (int rgba8888) {
rgba8888ToColor(this, rgba8888);
/** @see #rgba8888ToCvec(Cvec, int) */
public Cvec (int rgba8888) {
rgba8888ToCvec(this, rgba8888);
}
public Cvec (Color color) {
this.r = color.r;
this.g = color.g;
this.b = color.b;
this.a = color.a;
}
/** Constructor, sets the components of the color
......@@ -86,7 +51,7 @@ public class Color {
* @param g the green component
* @param b the blue component
* @param a the alpha component */
public Color (float r, float g, float b, float a) {
public Cvec (float r, float g, float b, float a) {
this.r = r;
this.g = g;
this.b = b;
......@@ -96,14 +61,14 @@ public class Color {
/** Constructs a new color using the given color
*
* @param color the color */
public Color (Color color) {
public Cvec (Cvec color) {
set(color);
}
/** Sets this color to the given color.
*
* @param color the Color */
public Color set (Color color) {
* @param color the Cvec */
public Cvec set (Cvec color) {
this.r = color.r;
this.g = color.g;
this.b = color.b;
......@@ -115,7 +80,7 @@ public class Color {
*
* @param color the color
* @return this color. */
public Color mul (Color color) {
public Cvec mul (Cvec color) {
this.r *= color.r;
this.g *= color.g;
this.b *= color.b;
......@@ -123,11 +88,11 @@ public class Color {
return this;
}
/** Multiplies all components of this Color with the given value.
/** Multiplies all components of this Cvec with the given value.
*
* @param value the value
* @return this color */
public Color mul (float value) {
public Cvec mul (float value) {
this.r *= value;
this.g *= value;
this.b *= value;
......@@ -139,7 +104,7 @@ public class Color {
*
* @param color the color
* @return this color */
public Color add (Color color) {
public Cvec add (Cvec color) {
this.r += color.r;
this.g += color.g;
this.b += color.b;
......@@ -151,7 +116,7 @@ public class Color {
*
* @param color the color
* @return this color */
public Color sub (Color color) {
public Cvec sub (Cvec color) {
this.r -= color.r;
this.g -= color.g;
this.b -= color.b;
......@@ -159,15 +124,15 @@ public class Color {
return this;
}
/** Sets this Color's component values.
/** Sets this Cvec's component values.
*
* @param r Red component
* @param g Green component
* @param b Blue component
* @param a Alpha component
*
* @return this Color for chaining */
public Color set (float r, float g, float b, float a) {
* @return this Cvec for chaining */
public Cvec set (float r, float g, float b, float a) {
this.r = r;
this.g = g;
this.b = b;
......@@ -177,22 +142,22 @@ public class Color {
/** Sets this color's component values through an integer representation.
*
* @return this Color for chaining
* @see #rgba8888ToColor(Color, int) */
public Color set (int rgba) {
rgba8888ToColor(this, rgba);
* @return this Cvec for chaining
* @see #rgba8888ToCvec(Cvec, int) */
public Cvec set (int rgba) {
rgba8888ToCvec(this, rgba);
return this;
}
/** Adds the given color component values to this Color's values.
/** Adds the given color component values to this Cvec's values.
*
* @param r Red component
* @param g Green component
* @param b Blue component
* @param a Alpha component
*
* @return this Color for chaining */
public Color add (float r, float g, float b, float a) {
* @return this Cvec for chaining */
public Cvec add (float r, float g, float b, float a) {
this.r += r;
this.g += g;
this.b += b;
......@@ -200,15 +165,15 @@ public class Color {
return this;
}
/** Subtracts the given values from this Color's component values.
/** Subtracts the given values from this Cvec's component values.
*
* @param r Red component
* @param g Green component
* @param b Blue component
* @param a Alpha component
*