🐳chore(库): 调整submodule

develop
xiaojin 5 years ago
parent 7f57515820
commit b582805df0

3
.gitmodules vendored

@ -1,9 +1,6 @@
[submodule "code/framework/3rd/ffi-lua"] [submodule "code/framework/3rd/ffi-lua"]
path = code/framework/3rd/ffi-lua path = code/framework/3rd/ffi-lua
url = git@github.com:cloudfreexiao/cffi-lua.git url = git@github.com:cloudfreexiao/cffi-lua.git
[submodule "code/framework/3rd/goscon"]
path = code/framework/3rd/goscon
url = git@github.com:cloudfreexiao/goscon.git
[submodule "code/framework/3rd/glm"] [submodule "code/framework/3rd/glm"]
path = code/framework/3rd/glm path = code/framework/3rd/glm
url = git@github.com:g-truc/glm.git url = git@github.com:g-truc/glm.git

@ -1 +0,0 @@
Subproject commit 2d6546b99b7f42b53824fdd89a62780e94252a46

@ -10,6 +10,7 @@
#include "aoi.h" #include "aoi.h"
// https://github.com/ssnobin/c_lua_aoi // https://github.com/ssnobin/c_lua_aoi
// 非实时抛出事件lua层定时aoi_update获得aoi事件
#define GET_INTEGER(L, index, isnum) \ #define GET_INTEGER(L, index, isnum) \
(int)lua_tointegerx(L, index, &isnum); \ (int)lua_tointegerx(L, index, &isnum); \

File diff suppressed because it is too large Load Diff

