diff --git a/CMakeLists.txt b/CMakeLists.txt index b6c2321..824ff7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,26 @@ cmake_minimum_required(VERSION 3.8) project(pixwerx) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/etc/cmake") - +# +# pixwerx ist C++17 +# set (CMAKE_CXX_STANDARD 17) +# internal cmake modules +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/etc/cmake ${CMAKE_MODULE_PATH}) + +# boilerplate locations for build +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin CACHE PATH "Executables go here") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib CACHE PATH "Libraries go here") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin CACHE PATH "Standalone DLLs go here") + +# boilerplate settings for shared libs +set(CMAKE_SKIP_BUILD_RPATH OFF) +set(CMAKE_POSITION_INDEPENDENT_CODE ON) + + +# +# now the actual code +# add_subdirectory(src) add_subdirectory(share) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index b323010..dccf5cc 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -11,18 +11,18 @@ set(hdrs include/pw/core/serialize.hpp include/pw/core/image.hpp include/pw/core/point.hpp - include/pw/core/rect.hpp - include/pw/core/size.hpp + include/pw/core/rect.hpp + include/pw/core/size.hpp include/pw/core/timer.hpp - include/pw/core/mesh.hpp + include/pw/core/mesh.hpp include/pw/core/globals.hpp ) set(srcs - src/buffer.cpp + src/buffer.cpp src/image.cpp src/debug.cpp - src/mesh.cpp + src/mesh.cpp src/core.cpp src/serialize.cpp src/timer.cpp diff --git a/src/core/include/pw/core/timer.hpp b/src/core/include/pw/core/timer.hpp index e32c2cb..7d5f4ef 100644 --- a/src/core/include/pw/core/timer.hpp +++ b/src/core/include/pw/core/timer.hpp @@ -23,7 +23,6 @@ #ifndef PW_CORE_TIMER_HPP_ #define PW_CORE_TIMER_HPP_ - #include #include @@ -36,10 +35,6 @@ namespace pw { class timer { public: - const static unsigned int UnitMicroSeconds = 1000000; - const static unsigned int UnitMilliSeconds = 1000; - const static unsigned int UnitSeconds = 1; - typedef std::chrono::time_point tick_t; timer(); /// c'tor @@ -49,17 +44,15 @@ public: /** * @brief elapsed time based on the scale - * @param scale units the time will be reported * @return value of the time since last @see reset */ - double elapsed(unsigned int scale = UnitMilliSeconds) const; + double elapsed() const; /** - * @brief Now - * @param scale - * @return + * @brief time from start of core in seconds + * @return time in seconds */ - static double now(unsigned int scale = UnitMicroSeconds); + static double now(); protected: diff --git a/src/core/src/timer.cpp b/src/core/src/timer.cpp index 6f1e405..16ae81e 100644 --- a/src/core/src/timer.cpp +++ b/src/core/src/timer.cpp @@ -1,13 +1,27 @@ -/* vim: set tabstop=4:softtabstop=4:shiftwidth=4:noexpandtab */ /* - * SSTT - Simplified Spatial Target Tracker + * Copyright (c) 1999-2019 Hartmut Seichter + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. * - * (c) Copyrights 2007-2018 Hartmut Seichter */ - #include "pw/core/timer.hpp" - namespace pw { static timer global_timer; @@ -26,15 +40,15 @@ void timer::reset() _start = std::chrono::high_resolution_clock::now(); } -double timer::elapsed( unsigned int scale ) const +double timer::elapsed() const { std::chrono::duration elapsed_seconds = std::chrono::high_resolution_clock::now() - _start; - return elapsed_seconds.count() * scale; + return elapsed_seconds.count(); } -double timer::now( unsigned int scale ) +double timer::now() { - return global_timer.elapsed(scale); + return global_timer.elapsed(); } } diff --git a/src/scripting/src/script_core.cpp b/src/scripting/src/script_core.cpp index d9c538a..668d7d7 100644 --- a/src/scripting/src/script_core.cpp +++ b/src/scripting/src/script_core.cpp @@ -6,6 +6,7 @@ #include "pw/core/debug.hpp" #include "pw/core/size.hpp" #include "pw/core/point.hpp" +#include "pw/core/timer.hpp" namespace pw { @@ -13,69 +14,76 @@ namespace pw { void script_core::load(sol::table &ns) { - typedef real_t Scalar; + typedef real_t Scalar; - ns.set("pi",pw::pi()); + ns.set("pi",pw::pi()); - ns.new_usertype("vector3", - sol::constructors(), - "set",&vector3::set, - "x", scripting::property(scripting::resolve(&vector3::x), &vector3::set_x), - "y", scripting::property(scripting::resolve(&vector3::y), &vector3::set_y), - "z", scripting::property(scripting::resolve(&vector3::z), &vector3::set_z), - "norm",&vector3::norm, - "cross",&vector3::cross, - "dot",&vector3::dot, - // sol::meta_function::addition, sol::resolve(::operator+), - // sol::meta_function::subtraction, &vector3::operator- - // "v",&vector3::values, - "clone",&vector3::clone - ); + ns.new_usertype("vector3", + sol::constructors(), + "set",&vector3::set, + "x", scripting::property(scripting::resolve(&vector3::x), &vector3::set_x), + "y", scripting::property(scripting::resolve(&vector3::y), &vector3::set_y), + "z", scripting::property(scripting::resolve(&vector3::z), &vector3::set_z), + "norm",&vector3::norm, + "cross",&vector3::cross, + "dot",&vector3::dot, + // sol::meta_function::addition, sol::resolve(::operator+), + // sol::meta_function::subtraction, &vector3::operator- + // "v",&vector3::values, + "clone",&vector3::clone + ); - ns.new_usertype("quaternion", - sol::constructors(), - "set",&quaternion::set, - "x", scripting::property(scripting::resolve(&quaternion::x), &quaternion::set_x), - "y", scripting::property(scripting::resolve(&quaternion::y), &quaternion::set_y), - "z", scripting::property(scripting::resolve(&quaternion::z), &quaternion::set_z), - "w", scripting::property(scripting::resolve(&quaternion::w), &quaternion::set_w), - "dot",&quaternion::dot, - "inverse",scripting::readonly_property(&quaternion::inverse), - "normalized",&quaternion::normalized, - "lerp",&quaternion::lerp, - "slerp",&quaternion::slerp - // "v",&vector3d::values, - // "clone",&vector3d::clone - ); + ns.new_usertype("quaternion", + sol::constructors(), + "set",&quaternion::set, + "x", scripting::property(scripting::resolve(&quaternion::x), &quaternion::set_x), + "y", scripting::property(scripting::resolve(&quaternion::y), &quaternion::set_y), + "z", scripting::property(scripting::resolve(&quaternion::z), &quaternion::set_z), + "w", scripting::property(scripting::resolve(&quaternion::w), &quaternion::set_w), + "dot",&quaternion::dot, + "inverse",scripting::readonly_property(&quaternion::inverse), + "normalized",&quaternion::normalized, + "lerp",&quaternion::lerp, + "slerp",&quaternion::slerp + // "v",&vector3d::values, + // "clone",&vector3d::clone + ); - ns.new_usertype("axisangle", - sol::constructors(), - "axis",scripting::property(&axisangle::axis,&axisangle::set_axis), - "angle",scripting::property(&axisangle::angle,&axisangle::set_angle) - ); + ns.new_usertype("axisangle", + sol::constructors(), + "axis",scripting::property(&axisangle::axis,&axisangle::set_axis), + "angle",scripting::property(&axisangle::angle,&axisangle::set_angle) + ); - ns.new_usertype("size", - sol::constructors(), - "width",&size::width, - "height",&size::height - // "none",sol::debug::level::none - ); + ns.new_usertype("size", + sol::constructors(), + "width",&size::width, + "height",&size::height + // "none",sol::debug::level::none + ); - ns.new_usertype("point", - sol::constructors(), - "x",&point::x, - "y",&point::y - ); + ns.new_usertype("point", + sol::constructors(), + "x",&point::x, + "y",&point::y + ); - ns.new_usertype("debug", - "new",sol::no_constructor, - "get",&debug::get, - "write",&debug::write - // "none",sol::debug::level::none - ); + ns.new_usertype("debug", + "new",sol::no_constructor, + "get",&debug::get, + "write",&debug::write + // "none",sol::debug::level::none + ); + + + ns.new_usertype("timer", + "now",sol::readonly_property(&timer::now), + "elapsed",sol::readonly_property(&timer::elapsed), + "reset",&timer::reset + ); } diff --git a/src/scripting/src/script_system.cpp b/src/scripting/src/script_system.cpp index 07dcc23..f838ebe 100644 --- a/src/scripting/src/script_system.cpp +++ b/src/scripting/src/script_system.cpp @@ -5,7 +5,7 @@ #include "pw/system/display.hpp" // hijacking -#include "pw/visual/pipeline.hpp" +//#include "pw/visual/pipeline.hpp" namespace pw { @@ -13,6 +13,7 @@ void script_system::load(sol::table &ns) { ns.new_usertype("window", "update",&window::update, + "set_on_update",&window::set_on_update, "title",sol::writeonly_property(&window::set_title), "size",sol::property(&window::size,&window::set_size), "position",sol::property(&window::position,&window::set_position), @@ -33,9 +34,16 @@ void script_system::load(sol::table &ns) "name",sol::readonly_property(&display::name) ); - ns.new_usertype("pipeline", - "create",&pipeline::create - ); + +// ns.set_function("my_class_func_2", &my_class::func); + + + // +// // hijack part +// // +// ns.new_usertype("pipeline", +// "create",&pipeline::create +// ); } } diff --git a/src/scripts/demos/simple_000.lua b/src/scripts/demos/simple_000.lua index 3261fcf..89763b5 100644 --- a/src/scripts/demos/simple_000.lua +++ b/src/scripts/demos/simple_000.lua @@ -71,13 +71,17 @@ local w = pw.window.new() w.title = "pixwerx 0.1" -- set size -w.size = pw.size.new(1200,800) +w.size = pw.size.new(800,600) +-- move window +w.position = pw.point.new(100,100) local ds = pw.display:all() for i = 1,#ds do print("display ",i,ds[i].name) end +local t = pw.timer.new() + while w:update() do -- somehow works @@ -87,6 +91,8 @@ do -- just to check if (pw.input:get().mouse_button == 1) then + print("elapsed",t.elapsed) + t:reset() print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y) end diff --git a/src/system/include/pw/system/window.hpp b/src/system/include/pw/system/window.hpp index 8244e75..176bcc2 100644 --- a/src/system/include/pw/system/window.hpp +++ b/src/system/include/pw/system/window.hpp @@ -5,11 +5,15 @@ #include #include +#include + namespace pw { class window { public: + typedef std::function on_update_t; + window(); ~window(); @@ -28,9 +32,12 @@ public: bool fullscreen() const; void set_fullscreen(bool use_fullscreen); + void set_on_update(on_update_t f) { _on_update = f; } protected: + on_update_t _on_update; + struct impl; std::unique_ptr _impl; diff --git a/src/system/src/window.cpp b/src/system/src/window.cpp index 3350f41..336327f 100644 --- a/src/system/src/window.cpp +++ b/src/system/src/window.cpp @@ -39,6 +39,8 @@ namespace pw { struct window::impl { + window& _parent; + GLFWwindow *_window = nullptr; sizei _old_size; @@ -125,7 +127,8 @@ struct window::impl { } - impl() + impl(window& w) + : _parent(w) { // initialize glfwInit(); @@ -190,6 +193,9 @@ struct window::impl { // get new events glfwPollEvents(); + _parent._on_update(_parent); + + // do other stuff #if 0 glClearColor(1,0,0,1); @@ -270,7 +276,8 @@ struct window::impl { window::window() - : _impl(std::make_unique()) + : _impl(std::make_unique(*this)) + , _on_update([](window&){}) { } diff --git a/src/visual/include/pw/visual/context.hpp b/src/visual/include/pw/visual/context.hpp index 089bb02..a8aeb64 100644 --- a/src/visual/include/pw/visual/context.hpp +++ b/src/visual/include/pw/visual/context.hpp @@ -33,7 +33,7 @@ public: virtual bool make_current() = 0; virtual void resize() = 0; - virtual size size() = 0; + virtual ::pw::size size() = 0; virtual void flush() = 0; virtual ~context() = default; diff --git a/src/visual/include/pw/visual/pipeline.hpp b/src/visual/include/pw/visual/pipeline.hpp index fbb5ea3..3c60c05 100644 --- a/src/visual/include/pw/visual/pipeline.hpp +++ b/src/visual/include/pw/visual/pipeline.hpp @@ -13,7 +13,7 @@ class pipeline { public: pipeline(); - ~pipeline() = default; + ~pipeline(); void draw(); diff --git a/src/visual/src/pipeline.cpp b/src/visual/src/pipeline.cpp index 800ccfe..06dadae 100644 --- a/src/visual/src/pipeline.cpp +++ b/src/visual/src/pipeline.cpp @@ -99,6 +99,11 @@ pipeline::pipeline() { } +pipeline::~pipeline() +{ + // +} + bool pipeline::create(size s) { return _impl->create(sizei(s.width,s.height));