@trentjones21 Your question makes a lot of sense. There were other users before asking about the same thing but in a different context. For example the last question in this post: ECSpanse - an Entity Component System framework for Elixir - #34 by iacobson
As I replied also there, it was a deliberate decision I took. I totally agree that spawning a new server for each room or session etc., feels more “Elixiry”.
However, the library needs to interact with a frontend framework (eg. LiveView, LiveBook) that is not aware of the internal context of the Ecspanse server. That would mean, for every query run outside of the ECS context, you would need to pass a map or a token that would identify the Ecspanse server and the corresponding ETS tables where the data is stored. So the query would need what room to run the query for.
For example, in a LiveView Component, instead of:
Ecspanse.Query.fetch_component(entity, Demo.Components.Energy)
you would have:
Ecspanse.Query.fetch_component(some_token, entity, Demo.Components.Energy)
This gets quite annoying, especially when you do not need this feature. So the tradeoff was to hardcode the Server and all ETS names and allow a single ETS “World” per instance.
The other reason is that sharing data between those servers is not trivial.
The alternative
That being said, the current alternative is to create room entities and assign the players as Children to the rooms.
The you can easily query all the players in a room. For example:
If only player entities are children of the room
player_entities = Ecspanse.Query.list_children(room_entity)
If the room has also other type of children
player_entities = Ecspanse.Query.select({Ecspanse.Entity},
with: [MyGame.Comp.Player],
for_children_of: [room_entity])
|> Ecspanse.Query.stream()
|> Enum.map( fn {player_entity} -> player_entity end )
Hope this answers your question, even if not ideal for your use case.