From 67ae8daef391c82ef2420b82af58d21f182ebe31 Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Sat, 27 Nov 2021 21:52:54 +0100 Subject: [PATCH] some cleanup --- src/binding/src/script_core.cpp | 17 +++++++++-------- src/binding/src/script_io.cpp | 2 +- src/binding/src/script_scene.cpp | 4 ++-- src/binding/src/script_system.cpp | 2 +- src/binding/src/script_visual.cpp | 18 +++++++++--------- src/scripts/demos/simple_002.lua | 6 +++--- src/scripts/demos/simple_003.lua | 22 ++++++++-------------- src/system/include/pw/system/path.hpp | 12 +++++------- src/system/src/path.cpp | 7 ++++++- src/visual/src/framebuffer.cpp | 2 ++ 10 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/binding/src/script_core.cpp b/src/binding/src/script_core.cpp index 6435830..ae8d5f9 100644 --- a/src/binding/src/script_core.cpp +++ b/src/binding/src/script_core.cpp @@ -216,12 +216,12 @@ void register_core_function(sol::state& lua,sol::table& ns) auto image_type = ns.new_usertype("image" - , sol::constructors() - ,"create",&image::create - ,"size",sol::readonly_property(&image::size) - ,"generate_noise",&image::generate_noise - ,"change_count",sol::property(&image::change_count,&image::set_change_count) - ); + ,sol::call_constructor,sol::constructors() + ,"create",&image::create + ,"size",sol::readonly_property(&image::size) + ,"generate_noise",&image::generate_noise + ,"change_count",sol::property(&image::change_count,&image::set_change_count) + ); ns.create_named("pixel_layout" ,"rgb8", image::RGB8 @@ -239,8 +239,9 @@ void register_core_function(sol::state& lua,sol::table& ns) ,sol::call_constructor,sol::constructors&,const size_&)>() ); - auto mathf_table = ns.create_named("mathf"); - mathf_table.set_function("ping_pong",ping_pong); + // some math function + ns.create_named("mathf") + .set_function("ping_pong",ping_pong); } diff --git a/src/binding/src/script_io.cpp b/src/binding/src/script_io.cpp index 557eeb2..77aa96c 100644 --- a/src/binding/src/script_io.cpp +++ b/src/binding/src/script_io.cpp @@ -7,7 +7,7 @@ namespace pw { void register_io_function(sol::state&,sol::table& ns) { ns.new_usertype("image_io" - ,"new", sol::no_constructor + ,"new",sol::no_constructor ,"get",&image_io::get ,"read",&image_io::read ,"write",&image_io::write diff --git a/src/binding/src/script_scene.cpp b/src/binding/src/script_scene.cpp index 80c85c7..0c90f26 100644 --- a/src/binding/src/script_scene.cpp +++ b/src/binding/src/script_scene.cpp @@ -17,14 +17,14 @@ void register_scene_function(sol::state&,sol::table &ns) { ns.new_usertype("scene", - sol::constructors() + sol::call_constructor,sol::constructors() ,"count_all_entities",sol::readonly_property(&scene::count_all_enties) ,"count_alive_entities",sol::readonly_property(&scene::count_alive_enties) ); ns.new_usertype("entity" - ,sol::constructors() + ,sol::call_constructor,sol::constructors() ,"add_child",&entity::add_child ,"remove_child",&entity::remove_child ,"child_count",sol::readonly_property(&entity::child_count) diff --git a/src/binding/src/script_system.cpp b/src/binding/src/script_system.cpp index 8c12cf8..0a26a62 100644 --- a/src/binding/src/script_system.cpp +++ b/src/binding/src/script_system.cpp @@ -42,7 +42,7 @@ void register_system_function(sol::state&, sol::table &ns) ); ns.new_usertype("path" - ,"new", sol::no_constructor + ,"new",sol::no_constructor ,"get",&path::get ,"separator",sol::readonly_property(&path::separator) ,"resource_paths",sol::readonly_property(&path::resource_paths) diff --git a/src/binding/src/script_visual.cpp b/src/binding/src/script_visual.cpp index 395b0f6..ddff54d 100644 --- a/src/binding/src/script_visual.cpp +++ b/src/binding/src/script_visual.cpp @@ -16,13 +16,13 @@ namespace pw { void register_visual_function(sol::state& lua,sol::table &ns) { - ns.new_usertype("pipeline" - ,"create",&pipeline::create - ,"draw",&pipeline::draw - ); +// ns.new_usertype("pipeline" +// ,"create",&pipeline::create +// ,"draw",&pipeline::draw +// ); ns.new_usertype("shader" - ,sol::constructors() + ,sol::call_constructor,sol::constructors() ,"ready",sol::readonly_property(&shader::ready) ,"use",&shader::use ,"build",&shader::build @@ -54,7 +54,7 @@ void register_visual_function(sol::state& lua,sol::table &ns) ns.new_usertype("renderer" - ,sol::constructors() + ,sol::call_constructor,sol::constructors() ,"create",&renderer::create ,"ready",sol::readonly_property(&renderer::ready) ,"release",&renderer::release @@ -62,14 +62,14 @@ void register_visual_function(sol::state& lua,sol::table &ns) ); ns.new_usertype("framebuffer" - ,sol::constructors() + ,sol::call_constructor,sol::constructors() ,"create",&framebuffer::create ,"bind",&framebuffer::bind ,"unbind",&framebuffer::unbind ,"blit",&framebuffer::blit); ns.new_usertype("texture" - ,sol::constructors() + ,sol::call_constructor,sol::constructors() ,"create",&texture::create ,"update",&texture::update ,"bind",&texture::bind @@ -78,7 +78,7 @@ void register_visual_function(sol::state& lua,sol::table &ns) ); ns.new_usertype("context" - ,sol::constructors() + ,sol::call_constructor,sol::constructors() ,"clear",&context::clear ,"set_viewport",&context::set_viewport ,"get_error",&context::get_error diff --git a/src/scripts/demos/simple_002.lua b/src/scripts/demos/simple_002.lua index 22a1652..5e4d413 100644 --- a/src/scripts/demos/simple_002.lua +++ b/src/scripts/demos/simple_002.lua @@ -15,13 +15,13 @@ local w = pw.window.new() w.title = "pixwerx - bare rendering" -- set size -w.size = pw.size.new(640,480) +w.size = pw.size(640,480) -- move window -w.position = pw.point.new(100,100) +w.position = pw.point(100,100) -- create a new geometry -local g = pw.geometry:new() +local g = pw.geometry() g.primitive_topology = pw.primitive_topology_type.triangle_list -- meh diff --git a/src/scripts/demos/simple_003.lua b/src/scripts/demos/simple_003.lua index 2b05969..851a14d 100644 --- a/src/scripts/demos/simple_003.lua +++ b/src/scripts/demos/simple_003.lua @@ -8,8 +8,8 @@ pw.script:load_all() print("executable path:",pw.path.get().executable_path) print("resource path:",pw.path.get().resource_path) -local img = pw.image.new() -if not img:create(pw.size(64,64),pw.pixel_layout.rgb8) then +local img = pw.image() +if not img:create(pw.size(512,512),pw.pixel_layout.rgb8) then print("image couldnt be created") @@ -42,10 +42,10 @@ g.primitive_topology = pw.primitive_topology_type.triangle_list -- meh -- create texture coordinates g.texture_coordinates = { { + { 0.0, 0.0 }, { 1.0, 1.0 }, { 1.0, 0.0 }, - { 0.0, 1.0 }, - { 0.0, 0.0 } + { 0.0, 1.0 } } } z = -5.0 @@ -79,7 +79,7 @@ local mm = pw.matrix4x4.identity local mv = pw.matrix4x4() local mp = pw.matrix4x4() -local s = pw.shader:new() +local s = pw.shader() s:set_source(pw.shader_type.vertex,[[ #version 400 @@ -122,7 +122,7 @@ if not s:build() then end -- the renderer for a geometry -local renderer = pw.renderer:new() +local renderer = pw.renderer() if not renderer:create(g) then print("couldn't create renderer") @@ -134,9 +134,9 @@ local cam_pos = pw.vector3(0,0,0) local model_pos = pw.vector3(0,0,0) -local ctx = pw.context:new() +local ctx = pw.context() -local tx = pw.texture:new() +local tx = pw.texture() tx:create(img) w.on_resize = function(self) @@ -171,23 +171,17 @@ w.on_update = function(self) -- update the uniforms, currently the slow path s:set_uniform_mat4("model",mm) - - - s:set_uniform_mat4("view",mv) s:set_uniform_mat4("projection",mp) s:set_uniform_vec4("color",cl) s:set_uniform_int("tex_color",0) - tx:bind() -- draw renderer:draw() --- tx:unbind() - local e = ctx:get_error() if e ~= 0 then print("OpenGL error",e) diff --git a/src/system/include/pw/system/path.hpp b/src/system/include/pw/system/path.hpp index 21376ea..553047e 100644 --- a/src/system/include/pw/system/path.hpp +++ b/src/system/include/pw/system/path.hpp @@ -31,6 +31,8 @@ namespace pw { class path { public: + using path_list = std::vector; + static path& get(); ~path(); @@ -38,19 +40,15 @@ public: std::string executable_path() const; - std::string resource_path() const; - - typedef std::vector path_list; - - std::string find_file(const std::string &filename) const; - path_list resource_paths() const { return _resource_paths; } + void set_resource_paths(path_list pl); + + std::string find_file(const std::string &filename) const; std::string get_filename(const std::string &filepath, bool with_extension = true) const; protected: - path_list _plugin_paths; path_list _resource_paths; path(); diff --git a/src/system/src/path.cpp b/src/system/src/path.cpp index a0deb36..205cb79 100644 --- a/src/system/src/path.cpp +++ b/src/system/src/path.cpp @@ -81,7 +81,12 @@ std::string path::executable_path() const #endif result.assign(buf.data()); - return result; + return result; +} + +void path::set_resource_paths(path::path_list pl) +{ + _resource_paths = pl; } std::string path::find_file(const std::string&) const diff --git a/src/visual/src/framebuffer.cpp b/src/visual/src/framebuffer.cpp index 878bd00..d0719c5 100644 --- a/src/visual/src/framebuffer.cpp +++ b/src/visual/src/framebuffer.cpp @@ -5,6 +5,8 @@ #include "glad/glad.h" +#include + namespace pw { // TODO stencil buffer?