add new block.get_AXIS functions overloads & add rotation support to base:falling_block

This commit is contained in:
MihailRis
2024-12-29 21:48:36 +03:00
parent 9a190acb8b
commit ab5a62c3aa
9 changed files with 72 additions and 75 deletions
+3 -3
View File
@@ -41,9 +41,9 @@ void BlocksController::updateSides(int x, int y, int z, int w, int h, int d) {
voxel* vox = blocks_agent::get(chunks, x, y, z);
const auto& def = level.content.getIndices()->blocks.require(vox->id);
const auto& rot = def.rotations.variants[vox->state.rotation];
const auto& xaxis = rot.axisX;
const auto& yaxis = rot.axisY;
const auto& zaxis = rot.axisZ;
const auto& xaxis = rot.axes[0];
const auto& yaxis = rot.axes[1];
const auto& zaxis = rot.axes[2];
for (int ly = -1; ly <= h; ly++) {
for (int lz = -1; lz <= d; lz++) {
for (int lx = -1; lx <= w; lx++) {
+25 -33
View File
@@ -125,55 +125,47 @@ static int l_get(lua::State* L) {
return lua::pushinteger(L, id);
}
static int l_get_x(lua::State* L) {
template<int n>
static int get_axis(lua::State* L, const Block& def, int rotation) {
const CoordSystem& rot = def.rotations.variants[rotation];
return lua::pushivec_stack(L, rot.axes[n]);
}
template<int n>
static int get_axis(lua::State* L) {
auto x = lua::tointeger(L, 1);
auto y = lua::tointeger(L, 2);
if (lua::gettop(L) == 2) {
const auto& def = level->content.getIndices()->blocks.require(x);
return get_axis<n>(L, def, y);
}
auto z = lua::tointeger(L, 3);
glm::ivec3 defAxis;
defAxis[n] = 1;
auto vox = blocks_agent::get(*level->chunks, x, y, z);
if (vox == nullptr) {
return lua::pushivec_stack(L, glm::ivec3(1, 0, 0));
return lua::pushivec_stack(L, defAxis);
}
const auto& def = level->content.getIndices()->blocks.require(vox->id);
if (!def.rotatable) {
return lua::pushivec_stack(L, glm::ivec3(1, 0, 0));
return lua::pushivec_stack(L, defAxis);
} else {
const CoordSystem& rot = def.rotations.variants[vox->state.rotation];
return lua::pushivec_stack(L, rot.axisX);
return get_axis<n>(L, def, vox->state.rotation);
}
}
static int l_get_x(lua::State* L) {
return get_axis<0>(L);
}
static int l_get_y(lua::State* L) {
auto x = lua::tointeger(L, 1);
auto y = lua::tointeger(L, 2);
auto z = lua::tointeger(L, 3);
auto vox = blocks_agent::get(*level->chunks, x, y, z);
if (vox == nullptr) {
return lua::pushivec_stack(L, glm::ivec3(0, 1, 0));
}
const auto& def = level->content.getIndices()->blocks.require(vox->id);
if (!def.rotatable) {
return lua::pushivec_stack(L, glm::ivec3(0, 1, 0));
} else {
const CoordSystem& rot = def.rotations.variants[vox->state.rotation];
return lua::pushivec_stack(L, rot.axisY);
}
return get_axis<1>(L);
}
static int l_get_z(lua::State* L) {
auto x = lua::tointeger(L, 1);
auto y = lua::tointeger(L, 2);
auto z = lua::tointeger(L, 3);
auto vox = blocks_agent::get(*level->chunks, x, y, z);
if (vox == nullptr) {
return lua::pushivec_stack(L, glm::ivec3(0, 0, 1));
}
const auto& def = level->content.getIndices()->blocks.require(vox->id);
if (!def.rotatable) {
return lua::pushivec_stack(L, glm::ivec3(0, 0, 1));
} else {
const CoordSystem& rot = def.rotations.variants[vox->state.rotation];
return lua::pushivec_stack(L, rot.axisZ);
}
return get_axis<2>(L);
}
static int l_get_rotation(lua::State* L) {