diff --git a/src/comments/BaseComment.ts b/src/comments/BaseComment.ts index 2afaa92b..b2f2ff0e 100755 --- a/src/comments/BaseComment.ts +++ b/src/comments/BaseComment.ts @@ -40,7 +40,7 @@ class BaseComment implements IComment { */ constructor(comment: FormattedComment, renderer: IRenderer, index: number) { this.renderer = renderer; - this.posY = 0; + this.posY = -1; this.pos = { x: 0, y: 0 }; comment.content = comment.content.replace(/\t/g, "\u2003\u2003"); this.comment = this.convertComment(comment); diff --git a/src/comments/HTML5Comment.ts b/src/comments/HTML5Comment.ts index 38f7e498..e25c0858 100755 --- a/src/comments/HTML5Comment.ts +++ b/src/comments/HTML5Comment.ts @@ -30,7 +30,7 @@ class HTML5Comment extends BaseComment { override readonly pluginName: string = "HTML5Comment"; constructor(comment: FormattedComment, context: IRenderer, index: number) { super(comment, context, index); - this.posY = 0; + this.posY = -1; } override get content() { diff --git a/src/main.ts b/src/main.ts index 19c83493..198fe0e2 100755 --- a/src/main.ts +++ b/src/main.ts @@ -193,7 +193,7 @@ class NiconiComments { const getCommentPosStart = performance.now(); if (this.processedCommentIndex + 1 >= end) return; for (const comment of data.slice(this.processedCommentIndex, end)) { - if (comment.invisible) continue; + if (comment.invisible || (comment.posY > -1 && !lazy)) continue; if (comment.loc === "naka") { processMovableComment(comment, this.collision, this.timeline, lazy); } else { diff --git a/src/utils/comment.ts b/src/utils/comment.ts index 4a6f3217..912cf296 100755 --- a/src/utils/comment.ts +++ b/src/utils/comment.ts @@ -622,6 +622,7 @@ const processMovableComment = ( for (let j = beforeVpos, n = comment.long + 125; j < n; j++) { const vpos = comment.vpos + j; const leftPos = getPosX(comment.comment, vpos); + if (timeline[vpos]?.includes(comment)) break; arrayPush(timeline, vpos, comment); if ( leftPos + comment.width + config.collisionPadding >= @@ -668,12 +669,16 @@ const getMovablePosY = ( } let posY = 0; let isChanged = true; + let lastUpdatedIndex: number | undefined = undefined; while (isChanged) { isChanged = false; - for (let j = beforeVpos, n = comment.long + 125; j < n; j++) { + for (let j = beforeVpos, n = comment.long + 125; j < n; j += 5) { const vpos = comment.vpos + j; const leftPos = getPosX(comment.comment, vpos); let isBreak = false; + if (lastUpdatedIndex !== undefined && lastUpdatedIndex === vpos) { + return posY; + } if ( leftPos + comment.width >= config.collisionRange.right && leftPos <= config.collisionRange.right @@ -681,6 +686,7 @@ const getMovablePosY = ( const result = getPosY(posY, comment, collision.right[vpos]); posY = result.currentPos; isChanged ||= result.isChanged; + if (result.isChanged) lastUpdatedIndex = vpos; isBreak = result.isBreak; } if ( @@ -690,6 +696,7 @@ const getMovablePosY = ( const result = getPosY(posY, comment, collision.left[vpos]); posY = result.currentPos; isChanged ||= result.isChanged; + if (result.isChanged) lastUpdatedIndex = vpos; isBreak = result.isBreak; } if (isBreak) return posY; @@ -715,11 +722,13 @@ const getPosY = ( let isBreak = false; if (!collision) return { currentPos, isChanged, isBreak }; for (const collisionItem of collision) { + if (collisionItem.index === targetComment.index || collisionItem.posY < 0) + continue; if ( - currentPos < collisionItem.posY + collisionItem.height && - currentPos + targetComment.height > collisionItem.posY && collisionItem.owner === targetComment.owner && - collisionItem.layer === targetComment.layer + collisionItem.layer === targetComment.layer && + currentPos < collisionItem.posY + collisionItem.height && + currentPos + targetComment.height > collisionItem.posY ) { if (collisionItem.posY + collisionItem.height > currentPos) { currentPos = collisionItem.posY + collisionItem.height;