Entity archetype registration and entity creation is a breeze when using
neoGFX's ECS:
namespace archetypes
{
const ng::game::entity_archetype spaceship
{
neolib::uuid{ 0x26730030, 0xa999, 0x4d99, 0xa7ad,{ 0x80, 0x89, 0x69,
0x23, 0x95, 0xf9 } },
"Spaceship",
{ ng::game::rigid_body::meta::id(), ng::game::box_collider::meta::id() }
};
const ng::game::entity_archetype asteroid
{
neolib::uuid{ 0x8283650f, 0x6e59, 0x4f0f, 0x8ae0, { 0x1d, 0x99, 0xeb,
0xf2, 0x49, 0xe0 } },
"Asteroid",
{ ng::game::rigid_body::meta::id(), ng::game::box_collider::meta::id() }
};
}
void create_game(ng::i_layout& aLayout)
{
auto& canvas = aLayout.add(std::make_shared<ng::game::ecs_canvas>());
auto& ecs = canvas.ecs();
canvas.set_font(ng::font(canvas.font(), ng::font::Bold, 28));
canvas.set_background_colour(ng::colour::Black);
ecs.register_archetype(archetypes::spaceship);
ecs.register_archetype(archetypes::asteroid);
auto spaceship = ecs.create_entity(archetypes::
spaceship.id(),
ng::game::rigid_body{ ng::vec3{ 400.0, 18.0, 0.0 }, 1.0 });
neolib::basic_random<double> prng;
for (int i = 0; i < 1000; ++i)
auto asteroid = ecs.create_entity(archetypes::
asteroid.id(),
ng::game::rigid_body{ ng::vec3{ prng(1000.0), prng(1000.0), 0.0 }, 1.0 });
}
That is all.
Message ends.
/Flibble
--
"Suppose it’s all true, and you walk up to the pearly gates, and are
confronted by God," Bryne asked on his show The Meaning of Life. "What
will Stephen Fry say to him, her, or it?"
"I’d say, bone cancer in children? What’s that about?" Fry replied.
"How dare you? How dare you create a world to which there is such misery
that is not our fault. It’s not right, it’s utterly, utterly evil."
"Why should I respect a capricious, mean-minded, stupid God who creates a
world that is so full of injustice and pain. That’s what I would say."