content-pack resources support
|
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 6.8 KiB |
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 6.6 KiB After Width: | Height: | Size: 6.6 KiB |
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 6.0 KiB After Width: | Height: | Size: 6.0 KiB |
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 7.2 KiB After Width: | Height: | Size: 7.2 KiB |
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 5.9 KiB |
|
Before Width: | Height: | Size: 7.4 KiB After Width: | Height: | Size: 7.4 KiB |
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 6.5 KiB |
|
Before Width: | Height: | Size: 7.9 KiB After Width: | Height: | Size: 7.9 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 6.2 KiB After Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 6.3 KiB |
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 6.7 KiB After Width: | Height: | Size: 6.7 KiB |
|
Before Width: | Height: | Size: 129 B After Width: | Height: | Size: 129 B |
|
Before Width: | Height: | Size: 163 B After Width: | Height: | Size: 163 B |
|
Before Width: | Height: | Size: 131 B After Width: | Height: | Size: 131 B |
|
Before Width: | Height: | Size: 171 KiB After Width: | Height: | Size: 171 KiB |
|
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
|
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 7.3 KiB |
|
Before Width: | Height: | Size: 7.5 KiB After Width: | Height: | Size: 7.5 KiB |
@ -7,19 +7,20 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "../constants.h"
|
#include "../constants.h"
|
||||||
|
#include "../files/engine_paths.h"
|
||||||
|
|
||||||
using std::filesystem::path;
|
using std::filesystem::path;
|
||||||
using std::unique_ptr;
|
using std::unique_ptr;
|
||||||
|
|
||||||
AssetsLoader::AssetsLoader(Assets* assets, path resdir)
|
AssetsLoader::AssetsLoader(Assets* assets, const ResPaths* paths)
|
||||||
: assets(assets), resdir(resdir) {
|
: assets(assets), paths(paths) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetsLoader::addLoader(int tag, aloader_func func) {
|
void AssetsLoader::addLoader(int tag, aloader_func func) {
|
||||||
loaders[tag] = func;
|
loaders[tag] = func;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssetsLoader::add(int tag, const path filename, const std::string alias) {
|
void AssetsLoader::add(int tag, const std::string filename, const std::string alias) {
|
||||||
entries.push(aloader_entry{ tag, filename, alias });
|
entries.push(aloader_entry{ tag, filename, alias });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +38,7 @@ bool AssetsLoader::loadNext() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
aloader_func loader = found->second;
|
aloader_func loader = found->second;
|
||||||
bool status = loader(assets, entry.filename, entry.alias);
|
bool status = loader(assets, paths, entry.filename, entry.alias);
|
||||||
entries.pop();
|
entries.pop();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -50,20 +51,19 @@ void AssetsLoader::createDefaults(AssetsLoader& loader) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AssetsLoader::addDefaults(AssetsLoader& loader) {
|
void AssetsLoader::addDefaults(AssetsLoader& loader) {
|
||||||
path resdir = loader.getDirectory();
|
loader.add(ASSET_SHADER, SHADERS_FOLDER"/main", "main");
|
||||||
loader.add(ASSET_SHADER, resdir/path(SHADERS_FOLDER"/main"), "main");
|
loader.add(ASSET_SHADER, SHADERS_FOLDER"/lines", "lines");
|
||||||
loader.add(ASSET_SHADER, resdir/path(SHADERS_FOLDER"/lines"), "lines");
|
loader.add(ASSET_SHADER, SHADERS_FOLDER"/ui", "ui");
|
||||||
loader.add(ASSET_SHADER, resdir/path(SHADERS_FOLDER"/ui"), "ui");
|
loader.add(ASSET_SHADER, SHADERS_FOLDER"/ui3d", "ui3d");
|
||||||
loader.add(ASSET_SHADER, resdir/path(SHADERS_FOLDER"/ui3d"), "ui3d");
|
loader.add(ASSET_SHADER, SHADERS_FOLDER"/background", "background");
|
||||||
loader.add(ASSET_SHADER, resdir/path(SHADERS_FOLDER"/background"), "background");
|
loader.add(ASSET_SHADER, SHADERS_FOLDER"/skybox_gen", "skybox_gen");
|
||||||
loader.add(ASSET_SHADER, resdir/path(SHADERS_FOLDER"/skybox_gen"), "skybox_gen");
|
|
||||||
|
|
||||||
loader.add(ASSET_ATLAS, resdir/path(TEXTURES_FOLDER"/blocks"), "blocks");
|
loader.add(ASSET_ATLAS, TEXTURES_FOLDER"/blocks", "blocks");
|
||||||
loader.add(ASSET_TEXTURE, resdir/path(TEXTURES_FOLDER"/menubg.png"), "menubg");
|
loader.add(ASSET_TEXTURE, TEXTURES_FOLDER"/menubg.png", "menubg");
|
||||||
|
|
||||||
loader.add(ASSET_FONT, resdir/path(FONTS_FOLDER"/font"), "normal");
|
loader.add(ASSET_FONT, FONTS_FOLDER"/font", "normal");
|
||||||
}
|
}
|
||||||
|
|
||||||
path AssetsLoader::getDirectory() const {
|
const ResPaths* AssetsLoader::getPaths() const {
|
||||||
return resdir;
|
return paths;
|
||||||
}
|
}
|
||||||
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <filesystem>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
@ -12,13 +11,14 @@ const short ASSET_SHADER = 2;
|
|||||||
const short ASSET_FONT = 3;
|
const short ASSET_FONT = 3;
|
||||||
const short ASSET_ATLAS = 4;
|
const short ASSET_ATLAS = 4;
|
||||||
|
|
||||||
|
class ResPaths;
|
||||||
class Assets;
|
class Assets;
|
||||||
|
|
||||||
typedef std::function<bool(Assets*, const std::filesystem::path&, const std::string&)> aloader_func;
|
typedef std::function<bool(Assets*, const ResPaths*, const std::string&, const std::string&)> aloader_func;
|
||||||
|
|
||||||
struct aloader_entry {
|
struct aloader_entry {
|
||||||
int tag;
|
int tag;
|
||||||
const std::filesystem::path filename;
|
const std::string filename;
|
||||||
const std::string alias;
|
const std::string alias;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -26,11 +26,11 @@ class AssetsLoader {
|
|||||||
Assets* assets;
|
Assets* assets;
|
||||||
std::map<int, aloader_func> loaders;
|
std::map<int, aloader_func> loaders;
|
||||||
std::queue<aloader_entry> entries;
|
std::queue<aloader_entry> entries;
|
||||||
std::filesystem::path resdir;
|
const ResPaths* paths;
|
||||||
public:
|
public:
|
||||||
AssetsLoader(Assets* assets, std::filesystem::path resdir);
|
AssetsLoader(Assets* assets, const ResPaths* paths);
|
||||||
void addLoader(int tag, aloader_func func);
|
void addLoader(int tag, aloader_func func);
|
||||||
void add(int tag, const std::filesystem::path filename, const std::string alias);
|
void add(int tag, const std::string filename, const std::string alias);
|
||||||
|
|
||||||
bool hasNext() const;
|
bool hasNext() const;
|
||||||
bool loadNext();
|
bool loadNext();
|
||||||
@ -38,7 +38,7 @@ public:
|
|||||||
static void createDefaults(AssetsLoader& loader);
|
static void createDefaults(AssetsLoader& loader);
|
||||||
static void addDefaults(AssetsLoader& loader);
|
static void addDefaults(AssetsLoader& loader);
|
||||||
|
|
||||||
std::filesystem::path getDirectory() const;
|
const ResPaths* getPaths() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ASSETS_ASSETS_LOADER_H
|
#endif // ASSETS_ASSETS_LOADER_H
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
#include "asset_loaders.h"
|
#include "asset_loaders.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <filesystem>
|
||||||
#include "Assets.h"
|
#include "Assets.h"
|
||||||
#include "../files/files.h"
|
#include "../files/files.h"
|
||||||
|
#include "../files/engine_paths.h"
|
||||||
#include "../coders/png.h"
|
#include "../coders/png.h"
|
||||||
#include "../graphics/Shader.h"
|
#include "../graphics/Shader.h"
|
||||||
#include "../graphics/Texture.h"
|
#include "../graphics/Texture.h"
|
||||||
@ -18,9 +20,10 @@ using std::filesystem::path;
|
|||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
bool assetload::texture(Assets* assets,
|
bool assetload::texture(Assets* assets,
|
||||||
const path filename,
|
const ResPaths* paths,
|
||||||
|
const string filename,
|
||||||
const string name) {
|
const string name) {
|
||||||
Texture* texture = png::load_texture(filename.string());
|
Texture* texture = png::load_texture(paths->find(filename).string());
|
||||||
if (texture == nullptr) {
|
if (texture == nullptr) {
|
||||||
std::cerr << "failed to load texture '" << name << "'" << std::endl;
|
std::cerr << "failed to load texture '" << name << "'" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
@ -30,10 +33,11 @@ bool assetload::texture(Assets* assets,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool assetload::shader(Assets* assets,
|
bool assetload::shader(Assets* assets,
|
||||||
const path filename,
|
const ResPaths* paths,
|
||||||
const string name) {
|
const string filename,
|
||||||
path vertexFile = path(filename.string()+".glslv");
|
const string name) {
|
||||||
path fragmentFile = path(filename.string()+".glslf");
|
path vertexFile = paths->find(filename+".glslv");
|
||||||
|
path fragmentFile = paths->find(filename+".glslf");
|
||||||
|
|
||||||
string vertexSource = files::read_string(vertexFile);
|
string vertexSource = files::read_string(vertexFile);
|
||||||
string fragmentSource = files::read_string(fragmentFile);
|
string fragmentSource = files::read_string(fragmentFile);
|
||||||
@ -49,13 +53,16 @@ bool assetload::shader(Assets* assets,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool assetload::atlas(Assets* assets,
|
bool assetload::atlas(Assets* assets,
|
||||||
const path directory,
|
const ResPaths* paths,
|
||||||
const string name) {
|
const string directory,
|
||||||
|
const string name) {
|
||||||
AtlasBuilder builder;
|
AtlasBuilder builder;
|
||||||
for (const auto& entry : fs::directory_iterator(directory)) {
|
for (const auto& file : paths->listdir(directory)) {
|
||||||
path file = entry.path();
|
|
||||||
if (file.extension() == ".png") {
|
if (file.extension() == ".png") {
|
||||||
string name = file.stem().string();
|
string name = file.stem().string();
|
||||||
|
if (builder.has(name)) {
|
||||||
|
continue; // skip duplicates
|
||||||
|
}
|
||||||
std::unique_ptr<ImageData> image (png::load_image(file.string()));
|
std::unique_ptr<ImageData> image (png::load_image(file.string()));
|
||||||
image->fixAlphaColor();
|
image->fixAlphaColor();
|
||||||
builder.add(name, image.release());
|
builder.add(name, image.release());
|
||||||
@ -67,11 +74,13 @@ bool assetload::atlas(Assets* assets,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool assetload::font(Assets* assets,
|
bool assetload::font(Assets* assets,
|
||||||
const path filename,
|
const ResPaths* paths,
|
||||||
const string name) {
|
const string filename,
|
||||||
|
const string name) {
|
||||||
vector<Texture*> pages;
|
vector<Texture*> pages;
|
||||||
for (size_t i = 0; i <= 4; i++) {
|
for (size_t i = 0; i <= 4; i++) {
|
||||||
string name = filename.string() + "_" + std::to_string(i) + ".png";
|
string name = filename + "_" + std::to_string(i) + ".png";
|
||||||
|
name = paths->find(name).string();
|
||||||
Texture* texture = png::load_texture(name);
|
Texture* texture = png::load_texture(name);
|
||||||
if (texture == nullptr) {
|
if (texture == nullptr) {
|
||||||
std::cerr << "failed to load bitmap font '" << name;
|
std::cerr << "failed to load bitmap font '" << name;
|
||||||
|
|||||||
@ -2,23 +2,27 @@
|
|||||||
#define ASSETS_ASSET_LOADERS_H_
|
#define ASSETS_ASSET_LOADERS_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <filesystem>
|
|
||||||
|
|
||||||
|
class ResPaths;
|
||||||
class Assets;
|
class Assets;
|
||||||
|
|
||||||
namespace assetload {
|
namespace assetload {
|
||||||
bool texture(Assets* assets,
|
bool texture(Assets* assets,
|
||||||
const std::filesystem::path filename,
|
const ResPaths* paths,
|
||||||
|
const std::string filename,
|
||||||
const std::string name);
|
const std::string name);
|
||||||
bool shader(Assets* assets,
|
bool shader(Assets* assets,
|
||||||
const std::filesystem::path filename,
|
const ResPaths* paths,
|
||||||
const std::string name);
|
const std::string filename,
|
||||||
bool atlas(Assets* assets,
|
|
||||||
const std::filesystem::path directory,
|
|
||||||
const std::string name);
|
const std::string name);
|
||||||
|
bool atlas(Assets* assets,
|
||||||
|
const ResPaths* paths,
|
||||||
|
const std::string directory,
|
||||||
|
const std::string name);
|
||||||
bool font(Assets* assets,
|
bool font(Assets* assets,
|
||||||
const std::filesystem::path filename,
|
const ResPaths* paths,
|
||||||
const std::string name);
|
const std::string filename,
|
||||||
|
const std::string name);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ASSETS_ASSET_LOADERS_H_
|
#endif // ASSETS_ASSET_LOADERS_H_
|
||||||
@ -5,25 +5,22 @@
|
|||||||
#include "../util/stringutil.h"
|
#include "../util/stringutil.h"
|
||||||
#include "../typedefs.h"
|
#include "../typedefs.h"
|
||||||
#include "../files/files.h"
|
#include "../files/files.h"
|
||||||
|
#include "../files/engine_paths.h"
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::filesystem::path;
|
using std::filesystem::path;
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
path GLSLExtension::getHeaderPath(string name) {
|
|
||||||
return libFolder/path(name+".glsl");
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLSLExtension::setLibFolder(path folder) {
|
|
||||||
this->libFolder = folder;
|
|
||||||
}
|
|
||||||
|
|
||||||
void GLSLExtension::setVersion(string version) {
|
void GLSLExtension::setVersion(string version) {
|
||||||
this->version = version;
|
this->version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLSLExtension::setPaths(const ResPaths* paths) {
|
||||||
|
this->paths = paths;
|
||||||
|
}
|
||||||
|
|
||||||
void GLSLExtension::loadHeader(string name) {
|
void GLSLExtension::loadHeader(string name) {
|
||||||
path file = getHeaderPath(name);
|
path file = paths->find("shaders/lib/"+name+".glsl");
|
||||||
string source = files::read_string(file);
|
string source = files::read_string(file);
|
||||||
addHeader(name, source);
|
addHeader(name, source);
|
||||||
}
|
}
|
||||||
@ -117,7 +114,6 @@ const string GLSLExtension::process(const path file, const string& source) {
|
|||||||
"expected '#include <filename>' syntax");
|
"expected '#include <filename>' syntax");
|
||||||
}
|
}
|
||||||
string name = line.substr(1, line.length()-2);
|
string name = line.substr(1, line.length()-2);
|
||||||
path hfile = getHeaderPath(name);
|
|
||||||
if (!hasHeader(name)) {
|
if (!hasHeader(name)) {
|
||||||
loadHeader(name);
|
loadHeader(name);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,19 +2,21 @@
|
|||||||
#define CODERS_GLSL_EXTESION_H_
|
#define CODERS_GLSL_EXTESION_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
|
class ResPaths;
|
||||||
|
|
||||||
class GLSLExtension {
|
class GLSLExtension {
|
||||||
std::unordered_map<std::string, std::string> headers;
|
std::unordered_map<std::string, std::string> headers;
|
||||||
std::unordered_map<std::string, std::string> defines;
|
std::unordered_map<std::string, std::string> defines;
|
||||||
std::filesystem::path libFolder;
|
|
||||||
std::string version = "330 core";
|
std::string version = "330 core";
|
||||||
|
|
||||||
|
const ResPaths* paths = nullptr;
|
||||||
void loadHeader(std::string name);
|
void loadHeader(std::string name);
|
||||||
std::filesystem::path getHeaderPath(std::string name);
|
|
||||||
public:
|
public:
|
||||||
void setLibFolder(std::filesystem::path folder);
|
void setPaths(const ResPaths* paths);
|
||||||
void setVersion(std::string version);
|
void setVersion(std::string version);
|
||||||
|
|
||||||
void define(std::string name, std::string value);
|
void define(std::string name, std::string value);
|
||||||
@ -30,4 +32,4 @@ public:
|
|||||||
const std::string process(const std::filesystem::path file, const std::string& source);
|
const std::string process(const std::filesystem::path file, const std::string& source);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CODERS_GLSL_EXTESION_H_
|
#endif // CODERS_GLSL_EXTESION_H_
|
||||||
|
|||||||
@ -52,29 +52,8 @@ Engine::Engine(EngineSettings& settings, EnginePaths* paths)
|
|||||||
|
|
||||||
auto resdir = paths->getResources();
|
auto resdir = paths->getResources();
|
||||||
contentPacks.push_back({"base", resdir/path("content/base")});
|
contentPacks.push_back({"base", resdir/path("content/base")});
|
||||||
{
|
loadContent();
|
||||||
ContentBuilder contentBuilder;
|
|
||||||
setup_definitions(&contentBuilder);
|
|
||||||
for (auto& pack : contentPacks) {
|
|
||||||
ContentLoader loader(pack.folder);
|
|
||||||
loader.load(&contentBuilder);
|
|
||||||
}
|
|
||||||
content.reset(contentBuilder.build());
|
|
||||||
}
|
|
||||||
Shader::preprocessor->setLibFolder(paths->getResources()/path("shaders/lib"));
|
|
||||||
|
|
||||||
assets = new Assets();
|
|
||||||
std::cout << "-- loading assets" << std::endl;
|
|
||||||
AssetsLoader loader(assets, paths->getResources());
|
|
||||||
AssetsLoader::createDefaults(loader);
|
|
||||||
AssetsLoader::addDefaults(loader);
|
|
||||||
while (loader.hasNext()) {
|
|
||||||
if (!loader.loadNext()) {
|
|
||||||
delete assets;
|
|
||||||
Window::terminate();
|
|
||||||
throw initialize_error("could not to initialize assets");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Audio::initialize();
|
Audio::initialize();
|
||||||
gui = new GUI();
|
gui = new GUI();
|
||||||
if (settings.ui.language == "auto") {
|
if (settings.ui.language == "auto") {
|
||||||
@ -120,7 +99,7 @@ void Engine::mainloop() {
|
|||||||
gui->act(delta);
|
gui->act(delta);
|
||||||
screen->update(delta);
|
screen->update(delta);
|
||||||
screen->draw(delta);
|
screen->draw(delta);
|
||||||
gui->draw(&batch, assets);
|
gui->draw(&batch, assets.get());
|
||||||
|
|
||||||
Window::swapInterval(settings.display.swapInterval);
|
Window::swapInterval(settings.display.swapInterval);
|
||||||
Window::swapBuffers();
|
Window::swapBuffers();
|
||||||
@ -135,7 +114,7 @@ Engine::~Engine() {
|
|||||||
Audio::finalize();
|
Audio::finalize();
|
||||||
|
|
||||||
std::cout << "-- shutting down" << std::endl;
|
std::cout << "-- shutting down" << std::endl;
|
||||||
delete assets;
|
assets.reset();
|
||||||
Window::terminate();
|
Window::terminate();
|
||||||
std::cout << "-- engine finished" << std::endl;
|
std::cout << "-- engine finished" << std::endl;
|
||||||
}
|
}
|
||||||
@ -149,7 +128,7 @@ EngineSettings& Engine::getSettings() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Assets* Engine::getAssets() {
|
Assets* Engine::getAssets() {
|
||||||
return assets;
|
return assets.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::setScreen(shared_ptr<Screen> screen) {
|
void Engine::setScreen(shared_ptr<Screen> screen) {
|
||||||
@ -173,3 +152,33 @@ void Engine::setLanguage(string locale) {
|
|||||||
langs::setup(paths->getResources(), locale, contentPacks);
|
langs::setup(paths->getResources(), locale, contentPacks);
|
||||||
menus::create_menus(this, gui->getMenu());
|
menus::create_menus(this, gui->getMenu());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::loadContent() {
|
||||||
|
auto resdir = paths->getResources();
|
||||||
|
ContentBuilder contentBuilder;
|
||||||
|
setup_definitions(&contentBuilder);
|
||||||
|
|
||||||
|
vector<path> resRoots;
|
||||||
|
for (auto& pack : contentPacks) {
|
||||||
|
ContentLoader loader(pack.folder);
|
||||||
|
loader.load(&contentBuilder);
|
||||||
|
resRoots.push_back(pack.folder);
|
||||||
|
}
|
||||||
|
content.reset(contentBuilder.build());
|
||||||
|
resPaths.reset(new ResPaths(resdir, resRoots));
|
||||||
|
|
||||||
|
Shader::preprocessor->setPaths(resPaths.get());
|
||||||
|
|
||||||
|
assets.reset(new Assets());
|
||||||
|
std::cout << "-- loading assets" << std::endl;
|
||||||
|
AssetsLoader loader(assets.get(), resPaths.get());
|
||||||
|
AssetsLoader::createDefaults(loader);
|
||||||
|
AssetsLoader::addDefaults(loader);
|
||||||
|
while (loader.hasNext()) {
|
||||||
|
if (!loader.loadNext()) {
|
||||||
|
assets.reset();
|
||||||
|
Window::terminate();
|
||||||
|
throw initialize_error("could not to initialize assets");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -8,13 +8,15 @@
|
|||||||
#include "typedefs.h"
|
#include "typedefs.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
|
|
||||||
|
#include "assets/Assets.h"
|
||||||
#include "content/Content.h"
|
#include "content/Content.h"
|
||||||
#include "content/ContentPack.h"
|
#include "content/ContentPack.h"
|
||||||
|
#include "files/engine_paths.h"
|
||||||
|
|
||||||
class Assets;
|
|
||||||
class Level;
|
class Level;
|
||||||
class Screen;
|
class Screen;
|
||||||
class EnginePaths;
|
class EnginePaths;
|
||||||
|
class ResPaths;
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
class GUI;
|
class GUI;
|
||||||
@ -26,12 +28,13 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class Engine {
|
class Engine {
|
||||||
Assets* assets;
|
std::unique_ptr<Assets> assets = nullptr;
|
||||||
std::shared_ptr<Screen> screen = nullptr;
|
std::shared_ptr<Screen> screen = nullptr;
|
||||||
std::vector<ContentPack> contentPacks;
|
std::vector<ContentPack> contentPacks;
|
||||||
EngineSettings& settings;
|
EngineSettings& settings;
|
||||||
std::unique_ptr<Content> content = nullptr;
|
std::unique_ptr<Content> content = nullptr;
|
||||||
EnginePaths* paths;
|
EnginePaths* paths;
|
||||||
|
std::unique_ptr<ResPaths> resPaths = nullptr;
|
||||||
|
|
||||||
uint64_t frame = 0;
|
uint64_t frame = 0;
|
||||||
double lastTime = 0.0;
|
double lastTime = 0.0;
|
||||||
@ -54,6 +57,7 @@ public:
|
|||||||
const Content* getContent() const;
|
const Content* getContent() const;
|
||||||
std::vector<ContentPack>& getContentPacks();
|
std::vector<ContentPack>& getContentPacks();
|
||||||
void setLanguage(std::string locale);
|
void setLanguage(std::string locale);
|
||||||
|
void loadContent();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SRC_ENGINE_H_
|
#endif // SRC_ENGINE_H_
|
||||||
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::vector;
|
||||||
using fs::path;
|
using fs::path;
|
||||||
|
|
||||||
path EnginePaths::getUserfiles() const {
|
path EnginePaths::getUserfiles() const {
|
||||||
@ -56,3 +57,38 @@ void EnginePaths::setUserfiles(path folder) {
|
|||||||
void EnginePaths::setResources(path folder) {
|
void EnginePaths::setResources(path folder) {
|
||||||
this->resources = folder;
|
this->resources = folder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResPaths::ResPaths(path mainRoot, vector<path> roots)
|
||||||
|
: mainRoot(mainRoot), roots(roots) {
|
||||||
|
}
|
||||||
|
|
||||||
|
path ResPaths::find(const string& filename) const {
|
||||||
|
for (auto& root : roots) {
|
||||||
|
path file = root / path(filename);
|
||||||
|
if (fs::exists(file)) {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mainRoot / path(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<path> ResPaths::listdir(const string& folderName) const {
|
||||||
|
vector<path> entries;
|
||||||
|
for (auto& root : roots) {
|
||||||
|
path folder = root / path(folderName);
|
||||||
|
if (!fs::is_directory(folder))
|
||||||
|
continue;
|
||||||
|
for (const auto& entry : fs::directory_iterator(folder)) {
|
||||||
|
entries.push_back(entry.path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
path folder = mainRoot / path(folderName);
|
||||||
|
if (!fs::is_directory(folder))
|
||||||
|
return entries;
|
||||||
|
for (const auto& entry : fs::directory_iterator(folder)) {
|
||||||
|
entries.push_back(entry.path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return entries;
|
||||||
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#define FILES_ENGINE_PATHS_H_
|
#define FILES_ENGINE_PATHS_H_
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
class EnginePaths {
|
class EnginePaths {
|
||||||
@ -19,4 +20,15 @@ public:
|
|||||||
void setResources(std::filesystem::path folder);
|
void setResources(std::filesystem::path folder);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ResPaths {
|
||||||
|
std::filesystem::path mainRoot;
|
||||||
|
std::vector<std::filesystem::path> roots;
|
||||||
|
public:
|
||||||
|
ResPaths(std::filesystem::path mainRoot,
|
||||||
|
std::vector<std::filesystem::path> roots);
|
||||||
|
|
||||||
|
std::filesystem::path find(const std::string& filename) const;
|
||||||
|
std::vector<std::filesystem::path> listdir(const std::string& folder) const;
|
||||||
|
};
|
||||||
|
|
||||||
#endif // FILES_ENGINE_PATHS_H_
|
#endif // FILES_ENGINE_PATHS_H_
|
||||||
@ -41,15 +41,20 @@ ImageData* Atlas::getImage() const {
|
|||||||
|
|
||||||
void AtlasBuilder::add(string name, ImageData* image) {
|
void AtlasBuilder::add(string name, ImageData* image) {
|
||||||
entries.push_back(atlasentry{name, shared_ptr<ImageData>(image)});
|
entries.push_back(atlasentry{name, shared_ptr<ImageData>(image)});
|
||||||
|
names.insert(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AtlasBuilder::has(string name) const {
|
||||||
|
return names.find(name) != names.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
Atlas* AtlasBuilder::build(uint extrusion, uint maxResolution) {
|
Atlas* AtlasBuilder::build(uint extrusion, uint maxResolution) {
|
||||||
unique_ptr<uint[]> sizes (new uint[entries.size() * 2]);
|
unique_ptr<uint[]> sizes (new uint[entries.size() * 2]);
|
||||||
for (uint i = 0; i < entries.size(); i++) {
|
uint index = 0;
|
||||||
auto& entry = entries[i];
|
for (auto& entry : entries) {
|
||||||
auto image = entry.image;
|
auto image = entry.image;
|
||||||
sizes[i*2] = image->getWidth();
|
sizes[index++] = image->getWidth();
|
||||||
sizes[i*2+1] = image->getHeight();
|
sizes[index++] = image->getHeight();
|
||||||
}
|
}
|
||||||
LMPacker packer(sizes.get(), entries.size()*2);
|
LMPacker packer(sizes.get(), entries.size()*2);
|
||||||
sizes.reset(nullptr);
|
sizes.reset(nullptr);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#ifndef GRAPHICS_ATLAS_H_
|
#ifndef GRAPHICS_ATLAS_H_
|
||||||
#define GRAPHICS_ATLAS_H_
|
#define GRAPHICS_ATLAS_H_
|
||||||
|
|
||||||
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -33,10 +34,12 @@ struct atlasentry {
|
|||||||
};
|
};
|
||||||
|
|
||||||
class AtlasBuilder {
|
class AtlasBuilder {
|
||||||
std::vector<atlasentry> entries;
|
std::vector<atlasentry> entries;
|
||||||
|
std::set<std::string> names;
|
||||||
public:
|
public:
|
||||||
AtlasBuilder() {}
|
AtlasBuilder() {}
|
||||||
void add(std::string name, ImageData* image);
|
void add(std::string name, ImageData* image);
|
||||||
|
bool has(std::string name) const;
|
||||||
|
|
||||||
Atlas* build(uint extrusion, uint maxResolution=8192);
|
Atlas* build(uint extrusion, uint maxResolution=8192);
|
||||||
};
|
};
|
||||||
|
|||||||