Beispiel #1
0
        public static State Create(TaskFactory creater, FSM fsm, State.StateAction nextState)
        {
            string over = "over" + index_.ToString();

            index_++;
            State state = new State();
            Task  task  = null;

            state.onStart += delegate {
                Debug.Log("task state on start...");
                task = creater();
                TaskManager.PushBack(task, delegate {
                    Debug.Log("task state of taskmanager push back...");
                    fsm.post(over);
                });
                Debug.Log("TaskManager run ....");
                TaskManager.Run(task);
            };

            state.onOver += delegate
            {
                task.isOver = delegate
                {
                    return(true);
                };
            };
            state.addAction(over, nextState);
            return(state);
        }
Beispiel #2
0
        public static TaskWait Create(float time, TaskShutdown shutdown)
        {
            TaskWait wait = new TaskWait(time);

            TaskManager.PushBack(wait, shutdown);
            return(wait);
        }
Beispiel #3
0
        public WebLoaderTask(string url)
        {
            pack_ = new WebPack(url);
            pack_.addField("a", "b");
            bool isOver = false;

            this.init = delegate {
                isOver   = false;
                Task web = WebTaskFactory.GetInstance().create(pack, delegate(string json) {
                    if (onSucceed != null)
                    {
                        T info = JsonDataHandler.reader <T>(json);
                        if (WebTimestamp.GetInstance() != null)
                        {
                            WebTimestamp.GetInstance().synchro(info.epoch);
                        }
                        onSucceed(info);
                    }
                }, delegate(string msg) {
                    if (onError != null)
                    {
                        onError(msg);
                    }
                });
                TaskManager.PushBack(web, delegate {
                    isOver = true;
                });
                this.isOver = delegate {
                    return(isOver);
                };
                TaskManager.Run(web);
            };
        }
Beispiel #4
0
 public static Task Logger(Task task, string taskName)
 {
                 #if DEBUG
     if (_instance == null)
     {
         GameObject go = new GameObject();
         go.name   = "TaskLogger";
         _instance = go.AddComponent <TaskLog>();
     }
     long begin = 0;
     TaskManager.PushFront(task, delegate() {
         //time_t t = time(null)
         begin = DateTime.Now.Ticks;
     });
     TaskManager.PushBack(task, delegate() {
         long all = DateTime.Now.Ticks - begin;
         if (_instance.dict_.ContainsKey(taskName))
         {
             _instance.dict_[taskName] += all;
         }
         else
         {
             _instance.dict_[taskName] = all;
         }
         //Debug.Log(taskName + ":" + all);
     });
                 #endif
     return(task);
 }
Beispiel #5
0
        private Task removeFacesTask()
        {
            int can_collapse_index = 0;

            TaskCircle tc = new TaskCircle();

            TaskManager.PushFront(tc, delegate {
                can_collapse_index = getCanCollapseVertexIndex();
            });
            Task task = new Task();

            task.init = delegate() {
                for (int i = 0; i < 200; ++i)
                {
                    collapse(vertices [can_collapse_index], vertices [can_collapse_index].collapse);
                    can_collapse_index = getCanCollapseVertexIndex();
                    if (can_collapse_index == -1)
                    {
                        break;
                    }
                }
            };
            TaskManager.PushBack(task, delegate {
                if (can_collapse_index == -1)
                {
                    tc.forceQuit();
                }
            });


            tc.push(task);
            return(tc);
        }
Beispiel #6
0
        private Task task_(string name, VoxelData[] datas, GeometryResult cb)
        {
            if (list_.Count == 0)
            {
                init();
            }

            VoxelProduct product = new VoxelProduct();

            begin_.setup(datas);

            TaskList tl = new TaskList();


            tl.push(begin_.task(product));
            for (int i = 0; i < list_.Count; ++i)
            {
                tl.push(list_[i].task(product));
            }

            TaskManager.PushBack(tl, delegate {
                VoxelGeometry geometry = new VoxelGeometry();
                geometry.draw(name, product, this.gameObject, this._material);;
                cb(geometry);
            });
            return(tl);
        }
Beispiel #7
0
        public Task buildTask(string name, VoxelStruct vs, GeometryResult cb)
        {
            VoxelGeometry.MeshData data = null;
            TaskPack tp = new TaskPack(delegate(){
                vs.arrange();
                string md5 = VoxelFormater.GetMd5(vs);
                data       = this.LoadFromFile(GetKey(md5));
                if (data == null)
                {
                    return(buildData(vs, delegate(VoxelGeometry.MeshData result) {
                        data = result;
//						Debug.Log(md5);

                        this.SaveToFile(GetKey(md5), data);
                    }));
                }
                return(new Task());
            });


            TaskManager.PushBack(tp, delegate {
                if (this.gameObject.GetComponent <VoxelMesh>() == null)
                {
                    this.gameObject.AddComponent <VoxelMesh>();
                }
                VoxelMesh mesh = VoxelGeometry.Draw(name, data, this.gameObject, this._material);
                mesh.vs        = vs;
                cb(mesh);
            });
            return(tp);
        }
