1
0
forked from 0ad/0ad

Fix and improve 001c411cc2.

This was SVN commit r18489.
This commit is contained in:
Nicolas Auvray 2016-07-05 20:23:12 +00:00
parent 05195d0692
commit ec2e2a84a4
2 changed files with 14 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2016 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -56,6 +56,15 @@ public:
CXeromyces::Terminate();
}
void test_namespace()
{
// Check that Pathfinding::NAVCELL_SIZE is actually an integer and that the definitions
// of Pathfinding::NAVCELL_SIZE_INT and Pathfinding::NAVCELL_SIZE_LOG2 match
TS_ASSERT_EQUALS(Pathfinding::NAVCELL_SIZE.ToInt_RoundToNegInfinity(), Pathfinding::NAVCELL_SIZE.ToInt_RoundToInfinity());
TS_ASSERT_EQUALS(Pathfinding::NAVCELL_SIZE.ToInt_RoundToNearest(), Pathfinding::NAVCELL_SIZE_INT);
TS_ASSERT_EQUALS((Pathfinding::NAVCELL_SIZE >> 1).ToInt_RoundToZero(), Pathfinding::NAVCELL_SIZE_LOG2);
}
void test_performance_DISABLED()
{
CTerrain terrain;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2015 Wildfire Games.
/* Copyright (C) 2016 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -144,11 +144,9 @@ namespace Pathfinding
*/
inline void NearestNavcell(entity_pos_t x, entity_pos_t z, u16& i, u16& j, u16 w, u16 h)
{
// x, z should be divided by NAVCELL_SIZE but that value happens to be 1 for now
// Since this is an i64 division and rather slow (10% of ComputeShortPath), cut it out
cassert(NAVCELL_SIZE_INT == 1);
i = (u16)clamp(x.ToInt_RoundToNegInfinity(), 0, w - 1);
j = (u16)clamp(z.ToInt_RoundToNegInfinity(), 0, h - 1);
// Use NAVCELL_SIZE_INT to save the cost of dividing by a fixed
i = (u16)clamp((x / NAVCELL_SIZE_INT).ToInt_RoundToNegInfinity(), 0, w - 1);
j = (u16)clamp((z / NAVCELL_SIZE_INT).ToInt_RoundToNegInfinity(), 0, h - 1);
}
/**