added camera implementation and plenty of other rendering related stuff - splitted out the initialization of the render context
This commit is contained in:
parent
ae37273021
commit
f7043fc0cb
43 changed files with 23280 additions and 15161 deletions
|
@ -1,5 +1,3 @@
|
|||
#add_subdirectory(src)
|
||||
|
||||
|
||||
set(hdrs
|
||||
include/pw/scripting/script.hpp
|
||||
|
@ -8,6 +6,12 @@ set(hdrs
|
|||
|
||||
set(srcs
|
||||
src/script.cpp
|
||||
src/script_core.hpp
|
||||
src/script_core.cpp
|
||||
src/script_system.hpp
|
||||
src/script_system.cpp
|
||||
src/script_scene.hpp
|
||||
src/script_scene.cpp
|
||||
)
|
||||
|
||||
add_library(pwscripting
|
||||
|
@ -16,17 +20,14 @@ add_library(pwscripting
|
|||
${srcs}
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
pwscripting
|
||||
PUBLIC
|
||||
include
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
pwscripting
|
||||
PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.4/src
|
||||
${CMAKE_SOURCE_DIR}/src/deps/sol
|
||||
${CMAKE_SOURCE_DIR}/src/deps/sol2-2.20.6
|
||||
PUBLIC
|
||||
include
|
||||
)
|
||||
|
||||
target_link_libraries(pwscripting lualib pwcore pwui pwscene)
|
||||
target_link_libraries(pwscripting lualib pwcore pwsystem pwscene)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef PW_SCRIPTING_SCRIPTING_HPP
|
||||
#define PW_SCRIPTING_SCRIPTING_HPP
|
||||
|
||||
#include "sol.hpp"
|
||||
#include "sol/sol.hpp"
|
||||
#include <lua.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
|
|
@ -2,19 +2,18 @@
|
|||
|
||||
#include "pw/scripting/scripting.hpp"
|
||||
|
||||
#include "pw/core/vector.hpp"
|
||||
#include "pw/core/quaternion.hpp"
|
||||
#include "pw/core/axisangle.hpp"
|
||||
|
||||
#include "pw/scene/node.hpp"
|
||||
|
||||
#include "pw/ui/window.hpp"
|
||||
#include "script_core.hpp"
|
||||
#include "script_system.hpp"
|
||||
#include "script_scene.hpp"
|
||||
|
||||
namespace pw {
|
||||
|
||||
struct lua_state : public pw::script::state {
|
||||
struct lua_state : public script::state {
|
||||
|
||||
pw::scripting::state _state;
|
||||
pw::scripting::table _namespace;
|
||||
scripting::state _state;
|
||||
scripting::table _namespace;
|
||||
|
||||
void load_modules();
|
||||
|
||||
|
@ -46,88 +45,32 @@ void lua_state::load_modules() {
|
|||
// open all libraries
|
||||
_state.open_libraries();
|
||||
|
||||
typedef double Scalar;
|
||||
|
||||
_namespace.set("pi",pw::pi<Scalar>());
|
||||
|
||||
using namespace pw;
|
||||
|
||||
_namespace.new_usertype<vector3d>("vector3",
|
||||
sol::constructors<vector3d(), vector3d(Scalar,Scalar,Scalar)>(),
|
||||
"set",&vector3d::set,
|
||||
"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),
|
||||
"z", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::z), &vector3d::set_z),
|
||||
"norm",&vector3d::norm,
|
||||
"cross",&vector3d::cross,
|
||||
"dot",&vector3d::dot,
|
||||
// sol::meta_function::addition, sol::resolve<vector3d(const vector3d&, const vector3d&)>(::operator+),
|
||||
// sol::meta_function::subtraction, &vector3d::operator-
|
||||
// "v",&vector3d::values,
|
||||
"clone",&vector3d::clone
|
||||
);
|
||||
|
||||
_namespace.new_usertype<quaterniond>("quaternion",
|
||||
sol::constructors<quaterniond(), vector3d(Scalar,Scalar,Scalar,Scalar)>(),
|
||||
"set",&quaterniond::set,
|
||||
"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),
|
||||
"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),
|
||||
"dot",&quaterniond::dot,
|
||||
"inverse",&quaterniond::inverse,
|
||||
"normalized",&quaterniond::normalized,
|
||||
"lerp",&quaterniond::lerp
|
||||
// "v",&vector3d::values,
|
||||
// "clone",&vector3d::clone
|
||||
);
|
||||
|
||||
_namespace.new_usertype<axisangled>("axisangle",
|
||||
sol::constructors<axisangled(), axisangled(vector3d,Scalar)>(),
|
||||
"axis",scripting::property(&axisangled::axis,&axisangled::set_axis),
|
||||
"angle",scripting::property(&axisangled::angle,&axisangled::set_angle)
|
||||
);
|
||||
|
||||
|
||||
|
||||
_namespace.new_usertype<window>("window",
|
||||
"update",&window::update,
|
||||
"title",sol::writeonly_property(&window::set_title),
|
||||
"set_size",&window::set_size
|
||||
);
|
||||
|
||||
|
||||
_namespace.new_usertype<node>("node",
|
||||
sol::constructors<node(), node(std::string)>(),
|
||||
"add_child",&node::add_child,
|
||||
"children",sol::readonly_property(&node::children),
|
||||
"child_count",sol::readonly_property(&node::child_count),
|
||||
"create", []() -> std::shared_ptr<node> { return std::make_shared<node>(); },
|
||||
"is_leaf", sol::readonly_property(&node::is_leaf),
|
||||
"is_root", sol::readonly_property(&node::is_root),
|
||||
// "share",scripting::property(scripting::resolve<std::shared_ptr<node>(std::make_shared<node>))
|
||||
"name",scripting::property(&node::name,&node::set_name)
|
||||
);
|
||||
script_core::load(_namespace);
|
||||
script_system::load(_namespace);
|
||||
script_scene::load(_namespace);
|
||||
|
||||
}
|
||||
|
||||
|
||||
pw::script::script()
|
||||
script::script()
|
||||
{
|
||||
_state.reset(new lua_state());
|
||||
}
|
||||
|
||||
pw::script::~script()
|
||||
script::~script()
|
||||
{
|
||||
_state = nullptr;
|
||||
}
|
||||
|
||||
int pw::script::run(const std::string &s)
|
||||
int script::run(const std::string &s)
|
||||
{
|
||||
return _state->run(s);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
59
src/scripting/src/script_core.cpp
Normal file
59
src/scripting/src/script_core.cpp
Normal file
|
@ -0,0 +1,59 @@
|
|||
#include "script_core.hpp"
|
||||
|
||||
#include "pw/core/vector.hpp"
|
||||
#include "pw/core/quaternion.hpp"
|
||||
#include "pw/core/axisangle.hpp"
|
||||
|
||||
|
||||
namespace pw {
|
||||
|
||||
void script_core::load(sol::table &ns)
|
||||
{
|
||||
|
||||
typedef double Scalar;
|
||||
|
||||
ns.set("pi",pw::pi<Scalar>());
|
||||
|
||||
|
||||
ns.new_usertype<vector3d>("vector3",
|
||||
sol::constructors<vector3d(), vector3d(Scalar,Scalar,Scalar)>(),
|
||||
"set",&vector3d::set,
|
||||
"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),
|
||||
"z", scripting::property(scripting::resolve<const Scalar&() const>(&vector3d::z), &vector3d::set_z),
|
||||
"norm",&vector3d::norm,
|
||||
"cross",&vector3d::cross,
|
||||
"dot",&vector3d::dot,
|
||||
// sol::meta_function::addition, sol::resolve<vector3d(const vector3d&, const vector3d&)>(::operator+),
|
||||
// sol::meta_function::subtraction, &vector3d::operator-
|
||||
// "v",&vector3d::values,
|
||||
"clone",&vector3d::clone
|
||||
);
|
||||
|
||||
ns.new_usertype<quaterniond>("quaternion",
|
||||
sol::constructors<quaterniond(), quaterniond(Scalar,Scalar,Scalar,Scalar)>(),
|
||||
"set",&quaterniond::set,
|
||||
"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),
|
||||
"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),
|
||||
"dot",&quaterniond::dot,
|
||||
"inverse",scripting::readonly_property(&quaterniond::inverse),
|
||||
"normalized",&quaterniond::normalized,
|
||||
"lerp",&quaterniond::lerp
|
||||
// "v",&vector3d::values,
|
||||
// "clone",&vector3d::clone
|
||||
);
|
||||
|
||||
ns.new_usertype<axisangled>("axisangle",
|
||||
sol::constructors<axisangled(), axisangled(vector3d,Scalar)>(),
|
||||
"axis",scripting::property(&axisangled::axis,&axisangled::set_axis),
|
||||
"angle",scripting::property(&axisangled::angle,&axisangled::set_angle)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
17
src/scripting/src/script_core.hpp
Normal file
17
src/scripting/src/script_core.hpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef PW_SCRIPTING_PRIVATE_CORE_HPP
|
||||
#define PW_SCRIPTING_PRIVATE_CORE_HPP
|
||||
|
||||
#include <pw/scripting/scripting.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
||||
struct script_core {
|
||||
|
||||
static void load(scripting::table& ns);
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
23
src/scripting/src/script_scene.cpp
Normal file
23
src/scripting/src/script_scene.cpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include "script_scene.hpp"
|
||||
|
||||
#include <pw/scene/node.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
||||
void script_scene::load(sol::table &ns)
|
||||
{
|
||||
|
||||
ns.new_usertype<node>("node",
|
||||
sol::constructors<node(), node(std::string)>(),
|
||||
"add_child",&node::add_child,
|
||||
"children",sol::readonly_property(&node::children),
|
||||
"child_count",sol::readonly_property(&node::child_count),
|
||||
"create", []() -> std::shared_ptr<node> { return std::make_shared<node>(); },
|
||||
"is_leaf", sol::readonly_property(&node::is_leaf),
|
||||
"is_root", sol::readonly_property(&node::is_root),
|
||||
// "share",scripting::property(scripting::resolve<std::shared_ptr<node>(std::make_shared<node>))
|
||||
"name",scripting::property(&node::name,&node::set_name)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
17
src/scripting/src/script_scene.hpp
Normal file
17
src/scripting/src/script_scene.hpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef PW_SCRIPTING_PRIVATE_SCENE_HPP
|
||||
#define PW_SCRIPTING_PRIVATE_SCENE_HPP
|
||||
|
||||
#include <pw/scripting/scripting.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
||||
struct script_scene {
|
||||
|
||||
static void load(scripting::table& ns);
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
16
src/scripting/src/script_system.cpp
Normal file
16
src/scripting/src/script_system.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
#include "script_system.hpp"
|
||||
|
||||
#include "pw/system/window.hpp"
|
||||
|
||||
namespace pw {
|
||||
|
||||
void script_system::load(sol::table &ns)
|
||||
{
|
||||
ns.new_usertype<window>("window",
|
||||
"update",&window::update,
|
||||
"title",sol::writeonly_property(&window::set_title),
|
||||
"set_size",&window::set_size
|
||||
);
|
||||
}
|
||||
|
||||
}
|
17
src/scripting/src/script_system.hpp
Normal file
17
src/scripting/src/script_system.hpp
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef PW_SCRIPTING_PRIVATE_SYSTEM_HPP
|
||||
#define PW_SCRIPTING_PRIVATE_SYSTEM_HPP
|
||||
|
||||
#include <pw/scripting/scripting.hpp>
|
||||
|
||||
namespace pw {
|
||||
|
||||
struct script_system {
|
||||
|
||||
static void load(scripting::table& ns);
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue