mirror of
https://github.com/bakpakin/tiny-ecs.git
synced 2026-07-22 07:56:52 -06:00
Compare commits
63 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2403a9019c | ||
|
|
6234e4b741 | ||
|
|
b870b5a34e | ||
|
|
f3b16a40f6 | ||
|
|
5035d2c8a7 | ||
|
|
18270cd60a | ||
|
|
dba8e7c89f | ||
|
|
fccff0329e | ||
|
|
8a759edca2 | ||
|
|
d9d311d858 | ||
|
|
9834dfa9d6 | ||
|
|
a5af4b6ecd | ||
|
|
f0e6ce7880 | ||
|
|
26f8259f2b | ||
|
|
b1c7e2ba83 | ||
|
|
6b549fcbc1 | ||
|
|
b9d994ad50 | ||
|
|
ce8ca35f7e | ||
|
|
19ae03707f | ||
|
|
c1f1225248 | ||
|
|
45e8552054 | ||
|
|
f187dce4fd | ||
|
|
927652597c | ||
|
|
6b3af0f2da | ||
|
|
31f3396db1 | ||
|
|
cb9ab332d2 | ||
|
|
1fd32dab9a | ||
|
|
0a12897695 | ||
|
|
e44ac6cdb3 | ||
|
|
6f299470d0 | ||
|
|
61ffd2551b | ||
|
|
c66ed98a5a | ||
|
|
2621bd16a3 | ||
|
|
c408267932 | ||
|
|
557927577d | ||
|
|
cbfc3d360f | ||
|
|
d35d62ed3c | ||
|
|
74666ca0c3 | ||
|
|
5978ace463 | ||
|
|
a504bd6336 | ||
|
|
69ae37586e | ||
|
|
44fb94c457 | ||
|
|
9230dad1e1 | ||
|
|
e4bf3f3767 | ||
|
|
71e97c12f6 | ||
|
|
7c4ff7747c | ||
|
|
808407f7c4 | ||
|
|
153f326612 | ||
|
|
a4e3c90724 | ||
|
|
e47920f332 | ||
|
|
e96d494526 | ||
|
|
994f3b6533 | ||
|
|
264d835334 | ||
|
|
e54f29884c | ||
|
|
9991ff7474 | ||
|
|
5e7d2ea7fc | ||
|
|
6d1b280a40 | ||
|
|
fb345c7718 | ||
|
|
0f86eae571 | ||
|
|
fd49633d17 | ||
|
|
94fc3ac453 | ||
|
|
4109d37cdb | ||
|
|
c9dccaf85f |
Vendored
+3
@@ -3,3 +3,6 @@ doc/*
|
||||
index.html
|
||||
ldoc.css
|
||||
topics/*
|
||||
|
||||
#Ignore generated rocks
|
||||
*.rock
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
language: erlang
|
||||
|
||||
env:
|
||||
global:
|
||||
- LUAROCKS_BASE=luarocks-2.2.2
|
||||
matrix:
|
||||
- LUA=lua5.1 LUA_DEV=liblua5.1-dev LUA_VER=5.1 LUA_SFX=5.1 LUA_INCDIR=/usr/include/lua5.1
|
||||
- LUA=lua5.2 LUA_DEV=liblua5.2-dev LUA_VER=5.2 LUA_SFX=5.2 LUA_INCDIR=/usr/include/lua5.2
|
||||
- LUA=luajit LUA_DEV=libluajit-5.1-dev LUA_VER=5.1 LUA_SFX=jit LUA_INCDIR=/usr/include/luajit-2.0
|
||||
|
||||
before_install:
|
||||
- if [ $LUA = "luajit" ]; then
|
||||
sudo add-apt-repository ppa:mwild1/ppa -y && sudo apt-get update -y;
|
||||
sudo apt-get install lua5.1;
|
||||
sudo apt-get install liblua5.1-dev;
|
||||
fi
|
||||
- sudo apt-get install $LUA
|
||||
- sudo apt-get install $LUA_DEV
|
||||
- lua$LUA_SFX -v
|
||||
# Install a recent luarocks release
|
||||
- wget http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz
|
||||
- tar zxvpf $LUAROCKS_BASE.tar.gz
|
||||
- cd $LUAROCKS_BASE
|
||||
- ./configure
|
||||
--lua-version=$LUA_VER --lua-suffix=$LUA_SFX --with-lua-include="$LUA_INCDIR"
|
||||
- sudo make
|
||||
- sudo make install
|
||||
- cd $TRAVIS_BUILD_DIR
|
||||
|
||||
install:
|
||||
- sudo -E luarocks install busted
|
||||
|
||||
script:
|
||||
- sudo -E busted -v
|
||||
|
||||
notifications:
|
||||
email:
|
||||
on_success: change
|
||||
on_failure: always
|
||||
@@ -1,16 +1,20 @@
|
||||
# tiny-ecs #
|
||||
|
||||
[](https://travis-ci.org/bakpakin/tiny-ecs)
|
||||
|
||||
[](LICENSE)
|
||||
|
||||
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
|
||||
for simulating large and complex systems. For more explanation on Entity
|
||||
Component Systems, here is some
|
||||
[basic info](http://en.wikipedia.org/wiki/Entity_component_system "Wikipedia").
|
||||
|
||||
Tiny-ecs also works well with Objected Oriented programming in lua because
|
||||
Tiny-ecs also works well with objected oriented programming in lua because
|
||||
Systems and Entities do not use metatables. This means you can subclass your
|
||||
Systems and Entities, and use existing lua class frameworks with tiny-ecs, no problem.
|
||||
|
||||
## Use It ##
|
||||
Copy paste tiny.lua into your source folder.
|
||||
For an example on how to use tiny-ecs with object-oriented lua, take a look at the
|
||||
demo branch, specifically the systems and entities sub-directories.
|
||||
|
||||
## Overview ##
|
||||
Tiny-ecs has four important types: Worlds, Filters, Systems, and Entities.
|
||||
@@ -32,7 +36,7 @@ Systems in tiny-ecs describe how to update Entities. Systems select certain Enti
|
||||
using a Filter, and then only update those select Entities. Some Systems don't
|
||||
update Entities, and instead just act as function callbacks every update. Tiny-ecs
|
||||
provides functions for creating Systems easily, as well as creating Systems that
|
||||
can be used in an Object Orientented fashion.
|
||||
can be used in an object oriented fashion.
|
||||
|
||||
### Filters ###
|
||||
Filters are used to select Entities. Filters can be any lua function, but
|
||||
@@ -64,17 +68,26 @@ for i = 1, 20 do
|
||||
end
|
||||
```
|
||||
|
||||
## Use It ##
|
||||
Copy paste tiny.lua into your source folder. For stability and consistent API,
|
||||
please use a tagged release or use luarocks. Tagged releases will have a version
|
||||
number in `tiny._VERSION`, while other commits will just have the string 'scm'.
|
||||
|
||||
## Luarocks ##
|
||||
Tiny-ecs is also on [Luarocks](https://luarocks.org/) and can be installed with
|
||||
`luarocks install tiny-ecs`.
|
||||
|
||||
## Demo ##
|
||||
Check out the [demo](https://github.com/bakpakin/tiny-ecs/tree/demo-commandokibbles), a game
|
||||
originally written for Ludum Dare 32 with the theme 'An Unconventional Weapon'. The demo uses
|
||||
[LÖVE](https://love2d.org/), an amazing game framework for lua.
|
||||
|
||||
## Testing ##
|
||||
Tiny-ecs uses [busted](http://olivinelabs.com/busted/) for testing. Install and run
|
||||
`busted` from the command line to test.
|
||||
|
||||
## Documentation ##
|
||||
See API [here](http://bakpakin.github.io/tiny-ecs/doc/).
|
||||
Documentation can be generated locally with [LDoc](http://stevedonovan.github.io/ldoc/).
|
||||
|
||||
## TODO ##
|
||||
|
||||
* More testing
|
||||
* Performance testing / optimization
|
||||
* Improve Documentation
|
||||
* Add more complete examples
|
||||
For the most up-to-date documentation, read the source code, or generate the HTML
|
||||
locally with [LDoc](http://stevedonovan.github.io/ldoc/).
|
||||
See the original forum thread [here](https://love2d.org/forums/viewtopic.php?f=5&t=79937&p=182589).
|
||||
|
||||
@@ -2,6 +2,12 @@ file = "tiny.lua"
|
||||
project = "tiny-ecs"
|
||||
description = "Entity Component System for lua."
|
||||
backtick_references = true
|
||||
one = false
|
||||
format = 'discount'
|
||||
title = "tiny-ecs API"
|
||||
one = true
|
||||
dir = doc
|
||||
sort = true
|
||||
style = '!fixed'
|
||||
package = 'tiny-ecs'
|
||||
not_luadoc = true
|
||||
boilerplate = true
|
||||
no_return_or_parms = true
|
||||
|
||||
@@ -21,4 +21,4 @@ build = {
|
||||
modules = {
|
||||
tiny = "tiny.lua"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package = "tiny-ecs"
|
||||
version = "1.1-1"
|
||||
source = {
|
||||
url = "git://github.com/bakpakin/tiny-ecs",
|
||||
tag = "1.1-1"
|
||||
}
|
||||
description = {
|
||||
summary = "Entity Component System for Lua.",
|
||||
detailed = [[
|
||||
Pure Lua implementation of an easy to use, compact, fast, and flexible
|
||||
Entity Component System. Works well with Object Orientation.
|
||||
]],
|
||||
homepage = "https://github.com/bakpakin/tiny-ecs",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
tiny = "tiny.lua"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package = "tiny-ecs"
|
||||
version = "1.1-2"
|
||||
source = {
|
||||
url = "git://github.com/bakpakin/tiny-ecs",
|
||||
tag = "1.1-2"
|
||||
}
|
||||
description = {
|
||||
summary = "Entity Component System for Lua.",
|
||||
detailed = [[
|
||||
Pure Lua implementation of an easy to use, compact, fast, and flexible
|
||||
Entity Component System. Works well with Object Orientation.
|
||||
]],
|
||||
homepage = "https://github.com/bakpakin/tiny-ecs",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
tiny = "tiny.lua"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package = "tiny-ecs"
|
||||
version = "1.1-3"
|
||||
source = {
|
||||
url = "git://github.com/bakpakin/tiny-ecs",
|
||||
tag = "1.1-3"
|
||||
}
|
||||
description = {
|
||||
summary = "Entity Component System for Lua.",
|
||||
detailed = [[
|
||||
Pure Lua implementation of an easy to use, compact, fast, and flexible
|
||||
Entity Component System. Works well with Object Orientation.
|
||||
]],
|
||||
homepage = "https://github.com/bakpakin/tiny-ecs",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
tiny = "tiny.lua"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package = "tiny-ecs"
|
||||
version = "1.1-4"
|
||||
source = {
|
||||
url = "git://github.com/bakpakin/tiny-ecs",
|
||||
tag = "1.1-4"
|
||||
}
|
||||
description = {
|
||||
summary = "Entity Component System for Lua.",
|
||||
detailed = [[
|
||||
Pure Lua implementation of an easy to use, compact, fast, and flexible
|
||||
Entity Component System. Works well with Object Orientation.
|
||||
]],
|
||||
homepage = "https://github.com/bakpakin/tiny-ecs",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
tiny = "tiny.lua"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package = "tiny-ecs"
|
||||
version = "1.1-5"
|
||||
source = {
|
||||
url = "git://github.com/bakpakin/tiny-ecs",
|
||||
tag = "1.1-5"
|
||||
}
|
||||
description = {
|
||||
summary = "Entity Component System for Lua.",
|
||||
detailed = [[
|
||||
Pure Lua implementation of an easy to use, compact, fast, and flexible
|
||||
Entity Component System. Works well with Object Orientation.
|
||||
]],
|
||||
homepage = "https://github.com/bakpakin/tiny-ecs",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
tiny = "tiny.lua"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package = "tiny-ecs"
|
||||
version = "1.1-6"
|
||||
source = {
|
||||
url = "git://github.com/bakpakin/tiny-ecs",
|
||||
tag = "1.1-6"
|
||||
}
|
||||
description = {
|
||||
summary = "Entity Component System for Lua.",
|
||||
detailed = [[
|
||||
Pure Lua implementation of an easy to use, compact, fast, and flexible
|
||||
Entity Component System. Works well with Object Orientation.
|
||||
]],
|
||||
homepage = "https://github.com/bakpakin/tiny-ecs",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
tiny = "tiny.lua"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package = "tiny-ecs"
|
||||
version = "1.1-7"
|
||||
source = {
|
||||
url = "git://github.com/bakpakin/tiny-ecs",
|
||||
tag = "1.1-7"
|
||||
}
|
||||
description = {
|
||||
summary = "Entity Component System for Lua.",
|
||||
detailed = [[
|
||||
Pure Lua implementation of an easy to use, compact, fast, and flexible
|
||||
Entity Component System. Works well with Object Orientation.
|
||||
]],
|
||||
homepage = "https://github.com/bakpakin/tiny-ecs",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
tiny = "tiny.lua"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package = "tiny-ecs"
|
||||
version = "1.2-1"
|
||||
source = {
|
||||
url = "git://github.com/bakpakin/tiny-ecs",
|
||||
tag = "1.2-1"
|
||||
}
|
||||
description = {
|
||||
summary = "Entity Component System for Lua.",
|
||||
detailed = [[
|
||||
Pure Lua implementation of an easy to use, compact, fast, and flexible
|
||||
Entity Component System. Works well with Object Orientation.
|
||||
]],
|
||||
homepage = "https://github.com/bakpakin/tiny-ecs",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
tiny = "tiny.lua"
|
||||
}
|
||||
}
|
||||
+65
-28
@@ -1,24 +1,20 @@
|
||||
local GLOBALS = {}
|
||||
for k, v in pairs(_G) do
|
||||
GLOBALS[k] = v
|
||||
end
|
||||
|
||||
local tiny = require "tiny"
|
||||
|
||||
-- Taken from answer at http://stackoverflow.com/questions/640642/how-do-you-copy-a-lua-table-by-value
|
||||
local function deep_copy(o, seen)
|
||||
seen = seen or {}
|
||||
if o == nil then return nil end
|
||||
if seen[o] then return seen[o] end
|
||||
|
||||
local no
|
||||
if type(o) == 'table' then
|
||||
no = {}
|
||||
seen[o] = no
|
||||
|
||||
for k, v in next, o, nil do
|
||||
no[deep_copy(k, seen)] = deep_copy(v, seen)
|
||||
local function deep_copy(x)
|
||||
if type(x) == 'table' then
|
||||
local nx = {}
|
||||
for k, v in next, x, nil do
|
||||
nx[deep_copy(k)] = deep_copy(v)
|
||||
end
|
||||
return nx
|
||||
else
|
||||
return x
|
||||
end
|
||||
setmetatable(no, deep_copy(getmetatable(o), seen))
|
||||
else -- number, string, boolean, etc
|
||||
no = o
|
||||
end
|
||||
return no
|
||||
end
|
||||
|
||||
local entityTemplate1 = {
|
||||
@@ -65,7 +61,14 @@ describe('tiny-ecs:', function()
|
||||
local ftap = tiny.requireAll("spinalTap")
|
||||
local fvel = tiny.requireAll("vel")
|
||||
local fxform = tiny.requireAll("xform")
|
||||
local fall = tiny.requireOne("spinalTap", "onlyTen", "littleMan")
|
||||
local fall = tiny.requireAny("spinalTap", "onlyTen", "littleMan")
|
||||
|
||||
-- Only select Entities without "spinalTap"
|
||||
local frtap = tiny.rejectAny("spinalTap")
|
||||
|
||||
-- Select Entities without all three: "spinalTap", "onlyTen", and
|
||||
-- "littleMan"
|
||||
local frall = tiny.rejectAll("spinalTap", "onlyTen", "littleMan")
|
||||
|
||||
assert.truthy(fall(nil, entity1))
|
||||
assert.truthy(ftap(nil, entity1))
|
||||
@@ -77,6 +80,14 @@ describe('tiny-ecs:', function()
|
||||
assert.truthy(fall(nil, entity2))
|
||||
assert.truthy(fall(nil, entity3))
|
||||
|
||||
assert.falsy(frtap(nil, entity1))
|
||||
assert.truthy(frtap(nil, entity2))
|
||||
assert.truthy(frtap(nil, entity3))
|
||||
|
||||
assert.truthy(frall(nil, entity1))
|
||||
assert.truthy(frall(nil, entity2))
|
||||
assert.truthy(frall(nil, entity3))
|
||||
|
||||
end)
|
||||
|
||||
end)
|
||||
@@ -97,9 +108,9 @@ describe('tiny-ecs:', function()
|
||||
|
||||
local timePassed = 0
|
||||
local oneTimeSystem = tiny.system()
|
||||
function oneTimeSystem:update(entities, dt)
|
||||
function oneTimeSystem:update(dt)
|
||||
timePassed = timePassed + dt
|
||||
end
|
||||
end
|
||||
|
||||
before_each(function()
|
||||
entity1 = deep_copy(entityTemplate1)
|
||||
@@ -109,6 +120,11 @@ describe('tiny-ecs:', function()
|
||||
timePassed = 0
|
||||
end)
|
||||
|
||||
after_each(function()
|
||||
world:clearSystems()
|
||||
world:refresh()
|
||||
end)
|
||||
|
||||
it("Create World", function()
|
||||
assert.equals(world:getEntityCount(), 3)
|
||||
assert.equals(world:getSystemCount(), 2)
|
||||
@@ -138,15 +154,19 @@ describe('tiny-ecs:', function()
|
||||
assert.equals(0, world:getSystemCount())
|
||||
end)
|
||||
|
||||
it("Disable and Enable Systems", function()
|
||||
world:deactivate(moveSystem, oneTimeSystem)
|
||||
it("Deactivate and Activate Systems", function()
|
||||
moveSystem.active = false
|
||||
oneTimeSystem.active = false
|
||||
world:update(1)
|
||||
assert.equals(world:getSystemCount(), 2)
|
||||
assert.equals(timePassed, 0)
|
||||
assert.equals(entity1.xform.x, entityTemplate1.xform.x)
|
||||
world:activate(moveSystem, oneTimeSystem)
|
||||
moveSystem.active = true
|
||||
oneTimeSystem.active = true
|
||||
world:update(1)
|
||||
assert.equals(timePassed, 1)
|
||||
assert.are_not.equal(entity1.xform.x, entityTemplate1.xform.x)
|
||||
assert.equals(world:getSystemCount(), 2)
|
||||
end)
|
||||
|
||||
it("Clear Entities", function()
|
||||
@@ -181,7 +201,7 @@ describe('tiny-ecs:', function()
|
||||
|
||||
it("Add Systems Multiple Times", function()
|
||||
world:update(1)
|
||||
world:add(moveSystem, oneTimeSystem)
|
||||
assert.has_error(function() world:add(moveSystem, oneTimeSystem) end, "System already belongs to a World.")
|
||||
world:update(2)
|
||||
assert.equals(2, world:getSystemCount())
|
||||
assert.equals(3, world:getEntityCount())
|
||||
@@ -191,7 +211,7 @@ describe('tiny-ecs:', function()
|
||||
world:update(1)
|
||||
world:remove(moveSystem)
|
||||
world:update(2)
|
||||
world:remove(moveSystem)
|
||||
assert.has_error(function() world:remove(moveSystem) end, "System does not belong to this World.")
|
||||
world:update(2)
|
||||
assert.equals(1, world:getSystemCount())
|
||||
assert.equals(3, world:getEntityCount())
|
||||
@@ -201,10 +221,27 @@ describe('tiny-ecs:', function()
|
||||
world:update(1)
|
||||
world:setSystemIndex(moveSystem, 2)
|
||||
world:update(1)
|
||||
assert.equals(2, world:getSystemIndex(moveSystem))
|
||||
assert.equals(1, world:getSystemIndex(oneTimeSystem))
|
||||
assert.equals(2, moveSystem.index)
|
||||
assert.equals(1, oneTimeSystem.index)
|
||||
end)
|
||||
|
||||
it("Sorts Entities in Sorting Systems", function()
|
||||
local sortsys = tiny.sortedProcessingSystem()
|
||||
sortsys.filter = tiny.requireAll("vel")
|
||||
function sortsys:compare(e1, e2)
|
||||
return e1.vel.x < e2.vel.x
|
||||
end
|
||||
world:add(sortsys)
|
||||
world:update(0)
|
||||
assert.equals(sortsys.entities[1], entity2)
|
||||
assert.equals(sortsys.entities[2], entity3)
|
||||
assert.equals(sortsys.entities[3], entity1)
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
it("Doesn't pollute the global namespace", function()
|
||||
assert.are.same(_G, GLOBALS)
|
||||
end)
|
||||
|
||||
end)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package = "tiny-ecs"
|
||||
version = "scm-0"
|
||||
source = {
|
||||
url = "git://github.com/bakpakin/tiny-ecs",
|
||||
}
|
||||
description = {
|
||||
summary = "Entity Component System for Lua.",
|
||||
detailed = [[
|
||||
Pure Lua implementation of an easy to use, compact, fast, and flexible
|
||||
Entity Component System. Works well with Object Orientation.
|
||||
]],
|
||||
homepage = "https://github.com/bakpakin/tiny-ecs",
|
||||
license = "MIT"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1"
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
tiny = "tiny.lua"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user