Ejemplo n.º 1
0
        static void Run(DrawingSystem drawing, SystemBase[] systems, CancellationToken token)
        {
            Task.Factory.StartNew(() =>
            {
                foreach (var system in systems) system.Initialize();

                var watch = Stopwatch.StartNew();
                double t = 0;

                while (token.IsCancellationRequested == false)
                {
                    var currentTick = watch.Elapsed.TotalSeconds;
                    var frameTime = currentTick - t;
                    t = currentTick;

                    foreach(var system in systems)
                    {
                        system.Frame(frameTime);
                    }

                    drawing.Frame(frameTime);
                }
                watch.Stop();

                drawing.Shutdown();
                foreach (var system in systems) system.Shutdown();
            }, token);
        }
Ejemplo n.º 2
0
        static void Main()
        {
            using (var source = new CancellationTokenSource())
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                var manager = new EntityManager();
                var form = new Form1(manager);
                var systems = new SystemBase[] {
                    new MovingSystem(manager),
                    new CollisionDetectionSystem(form, manager)
                };

                BuildEntities(manager);
                form.FormClosing += (o, e) => source.Cancel();
                form.Load += (o, e) => Run(new DrawingSystem(form, manager), systems, source.Token);

                Application.Run(form);
            }
        }