|
|
|
@ -7,7 +7,7 @@ |
|
|
|
|
using DinkyECS::Entity; |
|
|
|
|
using namespace fmt; |
|
|
|
|
|
|
|
|
|
FoundList require_found(const SpatialHashTable& collider, Point at, bool diag, size_t expect_size) { |
|
|
|
|
EntityList require_found(const spatial_map& collider, Point at, bool diag, size_t expect_size) { |
|
|
|
|
println("TEST require_found at={},{}", at.x, at.y); |
|
|
|
|
auto [found, nearby] = collider.neighbors(at, diag); |
|
|
|
|
REQUIRE(found == true); |
|
|
|
@ -21,7 +21,7 @@ TEST_CASE("confirm basic collision operations", "[collision]") { |
|
|
|
|
Entity player = world.entity(); |
|
|
|
|
Entity enemy = world.entity(); |
|
|
|
|
|
|
|
|
|
SpatialHashTable collider; |
|
|
|
|
spatial_map collider; |
|
|
|
|
collider.insert({11,11}, player); |
|
|
|
|
collider.insert({21,21}, enemy); |
|
|
|
|
|
|
|
|
@ -32,7 +32,7 @@ TEST_CASE("confirm basic collision operations", "[collision]") { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// found
|
|
|
|
|
FoundList nearby = require_found(collider, {10,10}, true, 1); |
|
|
|
|
EntityList nearby = require_found(collider, {10,10}, true, 1); |
|
|
|
|
REQUIRE(nearby[0] == player); |
|
|
|
|
|
|
|
|
|
{ // removed
|
|
|
|
@ -68,13 +68,13 @@ TEST_CASE("confirm multiple entities moving", "[collision]") { |
|
|
|
|
Entity e2 = world.entity(); |
|
|
|
|
Entity e3 = world.entity(); |
|
|
|
|
|
|
|
|
|
SpatialHashTable collider; |
|
|
|
|
spatial_map collider; |
|
|
|
|
collider.insert({11,11}, player); |
|
|
|
|
collider.insert({10,10}, e2); |
|
|
|
|
collider.insert({11,10}, e3); |
|
|
|
|
collider.insert({21,21}, e1); |
|
|
|
|
|
|
|
|
|
FoundList nearby = require_found(collider, {11,11}, false, 1); |
|
|
|
|
EntityList nearby = require_found(collider, {11,11}, false, 1); |
|
|
|
|
REQUIRE(nearby[0] == e3); |
|
|
|
|
|
|
|
|
|
nearby = require_found(collider, {11,11}, true, 2); |
|
|
|
@ -91,13 +91,13 @@ TEST_CASE("test edge cases that might crash", "[collision]") { |
|
|
|
|
Entity player = world.entity(); |
|
|
|
|
Entity enemy = world.entity(); |
|
|
|
|
|
|
|
|
|
SpatialHashTable collider; |
|
|
|
|
spatial_map collider; |
|
|
|
|
collider.insert({0,0}, player); |
|
|
|
|
|
|
|
|
|
Point enemy_at = {1, 0}; |
|
|
|
|
collider.insert(enemy_at, enemy); |
|
|
|
|
|
|
|
|
|
FoundList nearby = require_found(collider, {0,0}, true, 1); |
|
|
|
|
EntityList nearby = require_found(collider, {0,0}, true, 1); |
|
|
|
|
|
|
|
|
|
collider.move({1,0}, {1,1}, enemy); |
|
|
|
|
nearby = require_found(collider, {0,0}, true, 1); |
|
|
|
@ -113,7 +113,7 @@ TEST_CASE("check all diagonal works", "[collision]") { |
|
|
|
|
Entity player = world.entity(); |
|
|
|
|
Entity enemy = world.entity(); |
|
|
|
|
|
|
|
|
|
SpatialHashTable collider; |
|
|
|
|
spatial_map collider; |
|
|
|
|
Point player_at = {1,1}; |
|
|
|
|
collider.insert(player_at, player); |
|
|
|
|
|
|
|
|
@ -123,7 +123,7 @@ TEST_CASE("check all diagonal works", "[collision]") { |
|
|
|
|
for(size_t x = 0; x <= 2; x++) { |
|
|
|
|
for(size_t y = 0; y <= 2; y++) { |
|
|
|
|
if(enemy_at.x == player_at.x && enemy_at.y == player_at.y) continue; // skip player spot
|
|
|
|
|
FoundList nearby = require_found(collider, player_at, true, 1); |
|
|
|
|
EntityList nearby = require_found(collider, player_at, true, 1); |
|
|
|
|
REQUIRE(nearby[0] == enemy); |
|
|
|
|
|
|
|
|
|
// move the enemy to a new spot around the player
|
|
|
|
|