fix world previews generation
This commit is contained in:
parent
acea4604fe
commit
6bc549dd90
@ -94,7 +94,11 @@ LevelScreen::LevelScreen(
|
||||
renderer->clear();
|
||||
return false;
|
||||
}));
|
||||
|
||||
controller->preQuitCallbacks.listen([this]() {
|
||||
if (!controller->getLevel()->getWorld()->isNameless()) {
|
||||
saveWorldPreview();
|
||||
}
|
||||
});
|
||||
animator = std::make_unique<TextureAnimator>();
|
||||
animator->addAnimations(assets.getAnimations());
|
||||
|
||||
@ -104,7 +108,6 @@ LevelScreen::LevelScreen(
|
||||
LevelScreen::~LevelScreen() {
|
||||
if (!controller->getLevel()->getWorld()->isNameless()) {
|
||||
saveDecorations();
|
||||
saveWorldPreview();
|
||||
}
|
||||
scripting::on_frontend_close();
|
||||
// unblock all bindings
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include "delegates.hpp"
|
||||
#include "graphics/core/commons.hpp"
|
||||
#include "util/CallbacksSet.hpp"
|
||||
#include "window/input.hpp"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
@ -23,29 +24,6 @@ namespace gui {
|
||||
using OnNumberChange = std::function<void(GUI&, double)>;
|
||||
using OnStringChange = std::function<void(GUI&, const std::string&)>;
|
||||
|
||||
template<typename... Args>
|
||||
class CallbacksSet {
|
||||
public:
|
||||
using Func = std::function<void(Args...)>;
|
||||
private:
|
||||
std::unique_ptr<std::vector<Func>> callbacks;
|
||||
public:
|
||||
void listen(const Func& callback) {
|
||||
if (callbacks == nullptr) {
|
||||
callbacks = std::make_unique<std::vector<Func>>();
|
||||
}
|
||||
callbacks->push_back(callback);
|
||||
}
|
||||
|
||||
void notify(Args&&... args) {
|
||||
if (callbacks) {
|
||||
for (auto& callback : *callbacks) {
|
||||
callback(std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<class TagT, typename... Args>
|
||||
class TaggedCallbacksSet {
|
||||
public:
|
||||
|
||||
@ -122,6 +122,7 @@ void LevelController::update(float delta, bool pause) {
|
||||
}
|
||||
|
||||
void LevelController::processBeforeQuit() {
|
||||
preQuitCallbacks.notify();
|
||||
// todo: move somewhere else
|
||||
for (auto player : level->players->getAll()) {
|
||||
if (player->chunks) {
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include "BlocksController.hpp"
|
||||
#include "ChunksController.hpp"
|
||||
#include "util/Clock.hpp"
|
||||
#include "util/CallbacksSet.hpp"
|
||||
|
||||
class Engine;
|
||||
class Level;
|
||||
@ -21,6 +22,8 @@ class LevelController {
|
||||
|
||||
util::Clock playerTickClock;
|
||||
public:
|
||||
CallbacksSet<> preQuitCallbacks;
|
||||
|
||||
LevelController(Engine* engine, std::unique_ptr<Level> level, Player* clientPlayer);
|
||||
|
||||
/// @param delta time elapsed since the last update
|
||||
|
||||
28
src/util/CallbacksSet.hpp
Normal file
28
src/util/CallbacksSet.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
template<typename... Args>
|
||||
class CallbacksSet {
|
||||
public:
|
||||
using Func = std::function<void(Args...)>;
|
||||
private:
|
||||
std::unique_ptr<std::vector<Func>> callbacks;
|
||||
public:
|
||||
void listen(const Func& callback) {
|
||||
if (callbacks == nullptr) {
|
||||
callbacks = std::make_unique<std::vector<Func>>();
|
||||
}
|
||||
callbacks->push_back(callback);
|
||||
}
|
||||
|
||||
void notify(Args&&... args) {
|
||||
if (callbacks) {
|
||||
for (auto& callback : *callbacks) {
|
||||
callback(std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user