From 5cad3a1251d45508130d1b8d32cc21923ca42d16 Mon Sep 17 00:00:00 2001 From: Benjamin Adamson Date: Wed, 15 May 2013 16:29:11 -0700 Subject: [PATCH 1/3] Added new property sheets for BOOST, and release mode. Also killed the draw_scenegraphs() function in favor of a check_scenegraph_transform() function. --- props/(compiler)-boost-headers.props | 10 ++++ props/(linker)-boost-log-binay.props | 15 +++++ props/(linker)-sfml-binaries(release).props | 14 +++++ src/Tetris/Tetris.vcxproj | 2 + .../component/scenegraph_component.hpp | 39 ------------- src/entity-component/entity-component.vcxproj | 12 +++- .../system/graphics_system.cpp | 56 +++++++++---------- 7 files changed, 76 insertions(+), 72 deletions(-) create mode 100644 props/(compiler)-boost-headers.props create mode 100644 props/(linker)-boost-log-binay.props create mode 100644 props/(linker)-sfml-binaries(release).props delete mode 100644 src/entity-component/component/scenegraph_component.hpp diff --git a/props/(compiler)-boost-headers.props b/props/(compiler)-boost-headers.props new file mode 100644 index 0000000..32e35dc --- /dev/null +++ b/props/(compiler)-boost-headers.props @@ -0,0 +1,10 @@ + + + + + + C:\boost;$(IncludePath) + + + + \ No newline at end of file diff --git a/props/(linker)-boost-log-binay.props b/props/(linker)-boost-log-binay.props new file mode 100644 index 0000000..93bb80d --- /dev/null +++ b/props/(linker)-boost-log-binay.props @@ -0,0 +1,15 @@ + + + + + + C:\boost\stage64\lib\;$(LibraryPath) + + + + libboost_log_setup-vc110-mt-gd-1_53.lib;%(AdditionalDependencies) + C:\boost\stage64\lib\ + + + + \ No newline at end of file diff --git a/props/(linker)-sfml-binaries(release).props b/props/(linker)-sfml-binaries(release).props new file mode 100644 index 0000000..b3617f3 --- /dev/null +++ b/props/(linker)-sfml-binaries(release).props @@ -0,0 +1,14 @@ + + + + + + C:\sfml-2.0\lib\;$(LibraryPath) + + + + sfml-audio.lib;sfml-graphics.lib;sfml-main.lib;sfml-network.lib;sfml-system.lib;sfml-window.lib;%(AdditionalDependencies) + + + + \ No newline at end of file diff --git a/src/Tetris/Tetris.vcxproj b/src/Tetris/Tetris.vcxproj index 9e3ede3..762ef44 100644 --- a/src/Tetris/Tetris.vcxproj +++ b/src/Tetris/Tetris.vcxproj @@ -57,6 +57,7 @@ + @@ -65,6 +66,7 @@ + diff --git a/src/entity-component/component/scenegraph_component.hpp b/src/entity-component/component/scenegraph_component.hpp deleted file mode 100644 index 1e0cfb4..0000000 --- a/src/entity-component/component/scenegraph_component.hpp +++ /dev/null @@ -1,39 +0,0 @@ -//===-----------------------------------------------------------------------===// -// -// The Remnant Source code -// -// Authors: -// -// Benjamin Adamson (adamson.benjamin@gmail.com) -// Wesley Kos (kos.wesley@gmail.com) -// -//===----------------------------------------------------------------------===// -// -// TODO: comment -// -//===----------------------------------------------------------------------===// -#ifndef _SCENEGRAPH_COMPONENT_HPP_ -#define _SCENEGRAPH_COMPONENT_HPP_ -#include -#include "icomponent.hpp" - -namespace ec -{ - // forward declarations - class entity; - - struct scenegraph_component : - public icomponent - { - // static members - static const auto COMPONENT_TYPE = COMPONENT_TYPE_SCENEGRAPH; - - // members - scenegraph_component *root_scenegraph_ptr; - sf::Vector2f Offset; - - // constructors - scenegraph_component(void) : icomponent(COMPONENT_TYPE), root_scenegraph_ptr(nullptr) { } - }; -} -#endif // _SCENEGRAPH_COMPONENT_HPP_ \ No newline at end of file diff --git a/src/entity-component/entity-component.vcxproj b/src/entity-component/entity-component.vcxproj index 2eb945a..76e0cc5 100644 --- a/src/entity-component/entity-component.vcxproj +++ b/src/entity-component/entity-component.vcxproj @@ -43,7 +43,7 @@ MultiByte - Application + StaticLibrary false v110 true @@ -59,11 +59,19 @@ + + - + + + + + + + diff --git a/src/entity-component/system/graphics_system.cpp b/src/entity-component/system/graphics_system.cpp index 351ad8e..0959ad7 100644 --- a/src/entity-component/system/graphics_system.cpp +++ b/src/entity-component/system/graphics_system.cpp @@ -1,41 +1,38 @@ #include "..\engine.hpp" #include "..\component\sprite_component.hpp" #include "..\entity\entity.hpp" +//#include #include "graphics_system.hpp" + //===----------------------------------------------------------------------===// // -// TODO: comment +// If the entity_ptr has a parent_component // //===----------------------------------------------------------------------===// -void -draw_scenegraphs( - sf::RenderWindow &window, - const ec::transform_component &transform_component, - const ec::sprite_component &sprite_component, - const ec::parent_component &parent_component - ) +sf::Transform +check_scenegraph_transform(const ec::transform_component &transform, ec::entity *const entity_ptr) { using namespace ec; + sf::Transform result = transform.getTransform(); + const auto parent_component_ptr = entity_helpers::get_parent_component(entity_ptr); // alias - const auto parent_entity_ptr = parent_component.parent_entity_ptr; // alias - - if(parent_entity_ptr == parent_component.Entity_Pointer) { - __debugbreak(); - } - - const auto parent_transform_ptr = entity_helpers::get_transform_component(parent_entity_ptr); - if(parent_transform_ptr == nullptr) { - __debugbreak(); + if(parent_component_ptr == nullptr) { // entity is not a member of a scenegraph + return result; } + const auto parent_transform_component = entity_helpers::get_transform_component(parent_component_ptr->parent_entity_ptr); + if(parent_transform_component == nullptr) { // parent component is not a member of a scenegraph + //BOOST_LOG_TRIVIAL(warning) << "TODO: figure out if this should be a bug, or not." << std::endl; + return result; + } - // combine the parent transform with the transform component - const auto combined_transform = parent_transform_ptr->getTransform() * transform_component.getTransform(); - - window.draw(sprite_component.Sprite, combined_transform); + // combine the parent transform with the transform component + result = parent_transform_component->getTransform() * transform.getTransform(); + return result; } + //===----------------------------------------------------------------------===// // // The function update_screen() is responsible for drawing the screen within the @@ -58,21 +55,18 @@ ec::graphics_system::update_screen(ec::engine &engine) } if(transform_component_ptr == nullptr) { + //BOOST_LOG_TRIVIAL(error) << "Entity with sprite component, missing transform component." << std::endl; __debugbreak(); } - const auto parent_component_ptr = entity_helpers::get_parent_component(entity_ptr); // alias - - if(parent_component_ptr != nullptr) { // drawing a scenegraph - draw_scenegraphs(engine.Window, *transform_component_ptr, *sprite_component_ptr, *parent_component_ptr); - continue; - } + // if entity_ptr is a member of a scenegraph, then multiply our transform with the parent's transform. + const sf::Transform transform = check_scenegraph_transform(*transform_component_ptr, entity_ptr); - sprite_component_ptr->Sprite.setPosition(transform_component_ptr->getPosition()); - sprite_component_ptr->Sprite.setRotation(transform_component_ptr->getRotation()); - sprite_component_ptr->Sprite.setScale(transform_component_ptr->getScale()); + //sprite_component_ptr->Sprite.setPosition(transform_component_ptr->getPosition()); + //sprite_component_ptr->Sprite.setRotation(transform_component_ptr->getRotation()); + //sprite_component_ptr->Sprite.setScale(transform_component_ptr->getScale()); - engine.Window.draw(sprite_component_ptr->Sprite); + engine.Window.draw(sprite_component_ptr->Sprite, transform); } // current frame ends here From 78b5330a6dba13e6d1ad99cf1f2460067e5b49b7 Mon Sep 17 00:00:00 2001 From: Benjamin Adamson Date: Wed, 15 May 2013 17:15:39 -0700 Subject: [PATCH 2/3] Removed the parent_component in favor of storing a parent entity pointer directly on the entity. --- src/Tetris/game.cpp | 21 ++++------ .../component/component_factory.inc | 1 - .../component/parent_component.hpp | 40 ------------------- src/entity-component/entity-component.vcxproj | 1 - .../entity-component.vcxproj.filters | 3 -- src/entity-component/entity/entity.cpp | 1 + src/entity-component/entity/entity.hpp | 3 +- .../entity/entity_helpers.hpp | 2 - .../entity/entity_helpers.inc | 13 ------ .../system/graphics_system.cpp | 15 ++++--- 10 files changed, 20 insertions(+), 80 deletions(-) delete mode 100644 src/entity-component/component/parent_component.hpp diff --git a/src/Tetris/game.cpp b/src/Tetris/game.cpp index 94633fd..350c0f2 100644 --- a/src/Tetris/game.cpp +++ b/src/Tetris/game.cpp @@ -55,12 +55,11 @@ add_test_L_block_to_engine(ec::engine &engine, ec::entity *parent_entity_ptr, co const entity_factory ef; const auto e0 = ef.get(); + e0->Parent = parent_entity_ptr; const component_factory sprite_cfactory; auto spritecomponent_ptr = sprite_cfactory.get(); - - const auto load_result = spritecomponent_ptr->Texture.loadFromFile("../../assets/tetris-block.png"); if(load_result == false) { // file failed to load @@ -76,13 +75,6 @@ add_test_L_block_to_engine(ec::engine &engine, ec::entity *parent_entity_ptr, co const auto shared_transform_component_ptr = transform_cfactory.get(); shared_transform_component_ptr->move(offset); e0->add_component(shared_transform_component_ptr); - - const component_factory parent_cfactory; - const auto parent_component_ptr = parent_cfactory.get(); - - parent_component_ptr->Offset = offset; - parent_component_ptr->parent_entity_ptr = parent_entity_ptr; - e0->add_component(parent_component_ptr); engine.Entities.emplace_back(e0); } @@ -121,11 +113,12 @@ tet::game::game_loop( setup_window(engine); setup_test_code(engine); - add_test_L_block_to_engine(engine, engine.Entities.front(), sf::Vector2f(-15.0f, -15.0f)); - add_test_L_block_to_engine(engine, engine.Entities.front(), sf::Vector2f(-15.0f, 0.0f)); - add_test_L_block_to_engine(engine, engine.Entities.front(), sf::Vector2f(-15.0f, 15.0f)); - add_test_L_block_to_engine(engine, engine.Entities.front(), sf::Vector2f(0.0f, 15.0f)); - add_test_L_block_to_engine(engine, engine.Entities.front(), sf::Vector2f(15.0f, 15.0f)); + const auto parent_entity = engine.Entities.front(); + add_test_L_block_to_engine(engine, parent_entity, sf::Vector2f(-15.0f, -15.0f)); + add_test_L_block_to_engine(engine, parent_entity, sf::Vector2f(-15.0f, 0.0f)); + add_test_L_block_to_engine(engine, parent_entity, sf::Vector2f(-15.0f, 15.0f)); + add_test_L_block_to_engine(engine, parent_entity, sf::Vector2f(0.0f, 15.0f)); + add_test_L_block_to_engine(engine, parent_entity, sf::Vector2f(15.0f, 15.0f)); sf::Clock clock_instance; bool finished = false; diff --git a/src/entity-component/component/component_factory.inc b/src/entity-component/component/component_factory.inc index 19b78bf..a4c6d0a 100644 --- a/src/entity-component/component/component_factory.inc +++ b/src/entity-component/component/component_factory.inc @@ -2,7 +2,6 @@ #include "sprite_component.hpp" #include "movement_component.hpp" #include "gravity_component.hpp" -#include "parent_component.hpp" //===----------------------------------------------------------------------===// // diff --git a/src/entity-component/component/parent_component.hpp b/src/entity-component/component/parent_component.hpp deleted file mode 100644 index 1de5ddf..0000000 --- a/src/entity-component/component/parent_component.hpp +++ /dev/null @@ -1,40 +0,0 @@ -//===-----------------------------------------------------------------------===// -// -// The Remnant Source code -// -// Authors: -// -// Benjamin Adamson (adamson.benjamin@gmail.com) -// Wesley Kos (kos.wesley@gmail.com) -// -//===----------------------------------------------------------------------===// -// -// The parent_component provides a connection between two different entities in a -// pseudo parent/child relationship. -// -//===----------------------------------------------------------------------===// -#ifndef _PARENT_COMPONENT_HPP_ -#define _PARENT_COMPONENT_HPP_ -#include -#include "icomponent.hpp" - -namespace ec -{ - // forward declarations - class entity; - - struct parent_component : - public icomponent - { - // static members - static const auto COMPONENT_TYPE = COMPONENT_TYPE_PARENT; - - // members - entity *parent_entity_ptr; - sf::Vector2f Offset; - - // constructors - parent_component(void) : icomponent(COMPONENT_TYPE), parent_entity_ptr(nullptr) { } - }; -} -#endif // _PARENT_COMPONENT_HPP_ \ No newline at end of file diff --git a/src/entity-component/entity-component.vcxproj b/src/entity-component/entity-component.vcxproj index 76e0cc5..0c87af7 100644 --- a/src/entity-component/entity-component.vcxproj +++ b/src/entity-component/entity-component.vcxproj @@ -144,7 +144,6 @@ - diff --git a/src/entity-component/entity-component.vcxproj.filters b/src/entity-component/entity-component.vcxproj.filters index e76970e..ce69a7a 100644 --- a/src/entity-component/entity-component.vcxproj.filters +++ b/src/entity-component/entity-component.vcxproj.filters @@ -100,9 +100,6 @@ component - - component - diff --git a/src/entity-component/entity/entity.cpp b/src/entity-component/entity/entity.cpp index 41507ff..71b4ecf 100644 --- a/src/entity-component/entity/entity.cpp +++ b/src/entity-component/entity/entity.cpp @@ -9,6 +9,7 @@ //===----------------------------------------------------------------------===// ec::entity::entity(const ec::entity_id id) : _id(id), + Parent(nullptr), _components(COMPONENT_TYPE_MAX, nullptr) { } diff --git a/src/entity-component/entity/entity.hpp b/src/entity-component/entity/entity.hpp index e47d964..c9104d2 100644 --- a/src/entity-component/entity/entity.hpp +++ b/src/entity-component/entity/entity.hpp @@ -45,11 +45,12 @@ namespace ec public: // members + entity *Parent; std::queue Message_Queue; // methods void add_component(icomponent *const component_ptr); - void remove_component(const int component_type); // TODO: determine how this should work. + void remove_component(const int component_type); }; } #endif // _ENTITY_HPP_ definition \ No newline at end of file diff --git a/src/entity-component/entity/entity_helpers.hpp b/src/entity-component/entity/entity_helpers.hpp index 3771763..0151141 100644 --- a/src/entity-component/entity/entity_helpers.hpp +++ b/src/entity-component/entity/entity_helpers.hpp @@ -22,7 +22,6 @@ namespace ec struct movement_component; struct sprite_component; struct transform_component; - struct parent_component; namespace entity_helpers { @@ -31,7 +30,6 @@ namespace entity_helpers input_component* get_input_component(entity *const entity_ptr); movement_component* get_movement_component(entity *const entity_ptr); sprite_component* get_sprite_component(entity *const entity_ptr); - parent_component* get_parent_component(entity *const entity_ptr); // templated function declarations template diff --git a/src/entity-component/entity/entity_helpers.inc b/src/entity-component/entity/entity_helpers.inc index 21df6a6..7880533 100644 --- a/src/entity-component/entity/entity_helpers.inc +++ b/src/entity-component/entity/entity_helpers.inc @@ -3,7 +3,6 @@ #include "../component/input_component.hpp" #include "../component/movement_component.hpp" #include "../component/sprite_component.hpp" -#include "../component/parent_component.hpp" //===----------------------------------------------------------------------===// @@ -72,16 +71,4 @@ inline ec::sprite_component* ec::entity_helpers::get_sprite_component(entity *const entity_ptr) { return get_component(entity_ptr); -} - - -//===----------------------------------------------------------------------===// -// -// Wrapper for getting the parent_component from an entity. -// -//===----------------------------------------------------------------------===// -inline ec::parent_component* -ec::entity_helpers::get_parent_component(entity *const entity_ptr) -{ - return get_component(entity_ptr); } \ No newline at end of file diff --git a/src/entity-component/system/graphics_system.cpp b/src/entity-component/system/graphics_system.cpp index 0959ad7..11832a2 100644 --- a/src/entity-component/system/graphics_system.cpp +++ b/src/entity-component/system/graphics_system.cpp @@ -11,17 +11,16 @@ // //===----------------------------------------------------------------------===// sf::Transform -check_scenegraph_transform(const ec::transform_component &transform, ec::entity *const entity_ptr) +scenegraph_transform(const ec::transform_component &transform, ec::entity *const parent_ptr) { using namespace ec; sf::Transform result = transform.getTransform(); - const auto parent_component_ptr = entity_helpers::get_parent_component(entity_ptr); // alias - if(parent_component_ptr == nullptr) { // entity is not a member of a scenegraph + if(parent_ptr == nullptr) { // entity is not a member of a scenegraph return result; } - const auto parent_transform_component = entity_helpers::get_transform_component(parent_component_ptr->parent_entity_ptr); + const auto parent_transform_component = entity_helpers::get_transform_component(parent_ptr); if(parent_transform_component == nullptr) { // parent component is not a member of a scenegraph //BOOST_LOG_TRIVIAL(warning) << "TODO: figure out if this should be a bug, or not." << std::endl; return result; @@ -47,6 +46,12 @@ ec::graphics_system::update_screen(ec::engine &engine) // draw everything here for(const auto entity_ptr : engine.Entities) { + + if(entity_ptr == nullptr) { // error + //BOOST_TRIVIAL_LOG(error) << "Error nullptr entity* in engine.Entities collection." << std::endl; + __debugbreak(); + } + const auto sprite_component_ptr = entity_helpers::get_sprite_component(entity_ptr); // alias const auto transform_component_ptr = entity_helpers::get_transform_component(entity_ptr); // alias @@ -60,7 +65,7 @@ ec::graphics_system::update_screen(ec::engine &engine) } // if entity_ptr is a member of a scenegraph, then multiply our transform with the parent's transform. - const sf::Transform transform = check_scenegraph_transform(*transform_component_ptr, entity_ptr); + const sf::Transform transform = scenegraph_transform(*transform_component_ptr, entity_ptr->Parent); //sprite_component_ptr->Sprite.setPosition(transform_component_ptr->getPosition()); //sprite_component_ptr->Sprite.setRotation(transform_component_ptr->getRotation()); From fad9081ceb6ea747cde40d7d04460c579256ff15 Mon Sep 17 00:00:00 2001 From: Benjamin Adamson Date: Wed, 15 May 2013 17:20:07 -0700 Subject: [PATCH 3/3] Renamed the transform component to something less confusing, since the entities are indeed NOT sharing transform components. --- src/Tetris/game.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Tetris/game.cpp b/src/Tetris/game.cpp index f17dd68..78d3afe 100644 --- a/src/Tetris/game.cpp +++ b/src/Tetris/game.cpp @@ -69,12 +69,10 @@ add_test_L_block_to_engine(ec::engine &engine, ec::entity *parent_entity_ptr, co spritecomponent_ptr->Sprite.setTexture(spritecomponent_ptr->Texture); e0->add_component(spritecomponent_ptr); - // the two entities are sharing the transform component - //const auto shared_transform_component_ptr = entity_helpers::get_transform_component(parent_entity_ptr); const component_factory transform_cfactory; - const auto shared_transform_component_ptr = transform_cfactory.get(); - shared_transform_component_ptr->move(offset); - e0->add_component(shared_transform_component_ptr); + const auto transform_component_ptr = transform_cfactory.get(); + transform_component_ptr->move(offset); + e0->add_component(transform_component_ptr); engine.Entities.emplace_back(e0); }