Exemplo n.º 1
0
    void Update()
    {
        int count = this.m_kExecQueue.Count;
        int num   = 0; //每帧从0开始计数
        int num2  = 1; //控制每帧添加的任务数 默认1个(适度修改)

        for (int i = 0; i < this.m_kLoadingQueue.Count; i++)
        {
            if (num >= num2)
            {
                break;
            }
            LoadingTask item = this.m_kLoadingQueue[i];
            this.m_kExecQueue.Add(item);
            num++;
        }
        //上面的for 中 加入了几个任务就从需要加载的队列中移除
        this.m_kLoadingQueue.RemoveRange(0, num);

        //循环新增任务  进行加载
        for (int j = count; j < this.m_kExecQueue.Count; j++)
        {
            StartCoroutine(DoLoad(this.m_kExecQueue[j]));
        }
    }
    IEnumerator _KickTask(IList <LoadingTask> tasks)
    {
        isRunningTask = true;

        ChartEditor.Instance.ChangeStateToLoading();
        loadingScreen.FadeIn();

        for (int i = 0; i < tasks.Count; ++i)
        {
            LoadingTask currentTask = tasks[i];
            loadingScreen.loadingInformation.text = currentTask.description;

            Thread taskThread = new Thread(currentTask.task);
            taskThread.Start();

            while (taskThread.ThreadState == ThreadState.Running)
            {
                yield return(null);
            }
        }

        loadingScreen.FadeOut();
        loadingScreen.loadingInformation.text = "Complete!";

        isRunningTask = false;
    }
Exemplo n.º 3
0
    static void P(LoadingTask task, [CallerLineNumber] int __LINE__ = 0)
    {
        const int BEGIN = 19;
        const int END   = 110;

        task.ProgressRate = (float)(__LINE__ - BEGIN) / (END - BEGIN);
    }
Exemplo n.º 4
0
        /// <summary>
        /// Called from the main thread when we want to check for the completetion of loadables.
        /// When a loadable is completed, this will finalize them; this blocks the main thread.
        /// </summary>
        public void Update()
        {
            if (m_completed)
            {
                return;
            }

            if (!m_started || !IsLoadCompleted)
            {
                return;
            }
            if (IsFinalizeSuccessful)
            {
                m_completed = true;
                return;
            }

            // finalize once per frame
            if (m_loadableEnumerator == null)
            {
                m_loadableEnumerator = m_loadables.Values.GetEnumerator();
            }

            var enumerator = m_loadableEnumerator.Value;

            if (enumerator.MoveNext())
            {
                LoadingTask current = enumerator.Current;
                current.DoFinalize();
            }
        }
Exemplo n.º 5
0
    public override void MakeScene(LoadingTask task, object[] args)
    {
        Entity system = Entity.Instantiate();

        system.Name = "system";
        system.Attach(new SystemComponent());

        task.ProgressRate = 0.25f;

        Entity camera2d = Entity.Instantiate();

        camera2d.Name = "camera2d";
        camera2d.Attach(new TransformComponent());
        camera2d.Attach(new CameraComponent());

        task.ProgressRate = 0.5f;

        Entity projector2d = Entity.Instantiate();

        projector2d.Name = "projector2d";
        projector2d.Attach(new ProjectorComponent());
        projector2d.Get <ProjectorComponent>().SetOrthogonalMode(DisplayAspect * 2.0f, 2.0f, 0, 1);

        task.ProgressRate = 0.75f;

        Entity entity = Entity.Instantiate();

        entity.Attach <GameClearComponent>();

        task.ProgressRate = 1.0f;
    }
Exemplo n.º 6
0
    public async void KickTasks(IList <LoadingTask> tasks)
    {
        Debug.Assert(!isRunningTask);

        isRunningTask = true;

        ChartEditor.Instance.ChangeStateToLoading();
        loadingScreen.FadeIn();

        try {
            for (int i = 0; i < tasks.Count; ++i)
            {
                LoadingTask currentTask = tasks[i];
                loadingScreen.loadingInformation.text = currentTask.description;

                await Task.Run(currentTask.task);
            }
        } finally {
            isRunningTask = false;

            loadingScreen.loadingInformation.text = "Complete!";
            loadingScreen.FadeOut();

            ChartEditor.Instance.ChangeStateToEditor();
        }
    }
Exemplo n.º 7
0
    public static void Draw(LoadingTask task)
    {
        VisibleProgressRate = clamp(close(VisibleProgressRate, task.ProgressRate, 0.02f), 0, task.ProgressRate);

        var device   = GraphicsDevice.Instance;
        var device2d = Graphics2D.Instance;
        var proj     = new Matrix4x4().Orthogonal(DisplayAspect * 2, 2, 0, 1);

        device.SetBlendState(Addition);
        device.SetDepthStencilState(ZTestOff);
        device.SetRasterizerState(CullingOff);

        device2d.SetColor(ColorCode.White);
        device2d.SetMatrix(new Matrix4x3().Identity().Translate(0.5f, -0.75f).Scale(0.06f) * proj);
        device2d.DrawText("Now Loading" + "...".Substring(0, (frame / 30) % 3), TextAlignment.Left, TextAlignment.Center);

        device2d.SetColor(ColorCode.Gray);
        device2d.SetMatrix(new Matrix4x3().Identity().Translate(0.5f, -0.75f).Translate(0, -0.05f).Scale(0.5f, 0.02f, 1) * proj);
        device2d.SetVertexPositions(0, 0.5f, 1, -0.5f);
        device2d.DrawRectangleWithDynamical();

        device2d.SetColor(ColorCode.White);
        device2d.SetMatrix(new Matrix4x3().Identity().Translate(0.5f, -0.75f).Translate(0, -0.05f).Scale(0.5f, 0.02f, 1) * proj);
        device2d.SetVertexPositions(0, 0.5f, VisibleProgressRate, -0.5f);
        device2d.DrawRectangleWithDynamical();

        device2d.SetMatrix(new Matrix4x3().Identity().Translate(1.05f, -0.75f).Translate(0, -0.05f).Scale(0.04f) * proj);
        device2d.DrawText(VisibleProgressRate.ToString("P0"), TextAlignment.Left, TextAlignment.Center);
    }
    public MissionControllerComponent(LoadingTask task, string missionName)
    {
        var type = Missions.MissionAssemblies[missionName].GetType("Mission");

        StartMethod  = type.GetMethod("start");
        UpdateMethod = type.GetMethod("update");
        StartMethod.Invoke(null, new object[] { task });
    }
Exemplo n.º 9
0
 public static void ShowDialog(Image image, params LoadingTask[] Tasks)
 {
     Failed = null;
     using (frmLoading <T> frm = new frmLoading <T>()) {
         frm.pictureBox1.Image = image;
         frm.label1.Text       = Tasks[0].Text;
         _TasksToExecute       = Tasks;
         frm.ShowDialog();
     }
 }
Exemplo n.º 10
0
 public static bool LoadSceneAsync(string sceneName, LoadingTask task = LoadingTask.Nothing)
 {
     if (Application.CanStreamedLevelBeLoaded(sceneName))
     {
         Loading.targetSceneName = sceneName;
         Loading.loadingTask     = task;
         SceneManager.LoadScene(StringAssets.loadingSceneName);
         return(true);
     }
     return(false);
 }
Exemplo n.º 11
0
        public void Load <T>(Func <T> loadContent, Action <T> onLoaded)
        {
            var newTask = new LoadingTask <T>(_syncContext, loadContent, onLoaded, OnLoadingError);

            lock (_taskLock)
            {
                _currentTask.Cancel();
                _currentTask = newTask;
            }

            newTask.RunAsync();
        }
        /// <summary>
        /// Launch the loading of a data page.
        /// If a task is currently running, it gets discarded (callbacks won't be called).
        /// If the first page loading is asked whereas one or several pages have already been loaded, a "refresh" is detected.
        /// </summary>
        /// <param name="pageNumber">The page number to load (pageNumber = 1 for the first page).</param>
        /// <param name="calledFromScroll">True if LoadPage has been called from OnScroll method of the IInfiniteListLoader.</param>
        public Task <PageResult <TResult> > LoadPage(int pageNumber, bool calledFromScroll = false)
        {
            Contract.Requires(() => pageNumber > 0);
            Contract.Requires(
                () => calledFromScroll || (pageNumber == 1 || pageNumber == (PageLoadedCount + 1)),
                "The paginator can only load sequential pages");

            InternalLogger.Info($"Requesting page n°{pageNumber} load, {PageLoadedCount} pages loaded so far");
            lock (_syncRoot)
            {
                if (calledFromScroll)
                {
                    if (pageNumber <= PageLoadedCount)
                    {
                        InternalLogger.Info($"Aborting IInfiniteListLoader call: only a direct call to LoadPage can lead to a refresh");
                        return(Task.FromResult(PageResult <TResult> .Empty));
                    }
                }

                if (pageNumber > PageLoadedCount && IsFull)
                {
                    InternalLogger.Info($"Cannot load page {pageNumber} total item count has already been reached ({TotalCount})");
                    return(Task.FromResult(PageResult <TResult> .Empty));
                }

                if (pageNumber == 1 && PageLoadedCount > 0)
                {
                    InternalLogger.Info("Refresh detected");
                    _refreshRequested = true;
                }
                else
                {
                    _refreshRequested = false;
                }

                if (LoadingTask != null && LoadingTask.IsNotCompleted)
                {
                    // Cancels callbacks of previous task if not completed
                    LoadingTask.CancelCallbacks();
                }

                LoadingTask = new TaskMonitor <PageResult <TResult> > .Builder(
                    () => _pageSourceLoader(pageNumber, PageSize, _refreshRequested))
                              .WithWhenSuccessfullyCompleted(OnPageRetrieved)
                              .WithWhenCompleted(OnTaskCompleted)
                              .Build();

                InternalLogger.Info($"Page n°{pageNumber} loading started");
                LoadingTask.Start();
                return(LoadingTask.Task);
            }
        }
Exemplo n.º 13
0
        public void Add(IAsyncLoadable loadable)
        {
            if (m_started || m_completed)
            {
                return;
            }

            if (m_loadables.ContainsKey(loadable))
            {
                return;
            }
            m_loadables[loadable] = new LoadingTask(loadable);
        }
Exemplo n.º 14
0
        void StartTask(LoadingTask task)
        {
            if (_CurrentlyLoadingTasks.Count == 0)
            {
                // On first task, notify listeners that a loading session begins
                if (LoadingSessionStarted != null)
                {
                    LoadingSessionStarted();
                }
            }
            _CurrentlyLoadingTasks.Add(task);

            if (ShowLogs)
            {
                Debug.Log("Starting loading task '" + task + "'. numLoadingTasks now is " + _CurrentlyLoadingTasks.Count);
            }
            task.Start();
        }
Exemplo n.º 15
0
 private async void frmLoading_Shown(Object sender, EventArgs e)
 {
     foreach (var ts in _TasksToExecute)
     {
         this.label1.Text = ts.Text;
         if (ts.Task.IsStarted())
         {
             continue;
         }
         ts.Task.Start();
         ts.Result = await ts.Task;
         if (ts.Result != null)
         {
             Failed = ts;
             break;
         }
     }
     this.Close();
 }
Exemplo n.º 16
0
    /// <summary>
    /// 加载协同
    /// </summary>
    IEnumerator DoLoad(LoadingTask kCurrentTask)
    {
        WWW www = new WWW(kCurrentTask.kAssetPath);

        yield return(www);

        if (www.isDone)
        {
            //检查报错
            if (www.error != null)
            {
                GameSys.Log(www.error);
                www = null;
                yield break;
            }
            AssetBundle bundle = www.assetBundle;
            if (bundle != null)
            {
                kCurrentTask.OnLoaded(bundle.mainAsset, true);
                this.m_kLoadedAsset.Add(kCurrentTask.kAssetPath, bundle.mainAsset);
            }
            else
            {
                AudioClip audioClip = www.audioClip;
                if (audioClip != null)
                {
                    kCurrentTask.OnLoaded(audioClip, true);
                    this.m_kLoadedAsset.Add(kCurrentTask.kAssetPath, audioClip);
                }
            }
        }
        else
        {
            GameSys.Log("声音加载错误");
        }
        //加载完毕从执行序列中移除
        if (this.m_kExecQueue.Contains(kCurrentTask))
        {
            this.m_kExecQueue.Remove(kCurrentTask);
        }
    }
Exemplo n.º 17
0
        void OnFinishedOneTask(LoadingTask task)
        {
            // Ignore the callback if meanwhile something invalidated the list of tasks
            if (!_CurrentlyLoadingTasks.Remove(task))
            {
                if (ShowLogs)
                {
                    Debug.Log("Finished loading task '" + task + "', but the task list was invalidated meanwhile. numLoadingTasks is " + _CurrentlyLoadingTasks.Count);
                }

                return;
            }

            // Commit the populated local buffer to the data source
            _DataSource.ManuallyUpdateCreatedValues(task.FirstItemIndex, task.Buffer, 0, task.CountToRead);

            // Recycle the buffer
            _BuffersPool.Enqueue(task.Buffer);

            bool noMoreTasks = _CurrentlyLoadingTasks.Count == 0;

            if (ShowLogs)
            {
                Debug.Log("Finished loading task '" + task + "'. numLoadingTasks now is " + _CurrentlyLoadingTasks.Count);
            }

            if (SingleTaskFinished != null)
            {
                SingleTaskFinished(task);
            }

            if (noMoreTasks)
            {
                if (LoadingSessionEnded != null)
                {
                    LoadingSessionEnded();
                }
            }
        }
Exemplo n.º 18
0
        void ChunkReader(T[] into, int firstItemIndex, int countToRead)
        {
            // Important: passing a clone of the buffer to the task, as multiple tasks can overlap in time and so
            // we don't want them to modify the same buffer after the initial empty values were assigned
            var into_Copy = GetPooledBuffer();

            //// Filling slots with empty objects (i.e. valid objects, but with null/empty fields)
            //for (int i = 0; i < countToRead; i++)
            //{
            //	var val = _EmptyValueCreator();
            //	into[i] = val; // passing the empty values to the reqder, as requested
            //	into_Copy[i] = val; // but storing them in a separate local buffer (pooled)
            //}

            var task = new LoadingTask(into_Copy, firstItemIndex, countToRead, _Loader, OnFinishedOneTask);

            // Some debugging to check if ranges overlap. They do not, as of 21-Jul-2019
            //foreach (var existingTask in _CurrentlyLoadingTasks)
            //{
            //	if (existingTask.FirstItemIndex == firstItemIndex)
            //		throw new InvalidOperationException(firstItemIndex + "");
            //	if (existingTask.LastItemIndexExcl == task.LastItemIndexExcl)
            //		throw new InvalidOperationException(task.LastItemIndexExcl + "");

            //	if (task.FirstItemIndex < existingTask.FirstItemIndex)
            //	{
            //		if (task.LastItemIndexExcl > existingTask.FirstItemIndex)
            //			throw new InvalidOperationException(existingTask.FirstItemIndex + ", " + existingTask.LastItemIndexExcl + ", " + task.FirstItemIndex + ", " + task.LastItemIndexExcl);
            //	}
            //	else
            //	{
            //		if (task.FirstItemIndex < existingTask.LastItemIndexExcl)
            //			throw new InvalidOperationException(existingTask.FirstItemIndex + ", " + existingTask.LastItemIndexExcl + ", " + task.FirstItemIndex + ", " + task.LastItemIndexExcl);
            //	}
            //}

            StartTask(task);
        }
Exemplo n.º 19
0
    public void UserCheckForUpdates()
    {
        ApplicationUpdateManager updateManager = services.updateManager;

        updateManager.CheckForUpdates(OnUserCheckForUpdatesComplete);

        LoadingTask waitForUpdateCheckTask = new LoadingTask("Checking for updates...", () =>
        {
            while (updateManager.UpdateCheckInProgress)
            {
                ;
            }
        });

        List <LoadingTask> tasks = new List <LoadingTask>()
        {
            waitForUpdateCheckTask
        };

        LoadingTasksManager tasksManager = services.loadingTasksManager;

        tasksManager.KickTasks(tasks);
    }
