Skip to content
Snippets Groups Projects
Commit 198b80df authored by Sebastian Freitag's avatar Sebastian Freitag
Browse files

Merge branch 'feature/#336_remove_scene_engine_getter' into 'develop'

Feature/#336 remove scene engine getter

See merge request VR-Group/Project_Phoenix!113
parents 871bebe1 bb2241f4
No related branches found
No related tags found
1 merge request!113Feature/#336 remove scene engine getter
...@@ -39,15 +39,15 @@ SUPPRESS_WARNINGS_END ...@@ -39,15 +39,15 @@ SUPPRESS_WARNINGS_END
#include "phx/scene.hpp" #include "phx/scene.hpp"
#include "phx/transform.hpp" #include "phx/transform.hpp"
NavigationBehavior::NavigationBehavior(
phx::DisplaySystemOpenVR* display_system_openvr)
: display_system_openvr_(display_system_openvr) {}
void NavigationBehavior::OnUpdate() { void NavigationBehavior::OnUpdate() {
// If there exists an HMD and a transform. // If there exists an HMD and a transform.
const auto display_system_hmd = GetEntity()
->GetScene()
->GetEngine()
->GetSystem<phx::DisplaySystemOpenVR>();
phx::HMD* hmd = nullptr; phx::HMD* hmd = nullptr;
if (display_system_hmd != nullptr) { if (display_system_openvr_ != nullptr) {
hmd = display_system_hmd->GetHMD(); hmd = display_system_openvr_->GetHMD();
} }
const auto transform = GetEntity()->GetFirstComponent<phx::Transform>(); const auto transform = GetEntity()->GetFirstComponent<phx::Transform>();
if (hmd == nullptr || transform == nullptr) return; if (hmd == nullptr || transform == nullptr) return;
......
...@@ -24,10 +24,21 @@ ...@@ -24,10 +24,21 @@
#define DEMOS_VIEWER_SRC_NAVIGATION_BEHAVIOR_HPP_ #define DEMOS_VIEWER_SRC_NAVIGATION_BEHAVIOR_HPP_
#include "phx/behavior.hpp" #include "phx/behavior.hpp"
#include "phx/display_system_openvr.hpp"
class NavigationBehavior : public phx::Behavior { class NavigationBehavior : public phx::Behavior {
public: public:
explicit NavigationBehavior(phx::DisplaySystemOpenVR* display_system_openvr);
NavigationBehavior(const NavigationBehavior& that) = default;
NavigationBehavior(NavigationBehavior&& temp) = default;
virtual ~NavigationBehavior() = default;
NavigationBehavior& operator=(const NavigationBehavior& that) = default;
NavigationBehavior& operator=(NavigationBehavior&& temp) = default;
void OnUpdate() override; void OnUpdate() override;
protected:
phx::DisplaySystemOpenVR* display_system_openvr_;
}; };
#endif // DEMOS_VIEWER_SRC_NAVIGATION_BEHAVIOR_HPP_ #endif // DEMOS_VIEWER_SRC_NAVIGATION_BEHAVIOR_HPP_
...@@ -118,14 +118,16 @@ int main(int, char**) { ...@@ -118,14 +118,16 @@ int main(int, char**) {
phx::Entity* camera = scene->CreateEntity(); phx::Entity* camera = scene->CreateEntity();
auto camera_transform = camera->AddComponent<phx::Transform>(); auto camera_transform = camera->AddComponent<phx::Transform>();
auto camera_projection = camera->AddComponent<phx::Projection>(); auto camera_projection = camera->AddComponent<phx::Projection>();
camera->AddComponent<NavigationBehavior>(); camera->AddComponent<NavigationBehavior>(
engine->GetSystem<phx::DisplaySystemOpenVR>());
camera_projection->SetPerspective(glm::radians(68.0f), 4.0f / 3.0f, 0.01f, camera_projection->SetPerspective(glm::radians(68.0f), 4.0f / 3.0f, 0.01f,
1000.0f); 1000.0f);
camera_transform->SetLocalTranslation(glm::vec3(0, 0, 0)); camera_transform->SetLocalTranslation(glm::vec3(0, 0, 0));
camera_transform->SetParent(virtual_platform_transform, false); camera_transform->SetParent(virtual_platform_transform, false);
auto virtual_platform = scene->GetEntitiesWithComponents< auto virtual_platform = scene->GetEntitiesWithComponents<
phx::RuntimeComponent<phx::USER_PLATFORM>>()[0]; phx::RuntimeComponent<phx::USER_PLATFORM>>()[0];
virtual_platform->AddComponent<NavigationBehavior>(); virtual_platform->AddComponent<NavigationBehavior>(
engine->GetSystem<phx::DisplaySystemOpenVR>());
engine->Run(); engine->Run();
......
...@@ -52,11 +52,11 @@ class PHOENIX_EXPORT Entity : public Nameable, public Loggable { ...@@ -52,11 +52,11 @@ class PHOENIX_EXPORT Entity : public Nameable, public Loggable {
Entity& operator=(const Entity&) = delete; Entity& operator=(const Entity&) = delete;
Entity& operator=(Entity&&) = default; Entity& operator=(Entity&&) = default;
template <class ComponentType> template <class ComponentType, class... ArgumentTypes>
ComponentType* AddComponent() { ComponentType* AddComponent(ArgumentTypes&&... arguments) {
static_assert(std::is_base_of<phx::Component, ComponentType>::value, static_assert(std::is_base_of<phx::Component, ComponentType>::value,
"ComponentType is not derived from phx::Component."); "ComponentType is not derived from phx::Component.");
auto component_ptr = new ComponentType(); auto component_ptr = new ComponentType(arguments...);
components_.push_back(std::unique_ptr<ComponentType>(component_ptr)); components_.push_back(std::unique_ptr<ComponentType>(component_ptr));
component_ptr->entity_ = this; component_ptr->entity_ = this;
return component_ptr; return component_ptr;
......
...@@ -73,6 +73,4 @@ std::string Scene::ToString() const { ...@@ -73,6 +73,4 @@ std::string Scene::ToString() const {
"(Scene #Entities: " + std::to_string(GetNumberOfEntities()) + ")"; "(Scene #Entities: " + std::to_string(GetNumberOfEntities()) + ")";
} }
phx::Engine* Scene::GetEngine() const { return engine_; }
} // namespace phx } // namespace phx
...@@ -197,10 +197,7 @@ SCENARIO("The active scene in an engine can be switched", ...@@ -197,10 +197,7 @@ SCENARIO("The active scene in an engine can be switched",
}); });
engine.SetScene(first_scene); engine.SetScene(first_scene);
THEN("It has a scene") { THEN("It has a scene") { REQUIRE(engine.GetScene() != nullptr); }
REQUIRE(engine.GetScene() != nullptr);
REQUIRE(engine.GetScene()->GetEngine() == &engine);
}
THEN("The old scene is nullptr.") { REQUIRE(s1 == nullptr); } THEN("The old scene is nullptr.") { REQUIRE(s1 == nullptr); }
THEN("The new scene is the one we just set.") { THEN("The new scene is the one we just set.") {
REQUIRE(s2 == first_scene.get()); REQUIRE(s2 == first_scene.get());
...@@ -213,9 +210,6 @@ SCENARIO("The active scene in an engine can be switched", ...@@ -213,9 +210,6 @@ SCENARIO("The active scene in an engine can be switched",
"The new scene is attached to the engine and the old scene is " "The new scene is attached to the engine and the old scene is "
"detached") { "detached") {
REQUIRE(engine.GetScene() == new_scene); REQUIRE(engine.GetScene() == new_scene);
REQUIRE(new_scene->GetEngine() == &engine);
REQUIRE(first_scene->GetEngine() == nullptr);
} }
THEN("The signal is triggered with the appropriate values.") { THEN("The signal is triggered with the appropriate values.") {
REQUIRE(s1 == first_scene.get()); REQUIRE(s1 == first_scene.get());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment