renamed logger into debug and start of piping through the GLFW input system to the script system

This commit is contained in:
Hartmut Seichter 2019-01-09 11:34:19 +01:00
parent 24154087ba
commit b8f5681131
9 changed files with 193 additions and 169 deletions

View file

@ -1,6 +1,6 @@
set(hdrs set(hdrs
include/pw/core/log.hpp include/pw/core/debug.hpp
include/pw/core/axisangle.hpp include/pw/core/axisangle.hpp
include/pw/core/core.hpp include/pw/core/core.hpp
include/pw/core/math.hpp include/pw/core/math.hpp
@ -17,7 +17,7 @@ set(hdrs
set(srcs set(srcs
src/image.cpp src/image.cpp
src/log.cpp src/debug.cpp
src/core.cpp src/core.cpp
src/serialize.cpp src/serialize.cpp
src/timer.cpp src/timer.cpp

View file

@ -33,48 +33,13 @@
namespace pw { namespace pw {
class Log;
/**
* @brief the streaming interface for the logger
*/
class LogStream {
public:
LogStream(Log* log = nullptr);
~LogStream();
LogStream(const LogStream& other);
LogStream &operator << (const bool &value);
LogStream &operator << (const char *value);
LogStream& operator << (const std::string& value); ///! log a string
LogStream& operator << (const float &value); ///! log a float value
LogStream& operator << (const double &value); ///! log a double value
LogStream& operator << (const int &value); ///! log a int value
LogStream& operator << (const unsigned int &value); ///! log a int value
LogStream& operator << (const long &value); ///! log a long value
LogStream& operator << (const unsigned long &value); ///! log a int value
LogStream& operator << (const void *value); ///! pointer
protected:
Log* _log;
std::string _line;
};
/** /**
* @brief multipurpose logger used internally * @brief multipurpose logger used internally
*/ */
class Log { class debug {
public: public:
enum LogLevel { enum level {
kNone, //!< nothing will be logged, even no errors kNone, //!< nothing will be logged, even no errors
kError, //!< only errors will be logged kError, //!< only errors will be logged
kWarning, //!< log warnings (non-critical errors) kWarning, //!< log warnings (non-critical errors)
@ -84,28 +49,62 @@ public:
kAll = 0xFF //!< log absolutely everything kAll = 0xFF //!< log absolutely everything
}; };
/**
* @brief the streaming interface for the logger
*/
class stream {
public:
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 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 long &value); ///! log a long value
stream& operator << (const unsigned long &value); ///! log a int value
stream& operator << (const void *value); ///! pointer
protected:
debug* _log;
std::string _line;
};
/** sets the logging level */ /** sets the logging level */
void setLevel(LogLevel level) {_level = level;} void set_level(level level) {_level = level;}
/** gets the logging level */ /** gets the logging level */
LogLevel level() const { return _level; } level level() const { return _level; }
/** /**
* @brief get the stream interface of the logger * @brief get the stream interface of the logger
* @return return a temporary object that will write and flush the logger * @return return a temporary object that will write and flush the logger
*/ */
static LogStream s(LogLevel level = kInfo); static stream s(enum level level = kInfo);
inline static LogStream d() { return s(Log::kInfo); } inline static stream d() { return s(debug::kInfo); }
inline static LogStream e() { return s(Log::kError); } inline static stream e() { return s(debug::kError); }
inline static LogStream w() { return s(Log::kWarning); } inline static stream w() { return s(debug::kWarning); }
/** /**
* @brief returns the instance of the logger * @brief returns the instance of the logger
* @return * @return
*/ */
static Log& get(); static debug& get();
/** /**
* @brief write a message to the log * @brief write a message to the log
@ -118,46 +117,46 @@ public:
protected: protected:
Log(); debug();
~Log(); ~debug();
CallbackList _callbacks; CallbackList _callbacks;
LogLevel _level; enum level _level;
}; };
/** ///**
* @brief helper for changing the log level in a scope // * @brief helper for changing the log level in a scope
*/ // */
struct ScopeLogLevel //struct ScopeLogLevel
{ //{
Log::LogLevel levelOutside; // debug::level levelOutside;
explicit ScopeLogLevel(Log::LogLevel level) // explicit ScopeLogLevel(debug::level level)
{ // {
levelOutside = Log::get().level(); // levelOutside = debug::get().level();
Log::get().setLevel(level); // debug::get().setLevel(level);
} // }
~ScopeLogLevel() // ~ScopeLogLevel()
{ // {
Log::get().setLevel(levelOutside); // debug::get().setLevel(levelOutside);
} // }
}; //};
template <Log::LogLevel level> //template <debug::level level>
struct tpScopeLog { //struct tpScopeLog {
const char* info; // const char* info;
explicit tpScopeLog(const char* i) : info(i) { // explicit tpScopeLog(const char* i) : info(i) {
Log::s(level) << info; // debug::s(level) << info;
} // }
~tpScopeLog() { // ~tpScopeLog() {
Log::s(level) << info; // debug::s(level) << info;
} // }
}; //};
// some macros // some macros
#define LOG_INFO() Log::s() //#define LOG_INFO() Log::s()
#define LOG_FUNC() LOG_INFO() << __FUNCTION__ << " " << __LINE__ << " " //#define LOG_FUNC() LOG_INFO() << __FUNCTION__ << " " << __LINE__ << " "
} }

View file

@ -46,6 +46,7 @@ typedef size_<real_t> size;
typedef size_<int> sizei; typedef size_<int> sizei;
typedef size_<float> sizef; typedef size_<float> sizef;
typedef size_<float> sized;
} }

View file

@ -4,7 +4,7 @@
* *
* (c) Copyrights 2007-2018 Hartmut Seichter * (c) Copyrights 2007-2018 Hartmut Seichter
*/ */
#include "pw/core/log.hpp" #include "pw/core/debug.hpp"
#include <cstdarg> #include <cstdarg>
#include <cstdio> #include <cstdio>
@ -59,8 +59,8 @@ struct tpFileLog {
Log::Log() : debug::debug() :
_level(Log::kNotify) _level(debug::kNotify)
{ {
#if defined(_WINCE) #if defined(_WINCE)
_callbacks.add(new tpFileLog()); _callbacks.add(new tpFileLog());
@ -68,17 +68,17 @@ Log::Log() :
_callbacks.push_back(tpConsoleLog()); _callbacks.push_back(tpConsoleLog());
#endif #endif
// drop some info // drop some info
LogStream stream(this); stream stream(this);
// stream << "SSTT " << versionString(kVersionFull) << " " << std::thread::hardware_concurrency() << " threads"; // stream << "SSTT " << versionString(kVersionFull) << " " << std::thread::hardware_concurrency() << " threads";
} }
Log::~Log() debug::~debug()
{ {
} }
void Log::write(const std::string& message) void debug::write(const std::string& message)
{ {
for (CallbackList::iterator i = _callbacks.begin(); for (CallbackList::iterator i = _callbacks.begin();
i != _callbacks.end(); i != _callbacks.end();
@ -90,12 +90,13 @@ void Log::write(const std::string& message)
/* static */ /* static */
LogStream Log::s(Log::LogLevel level) { debug::stream debug::s(enum debug::level level)
return LogStream(&Log::get()); {
return stream(&debug::get());
} }
Log &Log::get() { debug &debug::get() {
static Log the_log; static debug the_log;
return the_log; return the_log;
} }
@ -104,42 +105,42 @@ Log &Log::get() {
// tpLogStream // tpLogStream
// //
LogStream::LogStream(Log *log) debug::stream::stream(debug *log)
: _log(log) : _log(log)
{ {
// _line.append(std::to_string(Timer::now(Timer::UnitSeconds)) + " "); // _line.append(std::to_string(Timer::now(Timer::UnitSeconds)) + " ");
} }
LogStream::~LogStream() debug::stream::~stream()
{ {
_log->write(_line + "\n"); _log->write(_line + "\n");
} }
LogStream::LogStream(const LogStream &other) debug::stream::stream(const stream &other)
: _log(other._log) : _log(other._log)
, _line(other._line) , _line(other._line)
{ {
} }
LogStream &LogStream::operator <<(const bool &value) debug::stream &debug::stream::operator <<(const bool &value)
{ {
_line.append(value ? "true" : "false"); _line.append(value ? "true" : "false");
return *this; return *this;
} }
LogStream &LogStream::operator <<(const char* value) debug::stream &debug::stream::operator <<(const char* value)
{ {
_line.append(value); _line.append(value);
return *this; return *this;
} }
LogStream &LogStream::operator <<(const std::string &value) debug::stream &debug::stream::operator <<(const std::string &value)
{ {
_line.append(value); _line.append(value);
return *this; return *this;
} }
LogStream &LogStream::operator <<(const float &value) debug::stream &debug::stream::operator <<(const float &value)
{ {
std::stringstream ss; std::stringstream ss;
ss << value; ss << value;
@ -148,7 +149,7 @@ LogStream &LogStream::operator <<(const float &value)
return *this; return *this;
} }
LogStream &LogStream::operator <<(const double &value) debug::stream &debug::stream::operator <<(const double &value)
{ {
std::stringstream ss; std::stringstream ss;
ss << value; ss << value;
@ -157,7 +158,7 @@ LogStream &LogStream::operator <<(const double &value)
return *this; return *this;
} }
LogStream &LogStream::operator <<(const int &value) debug::stream &debug::stream::operator <<(const int &value)
{ {
std::stringstream ss; std::stringstream ss;
ss << value; ss << value;
@ -166,7 +167,7 @@ LogStream &LogStream::operator <<(const int &value)
return *this; return *this;
} }
LogStream &LogStream::operator <<(const unsigned int &value) debug::stream &debug::stream::operator <<(const unsigned int &value)
{ {
std::stringstream ss; std::stringstream ss;
ss << value; ss << value;
@ -175,7 +176,7 @@ LogStream &LogStream::operator <<(const unsigned int &value)
return *this; return *this;
} }
LogStream &LogStream::operator <<(const long &value) debug::stream &debug::stream::operator <<(const long &value)
{ {
std::stringstream ss; std::stringstream ss;
ss << value; ss << value;
@ -184,7 +185,7 @@ LogStream &LogStream::operator <<(const long &value)
return *this; return *this;
} }
LogStream &LogStream::operator <<(const unsigned long &value) debug::stream &debug::stream::operator <<(const unsigned long &value)
{ {
std::stringstream ss; std::stringstream ss;
ss << value; ss << value;
@ -193,7 +194,7 @@ LogStream &LogStream::operator <<(const unsigned long &value)
return *this; return *this;
} }
LogStream &LogStream::operator <<(const void *value) debug::stream &debug::stream::operator <<(const void *value)
{ {
std::stringstream ss; std::stringstream ss;
ss << value; ss << value;

View file

@ -10,46 +10,46 @@ namespace pw {
void script_core::load(sol::table &ns) void script_core::load(sol::table &ns)
{ {
typedef double Scalar; typedef double Scalar;
ns.set("pi",pw::pi<Scalar>()); ns.set("pi",pw::pi<Scalar>());
ns.new_usertype<vector3d>("vector3", ns.new_usertype<vector3d>("vector3",
sol::constructors<vector3d(), vector3d(Scalar,Scalar,Scalar)>(), sol::constructors<vector3d(), vector3d(Scalar,Scalar,Scalar)>(),
"set",&vector3d::set, "set",&vector3d::set,
"x", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::x), &vector3d::set_x), "x", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::x), &vector3d::set_x),
"y", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::y), &vector3d::set_y), "y", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::y), &vector3d::set_y),
"z", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::z), &vector3d::set_z), "z", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::z), &vector3d::set_z),
"norm",&vector3d::norm, "norm",&vector3d::norm,
"cross",&vector3d::cross, "cross",&vector3d::cross,
"dot",&vector3d::dot, "dot",&vector3d::dot,
// sol::meta_function::addition, sol::resolve<vector3d(const vector3d&, const vector3d&)>(::operator+), // sol::meta_function::addition, sol::resolve<vector3d(const vector3d&, const vector3d&)>(::operator+),
// sol::meta_function::subtraction, &vector3d::operator- // sol::meta_function::subtraction, &vector3d::operator-
// "v",&vector3d::values, // "v",&vector3d::values,
"clone",&vector3d::clone "clone",&vector3d::clone
); );
ns.new_usertype<quaterniond>("quaternion", ns.new_usertype<quaterniond>("quaternion",
sol::constructors<quaterniond(), quaterniond(Scalar,Scalar,Scalar,Scalar)>(), sol::constructors<quaterniond(), quaterniond(Scalar,Scalar,Scalar,Scalar)>(),
"set",&quaterniond::set, "set",&quaterniond::set,
"x", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::x), &quaterniond::set_x), "x", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::x), &quaterniond::set_x),
"y", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::y), &quaterniond::set_y), "y", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::y), &quaterniond::set_y),
"z", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::z), &quaterniond::set_z), "z", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::z), &quaterniond::set_z),
"w", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::w), &quaterniond::set_w), "w", scripting::property(scripting::resolve<const Scalar&() const>(&quaterniond::w), &quaterniond::set_w),
"dot",&quaterniond::dot, "dot",&quaterniond::dot,
"inverse",scripting::readonly_property(&quaterniond::inverse), "inverse",scripting::readonly_property(&quaterniond::inverse),
"normalized",&quaterniond::normalized, "normalized",&quaterniond::normalized,
"lerp",&quaterniond::lerp "lerp",&quaterniond::lerp
// "v",&vector3d::values, // "v",&vector3d::values,
// "clone",&vector3d::clone // "clone",&vector3d::clone
); );
ns.new_usertype<axisangled>("axisangle", ns.new_usertype<axisangled>("axisangle",
sol::constructors<axisangled(), axisangled(vector3d,Scalar)>(), sol::constructors<axisangled(), axisangled(vector3d,Scalar)>(),
"axis",scripting::property(&axisangled::axis,&axisangled::set_axis), "axis",scripting::property(&axisangled::axis,&axisangled::set_axis),
"angle",scripting::property(&axisangled::angle,&axisangled::set_angle) "angle",scripting::property(&axisangled::angle,&axisangled::set_angle)
); );
} }

