mirror of
https://github.com/bakpakin/tiny-ecs.git
synced 2026-07-22 07:56:52 -06:00
Compare commits
46 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08e5f13d85 | ||
|
|
cbf71d2cb2 | ||
|
|
93a19d93c8 | ||
|
|
4148855233 | ||
|
|
27f881444a | ||
|
|
3b4bd9920b | ||
|
|
206361ca38 | ||
|
|
29158282bd | ||
|
|
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 |
+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
-1
@@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2015 Calvin Rose
|
Copyright (c) 2016 Calvin Rose
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
# tiny-ecs #
|
# 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.
|
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
|
||||||
@@ -75,7 +80,7 @@ Tiny-ecs is also on [Luarocks](https://luarocks.org/) and can be installed with
|
|||||||
## Demo ##
|
## Demo ##
|
||||||
Check out the [demo](https://github.com/bakpakin/tiny-ecs/tree/demo-commandokibbles), a game
|
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
|
originally written for Ludum Dare 32 with the theme 'An Unconventional Weapon'. The demo uses
|
||||||
[LOVE](https://love2d.org/), an amazing game framework for lua.
|
[LÖVE](https://love2d.org/), an amazing game framework for lua.
|
||||||
|
|
||||||
## Testing ##
|
## Testing ##
|
||||||
Tiny-ecs uses [busted](http://olivinelabs.com/busted/) for testing. Install and run
|
Tiny-ecs uses [busted](http://olivinelabs.com/busted/) for testing. Install and run
|
||||||
@@ -85,3 +90,4 @@ Tiny-ecs uses [busted](http://olivinelabs.com/busted/) for testing. Install and
|
|||||||
See API [here](http://bakpakin.github.io/tiny-ecs/doc/).
|
See API [here](http://bakpakin.github.io/tiny-ecs/doc/).
|
||||||
For the most up-to-date documentation, read the source code, or generate the HTML
|
For the most up-to-date documentation, read the source code, or generate the HTML
|
||||||
locally with [LDoc](http://stevedonovan.github.io/ldoc/).
|
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).
|
||||||
|
|||||||
@@ -10,3 +10,4 @@ style = '!fixed'
|
|||||||
package = 'tiny-ecs'
|
package = 'tiny-ecs'
|
||||||
not_luadoc = true
|
not_luadoc = true
|
||||||
boilerplate = true
|
boilerplate = true
|
||||||
|
no_return_or_parms = true
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package = "tiny-ecs"
|
||||||
|
version = "1.3-1"
|
||||||
|
source = {
|
||||||
|
url = "git://github.com/bakpakin/tiny-ecs",
|
||||||
|
tag = "1.3-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"
|
||||||
|
}
|
||||||
|
}
|
||||||
+76
-4
@@ -1,3 +1,8 @@
|
|||||||
|
local GLOBALS = {}
|
||||||
|
for k, v in pairs(_G) do
|
||||||
|
GLOBALS[k] = v
|
||||||
|
end
|
||||||
|
|
||||||
local tiny = require "tiny"
|
local tiny = require "tiny"
|
||||||
|
|
||||||
local function deep_copy(x)
|
local function deep_copy(x)
|
||||||
@@ -85,6 +90,49 @@ describe('tiny-ecs:', function()
|
|||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("Can use functions as subfilters", function()
|
||||||
|
|
||||||
|
local f1 = tiny.requireAny('a', 'b', 'c')
|
||||||
|
local f2 = tiny.requireAll('x', 'y', 'z')
|
||||||
|
local f = tiny.requireAll(f1, f2)
|
||||||
|
|
||||||
|
assert.truthy(f(nil, {
|
||||||
|
x = true, y = true, z = true, a = true, b = true, c = true
|
||||||
|
}))
|
||||||
|
assert.truthy(f(nil, {
|
||||||
|
x = true, y = true, z = true, a = true
|
||||||
|
}))
|
||||||
|
assert.falsy(f(nil, {
|
||||||
|
x = true, y = true, a = true
|
||||||
|
}))
|
||||||
|
assert.falsy(f(nil, {
|
||||||
|
x = true, y = true, z = true
|
||||||
|
}))
|
||||||
|
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("Can use string filters", function()
|
||||||
|
|
||||||
|
local f = tiny.filter('a|b|c')
|
||||||
|
|
||||||
|
assert.truthy(f(nil, {
|
||||||
|
a = true, b = true, c = true
|
||||||
|
}))
|
||||||
|
assert.truthy(f(nil, {
|
||||||
|
a = true
|
||||||
|
}))
|
||||||
|
assert.truthy(f(nil, {
|
||||||
|
b = true
|
||||||
|
}))
|
||||||
|
assert.truthy(f(nil, {
|
||||||
|
c = true
|
||||||
|
}))
|
||||||
|
assert.falsy(f(nil, {
|
||||||
|
x = true, y = true, z = true
|
||||||
|
}))
|
||||||
|
|
||||||
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('World:', function()
|
describe('World:', function()
|
||||||
@@ -115,6 +163,11 @@ describe('tiny-ecs:', function()
|
|||||||
timePassed = 0
|
timePassed = 0
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
after_each(function()
|
||||||
|
world:clearSystems()
|
||||||
|
world:refresh()
|
||||||
|
end)
|
||||||
|
|
||||||
it("Create World", function()
|
it("Create World", function()
|
||||||
assert.equals(world:getEntityCount(), 3)
|
assert.equals(world:getEntityCount(), 3)
|
||||||
assert.equals(world:getSystemCount(), 2)
|
assert.equals(world:getSystemCount(), 2)
|
||||||
@@ -180,9 +233,11 @@ describe('tiny-ecs:', function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
it("Remove Entities Multiple Times", function()
|
it("Remove Entities Multiple Times", function()
|
||||||
|
assert.equals(3, world:getEntityCount())
|
||||||
world:update(1)
|
world:update(1)
|
||||||
world:remove(entity1, entity2, entity3)
|
world:remove(entity1, entity2, entity3)
|
||||||
world:update(2)
|
world:update(2)
|
||||||
|
assert.equals(0, world:getEntityCount())
|
||||||
world:remove(entity1, entity2, entity3)
|
world:remove(entity1, entity2, entity3)
|
||||||
world:update(2)
|
world:update(2)
|
||||||
assert.equals(2, world:getSystemCount())
|
assert.equals(2, world:getSystemCount())
|
||||||
@@ -191,7 +246,7 @@ describe('tiny-ecs:', function()
|
|||||||
|
|
||||||
it("Add Systems Multiple Times", function()
|
it("Add Systems Multiple Times", function()
|
||||||
world:update(1)
|
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)
|
world:update(2)
|
||||||
assert.equals(2, world:getSystemCount())
|
assert.equals(2, world:getSystemCount())
|
||||||
assert.equals(3, world:getEntityCount())
|
assert.equals(3, world:getEntityCount())
|
||||||
@@ -201,7 +256,7 @@ describe('tiny-ecs:', function()
|
|||||||
world:update(1)
|
world:update(1)
|
||||||
world:remove(moveSystem)
|
world:remove(moveSystem)
|
||||||
world:update(2)
|
world:update(2)
|
||||||
world:remove(moveSystem)
|
assert.has_error(function() world:remove(moveSystem) end, "System does not belong to this World.")
|
||||||
world:update(2)
|
world:update(2)
|
||||||
assert.equals(1, world:getSystemCount())
|
assert.equals(1, world:getSystemCount())
|
||||||
assert.equals(3, world:getEntityCount())
|
assert.equals(3, world:getEntityCount())
|
||||||
@@ -211,10 +266,27 @@ describe('tiny-ecs:', function()
|
|||||||
world:update(1)
|
world:update(1)
|
||||||
world:setSystemIndex(moveSystem, 2)
|
world:setSystemIndex(moveSystem, 2)
|
||||||
world:update(1)
|
world:update(1)
|
||||||
assert.equals(2, world:getSystemIndex(moveSystem))
|
assert.equals(2, moveSystem.index)
|
||||||
assert.equals(1, world:getSystemIndex(oneTimeSystem))
|
assert.equals(1, oneTimeSystem.index)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("Sorts Entities in Sorting Systems", function()
|
||||||
|
local sortsys = tiny.sortedProcessingSystem()
|
||||||
|
sortsys.filter = tiny.filter("vel|xform")
|
||||||
|
function sortsys:compare(e1, e2)
|
||||||
|
return e1.vel.x < e2.vel.x
|
||||||
|
end
|
||||||
|
world:add(sortsys)
|
||||||
|
world:refresh()
|
||||||
|
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)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user