diff --git a/runtime/World/Components/Terrain.h b/runtime/World/Components/Terrain.h index 9b6211dfa..d0e1dbbef 100644 --- a/runtime/World/Components/Terrain.h +++ b/runtime/World/Components/Terrain.h @@ -66,7 +66,7 @@ namespace Spartan uint32_t GetVertexCount() const { return m_vertex_count; } uint32_t GetIndexCount() const { return m_index_count; } uint64_t GetHeightSampleCount() const { return m_height_samples; } - float* GetHeightData() { return &m_height_data[0]; } + float* GetHeightData() { return !m_height_data.empty() ? &m_height_data[0] : nullptr; } void GenerateAsync(std::function on_complete = nullptr); diff --git a/runtime/World/Entity.cpp b/runtime/World/Entity.cpp index aca130eef..cd8dc431d 100644 --- a/runtime/World/Entity.cpp +++ b/runtime/World/Entity.cpp @@ -303,7 +303,7 @@ namespace Spartan bool Entity::IsActiveRecursively() { - if (Entity* parent = GetParent()) + if (shared_ptr parent = GetParent()) { return m_is_active && parent->IsActiveRecursively(); } @@ -515,7 +515,7 @@ namespace Spartan shared_ptr new_parent = new_parent_in.lock(); shared_ptr parent = m_parent.lock(); - if (!new_parent) + if (new_parent) { // early exit if the parent is this entity if (GetObjectId() == new_parent->GetObjectId()) diff --git a/runtime/World/Entity.h b/runtime/World/Entity.h index b71ed57ff..d60c80bce 100644 --- a/runtime/World/Entity.h +++ b/runtime/World/Entity.h @@ -147,7 +147,7 @@ namespace Spartan bool HasRotationChangedThisFrame() const { return m_rotation_changed_this_frame; } //================================================================================ - //= HIERARCHY ============================================================================= + //= HIERARCHY =================================================================================== void SetParent(std::weak_ptr new_parent); Entity* GetChildByIndex(uint32_t index); Entity* GetChildByName(const std::string& name); @@ -157,13 +157,13 @@ namespace Spartan bool IsDescendantOf(Entity* transform) const; void GetDescendants(std::vector* descendants); Entity* GetDescendantByName(const std::string& name); - bool HasParent() const { return !m_parent.expired(); } - bool HasChildren() const { return GetChildrenCount() > 0 ? true : false; } - uint32_t GetChildrenCount() const { return static_cast(m_children.size()); } - Entity* GetRoot() { return HasParent() ? GetParent()->GetRoot() : this; } - Entity* GetParent() const { return m_parent.lock().get(); } - std::vector& GetChildren() { return m_children; } - //========================================================================================= + bool HasParent() const { return !m_parent.expired(); } + bool HasChildren() const { return GetChildrenCount() > 0 ? true : false; } + uint32_t GetChildrenCount() const { return static_cast(m_children.size()); } + Entity* GetRoot() { return HasParent() ? GetParent()->GetRoot() : this; } + std::shared_ptr GetParent() const { return m_parent.lock(); } + std::vector& GetChildren() { return m_children; } + //=============================================================================================== const Math::Matrix& GetMatrix() const { return m_matrix; } const Math::Matrix& GetLocalMatrix() const { return m_matrix_local; } diff --git a/runtime/World/World.cpp b/runtime/World/World.cpp index 308505a26..1d5854bb1 100644 --- a/runtime/World/World.cpp +++ b/runtime/World/World.cpp @@ -421,14 +421,14 @@ namespace Spartan // remove entities using a single loop m_entities.erase(remove_if(m_entities.begin(), m_entities.end(), - [&](const shared_ptr& entity) - { - return ids_to_remove.count(entity->GetObjectId()) > 0; - }), - m_entities.end()); + [&](const shared_ptr& entity) + { + return ids_to_remove.count(entity->GetObjectId()) > 0; + }), + m_entities.end()); // if there was a parent, update it - if (Entity* parent = entity_to_remove->GetParent()) + if (shared_ptr parent = entity_to_remove->GetParent()) { parent->AcquireChildren(); } @@ -673,29 +673,6 @@ namespace Spartan physics_body->GetCar()->SetSteeringWheelTransform(entity_steering_wheel); } - // remove all the wheels since they have weird rotations, we will add our own - { - World::RemoveEntity(entity_car->GetDescendantByName("FL_Wheel_RimMaterial_0")); - World::RemoveEntity(entity_car->GetDescendantByName("FL_Wheel_Brake Disc_0")); - World::RemoveEntity(entity_car->GetDescendantByName("FL_Wheel_TireMaterial_0")); - World::RemoveEntity(entity_car->GetDescendantByName("FL_Caliper_BrakeCaliper_0")); - - World::RemoveEntity(entity_car->GetDescendantByName("FR_Wheel_RimMaterial_0")); - World::RemoveEntity(entity_car->GetDescendantByName("FR_Wheel_Brake Disc_0")); - World::RemoveEntity(entity_car->GetDescendantByName("FR_Wheel_TireMaterial_0")); - World::RemoveEntity(entity_car->GetDescendantByName("FR_Caliper_BrakeCaliper_0")); - - World::RemoveEntity(entity_car->GetDescendantByName("RL_Wheel_RimMaterial_0")); - World::RemoveEntity(entity_car->GetDescendantByName("RL_Wheel_Brake Disc_0")); - World::RemoveEntity(entity_car->GetDescendantByName("RL_Wheel_TireMaterial_0")); - World::RemoveEntity(entity_car->GetDescendantByName("RL_Caliper_BrakeCaliper_0")); - - World::RemoveEntity(entity_car->GetDescendantByName("RR_Wheel_RimMaterial_0")); - World::RemoveEntity(entity_car->GetDescendantByName("RR_Wheel_Brake Disc_0")); - World::RemoveEntity(entity_car->GetDescendantByName("RR_Wheel_TireMaterial_0")); - World::RemoveEntity(entity_car->GetDescendantByName("RR_Caliper_BrakeCaliper_0")); - } - // load our own wheel if (m_default_model_wheel = ResourceCache::Load("project\\models\\wheel\\model.blend")) { @@ -792,8 +769,34 @@ namespace Spartan } } + // remove all the wheels since they have weird rotations, we will add our own + { + auto entity_car = m_default_model_car->GetRootEntity().lock(); + + World::RemoveEntity(entity_car->GetDescendantByName("FL_Wheel_RimMaterial_0")); + World::RemoveEntity(entity_car->GetDescendantByName("FL_Wheel_Brake Disc_0")); + World::RemoveEntity(entity_car->GetDescendantByName("FL_Wheel_TireMaterial_0")); + World::RemoveEntity(entity_car->GetDescendantByName("FL_Caliper_BrakeCaliper_0")); + + World::RemoveEntity(entity_car->GetDescendantByName("FR_Wheel_RimMaterial_0")); + World::RemoveEntity(entity_car->GetDescendantByName("FR_Wheel_Brake Disc_0")); + World::RemoveEntity(entity_car->GetDescendantByName("FR_Wheel_TireMaterial_0")); + World::RemoveEntity(entity_car->GetDescendantByName("FR_Caliper_BrakeCaliper_0")); + + World::RemoveEntity(entity_car->GetDescendantByName("RL_Wheel_RimMaterial_0")); + World::RemoveEntity(entity_car->GetDescendantByName("RL_Wheel_Brake Disc_0")); + World::RemoveEntity(entity_car->GetDescendantByName("RL_Wheel_TireMaterial_0")); + World::RemoveEntity(entity_car->GetDescendantByName("RL_Caliper_BrakeCaliper_0")); + + World::RemoveEntity(entity_car->GetDescendantByName("RR_Wheel_RimMaterial_0")); + World::RemoveEntity(entity_car->GetDescendantByName("RR_Wheel_Brake Disc_0")); + World::RemoveEntity(entity_car->GetDescendantByName("RR_Wheel_TireMaterial_0")); + World::RemoveEntity(entity_car->GetDescendantByName("RR_Caliper_BrakeCaliper_0")); + + SP_LOG_INFO("Take control: Use the arrow keys to steer the car and space for handbreak!"); + } + Engine::AddFlag(EngineMode::Game); - SP_LOG_INFO("Take control: Use the arrow keys to steer the car and space for handbreak!"); } void World::CreateDefaultWorldForest()