mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-07 12:01:50 +00:00
feat: solid entity material support & minor refactor
This commit is contained in:
parent
01d46b2690
commit
dbc7cd56bd
6 changed files with 91 additions and 63 deletions
|
|
@ -229,26 +229,8 @@ PlayerController::PlayerController(
|
|||
}
|
||||
|
||||
void PlayerController::onFootstep(const Hitbox& hitbox) {
|
||||
const auto& pos = hitbox.position;
|
||||
const auto& half = hitbox.getHalfSize();
|
||||
|
||||
for (int offsetZ = -1; offsetZ <= 1; offsetZ++) {
|
||||
for (int offsetX = -1; offsetX <= 1; offsetX++) {
|
||||
int x = std::floor(pos.x + half.x * offsetX);
|
||||
int y = std::floor(pos.y - half.y * 1.1f);
|
||||
int z = std::floor(pos.z + half.z * offsetZ);
|
||||
auto vox = player.chunks->get(x, y, z);
|
||||
if (vox) {
|
||||
auto& def = level.content.getIndices()->blocks.require(vox->id);
|
||||
if (!def.obstacle) {
|
||||
continue;
|
||||
}
|
||||
blocksController.onBlockInteraction(
|
||||
&player, glm::ivec3(x, y, z), def, BlockInteraction::step
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (footstepCallback) {
|
||||
footstepCallback(hitbox);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -557,3 +539,7 @@ void PlayerController::updateInteraction(const Input& inputEvents, float delta)
|
|||
Player& PlayerController::getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
void PlayerController::setFootstepCallback(FootstepCallback&& callback) {
|
||||
footstepCallback = std::move(callback);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ struct Hitbox;
|
|||
struct CameraSettings;
|
||||
struct EngineSettings;
|
||||
|
||||
using FootstepCallback = std::function<void(const Hitbox&)>;
|
||||
|
||||
class CameraControl {
|
||||
Player& player;
|
||||
std::shared_ptr<Camera> camera;
|
||||
|
|
@ -57,6 +59,7 @@ class PlayerController {
|
|||
CameraControl camControl;
|
||||
BlocksController& blocksController;
|
||||
float interactionTimer = 0.0f;
|
||||
FootstepCallback footstepCallback;
|
||||
|
||||
void updateKeyboard(const Input& inputEvents);
|
||||
void resetKeyboard();
|
||||
|
|
@ -89,5 +92,8 @@ public:
|
|||
void postUpdate(
|
||||
float delta, int windowHeight, const Input* inputEvents, bool pause
|
||||
);
|
||||
|
||||
Player& getPlayer();
|
||||
|
||||
void setFootstepCallback(FootstepCallback&& callback);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue