blob: 3c689741c639a3a20595736df9ab4fac8b4cb45e (
plain)
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
|
/** \file
*
* Standalone example for usage of the internal ECS
*/
#include <cassert>
#include <chrono>
#include <crepe/Component.h>
#include <crepe/ComponentManager.h>
#include <crepe/api/GameObject.h>
#include <crepe/api/Rigidbody.h>
#include <crepe/api/Sprite.h>
#include <crepe/util/log.h>
using namespace crepe::api;
using namespace crepe;
using namespace std;
#define OBJ_COUNT 100000
int main() {
dbg_trace();
auto & mgr = ComponentManager::get_instance();
auto start_adding = chrono::high_resolution_clock::now();
GameObject * game_object[OBJ_COUNT];
for (int i = 0; i < OBJ_COUNT; ++i) {
game_object[i] = new GameObject(i, "Name", "Tag", 0);
game_object[i]->add_component<Sprite>("test");
game_object[i]->add_component<Rigidbody>(0, 0, i);
}
auto stop_adding = chrono::high_resolution_clock::now();
auto sprites = mgr.get_components_by_type<Sprite>();
for (auto sprite : sprites) {
assert(true);
}
auto stop_looping = chrono::high_resolution_clock::now();
for (int i = 0; i < OBJ_COUNT; ++i) {
delete game_object[i];
}
auto add_time = chrono::duration_cast<chrono::microseconds>(stop_adding
- start_adding);
auto loop_time = chrono::duration_cast<chrono::microseconds>(stop_looping
- stop_adding);
printf("add time: %ldus\n", add_time.count());
printf("loop time: %ldus\n", loop_time.count());
return 0;
}
|