Exemplo n.º 20
0
    public override void MakeScene(LoadingTask task, object[] args)
    {
        Entity system = Entity.Instantiate();

        system.Name = "system";
        system.Attach(new SystemComponent());

        task.ProgressRate = 0.1f;

        Entity gamespace = Entity.Instantiate();

        gamespace.Name = "gamespace";
        gamespace.Attach(new GameSpaceComponent(10000.0f));

        task.ProgressRate = 0.2f;

        Entity camera = Entity.Instantiate();

        camera.Name = "camera";
        camera.Attach(new TransformComponent());
        camera.Attach(new CameraComponent());
        camera.Attach(new SoundObserverComponent()
        {
            EffectRange = 10000, SonicSpeed = SonicSpeed * 2
        });
        camera.Get <CameraComponent>().LookAt(new Vector3(52, 1004, -900), new Vector3(0, 1000, 0));
        camera.Attach <TransformControlComponent>();

        task.ProgressRate = 0.3f;

        Entity camera2d = Entity.Instantiate();

        camera2d.Name = "camera2d";
        camera2d.Attach(new TransformComponent());
        camera2d.Attach(new CameraComponent());

        task.ProgressRate = 0.4f;

        Entity projector = Entity.Instantiate();

        projector.Name = "projector";
        projector.Attach(new ProjectorComponent());
        projector.Get <ProjectorComponent>().SetPerspectiveMode(PI / 3, DisplayAspect, 1.0f, 4096.0f);

        task.ProgressRate = 0.5f;

        Entity projector2d = Entity.Instantiate();

        projector2d.Name = "projector2d";
        projector2d.Attach(new ProjectorComponent());
        projector2d.Get <ProjectorComponent>().SetOrthogonalMode(DisplayAspect * 2.0f, 2.0f, 0, 1);

        task.ProgressRate = 0.6f;

        Entity light = Entity.Instantiate();

        light.Name = "light";
        light.Attach(new TransformComponent());
        light.Attach(new LightComponent());
        light.Get <LightComponent>().LookAt(new Vector3(-1, 1, -1), new Vector3(0, 0, 0));

        task.ProgressRate = 0.7f;

        Entity missionSelect = Entity.Instantiate();

        missionSelect.Attach <MissionSelectComponent>();

        task.ProgressRate = 0.8f;
    }
Exemplo n.º 21
0
 public void DisplayTask(LoadingTask task)
 {
     SplashLabel.Text = _stepToTaskDictionary[task];
 }
