Beispiel #1
0
 internal static bool OnMenuAction(string action, Query query, Result result, Result menu, ActionContext e)
 {
     lock (s_PluginLock) {
         //由于Wox实现上的缺陷,这里根据menu的Title与SubTitle在菜单列表里查找真正的菜单项再调action
         int ix = s_ContextMenus.IndexOf(menu);
         if (ix < 0)
         {
             s_Context.API.ShowMsg("Can't find menu " + menu.Title, menu.SubTitle, menu.IcoPath);
             return(false);
         }
         if (s_ContextMenus[ix].ContextData != menu.ContextData || s_ContextMenus[ix].Action != menu.Action)
         {
             return(s_ContextMenus[ix].Action(e));
         }
         object r = BatchScript.Call(action, CalculatorValue.FromObject(query), CalculatorValue.FromObject(result), CalculatorValue.FromObject(menu), CalculatorValue.FromObject(e));
         ShowLog("OnMenuAction");
         if (s_NeedReload)
         {
             s_NeedReload = false;
             ReloadDsl();
         }
         if (null != r)
         {
             bool ret = (bool)Convert.ChangeType(r, typeof(bool));
             return(ret);
         }
         else
         {
             return(false);
         }
     }
 }
Beispiel #2
0
            public void CreateBatches()
            {
                BatchScript batchScript = null;
                var         meshBuffer  = new List <CombineInstance>();
                var         vertexCount = 0;

                foreach (var r in batchedRenderers)
                {
                    var meshFilter = r.GetComponent <MeshFilter>();
                    if (meshFilter == null)
                    {
                        continue;                     // do nothing
                    }
                    var newMesh = meshFilter.sharedMesh;
                    if (newMesh == null)
                    {
                        continue;                  // do nothing
                    }
                    if (newMesh.subMeshCount > 1)
                    {
                        Debug.LogError("Cannot batch mesh with submeshes, not implemented!", r);
                        continue;
                    }

                    // do twice max
                    for (int i = 0; i < 2; i++)
                    {
                        if (batchScript == null)
                        {
                            batchScript = batcher.CreateBatchScript(sharedMaterial, layer);

                            meshBuffer.Clear();
                            vertexCount = 0;
                        }

                        var shouldAddToExistingBatch = (vertexCount == 0 || vertexCount + newMesh.vertexCount <= 65000);

                        if (!shouldAddToExistingBatch)
                        {
                            // full, so build first, then repeat
                            batches.Add(batchScript);
                            batchScript = null;
                            continue;
                        }

                        //TODO: submeshes
                        batchScript.AddBatchedRenderer(r);
                        batcher.batchLookup.Add(r, batchScript);
                        vertexCount += newMesh.vertexCount;

                        break;
                    }
                }

                if (vertexCount > 0)
                {
                    batches.Add(batchScript);
                    batchScript = null;
                }
            }
Beispiel #3
0
    public void Init(PluginInitContext context)
    {
        s_StartupThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
        s_Context         = context;
        var txtWriter = new StringWriter(s_LogBuilder);

        Console.SetOut(txtWriter);
        Console.SetError(txtWriter);
        using (var sw = new StreamWriter(s_LogFile, false)) {
            sw.WriteLine("Startup Thread {0}.", s_StartupThreadId);
            sw.Close();
        }
        BatchScript.Init();
        BatchScript.Register("context", new ExpressionFactoryHelper <ContextExp>());
        BatchScript.Register("api", new ExpressionFactoryHelper <ApiExp>());
        BatchScript.Register("metadata", new ExpressionFactoryHelper <MetadataExp>());
        BatchScript.Register("reloaddsl", new ExpressionFactoryHelper <ReloadDslExp>());
        BatchScript.Register("evaldsl", new ExpressionFactoryHelper <EvalDslExp>());
        BatchScript.Register("addresult", new ExpressionFactoryHelper <AddResultExp>());
        BatchScript.Register("addcontextmenu", new ExpressionFactoryHelper <AddContextMenuExp>());
        BatchScript.Register("keywordregistered", new ExpressionFactoryHelper <ActionKeywordRegisteredExp>());
        BatchScript.Register("clearkeywords", new ExpressionFactoryHelper <ClearActionKeywordsExp>());
        BatchScript.Register("addkeyword", new ExpressionFactoryHelper <AddActionKeywordExp>());
        BatchScript.Register("showcontextmenu", new ExpressionFactoryHelper <ShowContextMenuExp>());
        BatchScript.Register("everythingreset", new ExpressionFactoryHelper <EverythingResetExp>());
        BatchScript.Register("everythingsetdefault", new ExpressionFactoryHelper <EverythingSetDefaultExp>());
        BatchScript.Register("everythingmatchpath", new ExpressionFactoryHelper <EverythingMatchPathExp>());
        BatchScript.Register("everythingmatchcase", new ExpressionFactoryHelper <EverythingMatchCaseExp>());
        BatchScript.Register("everythingmatchwholeword", new ExpressionFactoryHelper <EverythingMatchWholeWordExp>());
        BatchScript.Register("everythingregex", new ExpressionFactoryHelper <EverythingRegexExp>());
        BatchScript.Register("everythingsort", new ExpressionFactoryHelper <EverythingSortExp>());
        BatchScript.Register("everythingsearch", new ExpressionFactoryHelper <EverythingSearchExp>());
        ReloadDsl();
    }