@ -5,40 +5,45 @@
struct entity_world; struct entity_world;
struct ecs_capi { struct ecs_capi
void * (*iter)(struct entity_world *w, int cid, int index); {
void *(*iter)(struct entity_world *w, int cid, int index);
void (*clear_type)(struct entity_world *w, int cid); void (*clear_type)(struct entity_world *w, int cid);
int (*sibling_id)(struct entity_world *w, int cid, int index, int slibling_id); int (*sibling_id)(struct entity_world *w, int cid, int index, int slibling_id);
void* (*add_sibling)(struct entity_world *w, int cid, int index, int slibling_id, const void *buffer, void *L, int world_index); void *(*add_sibling)(struct entity_world *w, int cid, int index, int slibling_id, const void *buffer, void *L, int world_index);
int (*new_entity)(struct entity_world *w, int cid, const void *buffer, void *L, int world_index); int (*new_entity)(struct entity_world *w, int cid, const void *buffer, void *L, int world_index);
void (*remove)(struct entity_world *w, int cid, int index, void *L, int world_index); void (*remove)(struct entity_world *w, int cid, int index, void *L, int world_index);
void (*enable_tag)(struct entity_world *w, int cid, int index, int tag_id, void *L, int world_index); void (*enable_tag)(struct entity_world *w, int cid, int index, int tag_id, void *L, int world_index);
void (*disable_tag)(struct entity_world *w, int cid, int index, int tag_id); void (*disable_tag)(struct entity_world *w, int cid, int index, int tag_id);
void * (*iter_lua)(struct entity_world *w, int cid, int index, void *L, int world_index); void *(*iter_lua)(struct entity_world *w, int cid, int index, void *L, int world_index);
int (*assign_lua)(struct entity_world *w, int cid, int index, void *L, int world_index); int (*assign_lua)(struct entity_world *w, int cid, int index, void *L, int world_index);
}; };
struct ecs_context { struct ecs_context
{
struct ecs_capi *api; struct ecs_capi *api;
struct entity_world *world; struct entity_world *world;
void *L; // for memory allocator void *L; // for memory allocator
int max_id; int max_id;
int cid[1]; int cid[1];
}; };
static inline void static inline void
check_id_(struct ecs_context *ctx, int cid) { check_id_(struct ecs_context *ctx, int cid)
{
assert(cid >= 0 && cid <= ctx->max_id); assert(cid >= 0 && cid <= ctx->max_id);
} }
static inline void * static inline void *
entity_iter(struct ecs_context *ctx, int cid, int index) { entity_iter(struct ecs_context *ctx, int cid, int index)
{
check_id_(ctx, cid); check_id_(ctx, cid);
return ctx->api->iter(ctx->world, ctx->cid[cid], index); return ctx->api->iter(ctx->world, ctx->cid[cid], index);
} }
static inline void * static inline void *
entity_ref_object(struct ecs_context *ctx, int cid, int index) { entity_ref_object(struct ecs_context *ctx, int cid, int index)
{
if (index <= 0) if (index <= 0)
return NULL; return NULL;
check_id_(ctx, cid); check_id_(ctx, cid);
@ -46,96 +51,113 @@ entity_ref_object(struct ecs_context *ctx, int cid, int index) {
} }
static inline void static inline void
entity_clear_type(struct ecs_context *ctx, int cid) { entity_clear_type(struct ecs_context *ctx, int cid)
{
check_id_(ctx, cid); check_id_(ctx, cid);
ctx->api->clear_type(ctx->world, ctx->cid[cid]); ctx->api->clear_type(ctx->world, ctx->cid[cid]);
} }
static inline int static inline int
entity_sibling_id(struct ecs_context *ctx, int cid, int index, int sibling_id) { entity_sibling_id(struct ecs_context *ctx, int cid, int index, int sibling_id)
{
check_id_(ctx, cid); check_id_(ctx, cid);
check_id_(ctx, sibling_id); check_id_(ctx, sibling_id);
return ctx->api->sibling_id(ctx->world, ctx->cid[cid], index, ctx->cid[sibling_id]); return ctx->api->sibling_id(ctx->world, ctx->cid[cid], index, ctx->cid[sibling_id]);
} }
static inline void * static inline void *
entity_sibling(struct ecs_context *ctx, int cid, int index, int sibling_id) { entity_sibling(struct ecs_context *ctx, int cid, int index, int sibling_id)
{
check_id_(ctx, cid); check_id_(ctx, cid);
check_id_(ctx, sibling_id); check_id_(ctx, sibling_id);
int id = ctx->api->sibling_id(ctx->world, ctx->cid[cid], index, ctx->cid[sibling_id]); int id = ctx->api->sibling_id(ctx->world, ctx->cid[cid], index, ctx->cid[sibling_id]);
if (id == 0) { if (id == 0)
{
return NULL; return NULL;
} else { }
return ctx->api->iter(ctx->world, ctx->cid[sibling_id], id-1); else
{
return ctx->api->iter(ctx->world, ctx->cid[sibling_id], id - 1);
} }
} }
static inline void * static inline void *
entity_add_sibling(struct ecs_context *ctx, int cid, int index, int sibling_id, const void *buffer) { entity_add_sibling(struct ecs_context *ctx, int cid, int index, int sibling_id, const void *buffer)
{
check_id_(ctx, cid); check_id_(ctx, cid);
check_id_(ctx, sibling_id); check_id_(ctx, sibling_id);
return ctx->api->add_sibling(ctx->world, ctx->cid[cid], index, ctx->cid[sibling_id], buffer, ctx->L, 1); return ctx->api->add_sibling(ctx->world, ctx->cid[cid], index, ctx->cid[sibling_id], buffer, ctx->L, 1);
} }
static inline int static inline int
entity_new(struct ecs_context *ctx, int cid, const void *buffer) { entity_new(struct ecs_context *ctx, int cid, const void *buffer)
{
check_id_(ctx, cid); check_id_(ctx, cid);
return ctx->api->new_entity(ctx->world, ctx->cid[cid], buffer, ctx->L, 1); return ctx->api->new_entity(ctx->world, ctx->cid[cid], buffer, ctx->L, 1);
} }
static inline void static inline void
entity_remove(struct ecs_context *ctx, int cid, int index) { entity_remove(struct ecs_context *ctx, int cid, int index)
{
check_id_(ctx, cid); check_id_(ctx, cid);
ctx->api->remove(ctx->world, ctx->cid[cid], index, ctx->L, 1); ctx->api->remove(ctx->world, ctx->cid[cid], index, ctx->L, 1);
} }
static inline void static inline void
entity_enable_tag(struct ecs_context *ctx, int cid, int index, int tag_id) { entity_enable_tag(struct ecs_context *ctx, int cid, int index, int tag_id)
{
check_id_(ctx, cid); check_id_(ctx, cid);
check_id_(ctx, tag_id); check_id_(ctx, tag_id);
ctx->api->enable_tag(ctx->world, ctx->cid[cid], index, ctx->cid[tag_id], ctx->L, 1); ctx->api->enable_tag(ctx->world, ctx->cid[cid], index, ctx->cid[tag_id], ctx->L, 1);
} }
static inline void static inline void
entity_disable_tag(struct ecs_context *ctx, int cid, int index, int tag_id) { entity_disable_tag(struct ecs_context *ctx, int cid, int index, int tag_id)
{
check_id_(ctx, cid); check_id_(ctx, cid);
check_id_(ctx, tag_id); check_id_(ctx, tag_id);
ctx->api->disable_tag(ctx->world, ctx->cid[cid], index, ctx->cid[tag_id]); ctx->api->disable_tag(ctx->world, ctx->cid[cid], index, ctx->cid[tag_id]);
} }
static inline int static inline int
entity_assign_lua(struct ecs_context *ctx, int cid, int index) { entity_assign_lua(struct ecs_context *ctx, int cid, int index)
{
check_id_(ctx, cid); check_id_(ctx, cid);
assert(index > 0); assert(index > 0);
return ctx->api->assign_lua(ctx->world, ctx->cid[cid], index-1, ctx->L, 1); return ctx->api->assign_lua(ctx->world, ctx->cid[cid], index - 1, ctx->L, 1);
} }
static inline int static inline int
entity_new_ref(struct ecs_context *ctx, int cid) { entity_new_ref(struct ecs_context *ctx, int cid)
{
check_id_(ctx, cid); check_id_(ctx, cid);
int object_id = ctx->cid[cid]; int object_id = ctx->cid[cid];
int dead_tag = object_id + 1; int dead_tag = object_id + 1;
int id; int id;
if (ctx->api->iter(ctx->world, dead_tag, 0)) { if (ctx->api->iter(ctx->world, dead_tag, 0))
{
// reuse // reuse
id = ctx->api->sibling_id(ctx->world, dead_tag, 0, object_id); id = ctx->api->sibling_id(ctx->world, dead_tag, 0, object_id);
assert(id > 0); assert(id > 0);
--id; --id;
ctx->api->disable_tag(ctx->world, dead_tag, 0, dead_tag); ctx->api->disable_tag(ctx->world, dead_tag, 0, dead_tag);
} else { }
else
{
id = ctx->api->new_entity(ctx->world, object_id, NULL, ctx->L, 1); id = ctx->api->new_entity(ctx->world, object_id, NULL, ctx->L, 1);
} }
return id + 1; return id + 1;
} }
static inline void static inline void
entity_release_ref(struct ecs_context *ctx, int cid, int id) { entity_release_ref(struct ecs_context *ctx, int cid, int id)
{
if (id == 0) if (id == 0)
return; return;
check_id_(ctx, cid); check_id_(ctx, cid);
int object_id = ctx->cid[cid]; int object_id = ctx->cid[cid];
int dead_tag = object_id + 1; int dead_tag = object_id + 1;
ctx->api->enable_tag(ctx->world, object_id, id-1, dead_tag, ctx->L, 1); ctx->api->enable_tag(ctx->world, object_id, id - 1, dead_tag, ctx->L, 1);
} }
#endif #endif

@ -218,7 +218,7 @@ w:register {
type = "float", type = "float",
} }
for v in w:select "vector:in sum:temp" do for v in w:select "vector:in sum:new" do
print(v.vector.x, "+", v.vector.y) print(v.vector.x, "+", v.vector.y)
v.sum = v.vector.x + v.vector.y v.sum = v.vector.x + v.vector.y
end end

