mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-17 01:32:21 +02:00
Lambda decltype on compile time instead of runtime
This commit is contained in:
committed by
Andrii Danylchenko
parent
3d2dc2335b
commit
c24fc89fe3
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include "../../lib/CModHandler.h"
|
#include "../../lib/CModHandler.h"
|
||||||
|
|
||||||
extern boost::thread_specific_ptr<CCallback> cb;
|
|
||||||
extern boost::thread_specific_ptr<AIGateway> ai;
|
extern boost::thread_specific_ptr<AIGateway> ai;
|
||||||
|
|
||||||
//extern static const int3 dirs[8];
|
//extern static const int3 dirs[8];
|
||||||
@ -161,55 +160,6 @@ bool HeroPtr::operator==(const HeroPtr & rhs) const
|
|||||||
return h == rhs.get(true);
|
return h == rhs.get(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void foreach_tile_pos(std::function<void(const int3 & pos)> foo)
|
|
||||||
{
|
|
||||||
// some micro-optimizations since this function gets called a LOT
|
|
||||||
// callback pointer is thread-specific and slow to retrieve -> read map size only once
|
|
||||||
int3 mapSize = cb->getMapSize();
|
|
||||||
for(int i = 0; i < mapSize.x; i++)
|
|
||||||
{
|
|
||||||
for(int j = 0; j < mapSize.y; j++)
|
|
||||||
{
|
|
||||||
for(int k = 0; k < mapSize.z; k++)
|
|
||||||
foo(int3(i, j, k));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void foreach_tile_pos(CCallback * cbp, std::function<void(CCallback * cbp, const int3 & pos)> foo)
|
|
||||||
{
|
|
||||||
int3 mapSize = cbp->getMapSize();
|
|
||||||
for(int i = 0; i < mapSize.x; i++)
|
|
||||||
{
|
|
||||||
for(int j = 0; j < mapSize.y; j++)
|
|
||||||
{
|
|
||||||
for(int k = 0; k < mapSize.z; k++)
|
|
||||||
foo(cbp, int3(i, j, k));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void foreach_neighbour(const int3 & pos, std::function<void(const int3 & pos)> foo)
|
|
||||||
{
|
|
||||||
CCallback * cbp = cb.get(); // avoid costly retrieval of thread-specific pointer
|
|
||||||
for(const int3 & dir : int3::getDirs())
|
|
||||||
{
|
|
||||||
const int3 n = pos + dir;
|
|
||||||
if(cbp->isInTheMap(n))
|
|
||||||
foo(pos + dir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void foreach_neighbour(CCallback * cbp, const int3 & pos, std::function<void(CCallback * cbp, const int3 & pos)> foo)
|
|
||||||
{
|
|
||||||
for(const int3 & dir : int3::getDirs())
|
|
||||||
{
|
|
||||||
const int3 n = pos + dir;
|
|
||||||
if(cbp->isInTheMap(n))
|
|
||||||
foo(cbp, pos + dir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CDistanceSorter::operator()(const CGObjectInstance * lhs, const CGObjectInstance * rhs) const
|
bool CDistanceSorter::operator()(const CGObjectInstance * lhs, const CGObjectInstance * rhs) const
|
||||||
{
|
{
|
||||||
const CGPathNode * ln = ai->myCb->getPathsInfo(hero)->getPathInfo(lhs->visitablePos());
|
const CGPathNode * ln = ai->myCb->getPathsInfo(hero)->getPathInfo(lhs->visitablePos());
|
||||||
|
@ -69,6 +69,8 @@ const int ALLOWED_ROAMING_HEROES = 8;
|
|||||||
extern const float SAFE_ATTACK_CONSTANT;
|
extern const float SAFE_ATTACK_CONSTANT;
|
||||||
extern const int GOLD_RESERVE;
|
extern const int GOLD_RESERVE;
|
||||||
|
|
||||||
|
extern boost::thread_specific_ptr<CCallback> cb;
|
||||||
|
|
||||||
enum HeroRole
|
enum HeroRole
|
||||||
{
|
{
|
||||||
SCOUT = 0,
|
SCOUT = 0,
|
||||||
@ -197,10 +199,58 @@ struct creInfo
|
|||||||
};
|
};
|
||||||
creInfo infoFromDC(const dwellingContent & dc);
|
creInfo infoFromDC(const dwellingContent & dc);
|
||||||
|
|
||||||
void foreach_tile_pos(std::function<void(const int3 & pos)> foo);
|
template<class Func>
|
||||||
void foreach_tile_pos(CCallback * cbp, std::function<void(CCallback * cbp, const int3 & pos)> foo); // avoid costly retrieval of thread-specific pointer
|
void foreach_tile_pos(const Func & foo)
|
||||||
void foreach_neighbour(const int3 & pos, std::function<void(const int3 & pos)> foo);
|
{
|
||||||
void foreach_neighbour(CCallback * cbp, const int3 & pos, std::function<void(CCallback * cbp, const int3 & pos)> foo); // avoid costly retrieval of thread-specific pointer
|
// some micro-optimizations since this function gets called a LOT
|
||||||
|
// callback pointer is thread-specific and slow to retrieve -> read map size only once
|
||||||
|
int3 mapSize = cb->getMapSize();
|
||||||
|
for(int i = 0; i < mapSize.x; i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < mapSize.y; j++)
|
||||||
|
{
|
||||||
|
for(int k = 0; k < mapSize.z; k++)
|
||||||
|
foo(int3(i, j, k));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Func>
|
||||||
|
void foreach_tile_pos(CCallback * cbp, const Func & foo) // avoid costly retrieval of thread-specific pointer
|
||||||
|
{
|
||||||
|
int3 mapSize = cbp->getMapSize();
|
||||||
|
for(int i = 0; i < mapSize.x; i++)
|
||||||
|
{
|
||||||
|
for(int j = 0; j < mapSize.y; j++)
|
||||||
|
{
|
||||||
|
for(int k = 0; k < mapSize.z; k++)
|
||||||
|
foo(cbp, int3(i, j, k));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Func>
|
||||||
|
void foreach_neighbour(const int3 & pos, const Func & foo)
|
||||||
|
{
|
||||||
|
CCallback * cbp = cb.get(); // avoid costly retrieval of thread-specific pointer
|
||||||
|
for(const int3 & dir : int3::getDirs())
|
||||||
|
{
|
||||||
|
const int3 n = pos + dir;
|
||||||
|
if(cbp->isInTheMap(n))
|
||||||
|
foo(pos + dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class Func>
|
||||||
|
void foreach_neighbour(CCallback * cbp, const int3 & pos, const Func & foo) // avoid costly retrieval of thread-specific pointer
|
||||||
|
{
|
||||||
|
for(const int3 & dir : int3::getDirs())
|
||||||
|
{
|
||||||
|
const int3 n = pos + dir;
|
||||||
|
if(cbp->isInTheMap(n))
|
||||||
|
foo(cbp, pos + dir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool canBeEmbarkmentPoint(const TerrainTile * t, bool fromWater);
|
bool canBeEmbarkmentPoint(const TerrainTile * t, bool fromWater);
|
||||||
bool isObjectPassable(const CGObjectInstance * obj);
|
bool isObjectPassable(const CGObjectInstance * obj);
|
||||||
|
Reference in New Issue
Block a user