mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-09 21:11:50 +00:00
Merge branch 'MihailRis:main' into main
This commit is contained in:
commit
8e2d915dd7
26 changed files with 368 additions and 64 deletions
|
|
@ -111,10 +111,17 @@ void BlocksController::updateBlock(int x, int y, int z) {
|
|||
if (vox == nullptr) return;
|
||||
const auto& def = level.content.getIndices()->blocks.require(vox->id);
|
||||
if (def.grounded) {
|
||||
const auto& vec = get_ground_direction(def, vox->state.rotation);
|
||||
if (!blocks_agent::is_solid_at(chunks, x + vec.x, y + vec.y, z + vec.z)) {
|
||||
breakBlock(nullptr, def, x, y, z);
|
||||
return;
|
||||
if (def.rt.extended) {
|
||||
auto origin = blocks_agent::seek_origin(chunks, {x, y, z}, def, vox->state);
|
||||
if (!blocks_agent::check_grounding(chunks, def, vox->state.rotation, origin)) {
|
||||
breakBlock(nullptr, def, origin.x, origin.y, origin.z);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (!blocks_agent::check_grounding(chunks, def, vox->state.rotation, {x, y, z})) {
|
||||
breakBlock(nullptr, def, x, y, z);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (def.rt.funcsset.update) {
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include "scripting/scripting.hpp"
|
||||
#include "settings.hpp"
|
||||
#include "voxels/Block.hpp"
|
||||
#include "voxels/blocks_agent.hpp"
|
||||
#include "voxels/Chunks.hpp"
|
||||
#include "voxels/voxel.hpp"
|
||||
#include "window/Camera.hpp"
|
||||
|
|
@ -252,18 +253,18 @@ void PlayerController::onFootstep(const Hitbox& hitbox) {
|
|||
}
|
||||
|
||||
void PlayerController::updateFootsteps(float delta) {
|
||||
const float pi = glm::pi<float>();
|
||||
constexpr float GLM_PI = glm::pi<float>();
|
||||
auto hitbox = player.getHitbox();
|
||||
if (hitbox && hitbox->grounded) {
|
||||
const glm::vec3& vel = hitbox->velocity;
|
||||
float f = glm::length(glm::vec2(vel.x, vel.z));
|
||||
stepsTimer += delta * f * STEPS_SPEED;
|
||||
if (stepsTimer >= pi) {
|
||||
stepsTimer = fmod(stepsTimer, pi);
|
||||
if (stepsTimer >= GLM_PI) {
|
||||
stepsTimer = fmod(stepsTimer, GLM_PI);
|
||||
onFootstep(*hitbox);
|
||||
}
|
||||
} else {
|
||||
stepsTimer = pi;
|
||||
stepsTimer = GLM_PI;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -448,10 +449,7 @@ void PlayerController::processRightClick(
|
|||
return;
|
||||
}
|
||||
if (def.grounded) {
|
||||
const auto& vec = get_ground_direction(def, state.rotation);
|
||||
if (!chunks.isSolidBlock(
|
||||
coord.x + vec.x, coord.y + vec.y, coord.z + vec.z
|
||||
)) {
|
||||
if (!blocks_agent::check_grounding(chunks, def, state.rotation, coord)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -556,6 +554,6 @@ void PlayerController::updateInteraction(const Input& inputEvents, float delta)
|
|||
}
|
||||
}
|
||||
|
||||
Player* PlayerController::getPlayer() {
|
||||
return &player;
|
||||
Player& PlayerController::getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,5 +89,5 @@ public:
|
|||
void postUpdate(
|
||||
float delta, int windowHeight, const Input* inputEvents, bool pause
|
||||
);
|
||||
Player* getPlayer();
|
||||
Player& getPlayer();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,16 +1,17 @@
|
|||
#include "api_lua.hpp"
|
||||
|
||||
#include "../usertypes/lua_type_canvas.hpp"
|
||||
#include "assets/Assets.hpp"
|
||||
#include "assets/AssetsLoader.hpp"
|
||||
#include "coders/obj.hpp"
|
||||
#include "coders/png.hpp"
|
||||
#include "coders/vcm.hpp"
|
||||
#include "debug/Logger.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "graphics/commons/Model.hpp"
|
||||
#include "graphics/core/Texture.hpp"
|
||||
#include "graphics/core/Atlas.hpp"
|
||||
#include "graphics/core/Texture.hpp"
|
||||
#include "util/Buffer.hpp"
|
||||
#include "../usertypes/lua_type_canvas.hpp"
|
||||
|
||||
using namespace scripting;
|
||||
|
||||
|
|
@ -76,6 +77,11 @@ static int l_parse_model(lua::State* L) {
|
|||
skeletonName = lua::require_string(L, 4);
|
||||
}
|
||||
|
||||
if (format == "obj") {
|
||||
assets.store(obj::parse(name, string), name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (format != "xml" && format != "vcm") {
|
||||
throw std::runtime_error(
|
||||
"unknown format " + util::quote(std::string(format))
|
||||
|
|
|
|||
|
|
@ -246,11 +246,12 @@ static int l_get_user_bits(lua::State* L) {
|
|||
}
|
||||
|
||||
static int l_get_variant(lua::State* L) {
|
||||
auto& chunks = *level->chunks;
|
||||
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);
|
||||
auto vox = blocks_agent::get(chunks, x, y, z);
|
||||
if (vox == nullptr) {
|
||||
return lua::pushinteger(L, 0);
|
||||
}
|
||||
|
|
@ -258,6 +259,13 @@ static int l_get_variant(lua::State* L) {
|
|||
if (def.variants == nullptr) {
|
||||
return lua::pushinteger(L, 0);
|
||||
}
|
||||
if (def.rt.extended) {
|
||||
auto origin = blocks_agent::seek_origin(chunks, {x, y, z}, def, vox->state);
|
||||
vox = blocks_agent::get(chunks, origin.x, origin.y, origin.z);
|
||||
if (vox == nullptr) {
|
||||
return lua::pushinteger(L, 0);
|
||||
}
|
||||
}
|
||||
return lua::pushinteger(
|
||||
L, (vox->state.userbits >> def.variants->offset) & def.variants->mask
|
||||
);
|
||||
|
|
@ -290,6 +298,14 @@ static int l_set_user_bits(lua::State* L) {
|
|||
if (vox == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
int ocx = floordiv<CHUNK_W>(origin.x);
|
||||
int ocz = floordiv<CHUNK_D>(origin.z);
|
||||
if (cx != ocx || cz != ocz) {
|
||||
chunk = blocks_agent::get_chunk(chunks, ocx, ocz);
|
||||
if (chunk == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
vox->state.userbits = (vox->state.userbits & (~mask)) | value;
|
||||
chunk->setModifiedAndUnsaved();
|
||||
|
|
@ -318,8 +334,8 @@ static int l_set_variant(lua::State* L) {
|
|||
}
|
||||
|
||||
auto offset = def.variants->offset;
|
||||
auto mask = def.variants->mask;
|
||||
auto value = (lua::tointeger(L, 4) << offset) & mask;
|
||||
auto mask = def.variants->mask << offset;
|
||||
auto value = (lua::tointeger(L, 4) << offset);
|
||||
|
||||
if (def.rt.extended) {
|
||||
auto origin = blocks_agent::seek_origin(chunks, {x, y, z}, def, vox->state);
|
||||
|
|
@ -327,6 +343,14 @@ static int l_set_variant(lua::State* L) {
|
|||
if (vox == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
int ocx = floordiv<CHUNK_W>(origin.x);
|
||||
int ocz = floordiv<CHUNK_D>(origin.z);
|
||||
if (cx != ocx || cz != ocz) {
|
||||
chunk = blocks_agent::get_chunk(chunks, ocx, ocz);
|
||||
if (chunk == nullptr) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
vox->state.userbits = (vox->state.userbits & (~mask)) | value;
|
||||
chunk->setModifiedAndUnsaved();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue