virtual public bool RegisterObject(VsConnectSolver vscObject)
        {
            bool retSuccess = false;

            //check(vscObject);

            if (vscObject != null)
            {
                var name = vscObject.VscObjectName;
                name.Trim();

                if (string.IsNullOrEmpty(name) == false)
                {
                    var numElementsRemoved = mVscObjects.Remove(name);
                    if (numElementsRemoved)
                    {
                        LogWarning(($"Registering VS Connect Object with duplicate name \"{name}\" (not case sensitive). Newly registered object will replace previously registered object."));
                    }

                    mVscObjects.Add(name, vscObject);

                    retSuccess = true;
                }
            }

            return(retSuccess);
        }
Beispiel #2
0
        /// <summary>
        /// Get value property constructer
        /// </summary>
        /// <param name="setSolver"></param>
        /// <param name="setName"></param>
        /// <param name="setFunc"></param>
        public VsConnectVar(VsConnectSolver setSolver, string setName, Func <T> setFunc) : base(setName, VsVarDirection.Output)
        {
            Check(setSolver != null);
            Check(setFunc != null);

            solver = setSolver;
            func   = setFunc;
        }
Beispiel #3
0
        /// <summary>
        /// Set value constructer
        /// </summary>
        /// <param name="setSolver"></param>
        /// <param name="setName"></param>
        /// <param name="setAction"></param>
        /// <param name="defaultValue"></param>
        public VsConnectVar(VsConnectSolver setSolver, string setName, Action <T> setAction, T defaultValue = default(T)) : base(setName, VsVarDirection.Input)
        {
            Check(setSolver != null);
            Check(setAction != null);

            solver    = setSolver;
            action    = setAction;
            lastValue = defaultValue;
        }
        virtual public bool DeregisterObject(VsConnectSolver vscObject)
        {
            bool retSuccess = false;

            //check(object);
            foreach (var key in mVscObjects.Keys)
            {
                if (mVscObjects[key] == vscObject)
                {
                    mVscObjects.Remove(key);
                    retSuccess = true;
                    break;
                }
            }

            return(retSuccess);
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            //Set VSPath to the execution path
            VsModule.VsPath = System.Windows.Forms.Application.StartupPath;
            //
            VsModule.VsEngineUserDir = System.IO.Path.Combine(VsModule.VsPath, "Engine");

            //VSConnectServer is enabled.
            VsModule.EnableVsConnectServer = true;
            //Start Module
            VsModule.StartupModule();


            //Server time(second)
            double worldTime = 0;

            ///Tick Interval time 1 second
            TimeSpan Interval = TimeSpan.FromSeconds(1);



            double nextWorldTime = 0;
            double clientTime    = 0;



            //get server object
            var server = VsConnectServer.Singleton;

            BestMedia.VsDotnet.VsUtility.Check(server != null);

            //Add Server object  and register object
            BestMedia.VsDotnet.VsConnectSolver serverSolver = new BestMedia.VsDotnet.VsConnectSolver()
            {
                VscObjectName = "ServerObject"
            };
            server.RegisterObject(serverSolver);


            //Add age name action. world Time second to minutes.
            serverSolver.GetDoubleFuncs.Add("Age", () => worldTime / 60);


            //Add Client object and register object
            BestMedia.VsDotnet.VsConnectSolver clientSolver = new BestMedia.VsDotnet.VsConnectSolver()
            {
                VscObjectName = "ClientObject"
            };
            server.RegisterObject(clientSolver);

            //Add age name funcrtion that set climent time
            clientSolver.SetDoubleActions.Add("Age", (v) => { clientTime = v; Log($"Client Age{clientTime:0.00}"); });


            //set loop start time
            DateTime LoopStartTime = DateTime.Now;



            while (true)
            {
                ///Calc world time;
                worldTime = (DateTime.Now - LoopStartTime).TotalSeconds;
                Log($"World Age{worldTime/60:0.00}[minutes]");

                //Tick server object
                server.Tick(worldTime, 1);

                //Calc next loop time
                nextWorldTime += Interval.TotalSeconds;
                worldTime      = (DateTime.Now - LoopStartTime).TotalSeconds;

                //Sleep time until next  time
                if (nextWorldTime > worldTime)
                {
                    System.Threading.Thread.Sleep((int)(1000 * (nextWorldTime - worldTime)));
                }

                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo consoleKey = Console.ReadKey(true);
                    if (consoleKey.Key == ConsoleKey.Q)
                    {
                        break;
                    }
                }
            }



            VsModule.ShutdownModule();
        }