From 265fc0c6f88a26b8bb6fa1f57fe733b71db2fbf9 Mon Sep 17 00:00:00 2001 From: bakpakin Date: Sun, 29 Mar 2015 20:41:30 +0800 Subject: [PATCH] Docs commit. --- doc/index.html | 535 ++++++++++++++++++++++++++++++++++++++ doc/ldoc.css | 307 ++++++++++++++++++++++ doc/source/tiny.lua.html | 452 ++++++++++++++++++++++++++++++++ doc/topics/README.md.html | 122 +++++++++ index.html | 0 5 files changed, 1416 insertions(+) create mode 100644 doc/index.html create mode 100644 doc/ldoc.css create mode 100644 doc/source/tiny.lua.html create mode 100644 doc/topics/README.md.html create mode 100644 index.html diff --git a/doc/index.html b/doc/index.html new file mode 100644 index 0000000..f547acd --- /dev/null +++ b/doc/index.html @@ -0,0 +1,535 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

Module tiny-ecs

+

+

+

Info:

+
    +
  • Author: Calvin Rose
  • +
+ + +

Fields

+ + + + + +
tiny._VERSIONTiny-ecs Version, a period-separated three number string like "1.2.3" with + no leading zeros.
+

Filter functions

+ + + + + + + + + +
tiny.requireAll (...)Makes a Filter that filters Entities with specified Components.
tiny.requireOne (...)Makes a Filter that filters Entities with specified Components.
+

System functions

+ + + + + + + + + +
tiny.processingSystem (filter, entityCallback, onAdd, onRemove)Creates a System that processes Entities every update.
tiny.system (callback, filter, entityCallback, onAdd, onRemove)Creates a System.
+

World functions

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
tiny.add (world, ...)Adds Entities and Systems to the World.
tiny.clearEntities (world)Removes all Entities from the World.
tiny.clearSystems (world)Removes all Systems from the World.
tiny.manageEntities (world)Adds and removes Entities that have been marked.
tiny.manageSystems (world)Adds and removes Systems that have been marked from the World.
tiny.remove (world, ...)Removes Entities and Systems from the World.
tiny.setSystemActive (world, system, active)Sets if a System is active in a world.
tiny.update (world, dt)Updates the World.
tiny.updateSystem (world, system, dt)Updates a System.
tiny.world (...)Creates a new World.
+ +
+
+ + +

Fields

+ +
+
+ + tiny._VERSION +
+
+ Tiny-ecs Version, a period-separated three number string like "1.2.3" with + no leading zeros. + + + + + + + +
+
+

Filter functions

+ + + A Filter is a function that selects which Entities apply to a System. +
+
+ + tiny.requireAll (...) +
+
+ Makes a Filter that filters Entities with specified Components. + An Entity must have all Components to match the filter. + + +

Parameters:

+
    +
  • ... + List of Components +
  • +
+ + + + + +
+
+ + tiny.requireOne (...) +
+
+ Makes a Filter that filters Entities with specified Components. + An Entity must have at least one specified Component to match the filter. + + +

Parameters:

+
    +
  • ... + List of Components +
  • +
+ + + + + +
+
+

System functions

+ + + A System a wrapper around function callbacks for manipulating Entities. +
+
+ + tiny.processingSystem (filter, entityCallback, onAdd, onRemove) +
+
+ Creates a System that processes Entities every update. Also provides + optional callbacks for when Entities are added or removed from the System. + + +

Parameters:

+
    +
  • filter + Function of one argument, an Entity, that returns a boolean +
  • +
  • entityCallback + Function of two arguments, an Entity and delta time +
  • +
  • onAdd + Optional callback for when Entities are added to the System that + takes one argument, an Entity +
  • +
  • onRemove + Similar to onAdd, but is instead called when an Entity is + removed from the System +
  • +
+ + + + + +
+
+ + tiny.system (callback, filter, entityCallback, onAdd, onRemove) +
+
+ Creates a System. + + +

Parameters:

