sync to keep working
This commit is contained in:
parent
236cdd5ef7
commit
e267a0d2ed
12 changed files with 154 additions and 89 deletions
|
@ -5,9 +5,26 @@ cmake_minimum_required(VERSION 3.8)
|
||||||
|
|
||||||
project(pixwerx)
|
project(pixwerx)
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/etc/cmake")
|
#
|
||||||
|
# pixwerx ist C++17
|
||||||
|
#
|
||||||
set (CMAKE_CXX_STANDARD 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(src)
|
||||||
add_subdirectory(share)
|
add_subdirectory(share)
|
||||||
|
|
|
@ -11,18 +11,18 @@ set(hdrs
|
||||||
include/pw/core/serialize.hpp
|
include/pw/core/serialize.hpp
|
||||||
include/pw/core/image.hpp
|
include/pw/core/image.hpp
|
||||||
include/pw/core/point.hpp
|
include/pw/core/point.hpp
|
||||||
include/pw/core/rect.hpp
|
include/pw/core/rect.hpp
|
||||||
include/pw/core/size.hpp
|
include/pw/core/size.hpp
|
||||||
include/pw/core/timer.hpp
|
include/pw/core/timer.hpp
|
||||||
include/pw/core/mesh.hpp
|
include/pw/core/mesh.hpp
|
||||||
include/pw/core/globals.hpp
|
include/pw/core/globals.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(srcs
|
set(srcs
|
||||||
src/buffer.cpp
|
src/buffer.cpp
|
||||||
src/image.cpp
|
src/image.cpp
|
||||||
src/debug.cpp
|
src/debug.cpp
|
||||||
src/mesh.cpp
|
src/mesh.cpp
|
||||||
src/core.cpp
|
src/core.cpp
|
||||||
src/serialize.cpp
|
src/serialize.cpp
|
||||||
src/timer.cpp
|
src/timer.cpp
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#ifndef PW_CORE_TIMER_HPP_
|
#ifndef PW_CORE_TIMER_HPP_
|
||||||
#define PW_CORE_TIMER_HPP_
|
#define PW_CORE_TIMER_HPP_
|
||||||
|
|
||||||
|
|
||||||
#include <pw/core/globals.hpp>
|
#include <pw/core/globals.hpp>
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
@ -36,10 +35,6 @@ namespace pw {
|
||||||
class timer {
|
class timer {
|
||||||
public:
|
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;
|
typedef std::chrono::time_point<std::chrono::high_resolution_clock> tick_t;
|
||||||
|
|
||||||
timer(); /// c'tor
|
timer(); /// c'tor
|
||||||
|
@ -49,17 +44,15 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief elapsed time based on the scale
|
* @brief elapsed time based on the scale
|
||||||
* @param scale units the time will be reported
|
|
||||||
* @return value of the time since last @see reset
|
* @return value of the time since last @see reset
|
||||||
*/
|
*/
|
||||||
double elapsed(unsigned int scale = UnitMilliSeconds) const;
|
double elapsed() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Now
|
* @brief time from start of core in seconds
|
||||||
* @param scale
|
* @return time in seconds
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
static double now(unsigned int scale = UnitMicroSeconds);
|
static double now();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
|
@ -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"
|
#include "pw/core/timer.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
static timer global_timer;
|
static timer global_timer;
|
||||||
|
@ -26,15 +40,15 @@ void timer::reset()
|
||||||
_start = std::chrono::high_resolution_clock::now();
|
_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;
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "pw/core/debug.hpp"
|
#include "pw/core/debug.hpp"
|
||||||
#include "pw/core/size.hpp"
|
#include "pw/core/size.hpp"
|
||||||
#include "pw/core/point.hpp"
|
#include "pw/core/point.hpp"
|
||||||
|
#include "pw/core/timer.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
@ -13,69 +14,76 @@ namespace pw {
|
||||||
void script_core::load(sol::table &ns)
|
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",
|
ns.new_usertype<vector3>("vector3",
|
||||||
sol::constructors<vector3(), vector3(Scalar,Scalar,Scalar)>(),
|
sol::constructors<vector3(), vector3(Scalar,Scalar,Scalar)>(),
|
||||||
"set",&vector3::set,
|
"set",&vector3::set,
|
||||||
"x", scripting::property(scripting::resolve<const Scalar&() const>(&vector3::x), &vector3::set_x),
|
"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),
|
"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),
|
"z", scripting::property(scripting::resolve<const Scalar&() const>(&vector3::z), &vector3::set_z),
|
||||||
"norm",&vector3::norm,
|
"norm",&vector3::norm,
|
||||||
"cross",&vector3::cross,
|
"cross",&vector3::cross,
|
||||||
"dot",&vector3::dot,
|
"dot",&vector3::dot,
|
||||||
// sol::meta_function::addition, sol::resolve<vector3(const vector3&, const vector3&)>(::operator+),
|
// sol::meta_function::addition, sol::resolve<vector3(const vector3&, const vector3&)>(::operator+),
|
||||||
// sol::meta_function::subtraction, &vector3::operator-
|
// sol::meta_function::subtraction, &vector3::operator-
|
||||||
// "v",&vector3::values,
|
// "v",&vector3::values,
|
||||||
"clone",&vector3::clone
|
"clone",&vector3::clone
|
||||||
);
|
);
|
||||||
|
|
||||||
ns.new_usertype<quaternion>("quaternion",
|
ns.new_usertype<quaternion>("quaternion",
|
||||||
sol::constructors<quaternion(), quaternion(Scalar,Scalar,Scalar,Scalar)>(),
|
sol::constructors<quaternion(), quaternion(Scalar,Scalar,Scalar,Scalar)>(),
|
||||||
"set",&quaternion::set,
|
"set",&quaternion::set,
|
||||||
"x", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::x), &quaternion::set_x),
|
"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),
|
"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),
|
"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),
|
"w", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::w), &quaternion::set_w),
|
||||||
"dot",&quaternion::dot,
|
"dot",&quaternion::dot,
|
||||||
"inverse",scripting::readonly_property(&quaternion::inverse),
|
"inverse",scripting::readonly_property(&quaternion::inverse),
|
||||||
"normalized",&quaternion::normalized,
|
"normalized",&quaternion::normalized,
|
||||||
"lerp",&quaternion::lerp,
|
"lerp",&quaternion::lerp,
|
||||||
"slerp",&quaternion::slerp
|
"slerp",&quaternion::slerp
|
||||||
// "v",&vector3d::values,
|
// "v",&vector3d::values,
|
||||||
// "clone",&vector3d::clone
|
// "clone",&vector3d::clone
|
||||||
);
|
);
|
||||||
|
|
||||||
ns.new_usertype<axisangle>("axisangle",
|
ns.new_usertype<axisangle>("axisangle",
|
||||||
sol::constructors<axisangle(), axisangle(vector3,Scalar)>(),
|
sol::constructors<axisangle(), axisangle(vector3,Scalar)>(),
|
||||||
"axis",scripting::property(&axisangle::axis,&axisangle::set_axis),
|
"axis",scripting::property(&axisangle::axis,&axisangle::set_axis),
|
||||||
"angle",scripting::property(&axisangle::angle,&axisangle::set_angle)
|
"angle",scripting::property(&axisangle::angle,&axisangle::set_angle)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
ns.new_usertype<size>("size",
|
ns.new_usertype<size>("size",
|
||||||
sol::constructors<size(),size(Scalar,Scalar)>(),
|
sol::constructors<size(),size(Scalar,Scalar)>(),
|
||||||
"width",&size::width,
|
"width",&size::width,
|
||||||
"height",&size::height
|
"height",&size::height
|
||||||
// "none",sol::debug::level::none
|
// "none",sol::debug::level::none
|
||||||
);
|
);
|
||||||
|
|
||||||
ns.new_usertype<point>("point",
|
ns.new_usertype<point>("point",
|
||||||
sol::constructors<point(),point(Scalar,Scalar)>(),
|
sol::constructors<point(),point(Scalar,Scalar)>(),
|
||||||
"x",&point::x,
|
"x",&point::x,
|
||||||
"y",&point::y
|
"y",&point::y
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
ns.new_usertype<debug>("debug",
|
ns.new_usertype<debug>("debug",
|
||||||
"new",sol::no_constructor,
|
"new",sol::no_constructor,
|
||||||
"get",&debug::get,
|
"get",&debug::get,
|
||||||
"write",&debug::write
|
"write",&debug::write
|
||||||
// "none",sol::debug::level::none
|
// "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
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "pw/system/display.hpp"
|
#include "pw/system/display.hpp"
|
||||||
|
|
||||||
// hijacking
|
// hijacking
|
||||||
#include "pw/visual/pipeline.hpp"
|
//#include "pw/visual/pipeline.hpp"
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ void script_system::load(sol::table &ns)
|
||||||
{
|
{
|
||||||
ns.new_usertype<window>("window",
|
ns.new_usertype<window>("window",
|
||||||
"update",&window::update,
|
"update",&window::update,
|
||||||
|
"set_on_update",&window::set_on_update,
|
||||||
"title",sol::writeonly_property(&window::set_title),
|
"title",sol::writeonly_property(&window::set_title),
|
||||||
"size",sol::property(&window::size,&window::set_size),
|
"size",sol::property(&window::size,&window::set_size),
|
||||||
"position",sol::property(&window::position,&window::set_position),
|
"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)
|
"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
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,13 +71,17 @@ local w = pw.window.new()
|
||||||
w.title = "pixwerx 0.1"
|
w.title = "pixwerx 0.1"
|
||||||
|
|
||||||
-- set size
|
-- 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()
|
local ds = pw.display:all()
|
||||||
for i = 1,#ds do
|
for i = 1,#ds do
|
||||||
print("display ",i,ds[i].name)
|
print("display ",i,ds[i].name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local t = pw.timer.new()
|
||||||
|
|
||||||
while w:update()
|
while w:update()
|
||||||
do
|
do
|
||||||
-- somehow works
|
-- somehow works
|
||||||
|
@ -87,6 +91,8 @@ do
|
||||||
|
|
||||||
-- just to check
|
-- just to check
|
||||||
if (pw.input:get().mouse_button == 1) then
|
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)
|
print(pw.input:get().mouse_position.x,pw.input:get().mouse_position.y)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,15 @@
|
||||||
#include <pw/core/size.hpp>
|
#include <pw/core/size.hpp>
|
||||||
#include <pw/core/point.hpp>
|
#include <pw/core/point.hpp>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
class window {
|
class window {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef std::function<void(window&)> on_update_t;
|
||||||
|
|
||||||
window();
|
window();
|
||||||
~window();
|
~window();
|
||||||
|
|
||||||
|
@ -28,9 +32,12 @@ public:
|
||||||
bool fullscreen() const;
|
bool fullscreen() const;
|
||||||
void set_fullscreen(bool use_fullscreen);
|
void set_fullscreen(bool use_fullscreen);
|
||||||
|
|
||||||
|
void set_on_update(on_update_t f) { _on_update = f; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
on_update_t _on_update;
|
||||||
|
|
||||||
struct impl;
|
struct impl;
|
||||||
std::unique_ptr<impl> _impl;
|
std::unique_ptr<impl> _impl;
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,8 @@ namespace pw {
|
||||||
|
|
||||||
struct window::impl {
|
struct window::impl {
|
||||||
|
|
||||||
|
window& _parent;
|
||||||
|
|
||||||
GLFWwindow *_window = nullptr;
|
GLFWwindow *_window = nullptr;
|
||||||
|
|
||||||
sizei _old_size;
|
sizei _old_size;
|
||||||
|
@ -125,7 +127,8 @@ struct window::impl {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl()
|
impl(window& w)
|
||||||
|
: _parent(w)
|
||||||
{
|
{
|
||||||
// initialize
|
// initialize
|
||||||
glfwInit();
|
glfwInit();
|
||||||
|
@ -190,6 +193,9 @@ struct window::impl {
|
||||||
// get new events
|
// get new events
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
|
_parent._on_update(_parent);
|
||||||
|
|
||||||
|
|
||||||
// do other stuff
|
// do other stuff
|
||||||
#if 0
|
#if 0
|
||||||
glClearColor(1,0,0,1);
|
glClearColor(1,0,0,1);
|
||||||
|
@ -270,7 +276,8 @@ struct window::impl {
|
||||||
|
|
||||||
|
|
||||||
window::window()
|
window::window()
|
||||||
: _impl(std::make_unique<window::impl>())
|
: _impl(std::make_unique<window::impl>(*this))
|
||||||
|
, _on_update([](window&){})
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ public:
|
||||||
|
|
||||||
virtual bool make_current() = 0;
|
virtual bool make_current() = 0;
|
||||||
virtual void resize() = 0;
|
virtual void resize() = 0;
|
||||||
virtual size size() = 0;
|
virtual ::pw::size size() = 0;
|
||||||
virtual void flush() = 0;
|
virtual void flush() = 0;
|
||||||
|
|
||||||
virtual ~context() = default;
|
virtual ~context() = default;
|
||||||
|
|
|
@ -13,7 +13,7 @@ class pipeline {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
pipeline();
|
pipeline();
|
||||||
~pipeline() = default;
|
~pipeline();
|
||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,11 @@ pipeline::pipeline()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pipeline::~pipeline()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
bool pipeline::create(size s)
|
bool pipeline::create(size s)
|
||||||
{
|
{
|
||||||
return _impl->create(sizei(s.width,s.height));
|
return _impl->create(sizei(s.width,s.height));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue