Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8a126f0

Browse files
committed
Remove outdated references to old singleton API
1 parent6cf9186 commit8a126f0

File tree

2 files changed

+10
-101
lines changed

2 files changed

+10
-101
lines changed

‎docs/ObserversManual.md‎

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,101 +1641,6 @@ let e = world.entity().set(TimeOfDay { value: 0.0 });
16411641

16421642
Observers may match terms on multiple different sources. However, when an observer matches components both on the`$this` source (default) and on a fixed source, the fixed source terms will not match events. The reason for this is that otherwise emitting an event for a fixed source term would mean iterating all matching entities for the`$this` term. If an observer only has fixed source terms, events will be matched for each of the terms.
16431643

1644-
###Singletons
1645-
Singletons are a special case of fixed source term, where the component is matched on itself. An example:
1646-
1647-
<divclass="flecs-snippet-tabs">
1648-
<ul>
1649-
<li><bclass="tab-title">C</b>
1650-
1651-
```c
1652-
ecs_singleton_set(world, TimeOfDay, {0});
1653-
1654-
// Observer with singleton source
1655-
ecs_observer(world, {
1656-
.query.terms = {
1657-
{ ecs_id(TimeOfDay), .src.id = ecs_id(TimeOfDay) }
1658-
},
1659-
.events = { EcsOnSet },
1660-
.callback = MyObserver
1661-
});
1662-
1663-
// Triggers observer
1664-
ecs_singleton_set(world, TimeOfDay, {1});
1665-
1666-
// Does not trigger observer
1667-
ecs_entity_t e = ecs_insert(world, ecs_value(TimeOfDay, {0}));
1668-
```
1669-
1670-
</li>
1671-
<li><b class="tab-title">C++</b>
1672-
1673-
```cpp
1674-
world.set(TimeOfDay{0});
1675-
1676-
// Observer with singleton source
1677-
world.observer<TimeOfDay>()
1678-
.term_at(0).singleton()
1679-
.event(flecs::OnSet)
1680-
.each([](flecs::iter& it, size_t i, TimeOfDay& t) {
1681-
// ...
1682-
});
1683-
1684-
// Triggers observer
1685-
world.set(TimeOfDay{1});
1686-
1687-
// Does not trigger observer
1688-
flecs::entity e = world.entity().set(TimeOfDay{0});
1689-
```
1690-
1691-
</li>
1692-
<li><bclass="tab-title">C#</b>
1693-
1694-
```cs
1695-
world.Set(newTimeOfDay(0));
1696-
1697-
// Observer with singleton source
1698-
world.Observer<TimeOfDay>()
1699-
.TermAt(0).Singleton()
1700-
.Event(Ecs.OnSet)
1701-
.Each((Iterit,inti,refTimeOfDayt)=>
1702-
{
1703-
// ...
1704-
});
1705-
1706-
// Triggers observer
1707-
world.Set(newTimeOfDay(1));
1708-
1709-
// Does not trigger observer
1710-
Entitye=world.Entity().Set(newTimeOfDay(0));
1711-
```
1712-
1713-
</li>
1714-
<li><bclass="tab-title">Rust</b>
1715-
1716-
```rust
1717-
world.set(TimeOfDay {value:0.0 });
1718-
1719-
// Observer with singleton source
1720-
world
1721-
.observer::<flecs::OnSet,&TimeOfDay>()
1722-
.term_at(0)
1723-
.singleton()
1724-
.each_iter(|it,i,time| {
1725-
// ...
1726-
});
1727-
1728-
// Triggers observer
1729-
world.set(TimeOfDay {value:1.0 });
1730-
1731-
// Does not trigger observer
1732-
lete=world.entity().set(TimeOfDay {value:0.0 });
1733-
```
1734-
1735-
</li>
1736-
</ul>
1737-
</div>
1738-
17391644
##Event Propagation
17401645
When an observer has a query that uses (up) relationship traversal, events are propagated along the relationship edge. For example, when an observer requests component`Position` from a parent entity, setting`Position` on the parent will propagate an`OnSet` event along the`ChildOf` edge, notifying all child entities of the parent.
17411646

‎docs/Systems.md‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,8 +606,10 @@ void PrintTime(ecs_iter_t *it) {
606606
printf("Time: %f\n", g->time);
607607
}
608608

609+
ecs_add_id(world, Game, EcsSingleton);
610+
609611
// System declaration using the ECS_SYSTEM macro
610-
ECS_SYSTEM(world, PrintTime, EcsOnUpdate, Game($));
612+
ECS_SYSTEM(world, PrintTime, EcsOnUpdate, Game);
611613

612614
// System declaration using the descriptor API
613615
ecs_system(world, {
@@ -616,7 +618,7 @@ ecs_system(world, {
616618
.add = ecs_ids( ecs_dependson(EcsOnUpdate) )
617619
}),
618620
.query.terms = {
619-
{ .id = ecs_id(Game), .src.id = ecs_id(Game) } // Singleton source
621+
{ .id = ecs_id(Game) }
620622
},
621623
.callback = PrintTime
622624
});
@@ -625,8 +627,9 @@ ecs_system(world, {
625627
<li><b class="tab-title">C++</b>
626628
627629
```cpp
630+
world.component<Game>().add(flecs::Singleton);
631+
628632
world.system<Game>("PrintTime")
629-
.term_at(0).singleton()
630633
.kind(flecs::OnUpdate)
631634
.each([](Game& g) {
632635
printf("Time: %f\n", g.time);
@@ -636,8 +639,9 @@ world.system<Game>("PrintTime")
636639
<li><bclass="tab-title">C#</b>
637640

638641
```cs
642+
world.Component<Game>().Entity.Add(flecs::Singleton);
643+
639644
world.System<Game>("PrintTime")
640-
.TermAt(0).Singleton()
641645
.Kind(Ecs.OnUpdate)
642646
.Each((refGameg)=>
643647
{
@@ -648,10 +652,10 @@ world.System<Game>("PrintTime")
648652
<li><bclass="tab-title">Rust</b>
649653

650654
```rust
655+
world.component::<Game>().add_trait::<flecs::Singleton>();
656+
651657
world
652658
.system_named::<&Game>("PrintTime")
653-
.term_at(0)
654-
.singleton()
655659
.kind::<flecs::pipeline::OnUpdate>()
656660
.run_iter(|it,game| {
657661
println!("Time: {}",game[0].time);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp