add debug info in ResourceManager & SoundController & Time & Timeline
parent
a294b1de24
commit
9ea73ab184
|
@ -40,8 +40,8 @@ private:
|
||||||
public:
|
public:
|
||||||
explicit Object(ObjectNameTag nameTag) : _nameTag(std::move(nameTag)) {};
|
explicit Object(ObjectNameTag nameTag) : _nameTag(std::move(nameTag)) {};
|
||||||
Object(const Object& object) : _nameTag(object.name()), _transformMatrix(object.model()) {};
|
Object(const Object& object) : _nameTag(object.name()), _transformMatrix(object.model()) {};
|
||||||
|
|
||||||
// TODO: implement rotations using quaternions
|
// TODO: implement rotations using quaternions (?)
|
||||||
void transform(const Matrix4x4& t);
|
void transform(const Matrix4x4& t);
|
||||||
void transformRelativePoint(const Vec3D &point, const Matrix4x4& transform);
|
void transformRelativePoint(const Vec3D &point, const Matrix4x4& transform);
|
||||||
void translate(const Vec3D& dv);
|
void translate(const Vec3D& dv);
|
||||||
|
|
|
@ -16,6 +16,8 @@ bool ResourceManager::_validInstance = false;
|
||||||
void ResourceManager::init() {
|
void ResourceManager::init() {
|
||||||
_instance = new ResourceManager();
|
_instance = new ResourceManager();
|
||||||
_validInstance = true;
|
_validInstance = true;
|
||||||
|
|
||||||
|
Log::log("ResourceManager::init(): resource manager was initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceManager::unloadTextures() {
|
void ResourceManager::unloadTextures() {
|
||||||
|
@ -23,6 +25,9 @@ void ResourceManager::unloadTextures() {
|
||||||
_texture.second.reset();
|
_texture.second.reset();
|
||||||
}
|
}
|
||||||
_instance->_textures.clear();
|
_instance->_textures.clear();
|
||||||
|
|
||||||
|
Log::log("ResourceManager::unloadTextures(): all textures was unloaded");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceManager::unloadSoundBuffers() {
|
void ResourceManager::unloadSoundBuffers() {
|
||||||
|
@ -30,6 +35,8 @@ void ResourceManager::unloadSoundBuffers() {
|
||||||
_soundBuffer.second.reset();
|
_soundBuffer.second.reset();
|
||||||
}
|
}
|
||||||
_instance->_soundBuffers.clear();
|
_instance->_soundBuffers.clear();
|
||||||
|
|
||||||
|
Log::log("ResourceManager::unloadSoundBuffers(): all soundBuffers was unloaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceManager::unloadFonts() {
|
void ResourceManager::unloadFonts() {
|
||||||
|
@ -37,10 +44,14 @@ void ResourceManager::unloadFonts() {
|
||||||
_font.second.reset();
|
_font.second.reset();
|
||||||
}
|
}
|
||||||
_instance->_fonts.clear();
|
_instance->_fonts.clear();
|
||||||
|
|
||||||
|
Log::log("ResourceManager::unloadFonts(): all fonts was unloaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceManager::unloadObjects() {
|
void ResourceManager::unloadObjects() {
|
||||||
_instance->_objects.clear();
|
_instance->_objects.clear();
|
||||||
|
|
||||||
|
Log::log("ResourceManager::unloadObjects(): all objects was unloaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceManager::unloadAllResources() {
|
void ResourceManager::unloadAllResources() {
|
||||||
|
@ -52,12 +63,16 @@ void ResourceManager::unloadAllResources() {
|
||||||
unloadSoundBuffers();
|
unloadSoundBuffers();
|
||||||
unloadFonts();
|
unloadFonts();
|
||||||
unloadObjects();
|
unloadObjects();
|
||||||
|
|
||||||
|
Log::log("ResourceManager::unloadAllResources(): all resources was unloaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceManager::free() {
|
void ResourceManager::free() {
|
||||||
unloadAllResources();
|
unloadAllResources();
|
||||||
_validInstance = false;
|
_validInstance = false;
|
||||||
delete _instance;
|
delete _instance;
|
||||||
|
|
||||||
|
Log::log("ResourceManager::free(): pointer to 'ResourceManager' was freed");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<sf::Texture> ResourceManager::loadTexture(const std::string& filename) {
|
std::shared_ptr<sf::Texture> ResourceManager::loadTexture(const std::string& filename) {
|
||||||
|
@ -74,9 +89,12 @@ std::shared_ptr<sf::Texture> ResourceManager::loadTexture(const std::string& fil
|
||||||
// Otherwise - try to load it. If failure - return zero
|
// Otherwise - try to load it. If failure - return zero
|
||||||
std::shared_ptr<sf::Texture> texture(new sf::Texture);
|
std::shared_ptr<sf::Texture> texture(new sf::Texture);
|
||||||
if (!texture->loadFromFile(filename)) {
|
if (!texture->loadFromFile(filename)) {
|
||||||
|
Log::log("ResourceManager::loadTexture: error with loading texture '" + filename + "'");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log::log("ResourceManager::loadTexture: texture '" + filename + "' was loaded");
|
||||||
|
|
||||||
// If success - remember and return texture pointer
|
// If success - remember and return texture pointer
|
||||||
texture->setRepeated(true);
|
texture->setRepeated(true);
|
||||||
_instance->_textures.emplace(filename, texture);
|
_instance->_textures.emplace(filename, texture);
|
||||||
|
@ -98,9 +116,12 @@ std::shared_ptr<sf::SoundBuffer> ResourceManager::loadSoundBuffer(const std::str
|
||||||
// Otherwise - try to load it. If failure - return zero
|
// Otherwise - try to load it. If failure - return zero
|
||||||
std::shared_ptr<sf::SoundBuffer> soundBuffer(new sf::SoundBuffer);
|
std::shared_ptr<sf::SoundBuffer> soundBuffer(new sf::SoundBuffer);
|
||||||
if (!soundBuffer->loadFromFile(filename)) {
|
if (!soundBuffer->loadFromFile(filename)) {
|
||||||
|
Log::log("ResourceManager::loadSoundBuffer: error with loading sound buffer '" + filename + "'");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log::log("ResourceManager::loadSoundBuffer: sound buffer '" + filename + "' was loaded");
|
||||||
|
|
||||||
// If success - remember and return sound pointer
|
// If success - remember and return sound pointer
|
||||||
_instance->_soundBuffers.emplace(filename, soundBuffer);
|
_instance->_soundBuffers.emplace(filename, soundBuffer);
|
||||||
|
|
||||||
|
@ -121,9 +142,12 @@ std::shared_ptr<sf::Font> ResourceManager::loadFont(const std::string& filename)
|
||||||
// Otherwise - try to load it. If failure - return zero
|
// Otherwise - try to load it. If failure - return zero
|
||||||
std::shared_ptr<sf::Font> font(new sf::Font);
|
std::shared_ptr<sf::Font> font(new sf::Font);
|
||||||
if (!font->loadFromFile(filename)) {
|
if (!font->loadFromFile(filename)) {
|
||||||
|
Log::log("ResourceManager::loadFont: error with loading font: '" + filename + "'");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log::log("ResourceManager::loadFont: font '" + filename + "' was loaded");
|
||||||
|
|
||||||
// If success - remember and return font pointer
|
// If success - remember and return font pointer
|
||||||
_instance->_fonts.emplace(filename, font);
|
_instance->_fonts.emplace(filename, font);
|
||||||
|
|
||||||
|
@ -147,7 +171,7 @@ std::vector<std::shared_ptr<Mesh>> ResourceManager::loadObjects(const std::strin
|
||||||
|
|
||||||
std::ifstream file(filename);
|
std::ifstream file(filename);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
Log::log("Mesh::LoadObjects(): cannot load file from " + filename);
|
Log::log("Mesh::LoadObjects(): cannot load file from '" + filename + "'");
|
||||||
return objects;
|
return objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,6 +228,8 @@ std::vector<std::shared_ptr<Mesh>> ResourceManager::loadObjects(const std::strin
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
|
Log::log("Mesh::LoadObjects(): obj '" + filename + "' was loaded");
|
||||||
|
|
||||||
// If success - remember and return vector of objects pointer
|
// If success - remember and return vector of objects pointer
|
||||||
_instance->_objects.emplace(filename, objects);
|
_instance->_objects.emplace(filename, objects);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "SoundController.h"
|
#include "SoundController.h"
|
||||||
#include "ResourceManager.h"
|
#include "ResourceManager.h"
|
||||||
|
#include "utils/Log.h"
|
||||||
|
|
||||||
SoundController* SoundController::_instance = nullptr;
|
SoundController* SoundController::_instance = nullptr;
|
||||||
bool SoundController::_validInstance = false;
|
bool SoundController::_validInstance = false;
|
||||||
|
@ -12,6 +13,8 @@ bool SoundController::_validInstance = false;
|
||||||
void SoundController::init() {
|
void SoundController::init() {
|
||||||
_instance = new SoundController();
|
_instance = new SoundController();
|
||||||
_validInstance = true;
|
_validInstance = true;
|
||||||
|
|
||||||
|
Log::log("SoundController::init(): sound controller was initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundController::playSound(const SoundTag& soundTag, const std::string& filename) {
|
void SoundController::playSound(const SoundTag& soundTag, const std::string& filename) {
|
||||||
|
@ -22,6 +25,8 @@ void SoundController::playSound(const SoundTag& soundTag, const std::string& fil
|
||||||
stopSound(soundTag);
|
stopSound(soundTag);
|
||||||
_instance->_sounds.emplace(soundTag, sf::Sound(*ResourceManager::loadSoundBuffer(filename)));
|
_instance->_sounds.emplace(soundTag, sf::Sound(*ResourceManager::loadSoundBuffer(filename)));
|
||||||
_instance->_sounds[soundTag].play();
|
_instance->_sounds[soundTag].play();
|
||||||
|
|
||||||
|
Log::log("SoundController::playSound(): play sound '" + soundTag.str() + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundController::pauseSound(const SoundTag& soundTag) {
|
void SoundController::pauseSound(const SoundTag& soundTag) {
|
||||||
|
@ -32,6 +37,8 @@ void SoundController::pauseSound(const SoundTag& soundTag) {
|
||||||
if(_instance->_sounds.count(soundTag) > 0) {
|
if(_instance->_sounds.count(soundTag) > 0) {
|
||||||
_instance->_sounds[soundTag].pause();
|
_instance->_sounds[soundTag].pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log::log("SoundController::pauseSound(): sound '" + soundTag.str() + "' was paused");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SoundController::stopSound(const SoundTag& soundTag) {
|
void SoundController::stopSound(const SoundTag& soundTag) {
|
||||||
|
@ -43,6 +50,8 @@ void SoundController::stopSound(const SoundTag& soundTag) {
|
||||||
_instance->_sounds[soundTag].stop();
|
_instance->_sounds[soundTag].stop();
|
||||||
}
|
}
|
||||||
_instance->_sounds.erase(soundTag);
|
_instance->_sounds.erase(soundTag);
|
||||||
|
|
||||||
|
Log::log("SoundController::stopSound(): sound '" + soundTag.str() + "' was stopped");
|
||||||
}
|
}
|
||||||
|
|
||||||
sf::Sound::Status SoundController::getStatus(const SoundTag& soundTag) {
|
sf::Sound::Status SoundController::getStatus(const SoundTag& soundTag) {
|
||||||
|
@ -61,11 +70,13 @@ sf::Sound::Status SoundController::getStatus(const SoundTag& soundTag) {
|
||||||
void SoundController::free() {
|
void SoundController::free() {
|
||||||
if(_validInstance) {
|
if(_validInstance) {
|
||||||
for(auto& [soundTag, sound] : _instance->_sounds) {
|
for(auto& [soundTag, sound] : _instance->_sounds) {
|
||||||
sound.stop();
|
stopSound(soundTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_instance->_sounds.clear();
|
_instance->_sounds.clear();
|
||||||
_validInstance = false;
|
_validInstance = false;
|
||||||
delete _instance;
|
delete _instance;
|
||||||
|
|
||||||
|
Log::log("SoundController::free(): pointer to 'SoundController' was freed");
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "Animation.h"
|
#include "Animation.h"
|
||||||
#include "Timeline.h"
|
#include "Timeline.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "../utils/Log.h"
|
||||||
|
|
||||||
Timeline* Timeline::_instance = nullptr;
|
Timeline* Timeline::_instance = nullptr;
|
||||||
bool Timeline::_validInstance = false;
|
bool Timeline::_validInstance = false;
|
||||||
|
@ -13,6 +14,8 @@ bool Timeline::_validInstance = false;
|
||||||
void Timeline::init() {
|
void Timeline::init() {
|
||||||
_instance = new Timeline();
|
_instance = new Timeline();
|
||||||
_validInstance = true;
|
_validInstance = true;
|
||||||
|
|
||||||
|
Log::log("Timeline::init(): animation timeline was initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timeline::animate(const AnimationListTag& listName, std::shared_ptr<Animation> anim) {
|
void Timeline::animate(const AnimationListTag& listName, std::shared_ptr<Animation> anim) {
|
||||||
|
@ -21,6 +24,8 @@ void Timeline::animate(const AnimationListTag& listName, std::shared_ptr<Animati
|
||||||
}
|
}
|
||||||
|
|
||||||
_instance->_animations[listName].emplace_back(anim);
|
_instance->_animations[listName].emplace_back(anim);
|
||||||
|
|
||||||
|
Log::log("Timeline::animate(): add animation in '" + listName.str() + "' list");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timeline::deleteAllAnimations() {
|
void Timeline::deleteAllAnimations() {
|
||||||
|
@ -28,10 +33,15 @@ void Timeline::deleteAllAnimations() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int animCounter = 0;
|
||||||
|
|
||||||
for (auto& [listName, animationList] : _instance->_animations) {
|
for (auto& [listName, animationList] : _instance->_animations) {
|
||||||
|
animCounter += animationList.size();
|
||||||
animationList.clear();
|
animationList.clear();
|
||||||
}
|
}
|
||||||
_instance->_animations.clear();
|
_instance->_animations.clear();
|
||||||
|
|
||||||
|
Log::log("Timeline::deleteAllAnimations(): all " + std::to_string(animCounter) + " animations was deleted" );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Timeline::deleteAnimationList(const AnimationListTag& listName) {
|
void Timeline::deleteAnimationList(const AnimationListTag& listName) {
|
||||||
|
@ -39,8 +49,11 @@ void Timeline::deleteAnimationList(const AnimationListTag& listName) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int animCounter = _instance->_animations[listName].size();
|
||||||
_instance->_animations[listName].clear();
|
_instance->_animations[listName].clear();
|
||||||
_instance->_animations.erase(listName);
|
_instance->_animations.erase(listName);
|
||||||
|
|
||||||
|
Log::log("Timeline::deleteAnimationList(): list '" + listName.str() +"' with " + std::to_string(animCounter) + " animations was deleted" );
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool Timeline::isInAnimList(const AnimationListTag& listName) {
|
[[nodiscard]] bool Timeline::isInAnimList(const AnimationListTag& listName) {
|
||||||
|
@ -87,4 +100,6 @@ void Timeline::free() {
|
||||||
_validInstance = false;
|
_validInstance = false;
|
||||||
|
|
||||||
delete _instance;
|
delete _instance;
|
||||||
|
|
||||||
|
Log::log("Timeline::free(): pointer to 'Timeline' was freed");
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "Time.h"
|
#include "Time.h"
|
||||||
#include "../Consts.h"
|
#include "../Consts.h"
|
||||||
|
#include "Log.h"
|
||||||
|
|
||||||
using namespace std::chrono;
|
using namespace std::chrono;
|
||||||
|
|
||||||
|
@ -13,6 +14,8 @@ bool Time::_validInstance = false;
|
||||||
void Time::init() {
|
void Time::init() {
|
||||||
_instance = new Time();
|
_instance = new Time();
|
||||||
_validInstance = true;
|
_validInstance = true;
|
||||||
|
|
||||||
|
Log::log("Time::init(): time was initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
double Time::time() {
|
double Time::time() {
|
||||||
|
@ -68,4 +71,6 @@ int Time::fps() {
|
||||||
void Time::free() {
|
void Time::free() {
|
||||||
_validInstance = false;
|
_validInstance = false;
|
||||||
delete _instance;
|
delete _instance;
|
||||||
|
|
||||||
|
Log::log("Time::free(): pointer to 'Time' was freed");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue