| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //
- // scene.cpp
- // engine
- //
- // Created by Sam Jaffe on 9/2/16.
- //
- #include "game/engine/scene.hpp"
- #include "game/engine/entity.hpp"
- #include "game/engine/events.hpp"
- #include "game/engine/game_dispatch.hpp"
- #include "game/graphics/renderer.hpp"
- #include "game/math/common.hpp"
- #include "game/math/compare.hpp"
- using namespace engine;
- scene::scene(std::string const & str, std::shared_ptr<game_dispatch> dispatch)
- : identity<scene, std::string>(str), dispatch_(dispatch) {}
- scene::~scene() {}
- bool scene::in_bounds(math::dim2::point p) const {
- return math::between(p[0], 0.f, local_scene_dimension_[0]) &&
- math::between(p[1], 0.f, local_scene_dimension_[1]);
- }
- bool scene::in_bounds(collidable * c) const {
- auto & quad = c->render_info().points;
- return in_bounds(quad.ll) || in_bounds(quad.lr) || in_bounds(quad.ur) ||
- in_bounds(quad.ul);
- }
- void scene::check_collisions(std::vector<collidable *> const & from,
- std::vector<collidable *> const & to) {
- for (auto & ent : from) {
- for (auto & hit : to) {
- if (math::intersects(ent->render_info().points,
- hit->render_info().points)) {
- ent->collide(*hit);
- }
- }
- }
- }
- void scene::check_collisions() {
- for (auto & pair : colliders) {
- check_collisions(pair.second, collidables[pair.first]);
- }
- }
- // void scene::update(float delta) {
- // for (auto & ent : entities) {
- // ent.update(delta);
- // }
- // check_collisions();
- //}
- //
- // void scene::render(graphics::renderer & renderer) {
- // for (auto & ent : entities) {
- // renderer.draw(ent.render_info());
- // }
- //}
- graphics::manager const & scene::graphics_manager() const {
- return dispatch_.lock()->graphics_manager();
- }
- void scene::handle_key_event(event::key_event evt) {
- if (evt.type & event::PRESSED_MASK && evt.key == keys::QUIT) {
- dispatch_.lock()->quit();
- }
- }
- void scene::handle_mouse_event(event::mouse_event evt) {}
- math::vec2 scene::size() const { return local_scene_dimension_; }
- key_binding const & scene::keys() const { return keys_; }
|