| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- //
- // 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"
- #include "game/util/env.hpp"
- using namespace engine;
- scene::scene(std::string const & str, math::vec2 const & bounds,
- std::shared_ptr<game_dispatch> dispatch)
- : identity<scene, std::string>(str), local_bounds_(bounds),
- renderer_(dispatch->make_renderer(size())), dispatch_(dispatch) {}
- scene::~scene() {}
- bool scene::in_bounds(math::dim2::point const & p) const {
- return math::between(p[0], 0.f, local_bounds_[0]) &&
- math::between(p[1], 0.f, local_bounds_[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 (ent == hit) continue;
- 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) {
- // TODO (sjaffe): Handle quit binding correctly... (don't test this)
- 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_bounds_ == math::vec2()) ? math::vec2(env::screen_size())
- : local_bounds_;
- }
- key_binding const & scene::keys() const { return keys_; }
|