mirror of
https://github.com/bakpakin/tiny-ecs.git
synced 2026-07-22 07:56:52 -06:00
Docs commit.
This commit is contained in:
+535
@@ -0,0 +1,535 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<head>
|
||||
<title>Reference</title>
|
||||
<link rel="stylesheet" href="ldoc.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="container">
|
||||
|
||||
<div id="product">
|
||||
<div id="product_logo"></div>
|
||||
<div id="product_name"><big><b></b></big></div>
|
||||
<div id="product_description"></div>
|
||||
</div> <!-- id="product" -->
|
||||
|
||||
|
||||
<div id="main">
|
||||
|
||||
|
||||
<!-- Menu -->
|
||||
|
||||
<div id="navigation">
|
||||
<br/>
|
||||
<h1>tiny-ecs</h1>
|
||||
|
||||
|
||||
<h2>Contents</h2>
|
||||
<ul>
|
||||
<li><a href="#Fields">Fields</a></li>
|
||||
<li><a href="#Filter_functions">Filter functions </a></li>
|
||||
<li><a href="#System_functions">System functions </a></li>
|
||||
<li><a href="#World_functions">World functions </a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h2>Modules</h2>
|
||||
<ul class="$(kind=='Topics' and '' or 'nowrap'">
|
||||
<li><strong>tiny-ecs</strong></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="content">
|
||||
|
||||
<h1>Module <code>tiny-ecs</code></h1>
|
||||
<p></p>
|
||||
<p></p>
|
||||
<h3>Info:</h3>
|
||||
<ul>
|
||||
<li><strong>Author</strong>: Calvin Rose</li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h2><a href="#Fields">Fields</a></h2>
|
||||
<table class="function_list">
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny._VERSION">tiny._VERSION</a></td>
|
||||
<td class="summary">Tiny-ecs Version, a period-separated three number string like "1.2.3" with
|
||||
no leading zeros.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2><a href="#Filter_functions">Filter functions </a></h2>
|
||||
<table class="function_list">
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny.requireAll">tiny.requireAll (...)</a></td>
|
||||
<td class="summary">Makes a Filter that filters Entities with specified Components.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny.requireOne">tiny.requireOne (...)</a></td>
|
||||
<td class="summary">Makes a Filter that filters Entities with specified Components.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2><a href="#System_functions">System functions </a></h2>
|
||||
<table class="function_list">
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny.processingSystem">tiny.processingSystem (filter, entityCallback, onAdd, onRemove)</a></td>
|
||||
<td class="summary">Creates a System that processes Entities every update.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny.system">tiny.system (callback, filter, entityCallback, onAdd, onRemove)</a></td>
|
||||
<td class="summary">Creates a System.</td>
|
||||
</tr>
|
||||
</table>
|
||||
<h2><a href="#World_functions">World functions </a></h2>
|
||||
<table class="function_list">
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny.add">tiny.add (world, ...)</a></td>
|
||||
<td class="summary">Adds Entities and Systems to the World.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny.clearEntities">tiny.clearEntities (world)</a></td>
|
||||
<td class="summary">Removes all Entities from the World.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny.clearSystems">tiny.clearSystems (world)</a></td>
|
||||
<td class="summary">Removes all Systems from the World.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny.manageEntities">tiny.manageEntities (world)</a></td>
|
||||
<td class="summary">Adds and removes Entities that have been marked.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny.manageSystems">tiny.manageSystems (world)</a></td>
|
||||
<td class="summary">Adds and removes Systems that have been marked from the World.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny.remove">tiny.remove (world, ...)</a></td>
|
||||
<td class="summary">Removes Entities and Systems from the World.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny.setSystemActive">tiny.setSystemActive (world, system, active)</a></td>
|
||||
<td class="summary">Sets if a System is active in a world.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny.update">tiny.update (world, dt)</a></td>
|
||||
<td class="summary">Updates the World.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny.updateSystem">tiny.updateSystem (world, system, dt)</a></td>
|
||||
<td class="summary">Updates a System.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="name" nowrap><a href="#tiny.world">tiny.world (...)</a></td>
|
||||
<td class="summary">Creates a new World.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
|
||||
<h2><a name="Fields"></a>Fields</h2>
|
||||
|
||||
<dl class="function">
|
||||
<dt>
|
||||
<a name = "tiny._VERSION"></a>
|
||||
<strong>tiny._VERSION</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Tiny-ecs Version, a period-separated three number string like "1.2.3" with
|
||||
no leading zeros.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
<h2><a name="Filter_functions"></a>Filter functions </h2>
|
||||
|
||||
|
||||
A Filter is a function that selects which Entities apply to a System.
|
||||
<dl class="function">
|
||||
<dt>
|
||||
<a name = "tiny.requireAll"></a>
|
||||
<strong>tiny.requireAll (...)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Makes a Filter that filters Entities with specified Components.
|
||||
An Entity must have all Components to match the filter.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">...</span>
|
||||
List of Components
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "tiny.requireOne"></a>
|
||||
<strong>tiny.requireOne (...)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Makes a Filter that filters Entities with specified Components.
|
||||
An Entity must have at least one specified Component to match the filter.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">...</span>
|
||||
List of Components
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
<h2><a name="System_functions"></a>System functions </h2>
|
||||
|
||||
|
||||
A System a wrapper around function callbacks for manipulating Entities.
|
||||
<dl class="function">
|
||||
<dt>
|
||||
<a name = "tiny.processingSystem"></a>
|
||||
<strong>tiny.processingSystem (filter, entityCallback, onAdd, onRemove)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Creates a System that processes Entities every update. Also provides
|
||||
optional callbacks for when Entities are added or removed from the System.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">filter</span>
|
||||
Function of one argument, an Entity, that returns a boolean
|
||||
</li>
|
||||
<li><span class="parameter">entityCallback</span>
|
||||
Function of two arguments, an Entity and delta time
|
||||
</li>
|
||||
<li><span class="parameter">onAdd</span>
|
||||
Optional callback for when Entities are added to the System that
|
||||
takes one argument, an Entity
|
||||
</li>
|
||||
<li><span class="parameter">onRemove</span>
|
||||
Similar to onAdd, but is instead called when an Entity is
|
||||
removed from the System
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "tiny.system"></a>
|
||||
<strong>tiny.system (callback, filter, entityCallback, onAdd, onRemove)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Creates a System.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">callback</span>
|
||||
Function of one argument, delta time, that is called once
|
||||
per world update
|
||||
</li>
|
||||
<li><span class="parameter">filter</span>
|
||||
Function of one argument, an Entity, that returns a boolean
|
||||
</li>
|
||||
<li><span class="parameter">entityCallback</span>
|
||||
Function of two arguments, an Entity and delta time
|
||||
</li>
|
||||
<li><span class="parameter">onAdd</span>
|
||||
Optional callback for when Enities are added to the System that
|
||||
takes one argument, an Entity
|
||||
</li>
|
||||
<li><span class="parameter">onRemove</span>
|
||||
Similar to onAdd, but is instead called when an Entity is
|
||||
removed from the System
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
<h2><a name="World_functions"></a>World functions </h2>
|
||||
|
||||
|
||||
A World is a container that manages Entities and Systems. The tiny-ecs module
|
||||
is set to be the <code>__index</code> of all World tables, so the often clearer syntax of
|
||||
World:method can be used for any function in the library. For example,
|
||||
<code>tiny.add(world, e1, e2, e3)</code> is the same as <code>world:add(e1, e2, e3).</code>
|
||||
<dl class="function">
|
||||
<dt>
|
||||
<a name = "tiny.add"></a>
|
||||
<strong>tiny.add (world, ...)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
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.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">world</span>
|
||||
|
||||
</li>
|
||||
<li><span class="parameter">...</span>
|
||||
Systems and Entities
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "tiny.clearEntities"></a>
|
||||
<strong>tiny.clearEntities (world)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Removes all Entities from the World.
|
||||
When World:update(dt) is next called,
|
||||
all Entities will be removed.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">world</span>
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "tiny.clearSystems"></a>
|
||||
<strong>tiny.clearSystems (world)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Removes all Systems from the World.
|
||||
When World:update(dt) is next called,
|
||||
all Systems will be removed.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">world</span>
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "tiny.manageEntities"></a>
|
||||
<strong>tiny.manageEntities (world)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Adds and removes Entities that have been marked.
|
||||
The user of this library should seldom if ever call this.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">world</span>
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "tiny.manageSystems"></a>
|
||||
<strong>tiny.manageSystems (world)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Adds and removes Systems that have been marked from the World.
|
||||
The user of this library should seldom if ever call this.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">world</span>
|
||||
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "tiny.remove"></a>
|
||||
<strong>tiny.remove (world, ...)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Removes Entities and Systems from the World. Objects will exit the World the
|
||||
next time World:update(dt) is called.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">world</span>
|
||||
|
||||
</li>
|
||||
<li><span class="parameter">...</span>
|
||||
Systems and Entities
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "tiny.setSystemActive"></a>
|
||||
<strong>tiny.setSystemActive (world, system, active)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
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.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">world</span>
|
||||
|
||||
</li>
|
||||
<li><span class="parameter">system</span>
|
||||
A System in the World activate/deactivate
|
||||
</li>
|
||||
<li><span class="parameter">active</span>
|
||||
Boolean new state of the System
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "tiny.update"></a>
|
||||
<strong>tiny.update (world, dt)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Updates the World.
|
||||
Frees Entities that have been marked for freeing, adds
|
||||
entities that have been marked for adding, etc.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">world</span>
|
||||
|
||||
</li>
|
||||
<li><span class="parameter">dt</span>
|
||||
Delta time
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "tiny.updateSystem"></a>
|
||||
<strong>tiny.updateSystem (world, system, dt)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Updates a System.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">world</span>
|
||||
|
||||
</li>
|
||||
<li><span class="parameter">system</span>
|
||||
A System in the World to update
|
||||
</li>
|
||||
<li><span class="parameter">dt</span>
|
||||
Delta time
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<dt>
|
||||
<a name = "tiny.world"></a>
|
||||
<strong>tiny.world (...)</strong>
|
||||
</dt>
|
||||
<dd>
|
||||
Creates a new World.
|
||||
Can optionally add default Systems and Entities.
|
||||
|
||||
|
||||
<h3>Parameters:</h3>
|
||||
<ul>
|
||||
<li><span class="parameter">...</span>
|
||||
Systems and Entities to add to the World
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<h3>Returns:</h3>
|
||||
<ol>
|
||||
|
||||
A new World
|
||||
</ol>
|
||||
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
</div> <!-- id="content" -->
|
||||
</div> <!-- id="main" -->
|
||||
<div id="about">
|
||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||
<i style="float:right;">Last updated 2015-03-29 20:36:32 </i>
|
||||
</div> <!-- id="about" -->
|
||||
</div> <!-- id="container" -->
|
||||
</body>
|
||||
</html>
|
||||
+307
@@ -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; }
|
||||
@@ -0,0 +1,452 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<head>
|
||||
<title>Reference</title>
|
||||
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="container">
|
||||
|
||||
<div id="product">
|
||||
<div id="product_logo"></div>
|
||||
<div id="product_name"><big><b></b></big></div>
|
||||
<div id="product_description"></div>
|
||||
</div> <!-- id="product" -->
|
||||
|
||||
|
||||
<div id="main">
|
||||
|
||||
|
||||
<!-- Menu -->
|
||||
|
||||
<div id="navigation">
|
||||
<br/>
|
||||
<h1>tiny-ecs</h1>
|
||||
|
||||
|
||||
|
||||
|
||||
<h2>Source</h2>
|
||||
<ul class="$(kind=='Topics' and '' or 'nowrap'">
|
||||
<li><strong>tiny.lua</strong></li>
|
||||
</ul>
|
||||
<h2>Modules</h2>
|
||||
<ul class="$(kind=='Topics' and '' or 'nowrap'">
|
||||
<li><a href="../index.html">tiny-ecs</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="content">
|
||||
|
||||
<h2>tiny.lua</h2>
|
||||
<pre>
|
||||
<span class="comment">--- @module tiny-ecs
|
||||
</span><span class="comment">-- @author Calvin Rose
|
||||
</span><span class="keyword">local</span> tiny = {}
|
||||
|
||||
<span class="comment">--- Tiny-ecs Version, a period-separated three number string like "1.2.3" with
|
||||
</span><a id="7"></a><span class="comment">-- no leading zeros.
|
||||
</span>tiny._VERSION = <span class="string">"0.3.0"</span>
|
||||
|
||||
<span class="keyword">local</span> tinsert = <span class="global">table</span>.insert
|
||||
<span class="keyword">local</span> tremove = <span class="global">table</span>.remove
|
||||
<span class="keyword">local</span> tconcat = <span class="global">table</span>.concat
|
||||
<span class="keyword">local</span> <span class="global">pairs</span> = <span class="global">pairs</span>
|
||||
<span class="keyword">local</span> <span class="global">ipairs</span> = <span class="global">ipairs</span>
|
||||
<span class="keyword">local</span> <span class="global">setmetatable</span> = <span class="global">setmetatable</span>
|
||||
<span class="keyword">local</span> <span class="global">getmetatable</span> = <span class="global">getmetatable</span>
|
||||
|
||||
<span class="comment">-- Local versions of the library functions
|
||||
</span><span class="keyword">local</span> tiny_system
|
||||
<span class="keyword">local</span> tiny_manageEntities
|
||||
<span class="keyword">local</span> tiny_manageSystems
|
||||
<span class="keyword">local</span> tiny_updateSystem
|
||||
<span class="keyword">local</span> tiny_add
|
||||
<span class="keyword">local</span> tiny_remove
|
||||
|
||||
<span class="comment">--- Filter functions.
|
||||
</span><span class="comment">-- A Filter is a function that selects which Entities apply to a System.
|
||||
</span><span class="comment">-- @section Filter
|
||||
</span>
|
||||
<span class="comment">--- Makes a Filter that filters Entities with specified Components.
|
||||
</span><span class="comment">-- An Entity must have all Components to match the filter.
|
||||
</span><a id="32"></a><span class="comment">-- @param ... List of Components
|
||||
</span><span class="keyword">function</span> tiny.requireAll(...)
|
||||
<span class="keyword">local</span> components = {...}
|
||||
<span class="keyword">local</span> len = #components
|
||||
<span class="keyword">return</span> <span class="keyword">function</span>(e)
|
||||
<span class="keyword">local</span> c
|
||||
<span class="keyword">for</span> i = <span class="number">1</span>, len <span class="keyword">do</span>
|
||||
c = components[i]
|
||||
<span class="keyword">if</span> e[c] == <span class="keyword">nil</span> <span class="keyword">then</span>
|
||||
<span class="keyword">return</span> <span class="keyword">false</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">return</span> <span class="keyword">true</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
|
||||
<span class="comment">--- Makes a Filter that filters Entities with specified Components.
|
||||
</span><span class="comment">-- An Entity must have at least one specified Component to match the filter.
|
||||
</span><a id="50"></a><span class="comment">-- @param ... List of Components
|
||||
</span><span class="keyword">function</span> tiny.requireOne(...)
|
||||
<span class="keyword">local</span> components = {...}
|
||||
<span class="keyword">local</span> len = #components
|
||||
<span class="keyword">return</span> <span class="keyword">function</span>(e)
|
||||
<span class="keyword">local</span> c
|
||||
<span class="keyword">for</span> i = <span class="number">1</span>, len <span class="keyword">do</span>
|
||||
c = components[i]
|
||||
<span class="keyword">if</span> e[c] ~= <span class="keyword">nil</span> <span class="keyword">then</span>
|
||||
<span class="keyword">return</span> <span class="keyword">true</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">return</span> <span class="keyword">false</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
|
||||
<span class="comment">--- System functions.
|
||||
</span><span class="comment">-- A System a wrapper around function callbacks for manipulating Entities.
|
||||
</span><span class="comment">-- @section System
|
||||
</span>
|
||||
<span class="keyword">local</span> systemMetaTable = {}
|
||||
|
||||
<span class="comment">--- Creates a System.
|
||||
</span><span class="comment">-- @param callback Function of one argument, delta time, that is called once
|
||||
</span><span class="comment">-- per world update
|
||||
</span><span class="comment">-- @param filter Function of one argument, an Entity, that returns a boolean
|
||||
</span><span class="comment">-- @param entityCallback Function of two arguments, an Entity and delta time
|
||||
</span><span class="comment">-- @param onAdd Optional callback for when Enities are added to the System that
|
||||
</span><span class="comment">-- takes one argument, an Entity
|
||||
</span><span class="comment">-- @param onRemove Similar to onAdd, but is instead called when an Entity is
|
||||
</span><a id="80"></a><span class="comment">-- removed from the System
|
||||
</span><span class="keyword">function</span> tiny.system(callback, filter, entityCallback, onAdd, onRemove)
|
||||
<span class="keyword">local</span> ret = {
|
||||
callback = callback,
|
||||
filter = filter,
|
||||
entityCallback = entityCallback,
|
||||
onAdd = onAdd,
|
||||
onRemove = onRemove
|
||||
}
|
||||
<span class="global">setmetatable</span>(ret, systemMetaTable)
|
||||
<span class="keyword">return</span> ret
|
||||
<span class="keyword">end</span>
|
||||
tiny_system = tiny.system
|
||||
|
||||
<span class="comment">--- Creates a System that processes Entities every update. Also provides
|
||||
</span><span class="comment">-- optional callbacks for when Entities are added or removed from the System.
|
||||
</span><span class="comment">-- @param filter Function of one argument, an Entity, that returns a boolean
|
||||
</span><span class="comment">-- @param entityCallback Function of two arguments, an Entity and delta time
|
||||
</span><span class="comment">-- @param onAdd Optional callback for when Entities are added to the System that
|
||||
</span><span class="comment">-- takes one argument, an Entity
|
||||
</span><span class="comment">-- @param onRemove Similar to onAdd, but is instead called when an Entity is
|
||||
</span><a id="101"></a><span class="comment">-- removed from the System
|
||||
</span><span class="keyword">function</span> tiny.processingSystem(filter, entityCallback, onAdd, onRemove)
|
||||
<span class="keyword">return</span> tiny_system(<span class="keyword">nil</span>, filter, entityCallback, onAdd, onRemove)
|
||||
<span class="keyword">end</span>
|
||||
|
||||
<span class="keyword">local</span> worldMetaTable = { __index = tiny }
|
||||
|
||||
<span class="comment">--- World functions.
|
||||
</span><span class="comment">-- A World is a container that manages Entities and Systems. The tiny-ecs module
|
||||
</span><span class="comment">-- is set to be the <code>__index</code> of all World tables, so the often clearer syntax of
|
||||
</span><span class="comment">-- World:method can be used for any function in the library. For example,
|
||||
</span><span class="comment">-- <code>tiny.add(world, e1, e2, e3)</code> is the same as <code>world:add(e1, e2, e3).</code>
|
||||
</span><span class="comment">-- @section World
|
||||
</span>
|
||||
<span class="comment">--- Creates a new World.
|
||||
</span><span class="comment">-- Can optionally add default Systems and Entities.
|
||||
</span><span class="comment">-- @param ... Systems and Entities to add to the World
|
||||
</span><a id="118"></a><span class="comment">-- @return A new World
|
||||
</span><span class="keyword">function</span> tiny.world(...)
|
||||
|
||||
<span class="keyword">local</span> ret = {
|
||||
|
||||
<span class="comment">-- Table of Entities to status
|
||||
</span> status = {},
|
||||
|
||||
<span class="comment">-- Set of Entities
|
||||
</span> entities = {},
|
||||
|
||||
<span class="comment">-- Number of Entities in World.
|
||||
</span> entityCount = <span class="number">0</span>,
|
||||
|
||||
<span class="comment">-- Number of Systems in World.
|
||||
</span> systemCount = <span class="number">0</span>,
|
||||
|
||||
<span class="comment">-- List of Systems
|
||||
</span> systems = {},
|
||||
|
||||
<span class="comment">-- Table of Systems to whether or not they are active.
|
||||
</span> activeSystems = {},
|
||||
|
||||
<span class="comment">-- Table of Systems to System Indices
|
||||
</span> systemIndices = {},
|
||||
|
||||
<span class="comment">-- Table of Systems to Sets of matching Entities
|
||||
</span> systemEntities = {},
|
||||
|
||||
<span class="comment">-- List of Systems to add next update
|
||||
</span> systemsToAdd = {},
|
||||
|
||||
<span class="comment">-- List of Systems to remove next update
|
||||
</span> systemsToRemove = {}
|
||||
|
||||
}
|
||||
|
||||
tiny.add(ret, ...)
|
||||
tiny.manageSystems(ret)
|
||||
tiny.manageEntities(ret)
|
||||
|
||||
<span class="global">setmetatable</span>(ret, worldMetaTable)
|
||||
<span class="keyword">return</span> ret
|
||||
|
||||
<span class="keyword">end</span>
|
||||
|
||||
<span class="comment">--- Adds Entities and Systems to the World.
|
||||
</span><span class="comment">-- New objects will enter the World the next time World:update(dt) is called.
|
||||
</span><span class="comment">-- Also call this method when an Entity has had its Components changed, such
|
||||
</span><span class="comment">-- that it matches different Filters.
|
||||
</span><span class="comment">-- @param world
|
||||
</span><a id="169"></a><span class="comment">-- @param ... Systems and Entities
|
||||
</span><span class="keyword">function</span> tiny.add(world, ...)
|
||||
<span class="keyword">local</span> args = {...}
|
||||
<span class="keyword">local</span> status = world.status
|
||||
<span class="keyword">local</span> entities = world.entities
|
||||
<span class="keyword">local</span> systemsToAdd = world.systemsToAdd
|
||||
<span class="keyword">for</span> _, obj <span class="keyword">in</span> <span class="global">ipairs</span>(args) <span class="keyword">do</span>
|
||||
<span class="keyword">if</span> <span class="global">getmetatable</span>(obj) == systemMetaTable <span class="keyword">then</span>
|
||||
tinsert(systemsToAdd, obj)
|
||||
<span class="keyword">else</span> <span class="comment">-- Assume obj is an Entity
|
||||
</span> entities[obj] = <span class="keyword">true</span>
|
||||
status[obj] = <span class="string">"add"</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
tiny_add = tiny.add
|
||||
|
||||
<span class="comment">--- Removes Entities and Systems from the World. Objects will exit the World the
|
||||
</span><span class="comment">-- next time World:update(dt) is called.
|
||||
</span><span class="comment">-- @param world
|
||||
</span><a id="189"></a><span class="comment">-- @param ... Systems and Entities
|
||||
</span><span class="keyword">function</span> tiny.remove(world, ...)
|
||||
<span class="keyword">local</span> args = {...}
|
||||
<span class="keyword">local</span> status = world.status
|
||||
<span class="keyword">local</span> entities = world.entities
|
||||
<span class="keyword">local</span> systemsToRemove = world.systemsToRemove
|
||||
<span class="keyword">for</span> _, obj <span class="keyword">in</span> <span class="global">ipairs</span>(args) <span class="keyword">do</span>
|
||||
<span class="keyword">if</span> <span class="global">getmetatable</span>(obj) == systemMetaTable <span class="keyword">then</span>
|
||||
tinsert(systemsToRemove, obj)
|
||||
<span class="keyword">elseif</span> entities[obj] <span class="keyword">then</span> <span class="comment">-- Assume obj is an Entity
|
||||
</span> status[obj] = <span class="string">"remove"</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
tiny_remove = tiny.remove
|
||||
|
||||
<span class="comment">--- Updates a System.
|
||||
</span><span class="comment">-- @param world
|
||||
</span><span class="comment">-- @param system A System in the World to update
|
||||
</span><a id="208"></a><span class="comment">-- @param dt Delta time
|
||||
</span><span class="keyword">function</span> tiny.updateSystem(world, system, dt)
|
||||
<span class="keyword">local</span> callback = system.callback
|
||||
<span class="keyword">local</span> entityCallback = system.entityCallback
|
||||
|
||||
<span class="keyword">if</span> callback <span class="keyword">then</span>
|
||||
callback(dt)
|
||||
<span class="keyword">end</span>
|
||||
|
||||
<span class="keyword">if</span> entityCallback <span class="keyword">then</span>
|
||||
<span class="keyword">local</span> entities = world.entities
|
||||
<span class="keyword">local</span> es = world.systemEntities[system]
|
||||
<span class="keyword">if</span> es <span class="keyword">then</span>
|
||||
<span class="keyword">for</span> e <span class="keyword">in</span> <span class="global">pairs</span>(es) <span class="keyword">do</span>
|
||||
entityCallback(e, dt)
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
tiny_updateSystem = tiny.updateSystem
|
||||
|
||||
<span class="comment">--- Adds and removes Systems that have been marked from the World.
|
||||
</span><span class="comment">-- The user of this library should seldom if ever call this.
|
||||
</span><a id="231"></a><span class="comment">-- @param world
|
||||
</span><span class="keyword">function</span> tiny.manageSystems(world)
|
||||
|
||||
<span class="keyword">local</span> systemEntities = world.systemEntities
|
||||
<span class="keyword">local</span> systemIndices = world.systemIndices
|
||||
<span class="keyword">local</span> entities = world.entities
|
||||
<span class="keyword">local</span> systems = world.systems
|
||||
<span class="keyword">local</span> systemsToAdd = world.systemsToAdd
|
||||
<span class="keyword">local</span> systemsToRemove = world.systemsToRemove
|
||||
<span class="keyword">local</span> activeSystems = world.activeSystems
|
||||
|
||||
<span class="comment">-- Keep track of the number of Systems in the world
|
||||
</span> <span class="keyword">local</span> deltaSystemCount = <span class="number">0</span>
|
||||
|
||||
<span class="comment">-- Remove all Systems queued for removal
|
||||
</span> <span class="keyword">for</span> i = <span class="number">1</span>, #systemsToRemove <span class="keyword">do</span>
|
||||
<span class="comment">-- Pop system off the remove queue
|
||||
</span> <span class="keyword">local</span> sys = systemsToRemove[i]
|
||||
systemsToRemove[i] = <span class="keyword">nil</span>
|
||||
|
||||
<span class="keyword">local</span> sysID = systemIndices[sys]
|
||||
<span class="keyword">if</span> sysID <span class="keyword">then</span>
|
||||
tremove(systems, sysID)
|
||||
|
||||
<span class="keyword">local</span> onRemove = sys.onRemove
|
||||
<span class="keyword">if</span> onRemove <span class="keyword">then</span>
|
||||
<span class="keyword">for</span> e <span class="keyword">in</span> <span class="global">pairs</span>(systemEntities[sys]) <span class="keyword">do</span>
|
||||
onRemove(e)
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
|
||||
systemEntities[sys] = <span class="keyword">nil</span>
|
||||
activeSystems[sys] = <span class="keyword">nil</span>
|
||||
deltaSystemCount = deltaSystemCount - <span class="number">1</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
|
||||
<span class="comment">-- Add Systems queued for addition
|
||||
</span> <span class="keyword">for</span> i = <span class="number">1</span>, #systemsToAdd <span class="keyword">do</span>
|
||||
<span class="comment">-- Pop system off the add queue
|
||||
</span> <span class="keyword">local</span> sys = systemsToAdd[i]
|
||||
systemsToAdd[i] = <span class="keyword">nil</span>
|
||||
|
||||
<span class="comment">-- Add system to world
|
||||
</span> <span class="keyword">local</span> es = {}
|
||||
systemEntities[sys] = es
|
||||
tinsert(systems, sys)
|
||||
systemIndices[sys] = #systems
|
||||
activeSystems[sys] = <span class="keyword">true</span>
|
||||
|
||||
<span class="keyword">local</span> filter = sys.filter
|
||||
<span class="keyword">if</span> filter <span class="keyword">then</span>
|
||||
<span class="keyword">for</span> e <span class="keyword">in</span> <span class="global">pairs</span>(entities) <span class="keyword">do</span>
|
||||
es[e] = filter(e) <span class="keyword">and</span> <span class="keyword">true</span> <span class="keyword">or</span> <span class="keyword">nil</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
|
||||
deltaSystemCount = deltaSystemCount + <span class="number">1</span>
|
||||
<span class="keyword">end</span>
|
||||
|
||||
<span class="comment">-- Update the number of Systems in the World
|
||||
</span> world.systemCount = world.systemCount + deltaSystemCount
|
||||
<span class="keyword">end</span>
|
||||
tiny_manageSystems = tiny.manageSystems
|
||||
|
||||
<span class="comment">--- Adds and removes Entities that have been marked.
|
||||
</span><span class="comment">-- The user of this library should seldom if ever call this.
|
||||
</span><a id="298"></a><span class="comment">-- @param world
|
||||
</span><span class="keyword">function</span> tiny.manageEntities(world)
|
||||
|
||||
<span class="keyword">local</span> statuses = world.status
|
||||
<span class="keyword">local</span> systemEntities = world.systemEntities
|
||||
<span class="keyword">local</span> entities = world.entities
|
||||
<span class="keyword">local</span> systems = world.systems
|
||||
|
||||
<span class="comment">-- Keep track of the number of Entities in the World
|
||||
</span> <span class="keyword">local</span> deltaEntityCount = <span class="number">0</span>
|
||||
|
||||
<span class="comment">-- Add, remove, or change Entities
|
||||
</span> <span class="keyword">for</span> e, s <span class="keyword">in</span> <span class="global">pairs</span>(statuses) <span class="keyword">do</span>
|
||||
<span class="keyword">if</span> s == <span class="string">"add"</span> <span class="keyword">then</span>
|
||||
deltaEntityCount = deltaEntityCount + <span class="number">1</span>
|
||||
<span class="keyword">for</span> sys, es <span class="keyword">in</span> <span class="global">pairs</span>(systemEntities) <span class="keyword">do</span>
|
||||
<span class="keyword">local</span> filter = sys.filter
|
||||
<span class="keyword">if</span> filter <span class="keyword">then</span>
|
||||
<span class="keyword">local</span> matches = filter(e) <span class="keyword">and</span> <span class="keyword">true</span> <span class="keyword">or</span> <span class="keyword">nil</span>
|
||||
<span class="keyword">local</span> onAdd = sys.onAdd
|
||||
<span class="keyword">if</span> onAdd <span class="keyword">and</span> matches <span class="keyword">and</span> <span class="keyword">not</span> es[e] <span class="keyword">then</span>
|
||||
onAdd(e)
|
||||
<span class="keyword">end</span>
|
||||
es[e] = matches
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">elseif</span> s == <span class="string">"remove"</span> <span class="keyword">then</span>
|
||||
deltaEntityCount = deltaEntityCount - <span class="number">1</span>
|
||||
entities[e] = <span class="keyword">nil</span>
|
||||
<span class="keyword">for</span> sys, es <span class="keyword">in</span> <span class="global">pairs</span>(systemEntities) <span class="keyword">do</span>
|
||||
<span class="keyword">local</span> onRemove = sys.onRemove
|
||||
<span class="keyword">if</span> es[e] <span class="keyword">and</span> onRemove <span class="keyword">then</span>
|
||||
onRemove(e)
|
||||
<span class="keyword">end</span>
|
||||
es[e] = <span class="keyword">nil</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
statuses[e] = <span class="keyword">nil</span>
|
||||
<span class="keyword">end</span>
|
||||
|
||||
<span class="comment">-- Update Entity count
|
||||
</span> world.entityCount = world.entityCount + deltaEntityCount
|
||||
|
||||
<span class="keyword">end</span>
|
||||
tiny_manageEntities = tiny.manageEntities
|
||||
|
||||
<span class="comment">--- Updates the World.
|
||||
</span><span class="comment">-- Frees Entities that have been marked for freeing, adds
|
||||
</span><span class="comment">-- entities that have been marked for adding, etc.
|
||||
</span><span class="comment">-- @param world
|
||||
</span><a id="348"></a><span class="comment">-- @param dt Delta time
|
||||
</span><span class="keyword">function</span> tiny.update(world, dt)
|
||||
|
||||
tiny_manageSystems(world)
|
||||
tiny_manageEntities(world)
|
||||
|
||||
<span class="comment">-- Iterate through Systems IN ORDER
|
||||
</span> <span class="keyword">for</span> _, s <span class="keyword">in</span> <span class="global">ipairs</span>(world.systems) <span class="keyword">do</span>
|
||||
<span class="keyword">if</span> world.activeSystems[s] <span class="keyword">then</span>
|
||||
tiny_updateSystem(world, s, dt)
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
|
||||
<span class="comment">--- Removes all Entities from the World.
|
||||
</span><span class="comment">-- When World:update(dt) is next called,
|
||||
</span><span class="comment">-- all Entities will be removed.
|
||||
</span><a id="365"></a><span class="comment">-- @param world
|
||||
</span><span class="keyword">function</span> tiny.clearEntities(world)
|
||||
<span class="keyword">local</span> status = world.status
|
||||
<span class="keyword">for</span> e <span class="keyword">in</span> <span class="global">pairs</span>(world.entities) <span class="keyword">do</span>
|
||||
status[e] = <span class="string">"remove"</span>
|
||||
<span class="keyword">end</span>
|
||||
<span class="keyword">end</span>
|
||||
|
||||
<span class="comment">--- Removes all Systems from the World.
|
||||
</span><span class="comment">-- When World:update(dt) is next called,
|
||||
</span><span class="comment">-- all Systems will be removed.
|
||||
</span><a id="376"></a><span class="comment">-- @param world
|
||||
</span><span class="keyword">function</span> tiny.clearSystems(world)
|
||||
<span class="keyword">local</span> newSystemsToRemove = {}
|
||||
<span class="keyword">local</span> systems = world.systems
|
||||
<span class="keyword">for</span> i = <span class="number">1</span>, #systems <span class="keyword">do</span>
|
||||
newSystemsToRemove[i] = systems[i]
|
||||
<span class="keyword">end</span>
|
||||
world.systemsToRemove = newSystemsToRemove
|
||||
<span class="keyword">end</span>
|
||||
|
||||
<span class="comment">--- Sets if a System is active in a world. If the system is active, it will
|
||||
</span><span class="comment">-- update automatically when World:update(dt) is called. Otherwise, the user
|
||||
</span><span class="comment">-- must call World:updateSystem(system, dt) to update the unactivated system.
|
||||
</span><span class="comment">-- @param world
|
||||
</span><span class="comment">-- @param system A System in the World activate/deactivate
|
||||
</span><a id="391"></a><span class="comment">-- @param active Boolean new state of the System
|
||||
</span><span class="keyword">function</span> tiny.setSystemActive(world, system, active)
|
||||
world.activeSystem[system] = active <span class="keyword">and</span> <span class="keyword">true</span> <span class="keyword">or</span> <span class="keyword">nil</span>
|
||||
<span class="keyword">end</span>
|
||||
|
||||
<span class="keyword">return</span> tiny</pre>
|
||||
|
||||
|
||||
</div> <!-- id="content" -->
|
||||
</div> <!-- id="main" -->
|
||||
<div id="about">
|
||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||
<i style="float:right;">Last updated 2015-03-29 20:35:35 </i>
|
||||
</div> <!-- id="about" -->
|
||||
</div> <!-- id="container" -->
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,122 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||
<head>
|
||||
<title>tiny-ecs API</title>
|
||||
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="container">
|
||||
|
||||
<div id="product">
|
||||
<div id="product_logo"></div>
|
||||
<div id="product_name"><big><b></b></big></div>
|
||||
<div id="product_description"></div>
|
||||
</div> <!-- id="product" -->
|
||||
|
||||
|
||||
<div id="main">
|
||||
|
||||
|
||||
<!-- Menu -->
|
||||
|
||||
<div id="navigation">
|
||||
<br/>
|
||||
<h1>ldoc</h1>
|
||||
|
||||
|
||||
<h2>Contents</h2>
|
||||
<ul>
|
||||
<li><a href="#Use_It">Use It </a></li>
|
||||
<li><a href="#Overview">Overview </a></li>
|
||||
<li><a href="#Example">Example </a></li>
|
||||
<li><a href="#Testing">Testing </a></li>
|
||||
<li><a href="#TODO">TODO </a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
<h2>Topics</h2>
|
||||
<ul class="$(kind=='Topics' and '' or 'nowrap'">
|
||||
<li><strong>README</strong></li>
|
||||
</ul>
|
||||
<h2>Modules</h2>
|
||||
<ul class="$(kind=='Topics' and '' or 'nowrap'">
|
||||
<li><a href="../index.html">tiny-ecs</a></li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="content">
|
||||
|
||||
# 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").
|
||||
<p>## Use It ##
|
||||
Copy paste tiny.lua into your source folder.
|
||||
<p>## 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.
|
||||
<p>### 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.
|
||||
<p>### 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.
|
||||
<p>### 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.
|
||||
<p>### 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.
|
||||
<p>## Example ##
|
||||
```lua
|
||||
local tiny = require("tiny")
|
||||
<p>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
|
||||
)
|
||||
<p>local joe = {
|
||||
name = "Joe",
|
||||
phrase = "I'm a plumber.",
|
||||
mass = 150,
|
||||
hairColor = "brown"
|
||||
}
|
||||
<p>local world = tiny.newWorld(talkingSystem, joe)
|
||||
<p>for i = 1, 20 do
|
||||
world:update(1)
|
||||
end
|
||||
```
|
||||
<p>## Testing ##
|
||||
Tiny-ecs uses [busted](http://olivinelabs.com/busted/) for testing. Install and run
|
||||
`busted` from the command line to test.
|
||||
<p>## TODO ##
|
||||
<p>* Dynamic reordering of Systems
|
||||
* More testing
|
||||
* Performance testing / optimization
|
||||
* API outside of source code
|
||||
* Add more complete examples
|
||||
|
||||
|
||||
</div> <!-- id="content" -->
|
||||
</div> <!-- id="main" -->
|
||||
<div id="about">
|
||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
||||
<i style="float:right;">Last updated 2015-03-29 17:53:00 </i>
|
||||
</div> <!-- id="about" -->
|
||||
</div> <!-- id="container" -->
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user