testing a ecs

This commit is contained in:
Hartmut Seichter 2020-11-24 23:54:49 +01:00
parent 47d28b4f1e
commit 8915080b64
20 changed files with 20419 additions and 101 deletions

3
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1,3 @@
{
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
}

View file

@ -50,8 +50,8 @@ struct matrix_transform {
frustum(0,2) = (right+left)/(right-left); //A
frustum(1,2) = (top+bottom)/(top-bottom); //B
frustum(2,2) = -(z_far+z_near)/(z_far-z_near); //C
frustum(2,3) = -T(2) * z_far*z_near/(z_far-z_near); //D
frustum(2,2) = -(z_far+z_near)/(z_far-z_near); //C
frustum(2,3) = -T(2) * z_far*z_near/(z_far-z_near); //D
frustum(3,2) = -T(1);

View file

@ -1,12 +1,10 @@
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "Build the GLFW example programs" FORCE)
set(GLFW_BUILD_EXAMPLES TRUE CACHE BOOL "Build the GLFW example programs" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "Build the GLFW test programs" FORCE)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "Build the GLFW documentation" FORCE)
set(GLFW_INSTALL OFF CACHE BOOL "Generate installation target" FORCE)
add_subdirectory(glfw-3.3.2)
add_subdirectory(glfw-3.2.1)
add_subdirectory(lua-5.3.5)
add_subdirectory(glad)
#add_subdirectory(arrrgh)

21
src/deps/entt/LICENSE Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2017-2020 Michele Caini
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
copy 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
copy 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.

20185
src/deps/entt/entt/entt.hpp Normal file

File diff suppressed because it is too large Load diff

View file

