mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-06 19:41:51 +00:00
add direct-scripting-data-access setting
This commit is contained in:
parent
dc9ae6e99e
commit
24a2c35f41
5 changed files with 31 additions and 25 deletions
|
|
@ -5,8 +5,6 @@
|
|||
#include <limits>
|
||||
#include <string>
|
||||
|
||||
#define VC_LUA_DIRECT_BYTEARRAY_ACCESS
|
||||
|
||||
inline constexpr int ENGINE_VERSION_MAJOR = 0;
|
||||
inline constexpr int ENGINE_VERSION_MINOR = 32;
|
||||
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ SettingsHandler::SettingsHandler(EngineSettings& settings) {
|
|||
builder.addSection("system");
|
||||
builder.add("max-bg-asset-loaders", &settings.system.maxBgAssetLoaders);
|
||||
builder.add("preserve-assets-during-frame", &settings.system.preserveAssetsDuringFrame);
|
||||
builder.add("direct-scripting-data-access", &settings.system.directScriptingDataAccess);
|
||||
}
|
||||
|
||||
dv::value SettingsHandler::getValue(const std::string& name) const {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "util/stringutil.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
|
||||
using namespace lua;
|
||||
|
||||
|
|
@ -369,3 +370,29 @@ void lua::remove_environment(State* L, int id) {
|
|||
pushnil(L);
|
||||
store_env(L, id);
|
||||
}
|
||||
|
||||
std::string_view lua::bytearray_as_string(lua::State* L, int idx) {
|
||||
const auto& settings = scripting::engine->getSettings();
|
||||
if (type(L, idx) == LUA_TSTRING) {
|
||||
return tolstring(L, idx);
|
||||
}
|
||||
pushvalue(L, idx);
|
||||
|
||||
if (settings.system.directScriptingDataAccess.get()) {
|
||||
requireglobal(L, "Bytearray_as_ptr");
|
||||
pushvalue(L, -2);
|
||||
call(L, 1, 2);
|
||||
auto view = tolstring(L, -2);
|
||||
uint64_t size = touinteger(L, -1);
|
||||
auto ptr = (const char*)std::stoull(std::string(view), nullptr, 16);
|
||||
pop(L, 3);
|
||||
return std::string_view(ptr, size);
|
||||
} else {
|
||||
requireglobal(L, "Bytearray_as_string");
|
||||
pushvalue(L, -2);
|
||||
call(L, 1, 1);
|
||||
auto view = tolstring(L, -1);
|
||||
pop(L, 2);
|
||||
return view;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -828,27 +828,5 @@ namespace lua {
|
|||
return create_bytearray(L, bytes.data(), bytes.size());
|
||||
}
|
||||
|
||||
inline std::string_view bytearray_as_string(lua::State* L, int idx) {
|
||||
if (type(L, idx) == LUA_TSTRING) {
|
||||
return tolstring(L, idx);
|
||||
}
|
||||
pushvalue(L, idx);
|
||||
#ifdef VC_LUA_DIRECT_BYTEARRAY_ACCESS
|
||||
requireglobal(L, "Bytearray_as_ptr");
|
||||
pushvalue(L, -2);
|
||||
call(L, 1, 2);
|
||||
auto view = tolstring(L, -2);
|
||||
uint64_t size = touinteger(L, -1);
|
||||
auto ptr = (const char*)std::stoull(std::string(view), nullptr, 16);
|
||||
pop(L, 3);
|
||||
return std::string_view(ptr, size);
|
||||
#else
|
||||
requireglobal(L, "Bytearray_as_string");
|
||||
pushvalue(L, -2);
|
||||
call(L, 1, 1);
|
||||
auto view = tolstring(L, -1);
|
||||
pop(L, 2);
|
||||
return view;
|
||||
#endif // VC_LUA_DIRECT_BYTEARRAY_ACCESS
|
||||
}
|
||||
std::string_view bytearray_as_string(lua::State* L, int idx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -126,6 +126,8 @@ struct SystemSettings {
|
|||
IntegerSetting maxBgAssetLoaders {3, -4, 16};
|
||||
/// @brief Preserve assets during current frame from being destroyed
|
||||
FlagSetting preserveAssetsDuringFrame {true};
|
||||
/// @brief Allow luajit cdata objects direct data access optimizations
|
||||
FlagSetting directScriptingDataAccess {true};
|
||||
};
|
||||
|
||||
struct EngineSettings {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue