Merge branch 'main' into framerate-control
This commit is contained in:
@@ -217,6 +217,7 @@ void ContentLoader::loadBlock(Block& def, const std::string& name, const fs::pat
|
||||
root->flag("light-passing", def.lightPassing);
|
||||
root->flag("sky-light-passing", def.skyLightPassing);
|
||||
root->flag("shadeless", def.shadeless);
|
||||
root->flag("ambient-occlusion", def.ambientOcclusion);
|
||||
root->flag("breakable", def.breakable);
|
||||
root->flag("selectable", def.selectable);
|
||||
root->flag("grounded", def.grounded);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <functional>
|
||||
|
||||
namespace dynamic {
|
||||
class Map;
|
||||
@@ -27,6 +28,8 @@ namespace dynamic {
|
||||
bool,
|
||||
integer_t
|
||||
>;
|
||||
|
||||
using to_string_func = std::function<std::string(const Value&)>;
|
||||
}
|
||||
|
||||
#endif // DATA_DYNAMIC_FWD_HPP_
|
||||
|
||||
@@ -175,6 +175,7 @@ Hud::Hud(Engine* engine, LevelFrontend* frontend, Player* player)
|
||||
|
||||
auto dplotter = std::make_shared<Plotter>(350, 250, 2000, 16);
|
||||
dplotter->setGravity(Gravity::bottom_right);
|
||||
dplotter->setInteractive(false);
|
||||
add(HudElement(hud_element_mode::permanent, nullptr, dplotter, true));
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ void BlocksRenderer::face(
|
||||
index(0, 1, 3, 1, 2, 3);
|
||||
}
|
||||
|
||||
void BlocksRenderer::vertex(
|
||||
void BlocksRenderer::vertexAO(
|
||||
const vec3& coord,
|
||||
float u, float v,
|
||||
const vec4& tint,
|
||||
@@ -117,7 +117,7 @@ void BlocksRenderer::vertex(
|
||||
vertex(coord, u, v, light * tint);
|
||||
}
|
||||
|
||||
void BlocksRenderer::face(
|
||||
void BlocksRenderer::faceAO(
|
||||
const vec3& coord,
|
||||
const vec3& X,
|
||||
const vec3& Y,
|
||||
@@ -140,12 +140,12 @@ void BlocksRenderer::face(
|
||||
vec3 axisZ = glm::normalize(Z);
|
||||
|
||||
vec4 tint(d);
|
||||
vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, tint, axisX, axisY, axisZ);
|
||||
vertex(coord + ( X - Y + Z) * s, region.u2, region.v1, tint, axisX, axisY, axisZ);
|
||||
vertex(coord + ( X + Y + Z) * s, region.u2, region.v2, tint, axisX, axisY, axisZ);
|
||||
vertex(coord + (-X + Y + Z) * s, region.u1, region.v2, tint, axisX, axisY, axisZ);
|
||||
vertexAO(coord + (-X - Y + Z) * s, region.u1, region.v1, tint, axisX, axisY, axisZ);
|
||||
vertexAO(coord + ( X - Y + Z) * s, region.u2, region.v1, tint, axisX, axisY, axisZ);
|
||||
vertexAO(coord + ( X + Y + Z) * s, region.u2, region.v2, tint, axisX, axisY, axisZ);
|
||||
vertexAO(coord + (-X + Y + Z) * s, region.u1, region.v2, tint, axisX, axisY, axisZ);
|
||||
} else {
|
||||
vec4 tint(1.0f);
|
||||
glm::vec4 tint(1.0f);
|
||||
vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, tint);
|
||||
vertex(coord + ( X - Y + Z) * s, region.u2, region.v1, tint);
|
||||
vertex(coord + ( X + Y + Z) * s, region.u2, region.v2, tint);
|
||||
@@ -154,6 +154,33 @@ void BlocksRenderer::face(
|
||||
index(0, 1, 2, 0, 2, 3);
|
||||
}
|
||||
|
||||
void BlocksRenderer::face(
|
||||
const vec3& coord,
|
||||
const vec3& X,
|
||||
const vec3& Y,
|
||||
const vec3& Z,
|
||||
const UVRegion& region,
|
||||
vec4 tint,
|
||||
bool lights
|
||||
) {
|
||||
if (vertexOffset + BlocksRenderer::VERTEX_SIZE * 4 > capacity) {
|
||||
overflow = true;
|
||||
return;
|
||||
}
|
||||
|
||||
float s = 0.5f;
|
||||
if (lights) {
|
||||
float d = glm::dot(glm::normalize(Z), SUN_VECTOR);
|
||||
d = 0.8f + d * 0.2f;
|
||||
tint *= d;
|
||||
}
|
||||
vertex(coord + (-X - Y + Z) * s, region.u1, region.v1, tint);
|
||||
vertex(coord + ( X - Y + Z) * s, region.u2, region.v1, tint);
|
||||
vertex(coord + ( X + Y + Z) * s, region.u2, region.v2, tint);
|
||||
vertex(coord + (-X + Y + Z) * s, region.u1, region.v2, tint);
|
||||
index(0, 1, 2, 0, 2, 3);
|
||||
}
|
||||
|
||||
void BlocksRenderer::tetragonicFace(
|
||||
const vec3& coord,
|
||||
const vec3& p1, const vec3& p2, const vec3& p3, const vec3& p4,
|
||||
@@ -231,7 +258,8 @@ void BlocksRenderer::blockAABB(
|
||||
const UVRegion(&texfaces)[6],
|
||||
const Block* block,
|
||||
ubyte rotation,
|
||||
bool lights
|
||||
bool lights,
|
||||
bool ao
|
||||
) {
|
||||
if (block->hitboxes.empty()) {
|
||||
return;
|
||||
@@ -256,18 +284,30 @@ void BlocksRenderer::blockAABB(
|
||||
}
|
||||
coord = vec3(icoord) - vec3(0.5f) + hitbox.center();
|
||||
|
||||
face(coord, X*size.x, Y*size.y, Z*size.z, texfaces[5], lights); // north
|
||||
face(coord, -X*size.x, Y*size.y, -Z*size.z, texfaces[4], lights); // south
|
||||
if (ao) {
|
||||
faceAO(coord, X*size.x, Y*size.y, Z*size.z, texfaces[5], lights); // north
|
||||
faceAO(coord, -X*size.x, Y*size.y, -Z*size.z, texfaces[4], lights); // south
|
||||
|
||||
face(coord, X*size.x, -Z*size.z, Y*size.y, texfaces[3], lights); // top
|
||||
face(coord, -X*size.x, -Z*size.z, -Y*size.y, texfaces[2], lights); // bottom
|
||||
faceAO(coord, X*size.x, -Z*size.z, Y*size.y, texfaces[3], lights); // top
|
||||
faceAO(coord, -X*size.x, -Z*size.z, -Y*size.y, texfaces[2], lights); // bottom
|
||||
|
||||
face(coord, -Z*size.z, Y*size.y, X*size.x, texfaces[1], lights); // west
|
||||
face(coord, Z*size.z, Y*size.y, -X*size.x, texfaces[0], lights); // east
|
||||
faceAO(coord, -Z*size.z, Y*size.y, X*size.x, texfaces[1], lights); // west
|
||||
faceAO(coord, Z*size.z, Y*size.y, -X*size.x, texfaces[0], lights); // east
|
||||
} else {
|
||||
auto tint = pickLight(icoord);
|
||||
face(coord, X*size.x, Y*size.y, Z*size.z, texfaces[5], tint, lights); // north
|
||||
face(coord, -X*size.x, Y*size.y, -Z*size.z, texfaces[4], tint, lights); // south
|
||||
|
||||
face(coord, X*size.x, -Z*size.z, Y*size.y, texfaces[3], tint, lights); // top
|
||||
face(coord, -X*size.x, -Z*size.z, -Y*size.y, texfaces[2], tint, lights); // bottom
|
||||
|
||||
face(coord, -Z*size.z, Y*size.y, X*size.x, texfaces[1], tint, lights); // west
|
||||
face(coord, Z*size.z, Y*size.y, -X*size.x, texfaces[0], tint, lights); // east
|
||||
}
|
||||
}
|
||||
|
||||
void BlocksRenderer::blockCustomModel(
|
||||
const ivec3& icoord, const Block* block, ubyte rotation, bool lights
|
||||
const ivec3& icoord, const Block* block, ubyte rotation, bool lights, bool ao
|
||||
) {
|
||||
vec3 X(1, 0, 0);
|
||||
vec3 Y(0, 1, 0);
|
||||
@@ -289,12 +329,12 @@ void BlocksRenderer::blockCustomModel(
|
||||
orient.transform(box);
|
||||
}
|
||||
vec3 center_coord = coord - vec3(0.5f) + box.center();
|
||||
face(center_coord, X * size.x, Y * size.y, Z * size.z, block->modelUVs[i * 6 + 5], lights); // north
|
||||
face(center_coord, -X * size.x, Y * size.y, -Z * size.z, block->modelUVs[i * 6 + 4], lights); // south
|
||||
face(center_coord, X * size.x, -Z * size.z, Y * size.y, block->modelUVs[i * 6 + 3], lights); // top
|
||||
face(center_coord, -X * size.x, -Z * size.z, -Y * size.y, block->modelUVs[i * 6 + 2], lights); // bottom
|
||||
face(center_coord, -Z * size.z, Y * size.y, X * size.x, block->modelUVs[i * 6 + 1], lights); // west
|
||||
face(center_coord, Z * size.z, Y * size.y, -X * size.x, block->modelUVs[i * 6 + 0], lights); // east
|
||||
faceAO(center_coord, X * size.x, Y * size.y, Z * size.z, block->modelUVs[i * 6 + 5], lights); // north
|
||||
faceAO(center_coord, -X * size.x, Y * size.y, -Z * size.z, block->modelUVs[i * 6 + 4], lights); // south
|
||||
faceAO(center_coord, X * size.x, -Z * size.z, Y * size.y, block->modelUVs[i * 6 + 3], lights); // top
|
||||
faceAO(center_coord, -X * size.x, -Z * size.z, -Y * size.y, block->modelUVs[i * 6 + 2], lights); // bottom
|
||||
faceAO(center_coord, -Z * size.z, Y * size.y, X * size.x, block->modelUVs[i * 6 + 1], lights); // west
|
||||
faceAO(center_coord, Z * size.z, Y * size.y, -X * size.x, block->modelUVs[i * 6 + 0], lights); // east
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < block->modelExtraPoints.size()/4; i++) {
|
||||
@@ -314,7 +354,8 @@ void BlocksRenderer::blockCube(
|
||||
const UVRegion(&texfaces)[6],
|
||||
const Block* block,
|
||||
blockstate states,
|
||||
bool lights
|
||||
bool lights,
|
||||
bool ao
|
||||
) {
|
||||
ubyte group = block->drawGroup;
|
||||
|
||||
@@ -330,23 +371,44 @@ void BlocksRenderer::blockCube(
|
||||
Z = orient.axisZ;
|
||||
}
|
||||
|
||||
if (isOpen(x+Z.x, y+Z.y, z+Z.z, group)) {
|
||||
face(coord, X, Y, Z, texfaces[5], lights);
|
||||
}
|
||||
if (isOpen(x-Z.x, y-Z.y, z-Z.z, group)) {
|
||||
face(coord, -X, Y, -Z, texfaces[4], lights);
|
||||
}
|
||||
if (isOpen(x+Y.x, y+Y.y, z+Y.z, group)) {
|
||||
face(coord, X, -Z, Y, texfaces[3], lights);
|
||||
}
|
||||
if (isOpen(x-Y.x, y-Y.y, z-Y.z, group)) {
|
||||
face(coord, X, Z, -Y, texfaces[2], lights);
|
||||
}
|
||||
if (isOpen(x+X.x, y+X.y, z+X.z, group)) {
|
||||
face(coord, -Z, Y, X, texfaces[1], lights);
|
||||
}
|
||||
if (isOpen(x-X.x, y-X.y, z-X.z, group)) {
|
||||
face(coord, Z, Y, -X, texfaces[0], lights);
|
||||
if (ao) {
|
||||
if (isOpen(x+Z.x, y+Z.y, z+Z.z, group)) {
|
||||
faceAO(coord, X, Y, Z, texfaces[5], lights);
|
||||
}
|
||||
if (isOpen(x-Z.x, y-Z.y, z-Z.z, group)) {
|
||||
faceAO(coord, -X, Y, -Z, texfaces[4], lights);
|
||||
}
|
||||
if (isOpen(x+Y.x, y+Y.y, z+Y.z, group)) {
|
||||
faceAO(coord, X, -Z, Y, texfaces[3], lights);
|
||||
}
|
||||
if (isOpen(x-Y.x, y-Y.y, z-Y.z, group)) {
|
||||
faceAO(coord, X, Z, -Y, texfaces[2], lights);
|
||||
}
|
||||
if (isOpen(x+X.x, y+X.y, z+X.z, group)) {
|
||||
faceAO(coord, -Z, Y, X, texfaces[1], lights);
|
||||
}
|
||||
if (isOpen(x-X.x, y-X.y, z-X.z, group)) {
|
||||
faceAO(coord, Z, Y, -X, texfaces[0], lights);
|
||||
}
|
||||
} else {
|
||||
if (isOpen(x+Z.x, y+Z.y, z+Z.z, group)) {
|
||||
face(coord, X, Y, Z, texfaces[5], pickLight({x, y, z+1}), lights);
|
||||
}
|
||||
if (isOpen(x-Z.x, y-Z.y, z-Z.z, group)) {
|
||||
face(coord, -X, Y, -Z, texfaces[4], pickLight({x, y, z-1}), lights);
|
||||
}
|
||||
if (isOpen(x+Y.x, y+Y.y, z+Y.z, group)) {
|
||||
face(coord, X, -Z, Y, texfaces[3], pickLight({x, y+1, z}), lights);
|
||||
}
|
||||
if (isOpen(x-Y.x, y-Y.y, z-Y.z, group)) {
|
||||
face(coord, X, Z, -Y, texfaces[2], pickLight({x, y-1, z}), lights);
|
||||
}
|
||||
if (isOpen(x+X.x, y+X.y, z+X.z, group)) {
|
||||
face(coord, -Z, Y, X, texfaces[1], pickLight({x+1, y, z}), lights);
|
||||
}
|
||||
if (isOpen(x-X.x, y-X.y, z-X.z, group)) {
|
||||
face(coord, Z, Y, -X, texfaces[0], pickLight({x-1, y, z}), lights);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,7 +502,8 @@ void BlocksRenderer::render(const voxel* voxels) {
|
||||
int z = (i / CHUNK_D) % CHUNK_W;
|
||||
switch (def.model) {
|
||||
case BlockModel::block:
|
||||
blockCube(x, y, z, texfaces, &def, vox.state, !def.shadeless);
|
||||
blockCube(x, y, z, texfaces, &def, vox.state, !def.shadeless,
|
||||
def.ambientOcclusion);
|
||||
break;
|
||||
case BlockModel::xsprite: {
|
||||
blockXSprite(x, y, z, vec3(1.0f),
|
||||
@@ -448,11 +511,13 @@ void BlocksRenderer::render(const voxel* voxels) {
|
||||
break;
|
||||
}
|
||||
case BlockModel::aabb: {
|
||||
blockAABB(ivec3(x,y,z), texfaces, &def, vox.state.rotation, !def.shadeless);
|
||||
blockAABB(ivec3(x,y,z), texfaces, &def, vox.state.rotation,
|
||||
!def.shadeless, def.ambientOcclusion);
|
||||
break;
|
||||
}
|
||||
case BlockModel::custom: {
|
||||
blockCustomModel(ivec3(x, y, z), &def, vox.state.rotation, !def.shadeless);
|
||||
blockCustomModel(ivec3(x, y, z), &def, vox.state.rotation,
|
||||
!def.shadeless, def.ambientOcclusion);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -40,7 +40,7 @@ class BlocksRenderer {
|
||||
void vertex(const glm::vec3& coord, float u, float v, const glm::vec4& light);
|
||||
void index(int a, int b, int c, int d, int e, int f);
|
||||
|
||||
void vertex(
|
||||
void vertexAO(
|
||||
const glm::vec3& coord, float u, float v,
|
||||
const glm::vec4& brightness,
|
||||
const glm::vec3& axisX,
|
||||
@@ -58,6 +58,15 @@ class BlocksRenderer {
|
||||
const glm::vec4& tint
|
||||
);
|
||||
void face(
|
||||
const glm::vec3& coord,
|
||||
const glm::vec3& X,
|
||||
const glm::vec3& Y,
|
||||
const glm::vec3& Z,
|
||||
const UVRegion& region,
|
||||
glm::vec4 tint,
|
||||
bool lights
|
||||
);
|
||||
void faceAO(
|
||||
const glm::vec3& coord,
|
||||
const glm::vec3& axisX,
|
||||
const glm::vec3& axisY,
|
||||
@@ -80,14 +89,16 @@ class BlocksRenderer {
|
||||
const UVRegion(&faces)[6],
|
||||
const Block* block,
|
||||
blockstate states,
|
||||
bool lights
|
||||
bool lights,
|
||||
bool ao
|
||||
);
|
||||
void blockAABB(
|
||||
const glm::ivec3& coord,
|
||||
const UVRegion(&faces)[6],
|
||||
const Block* block,
|
||||
ubyte rotation,
|
||||
bool lights
|
||||
bool lights,
|
||||
bool ambientOcclusion
|
||||
);
|
||||
void blockXSprite(
|
||||
int x, int y, int z,
|
||||
@@ -100,7 +111,8 @@ class BlocksRenderer {
|
||||
const glm::ivec3& icoord,
|
||||
const Block* block,
|
||||
ubyte rotation,
|
||||
bool lights
|
||||
bool lights,
|
||||
bool ao
|
||||
);
|
||||
|
||||
bool isOpenForLight(int x, int y, int z) const;
|
||||
|
||||
@@ -50,6 +50,7 @@ ChunksRenderer::ChunksRenderer(
|
||||
renderer = std::make_unique<BlocksRenderer>(
|
||||
RENDERER_CAPACITY, level->content, cache, settings
|
||||
);
|
||||
logger.info() << "created " << threadPool.getWorkersCount() << " workers";
|
||||
}
|
||||
|
||||
ChunksRenderer::~ChunksRenderer() {
|
||||
|
||||
@@ -131,7 +131,7 @@ void GUI::actMouse(float delta) {
|
||||
focus->defocus();
|
||||
focus = nullptr;
|
||||
}
|
||||
} else if (pressed) {
|
||||
} else if (!Events::clicked(mousecode::BUTTON_1) && pressed) {
|
||||
pressed->mouseRelease(this, Events::cursor.x, Events::cursor.y);
|
||||
pressed = nullptr;
|
||||
}
|
||||
|
||||
@@ -50,6 +50,10 @@ void TrackBar::setConsumer(doubleconsumer consumer) {
|
||||
this->consumer = std::move(consumer);
|
||||
}
|
||||
|
||||
void TrackBar::setSubConsumer(doubleconsumer consumer) {
|
||||
this->subconsumer = std::move(consumer);
|
||||
}
|
||||
|
||||
void TrackBar::mouseMove(GUI*, int x, int) {
|
||||
glm::vec2 pos = calcPos();
|
||||
value = x - trackWidth/2;
|
||||
@@ -60,11 +64,19 @@ void TrackBar::mouseMove(GUI*, int x, int) {
|
||||
value = (value < min) ? min : value;
|
||||
value = (int64_t)round(value / step) * step;
|
||||
|
||||
if (consumer) {
|
||||
if (consumer && !changeOnRelease) {
|
||||
consumer(value);
|
||||
}
|
||||
if (subconsumer) {
|
||||
subconsumer(value);
|
||||
}
|
||||
}
|
||||
|
||||
void TrackBar::mouseRelease(GUI*, int, int) {
|
||||
if (consumer && changeOnRelease) {
|
||||
consumer(value);
|
||||
}
|
||||
}
|
||||
|
||||
double TrackBar::getValue() const {
|
||||
return value;
|
||||
@@ -90,6 +102,10 @@ glm::vec4 TrackBar::getTrackColor() const {
|
||||
return trackColor;
|
||||
}
|
||||
|
||||
bool TrackBar::isChangeOnRelease() const {
|
||||
return changeOnRelease;
|
||||
}
|
||||
|
||||
void TrackBar::setValue(double x) {
|
||||
value = x;
|
||||
}
|
||||
@@ -113,3 +129,7 @@ void TrackBar::setTrackWidth(int width) {
|
||||
void TrackBar::setTrackColor(glm::vec4 color) {
|
||||
trackColor = color;
|
||||
}
|
||||
|
||||
void TrackBar::setChangeOnRelease(bool flag) {
|
||||
changeOnRelease = flag;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define GRAPHICS_UI_ELEMENTS_TRACKBAR_HPP_
|
||||
|
||||
#include "UINode.hpp"
|
||||
#include "../../../data/dynamic_fwd.hpp"
|
||||
|
||||
namespace gui {
|
||||
class TrackBar : public UINode {
|
||||
@@ -9,11 +10,13 @@ namespace gui {
|
||||
glm::vec4 trackColor {1.0f, 1.0f, 1.0f, 0.4f};
|
||||
doublesupplier supplier = nullptr;
|
||||
doubleconsumer consumer = nullptr;
|
||||
doubleconsumer subconsumer = nullptr;
|
||||
double min;
|
||||
double max;
|
||||
double value;
|
||||
double step;
|
||||
int trackWidth;
|
||||
bool changeOnRelease = false;
|
||||
public:
|
||||
TrackBar(double min,
|
||||
double max,
|
||||
@@ -22,10 +25,12 @@ namespace gui {
|
||||
int trackWidth=12);
|
||||
virtual void draw(const DrawContext* pctx, Assets* assets) override;
|
||||
|
||||
virtual void setSupplier(doublesupplier supplier);
|
||||
virtual void setConsumer(doubleconsumer consumer);
|
||||
virtual void setSupplier(doublesupplier);
|
||||
virtual void setConsumer(doubleconsumer);
|
||||
virtual void setSubConsumer(doubleconsumer);
|
||||
|
||||
virtual void mouseMove(GUI*, int x, int y) override;
|
||||
virtual void mouseRelease(GUI*, int x, int y) override;
|
||||
|
||||
virtual double getValue() const;
|
||||
virtual double getMin() const;
|
||||
@@ -33,6 +38,7 @@ namespace gui {
|
||||
virtual double getStep() const;
|
||||
virtual int getTrackWidth() const;
|
||||
virtual glm::vec4 getTrackColor() const;
|
||||
virtual bool isChangeOnRelease() const;
|
||||
|
||||
virtual void setValue(double);
|
||||
virtual void setMin(double);
|
||||
@@ -40,6 +46,7 @@ namespace gui {
|
||||
virtual void setStep(double);
|
||||
virtual void setTrackWidth(int);
|
||||
virtual void setTrackColor(glm::vec4);
|
||||
virtual void setChangeOnRelease(bool);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+14
-11
@@ -392,30 +392,33 @@ static std::shared_ptr<UINode> readImage(UiXmlReader& reader, const xml::xmlelem
|
||||
}
|
||||
|
||||
static std::shared_ptr<UINode> readTrackBar(UiXmlReader& reader, const xml::xmlelement& element) {
|
||||
float min = element->attr("min", "0.0").asFloat();
|
||||
float max = element->attr("max", "1.0").asFloat();
|
||||
const auto& env = reader.getEnvironment();
|
||||
const auto& file = reader.getFilename();
|
||||
float minv = element->attr("min", "0.0").asFloat();
|
||||
float maxv = element->attr("max", "1.0").asFloat();
|
||||
float def = element->attr("value", "0.0").asFloat();
|
||||
float step = element->attr("step", "1.0").asFloat();
|
||||
int trackWidth = element->attr("track-width", "12").asInt();
|
||||
auto bar = std::make_shared<TrackBar>(min, max, def, step, trackWidth);
|
||||
auto bar = std::make_shared<TrackBar>(minv, maxv, def, step, trackWidth);
|
||||
_readUINode(reader, element, *bar);
|
||||
if (element->has("consumer")) {
|
||||
bar->setConsumer(scripting::create_number_consumer(
|
||||
reader.getEnvironment(),
|
||||
element->attr("consumer").getText(),
|
||||
reader.getFilename()
|
||||
));
|
||||
env, element->attr("consumer").getText(), file));
|
||||
}
|
||||
if (element->has("sub-consumer")) {
|
||||
bar->setSubConsumer(scripting::create_number_consumer(
|
||||
env, element->attr("sub-consumer").getText(), file));
|
||||
}
|
||||
if (element->has("supplier")) {
|
||||
bar->setSupplier(scripting::create_number_supplier(
|
||||
reader.getEnvironment(),
|
||||
element->attr("supplier").getText(),
|
||||
reader.getFilename()
|
||||
));
|
||||
env, element->attr("supplier").getText(), file));
|
||||
}
|
||||
if (element->has("track-color")) {
|
||||
bar->setTrackColor(element->attr("track-color").asColor());
|
||||
}
|
||||
if (element->has("change-on-release")) {
|
||||
bar->setChangeOnRelease(element->attr("change-on-release").asBool());
|
||||
}
|
||||
return bar;
|
||||
}
|
||||
|
||||
|
||||
@@ -169,13 +169,13 @@ void CameraControl::update(const PlayerInput& input, float delta, Chunks* chunks
|
||||
|
||||
if (player->currentCamera == spCamera) {
|
||||
spCamera->position = chunks->rayCastToObstacle(
|
||||
camera->position, camera->front, 3.0f) - 0.2f * camera->front;
|
||||
camera->position, camera->front, 3.0f) - 0.4f * camera->front;
|
||||
spCamera->dir = -camera->dir;
|
||||
spCamera->front = -camera->front;
|
||||
}
|
||||
else if (player->currentCamera == tpCamera) {
|
||||
tpCamera->position = chunks->rayCastToObstacle(
|
||||
camera->position, -camera->front, 3.0f) + 0.2f * camera->front;
|
||||
camera->position, -camera->front, 3.0f) + 0.4f * camera->front;
|
||||
tpCamera->dir = camera->dir;
|
||||
tpCamera->front = camera->front;
|
||||
}
|
||||
@@ -391,7 +391,7 @@ voxel* PlayerController::updateSelection(float maxDistance) {
|
||||
selection.position = chunks->seekOrigin(
|
||||
iend, indices->blocks.get(selection.vox.id), selectedState
|
||||
);
|
||||
auto origin = chunks->get(iend);
|
||||
auto origin = chunks->get(selection.position);
|
||||
if (origin && origin->id != vox->id) {
|
||||
chunks->set(iend.x, iend.y, iend.z, 0, {});
|
||||
return updateSelection(maxDistance);
|
||||
|
||||
@@ -380,6 +380,23 @@ static int l_raycast(lua::State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_compose_state(lua::State* L) {
|
||||
blockstate state {};
|
||||
state.rotation = lua::tointeger(L, 1);
|
||||
state.segment = lua::tointeger(L, 2);
|
||||
state.userbits = lua::tointeger(L, 3);
|
||||
return lua::pushinteger(L, blockstate2int(state));
|
||||
}
|
||||
|
||||
static int l_decompose_state(lua::State* L) {
|
||||
auto stateInt = static_cast<blockstate_t>(lua::tointeger(L, 1));
|
||||
auto state = int2blockstate(stateInt);
|
||||
lua::pushinteger(L, state.rotation);
|
||||
lua::pushinteger(L, state.segment);
|
||||
lua::pushinteger(L, state.userbits);
|
||||
return 3;
|
||||
}
|
||||
|
||||
const luaL_Reg blocklib [] = {
|
||||
{"index", lua::wrap<l_index>},
|
||||
{"name", lua::wrap<l_get_def>},
|
||||
@@ -411,5 +428,7 @@ const luaL_Reg blocklib [] = {
|
||||
{"place", lua::wrap<l_place>},
|
||||
{"destruct", lua::wrap<l_destruct>},
|
||||
{"raycast", lua::wrap<l_raycast>},
|
||||
{"compose_state", lua::wrap<l_compose_state>},
|
||||
{"decompose_state", lua::wrap<l_decompose_state>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "lua/lua_engine.hpp"
|
||||
#include "../../debug/Logger.hpp"
|
||||
#include "../../coders/json.hpp"
|
||||
#include "../../util/stringutil.hpp"
|
||||
|
||||
using namespace scripting;
|
||||
@@ -177,3 +178,25 @@ vec2supplier scripting::create_vec2_supplier(
|
||||
return glm::vec2(0, 0);
|
||||
};
|
||||
}
|
||||
|
||||
dynamic::to_string_func scripting::create_tostring(
|
||||
const scriptenv& env,
|
||||
const std::string& src,
|
||||
const std::string& file
|
||||
) {
|
||||
auto L = lua::get_main_thread();
|
||||
try {
|
||||
lua::loadbuffer(L, *env, src, file);
|
||||
lua::call(L, 0, 1);
|
||||
auto func = lua::create_lambda(L);
|
||||
return [func](const dynamic::Value& value) {
|
||||
auto result = func({value});
|
||||
return json::stringify(result, true, " ");
|
||||
};
|
||||
} catch (const lua::luaerror& err) {
|
||||
logger.error() << err.what();
|
||||
return [](const auto& value) {
|
||||
return json::stringify(value, true, " ");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,12 @@ namespace scripting {
|
||||
const std::string& src,
|
||||
const std::string& file="<string>"
|
||||
);
|
||||
|
||||
dynamic::to_string_func create_tostring(
|
||||
const scriptenv& env,
|
||||
const std::string& src,
|
||||
const std::string& file="<string>"
|
||||
);
|
||||
}
|
||||
|
||||
#endif // LOGIC_SCRIPTING_SCRIPTING_FUNCTIONAL_HPP_
|
||||
|
||||
@@ -200,7 +200,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void enqueueJob(std::shared_ptr<T> job) {
|
||||
void enqueueJob(const std::shared_ptr<T>& job) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(jobsMutex);
|
||||
jobs.push(job);
|
||||
@@ -244,6 +244,10 @@ public:
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
uint getWorkersCount() const {
|
||||
return threads.size();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace util
|
||||
|
||||
@@ -20,11 +20,11 @@ namespace timeutil {
|
||||
* ...
|
||||
* }
|
||||
*/
|
||||
class ScopeLogTimer : public Timer{
|
||||
long long scopeid_;
|
||||
public:
|
||||
ScopeLogTimer(long long id);
|
||||
~ScopeLogTimer();
|
||||
class ScopeLogTimer : public Timer {
|
||||
long long scopeid_;
|
||||
public:
|
||||
ScopeLogTimer(long long id);
|
||||
~ScopeLogTimer();
|
||||
};
|
||||
|
||||
inline constexpr float time_value(float hour, float minute, float second) {
|
||||
|
||||
@@ -136,6 +136,9 @@ public:
|
||||
|
||||
/// @brief Does block model have shading
|
||||
bool shadeless = false;
|
||||
|
||||
/// @brief Does block model have vertex-based AO effect
|
||||
bool ambientOcclusion = true;
|
||||
|
||||
/// @brief Is the block a physical obstacle
|
||||
bool obstacle = true;
|
||||
|
||||
Reference in New Issue
Block a user