aboutsummaryrefslogtreecommitdiff
path: root/src/example
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-16 21:45:36 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-16 21:45:36 +0100
commit73598a9e7f49047d74ca439cb0f300099d8c03bf (patch)
treeef62148ac6769f169670a1e7f7fd8482045ef65f /src/example
parentd258fcc8efdb6a968a220c4590a204292a16ad42 (diff)
parent121b64b1cb6cfead5814070c8b0185d3d7308095 (diff)
merge `master` into `loek/audio`
Diffstat (limited to 'src/example')
-rw-r--r--src/example/asset_manager.cpp13
-rw-r--r--src/example/audio_internal.cpp3
-rw-r--r--src/example/components_internal.cpp8
-rw-r--r--src/example/ecs.cpp25
-rw-r--r--src/example/particles.cpp5
-rw-r--r--src/example/rendering.cpp6
-rw-r--r--src/example/scene_manager.cpp25
7 files changed, 31 insertions, 54 deletions
diff --git a/src/example/asset_manager.cpp b/src/example/asset_manager.cpp
index a2ca8c3..660b318 100644
--- a/src/example/asset_manager.cpp
+++ b/src/example/asset_manager.cpp
@@ -6,18 +6,17 @@ using namespace crepe;
int main() {
- // this needs to be called before the asset manager otherwise the destructor
- // of sdl is not in the right order
+ // this needs to be called before the asset manager otherwise the destructor of sdl is not in
+ // the right order
{ Texture test("asset/texture/img.png"); }
- // FIXME: make it so the issue described by the above comment is not possible
- // (i.e. the order in which internal classes are instantiated should not
- // impact the way the engine works).
+ // FIXME: make it so the issue described by the above comment is not possible (i.e. the order
+ // in which internal classes are instantiated should not impact the way the engine works).
auto & mgr = AssetManager::get_instance();
{
- // TODO: [design] the Sound class can't be directly included by the user as
- // it includes SoLoud headers.
+ // TODO: [design] the Sound class can't be directly included by the user as it includes
+ // SoLoud headers.
auto bgm = mgr.cache<Sound>("mwe/audio/bgm.ogg");
auto sfx1 = mgr.cache<Sound>("mwe/audio/sfx1.wav");
auto sfx2 = mgr.cache<Sound>("mwe/audio/sfx2.wav");
diff --git a/src/example/audio_internal.cpp b/src/example/audio_internal.cpp
index 9b60e6b..e23d485 100644
--- a/src/example/audio_internal.cpp
+++ b/src/example/audio_internal.cpp
@@ -42,8 +42,7 @@ int main() {
// Start the background track
bgm.play();
- // Play each sample sequentially while pausing and resuming the background
- // track
+ // Play each sample sequentially while pausing and resuming the background track
this_thread::sleep_for(500ms);
sfx1.play();
this_thread::sleep_for(500ms);
diff --git a/src/example/components_internal.cpp b/src/example/components_internal.cpp
index eeecdc0..2a232a9 100644
--- a/src/example/components_internal.cpp
+++ b/src/example/components_internal.cpp
@@ -27,8 +27,6 @@ int main() {
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");
@@ -44,10 +42,8 @@ int main() {
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);
+ 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());
diff --git a/src/example/ecs.cpp b/src/example/ecs.cpp
index 5f83da1..d5ba51b 100644
--- a/src/example/ecs.cpp
+++ b/src/example/ecs.cpp
@@ -14,14 +14,10 @@ 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 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);
@@ -36,24 +32,21 @@ int main() {
}
// Get the Metadata and Transform components of each GameObject
- vector<reference_wrapper<Metadata>> metadata
- = mgr.get_components_by_type<Metadata>();
- vector<reference_wrapper<Transform>> transform
- = mgr.get_components_by_type<Transform>();
+ vector<reference_wrapper<Metadata>> metadata = mgr.get_components_by_type<Metadata>();
+ vector<reference_wrapper<Transform>> transform = mgr.get_components_by_type<Transform>();
// Print the Metadata and Transform components
for (auto & m : metadata) {
cout << "Id: " << m.get().game_object_id << " Name: " << m.get().name
- << " Tag: " << m.get().tag << " Parent: " << m.get().parent
- << " Children: ";
+ << " Tag: " << m.get().tag << " Parent: " << m.get().parent << " Children: ";
for (auto & c : m.get().children) {
cout << c << " ";
}
cout << endl;
}
for (auto & t : transform) {
- cout << "Id: " << t.get().game_object_id << " Position: ["
- << t.get().position.x << ", " << t.get().position.y << "]" << endl;
+ cout << "Id: " << t.get().game_object_id << " Position: [" << t.get().position.x
+ << ", " << t.get().position.y << "]" << endl;
}
return 0;
diff --git a/src/example/particles.cpp b/src/example/particles.cpp
index b65671a..d4638a2 100644
--- a/src/example/particles.cpp
+++ b/src/example/particles.cpp
@@ -14,12 +14,11 @@ using namespace crepe;
using namespace std;
int main(int argc, char * argv[]) {
- ComponentManager mgr;
+ ComponentManager mgr{};
GameObject game_object = mgr.new_object("", "", Vector2{0, 0}, 0, 0);
Color color(0, 0, 0, 0);
Sprite test_sprite = game_object.add_component<Sprite>(
- make_shared<Texture>("asset/texture/img.png"), color,
- FlipSettings{true, true});
+ make_shared<Texture>("asset/texture/img.png"), color, FlipSettings{true, true});
game_object.add_component<ParticleEmitter>(ParticleEmitter::Data{
.position = {0, 0},
.max_particles = 100,
diff --git a/src/example/rendering.cpp b/src/example/rendering.cpp
index 2157bdc..c813524 100644
--- a/src/example/rendering.cpp
+++ b/src/example/rendering.cpp
@@ -31,15 +31,13 @@ int main() {
{
Color color(0, 0, 0, 0);
obj.add_component<Sprite>(
- make_shared<Texture>("asset/texture/img.png"), color,
- FlipSettings{false, false});
+ make_shared<Texture>("asset/texture/img.png"), color, FlipSettings{false, false});
obj.add_component<Camera>(Color::get_red());
}
{
Color color(0, 0, 0, 0);
obj1.add_component<Sprite>(
- make_shared<Texture>("asset/texture/second.png"), color,
- FlipSettings{true, true});
+ make_shared<Texture>("asset/texture/second.png"), color, FlipSettings{true, true});
}
/*
diff --git a/src/example/scene_manager.cpp b/src/example/scene_manager.cpp
index 24ab72e..accec7d 100644
--- a/src/example/scene_manager.cpp
+++ b/src/example/scene_manager.cpp
@@ -16,12 +16,9 @@ public:
void load_scene() {
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);
+ 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);
}
};
@@ -31,14 +28,10 @@ public:
void load_scene() {
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);
+ 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);
}
};
@@ -50,8 +43,8 @@ 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 beginning because the
- // first scene will be automatically set as the next scene
+ // There is no need to call set_next_scene() at the beginnen, because the first scene will be
+ // automatically set as the next scene
// Load scene1 (the first scene added)
scene_mgr.load_next_scene();