player.get_selected_block
This commit is contained in:
parent
29ca6e969c
commit
74042b5c2a
@ -2,8 +2,6 @@
|
||||
#define CODERS_TOML_HPP_
|
||||
|
||||
#include "../data/dynamic.hpp"
|
||||
#include "commons.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
class SettingsHandler;
|
||||
|
||||
@ -25,11 +25,11 @@ public:
|
||||
enum class DependencyLevel {
|
||||
required, // dependency must be installed
|
||||
optional, // dependency will be installed if found
|
||||
weak, // dependency will not be installed automatically
|
||||
weak, // only affects packs order
|
||||
};
|
||||
|
||||
|
||||
/// @brief Content-pack that should be installed before the dependent
|
||||
/// @brief Content-pack that should be installed earlier the dependent
|
||||
struct DependencyPack {
|
||||
DependencyLevel level;
|
||||
std::string id;
|
||||
|
||||
@ -44,7 +44,7 @@ void Logger::log(LogLevel level, const std::string& name, std::string message) {
|
||||
auto ms = duration_cast<milliseconds>(system_clock::now().time_since_epoch()) % 1000;
|
||||
ss << " " << std::put_time(std::localtime(&tm), "%Y/%m/%d %T");
|
||||
ss << '.' << std::setfill('0') << std::setw(3) << ms.count();
|
||||
ss << utcOffset << " (" << std::setfill(' ') << std::setw(moduleLen) << name << ") ";
|
||||
ss << utcOffset << " [" << std::setfill(' ') << std::setw(moduleLen) << name << "] ";
|
||||
ss << message;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
@ -20,7 +20,7 @@ namespace files {
|
||||
std::ifstream file;
|
||||
size_t filelength;
|
||||
public:
|
||||
rafile(std::filesystem::path filename);
|
||||
rafile(fs::path filename);
|
||||
|
||||
void seekg(std::streampos pos);
|
||||
void read(char* buffer, std::streamsize size);
|
||||
|
||||
@ -79,8 +79,12 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
if (def) {
|
||||
stream << L" (" << util::str2wstr_utf8(def->name) << L")";
|
||||
}
|
||||
if (player->selectedVoxel.id == BLOCK_VOID) {
|
||||
return std::wstring {L"block: none"};
|
||||
} else {
|
||||
return L"block: "+std::to_wstring(player->selectedVoxel.id)+
|
||||
L" "+stream.str();
|
||||
}
|
||||
}));
|
||||
panel->add(create_label([=](){
|
||||
return L"seed: "+std::to_wstring(level->getWorld()->getSeed());
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
#include "../../typedefs.hpp"
|
||||
#include "ImageData.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
class Texture {
|
||||
|
||||
@ -194,7 +194,7 @@ void WorldRenderer::renderBlockSelection(Camera* camera, Shader* linesShader) {
|
||||
auto indices = level->content->getIndices();
|
||||
blockid_t id = PlayerController::selectedBlockId;
|
||||
auto block = indices->getBlockDef(id);
|
||||
const glm::vec3 pos = PlayerController::selectedBlockPosition;
|
||||
const glm::ivec3 pos = player->selectedBlockPosition;
|
||||
const glm::vec3 point = PlayerController::selectedPointPosition;
|
||||
const glm::vec3 norm = PlayerController::selectedBlockNormal;
|
||||
|
||||
@ -206,7 +206,7 @@ void WorldRenderer::renderBlockSelection(Camera* camera, Shader* linesShader) {
|
||||
linesShader->uniformMatrix("u_projview", camera->getProjView());
|
||||
lineBatch->lineWidth(2.0f);
|
||||
for (auto& hitbox: hitboxes) {
|
||||
const glm::vec3 center = pos + hitbox.center();
|
||||
const glm::vec3 center = glm::vec3(pos) + hitbox.center();
|
||||
const glm::vec3 size = hitbox.size();
|
||||
lineBatch->box(center, size + glm::vec3(0.02), glm::vec4(0.f, 0.f, 0.f, 0.5f));
|
||||
if (player->debug) {
|
||||
|
||||
@ -166,7 +166,6 @@ void CameraControl::update(const PlayerInput& input, float delta, Chunks* chunks
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 PlayerController::selectedBlockPosition;
|
||||
glm::vec3 PlayerController::selectedPointPosition;
|
||||
glm::ivec3 PlayerController::selectedBlockNormal;
|
||||
int PlayerController::selectedBlockId = -1;
|
||||
@ -362,11 +361,11 @@ void PlayerController::updateInteraction(){
|
||||
maxDistance,
|
||||
end, norm, iend
|
||||
);
|
||||
if (vox != nullptr){
|
||||
if (vox != nullptr) {
|
||||
player->selectedVoxel = *vox;
|
||||
selectedBlockId = vox->id;
|
||||
selectedBlockRotation = vox->rotation();
|
||||
selectedBlockPosition = iend;
|
||||
player->selectedBlockPosition = iend;
|
||||
selectedPointPosition = end;
|
||||
selectedBlockNormal = norm;
|
||||
int x = iend.x;
|
||||
@ -443,6 +442,7 @@ void PlayerController::updateInteraction(){
|
||||
} else {
|
||||
selectedBlockId = -1;
|
||||
selectedBlockRotation = 0;
|
||||
player->selectedVoxel.id = BLOCK_VOID;
|
||||
}
|
||||
if (rclick) {
|
||||
if (item->rt.funcsset.on_use) {
|
||||
|
||||
@ -77,7 +77,6 @@ class PlayerController {
|
||||
void onFootstep();
|
||||
void updateFootsteps(float delta);
|
||||
public:
|
||||
static glm::vec3 selectedBlockPosition;
|
||||
static glm::ivec3 selectedBlockNormal;
|
||||
static glm::vec3 selectedPointPosition;
|
||||
static int selectedBlockId;
|
||||
|
||||
@ -132,6 +132,20 @@ static int l_player_set_noclip(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int l_player_get_selected_block(lua_State* L) {
|
||||
if (auto player = get_player(L, 1)) {
|
||||
if (player->selectedVoxel.id == BLOCK_VOID) {
|
||||
return 0;
|
||||
}
|
||||
const glm::ivec3 pos = player->selectedBlockPosition;
|
||||
lua_pushinteger(L, pos.x);
|
||||
lua_pushinteger(L, pos.y);
|
||||
lua_pushinteger(L, pos.z);
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg playerlib [] = {
|
||||
{"get_pos", lua_wrap_errors<l_player_get_pos>},
|
||||
{"set_pos", lua_wrap_errors<l_player_set_pos>},
|
||||
@ -144,5 +158,6 @@ const luaL_Reg playerlib [] = {
|
||||
{"set_flight", lua_wrap_errors<l_player_set_flight>},
|
||||
{"is_noclip", lua_wrap_errors<l_player_is_noclip>},
|
||||
{"set_noclip", lua_wrap_errors<l_player_set_noclip>},
|
||||
{"get_selected_block", lua_wrap_errors<l_player_get_selected_block>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -46,6 +46,7 @@ public:
|
||||
bool debug = false;
|
||||
voxel selectedVoxel {0, 0};
|
||||
glm::vec3 cam {};
|
||||
glm::ivec3 selectedBlockPosition {};
|
||||
|
||||
Player(glm::vec3 position, float speed, std::shared_ptr<Inventory> inv);
|
||||
~Player();
|
||||
|
||||
@ -57,7 +57,7 @@ struct GraphicsSettings {
|
||||
/// 1.0 is linear, 2.0 is quadratic
|
||||
NumberSetting fogCurve {1.6f, 1.0f, 6.0f};
|
||||
/// @brief Lighting gamma
|
||||
NumberSetting gamma {1.0f, 0.5f, 2.0f};
|
||||
NumberSetting gamma {1.0f, 0.4f, 1.0f};
|
||||
/// @brief Enable blocks backlight to prevent complete darkness
|
||||
FlagSetting backlight {true};
|
||||
/// @brief Enable chunks frustum culling
|
||||
|
||||
@ -12,7 +12,6 @@
|
||||
#include "../voxels/Chunk.hpp"
|
||||
#include "../voxels/Chunks.hpp"
|
||||
#include "../voxels/ChunksStorage.hpp"
|
||||
#include "../window/Camera.hpp"
|
||||
#include "../world/WorldGenerators.hpp"
|
||||
|
||||
#include <memory>
|
||||
@ -135,7 +134,6 @@ std::unique_ptr<Level> World::load(
|
||||
}
|
||||
}
|
||||
}
|
||||
(void)world.release();
|
||||
return level;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user