示例#1
0
        public void TestReset()
        {
            HystrixTimer   timer = HystrixTimer.GetInstance();
            TestListener   l1    = new TestListener(50, "A");
            TimerReference tref  = timer.AddTimerListener(l1);

            Task ex = tref._timerTask;

            Assert.False(ex.IsCanceled);

            Time.WaitUntil(() => { return(ex.Status == TaskStatus.Running); }, 200);

            // perform reset which should shut it down
            HystrixTimer.Reset();

            Time.Wait(50);

            Assert.True(ex.IsCompleted);
            Assert.Null(tref._timerTask);

            // assert it starts up again on use
            TestListener   l2    = new TestListener(50, "A");
            TimerReference tref2 = timer.AddTimerListener(l2);

            Task ex2 = tref2._timerTask;

            Assert.False(ex2.IsCanceled);

            // reset again to shutdown what we just started
            HystrixTimer.Reset();
            // try resetting again to make sure it's idempotent (ie. doesn't blow up on an NPE)
            HystrixTimer.Reset();
        }
示例#2
0
        private object ReadParameter(BitStream s, ParameterDefinition paramDefinition)
        {
            IParameter param = null;

            switch (paramDefinition.ParameterType)
            {
            case ParameterType.Float: { param = new FloatValue(); } break;

            case ParameterType.EntityFilter: { param = new EntityFilter(); } break;

            case ParameterType.GenericReference: { param = new GenericReference(); } break;

            case ParameterType.IntegerReference: { param = new IntegerReference(); } break;

            case ParameterType.Meter: { param = new MeterData(); } break;

            case ParameterType.ObjectReference: { param = new ObjectReference(); } break;

            case ParameterType.PlayerReference: { param = new PlayerReference(); } break;

            case ParameterType.Shape: { param = new BoundaryData(); } break;

            case ParameterType.StringReference: { param = new StringReference(); } break;

            case ParameterType.StringReferenceOneToken: { param = new StringReferenceOneToken(); } break;

            case ParameterType.StringReferenceTwoTokens: { param = new StringReferenceTwoTokens(); } break;

            case ParameterType.StringReferenceThreeTokens: { param = new StringReferenceThreeTokens(); } break;

            case ParameterType.TargetReference: { param = new TargetReference(); } break;

            case ParameterType.TeamReference: { param = new TeamReference(); } break;

            case ParameterType.TimerReference: { param = new TimerReference(); } break;

            case ParameterType.VirtualTrigger: { param = new VirtualTrigger(); } break;

            case ParameterType.WaypointIcon: { param = new WaypointIconData(); } break;

            case ParameterType.Coordinates3d: { param = new Coordinates3d(); } break;

            case ParameterType.Boolean:
                return(s.Reader.ReadBit());

            default:
                object value = 0;
                StreamIntegerValue(s, paramDefinition, ref value);
                return(value);
            }

            if (param != null)
            {
                param.SerializeObject(s, paramDefinition);
            }

            return(param);
        }
示例#3
0
 /// <summary>
 ///     This function save someuser (Need to implement).
 /// </summary>
 /// <param name="state"></param>
 private void Save(object state)
 {
     m_vDatabase.Save(ResourcesManager.GetInMemoryLevels());
     m_vDatabase.Save(m_vAlliances.Values.ToList());
     if (m_vTimerCanceled)
     {
         TimerReference.Dispose();
     }
 }
示例#4
0
        public void TimerReference_CallsListenerOnTime()
        {
            Stopwatch      stopWatch      = new Stopwatch();
            TestListener   listener       = new TestListener(stopWatch);
            TimerReference timerReference = new TimerReference(listener, TimeSpan.FromMilliseconds(1000));

            stopWatch.Start();
            timerReference.Start();
            Time.WaitUntil(() => { return(!stopWatch.IsRunning); }, 2000);
            Assert.InRange(stopWatch.ElapsedMilliseconds, 950, 1000 + 200);
        }
