From 5bccef1f4f2c7199fbf455eacc494b3e11e2ec69 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 1 Mar 2018 23:19:42 +0000 Subject: [PATCH] Add print statements to hopefully help with debugging. --- src/gamelib/collider.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/gamelib/collider.cpp b/src/gamelib/collider.cpp index 14613bb..e58b1de 100644 --- a/src/gamelib/collider.cpp +++ b/src/gamelib/collider.cpp @@ -60,8 +60,10 @@ namespace curry { const vec2f& parTo, const WorldGrid& parWorld ) { + std::cout << "---------------- collision test start --------------------\n"; const vec2f direction = parTo - parFrom; std::cout << "direction: " << direction << ' '; + std::cout << "src_tile=" << pixel_to_world_tile(parWorld, parFrom) << '\n'; if (direction == 0.0f) return parTo; @@ -69,24 +71,28 @@ namespace curry { const vec2us length = check_tiles_count(parObjectSize, direction); std::cout << "side_offset: " << side_offset << " length: " << length << '\n'; const vec2us dest_tile = pixel_to_world_tile(parWorld, parTo); - vec2us stop_at = pixel_to_world_tile(parWorld, parFrom); + const vec2f pix_side_offset = + make_pixel_side_offset(parWorld.tile_size(), side_offset, direction); + vec2us stop_at = pixel_to_world_tile(parWorld, parFrom + pix_side_offset); vec2f tile_relative_offs = parTo - world_tile_to_pixel(parWorld, dest_tile); assert(tile_relative_offs < vector_cast(parWorld.tile_size())); auto forward_callback = [=,&parWorld,&stop_at,&tile_relative_offs](vec2us tile) { - for (auto curr_pos : vwr::increasing_sequence_range(tile, tile + parObjectSize)) { + std::cout << "\t------------------- callback invoked ---------------\n"; + for (auto curr_pos : vwr::increasing_sequence_range(tile, tile + length)) { + std::cout << "\ttesting " << curr_pos << " (stop_at=" << stop_at << ", tile=" << tile << ")\n"; const bool walkable = parWorld.tile_property(parWorld.tile(curr_pos)).walkable; if (not walkable) { + std::cout << "\t*not* walkable!\n"; tile_relative_offs = vec2f(0.0f); return false; } } - stop_at = tile - side_offset; + stop_at = tile; + std::cout << "\tstop_at set to " << stop_at << " and returning from callback\n"; return true; }; - const vec2f pix_side_offset = - make_pixel_side_offset(parWorld.tile_size(), side_offset, direction); for_each_voxel_under_segment( parFrom + pix_side_offset, parTo + pix_side_offset, @@ -95,7 +101,12 @@ namespace curry { forward_callback, false ); + std::cout << "loop done\n"; + std::cout << "world_tile_to_pixel() = " << world_tile_to_pixel(parWorld, stop_at) << + " tile_relative_offs: " << tile_relative_offs << + " pix_side_offset: " << pix_side_offset << '\n'; + std::cout << "returning " << world_tile_to_pixel(parWorld, stop_at) + tile_relative_offs - pix_side_offset << '\n'; return world_tile_to_pixel(parWorld, stop_at) + tile_relative_offs - pix_side_offset; } } //namespace curry