Commits

Lars Viklund committed 0f87902

Build fixes, framerate stats

  • Participants
  • Parent commits ba25274

Comments (0)

Files changed (2)

 #!/usr/bin/env bash
 
-CXXFLAGS="
- -std=c++11
- -stdlib=libc++"
+if (type clang++ >/dev/null 2>&1); then
+	CC=clang
+	CXX=clang++
+	CXXFLAGS+=" -stdlib=libc++"
+else
+	CC=gcc
+	CXX=g++
+fi
+
+CXXFLAGS+="
+-std=c++11"
+
+CXXFLAGS+=" -O3"
 
 CPPFLAGS="
  -Isrc
- -I${HOME}/opt/clang-3.4-libc++/SFML-git/include"
+ -I${HOME}/opt/clang-3.4-libc++/SFML-git/include
+ -I${HOME}/lap/SFML/git/include"
 
 LDFLAGS="
  -L${HOME}/opt/clang-3.4-libc++/SFML-git/lib
+ -L${HOME}/lap/SFML/git/lib
+ -Wl,-rpath
+ -Wl,${HOME}/opt/clang-3.4-libc++/SFML-git/lib
  -Wl,-rpath
- -Wl,${HOME}/opt/clang-3.4-libc++/SFML-git/lib"
+ -Wl,${HOME}/lap/SFML/git/lib"
 
 slade_LIBS="
  -lsfml-audio
 
 # -lsfml-network
 
-clang++ \
+$CXX \
   ${CXXFLAGS} \
   ${CPPFLAGS} \
   ${LDFLAGS} \
 #include <sstream>
 #include <vector>
 
+struct InfoCollection
+{
+  struct InfoSink
+  {
+    std::shared_ptr<std::ostringstream> OSS;
+    std::shared_ptr<std::function<void (std::string)>> F;
+
+    template <typename Sink>
+    InfoSink(Sink F)
+    : F(std::make_shared<std::function<void (std::string)>>(F))
+    , OSS(std::make_shared<std::ostringstream>())
+    {}
+
+    ~InfoSink() {
+      (*F)(OSS->str());
+    }
+
+    template <typename T>
+    InfoSink const& operator << (T& Value) const {
+      *OSS << Value;
+      return *this;
+    }
+  };
+
+  std::map<std::string, std::string> Values;
+  InfoSink record(std::string Key) {
+    return InfoSink([&](std::string Value)
+    {
+      record(Key, Value);
+    });
+  }
+
+  void record(std::string Key, std::string Value) {
+    Values[Key] = Value;
+  }
+
+  std::string get(std::string Key) {
+    return Values[Key];
+  }
+};
+
 struct GameState {
   GameState() : Points(0) {}
   sf::Vector2f SledPosition;
   Solids.push_back({{0.0f, -4.0f, 0.0f}, {10.0f, 1.0f, 0.0f}});
 
   int64_t CurrentFrame = 0;
+  int64_t GraphicsFrames = 0;
   int64_t const DropCooldown = (int64_t)(0.5f*(1000.0f/SIM_FRAME_TIME));
   int64_t const DropSlop = (int64_t)(0.1f*(1000.0f/SIM_FRAME_TIME));
   int64_t LastDropFrame = std::numeric_limits<int64_t>::min();
   if (!Options.Mute) {
     BGM.play();
   }
+  InfoCollection Info;
+  int64_t FrameLastSecond = 0;
+  sf::Time LastSecond = Clock.getElapsedTime();
   while (true) {
     sf::Event Event;
     while (Window.pollEvent(Event)) {
       Window.draw(ScoreText, BoardTransform);
 #endif
       Window.display();
+      ++GraphicsFrames;
+      if ((Now - LastSecond).asSeconds() >= 1.0) {
+        auto Span = Now - LastSecond;
+        auto N = GraphicsFrames - FrameLastSecond;
+        double FrameRate = N/Span.asSeconds();
+        LastSecond = Now;
+        FrameLastSecond = GraphicsFrames;
+        Info.record("graphics.framerate") << FrameRate;
+        std::cerr << "graphics.framerate: " << Info.get("graphics.framerate") << "\n";
+      }
     }
   }
 }
 
-// vim: set ts=2 sw=2 et:
+// vim: set ts=2 sw=2 et cin: