From 20f4de383207697cbae373efdbac447d89529cd6 Mon Sep 17 00:00:00 2001 From: PopSlime Date: Fri, 11 Nov 2022 00:36:16 +0800 Subject: [PATCH] Implement int_map function. Remove "long operator" concept. --- Assets/Cryville/Crtr/PdtEvaluator.cs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Assets/Cryville/Crtr/PdtEvaluator.cs b/Assets/Cryville/Crtr/PdtEvaluator.cs index d23e159..b93b508 100644 --- a/Assets/Cryville/Crtr/PdtEvaluator.cs +++ b/Assets/Cryville/Crtr/PdtEvaluator.cs @@ -7,7 +7,6 @@ using UnityEngine; namespace Cryville.Crtr { public class PdtEvaluator : PdtEvaluatorBase { static readonly Dictionary _shortops = new Dictionary(); - static readonly Dictionary _longops = new Dictionary(); readonly Dictionary _ctxops = new Dictionary(); readonly byte[] _numbuf = new byte[4]; @@ -63,6 +62,7 @@ namespace Cryville.Crtr { return result; } static readonly int _op_sep = IdentifierManager.SharedInstance.Request(","); + static readonly int _func_int_map = IdentifierManager.SharedInstance.Request("int_map"); protected override PdtOperator GetOperator(PdtOperatorSignature sig) { PdtOperator result; if (_shortops.TryGetValue(sig, out result)) { @@ -73,7 +73,9 @@ namespace Cryville.Crtr { _shortops.Add(new PdtOperatorSignature(_op_sep, sig.ParamCount), result); return result; } - else if (_longops.TryGetValue(sig.Name, out result)) { + else if (sig.Name == _func_int_map) { + result = new func_int_map(sig.ParamCount); + _shortops.Add(new PdtOperatorSignature(_func_int_map, sig.ParamCount), result); return result; } else if (_ctxops.TryGetValue(sig.Name, out result)) { @@ -145,8 +147,8 @@ namespace Cryville.Crtr { _shortops.Add(new PdtOperatorSignature("!", 1), new op_not_1()); - _longops.Add(IdentifierManager.SharedInstance.Request("frame_seq"), new func_frame_seq()); - _longops.Add(IdentifierManager.SharedInstance.Request("in_area"), new func_in_area()); + _shortops.Add(new PdtOperatorSignature("frame_seq", 3), new func_frame_seq()); + _shortops.Add(new PdtOperatorSignature("in_area", 1), new func_in_area()); } #region Operators #pragma warning disable IDE1006 @@ -411,6 +413,21 @@ namespace Cryville.Crtr { } } } + class func_int_map : PdtOperator { + public func_int_map(int pc) : base(pc) { + if (pc < 4) throw new ArgumentOutOfRangeException("Too few parameters for int_map"); + } + protected override unsafe void Execute() { + var value = GetOperand(0).AsNumber(); + var offset = GetOperand(1).AsNumber(); + var step = GetOperand(2).AsNumber(); + var index = (int)((value - offset) / step); + if (index < 0 || index >= LoadedOperandCount - 3) index = 0; + var hit = GetOperand(index + 3); + var ret = GetReturnFrame(hit.Type, hit.Length); + hit.CopyTo(ret); + } + } unsafe static class oputil { public static float AsNumber(PropSrc src) { if (src == null)