在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):bakpakin/tiny-ecs开源软件地址(OpenSource Url):https://github.com/bakpakin/tiny-ecs开源编程语言(OpenSource Language):Lua 100.0%开源软件介绍(OpenSource Introduction):tiny-ecsNOTEAlthough there have been almost no commits in several years, this project is not abandoned. tiny-ecs is, for most intents and purposes, finished, and no bugs have been brought to my attention in a while. New issues on GitHub will be addressed. 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. Tiny-ecs also works well with object-oriented programming in Lua because Systems and Entities do not use metatables. This means you can subclass your Systems and Entities and use existing Lua class frameworks with tiny-ecs, no problem. For an example on how to use tiny-ecs with object-oriented Lua, take a look at the demo branch, specifically the systems and entities subdirectories. OverviewTiny-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. EntitiesEntities are simply Lua tables of data that gets processed by Systems. Entities should contain primarily data rather than code, as it is the System's job to do logic on data. Henceforth, a key-value pair in an Entity will be referred to as a Component. WorldsWorlds are the outermost containers in tiny-ecs that contain both Systems and Entities. In typical use, only one World is used at a time. SystemsSystems 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, as well as creating Systems that can be used in an object oriented fashion. FiltersFilters 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. Examplelocal 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(("%s who weighs %d pounds, says %q."):format(e.name, e.mass, 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 Use ItCopy paste tiny.lua into your source folder. For stability and consistent API, please use a tagged release or use LuaRocks. LuarocksTiny-ecs is also on LuaRocks and can be installed with
DemoCheck out the demo, a game originally written for Ludum Dare 32 with the theme 'An Unconventional Weapon'. The demo uses LÖVE, an amazing game framework for Lua. TestingTiny-ecs uses busted for testing. Install and run
DocumentationSee API here. For the most up-to-date documentation, read the source code, or generate the HTML locally with LDoc. See the original forum thread here. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论