private int SetNakaLane(CommentElement c) { // 流すレーンを決める int lane = -1; bool[] laneChecked = new bool[N_LANES]; bool[] laneIsBlank = new bool[N_LANES]; for (int i = 0; i < N_LANES; i++) { laneChecked[i] = false; laneIsBlank[i] = true; } for (int i = this.comments.Count - 1; i >= 0; i--) { CommentElement comm = this.comments[i]; // ue,shitaなコメントとチェック済みレーンをスキップ if (comm.Lane >= N_LANES || laneChecked[this.comments[i].Lane]) { continue; } laneChecked[comm.Lane] = true; // 追加直後と先行するコメントが消える直前における // 流したいコメントとの衝突判定 int t = this.fps * (COMMENT_TTL) - comm.ElapsedFrames; if (comm.ElapsedFrames * comm.PixelsPerFrame - comm.Width < 0 || t * c.PixelsPerFrame > (comm.ElapsedFrames + t) * comm.PixelsPerFrame - comm.Width) { Utils.DebugLog("not blank, lane=" + comm.Lane); laneIsBlank[comm.Lane] = false; } } for (int i = 0; i < N_LANES; i++) { if (laneIsBlank[i]) { lane = i; break; } } if (lane == -1) { // FIXME lane = N_LANES-1; } return lane; }
private int SetUeShitaLane(CommentElement c, int offset) { for (int i = 0; i < N_LANES; i++) { bool isBlank = true; foreach (var comm in this.comments) { if (comm.Lane == i + offset) { isBlank = false; break; } } if (isBlank) { return i + offset; } } return offset; }
/// <summary> /// コメントを表示リストに追加 /// </summary> /// <param name="comment"></param> public void Add(Comment comment) { if (comment.Text == null) { return; } CommentElement c = new CommentElement(); c.Comment = comment; c.Y = posY; c.Color = CommentViewer.commentColors["white"]; c.Font = CommentViewer.commentFonts["medium"]; c.Lane = -1; foreach (var cmd in comment.Commands) { if (CommentViewer.commentColors.ContainsKey(cmd)) { Utils.DebugLog("color=" + cmd); c.Color = CommentViewer.commentColors[cmd]; continue; } if (CommentViewer.commentFonts.ContainsKey(cmd)) { Utils.DebugLog("size=" + cmd); c.Font = CommentViewer.commentFonts[cmd]; continue; } if (c.Lane == -1) { if (cmd == "ue") { c.Lane = SetUeShitaLane(c, 10); } else if (cmd == "shita") { c.Lane = SetUeShitaLane(c, 20); } } } // レーン決定前にPixelsPerFrameを決めておく必要がある c.Render(); c.CalcPPF(this.Width, this.fps); if (c.Lane == -1) { c.Lane = SetNakaLane(c); } lock (lockObject) { this.comments.Add(c); } Invalidate(); posY = (posY + c.Height) % (this.Height - c.Height); }