diff --git a/share/doc/pixwerx.xmind b/share/doc/pixwerx.xmind index ff3b907..34f1438 100644 Binary files a/share/doc/pixwerx.xmind and b/share/doc/pixwerx.xmind differ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1b9f4d7..3de2253 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,7 @@ add_subdirectory(deps) add_subdirectory(core) +add_subdirectory(scene) add_subdirectory(ui) add_subdirectory(scripting) add_subdirectory(engine) diff --git a/src/core/include/pw/core/globals.hpp b/src/core/include/pw/core/globals.hpp index 15d8e1c..030ce25 100644 --- a/src/core/include/pw/core/globals.hpp +++ b/src/core/include/pw/core/globals.hpp @@ -1,10 +1,13 @@ #ifndef PW_CORE_GLOBALS_HPP #define PW_CORE_GLOBALS_HPP - #include - #include +namespace pw { + +using std::shared_ptr; + +} #endif diff --git a/src/scene/CMakeLists.txt b/src/scene/CMakeLists.txt index e69de29..fdfb8f4 100644 --- a/src/scene/CMakeLists.txt +++ b/src/scene/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(src) +add_subdirectory(tests) diff --git a/src/scene/include/pw/scene/node.hpp b/src/scene/include/pw/scene/node.hpp new file mode 100644 index 0000000..8f921cb --- /dev/null +++ b/src/scene/include/pw/scene/node.hpp @@ -0,0 +1,62 @@ +#ifndef PW_SCENE_NODE_HPP +#define PW_SCENE_NODE_HPP + +#include + +#include +#include + +namespace pw { + +class component; + +class node { +public: + + typedef shared_ptr ref; + typedef std::vector ref_array; + typedef std::vector ptr_array; + + //! standard c'tor + node(const std::string& name = ""); + + //! copy c'tor + node(const node& node); + + //! cloning interface + virtual node* clone(const unsigned short& copymode) const; + + std::string name() const; + void set_name(const std::string &name); + + //! return list of parents + inline const ptr_array& parents() const { return _parents; } + + //! check if this is the root node + inline bool is_root() const { return parents().empty(); } + + //! add a child node + void add_child(node *anode); + + //! get the list of children + inline const ref_array& children() const { return _children; } + + //! get number of children + inline size_t child_count() const { return children().size(); } + + //! check if this node is a leaf node + inline bool is_leaf() const { return children().empty(); } + + virtual ~node(); + +protected: + + ref_array _children; + ptr_array _parents; + + std::string _name; +}; + +} + +#endif diff --git a/src/scene/src/CMakeLists.txt b/src/scene/src/CMakeLists.txt index e69de29..9b6f08c 100644 --- a/src/scene/src/CMakeLists.txt +++ b/src/scene/src/CMakeLists.txt @@ -0,0 +1,29 @@ + +set(hdrs + ../include/pw/scene/node.hpp + ) + +set(srcs + node.cpp + nodepath.cpp + component.cpp + ) + +add_library(pwscene + STATIC + ${hdrs} + ${srcs} + ) + +target_include_directories( + pwscene + PUBLIC + ../include + ) + +target_include_directories( + pwscene + PUBLIC + ) + +target_link_libraries(pwscene pwcore) diff --git a/src/scene/src/component.cpp b/src/scene/src/component.cpp new file mode 100644 index 0000000..e0088f2 --- /dev/null +++ b/src/scene/src/component.cpp @@ -0,0 +1,30 @@ +#include +#include + +#include + +namespace pw { + +class component { + + std::string _name; + + //! only very few components can be attached multiple times + virtual bool singular() const { return true; } +}; + +class transform : public component { + + matrix44d _local; + matrix44d _global; + +}; + +class trs : public transform { + + vector3d _position; + vector3d _scale; + quaterniond _rotation; +}; + +} diff --git a/src/scene/src/node.cpp b/src/scene/src/node.cpp new file mode 100644 index 0000000..0093c25 --- /dev/null +++ b/src/scene/src/node.cpp @@ -0,0 +1,39 @@ +#include "pw/scene/node.hpp" + +namespace pw { + +node::node(const std::string &name) + : _name(name) +{ +} + +node *node::clone(const unsigned short ©mode) const +{ + return nullptr; +} + +std::string node::name() const +{ + return _name; +} + +void node::set_name(const std::string &name) +{ + _name = name; +} + +void node::add_child(node *anode) +{ + _children.push_back(std::shared_ptr(anode)); + anode->_parents.push_back(this); +} + +node::~node() +{ + _children.clear(); + _parents.clear(); +} + + + +} diff --git a/src/scene/src/nodepath.cpp b/src/scene/src/nodepath.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/scene/tests/CMakeLists.txt b/src/scene/tests/CMakeLists.txt new file mode 100644 index 0000000..0497955 --- /dev/null +++ b/src/scene/tests/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(pwscene_test_node + pwscene_test_node.cpp + ) + +target_link_libraries(pwscene_test_node + pwcore pwscene) diff --git a/src/scene/tests/pwscene_test_node.cpp b/src/scene/tests/pwscene_test_node.cpp new file mode 100644 index 0000000..b9b1c3f --- /dev/null +++ b/src/scene/tests/pwscene_test_node.cpp @@ -0,0 +1,29 @@ +#include +#include +#include + +#include + +int main(int argc,char **argv) { + + using namespace pw; + + node::ref n(new node("test")); + + // check + { + n->add_child(new node("sub")); + } + + std::cout << "n name: " << n->name() << std::endl; + std::cout << "n leaf: " << n->is_leaf() << std::endl; + std::cout << "n root: " << n->is_root() << std::endl; + + std::cout << "s name: " << n->children()[0]->name() << std::endl; + std::cout << "s leaf: " << n->children()[0]->is_leaf() << std::endl; + std::cout << "s root: " << n->children()[0]->is_root() << std::endl; + + + + return 0; +} diff --git a/src/scripting/src/CMakeLists.txt b/src/scripting/src/CMakeLists.txt index 24478ff..15019a3 100644 --- a/src/scripting/src/CMakeLists.txt +++ b/src/scripting/src/CMakeLists.txt @@ -22,7 +22,7 @@ target_include_directories( target_include_directories( pwscripting - PUBLIC + PRIVATE ${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.4/src ${CMAKE_SOURCE_DIR}/src/deps/sol ) diff --git a/src/scripting/src/script.cpp b/src/scripting/src/script.cpp index f340e86..758b85a 100644 --- a/src/scripting/src/script.cpp +++ b/src/scripting/src/script.cpp @@ -12,10 +12,10 @@ struct lua_state : public pw::script::state { pw::scripting::state _state; pw::scripting::table _namespace; - void load_modules(); lua_state() { + // create global pw namespace _namespace = _state.create_named_table("pw"); @@ -46,7 +46,8 @@ void lua_state::load_modules() { _namespace.set("pi",pw::Pi()); -#if 0 + using namespace pw; + _namespace.new_usertype("vector3", "set",&vector3d::set, "x", scripting::property(scripting::resolve(&vector3d::x), &vector3d::set_x), @@ -71,25 +72,20 @@ void lua_state::load_modules() { "angle",scripting::property(&axisangled::angle,&axisangled::set_angle) ); -#endif } - -pw::script::script() { +pw::script::script() +{ + _state.reset(new lua_state()); } pw::script::~script() { - // _state.collect_garbage(); + _state = nullptr; } -//bool pw::script::load(const std::string &s) -//{ -// return _state.load(s.c_str()); -//} - int pw::script::run(const std::string &s) { return _state->run(s); diff --git a/src/scripts/demos/simple_000.lua b/src/scripts/demos/simple_000.lua index 19f9852..999d9c5 100644 --- a/src/scripts/demos/simple_000.lua +++ b/src/scripts/demos/simple_000.lua @@ -1,7 +1,7 @@ -- loading our libraries pw.script:initialize() -print("hellow pixwerx") +print("hello pixwerx!") local v = pw.vector3.new() v:set(0,1,2)