Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions modchart/backend/graphics/CtxRenderer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,18 @@ class CtxRenderer {
while (i < count) {
var item = queue[i];
for (camera in item.cameras) {
var dc = camera.startTrianglesBatch(item.graphic, item.antialiasing, item.isColored, item.blend, item.hasColorOffsets, item.shader);
@:privateAccess final cameraBounds = camera._bounds.set(camera.viewMarginLeft, camera.viewMarginTop, camera.viewWidth, camera.viewHeight);

final point = FlxPoint.weak(camera.scroll.x * -item.parent.scrollFactor.x, camera.scroll.y * -item.parent.scrollFactor.y);

if (item.color != null)
dc.addTriangles(item.vertices.toFloatFlash(), item.indices.toIntFlash(), item.uvs.toFloatFlash(), emptyVec, point, cameraBounds,
item.color);
else if (item.colors != null)
dc.addGradientTriangles(item.vertices.toFloatFlash(), item.indices.toIntFlash(), item.uvs.toFloatFlash(), point, cameraBounds, item.colors);
final drawItem:FlxDrawTrianglesItem = camera.startTrianglesBatch(item.graphic, item.antialiasing, item.isColored, item.blend, item.hasColorOffsets, item.shader);

if (item.color != null){
drawItem.addTriangles(item.vertices.toFloatFlash(), item.indices.toIntFlash(), item.uvs.toFloatFlash(), null, point, cameraBounds, item.color);
} else if (item.colors != null){
drawItem.addColoredTriangles(item.vertices.toFloatFlash(), item.indices.toIntFlash(), item.uvs.toFloatFlash(), null, point, cameraBounds, item.colors);
}

}
i++;
}
Expand Down
2 changes: 1 addition & 1 deletion modchart/backend/graphics/DrawCommand.hx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class DrawCommand {

// each has a different use
var color:Null<ColorTransform> = null;
var colors:Null<NativeVector<ColorTransform>> = null;
var colors:Null<Array<ColorTransform>> = null;

var zIndex:Int = 0;
}
4 changes: 0 additions & 4 deletions modchart/backend/graphics/renderers/ArrowRenderer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,15 @@ final class ArrowRenderer extends BaseRenderer<FlxSprite> {
// top left
uvData[k++] = uvRectangle.left;
uvData[k++] = uvRectangle.top;
uvData[k++] = 1 / projectionZ[0];
// top right
uvData[k++] = uvRectangle.right;
uvData[k++] = uvRectangle.top;
uvData[k++] = 1 / projectionZ[1];
// bottom left
uvData[k++] = uvRectangle.left;
uvData[k++] = uvRectangle.bottom;
uvData[k++] = 1 / projectionZ[2];
// bottom right
uvData[k++] = uvRectangle.right;
uvData[k++] = uvRectangle.bottom;
uvData[k++] = 1 / projectionZ[3];
#else
// top left
uvData[k++] = uvRectangle.x;
Expand Down
10 changes: 7 additions & 3 deletions modchart/backend/graphics/renderers/HoldRenderer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ final class HoldRenderer extends BaseRenderer<FlxSprite> {
basePos.y += Adapter.instance.getDefaultReceptorY(lane, player);

var vertices = new NativeVector(8 * HOLD_SUBDIVISIONS);
var transfTotal = new NativeVector<ColorTransform>(HOLD_SUBDIVISIONS);
var transfTotal:Array<ColorTransform> = [];
var tID = 0;

var lastData:ArrowData = null;
Expand Down Expand Up @@ -299,8 +299,12 @@ final class HoldRenderer extends BaseRenderer<FlxSprite> {

var ctr:ColorTransform;

transfTotal[tID++] = ctr = new ColorTransform(negGlow, negGlow, negGlow, out1.visuals.alpha * item.alpha,
Math.round(out1.visuals.glowR * absGlow), Math.round(out1.visuals.glowG * absGlow), Math.round(out1.visuals.glowB * absGlow));
ctr = new ColorTransform(negGlow, negGlow, negGlow, out1.visuals.alpha * item.alpha,
Math.round(out1.visuals.glowR * absGlow), Math.round(out1.visuals.glowG * absGlow), Math.round(out1.visuals.glowB * absGlow));

for(i in 0...HOLD_SUBDIVISIONS){
transfTotal.push(ctr);
}

if (ctr.hasRGBMultipliers() || ctr.alphaMultiplier != 1)
hasC = true;
Expand Down
9 changes: 4 additions & 5 deletions modchart/backend/graphics/renderers/PathRenderer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ final class PathRenderer extends BaseRenderer<FlxSprite> {

public function updateTris(divisions:Int) {
if (divisions != __lastDivisions) {
uvt = new NativeVector<Float>(divisions * 12);
uvt = new NativeVector<Float>(divisions * 9);
indices = new NativeVector<Int>(divisions * 6);
var ui = 0, ii = 0, vertCount = 0;
for (div in 0...divisions) {
for (_ in 0...4) {
uvt.set(ui++, 0);
uvt.set(ui++, 0);
uvt.set(ui++, 1);
}

// indices
Expand Down Expand Up @@ -93,7 +92,7 @@ final class PathRenderer extends BaseRenderer<FlxSprite> {
final colored = Config.ARROW_PATHS_CONFIG.APPLY_COLOR;
final applyAlpha = Config.ARROW_PATHS_CONFIG.APPLY_ALPHA;

final transforms = new NativeVector<ColorTransform>(segs);
final transforms:Array<ColorTransform> = [];
var tID:Int = 0;

var hasC = false;
Expand Down Expand Up @@ -156,8 +155,8 @@ final class PathRenderer extends BaseRenderer<FlxSprite> {

var ctr:ColorTransform;

transforms[tID++] = ctr = new ColorTransform(negGlow, negGlow, negGlow, fAlpha * pathAlpha, Math.round(p0.visuals.glowR * absGlow),
Math.round(p0.visuals.glowG * absGlow), Math.round(p0.visuals.glowB * absGlow));
transforms.push(ctr = new ColorTransform(negGlow, negGlow, negGlow, fAlpha * pathAlpha, Math.round(p0.visuals.glowR * absGlow),
Math.round(p0.visuals.glowG * absGlow), Math.round(p0.visuals.glowB * absGlow)));

if (ctr.hasRGBMultipliers() || ctr.alphaMultiplier != 1)
hasC = true;
Expand Down
53 changes: 24 additions & 29 deletions modchart/backend/util/ModchartUtil.hx
Original file line number Diff line number Diff line change
Expand Up @@ -144,43 +144,39 @@ using StringTools;
inline static public function getHoldUVT(arrow:FlxSprite, subs:Int):Vector<Float> {
var frameAngle = -ModchartUtil.getFrameAngle(arrow);

var uv = new Vector<Float>(12 * subs);
var uv = new Vector<Float>(8 * subs);

// i think this solution is a lot better -swordcube
// and yes i tested to make sure it works -swordcube again
var frameUV:FlxRect = cast arrow.frame.uv;
var frameUV = arrow.frame.uv;

var left = frameUV.x;
var right = frameUV.y;
var top = frameUV.width;
var bottom = frameUV.height;
// i do not like this
// but i was suggested to do this instead by theo -swordcube
var left = #if (flixel >= "6.1.0") frameUV.left #else frameUV.x #end;
var right = #if (flixel >= "6.1.0") frameUV.right #else frameUV.y #end;
var top = #if (flixel >= "6.1.0") frameUV.top #else frameUV.width #end;
var bottom = #if (flixel >= "6.1.0") frameUV.bottom #else frameUV.height #end;

var frameWidth = top - left;
var frameHeight = bottom - right;
var frameWidth = right - left;
var frameHeight = bottom - top;

var subDivided = 1.0 / subs;

// if the frame doesnt have rotation, we skip the rotated uv shit
if ((frameAngle % 360) == 0) {
for (curSub in 0...subs) {
var uvOffset = subDivided * curSub;
var subIndex = curSub * 12;
var subIndex = curSub * 8;

uv[subIndex] = left; // U
uv[subIndex + 1] = right + uvOffset * frameHeight; // V
uv[subIndex + 2] = 1; // T
uv[subIndex + 1] = top + frameHeight * uvOffset; // V

uv[subIndex + 3] = top;
uv[subIndex + 4] = right + uvOffset * frameHeight;
uv[subIndex + 5] = 1;
uv[subIndex + 2] = right;
uv[subIndex + 3] = top + frameHeight * uvOffset;

uv[subIndex + 6] = left;
uv[subIndex + 7] = right + (uvOffset + subDivided) * frameHeight;
uv[subIndex + 8] = 1;
uv[subIndex + 4] = left;
uv[subIndex + 5] = bottom - frameHeight * ((1.0 - subDivided) - uvOffset);

uv[subIndex + 9] = top;
uv[subIndex + 10] = right + (uvOffset + subDivided) * frameHeight;
uv[subIndex + 11] = 1;
uv[subIndex + 6] = right;
uv[subIndex + 7] = bottom - frameHeight * ((1.0 - subDivided) - uvOffset);
}
return uv;
}
Expand All @@ -190,7 +186,7 @@ using StringTools;
var sinA = ModchartUtil.sin(angleRad);

var uCenter = left + frameWidth * .5;
var vCenter = right + frameHeight * .5;
var vCenter = top + frameHeight * .5;

// my brain is not braining anymore
// i give up
Expand All @@ -200,10 +196,10 @@ using StringTools;

// uv coords before rotation
var uvCoords = [
[left, right + uvOffset * frameHeight], // tl
[top, right + uvOffset * frameHeight], // tr
[left, right + (uvOffset + subDivided) * frameHeight], // bl
[top, right + (uvOffset + subDivided) * frameHeight] // br
[left, top], // tl
[top, top], // tr
[left, bottom], // bl
[right, bottom] // br
];

// apply rotation
Expand All @@ -214,11 +210,10 @@ using StringTools;
var uRot = u * cosA - v * sinA;
var vRot = u * sinA + v * cosA;

var base = subIndex + i * 3;
var base = subIndex + i * 2;

uv[base] = uRot + uCenter; // U
uv[base + 1] = vRot + vCenter; // V
uv[base + 2] = 1; // T
}
}

Expand Down