Exemple #1
0
  void usePool() {

    ObjectPool<Resource> object_pool(100u);
    {
      auto r1 = object_pool.getResource();
      r1->init();
      std::cout << "R1 in use " << r1->inUse() << std::endl;
      auto r2 = object_pool.getResource();
      std::cout << "R2 in use " << r2->inUse() << std::endl;
    }
    auto r3 = object_pool.getResource();
    std::cout << "R3 in use " << r3->inUse() << std::endl;

  }
	void animate() {
		if (!inUse()) return;

		framesLeft_--;
		x_ += xVel_;
		y_ += yVel_;
	}
Exemple #3
0
void Platoons::spawn(GameLevel& context) {
  const byte INTERVALS[] = {10, 16, 16};
  for(byte i = 0; i < PLATOON_MAX; ++i) {
    if(!inUse(i)) { continue; }
    if(
      timers[i] % INTERVALS[types[i]] == 0 &&
      timers[i] < PLATOON_CONSISTS * INTERVALS[types[i]]  // limitation PLATOON_CONSISTS
    ) {
      // type
      const byte isOdd = timers[i] / INTERVALS[types[i]] % 2 == 1; // 0123 -> 1234
      byte spawnType;
      if(types[i] == PLATOON_ZIG_FILE) {
        spawnType = isOdd ? SENEMY_ZIG_FIRE : SENEMY_ZIG_NOFIRE;
      }
      else {
        spawnType = isOdd ? SENEMY_TRI_FIRE : SENEMY_TRI_NOFIRE;
      }
      // y
      char y = spawnYs[i];
      if(types[i] == PLATOON_TRI_SHOAL) {
        y += random(20) - 10;
      }
      // spawn
      if(context.spawnSmallEnemy(y, (i << 4) | spawnType)) {
        status[i] = 0;  // reset platoon
      }
    }
    if(timers[i] < 0xff) {
      ++timers[i];
    }
  }
}
Exemple #4
0
		void* ScratchAllocator::allocate(size_t size, size_t align)
		{
			RIO_ASSERT(align % 4 == 0, "Align should be 4 or 8");
			size = ((size + 3) / 4) * 4; // Move size to next alignment block

			uint8_t* ptr = ptrAllocate;
			Header* h = (Header*)ptr;
			uint8_t* data = (uint8_t*)getAlignTop(h + 1, align);
			ptr = data + size;

			// Reached the end of the buffer, wrap around to the beginning
			if (ptr > bufferEnd)
			{
				h->size = (bufferEnd - (uint8_t*)h) | ((size_t)(-1));

				ptr = bufferBegin;
				h = (Header*)ptr;
				data = (uint8_t*)getAlignTop(h + 1, align);
				ptr = data + size;
			}

			// If the buffer is exhausted use the backing allocator
			if (inUse(ptr))
				return backingAllocator.allocate(size, align);

			h->size = ptr - (uint8_t*)h;
			pad(h, data);

			ptrAllocate = ptr;

			return data;
		}
void CacheSpaceScene::validateItemsCacheImpl() const
{
    Q_ASSERT(m_itemsCacheInvalid);

    if (m_scene->count() == 0)
    {
        clearItemsCache();
        m_itemsCacheInvalid = false;
        return;
    }

    auto_value<bool> inUse(m_cacheIsInUse, true);

    QRect cacheRect(scrollOffset(), window().size());
    QPoint origin = originPos();

    int count = m_scene->count();
    auto it = m_items.begin();

    QVector<SharedPtr<CacheItem>> newItems;

    for (int id(0); id < count; ++id)
    {
        if (!cacheRect.intersects(m_scene->itemRect(ID(id))))
            continue;

        SharedPtr<CacheItem> newItem;
        while ((it != m_items.end()) && (index((*it)->id) <= id))
        {
            if (index((*it)->id) == id)
            {
                (*it)->correctRectangles(m_scrollDelta);
                newItem = *it;
                break;
            }

            ++it;
        }

        if (newItem.isNull())
        {
            newItem = createCacheItem(ID(id));
            // correct rectangle
            newItem->rect.translate(origin);
        }

        newItems.append(newItem);
    }

    m_items.swap(newItems);

    // clear offset
    m_scrollDelta = QPoint(0, 0);
    m_sizeDelta = QSize(0, 0);
    // mark items as valid
    m_itemsCacheInvalid = false;
}
	bool animate() {
		if (!inUse()) 
			return false;

		framesLeft_--;
		x_ += xVel_;
		y_ += yVel_;

		return framesLeft_ == 0;
	}
Exemple #7
0
void Platoons::set(const char y, const byte type) {
  for(byte i = 0; i < PLATOON_MAX; ++i) {
    if(!inUse(i)) {
      spawnYs[i] = y;
      types[i]   = type;
      timers[i]  = 0;
      status[i]  = PLATOON_USING_MASK;
      return;
    }
  }
}
Exemple #8
0
void CacheSpaceItem::validateItemsCacheImpl() const
{
    Q_ASSERT(m_itemsCacheInvalid);
    Q_ASSERT(!m_cacheIsInUse);

    auto_value<bool> inUse(m_cacheIsInUse, true);

    m_item = createCacheItem(m_spaceItem->id());
    m_item->rect.translate(originPos());

    // mark item as valid
    m_itemsCacheInvalid = false;
}
Exemple #9
0
void MemWatch::info(const std::string & str){
    if (debug()){
#if defined(WIN32_LEAN_AND_MEAN) || USE_PROC_READPROC
        std::cout << "\t" << str << " Memory "
#if USE_BOOST_THREAD
                    << "(mt)"
#endif // HAVE_BOOST_THREAD_HPP
                    << " in use: abs: " << inUse() << " rel: "
                    << current() << " MByte. t = "
                    << swatchAll_->duration() << "/" << swatchDur_->duration(true) << " s " <<  std::endl;
    #else
        std::cout << "\t" << str << " Memory no info"  <<  std::endl;
    #endif
    }
}
Exemple #10
0
bool Platoons::checkBonus(const byte idx, bool killed) {
  if(!inUse(idx)) { return false; }
  
  // count
  ++status[idx];
  if(killed) { status[idx] += (1 << 3); }

  // check
  if((status[idx] & PLATOON_COUNT_MASK) >= PLATOON_CONSISTS) {
    if(((status[idx] >> 3) & PLATOON_COUNT_MASK) >= PLATOON_CONSISTS) {
      status[idx] = 0;
      return true;
    }
    status[idx] = 0;
  }
  return false;
}
Exemple #11
0
bool LyXVC::copyEnabled() const
{
	if (!inUse())
		return false;
	return vcs->copyEnabled();
}
Exemple #12
0
bool LyXVC::renameEnabled() const
{
	if (!inUse())
		return false;
	return vcs->renameEnabled();
}
Exemple #13
0
double MemWatch::current(){
    double ret = inUse() - last_;
    last_ = inUse();
    return ret;
}
Exemple #14
0
MemWatch::MemWatch(){
    last_ = inUse();
    swatchAll_ = new Stopwatch(true);
    swatchDur_ = new Stopwatch(true);
}