forked from codex31373/HPC_FMI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_data_oriented_design.hpp
executable file
·102 lines (85 loc) · 2.65 KB
/
test_data_oriented_design.hpp
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
92
93
94
95
96
97
98
99
100
101
102
#pragma once
#include "diffclock.h"
namespace DataOrientedDesign {
struct MobBool {
MobBool() {
canJump = randomInt(0, 1);
canSwim = randomInt(0, 1);
canFly = randomInt(0, 1);
canRun = randomInt(0, 1);
canBite = randomInt(0, 1);
canShoot = randomInt(0, 1);
}
bool canJump;
bool canSwim;
float life;
float damage;
float size[3];
bool canFly;
int numLegs;
bool canRun;
bool canBite;
bool canShoot;
};
struct MobFlags {
enum {
CAN_JUMP = 1 << 0,
CAN_SWIM = 1 << 1,
CAN_FLY = 1 << 2,
CAN_RUN = 1 << 3,
CAN_BITE = 1 << 4,
CAN_SHOOT = 1 << 5,
LAST_FLAG = 1 << 6,
};
MobFlags() { flags = randomInt(0, LAST_FLAG) ;}
float life;
float damage;
int numLegs;
float size[3];
int flags;
bool canJump() const { return flags & CAN_JUMP; }
bool canSwim() const { return flags & CAN_SWIM; }
bool canFly() const { return flags & CAN_FLY; }
bool canRun() const { return flags & CAN_RUN; }
bool canBite() const { return flags & CAN_BITE; }
bool canShoot() const { return flags & CAN_SHOOT; }
};
bool isSuperMob(const MobBool& mob) {
return mob.canSwim && mob.canShoot && mob.canRun && mob.canJump && mob.canFly && mob.canBite;
}
bool isSuperMob(const MobFlags& mob) {
return mob.canSwim() && mob.canShoot() && mob.canRun() && mob.canJump() && mob.canFly() && mob.canBite();
}
size_t constexpr getTestSize() {
return 1_million;
}
void testMobBool() {
const auto TEST_SIZE = getTestSize();
std::unique_ptr<MobBool[]> mob(new MobBool[TEST_SIZE]);
bool areSuperMobs = true;
auto test0 = [&] {
for (auto i = 0; i < TEST_SIZE; ++i){
areSuperMobs &= isSuperMob(mob[i]);
}
};
ADD_BENCHMARK("DataOrientedDesign \t MobFlag", test0);
benchpress::run_benchmarks(benchpress::options());
}
void testMobFlags() {
const auto TEST_SIZE = getTestSize();
std::unique_ptr<MobFlags[]> mob(new MobFlags[TEST_SIZE]);
bool areSuperMobs = true;
auto test0 = [&] {
for (auto i = 0; i < TEST_SIZE; ++i){
areSuperMobs &= isSuperMob(mob[i]);
}
};
ADD_BENCHMARK("DataOrientedDesign \t MobBool", test0);
benchpress::run_benchmarks(benchpress::options());
}
void test() {
std::cout << "Testing data oriented design ..." << std::endl;
testMobBool();
testMobFlags();
}
}//namespace DataOrientedDesign