@ -17,7 +17,7 @@ for i = 1, 10 do
end end
local function add_temp(i) local function add_temp(i)
for v in w:select "key:in temp?temp" do for v in w:select "key:in temp?new" do
if v.key == i then if v.key == i then
v.temp = "Temp" v.temp = "Temp"
end end

@ -18,11 +18,28 @@ w:new {
order = true, order = true,
} }
w:new {
node = { id = 2, parent = 0 },
order = true,
}
w:new { w:new {
node = { id = 0, parent = -1 }, node = { id = 0, parent = -1 },
}
w:new {
node = { id = 3, parent = 0 },
order = true, order = true,
} }
for v in w:select "node:in order?new" do
assert(v.order == nil)
if v.node.parent < 0 then
-- add order
v.order = true
end
end
local cache = {} local cache = {}
for v in w:select "order node:update" do for v in w:select "order node:update" do

@ -1,51 +1,31 @@
-- test sort
local ecs = require "ecs" local ecs = require "ecs"
local w = ecs.world() local w = ecs.world()
w:register { w:register {
name = "data", name = "value",
type = "float", type = "int",
} }
w:register { w:register {
name = "index", name = "mark"
type = "int",
} }
local tmp = { 10,9,8,7,6,5,4,3,2,1 } w:new {
value = 1,
for i = 1, 10, 2 do mark = true,
w:new { data = tmp[i], index = tmp[i] } }
w:new { index = tmp[i+1] }
end
w:update()
for v in w:select "index data?in" do
print(v.data)
end
w:sort("sort", "index")
print "sorted"
for v in w:select "sort data:in index:in" do
print(v.data, v.index)
end
w:register { w:new {
name = "sorted_index", mark = true,
type = "int",
} }
for i = 1, 10 do
w:new { data = i * 0.5 , sorted_index = i * 2 }
end
for v in w:select "sorted_index:in data?in" do for v in w:select "mark" do
print(v.sorted_index, "=>", v.data) w:sync("value?in", v)
print(v.value)
end end
--w:remove(iter) for v in w:select "mark" do
print(pcall(w.sync, w, "value:in", v))
end

