add entity 'on_render' event
This commit is contained in:
parent
d099b294a2
commit
0d230f2449
@ -88,7 +88,7 @@ function on_trigger_exit(index, oid)
|
||||
end
|
||||
end
|
||||
|
||||
function on_update()
|
||||
function on_render()
|
||||
if inair then
|
||||
local dt = time.delta();
|
||||
|
||||
@ -100,6 +100,9 @@ function on_update()
|
||||
mat4.scale(matrix, scale, matrix)
|
||||
rig:set_matrix(0, matrix)
|
||||
end
|
||||
end
|
||||
|
||||
function on_update()
|
||||
if target ~= -1 then
|
||||
local dir = vec3.sub({player.get_pos(target)}, tsf:get_pos())
|
||||
vec3.normalize(dir, dir)
|
||||
|
||||
@ -68,7 +68,7 @@ return {
|
||||
end
|
||||
end,
|
||||
update = function()
|
||||
for id,entity in pairs(entities) do
|
||||
for _,entity in pairs(entities) do
|
||||
for _, component in pairs(entity.components) do
|
||||
local callback = component.on_update
|
||||
if callback then
|
||||
@ -80,5 +80,19 @@ return {
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
render = function()
|
||||
for _,entity in pairs(entities) do
|
||||
for _, component in pairs(entity.components) do
|
||||
local callback = component.on_render
|
||||
if callback then
|
||||
local result, err = pcall(callback)
|
||||
if err then
|
||||
--// TODO: replace with error logging
|
||||
print(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
@ -422,6 +422,13 @@ void scripting::on_entities_update() {
|
||||
lua::pop(L);
|
||||
}
|
||||
|
||||
void scripting::on_entities_render() {
|
||||
auto L = lua::get_main_thread();
|
||||
lua::get_from(L, STDCOMP, "render", true);
|
||||
lua::call_nothrow(L, 0, 0);
|
||||
lua::pop(L);
|
||||
}
|
||||
|
||||
void scripting::on_ui_open(
|
||||
UiDocument* layout,
|
||||
std::vector<dynamic::Value> args
|
||||
|
||||
@ -89,6 +89,7 @@ namespace scripting {
|
||||
bool on_entity_fall(const Entity& entity);
|
||||
bool on_entity_save(const Entity& entity);
|
||||
void on_entities_update();
|
||||
void on_entities_render();
|
||||
void on_trigger_enter(const Entity& entity, size_t index, entityid_t oid);
|
||||
void on_trigger_exit(const Entity& entity, size_t index, entityid_t oid);
|
||||
|
||||
|
||||
@ -311,12 +311,6 @@ void Entities::updatePhysics(float delta) {
|
||||
|
||||
void Entities::update() {
|
||||
scripting::on_entities_update();
|
||||
auto view = registry.view<Transform>();
|
||||
for (auto [entity, transform] : view.each()) {
|
||||
if (transform.dirty) {
|
||||
transform.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Entities::renderDebug(LineBatch& batch, const Frustum& frustum) {
|
||||
@ -343,8 +337,13 @@ void Entities::renderDebug(LineBatch& batch, const Frustum& frustum) {
|
||||
}
|
||||
|
||||
void Entities::render(Assets* assets, ModelBatch& batch, const Frustum& frustum) {
|
||||
scripting::on_entities_render();
|
||||
|
||||
auto view = registry.view<Transform, rigging::Rig>();
|
||||
for (auto [entity, transform, rig] : view.each()) {
|
||||
if (transform.dirty) {
|
||||
transform.refresh();
|
||||
}
|
||||
const auto& pos = transform.pos;
|
||||
const auto& size = transform.size;
|
||||
if (frustum.isBoxVisible(pos-size, pos+size)) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user