示例#5
0
        public void TestSingleCommandRemoveListener()
        {
            HystrixTimer timer = HystrixTimer.GetInstance();
            TestListener l1    = new TestListener(50, "A");

            timer.AddTimerListener(l1);

            TestListener   l2    = new TestListener(50, "B");
            TimerReference l2ref = timer.AddTimerListener(l2);

            try
            {
                Time.Wait(500);
            }
            catch (Exception e)
            {
                output.WriteLine(e.ToString());
            }

            // we should have 7 or more 50ms ticks within 500ms
            output.WriteLine("l1 ticks: " + l1.TickCount.Value);
            output.WriteLine("l2 ticks: " + l2.TickCount.Value);
            Assert.True(l1.TickCount.Value > 7);
            Assert.True(l2.TickCount.Value > 7);

            // remove l2
            l2ref.Dispose();

            // reset counts
            l1.TickCount.Value = 0;
            l2.TickCount.Value = 0;

            // wait for time to pass again
            try
            {
                Time.Wait(500);
            }
            catch (Exception e)
            {
                output.WriteLine(e.ToString());
            }

            // we should have 7 or more 50ms ticks within 500ms
            output.WriteLine("l1 ticks: " + l1.TickCount.Value);
            output.WriteLine("l2 ticks: " + l2.TickCount.Value);

            // l1 should continue ticking
            Assert.True(l1.TickCount.Value > 7);

            // we should have no ticks on l2 because we removed it
            output.WriteLine("tickCount.Value: " + l2.TickCount.Value + " on l2: " + l2);
            Assert.Equal(0, l2.TickCount.Value);
        }
示例#6
0
        public void Timer_SingleCommandRemoveListener()
        {
            HystrixTimer timer = HystrixTimer.Instance;
            TestListener l1    = new TestListener(50, "A");

            timer.AddTimerListener(l1);

            TestListener   l2    = new TestListener(50, "B");
            TimerReference l2ref = timer.AddTimerListener(l2);

            try
            {
                Thread.Sleep(500);
            }
            catch (ThreadInterruptedException e)
            {
                Console.WriteLine(e.ToString());
            }

            // we should have 7 or more 50ms ticks within 500ms
            Console.WriteLine("l1 ticks: " + l1.TickCount);
            Console.WriteLine("l2 ticks: " + l2.TickCount);
            Assert.IsTrue(l1.TickCount.Value > 7);
            Assert.IsTrue(l2.TickCount.Value > 7);

            // remove l2
            l2ref.Clear();

            // reset counts
            l1.TickCount.Value = 0;
            l2.TickCount.Value = 0;

            // wait for time to pass again
            try
            {
                Thread.Sleep(500);
            }
            catch (ThreadInterruptedException e)
            {
                Console.WriteLine(e.ToString());
            }

            // we should have 7 or more 50ms ticks within 500ms
            Console.WriteLine("l1 ticks: " + l1.TickCount);
            Console.WriteLine("l2 ticks: " + l2.TickCount);
            // l1 should continue ticking
            Assert.IsTrue(l1.TickCount.Value > 7);
            // we should have no ticks on l2 because we removed it
            Console.WriteLine("tickCount.get(): " + l2.TickCount + " on l2: " + l2);
            Assert.AreEqual(0, l2.TickCount);
        }
示例#7
0
        public void OnGameModeInit(ITimerService timerService)
        {
            _stopwatch1.Start();
            _stopwatch2.Start();

            TimerReference timer = null;

            timer = timerService.Start(_ =>
            {
                if (++_readonlyTicks == 3)
                {
                    Console.WriteLine("Stop timer");
                    timerService.Stop(timer);
                }
                Console.WriteLine($"Manual timer {_stopwatch2.Elapsed}");
                _stopwatch2.Restart();
            }, TimeSpan.FromSeconds(0.1));
        }
示例#8
0
        public static void main(String[] args)
        {
            PlayListener l1 = new PlayListener();
            PlayListener l2 = new PlayListener();
            PlayListener l3 = new PlayListener();
            PlayListener l4 = new PlayListener();
            PlayListener l5 = new PlayListener();

            TimerReference reference = HystrixTimer.Instance.AddTimerListener(l1);

            HystrixTimer.Instance.AddTimerListener(l2);
            HystrixTimer.Instance.AddTimerListener(l3);

            HystrixTimer.Instance.AddTimerListener(l4);

            try
            {
                Thread.Sleep(5000);
            }
            catch (ThreadInterruptedException e)
            {
                Console.WriteLine(e.ToString());
            }

            reference.Clear();
            HystrixTimer.Instance.AddTimerListener(l5);

            try
            {
                Thread.Sleep(10000);
            }
            catch (ThreadInterruptedException e)
            {
                Console.WriteLine(e.ToString());
            }

            Console.WriteLine("counter: " + l1.Counter);
            Console.WriteLine("counter: " + l2.Counter);
            Console.WriteLine("counter: " + l3.Counter);
            Console.WriteLine("counter: " + l4.Counter);
            Console.WriteLine("counter: " + l5.Counter);
        }