+
    +
  • callback + Function of one argument, delta time, that is called once + per world update +
  • +
  • filter + Function of one argument, an Entity, that returns a boolean +
  • +
  • entityCallback + Function of two arguments, an Entity and delta time +
  • +
  • onAdd + Optional callback for when Enities are added to the System that + takes one argument, an Entity +
  • +
  • onRemove + Similar to onAdd, but is instead called when an Entity is + removed from the System +
  • +
+ + + + + +
+
+

World functions

+ + + A World is a container that manages Entities and Systems. The tiny-ecs module + is set to be the __index of all World tables, so the often clearer syntax of + World:method can be used for any function in the library. For example, + tiny.add(world, e1, e2, e3) is the same as world:add(e1, e2, e3). +
+
+ + tiny.add (world, ...) +
+
+ Adds Entities and Systems to the World. + New objects will enter the World the next time World:update(dt) is called. + Also call this method when an Entity has had its Components changed, such + that it matches different Filters. + + +

Parameters:

+
    +
  • world + +
  • +
  • ... + Systems and Entities +
  • +
+ + + + + +
+
+ + tiny.clearEntities (world) +
+
+ Removes all Entities from the World. + When World:update(dt) is next called, + all Entities will be removed. + + +

Parameters:

+
    +
  • world + +
  • +
+ + + + + +
+
+ + tiny.clearSystems (world) +
+
+ Removes all Systems from the World. + When World:update(dt) is next called, + all Systems will be removed. + + +

Parameters:

+
    +
  • world + +
  • +
+ + + + + +
+
+ + tiny.manageEntities (world) +
+
+ Adds and removes Entities that have been marked. + The user of this library should seldom if ever call this. + + +

Parameters:

+
    +
  • world + +
  • +
+ + + + + +
+
+ + tiny.manageSystems (world) +
+
+ Adds and removes Systems that have been marked from the World. + The user of this library should seldom if ever call this. + + +

Parameters:

+
    +
  • world + +
  • +
+ + + + + +
+
+ + tiny.remove (world, ...) +
+
+ Removes Entities and Systems from the World. Objects will exit the World the + next time World:update(dt) is called. + + +

Parameters:

+
    +
  • world + +
  • +
  • ... + Systems and Entities +
  • +
+ + + + + +
+
+ + tiny.setSystemActive (world, system, active) +
+
+ Sets if a System is active in a world. If the system is active, it will + update automatically when World:update(dt) is called. Otherwise, the user + must call World:updateSystem(system, dt) to update the unactivated system. + + +

Parameters:

+
    +
  • world + +
  • +
  • system + A System in the World activate/deactivate +
  • +
  • active + Boolean new state of the System +
  • +
+ + + + + +
+
+ + tiny.update (world, dt) +
+
+ Updates the World. + Frees Entities that have been marked for freeing, adds + entities that have been marked for adding, etc. + + +

Parameters:

+
    +
  • world + +
  • +
  • dt + Delta time +
  • +
+ + + + + +
+
+ + tiny.updateSystem (world, system, dt) +
+
+ Updates a System. + + +

Parameters:

+
    +
  • world + +
  • +
  • system + A System in the World to update +
  • +
  • dt + Delta time +
  • +
+ + + + + +
+
+ + tiny.world (...) +
+
+ Creates a new World. + Can optionally add default Systems and Entities. + + +

Parameters:

+
    +
  • ... + Systems and Entities to add to the World +
  • +
+ +

Returns:

+
    + + A new World +
