Skip to content

Commit

Permalink
squash!
Browse files Browse the repository at this point in the history
  • Loading branch information
bjadamson committed Oct 13, 2013
1 parent b9ab825 commit 8e087c3
Show file tree
Hide file tree
Showing 17 changed files with 232 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@
*.lai
*.la
*.a

# YCM files
*.ycm*

# Syntastic files
*.syntastic_cpp_config
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 10 additions & 0 deletions include/event/event.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef EVENT_EVENT_HPP_
#define EVENT_EVENT_HPP_
#include <SFML/Window/Event.hpp>
namespace event {
struct Event {
sf::Event event_;
};
} // namespace event

#endif // EVENT_EVENT_HPP_
36 changes: 36 additions & 0 deletions include/event/filter-inl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef EVENT_FILTER_INL_HPP_
#define EVENT_FILTER_INL_HPP_
#include <event/filter_source.hpp>
#include <event/handle.hpp>

using sf::Event::EventType;
using std::function;

namespace event {
//===----------------------------------------------------------------------===//
// Filter
//===----------------------------------------------------------------------===//
template<typename EventType>
Filter::Filter(HandleFactory const& hf) : handle_factory_(hf) {
}

template<typename EventType>
Handle Filter::register(void) {
return handle_factory_.build();
}

template<typename EventType>
void Filter::unregister(Handle const handle) {
// TODO(@anyone) implement.
}

template<typename EventType>
bool Filter::send_events(std::vector<Event> const events) const {
for (auto const& event : events) {
// TODO(@anyone) implement
}
return false;
}
} // namespace event

#endif // EVENT_FILTER_INL_HPP_
26 changes: 26 additions & 0 deletions include/event/filter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef EVENT_FILTER_HPP_
#define EVENT_FILTER_HPP_
#include "handle.hpp"
#include "event.hpp"
#include <vector>
namespace event {
struct HandleFactory;

struct Filter {
virtual ~Filter(void) { }
virtual bool send_events(std::vector<Event> const events) const = 0;
};

template<typename EventType>
struct EventFilter : public Filter {
EventFilter(HandleFactory const& hf);
Handle register_filter(void);
void unregister(Handle const handle);
bool send_events(std::vector<Event> const events) const;
private:
HandleFactory const& handle_factory_;
std::vector<Handle> handles_;
};

} // namespace event
#endif // EVENT_FILTER_HPP_
20 changes: 20 additions & 0 deletions include/event/handle.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef EVENT_HANDLE_HPP_
#define EVENT_HANDLE_HPP_
#include <cstdint>

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_
28 changes: 28 additions & 0 deletions include/event/system.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef EVENT_SYSTEM_HPP_
#define EVENT_SYSTEM_HPP_
#include "handle.hpp"
#include "filter.hpp"
#include <vector>

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<Filter> filters_;
};

} // namespace event

#endif // EVENT_SYSTEM_HPP_
1 change: 0 additions & 1 deletion include/test_include.hpp

This file was deleted.

8 changes: 7 additions & 1 deletion include/tetrisplosion.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#ifndef TETRISPLOSION_HPP_
#define TETRISPLOSION_HPP_

#include <SFML/Graphics.hpp>
#include <event/system.hpp>

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
Expand Down
5 changes: 4 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
10 changes: 10 additions & 0 deletions lib/event/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
8 changes: 8 additions & 0 deletions lib/event/event.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <event/event.hpp>
#include <stdexcept>

using Event = sf::Event::EventType;

namespace event {

} // namespace event
20 changes: 20 additions & 0 deletions lib/event/handle.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <event/handle.hpp>
#include <cstdint>

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
26 changes: 26 additions & 0 deletions lib/event/system.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <event/system.hpp>
#include <event/filter.hpp>
#include <event/event.hpp>
#include <stdexcept>
#include <vector>

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<Event> const empty_events;
bool const result = filter.send_events(empty_events);
}
(*/
//throw std::runtime_error("Unimplemented");
}

} // namespace event
22 changes: 0 additions & 22 deletions lib/test_lib.cxx

This file was deleted.

28 changes: 26 additions & 2 deletions lib/tetrisplosion.cxx
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
#include <tetrisplosion.hpp>
#include <window_config.hpp>

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();
}
*/
}

}

Expand Down
5 changes: 2 additions & 3 deletions src/main.cxx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <window_config.hpp>
#include <menu_config.hpp>
#include <tetrisplosion.hpp>
#include <test_include.hpp>

using tet::WindowConfig;
using tet::WindowWidth;
Expand All @@ -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;
}

0 comments on commit 8e087c3

Please sign in to comment.