refactor replaystuff cursor drawing

This commit is contained in:
yugecin
2018-10-26 00:05:59 +02:00
parent a3c1cfad9e
commit 2b83657907
6 changed files with 192 additions and 105 deletions

View File

@@ -19,15 +19,10 @@
package yugecin.opsudance;
import java.awt.Point;
import java.nio.IntBuffer;
import java.util.Iterator;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.*;
import org.newdawn.slick.*;
import org.newdawn.slick.opengl.Texture;
import itdelatrisu.opsu.render.Rendertarget;
import static itdelatrisu.opsu.GameImage.*;
import static yugecin.opsudance.core.InstanceContainer.*;
@@ -40,80 +35,31 @@ public class ReplayCursor
public Color filter;
private Rendertarget fbo;
private static long nowtime;
public ReplayCursor(Color filter) {
this.filter = filter;
this.lastPosition = new Point(width2, 0);
this.fbo = Rendertarget.createRTTFramebuffer(width, height);
}
public void draw()
public void drawTrail(float trailw2, float trailh2, float txtw, float txth)
{
nowtime = System.currentTimeMillis();
// stuff copied from CurveRenderState and stuff, I don't know what I'm doing
int oldFb = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
int oldTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
//glGetInteger requires a buffer of size 16, even though just 4
//values are returned in this specific case
IntBuffer oldViewport = BufferUtils.createIntBuffer(16);
GL11.glGetInteger(GL11.GL_VIEWPORT, oldViewport);
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo.getID());
GL11.glViewport(0, 0, fbo.width, fbo.height);
// render
GL11.glClearColor(0f, 0f, 0f, 0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
final Image img = CURSOR_TRAIL.getImage();
final Texture txt = img.getTexture();
Color.white.bind();
txt.bind();
float alpha = 0f;
float alphaIncrease = .5f / trail.size;
float trailwidth2 = img.getWidth() * OPTION_CURSOR_SIZE.val / 100f / 2f;
float trailheight2 = img.getHeight() * OPTION_CURSOR_SIZE.val / 100f / 2f;
float txtwidth = txt.getWidth();
float txtheight = txt.getHeight();
GL11.glBegin(GL11.GL_QUADS);
for (Trailpart p : trail) {
alpha += alphaIncrease;
GL11.glColor4f(filter.r, filter.g, filter.b, alpha);
GL11.glTexCoord2f(0f, 0f);
GL11.glVertex3f(p.x - trailwidth2, p.y - trailheight2, 0f);
GL11.glTexCoord2f(txtwidth, 0);
GL11.glVertex3f(p.x + trailwidth2, p.y - trailheight2, 0f);
GL11.glTexCoord2f(txtwidth, txtheight);
GL11.glVertex3f(p.x + trailwidth2, p.y + trailheight2, 0f);
GL11.glTexCoord2f(0f, txtheight);
GL11.glVertex3f(p.x - trailwidth2, p.y + trailheight2, 0f);
GL11.glVertex3f(p.x - trailw2, p.y - trailh2, 0f);
GL11.glTexCoord2f(txtw, 0);
GL11.glVertex3f(p.x + trailw2, p.y - trailh2, 0f);
GL11.glTexCoord2f(txtw, txth);
GL11.glVertex3f(p.x + trailw2, p.y + trailh2, 0f);
GL11.glTexCoord2f(0f, txth);
GL11.glVertex3f(p.x - trailw2, p.y + trailh2, 0f);
}
GL11.glEnd();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, oldTex);
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, oldFb);
GL11.glViewport(oldViewport.get(0), oldViewport.get(1), oldViewport.get(2), oldViewport.get(3));
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_TEXTURE_1D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.getTextureID());
GL11.glBegin(GL11.GL_QUADS);
GL11.glColor4f(1f, 1f, 1f, 1f);
GL11.glTexCoord2f(1f, 1f);
GL11.glVertex2i(fbo.width, 0);
GL11.glTexCoord2f(0f, 1f);
GL11.glVertex2i(0, 0);
GL11.glTexCoord2f(0f, 0f);
GL11.glVertex2i(0, fbo.height);
GL11.glTexCoord2f(1f, 0f);
GL11.glVertex2i(fbo.width, fbo.height);
GL11.glEnd();
GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
public void drawCursor()
{
CURSOR.getScaledImage(OPTION_CURSOR_SIZE.val / 100f).drawCentered(lastPosition.x, lastPosition.y, filter);
CURSOR_MIDDLE.getScaledImage(OPTION_CURSOR_SIZE.val / 100f).drawCentered(lastPosition.x, lastPosition.y, filter);
}
@@ -186,11 +132,6 @@ public class ReplayCursor
return trail.size != size;
}
public void destroy()
{
this.fbo.destroyRTT();
}
private static class TrailList implements Iterable<Trailpart>
{
TrailNode first;

View File

@@ -0,0 +1,112 @@
/*
* opsu!dance - fork of opsu! with cursordance auto
* Copyright (C) 2018 yugecin
*
* opsu!dance is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* opsu!dance is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with opsu!dance. If not, see <http://www.gnu.org/licenses/>.
*/
package yugecin.opsudance;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.*;
import org.newdawn.slick.*;
import org.newdawn.slick.opengl.Texture;
import itdelatrisu.opsu.render.Rendertarget;
import static itdelatrisu.opsu.GameImage.*;
import static yugecin.opsudance.core.InstanceContainer.*;
import static yugecin.opsudance.options.Options.*;
import java.nio.IntBuffer;
public class ReplayCursors
{
public final ReplayPlayback[] playbacks;
private final Rendertarget fbo;
public ReplayCursors(int amount)
{
this.playbacks = new ReplayPlayback[amount];
this.fbo = Rendertarget.createRTTFramebuffer(width, height);
}
public void draw()
{
final Image img = CURSOR_TRAIL.getImage();
final Texture txt = img.getTexture();
final float trailw2 = img.getWidth() * OPTION_CURSOR_SIZE.val / 100f / 2f;
final float trailh2 = img.getHeight() * OPTION_CURSOR_SIZE.val / 100f / 2f;
float txtw = txt.getWidth();
float txth = txt.getHeight();
for (ReplayPlayback p : playbacks) {
if (!p.shouldDrawCursor()) {
continue;
}
// stuff copied from CurveRenderState and stuff, I don't know what I'm doing
int oldFb = GL11.glGetInteger(EXTFramebufferObject.GL_FRAMEBUFFER_BINDING_EXT);
int oldTex = GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D);
IntBuffer oldViewport = BufferUtils.createIntBuffer(16);
GL11.glGetInteger(GL11.GL_VIEWPORT, oldViewport);
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, fbo.getID());
GL11.glViewport(0, 0, fbo.width, fbo.height);
GL11.glClearColor(0f, 0f, 0f, 0f);
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
txt.bind();
GL11.glBegin(GL11.GL_QUADS);
p.cursor.drawTrail(trailw2, trailh2, txtw, txth);
GL11.glEnd();
GL11.glBindTexture(GL11.GL_TEXTURE_2D, oldTex);
EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, oldFb);
GL11.glViewport(oldViewport.get(0), oldViewport.get(1), oldViewport.get(2), oldViewport.get(3));
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
//GL11.glEnable(GL11.GL_TEXTURE_2D);
//GL11.glDisable(GL11.GL_TEXTURE_1D);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, fbo.getTextureID());
GL11.glBegin(GL11.GL_QUADS);
GL11.glColor4f(1f, 1f, 1f, 1f);
GL11.glTexCoord2f(1f, 1f);
GL11.glVertex2i(fbo.width, 0);
GL11.glTexCoord2f(0f, 1f);
GL11.glVertex2i(0, 0);
GL11.glTexCoord2f(0f, 0f);
GL11.glVertex2i(0, fbo.height);
GL11.glTexCoord2f(1f, 0f);
GL11.glVertex2i(fbo.width, fbo.height);
GL11.glEnd();
GL14.glBlendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, GL11.GL_ONE, GL11.GL_ONE_MINUS_SRC_ALPHA);
// something have to be drawn or things are broken... yeah...
CURSOR.getImage().draw(width, height);
}
for (ReplayPlayback p : playbacks) {
if (!p.shouldDrawCursor()) {
continue;
}
p.cursor.drawCursor();
}
}
public void destroy()
{
this.fbo.destroyRTT();
}
}