示例#9
0
        private GameType CreateMegaloGametype(GameType gametype, uint time)
        {
            // heuheuheuheuheu
            gametype.TimeLimit = time - 1;

            // string table her dongle so hard
            gametype.Name = new StringTable(string.Format("{0}/{1} - Yrs2013", _cityA, _cityB));

            // setup teams
            #region setup teams
            gametype.TeamsEnabled = true;
            gametype.TeamChanging = TeamChangingMode.Disabled;
            #endregion
            #region global variable declaration
            var currentTeamIndex = gametype.Script.GlobalVariables.Integers.Count;
            gametype.Script.GlobalVariables.Integers.Add(new IntegerVariableDefinition(0, NetworkPriority.High));

            var currentDataPointIndex = gametype.Script.GlobalVariables.Integers.Count;
            gametype.Script.GlobalVariables.Integers.Add(new IntegerVariableDefinition(0, NetworkPriority.High));

            var updateNextDataPoint = gametype.Script.GlobalVariables.Integers.Count;
            gametype.Script.GlobalVariables.Integers.Add(new IntegerVariableDefinition(1, NetworkPriority.High));

            var updateTimerIndex = gametype.Script.GlobalVariables.Timers.Count;
            gametype.Script.GlobalVariables.Timers.Add(new TimerVariableDefinition(0));
            #endregion
            #region trait creation
            var traitIndex = gametype.MegaloTraits.Count;
            gametype.MegaloTraits.Add(new MegaloTraits
            {
                WaypointVisible  = HUDVisibility.VisibleToEveryone,
                DamageMultiplier = (Modifier)1.6,
                PlayerScale      = (Modifier)2.0,
                JumpHeight       = (Modifier)2.0
            });
            #endregion

            // ************************************************************************************
            // To All Megalo Script Under Here ****************************************************
            // ************************************************************************************

            var initTrigger = new MegaloTrigger();
            #region trigger_data
            {
                Megalo.SetMegaloAction("var_operation", initTrigger,
                                       new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("result", new GenericReference(TimerReference.ForGlobal(updateTimerIndex))),
                    Megalo.CreateCondition("value", new GenericReference(IntegerReference.ForConstant(5))),
                    Megalo.CreateCondition("operation", OperationType.Set)
                });

                Megalo.SetMegaloAction("timer_set_rate", initTrigger,
                                       new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("timer", TimerReference.ForGlobal(updateTimerIndex)),
                    Megalo.CreateCondition("rate", 5)
                });

                gametype.Script.EntryPoints.InitTrigger = initTrigger;
                gametype.Script.Triggers.Add(initTrigger);
            }
            #endregion

            var trySetTraitsToTeam0 = new MegaloTrigger {
                EnumType = TriggerEnumType.EnumPlayers
            };
            #region trigger_data
            {
                var setPlayerTraits = Megalo.SetMegaloAction("player_set_traits", trySetTraitsToTeam0, new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("player", PlayerReference.ForGlobal(PlayerVariableType.CurrentPlayer)),
                    Megalo.CreateCondition("traits_index", traitIndex)
                });

                Megalo.SetMegaloCondition("compare", trySetTraitsToTeam0, setPlayerTraits, new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("value1", new GenericReference(IntegerReference.ForGlobal(currentTeamIndex))),
                    Megalo.CreateCondition("value2", new GenericReference(IntegerReference.ForConstant(0))),
                    Megalo.CreateCondition("comparison", ComparisonType.Equal)
                });

                Megalo.SetMegaloCondition("compare", trySetTraitsToTeam0, setPlayerTraits, new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("value1", new GenericReference(TeamReference.ForPlayerOwnerTeam(PlayerVariableType.CurrentPlayer))),
                    Megalo.CreateCondition("value2", new GenericReference(TeamReference.ForGlobal(TeamVariableType.Direct, 0))),
                    Megalo.CreateCondition("comparison", ComparisonType.Equal)
                }, 1);

                gametype.Script.Triggers.Add(trySetTraitsToTeam0);
            }
            #endregion

            var trySetTraitsToTeam1 = new MegaloTrigger {
                EnumType = TriggerEnumType.EnumPlayers
            };
            #region trigger_data
            {
                var setPlayerTraits = Megalo.SetMegaloAction("player_set_traits", trySetTraitsToTeam1, new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("player", PlayerReference.ForGlobal(PlayerVariableType.CurrentPlayer)),
                    Megalo.CreateCondition("traits_index", traitIndex)
                });

                Megalo.SetMegaloCondition("compare", trySetTraitsToTeam1, setPlayerTraits, new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("value1", new GenericReference(IntegerReference.ForGlobal(currentTeamIndex))),
                    Megalo.CreateCondition("value2", new GenericReference(IntegerReference.ForConstant(1))),
                    Megalo.CreateCondition("comparison", ComparisonType.Equal)
                });

                Megalo.SetMegaloCondition("compare", trySetTraitsToTeam1, setPlayerTraits, new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("value1", new GenericReference(TeamReference.ForPlayerOwnerTeam(PlayerVariableType.CurrentPlayer))),
                    Megalo.CreateCondition("value2", new GenericReference(TeamReference.ForGlobal(TeamVariableType.Direct, 1))),
                    Megalo.CreateCondition("comparison", ComparisonType.Equal)
                }, 1);

                gametype.Script.Triggers.Add(trySetTraitsToTeam1);
            }
            #endregion

            var updateDataPointEntryTrigger = new MegaloTrigger();
            #region trigger_data
            {
                // start action
                var resetNeedUpdateDataPoint = Megalo.SetMegaloAction("var_operation", updateDataPointEntryTrigger,
                                                                      new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("result", new GenericReference(IntegerReference.ForGlobal(updateNextDataPoint))),
                    Megalo.CreateCondition("value", new GenericReference(IntegerReference.ForConstant(0))),
                    Megalo.CreateCondition("operation", OperationType.Set)
                });

                var index = 0;
                foreach (var dataPoint in _session.DataPoints)
                {
                    var constructedMegaloTrigger = new MegaloTrigger();
                    {
                        MegaloAction startAction;
                        var          winner = "";
                        if (dataPoint.CityARating > dataPoint.CityBRating)
                        {
                            winner = _session.CityA;

                            startAction = Megalo.SetMegaloAction("var_operation", constructedMegaloTrigger,
                                                                 new List <KeyValuePair <string, object> >
                            {
                                Megalo.CreateCondition("result",
                                                       new GenericReference(IntegerReference.ForGlobal(currentTeamIndex))),
                                Megalo.CreateCondition("value",
                                                       new GenericReference(IntegerReference.ForConstant(0))),
                                Megalo.CreateCondition("operation", OperationType.Set)
                            });
                        }
                        else if (dataPoint.CityARating < dataPoint.CityBRating)
                        {
                            winner = _session.CityB;

                            startAction = Megalo.SetMegaloAction("var_operation", constructedMegaloTrigger,
                                                                 new List <KeyValuePair <string, object> >
                            {
                                Megalo.CreateCondition("result",
                                                       new GenericReference(IntegerReference.ForGlobal(currentTeamIndex))),
                                Megalo.CreateCondition("value",
                                                       new GenericReference(IntegerReference.ForConstant(1))),
                                Megalo.CreateCondition("operation", OperationType.Set)
                            });
                        }
                        else
                        {
                            winner = _session.CityA;

                            startAction = Megalo.SetMegaloAction("var_operation", constructedMegaloTrigger,
                                                                 new List <KeyValuePair <string, object> >
                            {
                                Megalo.CreateCondition("result",
                                                       new GenericReference(IntegerReference.ForGlobal(currentTeamIndex))),
                                Megalo.CreateCondition("value",
                                                       new GenericReference(IntegerReference.ForConstant(0))),
                                Megalo.CreateCondition("operation", OperationType.Set)
                            });
                        }



                        var str           = new StringReference(gametype.MegaloStrings.Add(string.Format("Current Winner Is: {0}!", winner)));
                        var effectMessage = new MegaloAction("chud_message");
                        effectMessage.Arguments.Set("target", TargetReference.All);
                        effectMessage.Arguments.Set("sound_index", -1);
                        effectMessage.Arguments.Set("text", str);
                        constructedMegaloTrigger.Actions.Add(effectMessage);

                        // call if swag is gucci
                        Megalo.SetMegaloCondition("compare", constructedMegaloTrigger, startAction,
                                                  new List <KeyValuePair <string, object> >
                        {
                            Megalo.CreateCondition("value1", new GenericReference(IntegerReference.ForGlobal(currentDataPointIndex))),
                            Megalo.CreateCondition("value2", new GenericReference(IntegerReference.ForConstant((short)index))),
                            Megalo.CreateCondition("comparison", ComparisonType.Equal)
                        });
                    }
                    var callConstructedMegaloTrigger = MegaloAction.ForTriggerCall(constructedMegaloTrigger);
                    updateDataPointEntryTrigger.Actions.Add(callConstructedMegaloTrigger);

                    index++;
                }

                Megalo.SetMegaloAction("var_operation", updateDataPointEntryTrigger,
                                       new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("result", new GenericReference(IntegerReference.ForGlobal(currentDataPointIndex))),
                    Megalo.CreateCondition("value", new GenericReference(IntegerReference.ForConstant(1))),
                    Megalo.CreateCondition("operation", OperationType.Add)
                });

                Megalo.SetMegaloCondition("compare", updateDataPointEntryTrigger, resetNeedUpdateDataPoint,
                                          new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("value1", new GenericReference(IntegerReference.ForGlobal(updateNextDataPoint))),
                    Megalo.CreateCondition("value2", new GenericReference(IntegerReference.ForConstant(1))),
                    Megalo.CreateCondition("comparison", ComparisonType.Equal)
                });

                gametype.Script.Triggers.Add(updateDataPointEntryTrigger);
            }
            #endregion

            var dealWithTheTimerTrigger = new MegaloTrigger();
            #region trigger_data
            {
                // check timer has expired, if it has, set a variable and start it again
                var setTimer = Megalo.SetMegaloAction("var_operation", dealWithTheTimerTrigger,
                                                      new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("result", new GenericReference(TimerReference.ForGlobal(updateTimerIndex))),
                    Megalo.CreateCondition("value", new GenericReference(IntegerReference.ForConstant(3))),
                    Megalo.CreateCondition("operation", OperationType.Set)
                });

                Megalo.SetMegaloAction("timer_set_rate", dealWithTheTimerTrigger,
                                       new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("timer", TimerReference.ForGlobal(updateTimerIndex)),
                    Megalo.CreateCondition("rate", 5)
                });

                // set variable
                Megalo.SetMegaloAction("var_operation", dealWithTheTimerTrigger,
                                       new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("result", new GenericReference(IntegerReference.ForGlobal(updateNextDataPoint))),
                    Megalo.CreateCondition("value", new GenericReference(IntegerReference.ForConstant(1))),
                    Megalo.CreateCondition("operation", OperationType.Set)
                });

                Megalo.SetMegaloCondition("timer_is_zero", dealWithTheTimerTrigger, setTimer,
                                          new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("timer", TimerReference.ForGlobal(updateTimerIndex))
                });

                gametype.Script.Triggers.Add(dealWithTheTimerTrigger);
            }
            #endregion

            var roundEndingTimer = new MegaloTrigger();
            #region trigger_data
            {
                var endRound = Megalo.SetMegaloAction("round_end", roundEndingTimer);

                Megalo.SetMegaloCondition("timer_is_zero", roundEndingTimer, endRound,
                                          new List <KeyValuePair <string, object> >
                {
                    Megalo.CreateCondition("timer", TimerReference.RoundTimer)
                });

                gametype.Script.Triggers.Add(roundEndingTimer);
            }
            #endregion

            return(gametype);
        }