Prune code.

This commit is contained in:
2022-09-30 18:19:19 +08:00
parent e8e36b83bd
commit cd4ea557c3
41 changed files with 22 additions and 3592 deletions

View File

@@ -22,9 +22,6 @@ namespace Cryville.Common {
} }
public class EmptyBinder : Binder { public class EmptyBinder : Binder {
/*static readonly Type[] emptyTypeArray = {};
static readonly object[] emptyObjectArray = {};*/
public override FieldInfo BindToField(BindingFlags bindingAttr, FieldInfo[] match, object value, CultureInfo culture) { public override FieldInfo BindToField(BindingFlags bindingAttr, FieldInfo[] match, object value, CultureInfo culture) {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@@ -1,10 +0,0 @@
using System;
using System.Runtime.InteropServices;
namespace Cryville.Common.Buffers {
public class WStringPool {
public WStringPool() {
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 704270b37917aa1458db9d14bab07073
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
using System;
namespace Cryville.Common.Pdt {
public class ElementListAttribute : Attribute { }
public class ComponentListAttribute : Attribute { }
public class PropertyListAttribute : Attribute { }
}

View File

@@ -1,749 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Cryville.Common.Pdt {
#if false
[Obsolete]
public static class PdtReader {
readonly static char[] ws = {
' ', '\t', '\n', '\r'
};
readonly static char[] spunc = {
' ', '\t', '\n', '\r',
'{', '}', ';'
};
readonly static char[] ipunc = {
' ', '\t', '\n', '\r',
'{', '}', ';',
':'
};
readonly static char[] vpunc = {
'{', '}', ';'
};
static int pos;
static string data;
static char cc {
get {
return data[pos];
}
}
static bool eof {
get {
return pos == data.Length;
}
}
static Dictionary<string, Expression> definitions;
public static T Read<T>(string _data, Binder binder = null) {
data = _data;
pos = 0;
definitions = new Dictionary<string, Expression>();
while (true) {
if (cc == '#') {
SkipChar();
var s = GetIdentifier();
switch (s) {
case "ver":
var s2 = GetString();
if (s2 != "1") throw new FormatException("Invalid PDT version");
continue;
case "define":
var s3 = GetString();
var s4 = GetValue();
definitions.Add(s3, new Expression(s4, definitions));
SkipChar();
// TODO
continue;
default:
SkipLine();
continue;
}
}
break;
}
if (binder == null)
binder = BinderAttribute.CreateBinderOfType(typeof(T));
return (T)ParseObject(typeof(T), binder);
}
static object ParseObject(Type type, Binder binder) {
// TODO Binder
object obj = type.GetConstructor(new Type[]{}).Invoke(new object[]{});
while (true) {
if (eof) return obj;
string str = GetValue();
if (cc == '{') { // List item
SkipChar();
string strkey = str;
if (typeof(IDictionary).IsAssignableFrom(type)) {
var ktype = type.GetGenericArguments()[0];
var ptype = type.GetGenericArguments()[1];
object key = binder.ChangeType(strkey, ktype, null);
object value = ParseObject(ptype, binder);
((IDictionary)obj).Add(key, value);
}
else {
MemberInfo prop = null;
Type ttype = null;
bool flag = ReflectionHelper.TryFindMemberWithAttribute<ElementListAttribute>(type, out prop);
if (!flag)
prop = ReflectionHelper.GetMember(type, strkey);
ttype = ReflectionHelper.GetMemberType(prop);
if (!typeof(IDictionary).IsAssignableFrom(ttype)) {
throw new NotImplementedException();
}
else {
var ktype = ttype.GetGenericArguments()[0];
var ptype = ttype.GetGenericArguments()[1];
if (flag) {
object key = binder.ChangeType(strkey, ktype, null);
object value = ParseObject(ptype, binder);
((IDictionary)ReflectionHelper.GetValue(prop, obj)).Add(key, value);
}
else {
ReflectionHelper.SetValue(prop, obj, ParseObject(ttype, binder));
}
}
}
}
else if (cc == ';') { // Single property
SkipChar();
string strkey;
MemberInfo prop = null;
if (str[0] == '*') { // Component-like property
strkey = str.Substring(1);
prop = ReflectionHelper.FindMemberWithAttribute<ComponentListAttribute>(type);
var ttype = ReflectionHelper.GetMemberType(prop);
if (!typeof(IList).IsAssignableFrom(ttype))
throw new Exception(); // TODO
var ktype = ttype.GetGenericArguments()[0];
object key = binder.ChangeType(strkey, ktype, null);
((IList)ReflectionHelper.GetValue(prop, obj)).Add(key);
}
else { // Common property
var kv = str.Split(new char[]{':'}, 2);
strkey = kv[0];
// TODO
if (typeof(IDictionary).IsAssignableFrom(type)) {
var ktype = type.GetGenericArguments()[0];
var ptype = type.GetGenericArguments()[1];
object key = binder.ChangeType(strkey, ktype, null);
object value = binder.ChangeType(new Expression(
kv.Length == 1 ? "true" : kv[1], definitions
), ptype, null);
((IDictionary)obj).Add(key, value);
}
else {
bool flag = ReflectionHelper.TryFindMemberWithAttribute<PropertyListAttribute>(type, out prop);
if (!flag)
prop = ReflectionHelper.GetMember(type, strkey);
var ttype = ReflectionHelper.GetMemberType(prop);
if (!typeof(IDictionary).IsAssignableFrom(ttype)) {
object value = binder.ChangeType(new Expression(
kv.Length == 1 ? "true" : kv[1], definitions
), ttype, null);
ReflectionHelper.SetValue(prop, obj, value, binder);
}
else {
var ktype = ttype.GetGenericArguments()[0];
var ptype = ttype.GetGenericArguments()[1];
object key = binder.ChangeType(strkey, ktype, null);
object value = binder.ChangeType(new Expression(
kv.Length == 1 ? "true" : kv[1], definitions
), ptype, null);
((IDictionary)ReflectionHelper.GetValue(prop, obj)).Add(key, value);
}
}
}
}
else if (cc == '}') {
try { SkipChar(); }
catch (IndexOutOfRangeException) { }
return obj;
}
else throw new Exception(); // TODO
}
}
static void SkipChar() {
pos++;
SkipWs();
}
static void SkipWs() {
while (true) {
for (; ws.Contains(cc); pos++);
if (data[pos] == '/' && data[pos + 1] == '*') {
for (; data[pos] != '*' || data[pos+1] != '/'; pos++);
pos += 2;
}
else return;
}
}
static string GetIdentifier() {
SkipWs();
string r = "";
for (; !ipunc.Contains(cc); pos++) r += cc;
SkipWs();
return r;
}
static string GetString() {
SkipWs();
string r = "";
for (; !spunc.Contains(cc); pos++) r += cc;
SkipWs();
return r;
}
static string GetValue() {
SkipWs();
string r = "";
for (; !vpunc.Contains(cc); pos++) r += cc;
SkipWs();
return r.Trim();
}
static void SkipLine() {
for (; cc != '\n'; pos++);
SkipWs();
}
}
#endif
public class ElementListAttribute : Attribute { }
public class ComponentListAttribute : Attribute { }
public class PropertyListAttribute : Attribute { }
#if false
[Obsolete]
public abstract class ExpBase {
public string exp {
get;
private set;
}
public ExpBase(string s) {
exp = s;
}
public override string ToString() {
return exp;
}
}
[Obsolete]
public abstract class ValueBase : ExpBase {
public ValueBase(string s) : base(s) { }
object preEvalResult;
byte preEvalDepth = 0;
public bool IsDynamic {
get { return preEvalDepth == 0; }
}
protected abstract object EvalInternal(IEvaluator etor);
public void PreEval(IEvaluator etor, byte depth = 1) {
if (depth == 0) throw new ArgumentException("depth cannot be 0");
if (preEvalDepth != 0 && preEvalDepth < depth) return;
try {
preEvalResult = PreEvalInternal(etor, depth);
preEvalDepth = depth;
}
catch (Exception) { }
}
protected virtual object PreEvalInternal(IEvaluator etor, byte depth) {
return Eval(etor);
}
public object Eval(IEvaluator etor) {
if (preEvalDepth != 0)
return preEvalResult;
return EvalInternal(etor);
}
}
[Obsolete]
public class Identifier : ValueBase {
public Identifier(string s) : base(s) { }
protected override object EvalInternal(IEvaluator etor) {
return etor.EvalIdentifier(exp);
}
}
[Obsolete]
public class Operand : ExpBase {
public OperandPriority Priority {
get;
private set;
}
public Operand(string s) : base(s) {
switch (s) {
case ".": Priority = OperandPriority.Prop; break;
case "*": case "/": Priority = OperandPriority.Mul; break;
case "+": case "-": Priority = OperandPriority.Add; break;
case " ": case ",": Priority = OperandPriority.Sep; break;
default: Priority = OperandPriority.None; break;
}
}
public Operand(string s, OperandPriority p) : base(s) {
Priority = p;
}
}
[Obsolete]
public enum OperandPriority {
None = 0,
Prop = 5,
NeibMul = 4,
Mul = 3,
Add = 2,
Sep = 1
}
[Obsolete]
public abstract class ConstantBase : ValueBase {
public ConstantBase(string s) : base(s) { }
}
[Obsolete]
public class CNumber : ConstantBase {
public CNumber(string s) : base(s) { }
protected override object EvalInternal(IEvaluator etor) {
return etor.ParseNumber(exp);
}
}
[Obsolete]
public class CString : ConstantBase {
public CString(string s) : base(s) { }
protected override object EvalInternal(IEvaluator etor) {
return etor.ParseString(exp);
}
}
[Obsolete]
public class BracketInitial : ExpBase {
public BracketInitial() : base("(") { }
}
[Obsolete]
public class BracketFinal : ExpBase {
public BracketFinal() : base(")") { }
}
[Obsolete]
public class Expression : ValueBase {
List<ValueBase> estack = new List<ValueBase>();
List<Operand> ostack = new List<Operand>();
StackType type;
enum StackType {
Root, Unary, Bracketed, Supportive, Function
}
readonly OperandPriority Priority;
public Expression(string s, Dictionary<string, Expression> def) : base("") {
var exp = s.Trim();
type = StackType.Root;
int pos = 0;
var b = new List<ExpBase>();
while (pos < exp.Length) {
b.Add(Forward(ref exp, ref pos));
}
var lb = b[b.Count - 1];
if (def.ContainsKey(lb.exp)) {
b.Add(def[lb.exp]);
b.Remove(lb);
}
for (int i = b.Count - 2; i >= 0; i--) {
// TODO Insertion
var lhb = b[i];
var rhb = b[i + 1];
if (lhb is ConstantBase || lhb is Expression || lhb is BracketFinal) {
if (rhb is Identifier || rhb is Expression || rhb is BracketInitial) {
b.Insert(i + 1, new Operand("*", OperandPriority.NeibMul));
}
}
else if (lhb is Identifier) {
if (rhb is Expression) {
b.Insert(i + 1, new Operand("*", OperandPriority.NeibMul));
}
if (def.ContainsKey(lhb.exp)) {
b.Insert(i, def[lhb.exp]);
b.Remove(lhb);
}
}
}
int p = 0;
estack.Add(new Expression(b, ref p, StackType.Bracketed, def));
}
public Expression Clone() {
var r = (Expression)this.MemberwiseClone();
var es = new ValueBase[estack.Count];
estack.CopyTo(es);
r.estack = es.ToList();
var os = new Operand[ostack.Count];
ostack.CopyTo(os);
r.ostack = os.ToList();
return r;
}
Expression(List<ExpBase> b, ref int p, StackType t, Dictionary<string, Expression> def) : base("") {
type = t;
if (t == StackType.Unary) {
ostack.Add((Operand)b[p]);
p++;
}
while (p < b.Count - 1) {
if (estack.Count == 0) {
var b0 = b[p];
if (b0 is Operand) {
var lp = p;
var e = new Expression(
b,
ref p,
StackType.Unary,
def
);
b.Insert(p, e);
b.RemoveRange(lp, p - lp);
p = lp;
}
else if (b0 is BracketInitial) {
var lp = p;
p++;
var e = new Expression(
b,
ref p,
StackType.Bracketed,
def
);
b.Insert(p, e);
b.RemoveRange(lp, p - lp);
p = lp;
}
estack.Add((ValueBase)b[p]);
p++;
if (t == StackType.Unary) {
if (estack.Count != 1)
throw new Exception(); // TODO
else return;
}
}
if (p >= b.Count) return;
var b1 = b[p];
if (b1 is BracketFinal) {
if (t == StackType.Bracketed) p++;
return;
}
var b2 = b[p + 1];
if (b2 is BracketInitial) {
var lp = p + 1;
p += 2;
var e = new Expression(
b,
ref p,
StackType.Bracketed,
def
);
b.Insert(p, e);
b.RemoveRange(lp, p - lp);
p = lp - 1;
b2 = b[p + 1];
}
if (b1 is Operand) {
if (estack.Count == 1)
Priority = ((Operand)b1).Priority;
if (b2 is Operand) {
var lp = p + 1;
p++;
var e = new Expression(
b,
ref p,
StackType.Unary,
def
);
b.Insert(p, e);
b.RemoveRange(lp, p - lp);
p = lp - 1;
b2 = b[p + 1];
}
if (p + 2 >= b.Count) {
ostack.Add((Operand)b1);
estack.Add((ValueBase)b2);
p += 2;
return;
}
var b3 = b[p + 2];
if (b3 is BracketFinal) {
ostack.Add((Operand)b1);
estack.Add((ValueBase)b2);
p += 2;
if (t == StackType.Bracketed) p++;
return;
}
else if (b3 is Operand) {
var o1 = (Operand)b1; var o2 = (Operand)b3;
if (o2.Priority == Priority) {
ostack.Add(o1); estack.Add((ValueBase)b2);
p += 2;
continue;
}
else if (o2.Priority > Priority) {
var lp = p + 1;
p++;
var e = new Expression(
b, ref p,
StackType.Supportive, def
);
b.Insert(p, e);
b.RemoveRange(lp, p - lp);
p = lp - 1;
continue;
}
else if (o2.Priority < Priority) {
ostack.Add(o1);
estack.Add((ValueBase)b2);
// b.RemoveRange(0, 2);
if (type == StackType.Bracketed) {
Expression cl = this.Clone();
cl.type = StackType.Supportive;
estack.Clear();
ostack.Clear();
estack.Add(cl);
Priority = o2.Priority;
p += 2;
continue;
}
else {
type = StackType.Supportive;
p += 2;
return;
}
}
}
else
throw new Exception(); // TODO
}
else
throw new Exception(); // TODO
throw new Exception(); // TODO
/*if (lb is Identifier) {
if (def.ContainsKey(lb.exp)) {
b.Add(def[lb.exp]);
b.Remove(lb);
}
}
// Unary
if (estack.Count == 0) {
if (b[0] is Operand) {
b.Add(new Expression(
b,
ref p,
StackType.Unary,
def
));
b.RemoveAt(0);
}
if (b[0] is ValueBase) {
estack.Add((ValueBase)b[0]);
b.RemoveAt(0);
if (type == StackType.Unary) return;
if (b.Count == 0) continue;
}
}
if (estack.Count == 1) {
if (b[0] is Operand)
Priority = ((Operand)b[0]).Priority;
}
// Bracket
if (lb is BracketInitial) {
b.Remove(lb);
b.Add(new Expression(b, ref p, StackType.Bracketed, def));
}
else if (lb is BracketFinal) {
if (type != StackType.Bracketed) p--;
foreach (var i in b) {
if (i is Operand) ostack.Add((Operand)i);
else if (i is BracketFinal) return;
else estack.Add((ValueBase)i);
}
}
var c = b.Count;
if (c <= 1) continue;
// Two blocks
lb = b[c - 1];
var lb1 = b[c - 2];
if (lb is Operand && lb1 is Operand) {
b.Add(new Expression(
b,
ref p,
StackType.Unary,
def
));
b.RemoveAt(b.Count - 2);
}
c = b.Count;
if (c <= 2) continue;
// Three blocks
var b0 = b[0];
var b1 = b[1];
var b2 = b[2];
if (!(b0 is Operand))
throw new Exception(); // TODO
if (!(b1 is ValueBase))
throw new Exception(); // TODO
if (!(b2 is Operand))
throw new Exception(); // TODO
var o1 = (Operand)b0; var o2 = (Operand)b2;
if (o2.Priority == Priority) {
ostack.Add(o1); estack.Add((ValueBase)b1);
b.Remove(o1); b.Remove(b1);
continue;
}
if (o2.Priority > Priority) {
b.Add(new Expression(
b, ref p,
StackType.Supportive, def
));
b.RemoveRange(1, b.Count - 2);
continue;
}
if (o2.Priority < Priority) {
ostack.Add(o1);
estack.Add((ValueBase)b1);
b.RemoveRange(0, 2);
if (type == StackType.Bracketed) {
Expression cl = this.Clone();
cl.type = StackType.Supportive;
estack.Clear();
ostack.Clear();
estack.Add(cl);
Priority = o2.Priority;
}
else {
type = StackType.Supportive;
// p = o2.Index;
return;
}
}*/
}
estack.Add((ValueBase)b[b.Count - 1]);
p++;
}
ExpBase Forward(ref string s, ref int p) {
char sc = s[p];
string r = "";
if (cat(sc) == 3) {
p++;
return new BracketInitial();
}
else if (cat(sc) == 4) {
p++;
return new BracketFinal();
}
else if (cat(sc) == 5) {
for (; p < s.Length; p++) {
if (cat(s[p]) != 5) break;
r += s[p];
}
if (r == ".") return new Operand(r);
else return new CNumber(r);
}
else if (cat(sc) == 2) {
p++;
for (; s[p] != sc; p++)
r += s[p];
p++;
return new CString(r);
}
else if (cat(sc) == 0) {
for (; p < s.Length; p++) {
if (cat(s[p]) != 0) break;
r += s[p];
}
if (p == s.Length) return new Identifier(r);
if (s[p] == '(') return new Operand(r);
else return new Identifier(r);
}
else if (cat(sc) == 1) {
p++;
return new Operand(sc.ToString());
}
else
throw new Exception(); // TODO
}
protected override object EvalInternal(IEvaluator etor) {
if (type == StackType.Unary) {
if (ostack[0].Priority == OperandPriority.None)
return etor.OperateFunction(ostack[0], estack[0].Eval(etor));
else
return etor.OperateUnary(ostack[0], estack[0].Eval(etor));
}
else {
object r = estack[0].Eval(etor);
for (int i = 0; i < ostack.Count; i++) {
r = etor.OperateBinary(
ostack[i], r, estack[i+1].Eval(etor)
);
}
return r;
}
}
public T Eval<T>(IEvaluator etor) {
return (T)etor.Cast(typeof(T), EvalInternal(etor));
}
protected override object PreEvalInternal(IEvaluator etor, byte depth) {
try { return EvalInternal(etor); }
catch (Exception) {
foreach (var v in estack)
v.PreEval(etor, depth);
throw;
}
}
// 0: Other, 1: Operand, 2: String,
// 3: SOE, 4: EOE, 5: Number
static readonly byte[] ctl = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 2, 1, 0, 1, 1, 2, 3, 4, 1, 1, 1, 1, 5, 1,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 1, 1, 1, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0,
};
static byte cat(char c) {
if (c >> 7 != 0)
return 0;
else
return ctl[c];
}
public override string ToString() {
if (type == StackType.Unary)
return string.Format("{0}{1}", ostack[0], estack[0]);
if (type == StackType.Function)
return string.Format("{0}{1}", ostack[0], estack[0]);
string r = estack[0].ToString();
for (int i = 0; i < ostack.Count; i++) {
r += ostack[i].ToString();
r += estack[i + 1].ToString();
}
if (type == StackType.Bracketed)
r = string.Format("({0})", r);
return r;
}
}
[Obsolete]
public interface IEvaluator {
object ParseNumber(string exp);
object ParseString(string exp);
object EvalIdentifier(string exp);
object OperateUnary(Operand op, object q);
object OperateBinary(Operand op, object q, object r);
object OperateFunction(Operand op, object q);
// TODO [Obsolete]
object Cast(Type type, object obj);
//public abstract Func<Type, object, object> GetCastCallback(Type dest, Type source);
}
#endif
}

View File

@@ -3,120 +3,6 @@ using System.Collections.Generic;
using System.Reflection; using System.Reflection;
namespace Cryville.Common.Unity.Input { namespace Cryville.Common.Unity.Input {
/*public class InputManager {
int newId = 0;
int GetNewId() {
newId++;
return newId;
}
PointerHandler ptrHandler;
readonly Queue<PointerInfo> ptrEv = new Queue<PointerInfo>();
readonly Dictionary<int, PointerInfo> ptr
= new Dictionary<int, PointerInfo>();
double originTime;
void Callback(int id, PointerInfo info) {
/*if (info.Phase != PointerPhase.Update)
Logger.Log(
"main", 0, "Input",
"[{0}, p{1}] {2} {3} {4} at {5} (cs:{6}, ori:{7}, prs:{8})",
info.EventTime, info.ProcessTime, info.Type,
id, info.Phase, info.Position,
info.ContactSize, info.Orientation, info.Pressure
);*
lock (ptrEv) {
ptrEv.Enqueue(info);
ptr[id] = info;
}
}
public void Init() {
try {
if (Environment.OSVersion.Platform == PlatformID.Win32NT) {
if (WindowsPointerHandler.IsSupported()) {
ptrHandler = new WindowsPointerHandler(true, GetNewId, Callback);
Logger.Log("main", 1, "Input", "Initialized windows pointer handler");
}
else if (UnityTouchHandler.IsSupported()) {
ptrHandler = new UnityTouchHandler(GetNewId, Callback);
Logger.Log("main", 1, "Input", "Initialized multi-platform pointer handler");
}
}
else if (Application.platform == RuntimePlatform.Android) {
/*if (AndroidTouchHandler.IsSupported()) {
}
else*
if (UnityTouchHandler.IsSupported()) {
ptrHandler = new UnityTouchHandler(GetNewId, Callback);
Logger.Log("main", 1, "Input", "Initialized multi-platform pointer handler");
}
}
else {
/*if (UnityPointerHandler.IsSupported()) {
enableUnityTouch();
}*
}
}
catch (Exception ex) {
Logger.Log("main", 4, "Input", "An error occured while initializing pointer handler:\n{0}", ex);
}
if (ptrHandler == null) Logger.Log("main", 3, "Input", "Pointer input is not supported on this device");
}
public void Activate() {
if (ptrHandler != null) ptrHandler.Activate();
}
public void Deactivate() {
if (ptrHandler != null) ptrHandler.Deactivate();
ptr.Clear(); ptrEv.Clear();
}
public void Dispose() {
ptrHandler.Dispose();
}
public void EnumeratePtrEvents(Action<PointerInfo> callback) {
lock (ptrEv) {
while (ptrEv.Count > 0) {
var raw = ptrEv.Dequeue();
raw.OffsetTime(originTime);
callback(raw);
}
}
}
public void EnumeratePointers(Action<PointerInfo> callback) {
lock (ptrEv) {
var upid = new List<int>();
var rmid = new List<int>();
foreach (var p in ptr) {
var raw = p.Value;
if (raw.Phase == PointerPhase.Stationary)
raw.EventTime = raw.ProcessTime = Time;
else raw.OffsetTime(originTime);
callback(raw);
if (raw.Phase == PointerPhase.Begin || raw.Phase == PointerPhase.Update)
upid.Add(p.Key);
if (raw.Phase == PointerPhase.End || raw.Phase == PointerPhase.Cancel)
rmid.Add(p.Key);
}
foreach (var i in upid) {
var p = ptr[i];
p.Phase = PointerPhase.Stationary;
ptr[i] = p;
}
foreach (var i in rmid) ptr.Remove(i);
// Logger.Log("main", 0, "Input", "Ptr count {0}", ptr.Count);
}
}
public double Time {
get {
if (ptrHandler != null) return ptrHandler.GetCurrentTimestamp() - originTime;
else return 0;
}
}
public void SyncTime(double t) {
if (ptrHandler != null) {
originTime = ptrHandler.GetCurrentTimestamp() - t;
Logger.Log("main", 0, "Input", "Sync time {0}", originTime);
}
}
}*/
public class InputManager { public class InputManager {
static readonly List<Type> HandlerRegistries = new List<Type> { static readonly List<Type> HandlerRegistries = new List<Type> {
typeof(WindowsPointerHandler), typeof(WindowsPointerHandler),

View File

@@ -1,57 +0,0 @@
using System;
using UnityEngine;
namespace Cryville.Common.Unity.Input {
#if false
[Obsolete]
public abstract class PointerHandler {
protected Func<int> newIdCallback;
protected Action<int, PointerInfo> callback;
public PointerHandler(Func<int> newIdCallback, Action<int, PointerInfo> callback) {
this.newIdCallback = newIdCallback;
this.callback = callback;
}
public abstract void Activate();
public abstract void Deactivate();
public abstract void Dispose();
public abstract double GetCurrentTimestamp();
}
[Obsolete]
public struct PointerInfo {
public int Id;
public double EventTime;
public double ProcessTime;
public PointerPhase Phase;
public PointerType Type;
public Vector2 Position;
public Vector2? ContactSize;
public uint? Orientation;
public uint? Pressure;
public double Time {
// get { return EventTime == 0 ? ProcessTime : EventTime; }
get { return ProcessTime; }
}
public void OffsetTime(double originTime) {
if (EventTime != 0) EventTime -= originTime;
if (ProcessTime != 0) ProcessTime -= originTime;
}
}
[Obsolete]
public enum PointerPhase {
Begin = 0,
Update = 2, Stationary = 3,
End = 4, Cancel = 5
}
[Obsolete]
public enum PointerType {
Unknown, Mouse, Touch, Pen, TouchPad
}
#endif
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 6f0a4eae2ebff4d4d93e2f9fe31c1383
timeCreated: 1611272693
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -4,8 +4,6 @@ using UnityEngine;
#if UNITY_5_4_OR_NEWER #if UNITY_5_4_OR_NEWER
using UnityEngine.Networking; using UnityEngine.Networking;
using UnityEngine.Rendering; using UnityEngine.Rendering;
using static UnityEngine.Networking.UnityWebRequest;
#endif #endif
namespace Cryville.Common.Unity { namespace Cryville.Common.Unity {

View File

@@ -1,5 +1,4 @@
using System; using System;
using System.Collections;
using System.ComponentModel; using System.ComponentModel;
using System.Reflection; using System.Reflection;
using UnityEngine; using UnityEngine;

View File

@@ -80,9 +80,6 @@ namespace Cryville.Crtr {
return (ChartEvent)MemberwiseClone(); return (ChartEvent)MemberwiseClone();
} }
/*[DefaultValue(0.0f)][Obsolete]
public float duration = 0.0f;*/
[JsonIgnore] [JsonIgnore]
public float Duration { public float Duration {
get { get {
@@ -96,13 +93,6 @@ namespace Cryville.Crtr {
get { return Duration > 0; } get { return Duration > 0; }
} }
/*[JsonIgnore]
public float EndBeatPosition {
get {
return BeatPosition + duration;
}
}*/
private InstantEvent attev = null; private InstantEvent attev = null;
[JsonIgnore] [JsonIgnore]
public InstantEvent AttackEvent { public InstantEvent AttackEvent {
@@ -121,14 +111,6 @@ namespace Cryville.Crtr {
} }
} }
/*[JsonIgnore]
[Obsolete]
public Dictionary<string, Func<object>> Properties { get; private set; }
[Obsolete]
protected void SubmitProperty(string name, Func<object> property) {
Properties.Add(name, property);
}*/
[JsonIgnore] [JsonIgnore]
public Dictionary<string, PropSrc> PropSrcs { get; private set; } public Dictionary<string, PropSrc> PropSrcs { get; private set; }
protected void SubmitPropSrc(string name, PropSrc property) { protected void SubmitPropSrc(string name, PropSrc property) {
@@ -141,10 +123,6 @@ namespace Cryville.Crtr {
} }
protected ChartEvent() { protected ChartEvent() {
/*
Properties = new Dictionary<string, Func<object>>();
SubmitProperty("long", () => @long);
*/
PropSrcs = new Dictionary<string, PropSrc>(); PropSrcs = new Dictionary<string, PropSrc>();
SubmitPropSrc("long", new PropSrc.Boolean(() => IsLong)); SubmitPropSrc("long", new PropSrc.Boolean(() => IsLong));
PropOps = new Dictionary<string, PropOp>(); PropOps = new Dictionary<string, PropOp>();
@@ -350,26 +328,6 @@ namespace Cryville.Crtr {
public Vector AbsoluteValue; public Vector AbsoluteValue;
[JsonIgnore] [JsonIgnore]
public MotionNode RelativeNode; public MotionNode RelativeNode;
/*public struct Node {
public ushort Id;
public Vec1 Time;
public TransitionType? Transition;
public Vec1 Rate;
public Vector Value;
public Node LerpWith(MotionNode start, float lerpedTime) {
Vec1 time = Time == null ? null : (Vec1)Time.LerpWith(start.Time, lerpedTime);
Vec1 rate = Rate == null ? null : (Vec1)Rate.LerpWith(start.Rate, lerpedTime);
Vector value = Value == null ? null : Value.LerpWith(start.Value, lerpedTime);
return new Node() {
Id = Id,
Time = time,
Transition = Transition,
Rate = rate,
Value = value
};
}
}*/
[DefaultValue(TransitionType.Ease)] [DefaultValue(TransitionType.Ease)]
public TransitionType transition = TransitionType.Ease; public TransitionType transition = TransitionType.Ease;
@@ -406,19 +364,6 @@ namespace Cryville.Crtr {
public class Note : EventContainer { public class Note : EventContainer {
public Note() : base() { public Note() : base() {
/*
SubmitProperty("judge", () => judge);
SubmitProperty("endjudge", () => endjudge);
SubmitProperty("track", () => {
if (_track == null) {
var i = motions.FirstOrDefault(m => m.RelativeNode == null && m.Name.MainName == "track");
if (i == null) _track = ((Vec1)ChartPlayer.motionRegistry["track"].InitValue).Value;
else _track = ((Vec1)i.AbsoluteValue).Value;
}
return _track.Value;
});
*/
SubmitPropSrc("judge", new PropSrc.String(() => judge)); SubmitPropSrc("judge", new PropSrc.String(() => judge));
SubmitPropSrc("endjudge", new PropSrc.String(() => endjudge)); SubmitPropSrc("endjudge", new PropSrc.String(() => endjudge));
SubmitPropSrc("track", new PropSrc.Float(() => { SubmitPropSrc("track", new PropSrc.Float(() => {
@@ -430,9 +375,6 @@ namespace Cryville.Crtr {
SubmitPropOp("endjudge", new PropOp.String(v => endjudge = v)); SubmitPropOp("endjudge", new PropOp.String(v => endjudge = v));
} }
/*[DefaultValue(false)][Obsolete]
public bool wipe = false;*/
public string judge; public string judge;
public string endjudge; public string endjudge;
@@ -441,16 +383,7 @@ namespace Cryville.Crtr {
} }
} }
/* // TODO [Obsolete]
public class InternalJudgement : ChartEvent {
public Note Parent;
public override int Priority {
get { return 0; }
}
}*/
// TODO will likely be deprecated in the future
public List<Signature> sigs; // Signatures public List<Signature> sigs; // Signatures
// TODO [Obsolete] // TODO [Obsolete]
public class Signature : ChartEvent { public class Signature : ChartEvent {

View File

@@ -1,5 +1,3 @@
//#define NO_SOUND
using Cryville.Audio.Source; using Cryville.Audio.Source;
using Cryville.Crtr.Event; using Cryville.Crtr.Event;
using System; using System;
@@ -8,23 +6,12 @@ using System.IO;
namespace Cryville.Crtr { namespace Cryville.Crtr {
public class ChartHandler : ContainerHandler { public class ChartHandler : ContainerHandler {
//private StampedState cs;
public Chart chart; public Chart chart;
//readonly Dictionary<string, Sound> sounds = new Dictionary<string, Sound>();
readonly List<LibavFileAudioSource> sounds = new List<LibavFileAudioSource>(); readonly List<LibavFileAudioSource> sounds = new List<LibavFileAudioSource>();
public ChartHandler(Chart _chart, DirectoryInfo dir) : base() { public ChartHandler(Chart _chart, DirectoryInfo dir) : base() {
if (dir == null) throw new ArgumentNullException("dir"); if (dir == null) throw new ArgumentNullException("dir");
chart = _chart; chart = _chart;
/*foreach (Chart.Group g in chart.groups) {
var gh = new GroupHandler(g, this);
// cs.AddChild(new StampedState(new StampedState(chart, sevs)));
}*/
//PrehandleEvents();
} }
public override string TypeName { public override string TypeName {
@@ -37,50 +24,12 @@ namespace Cryville.Crtr {
base.PreInit(); base.PreInit();
} }
public override void Init() {
base.Init();
#if !NO_SOUND
/*foreach (Chart.Sound ev in chart.sounds) {
sounds.Add(ev, new LibavFileAudioSource(
Game.GameDataPath + "/songs/" + ev.id + "/.ogg"
));
Logger.Log("main", 0, "Load", "Loading song: {0}", ev.id);
}*/
#endif
}
public override void Dispose() { public override void Dispose() {
if (Disposed) return; if (Disposed) return;
base.Dispose(); base.Dispose();
// foreach (var h in handlers) h.Dispose();
foreach (var s in sounds) s.Dispose(); foreach (var s in sounds) s.Dispose();
} }
/*List<StampedEvent> sevs = new List<StampedEvent>();
public void PrehandleEvents() {
EventPrehandler ph = new EventPrehandler(
chart,
chart.motions.Cast<Chart.Event>()
.Concat<Chart.Event>(chart.signs.Cast<Chart.Event>())
.Concat<Chart.Event>(chart.sounds.Cast<Chart.Event>())
);
// foreach (var h in handlers) h.StartPrehandler(ph);
ph.Forward(ev => {
if (ev is Chart.Sound) {
Chart.Sound tev = (Chart.Sound)ev;
sevs.Add(new StampedEvent.PlaySound() {
Time = ph.Time - tev.offset + Settings.Default.SoundOffset,
Event = tev
});
}
// foreach (var h in handlers) h.PrehandleToTime(ph.Time);
});
sevs = sevs.Concat(ph.Result).ToList();
cs = new StampedState(chart, sevs);
// foreach (var h in handlers) h.EndPrehandler(cs);
}*/
public override void Update(ContainerState s, StampedEvent ev) { public override void Update(ContainerState s, StampedEvent ev) {
base.Update(s, ev); base.Update(s, ev);
if (s.CloneType == 16) { if (s.CloneType == 16) {
@@ -97,68 +46,13 @@ namespace Cryville.Crtr {
s.Time - tev.offset + ChartPlayer.soundOffset, s.Time - tev.offset + ChartPlayer.soundOffset,
source source
); );
/*var l = new List<StampedEvent> {
new StampedEvent.PlaySound() {
Time = s.Time - tev.offset + ChartPlayer.soundOffset,
Container = chart,
Unstamped = tev
}
};
cs.Bus.IssuePatch(l);*/
} }
} }
} }
public override void ExUpdate(ContainerState s, StampedEvent ev) {
base.ExUpdate(s, ev);
if (s.CloneType == 0) {
/*#if !NO_SOUND
if (ev is StampedEvent.PlaySound) {
StampedEvent.PlaySound tev = (StampedEvent.PlaySound)ev;
// sounds[tev.Event.file.ToLower()].audioSource.time = toTime - cs.Time;
sounds[tev.Unstamped.id].audioSource.Play();
}
#endif*/
}
}
public override void EndUpdate(ContainerState s) { public override void EndUpdate(ContainerState s) {
base.EndUpdate(s); base.EndUpdate(s);
// TODO End of chart // TODO End of chart
} }
/*public void SendInput(int id, TouchPhase phase, Vector2 pos) {
// Vector2 jpos = Camera.main.ScreenToWorldPoint(new Vector3(pos.x, pos.y, -cameraZ));
/*foreach (var h in handlers) {
h.SendInput(id, phase, jpos);
}*
}
int hits = 0;
int misses = 0;
public void ReportJudge(bool hit) {
if (hit) hits++;
else misses++;
GameObject.Find("Status").GetComponent<Text>().text = string.Format("Hits: {0}\nMisses: {1}", hits, misses);
}*/
} }
/*public class ChartState : ChartEventStateBase {
public ChartState(Chart c) : base(
c,
c.motions.Cast<Chart.Event>()
.Concat<Chart.Event>(c.signs.Cast<Chart.Event>())
.Concat<Chart.Event>(c.sounds.Cast<Chart.Event>())
) { }
protected override void Handle(Chart.Event ev) {
/*if (ev is Chart.Signature) {
Chart.Signature tev = (Chart.Signature)ev;
float tempo = tev.tempo;
if (tempo != 0)
Tempo = tempo;
}*
base.Handle(ev);
}
}*/
} }

View File

@@ -37,8 +37,6 @@ namespace Cryville.Crtr {
WWW texLoader = null; WWW texLoader = null;
#endif #endif
// ChartHandler handler;
// StampedState cs;
EventBus cbus; EventBus cbus;
EventBus bbus; EventBus bbus;
EventBus tbus; EventBus tbus;
@@ -49,8 +47,6 @@ namespace Cryville.Crtr {
static bool initialized; static bool initialized;
static Text logs; static Text logs;
Text status; Text status;
// static EventSystem eventSystem;
// static MetaDatabase metadb;
public static Rect hitRect; public static Rect hitRect;
public static Vector2 screenSize; public static Vector2 screenSize;
@@ -69,8 +65,6 @@ namespace Cryville.Crtr {
public static Dictionary<string, MotionRegistry> motionRegistry = new Dictionary<string, MotionRegistry>(); public static Dictionary<string, MotionRegistry> motionRegistry = new Dictionary<string, MotionRegistry>();
// public static AudioMixerGroup mixer;
public static PdtEvaluator etor; public static PdtEvaluator etor;
~ChartPlayer() { ~ChartPlayer() {
@@ -90,10 +84,7 @@ namespace Cryville.Crtr {
logs = logobj.GetComponent<Text>(); logs = logobj.GetComponent<Text>();
if (!initialized) { if (!initialized) {
Game.Init(); Game.Init();
// mixer = Resources.Load<AudioMixerGroup>("GameAudioMixer");
GenericResources.LoadDefault(); GenericResources.LoadDefault();
// eventSystem = GameObject.Find("EventSystem").GetComponent<EventSystem>();
// metadb = new MetaDatabase(new DirectoryInfo(persistentDataPath + "/db/cryville.github.io"));
initialized = true; initialized = true;
} }
OnSettingsUpdate(); OnSettingsUpdate();
@@ -108,18 +99,15 @@ namespace Cryville.Crtr {
Play(); Play();
#endif #endif
// metadb.GetObject(new Guid(""));
// Camera.main.RenderToCubemap(); // Camera.main.RenderToCubemap();
} }
void Update() { void Update() {
if (Input.GetKeyDown(KeyCode.Return)) TogglePlay(); if (Input.GetKeyDown(KeyCode.Return)) TogglePlay();
// if (Input.GetKeyDown(KeyCode.Escape)) ReturnToConsole();
if (started) { if (started) {
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");
//cs.ForwardByTime(Time.deltaTime);
float dt = firstFrame float dt = firstFrame
? 1f / Application.targetFrameRate ? 1f / Application.targetFrameRate
: Time.deltaTime; : Time.deltaTime;
@@ -134,9 +122,6 @@ namespace Cryville.Crtr {
}); });
judge.EndFrame(); judge.EndFrame();
UnityEngine.Profiling.Profiler.EndSample(); UnityEngine.Profiling.Profiler.EndSample();
/*StampedState ts = (StampedState)cs.Clone();
ts.ForwardStepToTime(cs.Time + fogDist, renderStep);
ts.BroadcastEndUpdate();*/
UnityEngine.Profiling.Profiler.BeginSample("ChartPlayer.Forward"); UnityEngine.Profiling.Profiler.BeginSample("ChartPlayer.Forward");
UnityEngine.Profiling.Profiler.BeginSample("EventBus.Copy"); UnityEngine.Profiling.Profiler.BeginSample("EventBus.Copy");
bbus.CopyTo(2, tbus); bbus.CopyTo(2, tbus);
@@ -265,10 +250,6 @@ namespace Cryville.Crtr {
} }
} }
/*public void ReturnToConsole() {
Application.LoadLevel("Console");
}*/
private void ReturnToMenu() { private void ReturnToMenu() {
#if UNITY_EDITOR #if UNITY_EDITOR
Invoke(nameof(_returnToMenu), 4); Invoke(nameof(_returnToMenu), 4);
@@ -392,9 +373,6 @@ namespace Cryville.Crtr {
f.Init(); f.Init();
frames.Add(t.Key, f); frames.Add(t.Key, f);
} }
// etor.Context = new EvaluatorContext() { Reservations = cruleset.scores.Keys.ToList() };
// pskin.PreEval(etor);
//cs.BroadcastInit();
Logger.Log("main", 0, "Load/Prehandle", "Initializing states"); Logger.Log("main", 0, "Load/Prehandle", "Initializing states");
cbus.BroadcastInit(); cbus.BroadcastInit();
Game.InputManager.Activate(); Game.InputManager.Activate();
@@ -408,8 +386,6 @@ namespace Cryville.Crtr {
Thread.Sleep((int)(Game.AudioClient.BufferPosition - Game.AudioClient.Position)); Thread.Sleep((int)(Game.AudioClient.BufferPosition - Game.AudioClient.Position));
Game.InputManager.SyncTime(cbus.Time); Game.InputManager.SyncTime(cbus.Time);
started = true; started = true;
// cs.ForwardByTime(startOffset);
// bus.ForwardByTime(startOffset);
} }
catch (Exception ex) { catch (Exception ex) {
Game.LogException("Load/Prehandle", "An error occured while prehandling the data", ex); Game.LogException("Load/Prehandle", "An error occured while prehandling the data", ex);
@@ -465,7 +441,6 @@ namespace Cryville.Crtr {
Logger.Log("main", 0, "Load/WorkerThread", "Batching events"); Logger.Log("main", 0, "Load/WorkerThread", "Batching events");
var batcher = new EventBatcher(chart); var batcher = new EventBatcher(chart);
batcher.Forward(); batcher.Forward();
// cruleset.PatchChart(batcher);
cbus = batcher.Batch(); cbus = batcher.Batch();
Logger.Log("main", 0, "Load/WorkerThread", "Batched {0} event batches", cbus.events.Count); Logger.Log("main", 0, "Load/WorkerThread", "Batched {0} event batches", cbus.events.Count);
@@ -475,46 +450,6 @@ namespace Cryville.Crtr {
LoadSkin(info.skinFile); LoadSkin(info.skinFile);
cbus.AttachSystems(pskin, judge); cbus.AttachSystems(pskin, judge);
// handler = new ChartHandler(chart, dir);
// cs = new StampedState(chart);
/*var cph = new EventPrehandler(chart, chart, chart.Events);
foreach (var g in chart.groups) {
var gph = new EventPrehandler(chart, g, g.Events, cph);
foreach (var i in g.Children) {
new EventPrehandler(chart, i, i.Events, gph);
}
}
cph.Forward(ev => {
if (ev is Chart.Sound) {
Chart.Sound tev = (Chart.Sound)ev;
cph.Result.Add(new StampedEvent.PlaySound() {
Time = cph.Time/* - tev.offset* + soundOffset,
Event = tev
});
}
});*/
/*var ch = new ChartHandler(chart, dir);
cs = new StampedState(chart, cph.Result, cskin, cph.StampedEvent);
cs.AttachHandler(ch);
foreach (var gph in cph.Children) {
var gh = new GroupHandler((Chart.Group)gph.Container, ch);
var gs = new StampedState(chart, gph.Result, cskin, gph.StampedEvent, cs);
gs.AttachHandler(gh);
foreach (var tph in gph.Children) {
StampedEventHandler th;
if (tph.Container is Chart.Note) {
th = new NoteHandler(gh, tph.StampedEvent);
}
else {
th = new TrackHandler(gh, (Chart.Track)tph.Container);
}
StampedState ts;
ts = new StampedState(chart, tph.Result, cskin, tph.StampedEvent, gs);
ts.AttachHandler(th);
}
}*/
Logger.Log("main", 0, "Load/WorkerThread", "Attaching handlers"); Logger.Log("main", 0, "Load/WorkerThread", "Attaching handlers");
var ch = new ChartHandler(chart, dir); var ch = new ChartHandler(chart, dir);
cbus.RootState.AttachHandler(ch); cbus.RootState.AttachHandler(ch);
@@ -592,7 +527,6 @@ namespace Cryville.Crtr {
if (bbus != null) bbus.Dispose(); if (bbus != null) bbus.Dispose();
if (tbus != null) tbus.Dispose(); if (tbus != null) tbus.Dispose();
if (nbus != null) nbus.Dispose(); if (nbus != null) nbus.Dispose();
//cs.Dispose();
Game.InputManager.Deactivate(); Game.InputManager.Deactivate();
foreach (var t in texs) Texture.Destroy(t.Value); foreach (var t in texs) Texture.Destroy(t.Value);
Logger.Log("main", 1, "Game", "Stopped"); Logger.Log("main", 1, "Game", "Stopped");
@@ -614,14 +548,6 @@ namespace Cryville.Crtr {
#endif #endif
} }
/*public void ShowSettings() {
var editor = GameObject.Instantiate<GameObject>(UnityEngine.Resources.Load<GameObject>("Common/PropertyEditor")).GetComponent<PropertyEditor>();
editor.Callback = () => {
Settings.Default.Save();
OnSettingsUpdate();
};
editor.TargetObject = Settings.Default;
}*/
void OnSettingsUpdate() { void OnSettingsUpdate() {
Application.targetFrameRate = Settings.Default.TargetFrameRate; Application.targetFrameRate = Settings.Default.TargetFrameRate;
QualitySettings.vSyncCount = Settings.Default.VSync ? 1 : 0; QualitySettings.vSyncCount = Settings.Default.VSync ? 1 : 0;

View File

@@ -139,17 +139,6 @@ namespace Cryville.Crtr {
} }
} }
/*public class RectConverter : TypeConverter {
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
if (sourceType == typeof(string))
return true;
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
return base.ConvertFrom(context, culture, value);
}
}*/
public class Cocos2dFramesBinder : EmptyBinder { public class Cocos2dFramesBinder : EmptyBinder {
public override object ChangeType(object value, Type type, CultureInfo culture) { public override object ChangeType(object value, Type type, CultureInfo culture) {
if (value is string) { if (value is string) {

View File

@@ -50,16 +50,7 @@ namespace Cryville.Crtr.Components {
static readonly ListPool<Vector2> _uvPool = new ListPool<Vector2>(); static readonly ListPool<Vector2> _uvPool = new ListPool<Vector2>();
static readonly ArrayPool<Vector2> _shapePool = new ArrayPool<Vector2>(0x100, 0x10000); static readonly ArrayPool<Vector2> _shapePool = new ArrayPool<Vector2>(0x100, 0x10000);
public PolygonSGO() public PolygonSGO() {
: base() {
/*
SubmitProperty("head", new Property(typeof(string), () => head.frame, v => head.frame = (string)v));
SubmitProperty("body", new Property(typeof(string), () => body.frame, v => body.frame = (string)v));
SubmitProperty("tail", new Property(typeof(string), () => tail.frame, v => tail.frame = (string)v));
SubmitProperty("transparent", new Property(typeof(bool), () => transparent, v => transparent = (bool)v));
SubmitProperty("shape", new Property(typeof(Vector2[]), () => _shape, v => _shape = (Vector2[])v));
*/
SubmitProperty("head", new PropOp.String(v => head.FrameName = v)); SubmitProperty("head", new PropOp.String(v => head.FrameName = v));
SubmitProperty("body", new PropOp.String(v => body.FrameName = v)); SubmitProperty("body", new PropOp.String(v => body.FrameName = v));
SubmitProperty("tail", new PropOp.String(v => tail.FrameName = v)); SubmitProperty("tail", new PropOp.String(v => tail.FrameName = v));
@@ -146,17 +137,9 @@ namespace Cryville.Crtr.Components {
lengths = _lPool.Rent(); lengths = _lPool.Rent();
} }
/*
r = new Vector3(0, 0, 0);
Quaternion rotq = Quaternion.Euler(r);
p = prevp + rotq * (p - prevpt);
prevp = p;*/
for (int i = 0; i < _shapeLength; i++) { for (int i = 0; i < _shapeLength; i++) {
Vector2 sp = r * _shape[i]; Vector2 sp = r * _shape[i];
vertices.Add(p + (Vector3)sp); vertices.Add(p + (Vector3)sp);
// uv.Add(new Vector2(i / (shape.Length - 1), vertCount));
} }
if (headGenerated) { if (headGenerated) {

View File

@@ -1,54 +1,9 @@
using Cryville.Common.Pdt; using Cryville.Common.Pdt;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
namespace Cryville.Crtr.Components { namespace Cryville.Crtr.Components {
public abstract class SkinComponent : MonoBehaviour { public abstract class SkinComponent : MonoBehaviour {
#if false
/// <summary>
/// The properties of the component.
/// </summary>
[Obsolete]
public Dictionary<string, Property> Properties { get; private set; }
/// <summary>
/// Submits a property.
/// </summary>
/// <param name="name">The name of the property.</param>
/// <param name="property">The property itself.</param>
[Obsolete]
protected void SubmitProperty(string name, Property property) {
Properties.Add(name, property);
}
/// <summary>
/// The property of a skin component.
/// </summary>
[Obsolete]
public struct Property {
/// <summary>
/// The type of the property.
/// </summary>
public readonly Type Type;
/// <summary>
/// The callback that gets the property value.
/// </summary>
public readonly Func<object> Get;
/// <summary>
/// The callback that sets the property value.
/// </summary>
public readonly Action<object> Set;
/// <summary>
/// Creates a property.
/// </summary>
/// <param name="type">The type of the property.</param>
/// <param name="get">The callback that gets the property value.</param>
/// <param name="set">The callback that sets the property value.</param>
public Property(Type type, Func<object> get, Action<object> set) {
Type = type; Get = get; Set = set;
}
}
#endif
/// <summary> /// <summary>
/// The property operators of the component. /// The property operators of the component.
/// </summary> /// </summary>

View File

@@ -1,21 +1,9 @@
using Cryville.Common.Pdt; using Cryville.Common.Pdt;
using System;
using System.Collections;
using UnityEngine; using UnityEngine;
namespace Cryville.Crtr.Components { namespace Cryville.Crtr.Components {
public abstract class SpriteBase : SkinComponent { public abstract class SpriteBase : SkinComponent {
public SpriteBase() public SpriteBase() {
: base() {
/*
SubmitProperty("bound", new Property(typeof(BoundInfo), null, v => Bound = (BoundInfo)v));
SubmitProperty("transparent", new Property(typeof(bool), () => transparent, v => transparent = (bool)v));
SubmitProperty("pivot", new Property(typeof(Vector2), () => Pivot, v => Pivot = (Vector2)v));
SubmitProperty("scale", new Property(typeof(Vector2), () => Scale, v => Scale = (Vector2)v));
SubmitProperty("ui", new Property(typeof(bool), () => UI, v => UI = (bool)v));
SubmitProperty("zindex", new Property(typeof(short), () => ZIndex, v => ZIndex = (short)v));
*/
SubmitProperty("bound", new op_set_bound(this)); SubmitProperty("bound", new op_set_bound(this));
SubmitProperty("transparent", new PropOp.Boolean(v => transparent = v)); SubmitProperty("transparent", new PropOp.Boolean(v => transparent = v));
SubmitProperty("pivot", new PropOp.Vector2(v => Pivot = v)); SubmitProperty("pivot", new PropOp.Vector2(v => Pivot = v));
@@ -87,28 +75,6 @@ namespace Cryville.Crtr.Components {
get { return Vector2.zero; } get { return Vector2.zero; }
} }
#if false
[Obsolete]
public struct BoundInfo : IConstructable {
public Vector2 Pivot;
public Vector3 Position;
public void Load(object data, IEvaluator etor) {
var d = (IList)data;
Pivot = (Vector2)etor.Cast(typeof(Vector2), d[0]);
Position = (Vector3)etor.Cast(typeof(Vector3), d[1]);
}
}
[Obsolete]
public BoundInfo Bound {
set {
var r = Quaternion.Inverse(transform.rotation);
var da = value.Pivot - Pivot;
var dp = r * (value.Position - transform.localPosition);
if (da.x != 0) _scale.x = dp.x / da.x;
if (da.y != 0) _scale.y = dp.z / da.y;
}
}
#endif
public void SetBound(Vector2 piv, Vector3 pos) { public void SetBound(Vector2 piv, Vector3 pos) {
var r = Quaternion.Inverse(transform.rotation); var r = Quaternion.Inverse(transform.rotation);
var da = piv - Pivot; var da = piv - Pivot;

View File

@@ -33,14 +33,7 @@ namespace Cryville.Crtr.Components {
} }
public class SpritePlane : SpriteBase { public class SpritePlane : SpriteBase {
public SpritePlane() public SpritePlane() {
: base() {
/*
SubmitProperty("frame", new Property(typeof(string), () => Frame, v => Frame = (string)v));
SubmitProperty("fit", new Property(typeof(FitMode), () => Fit, v => Fit = (FitMode)v));
SubmitProperty("opacity", new Property(typeof(float), () => Opacity, v => Opacity = (float)v));
*/
SubmitProperty("frame", new PropOp.String(v => Frame = v)); SubmitProperty("frame", new PropOp.String(v => Frame = v));
SubmitProperty("fit", new PropOp.Enum<FitMode>(v => Fit = v)); SubmitProperty("fit", new PropOp.Enum<FitMode>(v => Fit = v));
SubmitProperty("opacity", new PropOp.Float(v => Opacity = v)); SubmitProperty("opacity", new PropOp.Float(v => Opacity = v));

View File

@@ -1,14 +1,8 @@
using System.Collections.Generic; using UnityEngine;
using UnityEngine;
namespace Cryville.Crtr.Components { namespace Cryville.Crtr.Components {
public class SpriteRect : SpriteBase { public class SpriteRect : SpriteBase {
public SpriteRect() public SpriteRect() {
: base() {
/*
SubmitProperty("color", new Property(typeof(Color), () => Color, v => Color = (Color)v));
*/
SubmitProperty("color", new PropOp.Color(v => Color = v)); SubmitProperty("color", new PropOp.Color(v => Color = v));
transparent = true; transparent = true;

View File

@@ -4,12 +4,7 @@ using UnityEngine;
namespace Cryville.Crtr.Components { namespace Cryville.Crtr.Components {
public class SpriteScale3 : SpritePlane { public class SpriteScale3 : SpritePlane {
public SpriteScale3() public SpriteScale3() {
: base() {
/*
SubmitProperty("border", new Property(typeof(Vector2), () => Border, v => Border = (Vector2)v));
*/
SubmitProperty("border", new PropOp.Vector2(v => Border = v)); SubmitProperty("border", new PropOp.Vector2(v => Border = v));
} }

View File

@@ -1,22 +1,11 @@
using Cryville.Common.Pdt; using Cryville.Common.Pdt;
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine; using UnityEngine;
namespace Cryville.Crtr.Components { namespace Cryville.Crtr.Components {
public class SpriteText : SpriteBase { public class SpriteText : SpriteBase {
public SpriteText() { public SpriteText() {
/*
SubmitProperty("frames", new Property(typeof(TextFrames), () => Frames, v => Frames = (TextFrames)v));
SubmitProperty("value", new Property(typeof(string), () => Value, v => Value = (string)v));
SubmitProperty("size", new Property(typeof(float), () => Size, v => Size = (float)v));
SubmitProperty("spacing", new Property(typeof(float), () => Spacing, v => Spacing = (float)v));
SubmitProperty("opacity", new Property(typeof(float), () => Opacity, v => Opacity = (float)v));
*/
SubmitProperty("frames", new op_set_frames(this)); SubmitProperty("frames", new op_set_frames(this));
SubmitProperty("value", new PropOp.String(v => Value = v)); SubmitProperty("value", new PropOp.String(v => Value = v));
SubmitProperty("size", new PropOp.Float(v => Size = v)); SubmitProperty("size", new PropOp.Float(v => Size = v));
@@ -42,7 +31,7 @@ namespace Cryville.Crtr.Components {
o += v.Length * sizeof(char) + sizeof(int); o += v.Length * sizeof(char) + sizeof(int);
result.Add(keys[i], new SpriteInfo { FrameName = v }); result.Add(keys[i], new SpriteInfo { FrameName = v });
} }
_self.Frames = new TextFrames { Frames = result }; _self.Frames = result;
} }
} }
#pragma warning restore IDE1006 #pragma warning restore IDE1006
@@ -53,19 +42,8 @@ namespace Cryville.Crtr.Components {
} }
readonly Dictionary<Texture2D, MeshWrapper> meshes = new Dictionary<Texture2D, MeshWrapper>(); readonly Dictionary<Texture2D, MeshWrapper> meshes = new Dictionary<Texture2D, MeshWrapper>();
public struct TextFrames /*: IConstructable*/ { Dictionary<char, SpriteInfo> m_frames;
public Dictionary<char, SpriteInfo> Frames; public Dictionary<char, SpriteInfo> Frames {
/*public void Load(object data, IEvaluator etor) {
var d = (IList)data;
var keys = (string)d[0];
var values = (List<object>)d[1];
Frames = new Dictionary<char, SpriteInfo>(keys.Length);
for (int i = 0; i < keys.Length; i++)
Frames.Add(keys[i], new SpriteInfo() { FrameName = (string)values[i] });
}*/
}
TextFrames m_frames;
public TextFrames Frames {
get { return m_frames; } get { return m_frames; }
set { m_frames = value; UpdateFrames(); UpdateScale(); } set { m_frames = value; UpdateFrames(); UpdateScale(); }
} }
@@ -102,7 +80,7 @@ namespace Cryville.Crtr.Components {
float frameHeight = 0; float frameHeight = 0;
foreach (var m in meshes) m.Value.Destroy(); foreach (var m in meshes) m.Value.Destroy();
meshes.Clear(); meshes.Clear();
foreach (var f in m_frames.Frames) { foreach (var f in m_frames) {
f.Value.Load(); f.Value.Load();
if (frameHeight == 0) frameHeight = f.Value.Rect.height; if (frameHeight == 0) frameHeight = f.Value.Rect.height;
else if (frameHeight != f.Value.Rect.height) throw new Exception("Inconsistent frame height"); else if (frameHeight != f.Value.Rect.height) throw new Exception("Inconsistent frame height");
@@ -128,7 +106,7 @@ namespace Cryville.Crtr.Components {
uvs.Add(t, new List<Vector2>(vc)); uvs.Add(t, new List<Vector2>(vc));
} }
foreach (var c in m_value) { foreach (var c in m_value) {
var f = m_frames.Frames[c]; var f = m_frames[c];
var t = f.Frame.Texture; var t = f.Frame.Texture;
float w = f.Ratio * m_size; float w = f.Ratio * m_size;
verts[t].Add(new Vector3(sum_x , 0, 0)); verts[t].Add(new Vector3(sum_x , 0, 0));

View File

@@ -1,331 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Cryville.Common;
using Cryville.Common.Pdt;
using Cryville.Crtr.Components;
using Cryville.Crtr.Event;
using UnityEngine;
namespace Cryville.Crtr {
#if false
[Obsolete]
public struct Evaluator : IEvaluator {
public object ParseNumber(string exp) {
return float.Parse(exp);
}
public object ParseString(string exp) {
return exp;
}
public object EvalIdentifier(string exp) {
if (exp[0] == '$') {
var r = Context.State.GetRawValue<Vector>(new MotionName(exp.Substring(1)));
if (r is Vec1) return ((Vec1)r).Value;
if (r is Vec1m) return ((Vec1m)r).Value;
if (r is Vec3) return ((Vec3)r).ToVector3();
if (r is VecI1) return ((VecI1)r).Value;
if (r is VecPt) return ((VecPt)r).ToVector2(ChartPlayer.hitRect);
if (r is VecPtComp) return ((VecPtComp)r).ToFloat(ChartPlayer.hitRect);
throw new NotImplementedException();
}
switch (exp) {
case "w": return ChartPlayer.hitRect.width;
case "h": return ChartPlayer.hitRect.height;
case "true": return true;
case "false": return false;
case "pos":
return Context.State.Handler.Position;
// return ctx.Transform.position;
default:
if (Context.Extra != null && Context.Extra.ContainsKey(exp))
return Context.Extra[exp];
if (Context.Reservations != null && Context.Reservations.Contains(exp))
throw new Exception();
if (Context.State == null && !Context.DisableLiteralString)
return exp;
return Context.State.Container.Properties[exp]();
}
}
public object OperateUnary(Operand op, object q) {
switch (op.exp) {
case "-":
if (q is float) return -(float)q;
else throw new NotImplementedException();
default:
throw new NotImplementedException();
}
}
public object OperateBinary(Operand op, object q, object r) {
switch (op.exp) {
case "+":
if (!(q is float && r is float))
throw new ArgumentException(); // TODO
return (float)q + (float)r;
case "-":
if (!(q is float && r is float))
throw new ArgumentException(); // TODO
return (float)q - (float)r;
case "*":
if (!(q is float && r is float))
throw new ArgumentException(); // TODO
return (float)q * (float)r;
case "/":
if (!(q is float && r is float))
throw new ArgumentException(); // TODO
return (float)q / (float)r;
case " ":
if (typeof(List<object>).IsAssignableFrom(q.GetType())) {
((List<object>)q).Add(r);
return q;
}
else {
return new List<object>(){q, r};
}
case ",":
if (q is Stack) {
((Stack)q).Push(r);
return q;
}
else {
var s = new Stack();
s.Push(q); s.Push(r);
return s;
}
default:
throw new NotImplementedException();
}
}
public object OperateFunction(Operand op, object q) {
switch (op.exp) {
case "circle":
var lcirc = (Stack)q;
var radius = (float)Cast(typeof(float), lcirc.Pop());
var circcenter = (Vector2)Cast(typeof(Vector2), lcirc.Pop());
return ((Vector2)Context.Extra["-hitpos"] - circcenter).sqrMagnitude - radius * radius;
case "dist":
var ldist = (Stack)q;
var rhs = (Vector3)Cast(typeof(Vector3), ldist.Pop());
var lhs = (Vector3)Cast(typeof(Vector3), ldist.Pop());
return (lhs - rhs).magnitude;
case "frame_seq":
var lframeseq = (Stack)q;
var ub = (int)(float)Cast(typeof(float), lframeseq.Pop());
var lb = (int)(float)Cast(typeof(float), lframeseq.Pop());
var prefix = (string)lframeseq.Pop();
var frames = new List<object>();
for (int i = lb; i <= ub; i++) {
frames.Add(prefix + i.ToString());
}
return frames;
case "rect":
var lrect = (Stack)q;
var recth = (float)Cast(typeof(float), lrect.Pop()) / 2;
var rectw = (float)Cast(typeof(float), lrect.Pop()) / 2;
var rectcenter = (Vector2)Cast(typeof(Vector2), lrect.Pop());
var recthit = (Vector2)Context.Extra["-hitpos"] - rectcenter;
return (Mathf.Abs(recthit.x) <= Mathf.Abs(rectw) && Mathf.Abs(recthit.y) <= Mathf.Abs(recth)) ? -1f : 1f;
case "screen_edge":
float dist;
var ray = new Ray(Context.Transform.position, Context.Transform.rotation * Vector3.forward);
ChartPlayer.frustumPlanes[(int)(float)q].Raycast(ray, out dist);
return ray.GetPoint(dist);
default:
throw new NotImplementedException(
string.Format("Unknown function: {0}", op.exp)
);
}
}
// TODO [Obsolete]
public object Cast(Type type, object obj) {
if (type.IsAssignableFrom(obj.GetType()))
return obj;
if (typeof(ICollection).IsAssignableFrom(obj.GetType())) {
var o = ((ICollection)obj).Cast<object>().ToList();
if (obj is Stack) o.Reverse();
if (type == typeof(Color)) {
return new Color(
(float)o[0],
(float)o[1],
(float)o[2],
o.Count >= 4 ? (float)o[3] : 1
);
}
else if (type == typeof(Vector3)) {
float z = o.Count >= 3 ? (float)o[2] : 0;
return new Vector3((float)o[0], (float)o[1], z);
}
else if (type == typeof(Vector2)) {
return new Vector2((float)o[0], (float)o[1]);
}
else if (type == typeof(string)) {
return string.Join(",", o.Cast<string>().ToArray());
}
else if (type.BaseType == typeof(Array)) {
var etype = type.GetElementType();
IList r = (IList)ReflectionHelper.InvokeEmptyConstructor(typeof(List<>).MakeGenericType(etype));
foreach (var i in o) {
r.Add(Cast(etype, i));
}
return typeof(Enumerable).GetMethod("ToArray")
.MakeGenericMethod(etype).Invoke(
null, new object[]{r}
);
}
else if (typeof(IList).IsAssignableFrom(type)) {
var etype = type.GetGenericArguments()[0];
IList r = (IList)ReflectionHelper.InvokeEmptyConstructor(typeof(List<>).MakeGenericType(etype));
foreach (var i in o) {
r.Add(Cast(etype, i));
}
return r;
}
}
else if (obj is float) {
float g = (float)obj;
if (type == typeof(Vector3)) {
return new Vector3(g, g, g);
}
else if (type == typeof(Vector2)) {
return new Vector2(g, g);
}
else if (typeof(IConvertible).IsAssignableFrom(type)) {
return ((IConvertible)g).ToInt16(null);
}
}
if (type.IsEnum) {
return Enum.Parse(type, (string)Cast(typeof(string), obj), true);
}
else if (typeof(IConstructable).IsAssignableFrom(type)) {
var r = (IConstructable)Activator.CreateInstance(type);
r.Load(obj, this);
return r;
}
else if (typeof(IList).IsAssignableFrom(type)) {
IList r = (IList)ReflectionHelper.InvokeEmptyConstructor(typeof(List<>).MakeGenericType(obj.GetType()));
r.Add(obj);
return r;
}
throw new InvalidCastException(String.Format("Cannot cast {0} to {1}", obj.GetType(), type));
}
public EvaluatorContext Context { get; set; }
/*object CastBypass(object obj) { return obj; }
object CastListColor(object obj) {
var o = (IList)obj;
float a = o.Count >= 4 ? (float)o[3] : 1;
return new Color(
(float)o[0],
(float)o[1],
(float)o[2],
a
);
}
object CastListVector3(object obj) {
var o = (IList)obj;
float z = o.Count >= 3 ? (float)o[2] : 0;
return new Vector3((float)o[0], (float)o[1], z);
}
object CastListVector2(object obj) {
var o = (IList)obj;
return new Vector2((float)o[0], (float)o[1]);
}
object CastListString(object obj) {
var o = (IList)obj;
return String.Join(",", o.Cast<string>().ToArray());
}
object CastListArray(object obj) {
var o = (IList)obj;
var etype = dest.GetElementType();
IList r = (IList)ReflectionHelper.InvokeEmptyConstructor(typeof(List<>).MakeGenericType(etype));
foreach (var i in o) {
r.Add(Cast(etype, i));
}
return typeof(Enumerable).GetMethod("ToArray")
.MakeGenericMethod(etype).Invoke(
null, new object[] { r }
);
}
object CastNumberVector3(object obj) {
var o = (float)obj;
return new Vector3(o, o, o);
}
object CastNumberVector2(object obj) {
var o = (float)obj;
return new Vector2(o, o);
}
object CastNumberBypass(object obj) {
var o = (float)obj;
return ((IConvertible)o).ToInt16(null);
}
object CastListEnum(object obj) {
var o = (float)obj;
return ((IConvertible)o).ToInt16(null);
}
public override CastCallback GetCastCallback(Type dest, Type source) {
if (dest.IsAssignableFrom(source)) return new CastCallback(CastBypass);
if (typeof(IList).IsAssignableFrom(source)) {
if (dest == typeof(Color)) return new CastCallback(CastListColor);
if (dest == typeof(Vector3)) return new CastCallback(CastListVector3);
if (dest == typeof(Vector2)) return new CastCallback(CastListVector2);
if (dest == typeof(string)) return new CastCallback(CastListString);
if (dest.BaseType == typeof(Array)) {
var etype = type.GetElementType();
IList r = (IList)ReflectionHelper.InvokeEmptyConstructor(typeof(List<>).MakeGenericType(etype));
foreach (var i in o) {
r.Add(Cast(etype, i));
}
return typeof(Enumerable).GetMethod("ToArray")
.MakeGenericMethod(etype).Invoke(
null, new object[] { r }
);
}
else if (typeof(IList).IsAssignableFrom(type)) {
var etype = type.GetGenericArguments()[0];
IList r = (IList)ReflectionHelper.InvokeEmptyConstructor(typeof(List<>).MakeGenericType(etype));
foreach (var i in o) {
r.Add(Cast(etype, i));
}
return r;
}
}
else if (source == typeof(float)) {
if (dest == typeof(Vector3)) return new CastCallback(CastNumberVector3);
if (dest == typeof(Vector2)) return new CastCallback(CastNumberVector2);
if (typeof(IConvertible).IsAssignableFrom(dest)) return new CastCallback(CastNumberBypass);
}
if (type.IsEnum) {
return Enum.Parse(type, (string)Cast(typeof(string), obj), true);
}
else if (typeof(IConstructable).IsAssignableFrom(type)) {
var r = (IConstructable)Activator.CreateInstance(type);
r.Load(obj, this);
return r;
}
else if (typeof(IList).IsAssignableFrom(type)) {
IList r = (IList)ReflectionHelper.InvokeEmptyConstructor(typeof(List<>).MakeGenericType(obj.GetType()));
r.Add(obj);
return r;
}
throw new NotImplementedException();
}*/
}
/*class CastCallback {
public Func<object, object> Callback { get; set; }
public CastCallback Nested { get; set; }
public CastCallback(Func<object, object> cb, CastCallback ncc = null) {
Callback = cb;
Nested = ncc;
}
}*/
[Obsolete]
public struct EvaluatorContext {
public ContainerState State;
public Transform Transform;
public Dictionary<string, object> Extra;
public List<string> Reservations;
public bool DisableLiteralString;
}
#endif
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 1d956cad385858849a2681bed8031a77
timeCreated: 1617844741
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -14,9 +14,9 @@ namespace Cryville.Crtr.Event {
public Dictionary<EventContainer, ContainerState> Children public Dictionary<EventContainer, ContainerState> Children
= new Dictionary<EventContainer, ContainerState>(); = new Dictionary<EventContainer, ContainerState>();
HashSet<EventContainer> WorkingChildren readonly HashSet<EventContainer> WorkingChildren
= new HashSet<EventContainer>(); = new HashSet<EventContainer>();
HashSet<EventContainer> InvalidatedChildren readonly HashSet<EventContainer> InvalidatedChildren
= new HashSet<EventContainer>(); = new HashSet<EventContainer>();
public Dictionary<Type, List<ContainerState>> TypedChildren public Dictionary<Type, List<ContainerState>> TypedChildren
= new Dictionary<Type, List<ContainerState>>(); = new Dictionary<Type, List<ContainerState>>();
@@ -25,14 +25,8 @@ namespace Cryville.Crtr.Event {
return TypedChildren[handlerType][index]; return TypedChildren[handlerType][index];
} }
public ContainerState GetChild(EventContainer ev) { public ContainerState GetChild(EventContainer ev) {
/*if (!Children.ContainsKey(ev)) {
Children[ev] = prototype.FetchChildClone(ev, CloneType);
}*/
return Children[ev]; return Children[ev];
} }
/*ContainerState FetchChildClone(EventContainer ev, byte ct) {
return Children[ev].Clone(ct);
}*/
void NotifyWorkingChanged(EventContainer key) { void NotifyWorkingChanged(EventContainer key) {
InvalidatedChildren.Add(key); InvalidatedChildren.Add(key);
@@ -56,7 +50,6 @@ namespace Cryville.Crtr.Event {
public byte CloneType; public byte CloneType;
private ContainerState rootPrototype = null; private ContainerState rootPrototype = null;
private ContainerState prototype = null; private ContainerState prototype = null;
// public SkinManager skinManager;
public SkinContainer skinContainer; public SkinContainer skinContainer;
public Judge judge; public Judge judge;
@@ -97,7 +90,6 @@ namespace Cryville.Crtr.Event {
} }
void InvalidateMotion(MotionName name) { void InvalidateMotion(MotionName name) {
// if (CachedValues.ContainsKey(name))
CachedValueStates[name] = false; CachedValueStates[name] = false;
foreach (var c in Children) foreach (var c in Children)
c.Value.InvalidateMotion(name); c.Value.InvalidateMotion(name);
@@ -113,10 +105,6 @@ namespace Cryville.Crtr.Event {
foreach (var m in ChartPlayer.motionRegistry) foreach (var m in ChartPlayer.motionRegistry)
Values.Add(new MotionName(m.Key), new RealtimeMotionValue().Init(Parent == null ? m.Value.GlobalInitValue : m.Value.InitValue)); Values.Add(new MotionName(m.Key), new RealtimeMotionValue().Init(Parent == null ? m.Value.GlobalInitValue : m.Value.InitValue));
//skinManager = new SkinManager(skin, this);
//events.Sort((a, b) => a.Time.CompareTo(b.Time));
} }
static void AddChild(EventContainer c, ContainerState s, ContainerState target) { static void AddChild(EventContainer c, ContainerState s, ContainerState target) {
@@ -127,9 +115,6 @@ namespace Cryville.Crtr.Event {
} }
public ContainerState Clone(byte ct) { public ContainerState Clone(byte ct) {
/*if (prototype != null)
throw new InvalidOperationException();*/
var r = (ContainerState)MemberwiseClone(); var r = (ContainerState)MemberwiseClone();
var mvs = new Dictionary<MotionName, RealtimeMotionValue>(Values.Count); var mvs = new Dictionary<MotionName, RealtimeMotionValue>(Values.Count);
@@ -152,7 +137,6 @@ namespace Cryville.Crtr.Event {
r.Children = new Dictionary<EventContainer, ContainerState>(); r.Children = new Dictionary<EventContainer, ContainerState>();
foreach (var child in Children) { foreach (var child in Children) {
// if (!child.Value.Working && ct != 1) continue;
var cc = child.Value.Clone(ct); var cc = child.Value.Clone(ct);
cc.Parent = r; cc.Parent = r;
AddChild(child.Key, cc, r); AddChild(child.Key, cc, r);
@@ -184,7 +168,6 @@ namespace Cryville.Crtr.Event {
else dest.Values.Add(mv.Key, mv.Value.Clone()); else dest.Values.Add(mv.Key, mv.Value.Clone());
} }
// dest.CachedValues.Clear();
foreach (var cv in CachedValues) { foreach (var cv in CachedValues) {
Vector dv; Vector dv;
if(dest.CachedValues.TryGetValue(cv.Key, out dv)) cv.Value.CopyTo(dv); if(dest.CachedValues.TryGetValue(cv.Key, out dv)) cv.Value.CopyTo(dv);
@@ -224,7 +207,6 @@ namespace Cryville.Crtr.Event {
} }
public void AttachSystems(PdtSkin skin, Judge judge) { public void AttachSystems(PdtSkin skin, Judge judge) {
// skinManager = new SkinManager(skin);
skinContainer = new SkinContainer(skin); skinContainer = new SkinContainer(skin);
this.judge = judge; this.judge = judge;
} }
@@ -337,20 +319,15 @@ namespace Cryville.Crtr.Event {
} }
public void Handle(StampedEvent ev, Action<StampedEvent> callback = null) { public void Handle(StampedEvent ev, Action<StampedEvent> callback = null) {
if (breakflag) { if (breakflag) return;
// Time = toTime;
return;
}
if (ev != null) { if (ev != null) {
bool flag = false; bool flag = false;
if (ev.Unstamped is Chart.Motion) { if (ev.Unstamped is Chart.Motion) {
var tev = (Chart.Motion)ev.Unstamped; var tev = (Chart.Motion)ev.Unstamped;
// tev._apply(Values);
var mv = RMVPool.Rent(tev.Name); var mv = RMVPool.Rent(tev.Name);
GetMotionValue(tev.Name).CopyTo(mv); GetMotionValue(tev.Name).CopyTo(mv);
PlayingMotions.Add(ev, mv); PlayingMotions.Add(ev, mv);
Callback(ev, callback); Callback(ev, callback);
// UpdateMotions();
if (!ev.Unstamped.IsLong) if (!ev.Unstamped.IsLong)
PlayingMotions.Remove(ev); PlayingMotions.Remove(ev);
} }
@@ -371,9 +348,7 @@ namespace Cryville.Crtr.Event {
if (tev.IsRelease) { if (tev.IsRelease) {
var nev = tev.Original; var nev = tev.Original;
if (nev is Chart.Motion) { if (nev is Chart.Motion) {
// var tnev = (Chart.Motion)nev;
Callback(ev, callback); Callback(ev, callback);
// UpdateMotions();
PlayingMotions.Remove(ev.Origin); PlayingMotions.Remove(ev.Origin);
} }
else if (nev is EventContainer) { else if (nev is EventContainer) {
@@ -397,7 +372,6 @@ namespace Cryville.Crtr.Event {
if (!flag) Callback(null, callback); if (!flag) Callback(null, callback);
return; return;
} }
// Time = toTime;
Callback(null, callback); Callback(null, callback);
} }
@@ -407,21 +381,6 @@ namespace Cryville.Crtr.Event {
callback(ev); callback(ev);
if (ev == null || ev.Unstamped != null) Handler.Update(this, ev); if (ev == null || ev.Unstamped != null) Handler.Update(this, ev);
else Handler.ExUpdate(this, ev); else Handler.ExUpdate(this, ev);
/*if (CloneType == 1) {
if (ev == null || ev.Event != null) Handler.Forward(ev);
else Handler.ExUpdate(CloneType, ev);
}
else if (CloneType == 0) {
if (ev == null || ev.Event != null) Handler.Update(ev);
else Handler.ExUpdate(CloneType, ev);
}
else if (CloneType == 2) {
// TODO Do nothing atm
}
else if (CloneType >= 16) {
if (ev == null || ev.Event != null) Handler.PreUpdate(CloneType, ev);
else Handler.ExUpdate(CloneType, ev);
}*/
foreach (var m in PlayingMotions) foreach (var m in PlayingMotions)
Handler.MotionUpdate(CloneType, (Chart.Motion)m.Key.Unstamped); Handler.MotionUpdate(CloneType, (Chart.Motion)m.Key.Unstamped);
} }

View File

@@ -48,9 +48,6 @@ namespace Cryville.Crtr.Event {
if (ev.IsLong) { if (ev.IsLong) {
events.Add(ev.ReleaseEvent); events.Add(ev.ReleaseEvent);
table.Add(ev.ReleaseEvent, cs); table.Add(ev.ReleaseEvent, cs);
/*if (ev is Chart.Note) {
events.Add(ev.AttackEvent);
}*/
} }
events.Add(ev); events.Add(ev);
table.Add(ev, cs); table.Add(ev, cs);
@@ -101,7 +98,6 @@ namespace Cryville.Crtr.Event {
return_ahead: return_ahead:
Time = toTime; Time = toTime;
beat = toBeat; beat = toBeat;
// foreach (var c in Children) c.ForwardToTime(Time);
if (callback != null) callback(null); if (callback != null) callback(null);
} }

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine;
namespace Cryville.Crtr.Event { namespace Cryville.Crtr.Event {
public class EventBus : StateBase<EventBatch>, IDisposable { public class EventBus : StateBase<EventBatch>, IDisposable {
@@ -45,11 +44,9 @@ namespace Cryville.Crtr.Event {
public void CopyTo(byte ct, EventBus dest) { public void CopyTo(byte ct, EventBus dest) {
base.CopyTo(dest); base.CopyTo(dest);
// dest.states.Clear();
dest.workingStates.Clear(); dest.workingStates.Clear();
dest.invalidatedStates.Clear(); dest.invalidatedStates.Clear();
RootState.CopyTo(ct, dest.RootState); RootState.CopyTo(ct, dest.RootState);
// foreach (var s in dest.states) dest.invalidatedStates.Add(s.Value);
dest.ValidateStates(); dest.ValidateStates();
if (ct >= 2) { if (ct >= 2) {
@@ -86,13 +83,6 @@ namespace Cryville.Crtr.Event {
s.Bus = this; s.Bus = this;
} }
/*
public void AddChildState(EventContainer p, EventContainer c) {
if (!states.ContainsKey(p)) AddChildState(prototype.states[p].Parent.Container, p);
if (!states.ContainsKey(c)) AddState(states[p].GetChild(c));
// if (prototype != null) prototype.states[c].CopyTo(RootState.CloneType, states[c]);
}*/
void EnsureActivity(EventContainer c) { void EnsureActivity(EventContainer c) {
if (activeContainers.Contains(c)) return; if (activeContainers.Contains(c)) return;
if (RootState.CloneType >= 2) prototype.states[c].CopyTo(RootState.CloneType, states[c]); if (RootState.CloneType >= 2) prototype.states[c].CopyTo(RootState.CloneType, states[c]);
@@ -133,16 +123,11 @@ namespace Cryville.Crtr.Event {
for (var i = 0; i < batch.Count; i++) { for (var i = 0; i < batch.Count; i++) {
var ev = batch[i]; var ev = batch[i];
if (ev.Container != null) { if (ev.Container != null) {
/* if (prototype != null && !states.ContainsKey(ev.Container))
AddChildState(prototype.states[ev.Container].Parent.Container, ev.Container); */
// TODO
// if (prototype != null) prototype.states[ev.Container].CopyTo(RootState.CloneType, states[ev.Container]);
EnsureActivity(ev.Container); EnsureActivity(ev.Container);
states[ev.Container].Handle(ev); states[ev.Container].Handle(ev);
} }
if (ev.Unstamped is EventContainer) { if (ev.Unstamped is EventContainer) {
if (ev.Container != null) EnsureActivity((EventContainer)ev.Unstamped); if (ev.Container != null) EnsureActivity((EventContainer)ev.Unstamped);
// AddChildState(ev.Container, (EventContainer)ev.Unstamped);
} }
} }
ValidateStates(); ValidateStates();

View File

@@ -115,28 +115,9 @@ namespace Cryville.Crtr {
Settings.Default.LastRunVersion = Application.version; Settings.Default.LastRunVersion = Application.version;
Settings.Default.Save(); Settings.Default.Save();
// TODO Remove test log
/*Logger.Log("main", 0, "Game", "Installed fonts:");
foreach (var f in Font.GetOSInstalledFontNames()) {
Logger.Log("main", 0, "Game", " {0}", f);
}*/
Logger.Log("main", 1, "Game", "Initialized"); Logger.Log("main", 1, "Game", "Initialized");
/*ServicePointManager.SecurityProtocol
= SecurityProtocolType.Ssl3
| SecurityProtocolType.Tls
| SecurityProtocolTypeExtensions.Tls11
| SecurityProtocolTypeExtensions.Tls12
| SecurityProtocolTypeExtensions.Tls13
;
ServicePointManager.ServerCertificateValidationCallback = certValidCallback;*/
} }
/*static bool certValidCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) {
return true;
}*/
#if UNITY_ANDROID #if UNITY_ANDROID
[MonoPInvokeCallback(typeof(OpenSL.Native.slBufferQueueCallback))] [MonoPInvokeCallback(typeof(OpenSL.Native.slBufferQueueCallback))]
static void audioCallback(IntPtr caller, IntPtr context) { static void audioCallback(IntPtr caller, IntPtr context) {

View File

@@ -7,21 +7,13 @@ using UnityEngine;
namespace Cryville.Crtr { namespace Cryville.Crtr {
class GroupHandler : ContainerHandler { class GroupHandler : ContainerHandler {
// private StampedState cs;
public ChartHandler ch; public ChartHandler ch;
// Chart.Group group;
// Dictionary<StampedEvent, GameObject> notePool = new Dictionary<StampedEvent, GameObject>();
SquareMatrix matFrame; SquareMatrix matFrame;
List<ContainerState> tracks; List<ContainerState> tracks;
public GroupHandler(Chart.Group tg, ChartHandler ch) : base() { public GroupHandler(Chart.Group tg, ChartHandler ch) : base() {
//group = tg;
this.ch = ch; this.ch = ch;
/*foreach (Chart.Track t in group.tracks) {
handlers.Add(new TrackHandler(t, this));
}*/
} }
public override string TypeName { public override string TypeName {
@@ -40,117 +32,6 @@ namespace Cryville.Crtr {
matFrame = SquareMatrix.WithPolynomialCoefficients(tracks.Count); matFrame = SquareMatrix.WithPolynomialCoefficients(tracks.Count);
} }
/*EventPrehandler ph;
List<StampedEvent> sevs = new List<StampedEvent>();
public void StartPrehandler(EventPrehandler parent) {
/*List<Chart.Event> appevs = new List<Chart.Event>();
foreach (Chart.Note ev in group.notes) {
if (ev.duration > 0) {
for (float b = 0f; b < ev.duration; b += ev.jdg_interval) {
appevs.Add(new Chart.InternalJudgement() { beat = ev.beat, BeatOffset = b, Parent = ev });
}
}
}
ph = new EventPrehandler(
parent.chart,
group.motions.Cast<Chart.Event>()
.Concat<Chart.Event>(group.notes.Cast<Chart.Event>()),
parent
);
foreach (TrackHandler h in handlers)
h.StartPrehandler(ph);
}
public void PrehandleToTime(float toTime) {
ph.ForwardToTime(toTime, ev => {
foreach (var h in handlers) h.PrehandleToTime(ph.Time);
/*
if (ev is Chart.Note) {
var tev = (Chart.Note)ev;
sevs.Add(new StampedEvent.Judge() {
Time = phs.Time - Main.judge * tev.tol,
EndTime = phs.Time + Main.judge * tev.tol,
Event = tev,
Type = tev.wipe ? JudgementType.Held : JudgementType.Attack,
JudgeArea = new Area() {
Point1 = phs.Point,
Point2 = phs.Point + new Chart.Point(0f, 0.1f, 0f, 0.1f).ToRelative(Main.hitRect),
Type = AreaType.Circle
}
});
}
else if (ev is Chart.InternalJudgement) {
var tev = (Chart.InternalJudgement)ev;
sevs.Add(new StampedEvent.Judge() {
Time = phs.Time - Main.judge * tev.Parent.tol,
EndTime = phs.Time + Main.judge * tev.Parent.tol,
Event = tev,
Type = JudgementType.Held,
JudgeArea = new Area() {
Point1 = phs.Point,
Point2 = phs.Point + new Chart.Point(0f, 0.1f, 0f, 0.1f).ToRelative(Main.hitRect),
Type = AreaType.Circle
}
});
}
});
}
public void EndPrehandler(StampedState parent) {
sevs = ph.Result;
cs = new StampedState(ch.chart, sevs, parent);
foreach (var h in handlers) h.EndPrehandler(cs);
}*/
/*List<StampedEvent.Judge> judgements = new List<StampedEvent.Judge>();
public void SendInput(int id, TouchPhase phase, Vector2 jpos) {
for (int i = judgements.Count - 1; i >= 0; i--) {
if (judgements[i].JudgeArea.Contains(jpos)) {
if (phase == TouchPhase.Began && judgements[i].Type == JudgementType.Attack) {
ch.ReportJudge(true);
judgements.RemoveAt(i);
}
else if ((phase == TouchPhase.Stationary || phase == TouchPhase.Moved) && judgements[i].Type == JudgementType.Held) {
ch.ReportJudge(true);
judgements.RemoveAt(i);
}
}
}
}*/
/*Vector3 cpoint;
Vector3 cpoint2;
Vector3 prevp = Vector3.zero;
Vector3 prevwp = Vector3.zero;
Vector3 prevp2 = Vector3.zero;
Vector3 prevwp2 = Vector3.zero;*/
public override void Update(ContainerState s, StampedEvent ev) {
base.Update(s, ev);
/*cs.ForwardToTime(toTime);
foreach (var handler in handlers) handler.Update(cs.Time);*/
//cs.ForwardToTime(toTime);
/*ss.ForwardToTime(toTime, ev => {
if (ev is StampedEvent.Judge) {
var tev = (StampedEvent.Judge)ev;
judgements.Add(tev);
}
});
for (int i = judgements.Count - 1; i >= 0; i--) {
if (judgements[i].EndTime < cs.Time) {
ch.ReportJudge(false);
judgements.RemoveAt(i);
}
}*/
// gogroup.rotation = Quaternion.Euler(cs.Direction);
}
public override void EndUpdate(ContainerState s) {
base.EndUpdate(s);
}
public ColumnVector<Vector3> GetCurrentFrame(Func<ContainerState, Vector3> func) { public ColumnVector<Vector3> GetCurrentFrame(Func<ContainerState, Vector3> func) {
var vl = from t in tracks select func(t); var vl = from t in tracks select func(t);
return matFrame.Eliminate( return matFrame.Eliminate(

View File

@@ -3,675 +3,6 @@ using Cryville.Common.Unity.Input;
using System.Collections.Generic; using System.Collections.Generic;
namespace Cryville.Crtr { namespace Cryville.Crtr {
#region Obsolete
#if false
[Obsolete]
public class Judge {
/// <summary>
/// The computed positions of the notes.
/// </summary>
readonly Dictionary<StampedEvent.Judge, Vector2> pos
= new Dictionary<StampedEvent.Judge, Vector2>();
struct ActiveJudge : IEquatable<ActiveJudge> {
public StampedEvent.Judge Event;
public NoteHandler NoteHandler;
public bool Equals(ActiveJudge other) {
return Event == other.Event;
}
public override int GetHashCode() {
return Event.GetHashCode();
}
public ActiveJudge(StampedEvent.Judge ev, NoteHandler noteHandler) {
Event = ev; NoteHandler = noteHandler;
}
}
struct JudgeIdentifier : IEquatable<JudgeIdentifier> {
public NoteHandler NoteHandler { get; private set; }
public Chart.Note Note { get { return NoteHandler.Event; } }
public PrimaryJudge TargetJudge { get; private set; }
public int Layer { get { return TargetJudge.layer; } }
public override bool Equals(object obj) {
if (!(obj is JudgeIdentifier)) return false;
return Equals((JudgeIdentifier)obj);
}
public bool Equals(JudgeIdentifier other) {
return NoteHandler.Equals(other.NoteHandler) && Layer == other.Layer;
}
public override int GetHashCode() {
return NoteHandler.GetHashCode() ^ Layer;
}
public JudgeIdentifier(NoteHandler n, PrimaryJudge j) {
NoteHandler = n; TargetJudge = j;
}
}
struct JudgeEventIdentifier {
public JudgeIdentifier JudgeIdentifier { get; private set; }
public StampedEvent.Judge Event { get; private set; }
public JudgeEventIdentifier(JudgeIdentifier jid, StampedEvent.Judge ev) {
JudgeIdentifier = jid;
Event = ev;
}
}
readonly Dictionary<JudgeIdentifier, JudgeState> stateList = new Dictionary<JudgeIdentifier, JudgeState>();
readonly List<JudgeIdentifier> activeList = new List<JudgeIdentifier>();
readonly Dictionary<JudgeIdentifier, List<StampedEvent.Judge>> activeEvents = new Dictionary<JudgeIdentifier, List<StampedEvent.Judge>>();
readonly Dictionary<JudgeIdentifier, PrimaryJudge> immList = new Dictionary<JudgeIdentifier, PrimaryJudge>();
readonly List<StampedEvent.Judge> hitList = new List<StampedEvent.Judge>();
readonly List<JudgeEventIdentifier> missList = new List<JudgeEventIdentifier>();
readonly List<NoteHandler> deactivateList = new List<NoteHandler>();
readonly Dictionary<int, PointerInfo> ptr = new Dictionary<int, PointerInfo>();
readonly List<int> invalidatedPtr = new List<int>();
class JudgeState {
/// <summary>
/// The ID of the pointers currently holding on the note, the first of which is the main pointer.
/// </summary>
public readonly List<int> PointerIds = new List<int>();
/// <summary>
/// The ID of the pointers currently positioned on the note, but not sliding in nor holding down.
/// </summary>
public readonly List<int> NotOwnedPointerIds = new List<int>();
public Vector2 Position;
public Vector2 ImmediatePosition;
}
public readonly Dictionary<string, float> scores = new Dictionary<string, float>();
readonly CompiledRuleset ruleset;
public Judge(CompiledRuleset r) {
ruleset = r;
foreach (var s in r.scores)
scores.Add(s.Key, s.Value.init);
}
public void RecordPos(StampedEvent.Judge ev, Vector2 pt) { pos[ev] = pt; }
internal void Issue(StampedEvent.Judge ev, NoteHandler nh) {
// Logger.Log("main", 0, "Judge", "Issue: {0} {1} {2}", ev.Time, ev.Container.GetHashCode(), ruleset.primary_judges.First(i => i.Value == ev.TargetJudge).Key);
// var u = new ActiveJudge(ev, nh);
/*if (ev.TargetJudge.PassCh.ContainsKey("br"))
Logger.Log("main", 0, "Judge", "{0}", ev.StartEvent == null);*/
if (ev.StartEvent != null) {
var jid = new JudgeIdentifier(nh, ev.StartEvent.TargetJudge);
int i = activeList.IndexOf(jid);
if (i >= 0) missList.Add(new JudgeEventIdentifier(jid, ev.StartEvent));
}
else {
var jid = new JudgeIdentifier(nh, ev.TargetJudge);
if (!activeList.Contains(jid)) {
var i = activeList.FindLastIndex(j => j.TargetJudge.priority <= ev.TargetJudge.priority);
activeList.Insert(i + 1, jid);
}
if (!activeEvents.ContainsKey(jid)) activeEvents.Add(jid, new List<StampedEvent.Judge> { ev });
else activeEvents[jid].Add(ev);
if (!stateList.ContainsKey(jid)) {
stateList.Add(jid, CreateJudgeState(ev.TargetJudge, pos[ev]));
}
stateList[jid].Position = pos[ev];
}
}
internal void IssueImmediate(NoteHandler nh, string pjn, Vector2 pt) {
var key = new JudgeIdentifier(nh, ruleset.primary_judges[pjn]);
if (!immList.ContainsKey(key)) immList.Add(key, ruleset.primary_judges[pjn]);
if (!stateList.ContainsKey(key)) {
stateList.Add(key, CreateJudgeState(ruleset.primary_judges[pjn], pt));
}
stateList[key].ImmediatePosition = pt;
}
JudgeState CreateJudgeState(PrimaryJudge judge, Vector2 pt) {
var state = new JudgeState();
var etor = new Evaluator();
foreach (var p in ptr) {
var info = p.Value;
var wp = ScreenToWorldPoint(info.Position);
etor.Context = new EvaluatorContext {
Extra = new Dictionary<string, object> {
{ "npos", pt },
{ "-hitpos", wp }
}
};
if (MatchArea(judge.PassCh.Values.First().area, etor))
state.NotOwnedPointerIds.Add(info.Id);
}
return state;
}
Vector2 ScreenToWorldPoint(Vector2 pp) {
Vector3 sp = pp;
sp.y = Screen.height - sp.y;
sp.z = -Camera.main.transform.position.z;
return Camera.main.ScreenToWorldPoint(sp);
}
public void NewFrame() {
ptr.Clear();
}
public void Feed(PointerInfo info) {
var etor = new Evaluator();
var wp = ScreenToWorldPoint(info.Position);
foreach (var u in activeList) {
foreach (var j in activeEvents[u]) {
var t = j.NoteTime;
var deltat = info.Time - t;
var pj = j.TargetJudge;
etor.Context = new EvaluatorContext() {
Extra = new Dictionary<string, object>() {
{ "npos", pos[j] },
{ "-hitpos", wp }
}
};
foreach (var sj in pj.PassCh) {
var flag = false;
if (!MatchSecondaryJudge(u.NoteHandler, info.Id, stateList[u], sj.Value, j.IsEndJudge, info, deltat, wp, etor))
continue;
foreach (var tj in sj.Value.PassCh) {
if (!MatchTertiaryJudge(tj.Value, deltat, wp, etor))
continue;
// TODO Fire hit input
foreach (var s in tj.Value.scores)
UpdateScore(s.Key, s.Value);
Logger.Log("main", 0, "Judge", "Hit F: {0} {1}", sj.Key, tj.Key);
hitList.Add(j);
flag = true; break;
}
if (flag) break;
}
}
FlushHitList(u);
}
FlushDeactivateList();
foreach (var u in immList) {
var pj = u.Value;
etor.Context = new EvaluatorContext() {
Extra = new Dictionary<string, object>() {
{ "-hitpos", wp }
}
};
foreach (var sj in pj.PassCh) {
if (!MatchSecondaryJudge(u.Key.NoteHandler, info.Id, stateList[u.Key], sj.Value, false, info, 0, wp, etor, true))
continue;
if (MatchImmJudgeSubProcess(u.Key.NoteHandler, info.Id, sj.Key, sj.Value, sj.Value.type.ToString(), false, 0, wp, etor))
break;
}
}
}
public void Update(PointerInfo info) {
var etor = new Evaluator();
var wp = ScreenToWorldPoint(info.Position);
foreach (var u in activeList) {
foreach (var j in activeEvents[u]) {
var t = j.NoteTime;
var deltat = info.Time - t;
var pj = j.TargetJudge;
etor.Context = new EvaluatorContext() {
Extra = new Dictionary<string, object>() {
{ "npos", pos[j] },
{ "-hitpos", wp }
}
};
foreach (var sj in pj.PassCh) {
var flag = false;
if (!MatchSecondaryActiveJudge(u.NoteHandler, info.Id, stateList[u], sj.Value, j.IsEndJudge, info, deltat, wp, etor))
continue;
foreach (var tj in sj.Value.PassCh) {
if (!MatchTertiaryJudge(tj.Value, deltat, wp, etor))
continue;
// TODO Fire hit input
foreach (var s in tj.Value.scores)
UpdateScore(s.Key, s.Value);
Logger.Log("main", 0, "Judge", "Hit U: {0} {1}", sj.Key, tj.Key);
hitList.Add(j);
flag = true; break;
}
if (flag) break;
}
}
FlushHitList(u);
}
FlushDeactivateList();
if (!invalidatedPtr.Contains(info.Id)) ptr[info.Id] = info;
}
public void Trash(double time) {
var etor = new Evaluator();
foreach (var u in activeList) {
foreach (var j in activeEvents[u]) {
if (MatchImmJudge(u.NoteHandler, j.TargetJudge, j.IsEndJudge, time - j.NoteTime, stateList[u], etor))
hitList.Add(j);
}
// Logger.Log("main", 0, "Judge", "Active Events: {0}", activeEvents[u].Count);
FlushHitList(u);
}
FlushDeactivateList();
// Logger.Log("main", 0, "Judge", "Active States: {0}", activeList.Count);
foreach (var u in missList) {
// TODO this check shouldn't be done here, instead, invalidate/compensate those already in the active events
if (!activeEvents.ContainsKey(u.JudgeIdentifier)) continue;
var evs = activeEvents[u.JudgeIdentifier];
var ev = u.Event;
if (!evs.Contains(ev)) continue;
var pj = ev.TargetJudge;
var flag = false;
foreach (var sj in pj.PassCh) {
if (!MatchSecondaryMissJudge(u.JudgeIdentifier.NoteHandler, sj.Value, etor))
continue;
foreach (var tj in sj.Value.PassCh) {
/*if (!MatchTertiaryJudge(j, tj.Value, etor))
continue;*/
foreach (var s in tj.Value.scores)
UpdateScore(s.Key, s.Value);
Logger.Log("main", 0, "Judge", "Miss: {0}", tj.Key);
flag = true; break;
}
if (flag) break;
}
if (!flag)
Logger.Log("main", 3, "Judge", "Unjudged miss");
evs.Remove(ev);
if (u.Event.IsEndJudge) deactivateList.Add(u.JudgeIdentifier.NoteHandler);
}
FlushDeactivateList();
missList.Clear();
foreach (var j in immList) {
MatchImmJudge(j.Key.NoteHandler, j.Value, false, 0, stateList[j.Key], etor);
}
/*var rmimm = new List<JudgeIdentifier>();
foreach (var i in immList) {
if (i.Value.Active) i.Value.Active = false;
else rmimm.Add(i.Key);
}
foreach (var i in rmimm) immList.Remove(i);*/
// Logger.Log("main", 0, "Judge", "Active List: {0}", activeList.Count);
immList.Clear();
}
void FlushHitList(JudgeIdentifier jid) {
if (activeEvents.ContainsKey(jid))
foreach (var j in hitList) {
activeEvents[jid].Remove(j);
// TODO items in stateList need to be destroyed
}
hitList.Clear();
}
void FlushDeactivateList() {
for (int i = activeList.Count - 1; i >= 0; i--) {
if (deactivateList.Contains(activeList[i].NoteHandler)) {
activeEvents.Remove(activeList[i]);
activeList.RemoveAt(i);
}
}
deactivateList.Clear();
}
bool MatchImmJudge(NoteHandler nh, PrimaryJudge pj, bool endjudge, double deltat, JudgeState v, Evaluator etor) {
bool flag = false;
var ptrids = new Dictionary<int, int>();
foreach (var sj in pj.PassCh) {
var wp = ScreenToWorldPoint(v.ImmediatePosition);
ptrids.Clear();
foreach (var p in ptr) {
int id = p.Key;
Vector3 sp2 = p.Value.Position;
sp2.y = Screen.height - sp2.y;
sp2.z = -Camera.main.transform.position.z;
var wp2 = (Vector2)Camera.main.ScreenToWorldPoint(sp2);
etor.Context = new EvaluatorContext() {
Extra = new Dictionary<string, object>() {
{ "npos", v.Position },
{ "-hitpos", wp2 }
}
};
if (MatchArea(sj.Value.area, etor)) {
if (v.NotOwnedPointerIds.Contains(id)) continue;
bool flag2 = !v.PointerIds.Contains(id);
if (flag2) ptrids.Add(id, 1);
if (flag) continue;
if (sj.Value.type.HasFlag(JudgeType.enterp)) {
if (v.PointerIds.Count == 0) {
flag = MatchImmJudgeSubProcess(nh, p.Key, sj.Key, sj.Value, "enterp", endjudge, deltat, wp, etor);
}
}
else if (sj.Value.type.HasFlag(JudgeType.enters)) {
if (v.PointerIds.Count > 0) {
flag = MatchImmJudgeSubProcess(nh, p.Key, sj.Key, sj.Value, "enters", endjudge, deltat, wp, etor);
}
}
if (flag && sj.Value.@override && flag2) ptrids[id] = 2;
// else if ((int)sj.Value.type >= 4096) continue;
/*if (!v.PointerIds.Contains(id)) {
// Logger.Log("main", 0, "Judge", "push {0}", id);
if (sj.Value.@override) v.PointerIds.Insert(0, id);
else v.PointerIds.Add(id);
}*/
}
else {
if (v.PointerIds.Contains(id)) ptrids.Add(id, 0);
if (v.NotOwnedPointerIds.Contains(id)) ptrids.Add(id, -1);
if (flag) continue;
if (sj.Value.type.HasFlag(JudgeType.leaveb)) {
// Logger.Log("main", 0, "Judge", "POS {0}", v.Position);
if (v.PointerIds.Count == 1 && v.PointerIds[0] == id) {
flag = MatchImmJudgeSubProcess(nh, p.Key, sj.Key, sj.Value, "leaveb", endjudge, deltat, wp, etor);
}
}
else if (sj.Value.type.HasFlag(JudgeType.leavec)) {
if (v.PointerIds.Count > 1 && v.PointerIds[0] == id) {
flag = MatchImmJudgeSubProcess(nh, p.Key, sj.Key, sj.Value, "leavec", endjudge, deltat, wp, etor);
}
}
else if (sj.Value.type.HasFlag(JudgeType.leaves)) {
if (v.PointerIds.Count > 1 && v.PointerIds.IndexOf(id) > 0) {
flag = MatchImmJudgeSubProcess(nh, p.Key, sj.Key, sj.Value, "leaves", endjudge, deltat, wp, etor);
}
}
// else if ((int)sj.Value.type >= 4096) continue;
/*if (v.PointerIds.Contains(id)) {
// Logger.Log("main", 0, "Judge", "pop {0}", id);
v.PointerIds.Remove(id);
}*/
}
}
if (flag) {
foreach (var i in ptrids) {
switch (i.Value) {
case -1: v.NotOwnedPointerIds.Remove(i.Key); break;
case 0: v.PointerIds.Remove(i.Key); break;
case 1: v.PointerIds.Add(i.Key); break;
case 2: v.PointerIds.Insert(0, i.Key); break;
}
}
// Logger.Log("main", 0, "Judge", "{0}", v.PointerIds.Count);
return true;
}
}
foreach (var i in ptrids) {
switch (i.Value) {
case -1: v.NotOwnedPointerIds.Remove(i.Key); break;
case 0: v.PointerIds.Remove(i.Key); break;
case 1: v.PointerIds.Add(i.Key); break;
case 2: v.PointerIds.Insert(0, i.Key); break;
}
}
return false;
}
bool MatchImmJudgeSubProcess(NoteHandler nh, int ptrid, string sj_name, SecondaryJudge sj, string judge_type, bool endjudge, double deltat, Vector2 wp, IEvaluator etor) {
TryInvalidate(nh, sj, ptrid);
if (endjudge) Compensate(nh);
foreach (var tj in sj.PassCh) {
if (MatchTertiaryJudge(tj.Value, deltat, wp, etor)) {
foreach (var s in tj.Value.scores)
UpdateScore(s.Key, s.Value);
Logger.Log("main", 0, "Judge", "Hit I {2}: {0} {1}", sj_name, tj.Key, judge_type);
return true;
}
}
return false;
}
void TryInvalidate(NoteHandler nh, SecondaryJudge sj, int ptrid) {
if (sj.invalidate.HasFlag(Invalidation.finger) && ptrid != -1) {
invalidatedPtr.Add(ptrid);
ptr.Remove(ptrid);
}
if (sj.invalidate.HasFlag(Invalidation.note)) {
List<StampedEvent.Judge> invalidatedList = nh.Invalidate();
// TODO also handle events in `activeEvents`
foreach (var j in invalidatedList) {
if (j.StartEvent != null) continue;
Invalidate(j);
}
deactivateList.Add(nh);
}
}
void Invalidate(StampedEvent.Judge j) {
bool flag = false;
foreach (var sj in j.TargetJudge.PassCh) {
if (!sj.Value.type.HasFlag(JudgeType.invalidate)) continue;
foreach (var tj in sj.Value.PassCh) {
foreach (var s in tj.Value.scores)
UpdateScore(s.Key, s.Value);
Logger.Log("main", 0, "Judge", "Invalidate: {0}", tj.Key);
flag = true; break;
}
if (flag) break;
}
if (!flag) Logger.Log("main", 3, "Judge", "Unjudged invalidation");
}
void Compensate(NoteHandler nh) {
List<StampedEvent.Judge> compensateList = nh.Invalidate();
// Logger.Log("main", 0, "Judge", "comp {0}", compensateList.Count);
// TODO also handle events in `activeEvents`
foreach (var j in compensateList) {
if (j.StartEvent != null) continue;
bool flag = false;
foreach (var sj in j.TargetJudge.PassCh) {
if (!sj.Value.type.HasFlag(JudgeType.compensate)) continue;
foreach (var tj in sj.Value.PassCh) {
foreach (var s in tj.Value.scores)
UpdateScore(s.Key, s.Value);
Logger.Log("main", 0, "Judge", "Compensate: {0}", tj.Key);
flag = true; break;
}
if (flag) break;
}
if (!flag) Logger.Log("main", 3, "Judge", "Unjudged compensation");
}
deactivateList.Add(nh);
}
/// <summary>
/// Matches an attack or release judge.
/// </summary>
bool MatchSecondaryJudge(NoteHandler nh, int ptrid, JudgeState state, SecondaryJudge sj, bool endjudge, PointerInfo p, double deltat, Vector2 wp, IEvaluator etor, bool immsec = false) {
bool flag = false;
int pid = p.Id;
var phase = p.Phase;
if (sj.type == JudgeType.none) return false;
if (!immsec && sj.area != null) if (!MatchArea(sj.area, etor)) return false;
if (phase == PointerPhase.Begin) {
if (sj.type.HasFlag(JudgeType.attackp)) {
if (state.PointerIds.Count == 0) flag = true;
}
if (sj.type.HasFlag(JudgeType.attacks)) {
if (state.PointerIds.Count > 0) flag = true;
}
/*if (!state.PointerIds.Contains(pid)) {
if (sj.@override) ptrop = 2;
else ptrop = 1;
}*/
}
if (phase.HasFlag(PointerPhase.End)) {
if (sj.type.HasFlag(JudgeType.releaseb)) {
if (state.PointerIds.Count == 1 && state.PointerIds[0] == pid) flag = true;
}
if (sj.type.HasFlag(JudgeType.releasec)) {
if (state.PointerIds.Count > 1 && state.PointerIds[0] == pid) flag = true;
}
if (sj.type.HasFlag(JudgeType.releases)) {
if (state.PointerIds.IndexOf(pid) > 0) flag = true;
}
//if (state.PointerIds.IndexOf(pid) >= 0) ptrop = 0;
}
if (!flag) return false;
if (sj.time != null) {
var tr = sj.time.Eval<List<float>>(etor);
if (deltat < tr[0] || deltat > tr[1]) return false;
}
if (endjudge) Compensate(nh);
TryInvalidate(nh, sj, ptrid);
return true;
}
/// <summary>
/// Matches a contact judge.
/// </summary>
bool MatchSecondaryActiveJudge(NoteHandler nh, int ptrid, JudgeState state, SecondaryJudge sj, bool endjudge, PointerInfo p, double deltat, Vector2 wp, IEvaluator etor) {
bool flag = false;
int pid = p.Id;
// Logger.Log("main", 0, "Judge", "Pointers: {0}", state.PointerIds.Count);
if (sj.type == JudgeType.none) return false;
if (sj.type.HasFlag(JudgeType.contactp)) {
if (state.PointerIds.Count > 0 && pid == state.PointerIds[0]) flag = true;
}
if (sj.type.HasFlag(JudgeType.contacts)) {
if (state.PointerIds.Count > 0 && pid != state.PointerIds[0]) flag = true;
// if (sj.@override) stateList[j].PointerId = pid;
}
if (!flag) return false;
if (sj.time != null) {
var tr = sj.time.Eval<List<float>>(etor);
if (deltat < tr[0] || deltat > tr[1]) return false;
}
if (!MatchArea(sj.area, etor)) return false;
TryInvalidate(nh, sj, ptrid);
if (endjudge) Compensate(nh);
return true;
// TODO Invalidate & Call
}
bool MatchSecondaryMissJudge(NoteHandler nh, SecondaryJudge sj, Evaluator etor) {
if (sj.type.HasFlag(JudgeType.miss)) {
TryInvalidate(nh, sj, -1);
return true;
}
return false;
}
bool MatchTertiaryJudge(TertiaryJudge tj, double deltat, Vector3 wp, IEvaluator etor) {
if (tj.time != null) {
var tr = tj.time.Eval<List<float>>(etor);
if (deltat < tr[0] || deltat > tr[1]) return false;
}
if (!MatchArea(tj.area, etor)) return false;
return true;
}
bool MatchArea(Expression exp, IEvaluator etor) {
if (exp != null) {
var a = exp.Eval<float>(etor);
if (a > 0) return false;
}
return true;
}
void UpdateScore(string key, Expression value) {
var etor = new Evaluator();
var extra = new Dictionary<string, object>(scores.Count);
foreach (var s in scores) extra.Add(s.Key, s.Value);
etor.Context = new EvaluatorContext() { Extra = extra };
var ak = key.Split(' ');
string name = ak[ak.Length - 1];
bool setMode = false;
float result = scores[name];
var prop = ruleset.scores[name];
if (ak.Length > 1)
for (int i = 0; i < ak.Length - 1; i++)
if (ak[i] == "@set") setMode = true;
if (setMode)
result = value.Eval<float>(etor);
else
result += value.Eval<float>(etor);
if (prop.range != null) {
var range = prop.range.Eval<List<float>>(etor);
if (result < range[0]) result = range[0];
else if (result > range[1]) result = range[1];
}
if (prop.min != null && result < scores[prop.min])
scores[prop.min] = result;
if (prop.max != null && result > scores[prop.max])
scores[prop.max] = result;
scores[name] = result;
foreach (var s in scores) extra[s.Key] = s.Value;
etor.Context = new EvaluatorContext() { Extra = extra };
foreach (var s in ruleset.scores.Keys) {
if (ruleset.scores[s].value != null) {
scores[s] = ruleset.scores[s].value.Eval<float>(etor);
}
}
ScoreCache.Clear();
}
readonly Dictionary<string, string> ScoreCache = new Dictionary<string, string>();
public Dictionary<string, string> GetScoreStrings() {
if (ScoreCache.Count == 0) {
foreach (var s in scores) {
ScoreCache.Add(s.Key, s.Value.ToString(ruleset.scores[s.Key].format));
}
}
return ScoreCache;
}
public string FormatScores() {
using (gstring.Block()) {
bool flag = false;
gstring result = new gstring(0);
foreach (var s in GetScoreStrings()) {
result += gstring.Format(flag ? "\n{0}: {1}" : "{0}: {1}", s.Key, (string)s.Value);
flag = true;
}
return result.Intern();
}
}
}
[Obsolete]
public class PrimaryJudge {
public List<string> pass;
public Dictionary<string, SecondaryJudge> PassCh
= new Dictionary<string, SecondaryJudge>();
public Expression time;
/// <summary>
/// The layer of the primary judge. Judges on different layers do not interfere with each other.
/// </summary>
public int layer = 0;
/// <summary>
/// The priority of the primary judge. Judges with higher priority are handled first on the same layer.
/// </summary>
public int priority = 0;
}
[Obsolete]
public class SecondaryJudge {
public JudgeType type;
public List<string> call;
public Dictionary<string, SecondaryJudge> CallCh
= new Dictionary<string, SecondaryJudge>();
public bool @return;
public List<string> pass;
public Dictionary<string, TertiaryJudge> PassCh
= new Dictionary<string, TertiaryJudge>();
public Expression time;
public Expression area;
public Invalidation invalidate;
public bool @override;
}
[Flags][Obsolete]
public enum JudgeType {
none = 0,
attackp = 1, attacks = 2, attack = 3,
releaseb = 4, releasec = 8, releasep = 12, releases = 16, release = 28,
enterp = 32, enters = 64, enter = 96,
leaveb = 128, leavec = 256, leavep = 384, leaves = 512, leave = 896,
setp = 33, sets = 66, set = 99,
unsetb = 132, unsetc = 264, unsetp = 396, unsets = 528, unset = 924,
contactp = 1024, contacts = 2048, contact = 3072,
miss = 4096, compensate = 8192, invalidate = 16384
}
[Flags][Obsolete]
public enum Invalidation {
none = 0, finger = 1, note = 2
}
[Obsolete]
public class TertiaryJudge {
public Expression time;
public Expression area;
public Dictionary<string, Expression> scores
= new Dictionary<string, Expression>();
}
[Obsolete]
public class Score {
public Expression range;
public Expression value;
public float init = 0;
public string min;
public string max;
public string format = "";
}
#endif
#endregion
public class Judge { public class Judge {
readonly PdtRuleset rs; readonly PdtRuleset rs;
public Judge() { public Judge() {

View File

@@ -1,5 +1,4 @@
using UnityEngine; using UnityEngine;
using System.Collections;
namespace Cryville.Crtr { namespace Cryville.Crtr {
public class MeshWrapper { public class MeshWrapper {

View File

@@ -1,12 +1,9 @@
using Cryville.Common; using Cryville.Common;
using Cryville.Common.Pdt; using Cryville.Common.Pdt;
using Newtonsoft.Json.Linq;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Security.AccessControl;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using UnityEngine; using UnityEngine;
using UnityEngine.UIElements;
namespace Cryville.Crtr { namespace Cryville.Crtr {
public enum TransitionType : byte { public enum TransitionType : byte {
@@ -142,143 +139,6 @@ namespace Cryville.Crtr {
} }
} }
/*[JsonConverter(typeof(MotionValueConverter))]
public class MotionValue {
public MotionValue(Type type, int length) {
// if (!type.IsValueType) throw new ArgumentException();
Inherit = Inheritance.Inherit;
Method = InheritMethod.Addition;
values = new IVector[length];
for (int i = 0; i < length; i++) {
values[i] = (IVector)type.GetConstructor(new Type[]{}).Invoke(new object[]{});
_rel.Add(false);
}
valueType = type;
}
public MotionValue Clone() {
var r = (MotionValue)this.MemberwiseClone();
var len = Length;
var mvs = new IVector[len];
for (int i = 0; i < len; i++) {
var mv = values[i];
if (mv == null) mvs[i] = null;
else mvs[i] = mv.Clone();
}
r.values = mvs;
return r;
}
public MotionValue(string str) {
Inherit = Inheritance.Inherit;
Method = InheritMethod.Addition;
var m = Regex.Match(str, @"^([io]?)(p?)(h?)(.*)$");
switch (m.Groups[1].Value) {
case "i": Inherit = Inheritance.Inherit; break;
case "o": Inherit = Inheritance.Override; break;
}
// TODO Handle p and h modifiers
var vstr = m.Groups[4].Value;
var vs = vstr.Split(',');
if (vstr.Contains("w") || vstr.Contains("h")) valueType = typeof(Vec2);
else valueType = typeof(Vec1);
var len = vs.Length;
values = new IVector[len];
for (int i = 0; i < len; i++) {
var v = vs[i];
var m2 = Regex.Match(v, @"^\s*(\+?)\s*(.*?)\s*$");
_rel.Add(m2.Groups[1].Value != "");
if (m2.Groups[2].Value.Trim() == "") {
values[i] = null;
}
else if (valueType == typeof(Vec2)) {
Vector2 r = Vector2.zero;
var vs2 = m2.Groups[2].Value.Split('+');
foreach (var s in vs2) {
var s2 = s.Trim();
float n = float.Parse(s2.Substring(0, s2.Length - 1));
if (s2.EndsWith("w")) {
r.x += n;
}
else if (s2.EndsWith("h")) {
r.y += n;
}
}
values[i] = new Vec2(r);
}
else if (valueType == typeof(Vec1)) {
values[i] = new Vec1(float.Parse(v));
}
}
}
public Inheritance Inherit = Inheritance.Unset;
public InheritMethod Method = InheritMethod.Addition;
public readonly Type valueType;
List<bool> _rel = new List<bool>();
public IVector[] values;
/*public List<IVector> NonnullValues {
get {
var r = new List<IVector>();
foreach (var v in values) {
}
}
}*
public int Length { get { return values.Length; } }
public void Apply(MotionValue v) {
if (v.valueType != this.valueType) throw new ArgumentException();
if (v.Length != this.Length) throw new ArgumentException();
if (this.Inherit == Inheritance.Unset) this.Inherit = v.Inherit;
for (int i = 0; i < Length; i++) {
if (this.values[i] == null) continue;
if (v._rel[i]) {
this.values[i].Add(v.values[i]);
}
// else this.values[i] = v.values[i];
}
}
public void ApplyInheritance(MotionValue v) {
if (v.valueType != this.valueType) throw new ArgumentException();
if (v.Length != this.Length) throw new ArgumentException();
if (this.Inherit == Inheritance.Override) return;
for (int i = 0; i < Length; i++) {
if (Method == InheritMethod.Multiplication){
this.values[i].Multiply(((Vec1)v.values[i]).Value);
if (((Vec1)v.values[i]).Value < 1)
return;
}
else this.values[i].Add(v.values[i]);
}
}
}*/
/*public enum Inheritance {
Unset = 0, Inherit = 1, Override = 2
}
public enum InheritMethod {
Addition = 0, Multiplication = 1
}*/
/*public class MotionValueConverter : JsonConverter {
public override bool CanConvert(Type objectType) {
return objectType == typeof(string);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) {
return new MotionValue((string)reader.Value);
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) {
throw new NotImplementedException();
}
}*/
public struct MotionName : IEquatable<MotionName> { public struct MotionName : IEquatable<MotionName> {
public string MainName { get; private set; } public string MainName { get; private set; }
public string SubName { get; private set; } public string SubName { get; private set; }

View File

@@ -23,17 +23,6 @@ namespace Cryville.Crtr {
} }
} }
/*public override void Dispose() {
base.Dispose();
for (int i = notePool.Count - 1; i >= 0; i--) {
var t = notePool.ElementAt(i);
GameObject.Destroy(t.Value);
}
}*/
//Dictionary<StampedEvent, GameObject> notePool = new Dictionary<StampedEvent, GameObject>();
// Trail trail;
SectionalGameObject[] sgos; SectionalGameObject[] sgos;
public override void Init() { public override void Init() {
@@ -42,13 +31,6 @@ namespace Cryville.Crtr {
} }
protected override void PreAwake(ContainerState s) { protected override void PreAwake(ContainerState s) {
base.PreAwake(s); base.PreAwake(s);
/*var attev = StampedEvent.AttackEvent;
if (attev != null) {
GameObject headObj = null;
bool pooledh = notePool.TryGetValue(attev, out headObj);
if (pooledh)
GameObject.Destroy(headObj);
}*/
#if UNITY_5_6_OR_NEWER #if UNITY_5_6_OR_NEWER
a_head.SetPositionAndRotation(Position = GetFramePoint(s.Parent, s.Track), Rotation = GetFrameRotation(s.Parent, s.Track)); a_head.SetPositionAndRotation(Position = GetFramePoint(s.Parent, s.Track), Rotation = GetFrameRotation(s.Parent, s.Track));
#else #else
@@ -95,31 +77,14 @@ namespace Cryville.Crtr {
Rotation = GetFrameRotation(bs.Parent, bs.Track); Rotation = GetFrameRotation(bs.Parent, bs.Track);
} }
else if (s.CloneType == 2) { else if (s.CloneType == 2) {
/*for (int i = notePool.Count - 1; i >= 0; i--) {
var t = notePool.ElementAt(i);
var eev = t.Key;
var rev = t.Key.ReleaseEvent;
if (rev != null) {
eev = rev;
}
if (eev.Time < cs.Time) {
GameObject.Destroy(t.Value);
notePool.Remove(t.Key);
}
}*/
Position = GetFramePoint(ts.Parent, ts.Track); Position = GetFramePoint(ts.Parent, ts.Track);
Rotation = GetFrameRotation(ts.Parent, ts.Track); Rotation = GetFrameRotation(ts.Parent, ts.Track);
if (!gogroup) return; if (!gogroup) return;
// sgos = gogroup.GetComponentsInChildren<PolygonSGO>();
Chart.Note tev = Event; Chart.Note tev = Event;
if (tev.IsLong) { if (tev.IsLong) {
foreach (var i in sgos) foreach (var i in sgos)
i.AppendPoint(Position, Rotation); i.AppendPoint(Position, Rotation);
} }
/*else {
gogroup.position = p;
gogroup.rotation = Quaternion.Euler(ts.Direction);
}*/
} }
else if (s.CloneType == 16) { else if (s.CloneType == 16) {
if (ev == null) { } if (ev == null) { }
@@ -197,7 +162,6 @@ namespace Cryville.Crtr {
public override void EndUpdate(ContainerState s) { public override void EndUpdate(ContainerState s) {
if (s.CloneType == 0 || s.CloneType == 2) { if (s.CloneType == 0 || s.CloneType == 2) {
if (!gogroup) goto return_ahead; if (!gogroup) goto return_ahead;
// sgos = gogroup.GetComponentsInChildren<PolygonSGO>();
foreach (var i in sgos) i.Seal(); foreach (var i in sgos) i.Seal();
#if UNITY_5_6_OR_NEWER #if UNITY_5_6_OR_NEWER
a_tail.SetPositionAndRotation(GetFramePoint(ts.Parent, ts.Track), Quaternion.Euler(ts.Direction)); a_tail.SetPositionAndRotation(GetFramePoint(ts.Parent, ts.Track), Quaternion.Euler(ts.Direction));
@@ -255,22 +219,6 @@ namespace Cryville.Crtr {
if (tp != Vector3.zero) ctrl.Add(tp); if (tp != Vector3.zero) ctrl.Add(tp);
} }
if (ctrl.Count == 0) { if (ctrl.Count == 0) {
/* // Early algorithm
Vector3 m0, m1;
bool flag0 = id == 0;
bool flag1 = id == state.Children.Where(i => i.Key.Event is Chart.Track).Count() - 2;
if (flag0 && flag1) // Only two tracks exist
return (1 - t) * p1 + t * p2;
else {
Vector3 p0, p3;
if (!flag1) p3 = ((TrackHandler)tl.ElementAt(id + 2).Value.Handler).GetCurrentWorldPoint();
if (!flag0) p0 = ((TrackHandler)tl.ElementAt(id - 1).Value.Handler).GetCurrentWorldPoint();
if (flag0) m0 = 2 * (p2-p1).normalized - (p3-p1).normalized;
else m0 = 1f*((p1-p0).normalized + (p2-p1).normalized);
if (flag1) m1 = 2 * (p2-p1).normalized - (p2-p0).normalized;
else m1 = 1f*((p2-p1).normalized + (p3-p2).normalized);
return t*t*(2*t-3)*(p1-p2)+p1 + t*(t-1)*((t-1)*m0+t*m1);
}*/
var frame = gh.GetCurrentFrame(func); var frame = gh.GetCurrentFrame(func);
return frame.Dot( return frame.Dot(
ColumnVector<float>.WithPolynomialCoefficients( ColumnVector<float>.WithPolynomialCoefficients(

View File

@@ -1,14 +1,11 @@
using Cryville.Common; using Cryville.Common;
using Cryville.Common.Pdt; using Cryville.Common.Pdt;
using Cryville.Crtr.Components;
using Microsoft.Windows.PropSys;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Text; using System.Text;
using UnityEngine.Animations;
namespace Cryville.Crtr { namespace Cryville.Crtr {
public class Ruleset { public class Ruleset {
@@ -21,9 +18,6 @@ namespace Cryville.Crtr {
[JsonRequired] [JsonRequired]
public string pdt; public string pdt;
/*[JsonIgnore][Obsolete]
public CompiledRuleset c;*/
[JsonIgnore] [JsonIgnore]
public PdtRuleset Root { get; private set; } public PdtRuleset Root { get; private set; }
@@ -31,119 +25,10 @@ namespace Cryville.Crtr {
using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + pdt + ".pdt", Encoding.UTF8)) { using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + pdt + ".pdt", Encoding.UTF8)) {
var src = pdtreader.ReadToEnd(); var src = pdtreader.ReadToEnd();
Root = new RulesetInterpreter(src, null).Interpret(); Root = new RulesetInterpreter(src, null).Interpret();
/*c = PdtReader.Read<CompiledRuleset>(src);
c.PreEval(new Evaluator());*/
} }
} }
} }
#region Obsolete
#if false
[Binder(typeof(RulesetBinder))][Obsolete]
public class CompiledRuleset {
public Dictionary<string, PrimaryJudge> primary_judges;
public Dictionary<string, SecondaryJudge> secondary_judges;
public Dictionary<string, TertiaryJudge> tertiary_judges;
public Dictionary<string, Score> scores;
public void PreEval(Evaluator etor) {
foreach (var j in primary_judges.Values) {
foreach (var i in j.pass)
j.PassCh.Add(i, secondary_judges[i]);
if (j.time != null) j.time.PreEval(etor);
}
foreach (var j in secondary_judges.Values) {
if (j.call != null) foreach (var i in j.call)
j.CallCh.Add(i, secondary_judges[i]);
if (j.pass != null) foreach (var i in j.pass)
j.PassCh.Add(i, tertiary_judges[i]);
if (j.time != null) j.time.PreEval(etor);
etor.Context = new EvaluatorContext() { Reservations = new List<string>() { "npos" } };
if (j.area != null) j.area.PreEval(etor);
etor.Context = default(EvaluatorContext);
}
var scoreNames = scores.Keys.ToList();
foreach (var j in tertiary_judges.Values) {
if (j.time != null) j.time.PreEval(etor);
etor.Context = new EvaluatorContext() { Reservations = new List<string>() { "npos" } };
if (j.area != null) j.area.PreEval(etor);
etor.Context = new EvaluatorContext() { Reservations = scoreNames };
foreach (var s in j.scores.Values) {
s.PreEval(etor);
}
etor.Context = default(EvaluatorContext);
}
}
/*public void PatchChart(EventBatcher b) {
var etor = new EvalImpl();
List<StampedEvent> app = new List<StampedEvent>();
foreach (var ev in b.stampedEvents) {
if (ev.Event is Chart.Note) {
var tev = (Chart.Note)ev.Event;
if (tev.judge != null)
PatchJudge(tev, primary_judges[tev.judge], ev.Time, etor, app);
if (tev.endjudge != null)
PatchJudge(tev, primary_judges[tev.endjudge], ev.Time + ev.Duration, etor, app);
}
}
b.stampedEvents.AddRange(app);
}*/
public static void PatchJudge(Chart.Note tev, PrimaryJudge pj, float t, IEvaluator etor, List<StampedEvent.Judge> l, bool endjudge = false) {
float? min = null; float? max = null;
if (pj.time != null) {
var r = pj.time.Eval<List<float>>(etor);
min = r[0]; max = r[1];
}
else {
foreach (var sj in pj.PassCh.Values) {
if (sj.time == null) continue;
var r = sj.time.Eval<List<float>>(etor);
if (r[0] > min || min == null) min = r[0];
if (r[1] < max || max == null) max = r[1];
}
}
var sev = new StampedEvent.Judge() {
Time = t + (min ?? 0),
NoteTime = t,
Container = tev,
TargetJudge = pj,
IsEndJudge = endjudge,
};
var scev = new StampedEvent.Judge() {
Time = t,
NoteTime = t,
Container = tev,
StartEvent = sev,
IsEndJudge = endjudge,
};
var seev = new StampedEvent.Judge() {
Time = t + (max ?? 0),
NoteTime = t,
Container = tev,
TargetJudge = pj,
StartEvent = sev,
IsEndJudge = endjudge,
};
l.Add(sev); l.Add(scev); l.Add(seev);
}
}
[Obsolete]
public class RulesetBinder : EmptyBinder {
public override object ChangeType(object value, Type type, System.Globalization.CultureInfo culture) {
try {
var etor = new Evaluator();
var r = ((Expression)value).Eval(etor);
return etor.Cast(type, r);
}
catch (Exception) {
return base.ChangeType(value, type, culture);
}
}
}
#endif
#endregion
[Binder(typeof(PdtRulesetBinder))] [Binder(typeof(PdtRulesetBinder))]
public class PdtRuleset { public class PdtRuleset {
public Dictionary<string, InputDefinition> inputs; public Dictionary<string, InputDefinition> inputs;

View File

@@ -22,9 +22,6 @@ namespace Cryville.Crtr {
[JsonRequired] [JsonRequired]
public string pdt; public string pdt;
/*[JsonIgnore][Obsolete]
public CompiledSkin c;*/
[JsonIgnore] [JsonIgnore]
public PdtSkin Root { get; private set; } public PdtSkin Root { get; private set; }
@@ -32,72 +29,10 @@ namespace Cryville.Crtr {
using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + pdt + ".pdt", Encoding.UTF8)) { using (StreamReader pdtreader = new StreamReader(dir.FullName + "/" + pdt + ".pdt", Encoding.UTF8)) {
var src = pdtreader.ReadToEnd(); var src = pdtreader.ReadToEnd();
Root = new SkinInterpreter(src, null).Interpret(); Root = new SkinInterpreter(src, null).Interpret();
/*#pragma warning disable CS0612
c = PdtReader.Read<CompiledSkin>(src);
#pragma warning restore CS0612*/
// c.PreEval(new EvalImpl());
} }
} }
} }
#region Obsolete
#if false
[Obsolete]
public class CompiledSkin : Element { }
[Obsolete]
[Binder(typeof(ElementBinder))]
public class Element {
[ElementList]
public Dictionary<SkinSelectors, Element> elements
= new Dictionary<SkinSelectors, Element>();
[ComponentList]
public List<string> components
= new List<string>();
[PropertyList]
public Dictionary<string, Expression> properties
= new Dictionary<string, Expression>();
public bool IsDynamic {
get;
private set;
}
public void PreEval(IEvaluator etor, byte depth = 1) {
IsDynamic = false;
foreach (var e in properties.Values) {
e.PreEval(etor, depth);
if (e.IsDynamic)
IsDynamic = true;
}
foreach (var e in elements.Values) {
e.PreEval(etor, depth);
if (e.IsDynamic)
IsDynamic = true;
}
}
}
[Obsolete]
public class ElementBinder : EmptyBinder {
public override object ChangeType(object value, Type type, CultureInfo culture) {
if (value is string) {
if (type == typeof(SkinSelectors)) {
return new SkinSelectors((string)value);
}
}
return base.ChangeType(value, type, culture);
}
}
[Obsolete]
public interface IConstructable {
void Load(object data, IEvaluator etor);
}
#endif
#endregion
public class PdtSkin : SkinElement { } public class PdtSkin : SkinElement { }
[Binder(typeof(SkinElementBinder))] [Binder(typeof(SkinElementBinder))]

View File

@@ -1,163 +0,0 @@
using Cryville.Common.Pdt;
using Cryville.Crtr.Components;
using Cryville.Crtr.Event;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Cryville.Crtr {
#if false
[Obsolete]
public class SkinManager {
readonly CompiledSkin skin;
readonly Dictionary<Element, Transform> matchedStatic
= new Dictionary<Element, Transform>();
readonly Dictionary<Element, Transform> matchedDynamic
= new Dictionary<Element, Transform>();
public SkinManager(CompiledSkin _skin) {
skin = _skin;
}
public void MatchStatic(Evaluator etor, ContainerState context) {
matchedStatic.Clear();
MatchStatic(skin, context, context.Handler.gogroup);
foreach (var m in matchedStatic) {
var el = m.Key;
var obj = m.Value;
foreach (var c in el.components) {
obj.gameObject.AddComponent(GetComponentByName(c));
}
foreach (var p in el.properties) {
ParseProperty(obj, p.Key, p.Value, context, etor);
}
}
}
void MatchStatic(Element rel, ContainerState context, Transform anchor = null) {
matchedStatic.Add(rel, anchor);
foreach (var r in rel.elements) {
var new_anchor = r.Key.MatchStatic(context, anchor);
if (new_anchor != null) {
MatchStatic(r.Value, context, new_anchor);
}
}
}
public void MatchDynamic(Evaluator etor, ContainerState context) {
UnityEngine.Profiling.Profiler.BeginSample("SkinManager.MatchDynamic()");
matchedDynamic.Clear();
MatchDynamic(skin, context, context.Handler.gogroup);
foreach (var m in matchedDynamic) {
var el = m.Key;
var obj = m.Value;
/*foreach (var c in el.components) {
if (obj.gameObject.GetComponent(GetComponentByName(c)) == null)
obj.gameObject.AddComponent(GetComponentByName(c));
}*/
foreach (var p in el.properties) {
if (!p.Value.IsDynamic) continue;
ParseProperty(obj, p.Key, p.Value, context, etor);
}
}
UnityEngine.Profiling.Profiler.EndSample();
}
void MatchDynamic(Element rel, ContainerState context, Transform anchor = null) {
matchedDynamic.Add(rel, anchor);
foreach (var r in rel.elements) {
Transform new_anchor;
/*if (r.Value.IsDynamic) {
new_anchor = r.Key.MatchDynamic(
context, r.Value, null, anchor
);
}
else {*/
if (!matchedStatic.ContainsKey(r.Value)) continue;
if (!r.Key.IsUpdatable(context)) continue;
new_anchor = r.Key.MatchDynamic(
context, r.Value, matchedStatic[r.Value], anchor
);
//}
if (new_anchor != null) {
MatchDynamic(r.Value, context, new_anchor);
}
}
}
void ParseProperty(Transform obj, string key, Expression value, ContainerState context, Evaluator etor) {
etor.Context = new EvaluatorContext() {
// Extra = context.judge.GetScoreStrings(),
State = context,
Transform = obj,
};
/*var keytuple = key.Split('#');
int matid = 0;*/
switch (key) {
/*case "tex":
if (int.TryParse(keytuple[1], out matid) || keytuple.Length == 1) {
var mat = obj.GetComponent<Renderer>().materials[matid];
var frame = ChartPlayer.frames[value.Eval<string>(etor)];
var tex = frame.Texture;
if (keytuple.Length == 2) mat.mainTexture = tex;
else mat.SetTexture(keytuple[2], tex);
}
else throw new ArgumentException(); // TODO
break;*/
/*case "shader":
if (int.TryParse(keytuple[1], out matid) || keytuple.Length == 1) {
var mat = obj.GetComponent<Renderer>().materials[matid];
// TODO mat.shader = value.Eval<string>(etor);
}
else throw new ArgumentException(); // TODO
break;*/
case "pos":
obj.localPosition = value.Eval<Vector3>(etor);
break;
case "rot":
obj.localRotation = Quaternion.Euler(value.Eval<Vector3>(etor));
break;
case "scale":
var s = value.Eval<Vector3>(etor);
if (s.z == 0) s.z = 1;
obj.localScale = s;
break;
default:
var cp = key.Split('.');
if (cp.Length == 2) {
var ctype = GetComponentByName(cp[0]);
var comp = (SkinComponent)obj.GetComponent(ctype);
if (!comp.Properties.ContainsKey(cp[1]))
throw new ArgumentException(string.Format("Property {0}.{1} not found", cp[0], cp[1]));
var prop = comp.Properties[cp[1]];
/*MemberInfo[] mi = ctype.GetMember(cp[1]);
for (var i = 2; i < cp.Length; i++) {
prop = ReflectionHelper.GetValue(mi[0], prop);
ctype = prop.GetType();
mi = ctype.GetMember(cp[i]);
if (mi.Length != 1)
throw new ArgumentException(); // TODO
}
ReflectionHelper.SetValue(mi[0], prop, etor.Cast(
ReflectionHelper.GetMemberType(mi[0]),
value.Eval(etor)
));*/
var r = value.Eval(etor);
prop.Set(etor.Cast(prop.Type, r));
}
else
throw new NotImplementedException("Unknown property " + key);
break;
}
}
static readonly char[] nssep = new char[]{':'};
Type GetComponentByName(string name) {
var nstuple = name.Split(nssep, 2);
var ns = nssep.Length == 2 ? nstuple[0] : "generic";
name = nssep.Length == 2 ? nstuple[1] : nstuple[0];
if (ns == "generic")
return GenericResources.Components[name];
throw new ArgumentException(); // TODO
}
}
#endif
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 1b05e0ef6592fe349b3906653bdbdb4e
timeCreated: 1617841955
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -7,119 +7,6 @@ using System.Linq;
using UnityEngine; using UnityEngine;
namespace Cryville.Crtr { namespace Cryville.Crtr {
#if false
[Obsolete]
public class SkinSelectors {
static readonly char[] sep = new char[]{
'[', ' ', '$', '#', '*', '@', '.'
};
readonly SkinSelector[] selectors;
readonly string[] annotations;
public readonly static SkinSelectors None = new SkinSelectors("");
public SkinSelectors(string exp) {
exp = exp.Trim();
var r = new List<SkinSelector>();
var annos = new List<string>();
int i = 0;
int eos = exp.Length - 1;
while (i <= eos) {
while (exp[i] == ' ') i++;
char sc = exp[i];
int ep;
switch (sc) {
case '[':
ep = exp.IndexOf(']', i + 1);
if (ep == -1) throw new ArgumentException(); // TODO
r.Add(new SkinSelector.ElementProperty(exp.Substring(i, ep - i + 1)));
i = ep + 1;
break;
case '.':
if (exp[i + 1] == '.') {
ep = exp.IndexOfAny(sep, i + 2);
if (ep == -1) ep = eos + 1;
r.Add(new SkinSelector.ElementState(exp.Substring(i, ep - i)));
}
else {
ep = exp.IndexOfAny(sep, i + 1);
if (ep == -1) ep = eos + 1;
r.Add(new SkinSelector.ElementAnchor(exp.Substring(i, ep - i)));
}
i = ep;
break;
case '$':
ep = exp.IndexOfAny(sep, i + 1);
if (ep == -1) ep = eos + 1;
r.Add(new SkinSelector.CreateObject(exp.Substring(i, ep - i)));
i = ep;
break;
case '@':
ep = exp.IndexOfAny(sep, i + 1);
if (ep == -1) ep = eos + 1;
annos.Add(exp.Substring(i, ep - i));
i = ep;
break;
default:
ep = exp.IndexOfAny(sep, i);
if (ep == -1) ep = eos + 1;
if (i == ep)
throw new ArgumentException(); // TODO
r.Add(new SkinSelector.ElementType(exp.Substring(i, ep - i)));
i = ep;
break;
}
// throw new ArgumentException();
}
selectors = r.ToArray();
annotations = annos.ToArray();
}
public override string ToString() {
if (selectors.Length == 0) return "";
bool flag = false;
string r = "";
foreach (var a in annotations) {
if (flag) r += " " + a;
else { r += a; flag = true; }
}
foreach (var s in selectors) {
if (flag) r += " " + s.ToString();
else { r += s.ToString(); flag = true; }
}
return r;
}
public Transform MatchStatic(ContainerState h, Transform anchor = null) {
foreach (var s in selectors) {
anchor = s.Match(h, anchor);
if (anchor == null) return null;
}
return anchor;
}
public bool IsUpdatable(ContainerState h) {
foreach (var s in selectors)
if (!s.IsUpdatable(h)) return false;
return true;
}
[Obsolete]
public Transform MatchDynamic(ContainerState h, Element e, Transform old_target, Transform anchor = null) {
if (!e.IsDynamic) return null;
foreach (var s in selectors) {
anchor = s.Match(h, anchor, old_target);
if (anchor == null) return null;
}
return anchor;
}
public Transform MatchDynamic(ContainerState h, SkinElement e, Transform old_target, Transform anchor = null) {
if (!e.IsDynamic) return null;
foreach (var s in selectors) {
anchor = s.Match(h, anchor, old_target);
if (anchor == null) return null;
}
return anchor;
}
}
#endif
public class SkinSelectors { public class SkinSelectors {
readonly SkinSelector[] selectors; readonly SkinSelector[] selectors;
readonly string[] annotations; readonly string[] annotations;
@@ -170,17 +57,6 @@ namespace Cryville.Crtr {
} }
public abstract class SkinSelector { public abstract class SkinSelector {
#if false
[Obsolete]
public string Expression {
get;
private set;
}
[Obsolete]
protected SkinSelector(string exp) {
Expression = exp;
}
#endif
protected SkinSelector() { } protected SkinSelector() { }
public abstract bool IsStatic { public abstract bool IsStatic {
get; get;
@@ -192,8 +68,6 @@ namespace Cryville.Crtr {
} }
public class CreateObject : SkinSelector { public class CreateObject : SkinSelector {
public CreateObject() { } public CreateObject() { }
//[Obsolete]
//public CreateObject(string exp) : base(exp) { }
public override bool IsStatic { public override bool IsStatic {
get { return true; } get { return true; }
} }
@@ -208,25 +82,6 @@ namespace Cryville.Crtr {
return obj.transform; return obj.transform;
} }
} }
#if false
[Obsolete]
public class ElementAnchor : SkinSelector {
public ElementAnchor(string exp) : base(exp) {
AnchorName = Expression.Substring(1);
}
public override bool IsStatic {
get { return true; }
}
public string AnchorName { get; private set; }
public override Transform Match(ContainerState h, Transform a, Transform ot = null) {
return h.Handler.Anchors[AnchorName].Transform;
}
public override bool IsUpdatable(ContainerState h) {
return h.Handler.Anchors[AnchorName].Opened;
}
}
#endif
public class Anchor : SkinSelector { public class Anchor : SkinSelector {
public string Name { get; private set; } public string Name { get; private set; }
public Anchor(string name) { public Anchor(string name) {
@@ -243,61 +98,6 @@ namespace Cryville.Crtr {
return h.Handler.Anchors[Name].Opened; return h.Handler.Anchors[Name].Opened;
} }
} }
#if false
[Obsolete]
public class ElementProperty : SkinSelector {
readonly bool notFlag;
readonly string prop;
readonly string value;
// Expression exp;
public ElementProperty(string exp) : base(exp) {
if (exp.Length <= 2) throw new ArgumentException(); // TODO
char sc = exp[0];
char ec = exp[exp.Length - 1];
if (sc != '[') throw new ArgumentException(); // TODO
if (ec != ']') throw new ArgumentException(); // TODO
var pexp = exp.Substring(1, exp.Length - 2);
var m = Regex.Match(pexp, @"^(\!?)(.*?)(?(=)=(.*))$");
if (!m.Success) throw new ArgumentException(); // TODO
notFlag = m.Groups[1].Length != 0;
prop = m.Groups[2].Value;
value = m.Groups[3].Value;
// TODO exp = new Expression(m.Groups[3]);
}
public override bool IsStatic {
get { throw new NotImplementedException(); }
}
public override Transform Match(ContainerState h, Transform a, Transform ot = null) {
return (MatchPropertyInternal(h, a) ^ notFlag) ? a : null;
}
bool MatchPropertyInternal(ContainerState h, Transform a) {
/*if (prop[0] == '$') {
MotionValue v = h.GetRawValue(prop.Substring(1));
return MatchValueInternal(v, value);
}
else {*/
return MatchValueInternal(h.Container.Properties[prop](), value);
//}
}
bool MatchValueInternal(object obj, string cond) {
if (obj is bool)
return bool.Equals(obj, true);
if (cond == "odd") {
if (obj is float)
return (float)obj % 2 == 1;
}
if (cond == "even") {
if (obj is float)
return (float)obj % 2 == 0;
}
if (cond == "mid") {
return false; // TODO
}
return false; // TODO
//throw new ArgumentException(); // TODO
}
}
#endif
public class Property : SkinSelector { public class Property : SkinSelector {
readonly PdtExpression _exp; readonly PdtExpression _exp;
readonly PdtOperator _op; readonly PdtOperator _op;
@@ -319,18 +119,6 @@ namespace Cryville.Crtr {
return _flag ? a : null; return _flag ? a : null;
} }
} }
#if false
[Obsolete]
public class ElementState : SkinSelector {
public ElementState(string exp) : base(exp) { }
public override bool IsStatic {
get { return false; }
}
public override Transform Match(ContainerState h, Transform a, Transform ot = null) {
return null; // TODO
}
}
#endif
public class State : SkinSelector { public class State : SkinSelector {
public State(string state) { } public State(string state) { }
public override bool IsStatic { public override bool IsStatic {

View File

@@ -1,10 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine;
using Cryville.Common;
using Cryville.Crtr.Components;
using Cryville.Crtr.Event;
namespace Cryville.Crtr { namespace Cryville.Crtr {
public class StampedEvent : IComparable<StampedEvent> { public class StampedEvent : IComparable<StampedEvent> {
@@ -81,11 +77,6 @@ namespace Cryville.Crtr {
if (u != 0) return u; if (u != 0) return u;
u = cmpExtra(other); u = cmpExtra(other);
if (u != 0) return u; if (u != 0) return u;
/*if (this.Event != null && other.Event != null)
if (table.ContainsKey(this.Event) && table.ContainsKey(other.Event)) {
u = table[this.Event].Depth.CompareTo(table[other.Event].Depth);
if (u != 0) return u;
}*/
return GetHashCode().CompareTo(other.GetHashCode()); return GetHashCode().CompareTo(other.GetHashCode());
} }

View File

@@ -14,8 +14,6 @@ namespace Cryville.Crtr {
chart = c; chart = c;
events = evs; events = evs;
EventId = 0; EventId = 0;
/*float leadin = chart.BeatPosition;
Time = leadin * 60 / (float)c.sigs[0].tempo;*/
Time = 0; Time = 0;
} }
@@ -55,7 +53,6 @@ namespace Cryville.Crtr {
breakflag = false; breakflag = false;
ForwardOnceToTime(Time, callback); ForwardOnceToTime(Time, callback);
while (Time < toTime) { while (Time < toTime) {
// if (Time == toTime) breakflag = true;
ForwardOnceToTime(toTime, callback); ForwardOnceToTime(toTime, callback);
if (breakflag) break; if (breakflag) break;
} }
@@ -77,141 +74,4 @@ namespace Cryville.Crtr {
public abstract void ForwardOnceToTime(float toTime, Action<T> callback = null); public abstract void ForwardOnceToTime(float toTime, Action<T> callback = null);
} }
/*public abstract class ChartEventStateBase : StateBase<Chart.Event> {
public float Beat;
public float Tempo;
public bool Visible = false;
/*public Vector2 Point = Vector2.zero;
public Vector2 Point2 = Vector2.zero;
public Vector2 EndPoint = Vector2.zero;
public Chart.Rotation Direction = Chart.Rotation.Zero;
public Chart.Rotation Rotation = Chart.Rotation.Zero;
public PointMotion PointMotion = null;
public PointMotion Point2Motion = null;
public PointMotion EndPointMotion = null;
public RotationMotion DirectionMotion = null;
public RotationMotion RotationMotion = null;
Chart.Point pevp = Chart.Point.Zero;
Chart.Point pevp2 = Chart.Point.Zero;
Chart.Point pevep = Chart.Point.Zero;
Chart.Rotation pevd = Chart.Rotation.Zero;
Chart.Rotation pevr = Chart.Rotation.Zero;*
protected List<Chart.Motion> PlayingMotions = new List<Chart.Motion>();
protected Dictionary<string, MotionValue> Values = new Dictionary<string, MotionValue>();
bool breakflag = false;
public ChartEventStateBase(Chart c, IEnumerable<Chart.Event> evs) : base(c, evs.ToList()) {
float leadin = chart.leadin;
Tempo = (float)c.signs[0].tempo;
Beat = -leadin;
foreach (var ev in evs)
if (ev.duration > 0)
events.Add(ev.ReleaseEvent);
events.Sort((a, b) => a.BeatPosition.CompareTo(b.BeatPosition));
Values.Add("dir", new MotionValue(typeof(Vec1), 3));
Values.Add("rot", new MotionValue(typeof(Vec1), 3));
Values.Add("pdirz", new MotionValue(typeof(Vec1), 1));
Values.Add("protz", new MotionValue(typeof(Vec1), 1));
Values.Add("pivot", new MotionValue(typeof(Vec2), 2));
Values.Add("pt", new MotionValue(typeof(Vec2), 2));
Values.Add("pt2", new MotionValue(typeof(Vec2), 2));
Values.Add("visible", new MotionValue(typeof(Vec1), 1));
Values.Add("sv", new MotionValue(typeof(Vec1), 1));
Values.Add("tint", new MotionValue(typeof(Vec1), 3));
Values.Add("corner", new MotionValue(typeof(Vec1), 3));
Values.Add("ctrl", new MotionValue(typeof(Vec2), 2));
Values.Add("ctrlz", new MotionValue(typeof(Vec1), 1));
}
public override sealed void ForwardOnceToTime(float toTime, Action<Chart.Event> callback = null) {
float toBeat = Beat + (toTime - Time) * Tempo / 60f;
if (EventId >= events.Count)
goto return_ahead;
float ebeat = events[EventId].BeatPosition;
float etime = (ebeat - Beat) / Tempo * 60f + Time;
if (etime > toTime)
goto return_ahead;
var bunch = GetEventBunch();
Time = etime;
Beat = ebeat;
bool flag = false;
foreach (var ev in bunch) {
Handle(ev);
if (callback != null && ev.Priority >= 0) {
callback(ev);
flag = true;
}
}
if (callback != null && !flag) callback(bunch.First());
return;
return_ahead:
Time = toTime;
Beat = toBeat;
// UpdateMotions();
if (callback != null) callback(null);
}
protected virtual void Handle(Chart.Event ev) {
if (ev is Chart.Motion) {
var tev = (Chart.Motion)ev;
tev._initValues = Values;
PlayingMotions.Add(tev);
// UpdateMotions();
}
else if (ev is Chart.InstantEvent) {
var tev = (Chart.InstantEvent)ev;
if (tev.IsRelease) {
var nev = tev.Original;
if (nev is Chart.Motion) {
var tnev = (Chart.Motion)nev;
PlayingMotions.Remove(tnev);
}
}
}
EventId++;
}
/*void UpdateMotions() {
foreach (var m in PlayingMotions) {
var mv = m[Time];
}
/*if (PointMotion != null)
Point = PointMotion.Lerp(Time);
if (EndPointMotion != null)
EndPoint = EndPointMotion.Lerp(Time);
if (Point2Motion != null)
Point2 = Point2Motion.Lerp(Time);
if (DirectionMotion != null)
Direction = DirectionMotion.Lerp(Time);
if (RotationMotion != null)
Rotation = RotationMotion.Lerp(Time);
}*
IOrderedEnumerable<Chart.Event> GetEventBunch() {
float cbeat = events[EventId].BeatPosition;
int b = EventId;
while (events[b].BeatPosition == cbeat) {
b--;
if (b == -1) break;
}
int a = EventId;
while (events[a].BeatPosition == cbeat) {
a++;
if (a == events.Count) break;
}
return events.GetRange(b + 1, a - b - 1).OrderBy(ev => ev.Priority);
}
}*/
} }

View File

@@ -5,12 +5,8 @@ using Logger = Cryville.Common.Logger;
namespace Cryville.Crtr { namespace Cryville.Crtr {
class TrackHandler : ContainerHandler { class TrackHandler : ContainerHandler {
// private StampedState cs;
readonly GroupHandler gh; readonly GroupHandler gh;
readonly Chart.Track track; readonly Chart.Track track;
// List<GameObject> trackPool = new List<GameObject>();
// Dictionary<StampedEvent, GameObject> notePool = new Dictionary<StampedEvent, GameObject>();
public TrackHandler(GroupHandler gh, Chart.Track _track) : base() { public TrackHandler(GroupHandler gh, Chart.Track _track) : base() {
track = _track; track = _track;
@@ -23,79 +19,6 @@ namespace Cryville.Crtr {
} }
} }
/*EventPrehandler ph;
List<StampedEvent> sevs = new List<StampedEvent>();
public void StartPrehandler(EventPrehandler parent) {
List<Chart.Event> appevs = new List<Chart.Event>();
/*foreach (Chart.Note ev in track.notes) {
if (ev.duration > 0) {
for (float b = 0f; b < ev.duration; b += ev.judgeinterval) {
appevs.Add(new Chart.Track.InternalJudgement() { beat = ev.beat, BeatOffset = b, Parent = ev });
}
}
}
ph = new EventPrehandler(
parent.chart,
track.motions.Cast<Chart.Event>(),
parent
);
}
public void PrehandleToTime(float toTime) {
ph.ForwardToTime(toTime, ev => { });
/*phs.ForwardToTime(toTime, ev => {
if (ev is Chart.Note) {
var tev = (Chart.Note)ev;
sevs.Add(new StampedEvent.Judge() {
Time = phs.Time - judge * tev.tol,
EndTime = phs.Time + judge * tev.tol,
Event = tev,
Type = tev.wipe ? JudgementType.Held : JudgementType.Attack,
JudgeArea = new Area() {
Point1 = phs.Point,
Point2 = phs.Point + new Chart.Point(0f, 0.1f, 0f, 0.1f).ToRelative(hitRect),
Type = AreaType.Circle
}
});
}
else if (ev is Chart.InternalJudgement) {
var tev = (Chart.InternalJudgement)ev;
sevs.Add(new StampedEvent.Judge() {
Time = phs.Time - judge * tev.Parent.tol,
EndTime = phs.Time + judge * tev.Parent.tol,
Event = tev,
Type = JudgementType.Held,
JudgeArea = new Area() {
Point1 = phs.Point,
Point2 = phs.Point + new Chart.Point(0f, 0.1f, 0f, 0.1f).ToRelative(hitRect),
Type = AreaType.Circle
}
});
}
});
}
public void EndPrehandler(StampedState parent) {
sevs = ph.Result;
cs = new StampedState(gh.ch.chart, sevs, parent);
}*/
/*List<StampedEvent.Judge> judgements = new List<StampedEvent.Judge>();
public void SendInput(int id, TouchPhase phase, Vector2 jpos) {
for (int i = judgements.Count - 1; i >= 0; i--) {
if (judgements[i].JudgeArea.Contains(jpos)) {
if (phase == TouchPhase.Began && judgements[i].Type == JudgementType.Attack) {
gh.ch.ReportJudge(true);
judgements.RemoveAt(i);
}
else if ((phase == TouchPhase.Stationary || phase == TouchPhase.Moved) && judgements[i].Type == JudgementType.Held) {
gh.ch.ReportJudge(true);
judgements.RemoveAt(i);
}
}
}
}*/
public override void Init() { public override void Init() {
base.Init(); base.Init();
sgos = gogroup.GetComponentsInChildren<SectionalGameObject>(); sgos = gogroup.GetComponentsInChildren<SectionalGameObject>();
@@ -128,13 +51,11 @@ namespace Cryville.Crtr {
} }
} }
// readonly SectionalGameObject trackObj;
Vector3 cpt; // Current point Vector3 cpt; // Current point
Vector3 ppt = Vector3.zero; // Previous point Vector3 ppt = Vector3.zero; // Previous point
Vector3 pwp = Vector3.zero; // Previous world point Vector3 pwp = Vector3.zero; // Previous world point
float ptime; // Previous time float ptime; // Previous time
float length; float length;
// readonly GameObject obj;
public override void Update(ContainerState s, StampedEvent ev) { public override void Update(ContainerState s, StampedEvent ev) {
base.Update(s, ev); base.Update(s, ev);
@@ -142,17 +63,6 @@ namespace Cryville.Crtr {
var tpt = s.ScreenPoint; var tpt = s.ScreenPoint;
var tsv = s.ScrollVelocity; var tsv = s.ScrollVelocity;
/*Vector3 p = (Vector3)tpt - cpt;
p.z = prevz + (ts.Time - prevtime) * Main.sv * tsv;
Quaternion rotq = Quaternion.Euler(ts.Direction);
var np = prevwp + rotq * (p - prevp);
prevp = p;
prevz = p.z;
p = np;
prevwp = p;
prevtime = ts.Time;*/
Vector3 dpt = (Vector3)tpt - ppt; // Delta 2D point Vector3 dpt = (Vector3)tpt - ppt; // Delta 2D point
dpt.z = (s.Time - ptime) * ChartPlayer.sv * tsv; // Delta Z dpt.z = (s.Time - ptime) * ChartPlayer.sv * tsv; // Delta Z
Quaternion rotq = Quaternion.Euler(s.Direction); // Rotation Quaternion rotq = Quaternion.Euler(s.Direction); // Rotation
@@ -171,7 +81,6 @@ namespace Cryville.Crtr {
ptime = s.Time; ptime = s.Time;
if (!gogroup || s.CloneType == 3) return; if (!gogroup || s.CloneType == 3) return;
// sgos = gogroup.GetComponentsInChildren<PolygonSGO>();
var p = GetCurrentWorldPoint(); var p = GetCurrentWorldPoint();
foreach (var i in sgos) foreach (var i in sgos)
i.AppendPoint(p, s.QuatDir); i.AppendPoint(p, s.QuatDir);
@@ -200,13 +109,6 @@ namespace Cryville.Crtr {
CloseAnchor("tail"); CloseAnchor("tail");
if (s.CloneType == 0 || s.CloneType == 2) { if (s.CloneType == 0 || s.CloneType == 2) {
EndUpdatePosition(ts); EndUpdatePosition(ts);
/*if (trackObj != null) {
trackObj.AppendPoint(p);
trackObj.Seal();
}*/
// sgos = gogroup.GetComponentsInChildren<PolygonSGO>();
var p = GetCurrentWorldPoint(); var p = GetCurrentWorldPoint();
foreach (var i in sgos) { foreach (var i in sgos) {
i.AppendPoint(p, s.QuatDir); i.AppendPoint(p, s.QuatDir);
@@ -222,13 +124,6 @@ namespace Cryville.Crtr {
void EndUpdatePosition(ContainerState s) { void EndUpdatePosition(ContainerState s) {
var tpt = s.ScreenPoint; var tpt = s.ScreenPoint;
var tsv = s.ScrollVelocity; var tsv = s.ScrollVelocity;
/*float endtime = ts.Time + Main.fogDist;
Vector3 ep;
ep = (Vector3)tpt - (Vector3)cpt;
ep.z = (endtime - cs.Time) * Main.sv * tsv;
Quaternion erotq = Quaternion.Euler(ts.Direction);
ep = pwp + erotq * (ep - ppt);*/
Vector3 dpt = (Vector3)tpt - ppt; Vector3 dpt = (Vector3)tpt - ppt;
dpt.z = (s.Time - ptime) * ChartPlayer.sv * tsv; dpt.z = (s.Time - ptime) * ChartPlayer.sv * tsv;