mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 11:01:49 +00:00
Merge branch 'main' into animation
This commit is contained in:
commit
7c06a74244
67 changed files with 1231 additions and 260 deletions
|
|
@ -166,8 +166,7 @@ std::optional<Entities::RaycastResult> Entities::rayCast(
|
|||
glm::vec3 start,
|
||||
glm::vec3 dir,
|
||||
float maxDistance,
|
||||
entityid_t ignore,
|
||||
bool solidOnly
|
||||
const RaycastSettings& settings
|
||||
) {
|
||||
Ray ray(start, dir);
|
||||
auto view = registry->view<EntityId, Transform, Rigidbody>();
|
||||
|
|
@ -176,10 +175,18 @@ std::optional<Entities::RaycastResult> Entities::rayCast(
|
|||
glm::ivec3 foundNormal;
|
||||
|
||||
for (auto [entity, eid, transform, body] : view.each()) {
|
||||
if (eid.uid == ignore || !body.enabled || (solidOnly && !eid.def.solid)) {
|
||||
if (eid.uid == settings.ignoredUid || !body.enabled ||
|
||||
(settings.solidEntitiesOnly && !eid.def.solid)) {
|
||||
continue;
|
||||
}
|
||||
auto& hitbox = body.hitbox;
|
||||
if (settings.entitiesFilter) {
|
||||
bool matches = settings.entitiesFilter->find(eid.def.rt.id) !=
|
||||
settings.entitiesFilter->end();
|
||||
if (matches == settings.entityFilterExcludeMode) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
const auto& hitbox = body.hitbox;
|
||||
glm::ivec3 normal;
|
||||
double distance;
|
||||
if (ray.intersectAABB(
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "constants.hpp"
|
||||
#include "physics/Hitbox.hpp"
|
||||
#include "Transform.hpp"
|
||||
#include "Rigidbody.hpp"
|
||||
|
|
@ -46,12 +47,6 @@ class Entities final {
|
|||
);
|
||||
void preparePhysics(float delta);
|
||||
public:
|
||||
struct RaycastResult {
|
||||
entityid_t entity;
|
||||
glm::ivec3 normal;
|
||||
float distance;
|
||||
};
|
||||
|
||||
Entities(Level& level);
|
||||
|
||||
~Entities();
|
||||
|
|
@ -82,20 +77,33 @@ public:
|
|||
|
||||
std::optional<Entity> get(entityid_t id);
|
||||
|
||||
struct RaycastSettings {
|
||||
/// @param ignore Ignored entity uid
|
||||
entityid_t ignoredUid;
|
||||
/// @param solidEntitiesOnly If true, only entities with solid hitboxes
|
||||
/// will be checked
|
||||
bool solidEntitiesOnly = false;
|
||||
bool entityFilterExcludeMode = false;
|
||||
const std::set<entitydefid_t>* entitiesFilter = nullptr;
|
||||
};
|
||||
|
||||
struct RaycastResult {
|
||||
entityid_t entity;
|
||||
glm::ivec3 normal;
|
||||
float distance;
|
||||
};
|
||||
|
||||
/// @brief Entities raycast. No blocks check included, use combined with
|
||||
/// Chunks.rayCast
|
||||
/// @param start Ray start
|
||||
/// @param dir Ray direction normalized vector
|
||||
/// @param maxDistance Max ray length
|
||||
/// @param ignore Ignored entity ID
|
||||
/// @param solidOnly If true, only entities with solid hitboxes will be checked
|
||||
/// @return An optional structure containing entity, normal and distance
|
||||
std::optional<RaycastResult> rayCast(
|
||||
glm::vec3 start,
|
||||
glm::vec3 dir,
|
||||
float maxDistance,
|
||||
entityid_t ignore = -1,
|
||||
bool solidOnly = false
|
||||
const RaycastSettings& settings
|
||||
);
|
||||
|
||||
void loadEntities(dv::value map);
|
||||
|
|
|
|||
|
|
@ -113,6 +113,11 @@ int64_t Entity::getPlayer() const {
|
|||
}
|
||||
|
||||
void Entity::setPlayer(int64_t id) {
|
||||
registry.get<EntityId>(entity).player = id;
|
||||
auto& eid = registry.get<EntityId>(entity);
|
||||
if (eid.player == id) {
|
||||
return;
|
||||
}
|
||||
eid.player = id;
|
||||
scripting::on_entity_player_set(*this, id);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ void Player::updateEntity() {
|
|||
}
|
||||
}
|
||||
|
||||
Hitbox* Player::getHitbox() {
|
||||
Hitbox* Player::getHitbox() const {
|
||||
if (auto entity = level.entities->get(eid)) {
|
||||
return &entity->getRigidbody().hitbox;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ public:
|
|||
|
||||
bool isCurrentCameraBuiltin() const;
|
||||
|
||||
Hitbox* getHitbox();
|
||||
Hitbox* getHitbox() const;
|
||||
|
||||
void setSpawnPoint(glm::vec3 point);
|
||||
glm::vec3 getSpawnPoint() const;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ struct EntityFuncsSet {
|
|||
bool on_aim_off;
|
||||
bool on_attacked;
|
||||
bool on_used;
|
||||
bool on_player_set;
|
||||
};
|
||||
|
||||
struct UserComponent {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue