mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 10:17:37 +02:00
Timekeeping Improvements and Small Optimizations (#544)
* make BeatActions coroutines instead of componentrs * pooled scheduled sounds implement S' entity seek * remove debug prints from last two changes * implement absolute time tracking implement DSP time resyncing * optimize GameManager * update TMPro * update IDE packages * fix dsp sync making the drift worse * fix issue with the JSL dll * relocate debug print * make scheduled pitch setter functional * any cpu
This commit is contained in:
@ -124,7 +124,7 @@ namespace HeavenStudio.Editor
|
||||
UpdateEditorStatus(true);
|
||||
|
||||
BuildDateDisplay.text = GlobalGameManager.buildTime;
|
||||
isCursorEnabled = PersistentDataManager.gameSettings.editorCursorEnable;
|
||||
isCursorEnabled = PersistentDataManager.gameSettings.editorCursorEnable;
|
||||
isDiscordEnabled = PersistentDataManager.gameSettings.discordRPCEnable;
|
||||
GameManager.instance.CursorCam.enabled = isCursorEnabled;
|
||||
}
|
||||
@ -262,7 +262,7 @@ namespace HeavenStudio.Editor
|
||||
new ExtensionFilter("Music Files", "mp3", "ogg", "wav", "aiff", "aif", "aifc")
|
||||
};
|
||||
|
||||
#if UNITY_STANDALONE_WINDOWS
|
||||
#if UNITY_STANDALONE_WINDOWS
|
||||
StandaloneFileBrowser.OpenFilePanelAsync("Open File", "", extensions, false, async (string[] paths) =>
|
||||
{
|
||||
if (paths.Length > 0)
|
||||
@ -285,7 +285,7 @@ namespace HeavenStudio.Editor
|
||||
await Task.Yield();
|
||||
}
|
||||
);
|
||||
#else
|
||||
#else
|
||||
StandaloneFileBrowser.OpenFilePanelAsync("Open File", "", extensions, false, async (string[] paths) =>
|
||||
{
|
||||
if (paths.Length > 0)
|
||||
@ -308,7 +308,7 @@ namespace HeavenStudio.Editor
|
||||
await Task.Yield();
|
||||
}
|
||||
);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
IEnumerator LoadMusic()
|
||||
@ -343,7 +343,7 @@ namespace HeavenStudio.Editor
|
||||
{
|
||||
new ExtensionFilter("Heaven Studio Remix File", "riq")
|
||||
};
|
||||
|
||||
|
||||
StandaloneFileBrowser.SaveFilePanelAsync("Save Remix As", "", "remix_level", extensions, (string path) =>
|
||||
{
|
||||
if (path != String.Empty)
|
||||
@ -404,7 +404,7 @@ namespace HeavenStudio.Editor
|
||||
{
|
||||
var path = Path.Combine(paths);
|
||||
if (path == string.Empty) return;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
string tmpDir = RiqFileHandler.ExtractRiq(path);
|
||||
@ -479,7 +479,7 @@ namespace HeavenStudio.Editor
|
||||
|
||||
if (game != null)
|
||||
{
|
||||
foreach(FreeCam c in game.GetComponentsInChildren<FreeCam>(true))
|
||||
foreach (FreeCam c in game.GetComponentsInChildren<FreeCam>(true))
|
||||
{
|
||||
c.enabled = !c.enabled;
|
||||
}
|
||||
|
@ -197,6 +197,8 @@ namespace HeavenStudio.Editor.Track
|
||||
UpdateOffsetText();
|
||||
UpdateStartingBPMText();
|
||||
UpdateStartingVolText();
|
||||
|
||||
GameManager.instance.SortEventsList();
|
||||
}
|
||||
|
||||
public void Init()
|
||||
@ -368,21 +370,22 @@ namespace HeavenStudio.Editor.Track
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Conductor cond = Conductor.instance;
|
||||
// waveform.rectTransform.anchoredPosition = new Vector2(
|
||||
// -(GameManager.instance.Beatmap.data.offset / (60.0f / GameManager.instance.Beatmap.bpm)),
|
||||
// waveform.rectTransform.anchoredPosition.y);
|
||||
|
||||
// WaveformBTN.transform.GetChild(0).GetComponent<Image>().color = (Conductor.instance.musicSource.clip != null && waveform.gameObject.activeInHierarchy) ? Color.white : Color.gray;
|
||||
// WaveformBTN.transform.GetChild(0).GetComponent<Image>().color = (cond.musicSource.clip != null && waveform.gameObject.activeInHierarchy) ? Color.white : Color.gray;
|
||||
|
||||
if (!Conductor.instance.isPlaying && !Conductor.instance.isPaused)
|
||||
if (!cond.isPlaying && !cond.isPaused)
|
||||
{
|
||||
SongBeat.text = $"Beat {string.Format("{0:0.000}", TimelineSlider.localPosition.x)}";
|
||||
SongPos.text = FormatTime((float) Conductor.instance.GetSongPosFromBeat(TimelineSlider.localPosition.x));
|
||||
SongPos.text = FormatTime(cond.GetSongPosFromBeat(TimelineSlider.localPosition.x));
|
||||
}
|
||||
else
|
||||
{
|
||||
SongBeat.text = $"Beat {string.Format("{0:0.000}", Conductor.instance.songPositionInBeats)}";
|
||||
SongPos.text = FormatTime(Conductor.instance.songPosition);
|
||||
SongBeat.text = $"Beat {string.Format("{0:0.000}", cond.songPositionInBeats)}";
|
||||
SongPos.text = FormatTime(cond.songPositionAsDouble);
|
||||
}
|
||||
|
||||
SliderControl();
|
||||
@ -449,11 +452,11 @@ namespace HeavenStudio.Editor.Track
|
||||
}
|
||||
#endregion
|
||||
|
||||
if (Input.GetMouseButton(1) && !Conductor.instance.isPlaying && Editor.MouseInRectTransform(TimelineGridSelect))
|
||||
if (Input.GetMouseButton(1) && !cond.isPlaying && Editor.MouseInRectTransform(TimelineGridSelect))
|
||||
{
|
||||
movingPlayback = true;
|
||||
}
|
||||
else if (Input.GetMouseButtonUp(1) || Conductor.instance.isPlaying)
|
||||
else if (Input.GetMouseButtonUp(1) || cond.isPlaying)
|
||||
{
|
||||
movingPlayback = false;
|
||||
}
|
||||
@ -463,17 +466,17 @@ namespace HeavenStudio.Editor.Track
|
||||
TimelineSlider.localPosition = new Vector3(Mathf.Max(Mathp.Round2Nearest(lastMousePos.x + 0.12f, Timeline.SnapInterval()), 0), TimelineSlider.transform.localPosition.y);
|
||||
|
||||
if (TimelineSlider.localPosition.x != lastBeatPos)
|
||||
Conductor.instance.SetBeat(TimelineSlider.transform.localPosition.x);
|
||||
cond.SetBeat(TimelineSlider.transform.localPosition.x);
|
||||
|
||||
lastBeatPos = TimelineSlider.localPosition.x;
|
||||
}
|
||||
|
||||
if (Conductor.instance.isPlaying)
|
||||
if (cond.isPlaying)
|
||||
PlaybackFocus(true);
|
||||
|
||||
TimelineContent.transform.localPosition = new Vector3(Mathf.Clamp(TimelineContent.transform.localPosition.x, Mathf.NegativeInfinity, 0), TimelineContent.transform.localPosition.y);
|
||||
|
||||
CurrentTempo.text = $" = {Conductor.instance.songBpm}";
|
||||
CurrentTempo.text = $" = {cond.songBpm}";
|
||||
|
||||
LayersRect.GetWorldCorners(LayerCorners);
|
||||
}
|
||||
@ -610,7 +613,7 @@ namespace HeavenStudio.Editor.Track
|
||||
|
||||
|
||||
#region Extras
|
||||
private string FormatTime(float time)
|
||||
private string FormatTime(double time)
|
||||
{
|
||||
int minutes = (int)time / 60;
|
||||
int seconds = (int)time - 60 * minutes;
|
||||
@ -793,7 +796,6 @@ namespace HeavenStudio.Editor.Track
|
||||
if (entity == null)
|
||||
{
|
||||
RiqEntity en = GameManager.instance.Beatmap.AddNewEntity(eventName, g.transform.localPosition.x, gameAction.defaultLength);
|
||||
GameManager.instance.SortEventsList();
|
||||
|
||||
tempEntity = en;
|
||||
|
||||
@ -828,9 +830,9 @@ namespace HeavenStudio.Editor.Track
|
||||
else
|
||||
{
|
||||
GameManager.instance.Beatmap.Entities.Add(tempEntity);
|
||||
GameManager.instance.SortEventsList();
|
||||
}
|
||||
|
||||
GameManager.instance.SortEventsList();
|
||||
eventObj.entity = tempEntity;
|
||||
}
|
||||
else
|
||||
|
@ -47,6 +47,10 @@ namespace HeavenStudio.Editor.Track
|
||||
public bool isCreating;
|
||||
public int eventObjID;
|
||||
|
||||
Timeline tl;
|
||||
Texture2D resizeCursor;
|
||||
float leftSide, rightSide;
|
||||
|
||||
[Header("Colors")]
|
||||
public Color NormalCol;
|
||||
|
||||
@ -71,10 +75,16 @@ namespace HeavenStudio.Editor.Track
|
||||
if (i != 4)
|
||||
this.transform.GetChild(i).gameObject.SetActive(visible);
|
||||
}
|
||||
|
||||
tl = Timeline.instance;
|
||||
resizeCursor = Resources.Load<Texture2D>("Cursors/horizontal_resize");
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (tl == null)
|
||||
tl = Timeline.instance;
|
||||
|
||||
selected = Selections.instance.eventsSelected.Contains(this);
|
||||
if (eventObjID != entity.uid)
|
||||
{
|
||||
@ -82,23 +92,23 @@ namespace HeavenStudio.Editor.Track
|
||||
Debug.Log($"assigning uid {eventObjID}");
|
||||
}
|
||||
|
||||
mouseHovering = RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Editor.instance.EditorCamera) && Timeline.instance.timelineState.selected;
|
||||
mouseHovering = tl.timelineState.selected && RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Editor.instance.EditorCamera);
|
||||
|
||||
#region Optimizations
|
||||
|
||||
// thank you to @chrislo27 for suggesting the fix for this.
|
||||
// only renders blocks if they're in view of the timeline viewport
|
||||
var leftSide = rectTransform.localPosition.x;
|
||||
var rightSide = leftSide + rectTransform.sizeDelta.x;
|
||||
leftSide = rectTransform.localPosition.x;
|
||||
rightSide = leftSide + rectTransform.sizeDelta.x;
|
||||
|
||||
bool visible = (rightSide >= Timeline.instance.leftSide && leftSide <= Timeline.instance.rightSide);
|
||||
bool visible = rightSide >= tl.leftSide && leftSide <= tl.rightSide;
|
||||
|
||||
if (visible != lastVisible)
|
||||
{
|
||||
for (int i = 0; i < this.transform.childCount; i++)
|
||||
{
|
||||
if (transform.GetChild(i).gameObject != selectedImage)
|
||||
this.transform.GetChild(i).gameObject.SetActive(visible);
|
||||
// if (transform.GetChild(i).gameObject != selectedImage)
|
||||
this.transform.GetChild(i).gameObject.SetActive(visible);
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,7 +124,7 @@ namespace HeavenStudio.Editor.Track
|
||||
if (Input.GetKeyDown(KeyCode.Delete))
|
||||
{
|
||||
Selections.instance.Deselect(this);
|
||||
Timeline.instance.DestroyEventObject(entity);
|
||||
tl.DestroyEventObject(entity);
|
||||
}
|
||||
*/
|
||||
|
||||
@ -140,8 +150,10 @@ namespace HeavenStudio.Editor.Track
|
||||
Cancel();
|
||||
|
||||
if (moving)
|
||||
{
|
||||
moving = false;
|
||||
|
||||
}
|
||||
|
||||
if (selected)
|
||||
{
|
||||
selected = false;
|
||||
@ -150,14 +162,23 @@ namespace HeavenStudio.Editor.Track
|
||||
outline.GetChild(i).GetComponent<Image>().color = new Color32(0, 0, 0, 51);
|
||||
}
|
||||
|
||||
rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, Timeline.instance.LayerHeight());
|
||||
this.transform.localPosition = new Vector3(this.transform.localPosition.x, -entity["track"] * Timeline.instance.LayerHeight());
|
||||
rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, tl.LayerHeight());
|
||||
this.transform.localPosition = new Vector3(this.transform.localPosition.x, -entity["track"] * tl.LayerHeight());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!resizing)
|
||||
{
|
||||
if (Timeline.instance.eventObjs.FindAll(c => c.moving).Count > 0 && selected)
|
||||
int count = 0;
|
||||
foreach (TimelineEventObj e in tl.eventObjs)
|
||||
{
|
||||
if (e.moving)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0 && selected)
|
||||
{
|
||||
Vector3 mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
|
||||
// duplicate the entity if holding alt
|
||||
@ -170,7 +191,8 @@ namespace HeavenStudio.Editor.Track
|
||||
transform.localPosition = moveStartPos;
|
||||
OnComplete(false);
|
||||
|
||||
var te = Timeline.instance.CopyEventObject(this);
|
||||
TimelineEventObj te = tl.CopyEventObject(this);
|
||||
TimelineEventObj obj;
|
||||
|
||||
Selections.instance.DragSelect(te);
|
||||
|
||||
@ -178,10 +200,11 @@ namespace HeavenStudio.Editor.Track
|
||||
te.transform.localPosition = transform.localPosition;
|
||||
te.moveStartPos = transform.localPosition;
|
||||
|
||||
for (int i = 0; i < Timeline.instance.eventObjs.Count; i++)
|
||||
for (int i = 0; i < tl.eventObjs.Count; i++)
|
||||
{
|
||||
Timeline.instance.eventObjs[i].startPosX = mousePos.x - Timeline.instance.eventObjs[i].transform.position.x;
|
||||
Timeline.instance.eventObjs[i].startPosY = mousePos.y - Timeline.instance.eventObjs[i].transform.position.y;
|
||||
obj = tl.eventObjs[i];
|
||||
obj.startPosX = mousePos.x - obj.transform.position.x;
|
||||
obj.startPosY = mousePos.y - obj.transform.position.y;
|
||||
}
|
||||
|
||||
te.moving = true;
|
||||
@ -189,7 +212,7 @@ namespace HeavenStudio.Editor.Track
|
||||
else
|
||||
{
|
||||
this.transform.position = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY - 0.40f, 0);
|
||||
this.transform.localPosition = new Vector3(Mathf.Max(Mathp.Round2Nearest(this.transform.localPosition.x, Timeline.SnapInterval()), 0), Timeline.instance.SnapToLayer(this.transform.localPosition.y));
|
||||
this.transform.localPosition = new Vector3(Mathf.Max(Mathp.Round2Nearest(this.transform.localPosition.x, Timeline.SnapInterval()), 0), tl.SnapToLayer(this.transform.localPosition.y));
|
||||
}
|
||||
|
||||
if (lastPos != transform.localPosition)
|
||||
@ -199,8 +222,8 @@ namespace HeavenStudio.Editor.Track
|
||||
|
||||
lastPos = transform.localPosition;
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
if (moving) moving = false;
|
||||
if (resizingLeft) SetPivot(new Vector2(1, rectTransform.pivot.y));
|
||||
@ -211,7 +234,7 @@ namespace HeavenStudio.Editor.Track
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, Input.mousePosition, Editor.instance.EditorCamera, out mousePos);
|
||||
|
||||
sizeDelta = new Vector2((resizingLeft ? -mousePos.x : mousePos.x) + 0.15f, sizeDelta.y);
|
||||
sizeDelta = new Vector2(Mathf.Clamp(sizeDelta.x, Timeline.SnapInterval(), (resizingLeft ? rectTransform.localPosition.x : Mathf.Infinity)), sizeDelta.y);
|
||||
sizeDelta = new Vector2(Mathf.Clamp(sizeDelta.x, Timeline.SnapInterval(), resizingLeft ? rectTransform.localPosition.x : Mathf.Infinity), sizeDelta.y);
|
||||
|
||||
rectTransform.sizeDelta = new Vector2(Mathp.Round2Nearest(sizeDelta.x, Timeline.SnapInterval()), sizeDelta.y);
|
||||
SetPivot(new Vector2(0, rectTransform.pivot.y));
|
||||
@ -227,7 +250,7 @@ namespace HeavenStudio.Editor.Track
|
||||
if (resizing && selected || inResizeRegion && selected)
|
||||
{
|
||||
if (resizable)
|
||||
Cursor.SetCursor(Resources.Load<Texture2D>("Cursors/horizontal_resize"), new Vector2(8, 8), CursorMode.Auto);
|
||||
Cursor.SetCursor(resizeCursor, new Vector2(8, 8), CursorMode.Auto);
|
||||
}
|
||||
// should consider adding this someday
|
||||
// else if (moving && selected || mouseHovering && selected)
|
||||
@ -239,15 +262,15 @@ namespace HeavenStudio.Editor.Track
|
||||
Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto);
|
||||
}
|
||||
|
||||
rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, Timeline.instance.LayerHeight());
|
||||
this.transform.localPosition = new Vector3(this.transform.localPosition.x, -entity["track"] * Timeline.instance.LayerHeight());
|
||||
rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, tl.LayerHeight());
|
||||
this.transform.localPosition = new Vector3(this.transform.localPosition.x, -entity["track"] * tl.LayerHeight());
|
||||
}
|
||||
|
||||
#region ClickEvents
|
||||
|
||||
public void OnClick()
|
||||
{
|
||||
if (Input.GetMouseButton(0) && Timeline.instance.timelineState.selected)
|
||||
if (Input.GetMouseButton(0) && tl.timelineState.selected)
|
||||
{
|
||||
if (Input.GetKey(KeyCode.LeftShift))
|
||||
{
|
||||
@ -267,15 +290,15 @@ namespace HeavenStudio.Editor.Track
|
||||
{
|
||||
if (Input.GetMouseButton(0))
|
||||
{
|
||||
if (selected && Timeline.instance.timelineState.selected)
|
||||
if (selected && tl.timelineState.selected)
|
||||
{
|
||||
moveStartPos = transform.localPosition;
|
||||
|
||||
for (int i = 0; i < Timeline.instance.eventObjs.Count; i++)
|
||||
for (int i = 0; i < tl.eventObjs.Count; i++)
|
||||
{
|
||||
Vector3 mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
|
||||
Timeline.instance.eventObjs[i].startPosX = mousePos.x - Timeline.instance.eventObjs[i].transform.position.x;
|
||||
Timeline.instance.eventObjs[i].startPosY = mousePos.y - Timeline.instance.eventObjs[i].transform.position.y;
|
||||
tl.eventObjs[i].startPosX = mousePos.x - tl.eventObjs[i].transform.position.x;
|
||||
tl.eventObjs[i].startPosY = mousePos.y - tl.eventObjs[i].transform.position.y;
|
||||
}
|
||||
|
||||
moving = true;
|
||||
@ -289,19 +312,20 @@ namespace HeavenStudio.Editor.Track
|
||||
{
|
||||
var mgs = EventCaller.instance.minigames;
|
||||
string[] datamodels = entity.datamodel.Split('/');
|
||||
Debug.Log("Selected entity's datamodel : "+entity.datamodel);
|
||||
Debug.Log("Selected entity's datamodel : " + entity.datamodel);
|
||||
|
||||
bool isSwitchGame = datamodels[1] == "switchGame";
|
||||
int gameIndex = mgs.FindIndex(c => c.name == datamodels[isSwitchGame ? 2 : 0]);
|
||||
int block = isSwitchGame ? 0 : mgs[gameIndex].actions.FindIndex(c => c.actionName == datamodels[1]) + 1;
|
||||
|
||||
if (!isSwitchGame) {
|
||||
if (!isSwitchGame)
|
||||
{
|
||||
// hardcoded stuff
|
||||
// needs to happen because hidden blocks technically change the event index
|
||||
if (datamodels[0] == "gameManager") block -= 2;
|
||||
else if (datamodels[0] is "countIn" or "vfx") block -= 1;
|
||||
}
|
||||
|
||||
|
||||
GridGameSelector.instance.SelectGame(datamodels[isSwitchGame ? 2 : 0], block);
|
||||
}
|
||||
}
|
||||
@ -311,11 +335,11 @@ namespace HeavenStudio.Editor.Track
|
||||
// lastPos_ = this.lastPos_;
|
||||
// previousPos = this.transform.localPosition;
|
||||
|
||||
if (selected && Timeline.instance.timelineState.selected)
|
||||
if (selected && tl.timelineState.selected)
|
||||
{
|
||||
if (wasDuplicated)
|
||||
{
|
||||
Timeline.instance.FinalizeDuplicateEventStack();
|
||||
tl.FinalizeDuplicateEventStack();
|
||||
wasDuplicated = false;
|
||||
}
|
||||
if (eligibleToMove)
|
||||
@ -430,8 +454,9 @@ namespace HeavenStudio.Editor.Track
|
||||
{
|
||||
entity.length = rectTransform.sizeDelta.x;
|
||||
entity.beat = this.transform.localPosition.x;
|
||||
GameManager.instance.SortEventsList();
|
||||
entity["track"] = GetTrack();
|
||||
|
||||
GameManager.instance.SortEventsList();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
Reference in New Issue
Block a user