View file

@ -1,16 +1,24 @@
#include "script_system.hpp" #include "script_system.hpp"
#include "pw/system/window.hpp" #include "pw/system/window.hpp"
#include "pw/system/input.hpp"
namespace pw { namespace pw {
void script_system::load(sol::table &ns) void script_system::load(sol::table &ns)
{ {
ns.new_usertype<window>("window", ns.new_usertype<window>("window",
"update",&window::update, "update",&window::update,
"title",sol::writeonly_property(&window::set_title), "title",sol::writeonly_property(&window::set_title),
"set_size",&window::set_size "set_size",&window::set_size
); );
// ns.new_usertype<input>("input",
// "new", sol::no_constructor,
// "get",&input::get
// );
} }
} }

View file

@ -1,23 +1,25 @@
set(hdrs set(hdrs
include/pw/system/window.hpp include/pw/system/window.hpp
) include/pw/system/input.hpp
)
set(srcs set(srcs
src/window.cpp src/window.cpp
) src/input.cpp
)
add_library(pwsystem add_library(pwsystem
STATIC STATIC
${hdrs} ${hdrs}
${srcs} ${srcs}
) )
target_include_directories( target_include_directories(
pwsystem pwsystem
PUBLIC PUBLIC
include include
) )
target_link_libraries(pwsystem pwcore pwvisual glfw glad) target_link_libraries(pwsystem pwcore pwvisual glfw glad)

