-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
91 lines (71 loc) · 2.88 KB
/
main.cpp
File metadata and controls
91 lines (71 loc) · 2.88 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "engine/public/engine.h"
#include <iostream>
#include <chrono>
int main() {
std::cout << "Afterimage engine test\n";
// Create engine with basic config
afterimage::EngineConfig config{
60, // 60 Hz
1, // map_id
12345, // seed
8 // max_players
};
afterimage::Engine* engine = afterimage::engine_create(config);
std::cout << "Engine created, tick: " << afterimage::engine_tick_index(engine) << "\n";
// Test movement and dash with some inputs
afterimage::PlayerInput input;
input.player_id = 0;
input.frame.aim_q = 0; // aim right
std::cout << "Testing recording + replay...\n";
// Start recording
afterimage::engine_start_recording(engine);
// Generate some gameplay for 20 ticks
for (int i = 0; i < 20; ++i) {
// Simple input pattern
input.frame.buttons = (i % 4 == 0) ? afterimage::RIGHT : afterimage::UP;
input.frame.aim_q = 0;
afterimage::engine_apply_inputs(engine, &input, 1);
afterimage::engine_tick(engine);
}
afterimage::engine_stop_recording(engine);
// Get recorded data
uint32_t recorded_count;
const afterimage::TickRecord* recorded_ticks = afterimage::engine_get_recorded_ticks(engine, &recorded_count);
const afterimage::PlayerInput* recorded_inputs = afterimage::engine_get_recorded_inputs(engine);
std::cout << "Recorded " << recorded_count << " ticks\n";
// Test replay
afterimage::Engine* replay_engine = afterimage::engine_create(config);
afterimage::engine_start_replay(replay_engine, recorded_ticks, recorded_inputs, recorded_count);
bool replay_success = true;
uint32_t mismatch_tick = 0;
for (uint32_t i = 0; i < recorded_count; ++i) {
if (!afterimage::engine_replay_tick(replay_engine, &mismatch_tick)) {
std::cout << "Replay failed at tick " << mismatch_tick << "\n";
replay_success = false;
break;
}
}
std::cout << "Replay " << (replay_success ? "PASSED" : "FAILED") << "\n";
afterimage::engine_stop_replay(replay_engine);
afterimage::engine_destroy(replay_engine);
// Test determinism by resetting and running again
afterimage::engine_reset(engine, config);
uint64_t first_hash = afterimage::engine_state_hash(engine);
for (int i = 0; i < 10; ++i) {
afterimage::engine_tick(engine);
}
uint64_t second_hash = afterimage::engine_state_hash(engine);
afterimage::engine_reset(engine, config);
for (int i = 0; i < 10; ++i) {
afterimage::engine_tick(engine);
}
uint64_t third_hash = afterimage::engine_state_hash(engine);
std::cout << "Determinism check:\n";
std::cout << "First run final hash: " << first_hash << "\n";
std::cout << "Second run final hash: " << second_hash << "\n";
std::cout << "Third run final hash: " << third_hash << "\n";
std::cout << "Deterministic: " << (second_hash == third_hash ? "YES" : "NO") << "\n";
afterimage::engine_destroy(engine);
std::cout << "Engine destroyed\n";
return 0;
}