View File

@@ -45,8 +45,8 @@ public class ReplayPlayback {
public ReplayFrame currentFrame;
public ReplayFrame nextFrame;
private int frameIndex;
public Color color;
public Color originalcolor;
private Color color;
private final Color originalcolor;
public final ReplayCursor cursor;
private int keydelay[];
public static final int SQSIZE = 15;
@@ -71,15 +71,13 @@ public class ReplayPlayback {
private static final Color missedColor = new Color(0.4f, 0.4f, 0.4f, 1f);
public ReplayPlayback(Replay replay, HitData hitdata, Color color) {
public ReplayPlayback(Replay replay, HitData hitdata, Color color, ReplayCursor cursor) {
this.replay = replay;
this.hitdata = hitdata;
resetFrameIndex();
this.color = color;
this.originalcolor = new Color(color);
Color cursorcolor = new Color(color);
//cursorcolor.a = 0.5f;
cursor = new ReplayCursor(cursorcolor);
this.color = new Color(color);
this.originalcolor = color;
this.cursor = cursor;
keydelay = new int[4];
this.player = replay.playerName;
this.playerwidth = Fonts.SMALLBOLD.getWidth(this.player);
@@ -298,7 +296,11 @@ public class ReplayPlayback {
y = height - y;
}
cursor.setCursorPosition(renderdelta, currentFrame.getScaledX(), y);
cursor.draw();
}
public boolean shouldDrawCursor()
{
return !missed;
}
private void processKeys() {

View File

@@ -174,6 +174,7 @@ public class DisplayContainer implements ErrorDumpable, SkinChangedListener {
public void run() throws Exception {
while(!exitRequested && !(Display.isCloseRequested() && state.onCloseRequest()) || !confirmExit()) {
nowtime = System.currentTimeMillis();
delta = getDelta();
timeSinceLastRender += delta;

View File

@@ -82,6 +82,7 @@ public class InstanceContainer {
public static boolean isWidescreen;
public static int mouseX, mouseY;
public static int renderDelta;
public static long nowtime;
public static void kickstart() {
updater = new Updater();