Exemplo n.º 22
0
    public override void MakeScene(LoadingTask task, object[] args)
    {
        P(task); task.ProgressRate = 0.0f;

        P(task); string missionName = args[0] as string;

        P(task); Entity system = Entity.Instantiate();
        P(task); system.Name = "system";
        P(task); system.Attach(new SystemComponent());

        P(task); task.ProgressRate = 0.1f;

        P(task); Entity gamespace = Entity.Instantiate();
        P(task); gamespace.Name = "gamespace";
        P(task); gamespace.Attach(new GameSpaceComponent(10000.0f));

        P(task); task.ProgressRate = 0.2f;

        P(task); Entity camera = Entity.Instantiate();
        P(task); camera.Name = "camera";
        P(task); camera.Attach(new TransformComponent());
        P(task); camera.Attach(new CameraComponent());
        P(task); camera.Attach(new CustomCameraComponent());
        P(task); camera.Attach(new SoundObserverComponent()
        {
            EffectRange = 10000, SonicSpeed = SonicSpeed * 2
        });
        P(task); camera.Get <CameraComponent>().LookAt(new Vector3(sin(0.5f), 0.5f, -cos(0.5f)) * 2000, new Vector3(0, 0, 0));
        P(task);
        P(task); Entity camera2d = Entity.Instantiate();
        P(task); camera2d.Name = "camera2d";
        P(task); camera2d.Attach(new TransformComponent());
        P(task); camera2d.Attach(new CameraComponent());

        P(task); task.ProgressRate = 0.3f;

        P(task); Entity projector = Entity.Instantiate();
        P(task); projector.Name = "projector";
        P(task); projector.Attach(new ProjectorComponent());
        P(task); projector.Attach(new CustomProjectorComponent());
        P(task); projector.Get <ProjectorComponent>().SetPerspectiveMode(PI / 3, DisplayAspect, 1.0f, 4096.0f);

        P(task); Entity projector2d = Entity.Instantiate();
        P(task); projector2d.Name = "projector2d";
        P(task); projector2d.Attach(new ProjectorComponent());
        P(task); projector2d.Get <ProjectorComponent>().SetOrthogonalMode(DisplayAspect * 2.0f, 2.0f, 0, 1);

        P(task); task.ProgressRate = 0.4f;

        P(task); Entity light = Entity.Instantiate();
        P(task); light.Name = "light";
        P(task); light.Attach(new TransformComponent());
        P(task); light.Attach(new LightComponent());
        P(task); light.Get <LightComponent>().LookAt(new Vector3(-1, 1, -1), new Vector3(0, 0, 0));

        P(task); task.ProgressRate = 0.5f;

        P(task); Entity sky = Entity.Instantiate();
        P(task); sky.Attach(new TransformComponent());
        P(task); sky.Attach(new SkyComponent());

        P(task); Entity ground = Entity.Instantiate();
        P(task); ground.Name = "ground";
        P(task); ground.Attach(new TransformComponent());
        P(task); ground.Attach(new CollisionComponent());
        P(task); ground.Attach(new GroundComponent());

        P(task); Entity cloud = Entity.Instantiate();
        P(task); cloud.Name = "cloud";
        P(task); cloud.Attach(new CloudComponent(randoms(distmap("res/texture/cloud_distribution.png"), 10000).Select(tuple =>
        {
            float x    = tuple.Item1 - 0.5f;
            float z    = tuple.Item2 - 0.5f;
            var length = Entity.Find("gamespace").Get <GameSpaceComponent>().AreaLength;
            x         *= length;
            z         *= length;
            float y    = normal(1000, 100);
            return(new Vector3(x, y, z));
        }).ToArray()));

#if true
        P(task); camera.Attach(new WindComponent());
        P(task); camera.Attach(new VibrationComponent());

        P(task); Entity ui = Entity.Instantiate();
        P(task); ui.Name = "ui";
        P(task); ui.Attach(new UIComponent());
        P(task); ui.Attach(new DamageViewComponent());
#else
        P(task);        camera.Attach <TransformControlComponent>();
#endif

        P(task); task.ProgressRate = 0.6f;

        P(task); Entity missionController = Entity.Instantiate();
        P(task); missionController.Attach(new MissionControllerComponent(task, missionName));

        //#if true
        //        Entity player = Entity.Instantiate();
        //        player.Name = "player";
        //        player.Attach(new TransformComponent());
        //        player.Attach(new PhysicsComponent());
        //        player.Attach(new CollisionComponent());
        //        player.Attach(new JetComponent());
        //        player.Attach(new AircraftComponent());
        //        player.Attach(new AIComponent(Friend));
        //        player.Attach(new PlayerComponent());
        //        player.Attach(new SquadronComponent("Mobius"));
        //        player.Attach(new SoundComponent(JetSound));
        //        player.Get<TransformComponent>().Position = new Vector3(0, 1000, -2000);
        //        player.Get<SoundComponent>().LoopPlay();
        //#endif
        //        {
        //            Entity enemy1 = Entity.Instantiate();
        //            enemy1.Name = "enemy1";
        //            enemy1.Attach(new TransformComponent());
        //            enemy1.Attach(new PhysicsComponent());
        //            enemy1.Attach(new CollisionComponent());
        //            enemy1.Attach(new JetComponent());
        //            enemy1.Attach(new AircraftComponent());
        //            enemy1.Attach(new AIComponent(Enemy));
        //            enemy1.Attach(new SquadronComponent("Sorcerer"));
        //            enemy1.Attach(new NPCAIComponent());
        //            enemy1.Attach(new SoundComponent(JetSound));
        //            enemy1.Get<TransformComponent>().Matrix.RotateY(PI);
        //            enemy1.Get<TransformComponent>().Position = new Vector3(1000, 1000, 2500);
        //            //enemy1.Get<TransformComponent>().Position = new Vector3(100, 1000, 0);
        //            enemy1.Get<SoundComponent>().LoopPlay();
        //        }

        //        //camera.Get<CameraComponent>().Mode = CameraComponent.CameraMode.Tracking;
        //        //camera.Get<CameraComponent>().TrackingTarget = enemy1;
        //        //camera.Get<CameraComponent>().Offset = new Vector3(0, 4, -18);

        //#if true
        //        {
        //            Entity enemy2 = Entity.Instantiate();
        //            enemy2.Name = "enemy2";
        //            enemy2.Attach(new TransformComponent());
        //            enemy2.Attach(new PhysicsComponent());
        //            enemy2.Attach(new CollisionComponent());
        //            enemy2.Attach(new JetComponent());
        //            enemy2.Attach(new AircraftComponent());
        //            enemy2.Attach(new AIComponent(Enemy));
        //            enemy2.Attach(new SquadronComponent("Sorcerer"));
        //            enemy2.Attach(new NPCAIComponent());
        //            enemy2.Attach(new SoundComponent(JetSound));
        //            enemy2.Get<TransformComponent>().Matrix.RotateY(PI);
        //            enemy2.Get<TransformComponent>().Position = new Vector3(1050, 1000, 2520);
        //            enemy2.Get<SoundComponent>().LoopPlay();
        //        }
        //        {
        //            Entity enemy3 = Entity.Instantiate();
        //            enemy3.Name = "enemy3";
        //            enemy3.Attach(new TransformComponent());
        //            enemy3.Attach(new PhysicsComponent());
        //            enemy3.Attach(new CollisionComponent());
        //            enemy3.Attach(new JetComponent());
        //            enemy3.Attach(new AircraftComponent());
        //            enemy3.Attach(new AIComponent(Enemy));
        //            enemy3.Attach(new SquadronComponent("Sorcerer"));
        //            enemy3.Attach(new NPCAIComponent());
        //            enemy3.Attach(new SoundComponent(JetSound));
        //            enemy3.Get<TransformComponent>().Matrix.RotateY(PI);
        //            enemy3.Get<TransformComponent>().Position = new Vector3(1000 - 50, 1000, 2520);
        //            enemy3.Get<SoundComponent>().LoopPlay();
        //        }
        //        {
        //            Entity enemy4 = Entity.Instantiate();
        //            enemy4.Attach(new TransformComponent());
        //            enemy4.Attach(new PhysicsComponent());
        //            enemy4.Attach(new CollisionComponent());
        //            enemy4.Attach(new JetComponent());
        //            enemy4.Attach(new AircraftComponent());
        //            enemy4.Attach(new AIComponent(Enemy));
        //            enemy4.Attach(new SquadronComponent("Giant"));
        //            enemy4.Attach(new NPCAIComponent());
        //            enemy4.Attach(new SoundComponent(JetSound));
        //            enemy4.Get<TransformComponent>().Matrix.RotateY(PI);
        //            enemy4.Get<TransformComponent>().Position = new Vector3(-1000, 2000, 2500);
        //            enemy4.Get<SoundComponent>().LoopPlay();
        //        }
        //        {
        //            Entity enemy5 = Entity.Instantiate();
        //            enemy5.Attach(new TransformComponent());
        //            enemy5.Attach(new PhysicsComponent());
        //            enemy5.Attach(new CollisionComponent());
        //            enemy5.Attach(new JetComponent());
        //            enemy5.Attach(new AircraftComponent());
        //            enemy5.Attach(new AIComponent(Enemy));
        //            enemy5.Attach(new SquadronComponent("Giant"));
        //            enemy5.Attach(new NPCAIComponent());
        //            enemy5.Attach(new SoundComponent(JetSound));
        //            enemy5.Get<TransformComponent>().Position = new Vector3(-1050, 2000, 2500);
        //            enemy5.Get<SoundComponent>().LoopPlay();
        //        }
        //        {
        //            Entity friend1 = Entity.Instantiate();
        //            friend1.Name = "friend1";
        //            friend1.Attach(new TransformComponent());
        //            friend1.Attach(new PhysicsComponent());
        //            friend1.Attach(new CollisionComponent());
        //            friend1.Attach(new JetComponent());
        //            friend1.Attach(new AircraftComponent());
        //            friend1.Attach(new AIComponent(Friend));
        //            friend1.Attach(new SquadronComponent("Mobius"));
        //            friend1.Attach(new NPCAIComponent());
        //            friend1.Attach(new SoundComponent(JetSound));
        //            friend1.Get<TransformComponent>().Position = new Vector3(-50, 1000, -2050);
        //            friend1.Get<SoundComponent>().LoopPlay();
        //        }
        //        {
        //            Entity friend2 = Entity.Instantiate();
        //            friend2.Name = "friend2";
        //            friend2.Attach(new TransformComponent());
        //            friend2.Attach(new PhysicsComponent());
        //            friend2.Attach(new CollisionComponent());
        //            friend2.Attach(new JetComponent());
        //            friend2.Attach(new AircraftComponent());
        //            friend2.Attach(new AIComponent(Friend));
        //            friend2.Attach(new SquadronComponent("Mobius"));
        //            friend2.Attach(new NPCAIComponent());
        //            friend2.Attach(new SoundComponent(JetSound));
        //            friend2.Get<TransformComponent>().Position = new Vector3(50, 1000, -2050);
        //            friend2.Get<SoundComponent>().LoopPlay();
        //        }
        //        {
        //            Entity friend3 = Entity.Instantiate();
        //            friend3.Name = "friend3";
        //            friend3.Attach(new TransformComponent());
        //            friend3.Attach(new PhysicsComponent());
        //            friend3.Attach(new CollisionComponent());
        //            friend3.Attach(new JetComponent());
        //            friend3.Attach(new AircraftComponent());
        //            friend3.Attach(new AIComponent(Friend));
        //            friend3.Attach(new SquadronComponent("Venom"));
        //            friend3.Attach(new NPCAIComponent());
        //            friend3.Attach(new SoundComponent(JetSound));
        //            friend3.Get<TransformComponent>().Position = new Vector3(0, 1000, -2500);
        //            friend3.Get<SoundComponent>().LoopPlay();
        //        }
        //        {
        //            Entity friend4 = Entity.Instantiate();
        //            friend4.Name = "friend4";
        //            friend4.Attach(new TransformComponent());
        //            friend4.Attach(new PhysicsComponent());
        //            friend4.Attach(new CollisionComponent());
        //            friend4.Attach(new JetComponent());
        //            friend4.Attach(new AircraftComponent());
        //            friend4.Attach(new AIComponent(Friend));
        //            friend4.Attach(new SquadronComponent("Venom"));
        //            friend4.Attach(new NPCAIComponent());
        //            friend4.Attach(new SoundComponent(JetSound));
        //            friend4.Get<TransformComponent>().Position = new Vector3(-50, 1000, -2550);
        //            friend4.Get<SoundComponent>().LoopPlay();
        //        }
        //        {
        //            Entity friend5 = Entity.Instantiate();
        //            friend5.Name = "friend5";
        //            friend5.Attach(new TransformComponent());
        //            friend5.Attach(new PhysicsComponent());
        //            friend5.Attach(new CollisionComponent());
        //            friend5.Attach(new JetComponent());
        //            friend5.Attach(new AircraftComponent());
        //            friend5.Attach(new AIComponent(Friend));
        //            friend5.Attach(new SquadronComponent("Venom"));
        //            friend5.Attach(new NPCAIComponent());
        //            friend5.Attach(new SoundComponent(JetSound));
        //            friend5.Get<TransformComponent>().Position = new Vector3(50, 1000, -2550);
        //            friend5.Get<SoundComponent>().LoopPlay();
        //        }
        //#endif
    }
