Replies: 4 comments 2 replies
-
I'm experimenting with this now. I have some experience with ECS, but I'm new to both Rust and SpacetimeDB. The lack of querying power on the server side is an interesting obstacle. A server module doesn't query columns, but only the indexes you have defined. The server library cannot perform join queries at all. You are expected to write the join logic yourself. It may be reasonable to use SpacetimeDB with ECS principles in mind, but it does not currently offer the basics of ECS. My current best guess for how SpacetimeDB could make early progress to better support ECS:
But even if this approach worked, they may still need to do something (challenging) about the memory overhead of reserving unused space to hold many An alternate approach that comes to mind for better ECS support would be generating a different table for every possible archetype. Some attribute
The underlying data layer might still be SpacetimeDB, but the interface would be completely different. Example: let query = ctx.ecs.entity_type_for_grouping.with_hp().with_position().with_hitbox().without_invulnerable();
for entity in query {
let hp = entity.hp();
let p = entity.position();
// etc...
ctx.ecs.update(entity).hp(new_hp);
} |
Beta Was this translation helpful? Give feedback.
-
Experimenting with a macro to support ECS normalized tables: https://github.com/cryo-warden/trpg/blob/stdb-pilot/ecs%2Fsrc%2Ftests%2Fmod.rs
use ecs_macro::entity;
pub type EntityId = u64;
entity! {
entity Entity entity_id: EntityId tables();
component LocationComponent [
(location, location_components),
(secondary_location, secondary_location_components),
] {
pub location_entity_id: EntityId,
}
component PathComponent [
(path, path_components),
(excess_path, excess_path_components)
] {
pub destination_entity_id: EntityId,
}
}
impl LocationComponent {
pub fn new() -> Self {
Self {
entity_id: 0,
location_entity_id: 0,
}
}
}
impl<'a> EntityHandle<'a> {
pub fn peek() {}
}
#[allow(unused_variables, dead_code)]
fn sandbox(ctx: &spacetimedb::ReducerContext) -> Option<()> {
let e = EntityHandle { entity_id: 0, ctx };
LocationComponent::new();
EntityHandle::peek();
let e = e.with_path()?.with_location()?.with_secondary_location()?;
e.location();
e.path();
e.secondary_location();
Some(())
} |
Beta Was this translation helpful? Give feedback.
-
I added filter-by-component iteration to the macro I'm working on, which basically accomplishes joins via index lookups by shared entity ID. Whichever If you don't filter by a certain component field, then you will instead get an It is all static-dispatch only. for lp in LocationComponent::iter_location(ctx).with_path() {
println!("{:?}", lp.path());
}
for pl in PathComponent::iter_path(ctx)
.with_location()
.with_excess_path()
.with_secondary_location()
{
println!("{:?}", pl.location());
println!("{:?}", pl.path());
println!("{:?}", pl.excess_path());
println!("{:?}", pl.secondary_location());
} |
Beta Was this translation helpful? Give feedback.
-
Could you share the reasoning behind the migration? Just curious because it is a TD game. In other words: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Interested in trying to migrate a server authoritative tower defense game I made in bevy to Spacetime, and was curious if anyone has any material for how to reason about implementing game logic in Spacetime from an ECS?
I've seen the example repos, and how they use timers. But I'm struggling to grasp how, for example, one would handle multiple entities with a shared component. Like a player and mob both having a position/velocity to be ticked every 50ms or so. Do you just setup multiple timers like in the example? How do you mitigate duplicated code with many entity types? Do you foreign key and setup a position/velocity table?
Are there performance concerns in keeping all data structures an ECS would normally have in the DB, while using tables like individual components? like having an entity table with ids, then a velocity/position table with their relevant data and a foreign key into the entity table? Are there performance concerns for the big SQL joins you'd have to do to find all entities that share 5 or so components?
Beta Was this translation helpful? Give feedback.
All reactions