<commit_before>#include "game.hpp"
#include "ws.hpp"
#include "outputEvent.hpp"

#include <iostream>
#include <chrono>
#include <thread>

struct Ticker {
  Ticker(unsigned tpsTarget);
  bool tick();
  double ticksPerSecond();

  typedef std::chrono::steady_clock clock_t;
  std::intmax_t iteration;
  bool first;
  clock_t::duration period;
  clock_t::time_point start;
};

Ticker::Ticker(unsigned tpsTarget) {
  iteration = 0;
  using namespace std::literals::chrono_literals;
  period = 1s;
  period /= tpsTarget;
}

bool Ticker::tick() {
  if (iteration == 0) {
    start = clock_t::now();
    first = false;
    iteration++;
  } else {
    auto fromStart = clock_t::now() - start;
    if (fromStart / period < iteration - 1) {
      iteration++;
      return true;
    }
    auto nextIterTime = (iteration++) * period;
    std::this_thread::sleep_for(nextIterTime - fromStart);
  }
  return false;
}

int main() {
  std::unique_ptr<IWsServer> ws(wsServer(8000));
  Game game;
  ws->run();
  std::cout << "Game started!\n";
  OutputEventBuffer b(game);
  Ticker ticker(25);
  for (;;) {
    ticker.tick();
    {
      auto input = ws->getInput();
      for (auto& event : *input)
        event->apply(game);
    }

    auto t0 = std::chrono::steady_clock::now();
    game.step();
    auto t1 = std::chrono::steady_clock::now();
    std::cout << std::chrono::duration_cast<std::chrono::duration<double>>(t1-t0).count() << "\n";

    for (auto player : game.players) {
      player->connection->send(b.modifyWorld(player));

      for (auto newCell : player->newCells)
        player->connection->send(b.ownsBlob(newCell));
      player->newCells.clear();

      if (ticker.iteration % 32 == 0)
        player->connection->send(b.top());<commit_msg>`Server slowdown` messages<commit_after>#include "game.hpp"
#include "ws.hpp"
#include "outputEvent.hpp"

#include <iostream>
#include <chrono>
#include <thread>

struct Ticker {
  Ticker(unsigned tpsTarget);
  bool tick();
  double ticksPerSecond();

  typedef std::chrono::steady_clock clock_t;
  std::intmax_t iteration;
  bool first;
  clock_t::duration period;
  clock_t::time_point start;
};

Ticker::Ticker(unsigned tpsTarget) {
  iteration = 0;
  using namespace std::literals::chrono_literals;
  period = 1s;
  period /= tpsTarget;
}

bool Ticker::tick() {
  if (iteration == 0) {
    start = clock_t::now();
    first = false;
    iteration++;
  } else {
    auto fromStart = clock_t::now() - start;
    auto nextIterTime = (iteration++) * period;
    if (nextIterTime < fromStart)
      return true;
    std::this_thread::sleep_for(nextIterTime - fromStart);
  }
  return false;
}

int main() {
  std::unique_ptr<IWsServer> ws(wsServer(8000));
  Game game;
  ws->run();
  std::cout << "Game started!\n";
  OutputEventBuffer b(game);
  Ticker ticker(25);
  for (;;) {
    if (ticker.tick())
      std::cout << "Server slowdown\n";
    {
      auto input = ws->getInput();
      for (auto& event : *input)
        event->apply(game);
    }

    game.step();

    for (auto player : game.players) {
      player->connection->send(b.modifyWorld(player));

      for (auto newCell : player->newCells)
        player->connection->send(b.ownsBlob(newCell));
      player->newCells.clear();

      if (ticker.iteration % 32 == 0)
        player->connection->send(b.top());
{'fraction_non_alphanumeric': 0.162406015037594, 'fraction_numerical': 0.008721804511278195, 'mean_word_length': 3.4704301075268815, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7067524', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1147, 'n_words': 239}