aboutsummaryrefslogtreecommitdiff
path: root/src/example/components_internal.cpp
diff options
context:
space:
mode:
authormax-001 <maxsmits21@kpnmail.nl>2024-10-16 08:35:17 +0200
committermax-001 <maxsmits21@kpnmail.nl>2024-10-16 08:35:17 +0200
commit5b158d9705f9e912f938f22f2389d6f1dc783b2a (patch)
tree7addd40affd1e15b5e6c4ea108847ef6a6eef7ea /src/example/components_internal.cpp
parent2f644ac353f65cd182be13549e32e9b9409f7aad (diff)
parent579824011d5e8776e2079d6624a39535517760ff (diff)
Merge remote-tracking branch 'origin/master' into max/POC-ECS-homemade
Diffstat (limited to 'src/example/components_internal.cpp')
-rw-r--r--src/example/components_internal.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/example/components_internal.cpp b/src/example/components_internal.cpp
new file mode 100644
index 0000000..54ce295
--- /dev/null
+++ b/src/example/components_internal.cpp
@@ -0,0 +1,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;
+}