<commit_before>#pragma once

#include "../dhash.h"
#include "../hearthstone.h"
#include "../generated_markers.h"

#include <QPixmap>
#include <QElapsedTimer>

#define ADD_GENERATED_MARKER(NAME, DEF) AddMarker(NAME, DEF##_PATH, DEF##_X, DEF##_Y, DEF##_WIDTH, DEF##_HEIGHT)

class Scene
{
private:
  class Marker {
  public:
    string name;
    dhash hash;
    int x, y, w, h; // virtual canvas attributes!

    Marker():name(""), x(0), y(0), w(0), h(0) {
    }

    Marker(const string& name, const string& templateImagePath, int x, int y, int w, int h)
      :name(name), x(x), y(y), w(w), h(h)
    {
      hash = dhash_for_pixmap(QPixmap(templateImagePath.c_str()));
    }
  };

  map<string, Marker> markers;
  string name;

  map<string, QElapsedTimer> timerForMarkers;

public:
  Scene(const string& name):name(name) {
    Init();
  }

  virtual ~Scene() {
  }

  void AddMarker(const string& name, const string& templateImagePath, int x, int y, int w, int h) {
    markers[name] = Marker(name, templateImagePath, x, y, w, h);
  }

  bool FindMarker(const string& name, qint64 findIntervalInMs = 300) {
    const Marker& marker = markers[name];
    const QPixmap& capture = Hearthstone::Instance()->Capture(marker.x, marker.y, marker.w, marker.h);
    dhash currentHash = dhash_for_pixmap(capture);
    bool similar = dhash_check_similarity(currentHash, marker.hash);

    // Due to noise and the resulting false positives
    // make sure the marker is found for a certain amount of ms
    // to ensure the marker is indeed the one we looked for
    QElapsedTimer& timerForMarker = timerForMarkers[name];

    if(similar) {
      if(!timerForMarker.isValid()) {
        timerForMarker.start();
      }
    } else {
      timerForMarker.invalidate();
    }

    return timerForMarker.isValid() && timerForMarker.hasExpired(findIntervalInMs);
  }

  virtual bool Active() = 0;

  virtual void Init() {
  }

  virtual void Update() {
  }

  const string& GetName() const {
    return name;<commit_msg>revert the marker detection to the old system<commit_after>#pragma once

#include "../dhash.h"
#include "../hearthstone.h"
#include "../generated_markers.h"

#include <QPixmap>
#include <QDateTime>

#define ADD_GENERATED_MARKER(NAME, DEF) AddMarker(NAME, DEF##_PATH, DEF##_X, DEF##_Y, DEF##_WIDTH, DEF##_HEIGHT)

class Scene
{
private:
  class Marker {
  public:
    string name;
    dhash hash;
    int x, y, w, h; // virtual canvas attributes!

    Marker():name(""), x(0), y(0), w(0), h(0) {
    }

    Marker(const string& name, const string& templateImagePath, int x, int y, int w, int h)
      :name(name), x(x), y(y), w(w), h(h)
    {
      hash = dhash_for_pixmap(QPixmap(templateImagePath.c_str()));
    }
  };

  map<string, Marker> markers;
  string name;

public:
  Scene(const string& name):name(name) {
    Init();
  }

  virtual ~Scene() {
  }

  void AddMarker(const string& name, const string& templateImagePath, int x, int y, int w, int h) {
    markers[name] = Marker(name, templateImagePath, x, y, w, h);
  }

  bool FindMarker(const string& name) {
    const Marker& marker = markers[name];
    const QPixmap& capture = Hearthstone::Instance()->Capture(marker.x, marker.y, marker.w, marker.h);
    dhash currentHash = dhash_for_pixmap(capture);
    bool similar = dhash_check_similarity(currentHash, marker.hash);
    return similar;
  }

  virtual bool Active() = 0;

  virtual void Init() {
  }

  virtual void Update() {
  }

  const string& GetName() const {
    return name;
{'fraction_non_alphanumeric': 0.14069634703196346, 'fraction_numerical': 0.004280821917808219, 'mean_word_length': 3.5578673602080624, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, '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': '4289423', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1195, 'n_words': 330}