+ + + + +
+
+ + +
+
+
+generated by LDoc 1.4.3 +Last updated 2015-03-29 20:36:32 +
+
+ + diff --git a/doc/ldoc.css b/doc/ldoc.css new file mode 100644 index 0000000..7d74ca2 --- /dev/null +++ b/doc/ldoc.css @@ -0,0 +1,307 @@ +/* BEGIN RESET + +Copyright (c) 2010, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.com/yui/license.html +version: 2.8.2r1 +*/ +html { + color: #000; + background: #FFF; +} +body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,p,blockquote,th,td { + margin: 0; + padding: 0; +} +table { + border-collapse: collapse; + border-spacing: 0; +} +fieldset,img { + border: 0; +} +address,caption,cite,code,dfn,em,strong,th,var,optgroup { + font-style: inherit; + font-weight: inherit; +} +del,ins { + text-decoration: none; +} +li { + list-style: disc; + margin-left: 20px; +} +caption,th { + text-align: left; +} +h1,h2,h3,h4,h5,h6 { + font-size: 100%; + font-weight: bold; +} +q:before,q:after { + content: ''; +} +abbr,acronym { + border: 0; + font-variant: normal; +} +sup { + vertical-align: baseline; +} +sub { + vertical-align: baseline; +} +legend { + color: #000; +} +input,button,textarea,select,optgroup,option { + font-family: inherit; + font-size: inherit; + font-style: inherit; + font-weight: inherit; +} +input,button,textarea,select {*font-size:100%; +} +/* END RESET */ + +body { + margin-left: 1em; + margin-right: 1em; + font-family: arial, helvetica, geneva, sans-serif; + background-color: #ffffff; margin: 0px; +} + +code, tt { font-family: monospace; font-size: 1.1em; } +span.parameter { font-family:monospace; } +span.parameter:after { content:":"; } +span.types:before { content:"("; } +span.types:after { content:")"; } +.type { font-weight: bold; font-style:italic } + +body, p, td, th { font-size: .95em; line-height: 1.2em;} + +p, ul { margin: 10px 0 0 0px;} + +strong { font-weight: bold;} + +em { font-style: italic;} + +h1 { + font-size: 1.5em; + margin: 0 0 20px 0; +} +h2, h3, h4 { margin: 15px 0 10px 0; } +h2 { font-size: 1.25em; } +h3 { font-size: 1.15em; } +h4 { font-size: 1.06em; } + +a:link { font-weight: bold; color: #004080; text-decoration: none; } +a:visited { font-weight: bold; color: #006699; text-decoration: none; } +a:link:hover { text-decoration: underline; } + +hr { + color:#cccccc; + background: #00007f; + height: 1px; +} + +blockquote { margin-left: 3em; } + +ul { list-style-type: disc; } + +p.name { + font-family: "Andale Mono", monospace; + padding-top: 1em; +} + +pre.example { + background-color: rgb(245, 245, 245); + border: 1px solid silver; + padding: 10px; + margin: 10px 0 10px 0; + font-family: "Andale Mono", monospace; + font-size: .85em; +} + +pre { + background-color: rgb(245, 245, 245); + border: 1px solid silver; + padding: 10px; + margin: 10px 0 10px 0; + overflow: auto; + font-family: "Andale Mono", monospace; +} + + +table.index { border: 1px #00007f; } +table.index td { text-align: left; vertical-align: top; } + +#container { + margin-left: 1em; + margin-right: 1em; + background-color: #f0f0f0; +} + +#product { + text-align: center; + border-bottom: 1px solid #cccccc; + background-color: #ffffff; +} + +#product big { + font-size: 2em; +} + +#main { + background-color: #f0f0f0; + border-left: 2px solid #cccccc; +} + +#navigation { + float: left; + width: 14em; + vertical-align: top; + background-color: #f0f0f0; + overflow: visible; +} + +#navigation h2 { + background-color:#e7e7e7; + font-size:1.1em; + color:#000000; + text-align: left; + padding:0.2em; + border-top:1px solid #dddddd; + border-bottom:1px solid #dddddd; +} + +#navigation ul +{ + font-size:1em; + list-style-type: none; + margin: 1px 1px 10px 1px; +} + +#navigation li { + text-indent: -1em; + display: block; + margin: 3px 0px 0px 22px; +} + +#navigation li li a { + margin: 0px 3px 0px -1em; +} + +#content { + margin-left: 14em; + padding: 1em; + width: 700px; + border-left: 2px solid #cccccc; + border-right: 2px solid #cccccc; + background-color: #ffffff; +} + +#about { + clear: both; + padding: 5px; + border-top: 2px solid #cccccc; + background-color: #ffffff; +} + +@media print { + body { + font: 12pt "Times New Roman", "TimeNR", Times, serif; + } + a { font-weight: bold; color: #004080; text-decoration: underline; } + + #main { + background-color: #ffffff; + border-left: 0px; + } + + #container { + margin-left: 2%; + margin-right: 2%; + background-color: #ffffff; + } + + #content { + padding: 1em; + background-color: #ffffff; + } + + #navigation { + display: none; + } + pre.example { + font-family: "Andale Mono", monospace; + font-size: 10pt; + page-break-inside: avoid; + } +} + +table.module_list { + border-width: 1px; + border-style: solid; + border-color: #cccccc; + border-collapse: collapse; +} +table.module_list td { + border-width: 1px; + padding: 3px; + border-style: solid; + border-color: #cccccc; +} +table.module_list td.name { background-color: #f0f0f0; min-width: 200px; } +table.module_list td.summary { width: 100%; } + + +table.function_list { + border-width: 1px; + border-style: solid; + border-color: #cccccc; + border-collapse: collapse; +} +table.function_list td { + border-width: 1px; + padding: 3px; + border-style: solid; + border-color: #cccccc; +} +table.function_list td.name { background-color: #f0f0f0; min-width: 200px; } +table.function_list td.summary { width: 100%; } + +ul.nowrap { + overflow:auto; + white-space:nowrap; +} + +dl.table dt, dl.function dt {border-top: 1px solid #ccc; padding-top: 1em;} +dl.table dd, dl.function dd {padding-bottom: 1em; margin: 10px 0 0 20px;} +dl.table h3, dl.function h3 {font-size: .95em;} + +/* stop sublists from having initial vertical space */ +ul ul { margin-top: 0px; } +ol ul { margin-top: 0px; } +ol ol { margin-top: 0px; } +ul ol { margin-top: 0px; } + +/* make the target distinct; helps when we're navigating to a function */ +a:target + * { + background-color: #FF9; +} + +/* styles for prettification of source */ +pre .comment { color: #558817; } +pre .constant { color: #a8660d; } +pre .escape { color: #844631; } +pre .keyword { color: #aa5050; font-weight: bold; } +pre .library { color: #0e7c6b; } +pre .marker { color: #512b1e; background: #fedc56; font-weight: bold; } +pre .string { color: #8080ff; } +pre .number { color: #f8660d; } +pre .operator { color: #2239a8; font-weight: bold; } +pre .preprocessor, pre .prepro { color: #a33243; } +pre .global { color: #800080; } +pre .prompt { color: #558817; } +pre .url { color: #272fc2; text-decoration: underline; } diff --git a/doc/source/tiny.lua.html b/doc/source/tiny.lua.html new file mode 100644 index 0000000..c961c78 --- /dev/null +++ b/doc/source/tiny.lua.html @@ -0,0 +1,452 @@ + + + + + Reference + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ +

tiny.lua

+
+--- @module tiny-ecs
+-- @author Calvin Rose
+local tiny = {}
+
+--- Tiny-ecs Version, a period-separated three number string like "1.2.3" with
+-- no leading zeros.
+tiny._VERSION = "0.3.0"
+
+local tinsert = table.insert
+local tremove = table.remove
+local tconcat = table.concat
+local pairs = pairs
+local ipairs = ipairs
+local setmetatable = setmetatable
+local getmetatable = getmetatable
+
+-- Local versions of the library functions
+local tiny_system
+local tiny_manageEntities
+local tiny_manageSystems
+local tiny_updateSystem
+local tiny_add
+local tiny_remove
+
+--- Filter functions.
+-- A Filter is a function that selects which Entities apply to a System.
+-- @section Filter
+
+--- Makes a Filter that filters Entities with specified Components.
+-- An Entity must have all Components to match the filter.
+-- @param ... List of Components
+function tiny.requireAll(...)
+    local components = {...}
+    local len = #components
+    return function(e)
+        local c
+        for i = 1, len do
+            c = components[i]
+            if e[c] == nil then
+                return false
+            end
+        end
+        return true
+    end
+end
+
+--- Makes a Filter that filters Entities with specified Components.
+-- An Entity must have at least one specified Component to match the filter.
+-- @param ... List of Components
+function tiny.requireOne(...)
+    local components = {...}
+    local len = #components
+    return function(e)
+        local c
+        for i = 1, len do
+            c = components[i]
+            if e[c] ~= nil then
+                return true
+            end
+        end
+        return false
+    end
+end
+
+--- System functions.
+-- A System a wrapper around function callbacks for manipulating Entities.
+-- @section System
+
+local systemMetaTable = {}
+
+--- Creates a System.
+-- @param callback Function of one argument, delta time, that is called once
+-- per world update
+-- @param filter Function of one argument, an Entity, that returns a boolean
+-- @param entityCallback Function of two arguments, an Entity and delta time
+-- @param onAdd Optional callback for when Enities are added to the System that
+-- takes one argument, an Entity
+-- @param onRemove Similar to onAdd, but is instead called when an Entity is
+-- removed from the System
+function tiny.system(callback, filter, entityCallback, onAdd, onRemove)
+    local ret = {
+        callback = callback,
+        filter = filter,
+        entityCallback = entityCallback,
+        onAdd = onAdd,
+        onRemove = onRemove
+    }
+    setmetatable(ret, systemMetaTable)
+    return ret
+end
+tiny_system = tiny.system
+
+--- Creates a System that processes Entities every update. Also provides
+-- optional callbacks for when Entities are added or removed from the System.
+-- @param filter Function of one argument, an Entity, that returns a boolean
+-- @param entityCallback Function of two arguments, an Entity and delta time
+-- @param onAdd Optional callback for when Entities are added to the System that
+-- takes one argument, an Entity
+-- @param onRemove Similar to onAdd, but is instead called when an Entity is
+-- removed from the System
+function tiny.processingSystem(filter, entityCallback, onAdd, onRemove)
+    return tiny_system(nil, filter, entityCallback, onAdd, onRemove)
+end
+
+local worldMetaTable = { __index = tiny }
+
+--- World functions.
+-- A World is a container that manages Entities and Systems. The tiny-ecs module
+-- is set to be the __index of all World tables, so the often clearer syntax of
+-- World:method can be used for any function in the library. For example,
+-- tiny.add(world, e1, e2, e3) is the same as world:add(e1, e2, e3).
+-- @section World
+
+--- Creates a new World.
+-- Can optionally add default Systems and Entities.
+-- @param ... Systems and Entities to add to the World
+-- @return A new World
+function tiny.world(...)
+
+    local ret = {
+
+        -- Table of Entities to status
+        status = {},
+
+        -- Set of Entities
+        entities = {},
+
+        -- Number of Entities in World.
+        entityCount = 0,
+
+        -- Number of Systems in World.
+        systemCount = 0,
+
+        -- List of Systems
+        systems = {},
+
+        -- Table of Systems to whether or not they are active.
+        activeSystems = {},
+
+        -- Table of Systems to System Indices
+        systemIndices = {},
+
+        -- Table of Systems to Sets of matching Entities
+        systemEntities = {},
+
+        -- List of Systems to add next update
+        systemsToAdd = {},
+
+        -- List of Systems to remove next update
+        systemsToRemove = {}
+
+    }
+
+    tiny.add(ret, ...)
+    tiny.manageSystems(ret)
+    tiny.manageEntities(ret)
+
+    setmetatable(ret, worldMetaTable)
+    return ret
+
+end
+
+--- Adds Entities and Systems to the World.
+-- New objects will enter the World the next time World:update(dt) is called.
+-- Also call this method when an Entity has had its Components changed, such
+-- that it matches different Filters.
+-- @param world
+-- @param ... Systems and Entities
+function tiny.add(world, ...)
+    local args = {...}
+    local status = world.status
+    local entities = world.entities
+    local systemsToAdd = world.systemsToAdd
+    for _, obj in ipairs(args) do
+        if getmetatable(obj) == systemMetaTable then
+            tinsert(systemsToAdd, obj)
+        else -- Assume obj is an Entity
+            entities[obj] = true
+            status[obj] = "add"
+        end
+    end
+end
+tiny_add = tiny.add
+
+--- Removes Entities and Systems from the World. Objects will exit the World the
+-- next time World:update(dt) is called.
+-- @param world
+-- @param ... Systems and Entities
+function tiny.remove(world, ...)
+    local args = {...}
+    local status = world.status
+    local entities = world.entities
+    local systemsToRemove = world.systemsToRemove
+    for _, obj in ipairs(args) do
+        if getmetatable(obj) == systemMetaTable then
+            tinsert(systemsToRemove, obj)
+        elseif entities[obj] then -- Assume obj is an Entity
+            status[obj] = "remove"
+        end
+    end
+end
+tiny_remove = tiny.remove
+
+--- Updates a System.
+-- @param world
+-- @param system A System in the World to update
+-- @param dt Delta time
+function tiny.updateSystem(world, system, dt)
+    local callback = system.callback
+    local entityCallback = system.entityCallback
+
+    if callback then
+        callback(dt)
+    end
+
+    if entityCallback then
+        local entities = world.entities
+        local es = world.systemEntities[system]
+        if es then
+            for e in pairs(es) do
+                entityCallback(e, dt)
+            end
+        end
+    end
+end
+tiny_updateSystem = tiny.updateSystem
+
+--- Adds and removes Systems that have been marked from the World.
+-- The user of this library should seldom if ever call this.
+-- @param world
+function tiny.manageSystems(world)
+
+        local systemEntities = world.systemEntities
+        local systemIndices = world.systemIndices
+        local entities = world.entities
+        local systems = world.systems
+        local systemsToAdd = world.systemsToAdd
+        local systemsToRemove = world.systemsToRemove
+        local activeSystems = world.activeSystems
+
+        -- Keep track of the number of Systems in the world
+        local deltaSystemCount = 0
+
+        -- Remove all Systems queued for removal
+        for i = 1, #systemsToRemove do
+            -- Pop system off the remove queue
+            local sys = systemsToRemove[i]
+            systemsToRemove[i] = nil
+
+            local sysID = systemIndices[sys]
+            if sysID then
+                tremove(systems, sysID)
+
+                local onRemove = sys.onRemove
+                if onRemove then
+                    for e in pairs(systemEntities[sys]) do
+                        onRemove(e)
+                    end
+                end
+
+                systemEntities[sys] = nil
+                activeSystems[sys] = nil
+                deltaSystemCount = deltaSystemCount - 1
+            end
+        end
+
+        -- Add Systems queued for addition
+        for i = 1, #systemsToAdd do
+            -- Pop system off the add queue
+            local sys = systemsToAdd[i]
+            systemsToAdd[i] = nil
+
+            -- Add system to world
+            local es = {}
+            systemEntities[sys] = es
+            tinsert(systems, sys)
+            systemIndices[sys] = #systems
+            activeSystems[sys] = true
+
+            local filter = sys.filter
+            if filter then
+                for e in pairs(entities) do
+                    es[e] = filter(e) and true or nil
+                end
+            end
+
+            deltaSystemCount = deltaSystemCount + 1
+        end
+
+        -- Update the number of Systems in the World
+        world.systemCount = world.systemCount + deltaSystemCount
+end
+tiny_manageSystems = tiny.manageSystems
+
+--- Adds and removes Entities that have been marked.
+-- The user of this library should seldom if ever call this.
+-- @param world
+function tiny.manageEntities(world)
+
+    local statuses = world.status
+    local systemEntities = world.systemEntities
+    local entities = world.entities
+    local systems = world.systems
+
+    -- Keep track of the number of Entities in the World
+    local deltaEntityCount = 0
+
+    -- Add, remove, or change Entities
+    for e, s in pairs(statuses) do
+        if s == "add" then
+            deltaEntityCount = deltaEntityCount + 1
+            for sys, es in pairs(systemEntities) do
+                local filter = sys.filter
+                if filter then
+                    local matches = filter(e) and true or nil
+                    local onAdd = sys.onAdd
+                    if onAdd and matches and not es[e] then
+                        onAdd(e)
+                    end
+                    es[e] = matches
+                end
+            end
+        elseif s == "remove" then
+            deltaEntityCount = deltaEntityCount - 1
+            entities[e] = nil
+            for sys, es in pairs(systemEntities) do
+                local onRemove = sys.onRemove
+                if es[e] and onRemove then
+                    onRemove(e)
+                end
+                es[e] = nil
+            end
+        end
+        statuses[e] = nil
+    end
+
+    -- Update Entity count
+    world.entityCount = world.entityCount + deltaEntityCount
+
+end
+tiny_manageEntities = tiny.manageEntities
+
+--- Updates the World.
+-- Frees Entities that have been marked for freeing, adds
+-- entities that have been marked for adding, etc.
+-- @param world
+-- @param dt Delta time
+function tiny.update(world, dt)
+
+    tiny_manageSystems(world)
+    tiny_manageEntities(world)
+
+    --  Iterate through Systems IN ORDER
+    for _, s in ipairs(world.systems) do
+        if world.activeSystems[s] then
+            tiny_updateSystem(world, s, dt)
+        end
+    end
+end
+
+--- Removes all Entities from the World.
+-- When World:update(dt) is next called,
+-- all Entities will be removed.
+-- @param world
+function tiny.clearEntities(world)
+    local status = world.status
+    for e in pairs(world.entities) do
+        status[e] = "remove"
+    end
+end
+
+--- Removes all Systems from the World.
+-- When World:update(dt) is next called,
+-- all Systems will be removed.
+-- @param world
+function tiny.clearSystems(world)
+    local newSystemsToRemove = {}
+    local systems = world.systems
+    for i = 1, #systems do
+        newSystemsToRemove[i] = systems[i]
+    end
+    world.systemsToRemove = newSystemsToRemove
+end
+
+--- Sets if a System is active in a world. If the system is active, it will
+-- update automatically when World:update(dt) is called. Otherwise, the user
+-- must call World:updateSystem(system, dt) to update the unactivated system.
+-- @param world
+-- @param system A System in the World activate/deactivate
+-- @param active Boolean new state of the System
+function tiny.setSystemActive(world, system, active)
+    world.activeSystem[system] = active and true or nil
+end
+
+return tiny
+ + +
+
+
+generated by LDoc 1.4.3 +Last updated 2015-03-29 20:35:35 +
+
+ + diff --git a/doc/topics/README.md.html b/doc/topics/README.md.html new file mode 100644 index 0000000..4a324af --- /dev/null +++ b/doc/topics/README.md.html @@ -0,0 +1,122 @@ + + + + + tiny-ecs API + + + + +
+ +
+ +
+
+
+ + +
+ + + + + + +
+ + # 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 +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"). +

## Use It ## +Copy paste tiny.lua into your source folder. +

## Overview ## +Tiny-ecs has four important types: Worlds, Filters, Systems, and Entities. +Entities, however, can be any lua table, and Filters are just functions that +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 that code, as it is the Systems's job to +do logic on data. Henceforth, a key-value pair in an Entity will +be referred to as a Component. +

### Worlds ### +Worlds are the outermost containers in tiny-ecs that contain both Systems +and Entities. In typical use, only one World is used at a time. +

### Systems ### +Systems in tiny-ecs describe how to update Entities. Systems select certain Entities +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. +

### Filters ### +Filters are used to select Entities. Filters can be any lua function, but +tiny-ecs provides some functions for generating common ones, like selecting +only Entities that have all required components. +

## Example ## +```lua +local tiny = require("tiny") +

local talkingSystem = tiny.processingSystem( + tiny.requireAll("name", "mass", "phrase"), + function (p, delta) + p.mass = p.mass + delta * 3 + print(p.name .. ", who weighs " .. p.mass .. " pounds, says, \"" .. p.phrase .. "\"") + end +) +

local joe = { + name = "Joe", + phrase = "I'm a plumber.", + mass = 150, + hairColor = "brown" +} +

local world = tiny.newWorld(talkingSystem, joe) +

for i = 1, 20 do + world:update(1) +end +``` +

## Testing ## +Tiny-ecs uses [busted](http://olivinelabs.com/busted/) for testing. Install and run +`busted` from the command line to test. +

## TODO ## +

* Dynamic reordering of Systems +* More testing +* Performance testing / optimization +* API outside of source code +* Add more complete examples + + +

+
+
+generated by LDoc 1.4.3 +Last updated 2015-03-29 17:53:00 +
+
+ + diff --git a/index.html b/index.html new file mode 100644 index 0000000..e69de29