diff --git a/.gitignore b/.gitignore index 620d3dc..974f0cf 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,9 @@ *.lai *.la *.a + +# YCM files +*.ycm* + +# Syntastic files +*.syntastic_cpp_config diff --git a/CMakeLists.txt b/CMakeLists.txt index 4781c61..377fbbf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,10 +21,11 @@ endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux") include_directories(${SFML_INCLUDE_DIR}) include_directories(./include) +# Direct that an execuable tetrisplosion should be built using main.cxx) +add_executable(tetrisplosion src/main.cxx) + # List of subdirectories to run cmake on add_subdirectory(lib) add_subdirectory(extlibs) # managing all external libraries. -# Direct that an execuable tetrisplosion should be built using main.cxx) -add_executable(tetrisplosion src/main.cxx) target_link_libraries(tetrisplosion tetrisplosion_lib) diff --git a/include/event/event.hpp b/include/event/event.hpp new file mode 100644 index 0000000..a162126 --- /dev/null +++ b/include/event/event.hpp @@ -0,0 +1,10 @@ +#ifndef EVENT_EVENT_HPP_ +#define EVENT_EVENT_HPP_ +#include +namespace event { + struct Event { + sf::Event event_; + }; +} // namespace event + +#endif // EVENT_EVENT_HPP_ diff --git a/include/event/filter-inl.hpp b/include/event/filter-inl.hpp new file mode 100644 index 0000000..5826109 --- /dev/null +++ b/include/event/filter-inl.hpp @@ -0,0 +1,36 @@ +#ifndef EVENT_FILTER_INL_HPP_ +#define EVENT_FILTER_INL_HPP_ +#include +#include + +using sf::Event::EventType; +using std::function; + +namespace event { +//===----------------------------------------------------------------------===// +// Filter +//===----------------------------------------------------------------------===// +template +Filter::Filter(HandleFactory const& hf) : handle_factory_(hf) { +} + +template +Handle Filter::register(void) { + return handle_factory_.build(); +} + +template +void Filter::unregister(Handle const handle) { + // TODO(@anyone) implement. +} + +template +bool Filter::send_events(std::vector const events) const { + for (auto const& event : events) { + // TODO(@anyone) implement + } + return false; +} +} // namespace event + +#endif // EVENT_FILTER_INL_HPP_ diff --git a/include/event/filter.hpp b/include/event/filter.hpp new file mode 100644 index 0000000..444e678 --- /dev/null +++ b/include/event/filter.hpp @@ -0,0 +1,26 @@ +#ifndef EVENT_FILTER_HPP_ +#define EVENT_FILTER_HPP_ +#include "handle.hpp" +#include "event.hpp" +#include +namespace event { +struct HandleFactory; + +struct Filter { + virtual ~Filter(void) { } + virtual bool send_events(std::vector const events) const = 0; +}; + +template +struct EventFilter : public Filter { + EventFilter(HandleFactory const& hf); + Handle register_filter(void); + void unregister(Handle const handle); + bool send_events(std::vector const events) const; + private: + HandleFactory const& handle_factory_; + std::vector handles_; +}; + +} // namespace event +#endif // EVENT_FILTER_HPP_ diff --git a/include/event/handle.hpp b/include/event/handle.hpp new file mode 100644 index 0000000..da65bae --- /dev/null +++ b/include/event/handle.hpp @@ -0,0 +1,20 @@ +#ifndef EVENT_HANDLE_HPP_ +#define EVENT_HANDLE_HPP_ +#include + +namespace event { +class Handle { + friend class HandleFactory; + explicit Handle(uint64_t const id); + uint64_t const id_; +}; + +struct HandleFactory { + HandleFactory(void); + Handle Build(void); + private: + uint64_t index_; +}; +} // namespace event_ + +#endif // EVENT_HANDLE_HPP_ diff --git a/include/event/system.hpp b/include/event/system.hpp new file mode 100644 index 0000000..7c6113f --- /dev/null +++ b/include/event/system.hpp @@ -0,0 +1,28 @@ +#ifndef EVENT_SYSTEM_HPP_ +#define EVENT_SYSTEM_HPP_ +#include "handle.hpp" +#include "filter.hpp" +#include + +namespace sf { +class Window; +} // namespace sf + +namespace event { +struct System { + virtual void add_filter(Filter &&f) = 0; + virtual void enumerate(void) const = 0; +}; + +struct SfmlSystem : public System { + SfmlSystem(sf::Window &window); + virtual void add_filter(Filter &&f) override; + virtual void enumerate(void) const override; + private: + sf::Window &window_; + std::vector filters_; +}; + +} // namespace event + +#endif // EVENT_SYSTEM_HPP_ diff --git a/include/test_include.hpp b/include/test_include.hpp deleted file mode 100644 index 0f6cb37..0000000 --- a/include/test_include.hpp +++ /dev/null @@ -1 +0,0 @@ -void test_fn(void); diff --git a/include/tetrisplosion.hpp b/include/tetrisplosion.hpp index 3896de5..9bf7f89 100644 --- a/include/tetrisplosion.hpp +++ b/include/tetrisplosion.hpp @@ -1,14 +1,20 @@ #ifndef TETRISPLOSION_HPP_ #define TETRISPLOSION_HPP_ +#include +#include + namespace tet { struct WindowConfig; struct MenuConfig; struct Tetrisplosion { Tetrisplosion(WindowConfig const& wc, MenuConfig const& mc); + int run(void); private: - WindowConfig const& wc_; + //WindowConfig const& wc_; MenuConfig const& mc_; + sf::RenderWindow window_; + event::SfmlSystem event_system_; }; } // namespace tet diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index d706f4d..d44482a 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -4,9 +4,12 @@ set (SRCROOT ${PROJECT_SOURCE_DIR}/lib) set(SRC ${SRCROOT}/tetrisplosion.cxx ${SRCROOT}/window_config.cxx - ${SRCROOT}/test_lib.cxx ) source_group("" FILES ${SRC}) add_library(tetrisplosion_lib ${SRC}) + +add_subdirectory(event) +target_link_libraries(tetrisplosion_lib event_lib) + find_package(SFML 2.1 COMPONENTS system window graphics network audio REQUIRED) target_link_libraries(tetrisplosion_lib ${SFML_LIBRARIES}) diff --git a/lib/event/CMakeLists.txt b/lib/event/CMakeLists.txt new file mode 100644 index 0000000..e6a354a --- /dev/null +++ b/lib/event/CMakeLists.txt @@ -0,0 +1,10 @@ +set (SRCROOT ${PROJECT_SOURCE_DIR}/lib/event) + +# list of source files +set(SRC + ${SRCROOT}/event.cxx + ${SRCROOT}/handle.cxx + ${SRCROOT}/system.cxx + ) +source_group("" FILES ${SRC}) +add_library(event_lib ${SRC}) diff --git a/lib/event/event.cxx b/lib/event/event.cxx new file mode 100644 index 0000000..da73973 --- /dev/null +++ b/lib/event/event.cxx @@ -0,0 +1,8 @@ +#include +#include + +using Event = sf::Event::EventType; + +namespace event { + +} // namespace event diff --git a/lib/event/handle.cxx b/lib/event/handle.cxx new file mode 100644 index 0000000..6be2d9c --- /dev/null +++ b/lib/event/handle.cxx @@ -0,0 +1,20 @@ +#include +#include + +namespace event { +//===----------------------------------------------------------------------===// +// Handle +//===----------------------------------------------------------------------===// +Handle::Handle(uint64_t const id) : id_(id) { +} + +//===----------------------------------------------------------------------===// +// HandleFactory +//===----------------------------------------------------------------------===// +HandleFactory::HandleFactory(void) : index_(0U) { +} + +Handle HandleFactory::Build(void) { + return Handle(index_++); +} +} // namespace event diff --git a/lib/event/system.cxx b/lib/event/system.cxx new file mode 100644 index 0000000..5436f88 --- /dev/null +++ b/lib/event/system.cxx @@ -0,0 +1,26 @@ +#include +#include +#include +#include +#include + +using Event = sf::Event::EventType; + +namespace event { +SfmlSystem::SfmlSystem(sf::Window &window) : window_(window) { +} + +void SfmlSystem::add_filter(Filter &&f) { + filters_.push_back(f); +} + +void SfmlSystem::enumerate(void) const { + /*for (auto const& filter : filters_) { + std::vector const empty_events; + bool const result = filter.send_events(empty_events); + } +(*/ + //throw std::runtime_error("Unimplemented"); +} + +} // namespace event diff --git a/lib/test_lib.cxx b/lib/test_lib.cxx deleted file mode 100644 index e7487f4..0000000 --- a/lib/test_lib.cxx +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include -#include - -void test_fn(void) { - std::cout << "test_fn()" << std::endl; - sf::RenderWindow test(sf::VideoMode(800, 600), "TestProject"); - - sf::CircleShape shape(50); - shape.setFillColor(sf::Color(150, 100, 255)); - - while (test.isOpen()) { - sf::Event event; - while(test.pollEvent(event)) { - if (event.type == sf::Event::Closed) { - test.close(); - } - test.draw(shape); - test.display(); - } - } -} diff --git a/lib/tetrisplosion.cxx b/lib/tetrisplosion.cxx index 5c47432..e672bdc 100644 --- a/lib/tetrisplosion.cxx +++ b/lib/tetrisplosion.cxx @@ -1,9 +1,33 @@ #include +#include -namespace tet { +using event::System; +namespace tet { Tetrisplosion::Tetrisplosion(WindowConfig const& wc, MenuConfig const& mc) - : wc_(wc), mc_(mc) { + : mc_(mc), window_(sf::VideoMode(wc.width.get(), wc.height.get()), wc.title.get()), + event_system_(window_) { +} + +int Tetrisplosion::run(void) { + sf::CircleShape shape(150); + shape.setFillColor(sf::Color(80, 80, 150)); + + while(window_.isOpen()) { + event_system_.enumerate(); + window_.draw(shape); + window_.display(); + + /*sf::Event event; + while(window_.pollEvent(event)) { + if (event.type == sf::Event::Closed) { + window_.close(); + } + window_.draw(shape); + window_.display(); + } + */ + } } diff --git a/src/main.cxx b/src/main.cxx index b7012fe..dacacc0 100644 --- a/src/main.cxx +++ b/src/main.cxx @@ -1,7 +1,6 @@ #include #include #include -#include using tet::WindowConfig; using tet::WindowWidth; @@ -18,7 +17,7 @@ int main(int argc, char *agv[]) WindowConfig const window_config(width, height, title); MenuConfig const menu_config; - Tetrisplosion const tetrisplosion(window_config, menu_config); - test_fn(); + Tetrisplosion tetrisplosion(window_config, menu_config); + tetrisplosion.run(); return 0; }