mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-13 23:11:49 +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
|
end
|
||||||
|
|
||||||
--- @param query string page query string
|
--- @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)
|
local name, args = gui_util.parse_query(query)
|
||||||
for i = #gui_util.local_dispatchers, 1, -1 do
|
for i = #gui_util.local_dispatchers, 1, -1 do
|
||||||
local newname, newargs = gui_util.local_dispatchers[i](name, args)
|
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))
|
local filename = file.find(string.format("layouts/pages/%s.xml", name))
|
||||||
if filename then
|
if filename then
|
||||||
name = file.prefix(filename)..":pages/"..name
|
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
|
return name
|
||||||
end
|
end
|
||||||
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 function update_hand()
|
||||||
local skeleton = gfx.skeletons
|
local skeleton = gfx.skeletons
|
||||||
local pid = hud.get_player()
|
local pid = hud.get_player()
|
||||||
|
|
@ -123,8 +89,6 @@ function on_hud_open()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
configure_SSAO()
|
|
||||||
|
|
||||||
hud.default_hand_controller = update_hand
|
hud.default_hand_controller = update_hand
|
||||||
end
|
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 ------
|
------ Extended kit of standard functions ------
|
||||||
|
|
@ -119,12 +120,7 @@ local function complete_app_lib(app)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if app then
|
complete_app_lib(__app)
|
||||||
complete_app_lib(app)
|
|
||||||
elseif __vc_app then
|
|
||||||
complete_app_lib(__vc_app)
|
|
||||||
end
|
|
||||||
|
|
||||||
require "core:internal/maths_inline"
|
require "core:internal/maths_inline"
|
||||||
require "core:internal/debugging"
|
require "core:internal/debugging"
|
||||||
require "core:internal/audio_input"
|
require "core:internal/audio_input"
|
||||||
|
|
@ -175,18 +171,18 @@ function start_coroutine(chunk, name)
|
||||||
local co = coroutine.create(function()
|
local co = coroutine.create(function()
|
||||||
local status, error = xpcall(chunk, function(err)
|
local status, error = xpcall(chunk, function(err)
|
||||||
local fullmsg = "error: "..string.match(err, ": (.+)").."\n"..debug.traceback()
|
local fullmsg = "error: "..string.match(err, ": (.+)").."\n"..debug.traceback()
|
||||||
|
if vc.is_headless() then
|
||||||
if hud then
|
return fullmsg
|
||||||
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)
|
|
||||||
end
|
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
|
return fullmsg
|
||||||
end)
|
end)
|
||||||
if not status then
|
if not status then
|
||||||
|
|
@ -204,7 +200,7 @@ function __vc_start_app_script(path, name)
|
||||||
if chunk == nil then
|
if chunk == nil then
|
||||||
error(err)
|
error(err)
|
||||||
end
|
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)
|
chunk = setfenv(chunk, script_env)
|
||||||
if name then
|
if name then
|
||||||
start_coroutine(chunk, name)
|
start_coroutine(chunk, name)
|
||||||
|
|
@ -222,7 +218,7 @@ gui_util = require "core:internal/gui_util"
|
||||||
Document = gui_util.Document
|
Document = gui_util.Document
|
||||||
Element = gui_util.Element
|
Element = gui_util.Element
|
||||||
RadioGroup = gui_util.RadioGroup
|
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)
|
function __vc_get_document_node(docname, nodeid)
|
||||||
return Element.new(docname, nodeid)
|
return Element.new(docname, nodeid)
|
||||||
|
|
@ -384,6 +380,40 @@ math.randomseed(time.uptime() * 1536227939)
|
||||||
rules = require "core:internal/rules"
|
rules = require "core:internal/rules"
|
||||||
local _rules = 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()
|
function __vc_on_hud_open()
|
||||||
local _hud_is_content_access = hud._is_content_access
|
local _hud_is_content_access = hud._is_content_access
|
||||||
local _hud_set_content_access = hud._set_content_access
|
local _hud_set_content_access = hud._set_content_access
|
||||||
|
|
@ -446,6 +476,8 @@ function __vc_on_hud_open()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
hud.open_permanent("core:ingame_chat")
|
hud.open_permanent("core:ingame_chat")
|
||||||
|
|
||||||
|
configure_SSAO()
|
||||||
end
|
end
|
||||||
|
|
||||||
local Schedule = require "core:schedule"
|
local Schedule = require "core:schedule"
|
||||||
|
|
@ -590,4 +622,5 @@ end
|
||||||
require "core:internal/deprecated"
|
require "core:internal/deprecated"
|
||||||
|
|
||||||
ffi = nil
|
ffi = nil
|
||||||
|
__vc_app = nil
|
||||||
__vc_lock_internal_modules()
|
__vc_lock_internal_modules()
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ vc = {
|
||||||
}
|
}
|
||||||
|
|
||||||
local _ffi = ffi
|
local _ffi = ffi
|
||||||
local _debug_getinfo = debug.getinfo
|
|
||||||
local _crc32 = crc32
|
local _crc32 = crc32
|
||||||
|
|
||||||
function crc32(bytes, chksum)
|
function crc32(bytes, chksum)
|
||||||
|
|
@ -116,6 +115,8 @@ end
|
||||||
|
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
|
||||||
|
local _debug_getinfo = debug.getinfo
|
||||||
|
|
||||||
function debug.count_frames()
|
function debug.count_frames()
|
||||||
local frames = 1
|
local frames = 1
|
||||||
while true do
|
while true do
|
||||||
|
|
|
||||||
|
|
@ -64,12 +64,13 @@ static void create_libs(State* L, StateType stateType) {
|
||||||
openlib(L, "vec4", vec4lib);
|
openlib(L, "vec4", vec4lib);
|
||||||
openlib(L, "yaml", yamllib);
|
openlib(L, "yaml", yamllib);
|
||||||
|
|
||||||
|
openlib(L, "__vc_app", applib);
|
||||||
|
lua::getglobal(L, "__vc_app");
|
||||||
|
lua::setregistry(L, "app");
|
||||||
|
|
||||||
if (stateType == StateType::SCRIPT) {
|
if (stateType == StateType::SCRIPT) {
|
||||||
openlib(L, "app", applib);
|
lua::getregistry(L, "app");
|
||||||
lua::getglobal(L, "app");
|
lua::setglobal(L, "app");
|
||||||
lua::setglobal(L, "__vc_app");
|
|
||||||
} else if (stateType == StateType::BASE) {
|
|
||||||
openlib(L, "__vc_app", applib);
|
|
||||||
}
|
}
|
||||||
if (stateType == StateType::BASE || stateType == StateType::SCRIPT) {
|
if (stateType == StateType::BASE || stateType == StateType::SCRIPT) {
|
||||||
openlib(L, "assets", assetslib);
|
openlib(L, "assets", assetslib);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue