Exemplo n.º 1
0
        private void LogPositions(double time)
        {
            if (world.LoggingPositionObjectIds.Count == 0)
            {
                return;
            }


            Debugger.Log("Logging positions at " + CurrentTime);
            var engine = world.GetEngine <ICommonEngine>();
            var data   = world.LoggingPositionObjectIds
                         .Where(z => engine.ContainBody(z))
                         .ToDictionary(z => z, z => engine.GetAbsoluteLocation(z));

            var entry = new GameLogEntry
            {
                Time = CurrentTime,
                Type = GameLogEntryType.LocationCorrection,
                LocationCorrection = new LocationCorrectionLogEntry
                {
                    Locations = data
                }
            };

            AddEntry(entry);
        }
Exemplo n.º 2
0
        private void Play(GameLogEntry obj)
        {
            if (obj.Type == GameLogEntryType.EngineInvocation)
            {
                if (obj.EngineInvocation == null)
                {
                    throw new Exception("Line type is EngineInvocation, but the section EngineInvokation was empty");
                }
                if (!engines.ContainsKey(obj.EngineInvocation.EngineName))
                {
                    throw new Exception("Can not find engine with a name " + obj.EngineInvocation.EngineName);
                }
                var method = engines[obj.EngineInvocation.EngineName].GetType().GetMethod(obj.EngineInvocation.MethodName);
                if (method == null)
                {
                    throw new Exception("Can not find method " + obj.EngineInvocation.MethodName + " in the engine " + obj.EngineInvocation.EngineName);
                }
                object[] arguments = ParseArguments(obj.EngineInvocation.MethodName, obj.EngineInvocation.Arguments, method.GetParameters());
                method.Invoke(engines[obj.EngineInvocation.EngineName], arguments);
            }

            if (obj.Type == GameLogEntryType.LocationCorrection)
            {
                if (obj.LocationCorrection == null)
                {
                    throw new Exception("Line type is LocationCorrection, but the section LocationCorrection was empty");
                }
                foreach (var e in obj.LocationCorrection.Locations)
                {
                    if (!commonEngine.ContainBody(e.Key))
                    {
                        throw new Exception("Location update is defined for " + e.Key + " but it is absent at the map");
                    }
                    else
                    {
                        commonEngine.SetAbsoluteLocation(e.Key, e.Value);
                    }
                }
            }

            if (obj.Type == GameLogEntryType.ScoresUpdate)
            {
                if (obj.ScoresUpdate == null)
                {
                    throw new Exception("Line type is ScoresUpdate, but the section ScoresUpdate was empty");
                }

                ScoreProvider.UpdateScores(obj.ScoresUpdate);
            }
        }
Exemplo n.º 3
0
        public void AddOutgoingSensorData(string controllerId, object sensorData)
        {
            var entry = new GameLogEntry
            {
                Time = CurrentTime,
                Type = GameLogEntryType.OutgoingSensorData,
                OutgoingSensorData = new OutgoingSensorDataCommandLogEntry
                {
                    ControllerId = controllerId,
                    SensorData   = JObject.FromObject(sensorData)
                }
            };

            AddEntry(entry);
        }
Exemplo n.º 4
0
        public void AddIncomingCommand(string controllerId, object command)
        {
            var entry = new GameLogEntry
            {
                Time            = CurrentTime,
                Type            = GameLogEntryType.IncomingCommand,
                IncomingCommand = new IncomingCommandLogEntry
                {
                    Command      = JObject.FromObject(command),
                    ControllerId = controllerId
                }
            };

            AddEntry(entry);
        }
Exemplo n.º 5
0
        public void AddMethodInvocation(Type engine, string method, params object[] arguments)
        {
            var entry = new GameLogEntry
            {
                Time             = CurrentTime,
                Type             = GameLogEntryType.EngineInvocation,
                EngineInvocation = new EngineInvocationLogEntry
                {
                    EngineName = engine.Name,
                    MethodName = method,
                    Arguments  = arguments.Select(z => z.ToString()).ToArray()
                }
            };

            AddEntry(entry);
        }
Exemplo n.º 6
0
        private void Scores_ScoresChanged(string controllerId, int count, string reason, string type, int total)
        {
            var entry = new GameLogEntry
            {
                Time         = CurrentTime,
                Type         = GameLogEntryType.ScoresUpdate,
                ScoresUpdate = new ScoresUpdate
                {
                    ControllerId = controllerId,
                    Added        = count,
                    Reason       = reason,
                    Total        = total,
                    Type         = type,
                }
            };

            AddEntry(entry);
        }
Exemplo n.º 7
0
 private void AddEntry(GameLogEntry entry)
 {
     log.Add(entry);
 }