sync to keep working

This commit is contained in:
Hartmut Seichter 2019-01-14 21:48:16 +01:00
parent 236cdd5ef7
commit e267a0d2ed
12 changed files with 154 additions and 89 deletions

View file

@ -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

View file

@ -23,7 +23,6 @@
#ifndef PW_CORE_TIMER_HPP_
#define PW_CORE_TIMER_HPP_
#include <pw/core/globals.hpp>
#include <chrono>
@ -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<std::chrono::high_resolution_clock> 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:

View file

@ -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<double> 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();
}
}

View file

@ -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<Scalar>());
ns.set("pi",pw::pi<Scalar>());
ns.new_usertype<vector3>("vector3",
sol::constructors<vector3(), vector3(Scalar,Scalar,Scalar)>(),
"set",&vector3::set,
"x", scripting::property(scripting::resolve<const Scalar&() const>(&vector3::x), &vector3::set_x),
"y", scripting::property(scripting::resolve<const Scalar&() const>(&vector3::y), &vector3::set_y),
"z", scripting::property(scripting::resolve<const Scalar&() const>(&vector3::z), &vector3::set_z),
"norm",&vector3::norm,
"cross",&vector3::cross,
"dot",&vector3::dot,
// sol::meta_function::addition, sol::resolve<vector3(const vector3&, const vector3&)>(::operator+),
// sol::meta_function::subtraction, &vector3::operator-
// "v",&vector3::values,
"clone",&vector3::clone
);
ns.new_usertype<vector3>("vector3",
sol::constructors<vector3(), vector3(Scalar,Scalar,Scalar)>(),
"set",&vector3::set,
"x", scripting::property(scripting::resolve<const Scalar&() const>(&vector3::x), &vector3::set_x),
"y", scripting::property(scripting::resolve<const Scalar&() const>(&vector3::y), &vector3::set_y),
"z", scripting::property(scripting::resolve<const Scalar&() const>(&vector3::z), &vector3::set_z),
"norm",&vector3::norm,
"cross",&vector3::cross,
"dot",&vector3::dot,
// sol::meta_function::addition, sol::resolve<vector3(const vector3&, const vector3&)>(::operator+),
// sol::meta_function::subtraction, &vector3::operator-
// "v",&vector3::values,
"clone",&vector3::clone
);
ns.new_usertype<quaternion>("quaternion",
sol::constructors<quaternion(), quaternion(Scalar,Scalar,Scalar,Scalar)>(),
"set",&quaternion::set,
"x", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::x), &quaternion::set_x),
"y", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::y), &quaternion::set_y),
"z", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::z), &quaternion::set_z),
"w", scripting::property(scripting::resolve<const Scalar&() const>(&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>("quaternion",
sol::constructors<quaternion(), quaternion(Scalar,Scalar,Scalar,Scalar)>(),
"set",&quaternion::set,
"x", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::x), &quaternion::set_x),
"y", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::y), &quaternion::set_y),
"z", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::z), &quaternion::set_z),
"w", scripting::property(scripting::resolve<const Scalar&() const>(&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>("axisangle",
sol::constructors<axisangle(), axisangle(vector3,Scalar)>(),
"axis",scripting::property(&axisangle::axis,&axisangle::set_axis),
"angle",scripting::property(&axisangle::angle,&axisangle::set_angle)
);
ns.new_usertype<axisangle>("axisangle",
sol::constructors<axisangle(), axisangle(vector3,Scalar)>(),
"axis",scripting::property(&axisangle::axis,&axisangle::set_axis),
"angle",scripting::property(&axisangle::angle,&axisangle::set_angle)
);
ns.new_usertype<size>("size",
sol::constructors<size(),size(Scalar,Scalar)>(),
"width",&size::width,
"height",&size::height
// "none",sol::debug::level::none
);
ns.new_usertype<size>("size",
sol::constructors<size(),size(Scalar,Scalar)>(),
"width",&size::width,
"height",&size::height
// "none",sol::debug::level::none
);
ns.new_usertype<point>("point",
sol::constructors<point(),point(Scalar,Scalar)>(),
"x",&point::x,
"y",&point::y
);
ns.new_usertype<point>("point",
sol::constructors<point(),point(Scalar,Scalar)>(),
"x",&point::x,
"y",&point::y
);
ns.new_usertype<debug>("debug",
"new",sol::no_constructor,
"get",&debug::get,
"write",&debug::write
// "none",sol::debug::level::none
);
ns.new_usertype<debug>("debug",
"new",sol::no_constructor,
"get",&debug::get,
"write",&debug::write
// "none",sol::debug::level::none
);
ns.new_usertype<timer>("timer",
"now",sol::readonly_property(&timer::now),
"elapsed",sol::readonly_property(&timer::elapsed),
"reset",&timer::reset
);
}

View file

@ -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>("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>("pipeline",
"create",&pipeline::create
);
// ns.set_function("my_class_func_2", &my_class::func);
//
// // hijack part
// //
// ns.new_usertype<pipeline>("pipeline",
// "create",&pipeline::create
// );
}
}

View file

@ -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

View file

@ -5,11 +5,15 @@
#include <pw/core/size.hpp>
#include <pw/core/point.hpp>
#include <functional>
namespace pw {
class window {
public:
typedef std::function<void(window&)> 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> _impl;

View file

@ -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<window::impl>())
: _impl(std::make_unique<window::impl>(*this))
, _on_update([](window&){})
{
}

View file

@ -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;

View file

@ -13,7 +13,7 @@ class pipeline {
public:
pipeline();
~pipeline() = default;
~pipeline();
void draw();

View file

@ -99,6 +99,11 @@ pipeline::pipeline()
{
}
pipeline::~pipeline()
{
//
}
bool pipeline::create(size s)
{
return _impl->create(sizei(s.width,s.height));