mirror of
https://github.com/bakpakin/tiny-ecs.git
synced 2026-07-22 07:56:52 -06:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
821914795d | ||
|
|
2beca9a0ad | ||
|
|
afd7d326d7 | ||
|
|
e095e10d44 | ||
|
|
3c4b3a7f68 | ||
|
|
0f17f116ab | ||
|
|
584be2c952 | ||
|
|
36364df4e6 | ||
|
|
65de2a9c6f | ||
|
|
4631216c27 | ||
|
|
7c7de1db0c | ||
|
|
fe7e2854de | ||
|
|
311943e070 |
+2
-2
@@ -1,8 +1,8 @@
|
||||
language: erlang
|
||||
language: c
|
||||
|
||||
env:
|
||||
global:
|
||||
- LUAROCKS_BASE=luarocks-2.2.2
|
||||
- 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
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
# tiny-ecs #
|
||||
|
||||
## 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.
|
||||
@@ -8,11 +15,11 @@ 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 object-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.
|
||||
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 sub-directories.
|
||||
demo branch, specifically the systems and entities subdirectories.
|
||||
|
||||
## Overview ##
|
||||
Tiny-ecs has four important types: Worlds, Filters, Systems, and Entities.
|
||||
@@ -21,7 +28,7 @@ take an Entity as a parameter.
|
||||
|
||||
### 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
|
||||
be referred to as a Component.
|
||||
|
||||
@@ -49,7 +56,7 @@ local talkingSystem = tiny.processingSystem()
|
||||
talkingSystem.filter = tiny.requireAll("name", "mass", "phrase")
|
||||
function talkingSystem:process(e, dt)
|
||||
e.mass = e.mass + dt * 3
|
||||
print(("%s who weighs %d pounds, says %q."):format(e.name, e.mass, e.phrase)
|
||||
print(("%s who weighs %d pounds, says %q."):format(e.name, e.mass, e.phrase))
|
||||
end
|
||||
|
||||
local joe = {
|
||||
@@ -68,10 +75,10 @@ end
|
||||
|
||||
## Use It ##
|
||||
Copy paste tiny.lua into your source folder. For stability and consistent API,
|
||||
please use a tagged release or use luarocks.
|
||||
please use a tagged release or use 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`.
|
||||
|
||||
## Demo ##
|
||||
|
||||
@@ -1,5 +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 directory = (...):match("(.-)[^%.]+$")
|
||||
return require(directory .. 'tiny')
|
||||
local args = {...}
|
||||
local directory = args[1]
|
||||
return require(directory .. '.tiny')
|
||||
|
||||
@@ -310,4 +310,14 @@ describe('tiny-ecs:', 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)
|
||||
|
||||
@@ -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)
|
||||
@@ -230,7 +230,7 @@ end
|
||||
-- removed from the world, after all Entities are removed from the System.
|
||||
-- * `function system:preWrap(dt)` - Called on each system before update is
|
||||
-- called on any system.
|
||||
-- * `function system:postWrap(dt) - Called on each system in reverse order
|
||||
-- * `function system:postWrap(dt)` - Called on each system in reverse order
|
||||
-- after update is called on each system. The idea behind `preWrap` and
|
||||
-- `postWrap` is to allow for systems that modify the behavior of other systems.
|
||||
-- Say there is a DrawingSystem, which draws sprites to the screen, and a
|
||||
@@ -278,11 +278,13 @@ end
|
||||
--
|
||||
-- There is another option to (hopefully) increase performance in systems that
|
||||
-- have items added to or removed from them often, and have lots of entities in
|
||||
-- them. Setting the `nocache' field of the system might improve performance.
|
||||
-- them. Setting the `nocache` field of the system might improve performance.
|
||||
-- It is still experimental. There are some restriction to systems without
|
||||
-- caching, however. * There is no `entities` table. * Callbacks such onAdd,
|
||||
-- onRemove, and onModify will never be called * Noncached systems cannot be
|
||||
-- sorted (There is no entities list to sort).
|
||||
-- caching, however.
|
||||
--
|
||||
-- * There is no `entities` table.
|
||||
-- * Callbacks such onAdd, onRemove, and onModify will never be called
|
||||
-- * Noncached systems cannot be sorted (There is no entities list to sort).
|
||||
--
|
||||
-- @section System
|
||||
|
||||
@@ -307,7 +309,7 @@ local function processingSystemUpdate(system, dt)
|
||||
|
||||
if process then
|
||||
if system.nocache then
|
||||
local entities = system.world.entityList
|
||||
local entities = system.world.entities
|
||||
local filter = system.filter
|
||||
if filter then
|
||||
for i = 1, #entities do
|
||||
@@ -819,6 +821,7 @@ end
|
||||
-- the order in which they Systems processed, because lower indexed Systems are
|
||||
-- processed first. Returns the old system.index.
|
||||
function tiny.setSystemIndex(world, system, index)
|
||||
tiny_manageSystems(world)
|
||||
local oldIndex = system.index
|
||||
local systems = world.systems
|
||||
|
||||
|
||||
Reference in New Issue
Block a user