Beispiel #8
0
        private Task hide()
        {
            TweenTask task = new TweenTask(
                delegate {
                TweenGroupAlpha alpha = TweenGroupAlpha.Begin(this.gameObject, 0.15f, 0.0f);
                return(alpha);
            }
                );



            TaskManager.PushBack(task, delegate {
                if (_cg != null)
                {
                    _cg.alpha = 0.0f;
                }
                //Debug.LogError("????");
                //	if(_evtSys != null) _evtSys.enabled = true;
                if (this != null && this.gameObject != null)
                {
                    this.gameObject.SetActive(false);
                }
            });
            return(task);
        }
        private Task _popTask(string text, VoxelHead.Emotions emotion)
        {
            if (String.IsNullOrEmpty(text))
            {
                return(new Task());
            }


            Task task = null;

            if (isPop_)
            {
                Task next = _pop.next(text);
                task = next;
            }
            else
            {
                isPop_ = true;
                task   = _pop.openTask(text);
            }


            TaskManager.PushFront(task, delegate {
                _head.talk = true;
            });

            TaskManager.PushBack(task, delegate {
                _head.talk    = false;
                _head.emotion = emotion;
            });
            return(task);
        }
Beispiel #10
0
 public void push(Task task)
 {
     TaskManager.PushBack(task, delegate {
         index_++;
         runTask();
     });
     other_.Add(task);
 }
        public Task closePopTask()
        {
            Task task = new Task();

            TaskManager.PushBack(task, delegate {
                _pop.close();
            });
            return(task);
        }
Beispiel #12
0
        public Task closeTask()
        {
            Task task = new Task();

            TaskManager.PushBack(task, delegate {
                this.transform.localScale = Vector3.zero;
            });
            return(task);
        }
Beispiel #13
0
        private Task run(string text)
        {
            Task task = setTextTask(text);

            TaskManager.PushFront(task, delegate {
                locked_ = true;
            });
            TaskManager.PushBack(task, delegate {
                locked_ = false;
            });
            return(task);
        }
Beispiel #14
0
        Task removeTask(int i)
        {
            Task task = new TweenTask(delegate {
                chars_[i].gameObject.transform.eulerAngles = new Vector3(0, 0, 0);
                return(TweenRotation.Begin(chars_[i].gameObject, 0.15f, Quaternion.Euler(new Vector3(270, 0, 0))));
            });

            TaskManager.PushBack(task, delegate {
                chars_[i].gameObject.SetActive(false);
            });

            return(task);
        }
        /*
         * public Task popTalk (Sentence[] sentences)
         * {
         *
         *
         *      _face.doEyebrowAction (VoxelFace.EyebrowAction.Sorry);
         *      _face.doEyeAction (VoxelFace.EyeAction.Normal);
         *      TaskList tl = new TaskList ();
         *
         *      Task open = _board.openTask (sentences[0].talk);
         *
         *
         *      tl.push (open);
         *
         *      tl.push (new TaskWait(0.5f));
         *      for (int i = 1; i <sentences.Length; ++i) {
         *
         *              tl.push (new TaskWait(0.5f));
         *              tl.push (_board.next (sentences[i].talk));
         *
         *      }
         *      tl.push (new TaskWait(0.5f));
         *      tl.push (_board.closeTask ());
         *      return tl;
         *
         *
         *
         * }
         */
        public Task comeInTask()
        {
            if (isOpen())
            {
                return(new Task());
            }
            Task task = _head.openTask();

            TaskManager.PushBack(task, delegate {
                isPop_ = false;
            });
            return(task);
        }
Beispiel #16
0
        private Task packTask(Task task)
        {
            Task  pack      = new Task();
            float allTime   = 0.0f;
            bool  isOver    = false;
            bool  isLoading = false;
            bool  isLoaded  = false;

            pack.init = delegate {
                allTime   = 0;
                isOver    = false;
                isLoading = false;
                isLoaded  = false;
                TaskManager.PushBack(task, delegate {
                    isOver = true;
                });
                TaskManager.Run(task);
            };
            pack.update = delegate(float d) {
                allTime += d;
                if (allTime > _wait && !isLoading)
                {
                    isLoading = true;
                    Task show = this.show();
                    TaskManager.PushBack(show, delegate {
                        //Debug.LogError("???");
                        isLoaded = true;
                    });
                    TaskManager.Run(show);
                }
            };


            pack.isOver = delegate {
                if (isOver)
                {
                    if (!isLoading)                    //Debug.LogError("error");
                    {
                        return(true);
                    }
                    if (isLoaded)                    //Debug.LogError("erro2r");
                    {
                        return(true);
                    }
                }
                return(false);
            };
            return(pack);
        }
Beispiel #17
0
        public Task openTask()
        {
            if (_text == ' ' || _fontColor == _bgColor)
            {
                Task task = new Task();
                TaskManager.PushBack(task, delegate { open(); });
                return(task);
            }
            TweenTask tt = new TweenTask(delegate {
                this.transform.localEulerAngles = new Vector3(0, 179, 0);
                return(TweenRotation.Begin(this.gameObject, 0.3f, Quaternion.Euler(new Vector3(0, 0, 0))));
            });

            return(tt);
        }
Beispiel #18
0
        private Task show()
        {
            TweenTask task = new TweenTask(
                delegate {
                this.gameObject.SetActive(true);
                TweenGroupAlpha alpha = TweenGroupAlpha.Begin(this.gameObject, 0.3f, 1.0f);
                return(alpha);
            }
                );

            TaskManager.PushBack(task, delegate {
                _cg.alpha = 1.0f;
            });
            return(task);
        }
Beispiel #19
0
        public Task buildData(VoxelStruct vs, MeshDataResult result)
        {
            VoxelProduct product = new VoxelProduct();
            TaskList     tl      = new TaskList();

            VoxelData[] datas = vs.datas.ToArray();
            tl.push(TaskLog.Logger(Build.Task(new VoxelData2Point(datas), product), "d2p"));
            tl.push(TaskLog.Logger(Build.Task(new VoxelSplitSmall(new VectorInt3(8, 8, 8)), product), "vss"));
            tl.push(TaskLog.Logger(Build.Task(new VoxelMeshBuild(), product), "vmb"));             //43%
            tl.push(TaskLog.Logger(Build.Task(new VoxelRemoveSameVertices(), product), "vrv"));
            tl.push(TaskLog.Logger(Build.Task(new VoxelRemoveFace(), product), "vrf"));            //47%
            TaskManager.PushBack(tl, delegate {
                result(product.getMeshData());
            });
            return(tl);
        }
Beispiel #20
0
        public Task closeTask()
        {
            TweenTask task = new TweenTask(delegate {
                Tween tween = TweenScale.Begin(_neck.gameObject, 0.3f, Vector3.zero);
                return(tween);
            });

            TaskManager.PushBack(task, delegate {
                close();
            });

            TaskManager.PushFront(task, delegate {
                _neck.gameObject.transform.localScale = Vector3.one;
            });
            return(task);
        }
Beispiel #21
0
 private void refresh()
 {
     if (_target != _now && !_running)
     {
         Task task = refreshTask();
         TaskManager.PushFront(task, delegate
         {
             _running = true;
         });
         TaskManager.PushBack(task, delegate
         {
             _running = false;
         });
         TaskManager.Run(task);
     }
 }
Beispiel #22
0
 public void initImpl()
 {
     if (this.isCompleted_ == false && this.end_ != null)
     {
         TaskManager.PushBack(this.end_, delegate(){ this.isOver_ = true; });
         this.isCompleted_ = true;
     }
     if (this.begin_ != null)
     {
         this.isOver_ = false;
         TaskManager.Run(begin_);
     }
     else
     {
         this.isOver_ = true;
     }
 }
Beispiel #23
0
        public static Task Struct2Data(VoxelStruct vs, Struct2DataReturn ret)
        {
            TaskList     tl      = new TaskList();
            VoxelProduct product = new VoxelProduct();

            VoxelData[] datas = vs.datas.ToArray();
            tl.push(Build.Task(new VoxelData2Point(datas), product));
            tl.push(Build.Task(new VoxelSplitSmall(new VectorInt3(8, 8, 8)), product));
            tl.push(Build.Task(new VoxelMeshBuild(), product));
            tl.push(Build.Task(new VoxelRemoveSameVertices(), product));
            tl.push(Build.Task(new VoxelRemoveFace(), product));
            tl.push(Build.Task(new VoxelRemoveSameVertices(), product));
            TaskManager.PushBack(tl, delegate {
                ret(product.getMeshData());
            });

            return(tl);
        }
