hkvTriSampledHeightFieldCollection::hkvTriSampledHeightFieldCollection(const VTerrainSector *pSector, const hkpSampledHeightFieldShape *pShape) 
  : hkpTriSampledHeightFieldCollection(pShape), m_tileHoleMask(16*16, hkBitFieldValue::UNINITIALIZED)
{
#ifdef SUPPORTS_TERRAIN
  // these are the two possible return values
  m_iCollide = hkpGroupFilter::calcFilterInfo(vHavokPhysicsModule::HK_LAYER_COLLIDABLE_TERRAIN);
  m_iNonCollide = hkpGroupFilter::calcFilterInfo(vHavokPhysicsModule::HK_LAYER_COLLIDABLE_TERRAIN_HOLE);

  // build a bitmask from all terrain tiles so we can perform a fast lookup in getCollisionFilterInfoImpl
  const VTerrainConfig &cfg(pSector->m_Config);
  m_iStrideX = cfg.m_iTilesPerSector[0];
  m_tileHoleMask.setSizeAndFill(0, cfg.m_iTilesPerSector[0]*cfg.m_iTilesPerSector[1], 0);
  int iBit = 0;
  for (int y=0;y<cfg.m_iTilesPerSector[1];y++)
    for (int x=0;x<cfg.m_iTilesPerSector[0];x++,iBit++)
    {
      if (pSector->GetTile(x,cfg.m_iTilesPerSector[1]-1-y)->IsHole())
        m_tileHoleMask.set(iBit);
      else
        m_tileHoleMask.clear(iBit);
    }

  // since both values are power of two, we can store the result as a bit-index for even faster processing in getCollisionFilterInfoImpl
  m_iTileSamplesX = GetLog2(cfg.m_iHeightSamplesPerSector[0] / cfg.m_iTilesPerSector[0]);
  m_iTileSamplesY = GetLog2(cfg.m_iHeightSamplesPerSector[1] / cfg.m_iTilesPerSector[1]);
#endif
}
Ejemplo n.º 2
0
bool TileMap::Init(unsigned int mapSize, unsigned int maxAbsTileSize, unsigned int numLevels)
{
  if((!IS_POWEROF2(mapSize)) ||(numLevels < 1) || (maxAbsTileSize > mapSize) || (maxAbsTileSize < 16.0f))
    return false;

  this->mapSize = (float)mapSize; 
  log2MapSize = GetLog2(this->mapSize);
  this->maxAbsTileSize = (float)maxAbsTileSize;
  this->numLevels = numLevels;

  minAbsTileSize = this->mapSize;
  for(unsigned int i=0; i<(numLevels-1); i++)
    minAbsTileSize *= 0.5f;
  if((minAbsTileSize < 16.0f) || (minAbsTileSize > maxAbsTileSize))
    return false;

  numNodes = 1;
  unsigned int multiplier = 1;
  for(unsigned int i=1; i<numLevels; i++)
  {
    multiplier *= 4;
    numNodes += multiplier;
  }
  tileNodeList = new TileNode[numNodes];
  if(!tileNodeList)
    return false;

  TileNode &rootNode = tileNodeList[nodeIndex];
  rootNode.position.SetZero(); 
  rootNode.level = 0;
  rootNode.minLevel = 0;
  BuildTree(rootNode, 0);

  return true;
}
Ejemplo n.º 3
0
FileSystemExperiment::FileSystemExperiment(std::wstring name, StopwatchStack& ss)
	: Experiment(name, ss)
	, _devicePath(L"C:\\")
{
	if(_fileSizes.empty())
	{
		uint32_t secSize = GetLogicalSectorSize(_devicePath);
		uint32_t logSecSize = (uint32_t) GetLog2(secSize);  // HACK: assumes secSize is power of 2 (fair assumption)
		for(uint32_t i = 0; i < NumFileSizes; ++i)
		{
			_fileSizes.push_back(GuaranteedShift(1, (i+logSecSize)));
		}
	}
}
Ejemplo n.º 4
0
bool TileMap::GetTile(float size, Tile &tile)
{
  CLAMP(size, minAbsTileSize, maxAbsTileSize);
  unsigned int requiredLevel = log2MapSize-GetLog2(size);

  foundNode = NULL;
  TileNode &rootNode = tileNodeList[0];
  FindNode(rootNode, requiredLevel);
  if(!foundNode)
    return false;

  tile.position = foundNode->position;
  tile.size = size/mapSize;

  return true;
}