Minor refactor
This commit is contained in:
parent
0d36f52bdd
commit
2ad115a2a8
@ -3,6 +3,7 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
|
||||
#ifdef __APPLE__
|
||||
@ -192,13 +193,12 @@ char* load_wav(const std::string& filename,
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char* data = new char[size];
|
||||
std::unique_ptr<char[]> data (new char[size]);
|
||||
try {
|
||||
in.read(data, size);
|
||||
return data;
|
||||
in.read(data.get(), size);
|
||||
return data.release();
|
||||
}
|
||||
catch (const std::exception&) {
|
||||
delete[] data;
|
||||
std::cerr << "ERROR: Could not load wav data of \"" << filename << "\"" << std::endl;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -356,7 +356,7 @@ JObject& JObject::put(string key, int value) {
|
||||
|
||||
JObject& JObject::put(string key, int64_t value) {
|
||||
auto found = map.find(key);
|
||||
if (found != map.end()) delete found->second;
|
||||
if (found != map.end()) found->second;
|
||||
valvalue val;
|
||||
val.integer = value;
|
||||
map.insert(make_pair(key, new Value(valtype::integer, val)));
|
||||
|
||||
@ -66,7 +66,7 @@ Engine::Engine(EngineSettings& settings, EnginePaths* paths)
|
||||
}
|
||||
|
||||
Audio::initialize();
|
||||
gui = new gui::GUI();
|
||||
gui = std::make_unique<gui::GUI>();
|
||||
if (settings.ui.language == "auto") {
|
||||
settings.ui.language = langs::locale_by_envlocale(platform::detect_locale(), paths->getResources());
|
||||
}
|
||||
@ -125,7 +125,6 @@ void Engine::mainloop() {
|
||||
Engine::~Engine() {
|
||||
scripting::close();
|
||||
screen = nullptr;
|
||||
delete gui;
|
||||
|
||||
Audio::finalize();
|
||||
|
||||
@ -182,7 +181,7 @@ void Engine::setLanguage(std::string locale) {
|
||||
}
|
||||
|
||||
gui::GUI* Engine::getGUI() {
|
||||
return gui;
|
||||
return gui.get();
|
||||
}
|
||||
|
||||
EngineSettings& Engine::getSettings() {
|
||||
|
||||
@ -40,7 +40,7 @@ class Engine {
|
||||
double lastTime = 0.0;
|
||||
double delta = 0.0;
|
||||
|
||||
gui::GUI* gui;
|
||||
std::unique_ptr<gui::GUI> gui;
|
||||
public:
|
||||
Engine(EngineSettings& settings, EnginePaths* paths);
|
||||
~Engine();
|
||||
|
||||
@ -73,12 +73,10 @@ WorldFiles::WorldFiles(fs::path directory, const DebugSettings& settings)
|
||||
: directory(directory),
|
||||
generatorTestMode(settings.generatorTestMode),
|
||||
doWriteLights(settings.doWriteLights) {
|
||||
compressionBuffer = new ubyte[CHUNK_DATA_LEN * 2];
|
||||
compressionBuffer.reset(new ubyte[CHUNK_DATA_LEN * 2]);
|
||||
}
|
||||
|
||||
WorldFiles::~WorldFiles(){
|
||||
delete[] compressionBuffer;
|
||||
regions.clear();
|
||||
}
|
||||
|
||||
WorldRegion* WorldFiles::getRegion(regionsmap& regions, int x, int z) {
|
||||
@ -98,10 +96,12 @@ WorldRegion* WorldFiles::getOrCreateRegion(regionsmap& regions, int x, int z) {
|
||||
}
|
||||
|
||||
ubyte* WorldFiles::compress(const ubyte* src, size_t srclen, size_t& len) {
|
||||
len = extrle::encode(src, srclen, compressionBuffer);
|
||||
ubyte* buffer = this->compressionBuffer.get();
|
||||
|
||||
len = extrle::encode(src, srclen, buffer);
|
||||
ubyte* data = new ubyte[len];
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
data[i] = compressionBuffer[i];
|
||||
data[i] = buffer[i];
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ public:
|
||||
regionsmap regions;
|
||||
regionsmap lights;
|
||||
std::filesystem::path directory;
|
||||
ubyte* compressionBuffer;
|
||||
std::unique_ptr<ubyte[]> compressionBuffer;
|
||||
bool generatorTestMode;
|
||||
bool doWriteLights;
|
||||
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
files::rafile::rafile(std::filesystem::path filename)
|
||||
files::rafile::rafile(fs::path filename)
|
||||
: file(filename, std::ios::binary | std::ios::ate) {
|
||||
if (!file) {
|
||||
throw std::runtime_error("could not to open file "+filename.string());
|
||||
@ -102,7 +102,7 @@ json::JObject* files::read_json(fs::path file) {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> files::read_list(std::filesystem::path filename) {
|
||||
std::vector<std::string> files::read_list(fs::path filename) {
|
||||
std::ifstream file(filename);
|
||||
if (!file) {
|
||||
throw std::runtime_error("could not to open file "+filename.u8string());
|
||||
|
||||
@ -18,11 +18,10 @@ BlocksPreview::BlocksPreview(Shader* shader,
|
||||
Atlas* atlas,
|
||||
const ContentGfxCache* cache)
|
||||
: shader(shader), atlas(atlas), cache(cache) {
|
||||
batch = new Batch3D(1024);
|
||||
batch = std::make_unique<Batch3D>(1024);
|
||||
}
|
||||
|
||||
BlocksPreview::~BlocksPreview() {
|
||||
delete batch;
|
||||
}
|
||||
|
||||
void BlocksPreview::begin(const Viewport* viewport) {
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
|
||||
#include "../typedefs.h"
|
||||
#include <glm/glm.hpp>
|
||||
#include <memory>
|
||||
|
||||
class Viewport;
|
||||
class Shader;
|
||||
@ -14,7 +15,7 @@ class ContentGfxCache;
|
||||
class BlocksPreview {
|
||||
Shader* shader;
|
||||
Atlas* atlas;
|
||||
Batch3D* batch;
|
||||
std::unique_ptr<Batch3D> batch;
|
||||
const ContentGfxCache* const cache;
|
||||
const Viewport* viewport;
|
||||
public:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user