@ -53,74 +53,3 @@ for v in w:select "index:in" do
print(v.index) print(v.index)
end end
print "Index refobject"
for v in w:select "refobject(index):in" do
print(v.refobject)
end
w:register {
name = "name",
type = "lua",
}
w:new {
name = "Hello"
}
for v in w:select "index:in" do
print(v.index)
end
for v in w:select "name refobject(index):temp" do
v.refobject = 42
end
for v in w:select "refobject:in" do
print(v.refobject)
end
for v in w:select "refobject(index):update" do
v.refobject = v.refobject + 1
end
for v in w:select "refobject:in" do
print(v.refobject)
end
w:register {
name = "mark"
}
local ref = w:object_ref("refobject", id4)
ref.mark = true
w:sync("mark?out", ref)
w:ref ("refobject", {
refobject = 42,
mark = true
})
print "Marked refobject"
for v in w:select "mark refobject?in" do
print(v.refobject)
end
w:register {
name = "refobject2",
type = "int",
ref = true,
}
w:register {
name = "mark2"
}
w:ref ("refobject2", {
refobject2 = 42,
mark = true,
mark2 = false,
})

@ -20,7 +20,7 @@ for v in w:select "a:in" do
if v.a %2 == 0 then if v.a %2 == 0 then
v.a = -v.a v.a = -v.a
v.temp = 42 v.temp = 42
w:sync("a:out temp:temp", v) w:sync("a:out temp:new", v)
end end
end end

