aboutsummaryrefslogtreecommitdiff
path: root/src/example/components_internal.cpp
blob: 54ce295f7812af71d8dff7ed5268b17145233c6a (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
/** \file
 * 
 * Standalone example for usage of the internal ECS
 */

#include <cassert>
#include <chrono>

#include <crepe/Collider.h>
#include <crepe/Component.h>
#include <crepe/ComponentManager.h>
#include <crepe/GameObject.h>
#include <crepe/Rigidbody.h>
#include <crepe/Sprite.h>
#include <crepe/util/log.h>

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);
		game_object[i]->add_component<Collider>(i);
	}

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

	auto sprites = mgr.get_components_by_type<Sprite>();
	for (auto sprite : sprites) {
		assert(sprite.get().path == "test");
	}

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