Skip to content
Snippets Groups Projects
Commit b241f3b9 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

add fallback (null) physics implementation

parent fcc6b959
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#if __has_include("fggl/phys/bullet/bullet.hpp") #if __has_include("fggl/phys/bullet/bullet.hpp")
#include "fggl/phys/bullet/bullet.hpp" #include "fggl/phys/bullet/bullet.hpp"
#else
#include "fggl/phys/null.hpp"
#endif #endif
#include "fggl/fggl.hpp" #include "fggl/fggl.hpp"
...@@ -87,6 +89,8 @@ int main(int argc, const char* argv[]) { ...@@ -87,6 +89,8 @@ int main(int argc, const char* argv[]) {
moduleManager.use<fggl::entity::ECS>(); moduleManager.use<fggl::entity::ECS>();
#ifdef FGGL_MODULE_BULLET #ifdef FGGL_MODULE_BULLET
moduleManager.use<fggl::phys::Bullet3>(); moduleManager.use<fggl::phys::Bullet3>();
#else
moduleManager.use<fggl::phys::NullPhysics>();
#endif #endif
moduleManager.resolve(); moduleManager.resolve();
......
...@@ -36,6 +36,7 @@ add_subdirectory(math) ...@@ -36,6 +36,7 @@ add_subdirectory(math)
add_subdirectory(util) add_subdirectory(util)
add_subdirectory(assets) add_subdirectory(assets)
add_subdirectory(phys)
target_sources(${PROJECT_NAME} target_sources(${PROJECT_NAME}
PRIVATE PRIVATE
......
target_sources(fggl
PRIVATE
null.cpp
)
\ No newline at end of file
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 20/08/22.
//
#include "fggl/phys/null.hpp"
namespace fggl::phys {
bool NullPhysics::factory(modules::ModuleService serviceName, modules::Services &serviceManager) {
if (serviceName == phys::PhysicsProvider::service) {
serviceManager.bind<phys::PhysicsProvider, NullPhysicsProvider>();
return true;
}
return false;
}
}
\ No newline at end of file
...@@ -28,8 +28,8 @@ namespace fggl::audio { ...@@ -28,8 +28,8 @@ namespace fggl::audio {
NullAudioService() = default; NullAudioService() = default;
virtual ~NullAudioService() = default; virtual ~NullAudioService() = default;
void play(const std::string& filename, bool looping = false) override {} void play(const std::string& /*filename*/, bool /*looping = false*/) override {}
void play(AudioClip& clip, bool looping = false) override {} void play(AudioClip& /*clip*/, bool /*looping = false*/) override {}
}; };
struct NullAudio { struct NullAudio {
......
/*
* This file is part of FGGL.
*
* FGGL is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* FGGL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with FGGL.
* If not, see <https://www.gnu.org/licenses/>.
*/
//
// Created by webpigeon on 20/08/22.
//
#ifndef FGGL_PHYS_NULL_HPP
#define FGGL_PHYS_NULL_HPP
#include "fggl/phys/types.hpp"
#include "fggl/phys/service.hpp"
namespace fggl::phys {
inline void build_noop(const entity::ComponentSpec& /*config*/,
entity::EntityManager& /*manager*/,
const entity::EntityID& /*entity*/) {}
class NullPhysicsEngine : public PhysicsEngine {
public:
inline void step() override {}
void setDebugDraw(bool /* enable */) override {}
inline std::vector<ContactPoint> scanCollisions(entity::EntityID /*entity*/) override {
return {};
}
inline entity::EntityID raycast(math::vec3 /*from*/, math::vec3 /*to*/) override {
return entity::INVALID;
}
inline std::vector<entity::EntityID> raycastAll(math::vec3 /*from*/, math::vec3 /*to*/) override {
return {};
}
inline std::vector<entity::EntityID> sweep(PhyShape& /*shape*/, math::Transform& /*from*/, math::Transform& /*to*/) override {
return {};
}
};
class NullPhysicsProvider : public PhysicsProvider {
public:
virtual ~NullPhysicsProvider() = default;
inline PhysicsEngine* create(entity::EntityManager* /*entityManager*/, entity::EntityFactory* factory) override {
factory->bind(util::make_guid("phys::Body"), build_noop );
return new NullPhysicsEngine();
}
};
struct NullPhysics {
constexpr static const char* name = "fggl::phys::null";
constexpr static const std::array<modules::ModuleService, 1> provides = {
phys::PhysicsProvider::service
};
constexpr static const std::array<modules::ModuleService, 1> depends = {
entity::EntityFactory::service
};
static bool factory(modules::ModuleService serviceName, modules::Services& serviceManager);
};
} // namespace fggl::phys
#endif //FGGL_PHYS_NULL_HPP
...@@ -28,7 +28,7 @@ namespace fggl::phys { ...@@ -28,7 +28,7 @@ namespace fggl::phys {
class PhysicsProvider { class PhysicsProvider {
public: public:
constexpr static const modules::ModuleService service = modules::make_service("fggl::phys::service"); constexpr static const modules::ModuleService service = modules::make_service("fggl::phys::service");
virtual ~PhysicsProvider() = default;
virtual PhysicsEngine* create(entity::EntityManager* entityManager, entity::EntityFactory* factory) = 0; virtual PhysicsEngine* create(entity::EntityManager* entityManager, entity::EntityFactory* factory) = 0;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment