forked from sashavol/Frozlunky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
new_game_detector.h
55 lines (44 loc) · 1.22 KB
/
new_game_detector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#pragma once
#include "patches.h"
#include "game_hooks.h"
#include <functional>
#include <chrono>
#define NG_STATE_WAITING 1
#define NG_STATE_WAITING2 2
#define NG_STATE_COMPLETED 4
//a light-weight one time disposable detector for a new spelunky game
class NewGameDetector {
public:
typedef std::function<void()> newgame_callback;
typedef std::function<void(bool)> potential_init_callback;
private:
typedef std::chrono::high_resolution_clock::time_point time_point;
potential_init_callback init_cb;
newgame_callback newgame_cb;
std::shared_ptr<GameHooks> hooks;
int init_state;
time_point waiting_point;
bool is_empty;
public:
NewGameDetector(std::shared_ptr<GameHooks> hooks, newgame_callback ng, potential_init_callback uncertain_init) :
init_cb(uncertain_init),
newgame_cb(ng),
hooks(hooks),
init_state(NG_STATE_WAITING)
{
is_empty = !hooks || (!ng && !uncertain_init);
}
NewGameDetector(std::shared_ptr<GameHooks> hooks, newgame_callback ng) :
newgame_cb(ng),
hooks(hooks),
init_state(NG_STATE_WAITING)
{
is_empty = !hooks || !ng;
}
//empty ngd
NewGameDetector() : is_empty(true) {}
bool empty() {
return is_empty;
}
void cycle();
};