Skip to content

Commit

Permalink
Merge branch 'main' into 265-add-scene-editor
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA authored Feb 23, 2023
2 parents 9abc245 + 1187084 commit f82eb32
Show file tree
Hide file tree
Showing 38 changed files with 533 additions and 672 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-engine-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
sudo apt-get install xorg-dev libglu1-mesa-dev gcc-10 g++-10
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_CORE_SAMPLES=ON -DBUILD_CORE_TESTS=ON
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_CORE_SAMPLES=ON -DBUILD_CORE_TESTS=ON -DBUILD_ENGINE_SAMPLES=ON
shell: bash
env:
CC: gcc-10
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-engine-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
brew install glfw llvm@14
- name: Configure CMake
run: CC=$(brew --prefix llvm@14)/bin/clang CXX=$(brew --prefix llvm@14)/bin/clang++ cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DGLFW_USE_SUBMODULE=OFF -DBUILD_CORE_SAMPLES=ON -DBUILD_CORE_TESTS=ON
run: CC=$(brew --prefix llvm@14)/bin/clang CXX=$(brew --prefix llvm@14)/bin/clang++ cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DGLFW_USE_SUBMODULE=OFF -DBUILD_CORE_SAMPLES=ON -DBUILD_CORE_TESTS=ON -DBUILD_ENGINE_SAMPLES=ON
shell: bash

- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-engine-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
run: cmake -E make_directory ${{github.workspace}}\build

- name: Configure CMake
run: cmake -B ${{github.workspace}}\build -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_CORE_SAMPLES=ON -DBUILD_CORE_TESTS=ON
run: cmake -B ${{github.workspace}}\build -G "Visual Studio 17 2022" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DBUILD_CORE_SAMPLES=ON -DBUILD_CORE_TESTS=ON -DBUILD_ENGINE_SAMPLES=ON

- name: Build
run: cmake --build ${{github.workspace}}\build --config ${{env.BUILD_TYPE}}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,7 @@ build
.ccls-cache

imgui.ini

# direnv - maybe .envrc is ok if 'use flake' doesn't break non nixos machines
/.envrc
/.direnv
57 changes: 38 additions & 19 deletions core/include/cubos/core/ecs/dispatcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#define ENSURE_CURR_TAG() \
do \
{ \
if (!currTagSettings) \
if (currTag.empty()) \
{ \
CUBOS_ERROR("No tag currently selected!"); \
return; \
Expand All @@ -35,6 +35,14 @@
obj->settings = std::make_shared<SystemSettings>(); \
} \
} while (false)
#define ENSURE_TAG_SETTINGS(tag) \
do \
{ \
if (tagSettings.find(tag) == tagSettings.end()) \
{ \
tagSettings[tag] = std::make_shared<SystemSettings>(); \
} \
} while (false)

