audio::reset_channel + minor refactor
This commit is contained in:
@@ -52,6 +52,12 @@ class AssetsLoader {
|
|||||||
public:
|
public:
|
||||||
AssetsLoader(Assets* assets, const ResPaths* paths);
|
AssetsLoader(Assets* assets, const ResPaths* paths);
|
||||||
void addLoader(int tag, aloader_func func);
|
void addLoader(int tag, aloader_func func);
|
||||||
|
|
||||||
|
/// @brief Enqueue asset load
|
||||||
|
/// @param tag asset type
|
||||||
|
/// @param filename asset file path
|
||||||
|
/// @param alias internal asset name
|
||||||
|
/// @param settings asset loading settings (based on asset type)
|
||||||
void add(
|
void add(
|
||||||
int tag,
|
int tag,
|
||||||
const std::string filename,
|
const std::string filename,
|
||||||
@@ -59,10 +65,12 @@ public:
|
|||||||
std::shared_ptr<AssetCfg> settings=nullptr
|
std::shared_ptr<AssetCfg> settings=nullptr
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
bool hasNext() const;
|
bool hasNext() const;
|
||||||
bool loadNext();
|
bool loadNext();
|
||||||
|
|
||||||
|
/// @brief Enqueue core and content assets
|
||||||
|
/// @param loader target loader
|
||||||
|
/// @param content engine content
|
||||||
static void addDefaults(AssetsLoader& loader, const Content* content);
|
static void addDefaults(AssetsLoader& loader, const Content* content);
|
||||||
|
|
||||||
const ResPaths* getPaths() const;
|
const ResPaths* getPaths() const;
|
||||||
|
|||||||
@@ -20,6 +20,14 @@
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
static bool animation(
|
||||||
|
Assets* assets,
|
||||||
|
const ResPaths* paths,
|
||||||
|
const std::string directory,
|
||||||
|
const std::string name,
|
||||||
|
Atlas* dstAtlas
|
||||||
|
);
|
||||||
|
|
||||||
bool assetload::texture(
|
bool assetload::texture(
|
||||||
AssetsLoader&,
|
AssetsLoader&,
|
||||||
Assets* assets,
|
Assets* assets,
|
||||||
@@ -102,7 +110,7 @@ bool assetload::atlas(
|
|||||||
Atlas* atlas = builder.build(2);
|
Atlas* atlas = builder.build(2);
|
||||||
assets->store(atlas, name);
|
assets->store(atlas, name);
|
||||||
for (const auto& file : builder.getNames()) {
|
for (const auto& file : builder.getNames()) {
|
||||||
assetload::animation(assets, paths, "textures", file, atlas);
|
animation(assets, paths, "textures", file, atlas);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -172,7 +180,7 @@ bool assetload::sound(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool assetload::animation(
|
static bool animation(
|
||||||
Assets* assets,
|
Assets* assets,
|
||||||
const ResPaths* paths,
|
const ResPaths* paths,
|
||||||
const std::string directory,
|
const std::string directory,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class AssetsLoader;
|
|||||||
class Atlas;
|
class Atlas;
|
||||||
struct AssetCfg;
|
struct AssetCfg;
|
||||||
|
|
||||||
|
/// @brief see AssetsLoader.h: aloader_func
|
||||||
namespace assetload {
|
namespace assetload {
|
||||||
bool texture(
|
bool texture(
|
||||||
AssetsLoader&,
|
AssetsLoader&,
|
||||||
@@ -60,14 +61,6 @@ namespace assetload {
|
|||||||
const std::string name,
|
const std::string name,
|
||||||
std::shared_ptr<AssetCfg> settings
|
std::shared_ptr<AssetCfg> settings
|
||||||
);
|
);
|
||||||
|
|
||||||
bool animation(
|
|
||||||
Assets*,
|
|
||||||
const ResPaths* paths,
|
|
||||||
const std::string directory,
|
|
||||||
const std::string name,
|
|
||||||
Atlas* dstAtlas
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ASSETS_ASSET_LOADERS_H_
|
#endif // ASSETS_ASSET_LOADERS_H_
|
||||||
+19
-11
@@ -157,10 +157,6 @@ void audio::initialize(bool enabled) {
|
|||||||
backend = NoAudio::create();
|
backend = NoAudio::create();
|
||||||
}
|
}
|
||||||
create_channel("master");
|
create_channel("master");
|
||||||
create_channel("regular");
|
|
||||||
create_channel("music");
|
|
||||||
create_channel("ambient");
|
|
||||||
create_channel("ui");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PCM* audio::load_PCM(const fs::path& file, bool headerOnly) {
|
PCM* audio::load_PCM(const fs::path& file, bool headerOnly) {
|
||||||
@@ -379,20 +375,32 @@ void audio::update(double delta) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio::reset() {
|
void audio::reset_channel(int index) {
|
||||||
|
auto channel = get_channel(index);
|
||||||
|
if (channel == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (auto& entry : speakers) {
|
for (auto& entry : speakers) {
|
||||||
entry.second->stop();
|
if (entry.second->getChannel() == index) {
|
||||||
|
entry.second->stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (auto& entry : streams) {
|
for (auto& entry : streams) {
|
||||||
entry.second->update(0.0f);
|
entry.second->update(0.0f);
|
||||||
}
|
}
|
||||||
for (auto& channel : channels) {
|
for (auto it = speakers.begin(); it != speakers.end();) {
|
||||||
if (channel->isPaused()) {
|
auto speaker = it->second.get();
|
||||||
channel->resume();
|
int speakerChannel = speaker->getChannel();
|
||||||
|
if (speakerChannel == index) {
|
||||||
|
streams.erase(it->first);
|
||||||
|
it = speakers.erase(it);
|
||||||
|
} else {
|
||||||
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
streams.clear();
|
if (channel->isPaused()) {
|
||||||
speakers.clear();
|
channel->resume();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void audio::close() {
|
void audio::close() {
|
||||||
|
|||||||
+2
-2
@@ -474,8 +474,8 @@ namespace audio {
|
|||||||
/// @param delta time elapsed since the last update (seconds)
|
/// @param delta time elapsed since the last update (seconds)
|
||||||
extern void update(double delta);
|
extern void update(double delta);
|
||||||
|
|
||||||
/// @brief Stop all playing audio, destroy all non-builtin channels
|
/// @brief Stop all playing audio in channel, reset channel state
|
||||||
extern void reset();
|
extern void reset_channel(int channel);
|
||||||
|
|
||||||
/// @brief Finalize audio system
|
/// @brief Finalize audio system
|
||||||
extern void close();
|
extern void close();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include <set>
|
#include <set>
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
|
|
||||||
using DrawGroups = std::set<unsigned char>;
|
using DrawGroups = std::set<ubyte>;
|
||||||
|
|
||||||
class Block;
|
class Block;
|
||||||
class ItemDef;
|
class ItemDef;
|
||||||
|
|||||||
+6
-1
@@ -57,6 +57,10 @@ Engine::Engine(EngineSettings& settings, EnginePaths* paths)
|
|||||||
throw initialize_error("could not initialize window");
|
throw initialize_error("could not initialize window");
|
||||||
}
|
}
|
||||||
audio::initialize(true);
|
audio::initialize(true);
|
||||||
|
audio::create_channel("regular");
|
||||||
|
audio::create_channel("music");
|
||||||
|
audio::create_channel("ambient");
|
||||||
|
audio::create_channel("ui");
|
||||||
|
|
||||||
auto resdir = paths->getResources();
|
auto resdir = paths->getResources();
|
||||||
scripting::initialize(this);
|
scripting::initialize(this);
|
||||||
@@ -238,7 +242,8 @@ double Engine::getDelta() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Engine::setScreen(std::shared_ptr<Screen> screen) {
|
void Engine::setScreen(std::shared_ptr<Screen> screen) {
|
||||||
audio::reset();
|
audio::reset_channel(audio::get_channel_index("regular"));
|
||||||
|
audio::reset_channel(audio::get_channel_index("ambient"));
|
||||||
this->screen = screen;
|
this->screen = screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-10
@@ -17,18 +17,18 @@
|
|||||||
|
|
||||||
#include "../voxels/Chunk.h"
|
#include "../voxels/Chunk.h"
|
||||||
|
|
||||||
const uint REGION_HEADER_SIZE = 10;
|
inline constexpr uint REGION_HEADER_SIZE = 10;
|
||||||
|
|
||||||
const uint REGION_LAYER_VOXELS = 0;
|
inline constexpr uint REGION_LAYER_VOXELS = 0;
|
||||||
const uint REGION_LAYER_LIGHTS = 1;
|
inline constexpr uint REGION_LAYER_LIGHTS = 1;
|
||||||
const uint REGION_LAYER_INVENTORIES = 2;
|
inline constexpr uint REGION_LAYER_INVENTORIES = 2;
|
||||||
|
|
||||||
const uint REGION_SIZE_BIT = 5;
|
inline constexpr uint REGION_SIZE_BIT = 5;
|
||||||
const uint REGION_SIZE = (1 << (REGION_SIZE_BIT));
|
inline constexpr uint REGION_SIZE = (1 << (REGION_SIZE_BIT));
|
||||||
const uint REGION_CHUNKS_COUNT = ((REGION_SIZE) * (REGION_SIZE));
|
inline constexpr uint REGION_CHUNKS_COUNT = ((REGION_SIZE) * (REGION_SIZE));
|
||||||
const uint REGION_FORMAT_VERSION = 2;
|
inline constexpr uint REGION_FORMAT_VERSION = 2;
|
||||||
const uint WORLD_FORMAT_VERSION = 1;
|
inline constexpr uint WORLD_FORMAT_VERSION = 1;
|
||||||
const uint MAX_OPEN_REGION_FILES = 16;
|
inline constexpr uint MAX_OPEN_REGION_FILES = 16;
|
||||||
|
|
||||||
#define REGION_FORMAT_MAGIC ".VOXREG"
|
#define REGION_FORMAT_MAGIC ".VOXREG"
|
||||||
#define WORLD_FORMAT_MAGIC ".VOXWLD"
|
#define WORLD_FORMAT_MAGIC ".VOXWLD"
|
||||||
|
|||||||
@@ -445,12 +445,12 @@ void TextBox::drawBackground(const GfxContext* pctx, Assets* assets) {
|
|||||||
if (isFocused() && multiline) {
|
if (isFocused() && multiline) {
|
||||||
batch->setColor(glm::vec4(1, 1, 1, 0.1f));
|
batch->setColor(glm::vec4(1, 1, 1, 0.1f));
|
||||||
glm::vec2 lcoord = label->calcCoord();
|
glm::vec2 lcoord = label->calcCoord();
|
||||||
lcoord.y -= 4;
|
lcoord.y -= 2;
|
||||||
uint line = label->getLineByTextIndex(caret);
|
uint line = label->getLineByTextIndex(caret);
|
||||||
int lineY = label->getLineYOffset(line);
|
int lineY = label->getLineYOffset(line);
|
||||||
int lineHeight = font->getLineHeight() * label->getLineInterval();
|
int lineHeight = font->getLineHeight() * label->getLineInterval();
|
||||||
batch->rect(lcoord.x, lcoord.y+lineY, label->getSize().x, 1);
|
batch->rect(lcoord.x, lcoord.y+lineY, label->getSize().x, 1);
|
||||||
batch->rect(lcoord.x, lcoord.y+lineY+lineHeight, label->getSize().x, 1);
|
batch->rect(lcoord.x, lcoord.y+lineY+lineHeight-2, label->getSize().x, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
label->setColor(glm::vec4(input.empty() ? 0.5f : 1.0f));
|
label->setColor(glm::vec4(input.empty() ? 0.5f : 1.0f));
|
||||||
|
|||||||
Reference in New Issue
Block a user