even more steps sounds test

This commit is contained in:
MihailRis 2024-03-09 02:42:53 +03:00
parent 015b1c2ed7
commit 90f3373f46
11 changed files with 56 additions and 22 deletions

View File

@ -1,4 +1,5 @@
{
"material": "base:grass",
"texture-faces": [
"grass_side",
"grass_side",

View File

@ -7,6 +7,7 @@
"pane",
"pane"
],
"material": "base:wood",
"model": "aabb",
"hitbox": [0.0, 0.0, 0.0, 1.0, 1.0, 0.2],
"light-passing": true,

View File

@ -1,3 +1,4 @@
{
"texture": "planks"
"texture": "planks",
"material": "base:wood"
}

View File

@ -1,4 +1,5 @@
{
"material": "base:wood",
"texture-faces": [
"wood",
"wood",

View File

@ -80,7 +80,13 @@ void AssetsLoader::addDefaults(AssetsLoader& loader, const Content* content) {
loader.add(ASSET_TEXTURE, TEXTURES_FOLDER"/misc/moon.png", "misc/moon");
loader.add(ASSET_TEXTURE, TEXTURES_FOLDER"/misc/sun.png", "misc/sun");
loader.add(ASSET_TEXTURE, TEXTURES_FOLDER"/gui/crosshair.png", "gui/crosshair");
// (test code)
// TODO: remove
loader.add(ASSET_SOUND, SOUNDS_FOLDER"/steps/grass.ogg", "steps/grass");
loader.add(ASSET_SOUND, SOUNDS_FOLDER"/steps/stone.ogg", "steps/stone");
loader.add(ASSET_SOUND, SOUNDS_FOLDER"/steps/wood.ogg", "steps/wood");
loader.add(ASSET_SOUND, SOUNDS_FOLDER"/steps/ground.ogg", "steps/ground");
addLayouts(0, "core", loader.getPaths()->getMainRoot()/fs::path("layouts"), loader);
for (auto& entry : content->getPacks()) {

View File

@ -249,6 +249,9 @@ speakerid_t audio::play(
int priority,
int channel
) {
if (sound == nullptr) {
return 0;
}
if (!sound->variants.empty()) {
size_t index = rand() % (sound->variants.size() + 1);
if (index < sound->variants.size()) {

View File

@ -144,6 +144,8 @@ void ContentLoader::loadBlock(Block& def, std::string name, fs::path file) {
def.model = BlockModel::none;
}
root->str("material", def.material);
// rotation profile
std::string profile = "none";
root->str("rotation", profile);

View File

@ -1,11 +1,17 @@
#include "LevelFrontend.h"
#include "../world/Level.h"
#include "../assets/Assets.h"
#include "../graphics/Atlas.h"
#include "BlocksPreview.h"
#include "ContentGfxCache.h"
#include "../audio/audio.h"
#include "../world/Level.h"
#include "../voxels/Block.h"
#include "../assets/Assets.h"
#include "../graphics/Atlas.h"
#include "../logic/LevelController.h"
#include "../logic/PlayerController.h"
LevelFrontend::LevelFrontend(Level* level, Assets* assets)
: level(level),
assets(assets),
@ -13,6 +19,29 @@ LevelFrontend::LevelFrontend(Level* level, Assets* assets)
blocksAtlas(BlocksPreview::build(contentCache.get(), assets, level->content)) {
}
void LevelFrontend::observe(LevelController* controller) {
controller->getPlayerController()->listenBlockInteraction(
[=](Player*, glm::ivec3 pos, const Block* def, BlockInteraction type) {
if (type != BlockInteraction::step) {
return;
}
// (test code)
// TODO: replace with BlockMaterial properties access
auto sound = assets->getSound("steps/"+def->material.substr(def->material.find(':')+1));
audio::play(
sound,
glm::vec3(),
true,
0.333f,
1.0f,
false,
audio::PRIORITY_LOW,
audio::get_channel_index("regular")
);
}
);
}
LevelFrontend::~LevelFrontend() {
}

View File

@ -8,6 +8,7 @@ class Level;
class Assets;
class BlocksPreview;
class ContentGfxCache;
class LevelController;
class LevelFrontend {
Level* level;
@ -18,6 +19,8 @@ public:
LevelFrontend(Level* level, Assets* assets);
~LevelFrontend();
void observe(LevelController* controller);
Level* getLevel() const;
Assets* getAssets() const;
ContentGfxCache* getContentGfxCache() const;

View File

@ -100,24 +100,7 @@ LevelScreen::LevelScreen(Engine* engine, Level* level) : Screen(engine) {
worldRenderer = std::make_unique<WorldRenderer>(engine, frontend.get(), controller->getPlayer());
hud = std::make_unique<Hud>(engine, frontend.get(), controller->getPlayer());
controller->getPlayerController()->listenBlockInteraction(
[=](Player*, glm::ivec3 pos, const Block* def, BlockInteraction type) {
if (type != BlockInteraction::step) {
return;
}
auto sound = assets->getSound("steps/grass");
audio::play(
sound,
glm::vec3(),
true,
1.0f,
1.0f,
false,
audio::PRIORITY_LOW,
audio::get_channel_index("regular")
);
}
);
frontend->observe(controller.get());
backlight = settings.graphics.backlight;

View File

@ -20,6 +20,8 @@ inline constexpr uint FACE_PZ = 5;
inline constexpr uint BLOCK_AABB_GRID = 16;
inline std::string DEFAULT_MATERIAL = "base:stone";
struct block_funcs_set {
bool init: 1;
bool update: 1;
@ -96,6 +98,8 @@ public:
std::vector<glm::vec3> modelExtraPoints = {}; //initially made for tetragons
std::vector<UVRegion> modelUVs = {}; // boxes' tex-UVs also there
std::string material = DEFAULT_MATERIAL;
/// @brief Light emission R, G, B, S (sky lights: sun, moon, radioactive clouds)
uint8_t emission[4] {0, 0, 0, 0};
/// @brief Influences visible block sides for transparent blocks