Beispiel #24
0
        Task changeTask(int i, char ch, int count)
        {
            TaskList tl = new TaskList();

            Task remove = new TweenTask(delegate {
                chars_[i].gameObject.transform.eulerAngles = new Vector3(0, 0, 0);
                return(TweenRotation.Begin(chars_[i].gameObject, 0.15f, Quaternion.Euler(new Vector3(270, 0, 0))));
            });

            TaskManager.PushBack(remove, delegate {
                chars_[i].gameObject.SetActive(false);
            });
            tl.push(remove);



            Task add = new TweenTask(delegate {
                VoxelChar vc = _create.create(ch);
                if (vc != null)
                {
                    vc.gameObject.SetActive(true);
                    vc.setLayer(this.gameObject.layer);
                    vc.setMainColor(_maincolor);
                    vc.setLightColor(_lightColor);
                    vc.gameObject.transform.SetParent(this.transform);

                    vc.gameObject.transform.localScale    = Vector3.one;
                    vc.gameObject.transform.localPosition = this.getOffset(count, i);
                    chars_[i] = vc;
                    vc.gameObject.transform.eulerAngles = new Vector3(-270, 0, 0);
                    return(TweenRotation.Begin(vc.gameObject, 0.15f, Quaternion.Euler(new Vector3(0, 0, 0))));
                }
                return(null);
            });



            tl.push(add);


            return(tl);
        }
Beispiel #25
0
 public TaskPack(CreateTask createTask)
 {
     this.init = delegate
     {
         isOver_ = false;
         task_   = createTask();
         if (task_ == null)
         {
             isOver_ = true;
         }
         else
         {
             TaskManager.PushBack(task_, delegate {
                 isOver_ = true;
             });
             TaskManager.Run(task_);
         }
     };
     this.isOver = delegate {
         return(isOver_);
     };
 }
Beispiel #26
0
        private Task setTextTask_(string text)
        {
            TaskSet ts   = new TaskSet();
            string  comp = compress(text);
            int     n    = Mathf.Min(chars_.Count, comp.Length);

            for (int i = 0; i < n; ++i)
            {
                if (chars_[i].ch != comp[i])
                {
                    ts.push(changeTask(i, comp[i], comp.Length));
                }
            }
            if (chars_.Count > comp.Length)
            {
                for (int i = n; i < chars_.Count; i++)
                {
                    Task remove = removeTask(i);
                    TaskManager.PushBack(ts, delegate {
                        chars_.RemoveRange(n, chars_.Count - n);
                    });
                    ts.push(remove);
                }
            }


            if (comp.Length > chars_.Count)
            {
                for (int i = n; i < comp.Length; ++i)
                {
                    ts.push(addTask(comp[i], comp.Length));
                }
            }



            return(ts);
        }
Beispiel #27
0
        public WebLoaderTask(string url)
        {
            pack_ = new WebPack(url);
            pack_.addField("a", "b");
            bool isOver = false;


            this.init = delegate {
                Task web = WebTaskFactory.Instance.create(pack, succeed, error);
                TaskManager.PushFront(web, delegate {
                    isOver = false;
                });
                TaskManager.PushBack(web, delegate {
                    isOver = true;
                });
                this.isOver = delegate {
                    return(isOver);
                };


                TaskManager.Run(web);
            };
        }
Beispiel #28
0
        //public delegate string NextState();

        static public State Create(TaskFactory creater, FSM fsm, State.StateAction nextState)
        {
            string over = "over" + index_.ToString();

            index_++;
            State state = new State();
            Task  task  = null;

            state.onStart += delegate {
                task = creater();
                TaskManager.PushBack(task, delegate {
                    fsm.post(over);
                });
                TaskManager.Run(task);
            };
            state.onOver += delegate {
                task.isOver = delegate {
                    return(true);
                };
            };
            state.addAction(over, nextState);
            return(state);
        }
Beispiel #29
0
        private Task hide()
        {
            TweenTask task = new TweenTask
                             (
                delegate {
                TweenGroupAlpha alpha = TweenGroupAlpha.Begin(this.gameObject, 0.15f, 0.0f);
                return(alpha);
            }
                             );



            TaskManager.PushBack(task, delegate {
                if (_cg != null)
                {
                    _cg.alpha = 0.0f;
                }
                if (this != null && this.gameObject != null)
                {
                    this.gameObject.SetActive(false);
                }
            });
            return(task);
        }
Beispiel #30
0
 public void push(Task task)
 {
     this.tasks_.Add(task);
     TaskManager.PushBack(task, delegate(){ overCount_++; });
 }