Difference between revisions of "tiny-ecs"

m
(Entity Component System for lua.)
Line 4: Line 4:
 
Because of lua's tabular nature, Entity Component Systems are a natural choice for
 
Because of lua's tabular nature, Entity Component Systems are a natural choice for
 
simulating large and complex systems. In game programming, ECS is a great way to simplify the game loop. For more explanation on Entity Component Systems,
 
simulating large and complex systems. In game programming, ECS is a great way to simplify the game loop. For more explanation on Entity Component Systems,
here is some basic info. http://en.wikipedia.org/wiki/Entity_component_system
+
here is some [http://en.wikipedia.org/wiki/Entity_component_system basic info].
 +
<br/>
 +
<br/>
  
 
Tiny-ecs also works well with objected oriented programming in lua because Systems and
 
Tiny-ecs also works well with objected oriented programming in lua because Systems and
 
Entities do not use metatables. This means you can subclass your Systems and Entities, and
 
Entities do not use metatables. This means you can subclass your Systems and Entities, and
 
use existing lua class frameworks with tiny-ecs, no problem.
 
use existing lua class frameworks with tiny-ecs, no problem.
 +
<br/>
 +
<br/>
  
Copy/Paste Latest Source: https://raw.githubusercontent.com/bakpakin/tiny-ecs/master/tiny.lua
+
Example:
 +
<source lang="lua">
 +
local tiny = require("tiny")
  
* Source: https://github.com/bakpakin/tiny-ecs
+
local talkingSystem = tiny.processingSystem()
* Demo Source: https://github.com/bakpakin/tiny-ecs/tree/demo-commandokibbles
+
talkingSystem.filter = tiny.requireAll("name", "mass", "phrase")
* API: https://bakpakin.github.io/tiny-ecs/doc/
+
function talkingSystem:process(e, dt)
* Forum Thread: https://love2d.org/forums/viewtopic.php?f=5&t=79937
+
    e.mass = e.mass + dt * 3
 +
    print(e.name .. ", who weighs " .. e.mass .. " pounds, says, \"" .. e.phrase .. "\"")
 +
end
 +
 
 +
local joe = {
 +
    name = "Joe",
 +
    phrase = "I'm a plumber.",
 +
    mass = 150,
 +
    hairColor = "brown"
 +
}
 +
 
 +
local world = tiny.world(talkingSystem, joe)
 +
 
 +
for i = 1, 20 do
 +
    world:update(1)
 +
end
 +
</source>
 +
<br/>
 +
 
 +
 
 +
[https://raw.githubusercontent.com/bakpakin/tiny-ecs/master/tiny.lua Copy/Paste Latest Source]
 +
 
 +
* [https://github.com/bakpakin/tiny-ecs Source]
 +
* [https://github.com/bakpakin/tiny-ecs/tree/demo-commandokibbles Demo Source]
 +
* [https://bakpakin.github.io/tiny-ecs/doc/ API]
 +
* [https://love2d.org/forums/viewtopic.php?f=5&t=79937 Forum Thread]
  
 
{{#set:LOVE Version=Any}}
 
{{#set:LOVE Version=Any}}
 
{{#set:Description=Entity Component System for lua.}}
 
{{#set:Description=Entity Component System for lua.}}
 
[[Category:Libraries]]
 
[[Category:Libraries]]

Revision as of 18:49, 29 August 2015

Entity Component System for lua.

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. In game programming, ECS is a great way to simplify the game loop. For more explanation on Entity Component Systems, here is some basic info.

Tiny-ecs also works well with objected oriented programming in lua because Systems and Entities do not use metatables. This means you can subclass your Systems and Entities, and use existing lua class frameworks with tiny-ecs, no problem.

Example:

local tiny = require("tiny")

local talkingSystem = tiny.processingSystem()
talkingSystem.filter = tiny.requireAll("name", "mass", "phrase")
function talkingSystem:process(e, dt)
    e.mass = e.mass + dt * 3
    print(e.name .. ", who weighs " .. e.mass .. " pounds, says, \"" .. e.phrase .. "\"")
end

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

local world = tiny.world(talkingSystem, joe)

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



Copy/Paste Latest Source