aboutsummaryrefslogtreecommitdiff
path: root/src/example/components_internal.cpp
blob: dd4c7dff1a996c8a94dcbf81806788ec9550594d (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
/** \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;
using namespace std;

#define OBJ_COUNT 100000

int main() {
	dbg_trace();

	ComponentManager mgr{};

	auto start_adding = chrono::high_resolution_clock::now();

	GameObject * game_object[OBJ_COUNT];

	for (int i = 0; i < OBJ_COUNT; ++i) {
		GameObject & obj = mgr.new_object("Name", "Tag");
		obj.add_component<Sprite>("test");
		obj.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();

	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;
}