84 Commits

Author SHA1 Message Date
Calvin Rose
5997f949cd Update rockspecs. 2016-06-19 11:01:57 -04:00
Calvin Rose
ea6009a8d2 Add a rockspec. 2016-06-18 22:47:06 -04:00
Calvin Rose
7da4efb7df Edit README and remove version from library code for easier release cycle.
I don't like git hooks for that kind of thing and its not really necessary.
2016-06-18 13:35:26 -04:00
Calvin Rose
9bc366a2fb Merge branch 'master' of https://github.com/bakpakin/tiny-ecs 2016-06-18 13:22:08 -04:00
Calvin Rose
80b7b48703 Conform to 80 column lines. 2016-06-18 13:21:34 -04:00
bakpakin
0488bff1d9 Fix slightly incorrect pattern for matching filters (only matters on incorrect filters). 2016-05-19 18:18:39 +08:00
bakpakin
ee192d94af Add init.lua for easy require if used as a submodule. 2016-05-19 17:50:54 +08:00
Calvin Rose
a518e15e44 Merge pull request #7 from tst2005/patch-1
typo fix
2016-04-27 10:30:25 -04:00
TsT
37c2c49300 typo fix
Currenty the `doc = doc` is equal to `doc = nil`.
The "doc" directory is used because it's the internal LDoc default.
2016-04-27 13:55:10 +02:00
Calvin Rose
195c882bbd Add documentation for preWrap and postWrap. 2016-04-13 15:01:53 -04:00
Calvin Rose
29a4a02f30 Add tests for postWrap and preWrap. 2016-04-13 14:39:39 -04:00
Calvin Rose
df5c84033b Add code for preWrap and postWrap to system. 2016-04-13 14:28:38 -04:00
bakpakin
d9c296dae6 Update documentation. 2016-03-06 18:20:18 -05:00
bakpakin
08e5f13d85 Begin experimental option to not use caching. 2016-03-06 14:42:48 -05:00
bakpakin
cbf71d2cb2 Add rockspec for version to 1.3-1 2016-03-05 16:42:14 -05:00
bakpakin
93a19d93c8 Wrap error throwing functions in pcalls and make doc look cleaner for tiny.filter. 2016-03-05 16:35:06 -05:00
bakpakin
4148855233 Bump version. 2016-03-05 16:20:09 -05:00
bakpakin
27f881444a Fix string filter generator. 2016-03-05 16:06:56 -05:00
bakpakin
3b4bd9920b Add generic filter. 2016-03-05 15:34:21 -05:00
bakpakin
206361ca38 Make filters compile. Add some filter tests. 2016-03-05 13:34:44 -05:00
bakpakin
29158282bd Update Copyright Date. 2016-02-29 19:19:34 -05:00
bakpakin
2403a9019c Release version 1.2-1. 2015-09-08 16:25:10 -04:00
bakpakin
6234e4b741 Document onAddToWorld and onRemoveFromWorld. 2015-09-08 16:19:07 -04:00
bakpakin
b870b5a34e Add onAddToWorld and onRemoveFromWorld callbacks to systems. Also, adding or removing systems to a world twice raises an error. 2015-09-08 13:37:53 -04:00
bakpakin
f3b16a40f6 Add some simple assertions to adding and removing systems. 2015-09-08 13:22:07 -04:00
bakpakin
5035d2c8a7 Make the scope of many local variables smaller. 2015-08-27 14:55:24 -04:00
bakpakin
18270cd60a Adding already added entities no longer removes them from the World first, just updates them to relavent Systems. 2015-08-27 14:31:45 -04:00
bakpakin
dba8e7c89f Remove indication of a versioned release in tiny.lua. 2015-08-27 13:51:13 -04:00
bakpakin
fccff0329e Add travis to tiny-ecs. 2015-08-27 13:47:28 -04:00
bakpakin
8a759edca2 Fix docs again. *sigh* 2015-08-27 13:32:51 -04:00
bakpakin
d9d311d858 Fix system docs. 2015-08-27 13:26:09 -04:00
bakpakin
9834dfa9d6 Fix Adding systems and items to the world inside a call to system:onAdd() 2015-08-24 12:52:11 -04:00
bakpakin
a5af4b6ecd Index systems from the end like string.sub. 2015-08-22 22:45:07 -04:00
bakpakin
f0e6ce7880 Update to version 1.1-7. 2015-08-05 21:01:53 -04:00
bakpakin
26f8259f2b Add tiny.refresh for updating a World without updating Systems. 2015-07-29 12:40:13 -04:00
bakpakin
b1c7e2ba83 Update to version 1.1-6. 2015-07-07 19:47:06 -04:00
bakpakin
6b549fcbc1 Readd tiny.getSystemIndex(world, system) 2015-07-07 19:26:12 -04:00
bakpakin
b9d994ad50 Update documentation for what functions return.
Remove useless code in world metatable
Make tiny.world(...) return newworld, ...
2015-07-07 19:05:56 -04:00
bakpakin
ce8ca35f7e Remove world.systemIndices to fix possible obscure bugs.
Remove tiny.getSystemIndex(world, system) in favor of a System 'index'
field.
Add some comments and documentation.
2015-07-06 23:28:50 -04:00
bakpakin
19ae03707f Make tiny.add, tiny.remove, and similar methods return entities and systems. 2015-07-06 22:01:06 -04:00
bakpakin
c1f1225248 Update to version 1.1-5. 2015-06-21 14:48:48 -04:00
bakpakin
45e8552054 Fix entity count in worlds. 2015-06-21 14:42:03 -04:00
bakpakin
f187dce4fd Update documentation. 2015-06-19 19:45:26 -04:00
bakpakin
927652597c Update to version 1.1-4. 2015-06-19 19:08:06 -04:00
bakpakin
6b3af0f2da Remove 2.0-1 from existence. 2015-06-19 18:55:06 -04:00
bakpakin
31f3396db1 Change System API again.
Remove tiny.getSystemEntityCount because it's useless and deprecation is for chumps.
2015-06-19 18:48:18 -04:00
bakpakin
cb9ab332d2 Fix sorting + add sorting test. 2015-06-18 16:02:16 -04:00
bakpakin
1fd32dab9a Add "world" flag in Systems. Clean up Systems when removing them from Worlds. 2015-06-18 15:19:21 -04:00
bakpakin
0a12897695 Correct use of 'self' in intervalSystemUpdate 2015-06-17 10:35:47 -04:00
bakpakin
e44ac6cdb3 Update to version 2.0-1 2015-06-16 23:48:57 -04:00
bakpakin
6f299470d0 Add CHANGELOG.md 2015-06-16 23:44:19 -04:00
bakpakin
61ffd2551b Readd tiny.processingSystem(table). 2015-06-16 23:26:48 -04:00
bakpakin
c66ed98a5a Add License sticker to README.md. 2015-06-16 23:13:53 -04:00
bakpakin
2621bd16a3 Add tiny.getSystemEntityCount(system). 2015-06-16 22:51:23 -04:00
bakpakin
c408267932 Update documentation. 2015-06-16 22:39:10 -04:00
bakpakin
557927577d Fix sorting. Change API for creating Systems to be more flexible. 2015-06-16 21:15:30 -04:00
bakpakin
cbfc3d360f Add attributes to tiny.system. Implement Interval Systems. 2015-06-16 20:28:21 -04:00
bakpakin
d35d62ed3c Add optional filter to tiny.update(world, dt, [filter]) 2015-06-16 19:45:09 -04:00
bakpakin
74666ca0c3 Fix adding inactive Systems. 2015-06-16 19:14:56 -04:00
bakpakin
5978ace463 Update to version 1.1-3 2015-06-14 10:22:03 -04:00
bakpakin
a504bd6336 Add removeSystem to World metatable. 2015-06-14 10:17:18 -04:00
bakpakin
69ae37586e Fix scm rockspec. 2015-06-07 20:05:56 -04:00
bakpakin
44fb94c457 Add scm rockspec. Fix README. 2015-06-07 18:47:50 -04:00
bakpakin
9230dad1e1 Update README.md to direct users to demo. 2015-05-17 08:26:04 +08:00
bakpakin
e4bf3f3767 Update to version 1.1-2. 2015-05-07 19:53:51 +08:00
bakpakin
71e97c12f6 Improve System documentation. 2015-05-07 19:45:28 +08:00
bakpakin
7c4ff7747c Change names of tiny.requireOne and tiny.rejectOne to tiny.requireAny and tiny.rejectAny. 2015-05-07 17:32:32 +08:00
bakpakin
808407f7c4 Fix 'tiny.add' and 'tiny.remove' iterating nil values. 2015-05-05 22:21:39 +08:00
bakpakin
153f326612 Add two new filter functions - rejectAll and rejectOne. 2015-05-05 22:03:04 +08:00
bakpakin
a4e3c90724 Update version to 1.1-1. 2015-05-04 20:24:03 +08:00
bakpakin
e47920f332 Update documentation. 2015-05-04 20:21:12 +08:00
bakpakin
e96d494526 Change sorted System calbacks. 2015-05-04 12:05:53 +08:00
bakpakin
994f3b6533 Remove tiny.activate and tiny.deactivate. 2015-05-04 11:46:18 +08:00
bakpakin
264d835334 Fix Clearing Systems. 2015-05-04 09:32:04 +08:00
bakpakin
e54f29884c Remove systemData from luadoc. 2015-05-04 09:24:36 +08:00
bakpakin
9991ff7474 Remove use of systemData - instead, Systems now have mutable data.
This removes a level of indirection and prevents passing around of entities.
2015-05-04 09:09:34 +08:00
bakpakin
5e7d2ea7fc Add license in tiny.lua.
All non-release commits are now versioned 'dev'.
2015-05-04 08:21:30 +08:00
bakpakin
6d1b280a40 Make enabling/disabling Systems not use varargs. 2015-05-03 23:31:56 +08:00
bakpakin
fb345c7718 Add Sorted Systems.
Remove tiny.manageSystems and tiny.manageEntities from API.
Add onModify System callback.
2015-05-03 23:05:50 +08:00
bakpakin
0f86eae571 Remove pesky trailing whitespace >:( 2015-04-27 21:48:27 +08:00
bakpakin
fd49633d17 Don't update a System without an update field in the System. 2015-04-27 15:45:54 +08:00
bakpakin
94fc3ac453 Update README.md to include luarocks. 2015-04-27 14:24:59 +08:00
bakpakin
4109d37cdb Update README.md to include demo. 2015-04-27 14:20:34 +08:00
bakpakin
c9dccaf85f Ignore .rock. 2015-04-26 11:55:07 +08:00
20 changed files with 1164 additions and 377 deletions
Vendored
+3
View File
@@ -3,3 +3,6 @@ doc/*
index.html index.html
ldoc.css ldoc.css
topics/* topics/*
#Ignore generated rocks
*.rock
+39
View File
@@ -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
View File
@@ -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:
+30 -20
View File
@@ -1,24 +1,26 @@
# 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 [![Build Status](https://travis-ci.org/bakpakin/tiny-ecs.png?branch=master)](https://travis-ci.org/bakpakin/tiny-ecs)[![License](http://img.shields.io/badge/Licence-MIT-brightgreen.svg)](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 objected 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
## Use It ## demo branch, specifically the systems and entities sub-directories.
Copy paste tiny.lua into your source folder.
## 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 Systems'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.
@@ -32,10 +34,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.
@@ -47,7 +49,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 = {
@@ -64,17 +66,25 @@ for i = 1, 20 do
end end
``` ```
## Use It ##
Copy paste tiny.lua into your source folder. For stability and consistent API,
please use a tagged release or use luarocks.
## 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 ## ## 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
`busted` from the command line to test. `busted` from the command line to test.
## 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
* Improve Documentation
* Add more complete examples
+9 -3
View File
@@ -2,6 +2,12 @@ file = "tiny.lua"
project = "tiny-ecs" project = "tiny-ecs"
description = "Entity Component System for lua." description = "Entity Component System for lua."
backtick_references = true backtick_references = true
one = false format = 'discount'
dir = doc title = "tiny-ecs API"
sort = true one = true
dir = "doc"
style = '!fixed'
package = 'tiny-ecs'
not_luadoc = true
boilerplate = true
no_return_or_parms = true
+5
View File
@@ -0,0 +1,5 @@
-- 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 directory = (...):match("(.-)[^%.]+$")
return require(directory .. 'tiny')
+1 -1
View File
@@ -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.",
+24
View File
@@ -0,0 +1,24 @@
package = "tiny-ecs"
version = "1.1-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"
}
}
+24
View File
@@ -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"
}
}
+24
View File
@@ -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"
}
}
+24
View File
@@ -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"
}
}
+24
View File
@@ -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"
}
}
+24
View File
@@ -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"
}
}
+24
View File
@@ -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"
}
}
+24
View File
@@ -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"
}
}
+24
View File
@@ -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"
}
}
+24
View File
@@ -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"
}
}
+129 -26
View File
@@ -1,24 +1,20 @@
local GLOBALS = {}
for k, v in pairs(_G) do
GLOBALS[k] = v
end
local tiny = require "tiny" 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(x)
local function deep_copy(o, seen) if type(x) == 'table' then
seen = seen or {} local nx = {}
if o == nil then return nil end for k, v in next, x, nil do
if seen[o] then return seen[o] end nx[deep_copy(k)] = deep_copy(v)
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)
end end
setmetatable(no, deep_copy(getmetatable(o), seen)) return nx
else -- number, string, boolean, etc else
no = o return x
end end
return no
end end
local entityTemplate1 = { local entityTemplate1 = {
@@ -65,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))
@@ -77,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)
@@ -97,7 +151,7 @@ describe('tiny-ecs:', function()
local timePassed = 0 local timePassed = 0
local oneTimeSystem = tiny.system() local oneTimeSystem = tiny.system()
function oneTimeSystem:update(entities, dt) function oneTimeSystem:update(dt)
timePassed = timePassed + dt timePassed = timePassed + dt
end end
@@ -109,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)
@@ -138,15 +197,19 @@ describe('tiny-ecs:', function()
assert.equals(0, world:getSystemCount()) assert.equals(0, world:getSystemCount())
end) end)
it("Disable and Enable Systems", function() it("Deactivate and Activate Systems", function()
world:deactivate(moveSystem, oneTimeSystem) moveSystem.active = false
oneTimeSystem.active = false
world:update(1) world:update(1)
assert.equals(world:getSystemCount(), 2)
assert.equals(timePassed, 0) assert.equals(timePassed, 0)
assert.equals(entity1.xform.x, entityTemplate1.xform.x) assert.equals(entity1.xform.x, entityTemplate1.xform.x)
world:activate(moveSystem, oneTimeSystem) moveSystem.active = true
oneTimeSystem.active = true
world:update(1) world:update(1)
assert.equals(timePassed, 1) assert.equals(timePassed, 1)
assert.are_not.equal(entity1.xform.x, entityTemplate1.xform.x) assert.are_not.equal(entity1.xform.x, entityTemplate1.xform.x)
assert.equals(world:getSystemCount(), 2)
end) end)
it("Clear Entities", function() it("Clear Entities", function()
@@ -170,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())
@@ -181,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())
@@ -191,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())
@@ -201,10 +266,48 @@ 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)
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)
it("Doesn't pollute the global namespace", function()
assert.are.same(_G, GLOBALS)
end) end)
end) end)
+23
View File
@@ -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"
}
}
+655 -297
View File
File diff suppressed because it is too large Load Diff