Exemple #1
0
 rect(point2d<U> const p, V const w, V const h)
     : left(p.x)
     , top(p.y)
     , right(p.x + w)
     , bottom(p.y + h)
 {
     BK_ASSERT(w > static_cast<T>(0));
     BK_ASSERT(h > static_cast<T>(0));
 }
Exemple #2
0
    auto const& get_definition_at(int const index) const {
        BK_ASSERT(index < get_definitions_size());

        auto it = definitions_.begin();
        std::advance(it, index);
        return it->second;
    }
		void
		stop( const string &id )
		{
			OpenALData *data = m_buffers[ id ];
			BK_ASSERT( data != NULL, "nothing with the given id " << id << " could be found!" );
			alSourceStop( data->m_source );
		}
Exemple #4
0
inline T get_integer(cref json_value,
    typename std::enable_if<
        std::is_signed<T>::value && !std::is_same<T, int64_t>::value
    >::type* = 0
) {
    BK_ASSERT(json_value.isIntegral());
    return truncate_cast<T>(json_value.asInt());
}
		void
		setLoop( const string &id, bool loop )
		{
			OpenALData *data = m_buffers[ id ];
			BK_ASSERT( data != NULL, "nothing with the given id " << id << " could be found!" );

			alSourcei( data->m_source, AL_LOOPING, loop );
		}
		void
		play( const string &id, int from, int to )
		{
			OpenALData *data = m_buffers[ id ];
			BK_ASSERT( data != NULL, "nothing with the given id " << id << " could be found!" );

			alSourcei( data->m_source, AL_SEC_OFFSET, from );
			alSourcePlay( data->m_source );
		}
		void
		setDirection( const string &id, const vec3<float> &dir )
		{
			OpenALData *data = m_buffers[ id ];
			BK_ASSERT( data != NULL, "nothing with the given id " << id << " could be found!" );

			ALfloat _dir[]{ dir[BK_X], dir[BK_Y], dir[BK_Z] };
			alSourcefv( data->m_source, AL_DIRECTION, _dir );
		}
		void
		setPosition( const string &id, const vec3<float> &pos )
		{
			OpenALData *data = m_buffers[ id ];
			BK_ASSERT( data != NULL, "nothing with the given id " << id << " could be found!" );

			ALfloat _pos[]{ pos[BK_X], pos[BK_Y], pos[BK_Z] };
			alSourcefv( data->m_source, AL_POSITION, _pos );
		}
		void
		setVolume( const string &id, const float volume )
		{
			OpenALData *data = m_buffers[ id ];
			BK_ASSERT( data != NULL, "nothing with the given id " << id << " could be found!" );

			data->m_gain = volume;
			alSourcef( data->m_source, AL_GAIN, volume * m_gainFactor );
		}
Exemple #10
0
//==============================================================================
//! Return a direction vector for d.
//==============================================================================
inline std::pair<signed, signed> direction_vector(direction const d) {
    typedef std::underlying_type<direction>::type type;

    auto const i = static_cast<type>(d);

    BK_ASSERT(i < static_cast<type>(direction::up));

    BK_DECLARE_DIRECTION_ARRAYS(xd, yd);
    return std::make_pair(xd[i], yd[i]);
}
Exemple #11
0
bkrl::equipment::result_t
bkrl::player::equip_item(item_id iid, defs_t defs, items_t istore) {
    auto const try_equip = equip_.equip(iid, defs, istore);
    if (!try_equip.second) {
        return try_equip;
    }

    auto const result = items().remove(iid);
    BK_ASSERT(result == true);

    return try_equip;
}
Exemple #12
0
void tez::path_generator::write_path(map& out) {
    BK_ASSERT(path_.size() >= 2);
 
    for (size_t i = 1; i < path_.size() - 1; ++i) {
        auto& tile = out.at(path_[i].x, path_[i].y);
        tile.type = tile_category::corridor;
    }

    auto& first = out.at(path_.front().x, path_.front().y);
    auto& last  = out.at(path_.back().x, path_.back().y);

    first.type = last.type = tile_category::door;
    first.get_data<door_data>().state = door_data::door_state::open;
    last.get_data<door_data>().state  = door_data::door_state::closed;

    path_.clear();
}
		void
		loadFile( const string &path, const string &id )
		{
			BK_ASSERT( m_buffers.count( id ) == 0, "id " << id << " must be unique in the collection!" );

			ALuint buffer = alutCreateBufferFromFile( path.c_str() );
			ALuint source;

			alGenSources( 1, &source );
			alSourcei( source, AL_BUFFER, buffer );

			OpenALData *data = new OpenALData();

			data->m_id      =  id;
			data->m_path    =  path;
			data->m_buffer  =  buffer;
			data->m_source  =  source;

			m_buffers[ id ] = data;
		}
Exemple #14
0
bool tez::path_generator::generate(
    tez::room const& origin,
    tez::map  const& map,
    direction const  dir
) {
    typedef room::connection_point point_t;

    static unsigned const MAX_PATH_FAILURES       = 5;
    static unsigned const MAX_FIND_START_FAILURES = 5;
    
    auto const temp = origin.bounds();
    BK_ASSERT(temp.left >= 0);
    BK_ASSERT(temp.top >= 0);
    auto const bounds = static_cast<bklib::rect<unsigned>>(temp);

    BK_DECLARE_DIRECTION_ARRAYS(dir_x, dir_y);
    //--------------------------------------------------------------------------
    // Get a random unit vector
    //--------------------------------------------------------------------------    
    auto const get_random_vector = [&](distribution_t const& dist) {
        auto const i = dist(random_);
        return bklib::make_point(dir_x[i], dir_y[i]);
    };
    //--------------------------------------------------------------------------
    auto const is_pathable = [](tile_category const type) {
        return (type == tile_category::corridor) ||
               (type == tile_category::empty);
    };
    //--------------------------------------------------------------------------
    auto const is_connectable = [&](map::const_block const block) -> bool {
        auto const get = [](tile_data const* tile) {
            return tile ? tile->type : tile_category::empty;
        };

        static auto const CEIL  = tile_category::ceiling;
        static auto const FLOOR = tile_category::floor;
        static auto const WALL  = tile_category::wall;

        if (get(block.here()) != CEIL) {
            return false;
        }

        auto const n = get(block.north());
        auto const s = get(block.south());
        auto const e = get(block.east());
        auto const w = get(block.west());

        return (n == CEIL && s == CEIL && (e == FLOOR || w == FLOOR)) ||
               (e == CEIL && w == CEIL && (n == FLOOR || s == WALL));
    };
    //--------------------------------------------------------------------------
    auto const is_on_path = [&](point_t const p) {
        return path_.cend() != std::find_if(
            path_.cbegin(),
            path_.cend(), [&](point_t const q) { return p == q; }
        );
    };
    //--------------------------------------------------------------------------
    auto const is_in_origin = [&](point_t const p) {
        return bklib::intersects(bounds, p);
    };
    //--------------------------------------------------------------------------
    auto const find_path_start = [&]() -> std::pair<bool, point_t> {
        auto const check = [](tile_data const* tile) {
            return tile ? tile->type != tile_category::door : true;
        };

        for (unsigned i = 0; i < MAX_FIND_START_FAILURES; ++i) {
            auto const  p     = origin.find_connection_point(dir, random_);           
            auto const  type  = map.at(p).type;
            auto const& block = map.block_at(p);
                 
            if ((type == tile_category::ceiling) &&
                check(block.north()) && check(block.south()) &&
                check(block.east())  && check(block.west())
            ) {
                return std::make_pair(true, p);
            }
        }
        
        return std::make_pair(false, room::connection_point(0, 0));
    };
    //--------------------------------------------------------------------------
    auto const path_start = find_path_start();
    if (!path_start.first) {
        return false;
    }
    
    auto pos = path_start.second;

    distribution_t const& dist =
        (dir == direction::north ) ? path_prob_n :
        (dir == direction::south ) ? path_prob_s :
        (dir == direction::east )  ? path_prob_e :
        (dir == direction::west )  ? path_prob_w : path_prob_w;

    path_.clear();
    path_.push_back(pos);

    bool found_path = false;

    for (unsigned i = 1; !found_path && i < MAX_FIND_START_FAILURES; ++i) {
        auto const p = bklib::translate_by(pos, get_random_vector(dist));

        if (!map.is_valid_position(p)) {
            continue;
        } else if (!is_pathable(map.at(p).type)) {
            if (is_in_origin(p)) {
                continue;
            } else if (!is_connectable(map.block_at(p))) {
                continue;
            } else if (is_on_path(p)) {
                continue;
            } else {
                found_path = true;
            }
        }

        path_.emplace_back((pos = p));
        i--;
    }

    return found_path && path_.size() >= 2;
}
Exemple #15
0
void entity::detach(level& level) {
    BK_ASSERT(level_ == &level);

    level_ = nullptr;
}
Exemple #16
0
void entity::attach(level& level) {
    BK_ASSERT(level_ != &level);
    level_ = &level;
}
Exemple #17
0
T get_integer(cref value,
    typename std::enable_if<std::is_same<T, int64_t>::value>::type* = 0
) {
    BK_ASSERT(value.isIntegral());
    return value.asInt64();
}