Example #1
0
    public void GameOver()
    {
        NewCheckPoint();
        string output = string.Format("Run Completed\nTotal Time required {0}\nTotal Deaths {1}\n\n", totalTime, totalDeaths);

        StatLogger.GetInstance().WriteToFile(output);
    }
Example #2
0
 void Start()
 {
     //enable start menu
     menu.SetGameController(this);
     menu.Show();
     logger = StatLogger.GetInstance();
 }
Example #3
0
        private void LogSimStats(SimStats stats)
        {
            SimStatsPacket pack = new SimStatsPacket();

            pack.Region                = new SimStatsPacket.RegionBlock();
            pack.Region.RegionX        = stats.RegionX;
            pack.Region.RegionY        = stats.RegionY;
            pack.Region.RegionFlags    = stats.RegionFlags;
            pack.Region.ObjectCapacity = stats.ObjectCapacity;
            //pack.Region = //stats.RegionBlock;
            pack.Stat            = stats.StatsBlock;
            pack.Header.Reliable = false;

            // note that we are inside the reporter lock when called
            DateTime now = DateTime.Now;

            // hide some time information into the packet
            pack.Header.Sequence = (uint)now.Ticks;

            lock (m_statLockObject) // m_statLog is shared so make sure there is only executer here
            {
                try
                {
                    if (m_statLog == null || now > m_statLog.StartTime + m_statLogPeriod)
                    {
                        // First log file or time has expired, start writing to a new log file
                        if (m_statLog != null && m_statLog.Log != null)
                        {
                            m_statLog.Log.Close();
                        }
                        m_statLog           = new StatLogger();
                        m_statLog.StartTime = now;
                        m_statLog.Path      = (m_statsDir.Length > 0 ? m_statsDir + System.IO.Path.DirectorySeparatorChar.ToString() : "")
                                              + String.Format("stats-{0}.log", now.ToString("yyyyMMddHHmmss"));
                        m_statLog.Log = new BinaryWriter(File.Open(m_statLog.Path, FileMode.Append, FileAccess.Write));
                    }

                    // Write the serialized data to disk
                    if (m_statLog != null && m_statLog.Log != null)
                    {
                        m_statLog.Log.Write(pack.ToBytes());
                    }
                }
                catch (Exception ex)
                {
                    m_log.Error("statistics gathering failed: " + ex.Message, ex);
                    if (m_statLog != null && m_statLog.Log != null)
                    {
                        m_statLog.Log.Close();
                    }
                    m_statLog = null;
                }
            }
            return;
        }
Example #4
0
 public static StatLogger GetInstance()
 {
     // Lazily loaded singleton means statlogger created when first accessed
     if (instance == null)
     {
         lock (mutex)
         {
             if (instance == null)
             {
                 instance = new StatLogger();
             }
         }
     }
     return(instance);
 }
        void LogSimStats(SimStats stats)
        {
            SimStatsPacket pack = new SimStatsPacket {
                Region = stats.RegionBlock, Stat = stats.StatsBlock, Header = { Reliable = false }
            };

            // note that we are inside the reporter lock when called
            DateTime now = DateTime.Now;

            // hide some time information into the packet
            pack.Header.Sequence = (uint)now.Ticks;

            lock (m_statLockObject) // m_statLog is shared so make sure there is only executer here
            {
                try {
                    if (m_statLog == null || now > m_statLog.StartTime + m_statLogPeriod)
                    {
                        // First log file or time has expired, start writing to a new log file
                        if (m_statLog != null && m_statLog.Log != null)
                        {
                            m_statLog.Log.Close();
                        }
                        m_statLog = new StatLogger {
                            StartTime = now,
                            Path      = (m_statsDir.Length > 0
                                                        ? m_statsDir + Path.DirectorySeparatorChar
                                                        : "")
                                        + string.Format("stats-{0}.log", now.ToString("yyyyMMddHHmmss"))
                        };
                        m_statLog.Log = new BinaryWriter(File.Open(m_statLog.Path, FileMode.Append, FileAccess.Write));
                    }

                    // Write the serialized data to disk
                    if (m_statLog != null && m_statLog.Log != null)
                    {
                        m_statLog.Log.Write(pack.ToBytes());
                    }
                } catch (Exception ex) {
                    MainConsole.Instance.ErrorFormat("[Binary stats]: Statistics gathering failed: {0}", ex);
                    if (m_statLog != null && m_statLog.Log != null)
                    {
                        m_statLog.Log.Close();
                    }
                    m_statLog = null;
                }
            }
            return;
        }
        private void LogSimStats(SimStats stats)
        {
            SimStatsPacket pack = new SimStatsPacket();
            pack.Region = stats.RegionBlock;
            pack.Stat = stats.StatsBlock;
            pack.Header.Reliable = false;

            // note that we are inside the reporter lock when called
            DateTime now = DateTime.Now;

            // hide some time information into the packet
            pack.Header.Sequence = (uint)now.Ticks;

            lock (m_statLockObject) // m_statLog is shared so make sure there is only executer here
            {
                try
                {
                    if (m_statLog == null || now > m_statLog.StartTime + m_statLogPeriod)
                    {
                        // First log file or time has expired, start writing to a new log file
                        if (m_statLog != null && m_statLog.Log != null)
                        {
                            m_statLog.Log.Close();
                        }
                        m_statLog = new StatLogger();
                        m_statLog.StartTime = now;
                        m_statLog.Path = (m_statsDir.Length > 0 ? m_statsDir + System.IO.Path.DirectorySeparatorChar.ToString() : "")
                                + String.Format("stats-{0}.log", now.ToString("yyyyMMddHHmmss"));
                        m_statLog.Log = new BinaryWriter(File.Open(m_statLog.Path, FileMode.Append, FileAccess.Write));
                    }

                    // Write the serialized data to disk
                    if (m_statLog != null && m_statLog.Log != null)
                        m_statLog.Log.Write(pack.ToBytes());
                }
                catch (Exception ex)
                {
                    m_log.Error("statistics gathering failed: " + ex.Message, ex);
                    if (m_statLog != null && m_statLog.Log != null)
                    {
                        m_statLog.Log.Close();
                    }
                    m_statLog = null;
                }
            }
            return;
        }
Example #7
0
    void LogDetails()
    {
        string output = string.Format("Section {2} Complete\nTime required {0}\nDeaths {1}\n\n", CurrentTimer, CurrentDeaths, sectionNum);

        StatLogger.GetInstance().WriteToFile(output);
    }
Example #8
0
 public void StartRun()
 {
     StatLogger.GetInstance().WriteToFile("Starting new run");
     sectionNum = 0;
 }