From f840d51f4f243e788f6cbbb8ff01d2413379877f Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Wed, 9 Jan 2019 17:50:18 +0100 Subject: [PATCH] intermediate state --- src/core/include/pw/core/debug.hpp | 118 ++++++++++++------------ src/core/include/pw/core/point.hpp | 9 +- src/core/include/pw/core/size.hpp | 7 +- src/core/include/pw/core/vector.hpp | 6 +- src/scripting/src/script_core.cpp | 97 +++++++++++-------- src/scripting/src/script_system.cpp | 18 ++-- src/scripts/demos/simple_000.lua | 7 +- src/system/include/pw/system/input.hpp | 3 +- src/system/include/pw/system/window.hpp | 5 +- src/system/src/window.cpp | 6 +- 10 files changed, 146 insertions(+), 130 deletions(-) diff --git a/src/core/include/pw/core/debug.hpp b/src/core/include/pw/core/debug.hpp index 4b6904b..41a4571 100644 --- a/src/core/include/pw/core/debug.hpp +++ b/src/core/include/pw/core/debug.hpp @@ -39,90 +39,90 @@ namespace pw { class debug { public: - enum level { - none, //!< nothing will be logged, even no errors - error, //!< only errors will be logged - warning, //!< log warnings (non-critical errors) - message, //!< log messages (something to note but not an error) - notification, //!< log some more information - info, //!< log verbose information - all = 0xFF //!< log absolutely everything - }; + enum level { + none, //!< nothing will be logged, even no errors + error, //!< only errors will be logged + warning, //!< log warnings (non-critical errors) + message, //!< log messages (something to note but not an error) + notification, //!< log some more information + info, //!< log verbose information + all = 0xFF //!< log absolutely everything + }; - /** - * @brief the streaming interface for the logger - */ - class stream { - public: + /** + * @brief the streaming interface for the logger + */ + class stream { + public: - stream(debug* log = nullptr); - ~stream(); - stream(const stream& other); + stream(debug* log = nullptr); + ~stream(); + stream(const stream& other); - stream &operator << (const bool &value); - stream &operator << (const char *value); - stream& operator << (const std::string& value); ///! log a string + stream &operator << (const bool &value); + stream &operator << (const char *value); + stream& operator << (const std::string& value); ///! log a string - stream& operator << (const float &value); ///! log a float value - stream& operator << (const double &value); ///! log a double value + stream& operator << (const float &value); ///! log a float value + stream& operator << (const double &value); ///! log a double value - stream& operator << (const int &value); ///! log a int value - stream& operator << (const unsigned int &value); ///! log a int value + stream& operator << (const int &value); ///! log a int value + stream& operator << (const unsigned int &value); ///! log a int value - stream& operator << (const long &value); ///! log a long value - stream& operator << (const unsigned long &value); ///! log a int value + stream& operator << (const long &value); ///! log a long value + stream& operator << (const unsigned long &value); ///! log a int value - stream& operator << (const void *value); ///! pointer + stream& operator << (const void *value); ///! pointer - protected: + protected: - debug* _log; - std::string _line; - }; + debug* _log; + std::string _line; + }; - /** sets the logging level */ - void set_level(level level) {_level = level;} + /** sets the logging level */ + void set_level(level level) {_level = level;} - /** gets the logging level */ - level level() const { return _level; } + /** gets the logging level */ + level level() const { return _level; } - /** - * @brief get the stream interface of the logger - * @return return a temporary object that will write and flush the logger - */ - static stream s(enum level level = info); + /** + * @brief get the stream interface of the logger + * @return return a temporary object that will write and flush the logger + */ + static stream s(enum level level = info); - inline static stream d() { return s(debug::info); } - inline static stream e() { return s(debug::error); } - inline static stream w() { return s(debug::warning); } + inline static stream d() { return s(debug::info); } + inline static stream e() { return s(debug::error); } + inline static stream w() { return s(debug::warning); } - /** - * @brief returns the instance of the logger - * @return - */ - static debug& get(); + /** + * @brief returns the instance of the logger + * @return + */ + static debug& get(); - /** - * @brief write a message to the log - * @param message string - */ - void write(const std::string &message); + /** + * @brief write a message to the log + * @param message string + */ + void write(const std::string &message); - typedef std::function Callback; - typedef std::vector CallbackList; + typedef std::function Callback; + typedef std::vector CallbackList; - ~debug(); + ~debug(); protected: - debug(); + debug(); - CallbackList _callbacks; - enum level _level; + CallbackList _callbacks; + enum level _level; }; ///** diff --git a/src/core/include/pw/core/point.hpp b/src/core/include/pw/core/point.hpp index d9e628e..62c49e8 100644 --- a/src/core/include/pw/core/point.hpp +++ b/src/core/include/pw/core/point.hpp @@ -1,5 +1,5 @@ #ifndef PW_CORE_POINT_HPP -#define PW_CORE_SIZE_HPP +#define PW_CORE_POINT_HPP #include @@ -8,13 +8,10 @@ namespace pw { template struct point_ { - T_ p[2] = { 0, 0 }; + T_ x, y; point_() = default; - point_(T_ x,T_ y) : p( {x,y} ) {} - - const T_ x() { return p[0]; } - const T_ y() { return p[1]; } + point_(T_ x_,T_ y_) : x(x_), y(y_) {} }; diff --git a/src/core/include/pw/core/size.hpp b/src/core/include/pw/core/size.hpp index 465ecf6..1e0dfa3 100644 --- a/src/core/include/pw/core/size.hpp +++ b/src/core/include/pw/core/size.hpp @@ -33,14 +33,11 @@ namespace pw { template struct size_ { - T_ dim[2] = { 0, 0 }; + T_ width,height; size_() = default; - size_(T_ w,T_ h) : dim( { w, h }) {} - - const T_ width() { return dim[0]; } - const T_ height() { return dim[1]; } + size_(T_ w,T_ h) : width(w), height(h) {} }; diff --git a/src/core/include/pw/core/vector.hpp b/src/core/include/pw/core/vector.hpp index a95dd38..400b1f9 100644 --- a/src/core/include/pw/core/vector.hpp +++ b/src/core/include/pw/core/vector.hpp @@ -192,16 +192,16 @@ typedef vector2_ vector2l; typedef vector2_ vector2d; typedef vector2_ vector2f; +typedef vector2_ vector2; - - - +typedef vector3_ vector3; typedef vector3_ vector3d; typedef vector3_ vector3f; typedef vector3_ vector3i; typedef vector3_ vector3ui; +typedef vector4_ vector4; typedef vector4_ vector4d; typedef vector4_ vector4f; typedef vector4_ vector4i; diff --git a/src/scripting/src/script_core.cpp b/src/scripting/src/script_core.cpp index cb4f6e2..d9c538a 100644 --- a/src/scripting/src/script_core.cpp +++ b/src/scripting/src/script_core.cpp @@ -4,6 +4,8 @@ #include "pw/core/quaternion.hpp" #include "pw/core/axisangle.hpp" #include "pw/core/debug.hpp" +#include "pw/core/size.hpp" +#include "pw/core/point.hpp" namespace pw { @@ -11,52 +13,69 @@ namespace pw { void script_core::load(sol::table &ns) { - typedef double Scalar; + typedef real_t Scalar; - ns.set("pi",pw::pi()); + ns.set("pi",pw::pi()); - ns.new_usertype("vector3", - sol::constructors(), - "set",&vector3d::set, - "x", scripting::property(scripting::resolve(&vector3d::x), &vector3d::set_x), - "y", scripting::property(scripting::resolve(&vector3d::y), &vector3d::set_y), - "z", scripting::property(scripting::resolve(&vector3d::z), &vector3d::set_z), - "norm",&vector3d::norm, - "cross",&vector3d::cross, - "dot",&vector3d::dot, - // sol::meta_function::addition, sol::resolve(::operator+), - // sol::meta_function::subtraction, &vector3d::operator- - // "v",&vector3d::values, - "clone",&vector3d::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",&quaterniond::set, - "x", scripting::property(scripting::resolve(&quaterniond::x), &quaterniond::set_x), - "y", scripting::property(scripting::resolve(&quaterniond::y), &quaterniond::set_y), - "z", scripting::property(scripting::resolve(&quaterniond::z), &quaterniond::set_z), - "w", scripting::property(scripting::resolve(&quaterniond::w), &quaterniond::set_w), - "dot",&quaterniond::dot, - "inverse",scripting::readonly_property(&quaterniond::inverse), - "normalized",&quaterniond::normalized, - "lerp",&quaterniond::lerp - // "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(&axisangled::axis,&axisangled::set_axis), - "angle",scripting::property(&axisangled::angle,&axisangled::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("debug", - "new",sol::no_constructor, - "get",&debug::get - ); + 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("debug", + "new",sol::no_constructor, + "get",&debug::get, + "write",&debug::write + // "none",sol::debug::level::none + ); } diff --git a/src/scripting/src/script_system.cpp b/src/scripting/src/script_system.cpp index 8ccf627..3ca4c4a 100644 --- a/src/scripting/src/script_system.cpp +++ b/src/scripting/src/script_system.cpp @@ -8,16 +8,16 @@ namespace pw { void script_system::load(sol::table &ns) { - ns.new_usertype("window", - "update",&window::update, - "title",sol::writeonly_property(&window::set_title), - "set_size",&window::set_size - ); + ns.new_usertype("window", + "update",&window::update, + "title",sol::writeonly_property(&window::set_title), + "size",sol::property(&window::size,&window::set_size) + ); -// ns.new_usertype("input", -// "new", sol::no_constructor, -// "get",&input::get -// ); + ns.new_usertype("input", + "new", sol::no_constructor, + "get",&input::get + ); } diff --git a/src/scripts/demos/simple_000.lua b/src/scripts/demos/simple_000.lua index ad1348d..96f7310 100644 --- a/src/scripts/demos/simple_000.lua +++ b/src/scripts/demos/simple_000.lua @@ -67,9 +67,12 @@ end local w = pw.window.new() -w.title = "pixwerx 1.0" +-- set title +w.title = "pixwerx 0.1" + +-- set size +w.size = pw.size.new(1200,800) -w:set_size(1280,768) while w:update() do diff --git a/src/system/include/pw/system/input.hpp b/src/system/include/pw/system/input.hpp index d9e63b6..f5fa55c 100644 --- a/src/system/include/pw/system/input.hpp +++ b/src/system/include/pw/system/input.hpp @@ -13,12 +13,13 @@ public: point mouse_position() const { return _mouse_position; } + ~input() = default; + protected: friend class window; input(); - ~input() = default; private: diff --git a/src/system/include/pw/system/window.hpp b/src/system/include/pw/system/window.hpp index 6c254d9..577c10a 100644 --- a/src/system/include/pw/system/window.hpp +++ b/src/system/include/pw/system/window.hpp @@ -16,12 +16,11 @@ public: void set_title(const std::string& title); - void set_size(int w, int h); - size get_size() const; + void set_size(const size& s); + size size() const; typedef void drop_callback; - protected: struct impl; diff --git a/src/system/src/window.cpp b/src/system/src/window.cpp index a82b014..f748880 100644 --- a/src/system/src/window.cpp +++ b/src/system/src/window.cpp @@ -178,12 +178,12 @@ void window::set_title(const std::string& title) _impl->set_title(title); } -void window::set_size(int w,int h) +void window::set_size(const ::pw::size& s) { - _impl->set_size(w,h); + _impl->set_size(s.width,s.height); } -size window::get_size() const +size window::size() const { return _impl->size(); }