mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-08 12:31:51 +00:00
Merge branch 'MihailRis:main' into main
This commit is contained in:
commit
9a942cf634
32 changed files with 298 additions and 139 deletions
|
|
@ -47,9 +47,10 @@ void AssetsLoader::add(
|
|||
AssetType tag,
|
||||
const std::string& filename,
|
||||
const std::string& alias,
|
||||
std::shared_ptr<AssetCfg> settings
|
||||
std::shared_ptr<AssetCfg> settings,
|
||||
bool overwrite
|
||||
) {
|
||||
if (enqueued.find({tag, alias}) != enqueued.end()){
|
||||
if (!overwrite && enqueued.find({tag, alias}) != enqueued.end()){
|
||||
return;
|
||||
}
|
||||
entries.push(aloader_entry {tag, filename, alias, std::move(settings)});
|
||||
|
|
@ -154,11 +155,12 @@ void AssetsLoader::processPreload(
|
|||
std::string defFolder = assets_def_folder(tag);
|
||||
std::string path = defFolder + "/" + name;
|
||||
if (map == nullptr) {
|
||||
add(tag, path, name);
|
||||
add(tag, path, name, nullptr, true);
|
||||
return;
|
||||
}
|
||||
std::shared_ptr<AssetCfg> config = nullptr;
|
||||
map.at("path").get(path);
|
||||
logger.debug() << "processing preload " << util::quote(name) << " path: " << util::quote(path);
|
||||
switch (tag) {
|
||||
case AssetType::SOUND: {
|
||||
bool keepPCM = false;
|
||||
|
|
@ -196,7 +198,7 @@ void AssetsLoader::processPreload(
|
|||
default:
|
||||
break;
|
||||
}
|
||||
add(tag, path, name, std::move(config));
|
||||
add(tag, path, name, std::move(config), true);
|
||||
}
|
||||
|
||||
void AssetsLoader::processPreloadList(AssetType tag, const dv::value& list) {
|
||||
|
|
|
|||
|
|
@ -110,7 +110,8 @@ public:
|
|||
AssetType tag,
|
||||
const std::string& filename,
|
||||
const std::string& alias,
|
||||
std::shared_ptr<AssetCfg> settings = nullptr
|
||||
std::shared_ptr<AssetCfg> settings = nullptr,
|
||||
bool overwrite = false
|
||||
);
|
||||
|
||||
bool hasNext() const;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "debug/Logger.hpp"
|
||||
#include "alutil.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
#include "../MemoryPCMStream.hpp"
|
||||
|
||||
static debug::Logger logger("al-audio");
|
||||
|
|
@ -99,6 +100,8 @@ ALInputDevice::ALInputDevice(
|
|||
|
||||
if (deviceName) {
|
||||
deviceSpecifier = std::string(deviceName);
|
||||
logger.info() << "created input device with specifier "
|
||||
<< util::quote(deviceSpecifier);
|
||||
} else {
|
||||
logger.warning() << "could not retrieve input device specifier";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -211,12 +211,15 @@ void audio::initialize(
|
|||
return;
|
||||
}
|
||||
if (enabled) {
|
||||
logger.info() << "recording enabled; input device is "
|
||||
<< settings.inputDevice.get();
|
||||
const auto& targetDevice = settings.inputDevice.get();
|
||||
logger.info() << "recording enabled; target input device is "
|
||||
<< (targetDevice.empty() ? "not specified"
|
||||
: targetDevice);
|
||||
::input_device = backend->openInputDevice(
|
||||
settings.inputDevice.get(), 44100, 1, 16
|
||||
);
|
||||
if (::input_device != nullptr) {
|
||||
logger.error() << "could not create input device";
|
||||
::input_device->startCapture();
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -208,6 +208,14 @@ namespace {
|
|||
class Parser : BasicParser<char> {
|
||||
std::unique_ptr<Document> document;
|
||||
|
||||
void processEscapes(std::string& text) {
|
||||
util::replaceAll(text, """, "\"");
|
||||
util::replaceAll(text, "'", "'");
|
||||
util::replaceAll(text, "<", "<");
|
||||
util::replaceAll(text, ">", ">");
|
||||
util::replaceAll(text, "&", "&");
|
||||
}
|
||||
|
||||
std::unique_ptr<Node> parseOpenTag() {
|
||||
std::string tag = parseXMLName();
|
||||
auto node = std::make_unique<Node>(tag);
|
||||
|
|
@ -230,6 +238,7 @@ class Parser : BasicParser<char> {
|
|||
}
|
||||
skip(1);
|
||||
attrtext = parseString(quote);
|
||||
processEscapes(attrtext);
|
||||
}
|
||||
node->set(attrname, attrtext);
|
||||
}
|
||||
|
|
@ -241,11 +250,7 @@ class Parser : BasicParser<char> {
|
|||
if (peek() != '<') {
|
||||
auto element = std::make_unique<Node>("#");
|
||||
auto text = parseText();
|
||||
util::replaceAll(text, """, "\"");
|
||||
util::replaceAll(text, "'", "'");
|
||||
util::replaceAll(text, "<", "<");
|
||||
util::replaceAll(text, ">", ">");
|
||||
util::replaceAll(text, "&", "&");
|
||||
processEscapes(text);
|
||||
element->set("#", text);
|
||||
return element;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ void Texture::resize(uint width, uint height) {
|
|||
}
|
||||
|
||||
void Texture::reload(const ImageData& image) {
|
||||
reload(image.getData(), width, height);
|
||||
reload(image.getData(), image.getWidth(), image.getHeight());
|
||||
}
|
||||
|
||||
void Texture::reload(const ubyte* data, uint width, uint height) {
|
||||
|
|
|
|||
|
|
@ -78,9 +78,10 @@ void Panel::refresh() {
|
|||
glm::vec2 size = getSize();
|
||||
if (orientation == Orientation::VERTICAL) {
|
||||
float maxw = size.x;
|
||||
for (auto& node : nodes) {
|
||||
for (size_t i = 0; i < nodes.size(); i++) {
|
||||
const auto& node = nodes[i];
|
||||
const glm::vec4 margin = node->getMargin();
|
||||
y += margin.y;
|
||||
y += margin.y + (i > 0 ? interval : 0);
|
||||
|
||||
float ex = x + margin.x;
|
||||
node->setPos(glm::vec2(ex, y));
|
||||
|
|
@ -94,16 +95,17 @@ void Panel::refresh() {
|
|||
}
|
||||
node->refresh();
|
||||
glm::vec2 nodeSize = node->getSize();
|
||||
y += nodeSize.y + margin.w + interval;
|
||||
y += nodeSize.y + margin.w;
|
||||
maxw = fmax(maxw, ex + nodeSize.x + margin.z + padding.z);
|
||||
}
|
||||
actualLengthX = size.x;
|
||||
actualLengthY = y + padding.w;
|
||||
} else {
|
||||
float maxh = size.y;
|
||||
for (auto& node : nodes) {
|
||||
for (size_t i = 0; i < nodes.size(); i++) {
|
||||
const auto& node = nodes[i];
|
||||
const glm::vec4 margin = node->getMargin();
|
||||
x += margin.x;
|
||||
x += margin.x + (i > 0 ? interval : 0);
|
||||
|
||||
float ey = y + margin.y;
|
||||
node->setPos(glm::vec2(x, ey));
|
||||
|
|
@ -117,7 +119,7 @@ void Panel::refresh() {
|
|||
}
|
||||
node->refresh();
|
||||
glm::vec2 nodesize = node->getSize();
|
||||
x += nodesize.x + margin.z + interval;
|
||||
x += nodesize.x + margin.z;
|
||||
maxh = fmax(maxh, ey + nodesize.y + margin.w + padding.w);
|
||||
}
|
||||
actualLengthY = size.y;
|
||||
|
|
|
|||
|
|
@ -199,6 +199,20 @@ static int l_get_ground_vel(lua::State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int l_is_selectable(lua::State* L) {
|
||||
if (auto entity = get_entity(L, 1)) {
|
||||
return lua::pushboolean(L, entity->getRigidbody().hitbox.selectable);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_set_selectable(lua::State* L) {
|
||||
if (auto entity = get_entity(L, 1)) {
|
||||
entity->getRigidbody().selectable = lua::toboolean(L, 2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
const luaL_Reg rigidbodylib[] = {
|
||||
{"is_enabled", lua::wrap<l_is_enabled>},
|
||||
|
|
@ -226,5 +240,7 @@ const luaL_Reg rigidbodylib[] = {
|
|||
{"get_elasticity", lua::wrap<l_get_elasticity>},
|
||||
{"set_elasticity", lua::wrap<l_set_elasticity>},
|
||||
{"get_ground_vel", lua::wrap<l_get_ground_vel>},
|
||||
{"is_selectable", lua::wrap<l_is_selectable>},
|
||||
{"set_selectable", lua::wrap<l_set_selectable>},
|
||||
{nullptr, nullptr}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -92,6 +92,17 @@ static int l_reconfig_packs(lua::State* L) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/// @brief Get current content packs configuration
|
||||
static int l_get_content(lua::State* L) {
|
||||
const auto& configuration = content_control->getContentPacks();
|
||||
lua::createtable(L, configuration.size(), 0);
|
||||
for (int i = 0; i < configuration.size(); i++) {
|
||||
lua::pushlstring(L, configuration[i].id);
|
||||
lua::rawseti(L, i + 1);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/// @brief Get content sources list
|
||||
static int l_get_content_sources(lua::State* L) {
|
||||
const auto& sources = engine->getContentControl().getContentSources();
|
||||
|
|
@ -453,6 +464,7 @@ const luaL_Reg applib[] = {
|
|||
{"load_content", lua::wrap<l_load_content>},
|
||||
{"reset_content", lua::wrap<l_reset_content>},
|
||||
{"reconfig_packs", lua::wrap<l_reconfig_packs>},
|
||||
{"get_content", lua::wrap<l_get_content>},
|
||||
{"get_content_sources", lua::wrap<l_get_content_sources>},
|
||||
{"set_content_sources", lua::wrap<l_set_content_sources>},
|
||||
{"reset_content_sources", lua::wrap<l_reset_content_sources>},
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "engine/Engine.hpp"
|
||||
#include "api_lua.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
using namespace scripting;
|
||||
|
|
@ -20,11 +21,18 @@ static int l_utc_time(lua::State* L) {
|
|||
return lua::pushnumber(L, std::time(nullptr));
|
||||
}
|
||||
|
||||
static int l_precise_utc_time(lua::State* L) {
|
||||
auto now = std::chrono::system_clock::now();
|
||||
return lua::pushnumber(
|
||||
L, std::chrono::duration<double>(now.time_since_epoch()).count()
|
||||
);
|
||||
}
|
||||
|
||||
static int l_local_time(lua::State* L) {
|
||||
std::time_t t = std::time(nullptr);
|
||||
|
||||
std::tm gmt_tm{};
|
||||
std::tm local_tm{};
|
||||
std::tm gmt_tm {};
|
||||
std::tm local_tm {};
|
||||
|
||||
#if defined(USE_MSVC_TIME_SAFE)
|
||||
gmtime_s(&gmt_tm, &t);
|
||||
|
|
@ -44,8 +52,8 @@ static int l_local_time(lua::State* L) {
|
|||
static int l_utc_offset(lua::State* L) {
|
||||
std::time_t t = std::time(nullptr);
|
||||
|
||||
std::tm gmt_tm{};
|
||||
std::tm local_tm{};
|
||||
std::tm gmt_tm {};
|
||||
std::tm local_tm {};
|
||||
|
||||
#if defined(USE_MSVC_TIME_SAFE)
|
||||
gmtime_s(&gmt_tm, &t);
|
||||
|
|
@ -74,6 +82,7 @@ const luaL_Reg timelib[] = {
|
|||
{"uptime", lua::wrap<l_uptime>},
|
||||
{"delta", lua::wrap<l_delta>},
|
||||
{"utc_time", lua::wrap<l_utc_time>},
|
||||
{"precise_utc_time", lua::wrap<l_precise_utc_time>},
|
||||
{"utc_offset", lua::wrap<l_utc_offset>},
|
||||
{"local_time", lua::wrap<l_local_time>},
|
||||
{"precise_time", lua::wrap<l_precise_time>},
|
||||
|
|
|
|||
|
|
@ -74,6 +74,11 @@ static void create_libs(State* L, StateType stateType) {
|
|||
getglobal(L, "__vc_app");
|
||||
setregistry(L, "app");
|
||||
|
||||
createtable(L, 0, 0);
|
||||
pushvalue(L, -1);
|
||||
setglobal(L, "__vc_internals");
|
||||
setregistry(L, "internals");
|
||||
|
||||
if (stateType == StateType::SCRIPT) {
|
||||
getregistry(L, "app");
|
||||
setglobal(L, "app");
|
||||
|
|
|
|||
|
|
@ -288,7 +288,23 @@ void scripting::on_content_load(Content* content) {
|
|||
lua::setfield(L, "properties");
|
||||
lua::pop(L);
|
||||
}
|
||||
load_script("post_content.lua", true);
|
||||
|
||||
lua::getregistry(L, "app");
|
||||
lua::setglobal(L, "__vc_app");
|
||||
lua::getregistry(L, "internals");
|
||||
lua::setglobal(L, "__vc_internals");
|
||||
try {
|
||||
load_script("post_content.lua", true);
|
||||
} catch (const std::exception&) {
|
||||
lua::pushnil(L);
|
||||
lua::setglobal(L, "__vc_app");
|
||||
throw;
|
||||
}
|
||||
lua::pushnil(L);
|
||||
lua::setglobal(L, "__vc_app");
|
||||
lua::pushnil(L);
|
||||
lua::setglobal(L, "__vc_internals");
|
||||
|
||||
load_script("stdcmd.lua", true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -175,9 +175,10 @@ std::optional<Entities::RaycastResult> Entities::rayCast(
|
|||
glm::ivec3 foundNormal;
|
||||
|
||||
for (auto [entity, eid, transform, body] : view.each()) {
|
||||
const auto& hitbox = body.hitbox;
|
||||
if (eid.uid == settings.ignoredUid || !body.enabled ||
|
||||
(settings.solidEntitiesOnly && !eid.def.solid) ||
|
||||
(!eid.def.selectable && !settings.includeNonSelectable)) {
|
||||
(!hitbox.selectable && !settings.includeNonSelectable)) {
|
||||
continue;
|
||||
}
|
||||
if (settings.entitiesFilter) {
|
||||
|
|
@ -187,7 +188,6 @@ std::optional<Entities::RaycastResult> Entities::rayCast(
|
|||
continue;
|
||||
}
|
||||
}
|
||||
const auto& hitbox = body.hitbox;
|
||||
glm::ivec3 normal;
|
||||
double distance;
|
||||
if (ray.intersectAABB(
|
||||
|
|
@ -330,6 +330,7 @@ void Entities::preparePhysics(float delta) {
|
|||
? rigidbody.mass
|
||||
: std::numeric_limits<float>::infinity();
|
||||
rigidbody.hitbox.elasticity = rigidbody.elasticity;
|
||||
rigidbody.hitbox.selectable = rigidbody.selectable;
|
||||
hitboxes.emplace_back(&rigidbody.hitbox);
|
||||
if (!eid.def.solid) {
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ dv::value Rigidbody::serialize(bool saveVelocity, bool saveBodySettings) const {
|
|||
}
|
||||
bodymap["mass"] = mass;
|
||||
bodymap["elasticity"] = elasticity;
|
||||
bodymap["selectable"] = selectable;
|
||||
}
|
||||
return bodymap;
|
||||
}
|
||||
|
|
@ -37,6 +38,7 @@ void Rigidbody::deserialize(const dv::value& root) {
|
|||
root["damping"].asNumber(hitbox.linearDamping);
|
||||
root["mass"].asNumber(mass);
|
||||
root["elasticity"].asNumber(elasticity);
|
||||
root["selectable"].asBoolean(selectable);
|
||||
}
|
||||
|
||||
template <void (*callback)(const Entity&, size_t, entityid_t)>
|
||||
|
|
@ -55,6 +57,7 @@ void Rigidbody::initialize(
|
|||
) {
|
||||
mass = def.mass;
|
||||
elasticity = def.elasticity;
|
||||
selectable = def.selectable;
|
||||
sensors.resize(def.radialSensors.size() + def.boxSensors.size());
|
||||
for (auto& [i, box] : def.boxSensors) {
|
||||
SensorParams params {};
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ struct Rigidbody {
|
|||
std::vector<Sensor> sensors;
|
||||
float mass;
|
||||
float elasticity;
|
||||
bool selectable;
|
||||
|
||||
dv::value serialize(bool saveVelocity, bool saveBodySettings) const;
|
||||
void deserialize(const dv::value& root);
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ struct Hitbox {
|
|||
float stepHeight = 0.5f;
|
||||
float mass = 1.0f;
|
||||
float elasticity = 0.0f;
|
||||
bool selectable = true;
|
||||
std::string material;
|
||||
std::string groundMaterial;
|
||||
glm::vec3 groundVelocity {};
|
||||
|
|
|
|||
|
|
@ -122,7 +122,7 @@ static void calc_collision(
|
|||
|
||||
auto aabb = AABB(pos - half, pos + half);
|
||||
glm::vec3 scale(1.0f);
|
||||
scale[nz] = 1.0f - E * 8.0f;
|
||||
scale[nz] = 1.0f - E * 2.0f;
|
||||
aabb.scale(scale);
|
||||
aabb = aabb + offset;
|
||||
aabb.b.y -= stepHeight + E * 2;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ struct AudioSettings {
|
|||
NumberSetting volumeAmbient {1.0f, 0.0f, 1.0f, setting_format::percent};
|
||||
NumberSetting volumeMusic {1.0f, 0.0f, 1.0f, setting_format::percent};
|
||||
|
||||
StringSetting inputDevice {"auto"};
|
||||
StringSetting inputDevice {""};
|
||||
|
||||
FlagSetting acousticEffects {true};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ void WorldConverter::createBlockFieldsConvertTasks() {
|
|||
REGION_LAYER_BLOCKS_DATA,
|
||||
ConvertTaskType::CONVERT_BLOCKS_DATA
|
||||
);
|
||||
break;
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -189,7 +189,7 @@ void WorldConverter::upgradeRegion(
|
|||
}
|
||||
|
||||
void WorldConverter::convertVoxels(const io::path& file, int x, int z) const {
|
||||
logger.info() << "converting voxels region " << x << "_" << z;
|
||||
logger.info() << "converting voxels in region " << x << "_" << z;
|
||||
wfile->getRegions().processRegion(x, z, REGION_LAYER_VOXELS,
|
||||
[=](std::unique_ptr<ubyte[]> data, uint32_t*) {
|
||||
Chunk::convert(data.get(), report.get());
|
||||
|
|
@ -198,7 +198,7 @@ void WorldConverter::convertVoxels(const io::path& file, int x, int z) const {
|
|||
}
|
||||
|
||||
void WorldConverter::convertInventories(const io::path& file, int x, int z) const {
|
||||
logger.info() << "converting inventories region " << x << "_" << z;
|
||||
logger.info() << "converting inventories in region " << x << "_" << z;
|
||||
wfile->getRegions().processInventories(x, z, [=](Inventory* inventory) {
|
||||
inventory->convert(report.get());
|
||||
});
|
||||
|
|
@ -212,7 +212,7 @@ void WorldConverter::convertPlayer(const io::path& file) const {
|
|||
}
|
||||
|
||||
void WorldConverter::convertBlocksData(int x, int z, const ContentReport& report) const {
|
||||
logger.info() << "converting blocks data";
|
||||
logger.info() << "converting blocks data in region " << x << "_" << z;
|
||||
wfile->getRegions().processBlocksData(x, z,
|
||||
[=](BlocksMetadata* heap, std::unique_ptr<ubyte[]> voxelsData) {
|
||||
Chunk chunk(0, 0);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue