aboutsummaryrefslogtreecommitdiff
path: root/src/example
diff options
context:
space:
mode:
Diffstat (limited to 'src/example')
-rw-r--r--src/example/components_internal.cpp13
-rw-r--r--src/example/ecs.cpp18
-rw-r--r--src/example/physics.cpp9
-rw-r--r--src/example/rendering.cpp10
-rw-r--r--src/example/scene_manager.cpp4
5 files changed, 29 insertions, 25 deletions
diff --git a/src/example/components_internal.cpp b/src/example/components_internal.cpp
index ea1eaad..dd4c7df 100644
--- a/src/example/components_internal.cpp
+++ b/src/example/components_internal.cpp
@@ -23,17 +23,16 @@ using namespace std;
int main() {
dbg_trace();
- auto & mgr = ComponentManager::get_instance();
+ ComponentManager mgr{};
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);
+ 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();
@@ -45,10 +44,6 @@ int main() {
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
diff --git a/src/example/ecs.cpp b/src/example/ecs.cpp
index e61c398..9a008ea 100644
--- a/src/example/ecs.cpp
+++ b/src/example/ecs.cpp
@@ -9,13 +9,20 @@ using namespace crepe;
using namespace std;
int main() {
+ ComponentManager mgr{};
+
// Create a few GameObjects
try {
- GameObject body(0, "body", "person", Vector2{0, 0}, 0, 1);
- GameObject right_leg(1, "rightLeg", "person", Vector2{1, 1}, 0, 1);
- GameObject left_leg(2, "leftLeg", "person", Vector2{1, 1}, 0, 1);
- GameObject right_foot(3, "rightFoot", "person", Vector2{2, 2}, 0, 1);
- GameObject left_foot(4, "leftFoot", "person", Vector2{2, 2}, 0, 1);
+ GameObject & body
+ = mgr.new_object("body", "person", Vector2{0, 0}, 0, 1);
+ GameObject & right_leg
+ = mgr.new_object("rightLeg", "person", Vector2{1, 1}, 0, 1);
+ GameObject & left_leg
+ = mgr.new_object("leftLeg", "person", Vector2{1, 1}, 0, 1);
+ GameObject & right_foot
+ = mgr.new_object("rightFoot", "person", Vector2{2, 2}, 0, 1);
+ GameObject & left_foot
+ = mgr.new_object("leftFoot", "person", Vector2{2, 2}, 0, 1);
// Set the parent of each GameObject
right_foot.set_parent(right_leg);
@@ -30,7 +37,6 @@ int main() {
}
// Get the Metadata and Transform components of each GameObject
- ComponentManager & mgr = ComponentManager::get_instance();
vector<reference_wrapper<Metadata>> metadata
= mgr.get_components_by_type<Metadata>();
vector<reference_wrapper<Transform>> transform
diff --git a/src/example/physics.cpp b/src/example/physics.cpp
index 848f857..2ebf779 100644
--- a/src/example/physics.cpp
+++ b/src/example/physics.cpp
@@ -9,9 +9,11 @@ using namespace crepe;
using namespace std;
int main(int argc, char * argv[]) {
- GameObject * game_object;
- game_object = new GameObject(0, "Name", "Tag", Vector2{0, 0}, 0, 0);
- game_object->add_component<Rigidbody>(Rigidbody::Data{
+ ComponentManager mgr{};
+
+ GameObject & game_object
+ = mgr.new_object("Name", "Tag", Vector2{0, 0}, 0, 0);
+ game_object.add_component<Rigidbody>(Rigidbody::Data{
.mass = 1,
.gravity_scale = 1,
.body_type = Rigidbody::BodyType::DYNAMIC,
@@ -19,6 +21,5 @@ int main(int argc, char * argv[]) {
.use_gravity = true,
.bounce = false,
});
- delete game_object;
return 0;
}
diff --git a/src/example/rendering.cpp b/src/example/rendering.cpp
index 493169b..95d5dac 100644
--- a/src/example/rendering.cpp
+++ b/src/example/rendering.cpp
@@ -20,9 +20,12 @@ using namespace crepe;
int main() {
dbg_trace();
- auto obj = GameObject(0, "name", "tag", Vector2{0, 0}, 1, 1);
- auto obj1 = GameObject(1, "name", "tag", Vector2{500, 0}, 1, 0.1);
- auto obj2 = GameObject(2, "name", "tag", Vector2{800, 0}, 1, 0.1);
+ ComponentManager mgr{};
+ RenderSystem sys{mgr};
+
+ auto & obj = mgr.new_object("name", "tag", Vector2{0, 0}, 1, 1);
+ auto & obj1 = mgr.new_object("name", "tag", Vector2{500, 0}, 1, 0.1);
+ auto & obj2 = mgr.new_object("name", "tag", Vector2{800, 0}, 1, 0.1);
// Normal adding components
{
@@ -47,7 +50,6 @@ int main() {
}
*/
- auto & sys = crepe::AssetManager::get_instance();
auto start = std::chrono::steady_clock::now();
while (std::chrono::steady_clock::now() - start < std::chrono::seconds(5)) {
sys.update();
diff --git a/src/example/scene_manager.cpp b/src/example/scene_manager.cpp
index f46dc36..5cd7336 100644
--- a/src/example/scene_manager.cpp
+++ b/src/example/scene_manager.cpp
@@ -34,7 +34,8 @@ public:
};
int main() {
- SceneManager & scene_mgr = SceneManager::get_instance();
+ ComponentManager component_mgr{};
+ SceneManager scene_mgr{component_mgr};
// Add the scenes to the scene manager
scene_mgr.add_scene<ConcreteScene1>("scene1");
@@ -45,7 +46,6 @@ int main() {
scene_mgr.load_next_scene();
// Get the Metadata components of each GameObject of Scene1
- ComponentManager & component_mgr = ComponentManager::get_instance();
vector<reference_wrapper<Metadata>> metadata
= component_mgr.get_components_by_type<Metadata>();