Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • gamedev/fggl
  • onuralpsezer/fggl
2 results
Show changes
Showing
with 676 additions and 110 deletions
/*
* 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 18/10/22.
//
#ifndef FGGL_DEMO_INCLUDE_MODELS_VIEWER_HPP
#define FGGL_DEMO_INCLUDE_MODELS_VIEWER_HPP
#include "fggl/scenes/game.hpp"
#include "fggl/assets/types.hpp"
namespace demo {
class Viewer : public fggl::scenes::Game {
public:
explicit Viewer(fggl::App& app);
void activate() override;
void deactivate() override;
void update(float dt) override;
void render(fggl::gfx::Graphics& gfx) override;
private:
fggl::entity::EntityID m_model = fggl::entity::INVALID;
std::vector< fggl::assets::AssetID> m_assets;
uint64_t m_lastAsset = 0;
bool m_debug = false;
void cycleAsset(uint64_t asset);
};
}
#endif //FGGL_DEMO_INCLUDE_MODELS_VIEWER_HPP
......@@ -12,61 +12,58 @@
* If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef FGGL_GFX_OGL_COMPAT_HPP
#define FGGL_GFX_OGL_COMPAT_HPP
/**
* Legacy/Direct OpenGL calls.
*
* This shouldn't be exposed to the demo app, but the ECS we're using isn't smart enouph to allow us to
* abstract this yet. It's next thing on the list, but this branch is about cleaning up OpenGL not about
* extending our ECS.
*
* Should be removed when the engine has suitable abstractions in place.
*/
//
// Created by webpigeon on 04/09/22.
//
#include <functional>
#ifndef FGGL_DEMO_INCLUDE_ROBOT_PROGRAMMER_HPP
#define FGGL_DEMO_INCLUDE_ROBOT_PROGRAMMER_HPP
#include <fggl/gfx/ogl/shader.hpp>
#include <fggl/gfx/ogl/renderer.hpp>
#include <functional>
#include <fggl/gfx/common.hpp>
#include <fggl/gfx/camera.hpp>
#include "fggl/gui/containers.hpp"
#include <utility>
#include <fggl/input/camera_input.hpp>
#include <fggl/data/heightmap.hpp>
namespace demo::robot {
#include "fggl/gfx/phong.hpp"
struct Instruction {
const char* name;
std::function<void(void)> m_func;
};
namespace fggl::gfx {
struct Program {
std::vector<Instruction> m_instructions;
uint32_t m_currInstruction;
bool playing = false;
//
// fake module support - allows us to still RAII
//
/*struct SceneUtils : ecs3::Module {
inline std::size_t size() {
return m_instructions.size();
}
SceneUtils() = default;
inline void step() {
m_instructions[ m_currInstruction ].m_func();
m_currInstruction++;
}
[[nodiscard]]
std::string name() const override {
return "gfx::scene";
inline void stop() {
playing = false;
m_currInstruction = 0;
}
};
void onLoad(ecs3::ModuleManager &manager, ecs3::TypeRegistry &types) override {
// mesh dependencies
types.make<math::Transform>();
types.make<data::StaticMesh>();
types.make<data::HeightMap>();
class Timeline : public fggl::gui::Panel {
public:
explicit Timeline(Program& program);
types.make<gfx::PhongMaterial>();
void update(float deltaTime) override;
void render(fggl::gfx::Paint& paint) override;
// camera dependencies
types.make<fggl::gfx::Camera>();
types.make<fggl::input::FreeCamKeys>();
}
protected:
void renderInstructions(fggl::gfx::Paint& paint);
};*/
private:
std::vector<std::reference_wrapper<Program>> m_tracks;
};
}
#endif
#endif //FGGL_DEMO_INCLUDE_ROBOT_PROGRAMMER_HPP
......@@ -27,6 +27,7 @@
#include "fggl/scenes/game.hpp"
#include "fggl/phys/service.hpp"
#include "fggl/script/engine.hpp"
namespace demo {
......@@ -40,11 +41,7 @@ namespace demo {
fggl::entity::EntityID player = fggl::entity::INVALID;
fggl::entity::EntityID closestPickup;
DebugMode mode = DebugMode::NORMAL;
std::array<fggl::entity::EntityID, 3> collectables {
fggl::entity::INVALID,
fggl::entity::INVALID,
fggl::entity::INVALID };
std::vector<fggl::entity::EntityID> collectables;
float time = 0.0f;
};
......@@ -57,13 +54,14 @@ namespace demo {
void activate() override;
void deactivate() override;
void update() override;
void update(float dt) override;
void render(fggl::gfx::Graphics& gfx) override;
private:
constexpr static fggl::math::vec3 HINT_COLOUR{0.5f, 0.0f, 0.0f};
RollState state;
fggl::phys::PhysicsEngine* m_phys;
fggl::script::ScriptEngine* m_scripts;
fggl::math::vec3 cameraOffset = {-15.0F, 15.0F, 0.0F};
void closestPickup(fggl::entity::EntityManager& world);
......
......@@ -29,7 +29,7 @@ namespace demo {
explicit TopDown(fggl::App& app);
void activate() override;
void update() override;
void update(float dt) override;
void render(fggl::gfx::Graphics& gfx) override;
private:
......
......@@ -979,7 +979,7 @@ EXCLUDE_PATTERNS =
# Note that the wildcards are matched against the file with absolute path, so to
# exclude all test directories use the pattern */test/*
EXCLUDE_SYMBOLS =
EXCLUDE_SYMBOLS = "YAML" "glm" "dd"
# The EXAMPLE_PATH tag can be used to specify one or more files or directories
# that contain example code fragments that are included (see the \include
......
......@@ -5,12 +5,14 @@ file(GLOB_RECURSE HEADER_LIST CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/include/fgg
# Should be shared linkage for legal reasons (LGPL)
add_library(fggl ${HEADER_LIST})
target_link_libraries(fggl PUBLIC entt)
# we need to tell people using the library about our headers
target_include_directories(fggl
PUBLIC
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
)
# users of this library need at least C++20
target_compile_features(fggl PUBLIC cxx_std_20)
......@@ -34,12 +36,13 @@ endif ()
# the important stuff everything else uses
add_subdirectory(math)
add_subdirectory(util)
add_subdirectory(grid)
add_subdirectory(assets)
add_subdirectory(phys)
target_sources(${PROJECT_NAME}
PRIVATE
PRIVATE
app.cpp
data/model.cpp
......@@ -53,27 +56,17 @@ target_sources(${PROJECT_NAME}
input/input.cpp
input/mouse.cpp
input/camera_input.cpp
gui/widget.cpp
gui/widgets.cpp
gui/containers.cpp
gui/fonts.cpp
)
# GUI support
add_subdirectory(gui)
# yaml-cpp for configs and storage
find_package(yaml-cpp)
target_link_libraries(fggl PUBLIC yaml-cpp)
# model loading
find_package(assimp CONFIG)
if ( MSVC )
target_link_libraries(${PROJECT_NAME} PUBLIC assimp::assimp)
else()
target_link_libraries(${PROJECT_NAME} PUBLIC assimp)
endif()
find_package(Freetype)
target_link_libraries(${PROJECT_NAME} PUBLIC Freetype::Freetype)
add_subdirectory(data/assimp)
# Graphics backend
add_subdirectory(gfx)
......@@ -91,7 +84,7 @@ add_subdirectory(entity)
##
# begin windows support
##
if(MSVC)
target_compile_options(${PROJECT_NAME} PUBLIC "/ZI")
target_link_options(${PROJECT_NAME} PUBLIC "/INCREMENTAL")
endif()
if (MSVC)
target_compile_options(${PROJECT_NAME} PUBLIC "/ZI")
target_link_options(${PROJECT_NAME} PUBLIC "/INCREMENTAL")
endif ()
......@@ -13,74 +13,79 @@
*/
#include <cstdlib>
#include <memory>
#include <spdlog/spdlog.h>
#include <fggl/app.hpp>
namespace fggl {
App::App(modules::Manager* services, const Identifer& name) : App::App( services, name, name ) {
}
App::App(modules::Manager *services, const Identifer &name) : App::App(services, name, name) {
}
App::App(modules::Manager* services, const Identifer& /*name*/, const Identifer& /*folder*/ ) :
m_running(true),
App::App(modules::Manager *services, const Identifer & /*name*/, const Identifer & /*folder*/ ) :
m_running(true),
m_window(nullptr),
m_states(),
m_subsystems(services){}
m_states(),
m_subsystems(services) {}
int App::run(int argc, const char** argv) {
auto* windowing = m_subsystems->get<display::WindowService>();
auto App::run(int /*argc*/, const char **/*argv*/) -> int {
auto *windowing = m_subsystems->get<display::WindowService>();
{
// activate the first state
auto& state = m_states.active();
{
// activate the first state
auto &state = m_states.active();
m_expectedScene = m_states.activeID();
state.activate();
}
state.activate();
}
auto lastTime = glfwGetTime();
while (m_running) {
auto currTime = glfwGetTime();
auto delta = currTime - lastTime;
lastTime = currTime;
while ( m_running ) {
// trigger a state change if expected
if ( m_expectedScene != m_states.activeID() ) {
if (m_expectedScene != m_states.activeID()) {
auto result = m_states.change(m_expectedScene);
if ( !result ) {
if (!result) {
m_expectedScene = m_states.activeID();
}
}
// process window events
if ( windowing != nullptr) {
if (windowing != nullptr) {
windowing->pollEvents();
}
//m_modules->onUpdate();
//m_modules->onUpdate();
auto& state = m_states.active();
state.update();
auto &state = m_states.active();
state.update((float)delta);
// window rendering to frame buffer
if ( m_window != nullptr ) {
// m_modules->onFrameStart();
// window rendering to frame buffer
if (m_window != nullptr) {
// m_modules->onFrameStart();
m_window->frameStart();
// get draw instructions
auto& graphics = m_window->graphics();
state.render(graphics);
// get draw instructions
auto &graphics = m_window->graphics();
state.render(graphics);
m_window->frameEnd();
// m_modules->onFrameEnd();
m_window->frameEnd();
// m_modules->onFrameEnd();
m_running = m_running && !m_window->wantClose();
}
}
}
}
{
// shutdown last state
auto& state = m_states.active();
state.deactivate();
}
{
// shutdown last state
auto &state = m_states.active();
state.deactivate();
}
return EXIT_SUCCESS;
}
return EXIT_SUCCESS;
}
} //namespace fggl
target_sources(fggl PRIVATE
module.cpp
module.cpp
types.cpp
packed/module.cpp
)
\ No newline at end of file
......@@ -20,10 +20,11 @@
namespace fggl::assets {
bool AssetFolders::factory(modules::ModuleService service, modules::Services& services) {
if ( service == Loader::service) {
auto storage = services.get<data::Storage>();
services.create<Loader>(storage);
auto AssetFolders::factory(modules::ServiceName service, modules::Services &services) -> bool {
if (service == Loader::service) {
auto *storage = services.get<data::Storage>();
auto *checkin = services.get<CheckinAdapted>();
services.create<Loader>(storage, checkin);
return true;
}
if (service == AssetManager::service) {
......
/*
* 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/assets/packed/module.hpp"
namespace fggl::assets {
auto PackedAssets::factory(modules::ServiceName service, modules::Services &services) -> bool {
if (service == RawCheckin::service) {
services.create<RawCheckin>();
return true;
}
if (service == CheckinAdapted::service) {
auto* storage = services.get<data::Storage>();
auto* rawCheckin = services.get<RawCheckin>();
services.create<CheckinAdapted>(storage, rawCheckin);
return true;
}
return false;
}
} // namespace fggl::assets
\ 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 19/11/22.
//
#include <stack>
#include <vector>
#include <memory>
#include <set>
#include <map>
#include <concepts>
#include "fggl/util/guid.hpp"
namespace fggl::assets {
using AssetName = util::OpaqueName<uint64_t, struct AssetRefStruct>;
/**
* The base class representing an asset.
*
* This can be combined with the templated version.
*/
class Asset {
public:
Asset(AssetName name) : m_name(name) {}
virtual ~Asset() = default;
inline void release() {
releaseImpl();
}
bool operator==(const Asset& asset) const {
return m_name == asset.m_name;
}
bool operator!=(const Asset& asset) const {
return m_name != asset.m_name;
}
private:
AssetName m_name;
virtual void releaseImpl() = 0;
};
/**
* Wrapper for types that cannot extend Asset themselves.
*
* @tparam T the asset to wrap
*/
template<typename T>
class AssetBox : public Asset {
public:
AssetBox(T* ptr) : m_ptr(ptr) {}
~AssetBox() override {
release();
}
T* ptr() {
return m_ptr;
}
private:
T* m_ptr;
void releaseImpl() override {
delete m_ptr;
m_ptr = nullptr;
}
};
/**
* Asset Library.
*
* The currently usable set of assets loaded into the engine.
*/
class AssetLibrary {
public:
void load(AssetName name);
void unload(AssetName name);
template<typename T>
requires std::derived_from<T, Asset>
void store(AssetName name, T* ptr) {
m_assets[name] = std::make_unique<T>(ptr);
}
template<typename T>
requires std::derived_from<T, Asset>
void get(AssetName name) const {
Asset* asset = m_assets.at(name).get();
return dynamic_cast<T>(asset);
}
inline Asset* get(AssetName name) const {
return m_assets.at( name ).get();
}
private:
std::map<AssetName, std::unique_ptr<Asset>> m_assets;
};
struct AssetRecord {
AssetName id;
std::vector<AssetName> dependencies;
bool hasDepends(AssetName name) const;
void addDepend(AssetName name);
};
class AssetGraph {
public:
AssetGraph(AssetLibrary* loader);
/**
*
*
* @param name
*/
void require(AssetName& name) {
if ( m_loaded.find(name) != m_loaded.end() ) {
return;
}
m_required.push(name);
}
/**
*
*
* @return
*/
[[nodiscard]]
inline bool isLoadComplete() const {
return m_required.empty();
}
/**
*
*
* @param name
* @return
*/
[[nodiscard]]
inline bool isLoaded(AssetName name) const {
return m_loaded.find(name) != m_loaded.end();
}
/**
*
* @param name
* @param description
*/
void addDependency(AssetName& name, AssetName& description) {
auto& assets = m_assets.at(name);
assets.addDepend(description);
}
/**
*
* @param name
* @param dependency
* @return
*/
[[nodiscard]]
bool hasDependency(AssetName& name , AssetName& dependency) const {
try {
auto &assets = m_assets.at(name);
return assets.hasDepends(dependency);
} catch ( std::out_of_range& ) {
return false;
}
}
/**
*
*/
void process() {
auto asset = m_required.top();
m_loader->load( asset );
m_required.pop();
}
/**
*
*/
void finishLoading() {
while ( !m_loaded.empty() ) {
process();
}
}
private:
std::stack<AssetName> m_required;
std::set<AssetName> m_loaded;
std::map<AssetName, AssetRecord> m_assets;
AssetLibrary* m_loader;
};
} // namespace fggl::assets
\ 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/11/22.
//
#include "fggl/assets/types.hpp"
namespace fggl::assets {
auto make_asset_id_rt(const std::string &pack, const std::string &path, const std::string &view) -> AssetID {
auto fullPath = pack + ":" + path;
if (!view.empty()) {
fullPath += "[" + view + "]";
}
#ifndef NDEBUG
util::intern_string(fullPath.c_str());
#endif
auto hash = util::hash_fnv1a_64(fullPath.c_str());
return AssetID::make(hash);
}
auto asset_from_user(const std::string &input, const std::string &pack) -> AssetID {
if (input.find(':') != std::string::npos ) {
// probably fully qualified
#ifndef NDEBUG
util::intern_string(input.c_str());
#endif
auto hash = util::hash_fnv1a_64(input.c_str());
return AssetID::make(hash);
}
// probably local
return make_asset_id_rt(pack, input);
}
}
\ No newline at end of file
target_sources(fggl
PRIVATE
types.cpp
)
types.cpp
)
add_subdirectory(openal)
\ No newline at end of file
add_subdirectory(openal)
add_subdirectory(fallback)
\ No newline at end of file
target_sources(fggl
PRIVATE
audio.cpp
)
/*
* 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 05/11/22.
//
#include "fggl/audio/null_audio.hpp"
namespace fggl::audio {
void NullAudioService::play(const std::string &, bool) {
}
void NullAudioService::play(const fggl::audio::AudioClipShort &, bool) {
}
auto NullAudio::factory(modules::ServiceName service, modules::Services &services) -> bool{
if (service == SERVICE_AUDIO_PLAYBACK) {
services.bind<audio::AudioService, audio::NullAudioService>();
return true;
}
return false;
}
} // namespace fggl::audio
\ No newline at end of file
find_package( OpenAL CONFIG )
if ( NOT OpenAL_FOUND )
find_package(OpenAL CONFIG)
if (NOT OpenAL_FOUND)
# ubuntu/debian openal-soft package doesn't seem to have a config file
# it's probably falling back to findOpenAL.cmake
message( STATUS "OpenAL-Soft config missing - falling back" )
find_package( OpenAL REQUIRED )
target_link_libraries( fggl PUBLIC ${OPENAL_LIBRARY} )
target_include_directories( fggl PUBLIC ${OPENAL_INCLUDE_DIR} )
else()
message(STATUS "OpenAL-Soft config missing - falling back")
find_package(OpenAL REQUIRED)
target_link_libraries(fggl PUBLIC ${OPENAL_LIBRARY})
target_include_directories(fggl PUBLIC ${OPENAL_INCLUDE_DIR})
else ()
# we're using target-based
message( STATUS "Using OpenAL-Soft config file" )
if ( TARGET OpenAL::OpenAL )
target_link_libraries( fggl PUBLIC OpenAL::OpenAL )
else()
target_link_libraries( fggl PUBLIC OpenAL )
endif()
message(STATUS "Using OpenAL-Soft config file")
if (TARGET OpenAL::OpenAL)
target_link_libraries(fggl PUBLIC OpenAL::OpenAL)
else ()
target_link_libraries(fggl PUBLIC OpenAL)
endif ()
endif()
endif ()
target_sources(fggl
PRIVATE
audio.cpp
module.cpp
)
......@@ -27,28 +27,98 @@
*/
#include "fggl/audio/openal/audio.hpp"
#include "fggl/data/storage.hpp"
#include "fggl/assets/types.hpp"
#include "fggl/assets/manager.hpp"
#include "../../stb/stb_vorbis.h"
namespace fggl::audio::openal {
auto load_vorbis(assets::Loader* /*loader*/, const assets::AssetID &guid, const assets::LoaderContext &data, void* userPtr) -> assets::AssetRefRaw {
auto *manager = static_cast<assets::AssetManager*>(userPtr);
auto filePath = data.assetPath;
// vorbis
auto* clip = new AudioClipShort();
clip->sampleCount = stb_vorbis_decode_filename( filePath.c_str(), &clip->channels, &clip->sampleRate, &clip->data);
debug::info("clip loaded: channels={}, sampleRate={}, sampleCount={}", clip->channels, clip->sampleRate, clip->sampleCount);
if ( clip->sampleCount == -1 ) {
return nullptr;
}
manager->set(guid, clip);
return nullptr;
}
auto load_vorbis_short(std::filesystem::path path, assets::MemoryBlock& /*block*/) -> bool {
// vorbis
auto* clip = new AudioClipShort();
clip->sampleCount = stb_vorbis_decode_filename( path.c_str(), &clip->channels, &clip->sampleRate, &clip->data);
debug::info("clip loaded: channels={}, sampleRate={}, sampleCount={}", clip->channels, clip->sampleRate, clip->sampleCount);
return clip->sampleCount != 1;
}
auto check_vorbis(const std::filesystem::path& path ) -> assets::AssetTypeID {
if ( path.extension() != ".ogg" ) {
return assets::INVALID_ASSET_TYPE;
}
auto* clip = new AudioClipShort();
clip->sampleCount = stb_vorbis_decode_filename( path.c_str(), &clip->channels, &clip->sampleRate, &clip->data);
if ( clip->sampleCount == -1 ) {
return assets::INVALID_ASSET_TYPE;
}
delete clip;
return ASSET_CLIP_SHORT;
}
void AudioSource::play(const AudioClipShort &clip, bool looping) {
check_error("pre play");
AudioType format = clip.channels == 1 ? AudioType::MONO_16 : AudioType::STEREO_16;
m_splat.setData(format, clip.data, clip.size(), clip.sampleRate);
check_error("saving to buffer");
play(m_splat, looping);
check_error("post play");
}
void AudioServiceOAL::play(const std::string &filename, bool looping) {
debug::info("beginning audio: {}", filename);
// load audio clip into temp storage
AudioClip clip;
bool result = m_storage->load(data::StorageType::Data, filename, &clip);
if ( !result ) {
std::cerr << "error: can't load audio data" << std::endl;
auto assetRef = assets::make_asset_id_rt("core", filename);
auto* clip = m_assets->get<AudioClipShort>(assetRef);
if ( clip == nullptr ) {
debug::warning("audio asset requested, but not loaded: {}", filename);
return;
}
play(clip, looping);
play(*clip, looping);
debug::info("played audio: {}", filename);
}
void AudioServiceOAL::play(AudioClip &clip, bool looping) {
// play the audio on the default (non-positioned) source
if ( m_defaultSource != nullptr ) {
m_defaultSource->play(clip, looping);
void AudioServiceOAL::play(const AudioClipShort &clip, bool looping) {
if ( m_defaultSource == nullptr ){
return;
}
// play the audio on the default (non-positioned) source
m_defaultSource->play(clip, looping);
}
void AudioServiceOAL::release() {
m_defaultSource = nullptr;
alcMakeContextCurrent(nullptr);
alcDestroyContext(m_context);
alcCloseDevice(m_device);
m_context = nullptr;
m_device = nullptr;
}
}
\ 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 05/11/22.
//
#include "fggl/audio/openal/module.hpp"
namespace fggl::audio {
auto OpenAL::factory(modules::ServiceName service, modules::Services &services) -> bool {
if (service == SERVICE_AUDIO_PLAYBACK) {
auto* assets = services.get<assets::AssetManager>();
{
auto *assetLoader = services.get<assets::Loader>();
assetLoader->setFactory( ASSET_CLIP_SHORT, openal::load_vorbis, assets::LoadType::PATH);
}
{
auto *checkin = services.get<assets::CheckinAdapted>();
checkin->setLoader( RES_OGG_VORBIS, openal::load_vorbis_short, openal::check_vorbis );
}
services.bind<audio::AudioService, openal::AudioServiceOAL>(assets);
return true;
}
return false;
}
}
\ No newline at end of file
......@@ -15,22 +15,11 @@
#include "fggl/data/storage.hpp"
#include "fggl/audio/audio.hpp"
#include "../stb/stb_vorbis.h"
namespace fggl::audio {
} // namespace fggl::audio
namespace fggl::data {
template<>
bool fggl_deserialize<audio::AudioClip>(std::filesystem::path &data, audio::AudioClip* out) {
out->sampleCount = stb_vorbis_decode_filename(data.string().c_str(),
&out->channels,
&out->sampleRate,
&out->data);
return out->sampleCount != -1;
}
} // namespace fggl::data