Exemplo n.º 1
0
///////////////////////////////////////////////////////////////////////////////////////////////////
// Moves a block
// Parameters:
//    b_idx: Index of the block
// Returns:
//    1 if the moved block has been destroyed
//    0 if not
//
u8 moveBlock(u8 b_idx) {
   TEntity *e = &g_blocks[b_idx]; // Get next block entity
//   u8 newY;                       // New calculated Y coordinate after movement

   // Update block location acording to its Y physics
   e->phys.y += G_scrollVel;      // All blocks use this same velocity for Y axis
   e->y       = e->ny;
   e->ny      = e->phys.y / SCALE;
   
   // Check if we have to move the block graphically
   if (e->ny != e->y) {    
      // Check if the block has disappeared from the screen, to destroy it
      // Beware! Destroying a block moves all the rest in the array!
      if (e->ny > G_maxY) {
         destroyBlock(b_idx);
         return 1;         // Return informing that the block has been destroyed!
      }

      e->draw = 1;
   }

   // Update block location according to its X physics
   if (e->phys.vx) {
      e->x       = e->nx;
      e->phys.x += e->phys.vx;
      e->nx      = e->phys.x / SCALE;

      // Is there any graphical movement?
      if (e->x != e->nx) {
         // Maintain into limits
         if (e->nx < G_minX) {
            // Crossed left boundary, bounce right
            e->nx      = G_minX + 1; 
            e->phys.x  = e->nx * SCALE; 
            e->phys.vx = -e->phys.vx;
         } else if ( e->nx + e->graph.block.w >= G_maxX ) {
            // Crossed right boundary, bounce left
            e->nx      = G_maxX - e->graph.block.w;
            e->phys.x  = e->nx * SCALE;  
            e->phys.vx = -e->phys.vx;
         }
         e->draw = 1; // Set for redraw
      }
   }

   // Calculate new screen position, on draw
   if (e->draw) {
      e->pscreen  = e->npscreen;
      e->npscreen = cpct_getScreenPtr(CPCT_VMEM_START, e->nx, e->ny);
   }

   // Return signalling that the block has NOT been destroyed
   return 0;
}
Exemplo n.º 2
0
GrBufferAllocPool::~GrBufferAllocPool() {
    VALIDATE();
    if (fBlocks.count()) {
        GrGeometryBuffer* buffer = fBlocks.back().fBuffer;
        if (buffer->isLocked()) {
            buffer->unlock();
        }
    }
    while (!fBlocks.empty()) {
        destroyBlock();
    }
    fPreallocBuffers.unrefAll();
    releaseGpuRef();
}
Exemplo n.º 3
0
static void buildNewStatusString( int block, int id )
{
    char    *mod;

    mod = findBlockString( block );

    switch( id ) {
    case SS_SPLIT:
        splitBlock( block, mod );
        break;
    case SS_DESTROY:
        destroyBlock( block, mod );
        break;
    case SS_DEFAULTS:
        buildDefaults();
        break;
    default:
        buildNewItem( mod, id );
    }
}
Exemplo n.º 4
0
void GrBufferAllocPool::reset() {
    VALIDATE();
    fBytesInUse = 0;
    if (fBlocks.count()) {
        GrGeometryBuffer* buffer = fBlocks.back().fBuffer;
        if (buffer->isLocked()) {
            buffer->unlock();
        }
    }
    while (!fBlocks.empty()) {
        destroyBlock();
    }
    if (fPreallocBuffers.count()) {
        // must set this after above loop.
        fFirstPreallocBuffer = (fFirstPreallocBuffer + fPreallocBuffersInUse) %
                               fPreallocBuffers.count();
    }
    fCpuData.reset(fGpu->getCaps().fBufferLockSupport ? 0 : fMinBlockSize);
    GrAssert(0 == fPreallocBuffersInUse);
    VALIDATE();
}
	/*
	 * Destroy the object, and free the block for re-use.
	 *
	 * @param theObject the address of the object.
	 * @return true if the object was deleted, false if not.
	 */
	bool
	destroyObject(ObjectType*	theObject)
	{
		bool bResult = false;

		assert ( theObject != 0 );

		if ( this->m_blocks.empty() )
			return bResult;

		iterator iTerator = this->m_blocks.begin();

		iterator iEnd = this->m_blocks.end();

		// first , run over unfull blocks ( that consentrated from the head )
		while( iTerator != iEnd 
					&& (*iTerator)->blockAvailable() )
		{
			if ((*iTerator)->ownsBlock(theObject) == true)
			{
				(*iTerator)->destroyObject(theObject);
				
				// move the block we have just deleted to the head of the list
				if (iTerator != this->m_blocks.begin())
				{
					// move the block to the beginning
					ReusableArenaBlockType* block = *iTerator;

					assert(block != 0);
					
					this->m_blocks.erase(iTerator);

					this->m_blocks.push_front(block);
				}

				if (m_destroyBlocks)
				{
					destroyBlock();
				}

				bResult = true;

				break;
			}

			++iTerator;
		}

		reverse_iterator rIterator = this->m_blocks.rbegin();

		reverse_iterator rEnd = this->m_blocks.rend();

		// if the block hasn't been found from the head , start with full blocks ( from the taile)
		while ( !bResult && rIterator != rEnd )
		{
			if ((*rIterator)->ownsBlock(theObject))
			{
				(*rIterator)->destroyObject(theObject);

				if (rIterator != this->m_blocks.rbegin())
				{
					// move the block to the beginning
					ReusableArenaBlockType* block = *iTerator;

					assert(block != 0);
					
					this->m_blocks.erase(iTerator);

					this->m_blocks.push_front(block);

				}

				if (m_destroyBlocks)
				{
					destroyBlock();
				}

				bResult = true;

				break; 
			}

			if ( *rIterator == *iTerator)
			{
				break;
			}
			else
			{
				++rIterator;
			}
		}

		return bResult;

		assert ( bResult );
	}
Exemplo n.º 6
0
void UserMgmtWidget::unblock(QString screenName, UserMgmtWidgetItem *item)
{
    emit destroyBlock(screenName, item);
}