//=============================================================================================================================
//
// Copyright (c) 2015-2022 VisionStar Information Technology (Shanghai) Co., Ltd. All Rights Reserved.
// EasyAR is the registered trademark or trademark of VisionStar Information Technology (Shanghai) Co., Ltd in China
// and other countries for the augmented reality technology developed by VisionStar Information Technology (Shanghai) Co., Ltd.
//
//=============================================================================================================================

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

namespace HelloAR
{
    public class Program
    {
        public static int Main(string[] args)
        {
            var isQuitedSource = new CancellationTokenSource();
            var isQuited = isQuitedSource.Token;

            var result = easyar.Engine.initialize("===PLEASE ENTER YOUR KEY HERE===");
            if (!result)
            {
                Console.WriteLine("Initialization failed.");
                return 1;
            }
            if (!easyar.CameraDevice.isAvailable())
            {
                Console.WriteLine("CameraDevice not available.");
                return 1;
            }
            if (!easyar.ImageTracker.isAvailable())
            {
                Console.WriteLine("ImageTracker not available.");
                return 1;
            }

            Console.CancelKeyPress += (sender, e) =>
            {
                isQuitedSource.Cancel();
                e.Cancel = true;
            };

            using (var helloAR = new HelloAR())
            {
                helloAR.start();
                while (!isQuited.IsCancellationRequested)
                {
                    Thread.Sleep(TimeSpan.FromMilliseconds(5));
                    helloAR.nextFrame();
                }
                helloAR.stop();
            }

            return 0;
        }
    }
}
