mirror of
https://github.com/ondra-novak/gates_of_skeldal.git
synced 2025-07-09 16:10:27 -04:00
windows release build, fix book crash, fix lock, fix finale
This commit is contained in:
parent
3d8ee275e4
commit
d13297e4f4
24 changed files with 158 additions and 63 deletions
|
@ -26,9 +26,8 @@ void SDLContext::SDL_Deleter::operator ()(SDL_Texture* texture) {
|
|||
SDL_DestroyTexture(texture);
|
||||
}
|
||||
|
||||
void SDLContext::SDL_Audio_Deleter::operator()(void *x) {
|
||||
SDL_AudioDeviceID id = reinterpret_cast<std::uintptr_t>(x);
|
||||
SDL_CloseAudioDevice(id);
|
||||
void SDLContext::SDL_Audio_Deleter::operator()(SDL_AudioDeviceID x) {
|
||||
SDL_CloseAudioDevice(x);
|
||||
}
|
||||
|
||||
struct SDL_INIT_Context {
|
||||
|
@ -602,12 +601,12 @@ SDLContext::AudioInfo SDLContext::init_audio(const AudioConfig &config, SDL_Audi
|
|||
}
|
||||
throw std::runtime_error(err.str());
|
||||
}
|
||||
_audio.reset(reinterpret_cast<void *>(id));
|
||||
_audio.reset(id);
|
||||
|
||||
return {obtaied.freq};
|
||||
}
|
||||
void SDLContext::pause_audio(bool pause) {
|
||||
SDL_AudioDeviceID id = reinterpret_cast<std::intptr_t>(_audio.get());
|
||||
SDL_AudioDeviceID id = _audio.get();
|
||||
SDL_PauseAudioDevice(id, pause?1:0);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <vector>
|
||||
#include <libs/mouse.h>
|
||||
#include <functional>
|
||||
#include "unique_value.h"
|
||||
|
||||
#include <queue>
|
||||
|
||||
|
@ -124,7 +125,7 @@ protected:
|
|||
};
|
||||
|
||||
struct SDL_Audio_Deleter {
|
||||
void operator()(void *x);
|
||||
void operator()(SDL_AudioDeviceID x);
|
||||
};
|
||||
|
||||
|
||||
|
@ -142,7 +143,7 @@ protected:
|
|||
std::unique_ptr<SDL_Texture, SDL_Deleter> _texture;
|
||||
std::unique_ptr<SDL_Texture, SDL_Deleter> _texture2;
|
||||
std::unique_ptr<SDL_Texture, SDL_Deleter> _crt_effect;
|
||||
std::unique_ptr<void, SDL_Audio_Deleter> _audio;
|
||||
unique_value<SDL_AudioDeviceID, SDL_Audio_Deleter> _audio;
|
||||
SDL_Texture *_visible_texture;
|
||||
SDL_Texture *_hidden_texture;
|
||||
|
||||
|
|
96
platform/sdl/unique_value.h
Normal file
96
platform/sdl/unique_value.h
Normal file
|
@ -0,0 +1,96 @@
|
|||
#include <optional>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
template<typename T, typename Deleter>
|
||||
class unique_value {
|
||||
public:
|
||||
using value_type = T;
|
||||
using deleter_type = Deleter;
|
||||
|
||||
private:
|
||||
std::optional<T> value;
|
||||
deleter_type deleter;
|
||||
|
||||
public:
|
||||
unique_value() noexcept(std::is_nothrow_default_constructible_v<Deleter>)
|
||||
: value(std::nullopt), deleter{} { }
|
||||
|
||||
explicit unique_value(T v, Deleter d = Deleter{}) noexcept
|
||||
: value(std::move(v)), deleter(std::move(d)) { }
|
||||
|
||||
// Zakázání kopírování
|
||||
unique_value(const unique_value&) = delete;
|
||||
unique_value& operator=(const unique_value&) = delete;
|
||||
|
||||
unique_value(unique_value&& other) noexcept
|
||||
: value(std::move(other.value)), deleter(std::move(other.deleter))
|
||||
{
|
||||
other.value.reset();
|
||||
}
|
||||
|
||||
unique_value& operator=(unique_value&& other) noexcept {
|
||||
if (this != &other) {
|
||||
reset(); // Uvolní aktuální hodnotu (volá deleter)
|
||||
value = std::move(other.value);
|
||||
deleter = std::move(other.deleter);
|
||||
other.value.reset();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
~unique_value() {
|
||||
reset();
|
||||
}
|
||||
|
||||
T* operator->() {
|
||||
return &(*value);
|
||||
}
|
||||
const T* operator->() const {
|
||||
return &(*value);
|
||||
}
|
||||
|
||||
T& operator*() {
|
||||
return *value;
|
||||
}
|
||||
const T& operator*() const {
|
||||
return *value;
|
||||
}
|
||||
|
||||
T& get() {
|
||||
return *value;
|
||||
}
|
||||
const T& get() const {
|
||||
return *value;
|
||||
}
|
||||
|
||||
bool has_value() const noexcept {
|
||||
return value.has_value();
|
||||
}
|
||||
|
||||
explicit operator bool() const noexcept {
|
||||
return value.has_value();
|
||||
}
|
||||
|
||||
std::optional<T> release() noexcept {
|
||||
auto temp = std::move(value);
|
||||
value.reset();
|
||||
return temp;
|
||||
}
|
||||
|
||||
void reset() noexcept {
|
||||
if (value.has_value()) {
|
||||
deleter(*value);
|
||||
value.reset();
|
||||
}
|
||||
}
|
||||
void reset(T &&v) noexcept {
|
||||
reset();
|
||||
value = std::move(v);
|
||||
}
|
||||
void reset(const T &v) noexcept {
|
||||
reset();
|
||||
value = v;
|
||||
}
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue