[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r4147 - branches/pingus-hanusz/src
From: |
grumbel |
Subject: |
[Pingus-CVS] r4147 - branches/pingus-hanusz/src |
Date: |
Thu, 12 May 2011 18:25:01 +0200 |
Author: grumbel
Date: 2011-05-12 18:25:01 +0200 (Thu, 12 May 2011)
New Revision: 4147
Added:
branches/pingus-hanusz/src/statistics.cpp
branches/pingus-hanusz/src/statistics.hpp
Modified:
branches/pingus-hanusz/src/result.hpp
Log:
Added statistic tracking
Modified: branches/pingus-hanusz/src/result.hpp
===================================================================
--- branches/pingus-hanusz/src/result.hpp 2011-05-12 16:24:30 UTC (rev
4146)
+++ branches/pingus-hanusz/src/result.hpp 2011-05-12 16:25:01 UTC (rev
4147)
@@ -48,7 +48,7 @@
/** Number of Pingus needed to save */
int needed;
- bool success() {
+ bool success() const {
return (saved >= needed);
}
};
Added: branches/pingus-hanusz/src/statistics.cpp
===================================================================
--- branches/pingus-hanusz/src/statistics.cpp (rev 0)
+++ branches/pingus-hanusz/src/statistics.cpp 2011-05-12 16:25:01 UTC (rev
4147)
@@ -0,0 +1,62 @@
+// Pingus - A free Lemmings clone
+// Copyright (C) 1998-2011 Ingo Ruhnke <address@hidden>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "result.hpp"
+
+#include "statistics.hpp"
+#include <stdexcept>
+
+Statistics* Statistics::s_instance = 0;
+
+Statistics::Statistics() :
+ m_filename("statistics.txt"),
+ m_username("<unset>")
+{
+
+}
+
+Statistics::~Statistics()
+{
+
+}
+
+void
+Statistics::set_username(const std::string& username)
+{
+ m_username = username;
+}
+
+void
+Statistics::save_result(const Result& result)
+{
+ //m_out << "# username, levelname, saved, killed, time, success" <<
std::endl;
+ std::ofstream m_out(m_filename.c_str(), std::ios::app);
+ if (!m_out)
+ {
+ throw std::runtime_error(m_filename + ": couldn't open file for writing");
+ }
+ else
+ {
+ m_out << m_username << ", "
+ << result.plf.get_resname() << ", "
+ << result.saved << ", "
+ << result.killed << ", "
+ << result.used_time << ", "
+ << (result.success()?"success":"failure") << std::endl;
+ }
+}
+
+/* EOF */
Property changes on: branches/pingus-hanusz/src/statistics.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Added: branches/pingus-hanusz/src/statistics.hpp
===================================================================
--- branches/pingus-hanusz/src/statistics.hpp (rev 0)
+++ branches/pingus-hanusz/src/statistics.hpp 2011-05-12 16:25:01 UTC (rev
4147)
@@ -0,0 +1,54 @@
+// Pingus - A free Lemmings clone
+// Copyright (C) 1998-2011 Ingo Ruhnke <address@hidden>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_PINGUS_STATISTICS_HPP
+#define HEADER_PINGUS_STATISTICS_HPP
+
+#include <fstream>
+
+class Result;
+
+class Statistics
+{
+private:
+ static Statistics* s_instance;
+public:
+ static Statistics* instance() {
+ if (s_instance)
+ return s_instance;
+ else
+ return s_instance = new Statistics;
+ }
+
+private:
+ std::string m_filename;
+ std::string m_username;
+
+public:
+ Statistics();
+ ~Statistics();
+
+ void set_username(const std::string& username);
+ void save_result(const Result& result);
+
+private:
+ Statistics(const Statistics&);
+ Statistics& operator=(const Statistics&);
+};
+
+#endif
+
+/* EOF */
Property changes on: branches/pingus-hanusz/src/statistics.hpp
___________________________________________________________________
Added: svn:eol-style
+ native
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r4147 - branches/pingus-hanusz/src,
grumbel <=