aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/facade')
-rw-r--r--src/crepe/facade/DB.cpp19
-rw-r--r--src/crepe/facade/SDLContext.cpp6
-rw-r--r--src/crepe/facade/Sound.cpp11
-rw-r--r--src/crepe/facade/Sound.h6
-rw-r--r--src/crepe/facade/SoundContext.cpp2
-rw-r--r--src/crepe/facade/SoundContext.h11
6 files changed, 33 insertions, 22 deletions
diff --git a/src/crepe/facade/DB.cpp b/src/crepe/facade/DB.cpp
index 0a2f455..80047a6 100644
--- a/src/crepe/facade/DB.cpp
+++ b/src/crepe/facade/DB.cpp
@@ -1,7 +1,7 @@
#include <cstring>
#include "Exception.h"
-#include "util/log.h"
+#include "util/Log.h"
#include "DB.h"
@@ -15,19 +15,18 @@ DB::DB(const string & path) {
// init database struct
libdb::DB * db;
if ((ret = libdb::db_create(&db, NULL, 0)) != 0)
- throw Exception("db_create: %s", libdb::db_strerror(ret));
+ throw Exception("db_create: {}", libdb::db_strerror(ret));
this->db = {db, [](libdb::DB * db) { db->close(db, 0); }};
// load or create database file
- if ((ret = this->db->open(this->db.get(), NULL, path.c_str(), NULL,
- libdb::DB_BTREE, DB_CREATE, 0))
- != 0)
- throw Exception("db->open: %s", libdb::db_strerror(ret));
+ ret = this->db->open(this->db.get(), NULL, path.c_str(), NULL,
+ libdb::DB_BTREE, DB_CREATE, 0);
+ if (ret != 0) throw Exception("db->open: {}", libdb::db_strerror(ret));
// create cursor
libdb::DBC * cursor;
- if ((ret = this->db->cursor(this->db.get(), NULL, &cursor, 0)) != 0)
- throw Exception("db->cursor: %s", libdb::db_strerror(ret));
+ ret = this->db->cursor(this->db.get(), NULL, &cursor, 0);
+ if (ret != 0) throw Exception("db->cursor: {}", libdb::db_strerror(ret));
this->cursor = {cursor, [](libdb::DBC * cursor) { cursor->close(cursor); }};
}
@@ -45,7 +44,7 @@ string DB::get(const string & key) {
memset(&db_val, 0, sizeof(libdb::DBT));
int ret = this->cursor->get(this->cursor.get(), &db_key, &db_val, DB_FIRST);
- if (ret != 0) throw Exception("cursor->get: %s", libdb::db_strerror(ret));
+ if (ret != 0) throw Exception("cursor->get: {}", libdb::db_strerror(ret));
return {static_cast<char *>(db_val.data), db_val.size};
}
@@ -53,7 +52,7 @@ void DB::set(const string & key, const string & value) {
libdb::DBT db_key = this->to_thing(key);
libdb::DBT db_val = this->to_thing(value);
int ret = this->db->put(this->db.get(), NULL, &db_key, &db_val, 0);
- if (ret != 0) throw Exception("cursor->get: %s", libdb::db_strerror(ret));
+ if (ret != 0) throw Exception("cursor->get: {}", libdb::db_strerror(ret));
}
bool DB::has(const std::string & key) noexcept {
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 46230b4..a68d940 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -15,7 +15,7 @@
#include "../api/Sprite.h"
#include "../api/Texture.h"
#include "../api/Transform.h"
-#include "../util/log.h"
+#include "../util/Log.h"
#include "Exception.h"
#include "SDLContext.h"
@@ -159,7 +159,7 @@ SDLContext::texture_from_path(const std::string & path) {
SDL_Surface * tmp = IMG_Load(path.c_str());
if (tmp == nullptr) {
- tmp = IMG_Load("../asset/texture/ERROR.png");
+ tmp = IMG_Load("../asset/texture/ERROR.png");
}
std::unique_ptr<SDL_Surface, std::function<void(SDL_Surface *)>>
@@ -171,7 +171,7 @@ SDLContext::texture_from_path(const std::string & path) {
this->game_renderer.get(), img_surface.get());
if (tmp_texture == nullptr) {
- throw Exception("Texture cannot be load from %s", path.c_str());
+ throw Exception("Texture cannot be load from {}", path);
}
std::unique_ptr<SDL_Texture, std::function<void(SDL_Texture *)>>
diff --git a/src/crepe/facade/Sound.cpp b/src/crepe/facade/Sound.cpp
index 648ec81..a65b052 100644
--- a/src/crepe/facade/Sound.cpp
+++ b/src/crepe/facade/Sound.cpp
@@ -1,22 +1,23 @@
-#include "../util/log.h"
+#include "../util/Log.h"
#include "Sound.h"
#include "SoundContext.h"
using namespace crepe;
+using namespace std;
-Sound::Sound(std::unique_ptr<Asset> res) {
+Sound::Sound(unique_ptr<Asset> res) {
dbg_trace();
this->load(std::move(res));
}
Sound::Sound(const char * src) {
dbg_trace();
- this->load(std::make_unique<Asset>(src));
+ this->load(make_unique<Asset>(src));
}
-void Sound::load(std::unique_ptr<Asset> res) {
- this->sample.load(res->canonical());
+void Sound::load(unique_ptr<Asset> res) {
+ this->sample.load(res->get_canonical().c_str());
}
void Sound::play() {
diff --git a/src/crepe/facade/Sound.h b/src/crepe/facade/Sound.h
index 183bd7c..402482f 100644
--- a/src/crepe/facade/Sound.h
+++ b/src/crepe/facade/Sound.h
@@ -8,6 +8,12 @@
namespace crepe {
+/**
+ * \brief Sound resource facade
+ *
+ * This class is a wrapper around a \c SoLoud::Wav instance, which holds a
+ * single sample. It is part of the sound facade.
+ */
class Sound {
public:
/**
diff --git a/src/crepe/facade/SoundContext.cpp b/src/crepe/facade/SoundContext.cpp
index 5e5a3a9..deb2b62 100644
--- a/src/crepe/facade/SoundContext.cpp
+++ b/src/crepe/facade/SoundContext.cpp
@@ -1,4 +1,4 @@
-#include "../util/log.h"
+#include "../util/Log.h"
#include "SoundContext.h"
diff --git a/src/crepe/facade/SoundContext.h b/src/crepe/facade/SoundContext.h
index d3123d2..d703c16 100644
--- a/src/crepe/facade/SoundContext.h
+++ b/src/crepe/facade/SoundContext.h
@@ -6,19 +6,24 @@
namespace crepe {
+/**
+ * \brief Sound engine facade
+ *
+ * This class is a wrapper around a \c SoLoud::Soloud instance, which provides
+ * the methods for playing \c Sound instances. It is part of the sound facade.
+ */
class SoundContext {
private:
+ // singleton
SoundContext();
virtual ~SoundContext();
-
- // singleton
- static SoundContext & get_instance();
SoundContext(const SoundContext &) = delete;
SoundContext(SoundContext &&) = delete;
SoundContext & operator=(const SoundContext &) = delete;
SoundContext & operator=(SoundContext &&) = delete;
private:
+ static SoundContext & get_instance();
SoLoud::Soloud engine;
friend class Sound;
};