Compare commits

...

3 Commits

Author SHA1 Message Date
DaniTheSkunk 978614be36 added documentation 2022-11-25 00:52:43 +00:00
DaniTheSkunk 3857c64e41 added datatypes to Data 2022-11-25 00:52:21 +00:00
DaniTheSkunk e4d090dbd9 disabling depth buffer for 2d 2022-11-25 00:51:42 +00:00
3 changed files with 100 additions and 4 deletions

View File

@ -1,13 +1,18 @@
package com.danitheskunk.skunkworks;
import com.danitheskunk.skunkworks.gfx.Color;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
public class Data {
static final String[] vectorSeperators = new String[]{"x", ",", " "};
private final LinkedHashMap<String, LinkedHashMap<String, String>> data;
private Runnable callback;
private String currentCategory;
private final LinkedHashMap<String, LinkedHashMap<String, String>> data;
public Data(ByteBuffer data) {
this.data = new LinkedHashMap<>();
@ -17,7 +22,57 @@ public class Data {
}
public String get(String category, String key) {
return data.get(category).get(key);
var val = data.get(category).get(key);
return val == null ? "" : val;
}
public List<String> getCategories() {
return new ArrayList<>(data.keySet());
}
public Color getColor(String category, String key) {
var str = get(category, key);
if(str.equals("")) {
return Color.WHITE;
}
if(str.startsWith("#") && (str.length() == 7 || str.length() == 9)) {
var r = Integer.parseInt(str.substring(1, 3), 16);
var g = Integer.parseInt(str.substring(3, 5), 16);
var b = Integer.parseInt(str.substring(5, 7), 16);
var a = str.length() == 9 ? Integer.parseInt(
str.substring(7, 9),
16
) : 255;
return new Color(r, g, b, a);
}
for(var seperator : vectorSeperators) {
if(str.contains(seperator)) {
var posStr = str.split(seperator);
return new Color(Integer.parseInt(posStr[0].strip()),
Integer.parseInt(posStr[1].strip()),
Integer.parseInt(posStr[2].strip())
);
}
}
return Color.WHITE;
}
public Vec2i getVec2i(String category, String key) {
var str = get(category, key);
if(str.equals("")) {
return Vec2i.ZERO;
}
for(var seperator : vectorSeperators) {
if(str.contains(seperator)) {
var posStr = str.split(seperator);
return new Vec2i(Integer.parseInt(posStr[0].strip()),
Integer.parseInt(posStr[1].strip())
);
}
}
return Vec2i.ZERO;
}
public void onReload(Runnable callback) {

View File

@ -1,16 +1,56 @@
package com.danitheskunk.skunkworks.audio;
/**
* An audio sample
* <p>
* Either mono or stereo. Samplerate unaware.
*/
//todo: samplerate stuffs?
public interface ISample {
/**
* Returns the length
*
* @return the length in samples
*/
int getLength();
/**
* Returns the sample of left channel at position
*
* @param pos position in samples
* @return the sample value from -1.0 to 1.0 (+ headroom if clipping)
*/
double getSampleLeft(int pos);
/**
* Returns the sample of right channel at position
*
* @param pos position in samples
* @return the sample value from -1.0 to 1.0 (+ headroom if clipping)
*/
double getSampleRight(int pos);
/**
* Returns if the sample is in stereo
*
* @return true if the sample is stereo, false if mono
*/
boolean isStereo();
/**
* Set a sample value for left and right channel
*
* @param pos position in samples
* @param left sample value of left channel -32768 to 32768
* @param right sample value of right channel -32768 to 32768
*/
void setSamplei(int pos, short left, short right);
/**
* Set a sample value for left or mono channel
*
* @param pos position in samples
* @param left sample value of left(or mono) channel -32768 to 32768
*/
void setSamplei(int pos, short left);
}

View File

@ -145,7 +145,6 @@ public class Window extends BaseWindow {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
//glDepthFunc(GL_GREATER);
glfwSetWindowSizeCallback(window, this::windowSizeCallback);
glfwSetMouseButtonCallback(window, this::mouseButtonCallback);
@ -349,6 +348,7 @@ public class Window extends BaseWindow {
textureAtlas.update();
glClearColor(0.f, 0.f, 0.f, 0.0f);
glClear(GL_DEPTH_BUFFER_BIT);
glDepthFunc(GL_ALWAYS);
//glBegin(GL_TRIANGLES);
return renderContext;
}
@ -360,8 +360,9 @@ public class Window extends BaseWindow {
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glViewport(0, 0, size.getX(), size.getY());
textureAtlas.update();
glClearColor(0.f, 1.f, 0.f, 1.0f);
glClearColor(0.f, 0.f, 0.f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDepthFunc(GL_LESS);
//glBegin(GL_TRIANGLES);
glUniformMatrix4fv(program3D.getUniformLocation("projection"),
true,