예제 #1
0
파일: test.cpp 프로젝트: cdave1/stoked
void test::TestComponentPool() {
    auto components = new stoked::ComponentPool<ComponentA>(4);

    auto c1 = components->Get();
    auto c2 = components->Get();
    auto c3 = components->Get();
    auto c4 = components->Get();

    assert(c1 != nullptr);
    assert(c2 != nullptr);
    assert(c3 != nullptr);
    assert(c4 != nullptr);

    assert(c1->GetID() < components->GetCapacity());
    assert(c2->GetID() < components->GetCapacity());
    assert(c3->GetID() < components->GetCapacity());
    assert(c4->GetID() < components->GetCapacity());

    // Currently, when "Get" is called, the component is not "free", in the sense that it is assumed that it is
    // attached to an entity.  This is actually pretty confusing.
    assert(!c1->IsFree());
    assert(!c2->IsFree());
    assert(!c3->IsFree());
    assert(!c4->IsFree());

    PASSED();
}
예제 #2
0
파일: test.cpp 프로젝트: cdave1/stoked
void test::TestEntityPool() {
    auto entities = new stoked::EntityPool(4);

    auto e1 = entities->Create();
    auto e2 = entities->Create();
    auto e3 = entities->Create();
    auto e4 = entities->Create();

    assert(e1 != nullptr);
    assert(e2 != nullptr);
    assert(e3 != nullptr);
    assert(e4 != nullptr);

    assert(e1->GetID() < entities->GetCapacity());
    assert(e2->GetID() < entities->GetCapacity());
    assert(e3->GetID() < entities->GetCapacity());
    assert(e4->GetID() < entities->GetCapacity());

    assert(entities->Empty() && !entities->Available());

    entities->FreeAll();

    assert(!entities->Empty() && entities->Available());

    e1 = entities->Create();
    bool freeResult = entities->Free(e1);
    assert(freeResult == true);

    delete entities;

    PASSED();
}
예제 #3
0
bool TBListBackend::GrowIfNeeded()
{
	int capacity = GetCapacity();
	if (GetNumItems() == capacity)
		return Reserve(CLAMP(4, capacity * 2, 1024));
	return true;
}
예제 #4
0
CPUBuffer::CPUBuffer(uint8_t elementSize, uint32_t capacity)
  : TBase(elementSize, capacity)
{
  uint32_t memorySize = my::NextPowOf2(GetCapacity() * GetElementSize());
  m_memory = SharedBufferManager::instance().reserveSharedBuffer(memorySize);
  m_memoryCursor = NonConstData();
}
	int Append(const T& stValue)
	{
		if (m_iSize >= GetCapacity())
		{
			return -1;
		}

		m_astData[m_iSize++] = stValue;
	}
예제 #6
0
Object2D* Bullet2DFactory::GetObject()
{
	for(Bullet2D* bullet = begin; bullet != end; ++bullet)
	{
		if(!bullet->active)
		{
			return bullet;
		}
	}

	IncreaseSize();
	
	return begin + GetCapacity();
}
예제 #7
0
bool TBListBackend::Reserve(int new_capacity)
{
	assert(new_capacity > 0);
	if (new_capacity > GetCapacity())
	{
		int num = GetNumItems();
		if (char *new_data = (char *) realloc(m_data, sizeof(TBLIST_DATA) + sizeof(void *) * (new_capacity)))
		{
			m_data = (TBLIST_DATA *) new_data;
			m_data->num = num;
			m_data->capacity = new_capacity;
			m_data->list = (void**) (new_data + sizeof(TBLIST_DATA));
			return true;
		}
		return false;
	}
	return true;
}
예제 #8
0
void Bullet2DFactory::IncreaseSize()
{
	const unsigned oldCapacity = GetCapacity();
	const unsigned newCapacity = oldCapacity + sizeIncrease;

	Bullet2D* buffer = new Bullet2D[newCapacity];

	if(begin)
	{
		//transfer the previous bullet data to the new memory
		memcpy(buffer, begin, oldCapacity);

		delete [] begin;
		begin = NULL;
		end = NULL;
	}

	begin = buffer;
	end = buffer + newCapacity;
}
예제 #9
0
// Load
//------------------------------------------------------------------------------
bool Dependencies::Load( NodeGraph & nodeGraph, IOStream & stream )
{
	uint32_t numDeps;
	if ( stream.Read( numDeps ) == false )
	{
		return false;
	}
	if ( GetCapacity() < GetSize() + numDeps )
	{
		SetCapacity( GetSize() + numDeps );
	}
	for ( uint32_t i=0; i<numDeps; ++i )
	{
		// Read node index
		uint32_t index( INVALID_NODE_INDEX );
		if ( stream.Read( index ) == false )
		{
			return false;
		}

		// Convert to Node *
		Node * node = nodeGraph.GetNodeByIndex( index );
		ASSERT( node );

		// Read weak flag
		bool isWeak( false );
		if ( stream.Read( isWeak ) == false )
		{
			return false;
		}

		// Recombine dependency info
		Append( Dependency( node, isWeak ) );
	}
	return true;
}
예제 #10
0
	/// Zwraca true, jeœli bufor jest pe³ny
	bool IsFull() { return GetSize() == GetCapacity(); }
