engine.cpp indentation fix
This commit is contained in:
parent
a82a77ba2d
commit
fb109e0ce2
180
src/engine.cpp
180
src/engine.cpp
@ -46,16 +46,16 @@
|
|||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
void addWorldGenerators() {
|
void addWorldGenerators() {
|
||||||
WorldGenerators::addGenerator<DefaultWorldGenerator>("core:default");
|
WorldGenerators::addGenerator<DefaultWorldGenerator>("core:default");
|
||||||
WorldGenerators::addGenerator<FlatWorldGenerator>("core:flat");
|
WorldGenerators::addGenerator<FlatWorldGenerator>("core:flat");
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine::Engine(EngineSettings& settings, EnginePaths* paths)
|
Engine::Engine(EngineSettings& settings, EnginePaths* paths)
|
||||||
: settings(settings), paths(paths)
|
: settings(settings), paths(paths)
|
||||||
{
|
{
|
||||||
if (Window::initialize(settings.display)){
|
if (Window::initialize(settings.display)){
|
||||||
throw initialize_error("could not initialize window");
|
throw initialize_error("could not initialize window");
|
||||||
}
|
}
|
||||||
audio::initialize(true);
|
audio::initialize(true);
|
||||||
audio::create_channel("regular");
|
audio::create_channel("regular");
|
||||||
audio::create_channel("music");
|
audio::create_channel("music");
|
||||||
@ -65,100 +65,100 @@ Engine::Engine(EngineSettings& settings, EnginePaths* paths)
|
|||||||
auto resdir = paths->getResources();
|
auto resdir = paths->getResources();
|
||||||
scripting::initialize(this);
|
scripting::initialize(this);
|
||||||
|
|
||||||
std::cout << "-- loading assets" << std::endl;
|
std::cout << "-- loading assets" << std::endl;
|
||||||
std::vector<fs::path> roots {resdir};
|
std::vector<fs::path> roots {resdir};
|
||||||
|
|
||||||
resPaths = std::make_unique<ResPaths>(resdir, roots);
|
resPaths = std::make_unique<ResPaths>(resdir, roots);
|
||||||
assets = std::make_unique<Assets>();
|
assets = std::make_unique<Assets>();
|
||||||
|
|
||||||
AssetsLoader loader(assets.get(), resPaths.get());
|
AssetsLoader loader(assets.get(), resPaths.get());
|
||||||
AssetsLoader::addDefaults(loader, nullptr);
|
AssetsLoader::addDefaults(loader, nullptr);
|
||||||
|
|
||||||
Shader::preprocessor->setPaths(resPaths.get());
|
Shader::preprocessor->setPaths(resPaths.get());
|
||||||
while (loader.hasNext()) {
|
while (loader.hasNext()) {
|
||||||
if (!loader.loadNext()) {
|
if (!loader.loadNext()) {
|
||||||
assets.reset();
|
assets.reset();
|
||||||
scripting::close();
|
scripting::close();
|
||||||
Window::terminate();
|
Window::terminate();
|
||||||
throw initialize_error("could not to load assets");
|
throw initialize_error("could not to load assets");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gui = std::make_unique<gui::GUI>();
|
gui = std::make_unique<gui::GUI>();
|
||||||
if (settings.ui.language == "auto") {
|
if (settings.ui.language == "auto") {
|
||||||
settings.ui.language = langs::locale_by_envlocale(platform::detect_locale(), paths->getResources());
|
settings.ui.language = langs::locale_by_envlocale(platform::detect_locale(), paths->getResources());
|
||||||
}
|
}
|
||||||
if (ENGINE_VERSION_INDEV) {
|
if (ENGINE_VERSION_INDEV) {
|
||||||
menus::create_version_label(this);
|
menus::create_version_label(this);
|
||||||
}
|
}
|
||||||
setLanguage(settings.ui.language);
|
setLanguage(settings.ui.language);
|
||||||
addWorldGenerators();
|
addWorldGenerators();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::updateTimers() {
|
void Engine::updateTimers() {
|
||||||
frame++;
|
frame++;
|
||||||
double currentTime = Window::time();
|
double currentTime = Window::time();
|
||||||
delta = currentTime - lastTime;
|
delta = currentTime - lastTime;
|
||||||
lastTime = currentTime;
|
lastTime = currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::updateHotkeys() {
|
void Engine::updateHotkeys() {
|
||||||
if (Events::jpressed(keycode::F2)) {
|
if (Events::jpressed(keycode::F2)) {
|
||||||
std::unique_ptr<ImageData> image(Window::takeScreenshot());
|
std::unique_ptr<ImageData> image(Window::takeScreenshot());
|
||||||
image->flipY();
|
image->flipY();
|
||||||
fs::path filename = paths->getScreenshotFile("png");
|
fs::path filename = paths->getScreenshotFile("png");
|
||||||
png::write_image(filename.string(), image.get());
|
png::write_image(filename.string(), image.get());
|
||||||
std::cout << "saved screenshot as " << filename << std::endl;
|
std::cout << "saved screenshot as " << filename << std::endl;
|
||||||
}
|
}
|
||||||
if (Events::jpressed(keycode::F11)) {
|
if (Events::jpressed(keycode::F11)) {
|
||||||
Window::toggleFullscreen();
|
Window::toggleFullscreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::mainloop() {
|
void Engine::mainloop() {
|
||||||
setScreen(std::make_shared<MenuScreen>(this));
|
setScreen(std::make_shared<MenuScreen>(this));
|
||||||
|
|
||||||
Batch2D batch(1024);
|
Batch2D batch(1024);
|
||||||
lastTime = Window::time();
|
lastTime = Window::time();
|
||||||
|
|
||||||
std::cout << "-- initialized" << std::endl;
|
std::cout << "-- initialized" << std::endl;
|
||||||
while (!Window::isShouldClose()){
|
while (!Window::isShouldClose()){
|
||||||
assert(screen != nullptr);
|
assert(screen != nullptr);
|
||||||
updateTimers();
|
updateTimers();
|
||||||
updateHotkeys();
|
updateHotkeys();
|
||||||
|
|
||||||
audio::update(delta);
|
audio::update(delta);
|
||||||
|
|
||||||
gui->act(delta);
|
gui->act(delta);
|
||||||
screen->update(delta);
|
screen->update(delta);
|
||||||
|
|
||||||
if (!Window::isIconified()) {
|
if (!Window::isIconified()) {
|
||||||
screen->draw(delta);
|
screen->draw(delta);
|
||||||
|
|
||||||
Viewport viewport(Window::width, Window::height);
|
Viewport viewport(Window::width, Window::height);
|
||||||
GfxContext ctx(nullptr, viewport, &batch);
|
GfxContext ctx(nullptr, viewport, &batch);
|
||||||
gui->draw(&ctx, assets.get());
|
gui->draw(&ctx, assets.get());
|
||||||
|
|
||||||
Window::swapInterval(settings.display.swapInterval);
|
Window::swapInterval(settings.display.swapInterval);
|
||||||
} else {
|
} else {
|
||||||
Window::swapInterval(1);
|
Window::swapInterval(1);
|
||||||
}
|
}
|
||||||
Window::swapBuffers();
|
Window::swapBuffers();
|
||||||
Events::pollEvents();
|
Events::pollEvents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Engine::~Engine() {
|
Engine::~Engine() {
|
||||||
std::cout << "-- shutting down" << std::endl;
|
std::cout << "-- shutting down" << std::endl;
|
||||||
if (screen) {
|
if (screen) {
|
||||||
screen->onEngineShutdown();
|
screen->onEngineShutdown();
|
||||||
}
|
}
|
||||||
screen.reset();
|
screen.reset();
|
||||||
content.reset();
|
content.reset();
|
||||||
assets.reset();
|
assets.reset();
|
||||||
audio::close();
|
audio::close();
|
||||||
scripting::close();
|
scripting::close();
|
||||||
Window::terminate();
|
Window::terminate();
|
||||||
std::cout << "-- engine finished" << std::endl;
|
std::cout << "-- engine finished" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const std::string checkPacks(
|
inline const std::string checkPacks(
|
||||||
@ -183,29 +183,29 @@ void Engine::loadContent() {
|
|||||||
std::vector<ContentPack> srcPacks = contentPacks;
|
std::vector<ContentPack> srcPacks = contentPacks;
|
||||||
contentPacks.clear();
|
contentPacks.clear();
|
||||||
|
|
||||||
std::string missingDependency;
|
std::string missingDependency;
|
||||||
std::unordered_set<std::string> loadedPacks, existingPacks;
|
std::unordered_set<std::string> loadedPacks, existingPacks;
|
||||||
for (const auto& item : srcPacks) {
|
for (const auto& item : srcPacks) {
|
||||||
existingPacks.insert(item.id);
|
existingPacks.insert(item.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (existingPacks.size() > loadedPacks.size()) {
|
while (existingPacks.size() > loadedPacks.size()) {
|
||||||
for (auto& pack : srcPacks) {
|
for (auto& pack : srcPacks) {
|
||||||
if(loadedPacks.find(pack.id) != loadedPacks.end()) {
|
if(loadedPacks.find(pack.id) != loadedPacks.end()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
missingDependency = checkPacks(existingPacks, pack.dependencies);
|
missingDependency = checkPacks(existingPacks, pack.dependencies);
|
||||||
if (!missingDependency.empty()) {
|
if (!missingDependency.empty()) {
|
||||||
throw contentpack_error(pack.id, pack.folder, "missing dependency '"+missingDependency+"'");
|
throw contentpack_error(pack.id, pack.folder, "missing dependency '"+missingDependency+"'");
|
||||||
}
|
}
|
||||||
if (pack.dependencies.empty() || checkPacks(loadedPacks, pack.dependencies).empty()) {
|
if (pack.dependencies.empty() || checkPacks(loadedPacks, pack.dependencies).empty()) {
|
||||||
loadedPacks.insert(pack.id);
|
loadedPacks.insert(pack.id);
|
||||||
resRoots.push_back(pack.folder);
|
resRoots.push_back(pack.folder);
|
||||||
contentPacks.push_back(pack);
|
contentPacks.push_back(pack);
|
||||||
ContentLoader loader(&pack);
|
ContentLoader loader(&pack);
|
||||||
loader.load(contentBuilder);
|
loader.load(contentBuilder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
content.reset(contentBuilder.build());
|
content.reset(contentBuilder.build());
|
||||||
@ -214,15 +214,15 @@ void Engine::loadContent() {
|
|||||||
Shader::preprocessor->setPaths(resPaths.get());
|
Shader::preprocessor->setPaths(resPaths.get());
|
||||||
|
|
||||||
std::unique_ptr<Assets> new_assets(new Assets());
|
std::unique_ptr<Assets> new_assets(new Assets());
|
||||||
std::cout << "-- loading assets" << std::endl;
|
std::cout << "-- loading assets" << std::endl;
|
||||||
AssetsLoader loader(new_assets.get(), resPaths.get());
|
AssetsLoader loader(new_assets.get(), resPaths.get());
|
||||||
AssetsLoader::addDefaults(loader, content.get());
|
AssetsLoader::addDefaults(loader, content.get());
|
||||||
while (loader.hasNext()) {
|
while (loader.hasNext()) {
|
||||||
if (!loader.loadNext()) {
|
if (!loader.loadNext()) {
|
||||||
new_assets.reset();
|
new_assets.reset();
|
||||||
throw std::runtime_error("could not to load assets");
|
throw std::runtime_error("could not to load assets");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assets->extend(*new_assets.get());
|
assets->extend(*new_assets.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,14 +230,14 @@ void Engine::loadWorldContent(const fs::path& folder) {
|
|||||||
contentPacks.clear();
|
contentPacks.clear();
|
||||||
auto packNames = ContentPack::worldPacksList(folder);
|
auto packNames = ContentPack::worldPacksList(folder);
|
||||||
ContentPack::readPacks(paths, contentPacks, packNames, folder);
|
ContentPack::readPacks(paths, contentPacks, packNames, folder);
|
||||||
paths->setWorldFolder(folder);
|
paths->setWorldFolder(folder);
|
||||||
loadContent();
|
loadContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::loadAllPacks() {
|
void Engine::loadAllPacks() {
|
||||||
auto resdir = paths->getResources();
|
auto resdir = paths->getResources();
|
||||||
contentPacks.clear();
|
contentPacks.clear();
|
||||||
ContentPack::scan(paths, contentPacks);
|
ContentPack::scan(paths, contentPacks);
|
||||||
}
|
}
|
||||||
|
|
||||||
double Engine::getDelta() const {
|
double Engine::getDelta() const {
|
||||||
@ -247,29 +247,29 @@ double Engine::getDelta() const {
|
|||||||
void Engine::setScreen(std::shared_ptr<Screen> screen) {
|
void Engine::setScreen(std::shared_ptr<Screen> screen) {
|
||||||
audio::reset_channel(audio::get_channel_index("regular"));
|
audio::reset_channel(audio::get_channel_index("regular"));
|
||||||
audio::reset_channel(audio::get_channel_index("ambient"));
|
audio::reset_channel(audio::get_channel_index("ambient"));
|
||||||
this->screen = screen;
|
this->screen = screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::setLanguage(std::string locale) {
|
void Engine::setLanguage(std::string locale) {
|
||||||
settings.ui.language = locale;
|
settings.ui.language = locale;
|
||||||
langs::setup(paths->getResources(), locale, contentPacks);
|
langs::setup(paths->getResources(), locale, contentPacks);
|
||||||
menus::create_menus(this);
|
menus::create_menus(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
gui::GUI* Engine::getGUI() {
|
gui::GUI* Engine::getGUI() {
|
||||||
return gui.get();
|
return gui.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
EngineSettings& Engine::getSettings() {
|
EngineSettings& Engine::getSettings() {
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
Assets* Engine::getAssets() {
|
Assets* Engine::getAssets() {
|
||||||
return assets.get();
|
return assets.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Content* Engine::getContent() const {
|
const Content* Engine::getContent() const {
|
||||||
return content.get();
|
return content.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<ContentPack>& Engine::getContentPacks() {
|
std::vector<ContentPack>& Engine::getContentPacks() {
|
||||||
@ -277,7 +277,7 @@ std::vector<ContentPack>& Engine::getContentPacks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EnginePaths* Engine::getPaths() {
|
EnginePaths* Engine::getPaths() {
|
||||||
return paths;
|
return paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResPaths* Engine::getResPaths() {
|
ResPaths* Engine::getResPaths() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user