mirror of
https://github.com/bakpakin/tiny-ecs.git
synced 2026-07-22 07:56:52 -06:00
Change repo name
This commit is contained in:
@@ -1,15 +1,15 @@
|
|||||||
# Jojo #
|
# tiny-ecs #
|
||||||
Jojo is an Entity Component System for lua that's simple, flexible, and useful.
|
Tiny-ecs is an Entity Component System for lua that's simple, flexible, and useful.
|
||||||
Because of lua's tabular nature, Entity Component Systems are a natural choice
|
Because of lua's tabular nature, Entity Component Systems are a natural choice
|
||||||
for simulating large and complex systems. For more explanation on Entity
|
for simulating large and complex systems. For more explanation on Entity
|
||||||
Component Systems, here is some
|
Component Systems, here is some
|
||||||
[basic info](http://en.wikipedia.org/wiki/Entity_component_system "Wikipedia").
|
[basic info](http://en.wikipedia.org/wiki/Entity_component_system "Wikipedia").
|
||||||
|
|
||||||
## Use It ##
|
## Use It ##
|
||||||
Copy paste jojo.lua into your source folder.
|
Copy paste tiny.lua into your source folder.
|
||||||
|
|
||||||
## Overview ##
|
## Overview ##
|
||||||
Jojo has four important types: Worlds, Aspects, Systems, and Entities.
|
Tiny-ecs has four important types: Worlds, Aspects, Systems, and Entities.
|
||||||
Entities, however, can be any lua table.
|
Entities, however, can be any lua table.
|
||||||
|
|
||||||
### Entities ###
|
### Entities ###
|
||||||
@@ -19,11 +19,11 @@ do logic on data. Henceforth, a key-value pair in an Entity will
|
|||||||
be referred to as a Component.
|
be referred to as a Component.
|
||||||
|
|
||||||
### Worlds ###
|
### Worlds ###
|
||||||
Worlds are the outermost containers in Jojo that contain both Systems
|
Worlds are the outermost containers in tiny-ecs that contain both Systems
|
||||||
and Entities. In typical use, only one World is used at a time.
|
and Entities. In typical use, only one World is used at a time.
|
||||||
|
|
||||||
### Systems ###
|
### Systems ###
|
||||||
Systems in Jojo describe how to update Entities. Systems select certain Entities
|
Systems in tiny-ecs describe how to update Entities. Systems select certain Entities
|
||||||
using an aspect, and then only update those select Entities. Systems have three
|
using an aspect, and then only update those select Entities. Systems have three
|
||||||
parts: a one-time update function, a per Entity update function, and an Aspect.
|
parts: a one-time update function, a per Entity update function, and an Aspect.
|
||||||
The one-time update function is called once per World update, and the per Entity
|
The one-time update function is called once per World update, and the per Entity
|
||||||
@@ -39,15 +39,11 @@ are equivalent to the union of all sub-Aspects.
|
|||||||
|
|
||||||
## Example ##
|
## Example ##
|
||||||
```lua
|
```lua
|
||||||
local jojo = require("jojo")
|
local tiny = require("tiny")
|
||||||
|
|
||||||
local World = jojo.World
|
local personAspect = tiny.Aspect({"name", "mass", "phrase"})
|
||||||
local Aspect = jojo.Aspect
|
|
||||||
local System = jojo.System
|
|
||||||
|
|
||||||
local personAspect = Aspect({"name", "mass", "phrase"})
|
local talkingSystem = tiny.System(
|
||||||
|
|
||||||
local talkingSystem = System(
|
|
||||||
nil,
|
nil,
|
||||||
function (p, delta)
|
function (p, delta)
|
||||||
p.mass = p.mass + delta * 3
|
p.mass = p.mass + delta * 3
|
||||||
@@ -63,7 +59,7 @@ local joe = {
|
|||||||
hairColor = "brown"
|
hairColor = "brown"
|
||||||
}
|
}
|
||||||
|
|
||||||
local world = World(talkingSystem, joe)
|
local world = tiny.World(talkingSystem, joe)
|
||||||
|
|
||||||
for i = 1, 20 do
|
for i = 1, 20 do
|
||||||
world:update(1)
|
world:update(1)
|
||||||
@@ -71,7 +67,7 @@ end
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Testing ##
|
## Testing ##
|
||||||
Jojo uses [busted](http://olivinelabs.com/busted/) for testing. Install and run
|
Tiny-ecs uses [busted](http://olivinelabs.com/busted/) for testing. Install and run
|
||||||
`busted` from the command line to test.
|
`busted` from the command line to test.
|
||||||
|
|
||||||
## TODO ##
|
## TODO ##
|
||||||
@@ -80,3 +76,4 @@ Jojo uses [busted](http://olivinelabs.com/busted/) for testing. Install and run
|
|||||||
* More testing
|
* More testing
|
||||||
* Performance testing / optimization
|
* Performance testing / optimization
|
||||||
* API outside of source code
|
* API outside of source code
|
||||||
|
* Add more complete examples
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
local jojo = require "jojo"
|
local tiny = require "tiny"
|
||||||
|
|
||||||
local World = jojo.World
|
local World = tiny.World
|
||||||
local Aspect = jojo.Aspect
|
local Aspect = tiny.Aspect
|
||||||
local System = jojo.System
|
local System = tiny.System
|
||||||
|
|
||||||
-- Taken from answer at http://stackoverflow.com/questions/640642/how-do-you-copy-a-lua-table-by-value
|
-- Taken from answer at http://stackoverflow.com/questions/640642/how-do-you-copy-a-lua-table-by-value
|
||||||
local function deep_copy(o, seen)
|
local function deep_copy(o, seen)
|
||||||
@@ -50,7 +50,7 @@ local entityTemplate3 = {
|
|||||||
description = "The smallest entity."
|
description = "The smallest entity."
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Jojo:', function()
|
describe('tiny-ecs:', function()
|
||||||
|
|
||||||
describe('Aspect:', function()
|
describe('Aspect:', function()
|
||||||
|
|
||||||
+12
-12
@@ -1,7 +1,7 @@
|
|||||||
local jojo = {
|
local tiny = {
|
||||||
_VERSION = "0.1.0",
|
_VERSION = "0.2.0",
|
||||||
_URL = "https://github.com/bakpakin/Jojo",
|
_URL = "https://github.com/bakpakin/tiny-ecs",
|
||||||
_DESCRIPTION = "jojo - Entity Component System for lua."
|
_DESCRIPTION = "tiny-ecs - Entity Component System for lua."
|
||||||
}
|
}
|
||||||
|
|
||||||
local tinsert = table.insert
|
local tinsert = table.insert
|
||||||
@@ -34,9 +34,9 @@ local World = class("World")
|
|||||||
local Aspect = class("Aspect")
|
local Aspect = class("Aspect")
|
||||||
local System = class("System")
|
local System = class("System")
|
||||||
|
|
||||||
jojo.World = World
|
tiny.World = World
|
||||||
jojo.Aspect = Aspect
|
tiny.Aspect = Aspect
|
||||||
jojo.System = System
|
tiny.System = System
|
||||||
|
|
||||||
----- Aspect -----
|
----- Aspect -----
|
||||||
|
|
||||||
@@ -156,9 +156,9 @@ end
|
|||||||
|
|
||||||
function Aspect:__tostring()
|
function Aspect:__tostring()
|
||||||
if self[4] then
|
if self[4] then
|
||||||
return "JojoAspect<>"
|
return "TinyAspect<>"
|
||||||
else
|
else
|
||||||
return "JojoAspect<Required: {" ..
|
return "TinyAspect<Required: {" ..
|
||||||
tconcat(self[1], ", ") ..
|
tconcat(self[1], ", ") ..
|
||||||
"}, Excluded: {" ..
|
"}, Excluded: {" ..
|
||||||
tconcat(self[2], ", ") ..
|
tconcat(self[2], ", ") ..
|
||||||
@@ -188,7 +188,7 @@ function System:init(preupdate, update, aspect, add, remove)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function System:__tostring()
|
function System:__tostring()
|
||||||
return "JojoSystem<preupdate: " ..
|
return "TinySystem<preupdate: " ..
|
||||||
self.preupdate ..
|
self.preupdate ..
|
||||||
", update: " ..
|
", update: " ..
|
||||||
self.update ..
|
self.update ..
|
||||||
@@ -241,7 +241,7 @@ function World:init(...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function World:__tostring()
|
function World:__tostring()
|
||||||
return "JojoWorld<systemCount: " ..
|
return "TinyWorld<systemCount: " ..
|
||||||
self.systemCount ..
|
self.systemCount ..
|
||||||
", entityCount: " ..
|
", entityCount: " ..
|
||||||
self.entityCount ..
|
self.entityCount ..
|
||||||
@@ -467,4 +467,4 @@ function World:setSystemActive(system, active)
|
|||||||
self.activeSystem[system] = active and true or nil
|
self.activeSystem[system] = active and true or nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return jojo
|
return tiny
|
||||||
Reference in New Issue
Block a user