add debug info in ResourceManager & SoundController & Time & Timeline

master
Vectozavr 2021-10-31 01:54:55 +07:00
parent 20869dad6b
commit 1b3e85039c
3 changed files with 15 additions and 11 deletions

View File

@ -174,8 +174,14 @@ void PlayerController::update() {
_player->reload();
}
if ((_inRunning || _player->velocity().sqrAbs() > 3) && _player->inCollision() && SoundController::getStatus(SoundTag("walk")) != sf::Sound::Status::Playing) {
int soundNum = (int)((double) rand() / RAND_MAX * 5) + 1;
SoundController::playSound(SoundTag("walk"), "sound/stonestep" + std::to_string(soundNum) + ".ogg");
bool walkSoundPlayed = false;
for(int k = 1; k < 7; k++) {
if(SoundController::getStatus(SoundTag("walkSound_" + std::to_string(k))) == sf::Sound::Status::Playing) {
walkSoundPlayed = true;
}
}
if ((_inRunning || _player->velocity().sqrAbs() > 3) && _player->inCollision() && !walkSoundPlayed) {
int soundNum = (int)((double) rand() / RAND_MAX * 6) + 1;
SoundController::playSound(SoundTag("walkSound_" + std::to_string(soundNum)), "sound/stonestep" + std::to_string(soundNum) + ".ogg");
}
}

View File

@ -22,8 +22,9 @@ void SoundController::playSound(const SoundTag& soundTag, const std::string& fil
return;
}
stopSound(soundTag);
if(_instance->_sounds.count(soundTag) == 0) {
_instance->_sounds.emplace(soundTag, sf::Sound(*ResourceManager::loadSoundBuffer(filename)));
}
_instance->_sounds[soundTag].play();
Log::log("SoundController::playSound(): play sound '" + soundTag.str() + "'");
@ -49,7 +50,6 @@ void SoundController::stopSound(const SoundTag& soundTag) {
if(_instance->_sounds.count(soundTag) > 0) {
_instance->_sounds[soundTag].stop();
}
_instance->_sounds.erase(soundTag);
Log::log("SoundController::stopSound(): sound '" + soundTag.str() + "' was stopped");
}
@ -62,7 +62,6 @@ sf::Sound::Status SoundController::getStatus(const SoundTag& soundTag) {
if(_instance->_sounds.count(soundTag) > 0) {
return _instance->_sounds[soundTag].getStatus();
} else {
_instance->_sounds.erase(soundTag);
return sf::Sound::Status::Stopped;
}
}
@ -70,8 +69,7 @@ sf::Sound::Status SoundController::getStatus(const SoundTag& soundTag) {
void SoundController::free() {
if(_validInstance) {
for(auto& [soundTag, sound] : _instance->_sounds) {
_instance->_sounds[soundTag].stop();
Log::log("SoundController::stopSound(): sound '" + soundTag.str() + "' was stopped");
stopSound(soundTag);
}
_instance->_sounds.clear();
}

View File

@ -40,7 +40,7 @@ FireInformation Weapon::fire(std::function<IntersectionInformation(const Vec3D&,
reload();
}
SoundController::playSound(SoundTag("fire"), _fireSound);
SoundController::playSound(SoundTag("fireSound_" + name().str()), _fireSound);
Log::log("Weapon::fire (" + std::to_string(_stockAmmo) + " : " + std::to_string(_clipAmmo) + ")");
return FireInformation{processFire(std::move(rayCastFunction), position, direction), true};
@ -58,7 +58,7 @@ void Weapon::reload() {
_stockAmmo = 0;
}
SoundController::playSound(SoundTag("reload"), _reloadSound);
SoundController::playSound(SoundTag("reloadSound_" + name().str()), _reloadSound);
Log::log("Weapon::reload (" + std::to_string(_stockAmmo) + " : " + std::to_string(_clipAmmo) + ")");
_lastReloadTime = Time::time();
}