diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/assets.cc | 4 | ||||
| -rw-r--r-- | src/assets.h | 3 | ||||
| -rw-r--r-- | src/context.h | 6 | ||||
| -rw-r--r-- | src/gl.cc | 4 | ||||
| -rw-r--r-- | src/gl.h | 5 | ||||
| -rw-r--r-- | src/json.h | 1 | ||||
| -rw-r--r-- | src/log.h | 5 | ||||
| -rw-r--r-- | src/mauri.cc | 100 | ||||
| -rw-r--r-- | src/objects/object.cc | 2 | ||||
| -rw-r--r-- | src/objects/pass.cc | 31 | ||||
| -rw-r--r-- | src/objects/scene.cc | 6 | ||||
| -rw-r--r-- | src/shader.cc | 7 | ||||
| -rw-r--r-- | src/shader.h | 4 | ||||
| -rw-r--r-- | src/texture.cc | 1 | ||||
| -rw-r--r-- | src/util.h | 11 |
15 files changed, 112 insertions, 78 deletions
diff --git a/src/assets.cc b/src/assets.cc index 8d2ac18..2bc227f 100644 --- a/src/assets.cc +++ b/src/assets.cc @@ -3,6 +3,8 @@ #include "assets.h" #include "texture.h" +//#define AL_LOG_ENABLE_TRACE +#include "log.h" namespace Mauri { @@ -192,7 +194,7 @@ auto AssetManager::get(const std::string &part, AssetTypeHint hint) -> Asset * continue; } asset->hash = hash; - debug("found asset in: (%s)", dir.c_str()); + trace("found asset in: (%s)", dir.c_str()); break; } diff --git a/src/assets.h b/src/assets.h index d1b8144..015564e 100644 --- a/src/assets.h +++ b/src/assets.h @@ -1,6 +1,9 @@ #ifndef _ASSET_H #define _ASSET_H +#include <string> +#include <vector> + #include "util.h" namespace Mauri diff --git a/src/context.h b/src/context.h index a64dde7..ab27cb2 100644 --- a/src/context.h +++ b/src/context.h @@ -2,12 +2,12 @@ #define _CONTEXT_H extern "C" { +#include <nnwt/thread.h> #include <stl/window.h> #include <stl/gl.h> -#include <nnwt/thread.h> } -#include "gl.h" +#include <string> namespace Mauri { @@ -31,7 +31,7 @@ class Context auto create_window(s32 width, s32 height, const std::string &name, const std::string monitor) -> bool { - this->window = stl_window_create(NULL); + this->window = stl_window_create(); this->window->pointer_pos_callback = pointer_pos_callback; this->window->should_close_callback = should_close_callback; this->window->userdata = this; @@ -1,3 +1,7 @@ +extern "C" { +#include <nnwt/net.h> +} + #include "gl.h" #include "log.h" #include "context.h" @@ -5,14 +5,15 @@ extern "C" { #include <stl/gl.h> } +#include <vector> +#include <unordered_map> + #define GLM_ENABLE_EXPERIMENTAL #include <glm/glm.hpp> #include <glm/gtx/matrix_major_storage.hpp> #include <glm/gtc/type_ptr.hpp> #include <glm/gtx/string_cast.hpp> -#include "util.h" - using namespace glm; namespace Mauri @@ -2,7 +2,6 @@ #define _JSON_H #define JSON_NO_IO -#undef array #include <nlohmann/json.hpp> #include "gl.h" @@ -5,9 +5,4 @@ extern "C" { #include <al/log.h> } -#define info(fmt, ...) al_log_info(NULL, fmt, ##__VA_ARGS__) -#define warn(fmt, ...) al_log_warn(NULL, fmt, ##__VA_ARGS__) -#define error(fmt, ...) al_log_error(NULL, fmt, ##__VA_ARGS__) -#define debug(fmt, ...) al_log_debug(NULL, fmt, ##__VA_ARGS__) - #endif // _LOG_H diff --git a/src/mauri.cc b/src/mauri.cc index e562a76..9351320 100644 --- a/src/mauri.cc +++ b/src/mauri.cc @@ -2,12 +2,12 @@ extern "C" { #include <nnwt/common.h> #include <stl/window.h> } - #include <janus.h> -#include "context.h" #include "assets.h" +#include "context.h" #include "engine.h" +#include "log.h" #include "objects/scene.h" @@ -19,33 +19,16 @@ Usage: mauri (-p, --package [path_to_scene.pkg]|-d, --directory [path_to_wallpap -w, --width window width (default: 640)\n\ -h, --height window height (default: 480)\n\ -o, --offset offset of the scene camera (default: 0,0)\n\ + -s, --scale scale the window to the scene\n\ -m, --monitor set as the background of this monitor (by name)\n\ - -t, --target dump scene into this directory and exit\ + -t, --target dump the scene tree into this directory and exit\ " -#ifndef _WIN32 -auto main(s32 argc, char *argv[]) -> s32 -#else -auto wmain(s32 argc, wchar_t **argv) -> s32 -#endif +auto window_system_main(u32 argc, str *argv, void *extra) -> s32 { - if (!nn_common_init()) return EXIT_FAILURE; - - janus::ArgParser args(HELP_TEXT, "0.13"); - - args.newString("package p", ""); - args.newString("directory d", ""); - args.newString("assets a", ""); - args.newInt("width w", 0); - args.newInt("height h", 0); - args.newString("offset o", "0,0"); - args.newString("monitor m", ""); - args.newString("target t", ""); -#ifndef _WIN32 - args.parse(argc, argv); -#else - args.wparse(argc, argv); -#endif + (void)argc; + (void)argv; + janus::ArgParser args = *(janus::ArgParser *)extra; if (!(args.found("package") ^ args.found("directory"))) { @@ -53,7 +36,7 @@ auto wmain(s32 argc, wchar_t **argv) -> s32 return EXIT_FAILURE; } - s32 width = 640; + s32 width = 720; s32 height = 480; if (args.found("width")) width = args.getInt("width"); if (args.found("height")) height = args.getInt("height"); @@ -65,16 +48,22 @@ auto wmain(s32 argc, wchar_t **argv) -> s32 s32 xoffset; s32 yoffset; - if (sscanf(args.getString("offset").c_str(), "%d,%d", &xoffset, &yoffset) != 2) { + if (sscanf(args.getString("offset").c_str(), "%d,%d", &xoffset, &yoffset) != 2) + { error("invalid offset in arguments"); return EXIT_FAILURE; } - if (!stl_global_init(false)) return EXIT_FAILURE; - + bool gifscene = false; if (args.found("package")) { - if (!asset_manager()->arm_package(args.getString("package"), args.found("target"))) + std::string package_path = args.getString("package"); + size_t slash = package_path.rfind("/"); + std::string filename; + if (slash != std::string::npos) filename = package_path.substr(slash + 1); + else filename = package_path; + gifscene = filename == "gifscene.pkg"; + if (!asset_manager()->arm_package(package_path, args.found("target"))) { return EXIT_FAILURE; } @@ -86,15 +75,26 @@ auto wmain(s32 argc, wchar_t **argv) -> s32 asset_manager()->add_search_directory(args.getString("directory")); } - if (args.found("assets")) { + if (args.found("assets")) + { asset_manager()->add_search_directory(args.getString("assets")); } - Scene *scene = Scene::parse("scene.json"); + Scene *scene = Scene::parse(gifscene ? "gifscene.json" : "scene.json"); if (!scene) return EXIT_FAILURE; - if (width <= 0) width = scene->width; - if (height <= 0) height = scene->height; + if (width <= 0 || height <= 0) + { + width = scene->width; + height = scene->height; + } + + if (args.getFlag("scale")) + { + f32 ratio = scene->width / (f32)scene->height; + if (ratio > 1.f) height = width / ratio; + else width = height * ratio; + } Context *new_context = new Context(); if (!new_context->create_window(width, height, "mauri", args.getString("monitor"))) @@ -131,3 +131,35 @@ auto wmain(s32 argc, wchar_t **argv) -> s32 return EXIT_SUCCESS; } + +#ifndef _WIN32 +auto main(s32 argc, char *argv[]) -> s32 +#else +auto wmain(s32 argc, wchar_t **argv) -> s32 +#endif +{ + if (!nn_common_init()) return EXIT_FAILURE; + + janus::ArgParser args(HELP_TEXT, "0.13"); + args.newString("package p", ""); + args.newString("directory d", ""); + args.newString("assets a", ""); + args.newInt("width w", 0); + args.newInt("height h", 0); + args.newString("offset o", "0,0"); + args.newFlag("scale s"); + args.newString("monitor m", ""); + args.newString("target t", ""); +#ifndef _WIN32 + args.parse(argc, argv); +#else + args.wparse(argc, argv); +#endif + + if (!stl_global_init(false)) return EXIT_FAILURE; + + s32 ret = stl_swallow_main(0, NULL, window_system_main, &args); + stl_global_close(); + + return ret; +} diff --git a/src/objects/object.cc b/src/objects/object.cc index 4cf9790..6240c30 100644 --- a/src/objects/object.cc +++ b/src/objects/object.cc @@ -1,3 +1,5 @@ +#include "../log.h" + #include "object.h" #include "scene.h" #include "pass.h" diff --git a/src/objects/pass.cc b/src/objects/pass.cc index 0ed32ae..dc19378 100644 --- a/src/objects/pass.cc +++ b/src/objects/pass.cc @@ -1,5 +1,6 @@ #include "../gl.h" -#include "../context.h" +//#define AL_LOG_ENABLE_TRACE +#include "../log.h" #include "pass.h" @@ -271,14 +272,13 @@ RenderPass::RenderPass(Engine *engine, Pass *pass) } } -#ifdef _DEBUG_ - debug("PASS (%s)", this->command == COPY ? "copy" : "draw"); - debug(" object: %s (passthrough: %s, fullscreen %s)", this->object->name.c_str(), + trace("PASS (%s)", this->command == COPY ? "copy" : "draw"); + trace(" object: %s (passthrough: %s, fullscreen %s)", this->object->name.c_str(), BOOLSTR(this->object->passthrough), BOOLSTR(this->object->fullscreen)); - debug(" visible: %s", BOOLSTR(this->object->visible)); - debug(" shader: %s", this->shader->origin()->name.c_str()); - debug(" target: %s", pass->target.c_str()); - debug(" textures (%u):", this->shader->origin()->texture_count); + trace(" visible: %s", BOOLSTR(this->object->visible)); + trace(" shader: %s", this->shader->origin()->name.c_str()); + trace(" target: %s", pass->target.c_str()); + trace(" textures (%u):", this->shader->origin()->texture_count); for (u32 i = 0; i < this->shader->origin()->texture_count; i++) { switch (this->texture_types[i]) @@ -286,27 +286,26 @@ RenderPass::RenderPass(Engine *engine, Pass *pass) case STATIC: if (!this->shader->origin()->textures[i].empty() && pass->textures[i] == this->shader->origin()->textures[i]) { - debug(" [%u] %s (DEFAULT)", i, this->shader->origin()->textures[i].c_str()); + trace(" [%u] %s (DEFAULT)", i, this->shader->origin()->textures[i].c_str()); } else { - debug(" [%u] %s", i, pass->textures[i].c_str()); + trace(" [%u] %s", i, pass->textures[i].c_str()); } break; case PREVIOUS: - debug(" [%u] previous", i); + trace(" [%u] previous", i); break; } } - debug(" uniforms (%u)", this->shader->uniforms.size()); + trace(" uniforms (%u)", this->shader->uniforms.size()); for (Uniform *uniform : this->shader->uniforms) { - debug(" %s %s %s", uniform_type_to_string(uniform->type).c_str(), + trace(" %s %s %s", uniform_type_to_string(uniform->type).c_str(), uniform->uname.c_str(), glm::to_string(*uniform->value).c_str()); } - debug(" model: %s", BOOLSTR(this->model)); - debug(" combine: %s", BOOLSTR(this->combine)); -#endif + trace(" model: %s", BOOLSTR(this->model)); + trace(" combine: %s", BOOLSTR(this->combine)); } auto RenderPass::draw(Engine *engine) -> void diff --git a/src/objects/scene.cc b/src/objects/scene.cc index b9728c7..fa03622 100644 --- a/src/objects/scene.cc +++ b/src/objects/scene.cc @@ -37,6 +37,12 @@ auto Scene::parse(const std::string &path) -> Scene * if (obj) scene->objects.emplace_back(obj); } + if ((scene->width == 0 || scene->height == 0) && scene->objects.size() > 0) + { + scene->width = scene->objects[0]->size[0]; + scene->height = scene->objects[0]->size[1]; + } + return scene; } diff --git a/src/shader.cc b/src/shader.cc index c8ba7b0..71597da 100644 --- a/src/shader.cc +++ b/src/shader.cc @@ -1,11 +1,11 @@ #include "shader.h" -#include "gl.h" #include "json.h" +#include "gl.h" #include "objects/object.h" +static const char *version = "#version 330\n"; static const char *compat = \ -// "#define mul(x, y) ((y) * (x))\n" "#define max(x, y) max(y, x)\n" "#define frac fract\n" "#define log10 log\n" @@ -25,9 +25,6 @@ static const char *compat = \ "#define GLSL 1\n"; static const char *mul = "#define mul(x, y) ((y) * (x))\n"; -//static const char *mul = ""; - -static const char *version = "#version 330\n"; namespace Mauri { diff --git a/src/shader.h b/src/shader.h index 132b843..ae02887 100644 --- a/src/shader.h +++ b/src/shader.h @@ -1,6 +1,10 @@ #ifndef _SHADER_H #define _SHADER_H +#include <array> +#include <sstream> +#include <algorithm> + #include "texture.h" #define MAX_TEXTURES 8 diff --git a/src/texture.cc b/src/texture.cc index 4ea7211..3128a23 100644 --- a/src/texture.cc +++ b/src/texture.cc @@ -15,6 +15,7 @@ _Pragma("GCC diagnostic pop") #include <s3tc.h> #include "texture.h" +#include "log.h" using namespace Mauri; @@ -3,19 +3,8 @@ extern "C" { #include <al/types.h> -#include <nnwt/socket.h> } -#include "log.h" - -#undef array -#include <array> -#include <vector> -#include <unordered_map> -#include <sstream> -#include <algorithm> -#include <cmath> - // Pause after every pass. //#define FRAME_STEP |