Merge branch 'main' into update-gfx-pipeline
This commit is contained in:
commit
6927a87973
10
Dockerfile
10
Dockerfile
@ -11,6 +11,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||
g++ \
|
||||
make \
|
||||
cmake \
|
||||
pkg-config \
|
||||
xauth \
|
||||
gdb \
|
||||
gdbserver \
|
||||
@ -25,8 +26,17 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||
libvorbis-dev \
|
||||
libcurl4-openssl-dev \
|
||||
ca-certificates \
|
||||
wget \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Установка CMake >= 3.26 вручную
|
||||
ARG CMAKE_VERSION=3.27.9
|
||||
RUN wget https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-linux-x86_64.sh && \
|
||||
chmod +x cmake-${CMAKE_VERSION}-linux-x86_64.sh && \
|
||||
./cmake-${CMAKE_VERSION}-linux-x86_64.sh --skip-license --prefix=/usr/local && \
|
||||
rm cmake-${CMAKE_VERSION}-linux-x86_64.sh
|
||||
|
||||
|
||||
# Install EnTT
|
||||
RUN git clone https://github.com/skypjack/entt.git && \
|
||||
cd entt/build && \
|
||||
|
||||
46
README.md
46
README.md
@ -2,8 +2,8 @@
|
||||
|
||||
## Latest release
|
||||
|
||||
- [Download](https://github.com/MihailRis/VoxelEngine-Cpp/releases/latest) | [Скачать](https://github.com/MihailRis/VoxelEngine-Cpp/releases/latest)
|
||||
- [Documentation](https://github.com/MihailRis/VoxelEngine-Cpp/blob/release-0.27/doc/en/main-page.md) | [Документация](https://github.com/MihailRis/VoxelEngine-Cpp/blob/release-0.27/doc/ru/main-page.md)
|
||||
- [Download](https://github.com/MihailRis/VoxelCore/releases/latest) | [Скачать](https://github.com/MihailRis/VoxelCore/releases/latest)
|
||||
- [Documentation](https://github.com/MihailRis/VoxelCore/blob/release-0.27/doc/en/main-page.md) | [Документация](https://github.com/MihailRis/VoxelCore/blob/release-0.27/doc/ru/main-page.md)
|
||||
|
||||
## Build project in Linux
|
||||
|
||||
@ -71,8 +71,8 @@ yay -S entt
|
||||
### Building engine with CMake
|
||||
|
||||
```sh
|
||||
git clone --recursive https://github.com/MihailRis/VoxelEngine-Cpp.git
|
||||
cd VoxelEngine-Cpp
|
||||
git clone --recursive https://github.com/MihailRis/VoxelCore.git
|
||||
cd VoxelCore
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release ..
|
||||
@ -95,8 +95,8 @@ brew install glfw3 glew glm libpng libvorbis lua luajit libcurl openal-soft skyp
|
||||
### Building engine with CMake
|
||||
|
||||
```sh
|
||||
git clone --recursive https://github.com/MihailRis/VoxelEngine-Cpp.git
|
||||
cd VoxelEngine-Cpp
|
||||
git clone --recursive https://github.com/MihailRis/VoxelCore.git
|
||||
cd VoxelCore
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release ..
|
||||
@ -128,8 +128,8 @@ $env:PATH = "$env:VCPKG_ROOT;$env:PATH"
|
||||
|
||||
After installing **vcpkg** you can build project:
|
||||
```PowerShell
|
||||
git clone --recursive https://github.com/MihailRis/VoxelEngine-Cpp.git
|
||||
cd VoxelEngine-Cpp
|
||||
git clone --recursive https://github.com/MihailRis/VoxelCore.git
|
||||
cd VoxelCore
|
||||
cmake --preset default-vs-msvc-windows
|
||||
cmake --build --preset default-vs-msvc-windows
|
||||
```
|
||||
@ -140,6 +140,8 @@ cmake --build --preset default-vs-msvc-windows
|
||||
|
||||
See <https://docs.docker.com/engine/install>
|
||||
|
||||
### Do you have Linux
|
||||
|
||||
### Step 1. Build docker container
|
||||
|
||||
```sh
|
||||
@ -157,3 +159,31 @@ docker run --rm -it -v$(pwd):/project voxel-engine bash -c "cmake -DCMAKE_BUILD_
|
||||
```sh
|
||||
docker run --rm -it -v$(pwd):/project -v/tmp/.X11-unix:/tmp/.X11-unix -v${XAUTHORITY}:/home/user/.Xauthority:ro -eDISPLAY --network=host voxel-engine ./build/VoxelEngine
|
||||
```
|
||||
|
||||
### Do you have Windows
|
||||
|
||||
### Step 1. You need to install VcXsrv
|
||||
|
||||
### Step 2. Run VcXsrv with the command
|
||||
|
||||
```powershell
|
||||
.\vcxsrv.exe :0 -multiwindow -ac
|
||||
```
|
||||
|
||||
### Step 3. Build docker container
|
||||
|
||||
```powershell
|
||||
docker build -t voxel-engine .
|
||||
```
|
||||
|
||||
### Step 4. Build project using the docker container
|
||||
|
||||
```powershell
|
||||
docker run --rm -it -v "${PWD}:/project" voxel-engine bash -c "cmake -DCMAKE_BUILD_TYPE=Release -Bbuild && cmake --build build"
|
||||
```
|
||||
|
||||
### Step 5. Run project using the docker container
|
||||
|
||||
```powershell
|
||||
docker run --rm -it -v "${PWD}:/project" -e DISPLAY=host.docker.internal:0.0 --network host voxel-engine ./build/VoxelEngine
|
||||
```
|
||||
|
||||
3
res/devtools/syntax/vcm.toml
Normal file
3
res/devtools/syntax/vcm.toml
Normal file
@ -0,0 +1,3 @@
|
||||
language = "VCM"
|
||||
extensions = ["vcm"]
|
||||
line-comment-start = "#"
|
||||
@ -8,7 +8,8 @@
|
||||
</panel>
|
||||
</splitbox>
|
||||
<splitbox id="editorContainer" split-pos="0.8">
|
||||
<container color="#00000080"
|
||||
<splitbox id="codePanel" orientation="horizontal">
|
||||
<container color="#00000080" cursor="text"
|
||||
onclick="document.editor.focused = true document.editor.caret = -1">
|
||||
<container size-func="-1,30" color="#00000020">
|
||||
<image id="lockIcon" src="gui/lock" tooltip="@Read only"
|
||||
@ -47,8 +48,9 @@
|
||||
text-wrap='false'
|
||||
scroll-step='50'
|
||||
></textbox>
|
||||
<modelviewer size="480" model="stairs" center="0.5,0.5,0.5" cam-rotation="45,-45,0" gravity="top-right"/>
|
||||
</container>
|
||||
<modelviewer id="modelviewer" visible="false" center="0.5,0.5,0.5" cam-rotation="45,-45,0"/>
|
||||
</splitbox>
|
||||
<splitbox orientation="horizontal" split-pos="0.4">
|
||||
<panel id="traceback" padding="4" color="#000000A0">
|
||||
</panel>
|
||||
|
||||
@ -104,10 +104,29 @@ function unlock_access()
|
||||
)
|
||||
end
|
||||
|
||||
local function reload_model(filename, name)
|
||||
assets.parse_model("xml", document.editor.text, name)
|
||||
end
|
||||
|
||||
function run_current_file()
|
||||
if not current_file.filename then
|
||||
return
|
||||
end
|
||||
|
||||
local info = registry.get_info(current_file.filename)
|
||||
local script_type = info and info.type or "file"
|
||||
local unit = info and info.unit
|
||||
|
||||
if script_type == "model" then
|
||||
print(current_file.filename)
|
||||
clear_output()
|
||||
local _, err = pcall(reload_model, current_file.filename, unit)
|
||||
if err then
|
||||
document.output:paste(string.format("\n[#FF0000]%s[#FFFFFF]", err))
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local chunk, err = loadstring(document.editor.text, current_file.filename)
|
||||
clear_output()
|
||||
if not chunk then
|
||||
@ -119,9 +138,7 @@ function run_current_file()
|
||||
)
|
||||
return
|
||||
end
|
||||
local info = registry.get_info(current_file.filename)
|
||||
local script_type = info and info.type or "file"
|
||||
local unit = info and info.unit
|
||||
|
||||
save_current_file()
|
||||
|
||||
local func = function()
|
||||
@ -191,6 +208,7 @@ events.on("core:open_traceback", function(traceback_b64)
|
||||
tb_list.size = srcsize
|
||||
end)
|
||||
|
||||
--- Save the current file in the code editor if has writeable path.
|
||||
function save_current_file()
|
||||
if not current_file.mutable then
|
||||
return
|
||||
@ -202,7 +220,22 @@ function save_current_file()
|
||||
document.editor.edited = false
|
||||
end
|
||||
|
||||
--- Open a file in the code editor.
|
||||
--- @param filename string - the path to the file to open.
|
||||
--- @param line integer - the line number to focus on (optional).
|
||||
--- @param mutable string - writeable file path (optional).
|
||||
function open_file_in_editor(filename, line, mutable)
|
||||
debug.log("opening file " .. string.escape(filename) .. " in editor")
|
||||
|
||||
local ext = file.ext(filename)
|
||||
if ext == "xml" or ext == "vcm" then
|
||||
document.modelviewer.src = file.stem(filename)
|
||||
document.modelviewer.visible = true
|
||||
else
|
||||
document.modelviewer.visible = false
|
||||
end
|
||||
document.codePanel:refresh()
|
||||
|
||||
local editor = document.editor
|
||||
local source = file.read(filename):gsub('\t', ' ')
|
||||
editor.scroll = 0
|
||||
@ -225,7 +258,7 @@ end
|
||||
function on_open(mode)
|
||||
registry = require "core:internal/scripts_registry"
|
||||
|
||||
document.editorContainer:setInterval(200, refresh_file_title)
|
||||
document.codePanel:setInterval(200, refresh_file_title)
|
||||
|
||||
clear_traceback()
|
||||
clear_output()
|
||||
|
||||
@ -22,8 +22,7 @@
|
||||
markup="md"
|
||||
></textbox>
|
||||
</container>
|
||||
<iframe id="editorRoot" pos="0,30" size-func="-1,gui.get_viewport()[2]-30"
|
||||
src="core:code_editor">
|
||||
<iframe id="editorRoot" pos="0,30" size-func="-1,gui.get_viewport()[2]-30">
|
||||
</iframe>
|
||||
<textbox id='prompt'
|
||||
consumer='submit'
|
||||
|
||||
@ -104,8 +104,10 @@ function set_mode(mode)
|
||||
|
||||
if mode == 'debug' then
|
||||
document.root.color = {16, 18, 20, 220}
|
||||
document.editorRoot.src = "core:code_editor"
|
||||
else
|
||||
document.root.color = {0, 0, 0, 128}
|
||||
document.editorRoot.src = ""
|
||||
end
|
||||
|
||||
document.prompt.visible = show_prompt
|
||||
|
||||
4
res/models/stairs.vcm
Normal file
4
res/models/stairs.vcm
Normal file
@ -0,0 +1,4 @@
|
||||
@box from (0,0,0) to (1,0.5,1) delete (top,south)
|
||||
@box from (0,0.5,0) to (1,1,0.5) delete (bottom,south)
|
||||
@rect from (0,0.5,0.5) right (1,0,0) up (0,0,0.5) texture "$2"
|
||||
@rect from (0,0,0) right (1,0,0) up (0,1,0) texture "$1"
|
||||
@ -1,6 +0,0 @@
|
||||
<model>
|
||||
<box from="0,0,0" to="1,0.5,1" delete="top,south"/>
|
||||
<box from="0,0.5,0" to="1,1,0.5" delete="bottom,south"/>
|
||||
<rect from="0,0.5,0.5" right="1,0,0" up="0,0,0.5" texture="$2"/>
|
||||
<rect from="0,0,0" right="1,0,0" up="0,1,0" texture="$1"/>
|
||||
</model>
|
||||
@ -55,7 +55,7 @@ local function load_models_list(packs)
|
||||
local registry = export.registry
|
||||
for _, filename in ipairs(file.list("models")) do
|
||||
local ext = file.ext(filename)
|
||||
if ext == "xml" then
|
||||
if ext == "xml" or ext == "vcm" then
|
||||
registry[filename] = {type="model", unit=file.stem(filename)}
|
||||
table.insert(export.filenames, filename)
|
||||
end
|
||||
|
||||
@ -291,6 +291,19 @@ console.add_command(
|
||||
end
|
||||
)
|
||||
|
||||
console.add_command(
|
||||
"weather.list",
|
||||
"Show available weather presets list",
|
||||
function(args, kwargs)
|
||||
local filenames = file.list_all_res("presets/weather/")
|
||||
local presets = " "
|
||||
for index, filename in pairs(filenames) do
|
||||
presets = presets .. "\n" .. file.stem(filename)
|
||||
end
|
||||
return "available presets:" .. presets
|
||||
end
|
||||
)
|
||||
|
||||
console.cheats = {
|
||||
"blocks.fill",
|
||||
"tp",
|
||||
|
||||
@ -19,8 +19,17 @@ Problems=Праблемы
|
||||
Monitor=Маніторынг
|
||||
Debug=Адладка
|
||||
File=Файл
|
||||
Read only=Толькі для чытання
|
||||
Save=Захаваць
|
||||
Grant %{0} pack modification permission?=Выдаць дазвол на мадыфікацыю пака %{0}?
|
||||
Error at line %{0}=Памылка ў радку %{0}
|
||||
Run=Запусціць
|
||||
Filter=Фільтр
|
||||
|
||||
editor.info.tooltip=CTRL+S - Захаваць\nCTRL+R - Запусціць\nCTRL+Z - Скасаваць\nCTRL+Y - Паўтарыць
|
||||
devtools.traceback=Стэк выклікаў (ад апошняга)
|
||||
devtools.output=Вывод
|
||||
|
||||
error.pack-not-found=Не ўдалося знайсці пакет
|
||||
error.dependency-not-found=Выкарыстоўваная залежнасць не знойдзена
|
||||
pack.remove-confirm=Выдаліць увесь кантэнт, які пастаўляецца пакетам/пакетамі, са свету (беззваротна)?
|
||||
@ -43,7 +52,7 @@ menu.Display=Дысплей
|
||||
menu.Graphics=Графіка
|
||||
menu.missing-content=Адсутнічае Кантэнт!
|
||||
menu.New World=Новы Свет
|
||||
menu.Open worlds folder=Адкрыць папку з сусветамі
|
||||
menu.Open worlds folder=Адкрыць тэчку са сусветамі
|
||||
menu.Worlds=Сусветы
|
||||
menu.Page not found=Старонка не знойдзена
|
||||
menu.Quit=Выхад
|
||||
@ -51,8 +60,8 @@ menu.Save and Quit to Menu=Захаваць і Выйсці ў Меню
|
||||
menu.Settings=Налады
|
||||
menu.Reset settings=Скінуць налады
|
||||
menu.Contents Menu=Меню кантэнт-пакаў
|
||||
menu.Open data folder=Адкрыць папку з дадзенымі
|
||||
menu.Open content folder=Адкрыць папку [content]
|
||||
menu.Open data folder=Адкрыць тэчку з дадзенымі
|
||||
menu.Open content folder=Адкрыць тэчку [content]
|
||||
|
||||
world.Seed=Зерне
|
||||
world.Name=Назва
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include "assetload_funcs.hpp"
|
||||
|
||||
#include <array>
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
@ -352,8 +353,24 @@ assetload::postfunc assetload::model(
|
||||
throw;
|
||||
}
|
||||
}
|
||||
path = paths.find(file + ".xml");
|
||||
if (io::exists(path)) {
|
||||
|
||||
std::array<std::string, 2> extensions {
|
||||
".xml",
|
||||
".vcm"
|
||||
};
|
||||
|
||||
path = "";
|
||||
for (const auto& ext : extensions) {
|
||||
auto newPath = paths.find(file + ext);
|
||||
if (io::exists(newPath)) {
|
||||
path = std::move(newPath);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (path.empty()) {
|
||||
throw std::runtime_error("could not to find model " + util::quote(file));
|
||||
}
|
||||
|
||||
auto text = io::read_string(path);
|
||||
try {
|
||||
auto model = vcm::parse(path.string(), text).release();
|
||||
@ -366,8 +383,6 @@ assetload::postfunc assetload::model(
|
||||
throw;
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("could not to find model " + util::quote(file));
|
||||
}
|
||||
|
||||
static void read_anim_file(
|
||||
const std::string& animFile,
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include "xml.hpp"
|
||||
#include "util/stringutil.hpp"
|
||||
#include "graphics/commons/Model.hpp"
|
||||
#include "io/io.hpp"
|
||||
|
||||
using namespace vcm;
|
||||
using namespace xml;
|
||||
@ -143,12 +144,18 @@ static std::unique_ptr<model::Model> load_model(const xmlelement& root) {
|
||||
std::unique_ptr<model::Model> vcm::parse(
|
||||
std::string_view file, std::string_view src
|
||||
) {
|
||||
auto doc = xml::parse(file, src);
|
||||
try {
|
||||
auto doc = io::path(std::string(file)).extension() == ".xml"
|
||||
? xml::parse(file, src) : xml::parse_vcm(file, src, "model");
|
||||
const auto& root = *doc->getRoot();
|
||||
if (root.getTag() != "model") {
|
||||
throw std::runtime_error(
|
||||
"'model' tag expected as root, got '" + root.getTag() + "'"
|
||||
);
|
||||
}
|
||||
std::cout << xml::stringify(*doc) << std::endl;
|
||||
return load_model(root);
|
||||
} catch (const parsing_error& err) {
|
||||
throw std::runtime_error(err.errorLog());
|
||||
}
|
||||
}
|
||||
|
||||
@ -355,6 +355,83 @@ std::unique_ptr<Document> xml::parse(
|
||||
return parser.parse();
|
||||
}
|
||||
|
||||
namespace {
|
||||
class VcmParser : public BasicParser<char> {
|
||||
public:
|
||||
VcmParser(std::string_view filename, std::string_view source)
|
||||
: BasicParser(filename, source) {
|
||||
document = std::make_unique<Document>("1.0", "UTF-8");
|
||||
hashComment = true;
|
||||
}
|
||||
|
||||
std::string parseValue() {
|
||||
char c = peek();
|
||||
if (c == '"' || c == '\'') {
|
||||
nextChar();
|
||||
return parseString(c);
|
||||
}
|
||||
if (c == '(') {
|
||||
nextChar();
|
||||
// TODO: replace with array parsing after moving to dv::value's
|
||||
std::string value = std::string(readUntil(')'));
|
||||
expect(')');
|
||||
return value;
|
||||
}
|
||||
return std::string(readUntilWhitespace());
|
||||
}
|
||||
|
||||
void parseSubElements(Node& node) {
|
||||
skipWhitespace();
|
||||
while (hasNext()) {
|
||||
if (peek() != '@') {
|
||||
throw error("unexpected character in element");
|
||||
}
|
||||
nextChar();
|
||||
auto subnodePtr = std::make_unique<Node>(parseName());
|
||||
auto subnode = subnodePtr.get();
|
||||
node.add(std::move(subnodePtr));
|
||||
|
||||
skipWhitespace();
|
||||
while (hasNext() && peek() != '@' && peek() != '{' && peek() != '}') {
|
||||
std::string attrname = parseName();
|
||||
skipWhitespace();
|
||||
std::string value = parseValue();
|
||||
subnode->set(attrname, value);
|
||||
skipWhitespace();
|
||||
}
|
||||
if (!hasNext()) {
|
||||
break;
|
||||
}
|
||||
char c = peek();
|
||||
if (c == '{') {
|
||||
nextChar();
|
||||
parseSubElements(*subnode);
|
||||
expect('}');
|
||||
skipWhitespace();
|
||||
} else if (c == '}') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<Document> parse(const std::string& rootTag) {
|
||||
auto root = std::make_unique<Node>(rootTag);
|
||||
parseSubElements(*root);
|
||||
document->setRoot(std::move(root));
|
||||
return std::move(document);
|
||||
}
|
||||
private:
|
||||
std::unique_ptr<Document> document;
|
||||
};
|
||||
}
|
||||
|
||||
std::unique_ptr<Document> xml::parse_vcm(
|
||||
std::string_view filename, std::string_view source, std::string_view tag
|
||||
) {
|
||||
VcmParser parser(filename, source);
|
||||
return parser.parse(std::string(tag));
|
||||
}
|
||||
|
||||
inline void newline(
|
||||
std::stringstream& ss, bool nice, const std::string& indentStr, int indent
|
||||
) {
|
||||
|
||||
@ -126,5 +126,9 @@ namespace xml {
|
||||
std::string_view filename, std::string_view source
|
||||
);
|
||||
|
||||
std::unique_ptr<Document> parse_vcm(
|
||||
std::string_view filename, std::string_view source, std::string_view tag
|
||||
);
|
||||
|
||||
using xmlelement = Node;
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
#include <array>
|
||||
#include <glm/ext.hpp>
|
||||
#include "ModelViewer.hpp"
|
||||
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
#include "SplitBox.hpp"
|
||||
|
||||
#include "util/stack_vector.hpp"
|
||||
|
||||
using namespace gui;
|
||||
|
||||
SplitBox::SplitBox(GUI& gui, const glm::vec2& size, float splitPos, Orientation orientation)
|
||||
@ -28,18 +30,31 @@ void SplitBox::mouseMove(int x, int y) {
|
||||
void SplitBox::refresh() {
|
||||
Container::refresh();
|
||||
|
||||
if (nodes.empty()) {
|
||||
util::stack_vector<UINode*, 2> visibleNodes;
|
||||
|
||||
for (const auto& node : nodes) {
|
||||
if (!node->isVisible()) {
|
||||
continue;
|
||||
}
|
||||
visibleNodes.push_back(node.get());
|
||||
if (visibleNodes.full()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (visibleNodes.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
glm::vec2 size = getSize();
|
||||
if (nodes.size() == 1) {
|
||||
auto node = nodes.at(0);
|
||||
if (visibleNodes.size() == 1) {
|
||||
auto node = visibleNodes.at(0);
|
||||
node->setPos(glm::vec2());
|
||||
node->setSize(size);
|
||||
return;
|
||||
}
|
||||
auto nodeA = nodes.at(0);
|
||||
auto nodeB = nodes.at(1);
|
||||
auto nodeA = visibleNodes.at(0);
|
||||
auto nodeB = visibleNodes.at(1);
|
||||
|
||||
float sepRadius = interval / 2.0f;
|
||||
|
||||
|
||||
@ -372,7 +372,7 @@ static std::shared_ptr<UINode> read_split_box(
|
||||
static std::shared_ptr<UINode> read_model_viewer(
|
||||
UiXmlReader& reader, const xml::xmlelement& element
|
||||
) {
|
||||
auto model = element.attr("model", "").getText();
|
||||
auto model = element.attr("src", "").getText();
|
||||
auto viewer = std::make_shared<ModelViewer>(
|
||||
reader.getGUI(), glm::vec2(), model
|
||||
);
|
||||
|
||||
@ -192,6 +192,9 @@ std::string EnginePaths::createWriteableDevice(const std::string& name) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (name == "core") {
|
||||
folder = "res:";
|
||||
}
|
||||
if (folder.emptyOrInvalid()) {
|
||||
throw std::runtime_error("pack not found");
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ static int l_parse_model(lua::State* L) {
|
||||
auto string = lua::require_lstring(L, 2);
|
||||
auto name = lua::require_string(L, 3);
|
||||
|
||||
if (format == "xml") {
|
||||
if (format == "xml" || format == "vcm") {
|
||||
engine->getAssets()->store(vcm::parse(name, string), name);
|
||||
} else {
|
||||
throw std::runtime_error("unknown format " + util::quote(std::string(format)));
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
|
||||
#include "api_lua.hpp"
|
||||
#include "constants.hpp"
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <set>
|
||||
|
||||
@ -156,7 +155,8 @@ static int l_write_bytes(lua::State* L) {
|
||||
return lua::pushboolean(L, res);
|
||||
}
|
||||
|
||||
static int l_list_all_res(lua::State* L, const std::string& path) {
|
||||
static int l_list_all_res(lua::State* L) {
|
||||
std::string path = lua::require_string(L, 1);
|
||||
auto files = engine->getResPaths().listdirRaw(path);
|
||||
lua::createtable(L, files.size(), 0);
|
||||
for (size_t i = 0; i < files.size(); i++) {
|
||||
@ -169,7 +169,7 @@ static int l_list_all_res(lua::State* L, const std::string& path) {
|
||||
static int l_list(lua::State* L) {
|
||||
std::string dirname = lua::require_string(L, 1);
|
||||
if (dirname.find(':') == std::string::npos) {
|
||||
return l_list_all_res(L, dirname);
|
||||
return l_list_all_res(L);
|
||||
}
|
||||
io::path path = dirname;
|
||||
if (!io::is_directory(path)) {
|
||||
@ -265,6 +265,7 @@ const luaL_Reg filelib[] = {
|
||||
{"isfile", lua::wrap<l_isfile>},
|
||||
{"length", lua::wrap<l_length>},
|
||||
{"list", lua::wrap<l_list>},
|
||||
{"list_all_res", lua::wrap<l_list_all_res>},
|
||||
{"mkdir", lua::wrap<l_mkdir>},
|
||||
{"mkdirs", lua::wrap<l_mkdirs>},
|
||||
{"read_bytes", lua::wrap<l_read_bytes>},
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include "graphics/ui/elements/TextBox.hpp"
|
||||
#include "graphics/ui/elements/TrackBar.hpp"
|
||||
#include "graphics/ui/elements/InlineFrame.hpp"
|
||||
#include "graphics/ui/elements/ModelViewer.hpp"
|
||||
#include "graphics/ui/gui_util.hpp"
|
||||
#include "graphics/ui/markdown.hpp"
|
||||
#include "graphics/core/Font.hpp"
|
||||
@ -114,6 +115,16 @@ static int l_node_destruct(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_container_refresh(lua::State* L) {
|
||||
auto docnode = get_document_node(L);
|
||||
auto node = dynamic_cast<Container*>(docnode.node.get());
|
||||
if (node == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
node->refresh();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_node_reposition(lua::State* L) {
|
||||
auto docnode = get_document_node(L);
|
||||
docnode.node->reposition();
|
||||
@ -341,6 +352,8 @@ static int p_get_src(UINode* node, lua::State* L) {
|
||||
return lua::pushstring(L, image->getTexture());
|
||||
} else if (auto iframe = dynamic_cast<InlineFrame*>(node)) {
|
||||
return lua::pushstring(L, iframe->getSrc());
|
||||
} else if (auto modelviewer = dynamic_cast<ModelViewer*>(node)) {
|
||||
return lua::pushstring(L, modelviewer->getModel());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@ -408,6 +421,13 @@ static int p_get_destruct(UINode*, lua::State* L) {
|
||||
return lua::pushcfunction(L, lua::wrap<l_node_destruct>);
|
||||
}
|
||||
|
||||
static int p_refresh(UINode* node, lua::State* L) {
|
||||
if (dynamic_cast<Container*>(node)) {
|
||||
return lua::pushcfunction(L, lua::wrap<l_container_refresh>);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int p_get_reposition(UINode*, lua::State* L) {
|
||||
return lua::pushcfunction(L, lua::wrap<l_node_reposition>);
|
||||
}
|
||||
@ -539,6 +559,7 @@ static int l_gui_getattr(lua::State* L) {
|
||||
{"moveInto", p_move_into},
|
||||
{"add", p_get_add},
|
||||
{"destruct", p_get_destruct},
|
||||
{"refresh", p_refresh},
|
||||
{"reposition", p_get_reposition},
|
||||
{"clear", p_get_clear},
|
||||
{"setInterval", p_set_interval},
|
||||
@ -675,6 +696,8 @@ static void p_set_src(UINode* node, lua::State* L, int idx) {
|
||||
image->setTexture(lua::require_string(L, idx));
|
||||
} else if (auto iframe = dynamic_cast<InlineFrame*>(node)) {
|
||||
iframe->setSrc(lua::require_string(L, idx));
|
||||
} else if (auto modelviewer = dynamic_cast<ModelViewer*>(node)) {
|
||||
modelviewer->setModel(lua::require_string(L, idx));
|
||||
}
|
||||
}
|
||||
static void p_set_region(UINode* node, lua::State* L, int idx) {
|
||||
|
||||
99
src/util/stack_vector.hpp
Normal file
99
src/util/stack_vector.hpp
Normal file
@ -0,0 +1,99 @@
|
||||
#pragma once
|
||||
|
||||
namespace util {
|
||||
template<typename T, int capacity>
|
||||
class stack_vector {
|
||||
public:
|
||||
stack_vector() : size_(0) {}
|
||||
|
||||
stack_vector(const stack_vector<T, capacity>& other)
|
||||
: size_(other.size_) {
|
||||
for (int i = 0; i < size_; ++i) {
|
||||
new (&data_[i]) T(data_[i]);
|
||||
}
|
||||
}
|
||||
|
||||
stack_vector(stack_vector<T, capacity>&& other) noexcept
|
||||
: size_(other.size_) {
|
||||
for (int i = 0; i < size_; ++i) {
|
||||
new (&data_[i]) T(std::move(other.data_[i]));
|
||||
}
|
||||
other.size_ = 0;
|
||||
}
|
||||
|
||||
stack_vector(const std::initializer_list<T>& init) : size_(0) {
|
||||
static_assert(
|
||||
init.size() <= capacity,
|
||||
"initializer list exceeds stack vector capacity"
|
||||
);
|
||||
for (const auto& value : init) {
|
||||
new (&data_[size_++]) T(value);
|
||||
}
|
||||
}
|
||||
|
||||
~stack_vector() {
|
||||
clear();
|
||||
}
|
||||
|
||||
void push_back(const T& value) {
|
||||
if (size_ < capacity) {
|
||||
data_[size_++] = value;
|
||||
} else {
|
||||
throw std::overflow_error("stack vector capacity exceeded");
|
||||
}
|
||||
}
|
||||
|
||||
void pop_back() {
|
||||
if (size_ > 0) {
|
||||
data_[size_ - 1].~T();
|
||||
--size_;
|
||||
} else {
|
||||
throw std::underflow_error("stack vector is empty");
|
||||
}
|
||||
}
|
||||
|
||||
void clear() {
|
||||
for (int i = 0; i < size_; ++i) {
|
||||
data_[i].~T();
|
||||
}
|
||||
size_ = 0;
|
||||
}
|
||||
|
||||
T& operator[](int index) {
|
||||
return data_[index];
|
||||
}
|
||||
|
||||
const T& operator[](int index) const {
|
||||
return data_[index];
|
||||
}
|
||||
|
||||
T& at(int index) {
|
||||
if (index < 0 || index >= size_) {
|
||||
throw std::out_of_range("index out of range");
|
||||
}
|
||||
return data_[index];
|
||||
}
|
||||
|
||||
const T& at(int index) const {
|
||||
if (index < 0 || index >= size_) {
|
||||
throw std::out_of_range("index out of range");
|
||||
}
|
||||
return data_[index];
|
||||
}
|
||||
|
||||
int size() const {
|
||||
return size_;
|
||||
}
|
||||
|
||||
bool empty() const {
|
||||
return size_ == 0;
|
||||
}
|
||||
|
||||
bool full() const {
|
||||
return size_ == capacity;
|
||||
}
|
||||
private:
|
||||
T data_[capacity];
|
||||
int size_;
|
||||
};
|
||||
}
|
||||
24
test/coders/xml.cpp
Normal file
24
test/coders/xml.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "coders/xml.hpp"
|
||||
#include "coders/commons.hpp"
|
||||
|
||||
TEST(XML, VCM) {
|
||||
std::string code = ""
|
||||
"@line x1 y1 z1\n"
|
||||
"# @tst ysfdrg\n"
|
||||
"@box {\n"
|
||||
" @rect texture \"$2\"\n"
|
||||
" @utro a 53.1\n"
|
||||
"}\n"
|
||||
;
|
||||
std::cout << code << std::endl;
|
||||
|
||||
try {
|
||||
auto document = xml::parse_vcm("<test>", code, "test");
|
||||
std::cout << xml::stringify(*document);
|
||||
} catch (const parsing_error& err) {
|
||||
std::cerr << err.errorLog() << std::endl;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user