namespace cubos::core::ecs
{
Expand All @@ -43,6 +51,8 @@ namespace cubos::core::ecs
class Dispatcher
{
public:
~Dispatcher();

/// Adds a tag, and sets it as the current tag for further
/// settings.
/// @param tag Tag to add.
Expand Down Expand Up @@ -121,9 +131,10 @@ namespace cubos::core::ecs
/// Internal class with settings pertaining to system/tag execution
struct SystemSettings
{
void copyFrom(const SystemSettings* other);

Dependency before, after;
// TODO: Add run conditions, threading modes, etc...
// TODO: Implement inherithance behavior
std::vector<std::string> inherits;
};

Expand All @@ -132,6 +143,7 @@ namespace cubos::core::ecs
{
std::shared_ptr<SystemSettings> settings;
std::shared_ptr<AnySystemWrapper<void>> system;
std::string tag;
};

/// Internal class used to implement a DFS algorithm for call chain compilation
Expand All @@ -153,31 +165,36 @@ namespace cubos::core::ecs
/// @return True if a cycle was detected, false if otherwise.
bool dfsVisit(DFSNode& node, std::vector<DFSNode>& nodes);

/// Copies settings from inherited tags to this system, recursively
/// solving nested inheritance.
/// @param settings Settings to handle inheritance for.
void handleTagInheritance(std::shared_ptr<SystemSettings>& settings);

/// Variables for holding information before call chain is compiled.
std::vector<System> pendingSystems; ///< All systems.
std::vector<System*> pendingSystems; ///< All systems.
std::map<std::string, std::shared_ptr<SystemSettings>> tagSettings; ///< All tags.
System* currSystem; ///< Last set system, for changing settings.
SystemSettings* currTagSettings; ///< Last set tag, for changing settings.
std::string currTag; ///< Last set tag, for changing settings.

/// Variables for holding information after call chain is compiled.
std::vector<System> systems; ///< Compiled order of running systems.
bool prepared = false; ///< Whether the systems are prepared for execution.
std::vector<System*> systems; ///< Compiled order of running systems.
bool prepared = false; ///< Whether the systems are prepared for execution.
};

template <typename F>
void Dispatcher::addSystem(F func)
{
// Wrap the system and put it in the pending queue
System system = {nullptr, std::make_shared<SystemWrapper<F>>(func)};
pendingSystems.push_back(std::move(system));
currSystem = &pendingSystems.back();
System* system = new System{nullptr, std::make_shared<SystemWrapper<F>>(func)};
pendingSystems.push_back(system);
currSystem = pendingSystems.back();
}

template <typename F>
void Dispatcher::systemSetAfterSystem(F func)
{
auto it = std::find_if(pendingSystems.begin(), pendingSystems.end(), [&func](const System& system) {
SystemWrapper<F>* wrapper = dynamic_cast<SystemWrapper<F>*>(system.system.get());
auto it = std::find_if(pendingSystems.begin(), pendingSystems.end(), [&func](const System* system) {
SystemWrapper<F>* wrapper = dynamic_cast<SystemWrapper<F>*>(system->system.get());
if (!wrapper)
return false;
return wrapper->system == func;
Expand All @@ -189,18 +206,19 @@ namespace cubos::core::ecs
}
ENSURE_CURR_SYSTEM();
ENSURE_SYSTEM_SETTINGS(currSystem);
ENSURE_SYSTEM_SETTINGS(it);
System* system = *it;
ENSURE_SYSTEM_SETTINGS(system);
// Set curr to run after this system
currSystem->settings->after.system.push_back(&(*it));
currSystem->settings->after.system.push_back(system);
// And this system to run before curr
it->settings->before.system.push_back(currSystem);
system->settings->before.system.push_back(currSystem);
}

template <typename F>
void Dispatcher::systemSetBeforeSystem(F func)
{
auto it = std::find_if(pendingSystems.begin(), pendingSystems.end(), [&func](const System& system) {
SystemWrapper<F>* wrapper = dynamic_cast<SystemWrapper<F>*>(system.system.get());
auto it = std::find_if(pendingSystems.begin(), pendingSystems.end(), [&func](const System* system) {
SystemWrapper<F>* wrapper = dynamic_cast<SystemWrapper<F>*>(system->system.get());
if (!wrapper)
return false;
return wrapper->system == func;
Expand All @@ -212,11 +230,12 @@ namespace cubos::core::ecs
}
ENSURE_CURR_SYSTEM();
ENSURE_SYSTEM_SETTINGS(currSystem);
ENSURE_SYSTEM_SETTINGS(it);
System* system = *it;
ENSURE_SYSTEM_SETTINGS(system);
// Set curr to run before this system
currSystem->settings->before.system.push_back(&(*it));
currSystem->settings->before.system.push_back(system);
// And this system to run after curr
it->settings->after.system.push_back(currSystem);
system->settings->after.system.push_back(currSystem);
}
} // namespace cubos::core::ecs
#endif // CUBOS_CORE_ECS_DISPATCHER_HPP
47 changes: 47 additions & 0 deletions core/src/cubos/core/al/oal_audio_device.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
#include <cubos/core/al/oal_audio_device.hpp>
#include <cubos/core/log.hpp>

#ifdef WITH_OPENAL
#include <AL/al.h>
#include <AL/alc.h>
#endif // WITH_OPENAL

#define UNSUPPORTED() \
do \
{ \
CUBOS_CRITICAL("Unsupported when building without OpenAL"); \
abort(); \
} while (0)

using namespace cubos::core::al;

#ifdef WITH_OPENAL
class OALBuffer : public impl::Buffer
{
public:
Expand Down Expand Up @@ -127,25 +137,35 @@ class OALSource : public impl::Source

ALuint id;
};
#endif // WITH_OPENAL

OALAudioDevice::OALAudioDevice(std::string specifier)
{
#ifdef WITH_OPENAL
auto device = alcOpenDevice(specifier.c_str());
auto context = alcCreateContext(device, nullptr);
alcMakeContextCurrent(context);
#else
UNSUPPORTED();
#endif // WITH_OPENAL
}

OALAudioDevice::~OALAudioDevice()
{
#ifdef WITH_OPENAL
auto context = alcGetCurrentContext();
auto device = alcGetContextsDevice(context);
alcMakeContextCurrent(nullptr);
alcDestroyContext(context);
alcCloseDevice(device);
#else
UNSUPPORTED();
#endif // WITH_OPENAL
}

void OALAudioDevice::enumerateDevices(std::vector<std::string>& devices)
{
#ifdef WITH_OPENAL
if (alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT") == AL_FALSE)
{
CUBOS_CRITICAL("Missing extension ALC_ENUMERATION_EXT");
Expand All @@ -160,47 +180,74 @@ void OALAudioDevice::enumerateDevices(std::vector<std::string>& devices)
devices.push_back(s);
pointer += s.size() + 1;
}
#else
UNSUPPORTED();
#endif // WITH_OPENAL
}

std::string OALAudioDevice::getDefaultDevice()
{
#ifdef WITH_OPENAL
if (alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT") == AL_FALSE)
{
CUBOS_CRITICAL("Missing extension ALC_ENUMERATION_EXT");
abort();
}

return alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER);
#else
UNSUPPORTED();
#endif // WITH_OPENAL
}

Buffer OALAudioDevice::createBuffer()
{
#ifdef WITH_OPENAL
ALuint id;
alGenBuffers(1, &id);

return std::make_shared<OALBuffer>(id);
#else
UNSUPPORTED();
#endif // WITH_OPENAL
}

Source OALAudioDevice::createSource()
{
#ifdef WITH_OPENAL
ALuint sources;
alGenSources(1, &sources);

return std::make_shared<OALSource>(sources);
#else
UNSUPPORTED();
#endif // WITH_OPENAL
}

void OALAudioDevice::setListenerPosition(const glm::vec3& position)
{
#ifdef WITH_OPENAL
alListener3f(AL_POSITION, position.x, position.y, position.z);
#else
UNSUPPORTED();
#endif // WITH_OPENAL
}

void OALAudioDevice::setListenerOrientation(const glm::vec3& forward, const glm::vec3& up)
{
#ifdef WITH_OPENAL
float orientation[6] = {forward.x, forward.y, forward.z, up.x, up.y, up.z};
alListenerfv(AL_ORIENTATION, orientation);
#else
UNSUPPORTED();
#endif // WITH_OPENAL
}

void OALAudioDevice::setListenerVelocity(const glm::vec3& velocity)
{
#ifdef WITH_OPENAL
alListener3f(AL_VELOCITY, velocity.x, velocity.y, velocity.z);
#else
UNSUPPORTED();
#endif // WITH_OPENAL
}
Loading

0 comments on commit f82eb32

Please sign in to comment.