6 Commits

9 changed files with 86 additions and 25 deletions

View File

@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using Logger = Cryville.Common.Logger;
namespace Cryville.Crtr.Browsing { namespace Cryville.Crtr.Browsing {
internal class LegacyResourceManager : IResourceManager<ChartDetail> { internal class LegacyResourceManager : IResourceManager<ChartDetail> {
@@ -117,7 +118,10 @@ namespace Cryville.Crtr.Browsing {
foreach (var converter in converters[file.Extension]) { foreach (var converter in converters[file.Extension]) {
var resources = converter.ConvertFrom(file); var resources = converter.ConvertFrom(file);
foreach (var res in resources) { foreach (var res in resources) {
if (res is ChartResource) { if (!res.Valid) {
Logger.Log("main", 3, "Resource", "Attempt to import invalid resource {0}", res);
}
else if (res is ChartResource) {
var tres = (ChartResource)res; var tres = (ChartResource)res;
var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name); var dir = new DirectoryInfo(_rootPath + "/charts/" + res.Name);
if (!dir.Exists) dir.Create(); if (!dir.Exists) dir.Create();
@@ -134,6 +138,7 @@ namespace Cryville.Crtr.Browsing {
if (!dir.Exists) dir.Create(); if (!dir.Exists) dir.Create();
var dest = new FileInfo(_rootPath + "/charts/" + res.Name + "/cover" + tres.Source.Extension); var dest = new FileInfo(_rootPath + "/charts/" + res.Name + "/cover" + tres.Source.Extension);
if (!dest.Exists) tres.Source.CopyTo(dest.FullName); if (!dest.Exists) tres.Source.CopyTo(dest.FullName);
} }
else if (res is SongResource) { else if (res is SongResource) {
var tres = (SongResource)res; var tres = (SongResource)res;

View File

@@ -24,10 +24,6 @@ namespace Cryville.Crtr.Browsing {
const float SPEED = 8; const float SPEED = 8;
float _ratio; float _ratio;
#pragma warning disable IDE0051 #pragma warning disable IDE0051
void Start() {
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
}
void Update() { void Update() {
if (_value && _ratio != 1) { if (_value && _ratio != 1) {
_ratio += SPEED * Time.deltaTime; _ratio += SPEED * Time.deltaTime;
@@ -40,6 +36,10 @@ namespace Cryville.Crtr.Browsing {
UpdateGraphics(); UpdateGraphics();
} }
} }
void OnRectTransformDimensionsChange() {
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
}
#pragma warning restore IDE0051 #pragma warning restore IDE0051
void UpdateGraphics() { void UpdateGraphics() {

View File

@@ -60,7 +60,6 @@ namespace Cryville.Crtr.Browsing {
ev.callback.AddListener(e => OnPointerClick((PointerEventData)e)); ev.callback.AddListener(e => OnPointerClick((PointerEventData)e));
m_ctn.triggers.Add(ev); m_ctn.triggers.Add(ev);
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
if (MaxStep != 0) SetRatio(0.5f); if (MaxStep != 0) SetRatio(0.5f);
} }
@@ -70,6 +69,10 @@ namespace Cryville.Crtr.Browsing {
SetValueFromPos(pp); SetValueFromPos(pp);
} }
} }
void OnRectTransformDimensionsChange() {
m_handleArea.sizeDelta = new Vector2(m_handle.rect.height - m_handle.rect.width, 0);
}
#pragma warning restore IDE0051 #pragma warning restore IDE0051
Vector2 pp; Vector2 pp;

View File

@@ -12,6 +12,10 @@ namespace Cryville.Crtr.Browsing {
Name = StringUtils.EscapeFileName(name); Name = StringUtils.EscapeFileName(name);
} }
public string Name { get; private set; } public string Name { get; private set; }
public abstract bool Valid { get; }
public override string ToString() {
return string.Format("{0} ({1})", Name, ReflectionHelper.GetSimpleName(GetType()));
}
} }
public class ChartResource : Resource { public class ChartResource : Resource {
public ChartResource(string name, Chart main, ChartMeta meta) : base(name) { public ChartResource(string name, Chart main, ChartMeta meta) : base(name) {
@@ -19,17 +23,20 @@ namespace Cryville.Crtr.Browsing {
} }
public Chart Main { get; private set; } public Chart Main { get; private set; }
public ChartMeta Meta { get; private set; } public ChartMeta Meta { get; private set; }
public override bool Valid { get { return true; } }
} }
public class CoverResource : Resource { public class CoverResource : Resource {
public CoverResource(string name, FileInfo src) : base(name) { public CoverResource(string name, FileInfo src) : base(name) {
Source = src; Source = src;
} }
public FileInfo Source { get; private set; } public FileInfo Source { get; private set; }
public override bool Valid { get { return Source.Exists; } }
} }
public class SongResource : Resource { public class SongResource : Resource {
public SongResource(string name, FileInfo src) : base(name) { public SongResource(string name, FileInfo src) : base(name) {
Source = src; Source = src;
} }
public FileInfo Source { get; private set; } public FileInfo Source { get; private set; }
public override bool Valid { get { return Source.Exists; } }
} }
} }

View File

@@ -107,8 +107,14 @@ namespace Cryville.Crtr {
bool firstFrame; bool firstFrame;
double atime0; double atime0;
void Update() { void Update() {
// if (Input.GetKeyDown(KeyCode.Return)) TogglePlay(); if (started) GameUpdate();
if (started) { #if !NO_THREAD
else if (loadThread != null) LoadUpdate();
#endif
if (logEnabled) LogUpdate();
else Game.MainLogger.Enumerate((level, module, msg) => { });
}
void GameUpdate() {
try { try {
if (Screen.width != screenSize.x || Screen.height != screenSize.y) if (Screen.width != screenSize.x || Screen.height != screenSize.y)
throw new InvalidOperationException("Window resized while playing"); throw new InvalidOperationException("Window resized while playing");
@@ -144,8 +150,7 @@ namespace Cryville.Crtr {
Stop(); Stop();
} }
} }
#if !NO_THREAD void LoadUpdate() {
else if (loadThread != null) {
if (texLoader != null) { if (texLoader != null) {
string url = texLoader.url; string url = texLoader.url;
string name = StringUtils.TrimExt(url.Substring(url.LastIndexOfAny(new char[] {'/', '\\'}) + 1)); string name = StringUtils.TrimExt(url.Substring(url.LastIndexOfAny(new char[] {'/', '\\'}) + 1));
@@ -203,8 +208,8 @@ namespace Cryville.Crtr {
} }
} }
} }
#endif string timetext = string.Empty;
if (logEnabled) { void LogUpdate() {
string _logs = logs.text; string _logs = logs.text;
Game.MainLogger.Enumerate((level, module, msg) => { Game.MainLogger.Enumerate((level, module, msg) => {
string color; string color;
@@ -239,18 +244,18 @@ namespace Cryville.Crtr {
UnityEngine.Profiling.Profiler.GetTotalReservedMemory() UnityEngine.Profiling.Profiler.GetTotalReservedMemory()
#endif #endif
); );
if (started) sttext += string.Format( sttext += timetext;
if (judge != null) sttext += "\n== Scores ==\n" + judge.GetFullFormattedScoreString();
status.text = sttext;
}
void OnCameraPostRender(Camera cam) {
if (started) timetext = string.Format(
"\nSTime: {0:R}\nATime: {1:R}\nITime: {2:R}", "\nSTime: {0:R}\nATime: {1:R}\nITime: {2:R}",
cbus.Time, cbus.Time,
Game.AudioClient.Position - atime0, Game.AudioClient.Position - atime0,
inputProxy.GetTimestampAverage() inputProxy.GetTimestampAverage()
); );
if (judge != null) sttext += "\n== Scores ==\n" + judge.GetFullFormattedScoreString(); else timetext = string.Empty;
status.text = sttext;
}
else {
Game.MainLogger.Enumerate((level, module, msg) => { });
}
} }
#endregion #endregion
@@ -309,6 +314,8 @@ namespace Cryville.Crtr {
Game.NetworkTaskWorker.SuspendBackgroundTasks(); Game.NetworkTaskWorker.SuspendBackgroundTasks();
Game.AudioSession = Game.AudioSequencer.NewSession(); Game.AudioSession = Game.AudioSequencer.NewSession();
Camera.onPostRender += OnCameraPostRender;
var hitPlane = new Plane(Vector3.forward, Vector3.zero); var hitPlane = new Plane(Vector3.forward, Vector3.zero);
var r0 = Camera.main.ViewportPointToRay(new Vector3(0, 0, 1)); var r0 = Camera.main.ViewportPointToRay(new Vector3(0, 0, 1));
float dist; float dist;
@@ -430,6 +437,7 @@ namespace Cryville.Crtr {
if (nbus != null) nbus.Dispose(); if (nbus != null) nbus.Dispose();
inputProxy.Deactivate(); inputProxy.Deactivate();
foreach (var t in texs) Texture.Destroy(t.Value); foreach (var t in texs) Texture.Destroy(t.Value);
Camera.onPostRender -= OnCameraPostRender;
Logger.Log("main", 1, "Game", "Stopped"); Logger.Log("main", 1, "Game", "Stopped");
} }
catch (Exception ex) { catch (Exception ex) {

View File

@@ -21,6 +21,7 @@ namespace Cryville.Crtr.Extensions.Malody {
src = JsonConvert.DeserializeObject<MalodyChart>(reader.ReadToEnd()); src = JsonConvert.DeserializeObject<MalodyChart>(reader.ReadToEnd());
} }
if (src.meta.mode != 0) throw new NotImplementedException("The chart mode is not supported"); if (src.meta.mode != 0) throw new NotImplementedException("The chart mode is not supported");
if (src.meta.mode_ext.column != 4) throw new NotImplementedException("The key count is not supported");
ChartMeta meta = new ChartMeta() { ChartMeta meta = new ChartMeta() {
song = new ChartMeta.MetaInfo() { song = new ChartMeta.MetaInfo() {
@@ -68,7 +69,7 @@ namespace Cryville.Crtr.Extensions.Malody {
float pbeat = 0f, ctime = 0f; float pbeat = 0f, ctime = 0f;
int[] endbeat = new int[] { 0, 0, 1 }; int[] endbeat = new int[] { 0, 0, 1 };
foreach (var ev in events) { foreach (var ev in events) {
float cbeat = bp(ev.beat); float cbeat = ConvertBeat(ev.beat);
ctime += baseBpm == null ? 0 : (cbeat - pbeat) / baseBpm.Value * 60f; ctime += baseBpm == null ? 0 : (cbeat - pbeat) / baseBpm.Value * 60f;
pbeat = cbeat; pbeat = cbeat;
if (ev is MalodyChart.Time) { if (ev is MalodyChart.Time) {
@@ -105,7 +106,7 @@ namespace Cryville.Crtr.Extensions.Malody {
else throw new NotImplementedException(); else throw new NotImplementedException();
} }
else { else {
if (bp(tev.beat) > bp(endbeat)) endbeat = tev.beat; if (ConvertBeat(tev.beat) > ConvertBeat(endbeat)) endbeat = tev.beat;
var rn = new Chart.Note() { var rn = new Chart.Note() {
time = new BeatTime(tev.beat[0], tev.beat[1], tev.beat[2]), time = new BeatTime(tev.beat[0], tev.beat[1], tev.beat[2]),
motions = new List<Chart.Motion> { motions = new List<Chart.Motion> {
@@ -113,7 +114,7 @@ namespace Cryville.Crtr.Extensions.Malody {
}, },
}; };
if (tev.endbeat != null) { if (tev.endbeat != null) {
if (bp(tev.endbeat) > bp(endbeat)) endbeat = tev.endbeat; if (ConvertBeat(tev.endbeat) > ConvertBeat(endbeat)) endbeat = tev.endbeat;
rn.endtime = new BeatTime(tev.endbeat[0], tev.endbeat[1], tev.endbeat[2]); rn.endtime = new BeatTime(tev.endbeat[0], tev.endbeat[1], tev.endbeat[2]);
longEvents.Add(ev, new StartEventState { longEvents.Add(ev, new StartEventState {
Destination = rn, Destination = rn,
@@ -152,7 +153,7 @@ namespace Cryville.Crtr.Extensions.Malody {
public ChartEvent Destination { get; set; } public ChartEvent Destination { get; set; }
} }
float bp(int[] beat) { float ConvertBeat(int[] beat) {
return beat[0] + (float)beat[1] / beat[2]; return beat[0] + (float)beat[1] / beat[2];
} }
} }

View File

@@ -85,6 +85,19 @@ namespace Cryville.Crtr {
} }
return ~num; return ~num;
} }
int BinarySearchFirst(List<JudgeEvent> list, float time, int stack) {
if (list[0].Definition.stack == stack && list[0].StartClip == time) return 0;
int num = 0;
int num2 = list.Count - 1;
while (num <= num2) {
int num3 = num + (num2 - num >> 1);
int num4 = -list[num3].Definition.stack.CompareTo(stack);
if (num4 == 0) num4 = list[num3].StartClip.CompareTo(time);
if (num4 >= 0) num2 = num3 - 1;
else num = num3 + 1;
}
return num + 1;
}
public void Feed(Identifier target, float ft, float tt) { public void Feed(Identifier target, float ft, float tt) {
Forward(target, tt); Forward(target, tt);
var actlist = activeEvs[target]; var actlist = activeEvs[target];
@@ -103,11 +116,14 @@ namespace Cryville.Crtr {
if (def.scores != null) UpdateScore(def.scores); if (def.scores != null) UpdateScore(def.scores);
if (def.pass != null) Pass(def.pass); if (def.pass != null) Pass(def.pass);
actlist.RemoveAt(index); actlist.RemoveAt(index);
index = BinarySearch(actlist, ev.StartClip, def.prop); if (def.stack != def.prop && actlist.Count > 0) {
index = BinarySearchFirst(actlist, ev.StartClip, def.prop);
if (index < 0) index = ~index; if (index < 0) index = ~index;
} }
else index++; else index++;
} }
else index++;
}
} }
} }
bool Pass(Identifier[] ids) { bool Pass(Identifier[] ids) {
@@ -150,10 +166,12 @@ namespace Cryville.Crtr {
var key = scoreop.Key; var key = scoreop.Key;
_etor.ContextSelfValue = scoreSrcs[key.name.Key]; _etor.ContextSelfValue = scoreSrcs[key.name.Key];
_etor.Evaluate(scoreOps[key.name.Key], scoreop.Value); _etor.Evaluate(scoreOps[key.name.Key], scoreop.Value);
scoreSrcs[key.name.Key].Invalidate();
foreach (var s in _rs.scores) { foreach (var s in _rs.scores) {
if (s.Value.value != null) { if (s.Value.value != null) {
_etor.ContextSelfValue = scoreSrcs[s.Key.Key]; _etor.ContextSelfValue = scoreSrcs[s.Key.Key];
_etor.Evaluate(scoreOps[s.Key.Key], s.Value.value); _etor.Evaluate(scoreOps[s.Key.Key], s.Value.value);
scoreSrcs[s.Key.Key].Invalidate();
} }
} }
} }

View File

@@ -146,6 +146,8 @@ namespace Cryville.Crtr {
_ctxops.Add(IdentifierManager.SharedInstance.Request("attack_timing"), new func_attack_timing(cccb)); _ctxops.Add(IdentifierManager.SharedInstance.Request("attack_timing"), new func_attack_timing(cccb));
_ctxops.Add(IdentifierManager.SharedInstance.Request("enter_timing"), new func_enter_timing(cccb)); _ctxops.Add(IdentifierManager.SharedInstance.Request("enter_timing"), new func_enter_timing(cccb));
_ctxops.Add(IdentifierManager.SharedInstance.Request("release_timing"), new func_release_timing(cccb)); _ctxops.Add(IdentifierManager.SharedInstance.Request("release_timing"), new func_release_timing(cccb));
_ctxops.Add(IdentifierManager.SharedInstance.Request("leave_timing"), new func_leave_timing(cccb));
_ctxops.Add(IdentifierManager.SharedInstance.Request("contact_timing"), new func_contact_timing(cccb));
} }
static PdtEvaluator() { static PdtEvaluator() {
_shortops.Add(new PdtOperatorSignature("@", 2), new op_at_2()); _shortops.Add(new PdtOperatorSignature("@", 2), new op_at_2());
@@ -507,6 +509,22 @@ namespace Cryville.Crtr {
return ft > t0 && ft <= t1; return ft > t0 && ft <= t1;
} }
} }
class func_leave_timing : JudgeFunction {
public func_leave_timing(Func<int, PropSrc> ctxcb) : base(1, ctxcb) { }
protected override bool ExecuteImpl(float fn, float tn, float ft, float tt, Vector3? fv, Vector3? tv) {
if (fv == null || tv == null) return false;
var t1 = GetOperand(0).AsNumber() + tn;
return ft < t1 && tt >= t1;
}
}
class func_contact_timing : JudgeFunction {
public func_contact_timing(Func<int, PropSrc> ctxcb) : base(2, ctxcb) { }
protected override bool ExecuteImpl(float fn, float tn, float ft, float tt, Vector3? fv, Vector3? tv) {
var t0 = GetOperand(0).AsNumber() + fn;
var t1 = GetOperand(1).AsNumber() + tn;
return (fv == null || ft < t1) && (tv == null || tt >= t0);
}
}
#endregion #endregion
unsafe static class oputil { unsafe static class oputil {
public static float AsNumber(PropSrc src) { public static float AsNumber(PropSrc src) {

View File

@@ -6,6 +6,7 @@ namespace Cryville.Crtr {
public abstract class PropSrc { public abstract class PropSrc {
int _type; int _type;
byte[] _buf = null; byte[] _buf = null;
public void Invalidate() { _buf = null; }
public void Get(out int type, out byte[] value) { public void Get(out int type, out byte[] value) {
if (_buf == null) InternalGet(out _type, out _buf); if (_buf == null) InternalGet(out _type, out _buf);
type = _type; type = _type;