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

remove subsystem code - modules replace it

parent cf19c5b0
No related branches found
No related tags found
No related merge requests found
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include "fggl/util/service.hpp" #include "fggl/util/service.hpp"
#include "fggl/data/storage.hpp" #include "fggl/data/storage.hpp"
#include "fggl/subsystem/provider.hpp"
namespace fggl::audio::openal { namespace fggl::audio::openal {
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
#define FGGL_AUDIO_AUDIO_HPP #define FGGL_AUDIO_AUDIO_HPP
#include <string> #include <string>
#include "fggl/subsystem/types.hpp"
#include "fggl/data/storage.hpp" #include "fggl/data/storage.hpp"
#include "fggl/modules/module.hpp" #include "fggl/modules/module.hpp"
......
/*
* 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 27/06/22.
// This is the 'quick and dirty' subsystem approach, recommended in 'Game Engine Architecture'
// Architecturally, this is an abomination, but it works (at least until I build something dependency-based).
//
#ifndef FGGL_SUBSYSTEM_CURSED_GOD_OBJECT_HPP
#define FGGL_SUBSYSTEM_CURSED_GOD_OBJECT_HPP
#include <memory>
#include "fggl/subsystem/types.hpp"
#include "fggl/subsystem/provider.hpp"
#include "fggl/audio/null_audio.hpp"
namespace fggl::subsystem {
template<typename T>
class ServiceContainer {
T* m_service = nullptr;
public:
inline void set(T* service) {
m_service = service;
}
void release() {
if ( m_service != nullptr ) {
delete m_service;
m_service = nullptr;
}
}
[[nodiscard]]
inline T* getPtr() const {
return m_service;
}
[[nodiscard]]
inline T& getRef() const {
return *m_service;
}
};
class GodObject : public ServiceProvider,
private ServiceContainer<data::Storage>,
private ServiceContainer<audio::AudioService>
{
public:
GodObject() = default;
inline void setup() {
m_setup = true;
}
inline void teardown() {}
template<typename T>
inline void provide(T* service) {
assert(service != nullptr);
assert( !m_setup );
ServiceContainer<T>::set(service);
}
template<typename T>
[[nodiscard]]
inline T* get() {
return ServiceContainer<T>::get();
}
inline audio::AudioService* getAudio() override {
assert(m_setup);
return ServiceContainer<audio::AudioService>::getPtr();
}
inline void setFontLibrary(gui::FontLibrary* fontLibrary) {
assert( !m_setup );
m_fonts = fontLibrary;
}
inline gui::FontLibrary* getFontLibrary() override {
assert(m_setup);
return m_fonts;
}
inline void setInput(input::Input* input){
assert( !m_setup );
m_input = input;
}
input::Input* getInput() override {
assert(m_setup);
return m_input;
}
data::Storage* getStorage() override {
assert(m_setup);
return ServiceContainer<data::Storage>::getPtr();
}
inline void setTypeRegistry(ecs3::TypeRegistry* registry) {
assert( !m_setup );
m_types = registry;
}
ecs3::TypeRegistry* getTypeRegistry() override {
assert(m_setup);
return m_types;
}
private:
bool m_setup = false;
gui::FontLibrary* m_fonts = nullptr;
ecs3::TypeRegistry* m_types = nullptr;
input::Input* m_input = nullptr;
};
} // namespace fggl::subsystem
#endif //FGGL_SUBSYSTEM_CURSED_GOD_OBJECT_HPP
/*
* 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 27/06/22.
//
#ifndef FGGL_SUBSYSTEM_PROVIDER_HPP
#define FGGL_SUBSYSTEM_PROVIDER_HPP
#include "fggl/audio/audio.hpp"
#include "fggl/gui/gui.hpp"
#include "fggl/ecs3/types.hpp"
#include "fggl/input/input.hpp"
namespace fggl::subsystem {
class ServiceProvider {
public:
virtual audio::AudioService* getAudio() = 0;
virtual gui::FontLibrary* getFontLibrary() = 0;
virtual input::Input* getInput() = 0;
virtual data::Storage* getStorage() = 0;
virtual ecs3::TypeRegistry* getTypeRegistry() = 0;
};
} // namespace fggl::subsystem
#endif //FGGL_SUBSYSTEM_PROVIDER_HPP
/*
* 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 27/06/22.
//
#ifndef FGGL_SUBSYSTEM_SUBSYSTEM_HPP
#define FGGL_SUBSYSTEM_SUBSYSTEM_HPP
#include "fggl/subsystem/cursed/god_object.hpp"
namespace fggl::subsystem {
using SubsystemManager = GodObject;
} // namespace fggl::subsystem
#endif //FGGL_SUBSYSTEM_SUBSYSTEM_HPP
/*
* 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 27/06/22.
//
#ifndef FGGL_SUBSYSTEM_TYPES_HPP
#define FGGL_SUBSYSTEM_TYPES_HPP
namespace fggl::subsystem {
class ServiceProvider;
class Subsystem {
virtual ~Subsystem() = default;
virtual void setup(ServiceProvider& provider) = 0;
virtual void teardown(ServiceProvider& provider) = 0;
};
} // namespace fggl::subsystem
#endif //FGGL_SUBSYSTEM_TYPES_HPP
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