Beispiel #1
0
        public static GraphicEntity Build(IEntityManager context, IAppWindow window)
        {
            var view = context.CreateEntity(new ElementTag("EngineInfo"));

            view//.AddComponent(new WindowHeaderUpdaterComponent(window))
            .AddComponent(new InputInfoComponent())
            .AddComponent(PerfomanceComponent.Create(0, 0));

            return(view);
        }
Beispiel #2
0
        void Loop()
        {
            System.Threading.Thread.CurrentThread.Name = "Game Loop";
            var imanager = Window.InputManager;

            //first synchronization
            Context.GetEntityManager().Synchronize(Thread.CurrentThread.ManagedThreadId);
            imanager.Synchronize(Thread.CurrentThread.ManagedThreadId);

            var speed = new Stopwatch();
            var any   = Context
                        .GetEntityManager()
                        .GetEntities()
                        .Where(x => x.Has <PerfomanceComponent>());
            ElementTag engineInfoTag;

            if (any.Any())
            {
                engineInfoTag = any.Single().Tag;
            }

            double millisec = oneFrameMilliseconds;

            while (Window.IsActive && !token.IsCancellationRequested)
            {
                speed.Restart();

                imanager.Synchronize(Thread.CurrentThread.ManagedThreadId);
                OnSynchronizing();

                var eman = Context.GetEntityManager();

                Rendering(eman, imanager, millisec);

                millisec = speed.ElapsedMilliseconds;

                if (millisec < oneFrameMilliseconds)
                {
                    Thread.Sleep((int)(oneFrameMilliseconds - millisec));
                }
                speed.Stop();

                millisec = speed.ElapsedMilliseconds;

                eman.GetEntity(engineInfoTag)
                .UpdateComponent(PerfomanceComponent.Create(millisec, (int)(total / millisec)));
                //Debug.WriteLine($"FPS {(int)(total / speed.ElapsedMilliseconds)} / {speed.ElapsedMilliseconds} ms");

                notify.NotifyRender(eman.GetEntities().ToArray());
            }

            Window.InputManager.Dispose();
            Context.Dispose();
        }
Beispiel #3
0
        bool Rendering(IEntityManager emanager, IInputManager imanager, double millisec, bool changed)
        {
            var syncContext = Context.GetSynchronizationContext();
            var isnap       = InputManager.GetInputSnapshot();

            changed = changed || syncContext.HasChanges;

            if (isnap.Events.Any() || changed)
            {
                emanager
                .GetEntity(WorldTag)
                .UpdateComponent(PerfomanceComponent.Create(millisec, total, millisec));
            }

            syncContext.Synchronize(managedThreadId);

            if (!isnap.Events.Any() && !changed)  //no input no rendering
            {
                return(false);
            }

            var snapshot = CreateSceneSnapshot(isnap, TimeSpan.FromMilliseconds(millisec));// new SceneSnapshot(Window, notificator, viewport, Octree, ishapshot, TimeSpan.FromMilliseconds(millisec));

            foreach (var sys in Context.GetSystemManager().GetSystems())
            {
                try {
                    sys.Execute(snapshot);
                    //run synchronization after each exetuted system, to synchronize state for the next system
                    syncContext.Synchronize(managedThreadId);
                } catch (Exception ex) {
                    Context.Logger.Error(ex);
#if !DEBUG
                    throw ex;
#endif
                }
            }
            return(true);
        }