audio fixes
This commit is contained in:
parent
3ee350fc0c
commit
8ac51752d3
5
res/content/base/block_materials/grass_block.json
Normal file
5
res/content/base/block_materials/grass_block.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"steps-sound": "steps/grass",
|
||||
"place-sound": "blocks/ground_place",
|
||||
"break-sound": "blocks/ground_break"
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"steps-sound": "steps/ground",
|
||||
"place-sound": "steps/ground_place",
|
||||
"break-sound": "steps/ground_break"
|
||||
"place-sound": "blocks/ground_place",
|
||||
"break-sound": "blocks/ground_break"
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"texture": "flower",
|
||||
"material": "base:grass",
|
||||
"draw-group": 1,
|
||||
"light-passing": true,
|
||||
"obstacle": false,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
{
|
||||
"texture": "grass",
|
||||
"material": "base:grass",
|
||||
"draw-group": 1,
|
||||
"light-passing": true,
|
||||
"obstacle": false,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"material": "base:grass",
|
||||
"material": "base:grass_block",
|
||||
"texture-faces": [
|
||||
"grass_side",
|
||||
"grass_side",
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
{
|
||||
"texture": "leaves"
|
||||
"texture": "leaves",
|
||||
"material": "base:grass"
|
||||
}
|
||||
@ -38,6 +38,11 @@ ALStream::ALStream(ALAudio* al, std::shared_ptr<PCMStream> source, bool keepSour
|
||||
ALStream::~ALStream() {
|
||||
bindSpeaker(0);
|
||||
source = nullptr;
|
||||
|
||||
while (!unusedBuffers.empty()) {
|
||||
al->freeBuffer(unusedBuffers.front());
|
||||
unusedBuffers.pop();
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<PCMStream> ALStream::getSource() const {
|
||||
@ -135,6 +140,11 @@ void ALStream::update(double delta) {
|
||||
return;
|
||||
}
|
||||
ALSpeaker* alspeaker = dynamic_cast<ALSpeaker*>(speaker);
|
||||
if (alspeaker->stopped) {
|
||||
speaker = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
uint alsource = alspeaker->source;
|
||||
|
||||
unqueueBuffers(alsource);
|
||||
@ -194,6 +204,8 @@ ALSpeaker::~ALSpeaker() {
|
||||
}
|
||||
|
||||
void ALSpeaker::update(const Channel* channel, float masterVolume) {
|
||||
if (source == 0)
|
||||
return;
|
||||
float gain = this->volume * channel->getVolume()*masterVolume;
|
||||
AL_CHECK(alSourcef(source, AL_GAIN, gain));
|
||||
|
||||
@ -265,7 +277,9 @@ void ALSpeaker::stop() {
|
||||
AL_CHECK(alSourceUnqueueBuffers(source, 1, &buffer));
|
||||
al->freeBuffer(buffer);
|
||||
}
|
||||
AL_CHECK(alSourcei(source, AL_BUFFER, 0));
|
||||
al->freeSource(source);
|
||||
source = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -395,8 +409,9 @@ uint ALAudio::getFreeSource(){
|
||||
}
|
||||
ALuint id;
|
||||
alGenSources(1, &id);
|
||||
if (!AL_GET_ERROR())
|
||||
if (!AL_GET_ERROR()) {
|
||||
return 0;
|
||||
}
|
||||
allsources.push_back(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
@ -17,7 +17,8 @@
|
||||
#define AL_CHECK(STATEMENT) STATEMENT; AL::check_errors(__FILE__, __LINE__)
|
||||
#define AL_GET_ERROR() AL::check_errors(__FILE__, __LINE__)
|
||||
|
||||
namespace AL {
|
||||
namespace AL {
|
||||
/// @return true if no errors
|
||||
bool check_errors(const std::string& filename, const std::uint_fast32_t line);
|
||||
|
||||
/// @brief alGetSourcef wrapper
|
||||
@ -27,6 +28,8 @@ namespace AL {
|
||||
/// @return field value or default
|
||||
inline float getSourcef(uint source, ALenum field, float def=0.0f) {
|
||||
float value = def;
|
||||
if (source == 0)
|
||||
return def;
|
||||
AL_CHECK(alGetSourcef(source, field, &value));
|
||||
return value;
|
||||
}
|
||||
@ -38,6 +41,8 @@ namespace AL {
|
||||
/// @return field value or default
|
||||
inline glm::vec3 getSource3f(uint source, ALenum field, glm::vec3 def={}) {
|
||||
glm::vec3 value = def;
|
||||
if (source == 0)
|
||||
return def;
|
||||
AL_CHECK(alGetSource3f(source, field, &value.x, &value.y, &value.z));
|
||||
return value;
|
||||
}
|
||||
@ -49,6 +54,8 @@ namespace AL {
|
||||
/// @return field value or default
|
||||
inline float getSourcei(uint source, ALenum field, int def=0) {
|
||||
int value = def;
|
||||
if (source == 0)
|
||||
return def;
|
||||
AL_CHECK(alGetSourcei(source, field, &value));
|
||||
return value;
|
||||
}
|
||||
|
||||
@ -368,6 +368,10 @@ size_t audio::count_speakers() {
|
||||
return speakers.size();
|
||||
}
|
||||
|
||||
size_t audio::count_streams() {
|
||||
return streams.size();
|
||||
}
|
||||
|
||||
void audio::update(double delta) {
|
||||
backend->update(delta);
|
||||
|
||||
|
||||
@ -484,6 +484,9 @@ namespace audio {
|
||||
/// @brief Get alive speakers number (including paused)
|
||||
extern size_t count_speakers();
|
||||
|
||||
/// @brief Get playing streams number (including paused)
|
||||
extern size_t count_streams();
|
||||
|
||||
/// @brief Update audio streams and sound instanced
|
||||
/// @param delta time elapsed since the last update (seconds)
|
||||
extern void update(double delta);
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "gui/controls.h"
|
||||
#include "../audio/audio.h"
|
||||
#include "../graphics/Mesh.h"
|
||||
#include "../objects/Player.h"
|
||||
#include "../physics/Hitbox.h"
|
||||
@ -52,6 +53,10 @@ std::shared_ptr<UINode> create_debug_panel(
|
||||
panel->add(create_label([](){
|
||||
return L"meshes: " + std::to_wstring(Mesh::meshesCount);
|
||||
}));
|
||||
panel->add(create_label([](){
|
||||
return L"speakers: " + std::to_wstring(audio::count_speakers())+
|
||||
L" streams: " + std::to_wstring(audio::count_streams());
|
||||
}));
|
||||
panel->add(create_label([=](){
|
||||
auto& settings = engine->getSettings();
|
||||
bool culling = settings.graphics.frustumCulling;
|
||||
|
||||
@ -382,7 +382,7 @@ void PlayerController::updateInteraction(){
|
||||
Block* target = indices->getBlockDef(vox->id);
|
||||
if (lclick && target->breakable){
|
||||
onBlockInteraction(
|
||||
glm::ivec3(x, y, z), def,
|
||||
glm::ivec3(x, y, z), target,
|
||||
BlockInteraction::destruction
|
||||
);
|
||||
blocksController->breakBlock(player.get(), target, x, y, z);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user