mirror of
https://github.com/bakpakin/tiny-ecs.git
synced 2026-07-22 07:56:52 -06:00
Compare commits
88 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
821914795d | ||
|
|
2beca9a0ad | ||
|
|
afd7d326d7 | ||
|
|
e095e10d44 | ||
|
|
3c4b3a7f68 | ||
|
|
0f17f116ab | ||
|
|
584be2c952 | ||
|
|
36364df4e6 | ||
|
|
65de2a9c6f | ||
|
|
4631216c27 | ||
|
|
7c7de1db0c | ||
|
|
fe7e2854de | ||
|
|
311943e070 | ||
|
|
8a3c22e74f | ||
|
|
a0fa0904f6 | ||
|
|
80bb6b8d31 | ||
|
|
83d806011b | ||
|
|
d720d361e6 | ||
|
|
d94b178670 | ||
|
|
5997f949cd | ||
|
|
ea6009a8d2 | ||
|
|
7da4efb7df | ||
|
|
9bc366a2fb | ||
|
|
80b7b48703 | ||
|
|
0488bff1d9 | ||
|
|
ee192d94af | ||
|
|
a518e15e44 | ||
|
|
37c2c49300 | ||
|
|
195c882bbd | ||
|
|
29a4a02f30 | ||
|
|
df5c84033b | ||
|
|
d9c296dae6 | ||
|
|
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 | ||
|
|
5978ace463 | ||
|
|
a504bd6336 | ||
|
|
69ae37586e | ||
|
|
44fb94c457 | ||
|
|
9230dad1e1 | ||
|
|
e4bf3f3767 | ||
|
|
71e97c12f6 | ||
|
|
7c4ff7747c | ||
|
|
808407f7c4 | ||
|
|
153f326612 |
+39
@@ -0,0 +1,39 @@
|
|||||||
|
language: c
|
||||||
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- LUAROCKS_BASE=luarocks-3.2.1
|
||||||
|
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,22 +1,34 @@
|
|||||||
# tiny-ecs #
|
# tiny-ecs #
|
||||||
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
|
## NOTE
|
||||||
|
|
||||||
|
Although there have been almost no commits in several years, this
|
||||||
|
project is not abandoned. tiny-ecs is, for most intents and
|
||||||
|
purposes, finished, and no bugs have been brought to my attention in a while.
|
||||||
|
New issues on GitHub will be addressed.
|
||||||
|
|
||||||
|
[](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
|
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").
|
||||||
|
|
||||||
Tiny-ecs also works well with Objected Oriented programming in lua because
|
Tiny-ecs also works well with object-oriented programming in Lua because
|
||||||
Systems and Entities do not use metatables. This means you can subclass your
|
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.
|
Systems and Entities and use existing Lua class frameworks with tiny-ecs, no problem.
|
||||||
|
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 subdirectories.
|
||||||
|
|
||||||
## Overview ##
|
## Overview ##
|
||||||
Tiny-ecs has four important types: Worlds, Filters, Systems, and Entities.
|
Tiny-ecs has four important types: Worlds, Filters, Systems, and Entities.
|
||||||
Entities, however, can be any lua table, and Filters are just functions that
|
Entities, however, can be any Lua table, and Filters are just functions that
|
||||||
take an Entity as a parameter.
|
take an Entity as a parameter.
|
||||||
|
|
||||||
### Entities ###
|
### Entities ###
|
||||||
Entities are simply lua tables of data that gets processed by Systems. Entities
|
Entities are simply Lua tables of data that gets processed by Systems. Entities
|
||||||
should contain primarily data rather than code, as it is the Systems's job to
|
should contain primarily data rather than code, as it is the System's job to
|
||||||
do logic on data. Henceforth, a key-value pair in an Entity will
|
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.
|
||||||
|
|
||||||
@@ -29,10 +41,10 @@ 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
|
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
|
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
|
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 ###
|
||||||
Filters are used to select Entities. Filters can be any lua function, but
|
Filters are used to select Entities. Filters can be any Lua function, but
|
||||||
tiny-ecs provides some functions for generating common ones, like selecting
|
tiny-ecs provides some functions for generating common ones, like selecting
|
||||||
only Entities that have all required components.
|
only Entities that have all required components.
|
||||||
|
|
||||||
@@ -44,7 +56,7 @@ local talkingSystem = tiny.processingSystem()
|
|||||||
talkingSystem.filter = tiny.requireAll("name", "mass", "phrase")
|
talkingSystem.filter = tiny.requireAll("name", "mass", "phrase")
|
||||||
function talkingSystem:process(e, dt)
|
function talkingSystem:process(e, dt)
|
||||||
e.mass = e.mass + dt * 3
|
e.mass = e.mass + dt * 3
|
||||||
print(e.name .. ", who weighs " .. e.mass .. " pounds, says, \"" .. e.phrase .. "\"")
|
print(("%s who weighs %d pounds, says %q."):format(e.name, e.mass, e.phrase))
|
||||||
end
|
end
|
||||||
|
|
||||||
local joe = {
|
local joe = {
|
||||||
@@ -63,17 +75,16 @@ end
|
|||||||
|
|
||||||
## Use It ##
|
## Use It ##
|
||||||
Copy paste tiny.lua into your source folder. For stability and consistent API,
|
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
|
please use a tagged release or use LuaRocks.
|
||||||
number in `tiny._VERSION`, while other commits will just have the string 'dev'.
|
|
||||||
|
|
||||||
## Luarocks ##
|
## Luarocks ##
|
||||||
Tiny-ecs is also on [Luarocks](https://luarocks.org/) and can be installed with
|
Tiny-ecs is also on [LuaRocks](https://luarocks.org/) and can be installed with
|
||||||
`luarocks install tiny-ecs`.
|
`luarocks install tiny-ecs`.
|
||||||
|
|
||||||
## 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
|
||||||
@@ -81,11 +92,6 @@ Tiny-ecs uses [busted](http://olivinelabs.com/busted/) for testing. Install and
|
|||||||
|
|
||||||
## Documentation ##
|
## Documentation ##
|
||||||
See API [here](http://bakpakin.github.io/tiny-ecs/doc/).
|
See API [here](http://bakpakin.github.io/tiny-ecs/doc/).
|
||||||
Documentation can be generated locally with [LDoc](http://stevedonovan.github.io/ldoc/).
|
For the most up-to-date documentation, read the source code, or generate the HTML
|
||||||
|
locally with [LDoc](http://stevedonovan.github.io/ldoc/).
|
||||||
## TODO ##
|
See the original forum thread [here](https://love2d.org/forums/viewtopic.php?f=5&t=79937&p=182589).
|
||||||
|
|
||||||
* More testing
|
|
||||||
* Performance testing / optimization
|
|
||||||
* Add more System types
|
|
||||||
* Improve Documentation
|
|
||||||
|
|||||||
@@ -5,8 +5,9 @@ backtick_references = true
|
|||||||
format = 'discount'
|
format = 'discount'
|
||||||
title = "tiny-ecs API"
|
title = "tiny-ecs API"
|
||||||
one = true
|
one = true
|
||||||
dir = doc
|
dir = "doc"
|
||||||
style = '!fixed'
|
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,6 @@
|
|||||||
|
-- Helper Lua file for easy require if tiny-ecs is used as a git submodule or
|
||||||
|
-- folder. Not needed in many cases, including luarocks distribution.
|
||||||
|
|
||||||
|
local args = {...}
|
||||||
|
local directory = args[1]
|
||||||
|
return require(directory .. '.tiny')
|
||||||
@@ -2,7 +2,7 @@ package = "tiny-ecs"
|
|||||||
version = "1.0-2"
|
version = "1.0-2"
|
||||||
source = {
|
source = {
|
||||||
url = "git://github.com/bakpakin/tiny-ecs",
|
url = "git://github.com/bakpakin/tiny-ecs",
|
||||||
tag = "1.0-2"
|
tag = version
|
||||||
}
|
}
|
||||||
description = {
|
description = {
|
||||||
summary = "Entity Component System for Lua.",
|
summary = "Entity Component System for Lua.",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package = "tiny-ecs"
|
|||||||
version = "1.1-1"
|
version = "1.1-1"
|
||||||
source = {
|
source = {
|
||||||
url = "git://github.com/bakpakin/tiny-ecs",
|
url = "git://github.com/bakpakin/tiny-ecs",
|
||||||
tag = "1.1-1"
|
tag = version
|
||||||
}
|
}
|
||||||
description = {
|
description = {
|
||||||
summary = "Entity Component System for Lua.",
|
summary = "Entity Component System for Lua.",
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package = "tiny-ecs"
|
||||||
|
version = "1.1-2"
|
||||||
|
source = {
|
||||||
|
url = "git://github.com/bakpakin/tiny-ecs",
|
||||||
|
tag = version
|
||||||
|
}
|
||||||
|
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 = version
|
||||||
|
}
|
||||||
|
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 = version
|
||||||
|
}
|
||||||
|
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 = version
|
||||||
|
}
|
||||||
|
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 = version
|
||||||
|
}
|
||||||
|
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 = version
|
||||||
|
}
|
||||||
|
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 = version
|
||||||
|
}
|
||||||
|
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 = version
|
||||||
|
}
|
||||||
|
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-2"
|
||||||
|
source = {
|
||||||
|
url = "git://github.com/bakpakin/tiny-ecs",
|
||||||
|
tag = version
|
||||||
|
}
|
||||||
|
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-3"
|
||||||
|
source = {
|
||||||
|
url = "git://github.com/bakpakin/tiny-ecs",
|
||||||
|
tag = version
|
||||||
|
}
|
||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
+123
-5
@@ -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)
|
||||||
@@ -56,7 +61,14 @@ describe('tiny-ecs:', function()
|
|||||||
local ftap = tiny.requireAll("spinalTap")
|
local ftap = tiny.requireAll("spinalTap")
|
||||||
local fvel = tiny.requireAll("vel")
|
local fvel = tiny.requireAll("vel")
|
||||||
local fxform = tiny.requireAll("xform")
|
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(fall(nil, entity1))
|
||||||
assert.truthy(ftap(nil, entity1))
|
assert.truthy(ftap(nil, entity1))
|
||||||
@@ -68,6 +80,57 @@ describe('tiny-ecs:', function()
|
|||||||
assert.truthy(fall(nil, entity2))
|
assert.truthy(fall(nil, entity2))
|
||||||
assert.truthy(fall(nil, entity3))
|
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)
|
||||||
|
|
||||||
|
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)
|
end)
|
||||||
@@ -100,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)
|
||||||
@@ -165,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())
|
||||||
@@ -176,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())
|
||||||
@@ -186,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())
|
||||||
@@ -196,10 +266,58 @@ 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)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
it("Runs preWrap and postWrap for systems.", function()
|
||||||
|
local str = ""
|
||||||
|
local sys1 = tiny.system()
|
||||||
|
local sys2 = tiny.system()
|
||||||
|
function sys1:preWrap(dt)
|
||||||
|
str = str .. "<"
|
||||||
|
end
|
||||||
|
function sys2:preWrap(dt)
|
||||||
|
str = str .. "{"
|
||||||
|
end
|
||||||
|
function sys1:postWrap(dt)
|
||||||
|
str = str .. ">"
|
||||||
|
end
|
||||||
|
function sys2:postWrap(dt)
|
||||||
|
str = str .. "}"
|
||||||
|
end
|
||||||
|
world:add(sys1, sys2)
|
||||||
|
world:update(1)
|
||||||
|
assert.equals(str, "{<>}")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("Doesn't pollute the global namespace", function()
|
||||||
|
assert.are.same(_G, GLOBALS)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("Can set system indices", function()
|
||||||
|
local world = tiny.world()
|
||||||
|
local systemA = tiny.system()
|
||||||
|
local systemB = tiny.system()
|
||||||
|
world:addSystem(systemA)
|
||||||
|
world:addSystem(systemB)
|
||||||
|
world:setSystemIndex(systemA, 1)
|
||||||
|
assert(true)
|
||||||
|
end)
|
||||||
|
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
local tiny = require('tiny')
|
||||||
|
|
||||||
|
local world = tiny.world()
|
||||||
|
local systemA = tiny.system()
|
||||||
|
local systemB = tiny.system()
|
||||||
|
world:addSystem(systemA)
|
||||||
|
world:addSystem(systemB)
|
||||||
|
world:setSystemIndex(systemA, 1)
|
||||||
@@ -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