rrbox / ecs-swift

Entity Component System for swift
MIT License
3 stars 0 forks source link

Swift 自体の更新に備える #16

Open rrbox opened 9 months ago

rrbox commented 9 months ago

Swift 5.9 では以下の機能が通過されたようです。

今後 swift の更新が ECS に大きな影響を与える可能性が大きいので、今のうちに妄想を膨らませておきます。

rrbox commented 9 months ago

Query の型がひとつだけになる可能性

final class Query<each T: Component>: Chunk {}

それでいて、Query で指定できる Component の数が無制限になります。

rrbox commented 9 months ago

アルゴリズムのコアな部分を C++ にする選択肢もあります。

rrbox commented 9 months ago

System の型の数も減らせそうです

final class UpdateSystem<each T: SystemParameter> {}

extension World {
    @discardableResult func addUpdateSystem<each T: SystemParameter>(_ system: UpdateSystem<repeat each T>) -> World {

    }
}

System parameter の数も無制限になりそうです。

ただ、内部でクロージャに値を渡せるのかどうかが不明なので(Document などでは「関数」での使用例のみであるため)、実現可能かは不明です。

rrbox commented 9 months ago

type, value pack の構造体向けの実装はまだらしいです。Variadic generic types

rrbox commented 8 months ago

Swift 5.9 時点では ECS に大きく関連する変化がないため、このissueのテーマを少し変更しました。

rrbox commented 5 months ago

"真の stored property packs": https://github.com/apple/swift-evolution/blob/main/proposals/0398-variadic-types.md#future-directions

これが導入されるまでは、更新はお預けだと思います。

この提案が swift に導入されると、以下のような Query が作成できまさす。

class Query<each C: Component> {
    var components: SparseSet<(repeat each Ref<C>)>
}