diff --git a/src/logic/PlayerController.cpp b/src/logic/PlayerController.cpp index 6d5c168a1..9d515d533 100644 --- a/src/logic/PlayerController.cpp +++ b/src/logic/PlayerController.cpp @@ -498,11 +498,11 @@ void PlayerController::processRightClick( void PlayerController::updateEntityInteraction( entityid_t eid, bool lclick, bool rclick ) { - auto entityOpt = level.entities->get(eid); - if (!entityOpt.has_value()) { + auto entityPtr = level.entities->get(eid); + if (entityPtr == nullptr) { return; } - auto entity = *entityOpt; + const auto& entity = *entityPtr; if (lclick) { scripting::on_attacked(entity, &player, player.getEntity()); } diff --git a/src/logic/scripting/lua/libs/libentity.cpp b/src/logic/scripting/lua/libs/libentity.cpp index 879614da8..02e66991b 100644 --- a/src/logic/scripting/lua/libs/libentity.cpp +++ b/src/logic/scripting/lua/libs/libentity.cpp @@ -28,7 +28,7 @@ static const EntityDef* require_entity_def(lua::State* L) { } static int l_exists(lua::State* L) { - return lua::pushboolean(L, get_entity(L, 1).has_value()); + return lua::pushboolean(L, get_entity(L, 1) != nullptr); } static int l_def_index(lua::State* L) { @@ -138,8 +138,7 @@ static int l_get_all_in_box(lua::State* L) { auto found = level->entities->getAllInside(AABB(pos, pos + size)); lua::createtable(L, found.size(), 0); for (size_t i = 0; i < found.size(); i++) { - const auto& entity = found[i]; - lua::pushinteger(L, entity.getUID()); + lua::pushinteger(L, found[i]->getUID()); lua::rawseti(L, i + 1); } return 1; @@ -151,8 +150,7 @@ static int l_get_all_in_radius(lua::State* L) { auto found = level->entities->getAllInRadius(pos, radius); lua::createtable(L, found.size(), 0); for (size_t i = 0; i < found.size(); i++) { - const auto& entity = found[i]; - lua::pushinteger(L, entity.getUID()); + lua::pushinteger(L, found[i]->getUID()); lua::rawseti(L, i + 1); } return 1; diff --git a/src/logic/scripting/lua/libs/libentity.hpp b/src/logic/scripting/lua/libs/libentity.hpp index 5400b449a..77baeca69 100644 --- a/src/logic/scripting/lua/libs/libentity.hpp +++ b/src/logic/scripting/lua/libs/libentity.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #include "frontend/hud.hpp" #include "objects/Entities.hpp" #include "objects/Entity.hpp" @@ -13,7 +11,7 @@ namespace scripting { extern Hud* hud; } -inline std::optional get_entity(lua::State* L, int idx) { +inline Entity* get_entity(lua::State* L, int idx) { auto id = lua::tointeger(L, idx); auto level = scripting::controller->getLevel(); return level->entities->get(id); diff --git a/src/objects/Entities.cpp b/src/objects/Entities.cpp index b0027fb68..a1d560799 100644 --- a/src/objects/Entities.cpp +++ b/src/objects/Entities.cpp @@ -20,7 +20,6 @@ #include "physics/PhysicsSolver.hpp" #include "world/Level.hpp" -#include #include #include #include @@ -28,8 +27,7 @@ static debug::Logger logger("entities"); Entities::Entities(Level& level) - : registry(std::make_unique()), - level(level), + : level(level), sensorsTickClock(20, 3), updateTickClock(20, 3) { } @@ -40,12 +38,12 @@ void Entities::setAssets(Assets& assets) { this->assets = &assets; } -std::optional Entities::get(entityid_t id) { +Entity* Entities::get(entityid_t id) { const auto& found = entities.find(id); - if (found != entities.end() && registry->valid(found->second)) { - return Entity(*this, id, *registry, found->second); + if (found != entities.end()) { + return found->second.get(); } - return std::nullopt; + return nullptr; } entityid_t Entities::spawn( @@ -81,33 +79,30 @@ entityid_t Entities::spawn( throw std::runtime_error(ss.str()); } } - auto entity = registry->create(); - entities[id] = entity; - uids[entity] = id; - - registry->emplace(entity, id, def); - const auto& tsf = registry->emplace( - entity, - position, - glm::vec3(1.0f), - glm::mat3(1.0f), - glm::mat4(1.0f), - true - ); - auto& body = registry->emplace( - entity, - true, - Hitbox {id, def.bodyType, position, def.hitbox * 0.5f}, - std::vector {} - ); - body.initialize(def, id, *this); - - auto& scripting = registry->emplace(entity); + std::unique_ptr skeletonInstance; if (assets) { - registry->emplace( - entity, skeleton ? skeleton->instance() : rigging::Skeleton(nullptr) + skeletonInstance = std::make_unique( + skeleton ? skeleton->instance() : rigging::Skeleton(nullptr) ); } + auto& entity = *(entities[id] = std::make_unique( + *this, + EntityId {id, def}, + Transform { + position, glm::vec3(1.0f), glm::mat3(1.0f), glm::mat4(1.0f), true + }, + Rigidbody { + true, + Hitbox {id, def.bodyType, position, def.hitbox * 0.5f}, + std::vector {} + }, + std::move(skeletonInstance) + )); + const auto& tsf = entity.getTransform(); + auto& body = entity.getRigidbody(); + body.initialize(def, id, *this); + + auto& scripting = entity.getScripting(); for (auto& instance : def.components) { auto component = std::make_unique( @@ -118,7 +113,7 @@ entityid_t Entities::spawn( dv::value componentsMap = nullptr; if (saved != nullptr) { componentsMap = saved["comps"]; - loadEntity(saved, get(id).value()); + loadEntity(saved, entity); } body.hitbox.position = tsf.pos; scripting::on_entity_spawn( @@ -144,7 +139,7 @@ void Entities::loadEntity(const dv::value& map) { spawn(def, {}, nullptr, map, uid); } -void Entities::loadEntity(const dv::value& map, Entity entity) { +void Entities::loadEntity(const dv::value& map, Entity& entity) { auto& transform = entity.getTransform(); auto& body = entity.getRigidbody(); auto skeleton = entity.getSkeleton(); @@ -175,12 +170,12 @@ std::optional Entities::rayCast( const RaycastSettings& settings ) { Ray ray(start, dir); - auto view = registry->view(); - entityid_t foundUID = 0; glm::ivec3 foundNormal; - for (auto [entity, eid, transform, body] : view.each()) { + for (const auto& [uid, entity] : entities) { + const auto& eid = entity->getID(); + const auto& body = entity->getRigidbody(); const auto& hitbox = body.hitbox; if (eid.uid == settings.ignoredUid || !body.enabled || (settings.solidEntitiesOnly && !eid.def.solid) || @@ -227,40 +222,38 @@ void Entities::onSave(const Entity& entity) { scripting::on_entity_save(entity); } -dv::value Entities::serialize(const std::vector& entities) { +dv::value Entities::serialize(const std::vector& entities) { auto list = dv::list(); - for (auto& entity : entities) { - const EntityId& eid = entity.getID(); - if (!entity.getDef().save.enabled || eid.destroyFlag) { + for (auto entity : entities) { + const EntityId& eid = entity->getID(); + if (!entity->getDef().save.enabled || eid.destroyFlag) { continue; } - level.entities->onSave(entity); + level.entities->onSave(*entity); if (!eid.destroyFlag) { - list.add(entity.serialize()); + list.add(entity->serialize()); } } return list; } -void Entities::despawn(std::vector entities) { - for (auto& entity : entities) { - entity.destroy(); +void Entities::despawn(const std::vector& entities) { + for (auto entity : entities) { + entity->destroy(); } } void Entities::clean() { for (auto it = entities.begin(); it != entities.end();) { - if (!registry->get(it->second).destroyFlag) { + if (!it->second->getID().destroyFlag) { ++it; } else { - auto& rigidbody = registry->get(it->second); + auto& rigidbody = it->second->getRigidbody(); // todo: refactor auto physics = level.physics.get(); for (auto& sensor : rigidbody.sensors) { physics->removeSensor(&sensor); } - uids.erase(it->second); - registry->destroy(it->second); it = entities.erase(it); } } @@ -309,15 +302,16 @@ void Entities::preparePhysics(float delta) { auto part = sensorsTickClock.convertPart(i); auto allParts = sensorsTickClock.getParts(); - auto view = registry->view(); - for (auto [entity, eid, transform, rigidbody] : view.each()) { + for (const auto& [uid, entity] : entities) { + const auto& eid = entity->getID(); + auto& rigidbody = entity->getRigidbody(); if (!rigidbody.enabled) { continue; } if ((eid.uid + part) % allParts != 0) { continue; } - updateSensors(rigidbody, transform, sensors); + updateSensors(rigidbody, entity->getTransform(), sensors); } } } @@ -325,8 +319,9 @@ void Entities::preparePhysics(float delta) { hitboxes.clear(); solidHitboxes.clear(); - auto view = registry->view(); - for (auto [entity, eid, rigidbody] : view.each()) { + for (const auto& [uid, entity] : entities) { + const auto& eid = entity->getID(); + auto& rigidbody = entity->getRigidbody(); auto bodyType = rigidbody.hitbox.type; if (eid.destroyFlag || !rigidbody.enabled) { continue; @@ -350,13 +345,15 @@ void Entities::preparePhysics(float delta) { void Entities::updatePhysics(float delta) { preparePhysics(delta); - auto view = registry->view(); auto physics = level.physics.get(); int substeps = std::max(std::min(delta * 1000, 200), 8); physics->step(*level.chunks, delta, substeps); - for (auto [entity, eid, transform, rigidbody] : view.each()) { + for (const auto& [uid, entity] : entities) { + const auto& eid = entity->getID(); + auto& transform = entity->getTransform(); + auto& rigidbody = entity->getRigidbody(); if (!rigidbody.enabled || rigidbody.hitbox.type == BodyType::STATIC) { continue; @@ -373,11 +370,11 @@ void Entities::updatePhysics(float delta) { } if (hitbox.grounded && !hitbox.prevGrounded) { scripting::on_entity_grounded( - *get(eid.uid), glm::length(hitbox.prevVelocity - hitbox.velocity) + *entity, glm::length(hitbox.prevVelocity - hitbox.velocity) ); } if (!hitbox.grounded && hitbox.prevGrounded) { - scripting::on_entity_fall(*get(eid.uid)); + scripting::on_entity_fall(*entity); } } } @@ -395,8 +392,12 @@ void Entities::update(float delta) { updatePhysics(delta); scripting::on_entities_physics_update(delta); - auto view = registry->view(); - for (auto [entity, transform, skeleton] : view.each()) { + for (const auto& [uid, entity] : entities) { + if (!entity->getSkeleton()) { + continue; + } + auto& transform = entity->getTransform(); + auto& skeleton = *entity->getSkeleton(); if (transform.dirty) { transform.refresh(); } @@ -457,8 +458,13 @@ void Entities::renderDebug( { auto ctx = pctx.sub(&batch); ctx.setLineWidth(1); - auto view = registry->view(); - for (auto [entity, transform, rigidbody, skeleton] : view.each()) { + for (const auto& [uid, entity] : entities) { + if (!entity->getSkeleton()) { + continue; + } + const auto& transform = entity->getTransform(); + const auto& rigidbody = entity->getRigidbody(); + const auto& skeleton = *entity->getSkeleton(); const auto& hitbox = rigidbody.hitbox; if (frustum && !check_frustum(*frustum, transform, rigidbody, skeleton)) { continue; @@ -481,15 +487,17 @@ void Entities::renderDebug( } } { - auto view = registry->view(); auto ctx = pctx.sub(&batch); ctx.setDepthTest(false); ctx.setDepthMask(false); ctx.setLineWidth(2); - for (auto [entity, eid, transform, rigidbody, skeleton] : view.each()) { - if (eid.uid == fpsEntity) { + for (const auto& [uid, entity] : entities) { + if (!entity->getSkeleton() || uid == fpsEntity) { continue; } + const auto& transform = entity->getTransform(); + const auto& rigidbody = entity->getRigidbody(); + const auto& skeleton = *entity->getSkeleton(); auto config = skeleton.config; if (config == nullptr) { continue; @@ -509,12 +517,14 @@ void Entities::render( const Frustum* frustum, entityid_t fpsEntity ) { - auto view = registry->view(); - for (auto [entity, eid, transform, skeleton, rigidbody] : view.each()) { - if (eid.uid == fpsEntity) { + for (const auto& [uid, entity] : entities) { + if (!entity->getSkeleton() || uid == fpsEntity) { continue; } - const auto& def = eid.def; + const auto& transform = entity->getTransform(); + const auto& rigidbody = entity->getRigidbody(); + auto& skeleton = *entity->getSkeleton(); + const auto& def = entity->getID().def; const auto& pos = transform.pos; const auto& size = transform.size; const auto& rigConfig = skeleton.config; @@ -544,58 +554,48 @@ void Entities::render( } void Entities::updateCulling(const Frustum* frustum, entityid_t fpsEntity) { - auto view = registry->view(); - for (auto [entity, eid, transform, skeleton, rigidbody] : view.each()) { - if (frustum == nullptr || eid.uid == fpsEntity) { + for (const auto& [uid, entity] : entities) { + if (!entity->getSkeleton()) { + continue; + } + auto& skeleton = *entity->getSkeleton(); + if (frustum == nullptr || uid == fpsEntity) { skeleton.culled = false; continue; } - skeleton.culled = !check_frustum(*frustum, transform, rigidbody, skeleton); + skeleton.culled = !check_frustum( + *frustum, entity->getTransform(), entity->getRigidbody(), skeleton + ); } } bool Entities::hasBlockingInside(AABB aabb) { constexpr float eps = 0.05f; - auto view = registry->view(); - for (auto [entity, eid, body] : view.each()) { - AABB bodyAABB(body.hitbox.getAABB()); + for (const auto& [uid, entity] : entities) { + AABB bodyAABB(entity->getRigidbody().hitbox.getAABB()); bodyAABB.scale(glm::vec3(1.0f - eps)); - if (eid.def.blocking && aabb.intersects(bodyAABB)) { + if (entity->getID().def.blocking && aabb.intersects(bodyAABB)) { return true; } } return false; } -std::vector Entities::getAllInside(AABB aabb) { - std::vector collected; - auto view = registry->view(); - for (auto [entity, eid, transform] : view.each()) { - if (!eid.destroyFlag && aabb.contains(transform.pos)) { - const auto& found = uids.find(entity); - if (found == uids.end()) { - continue; - } - if (auto wrapper = get(found->second)) { - collected.push_back(*wrapper); - } +std::vector Entities::getAllInside(AABB aabb) { + std::vector collected; + for (const auto& [uid, entity] : entities) { + if (!entity->getID().destroyFlag && aabb.contains(entity->getTransform().pos)) { + collected.push_back(entity.get()); } } return collected; } -std::vector Entities::getAllInRadius(glm::vec3 center, float radius) { - std::vector collected; - auto view = registry->view(); - for (auto [entity, transform] : view.each()) { - if (glm::distance2(transform.pos, center) <= radius * radius) { - const auto& found = uids.find(entity); - if (found == uids.end()) { - continue; - } - if (auto wrapper = get(found->second)) { - collected.push_back(*wrapper); - } +std::vector Entities::getAllInRadius(glm::vec3 center, float radius) { + std::vector collected; + for (const auto& [uid, entity] : entities) { + if (glm::distance2(entity->getTransform().pos, center) <= radius * radius) { + collected.push_back(entity.get()); } } return collected; diff --git a/src/objects/Entities.hpp b/src/objects/Entities.hpp index 8b656d2f3..ff203f47d 100644 --- a/src/objects/Entities.hpp +++ b/src/objects/Entities.hpp @@ -6,6 +6,7 @@ #include #include "constants.hpp" +#include "Entity.hpp" #include "physics/Hitbox.hpp" #include "Transform.hpp" #include "Rigidbody.hpp" @@ -13,8 +14,7 @@ #include "typedefs.hpp" #include "util/Clock.hpp" -#include -#include +#include struct EntityDef; @@ -33,10 +33,8 @@ namespace rigging { } class Entities final { - std::unique_ptr registry; Level& level; - std::unordered_map entities; - std::unordered_map uids; + std::map> entities; entityid_t nextID = 1; util::Clock sensorsTickClock; util::Clock updateTickClock; @@ -77,7 +75,7 @@ public: entityid_t uid = 0 ); - std::optional get(entityid_t id); + Entity* get(entityid_t id); struct RaycastSettings { /// @param ignore Ignored entity uid @@ -111,14 +109,14 @@ public: void loadEntities(dv::value map); void loadEntity(const dv::value& map); - void loadEntity(const dv::value& map, Entity entity); + void loadEntity(const dv::value& map, Entity& entity); void onSave(const Entity& entity); bool hasBlockingInside(AABB aabb); - std::vector getAllInside(AABB aabb); - std::vector getAllInRadius(glm::vec3 center, float radius); + std::vector getAllInside(AABB aabb); + std::vector getAllInRadius(glm::vec3 center, float radius); void despawn(entityid_t id); - void despawn(std::vector entities); - dv::value serialize(const std::vector& entities); + void despawn(const std::vector& entities); + dv::value serialize(const std::vector& entities); void setNextID(entityid_t id) { nextID = id; diff --git a/src/objects/Entity.cpp b/src/objects/Entity.cpp index 807e79bd4..a5aa4eeec 100644 --- a/src/objects/Entity.cpp +++ b/src/objects/Entity.cpp @@ -8,58 +8,62 @@ #include "ScriptComponents.hpp" #include "Transform.hpp" -#include - static inline std::string SAVED_DATA_VARNAME = "SAVED_DATA"; +Entity::Entity( + Entities& entities, + EntityId id, + Transform transform, + Rigidbody rigidbody, + std::unique_ptr skeleton +) + : entities(entities), + id(std::move(id)), + transform(std::move(transform)), + rigidbody(std::move(rigidbody)), + skeleton(std::move(skeleton)) { +} + +Entity::~Entity() = default; + void Entity::setInterpolatedPosition(const glm::vec3& position) { - if (auto skeleton = getSkeleton()) { + if (skeleton) { skeleton->interpolation.refresh(position); } } glm::vec3 Entity::getInterpolatedPosition() const { - if (auto skeleton = getSkeleton()) { + if (skeleton) { const auto& interpolation = skeleton->interpolation; if (interpolation.isEnabled() && interpolation.isRefreshed()) { return interpolation.getCurrent(); } } - return getTransform().pos; + return transform.pos; } void Entity::setInterpolatedRotation(const glm::quat& rotation) { - if (auto skeleton = getSkeleton()) { + if (skeleton) { skeleton->rotationInterpolation.refresh(rotation); } } void Entity::destroy() { - if (isValid()) { - entities.despawn(id); - } -} - -rigging::Skeleton* Entity::getSkeleton() const { - return registry.try_get(entity); + entities.despawn(id.uid); } void Entity::setRig(std::shared_ptr rigConfig) { - auto& skeleton = registry.get(entity); - skeleton.setConfig(std::move(rigConfig)); + if (skeleton) { + skeleton->setConfig(std::move(rigConfig)); + } } dv::value Entity::serialize() const { - const auto& eid = getID(); - const auto& def = eid.def; - const auto& transform = getTransform(); - const auto& rigidbody = getRigidbody(); - const auto& scripts = getScripting(); - auto skeleton = getSkeleton(); + const auto& def = id.def; auto root = dv::object(); root["def"] = def.name; - root["uid"] = eid.uid; + root["uid"] = id.uid; root[COMP_TRANSFORM] = transform.serialize(); root[COMP_RIGIDBODY] = @@ -75,9 +79,9 @@ dv::value Entity::serialize() const { ); } } - if (!scripts.components.empty()) { + if (!scripting.components.empty()) { auto& compsMap = root.object("comps"); - for (auto& comp : scripts.components) { + for (auto& comp : scripting.components) { if (comp->env == nullptr) { continue; } @@ -89,45 +93,11 @@ dv::value Entity::serialize() const { return root; } -EntityId& Entity::getID() const { - return registry.get(entity); -} - -bool Entity::isValid() const { - return registry.valid(entity); -} - -Transform& Entity::getTransform() const { - return registry.get(entity); -} - - -ScriptComponents& Entity::getScripting() const { - return registry.get(entity); -} - -const EntityDef& Entity::getDef() const { - return registry.get(entity).def; -} - -Rigidbody& Entity::getRigidbody() const { - return registry.get(entity); -} - -entityid_t Entity::getUID() const { - return registry.get(entity).uid; -} - -int64_t Entity::getPlayer() const { - return registry.get(entity).player; -} - -void Entity::setPlayer(int64_t id) { - auto& eid = registry.get(entity); - if (eid.player == id) { +void Entity::setPlayer(int64_t player) { + if (id.player == player) { return; } - eid.player = id; - scripting::on_entity_player_set(*this, id); + id.player = player; + scripting::on_entity_player_set(*this, player); } diff --git a/src/objects/Entity.hpp b/src/objects/Entity.hpp index 424c2e22b..f7c7c3b5d 100644 --- a/src/objects/Entity.hpp +++ b/src/objects/Entity.hpp @@ -2,17 +2,17 @@ #include "typedefs.hpp" #include "data/dv_fwd.hpp" +#include "Transform.hpp" +#include "Rigidbody.hpp" +#include "ScriptComponents.hpp" +#include #include -#include #include #include class Entities; struct EntityDef; -struct Transform; -struct Rigidbody; -struct ScriptComponents; inline std::string COMP_TRANSFORM = "transform"; inline std::string COMP_RIGIDBODY = "rigidbody"; @@ -32,42 +32,77 @@ struct EntityId { class Entity { Entities& entities; - entityid_t id; - entt::registry& registry; - const entt::entity entity; + EntityId id; + Transform transform; + Rigidbody rigidbody; + ScriptComponents scripting; + std::unique_ptr skeleton; public: Entity( Entities& entities, - entityid_t id, - entt::registry& registry, - const entt::entity entity - ) - : entities(entities), id(id), registry(registry), entity(entity) { - } + EntityId id, + Transform transform, + Rigidbody rigidbody, + std::unique_ptr skeleton + ); + + Entity(const Entity&) = delete; + Entity& operator=(const Entity&) = delete; + + ~Entity(); dv::value serialize() const; - EntityId& getID() const; + EntityId& getID() { + return id; + } + const EntityId& getID() const { + return id; + } - bool isValid() const; + const EntityDef& getDef() const { + return id.def; + } - const EntityDef& getDef() const; + Transform& getTransform() { + return transform; + } + const Transform& getTransform() const { + return transform; + } - Transform& getTransform() const; + Rigidbody& getRigidbody() { + return rigidbody; + } + const Rigidbody& getRigidbody() const { + return rigidbody; + } - Rigidbody& getRigidbody() const; + ScriptComponents& getScripting() { + return scripting; + } + const ScriptComponents& getScripting() const { + return scripting; + } - ScriptComponents& getScripting() const; - - rigging::Skeleton* getSkeleton() const; + rigging::Skeleton* getSkeleton() { + return skeleton.get(); + } + const rigging::Skeleton* getSkeleton() const { + return skeleton.get(); + } void setRig(std::shared_ptr rigConfig); - entityid_t getUID() const; + entityid_t getUID() const { + return id.uid; + } - int64_t getPlayer() const; + int64_t getPlayer() const { + return id.player; + } - void setPlayer(int64_t id); + void setPlayer(int64_t player); void setInterpolatedPosition(const glm::vec3& position); @@ -75,9 +110,5 @@ public: void setInterpolatedRotation(const glm::quat& rotation); - entt::entity getHandler() const { - return entity; - } - void destroy(); }; diff --git a/src/objects/Player.cpp b/src/objects/Player.cpp index bc40fdb86..760b14ef7 100644 --- a/src/objects/Player.cpp +++ b/src/objects/Player.cpp @@ -107,7 +107,7 @@ void Player::updateSelectedEntity() { void Player::postUpdate() { auto entity = level.entities->get(eid); - if (!entity.has_value()) { + if (entity == nullptr) { return; } auto& hitbox = entity->getRigidbody().hitbox; diff --git a/src/objects/Rigidbody.cpp b/src/objects/Rigidbody.cpp index 337bb9f67..eedb0dbc1 100644 --- a/src/objects/Rigidbody.cpp +++ b/src/objects/Rigidbody.cpp @@ -45,9 +45,7 @@ template static sensorcallback create_sensor_callback(Entities& entities) { return [&entities](auto entityid, auto index, auto otherid) { if (auto entity = entities.get(entityid)) { - if (entity->isValid()) { - callback(*entity, index, otherid); - } + callback(*entity, index, otherid); } }; } diff --git a/src/objects/Rigidbody.hpp b/src/objects/Rigidbody.hpp index fb96f138f..4a11d4525 100644 --- a/src/objects/Rigidbody.hpp +++ b/src/objects/Rigidbody.hpp @@ -4,7 +4,6 @@ #include "physics/Hitbox.hpp" #include -#include class Entities; struct EntityDef; @@ -13,9 +12,9 @@ struct Rigidbody { bool enabled = true; Hitbox hitbox; std::vector sensors; - float mass; - float elasticity; - bool selectable; + float mass = 1.0f; + float elasticity = 0.0f; + bool selectable = false; dv::value serialize(bool saveVelocity, bool saveBodySettings) const; void deserialize(const dv::value& root); diff --git a/src/objects/Transform.hpp b/src/objects/Transform.hpp index 8c49d6859..5cea5c83c 100644 --- a/src/objects/Transform.hpp +++ b/src/objects/Transform.hpp @@ -16,8 +16,8 @@ struct Transform { glm::mat4 combined; bool dirty = true; - glm::vec3 displayPos; - glm::vec3 displaySize; + glm::vec3 displayPos {}; + glm::vec3 displaySize {}; dv::value serialize() const; void deserialize(const dv::value& root);