mirror of
https://github.com/Reuh/ubiquitousse.git
synced 2025-10-27 09:09:30 +00:00
ecs: always pass entity as first arguments in callback for consistency, add System.component to set system component name independently from System.name
This commit is contained in:
parent
027b6b9bb2
commit
86373c98de
12 changed files with 113 additions and 72 deletions
|
|
@ -108,7 +108,7 @@
|
||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||||
<i style="float:right;">Last updated 2021-12-27 12:20:29 </i>
|
<i style="float:right;">Last updated 2021-12-27 13:15:05 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,7 @@
|
||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||||
<i style="float:right;">Last updated 2021-12-27 12:20:29 </i>
|
<i style="float:right;">Last updated 2021-12-27 13:15:05 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ local ecs = require("ubiquitousse.ecs")
|
||||||
|
|
||||||
local talkingSystem = {
|
local talkingSystem = {
|
||||||
filter = { "name", "mass", "phrase" },
|
filter = { "name", "mass", "phrase" },
|
||||||
process = function(self, c, e, dt)
|
process = function(self, e, c, dt)
|
||||||
e.mass = e.mass + dt * 3
|
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
|
end
|
||||||
|
|
@ -166,6 +166,10 @@ end
|
||||||
<td class="summary">The system and its subsystems will only draw if this is <code>true</code>.</td>
|
<td class="summary">The system and its subsystems will only draw if this is <code>true</code>.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#System.component">System.component</a></td>
|
||||||
|
<td class="summary">Name of the system component.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
<td class="name" nowrap><a href="#System.default">System.default</a></td>
|
<td class="name" nowrap><a href="#System.default">System.default</a></td>
|
||||||
<td class="summary">Defaults value to put into the entities’s system component when they are added.</td>
|
<td class="summary">Defaults value to put into the entities’s system component when they are added.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
@ -181,11 +185,11 @@ end
|
||||||
<td class="summary">Called when adding an entity to this system determining its order.</td>
|
<td class="summary">Called when adding an entity to this system determining its order.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="name" nowrap><a href="#System:onAdd">System:onAdd (c, e) <sup><em>[callback]</em></sup></a></td>
|
<td class="name" nowrap><a href="#System:onAdd">System:onAdd (e, c) <sup><em>[callback]</em></sup></a></td>
|
||||||
<td class="summary">Called when adding an entity to the system.</td>
|
<td class="summary">Called when adding an entity to the system.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="name" nowrap><a href="#System:onRemove">System:onRemove (c, e) <sup><em>[callback]</em></sup></a></td>
|
<td class="name" nowrap><a href="#System:onRemove">System:onRemove (e, c) <sup><em>[callback]</em></sup></a></td>
|
||||||
<td class="summary">Called when removing an entity from the system.</td>
|
<td class="summary">Called when removing an entity from the system.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -213,11 +217,11 @@ end
|
||||||
<td class="summary">Called when drawing the system.</td>
|
<td class="summary">Called when drawing the system.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="name" nowrap><a href="#System:process">System:process (c, e, dt) <sup><em>[callback]</em></sup></a></td>
|
<td class="name" nowrap><a href="#System:process">System:process (e, c, dt) <sup><em>[callback]</em></sup></a></td>
|
||||||
<td class="summary">Called when updating the system, for every entity the system contains.</td>
|
<td class="summary">Called when updating the system, for every entity the system contains.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="name" nowrap><a href="#System:render">System:render (c, e) <sup><em>[callback]</em></sup></a></td>
|
<td class="name" nowrap><a href="#System:render">System:render (e, c) <sup><em>[callback]</em></sup></a></td>
|
||||||
<td class="summary">Called when drawing the system, for every entity the system contains.</td>
|
<td class="summary">Called when drawing the system, for every entity the system contains.</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
@ -459,7 +463,8 @@ whatever you want, and ideally each component <em>should</em> store the data for
|
||||||
so you are free to handle them as you want in your systems or elsewhere.</p>
|
so you are free to handle them as you want in your systems or elsewhere.</p>
|
||||||
|
|
||||||
<p>Since it’s relatively common for systems to only operate on a single component, as a shortcut the library often consider what it calls the “system component”:
|
<p>Since it’s relatively common for systems to only operate on a single component, as a shortcut the library often consider what it calls the “system component”:
|
||||||
that is, the component in the entity that has the same name as the system (if it exists).
|
that is, the component in the entity that is named like <a href="../modules/ecs.html#System.component">System.component</a> (or <a href="../modules/ecs.html#System.name">System.name</a> if it is not set). Though there’s no problem if there’s no system
|
||||||
|
component or if it doesn’t exist in the entity.
|
||||||
</div>
|
</div>
|
||||||
<dl class="function">
|
<dl class="function">
|
||||||
|
|
||||||
|
|
@ -486,9 +491,9 @@ that is, the component in the entity that has the same name as the system (if it
|
||||||
filter = <span class="string">"sprite"</span>, <span class="comment">-- process entities that have a "sprite" component
|
filter = <span class="string">"sprite"</span>, <span class="comment">-- process entities that have a "sprite" component
|
||||||
</span> <span class="comment">-- systems callbacks that are called per-entity often give you the system component as an argument
|
</span> <span class="comment">-- systems callbacks that are called per-entity often give you the system component as an argument
|
||||||
</span> <span class="comment">-- the system component is the component with the same name as the system, thus here the sprite component
|
</span> <span class="comment">-- the system component is the component with the same name as the system, thus here the sprite component
|
||||||
</span> render = <span class="keyword">function</span>(self, component, entity)
|
</span> render = <span class="keyword">function</span>(self, entity, component)
|
||||||
<span class="comment">-- component == entity.sprite
|
<span class="comment">-- component == entity.sprite
|
||||||
</span> component:draw()
|
</span> draw(component)
|
||||||
<span class="keyword">end</span>
|
<span class="keyword">end</span>
|
||||||
}</pre>
|
}</pre>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
@ -532,12 +537,12 @@ avoid repeating your filters or allow controlling several system from a single p
|
||||||
</span> systems = { animated }, <span class="comment">-- subsystems: they only operate on entities already filtered by this system (on top of their own filtering)
|
</span> systems = { animated }, <span class="comment">-- subsystems: they only operate on entities already filtered by this system (on top of their own filtering)
|
||||||
</span>
|
</span>
|
||||||
<span class="comment">-- Called when an entity is added to this system.
|
<span class="comment">-- Called when an entity is added to this system.
|
||||||
</span> onAdd = <span class="keyword">function</span>(self, component, entity)
|
</span> onAdd = <span class="keyword">function</span>(self, entity, component)
|
||||||
<span class="global">print</span>(<span class="string">"Added an entity, entity count in the system:"</span>, self.entityCount) <span class="comment">-- self refer to the instancied system
|
<span class="global">print</span>(<span class="string">"Added an entity, entity count in the system:"</span>, self.entityCount) <span class="comment">-- self refer to the instancied system
|
||||||
</span> <span class="keyword">end</span>,
|
</span> <span class="keyword">end</span>,
|
||||||
|
|
||||||
<span class="comment">-- Called when the system is updated, for every entity the system
|
<span class="comment">-- Called when the system is updated, for every entity the system
|
||||||
</span> process = <span class="keyword">function</span>(self, component, entity, dt)
|
</span> process = <span class="keyword">function</span>(self, entity, component, dt)
|
||||||
<span class="comment">-- processing...
|
<span class="comment">-- processing...
|
||||||
</span> <span class="keyword">end</span>
|
</span> <span class="keyword">end</span>
|
||||||
}
|
}
|
||||||
|
|
@ -583,8 +588,8 @@ avoid repeating your filters or allow controlling several system from a single p
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
Name of the system.
|
Name of the system.
|
||||||
Used to create a field with the system’s name in <code>world.s</code> and determine the associated system component.
|
Used to create a field with the system’s name in <code>world.s</code> and determine the associated system component if <a href="../modules/ecs.html#System.component">System.component</a> is not set.
|
||||||
If not set, the system will not appear in <code>world.s</code> and gives <code>nil</code> instead of the system component in callbacks.</p>
|
If not set, the system will not appear in <code>world.s</code>.</p>
|
||||||
|
|
||||||
<p> Do not change after system instanciation.
|
<p> Do not change after system instanciation.
|
||||||
|
|
||||||
|
|
@ -694,6 +699,30 @@ avoid repeating your filters or allow controlling several system from a single p
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
<dt>
|
||||||
|
<a name = "System.component"></a>
|
||||||
|
<strong>System.component</strong>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
Name of the system component.
|
||||||
|
Used to determine the associated system component.
|
||||||
|
If not set, this will fall back to <a href="../modules/ecs.html#System.name">System.name</a>. If this is also not set, then we will give <code>nil</code> instead of the system component in callbacks.
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
<h3>Type:</h3>
|
||||||
|
<ul>
|
||||||
|
<li><code>string</code></li>
|
||||||
|
<li><code>nil</code> if no name</li>
|
||||||
|
</ul>
|
||||||
|
</ul>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</dd>
|
</dd>
|
||||||
<dt>
|
<dt>
|
||||||
<a name = "System.default"></a>
|
<a name = "System.default"></a>
|
||||||
|
|
@ -706,7 +735,7 @@ avoid repeating your filters or allow controlling several system from a single p
|
||||||
Metatables will be preserved during the copy but not copied themselves.</p>
|
Metatables will be preserved during the copy but not copied themselves.</p>
|
||||||
|
|
||||||
<p> Changing this will not affect entities already in the system.
|
<p> Changing this will not affect entities already in the system.
|
||||||
Doesn’t have any effect if the system doesn’t have a name.
|
Doesn’t have any effect if the system doesn’t have a component name.
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
<h3>Type:</h3>
|
<h3>Type:</h3>
|
||||||
|
|
@ -825,7 +854,7 @@ avoid repeating your filters or allow controlling several system from a single p
|
||||||
</dd>
|
</dd>
|
||||||
<dt>
|
<dt>
|
||||||
<a name = "System:onAdd"></a>
|
<a name = "System:onAdd"></a>
|
||||||
<strong>System:onAdd (c, e) <sup><em>[callback]</em></sup></strong>
|
<strong>System:onAdd (e, c) <sup><em>[callback]</em></sup></strong>
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
Called when adding an entity to the system.
|
Called when adding an entity to the system.
|
||||||
|
|
@ -837,14 +866,14 @@ avoid repeating your filters or allow controlling several system from a single p
|
||||||
|
|
||||||
<h3>Parameters:</h3>
|
<h3>Parameters:</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li><span class="parameter">c</span>
|
|
||||||
<span class="types"><a class="type" href="../modules/ecs.html#Entity.Component">Component</a></span>
|
|
||||||
the entity’s system component
|
|
||||||
</li>
|
|
||||||
<li><span class="parameter">e</span>
|
<li><span class="parameter">e</span>
|
||||||
<span class="types"><a class="type" href="../modules/ecs.html#Entity_objects">Entity</a></span>
|
<span class="types"><a class="type" href="../modules/ecs.html#Entity_objects">Entity</a></span>
|
||||||
the entity table
|
the entity table
|
||||||
</li>
|
</li>
|
||||||
|
<li><span class="parameter">c</span>
|
||||||
|
<span class="types"><a class="type" href="../modules/ecs.html#Entity.Component">Component</a></span>
|
||||||
|
the entity’s system component, if any
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -854,7 +883,7 @@ avoid repeating your filters or allow controlling several system from a single p
|
||||||
</dd>
|
</dd>
|
||||||
<dt>
|
<dt>
|
||||||
<a name = "System:onRemove"></a>
|
<a name = "System:onRemove"></a>
|
||||||
<strong>System:onRemove (c, e) <sup><em>[callback]</em></sup></strong>
|
<strong>System:onRemove (e, c) <sup><em>[callback]</em></sup></strong>
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
Called when removing an entity from the system.
|
Called when removing an entity from the system.
|
||||||
|
|
@ -866,14 +895,14 @@ avoid repeating your filters or allow controlling several system from a single p
|
||||||
|
|
||||||
<h3>Parameters:</h3>
|
<h3>Parameters:</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li><span class="parameter">c</span>
|
|
||||||
<span class="types"><a class="type" href="../modules/ecs.html#Entity.Component">Component</a></span>
|
|
||||||
the entity’s system component
|
|
||||||
</li>
|
|
||||||
<li><span class="parameter">e</span>
|
<li><span class="parameter">e</span>
|
||||||
<span class="types"><a class="type" href="../modules/ecs.html#Entity_objects">Entity</a></span>
|
<span class="types"><a class="type" href="../modules/ecs.html#Entity_objects">Entity</a></span>
|
||||||
the entity table
|
the entity table
|
||||||
</li>
|
</li>
|
||||||
|
<li><span class="parameter">c</span>
|
||||||
|
<span class="types"><a class="type" href="../modules/ecs.html#Entity.Component">Component</a></span>
|
||||||
|
the entity’s system component, if any
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1012,7 +1041,7 @@ avoid repeating your filters or allow controlling several system from a single p
|
||||||
</dd>
|
</dd>
|
||||||
<dt>
|
<dt>
|
||||||
<a name = "System:process"></a>
|
<a name = "System:process"></a>
|
||||||
<strong>System:process (c, e, dt) <sup><em>[callback]</em></sup></strong>
|
<strong>System:process (e, c, dt) <sup><em>[callback]</em></sup></strong>
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
Called when updating the system, for every entity the system contains. Called after <a href="../modules/ecs.html#System:onUpdate">System:onUpdate</a> was called on the system.
|
Called when updating the system, for every entity the system contains. Called after <a href="../modules/ecs.html#System:onUpdate">System:onUpdate</a> was called on the system.
|
||||||
|
|
@ -1024,14 +1053,14 @@ avoid repeating your filters or allow controlling several system from a single p
|
||||||
|
|
||||||
<h3>Parameters:</h3>
|
<h3>Parameters:</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li><span class="parameter">c</span>
|
|
||||||
<span class="types"><a class="type" href="../modules/ecs.html#Entity.Component">Component</a></span>
|
|
||||||
the entity’s system component
|
|
||||||
</li>
|
|
||||||
<li><span class="parameter">e</span>
|
<li><span class="parameter">e</span>
|
||||||
<span class="types"><a class="type" href="../modules/ecs.html#Entity_objects">Entity</a></span>
|
<span class="types"><a class="type" href="../modules/ecs.html#Entity_objects">Entity</a></span>
|
||||||
the entity table
|
the entity table
|
||||||
</li>
|
</li>
|
||||||
|
<li><span class="parameter">c</span>
|
||||||
|
<span class="types"><a class="type" href="../modules/ecs.html#Entity.Component">Component</a></span>
|
||||||
|
the entity’s system component, if any
|
||||||
|
</li>
|
||||||
<li><span class="parameter">dt</span>
|
<li><span class="parameter">dt</span>
|
||||||
<span class="types"><span class="type">number</span></span>
|
<span class="types"><span class="type">number</span></span>
|
||||||
delta-time since last update
|
delta-time since last update
|
||||||
|
|
@ -1045,7 +1074,7 @@ avoid repeating your filters or allow controlling several system from a single p
|
||||||
</dd>
|
</dd>
|
||||||
<dt>
|
<dt>
|
||||||
<a name = "System:render"></a>
|
<a name = "System:render"></a>
|
||||||
<strong>System:render (c, e) <sup><em>[callback]</em></sup></strong>
|
<strong>System:render (e, c) <sup><em>[callback]</em></sup></strong>
|
||||||
</dt>
|
</dt>
|
||||||
<dd>
|
<dd>
|
||||||
Called when drawing the system, for every entity the system contains. Called after <a href="../modules/ecs.html#System:onDraw">System:onDraw</a> was called on the system.
|
Called when drawing the system, for every entity the system contains. Called after <a href="../modules/ecs.html#System:onDraw">System:onDraw</a> was called on the system.
|
||||||
|
|
@ -1057,14 +1086,14 @@ avoid repeating your filters or allow controlling several system from a single p
|
||||||
|
|
||||||
<h3>Parameters:</h3>
|
<h3>Parameters:</h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li><span class="parameter">c</span>
|
|
||||||
<span class="types"><a class="type" href="../modules/ecs.html#Entity.Component">Component</a></span>
|
|
||||||
the entity’s system component
|
|
||||||
</li>
|
|
||||||
<li><span class="parameter">e</span>
|
<li><span class="parameter">e</span>
|
||||||
<span class="types"><a class="type" href="../modules/ecs.html#Entity_objects">Entity</a></span>
|
<span class="types"><a class="type" href="../modules/ecs.html#Entity_objects">Entity</a></span>
|
||||||
the entity table
|
the entity table
|
||||||
</li>
|
</li>
|
||||||
|
<li><span class="parameter">c</span>
|
||||||
|
<span class="types"><a class="type" href="../modules/ecs.html#Entity.Component">Component</a></span>
|
||||||
|
the entity’s system component, if any
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1493,7 +1522,7 @@ avoid repeating your filters or allow controlling several system from a single p
|
||||||
<dd>
|
<dd>
|
||||||
Trigger a custom callback on a single entity. </p>
|
Trigger a custom callback on a single entity. </p>
|
||||||
|
|
||||||
<p> This will call the <code>System:name(c, e, …)</code> method in this system and its subsystems,
|
<p> This will call the <code>System:name(e, c, …)</code> method in this system and its subsystems,
|
||||||
if the method exists and the entity is in the system. <code>c</code> is the system <a href="#Entity.Component">component</a>
|
if the method exists and the entity is in the system. <code>c</code> is the system <a href="#Entity.Component">component</a>
|
||||||
associated with the current system, and <code>e</code> is the <a href="../modules/ecs.html#Entity_objects">Entity</a>.</p>
|
associated with the current system, and <code>e</code> is the <a href="../modules/ecs.html#Entity_objects">Entity</a>.</p>
|
||||||
|
|
||||||
|
|
@ -1597,7 +1626,7 @@ its sibling systems (i.e. completely stop the propagation of the event).</li>
|
||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||||
<i style="float:right;">Last updated 2021-12-27 12:20:29 </i>
|
<i style="float:right;">Last updated 2021-12-27 13:15:05 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -1754,7 +1754,7 @@ end
|
||||||
Level background. </p>
|
Level background. </p>
|
||||||
|
|
||||||
<p> If there is a background image, <code>background.image</code> contains a table <code>{image=image, x=number, y=number, sx=number, sy=number}</code>
|
<p> If there is a background image, <code>background.image</code> contains a table <code>{image=image, x=number, y=number, sx=number, sy=number}</code>
|
||||||
where <a href="../modules/ldtk.html#Tileset.image">image</a> is the LÖVE image (or image filepath if LÖVE not available) <a href="../modules/ldtk.html#Entity.x">x</a> and <a href="../modules/ldtk.html#Tile.y">y</a> are the top-left position,
|
where <a href="../modules/ldtk.html#Tileset.image">image</a> is the LÖVE image (or image filepath if LÖVE not available) <a href="../modules/ldtk.html#Level.x">x</a> and <a href="../modules/ldtk.html#Tile.y">y</a> are the top-left position,
|
||||||
and <a href="../modules/ldtk.html#Entity.sx">sx</a> and <a href="../modules/ldtk.html#Entity.sy">sy</a> the horizontal and vertical scale factors.
|
and <a href="../modules/ldtk.html#Entity.sx">sx</a> and <a href="../modules/ldtk.html#Entity.sy">sy</a> the horizontal and vertical scale factors.
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
@ -1829,7 +1829,7 @@ end
|
||||||
<li>Enum are converted into a Lua string giving the currently selected enum value.</li>
|
<li>Enum are converted into a Lua string giving the currently selected enum value.</li>
|
||||||
<li>Filepath are converted into a Lua string giving the file path.</li>
|
<li>Filepath are converted into a Lua string giving the file path.</li>
|
||||||
<li>Arrays are converted into a Lua table with the elements in it as a list.</li>
|
<li>Arrays are converted into a Lua table with the elements in it as a list.</li>
|
||||||
<li>Points are converted into a Lua table with the fields <a href="../modules/ldtk.html#Entity.x">x</a> and <a href="../modules/ldtk.html#Tile.y">y</a>: <code>{ x=number, y=number }</code>.</li>
|
<li>Points are converted into a Lua table with the fields <a href="../modules/ldtk.html#Level.x">x</a> and <a href="../modules/ldtk.html#Tile.y">y</a>: <code>{ x=number, y=number }</code>.</li>
|
||||||
<li>Colors are converted into a Lua table with the red, green and blue components in [0-1] as a list: <code>{r,g,b}</code>.</li>
|
<li>Colors are converted into a Lua table with the red, green and blue components in [0-1] as a list: <code>{r,g,b}</code>.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
|
@ -1855,7 +1855,7 @@ end
|
||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||||
<i style="float:right;">Last updated 2021-12-27 12:20:29 </i>
|
<i style="float:right;">Last updated 2021-12-27 13:15:05 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -702,7 +702,7 @@
|
||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||||
<i style="float:right;">Last updated 2021-12-27 12:20:29 </i>
|
<i style="float:right;">Last updated 2021-12-27 13:15:05 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -414,7 +414,7 @@
|
||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||||
<i style="float:right;">Last updated 2021-12-27 12:20:29 </i>
|
<i style="float:right;">Last updated 2021-12-27 13:15:05 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -1153,7 +1153,7 @@
|
||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||||
<i style="float:right;">Last updated 2021-12-27 12:20:29 </i>
|
<i style="float:right;">Last updated 2021-12-27 13:15:05 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -362,7 +362,7 @@
|
||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||||
<i style="float:right;">Last updated 2021-12-27 12:20:29 </i>
|
<i style="float:right;">Last updated 2021-12-27 13:15:05 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -784,7 +784,7 @@
|
||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||||
<i style="float:right;">Last updated 2021-12-27 12:20:29 </i>
|
<i style="float:right;">Last updated 2021-12-27 13:15:05 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,7 @@
|
||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||||
<i style="float:right;">Last updated 2021-12-27 12:20:29 </i>
|
<i style="float:right;">Last updated 2021-12-27 13:15:05 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@
|
||||||
</div> <!-- id="main" -->
|
</div> <!-- id="main" -->
|
||||||
<div id="about">
|
<div id="about">
|
||||||
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
|
||||||
<i style="float:right;">Last updated 2021-12-27 12:20:29 </i>
|
<i style="float:right;">Last updated 2021-12-27 13:15:05 </i>
|
||||||
</div> <!-- id="about" -->
|
</div> <!-- id="about" -->
|
||||||
</div> <!-- id="container" -->
|
</div> <!-- id="container" -->
|
||||||
</body>
|
</body>
|
||||||
|
|
|
||||||
62
ecs/ecs.can
62
ecs/ecs.can
|
|
@ -28,7 +28,7 @@ local ecs = require("ubiquitousse.ecs")
|
||||||
|
|
||||||
local talkingSystem = {
|
local talkingSystem = {
|
||||||
filter = { "name", "mass", "phrase" },
|
filter = { "name", "mass", "phrase" },
|
||||||
process = function(self, c, e, dt)
|
process = function(self, e, c, dt)
|
||||||
e.mass = e.mass + dt * 3
|
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
|
end
|
||||||
|
|
@ -74,7 +74,8 @@ This library does not do any kind of special processing by itself on the entity
|
||||||
so you are free to handle them as you want in your systems or elsewhere.
|
so you are free to handle them as you want in your systems or elsewhere.
|
||||||
|
|
||||||
Since it's relatively common for systems to only operate on a single component, as a shortcut the library often consider what it calls the "system component":
|
Since it's relatively common for systems to only operate on a single component, as a shortcut the library often consider what it calls the "system component":
|
||||||
that is, the component in the entity that has the same name as the system (if it exists).
|
that is, the component in the entity that is named like `System.component` (or `System.name` if it is not set). Though there's no problem if there's no system
|
||||||
|
component or if it doesn't exist in the entity.
|
||||||
|
|
||||||
@doc Component
|
@doc Component
|
||||||
@usage
|
@usage
|
||||||
|
|
@ -90,9 +91,9 @@ local sprite = {
|
||||||
filter = "sprite", -- process entities that have a "sprite" component
|
filter = "sprite", -- process entities that have a "sprite" component
|
||||||
-- systems callbacks that are called per-entity often give you the system component as an argument
|
-- systems callbacks that are called per-entity often give you the system component as an argument
|
||||||
-- the system component is the component with the same name as the system, thus here the sprite component
|
-- the system component is the component with the same name as the system, thus here the sprite component
|
||||||
render = function(self, component, entity)
|
render = function(self, entity, component)
|
||||||
-- component == entity.sprite
|
-- component == entity.sprite
|
||||||
component:draw()
|
draw(component)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
]]--
|
]]--
|
||||||
|
|
@ -187,12 +188,12 @@ local sprite = {
|
||||||
systems = { animated }, -- subsystems: they only operate on entities already filtered by this system (on top of their own filtering)
|
systems = { animated }, -- subsystems: they only operate on entities already filtered by this system (on top of their own filtering)
|
||||||
|
|
||||||
-- Called when an entity is added to this system.
|
-- Called when an entity is added to this system.
|
||||||
onAdd = function(self, component, entity)
|
onAdd = function(self, entity, component)
|
||||||
print("Added an entity, entity count in the system:", self.entityCount) -- self refer to the instancied system
|
print("Added an entity, entity count in the system:", self.entityCount) -- self refer to the instancied system
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-- Called when the system is updated, for every entity the system
|
-- Called when the system is updated, for every entity the system
|
||||||
process = function(self, component, entity, dt)
|
process = function(self, entity, component, dt)
|
||||||
-- processing...
|
-- processing...
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
@ -221,8 +222,8 @@ let system_mt = {
|
||||||
-- @doc modifiable
|
-- @doc modifiable
|
||||||
|
|
||||||
--- Name of the system.
|
--- Name of the system.
|
||||||
-- Used to create a field with the system's name in `world.s` and determine the associated system component.
|
-- Used to create a field with the system's name in `world.s` and determine the associated system component if `System.component` is not set.
|
||||||
-- If not set, the system will not appear in `world.s` and gives `nil` instead of the system component in callbacks.
|
-- If not set, the system will not appear in `world.s`.
|
||||||
--
|
--
|
||||||
-- Do not change after system instanciation.
|
-- Do not change after system instanciation.
|
||||||
-- @ftype string
|
-- @ftype string
|
||||||
|
|
@ -251,13 +252,19 @@ let system_mt = {
|
||||||
-- @ftype boolean
|
-- @ftype boolean
|
||||||
visible = true,
|
visible = true,
|
||||||
|
|
||||||
|
--- Name of the system component.
|
||||||
|
-- Used to determine the associated system component.
|
||||||
|
-- If not set, this will fall back to `System.name`. If this is also not set, then we will give `nil` instead of the system component in callbacks.
|
||||||
|
-- @ftype string
|
||||||
|
-- @ftype nil if no name
|
||||||
|
component = nil,
|
||||||
--- Defaults value to put into the entities's system component when they are added.
|
--- Defaults value to put into the entities's system component when they are added.
|
||||||
--
|
--
|
||||||
-- If this is table, will recursively fill missing values.
|
-- If this is table, will recursively fill missing values.
|
||||||
-- Metatables will be preserved during the copy but not copied themselves.
|
-- Metatables will be preserved during the copy but not copied themselves.
|
||||||
--
|
--
|
||||||
-- Changing this will not affect entities already in the system.
|
-- Changing this will not affect entities already in the system.
|
||||||
-- Doesn't have any effect if the system doesn't have a name.
|
-- Doesn't have any effect if the system doesn't have a component name.
|
||||||
-- @ftype any
|
-- @ftype any
|
||||||
-- @ftype nil if no default
|
-- @ftype nil if no default
|
||||||
default = nil,
|
default = nil,
|
||||||
|
|
@ -297,14 +304,14 @@ let system_mt = {
|
||||||
|
|
||||||
--- Called when adding an entity to the system.
|
--- Called when adding an entity to the system.
|
||||||
-- @callback
|
-- @callback
|
||||||
-- @tparam Component c the entity's system component
|
|
||||||
-- @tparam Entity e the entity table
|
-- @tparam Entity e the entity table
|
||||||
onAdd = :(c, e) end,
|
-- @tparam Component c the entity's system component, if any
|
||||||
|
onAdd = :(e, c) end,
|
||||||
--- Called when removing an entity from the system.
|
--- Called when removing an entity from the system.
|
||||||
-- @callback
|
-- @callback
|
||||||
-- @tparam Component c the entity's system component
|
|
||||||
-- @tparam Entity e the entity table
|
-- @tparam Entity e the entity table
|
||||||
onRemove = :(c, e) end,
|
-- @tparam Component c the entity's system component, if any
|
||||||
|
onRemove = :(e, c) end,
|
||||||
--- Called when the system is instancied, before any call to `System:onAddToWorld` (including other systems in the world).
|
--- Called when the system is instancied, before any call to `System:onAddToWorld` (including other systems in the world).
|
||||||
-- @callback
|
-- @callback
|
||||||
onInstance = :() end,
|
onInstance = :() end,
|
||||||
|
|
@ -328,15 +335,15 @@ let system_mt = {
|
||||||
onDraw = :() end,
|
onDraw = :() end,
|
||||||
--- Called when updating the system, for every entity the system contains. Called after `System:onUpdate` was called on the system.
|
--- Called when updating the system, for every entity the system contains. Called after `System:onUpdate` was called on the system.
|
||||||
-- @callback
|
-- @callback
|
||||||
-- @tparam Component c the entity's system component
|
|
||||||
-- @tparam Entity e the entity table
|
-- @tparam Entity e the entity table
|
||||||
|
-- @tparam Component c the entity's system component, if any
|
||||||
-- @number dt delta-time since last update
|
-- @number dt delta-time since last update
|
||||||
process = :(c, e, dt) end,
|
process = :(e, c, dt) end,
|
||||||
--- Called when drawing the system, for every entity the system contains. Called after `System:onDraw` was called on the system.
|
--- Called when drawing the system, for every entity the system contains. Called after `System:onDraw` was called on the system.
|
||||||
-- @callback
|
-- @callback
|
||||||
-- @tparam Component c the entity's system component
|
|
||||||
-- @tparam Entity e the entity table
|
-- @tparam Entity e the entity table
|
||||||
render = :(c, e) end,
|
-- @tparam Component c the entity's system component, if any
|
||||||
|
render = :(e, c) end,
|
||||||
|
|
||||||
--- Read-only fields.
|
--- Read-only fields.
|
||||||
--
|
--
|
||||||
|
|
@ -395,8 +402,8 @@ let system_mt = {
|
||||||
add = :(e, ...)
|
add = :(e, ...)
|
||||||
if e ~= nil and not @_previous[e] and @filter(e) then
|
if e ~= nil and not @_previous[e] and @filter(e) then
|
||||||
-- copy default system component
|
-- copy default system component
|
||||||
if @name and @default then
|
if @component and @default then
|
||||||
copy({ [@name] = @default }, e)
|
copy({ [@component] = @default }, e)
|
||||||
end
|
end
|
||||||
-- add to linked list
|
-- add to linked list
|
||||||
if @_first == nil then
|
if @_first == nil then
|
||||||
|
|
@ -426,7 +433,7 @@ let system_mt = {
|
||||||
end
|
end
|
||||||
-- notify addition
|
-- notify addition
|
||||||
@entityCount += 1
|
@entityCount += 1
|
||||||
@onAdd(e[@name], e)
|
@onAdd(e, e[@component])
|
||||||
-- add to subsystems (if it wasn't immediately removed in onAdd)
|
-- add to subsystems (if it wasn't immediately removed in onAdd)
|
||||||
if @_previous[e] then
|
if @_previous[e] then
|
||||||
for _, s in ipairs(@systems) do
|
for _, s in ipairs(@systems) do
|
||||||
|
|
@ -477,7 +484,7 @@ let system_mt = {
|
||||||
-- notify removal
|
-- notify removal
|
||||||
@_previous[e] = nil
|
@_previous[e] = nil
|
||||||
@entityCount -= 1
|
@entityCount -= 1
|
||||||
@onRemove(e[@name], e)
|
@onRemove(e, e[@component])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if ... then
|
if ... then
|
||||||
|
|
@ -613,7 +620,7 @@ let system_mt = {
|
||||||
@onUpdate(dt)
|
@onUpdate(dt)
|
||||||
if @process ~= system_mt.process then
|
if @process ~= system_mt.process then
|
||||||
for e in @iter() do
|
for e in @iter() do
|
||||||
@process(e[@name], e, dt)
|
@process(e, e[@component], dt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for _, s in ipairs(@systems) do
|
for _, s in ipairs(@systems) do
|
||||||
|
|
@ -632,7 +639,7 @@ let system_mt = {
|
||||||
@onDraw()
|
@onDraw()
|
||||||
if @render ~= system_mt.render then
|
if @render ~= system_mt.render then
|
||||||
for e in @iter() do
|
for e in @iter() do
|
||||||
@render(e[@name], e)
|
@render(e, e[@component])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for _, s in ipairs(@systems) do
|
for _, s in ipairs(@systems) do
|
||||||
|
|
@ -642,7 +649,7 @@ let system_mt = {
|
||||||
end,
|
end,
|
||||||
--- Trigger a custom callback on a single entity.
|
--- Trigger a custom callback on a single entity.
|
||||||
--
|
--
|
||||||
-- This will call the `System:name(c, e, ...)` method in this system and its subsystems,
|
-- This will call the `System:name(e, c, ...)` method in this system and its subsystems,
|
||||||
-- if the method exists and the entity is in the system. `c` is the system [component](#Entity.Component)
|
-- if the method exists and the entity is in the system. `c` is the system [component](#Entity.Component)
|
||||||
-- associated with the current system, and `e` is the `Entity`.
|
-- associated with the current system, and `e` is the `Entity`.
|
||||||
--
|
--
|
||||||
|
|
@ -653,7 +660,7 @@ let system_mt = {
|
||||||
callback = :(name, e, ...)
|
callback = :(name, e, ...)
|
||||||
-- call callback
|
-- call callback
|
||||||
if @_previous[e] and @[name] then
|
if @_previous[e] and @[name] then
|
||||||
@[name](@, e[@name], e, ...)
|
@[name](@, e, e[@component], ...)
|
||||||
end
|
end
|
||||||
-- callback on subsystems (if it wasn't removed during the callback)
|
-- callback on subsystems (if it wasn't removed during the callback)
|
||||||
if @_previous[e] then
|
if @_previous[e] then
|
||||||
|
|
@ -732,6 +739,7 @@ let recInstanciateSystems = (world, systems)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
-- create filter
|
||||||
if type(s.filter) == "string" then
|
if type(s.filter) == "string" then
|
||||||
system.filter = (_, e) return e[s.filter] ~= nil end
|
system.filter = (_, e) return e[s.filter] ~= nil end
|
||||||
elseif type(s.filter) == "table" then
|
elseif type(s.filter) == "table" then
|
||||||
|
|
@ -743,6 +751,10 @@ let recInstanciateSystems = (world, systems)
|
||||||
system.filter = alwaysFalse
|
system.filter = alwaysFalse
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- system component fallback on system name
|
||||||
|
if not s.component and s.name then
|
||||||
|
s.component = s.name
|
||||||
|
end
|
||||||
-- add system
|
-- add system
|
||||||
table.insert(t, system)
|
table.insert(t, system)
|
||||||
if s.name then
|
if s.name then
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue