mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-24 17:10:03 +00:00
Updated with changes as per PR #194
This commit is contained in:
parent
8e9c1e808b
commit
4a5a425a9c
2 changed files with 13 additions and 126 deletions
|
@ -22,14 +22,22 @@
|
|||
```lua
|
||||
local world = jecs.World.new()
|
||||
local pair = jecs.pair
|
||||
local Position = world:component() :: jecs.Id<Vector3>
|
||||
local Velocity = world:component() :: jecs.Id<Vector3>
|
||||
|
||||
-- These components and functions are actually already builtin
|
||||
-- but have been illustrated for demonstration purposes
|
||||
local ChildOf = world:component()
|
||||
local Name = world:component()
|
||||
local entity = world:entity()
|
||||
world:set(entity, Position, Vector3.new(0, 0, 0))
|
||||
world:set(entity, Velocity, Vector3.new(1, 0, 0))
|
||||
|
||||
local function parent(entity)
|
||||
return world:target(entity, ChildOf)
|
||||
-- Update system (example)
|
||||
for id, position, velocity in world:query(Position, Velocity) do
|
||||
world:set(id, Position, position + velocity)
|
||||
end
|
||||
|
||||
local function getName(entity)
|
||||
|
@ -89,3 +97,4 @@ Please read our [Contributing Guidelines](CONTRIBUTING.md) before submitting pul
|
|||
## 📄 License
|
||||
|
||||
Jecs is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
||||
```
|
||||
|
|
|
@ -1,122 +0,0 @@
|
|||
# Migrating from Matter
|
||||
|
||||
This guide helps you migrate your code from Matter ECS to Jecs.
|
||||
|
||||
## Key Differences
|
||||
|
||||
### World Creation
|
||||
```lua
|
||||
-- Matter
|
||||
local world = Matter.World.new()
|
||||
|
||||
-- Jecs
|
||||
local world = jecs.World.new()
|
||||
```
|
||||
|
||||
### Component Definition
|
||||
```lua
|
||||
-- Matter
|
||||
local Position = { name = "Position" }
|
||||
local Velocity = { name = "Velocity" }
|
||||
|
||||
-- Jecs
|
||||
local Position = world:component() :: jecs.Entity<Vector3>
|
||||
local Velocity = world:component() :: jecs.Entity<Vector3>
|
||||
```
|
||||
|
||||
### Entity Creation
|
||||
```lua
|
||||
-- Matter
|
||||
local entity = world:spawn()
|
||||
|
||||
-- Jecs
|
||||
local entity = world:entity()
|
||||
```
|
||||
|
||||
### Adding Components
|
||||
```lua
|
||||
-- Matter
|
||||
world:insert(entity, Position, { x = 0, y = 0, z = 0 })
|
||||
|
||||
-- Jecs
|
||||
world:set(entity, Position, Vector3.new(0, 0, 0))
|
||||
```
|
||||
|
||||
### Querying
|
||||
```lua
|
||||
-- Matter
|
||||
for id, pos, vel in world:query(Position, Velocity) do
|
||||
-- Process entities
|
||||
end
|
||||
|
||||
-- Jecs
|
||||
for id, pos, vel in world:query(Position, Velocity) do
|
||||
-- Process entities
|
||||
end
|
||||
```
|
||||
|
||||
## Major Feature Differences
|
||||
|
||||
### Relationships
|
||||
Jecs provides built-in support for entity relationships:
|
||||
```lua
|
||||
-- Jecs only
|
||||
world:add(child, pair(ChildOf, parent))
|
||||
```
|
||||
|
||||
### Component Traits
|
||||
Jecs allows adding traits to components:
|
||||
```lua
|
||||
-- Jecs only
|
||||
world:add(Position, Networked)
|
||||
```
|
||||
|
||||
### Query Caching
|
||||
Jecs provides explicit query caching:
|
||||
```lua
|
||||
-- Jecs only
|
||||
local cachedQuery = world:query(Position, Velocity):cached()
|
||||
```
|
||||
|
||||
## Migration Steps
|
||||
|
||||
1. **Update Component Definitions**
|
||||
- Replace Matter component tables with Jecs components
|
||||
- Add type annotations for better type safety
|
||||
|
||||
2. **Update Entity Management**
|
||||
- Replace `spawn()` with `entity()`
|
||||
- Update component insertion syntax
|
||||
|
||||
3. **Update Queries**
|
||||
- Review and update query usage
|
||||
- Consider using query caching for performance
|
||||
|
||||
4. **Add Relationships**
|
||||
- Replace custom parent-child implementations with Jecs relationships
|
||||
- Use built-in relationship features
|
||||
|
||||
5. **Update Systems**
|
||||
- Review system implementation patterns
|
||||
- Consider using component traits for better organization
|
||||
|
||||
## Performance Considerations
|
||||
|
||||
1. **Query Performance**
|
||||
- Cache frequently used queries
|
||||
- Use appropriate filters
|
||||
|
||||
2. **Component Storage**
|
||||
- Use tags for boolean states
|
||||
- Consider component data structure size
|
||||
|
||||
3. **Relationship Usage**
|
||||
- Be mindful of relationship complexity
|
||||
- Use built-in relationships when possible
|
||||
|
||||
## Getting Help
|
||||
|
||||
Need help migrating?
|
||||
- Join our [Discord server](https://discord.gg/h2NV8PqhAD)
|
||||
- Check the [API documentation](../../api/jecs.md)
|
||||
- Open an issue on [GitHub](https://github.com/ukendio/jecs/issues)
|
Loading…
Reference in a new issue