View file

@ -1,7 +1,8 @@
#ifndef PW_WINDOW_HPP #ifndef PW_SYSTEM_WINDOW_HPP
#define PW_WINDOW_HPP #define PW_SYSTEM_WINDOW_HPP
#include <pw/core/globals.hpp> #include <pw/core/globals.hpp>
#include <pw/core/size.hpp>
namespace pw { namespace pw {
@ -14,12 +15,12 @@ public:
bool update(); bool update();
void set_title(const std::string& title); void set_title(const std::string& title);
void set_size(int w, int h); void set_size(int w, int h);
size get_size() const;
// context* get_context(); typedef void drop_callback;
int get_heigth();
int get_width();
protected: protected:

View file

@ -4,6 +4,7 @@
//#include "glad/glad.h" //#include "glad/glad.h"
#include "pw/visual/context.hpp" #include "pw/visual/context.hpp"
#include "pw/system/input.hpp"
#include <iostream> #include <iostream>
@ -34,10 +35,18 @@ struct window::impl {
// window_context _context; // window_context _context;
static void key_callback(GLFWwindow *window,int key, int scancode, int action, int mods)
{
}
static void framebuffer_size_callback(GLFWwindow* window, int width, int height) static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{ {
window::impl* impl = static_cast<window::impl*>(glfwGetWindowUserPointer(window)); window::impl* impl = static_cast<window::impl*>(glfwGetWindowUserPointer(window));
// impl->on_resize(width,height); // impl->on_resize(width,height);
// std::cout << "framebuffer " << width << "x" << height << std::endl; // std::cout << "framebuffer " << width << "x" << height << std::endl;
// glViewport(0, 0, width, height); // glViewport(0, 0, width, height);
@ -50,7 +59,9 @@ struct window::impl {
_window = glfwCreateWindow(640, 480, "pixwerxs", nullptr, nullptr); _window = glfwCreateWindow(640, 480, "pixwerxs", nullptr, nullptr);
glfwSetWindowUserPointer(_window,this); glfwSetWindowUserPointer(_window,this);
glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback); glfwSetFramebufferSizeCallback(_window, window::impl::framebuffer_size_callback);
glfwSetKeyCallback(_window, window::impl::key_callback);
#if 0 #if 0
@ -70,6 +81,7 @@ struct window::impl {
{ {
if (!glfwWindowShouldClose(_window)) { if (!glfwWindowShouldClose(_window)) {
glfwPollEvents(); glfwPollEvents();
// do other stuff // do other stuff
@ -97,6 +109,14 @@ struct window::impl {
glfwSetWindowSize(_window,w,h); glfwSetWindowSize(_window,w,h);
} }
::pw::size size() const {
int w,h;
glfwGetWindowSize(_window,&w,&h);
return ::pw::size(w,h);
}
}; };
@ -125,19 +145,11 @@ void window::set_size(int w,int h)
_impl->set_size(w,h); _impl->set_size(w,h);
} }
int window::get_width() size window::get_size() const
{ {
// int w,h; return _impl->size();
// glfwGetWindowSize(_window,&w,&h);
// return w;
}
int window::get_heigth()
{
// int w,h;
// glfwGetWindowSize(_window,&w,&h);
// return h;
} }
} }