Esempio n. 1
0
sanguis::creator::grid_crange
sanguis::collision::impl::make_range(
	sanguis::creator::grid const &_grid,
	sanguis::collision::center const _center,
	sanguis::collision::radius const _radius
)
{
	sanguis::creator::difference_type const tile_size(
		fcppt::cast::to_signed(
			sanguis::creator::tile_size::value
		)
	);

	sanguis::creator::min const lower(
		fcppt::container::grid::clamped_min(
			fcppt::math::vector::structure_cast<
				sanguis::creator::signed_pos,
				fcppt::cast::float_to_int_fun
			>(
				fcppt::math::vector::map(
					_center.get()
					-
					_radius.get()
					,
					fcppt::boost_units_value{}
				)
			)
			/
			tile_size
		)
	);

	sanguis::creator::sup const upper(
		fcppt::container::grid::clamped_sup_signed(
			fcppt::math::vector::ceil_div_signed(
				fcppt::math::vector::structure_cast<
					sanguis::creator::signed_pos,
					fcppt::cast::float_to_int_fun
				>(
					fcppt::math::vector::map(
						_center.get()
						+
						_radius.get()
						,
						fcppt::boost_units_value{}
					)
				),
				tile_size
			),
			_grid.size()
		)
	);

	return
		fcppt::container::grid::make_pos_ref_crange_start_end(
			_grid,
			lower,
			upper
		);
}
Esempio n. 2
0
sanguis::client::draw2d::scene::world::batch_grid
sanguis::client::draw2d::scene::world::generate_batches(
	fcppt::log::context &_log_context,
	sanguis::random_generator &_random_generator,
	sanguis::client::draw::debug const _debug,
	sanguis::creator::grid const &_grid,
	sanguis::creator::background_grid const &_background_grid,
	sanguis::client::load::tiles::context &_tiles,
	sanguis::client::draw2d::scene::world::sprite::buffers &_sprite_buffers
)
{
	sanguis::tiles::log const tiles_log{
		_log_context
	};

	sanguis::creator::pos const batch_dim_pos(
		fcppt::math::vector::fill<
			sanguis::creator::pos
		>(
			sanguis::client::draw2d::scene::world::batch_size::value
		)
	);

	return
		sanguis::client::draw2d::scene::world::batch_grid(
			fcppt::math::map<
				sanguis::creator::grid::dim
			>(
				_grid.size(),
				[](
					sanguis::creator::grid::dim::value_type const _value
				)
				{
					return
						fcppt::math::ceil_div(
							_value,
							fcppt::cast::size<
								sanguis::creator::grid::dim::value_type
							>(
								sanguis::client::draw2d::scene::world::batch_size::value
							)
						);
				}
			),
			[
				&_random_generator,
				_debug,
				&_grid,
				&_background_grid,
				&_tiles,
				&_sprite_buffers,
				batch_dim_pos,
				&tiles_log
			](
				sanguis::creator::pos const _pos
			)
			{
				sanguis::creator::min const min(
					_pos
					*
					batch_dim_pos
				);

				sanguis::creator::sup const sup(
					min.get()
					+
					batch_dim_pos
					+
					// TODO: Why?
					fcppt::math::vector::fill<
						sanguis::creator::pos
					>(
						1u
					)
				);

				sanguis::client::draw2d::scene::world::sprite::container sprites(
					fcppt::algorithm::map_optional<
						sanguis::client::draw2d::scene::world::sprite::container
					>(
						sanguis::tiles::draw(
							tiles_log,
							_grid,
							_background_grid,
							_tiles.collection(),
							min,
							sup
						),
						[
							&_random_generator,
							_debug,
							&_tiles
						](
							sanguis::tiles::cell const &_cell
						)
						{
							return
								sanguis::client::draw2d::scene::world::make_sprite(
									_random_generator,
									_debug,
									_tiles,
									_cell
								);
						}
					)
				);

				return
					sanguis::client::draw2d::scene::world::batch(
						sge::sprite::geometry::sort_and_update(
							sge::sprite::geometry::make_random_access_range(
								sprites
							),
							sanguis::client::draw2d::scene::world::sprite::compare(),
							_sprite_buffers
						)
					);
			}
		);
}