예제 #11
0
파일: csstring.cpp 프로젝트: garinh/cs
void csStringBase::SetCapacity (size_t NewSize)
{
  if (NewSize + 1 > GetCapacity() + 1) // GLOBAL NOTE *1*
    SetCapacityInternal (NewSize, false);
}
예제 #12
0
파일: csstring.cpp 프로젝트: garinh/cs
void csStringBase::ExpandIfNeeded(size_t NewSize)
{
  if (GetData() == 0 || NewSize + 1 > GetCapacity() + 1) // GLOBAL NOTE *1*
    SetCapacityInternal (NewSize, true);
}
예제 #13
0
MockCSIPlugin::MockCSIPlugin()
{
  EXPECT_CALL(*this, GetPluginInfo(_, _, _))
    .WillRepeatedly(Return(Status::OK));

  // Enable all plugin capabilities by default for testing with the test CSI
  // plugin in forwarding mode.
  EXPECT_CALL(*this, GetPluginCapabilities(_, _, _))
    .WillRepeatedly(Invoke([](
        ServerContext* context,
        const csi::v0::GetPluginCapabilitiesRequest* request,
        csi::v0::GetPluginCapabilitiesResponse* response) {
      response->add_capabilities()->mutable_service()->set_type(
          csi::v0::PluginCapability::Service::CONTROLLER_SERVICE);

      return Status::OK;
    }));

  EXPECT_CALL(*this, Probe(_, _, _))
    .WillRepeatedly(Return(Status::OK));

  EXPECT_CALL(*this, CreateVolume(_, _, _))
    .WillRepeatedly(Return(Status::OK));

  EXPECT_CALL(*this, DeleteVolume(_, _, _))
    .WillRepeatedly(Return(Status::OK));

  EXPECT_CALL(*this, ControllerPublishVolume(_, _, _))
    .WillRepeatedly(Return(Status::OK));

  EXPECT_CALL(*this, ControllerUnpublishVolume(_, _, _))
    .WillRepeatedly(Return(Status::OK));

  EXPECT_CALL(*this, ValidateVolumeCapabilities(_, _, _))
    .WillRepeatedly(Return(Status::OK));

  EXPECT_CALL(*this, ListVolumes(_, _, _))
    .WillRepeatedly(Return(Status::OK));

  EXPECT_CALL(*this, GetCapacity(_, _, _))
    .WillRepeatedly(Return(Status::OK));

  // Enable all controller capabilities by default for testing with the test CSI
  // plugin in forwarding mode.
  EXPECT_CALL(*this, ControllerGetCapabilities(_, _, _))
    .WillRepeatedly(Invoke([](
        ServerContext* context,
        const csi::v0::ControllerGetCapabilitiesRequest* request,
        csi::v0::ControllerGetCapabilitiesResponse* response) {
      response->add_capabilities()->mutable_rpc()->set_type(
          csi::v0::ControllerServiceCapability::RPC::CREATE_DELETE_VOLUME);
      response->add_capabilities()->mutable_rpc()->set_type(
          csi::v0::ControllerServiceCapability::RPC::PUBLISH_UNPUBLISH_VOLUME);
      response->add_capabilities()->mutable_rpc()->set_type(
          csi::v0::ControllerServiceCapability::RPC::GET_CAPACITY);
      response->add_capabilities()->mutable_rpc()->set_type(
          csi::v0::ControllerServiceCapability::RPC::LIST_VOLUMES);

      return Status::OK;
    }));

  EXPECT_CALL(*this, NodeStageVolume(_, _, _))
    .WillRepeatedly(Return(Status::OK));

  EXPECT_CALL(*this, NodeUnstageVolume(_, _, _))
    .WillRepeatedly(Return(Status::OK));

  EXPECT_CALL(*this, NodePublishVolume(_, _, _))
    .WillRepeatedly(Return(Status::OK));

  EXPECT_CALL(*this, NodeUnpublishVolume(_, _, _))
    .WillRepeatedly(Return(Status::OK));

  EXPECT_CALL(*this, NodeGetId(_, _, _))
    .WillRepeatedly(Return(Status::OK));

  // Enable all node capabilities by default for testing with the test CSI
  // plugin in forwarding mode.
  EXPECT_CALL(*this, NodeGetCapabilities(_, _, _))
    .WillRepeatedly(Invoke([](
        ServerContext* context,
        const csi::v0::NodeGetCapabilitiesRequest* request,
        csi::v0::NodeGetCapabilitiesResponse* response) {
      response->add_capabilities()->mutable_rpc()->set_type(
          csi::v0::NodeServiceCapability::RPC::STAGE_UNSTAGE_VOLUME);

      return Status::OK;
    }));
}
예제 #14
0
int32 UFlareCargoBay::GetFreeCargoSpace() const
{
	return GetCapacity() - GetUsedCargoSpace();
}
	T& operator[](int i)
	{
		assert(i >= 0 && i < GetCapacity() && i < GetSize());
		return m_astData[i];
	}