aboutsummaryrefslogtreecommitdiff
path: root/src/example
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-13 18:46:06 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-13 18:46:06 +0100
commit0aa97807cb9b7f1d1850449dd5a5e45b961445ce (patch)
tree8f6a808669a39f5b8d91079ecb30c3d1f11e9e02 /src/example
parentbc2a31190b5afe7754b04e9c61fcda30e577d7d8 (diff)
fix scene_manager example
Diffstat (limited to 'src/example')
-rw-r--r--src/example/components_internal.cpp2
-rw-r--r--src/example/ecs.cpp15
-rw-r--r--src/example/physics.cpp3
-rw-r--r--src/example/rendering.cpp6
-rw-r--r--src/example/scene_manager.cpp25
-rw-r--r--src/example/script.cpp2
6 files changed, 26 insertions, 27 deletions
diff --git a/src/example/components_internal.cpp b/src/example/components_internal.cpp
index 7a8a08a..eeecdc0 100644
--- a/src/example/components_internal.cpp
+++ b/src/example/components_internal.cpp
@@ -30,7 +30,7 @@ int main() {
GameObject * game_object[OBJ_COUNT];
for (int i = 0; i < OBJ_COUNT; ++i) {
- GameObject & obj = mgr.new_object("Name", "Tag");
+ GameObject obj = mgr.new_object("Name", "Tag");
obj.add_component<Sprite>("test");
obj.add_component<Rigidbody>(0, 0, i);
}
diff --git a/src/example/ecs.cpp b/src/example/ecs.cpp
index 9a008ea..06fc563 100644
--- a/src/example/ecs.cpp
+++ b/src/example/ecs.cpp
@@ -13,16 +13,11 @@ int main() {
// Create a few GameObjects
try {
- 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);
+ 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);
diff --git a/src/example/physics.cpp b/src/example/physics.cpp
index 2ebf779..ad663a0 100644
--- a/src/example/physics.cpp
+++ b/src/example/physics.cpp
@@ -11,8 +11,7 @@ using namespace std;
int main(int argc, char * argv[]) {
ComponentManager mgr{};
- GameObject & game_object
- = mgr.new_object("Name", "Tag", Vector2{0, 0}, 0, 0);
+ 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,
diff --git a/src/example/rendering.cpp b/src/example/rendering.cpp
index 74c00e2..abd11b1 100644
--- a/src/example/rendering.cpp
+++ b/src/example/rendering.cpp
@@ -23,9 +23,9 @@ int main() {
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);
+ GameObject obj = mgr.new_object("name", "tag", Vector2{0, 0}, 1, 1);
+ GameObject obj1 = mgr.new_object("name", "tag", Vector2{500, 0}, 1, 0.1);
+ GameObject obj2 = mgr.new_object("name", "tag", Vector2{800, 0}, 1, 0.1);
// Normal adding components
{
diff --git a/src/example/scene_manager.cpp b/src/example/scene_manager.cpp
index 5cd7336..1c982aa 100644
--- a/src/example/scene_manager.cpp
+++ b/src/example/scene_manager.cpp
@@ -12,24 +12,26 @@ using namespace std;
class ConcreteScene1 : public Scene {
public:
- ConcreteScene1(string name) : Scene(name) {}
+ using Scene::Scene;
void load_scene() {
- GameObject object1(0, "scene_1", "tag_scene_1", Vector2{0, 0}, 0, 1);
- GameObject object2(1, "scene_1", "tag_scene_1", Vector2{1, 0}, 0, 1);
- GameObject object3(2, "scene_1", "tag_scene_1", Vector2{2, 0}, 0, 1);
+ auto & mgr = this->component_manager;
+ GameObject object1 = mgr.new_object("scene_1", "tag_scene_1", Vector2{0, 0}, 0, 1);
+ GameObject object2 = mgr.new_object("scene_1", "tag_scene_1", Vector2{1, 0}, 0, 1);
+ GameObject object3 = mgr.new_object("scene_1", "tag_scene_1", Vector2{2, 0}, 0, 1);
}
};
class ConcreteScene2 : public Scene {
public:
- ConcreteScene2(string name) : Scene(name) {}
+ using Scene::Scene;
void load_scene() {
- GameObject object1(0, "scene_2", "tag_scene_2", Vector2{0, 0}, 0, 1);
- GameObject object2(1, "scene_2", "tag_scene_2", Vector2{0, 1}, 0, 1);
- GameObject object3(2, "scene_2", "tag_scene_2", Vector2{0, 2}, 0, 1);
- GameObject object4(3, "scene_2", "tag_scene_2", Vector2{0, 3}, 0, 1);
+ auto & mgr = this->component_manager;
+ GameObject object1 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 0}, 0, 1);
+ GameObject object2 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 1}, 0, 1);
+ GameObject object3 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 2}, 0, 1);
+ GameObject object4 = mgr.new_object("scene_2", "tag_scene_2", Vector2{0, 3}, 0, 1);
}
};
@@ -41,7 +43,9 @@ int main() {
scene_mgr.add_scene<ConcreteScene1>("scene1");
scene_mgr.add_scene<ConcreteScene2>("scene2");
- // There is no need to call set_next_scene() at the beginnen, because the first scene will be automatically set as the next scene
+ // There is no need to call set_next_scene() at the beginning because the
+ // first scene will be automatically set as the next scene
+
// Load scene1 (the first scene added)
scene_mgr.load_next_scene();
@@ -73,3 +77,4 @@ int main() {
return 0;
}
+
diff --git a/src/example/script.cpp b/src/example/script.cpp
index c82764c..a23295b 100644
--- a/src/example/script.cpp
+++ b/src/example/script.cpp
@@ -39,7 +39,7 @@ int main() {
ScriptSystem system{component_manager};
// Create game object with Transform and BehaviorScript components
- auto & obj = component_manager.new_object("name");
+ GameObject obj = component_manager.new_object("name");
obj.add_component<BehaviorScript>().set_script<MyScript>();
// Update all scripts. This should result in MyScript::update being called