pass screen size in instead of polling it later
and add some comments
This commit is contained in:
parent
41c7825728
commit
2970972456
|
@ -485,9 +485,6 @@ public class Options {
|
||||||
/** The current skin. */
|
/** The current skin. */
|
||||||
private static Skin skin;
|
private static Skin skin;
|
||||||
|
|
||||||
/** Resolution that the latest Container passed to "setDisplayMode" was set to. */
|
|
||||||
private static Resolution lastSetResolution = Resolution.RES_1024_768;
|
|
||||||
|
|
||||||
/** Frame limiters. */
|
/** Frame limiters. */
|
||||||
private static final int[] targetFPS = { 60, 120, 240 };
|
private static final int[] targetFPS = { 60, 120, 240 };
|
||||||
|
|
||||||
|
@ -597,8 +594,6 @@ public class Options {
|
||||||
// set borderless window if dimensions match screen size
|
// set borderless window if dimensions match screen size
|
||||||
boolean borderless = (screenWidth == resolution.getWidth() && screenHeight == resolution.getHeight());
|
boolean borderless = (screenWidth == resolution.getWidth() && screenHeight == resolution.getHeight());
|
||||||
System.setProperty("org.lwjgl.opengl.Window.undecorated", Boolean.toString(borderless));
|
System.setProperty("org.lwjgl.opengl.Window.undecorated", Boolean.toString(borderless));
|
||||||
|
|
||||||
lastSetResolution = resolution;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
|
@ -893,24 +888,6 @@ public class Options {
|
||||||
return replayDir;
|
return replayDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the horizontal Resolution.
|
|
||||||
* If no game has been started then a default value is returned.
|
|
||||||
* @return the horizontal resolution of the latest game instance to be started.
|
|
||||||
*/
|
|
||||||
public static int getLatestResolutionWidth() {
|
|
||||||
return lastSetResolution.getWidth();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the vertical Resolution.
|
|
||||||
* If no game has been started then a default value is returned.
|
|
||||||
* @return the vertical resolution of the latest game instance to be started.
|
|
||||||
*/
|
|
||||||
public static int getLatestResolutionHeight() {
|
|
||||||
return lastSetResolution.getHeight();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current skin directory.
|
* Returns the current skin directory.
|
||||||
* If invalid, this will create a "Skins" folder in the root directory.
|
* If invalid, this will create a "Skins" folder in the root directory.
|
||||||
|
|
|
@ -30,20 +30,12 @@ import itdelatrisu.opsu.objects.curves.CatmullCurve;
|
||||||
import itdelatrisu.opsu.objects.curves.CircumscribedCircle;
|
import itdelatrisu.opsu.objects.curves.CircumscribedCircle;
|
||||||
import itdelatrisu.opsu.objects.curves.Curve;
|
import itdelatrisu.opsu.objects.curves.Curve;
|
||||||
import itdelatrisu.opsu.objects.curves.LinearBezier;
|
import itdelatrisu.opsu.objects.curves.LinearBezier;
|
||||||
import itdelatrisu.opsu.render.Rendertarget;
|
|
||||||
import itdelatrisu.opsu.states.Game;
|
import itdelatrisu.opsu.states.Game;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
import org.lwjgl.opengl.GL14;
|
|
||||||
import org.lwjgl.opengl.GL30;
|
|
||||||
|
|
||||||
import org.newdawn.slick.Color;
|
import org.newdawn.slick.Color;
|
||||||
import org.newdawn.slick.GameContainer;
|
import org.newdawn.slick.GameContainer;
|
||||||
import org.newdawn.slick.Graphics;
|
import org.newdawn.slick.Graphics;
|
||||||
import org.newdawn.slick.Image;
|
import org.newdawn.slick.Image;
|
||||||
import org.newdawn.slick.util.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Data type representing a slider object.
|
* Data type representing a slider object.
|
||||||
|
@ -58,9 +50,6 @@ public class Slider implements GameObject {
|
||||||
/** Rate at which slider ticks are placed. */
|
/** Rate at which slider ticks are placed. */
|
||||||
private static float sliderTickRate = 1.0f;
|
private static float sliderTickRate = 1.0f;
|
||||||
|
|
||||||
/** Scaling factor for display elements */
|
|
||||||
private static int diameter = 1;
|
|
||||||
|
|
||||||
/** The amount of time, in milliseconds, to fade in the slider. */
|
/** The amount of time, in milliseconds, to fade in the slider. */
|
||||||
private static final int FADE_IN_TIME = 375;
|
private static final int FADE_IN_TIME = 375;
|
||||||
|
|
||||||
|
@ -122,7 +111,7 @@ public class Slider implements GameObject {
|
||||||
containerWidth = container.getWidth();
|
containerWidth = container.getWidth();
|
||||||
containerHeight = container.getHeight();
|
containerHeight = container.getHeight();
|
||||||
|
|
||||||
diameter = (int) (104 - (circleSize * 8));
|
int diameter = (int) (104 - (circleSize * 8));
|
||||||
diameter = (int) (diameter * HitObject.getXMultiplier()); // convert from Osupixels (640x480)
|
diameter = (int) (diameter * HitObject.getXMultiplier()); // convert from Osupixels (640x480)
|
||||||
|
|
||||||
// slider ball
|
// slider ball
|
||||||
|
@ -399,7 +388,6 @@ public class Slider implements GameObject {
|
||||||
|
|
||||||
// calculate and send slider result
|
// calculate and send slider result
|
||||||
hitResult();
|
hitResult();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -481,8 +469,6 @@ public class Slider implements GameObject {
|
||||||
this.curve = new CatmullCurve(hitObject, color);
|
this.curve = new CatmullCurve(hitObject, color);
|
||||||
else
|
else
|
||||||
this.curve = new LinearBezier(hitObject, color, hitObject.getSliderType() == HitObject.SLIDER_LINEAR);
|
this.curve = new LinearBezier(hitObject, color, hitObject.getSliderType() == HitObject.SLIDER_LINEAR);
|
||||||
|
|
||||||
this.curve.setScale(diameter );//* 118 / 128);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -37,6 +37,9 @@ public abstract class Curve {
|
||||||
/** Points generated along the curve should be spaced this far apart. */
|
/** Points generated along the curve should be spaced this far apart. */
|
||||||
protected static float CURVE_POINTS_SEPERATION = 5;
|
protected static float CURVE_POINTS_SEPERATION = 5;
|
||||||
|
|
||||||
|
/** The width and height of the display container this curve gets drawn into */
|
||||||
|
protected static int containerWidth = 0, containerHeight = 0;
|
||||||
|
|
||||||
/** The associated HitObject. */
|
/** The associated HitObject. */
|
||||||
protected HitObject hitObject;
|
protected HitObject hitObject;
|
||||||
|
|
||||||
|
@ -46,9 +49,6 @@ public abstract class Curve {
|
||||||
/** The scaled slider x, y coordinate lists. */
|
/** The scaled slider x, y coordinate lists. */
|
||||||
protected float[] sliderX, sliderY;
|
protected float[] sliderX, sliderY;
|
||||||
|
|
||||||
/** scaling factor for drawing. */
|
|
||||||
protected static float scale;
|
|
||||||
|
|
||||||
/** Per-curve render-state used for the new style curve renders*/
|
/** Per-curve render-state used for the new style curve renders*/
|
||||||
private CurveRenderState renderState;
|
private CurveRenderState renderState;
|
||||||
|
|
||||||
|
@ -66,10 +66,22 @@ public abstract class Curve {
|
||||||
this.y = hitObject.getScaledY();
|
this.y = hitObject.getScaledY();
|
||||||
this.sliderX = hitObject.getScaledSliderX();
|
this.sliderX = hitObject.getScaledSliderX();
|
||||||
this.sliderY = hitObject.getScaledSliderY();
|
this.sliderY = hitObject.getScaledSliderY();
|
||||||
this.scale = 100;
|
|
||||||
this.renderState = null;
|
this.renderState = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the width and height of the container that Curves get drawn into
|
||||||
|
* Should be called before any curves are drawn.
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
*/
|
||||||
|
public static void init(int width, int height, float circleSize)
|
||||||
|
{
|
||||||
|
containerWidth = width;
|
||||||
|
containerHeight = height;
|
||||||
|
CurveRenderState.init(width, height, circleSize);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the point on the curve at a value t.
|
* Returns the point on the curve at a value t.
|
||||||
* @param t the t value [0, 1]
|
* @param t the t value [0, 1]
|
||||||
|
@ -83,13 +95,11 @@ public abstract class Curve {
|
||||||
*/
|
*/
|
||||||
public void draw(Color color) {
|
public void draw(Color color) {
|
||||||
if (curve == null) {
|
if (curve == null) {
|
||||||
Log.error("draw curve"+this);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Options.GameOption.NEW_SLIDER.getBooleanValue()) {
|
if (Options.GameOption.NEW_SLIDER.getBooleanValue()) {
|
||||||
if(renderState == null)
|
if (renderState == null) {
|
||||||
{
|
renderState = new CurveRenderState(hitObject);
|
||||||
renderState = new CurveRenderState(scale,hitObject);
|
|
||||||
}
|
}
|
||||||
renderState.draw(color, curve);
|
renderState.draw(color, curve);
|
||||||
} else {
|
} else {
|
||||||
|
@ -126,14 +136,6 @@ public abstract class Curve {
|
||||||
*/
|
*/
|
||||||
public float getY(int i) { return (i == 0) ? y : sliderY[i - 1]; }
|
public float getY(int i) { return (i == 0) ? y : sliderY[i - 1]; }
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the scaling factor.
|
|
||||||
* @param factor the new scaling factor for the UI representation
|
|
||||||
*/
|
|
||||||
public static void setScale(float factor) {
|
|
||||||
scale = factor;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Linear interpolation of a and b at t.
|
* Linear interpolation of a and b at t.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -41,11 +41,14 @@ import org.newdawn.slick.util.Log;
|
||||||
*/
|
*/
|
||||||
public class CurveRenderState {
|
public class CurveRenderState {
|
||||||
|
|
||||||
|
/** The width and height of the display container this curve gets drawn into */
|
||||||
|
protected static int containerWidth, containerHeight;
|
||||||
|
|
||||||
/** cached drawn slider, only used if new style sliders are activated */
|
/** cached drawn slider, only used if new style sliders are activated */
|
||||||
public Rendertarget fbo;
|
public Rendertarget fbo;
|
||||||
|
|
||||||
/** thickness of the curve */
|
/** thickness of the curve */
|
||||||
float scale;
|
protected static int scale;
|
||||||
|
|
||||||
/** The HitObject associated with the curve to be drawn */
|
/** The HitObject associated with the curve to be drawn */
|
||||||
HitObject hitObject;
|
HitObject hitObject;
|
||||||
|
@ -53,12 +56,40 @@ public class CurveRenderState {
|
||||||
/** Static state that's needed to draw the new style curves */
|
/** Static state that's needed to draw the new style curves */
|
||||||
private static final NewCurveStyleState staticState = new NewCurveStyleState();
|
private static final NewCurveStyleState staticState = new NewCurveStyleState();
|
||||||
|
|
||||||
public CurveRenderState(float scale, HitObject hitObject) {
|
/**
|
||||||
|
* Set the width and height of the container that Curves get drawn into
|
||||||
|
* Should be called before any curves are drawn.
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
*/
|
||||||
|
public static void init(int width, int height, float circleSize)
|
||||||
|
{
|
||||||
|
containerWidth = width;
|
||||||
|
containerHeight = height;
|
||||||
|
//equivalent to what happens in Slider.init
|
||||||
|
scale = (int) (104 - (circleSize * 8));
|
||||||
|
scale = (int) (scale * HitObject.getXMultiplier()); // convert from Osupixels (640x480)
|
||||||
|
//scale = scale * 118 / 128; //for curves exaclty as big as the sliderball
|
||||||
|
FrameBufferCache.init(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an object to hold the render state that's necessary to draw a curve.
|
||||||
|
* @param hitObject the HitObject that represents this curve, just used as a
|
||||||
|
* unique ID
|
||||||
|
*/
|
||||||
|
public CurveRenderState(HitObject hitObject) {
|
||||||
fbo = null;
|
fbo = null;
|
||||||
this.scale = scale;
|
|
||||||
this.hitObject = hitObject;
|
this.hitObject = hitObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw a curve to the screen that's tinted with `color`. The first time
|
||||||
|
* this is called this caches the image result of the curve and on subsequent
|
||||||
|
* runs it just draws the cached copy to the screen.
|
||||||
|
* @param color tint of the curve
|
||||||
|
* @param curve the points along the curve to be drawn
|
||||||
|
*/
|
||||||
public void draw(Color color, Vec2f[] curve) {
|
public void draw(Color color, Vec2f[] curve) {
|
||||||
float alpha = color.a;
|
float alpha = color.a;
|
||||||
//if this curve hasn't been drawn, draw it and cache the result
|
//if this curve hasn't been drawn, draw it and cache the result
|
||||||
|
@ -108,6 +139,11 @@ public class CurveRenderState {
|
||||||
FrameBufferCache.getInstance().freeMappingFor(hitObject);
|
FrameBufferCache.getInstance().freeMappingFor(hitObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Just a structure to hold all the important OpenGL state that needs to be
|
||||||
|
* changed to draw the curve. This is used to backup and restore the state
|
||||||
|
* so that the code outside of this (mainly Slick2D) doesn't break
|
||||||
|
*/
|
||||||
private class RenderState {
|
private class RenderState {
|
||||||
boolean smoothedPoly;
|
boolean smoothedPoly;
|
||||||
boolean blendEnabled;
|
boolean blendEnabled;
|
||||||
|
@ -119,6 +155,11 @@ public class CurveRenderState {
|
||||||
int oldArrayBuffer;
|
int oldArrayBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Backup the current state of the relevant OpenGL state and change it to
|
||||||
|
* what's needed to draw the curve
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
private RenderState startRender() {
|
private RenderState startRender() {
|
||||||
RenderState state = new RenderState();
|
RenderState state = new RenderState();
|
||||||
state.smoothedPoly = GL11.glGetBoolean(GL11.GL_POLYGON_SMOOTH);
|
state.smoothedPoly = GL11.glGetBoolean(GL11.GL_POLYGON_SMOOTH);
|
||||||
|
@ -154,6 +195,10 @@ public class CurveRenderState {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore the old OpenGL state that's backed up in {@code state}
|
||||||
|
* @param state the old state to restore
|
||||||
|
*/
|
||||||
private void endRender(RenderState state) {
|
private void endRender(RenderState state) {
|
||||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
|
@ -186,12 +231,12 @@ public class CurveRenderState {
|
||||||
* @param curve the points along the curve
|
* @param curve the points along the curve
|
||||||
*/
|
*/
|
||||||
private void draw_curve(Color color, Vec2f[] curve) {
|
private void draw_curve(Color color, Vec2f[] curve) {
|
||||||
|
staticState.initGradient();
|
||||||
RenderState state = startRender();
|
RenderState state = startRender();
|
||||||
int vtx_buf;
|
int vtx_buf;
|
||||||
//floatsize * (position + texture coordinates) * (number of cones) * (vertices in a cone)
|
//The size is: floatsize * (position + texture coordinates) * (number of cones) * (vertices in a cone)
|
||||||
FloatBuffer buff = BufferUtils.createByteBuffer(4 * (4 + 2) * (2 * curve.length - 1) * (NewCurveStyleState.DIVIDES + 2)).asFloatBuffer();
|
FloatBuffer buff = BufferUtils.createByteBuffer(4 * (4 + 2) * (2 * curve.length - 1) * (NewCurveStyleState.DIVIDES + 2)).asFloatBuffer();
|
||||||
staticState.initShaderProgram();
|
staticState.initShaderProgram();
|
||||||
staticState.initGradient();
|
|
||||||
vtx_buf = GL15.glGenBuffers();
|
vtx_buf = GL15.glGenBuffers();
|
||||||
for (int i = 0; i < curve.length; ++i) {
|
for (int i = 0; i < curve.length; ++i) {
|
||||||
float x = curve[i].x;
|
float x = curve[i].x;
|
||||||
|
@ -211,7 +256,20 @@ public class CurveRenderState {
|
||||||
buff.flip();
|
buff.flip();
|
||||||
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vtx_buf);
|
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vtx_buf);
|
||||||
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buff, GL15.GL_STATIC_DRAW);
|
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buff, GL15.GL_STATIC_DRAW);
|
||||||
staticState.render(color, curve.length * 2 - 1, vtx_buf);
|
GL20.glUseProgram(staticState.program);
|
||||||
|
GL20.glEnableVertexAttribArray(staticState.attribLoc);
|
||||||
|
GL20.glEnableVertexAttribArray(staticState.texCoordLoc);
|
||||||
|
GL20.glUniform1i(staticState.texLoc, 0);
|
||||||
|
GL20.glUniform3f(staticState.colLoc, color.r, color.g, color.b);
|
||||||
|
//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
|
||||||
|
//2*4 is for skipping the first 2 floats (u,v)
|
||||||
|
GL20.glVertexAttribPointer(staticState.attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
|
||||||
|
GL20.glVertexAttribPointer(staticState.texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
|
||||||
|
for (int i = 0; i < curve.length*2-1; ++i) {
|
||||||
|
GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
|
||||||
|
}
|
||||||
|
GL20.glDisableVertexAttribArray(staticState.texCoordLoc);
|
||||||
|
GL20.glDisableVertexAttribArray(staticState.attribLoc);
|
||||||
GL15.glDeleteBuffers(vtx_buf);
|
GL15.glDeleteBuffers(vtx_buf);
|
||||||
endRender(state);
|
endRender(state);
|
||||||
}
|
}
|
||||||
|
@ -226,8 +284,8 @@ public class CurveRenderState {
|
||||||
* @param DIVIDES the base of the cone is a regular polygon with this many sides
|
* @param DIVIDES the base of the cone is a regular polygon with this many sides
|
||||||
*/
|
*/
|
||||||
protected void fillCone(FloatBuffer buff, float x1, float y1, final int DIVIDES) {
|
protected void fillCone(FloatBuffer buff, float x1, float y1, final int DIVIDES) {
|
||||||
float divx = Options.getLatestResolutionWidth() / 2.0f;
|
float divx = containerWidth / 2.0f;
|
||||||
float divy = Options.getLatestResolutionHeight() / 2.0f;
|
float divy = containerHeight / 2.0f;
|
||||||
float offx = -1.0f;
|
float offx = -1.0f;
|
||||||
float offy = 1.0f;
|
float offy = 1.0f;
|
||||||
float x, y;
|
float x, y;
|
||||||
|
@ -271,7 +329,7 @@ public class CurveRenderState {
|
||||||
* Contains all the necessary state that needs to be tracked to draw curves
|
* Contains all the necessary state that needs to be tracked to draw curves
|
||||||
* in the new style and not re-create the shader each time.
|
* in the new style and not re-create the shader each time.
|
||||||
*
|
*
|
||||||
* @author Bigpet {@literal <dravorek@gmail.com>}
|
* @author Bigpet {@literal <dravorek (at) gmail.com>}
|
||||||
*/
|
*/
|
||||||
private static class NewCurveStyleState {
|
private static class NewCurveStyleState {
|
||||||
|
|
||||||
|
@ -281,29 +339,22 @@ public class CurveRenderState {
|
||||||
*/
|
*/
|
||||||
protected static final int DIVIDES = 30;
|
protected static final int DIVIDES = 30;
|
||||||
|
|
||||||
/**
|
/** OpenGL shader program ID used to draw and recolor the curve */
|
||||||
* OpenGL shader program ID used to draw and recolor the curve
|
|
||||||
*/
|
|
||||||
protected int program = 0;
|
protected int program = 0;
|
||||||
|
|
||||||
/**
|
/** OpenGL shader attribute location of the vertex position attribute */
|
||||||
* OpenGL shader attribute location of the vertex position attribute
|
|
||||||
*/
|
|
||||||
protected int attribLoc = 0;
|
protected int attribLoc = 0;
|
||||||
|
|
||||||
/**
|
/** OpenGL shader attribute location of the texture coordinate attribute */
|
||||||
* OpenGL shader attribute location of the texture coordinate attribute
|
|
||||||
*/
|
|
||||||
protected int texCoordLoc = 0;
|
protected int texCoordLoc = 0;
|
||||||
|
|
||||||
/**
|
/** OpenGL shader uniform location of the color attribute */
|
||||||
* OpenGL shader uniform location of the color attribute
|
|
||||||
*/
|
|
||||||
protected int colLoc = 0;
|
protected int colLoc = 0;
|
||||||
|
|
||||||
/**
|
/** OpenGL shader uniform location of the texture sampler attribute */
|
||||||
* OpenGL texture id for the gradient texture for the curve
|
protected int texLoc = 0;
|
||||||
*/
|
|
||||||
|
/** OpenGL texture id for the gradient texture for the curve */
|
||||||
protected int gradientTexture = 0;
|
protected int gradientTexture = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -324,7 +375,6 @@ public class CurveRenderState {
|
||||||
buff.put((byte)(255*col.g));
|
buff.put((byte)(255*col.g));
|
||||||
buff.put((byte)(255*col.b));
|
buff.put((byte)(255*col.b));
|
||||||
buff.put((byte)(255*col.a));
|
buff.put((byte)(255*col.a));
|
||||||
|
|
||||||
}
|
}
|
||||||
buff.flip();
|
buff.flip();
|
||||||
GL11.glBindTexture(GL11.GL_TEXTURE_1D, gradientTexture);
|
GL11.glBindTexture(GL11.GL_TEXTURE_1D, gradientTexture);
|
||||||
|
@ -391,38 +441,9 @@ public class CurveRenderState {
|
||||||
}
|
}
|
||||||
attribLoc = GL20.glGetAttribLocation(program, "in_position");
|
attribLoc = GL20.glGetAttribLocation(program, "in_position");
|
||||||
texCoordLoc = GL20.glGetAttribLocation(program, "in_tex_coord");
|
texCoordLoc = GL20.glGetAttribLocation(program, "in_tex_coord");
|
||||||
int texLoc = GL20.glGetUniformLocation(program, "tex");
|
texLoc = GL20.glGetUniformLocation(program, "tex");
|
||||||
colLoc = GL20.glGetUniformLocation(program, "col_tint");
|
colLoc = GL20.glGetUniformLocation(program, "col_tint");
|
||||||
GL20.glUniform1i(texLoc, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Make the drawcalls for the curve. This requires the {@code vertexBufferObject} to be filled with
|
|
||||||
* {@code numCones * (NewCurveStyleState.DIVIDES+2)} sets of (u,v,x,y,z,w) floats
|
|
||||||
* @param color the color of the curve to be drawn
|
|
||||||
* @param numCones the number of points in the {code vertexBufferObject}
|
|
||||||
* @param vertexBufferObject the OpenGL vertex buffer object ID that
|
|
||||||
* contains the positions and texture coordinates of the cones
|
|
||||||
*/
|
|
||||||
public void render(Color color, int numCones, int vertexBufferObject) {
|
|
||||||
GL20.glUseProgram(program);
|
|
||||||
GL20.glEnableVertexAttribArray(attribLoc);
|
|
||||||
GL20.glEnableVertexAttribArray(texCoordLoc);
|
|
||||||
//stride is 6*4 for the floats (4 bytes) (u,v)(x,y,z,w)
|
|
||||||
//2*4 is for skipping the first 2 floats (u,v)
|
|
||||||
GL20.glVertexAttribPointer(attribLoc, 4, GL11.GL_FLOAT, false, 6 * 4, 2 * 4);
|
|
||||||
GL20.glVertexAttribPointer(texCoordLoc, 2, GL11.GL_FLOAT, false, 6 * 4, 0);
|
|
||||||
|
|
||||||
GL20.glUniform3f(colLoc, color.r, color.g, color.b);
|
|
||||||
for (int i = 0; i < numCones; ++i) {
|
|
||||||
GL11.glDrawArrays(GL11.GL_TRIANGLE_FAN, i * (NewCurveStyleState.DIVIDES + 2), NewCurveStyleState.DIVIDES + 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GL20.glDisableVertexAttribArray(texCoordLoc);
|
|
||||||
GL20.glDisableVertexAttribArray(attribLoc);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
package itdelatrisu.opsu.render;
|
package itdelatrisu.opsu.render;
|
||||||
|
|
||||||
|
import itdelatrisu.opsu.Opsu;
|
||||||
import itdelatrisu.opsu.Options;
|
import itdelatrisu.opsu.Options;
|
||||||
import itdelatrisu.opsu.beatmap.HitObject;
|
import itdelatrisu.opsu.beatmap.HitObject;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -28,24 +29,31 @@ import org.newdawn.slick.util.Log;
|
||||||
* This is cache for OpenGL FrameBufferObjects. This is currently only used
|
* This is cache for OpenGL FrameBufferObjects. This is currently only used
|
||||||
* to draw curve objects of the new slider style. Does currently not integrate
|
* to draw curve objects of the new slider style. Does currently not integrate
|
||||||
* well and requires some manual OpenGL state manipulation to use it.
|
* well and requires some manual OpenGL state manipulation to use it.
|
||||||
* @author Bigpet {@literal <dravorek@gmail.com>}
|
* @author Bigpet {@literal <dravorek (at) gmail.com>}
|
||||||
*/
|
*/
|
||||||
public class FrameBufferCache {
|
public class FrameBufferCache {
|
||||||
private static final int INITIAL_CACHE_SIZE = 4;
|
private static final int INITIAL_CACHE_SIZE = 4;
|
||||||
private static FrameBufferCache instance = null;
|
private static FrameBufferCache instance = null;
|
||||||
private Map<HitObject, Rendertarget> cacheMap;
|
private Map<HitObject, Rendertarget> cacheMap;
|
||||||
private ArrayList<Rendertarget> cache;
|
private ArrayList<Rendertarget> cache;
|
||||||
public final int width;
|
public static int width;
|
||||||
public final int height;
|
public static int height;
|
||||||
|
|
||||||
private FrameBufferCache(int width, int height) {
|
/**
|
||||||
cache = new ArrayList<>(INITIAL_CACHE_SIZE);
|
* Set the width and height of the framebuffers in this cache.
|
||||||
cacheMap = new HashMap<>();
|
* Should be called before anything is inserted into the map.
|
||||||
this.width = width;
|
* @param width
|
||||||
this.height = height;
|
* @param height
|
||||||
for (int i = 0; i < INITIAL_CACHE_SIZE; ++i) {
|
*/
|
||||||
cache.add(Rendertarget.createRTTFramebuffer(width, height));
|
public static void init(int width, int height)
|
||||||
|
{
|
||||||
|
FrameBufferCache.width = width;
|
||||||
|
FrameBufferCache.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private FrameBufferCache() {
|
||||||
|
cache = new ArrayList<>();
|
||||||
|
cacheMap = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,7 +123,7 @@ public class FrameBufferCache {
|
||||||
*/
|
*/
|
||||||
public static FrameBufferCache getInstance() {
|
public static FrameBufferCache getInstance() {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = new FrameBufferCache(Options.getLatestResolutionWidth(), Options.getLatestResolutionHeight());
|
instance = new FrameBufferCache();
|
||||||
}
|
}
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ import itdelatrisu.opsu.objects.DummyObject;
|
||||||
import itdelatrisu.opsu.objects.GameObject;
|
import itdelatrisu.opsu.objects.GameObject;
|
||||||
import itdelatrisu.opsu.objects.Slider;
|
import itdelatrisu.opsu.objects.Slider;
|
||||||
import itdelatrisu.opsu.objects.Spinner;
|
import itdelatrisu.opsu.objects.Spinner;
|
||||||
|
import itdelatrisu.opsu.objects.curves.Curve;
|
||||||
import itdelatrisu.opsu.render.FrameBufferCache;
|
import itdelatrisu.opsu.render.FrameBufferCache;
|
||||||
import itdelatrisu.opsu.replay.PlaybackSpeed;
|
import itdelatrisu.opsu.replay.PlaybackSpeed;
|
||||||
import itdelatrisu.opsu.replay.Replay;
|
import itdelatrisu.opsu.replay.Replay;
|
||||||
|
@ -1024,7 +1025,7 @@ public class Game extends BasicGameState {
|
||||||
if (beatmap == null || beatmap.objects == null)
|
if (beatmap == null || beatmap.objects == null)
|
||||||
throw new RuntimeException("Running game with no beatmap loaded.");
|
throw new RuntimeException("Running game with no beatmap loaded.");
|
||||||
|
|
||||||
//@TODO: find a better place to clean the SliderCache
|
//free all previously cached hitobject to framebuffer mappings if some still exist
|
||||||
FrameBufferCache.getInstance().freeMap();
|
FrameBufferCache.getInstance().freeMap();
|
||||||
|
|
||||||
// grab the mouse (not working for touchscreen)
|
// grab the mouse (not working for touchscreen)
|
||||||
|
@ -1392,6 +1393,7 @@ public class Game extends BasicGameState {
|
||||||
Circle.init(container, circleSize);
|
Circle.init(container, circleSize);
|
||||||
Slider.init(container, circleSize, beatmap);
|
Slider.init(container, circleSize, beatmap);
|
||||||
Spinner.init(container);
|
Spinner.init(container);
|
||||||
|
Curve.init(container.getWidth(),container.getHeight(),circleSize);
|
||||||
|
|
||||||
// approachRate (hit object approach time)
|
// approachRate (hit object approach time)
|
||||||
if (approachRate < 5)
|
if (approachRate < 5)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user