From a95046a3e59322240dc7ab1b0d8a5a2bb6363e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=A6=E5=8F=B3=E7=9C=8B?= <1918891542@qq.com> Date: Mon, 24 Jul 2023 19:32:48 +0800 Subject: [PATCH] minor update --- .../Gallop/Live/Cutt/LiveTimelineWorkSheet.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineWorkSheet.cs b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineWorkSheet.cs index ec095a4..b366886 100644 --- a/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineWorkSheet.cs +++ b/Assets/Scripts/umamusume/Gallop/Live/Cutt/LiveTimelineWorkSheet.cs @@ -195,7 +195,60 @@ namespace Gallop.Live.Cutt public int depthCounter => 0; + //TO DO -> binary search algorithm public LiveTimelineKeyIndex FindCurrentKey(float currentTime) + { + if(thisList.Count > 0) + { + int ret = BinarySearchKey(0, thisList.Count - 1, currentTime); + thisTimeKeyIndex.index = ret; + thisTimeKeyIndex.key = thisList[ret]; + + if (ret + 1 != thisList.Count) + { + thisTimeKeyIndex.nextKey = thisList[ret + 1]; + } + else + { + thisTimeKeyIndex.nextKey = null; + } + if (ret - 1 >= 0) + { + thisTimeKeyIndex.prevKey = thisList[ret - 1]; + } + else + { + thisTimeKeyIndex.prevKey = null; + } + return thisTimeKeyIndex; + } + + return null; + } + + public int BinarySearchKey(int low, int high, float time) + { + float frame = time * 60; + int mid = (low + high) / 2; + + if (low == high || (frame >= thisList[mid].frame && frame < thisList[mid + 1].frame)) + { + return mid; + } + else + { + if(frame >= thisList[mid].frame) + { + return BinarySearchKey(mid + 1, high, time); + } + else + { + return BinarySearchKey(low, mid - 1, time); + } + } + } + + public LiveTimelineKeyIndex FindCurrentKeyLinear(float currentTime) { for (int i = thisList.Count - 1; i >= 0; i--) { @@ -222,6 +275,7 @@ namespace Gallop.Live.Cutt return thisTimeKeyIndex; } } + return null; }