Exemplo n.º 23
0
    static void Main(string[] args)
    {
#if DEBUG
        chdir("../../../");
#endif

        Window window = new Window();
        window.Create("application-02", (int)DisplayWidth, (int)DisplayHeight);

        GraphicsDevice.Instance.Create(window, FullScreen);

        SoundDevice.Instance.Create(window.Handle);

        if (ShowDebugInfo)
        {
            runner  = CommandRunner.Execute();
            monitor = GameSystemMonitor.Execute();
        }

        foreach (var file in Directory.GetFiles("res/mission/", "*.cs"))
        {
            var asm = ScriptCompiler.CompileAssemblyFromFile(new ScriptCompilerParameters()
            {
                BaseClassName      = "Script",
                BatchScriptStyle   = false,
                ClassName          = "Mission",
                GenerateExecutable = false,
                GenerateInMemory   = true,
                PythonScopeStyle   = false,
            }, file);
            Missions.MissionAssemblies.Add(Path.GetFileNameWithoutExtension(file), asm);
        }

        window.Updated += () =>
        {
            update();

            GraphicsDevice.Instance.Clear(ColorCode.Black);
#if true
            LoadingTask loadingTask = SceneManager.TryTransitScene();

            if (loadingTask.Finished)
            {
                Entity.BroadcastMessage(UpdateMessage);

                Entity.BroadcastMessage(RenderMessage);
                Entity.BroadcastMessage(TranslucentRenderMessage);
                Entity.BroadcastMessage(DrawMessage);
            }
            else
            {
                LoadingView.Draw(loadingTask);
            }
#endif
            GraphicsDevice.Instance.Present();

            if (pressed(KeyCode.Escape))
            {
                window.Close();
            }

            Entity.Update();
        };

        try
        {
            initialize();

            //SceneManager.FookScene(new MainScene());
            SceneManager.FookScene(new TitleScene());
            //SceneManager.FookScene(new MissionSelectScene());

            window.Start();
        }
        finally
        {
            Entity.Clear();

            ResourceManager.CleanUp();

            GC.Collect();

            finalize();

            GraphicsDevice.Instance.Dispose();
            SoundDevice.Instance.Dispose();

            if (ShowDebugInfo)
            {
                GameSystemMonitor.Shutdown(monitor);
                CommandRunner.Shutdown(runner);
            }
        }
    }