@ -23,7 +23,7 @@ int main(int argc,const char** argv) {
argagg::parser argparser {{
{ "help", {"-h", "--help"},
"shows this help message", 0},
"shows this help message", 0},
{ "file", {"-f", "--file"},
"load file to run", 1}
}
@ -52,12 +52,12 @@ int main(int argc,const char** argv) {
std::ostringstream sout;
std::copy(std::istreambuf_iterator<char>(input),
std::istreambuf_iterator<char>(),
std::ostreambuf_iterator<char>(sout));
std::istreambuf_iterator<char>(),
std::ostreambuf_iterator<char>(sout));
input.close();
pw::script::initialize();
pw::script::initialize();
pw::script s;

View file

@ -1,6 +1,7 @@
set(hdrs
include/pw/scene/camera.hpp
include/pw/scene/entity.hpp
include/pw/scene/projection.hpp
include/pw/scene/component.hpp
include/pw/scene/node.hpp
include/pw/scene/scene.hpp
@ -9,8 +10,9 @@ set(hdrs
)
set(srcs
src/entity.cpp
src/node.cpp
src/camera.cpp
src/projection.cpp
src/component.cpp
src/scene.cpp
src/transform.cpp
@ -25,6 +27,7 @@ add_library(pwscene
target_include_directories(
pwscene
PUBLIC
include
)
@ -32,6 +35,7 @@ target_include_directories(
target_include_directories(
pwscene
PUBLIC
${CMAKE_SOURCE_DIR}/src/deps/entt
)
target_link_libraries(pwscene pwcore)

View file

@ -1,5 +1,5 @@
/*
* Copyright (C) 1999-2017 Hartmut Seichter
* Copyright (C) 1999-2020 Hartmut Seichter
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions

View file

@ -0,0 +1,57 @@
/*
* Copyright (C) 1999-2020 Hartmut Seichter
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef PW_SCENE_ENTITY_HPP
#define PW_SCENE_ENTITY_HPP
#include <pw/core/globals.hpp>
#include <pw/scene/scene.hpp>
#include <string>
#include <vector>
#include <memory>
#include <entt/entt.hpp>
namespace pw {
class entity {
public:
entity() = delete;
protected:
entity(entt::entity e, scene *s);
private:
entt::entity _entity { entt::null };
scene *_scene;
friend class scene;
};
}
#endif

View file

@ -22,8 +22,8 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef PW_SCENE_CAMERA_HPP
#define PW_SCENE_CAMERA_HPP
#ifndef PW_SCENE_PROJECTION_HPP
#define PW_SCENE_PROJECTION_HPP
#include <pw/core/matrix.hpp>
@ -31,40 +31,24 @@
namespace pw {
class camera : public component {
class projection : public component {
public:
enum clearflags {
color,
depth,
none
};
using component::component;
enum projection {
orthographic,
perspective
};
projection(node &host);
using component::component;
void set_matrix(const matrix4x4 &projection);
const matrix4x4& matrix() const;
camera(node &host);
void set_projection(const matrix4x4 &projection);
const matrix4x4& projection() const;
// void set_field_of_view(float)
protected:
real_t _fov;
real_t _near_plane;
real_t _far_plane;
real_t _ortho_size = 2;
void set_frustum(real_t left,
real_t right,
real_t top,
real_t bottom);
private:
matrix4x4 _projection;
matrix4x4 _m;
};

View file

@ -26,22 +26,22 @@
#define PW_SCENE_SCENE_HPP
#include <pw/core/globals.hpp>
#include <pw/scene/node.hpp>
#include <entt/entt.hpp>
namespace pw {
class entity;
class scene {
public:
//! set root node
void set_root(node::ref root);
scene();
// request the root node
inline node::ref root() const { return _root; }
entity create_entity();
protected:
node::ref _root; //!< root node
entt::registry _registry;
};

View file

@ -1,42 +0,0 @@
#include "pw/scene/camera.hpp"
#include "pw/core/matrix_transform.hpp"
namespace pw {
camera::camera(node &host)
: component (host)
, _fov(60.0)
, _near_plane(0.2f)
, _far_plane(1000)
{
set_projection(matrix_transform<real_t>::perspective_projection(_fov,1,_near_plane,_far_plane));
}
void camera::set_projection(const matrix4x4 &projection)
{
this->_projection = projection;
// recompute the simplified parameters
auto near = _projection(3,4);
auto far = _projection(3,4);
// right = (1-m14) / m11
// near = (1+m34)/m33;
// far = -(1-m34)/m33;
// bottom = (1-m24)/m22;
// top = -(1+m24)/m22;
// left = -(1+m14)/m11;
// right = (1-m14)/m11;
// real_t fov_raw = float( atan (top / near_)) * * 2.0f;
}
const matrix4x4 &camera::projection() const
{
return _projection;
}
}

12
src/scene/src/entity.cpp Normal file
View file

@ -0,0 +1,12 @@
#include "pw/scene/entity.hpp"
namespace pw {
entity::entity(entt::entity e, scene *s)
: _entity(e)
, _scene(s)
{
}
}

View file

@ -0,0 +1,45 @@
#include "pw/scene/projection.hpp"
#include "pw/core/matrix_transform.hpp"
namespace pw {
projection::projection(node &host)
: component (host)
{
_m.set_identity();
// set_matrix(matrix_transform<real_t>::perspective_projection(_fov,1,_near_plane,_far_plane));
}
void projection::set_matrix(const matrix4x4 &projection)
{
this->_m = projection;
// recompute the simplified parameters
// auto near = _projection(3,4);
// auto far = _projection(3,4);
// right = (1-m14) / m11
// near = (1+m34)/m33;
// far = -(1-m34)/m33;
// bottom = (1-m24)/m22;
// top = -(1+m24)/m22;
// left = -(1+m14)/m11;
// right = (1-m14)/m11;
// real_t fov_raw = float( atan (top / near_)) * * 2.0f;
}
const matrix4x4 &projection::matrix() const
{
return _m;
}
void projection::set_frustum(real_t left, real_t right, real_t top, real_t bottom)
{
}
}

View file

@ -1,11 +1,24 @@
#include "pw/scene/scene.hpp"
#include "pw/scene/entity.hpp"
namespace pw {
void scene::set_root(node::ref root)
struct component {
int data;
};
scene::scene()
{
this->_root = root;
}
entity
scene::create_entity() {
return entity{_registry.create(),this};
}
}

View file

@ -12,3 +12,11 @@ add_executable(pwscene_test_traverser
target_link_libraries(pwscene_test_traverser
pwcore pwscene)
add_executable(pwscene_test_scene
pwscene_test_scene.cpp
)
target_link_libraries(pwscene_test_scene
pwcore pwscene)

View file

@ -0,0 +1,24 @@
#include <pw/core/vector.hpp>
#include <pw/core/serialize.hpp>
#include <pw/scene/node.hpp>
#include <pw/scene/transform.hpp>
#include <pw/scene/scene.hpp>
#include <pw/scene/entity.hpp>
#include <pw/core/serialize.hpp>
#include <iostream>
int main(int argc,char **argv) {
using pw::scene;
auto s = std::make_unique<scene>();
auto e = s->create_entity();
// e.add_component<transform>();
}

View file

@ -14,10 +14,10 @@ w.visible = false
w.title = "pixwerx 0.1"
-- set size
--w.size = pw.size.new(640,480)
w.size = pw.size.new(640,480)
-- move window
--w.position = pw.point.new(100,100)
w.position = pw.point.new(100,100)
print("client size after resize: ",w.client_size.width,w.client_size.height)
@ -32,7 +32,6 @@ end
w.on_update = function(self)
pl:draw()
-- print("test on update",w.position.x,w.position.y,pw.time.now)
end
-- show all displays
@ -51,6 +50,11 @@ while w:update() do
w.fullscreen = not w.fullscreen
end
-- keycode for quit
if (pw.input.get().input_string == 'q') then
break;
end
-- just to check
if (pw.input:get().mouse_button == 1) then
print("elapsed",t.elapsed)

View file

@ -207,16 +207,15 @@ struct window::impl {
if (_window && !glfwWindowShouldClose(_window))
{
// // reset input
// input::get().reset();
input::get().reset();
// get new events
glfwPollEvents();
_parent._on_update(_parent);
glfwSwapBuffers(_window);
// // get new events
glfwPollEvents();
return true;
}

View file

@ -1,5 +1,8 @@
#version 400
in vec3 vp;
in mat4 mvp;
void main() {
gl_Position = vec4(vp, 1.0);
gl_Position = mvp * vec4(vp, 1.0);
}