mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 18:41:51 +00:00
add animation.action
This commit is contained in:
parent
c19733b594
commit
39a3c1201f
6 changed files with 45 additions and 13 deletions
|
|
@ -299,4 +299,27 @@ function __vc_internals.load_vca_animation(filepath, identifier)
|
||||||
this.load_vca(filepath, identifier)
|
this.load_vca(filepath, identifier)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local running_actions = {}
|
||||||
|
|
||||||
|
function this.action(func)
|
||||||
|
table.insert(running_actions, coroutine.create(func))
|
||||||
|
end
|
||||||
|
|
||||||
|
function __vc_internals.on_animation_frame()
|
||||||
|
for i=#running_actions,1,-1 do
|
||||||
|
local co = running_actions[i]
|
||||||
|
local status, result = coroutine.resume(co)
|
||||||
|
if not status then
|
||||||
|
debug.error("error in animation action: "..result)
|
||||||
|
table.remove(running_actions, i)
|
||||||
|
elseif coroutine.status(co) == "dead" then
|
||||||
|
table.remove(running_actions, i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function __vc_internals.stop_all_actions()
|
||||||
|
running_actions = {}
|
||||||
|
end
|
||||||
|
|
||||||
return this
|
return this
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
local __app = __vc_app
|
local app = __vc_app
|
||||||
local __rules = rules
|
local __rules = rules
|
||||||
|
local internals = __vc_internals
|
||||||
|
|
||||||
local function configure_SSAO()
|
local function configure_SSAO()
|
||||||
-- Temporary using slot to configure built-in SSAO effect
|
-- Temporary using slot to configure built-in SSAO effect
|
||||||
|
|
@ -32,7 +33,7 @@ local function configure_SSAO()
|
||||||
end
|
end
|
||||||
events.on("core:setting.graphics.ssao.set", update_ssao_quality)
|
events.on("core:setting.graphics.ssao.set", update_ssao_quality)
|
||||||
|
|
||||||
update_ssao_quality(__app.get_setting("graphics.ssao"))
|
update_ssao_quality(app.get_setting("graphics.ssao"))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function __vc_on_hud_open()
|
local function __vc_on_hud_open()
|
||||||
|
|
@ -165,7 +166,8 @@ file.__close_all_descriptors = nil
|
||||||
gui_util.__reset_local = nil
|
gui_util.__reset_local = nil
|
||||||
stdcomp.reset = nil
|
stdcomp.reset = nil
|
||||||
|
|
||||||
local function __vc_on_world_quit()
|
function internals.on_world_quit()
|
||||||
|
internals.stop_all_actions()
|
||||||
__rules.clear()
|
__rules.clear()
|
||||||
__gui_util_reset_local()
|
__gui_util_reset_local()
|
||||||
__stdcomp_reset()
|
__stdcomp_reset()
|
||||||
|
|
@ -215,13 +217,16 @@ function time.post_runnable(runnable)
|
||||||
table.insert(__post_runnables, runnable)
|
table.insert(__post_runnables, runnable)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function internals.on_render()
|
||||||
|
internals.on_animation_frame()
|
||||||
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
__vc_on_hud_open = __vc_on_hud_open,
|
__vc_on_hud_open = __vc_on_hud_open,
|
||||||
__vc_on_world_open = __vc_on_world_open,
|
__vc_on_world_open = __vc_on_world_open,
|
||||||
__vc_on_world_tick = __vc_on_world_tick,
|
__vc_on_world_tick = __vc_on_world_tick,
|
||||||
__vc_process_before_quit = __vc_process_before_quit,
|
__vc_process_before_quit = __vc_process_before_quit,
|
||||||
__vc_on_world_save = __vc_on_world_save,
|
__vc_on_world_save = __vc_on_world_save,
|
||||||
__vc_on_world_quit = __vc_on_world_quit,
|
|
||||||
__vc__process_post_runnables = __vc__process_post_runnables,
|
__vc__process_post_runnables = __vc__process_post_runnables,
|
||||||
__vc_is_post_runnable_context = function()
|
__vc_is_post_runnable_context = function()
|
||||||
return __vc__is_post_runnable
|
return __vc__is_post_runnable
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ static void create_libs(State* L, StateType stateType) {
|
||||||
createtable(L, 0, 0);
|
createtable(L, 0, 0);
|
||||||
pushvalue(L, -1);
|
pushvalue(L, -1);
|
||||||
setglobal(L, "__vc_internals");
|
setglobal(L, "__vc_internals");
|
||||||
setregistry(L, "internals");
|
setregistry(L, lua::INTERNALS_TABLE);
|
||||||
|
|
||||||
if (stateType == StateType::SCRIPT) {
|
if (stateType == StateType::SCRIPT) {
|
||||||
getregistry(L, "app");
|
getregistry(L, "app");
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ namespace lua {
|
||||||
inline std::string CHUNKS_TABLE = "$C"; // precompiled lua chunks
|
inline std::string CHUNKS_TABLE = "$C"; // precompiled lua chunks
|
||||||
inline std::string PACK_ENVS_TABLE = "$P";
|
inline std::string PACK_ENVS_TABLE = "$P";
|
||||||
inline std::string ENVS_TABLE = "$E";
|
inline std::string ENVS_TABLE = "$E";
|
||||||
|
inline std::string INTERNALS_TABLE = "$I";
|
||||||
extern std::unordered_map<std::type_index, std::string> usertypeNames;
|
extern std::unordered_map<std::type_index, std::string> usertypeNames;
|
||||||
int userdata_destructor(lua::State* L);
|
int userdata_destructor(lua::State* L);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -291,7 +291,7 @@ void scripting::on_content_load(Content* content) {
|
||||||
|
|
||||||
lua::getregistry(L, "app");
|
lua::getregistry(L, "app");
|
||||||
lua::setglobal(L, "__vc_app");
|
lua::setglobal(L, "__vc_app");
|
||||||
lua::getregistry(L, "internals");
|
lua::getregistry(L, lua::INTERNALS_TABLE);
|
||||||
lua::setglobal(L, "__vc_internals");
|
lua::setglobal(L, "__vc_internals");
|
||||||
try {
|
try {
|
||||||
load_script("post_content.lua", true);
|
load_script("post_content.lua", true);
|
||||||
|
|
@ -367,7 +367,7 @@ void scripting::on_world_quit() {
|
||||||
for (auto& pack : content_control->getAllContentPacks()) {
|
for (auto& pack : content_control->getAllContentPacks()) {
|
||||||
lua::emit_event(L, pack.id + ":.worldquit");
|
lua::emit_event(L, pack.id + ":.worldquit");
|
||||||
}
|
}
|
||||||
if (lua::getglobal(L, "__vc_on_world_quit")) {
|
if (lua::get_from_registry(L, lua::INTERNALS_TABLE, "on_world_quit", true)) {
|
||||||
lua::call_nothrow(L, 0, 0);
|
lua::call_nothrow(L, 0, 0);
|
||||||
}
|
}
|
||||||
scripting::level = nullptr;
|
scripting::level = nullptr;
|
||||||
|
|
@ -849,7 +849,7 @@ void scripting::load_vca_animation(
|
||||||
const std::string& identifier
|
const std::string& identifier
|
||||||
) {
|
) {
|
||||||
auto L = lua::get_main_state();
|
auto L = lua::get_main_state();
|
||||||
if (lua::get_from_registry(L, "internals", "load_vca_animation", true)) {
|
if (lua::get_from_registry(L, lua::INTERNALS_TABLE, "load_vca_animation", true)) {
|
||||||
lua::pushlstring(L, file.string());
|
lua::pushlstring(L, file.string());
|
||||||
lua::pushlstring(L, identifier);
|
lua::pushlstring(L, identifier);
|
||||||
if (lua::call(L, 2, 0)) {
|
if (lua::call(L, 2, 0)) {
|
||||||
|
|
|
||||||
|
|
@ -63,12 +63,15 @@ void scripting::on_frontend_init(
|
||||||
}
|
}
|
||||||
|
|
||||||
void scripting::on_frontend_render() {
|
void scripting::on_frontend_render() {
|
||||||
|
auto L = lua::get_main_state();
|
||||||
|
|
||||||
|
if (lua::get_from_registry(L, lua::INTERNALS_TABLE, "on_render", true)) {
|
||||||
|
lua::call_nothrow(L, 0, 0);
|
||||||
|
}
|
||||||
for (auto& pack : content_control->getAllContentPacks()) {
|
for (auto& pack : content_control->getAllContentPacks()) {
|
||||||
lua::emit_event(
|
lua::emit_event(L, pack.id + ":.hudrender", [](lua::State* L) {
|
||||||
lua::get_main_state(),
|
return 0;
|
||||||
pack.id + ":.hudrender",
|
});
|
||||||
[](lua::State* L) { return 0; }
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue