Comments (4)
Thanks for opening the ticket, and I'm glad you're enjoying esper.
Can I ask why it's important that entities have the same ID after loading?
The proposed patch would work, but it's a bit outside of typical ECS structure.
The Entity ID happens to be an integer, but it's meant as a throw-away value.
Instead of storing the ID, if possible, I would recommend using a Component to "tag" specific Entities.
class Player:
pass
class EnemyTypeA:
pass
class EnemyTypeB:
pass
There may of course be multiple of the enemy types, but there would only be one entity tagged with Player
. This allows you to specifically query that entity, if you need to.
from esper.
I already use components as "Tags" and it works fine how i use it but my game has "unpredictable" Enemies aka an Entity with a random set of Components. It may work with a restructure of my db layout. I might make it possible without using the entity id as a key but changing components would be hard.
having a db without entity id as key might be look like this:
Entity
row_id | components |
---|---|
1 | "Position(7,3,0);Color(255,0,0);Faction(12);IsGiant();IsOrc();IsNPC();DialogTree(44);Level(3)" |
2 | "Position(7,3,0);Color(255,0,0);Faction(12);MoreRandomComponents()" |
3 | "Position(7,3,0);Color(255,0,0);Faction(12);EvenMoreComponents()" |
that way i have just one table in my db (what i don't really want to happen) and i don't need the entity id as a key as i can distinguish by the components. Now just imaging what i have to do to change the Position of a specific entity. i gets messy real fast.
my other solution would be to add a secondary id component to my entities like a RandomEntity having components Position, Color, Faction, etc AND a must have SecondaryIdComponent() like a string or another int which is different for every Entity.
It just might be "the problem saving ECS to a DB". I've never done it and it might be a stupid use case but i want to do like that to learn it.
Having a way to create known entities with specific ids would be the easiest solution for me. if it's not complieant with an ECS than that's ok. I have ways to work around it but it would make my life a little bit easier :D
from esper.
Sorry for leaving this hanging for so long.
I think for the main Esper releases I want to keep it as-is, just for performance reasons (even if very small).
That said, it would be pretty easy to subclass World with a custom create_known_entity(id)
method. It could probably work alongside the existing method as well. Would that work for you?
from esper.
Closing this due to lack of follow up.
On careful consideration, I don't think this makes sense in mainline esper
, due to placing relevance on what is supposed to be nothing more than a UUID (even if it's an int
in implementation).
This behavior can be achieved using a custom function. If you need help in producing something like that, please follow up or open a new ticket. Thanks!
from esper.
Related Issues (20)
- esper.current_world not usable as a module-level property HOT 2
- event handler as function HOT 4
- enhance `get_component` HOT 4
- Try another ECS implementation - ecs_pattern library HOT 2
- Typing of world under the processor class HOT 3
- Testing esper HOT 4
- mypy `get_components` gives "object" type HOT 1
- Relationships HOT 8
- `World().create_entity()` does not create entity if no components are given HOT 1
- `remove_component()` method removes entity if no more components left HOT 3
- Add mypy to unit tests HOT 2
- Querying entities with denylist of components HOT 5
- API Design : Why so much OOP ? HOT 20
- "Quick start" in README is targeting old version HOT 3
- Seeking Guidance on Persisting and Loading Esper from a Database HOT 2
- Is esper Thread-Safe for Multi-threaded Environments? HOT 5
- Why roll up world into esper module? HOT 4
- Event handlers set within a function don't remain once the block scope exits. Why use weak references here? HOT 4
- Event System does not preserve event handlers upon switching context HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esper.