Compare commits
6 Commits
ff94d338cc
...
901ecd4262
Author | SHA1 | Date |
---|---|---|
Green Sky | 901ecd4262 | |
Green Sky | 8036fdf2a9 | |
Green Sky | 5148ea7217 | |
Green Sky | ab0e5afb94 | |
Green Sky | 191e9f6b44 | |
Green Sky | 86c52c4fac |
|
@ -26,8 +26,6 @@ jobs:
|
|||
with:
|
||||
submodules: recursive
|
||||
|
||||
# TODO: cache
|
||||
|
||||
- name: Install Dependencies
|
||||
run: sudo apt update && sudo apt -y install libsdl2-dev xserver-xorg-video-dummy
|
||||
|
||||
|
@ -62,8 +60,6 @@ jobs:
|
|||
with:
|
||||
submodules: recursive
|
||||
|
||||
# TODO: cache
|
||||
|
||||
- name: Install Dependencies
|
||||
run: sudo apt update && sudo apt -y install libsdl2-dev
|
||||
|
||||
|
@ -102,9 +98,6 @@ jobs:
|
|||
with:
|
||||
submodules: recursive
|
||||
|
||||
#- name: Install Dependencies
|
||||
#run: sudo apt update && sudo apt -y install libsdl2-dev
|
||||
|
||||
- name: Setup emsdk
|
||||
uses: mymindstorm/setup-emsdk@v11
|
||||
with:
|
||||
|
@ -134,8 +127,6 @@ jobs:
|
|||
with:
|
||||
submodules: recursive
|
||||
|
||||
# TODO: cache
|
||||
|
||||
- name: Install Dependencies
|
||||
run: brew install sdl2
|
||||
|
||||
|
@ -156,7 +147,6 @@ jobs:
|
|||
submodules: recursive
|
||||
|
||||
# TODO: cache
|
||||
|
||||
- name: Install Dependencies
|
||||
run: vcpkg install sdl2[core,vulkan]:x64-windows
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit e4ccb878f47245a319704912435d3c89f34ad6be
|
||||
Subproject commit fef921132cae7588213d0f9bcd2fb9c8ffd8b7fc
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace MM::Components {
|
||||
struct Name {
|
||||
static const size_t max_str_len = 64;
|
||||
static const size_t max_str_len {64u};
|
||||
std::string str;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace MM::Components {
|
|||
|
||||
// used to lift 2D into 3D space. like a z-index in css/svg
|
||||
struct Position2D_ZOffset {
|
||||
float z_offset = 500.f; // default camera allows values to be between 0 and 1000
|
||||
float z_offset {500.f}; // default camera allows values to be between 0 and 1000
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Color, color)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Color, color)
|
||||
} // MM::Components
|
||||
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
|
||||
namespace glm {
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec2, x, y)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec3, x, y, z)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(vec4, x, y, z, w)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec2, x, y)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec3, x, y, z)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(vec4, x, y, z, w)
|
||||
|
||||
//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(mat4x4, [0], y, z, w)
|
||||
inline void to_json(nlohmann::json& nlohmann_json_j, const mat4x4& nlohmann_json_t) {
|
||||
inline void to_json(nlohmann::json& nlohmann_json_j, const mat4x4& nlohmann_json_t) {
|
||||
// TODO: make 2d array?
|
||||
nlohmann_json_j = nlohmann::json::array_t{};
|
||||
nlohmann_json_j[0] = nlohmann_json_t[0];
|
||||
|
@ -22,7 +22,7 @@ namespace glm {
|
|||
nlohmann_json_j[2] = nlohmann_json_t[2];
|
||||
nlohmann_json_j[3] = nlohmann_json_t[3];
|
||||
}
|
||||
inline void from_json(const nlohmann::json& nlohmann_json_j, mat4x4& nlohmann_json_t) {
|
||||
inline void from_json(const nlohmann::json& nlohmann_json_j, mat4x4& nlohmann_json_t) {
|
||||
if (!nlohmann_json_j.is_array()) {
|
||||
//throw nlohmann::json::type_error::create(0, "", nlohmann_json_j);
|
||||
assert(false && "expected array");
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <mm/components/name.hpp>
|
||||
|
||||
namespace MM::Components {
|
||||
// TODO: manual with str len limit
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Name, str)
|
||||
} // MM::Components
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position2D, pos)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position2D, pos)
|
||||
} // MM::Components
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position2D_ZOffset, z_offset)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position2D_ZOffset, z_offset)
|
||||
} // MM::Components
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Position3D, pos)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Position3D, pos)
|
||||
} // MM::Components
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Rotation2D, rot)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Rotation2D, rot)
|
||||
} // MM::Components
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Scale2D, scale)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Scale2D, scale)
|
||||
} // MM::Components
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Transform4x4, trans)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Transform4x4, trans)
|
||||
} // MM::Components
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DPosition, pos_vel)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DPosition, pos_vel)
|
||||
} // MM::Components
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DPositionIntent, intent)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DPositionIntent, intent)
|
||||
} // MM::Components
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
#include "./json_glm.hpp"
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Velocity2DRotation, rot_vel)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Velocity2DRotation, rot_vel)
|
||||
} // MM::Components
|
||||
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
#include <mm/components/view_dir2d.hpp>
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ViewDir2D, dir)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ViewDir2D, dir)
|
||||
} // MM::Components
|
||||
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
#include <mm/components/view_dir3d.hpp>
|
||||
|
||||
namespace MM::Components {
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ViewDir3D, yaw, pitch, roll)
|
||||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ViewDir3D, yaw, pitch, roll)
|
||||
} // MM::Components
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace MM::Components {
|
||||
|
||||
struct ViewDir2D {
|
||||
float dir = 0.f; // rad
|
||||
float dir {0.f}; // rad
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
namespace MM::Components {
|
||||
|
||||
struct ViewDir3D {
|
||||
float yaw = 0.f; // rad
|
||||
float pitch = 0.f; // rad
|
||||
float roll = 0.f; // rad
|
||||
float yaw {0.f}; // rad
|
||||
float pitch {0.f}; // rad
|
||||
float roll {0.f}; // rad
|
||||
};
|
||||
|
||||
} // MM::Components
|
||||
|
|
|
@ -316,6 +316,31 @@ nlohmann::json FilesystemService::readJson(const char* filepath) const {
|
|||
return r;
|
||||
}
|
||||
|
||||
nlohmann::ordered_json FilesystemService::readJsonOrdered(fs_file_t file) const {
|
||||
if (!file)
|
||||
return {};
|
||||
|
||||
seek(file, 0);
|
||||
|
||||
std::string buffer;
|
||||
readString(file, buffer);
|
||||
|
||||
// disable exeptions
|
||||
// TODO: use callback instead of readString()
|
||||
return nlohmann::ordered_json::parse(buffer, nullptr, false);
|
||||
}
|
||||
|
||||
nlohmann::ordered_json FilesystemService::readJsonOrdered(const char* filepath) const {
|
||||
if (!isFile(filepath)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto h = open(filepath, READ);
|
||||
auto r = readJsonOrdered(h);
|
||||
close(h);
|
||||
return r;
|
||||
}
|
||||
|
||||
bool FilesystemService::writeJson(fs_file_t file, nlohmann::json& j, const int indent, const char indent_char) const {
|
||||
if (!file) {
|
||||
LOG_ERROR("writing json to invalid file");
|
||||
|
|
|
@ -78,6 +78,9 @@ class FilesystemService : public Service {
|
|||
nlohmann::json readJson(fs_file_t file) const;
|
||||
nlohmann::json readJson(const char* filepath) const;
|
||||
|
||||
nlohmann::ordered_json readJsonOrdered(fs_file_t file) const;
|
||||
nlohmann::ordered_json readJsonOrdered(const char* filepath) const;
|
||||
|
||||
bool writeJson(fs_file_t file, nlohmann::json& j, const int indent = -1, const char indent_char = ' ') const;
|
||||
bool writeJson(const char* filepath, nlohmann::json& j, const int indent = -1, const char indent_char = ' ') const;
|
||||
|
||||
|
|
|
@ -85,8 +85,8 @@ private:
|
|||
|
||||
bool entityHasComponent(Registry& registry, EntityType& entity, ComponentTypeID type_id)
|
||||
{
|
||||
const auto storage_it = registry.storage(type_id);
|
||||
return storage_it != registry.storage().end() && storage_it->second.contains(entity);
|
||||
const auto* storage_ptr = registry.storage(type_id);
|
||||
return storage_ptr != nullptr && storage_ptr->contains(entity);
|
||||
}
|
||||
|
||||
public:
|
||||
|
@ -243,11 +243,11 @@ public:
|
|||
}
|
||||
});
|
||||
} else {
|
||||
entt::basic_runtime_view<entt::basic_sparse_set<EntityType>> view{};
|
||||
entt::runtime_view view{};
|
||||
for (const auto type : comp_list) {
|
||||
auto storage_it = registry.storage(type);
|
||||
if (storage_it != registry.storage().end()) {
|
||||
view.iterate(registry.storage(type)->second);
|
||||
auto* storage_ptr = registry.storage(type);
|
||||
if (storage_ptr != nullptr) {
|
||||
view.iterate(*storage_ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ void Camera3D(MM::Scene& scene) {
|
|||
ImGui::TextUnformatted("NO CAMERA!");
|
||||
return;
|
||||
}
|
||||
auto& camera = scene.ctx().at<MM::OpenGL::Camera3D>();
|
||||
auto& camera = scene.ctx().get<MM::OpenGL::Camera3D>();
|
||||
|
||||
static bool follow_entity = false;
|
||||
static MM::Entity tracking = entt::null;
|
||||
|
|
|
@ -157,7 +157,7 @@ namespace MM::Services {
|
|||
if (_show_time_delta_ctx) {
|
||||
if (ImGui::Begin("Scene TimeDelta Context", &_show_time_delta_ctx)) {
|
||||
if (scene.ctx().contains<MM::Components::TimeDelta>()) {
|
||||
auto& td = scene.ctx().at<MM::Components::TimeDelta>();
|
||||
auto& td = scene.ctx().get<MM::Components::TimeDelta>();
|
||||
ImGui::Value("tickDelta", td.tickDelta);
|
||||
ImGui::SliderFloat("deltaFactor", &td.deltaFactor, 0.f, 10.f, "%.5f", ImGuiSliderFlags_Logarithmic);
|
||||
} else {
|
||||
|
|
|
@ -117,7 +117,7 @@ void BatchedSpriteSheet::render(Services::OpenGLRenderer& rs, Engine& engine) {
|
|||
_vertexBuffer->bind(GL_ARRAY_BUFFER);
|
||||
_vao->bind();
|
||||
|
||||
auto& cam = scene.ctx().at<Camera3D>();
|
||||
auto& cam = scene.ctx().get<Camera3D>();
|
||||
|
||||
auto vp = cam.getViewProjection();
|
||||
_shader->setUniformMat4f("_VP", vp);
|
||||
|
|
|
@ -78,7 +78,7 @@ void FastSky::render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) {
|
|||
_vao->bind();
|
||||
|
||||
{
|
||||
auto& cam = scene.ctx().at<MM::OpenGL::Camera3D>();
|
||||
auto& cam = scene.ctx().get<MM::OpenGL::Camera3D>();
|
||||
MM::OpenGL::Camera3D tmp_cam = cam;
|
||||
// create cam with y up, bc shader says so
|
||||
tmp_cam.up = {0, 1, 0};
|
||||
|
@ -95,7 +95,7 @@ void FastSky::render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) {
|
|||
//}
|
||||
auto* ctx_ptr = &_default_context;
|
||||
if (scene.ctx().contains<FastSkyContext>()) {
|
||||
ctx_ptr = &scene.ctx().at<FastSkyContext>();
|
||||
ctx_ptr = &scene.ctx().get<FastSkyContext>();
|
||||
}
|
||||
|
||||
_shader->setUniform1f("time", ctx_ptr->time);
|
||||
|
|
|
@ -138,7 +138,7 @@ void LiteParticles2D::uploadParticles(Services::OpenGLRenderer&, Scene& scene) {
|
|||
return; // nothing to upload
|
||||
}
|
||||
|
||||
auto& queue = scene.ctx().at<Components::LiteParticles2DUploadQueue>();
|
||||
auto& queue = scene.ctx().get<Components::LiteParticles2DUploadQueue>();
|
||||
|
||||
while (!queue.queue.empty()) {
|
||||
// get range
|
||||
|
@ -200,7 +200,7 @@ void LiteParticles2D::computeParticles(Services::OpenGLRenderer&, Scene& scene)
|
|||
std::chrono::duration<double, std::ratio<1, 1>> deltaTime = newNow - _last_time;
|
||||
_last_time = newNow;
|
||||
|
||||
float time_delta = deltaTime.count() * scene.ctx().at<MM::Components::TimeDelta>().deltaFactor;
|
||||
float time_delta = deltaTime.count() * scene.ctx().get<MM::Components::TimeDelta>().deltaFactor;
|
||||
_time += time_delta;
|
||||
_tf_shader->setUniform1f("_time_delta", time_delta);
|
||||
_tf_shader->setUniform1f("_time", _time);
|
||||
|
@ -269,7 +269,7 @@ void LiteParticles2D::renderParticles(Services::OpenGLRenderer& rs, Scene& scene
|
|||
auto& rm_t = MM::ResourceManager<Texture>::ref();
|
||||
rm_t.get("MM::LiteParticles2DTypes::Render"_hs)->bind(0);
|
||||
|
||||
Camera3D& cam = scene.ctx().at<Camera3D>();
|
||||
Camera3D& cam = scene.ctx().get<Camera3D>();
|
||||
_points_shader->setUniformMat4f("_vp", cam.getViewProjection());
|
||||
|
||||
GLint view_port[4];
|
||||
|
|
|
@ -72,7 +72,7 @@ void SimpleRect::render(Services::OpenGLRenderer& rs, Engine& engine) {
|
|||
_shader->bind();
|
||||
_vao->bind();
|
||||
|
||||
Camera3D& cam = scene.ctx().at<Camera3D>();
|
||||
Camera3D& cam = scene.ctx().get<Camera3D>();
|
||||
auto vp = cam.getViewProjection();
|
||||
|
||||
scene.view<const Components::Transform4x4>().each([this, &scene, &vp](entt::entity e, const auto& t) {
|
||||
|
|
|
@ -80,7 +80,7 @@ void SimpleSprite::render(Services::OpenGLRenderer& rs, Engine& engine) {
|
|||
_vao->bind();
|
||||
|
||||
|
||||
Camera3D& cam = scene.ctx().at<Camera3D>();
|
||||
Camera3D& cam = scene.ctx().get<Camera3D>();
|
||||
auto vp = cam.getViewProjection();
|
||||
|
||||
scene.view<const Components::Transform4x4, Components::OpenGL::Texture>().each([this, &scene, &vp](entt::entity e, const auto& t, auto& tex) {
|
||||
|
|
|
@ -81,7 +81,7 @@ void SimpleSpriteSheet::render(Services::OpenGLRenderer& rs, Engine& engine) {
|
|||
_vertexBuffer->bind(GL_ARRAY_BUFFER);
|
||||
_vao->bind();
|
||||
|
||||
Camera3D& cam = scene.ctx().at<Camera3D>();
|
||||
Camera3D& cam = scene.ctx().get<Camera3D>();
|
||||
auto vp = cam.getViewProjection();
|
||||
|
||||
scene.view<const Components::Transform4x4, SpriteSheetRenderable>().each([this, &scene, &vp](entt::entity e, const auto& t, auto& spr) {
|
||||
|
|
|
@ -96,7 +96,7 @@ void Tilemap::render(MM::Services::OpenGLRenderer& rs, MM::Engine& engine) {
|
|||
_vertexBuffer->bind(GL_ARRAY_BUFFER);
|
||||
_vao->bind();
|
||||
|
||||
MM::OpenGL::Camera3D& cam = scene.ctx().at<MM::OpenGL::Camera3D>();
|
||||
MM::OpenGL::Camera3D& cam = scene.ctx().get<MM::OpenGL::Camera3D>();
|
||||
auto vp = cam.getViewProjection();
|
||||
|
||||
_shader->setUniform3f("_ambient_color", ambient_color);
|
||||
|
|
|
@ -81,7 +81,7 @@ void OrganizerSceneService::sceneFixedUpdate(Engine&) {
|
|||
_accumulator -= f_delta;
|
||||
continuous_counter++;
|
||||
|
||||
for (auto&& v : _scene->ctx().at<std::vector<entt::organizer::vertex>>()) {
|
||||
for (auto&& v : _scene->ctx().get<std::vector<entt::organizer::vertex>>()) {
|
||||
v.callback()(v.data(), *_scene);
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,8 @@ void OrganizerSceneService::updateOrganizerVertices(Scene& scene) {
|
|||
scene.ctx().emplace<MM::Components::TimeDelta>();
|
||||
}
|
||||
|
||||
SPDLOG_DEBUG("graph:\n{}", scene.ctx().at<std::vector<entt::organizer::vertex>>());
|
||||
// TODO: use entt::dot instead
|
||||
SPDLOG_DEBUG("graph:\n{}", scene.ctx().get<std::vector<entt::organizer::vertex>>());
|
||||
}
|
||||
|
||||
void OrganizerSceneService::resetTime(void) {
|
||||
|
|
|
@ -75,13 +75,13 @@ class ResourceManager {
|
|||
return reload<Loader>(entt::hashed_string{id}.value(), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
void discard(const res_id_type id) ENTT_NOEXCEPT {
|
||||
void discard(const res_id_type id) noexcept {
|
||||
if (auto it = _storage.find(id); it != _storage.end()) {
|
||||
_storage.erase(it);
|
||||
}
|
||||
}
|
||||
|
||||
void discard(const char* id) ENTT_NOEXCEPT {
|
||||
void discard(const char* id) noexcept {
|
||||
discard(entt::hashed_string{id}.value());
|
||||
}
|
||||
|
||||
|
@ -100,11 +100,11 @@ class ResourceManager {
|
|||
return _storage.empty();
|
||||
}
|
||||
|
||||
void clear(void) ENTT_NOEXCEPT {
|
||||
void clear(void) noexcept {
|
||||
_storage.clear();
|
||||
}
|
||||
|
||||
bool contains(const res_id_type id) const ENTT_NOEXCEPT {
|
||||
bool contains(const res_id_type id) const noexcept {
|
||||
return (_storage.find(id) != _storage.cend());
|
||||
}
|
||||
|
||||
|
|
|
@ -19,21 +19,6 @@ target_link_libraries(sound_service
|
|||
|
||||
###############################
|
||||
|
||||
add_library(filesystem_soloud_file
|
||||
./src/mm/soloud_filesystem_file_impl.hpp
|
||||
./src/mm/soloud_filesystem_file_impl.cpp
|
||||
|
||||
./src/mm/sound_loader_wav.hpp
|
||||
./src/mm/sound_loader_wav.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(filesystem_soloud_file
|
||||
filesystem_service
|
||||
soloud
|
||||
)
|
||||
|
||||
###############################
|
||||
|
||||
add_library(soloud_json
|
||||
./src/mm/soloud_json.hpp
|
||||
./src/mm/soloud_json.cpp
|
||||
|
@ -46,6 +31,24 @@ target_link_libraries(soloud_json
|
|||
nlohmann_json::nlohmann_json
|
||||
)
|
||||
|
||||
###############################
|
||||
|
||||
add_library(filesystem_soloud_file
|
||||
./src/mm/soloud_filesystem_file_impl.hpp
|
||||
./src/mm/soloud_filesystem_file_impl.cpp
|
||||
|
||||
./src/mm/sound_loader_wav.hpp
|
||||
./src/mm/sound_loader_wav.cpp
|
||||
./src/mm/sound_loader_sfxr.hpp
|
||||
./src/mm/sound_loader_sfxr.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(filesystem_soloud_file
|
||||
filesystem_service
|
||||
soloud
|
||||
soloud_json
|
||||
)
|
||||
|
||||
if (BUILD_TESTING)
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#include "./sound_loader_sfxr.hpp"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "./soloud_json.hpp"
|
||||
|
||||
#include <mm/services/filesystem.hpp>
|
||||
|
||||
|
||||
namespace MM {
|
||||
|
||||
std::shared_ptr<::SoLoud::Sfxr> SoundLoaderSfxrPreset::load(const ::SoLoud::Sfxr::SFXR_PRESETS preset, const int seed) const {
|
||||
auto sfxr = std::make_shared<::SoLoud::Sfxr>();
|
||||
sfxr->loadPreset(preset, seed);
|
||||
return sfxr;
|
||||
}
|
||||
|
||||
std::shared_ptr<::SoLoud::Sfxr> SoundLoaderSfxrJson::load(const nlohmann::json& j) const {
|
||||
auto sfxr = std::make_shared<::SoLoud::Sfxr>();
|
||||
*sfxr = j;
|
||||
return sfxr;
|
||||
}
|
||||
|
||||
std::shared_ptr<::SoLoud::Sfxr> SoundLoaderSfxrFile::load(const std::string& path, MM::Engine& engine) const {
|
||||
auto& fs = engine.getService<MM::Services::FilesystemService>();
|
||||
|
||||
if (!fs.isFile(path.c_str())) {
|
||||
// TODO: log error
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto j = fs.readJson(path.c_str());
|
||||
|
||||
return SoundLoaderSfxrJson{}.load(j);
|
||||
}
|
||||
|
||||
} // MM
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <soloud_sfxr.h>
|
||||
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
namespace MM {
|
||||
|
||||
// fwd
|
||||
class Engine;
|
||||
|
||||
struct SoundLoaderSfxrPreset {
|
||||
std::shared_ptr<::SoLoud::Sfxr> load(const ::SoLoud::Sfxr::SFXR_PRESETS preset, const int seed) const;
|
||||
};
|
||||
|
||||
struct SoundLoaderSfxrJson {
|
||||
std::shared_ptr<::SoLoud::Sfxr> load(const nlohmann::json& j) const;
|
||||
};
|
||||
|
||||
struct SoundLoaderSfxrFile {
|
||||
std::shared_ptr<::SoLoud::Sfxr> load(const std::string& path, MM::Engine& engine) const;
|
||||
};
|
||||
|
||||
} // MM
|
||||
|
|
@ -9,8 +9,10 @@ namespace MM {
|
|||
std::shared_ptr<::SoLoud::Wav> SoundLoaderWavFile::load(const std::string& path, Engine& engine) const {
|
||||
auto& fs = engine.getService<Services::FilesystemService>();
|
||||
|
||||
if (!fs.isFile(path.c_str()))
|
||||
if (!fs.isFile(path.c_str())) {
|
||||
// TODO: log error
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto h = fs.open(path.c_str());
|
||||
|
||||
|
@ -19,7 +21,7 @@ std::shared_ptr<::SoLoud::Wav> SoundLoaderWavFile::load(const std::string& path,
|
|||
auto ptr = std::make_shared<::SoLoud::Wav>();
|
||||
auto r = ptr->loadFile(&sl_f);
|
||||
if (r != ::SoLoud::SO_NO_ERROR) {
|
||||
// log error
|
||||
// TODO: log error
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,9 +5,11 @@
|
|||
#include <physfs.h>
|
||||
#include <mm/soloud_filesystem_file_impl.hpp>
|
||||
#include <mm/sound_loader_wav.hpp>
|
||||
#include <mm/sound_loader_sfxr.hpp>
|
||||
|
||||
#include <mm/resource_manager.hpp>
|
||||
|
||||
#include <soloud_sfxr.h>
|
||||
#include <soloud_wav.h>
|
||||
#include <soloud_wavstream.h>
|
||||
#include <soloud_monotone.h>
|
||||
|
@ -21,7 +23,7 @@ using namespace entt::literals;
|
|||
|
||||
extern char* argv0;
|
||||
|
||||
TEST(soloud_fs_loader, basic) {
|
||||
TEST(soloud_fs_loader, wav) {
|
||||
MM::Engine engine;
|
||||
|
||||
// setup
|
||||
|
@ -59,3 +61,38 @@ TEST(soloud_fs_loader, basic) {
|
|||
rm.clear();
|
||||
}
|
||||
|
||||
TEST(soloud_fs_loader, sfxr) {
|
||||
MM::Engine engine;
|
||||
|
||||
// setup
|
||||
auto& sound = engine.addService<MM::Services::SoundService>();
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::SoundService>());
|
||||
|
||||
engine.addService<MM::Services::FilesystemService>(argv0, "soloud_filesystem_loader_test");
|
||||
ASSERT_TRUE(engine.enableService<MM::Services::FilesystemService>());
|
||||
|
||||
auto& rm = MM::ResourceManager<SoLoud::Sfxr>::ref();
|
||||
|
||||
sound.engine.setGlobalVolume(0.4f);
|
||||
|
||||
ASSERT_FALSE(rm.contains("test_preset"_hs));
|
||||
rm.load<MM::SoundLoaderSfxrPreset>("test_preset", ::SoLoud::Sfxr::SFXR_PRESETS::EXPLOSION, 0);
|
||||
ASSERT_TRUE(rm.contains("test_preset"_hs));
|
||||
|
||||
// TODO: add load from json
|
||||
// TODO: add load from json from file
|
||||
|
||||
{
|
||||
auto sh = rm.get("test_preset"_hs);
|
||||
|
||||
sound.engine.play(*sh);
|
||||
|
||||
while (sound.engine.getActiveVoiceCount()) {
|
||||
using namespace std::chrono_literals;
|
||||
std::this_thread::sleep_for(5ms);
|
||||
}
|
||||
}
|
||||
|
||||
rm.clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,14 +7,14 @@ struct ScalarRange2 {
|
|||
T v_min {};
|
||||
T v_max {};
|
||||
|
||||
ScalarRange2(void) = default;
|
||||
constexpr ScalarRange2(void) = default;
|
||||
|
||||
ScalarRange2(const T& both) noexcept {
|
||||
constexpr ScalarRange2(const T& both) noexcept {
|
||||
v_min = both;
|
||||
v_max = both;
|
||||
}
|
||||
|
||||
ScalarRange2(const T& min, const T& max) noexcept {
|
||||
constexpr ScalarRange2(const T& min, const T& max) noexcept {
|
||||
if (min <= max) {
|
||||
v_min = min;
|
||||
v_max = max;
|
||||
|
@ -24,19 +24,19 @@ struct ScalarRange2 {
|
|||
}
|
||||
}
|
||||
|
||||
bool operator==(const ScalarRange2<T>& rhs) const {
|
||||
constexpr bool operator==(const ScalarRange2<T>& rhs) const {
|
||||
return min() == rhs.min() && max() == rhs.max();
|
||||
}
|
||||
|
||||
bool operator!=(const ScalarRange2<T>& rhs) const {
|
||||
constexpr bool operator!=(const ScalarRange2<T>& rhs) const {
|
||||
return !(*this == rhs);
|
||||
}
|
||||
|
||||
[[nodiscard]] T& min(void) { return v_min; }
|
||||
[[nodiscard]] T& max(void) { return v_max; }
|
||||
[[nodiscard]] constexpr T& min(void) { return v_min; }
|
||||
[[nodiscard]] constexpr T& max(void) { return v_max; }
|
||||
|
||||
[[nodiscard]] const T& min(void) const { return v_min; }
|
||||
[[nodiscard]] const T& max(void) const { return v_max; }
|
||||
[[nodiscard]] constexpr const T& min(void) const { return v_min; }
|
||||
[[nodiscard]] constexpr const T& max(void) const { return v_max; }
|
||||
|
||||
void setMin(const T& new_min) {
|
||||
min() = new_min;
|
||||
|
@ -57,7 +57,7 @@ struct ScalarRange2 {
|
|||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] bool inRange(T&& value) const {
|
||||
[[nodiscard]] constexpr bool inRange(T&& value) const {
|
||||
return value >= min() && value <= max();
|
||||
}
|
||||
};
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 40 KiB |
Loading…
Reference in New Issue