mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 10:31:50 +00:00
remove __vc_app global variable
This commit is contained in:
parent
678e5db03d
commit
ab179881e8
5 changed files with 63 additions and 64 deletions
|
|
@ -24,7 +24,7 @@ function gui_util.parse_query(query)
|
|||
end
|
||||
|
||||
--- @param query string page query string
|
||||
function gui_util.load_page(query)
|
||||
function gui_util.load_page(app, query)
|
||||
local name, args = gui_util.parse_query(query)
|
||||
for i = #gui_util.local_dispatchers, 1, -1 do
|
||||
local newname, newargs = gui_util.local_dispatchers[i](name, args)
|
||||
|
|
@ -34,7 +34,7 @@ function gui_util.load_page(query)
|
|||
local filename = file.find(string.format("layouts/pages/%s.xml", name))
|
||||
if filename then
|
||||
name = file.prefix(filename)..":pages/"..name
|
||||
gui.load_document(filename, name, args, { app = __vc_app })
|
||||
gui.load_document(filename, name, args, { app = app })
|
||||
return name
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,37 +1,3 @@
|
|||
local function configure_SSAO()
|
||||
-- Temporary using slot to configure built-in SSAO effect
|
||||
local slot = gfx.posteffects.index("core:ssao")
|
||||
gfx.posteffects.set_effect(slot, "ssao")
|
||||
|
||||
-- Generating random SSAO samples
|
||||
local buffer = Bytearray(0)
|
||||
for i = 0, 63 do
|
||||
local x = math.random() * 2.0 - 1.0
|
||||
local y = math.random() * 2.0 - 1.0
|
||||
local z = math.random() * 2.0
|
||||
local len = math.sqrt(x * x + y * y + z * z)
|
||||
if len > 0 then
|
||||
x = x / len
|
||||
y = y / len
|
||||
z = z / len
|
||||
end
|
||||
Bytearray.append(buffer, byteutil.pack("fff", x, y, z))
|
||||
end
|
||||
gfx.posteffects.set_array(slot, "u_ssaoSamples", Bytearray_as_string(buffer))
|
||||
|
||||
local function update_ssao_quality(value)
|
||||
value = math.min(value, 3)
|
||||
gfx.posteffects.set_params(slot, {
|
||||
u_kernelSize = value * 16,
|
||||
u_radius = 0.4 / value,
|
||||
u_bias = 0.006 / value / value,
|
||||
})
|
||||
end
|
||||
events.on("core:setting.graphics.ssao.set", update_ssao_quality)
|
||||
|
||||
update_ssao_quality(__vc_app.get_setting("graphics.ssao"))
|
||||
end
|
||||
|
||||
local function update_hand()
|
||||
local skeleton = gfx.skeletons
|
||||
local pid = hud.get_player()
|
||||
|
|
@ -123,8 +89,6 @@ function on_hud_open()
|
|||
end
|
||||
end)
|
||||
|
||||
configure_SSAO()
|
||||
|
||||
hud.default_hand_controller = update_hand
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
local enable_experimental = __vc_app.get_setting("debug.enable-experimental")
|
||||
local __app = __vc_app
|
||||
local enable_experimental = __app.get_setting("debug.enable-experimental")
|
||||
|
||||
------------------------------------------------
|
||||
------ Extended kit of standard functions ------
|
||||
|
|
@ -119,12 +120,7 @@ local function complete_app_lib(app)
|
|||
end
|
||||
end
|
||||
|
||||
if app then
|
||||
complete_app_lib(app)
|
||||
elseif __vc_app then
|
||||
complete_app_lib(__vc_app)
|
||||
end
|
||||
|
||||
complete_app_lib(__app)
|
||||
require "core:internal/maths_inline"
|
||||
require "core:internal/debugging"
|
||||
require "core:internal/audio_input"
|
||||
|
|
@ -175,18 +171,18 @@ function start_coroutine(chunk, name)
|
|||
local co = coroutine.create(function()
|
||||
local status, error = xpcall(chunk, function(err)
|
||||
local fullmsg = "error: "..string.match(err, ": (.+)").."\n"..debug.traceback()
|
||||
|
||||
if hud then
|
||||
gui.alert(fullmsg, function()
|
||||
if world.is_open() then
|
||||
__vc_app.close_world()
|
||||
else
|
||||
__vc_app.reset_content()
|
||||
menu:reset()
|
||||
menu.page = "main"
|
||||
end
|
||||
end)
|
||||
if vc.is_headless() then
|
||||
return fullmsg
|
||||
end
|
||||
gui.alert(fullmsg, function()
|
||||
if world.is_open() then
|
||||
__app.close_world()
|
||||
else
|
||||
__app.reset_content()
|
||||
menu:reset()
|
||||
menu.page = "main"
|
||||
end
|
||||
end)
|
||||
return fullmsg
|
||||
end)
|
||||
if not status then
|
||||
|
|
@ -204,7 +200,7 @@ function __vc_start_app_script(path, name)
|
|||
if chunk == nil then
|
||||
error(err)
|
||||
end
|
||||
local script_env = setmetatable({app = app or __vc_app}, {__index=_G})
|
||||
local script_env = setmetatable({app = __app}, {__index=_G})
|
||||
chunk = setfenv(chunk, script_env)
|
||||
if name then
|
||||
start_coroutine(chunk, name)
|
||||
|
|
@ -222,7 +218,7 @@ gui_util = require "core:internal/gui_util"
|
|||
Document = gui_util.Document
|
||||
Element = gui_util.Element
|
||||
RadioGroup = gui_util.RadioGroup
|
||||
__vc_page_loader = gui_util.load_page
|
||||
__vc_page_loader = function(...) return gui_util.load_page(__app, ...) end
|
||||
|
||||
function __vc_get_document_node(docname, nodeid)
|
||||
return Element.new(docname, nodeid)
|
||||
|
|
@ -384,6 +380,40 @@ math.randomseed(time.uptime() * 1536227939)
|
|||
rules = require "core:internal/rules"
|
||||
local _rules = rules
|
||||
|
||||
local function configure_SSAO()
|
||||
-- Temporary using slot to configure built-in SSAO effect
|
||||
local slot = gfx.posteffects.index("core:ssao")
|
||||
gfx.posteffects.set_effect(slot, "ssao")
|
||||
|
||||
-- Generating random SSAO samples
|
||||
local buffer = Bytearray(0)
|
||||
for i = 0, 63 do
|
||||
local x = math.random() * 2.0 - 1.0
|
||||
local y = math.random() * 2.0 - 1.0
|
||||
local z = math.random() * 2.0
|
||||
local len = math.sqrt(x * x + y * y + z * z)
|
||||
if len > 0 then
|
||||
x = x / len
|
||||
y = y / len
|
||||
z = z / len
|
||||
end
|
||||
Bytearray.append(buffer, byteutil.pack("fff", x, y, z))
|
||||
end
|
||||
gfx.posteffects.set_array(slot, "u_ssaoSamples", Bytearray_as_string(buffer))
|
||||
|
||||
local function update_ssao_quality(value)
|
||||
value = math.min(value, 3)
|
||||
gfx.posteffects.set_params(slot, {
|
||||
u_kernelSize = value * 16,
|
||||
u_radius = 0.4 / value,
|
||||
u_bias = 0.006 / value / value,
|
||||
})
|
||||
end
|
||||
events.on("core:setting.graphics.ssao.set", update_ssao_quality)
|
||||
|
||||
update_ssao_quality(__app.get_setting("graphics.ssao"))
|
||||
end
|
||||
|
||||
function __vc_on_hud_open()
|
||||
local _hud_is_content_access = hud._is_content_access
|
||||
local _hud_set_content_access = hud._set_content_access
|
||||
|
|
@ -446,6 +476,8 @@ function __vc_on_hud_open()
|
|||
end
|
||||
end)
|
||||
hud.open_permanent("core:ingame_chat")
|
||||
|
||||
configure_SSAO()
|
||||
end
|
||||
|
||||
local Schedule = require "core:schedule"
|
||||
|
|
@ -590,4 +622,5 @@ end
|
|||
require "core:internal/deprecated"
|
||||
|
||||
ffi = nil
|
||||
__vc_app = nil
|
||||
__vc_lock_internal_modules()
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ vc = {
|
|||
}
|
||||
|
||||
local _ffi = ffi
|
||||
local _debug_getinfo = debug.getinfo
|
||||
local _crc32 = crc32
|
||||
|
||||
function crc32(bytes, chksum)
|
||||
|
|
@ -116,6 +115,8 @@ end
|
|||
|
||||
----------------------------------------------
|
||||
|
||||
local _debug_getinfo = debug.getinfo
|
||||
|
||||
function debug.count_frames()
|
||||
local frames = 1
|
||||
while true do
|
||||
|
|
|
|||
|
|
@ -64,12 +64,13 @@ static void create_libs(State* L, StateType stateType) {
|
|||
openlib(L, "vec4", vec4lib);
|
||||
openlib(L, "yaml", yamllib);
|
||||
|
||||
openlib(L, "__vc_app", applib);
|
||||
lua::getglobal(L, "__vc_app");
|
||||
lua::setregistry(L, "app");
|
||||
|
||||
if (stateType == StateType::SCRIPT) {
|
||||
openlib(L, "app", applib);
|
||||
lua::getglobal(L, "app");
|
||||
lua::setglobal(L, "__vc_app");
|
||||
} else if (stateType == StateType::BASE) {
|
||||
openlib(L, "__vc_app", applib);
|
||||
lua::getregistry(L, "app");
|
||||
lua::setglobal(L, "app");
|
||||
}
|
||||
if (stateType == StateType::BASE || stateType == StateType::SCRIPT) {
|
||||
openlib(L, "assets", assetslib);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue