mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 22:41:49 +00:00
fix components order & add skeleton:get_matrix overload & add skeleton:reset_pose
This commit is contained in:
parent
8a9b4a9e9c
commit
8242d299ed
3 changed files with 29 additions and 8 deletions
|
|
@ -48,8 +48,9 @@ end
|
||||||
local Skeleton = {__index={
|
local Skeleton = {__index={
|
||||||
get_model=function(self, i) return __skeleton.get_model(self.eid, i) end,
|
get_model=function(self, i) return __skeleton.get_model(self.eid, i) end,
|
||||||
set_model=function(self, i, s) return __skeleton.set_model(self.eid, i, s) end,
|
set_model=function(self, i, s) return __skeleton.set_model(self.eid, i, s) end,
|
||||||
get_matrix=function(self, i) return __skeleton.get_matrix(self.eid, i) end,
|
get_matrix=function(self, i, ...) return __skeleton.get_matrix(self.eid, i, ...) end,
|
||||||
set_matrix=function(self, i, m) return __skeleton.set_matrix(self.eid, i, m) end,
|
set_matrix=function(self, i, m) return __skeleton.set_matrix(self.eid, i, m) end,
|
||||||
|
reset_pose=function(self) return __skeleton.reset_pose(self.eid) end,
|
||||||
get_texture=function(self, s) return __skeleton.get_texture(self.eid, s) end,
|
get_texture=function(self, s) return __skeleton.get_texture(self.eid, s) end,
|
||||||
set_texture=function(self, s, s2) return __skeleton.set_texture(self.eid, s, s2) end,
|
set_texture=function(self, s, s2) return __skeleton.set_texture(self.eid, s, s2) end,
|
||||||
index=function(self, s) return __skeleton.index(self.eid, s) end,
|
index=function(self, s) return __skeleton.index(self.eid, s) end,
|
||||||
|
|
@ -84,7 +85,7 @@ local Entity = {__index={
|
||||||
def_name=function(self) return entities.def_name(entities.get_def(self.eid)) end,
|
def_name=function(self) return entities.def_name(entities.get_def(self.eid)) end,
|
||||||
get_player=function(self) return entities.get_player(self.eid) end,
|
get_player=function(self) return entities.get_player(self.eid) end,
|
||||||
set_enabled=function(self, name, flag)
|
set_enabled=function(self, name, flag)
|
||||||
local comp = self.components[name]
|
local comp = self.components[name]
|
||||||
if comp then
|
if comp then
|
||||||
if flag then
|
if flag then
|
||||||
if comp.__disabled and comp.on_enable then
|
if comp.__disabled and comp.on_enable then
|
||||||
|
|
@ -110,6 +111,7 @@ return {
|
||||||
entity.rigidbody = new_Rigidbody(eid)
|
entity.rigidbody = new_Rigidbody(eid)
|
||||||
entity.skeleton = new_Skeleton(eid)
|
entity.skeleton = new_Skeleton(eid)
|
||||||
entity.components = {}
|
entity.components = {}
|
||||||
|
entity.ordered_components = {}
|
||||||
entities[eid] = entity;
|
entities[eid] = entity;
|
||||||
return entity
|
return entity
|
||||||
end,
|
end,
|
||||||
|
|
@ -120,6 +122,7 @@ return {
|
||||||
local entity = entities[eid]
|
local entity = entities[eid]
|
||||||
if entity then
|
if entity then
|
||||||
entity.components = nil
|
entity.components = nil
|
||||||
|
entity.ordered_components = nil
|
||||||
entities[eid] = nil;
|
entities[eid] = nil;
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
@ -128,10 +131,10 @@ return {
|
||||||
if uid % parts ~= part then
|
if uid % parts ~= part then
|
||||||
goto continue
|
goto continue
|
||||||
end
|
end
|
||||||
for _, component in pairs(entity.components) do
|
for _, component in ipairs(entity.ordered_components) do
|
||||||
local callback = component.on_update
|
local callback = component.on_update
|
||||||
if not component.__disabled and callback then
|
if not component.__disabled and callback then
|
||||||
local result, err = pcall(callback, tps)
|
local _, err = pcall(callback, tps)
|
||||||
if err then
|
if err then
|
||||||
debug.error(err)
|
debug.error(err)
|
||||||
end
|
end
|
||||||
|
|
@ -142,7 +145,7 @@ return {
|
||||||
end,
|
end,
|
||||||
physics_update = function(delta)
|
physics_update = function(delta)
|
||||||
for uid, entity in pairs(entities) do
|
for uid, entity in pairs(entities) do
|
||||||
for _, component in pairs(entity.components) do
|
for _, component in ipairs(entity.ordered_components) do
|
||||||
local callback = component.on_physics_update
|
local callback = component.on_physics_update
|
||||||
if not component.__disabled and callback then
|
if not component.__disabled and callback then
|
||||||
local result, err = pcall(callback, delta)
|
local result, err = pcall(callback, delta)
|
||||||
|
|
@ -155,10 +158,10 @@ return {
|
||||||
end,
|
end,
|
||||||
render = function(delta)
|
render = function(delta)
|
||||||
for _,entity in pairs(entities) do
|
for _,entity in pairs(entities) do
|
||||||
for _, component in pairs(entity.components) do
|
for _, component in ipairs(entity.ordered_components) do
|
||||||
local callback = component.on_render
|
local callback = component.on_render
|
||||||
if not component.__disabled and callback then
|
if not component.__disabled and callback then
|
||||||
local result, err = pcall(callback, delta)
|
local _, err = pcall(callback, delta)
|
||||||
if err then
|
if err then
|
||||||
debug.error(err)
|
debug.error(err)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,11 @@ static int l_set_model(lua::State* L) {
|
||||||
static int l_get_matrix(lua::State* L) {
|
static int l_get_matrix(lua::State* L) {
|
||||||
if (auto skeleton = get_skeleton(L)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
|
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
|
||||||
return lua::pushmat4(L, skeleton->pose.matrices[index]);
|
if (lua::istable(L, 3)) {
|
||||||
|
lua::setmat4(L, 3, skeleton->pose.matrices[index]);
|
||||||
|
} else {
|
||||||
|
return lua::pushmat4(L, skeleton->pose.matrices[index]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -79,6 +83,14 @@ static int l_set_matrix(lua::State* L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int l_reset_pose(lua::State* L) {
|
||||||
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
|
auto& pose = skeleton->pose;
|
||||||
|
std::fill(pose.matrices.begin(), pose.matrices.end(), glm::mat4(1.0f));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int l_get_texture(lua::State* L) {
|
static int l_get_texture(lua::State* L) {
|
||||||
if (auto skeleton = get_skeleton(L)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
const auto& found = skeleton->textures.find(lua::require_string(L, 2));
|
const auto& found = skeleton->textures.find(lua::require_string(L, 2));
|
||||||
|
|
@ -169,6 +181,7 @@ const luaL_Reg skeletonlib[] = {
|
||||||
{"set_model", lua::wrap<l_set_model>},
|
{"set_model", lua::wrap<l_set_model>},
|
||||||
{"get_matrix", lua::wrap<l_get_matrix>},
|
{"get_matrix", lua::wrap<l_get_matrix>},
|
||||||
{"set_matrix", lua::wrap<l_set_matrix>},
|
{"set_matrix", lua::wrap<l_set_matrix>},
|
||||||
|
{"reset_pose", lua::wrap<l_reset_pose>},
|
||||||
{"get_texture", lua::wrap<l_get_texture>},
|
{"get_texture", lua::wrap<l_get_texture>},
|
||||||
{"set_texture", lua::wrap<l_set_texture>},
|
{"set_texture", lua::wrap<l_set_texture>},
|
||||||
{"index", lua::wrap<l_index>},
|
{"index", lua::wrap<l_index>},
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,11 @@ static inline const std::string STDCOMP = "stdcomp";
|
||||||
lua::setfield(L, name);
|
lua::setfield(L, name);
|
||||||
lua::pop(L);
|
lua::pop(L);
|
||||||
}
|
}
|
||||||
|
if (lua::getfield(L, "ordered_components")) {
|
||||||
|
lua::pushenv(L, id);
|
||||||
|
lua::rawseti(L, lua::objlen(L, -2) + 1);
|
||||||
|
lua::pop(L);
|
||||||
|
}
|
||||||
lua::pop(L);
|
lua::pop(L);
|
||||||
|
|
||||||
return std::shared_ptr<int>(new int(id), [=](int* id) { //-V508
|
return std::shared_ptr<int>(new int(id), [=](int* id) { //-V508
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue