diff --git a/res/content/base/blocks/grass_block.json b/res/content/base/blocks/grass_block.json index 8c3cfb14..4c7ecf7b 100644 --- a/res/content/base/blocks/grass_block.json +++ b/res/content/base/blocks/grass_block.json @@ -1,4 +1,5 @@ { + "material": "base:grass", "texture-faces": [ "grass_side", "grass_side", diff --git a/res/content/base/blocks/pane.json b/res/content/base/blocks/pane.json index f82f9e2d..0eebec49 100644 --- a/res/content/base/blocks/pane.json +++ b/res/content/base/blocks/pane.json @@ -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, diff --git a/res/content/base/blocks/planks.json b/res/content/base/blocks/planks.json index c3e31ff3..508fac23 100644 --- a/res/content/base/blocks/planks.json +++ b/res/content/base/blocks/planks.json @@ -1,3 +1,4 @@ { - "texture": "planks" + "texture": "planks", + "material": "base:wood" } \ No newline at end of file diff --git a/res/content/base/blocks/wood.json b/res/content/base/blocks/wood.json index e29d126a..db77a6bc 100644 --- a/res/content/base/blocks/wood.json +++ b/res/content/base/blocks/wood.json @@ -1,4 +1,5 @@ { + "material": "base:wood", "texture-faces": [ "wood", "wood", diff --git a/src/assets/AssetsLoader.cpp b/src/assets/AssetsLoader.cpp index 20e9af4a..74b3d41d 100644 --- a/src/assets/AssetsLoader.cpp +++ b/src/assets/AssetsLoader.cpp @@ -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()) { diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index 9280d882..6476aeb0 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -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()) { diff --git a/src/content/ContentLoader.cpp b/src/content/ContentLoader.cpp index 951e522c..eccedf16 100644 --- a/src/content/ContentLoader.cpp +++ b/src/content/ContentLoader.cpp @@ -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); diff --git a/src/frontend/LevelFrontend.cpp b/src/frontend/LevelFrontend.cpp index 9561dfb2..c406ebce 100644 --- a/src/frontend/LevelFrontend.cpp +++ b/src/frontend/LevelFrontend.cpp @@ -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() { } diff --git a/src/frontend/LevelFrontend.h b/src/frontend/LevelFrontend.h index 772c5309..ea8cbe33 100644 --- a/src/frontend/LevelFrontend.h +++ b/src/frontend/LevelFrontend.h @@ -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; diff --git a/src/frontend/screens.cpp b/src/frontend/screens.cpp index fb057c5a..c127e2a7 100644 --- a/src/frontend/screens.cpp +++ b/src/frontend/screens.cpp @@ -100,24 +100,7 @@ LevelScreen::LevelScreen(Engine* engine, Level* level) : Screen(engine) { worldRenderer = std::make_unique(engine, frontend.get(), controller->getPlayer()); hud = std::make_unique(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; diff --git a/src/voxels/Block.h b/src/voxels/Block.h index 8d941d00..698d29d9 100644 --- a/src/voxels/Block.h +++ b/src/voxels/Block.h @@ -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 modelExtraPoints = {}; //initially made for tetragons std::vector 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