engine: move tick call to helper trampoline, +10% perf increase

master
q3k 2021-04-08 22:49:26 +00:00
parent 1553bdce9b
commit 057207fc72
2 changed files with 9 additions and 8 deletions

View File

@ -32,6 +32,14 @@ sent.register = function (cfg)
local sent_id = __sent_new(table, sent_class_id)
table.__sent_id = sent_id
-- Make 'tick' trampoline, used by runtime to do fast call into ticker
-- without bind/argument push.
table.__sent_tick = function()
if table.tick ~= nil then
table:tick()
end
end
-- Configure components dispatcher.
table.components = {}
table.components.__sent_id = sent_id

View File

@ -503,20 +503,13 @@ where
continue;
}
};
let tick: mlua::Function = match table.get("tick") {
let cb: mlua::Function = match table.raw_get("__sent_tick") {
Ok(tick) => tick,
Err(err) => {
log::warn!("Entity {}/{} tick failed: getting tick function failed: {:?}", ecsid, sent.internal_id, err);
continue;
}
};
let cb = match tick.bind(table) {
Ok(cb) => cb,
Err(err) => {
log::warn!("Entity {}/{} tick failed: could not bind: {:?}", ecsid, sent.internal_id, err);
continue;
},
};
tickers.push((*ecsid, cb));
}
}