From 908e17ee1f85472237aae329f8605a985841a4e8 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Thu, 21 Jul 2022 22:02:57 -0400 Subject: temporary fix for new assets, major cleanup --- src/assets.cc | 12 +++++------- src/assets.h | 1 - src/context.cc | 2 +- src/context.h | 12 +++++++----- src/context_glfw.cc | 8 ++++---- src/context_glfw.h | 8 ++++---- src/context_null.h | 8 ++++---- src/context_x11.cc | 8 +++----- src/context_x11.h | 12 ++++++------ src/engine.cc | 14 ++------------ src/engine.h | 4 ---- src/gl.cc | 12 ++++++------ src/gl.h | 11 ++--------- src/json.h | 25 ++++++++----------------- src/mauri.cc | 9 ++++----- src/objects/effect.cc | 7 ++----- src/objects/effect.h | 9 +++------ src/objects/material.cc | 14 +++++++------- src/objects/material.h | 6 ++---- src/objects/model.cc | 12 ++++++------ src/objects/model.h | 8 +++----- src/objects/object.cc | 23 +++++++---------------- src/objects/object.h | 8 ++------ src/objects/pass.cc | 44 ++++++++++++++++++-------------------------- src/objects/pass.h | 18 ++++++++---------- src/objects/scene.cc | 17 +++++++---------- src/objects/scene.h | 20 +++++++------------- src/shader.cc | 26 +++++++++++++++++--------- src/shader.h | 4 ---- src/texture.cc | 7 +++---- src/texture.h | 4 ---- src/util.cc | 6 +----- src/util.h | 3 +++ src/visualizer.cc | 38 +++++++++++++------------------------- 34 files changed, 165 insertions(+), 255 deletions(-) (limited to 'src') diff --git a/src/assets.cc b/src/assets.cc index 60199e2..de9d802 100644 --- a/src/assets.cc +++ b/src/assets.cc @@ -1,14 +1,12 @@ +#include +#include +#include + #include "assets.h" #include "log.h" #include "util.h" #include "texture.h" -#include -#include -#include -#include -#include - namespace Mauri { @@ -121,7 +119,7 @@ bool AssetManager::load_package(const std::string &path) std::vector pkg_files; pkg_files.reserve(count); - for (auto i = 0; i < count; i++) + for (auto i = 0u; i < count; i++) { pkg_files.emplace_back(PkgFile { pkg->reads(pkg->read()), diff --git a/src/assets.h b/src/assets.h index 1217d95..72665d3 100644 --- a/src/assets.h +++ b/src/assets.h @@ -1,7 +1,6 @@ #ifndef _ASSET_H #define _ASSET_H -#include #include #include #include diff --git a/src/context.cc b/src/context.cc index 3f7f299..32952f9 100644 --- a/src/context.cc +++ b/src/context.cc @@ -27,7 +27,7 @@ using namespace Mauri; void Context::print_gl_info() { - log_info("OpenGL loaded"); + log_info("%s", "OpenGL loaded"); log_info("Vendor: %s", glGetString(GL_VENDOR)); log_info("Renderer: %s", glGetString(GL_RENDERER)); log_info("Version: %s", glGetString(GL_VERSION)); diff --git a/src/context.h b/src/context.h index 215bbfa..a726f56 100644 --- a/src/context.h +++ b/src/context.h @@ -4,6 +4,8 @@ #include #include +#include "util.h" + #define GL_VERSION_MAJOR 3 #define GL_VERSION_MINOR 3 @@ -13,12 +15,12 @@ namespace Mauri class Context { public: - Context(int width, int height, const std::string &name, bool wallpaper) + Context(s32 width, s32 height, const std::string &name, bool wallpaper) : width(width), height(height) {} virtual ~Context() {} - int width, height; + s32 width, height; bool draw_enabled() const { @@ -30,7 +32,7 @@ class Context _draw_enabled = enabled; } - virtual void resize_window(int w, int h) = 0; + virtual void resize_window(s32 w, s32 h) = 0; virtual void close_window() = 0; virtual bool should_close() const = 0; @@ -38,9 +40,9 @@ class Context virtual void swap_buffers() = 0; virtual void process_input() = 0; - virtual void cursor_pos(float *x, float *y) = 0; + virtual void cursor_pos(f32 *x, f32 *y) = 0; - virtual double current_time() = 0; + virtual f64 current_time() = 0; protected: GLenum check_error(); diff --git a/src/context_glfw.cc b/src/context_glfw.cc index 8f3d847..a5a2f09 100644 --- a/src/context_glfw.cc +++ b/src/context_glfw.cc @@ -1,8 +1,8 @@ #include "context_glfw.h" #include "context.h" #include "log.h" -#include "src/objects/pass.h" -#include + +#include "objects/pass.h" using namespace Mauri; @@ -59,7 +59,7 @@ ContextGLFW::ContextGLFW(int width, int height, const std::string &name, bool wa { if (!glfwInit()) { - log_print("err", "failed to init glfw"); + log_error("%s", "failed to init glfw"); return; } @@ -77,7 +77,7 @@ ContextGLFW::ContextGLFW(int width, int height, const std::string &name, bool wa if (!gladLoadGL((GLADloadfunc)glfwGetProcAddress)) { - log_print("err", "could not load opengl"); + log_error("%s", "could not load opengl"); return; } diff --git a/src/context_glfw.h b/src/context_glfw.h index 2f407e3..34f2f96 100644 --- a/src/context_glfw.h +++ b/src/context_glfw.h @@ -13,20 +13,20 @@ namespace Mauri class ContextGLFW : public Context { public: - ContextGLFW(int width, int height, const std::string &name, bool wallpaper); + ContextGLFW(s32 width, s32 height, const std::string &name, bool wallpaper); ~ContextGLFW(); void close_window(); - void resize_window(int w, int h); + void resize_window(s32 w, s32 h); bool should_close() const; void process_input(); - void cursor_pos(float *x, float *y); + void cursor_pos(f32 *x, f32 *y); void swap_buffers(); - double current_time(); + f64 current_time(); private: GLFWwindow *window; diff --git a/src/context_null.h b/src/context_null.h index f6ecdb1..f95375e 100644 --- a/src/context_null.h +++ b/src/context_null.h @@ -9,7 +9,7 @@ namespace Mauri class ContextNull : public Context { public: - ContextNull(int width, int height, const std::string &name, bool wallpaper) + ContextNull(s32 width, s32 height, const std::string &name, bool wallpaper) : Context(width, height, name, wallpaper) { set_draw_enabled(false); @@ -17,7 +17,7 @@ public: ~ContextNull() {} - void resize_window(int w, int h) + void resize_window(s32 w, s32 h) { width = w; height = h; @@ -37,13 +37,13 @@ public: void process_input() {} - void cursor_pos(float *x, float *y) + void cursor_pos(f32 *x, f32 *y) { *y = 0.f; *x = 0.f; } - double current_time() + f64 current_time() { return 0.f; } diff --git a/src/context_x11.cc b/src/context_x11.cc index 3e0b118..225ebd1 100644 --- a/src/context_x11.cc +++ b/src/context_x11.cc @@ -4,11 +4,9 @@ #include "engine.h" #include "log.h" -#include - using namespace Mauri; -static Atom ATOM_WM_PROTOCOLS, ATOM_WM_DELETE_WINDOW, ATOM__NET_ACTIVE_WINDOW; +static Atom ATOM_WM_DELETE_WINDOW, ATOM__NET_ACTIVE_WINDOW; void ContextX11::disable_input() { @@ -64,7 +62,7 @@ ContextX11::ContextX11(int width, int height, const std::string &name, bool wall if (!fbc) return; - for (int t = 0; t < fb_sz; ++t) + for (auto t = 0; t < fb_sz; ++t) { XVisualInfo* xvi = glXGetVisualFromFBConfig(x11_d, fbc[t]); if (xvi) @@ -299,7 +297,7 @@ void ContextX11::process_input() switch (xev.type) { case ClientMessage: - if (xev.xclient.data.l[0] == ATOM_WM_DELETE_WINDOW) + if ((u64)xev.xclient.data.l[0] == ATOM_WM_DELETE_WINDOW) _should_close = true; break; case MapNotify: // make window not clickable diff --git a/src/context_x11.h b/src/context_x11.h index a5c88dc..c0e022c 100644 --- a/src/context_x11.h +++ b/src/context_x11.h @@ -25,7 +25,7 @@ #define _NET_WM_STATE_TOGGLE 2 -typedef GLXContext (*glXCreateContextAttribsARBProc)(Display *, GLXFBConfig, GLXContext, Bool, const int *); +typedef GLXContext (*glXCreateContextAttribsARBProc)(Display *, GLXFBConfig, GLXContext, Bool, const s32 *); using std::chrono::time_point; using std::chrono::system_clock; @@ -34,12 +34,12 @@ namespace Mauri { class ContextX11 : public Context { public: - ContextX11(int width, int height, const std::string &name, bool wallpaper); + ContextX11(s32 width, s32 height, const std::string &name, bool wallpaper); ~ContextX11(); void close_window(); - void resize_window(int w, int h); + void resize_window(s32 w, s32 h); bool should_close() const { @@ -49,11 +49,11 @@ class ContextX11 : public Context { void swap_buffers(); void process_input(); - void cursor_pos(float *x, float *y); + void cursor_pos(f32 *x, f32 *y); - double current_time() + f64 current_time() { - std::chrono::duration diff = (system_clock::now() - start); + std::chrono::duration diff = (system_clock::now() - start); return diff.count() * 0.5; } diff --git a/src/engine.cc b/src/engine.cc index f882646..254b06a 100644 --- a/src/engine.cc +++ b/src/engine.cc @@ -1,20 +1,10 @@ +#include + #include "engine.h" -#include "assets.h" -#include "context.h" -#include "json.h" -#include "shader.h" -#include "gl.h" -#include "texture.h" -#include "framebuffer.h" #include "objects/object.h" #include "objects/scene.h" -#include -#include -#include -#include - using namespace Mauri; void View::center_scale_viewport() diff --git a/src/engine.h b/src/engine.h index 45b441d..de0ff72 100644 --- a/src/engine.h +++ b/src/engine.h @@ -1,8 +1,6 @@ #ifndef _ENGINE_H #define _ENGINE_H -#include - #include "context.h" #include "gl.h" #include "shader.h" @@ -13,8 +11,6 @@ #include "visualizer.h" #endif -using namespace glm; - static const std::string COMBINE_BUFFER = "_rt_FullFrameBuffer"; namespace Mauri diff --git a/src/gl.cc b/src/gl.cc index 9c35e1d..daa2f64 100644 --- a/src/gl.cc +++ b/src/gl.cc @@ -1,6 +1,3 @@ -#include -#include - #include #include "gl.h" @@ -168,6 +165,7 @@ RenderShader::RenderShader(const std::string &vs_source, const std::string &fs_s u32 vs_shader = glCreateShader(GL_VERTEX_SHADER); if (!compile(vs_shader, vs_source.c_str(), error)) { + std::cout << vs_source << "\n"; log_error("failed to compile vertex shader (%s)", error); return; } @@ -290,11 +288,13 @@ RenderTexture::RenderTexture(bool no_interp, bool clamp_uv, bool filtering, s32 { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); @@ -315,7 +315,7 @@ void RenderTexture::upload(byte *data, s32 width, s32 height, s32 level, bool dx { case GL_RGBA: { byte *dp = data; - for (int i = 0; i < width * height; i++) + for (auto i = 0; i < width * height; i++) { pixels[i] = pack_rgba(*dp, *(dp + 1), *(dp + 2), *(dp + 3)); dp += 4; @@ -324,7 +324,7 @@ void RenderTexture::upload(byte *data, s32 width, s32 height, s32 level, bool dx } case GL_RG: { byte *dp = data; - for (int i = 0; i < width * height; i++) + for (auto i = 0; i < width * height; i++) { pixels[i] = pack_rg(*dp, *(dp + 1)); dp += 2; @@ -333,7 +333,7 @@ void RenderTexture::upload(byte *data, s32 width, s32 height, s32 level, bool dx } case GL_RED: { byte *dp = data; - for (int i = 0; i < width * height; i++) + for (auto i = 0; i < width * height; i++) { pixels[i] = pack_red(*dp); dp += 1; diff --git a/src/gl.h b/src/gl.h index 97edd4b..7a5fc07 100644 --- a/src/gl.h +++ b/src/gl.h @@ -1,15 +1,8 @@ #ifndef _GL_H #define _GL_H -#include -#include - -#include - #include "util.h" -using namespace glm; - namespace Mauri { @@ -40,7 +33,7 @@ class RenderObject void bind(); void draw(); - void set_data(float *vertices, s32 vertex_count); + void set_data(f32 *vertices, s32 vertex_count); private: u32 vao; @@ -81,7 +74,7 @@ class RenderTexture std::vector pixels; - void bind(int index); + void bind(s32 index); void upload(byte *data, s32 width, s32 height, s32 level, bool dxt = false, bool scale = true); }; diff --git a/src/json.h b/src/json.h index 2c3bb72..fc55c02 100644 --- a/src/json.h +++ b/src/json.h @@ -1,17 +1,8 @@ #ifndef _JSON_H #define _JSON_H -#include -#include -#include -#include -#include - #include "util.h" -using namespace glm; -using namespace nlohmann; - #define str_vec4(s, v) sscanf(s, "%f %f %f %f", &(v)[0], &(v)[1], &(v)[2], &(v)[3]) #define str_vec3(s, v) sscanf(s, "%f %f %f", &(v)[0], &(v)[1], &(v)[2]) #define str_vec2(s, v) sscanf(s, "%f %f", &(v)[0], &(v)[1]) @@ -65,7 +56,7 @@ class Parser JsonValueType type; - if (std::is_same::value) + if constexpr (std::is_same::value) { if (jvalue.is_number()) { @@ -73,7 +64,7 @@ class Parser } type = INT; } - else if (std::is_same::value) + else if constexpr (std::is_same::value) { if (jvalue.is_number()) { @@ -81,7 +72,7 @@ class Parser } type = INT; } - else if (std::is_same::value) + else if constexpr (std::is_same::value) { if (jvalue.is_number()) { @@ -89,7 +80,7 @@ class Parser } type = FLOAT; } - else if (std::is_same::value) + else if constexpr (std::is_same::value) { if (jvalue.is_string()) { @@ -97,7 +88,7 @@ class Parser } type = STRING; } - else if (std::is_same::value) + else if constexpr (std::is_same::value) { if (jvalue.is_string()) { @@ -105,7 +96,7 @@ class Parser } type = VEC2; } - else if (std::is_same::value) + else if constexpr (std::is_same::value) { if (jvalue.is_string()) { @@ -113,7 +104,7 @@ class Parser } type = VEC3; } - else if (std::is_same::value) + else if constexpr (std::is_same::value) { // Special case for because VEC4 is used for all // uniform values and some are written as a single number, not a string. @@ -127,7 +118,7 @@ class Parser } type = VEC4; } - else if (std::is_same::value) + else if constexpr (std::is_same::value) { if (jvalue.is_boolean()) { diff --git a/src/mauri.cc b/src/mauri.cc index 23a393e..3aa371e 100644 --- a/src/mauri.cc +++ b/src/mauri.cc @@ -18,8 +18,6 @@ #include "objects/scene.h" -#include - using namespace Mauri; static std::string scene_path = "scene.json"; @@ -33,6 +31,7 @@ s32 main(s32 argc, char *argv[]) #endif set_context(new ContextGLFW(1600, 900, "mauri", false)); + //set_context(new ContextGLFW(2560, 1440, "mauri", false)); //set_context(new ContextX11(2560, 1440, "mauri", true)); //set_context(new ContextNull(1920, 1080, "mauri", false)); @@ -44,16 +43,16 @@ s32 main(s32 argc, char *argv[]) return 1; } - //asset_manager()->write_files("./output"); - Parser parser; Scene *scene = new Scene(parser, scene_path); - //context()->resize_window(scene->width, scene->height); + context()->resize_window(scene->width / 1.75, scene->height / 1.75); Engine engine(scene, &parser, true); + //asset_manager()->write_files("./output"); + engine.run(); delete scene; diff --git a/src/objects/effect.cc b/src/objects/effect.cc index 8e61964..9257061 100644 --- a/src/objects/effect.cc +++ b/src/objects/effect.cc @@ -5,10 +5,7 @@ #include "effect.h" #include "object.h" - -#include "objects/pass.h" - -#include +#include "pass.h" using namespace Mauri; @@ -55,7 +52,7 @@ void Effect::load(Engine *engine, Object *object, bool last) u32 index = 0; - for (u32 i = 0; i < passes1.size(); i++) + for (auto i = 0u; i < passes1.size(); i++) { Pass pass; diff --git a/src/objects/effect.h b/src/objects/effect.h index 840830b..8be54e7 100644 --- a/src/objects/effect.h +++ b/src/objects/effect.h @@ -1,11 +1,9 @@ #ifndef _EFFECT_H #define _EFFECT_H -#include - -#include "engine.h" -#include "texture.h" -#include "util.h" +#include "../util.h" +#include "../engine.h" +#include "../texture.h" namespace Mauri { @@ -34,7 +32,6 @@ class Effect std::vector passes; - void load(Engine *engine, Object *object, bool last); void draw(Engine *engine); diff --git a/src/objects/material.cc b/src/objects/material.cc index aae5940..b99b918 100644 --- a/src/objects/material.cc +++ b/src/objects/material.cc @@ -1,11 +1,11 @@ -#include "assets.h" -#include "engine.h" -#include "json.h" -#include "log.h" +#include "../assets.h" +#include "../engine.h" +#include "../json.h" +#include "../log.h" -#include "objects/material.h" -#include "objects/object.h" -#include "objects/pass.h" +#include "material.h" +#include "object.h" +#include "pass.h" using namespace Mauri; diff --git a/src/objects/material.h b/src/objects/material.h index 11a2c46..5bc7c3a 100644 --- a/src/objects/material.h +++ b/src/objects/material.h @@ -1,10 +1,8 @@ #ifndef _MATERIAL_H #define _MATERIAL_H -#include - -#include "json.h" -#include "engine.h" +#include "../json.h" +#include "../engine.h" namespace Mauri { diff --git a/src/objects/model.cc b/src/objects/model.cc index 7fac34b..8af3224 100644 --- a/src/objects/model.cc +++ b/src/objects/model.cc @@ -1,10 +1,10 @@ -#include "assets.h" -#include "json.h" -#include "log.h" +#include "../assets.h" +#include "../json.h" +#include "../log.h" -#include "objects/material.h" -#include "objects/model.h" -#include "objects/pass.h" +#include "material.h" +#include "model.h" +#include "pass.h" using namespace Mauri; diff --git a/src/objects/model.h b/src/objects/model.h index 243de1f..a9b2b01 100644 --- a/src/objects/model.h +++ b/src/objects/model.h @@ -1,12 +1,10 @@ #ifndef _MODEL_H #define _MODEL_H -#include +#include "../engine.h" +#include "../json.h" -#include "engine.h" -#include "json.h" - -#include "objects/material.h" +#include "material.h" namespace Mauri { diff --git a/src/objects/object.cc b/src/objects/object.cc index bc744d1..4c7273b 100644 --- a/src/objects/object.cc +++ b/src/objects/object.cc @@ -1,21 +1,12 @@ -#include -#include -#include -#include - -#include -#include -#include - #include "../gl.h" #include "../json.h" #include "../log.h" -#include "objects/effect.h" -#include "objects/model.h" -#include "objects/object.h" -#include "objects/scene.h" -#include "objects/pass.h" +#include "effect.h" +#include "model.h" +#include "object.h" +#include "scene.h" +#include "pass.h" using namespace Mauri; @@ -31,13 +22,13 @@ Object::Object(Parser &p, json &root) // object or are repeated. This could be handled be sorting objects // on the scene in order of deps but I'm not sure if that would // break other things. - std::vector::const_iterator it = deps.begin(); + std::vector::const_iterator it = deps.begin(); while (it != deps.end()) { bool remove = false; - if (*it == id) + if ((u32)(*it) == id) { remove = true; } diff --git a/src/objects/object.h b/src/objects/object.h index eb8ad5a..d4a31a5 100644 --- a/src/objects/object.h +++ b/src/objects/object.h @@ -1,14 +1,10 @@ #ifndef _OBJECT_H #define _OBJECT_H -#include - #include "../engine.h" -#include "effect.h" #include "model.h" - -using namespace glm; +#include "effect.h" namespace Mauri { @@ -35,7 +31,7 @@ class Object bool visible; - std::vector deps; + std::vector deps; bool passthrough = false; bool fullscreen = false; diff --git a/src/objects/pass.cc b/src/objects/pass.cc index e938823..db5084a 100644 --- a/src/objects/pass.cc +++ b/src/objects/pass.cc @@ -1,23 +1,15 @@ -#include -#include -#include -#include -#include -#include - -#include "assets.h" -#include "engine.h" -#include "gl.h" -#include "json.h" -#include "shader.h" -#include "json.h" -#include "texture.h" - -#include "objects/pass.h" -#include "objects/material.h" -#include "objects/model.h" -#include "objects/object.h" -#include "objects/scene.h" +#include "../assets.h" +#include "../engine.h" +#include "../gl.h" +#include "../json.h" +#include "../shader.h" +#include "../texture.h" + +#include "pass.h" +#include "material.h" +#include "model.h" +#include "object.h" +#include "scene.h" using namespace Mauri; @@ -83,7 +75,7 @@ Pass::Pass(Parser &p, json &root, PassStage stage) auto _textures = root["textures"]; - for (int i = 0; i < _textures.size(); i++) + for (auto i = 0u; i < _textures.size(); i++) { auto texture = _textures[i]; if (texture.is_string()) @@ -102,7 +94,7 @@ void Pass::load(Engine *engine, PassStage stage, Pass *pass) { intermidiate = true; - for (int i = 0; i < MAX_TEXTURES; i++) + for (auto i = 0; i < MAX_TEXTURES; i++) { if (textures[i].empty()) continue; @@ -132,7 +124,7 @@ void Pass::load(Engine *engine, PassStage stage, Pass *pass) if (!pass->target.empty()) pass->target.append(pass->effect->buffer_id); - for (int i = 0; i < MAX_TEXTURES; i++) + for (auto i = 0; i < MAX_TEXTURES; i++) { if (binds[i].empty()) continue; @@ -194,7 +186,7 @@ RenderPass::RenderPass(Engine *engine, Pass *pass) shader = new Shader(engine->parser, pass->shader); - for (int i = 0; i < shader->texture_count; i++) + for (auto i = 0u; i < shader->texture_count; i++) { if (!shader->textures[i].empty()) { @@ -361,7 +353,7 @@ void RenderPass::draw(Engine *engine) _target->buffer->bind(); - for (int i = 0; i < shader->texture_count; i++) + for (auto i = 0u; i < shader->texture_count; i++) { if (texture_types[i] == PREVIOUS) { @@ -393,7 +385,7 @@ void RenderPass::draw(Engine *engine) #if FRAME_STEP _target->buffer->blit(0, context()->width, context()->height); context()->swap_buffers(); - std::this_thread::sleep_for(std::chrono::seconds(2)); + std::this_thread::sleep_for(std::chrono::seconds(1)); #endif break; diff --git a/src/objects/pass.h b/src/objects/pass.h index c8d8d0e..d2806d9 100644 --- a/src/objects/pass.h +++ b/src/objects/pass.h @@ -1,16 +1,14 @@ #ifndef _PASS_H #define _PASS_H -#include - -#include "json.h" -#include "context.h" -#include "engine.h" -#include "gl.h" -#include "shader.h" -#include "texture.h" - -#include "objects/object.h" +#include "../json.h" +#include "../context.h" +#include "../engine.h" +#include "../gl.h" +#include "../shader.h" +#include "../texture.h" + +#include "object.h" #define MAX_TEXTURES 8 diff --git a/src/objects/scene.cc b/src/objects/scene.cc index 97b9f58..9bdc86c 100644 --- a/src/objects/scene.cc +++ b/src/objects/scene.cc @@ -1,13 +1,10 @@ -#include -#include +#include "../assets.h" +#include "../json.h" +#include "../log.h" +#include "../util.h" -#include "assets.h" -#include "json.h" -#include "log.h" -#include "util.h" - -#include "objects/scene.h" -#include "objects/pass.h" +#include "scene.h" +#include "pass.h" using namespace Mauri; @@ -17,7 +14,7 @@ Scene::Scene(Parser &p, const std::string &path) if (asset->type == ASSET_VOID) { - log_error("err: failed to open scene.json"); + log_error("%s", "failed to open scene.json"); return; } diff --git a/src/objects/scene.h b/src/objects/scene.h index 5c2b3a0..7dda288 100644 --- a/src/objects/scene.h +++ b/src/objects/scene.h @@ -1,17 +1,11 @@ #ifndef _SCENE_H #define _SCENE_H -#include +#include "../assets.h" +#include "../engine.h" +#include "../json.h" -#include - -#include "assets.h" -#include "engine.h" - -#include "json.h" -#include "objects/object.h" - -using namespace glm; +#include "object.h" namespace Mauri { @@ -20,9 +14,9 @@ struct Camera { vec3 center; vec3 eye; vec3 up; - float farz; - float nearz; - float fov; + f32 farz; + f32 nearz; + f32 fov; }; class Scene diff --git a/src/shader.cc b/src/shader.cc index ae8032a..ee661fd 100644 --- a/src/shader.cc +++ b/src/shader.cc @@ -1,8 +1,3 @@ -#include -#include -#include -#include - #include #include @@ -51,6 +46,7 @@ void Shader::build_shader_source(Parser *p, const std::string &isource, std::str for (std::string line; std::getline(stream, line);) { auto cut_line = false; + auto prepend_line = false; if (line.compare(0, 8, "#include") == 0) { @@ -86,6 +82,7 @@ void Shader::build_shader_source(Parser *p, const std::string &isource, std::str { uniform->type = TYPE_SAMPLER2D; uniform->default_value[0] = texture_count++; + prepend_line = true; } auto open = type_string.find(' ') + 1; @@ -150,7 +147,10 @@ void Shader::build_shader_source(Parser *p, const std::string &isource, std::str auto root = json::parse(combo); - combos.emplace_back(Combo { root["combo"], root["default"] }); + if (!root["default"].is_null()) + { + combos.emplace_back(Combo { root["combo"], root["default"] }); + } } if (!cut_line) @@ -158,7 +158,14 @@ void Shader::build_shader_source(Parser *p, const std::string &isource, std::str //line = std::regex_replace(line, mod_regex, "mod($1$2, $3)"); //line = std::regex_replace(line, mod_regex, "uint(uint($1$2) % $3)"); //line = std::regex_replace(line, uint_regex, "int int($1)"); - res += line + "\n"; + if (prepend_line) + { + res.insert(0, line + "\n"); + } + else + { + res += line + "\n"; + } } } } @@ -230,13 +237,14 @@ void Shader::bind(Engine *engine, Object *object, mat4x4 *model, std::arrayvalue)[0] << " " << (*uniform->value)[1] << " " << (*uniform->value)[2] << " " << (*uniform->value)[3] << "\n"; #endif - if (uniform->value != nullptr && uniform->type != TYPE_MAT4) + //if (uniform->value != nullptr && uniform->type != TYPE_MAT4) + if (uniform->value != nullptr) rshader->set_uniform(uniform->uname, uniform->type, glm::value_ptr(*uniform->value)); } if (textures != nullptr) { - for (int i = 0; i < texture_count; i++) + for (auto i = 0u; i < texture_count; i++) { auto texture = (*textures)[i]; diff --git a/src/shader.h b/src/shader.h index e3519ff..1d41be7 100644 --- a/src/shader.h +++ b/src/shader.h @@ -1,16 +1,12 @@ #ifndef _SHADER_H #define _SHADER_H -#include - #include "gl.h" #include "texture.h" #include "json.h" #define MAX_TEXTURES 8 -using namespace glm; - namespace Mauri { diff --git a/src/texture.cc b/src/texture.cc index 96a541b..4eaaf23 100644 --- a/src/texture.cc +++ b/src/texture.cc @@ -5,7 +5,6 @@ #include #include - #include #include @@ -75,7 +74,7 @@ Texture::Texture(Asset *asset) textures.resize(image_count); - for (int s = 0; s < image_count; s++) + for (auto s = 0u; s < image_count; s++) { auto mm_count = asset->read(); @@ -83,7 +82,7 @@ Texture::Texture(Asset *asset) texture = textures[s]; - for (int i = 0; i < mm_count; i++) + for (auto i = 0u; i < mm_count; i++) { auto mwidth = asset->read(); auto mheight = asset->read(); @@ -191,7 +190,7 @@ Texture::Texture(Asset *asset) gif_height = asset->read(); } - for (int i = 0; i < frame_count; i++) + for (auto i = 0u; i < frame_count; i++) { // See TextureFrame frames.push_back(TextureFrame { diff --git a/src/texture.h b/src/texture.h index 0f19406..8c5477a 100644 --- a/src/texture.h +++ b/src/texture.h @@ -1,14 +1,10 @@ #ifndef _TEXTURE_H #define _TEXTURE_H -#include - #include "assets.h" #include "gl.h" #include "util.h" -using namespace glm; - namespace Mauri { diff --git a/src/util.cc b/src/util.cc index ff341ef..a9d7664 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1,13 +1,9 @@ -#include -#include -#include - #include "util.h" namespace Mauri { -int next_power_of_two(int n) +s32 next_power_of_two(s32 n) { n--; n |= n >> 1; diff --git a/src/util.h b/src/util.h index 1c351f2..126a779 100644 --- a/src/util.h +++ b/src/util.h @@ -3,8 +3,11 @@ #include #include +#include +#include using namespace nlohmann; +using namespace glm; #define FRAME_STEP 0 #define UNIFORM_DEBUG 0 diff --git a/src/visualizer.cc b/src/visualizer.cc index a374cf2..941ae54 100644 --- a/src/visualizer.cc +++ b/src/visualizer.cc @@ -1,22 +1,10 @@ -#include #include -#include -#include -#include -#include +#include "log.h" #include "assets.h" -#include "gst/gstbuffer.h" -#include "gst/gstcaps.h" -#include "gst/gstelement.h" -#include "gst/gstmemory.h" -#include "gst/gstsample.h" -#include "gst/gststructure.h" -#include "gst/gstutils.h" +#include "visualizer.h" -#include "log.h" #include "objects/material.h" -#include "visualizer.h" using namespace Mauri; @@ -27,7 +15,7 @@ void Visualizer::calc_cutoff() f64 freqconst = std::log10(low_freq_cap / (f64)high_freq_cap) / ((1.0 / (BAR_COUNT + 1.0)) - 1.0); - for (s32 i = 0; i <= BAR_COUNT; ++i) + for (auto i = 0; i <= BAR_COUNT; ++i) { freqconst_per_bin[i] = high_freq_cap * std::pow(10.0, (freqconst * -1) + (((i + 1.0) / (BAR_COUNT + 1.0)) * freqconst)); @@ -49,7 +37,7 @@ void Visualizer::gaussian_blur(bool right) { f32 *bars = (right) ? (f32 *)bars_64_right : (f32 *)bars_64_left; - for (int i = 1; i < BAR_COUNT - 1; i++) + for (auto i = 1; i < BAR_COUNT - 1; i++) { bars[i] = bars[i - 1] * gausian_array[0] + bars[i] * gausian_array[1] + bars[i + 1] * gausian_array[2]; @@ -62,14 +50,14 @@ void Visualizer::monstercat_smoothing(bool right) std::array smoothing_factors; - for (int i = 0; i < BAR_COUNT; ++i) + for (auto i = 0; i < BAR_COUNT; ++i) { smoothing_factors[i] = std::pow(1.5, i); } - for (int i = 1; i < BAR_COUNT; ++i) + for (auto i = 1; i < BAR_COUNT; ++i) { - for (int j = 0; j < BAR_COUNT; ++j) + for (auto j = 0; j < BAR_COUNT; ++j) { if (i == j) continue; @@ -105,11 +93,11 @@ void Visualizer::update_bars(bool right) out = &out_left[0]; } - for (s32 i = 0; i < BAR_COUNT; i++) + for (auto i = 0; i < BAR_COUNT; i++) { f64 magnitude = 0.0; - for (s32 s = low_cutoff[i]; s <= high_cutoff[i] && s < (sample_count / 2); ++s) + for (auto s = (s32)low_cutoff[i]; s <= high_cutoff[i] && s < (sample_count / 2); ++s) { magnitude += std::sqrt((out[s][0] * out[s][0]) + (out[s][1] * out[s][1])); } @@ -139,12 +127,12 @@ void Visualizer::update_bars(bool right) //monstercat_smoothing(right); - for (s32 i = 0; i < BAR_COUNT; i++) + for (auto i = 0; i < BAR_COUNT; i++) { bars_64[i] = bars_falloff[i] / 5500; } - for (s32 i = 0; i < BAR_COUNT / 2; i++) + for (auto i = 0; i < BAR_COUNT / 2; i++) { s32 index = i * 2; @@ -155,7 +143,7 @@ void Visualizer::update_bars(bool right) bars_32[i] /= 2.0; } - for (s32 i = 0; i < BAR_COUNT / 4; i++) + for (auto i = 0; i < BAR_COUNT / 4; i++) { s32 index = i * 4; @@ -184,7 +172,7 @@ void Visualizer::update_sample() g_mutex_lock(&mutex); - for (s32 i = 0; i < sample_count; i++) + for (auto i = 0; i < sample_count; i++) { in_left[i] = (f64)samples[i].left; in_right[i] = (f64)samples[i].right; -- cgit v1.2.3-101-g0448