@ -8,6 +8,10 @@ w:register {
"b:userdata", "b:userdata",
} }
w:register {
name = "flag",
}
w:new { w:new {
t = { t = {
a = false, a = false,
@ -36,3 +40,23 @@ print_v()
test.testuserdata(ctx) test.testuserdata(ctx)
print_v() print_v()
local v = w:singleton("t", "flag t:in")
assert(v == nil)
-- remove singleton of t
local v = w:singleton "t"
w:remove(v)
w:update()
w:new {
t = {
a = true,
b = ecs.NULL,
},
flag = true,
}
local v = w:singleton("t", "flag t:in")
assert(v.t.a == true)

File diff suppressed because it is too large Load Diff

@ -1,434 +1,455 @@
local ecs = require "ecs.core" local ecs = require "ecs.core"
local REFERENCE_ID <const> = 1 local REFERENCE_ID<const> = 1
local rawerror = error
local selfsource<const> = debug.getinfo(1, "S").source
local function error(errmsg)
local level = 2
while true do
local info = debug.getinfo(level, "S")
if not info then
rawerror(errmsg, 2)
return
end
if selfsource ~= info.source then
rawerror(errmsg, level)
return
end
level = level + 1
end
end
local function assert(cond, errmsg)
if not cond then
error(errmsg or "assertion failed!")
end
return cond
end
local function get_attrib(opt, inout) local function get_attrib(opt, inout)
if opt == nil then if opt == nil then
return { exist = true } return {
end exist = true,
local desc = {} }
if opt == "?" then end
desc.opt = true local desc = {}
else if opt == "?" then
assert(opt == ":") desc.opt = true
end else
if inout == "in" then assert(opt == ":")
desc.r = true end
elseif inout == "out" then if inout == "in" then
desc.w = true desc.r = true
elseif inout == "update" then elseif inout == "out" then
desc.r = true desc.w = true
desc.w = true elseif inout == "update" then
elseif inout == "exist" then desc.r = true
desc.exist = true desc.w = true
assert(not desc.opt) elseif inout == "exist" then
elseif inout == "absent" then desc.exist = true
desc.absent = true assert(not desc.opt)
assert(not desc.opt) elseif inout == "absent" then
else desc.absent = true
assert(inout == "temp") assert(not desc.opt)
end else
return desc assert(inout == "new")
end
return desc
end end
local function cache_world(obj, k) local function cache_world(obj, k)
local c = { local c = {
typenames = {}, typenames = {},
id = 0, id = 0,
select = {}, select = {},
ref = {}, ref = {},
} }
local function gen_ref_pat(key) local function gen_ref_pat(key)
local typenames = c.typenames local typenames = c.typenames
local desc = {} local desc = {}
local tc = typenames[key] local tc = typenames[key]
if tc == nil then if tc == nil then
error("Unknown type " .. key) error("Unknown type " .. key)
end end
local a = { local a = {
exist = true, exist = true,
name = tc.name, name = tc.name,
id = tc.id, id = tc.id,
type = tc.type, type = tc.type,
} }
local n = #tc local n = #tc
for i=1,#tc do for i = 1, #tc do
a[i] = tc[i] a[i] = tc[i]
end end
desc[1] = a desc[1] = a
return desc return desc
end end
local function gen_all_pat() local function gen_all_pat()
local desc = {} local desc = {}
local i = 1 local i = 1
for name,t in pairs(c.typenames) do for name, t in pairs(c.typenames) do
if t.tag ~= "ORDER" then if t.tag ~= "ORDER" then
local a = { local a = {
name = t.name, name = t.name,
id = t.id, id = t.id,
type = t.type, type = t.type,
opt = true, opt = true,
r = true, r = true,
} }
table.move(t, 1, #t, 1, a) table.move(t, 1, #t, 1, a)
desc[i] = a desc[i] = a
i = i + 1 i = i + 1
end end
end end
return desc return desc
end end
setmetatable(c, { __index = function(_, key) setmetatable(c, {
if key == "all" then __index = function(_, key)
local all = k:_groupiter(gen_all_pat()) if key == "all" then
c.all = all local all = k:_groupiter(gen_all_pat())
return all c.all = all
end return all
end }) end
end,
local function gen_select_pat(pat) })
local typenames = c.typenames
local desc = {} local function gen_select_pat(pat)
local idx = 1 local typenames = c.typenames
for token in pat:gmatch "[^ ]+" do local desc = {}
local key, index, padding = token:match "^([_%w]+)%(?([_%w]*)%)?(.*)" local idx = 1
assert(key, "Invalid pattern") for token in pat:gmatch "[^ ]+" do
local opt, inout local key, padding = token:match "^([_%w]+)(.*)"
if padding ~= "" then assert(key, "Invalid pattern")
opt, inout = padding:match "^([:?])(%l+)$" local opt, inout
assert(opt, "Invalid pattern") if padding ~= "" then
end opt, inout = padding:match "^([:?])(%l+)$"
local tc = typenames[key] assert(opt, "Invalid pattern")
if tc == nil then end
error("Unknown type " .. key) local tc = typenames[key]
end if tc == nil then
if index ~= "" then error("Unknown type " .. key)
local indexc = typenames[index] end
if indexc == nil then local a = get_attrib(opt, inout)
error("Unknown index type "..index) a.name = tc.name
end a.id = tc.id
local a = get_attrib(opt, inout == "temp" and "temp" or "in") a.type = tc.type
a.name = index local n = #tc
a.id = indexc.id for i = 1, #tc do
a.type = indexc.type a[i] = tc[i]
a.ref = true end
desc[idx] = a desc[idx] = a
idx = idx + 1 idx = idx + 1
end if tc.ref then
local a = get_attrib(opt, inout) local dead = typenames[key .. "_dead"]
a.name = tc.name local a = {
a.id = tc.id absent = true,
a.type = tc.type name = dead.name,
local n = #tc id = dead.id,
for i=1,#tc do }
a[i] = tc[i] desc[idx] = a
end idx = idx + 1
desc[idx] = a end
idx = idx + 1 end
if tc.ref and index == "" then return desc
local dead = typenames[key .. "_dead"] end
local a = {
absent = true, local function cache_select(cache, pat)
name = dead.name, local pat_desc = gen_select_pat(pat)
id = dead.id, cache[pat] = k:_groupiter(pat_desc)
} return cache[pat]
desc[idx] = a end
idx = idx + 1
end setmetatable(c.select, {
end __mode = "kv",
return desc __index = cache_select,
end })
local function cache_select(cache, pat) local function cache_ref(cache, pat)
local pat_desc = gen_select_pat(pat) local pat_desc = gen_ref_pat(pat)
cache[pat] = k:_groupiter(pat_desc) cache[pat] = k:_groupiter(pat_desc)
return cache[pat] return cache[pat]
end end
setmetatable(c.select, { setmetatable(c.ref, {
__mode = "kv", __mode = "kv",
__index = cache_select, __index = cache_ref,
}) })
local function cache_ref(cache, pat) obj[k] = c
local pat_desc = gen_ref_pat(pat) return c
cache[pat] = k:_groupiter(pat_desc)
return cache[pat]
end
setmetatable(c.ref, {
__mode = "kv",
__index = cache_ref,
})
obj[k] = c
return c
end end
local context = setmetatable({}, { __index = cache_world }) local context = setmetatable({}, {
__index = cache_world,
})
local typeid = { local typeid = {
int = assert(ecs._TYPEINT), int = assert(ecs._TYPEINT),
float = assert(ecs._TYPEFLOAT), float = assert(ecs._TYPEFLOAT),
bool = assert(ecs._TYPEBOOL), bool = assert(ecs._TYPEBOOL),
int64 = assert(ecs._TYPEINT64), int64 = assert(ecs._TYPEINT64),
dword = assert(ecs._TYPEDWORD), dword = assert(ecs._TYPEDWORD),
word = assert(ecs._TYPEWORD), word = assert(ecs._TYPEWORD),
byte = assert(ecs._TYPEBYTE), byte = assert(ecs._TYPEBYTE),
double = assert(ecs._TYPEDOUBLE), double = assert(ecs._TYPEDOUBLE),
userdata = assert(ecs._TYPEUSERDATA), userdata = assert(ecs._TYPEUSERDATA),
} }
local typesize = { local typesize = {
[typeid.int] = 4, [typeid.int] = 4,
[typeid.float] = 4, [typeid.float] = 4,
[typeid.bool] = 1, [typeid.bool] = 1,
[typeid.int64] = 8, [typeid.int64] = 8,
[typeid.dword] = 4, [typeid.dword] = 4,
[typeid.word] = 2, [typeid.word] = 2,
[typeid.byte] = 1, [typeid.byte] = 1,
[typeid.double] = 8, [typeid.double] = 8,
[typeid.userdata] = 8, [typeid.userdata] = 8,
} }
local M = ecs._METHODS local M = ecs._METHODS
do -- newtype do -- newtype
local function parse(s) local function parse(s)
-- s is "name:typename" -- s is "name:typename"
local name, typename = s:match "^([%w_]+):(%w+)$" local name, typename = s:match "^([%w_]+):(%w+)$"
local typeid = assert(typeid[typename]) local typeid = assert(typeid[typename])
return { typeid, name } return {typeid, name}
end end
local function align(c, field) local function align(c, field)
local t = field[1] local t = field[1]
local tsize = typesize[t] local tsize = typesize[t]
local offset = ((c.size + tsize - 1) & ~(tsize-1)) local offset = ((c.size + tsize - 1) & ~(tsize - 1))
c.size = offset + tsize c.size = offset + tsize
field[3] = offset field[3] = offset
return field return field
end end
local function align_struct(c, t) local function align_struct(c, t)
if t then if t then
local s = typesize[t] - 1 local s = typesize[t] - 1
c.size = ((c.size + s) & ~s) c.size = ((c.size + s) & ~s)
end end
end end
function M:register(typeclass) function M:register(typeclass)
local name = assert(typeclass.name) local name = assert(typeclass.name)
local ctx = context[self] local ctx = context[self]
ctx.all = nil -- clear all pattern ctx.all = nil -- clear all pattern
local typenames = ctx.typenames local typenames = ctx.typenames
local id = ctx.id + 1 local id = ctx.id + 1
assert(typenames[name] == nil and id <= ecs._MAXTYPE) assert(typenames[name] == nil and id <= ecs._MAXTYPE)
ctx.id = id ctx.id = id
local c = { local c = {
id = id, id = id,
name = name, name = name,
size = 0, size = 0,
} }
for i, v in ipairs(typeclass) do for i, v in ipairs(typeclass) do
c[i] = align(c, parse(v)) c[i] = align(c, parse(v))
end end
local ttype = typeclass.type local ttype = typeclass.type
if ttype == "lua" then if ttype == "lua" then
assert(c.size == 0) assert(c.size == 0)
c.size = ecs._LUAOBJECT c.size = ecs._LUAOBJECT
assert(c[1] == nil) assert(c[1] == nil)
elseif c.size > 0 then elseif c.size > 0 then
align_struct(c, typeclass[1][1]) align_struct(c, c[1][1])
else else
-- size == 0, one value -- size == 0, one value
if ttype then if ttype then
local t = assert(typeid[typeclass.type]) local t = assert(typeid[typeclass.type])
c.type = t c.type = t
c.size = typesize[t] c.size = typesize[t]
c[1] = { t, "v", 0 } c[1] = {t, "v", 0}
elseif typeclass.order then elseif typeclass.order then
c.size = ecs._ORDERKEY c.size = ecs._ORDERKEY
c.tag = "ORDER" c.tag = "ORDER"
else else
c.tag = true c.tag = true
end end
end end
typenames[name] = c typenames[name] = c
self:_newtype(id, c.size) self:_newtype(id, c.size)
if typeclass.ref then if typeclass.ref then
c.ref = true c.ref = true
self:register { name = name .. "_dead" } self:register{
end name = name .. "_dead",
end }
end
end
end end
local function dump(obj) local function dump(obj)
for e,v in pairs(obj) do for e, v in pairs(obj) do
if type(v) == "table" then if type(v) == "table" then
for k,v in pairs(v) do for k, v in pairs(v) do
print(e,k,v) print(e, k, v)
end end
else else
print(e,v) print(e, v)
end end
end end
end end
function M:new(obj) function M:new(obj)
-- dump(obj) -- dump(obj)
local eid = self:_newentity() local eid = self:_newentity()
local typenames = context[self].typenames local typenames = context[self].typenames
local reference = obj.reference local reference = obj.reference
if reference then if reference then
obj.reference = nil obj.reference = nil
end end
for k,v in pairs(obj) do for k, v in pairs(obj) do
local tc = typenames[k] local tc = typenames[k]
if not tc then if not tc then
error ("Invalid key : ".. k) error("Invalid key : " .. k)
end end
local id = self:_addcomponent(eid, tc.id) local id = self:_addcomponent(eid, tc.id)
if tc.tag ~= "ORDER" then if tc.tag ~= "ORDER" then
self:object(k, id, v) self:object(k, id, v)
end end
end end
if reference then if reference then
local id = self:_addcomponent(eid, REFERENCE_ID) local id = self:_addcomponent(eid, REFERENCE_ID)
reference[1] = id reference[1] = id
reference[2] = REFERENCE_ID reference[2] = REFERENCE_ID
self:object("reference", id, reference) self:object("reference", id, reference)
obj.reference = reference obj.reference = reference
return reference return reference
end end
end end
function M:ref(name, refobj) function M:ref(name, refobj)
local obj = assert(refobj[name]) local obj = assert(refobj[name])
local ctx = context[self] local ctx = context[self]
local typenames = ctx.typenames local typenames = ctx.typenames
local tc = assert(typenames[name]) local tc = assert(typenames[name])
local refid = self:_reuse(tc.id) local refid = self:_reuse(tc.id)
refobj[2] = tc.id refobj[2] = tc.id
if refid then if refid then
local p = context[self].select[name .. ":out"] local p = context[self].select[name .. ":out"]
refobj[1] = refid refobj[1] = refid
self:_sync(p, refobj) self:_sync(p, refobj)
else else
local eid = self:_newentity() local eid = self:_newentity()
refid = self:_addcomponent(eid, tc.id) refid = self:_addcomponent(eid, tc.id)
refobj[1] = refid refobj[1] = refid
self:object(name, refid, obj) self:object(name, refid, obj)
end end
for k,v in pairs(refobj) do for k, v in pairs(refobj) do
if (v == true or v == false) and name ~= k then if (v == true or v == false) and name ~= k then
local p = context[self].select[k .. "?out"] local p = context[self].select[k .. "?out"]
self:_sync(p, refobj) self:_sync(p, refobj)
end end
end end
return refid return refid
end end
function M:object_ref(name, refid) function M:object_ref(name, refid)
local typenames = context[self].typenames local typenames = context[self].typenames
return { refid, typenames[name].id } return {refid, typenames[name].id}
end end
function M:release(name, refid) function M:release(name, refid)
local id = assert(context[self].typenames[name].id) local id = assert(context[self].typenames[name].id)
self:_release(id, refid) self:_release(id, refid)
end end
function M:context(t) function M:context(t)
local typenames = context[self].typenames local typenames = context[self].typenames
local id = {} local id = {}
for i, name in ipairs(t) do for i, name in ipairs(t) do
local tc = typenames[name] local tc = typenames[name]
if not tc then if not tc then
error ("Invalid component name " .. name) error("Invalid component name " .. name)
end end
id[i] = tc.id id[i] = tc.id
end end
return self:_context(id) return self:_context(id)
end end
function M:select(pat) function M:select(pat)
return context[self].select[pat]() return context[self].select[pat]()
end end
function M:sync(pat, iter) function M:sync(pat, iter)
local p = context[self].select[pat] local p = context[self].select[pat]
self:_sync(p, iter) self:_sync(p, iter)
return iter return iter
end end
function M:readall(iter) function M:readall(iter)
local p = context[self].all local p = context[self].all
self:_sync(p, iter) self:_sync(p, iter)
return iter return iter
end end
function M:clear(name) function M:clear(name)
local id = assert(context[self].typenames[name].id) local id = assert(context[self].typenames[name].id)
self:_clear(id) self:_clear(id)
end end
function M:dumpid(name) function M:dumpid(name)
local typenames = context[self].typenames local typenames = context[self].typenames
return self:_dumpid(typenames[name].id) return self:_dumpid(typenames[name].id)
end end
function M:update() function M:update()
self:_update_reference(REFERENCE_ID) self:_update_reference(REFERENCE_ID)
self:_update() self:_update()
end end
function M:remove_reference(ref) function M:remove_reference(ref)
ref.reference = false ref.reference = false
self:sync("reference:out", ref) self:sync("reference:out", ref)
ref[1] = nil ref[1] = nil
end end
do do
local _object = M._object local _object = M._object
function M:object(name, refid, v) function M:object(name, refid, v)
local pat = context[self].ref[name] local pat = context[self].ref[name]
return _object(pat, v, refid) return _object(pat, v, refid)
end end
function M:singleton(name, pattern, iter) function M:singleton(name, pattern, iter)
local typenames = context[self].typenames local typenames = context[self].typenames
if iter == nil then if iter == nil then
iter = { 1, typenames[name].id } iter = {1, typenames[name].id}
if pattern then if pattern then
local p = context[self].select[pattern] local p = context[self].select[pattern]
self:_sync(p, iter) return self:_read(p, iter)
end else
return iter return iter
else end
iter[1] = 1 else
iter[2] = typenames[name].id iter[1] = 1
local p = context[self].select[pattern] iter[2] = typenames[name].id
self:_sync(p, iter) local p = context[self].select[pattern]
end self:_sync(p, iter)
return iter end
end return iter
end
end end
function ecs.world() function ecs.world()
local w = ecs._world() local w = ecs._world()
context[w].typenames.REMOVED = { context[w].typenames.REMOVED = {
name = "REMOVED", name = "REMOVED",
id = ecs._REMOVED, id = ecs._REMOVED,
size = 0, size = 0,
tag = true, tag = true,
} }
w:register { w:register{
name = "reference", name = "reference",
type = "lua", type = "lua",
} }
assert(context[w].typenames.reference.id == REFERENCE_ID) assert(context[w].typenames.reference.id == REFERENCE_ID)
return w return w
end end
return ecs return ecs

@ -0,0 +1,15 @@
https://www.cnblogs.com/lucky9322/p/14922842.html
NoSQLBooster for MongoDB 基于 Electro 编写 asar 打包,所以我们能够解包修改代码并重新打包
1.安装工具
npm install asar -g
2.解包
进入 /Applications/NoSQLBooster for MongoDB.app/Contents/Resources
3.修改 app\shared\lmCore.js 里的 MAX_TRIAL_DAYS 和 TRIAL_DAYS 值
MAX_TRIAL_DAYS=999999,TRIAL_DAYS=999999
4.打包,打包完之后删除 app 文件夹
asar pack app app.asar
Loading…
Cancel
Save