Exemplo n.º 24
0
    public override void MakeScene(LoadingTask task, object[] args)
    {
        P(task); Entity system = Entity.Instantiate();
        P(task); system.Name = "system";
        P(task); system.Attach(new SystemComponent());

        P(task); Entity gamespace = Entity.Instantiate();
        P(task); gamespace.Name = "gamespace";
        P(task); gamespace.Attach(new GameSpaceComponent(10000.0f));

        P(task); Entity camera = Entity.Instantiate();
        P(task); camera.Name = "camera";
        P(task); camera.Attach(new TransformComponent());
        P(task); camera.Attach(new CameraComponent());
        P(task); camera.Attach(new CustomCameraComponent());
        P(task); camera.Attach(new SoundObserverComponent()
        {
            EffectRange = 10000, SonicSpeed = SonicSpeed * 2
        });
        P(task); camera.Get <CameraComponent>().LookAt(new Vector3(52, 1004, -900), new Vector3(0, 1000, 0));
        P(task); camera.Attach <TransformControlComponent>();

        P(task); Entity camera2d = Entity.Instantiate();
        P(task); camera2d.Name = "camera2d";
        P(task); camera2d.Attach(new TransformComponent());
        P(task); camera2d.Attach(new CameraComponent());

        P(task); Entity projector = Entity.Instantiate();
        P(task); projector.Name = "projector";
        P(task); projector.Attach(new ProjectorComponent());
        P(task); projector.Attach(new CustomProjectorComponent());
        P(task); projector.Get <ProjectorComponent>().SetPerspectiveMode(PI / 3, DisplayAspect, 1.0f, 4096.0f);

        P(task); Entity projector2d = Entity.Instantiate();
        P(task); projector2d.Name = "projector2d";
        P(task); projector2d.Attach(new ProjectorComponent());
        P(task); projector2d.Get <ProjectorComponent>().SetOrthogonalMode(DisplayAspect * 2.0f, 2.0f, 0, 1);

        P(task); Entity light = Entity.Instantiate();
        P(task); light.Name = "light";
        P(task); light.Attach(new TransformComponent());
        P(task); light.Attach(new LightComponent());
        P(task); light.Get <LightComponent>().LookAt(new Vector3(-1, 1, -1), new Vector3(0, 0, 0));

        P(task); Entity title = Entity.Instantiate();
        P(task); title.Attach <TitleComponent>();

        P(task); Entity sky = Entity.Instantiate();
        P(task); sky.Attach(new TransformComponent());
        P(task); sky.Attach(new SkyComponent());

        P(task); Entity ground = Entity.Instantiate();
        P(task); ground.Name = "ground";
        P(task); ground.Attach(new TransformComponent());
        P(task); ground.Attach(new CollisionComponent());
        P(task); ground.Attach(new GroundComponent());

        P(task); Entity cloud = Entity.Instantiate();
        P(task); cloud.Name = "cloud";
        P(task); cloud.Attach(new CloudComponent(randoms(distmap("res/texture/cloud_distribution.png"), 10000).Select(tuple =>
        {
            float x    = tuple.Item1 - 0.5f;
            float z    = tuple.Item2 - 0.5f;
            var length = Entity.Find("gamespace").Get <GameSpaceComponent>().AreaLength;
            x         *= length;
            z         *= length;
            float y    = normal(1000, 100);
            return(new Vector3(x, y, z));
        }).ToArray()));

        {
            P(task); Entity enemy1 = Entity.Instantiate();
            P(task); enemy1.Name = "enemy1";
            P(task); enemy1.Attach(new TransformComponent());
            P(task); enemy1.Attach(new PhysicsComponent());
            P(task); enemy1.Attach(new CollisionComponent());
            P(task); enemy1.Attach(new JetComponent());
            P(task); enemy1.Attach(new SoundComponent(JetSound));
            P(task); enemy1.Attach(new AircraftComponent());
            P(task); enemy1.Attach(new AIComponent(Enemy));
            P(task); enemy1.Attach(new SquadronComponent("Enemy1"));
            P(task); enemy1.Attach(new NPCAIComponent());
            P(task); enemy1.Get <TransformComponent>().Matrix.RotateY(PI);
            P(task); enemy1.Get <TransformComponent>().Position = new Vector3(0, 1000, 1000);
            P(task); enemy1.Get <SoundComponent>().LoopPlay();
        }
        {
            P(task); Entity enemy2 = Entity.Instantiate();
            P(task); enemy2.Name = "enemy2";
            P(task); enemy2.Attach(new TransformComponent());
            P(task); enemy2.Attach(new PhysicsComponent());
            P(task); enemy2.Attach(new CollisionComponent());
            P(task); enemy2.Attach(new JetComponent());
            P(task); enemy2.Attach(new SoundComponent(JetSound));
            P(task); enemy2.Attach(new AircraftComponent());
            P(task); enemy2.Attach(new AIComponent(Enemy));
            P(task); enemy2.Attach(new SquadronComponent("Enemy2"));
            P(task); enemy2.Attach(new NPCAIComponent());
            P(task); enemy2.Get <TransformComponent>().Matrix.RotateY(PI);
            P(task); enemy2.Get <TransformComponent>().Position = new Vector3(50, 1000, 1050);
            P(task); enemy2.Get <SoundComponent>().LoopPlay();
        }
        {
            P(task); Entity enemy3 = Entity.Instantiate();
            P(task); enemy3.Name = "enemy3";
            P(task); enemy3.Attach(new TransformComponent());
            P(task); enemy3.Attach(new PhysicsComponent());
            P(task); enemy3.Attach(new CollisionComponent());
            P(task); enemy3.Attach(new JetComponent());
            P(task); enemy3.Attach(new SoundComponent(JetSound));
            P(task); enemy3.Attach(new AircraftComponent());
            P(task); enemy3.Attach(new AIComponent(Enemy));
            P(task); enemy3.Attach(new SquadronComponent("Enemy3"));
            P(task); enemy3.Attach(new NPCAIComponent());
            P(task); enemy3.Get <TransformComponent>().Matrix.RotateY(PI);
            P(task); enemy3.Get <TransformComponent>().Position = new Vector3(-50, 1000, 1050);
            P(task); enemy3.Get <SoundComponent>().LoopPlay();
        }

        {
            P(task); Entity friend1 = Entity.Instantiate();
            P(task); friend1.Name = "friend1";
            P(task); friend1.Attach(new TransformComponent());
            P(task); friend1.Attach(new PhysicsComponent());
            P(task); friend1.Attach(new CollisionComponent());
            P(task); friend1.Attach(new JetComponent());
            P(task); friend1.Attach(new SoundComponent(JetSound));
            P(task); friend1.Attach(new AircraftComponent());
            P(task); friend1.Attach(new AIComponent(Friend));
            P(task); friend1.Attach(new SquadronComponent("Friend1"));
            P(task); friend1.Attach(new NPCAIComponent());
            P(task); friend1.Get <TransformComponent>().Position = new Vector3(0, 1000, -1000);
            P(task); friend1.Get <SoundComponent>().LoopPlay();
        }
        {
            P(task); Entity friend2 = Entity.Instantiate();
            P(task); friend2.Name = "friend2";
            P(task); friend2.Attach(new TransformComponent());
            P(task); friend2.Attach(new PhysicsComponent());
            P(task); friend2.Attach(new CollisionComponent());
            P(task); friend2.Attach(new JetComponent());
            P(task); friend2.Attach(new SoundComponent(JetSound));
            P(task); friend2.Attach(new AircraftComponent());
            P(task); friend2.Attach(new AIComponent(Friend));
            P(task); friend2.Attach(new SquadronComponent("Friend2"));
            P(task); friend2.Attach(new NPCAIComponent());
            P(task); friend2.Get <TransformComponent>().Position = new Vector3(50, 1000, -1050);
            P(task); friend2.Get <SoundComponent>().LoopPlay();
        }
        {
            P(task); Entity friend3 = Entity.Instantiate();
            P(task); friend3.Name = "friend3";
            P(task); friend3.Attach(new TransformComponent());
            P(task); friend3.Attach(new PhysicsComponent());
            P(task); friend3.Attach(new CollisionComponent());
            P(task); friend3.Attach(new JetComponent());
            P(task); friend3.Attach(new SoundComponent(JetSound));
            P(task); friend3.Attach(new AircraftComponent());
            P(task); friend3.Attach(new AIComponent(Friend));
            P(task); friend3.Attach(new SquadronComponent("Friend3"));
            P(task); friend3.Attach(new NPCAIComponent());
            P(task); friend3.Get <TransformComponent>().Position = new Vector3(-50, 1000, -1050);
            P(task); friend3.Get <SoundComponent>().LoopPlay();
        }
    }