Beispiel #4
0
 internal static bool OnAction(string action, Query query, Result result, ActionContext e)
 {
     lock (s_PluginLock) {
         //由于Wox实现上的缺陷,这里根据result的Title与SubTitle在结果列表里查找真正的result项再调action
         int ix = s_Results.IndexOf(result);
         if (ix < 0)
         {
             s_Context.API.ShowMsg("Can't find result " + result.Title, result.SubTitle, result.IcoPath);
             return(false);
         }
         if (s_Results[ix].ContextData != result.ContextData || s_Results[ix].Action != result.Action)
         {
             return(s_Results[ix].Action(e));
         }
         var r = BatchScript.Call(action, CalculatorValue.FromObject(query), CalculatorValue.FromObject(result), CalculatorValue.FromObject(e));
         ShowLog("OnAction");
         if (s_NeedReload)
         {
             s_NeedReload = false;
             ReloadDsl();
         }
         if (r.IsBoolean)
         {
             bool ret = r.GetBool();
             return(ret);
         }
         else
         {
             return(false);
         }
     }
 }
Beispiel #5
0
        static void Main(string[] args)
        {
            int exitCode = 0;

            try {
                BatchScript.Init();
                var r     = DslExpression.CalculatorValue.NullObject;
                var vargs = BatchScript.NewCalculatorValueList();
                if (args.Length <= 0)
                {
                    r = BatchScript.Run(string.Empty, vargs);
                }
                else
                {
                    foreach (var arg in args)
                    {
                        vargs.Add(arg);
                    }
                    r = BatchScript.Run(args[0], vargs);
                }
                BatchScript.RecycleCalculatorValueList(vargs);
                if (!r.IsNullObject)
                {
                    exitCode = r.Get <int>();
                }
            } catch (Exception ex) {
                BatchScript.Log("exception:{0}\n{1}", ex.Message, ex.StackTrace);
                exitCode = -1;
            }
            Environment.Exit(exitCode);
        }
Beispiel #6
0
        private BatchScript CreateBatchScript(Material sharedMaterial, int layer)
        {
            var ret = BatchScript.Create(sharedMaterial, layer);

            ret.transform.SetParent(batchesContainer);
            ret.gameObject.name = $"Batch [{sharedMaterial.name}] Layer [{layer}";
            return(ret);
        }
Beispiel #7
0
 public List <Result> Query(Query query)
 {
     lock (s_PluginLock) {
         s_Results.Clear();
         BatchScript.Call("on_query", CalculatorValue.FromObject(query));
         ShowLog("Query");
         return(s_Results);
     }
 }
Beispiel #8
0
 public List <Result> LoadContextMenus(Result selectedResult)
 {
     lock (s_PluginLock) {
         s_ContextMenus.Clear();
         Query query = selectedResult.ContextData as Query;
         BatchScript.Call("on_context_menus", CalculatorValue.FromObject(query), CalculatorValue.FromObject(selectedResult));
         ShowLog("LoadContextMenus");
         return(s_ContextMenus);
     }
 }
Beispiel #9
0
 internal static void ReloadDsl()
 {
     lock (s_PluginLock) {
         string dslPath = Path.Combine(s_Context.CurrentPluginMetadata.PluginDirectory, "main.dsl");
         var    vargs   = BatchScript.NewCalculatorValueList();
         vargs.Add(s_Context.CurrentPluginMetadata.ID);
         vargs.Add(CalculatorValue.FromObject(s_Context.CurrentPluginMetadata));
         vargs.Add(CalculatorValue.FromObject(s_Context));
         BatchScript.Run(dslPath, vargs);
         BatchScript.RecycleCalculatorValueList(vargs);
         ShowLog("ReloadDsl");
     }
 }
Beispiel #10
0
    protected override CalculatorValue OnCalc(IList <CalculatorValue> operands)
    {
        CalculatorValue r = CalculatorValue.NullObject;

        if (operands.Count >= 1)
        {
            string code = operands[0].As <string>();
            var    args = BatchScript.NewCalculatorValueList();
            for (int i = 1; i < operands.Count; ++i)
            {
                var arg = operands[i];
                args.Add(arg);
            }
            var id = BatchScript.Eval(code, new string[] { "$query", "$result", "$actionContext" });
            if (null != id)
            {
                r = BatchScript.Call(id, args);
            }
            BatchScript.RecycleCalculatorValueList(args);
        }
        return(r);
    }