コード例 #1
0
ファイル: mm.c プロジェクト: punit9462/IT-Projects
/*
 * coalesce - Merges two free blocks
 *
 */
static void *coalesce(void *bp) {
    size_t prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp))); /* status of the previous block */
    size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp))); /* status of the next block */
    size_t size = GET_SIZE(HDRP(bp));
    if (prev_alloc && next_alloc) {
        addBlock(bp); /* Just add the free block in the free list */
        return bp;
    }
    else if (prev_alloc && !next_alloc) {
        removeBlock(NEXT_BLKP(bp)); /* remove the next free block */
        size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
        PUT(HDRP(bp), PACK(size, 0));
        PUT(FTRP(bp), PACK(size, 0));
        addBlock(bp); /* add the new merged free block in the list */
    }
    else if (!prev_alloc && next_alloc) {
        removeBlock(PREV_BLKP(bp));/* remove the previous free block */
        size += GET_SIZE(HDRP(PREV_BLKP(bp)));
        PUT(FTRP(bp), PACK(size, 0));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
        bp = PREV_BLKP(bp);
        addBlock(bp); /* add the new merged free block in the list */
    }
    else { /* If next and previous both blocks are free */
        /* remove the both free block */
        removeBlock(PREV_BLKP(bp));
        removeBlock(NEXT_BLKP(bp));

        size+=GET_SIZE(HDRP(PREV_BLKP(bp)));
        size+=GET_SIZE(HDRP(NEXT_BLKP(bp)));
        PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0));
        PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0));
        bp = PREV_BLKP(bp);
        addBlock(bp);/* add the new merged block in the list */
    }
    return bp; /* Pointer to the newly merged free block */
}
コード例 #2
0
ファイル: mm2.c プロジェクト: bremerle3/cse361
/*
* coalesce - boundary tag coalescing.
* This function joins adjecent free blocks together by
* finding the size (newsize) of the new (bigger) free block, removing the
* free block(s) from the free list, and changing the header
* and footer information to the newly coalesced free block
* (size = newsize, allocated = 0)
* Then, we add the new free block to the front of the free list.
*
* This function takes a block pointer to the newly freed block (around which
* we must coalesce) and returns the block pointer to the coalesced free
* block.
* Return ptr to coalesced block
*/
static void *coalesce(void *bp)
{
size_t prev_alloc;
prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp))) || PREV_BLKP(bp) == bp;
size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp)));
size_t size = GET_SIZE(HDRP(bp));
/* Case 1, extend the block leftward */
if (prev_alloc && !next_alloc)
{
size += GET_SIZE(HDRP(NEXT_BLKP(bp)));
removeBlock(NEXT_BLKP(bp));
PUT(HDRP(bp), PACK(size, 0));
PUT(FTRP(bp), PACK(size, 0));
}
/* Case 2, extend the block rightward */
else if (!prev_alloc && next_alloc)
{
size += GET_SIZE(HDRP(PREV_BLKP(bp)));
bp = PREV_BLKP(bp);
removeBlock(bp);
PUT(HDRP(bp), PACK(size, 0));
PUT(FTRP(bp), PACK(size, 0));
}
/* Case 3, extend the block in both directions */
else if (!prev_alloc && !next_alloc)
{
size += GET_SIZE(HDRP(PREV_BLKP(bp))) +
GET_SIZE(HDRP(NEXT_BLKP(bp)));
removeBlock(PREV_BLKP(bp));
removeBlock(NEXT_BLKP(bp));
bp = PREV_BLKP(bp);
PUT(HDRP(bp), PACK(size, 0));
PUT(FTRP(bp), PACK(size, 0));
}
insertAtFront(bp);
return bp;
}
コード例 #3
0
    //-----------------------------------------------------------------------
    void DynamicBlockObject::setEnable(Bool enable)
    {
        if (mEnable!=enable)
        {
            mEnable = enable;
            if (mEnable)
            {
                Vec3 pos;
                mEntity->getSceneNode()->getPosition(pos);
				refreshWorldBlockTriangle();
                refreshBlock( mOldPos, pos );
            }else
            {
                removeBlock();
            }
        }
    }
コード例 #4
0
ファイル: ballduino.c プロジェクト: benjmyers/Ballduino
/* Checks if the ball has collided with a block */
boolean checkBlockCollision(){
    int ballTop = ballY-rad;                                            // Values for easy reference
    int ballBottom = ballY+rad;
    int ballLeft = ballX-rad;
    int ballRight = ballX+rad;
    
    for(int i=0;i<numBlocks;i++){                                       // Loop through the blocks
        if(bricks[i][0] == 1){                                          // If the block hasn't been eliminated
         int blockX = bricks[i][1];                                     // Grab x and y location
         int blockY = bricks[i][2];
         if(ballBottom >= blockY && ballTop <= blockY+blockHeight){     // If hitting BLOCK
           if(ballRight >= blockX && ballLeft <= blockX+blockWidth){       
             removeBlock(i);                                            // Mark the block as out of play
             return true;
           }
         }
      }
    }
  return false;                                                         // No collision detected
}
コード例 #5
0
ファイル: blocks.cpp プロジェクト: tulip5/tulip
/**
 * Splits block b across constraint c into two new blocks, l and r (c's left
 * and right sides respectively)
 */
void Blocks::split(Block *b, Block *&l, Block *&r, Constraint *c) {
  b->split(l, r, c);
#ifdef RECTANGLE_OVERLAP_LOGGING
  ofstream f(LOGFILE, ios::app);
  f << "Split left: " << *l << endl;
  f << "Split right: " << *r << endl;
#endif
  r->posn = b->posn;
  r->wposn = r->posn * r->weight;
  mergeLeft(l);
  // r may have been merged!
  r = c->right->block;
  r->wposn = r->desiredWeightedPosition();
  r->posn = r->wposn / r->weight;
  mergeRight(r);
  removeBlock(b);

  insert(l);
  insert(r);
}
コード例 #6
0
ファイル: doc_block.cpp プロジェクト: fejo/TrollEdit-1
void DocBlock::textChanged()
{
    if (docType == Generic) return;

    QString text = myTextItem->toPlainText();

    if (text.isEmpty() && !myTextItem->hasFocus() && docType != Image)
    {
        removeBlock(true);
    }
    else
    {
        if (element->getType() != text)
        {
//            if(!isFolded()) {
//                element->setType(text);
//            }
            group->setModified(true);
            updateBlock(false);
        }
    }
}
コード例 #7
0
ファイル: BufferMgr.cpp プロジェクト: dbTeam420/OurSQL
void BufferMgr::addBlock(const char *file, Block *b)
{
	if (numMap.find(BufferId(file, b->getBlockNum())) != numMap.end())
		return;
	int nextBlock;
	if (curSize < MAX_BLOCK_SIZE) {
		nextBlock = curSize++;
	}
	else {
		// LRU替换策略
		nextBlock = getAndReleaseLruBlock();
		removeBlock(nextBlock);
	}
	BufferId *bid = new BufferId(file, b->getBlockNum());
	block[nextBlock] = b;
	blockInfo[nextBlock] = bid;
	numMap[*bid] = nextBlock;
	leastList.push_front(nextBlock);
	leastAddr[nextBlock] = leastList.begin();
	if (logRecord)
		printf("[Buffer Mgr]Block #%d in %s is added to Buffer\n", b->getBlockNum(), file);
}
コード例 #8
0
ファイル: blocks.cpp プロジェクト: tulip5/tulip
/**
 * Processes incoming constraints, most violated to least, merging with the
 * neighbouring (left) block until no more violated constraints are found
 */
void Blocks::mergeLeft(Block *r) {
#ifdef RECTANGLE_OVERLAP_LOGGING
  ofstream f(LOGFILE, ios::app);
  f << "mergeLeft called on " << *r << endl;
#endif
  r->timeStamp = ++blockTimeCtr;
  r->setUpInConstraints();
  Constraint *c = r->findMinInConstraint();

  while (c != nullptr && c->slack() < 0) {
#ifdef RECTANGLE_OVERLAP_LOGGING
    f << "mergeLeft on constraint: " << *c << endl;
#endif
    r->deleteMinInConstraint();
    Block *l = c->left->block;

    if (l->in == nullptr)
      l->setUpInConstraints();

    double dist = c->right->offset - c->left->offset - c->gap;

    if (r->vars->size() < l->vars->size()) {
      dist = -dist;
      std::swap(l, r);
    }

    blockTimeCtr++;
    r->merge(l, c, dist);
    r->mergeIn(l);
    r->timeStamp = blockTimeCtr;
    removeBlock(l);
    c = r->findMinInConstraint();
  }

#ifdef RECTANGLE_OVERLAP_LOGGING
  f << "merged " << *r << endl;
#endif
}
コード例 #9
0
 //-----------------------------------------------------------------------
 DynamicBlockObject::~DynamicBlockObject()
 {
     mEntity->getSceneNode()->removeSceneNodeLisitener( "MGEngine_DynamicBlockObject" );
     removeBlock();
 }
コード例 #10
0
ファイル: handleblock.c プロジェクト: atextor/blockmaster
void movePlayer(int whichPlayer, int direction)
{
	/* 	Function: movePlayer
		Purpose:  Move a Player to a certain direction
	*/
	
	int targetBlock, targetX, targetY, targetX2, targetY2;
	switch ( direction )
	{
		case UP:   
			targetX = player[whichPlayer].coord_x;
			targetY = player[whichPlayer].coord_y - 1; 
			targetX2 = player[whichPlayer].coord_x;
			targetY2 = player[whichPlayer].coord_y - 2;
			break;
		case DOWN: 
			targetX = player[whichPlayer].coord_x;
			targetY = player[whichPlayer].coord_y + 1; 
			targetX2 = player[whichPlayer].coord_x;
			targetY2 = player[whichPlayer].coord_y + 2;
			break;
		case LEFT: 
			targetX = player[whichPlayer].coord_x - 1;
			targetY = player[whichPlayer].coord_y;
			targetX2 = player[whichPlayer].coord_x - 2;
			targetY2 = player[whichPlayer].coord_y;
			break;
		case RIGHT:
			targetX = player[whichPlayer].coord_x + 1;
			targetY = player[whichPlayer].coord_y;
			targetX2 = player[whichPlayer].coord_x + 2;
			targetY2 = player[whichPlayer].coord_y;
			break;
	}
	
	targetBlock = level.data[targetX][targetY];
	
	// item
	if ( hasBlockBit(targetX, targetY, ISFETCHABLE) ) {
		takeItem(targetX, targetY);
	}
	
	// movable block
	if ( hasBlockBit(targetX, targetY, ISMOVABLE) ) {
		// water or hole
		if ( hasBlockBit(targetX2, targetY2, ISBLOCKDESTROYER) ) {
			removeBlock(targetX2, targetY2);	
			removeBlock(targetX, targetY);
		// other block container
		} else if ( hasBlockBit(targetX2, targetY2, ISBLOCKCONTAINER) ) {
			level.data[targetX2][targetY2] = level.data[targetX][targetY];
			removeBlock(targetX, targetY);
			addActivity(targetX, targetY, BLOCKMOVE);
		}
	}
	
	// arrow fields
	if ( (level.data[targetX][targetY] == B_UPARROW) ||
		 (level.data[targetX][targetY] == B_DOWNARROW) ||
		 (level.data[targetX][targetY] == B_RIGHTARROW) ||
		 (level.data[targetX][targetY] == B_LEFTARROW)) {
		addActivity(targetX, targetY, PLAYERMOVE);
	}

	// doors	
	if (targetBlock == B_REDDOOR) {
		inventory.redKeys--;
		removeBlock(targetX, targetY);
	}
	if (targetBlock == B_GREENDOOR) {
		inventory.greenKeys--;
		removeBlock(targetX, targetY);
	}
	if (targetBlock == B_BLUEDOOR) {
		inventory.blueKeys--;
		removeBlock(targetX, targetY);
	}
	if (targetBlock == B_YELLOWDOOR) {
		inventory.yellowKeys--;
		removeBlock(targetX, targetY);
	}
	
	// toggle button
	if (targetBlock == B_BUTTON) {
		toggleBlocks = !toggleBlocks;	
	}

	// general player movement	
	if ( hasBlockBit(targetX, targetY, ISWALKABLE) ) {
		player[whichPlayer].coord_x = targetX;
		player[whichPlayer].coord_y = targetY;		
	}
	// TODO
	// broken floor
	// finish
	// fake wall (air)
	// water w/ flippers
	// fire w/ fireshoes
	
	return;
	
}
コード例 #11
0
ファイル: chunk.cpp プロジェクト: andrew889/mycraft
Chunk::Chunk(int x, int z, unsigned int seed)
: m_x(x), m_z(z)
{
	PerlinNoise heightMap(seed);
	PerlinNoise noise(seed + 1);
	PerlinNoise caves(seed + 2);

	// Lower means more mountains and valleys
	const float SMOOTHNESS = 25.0;

	// Larger means flatter
	const float DETAIL = 1 / 16.0;

	// Larger means more overhangs and caves
	const float CARVING = 2.0;

	// Larger means more caves
	const float CAVES = 3.0;

	for (int i = 0; i < SIZE; ++i)
	{
		for (int j = 0; j < SIZE; ++j)
		{
			float heightSample = heightMap.sample(SMOOTHNESS * (x * SIZE + i), 0.0, SMOOTHNESS * (z * SIZE + j));
			float height = (DEPTH / 2) + SCALE * heightSample; //(0.5 + 0.25 * heightSample);

			for (int k = 0; k < DEPTH; ++k)
			{
				float sample = noise.sample(DETAIL * (x * SIZE + i), CARVING * DETAIL * k, DETAIL * (z * SIZE + j));
				sample += (height - k) / (SCALE / 4.0);

				// Ground threshold
				if (sample > 0.0f)
				{
					// Stone threshold
					if (sample > 0.5f)
						newBlock(x * SIZE + i, k, z * SIZE + j, BlockLibrary::STONE);
					else
						newBlock(x * SIZE + i, k, z * SIZE + j, BlockLibrary::DIRT);
				}
			}
		}
	}

	// Convert top-level dirt to grass
	for (int i = 0; i < SIZE; ++i)
	{
		for (int j = 0; j < SIZE; ++j)
		{
			// Fill any gap below sea level with water
			for (int k = 0; k < 0.45 * DEPTH; ++k)
			{
				Coordinate location(x * SIZE + i, k, z * SIZE + j);
				if (!get(location))
				{
					newBlock(location.x, location.y, location.z, BlockLibrary::WATER);
				}
			}
		}
	}

	// Cut out some caves
	for (int i = 0; i < SIZE; ++i)
	{
		for (int j = 0; j < SIZE; ++j)
		{
			for (int k = 0; k < DEPTH; ++k)
			{
				Coordinate location(x * SIZE + i, k, z * SIZE + j);
				if (m_blocks.find(location) == m_blocks.end())
					continue;

				float caveSample = caves.sample(DETAIL * (x * SIZE + i), CAVES * DETAIL * k, DETAIL * (z * SIZE + j));
				caveSample = pow(caveSample, 3.0);

				// Ground threshold
				if (caveSample <= -0.1)
				{
					removeBlock(location);
				}
			}

			// Convert top-level dirt to grass
			for (int k = DEPTH - 1; k >= 0; --k)
			{
				Coordinate location(x * SIZE + i, k, z * SIZE + j);

				if (get(location))
				{
					auto& block = m_blocks[location];
					if (block->blockType == BlockLibrary::DIRT)
						block->blockType = BlockLibrary::GRASS;

					// We only work on the top-most block in a column.
					break;
				}
			}
		}
	}
}
コード例 #12
0
static void
releaseMemory(virt_ptr<MEMExpHeap> heap,
              virt_ptr<uint8_t> memStart,
              virt_ptr<uint8_t> memEnd)
{
   decaf_check(memEnd - memStart >= sizeof(MEMExpHeapBlock) + 4);

   // Fill the released memory with debug data if needed
   if (heap->header.flags & MEMHeapFlags::DebugMode) {
      auto fillVal = MEMGetFillValForHeap(MEMHeapFillType::Freed);
      std::memset(memStart.get(), fillVal, memEnd - memStart);
   }

   // Find the preceeding block to the memory we are releasing
   virt_ptr<MEMExpHeapBlock> prevBlock = nullptr;
   virt_ptr<MEMExpHeapBlock> nextBlock = heap->freeList.head;

   for (auto block = heap->freeList.head; block; block = block->next) {
      if (getBlockMemStart(block) < memStart) {
         prevBlock = block;
         nextBlock = block->next;
      } else if (block >= prevBlock) {
         break;
      }
   }

   virt_ptr<MEMExpHeapBlock> freeBlock = nullptr;
   if (prevBlock) {
      // If there is a previous block, we need to check if we
      //  should just steal that block rather than making one.
      auto prevMemEnd = getBlockMemEnd(prevBlock);

      if (memStart == prevMemEnd) {
         // Previous block absorbs the new memory
         prevBlock->blockSize += static_cast<uint32_t>(memEnd - memStart);

         // Our free block becomes the previous one
         freeBlock = prevBlock;
      }
   }

   if (!freeBlock) {
      // We did not steal the previous block to free into,
      //  we need to allocate our own here.
      freeBlock = virt_cast<MEMExpHeapBlock *>(memStart);
      freeBlock->attribs = MEMExpHeapBlockAttribs::get(0);
      freeBlock->blockSize = static_cast<uint32_t>((memEnd - memStart) - sizeof(MEMExpHeapBlock));
      freeBlock->next = nullptr;
      freeBlock->prev = nullptr;
      freeBlock->tag = FreeTag;

      insertBlock(virt_addrof(heap->freeList), prevBlock, freeBlock);
   }

   if (nextBlock) {
      // If there is a next block, we need to possibly merge it down
      //  into this one.
      auto nextBlockStart = getBlockMemStart(nextBlock);

      if (nextBlockStart == memEnd) {
         // The next block needs to be merged into the freeBlock, as they
         //  are directly adjacent to each other in memory.
         auto nextBlockEnd = getBlockMemEnd(nextBlock);
         freeBlock->blockSize += static_cast<uint32_t>(nextBlockEnd - nextBlockStart);

         removeBlock(virt_addrof(heap->freeList), nextBlock);
      }
   }
}
コード例 #13
0
ファイル: lt.c プロジェクト: MateusZitelli/Tree-Bots
void resolveKileds(){
    int i;
    for(i = 0; i < quantityKiled; i++){
        removeBlock(tobeKiled[i]);
    }
}
コード例 #14
0
ファイル: OW_HDBNode.cpp プロジェクト: kkaempf/openwbem
bool
HDBNode::remove(HDBHandle& hdl)
{
	// If node hasn't been written yet, don't do anything.
	if (m_pdata->m_offset <= 0)
	{
		return false;
	}
	File file = hdl.getFile();
	HDB* pdb = hdl.getHDB();
	HDBBlock fblk;
	// Remove all children
	Int32 coffset = m_pdata->m_blk.lastChild;
	Int32 toffset;
	while (coffset > 0)
	{
		HDB::readBlock(fblk, file, coffset);
		toffset = coffset;			// Save offset for deletion class
		coffset = fblk.prevSib;		// Save offset for next read
		// Remove node and all of its children. This call will modify fblk.
		removeBlock(hdl, fblk, toffset);
	}
	// Set pointer on next sibling if it exists
	if (m_pdata->m_blk.nextSib > 0)
	{
		HDB::readBlock(fblk, file, m_pdata->m_blk.nextSib);
		fblk.prevSib = m_pdata->m_blk.prevSib;
		HDB::writeBlock(fblk, file, m_pdata->m_blk.nextSib);
	}
	// Set pointer on prev sibling if it exists
	if (m_pdata->m_blk.prevSib > 0)
	{
		HDB::readBlock(fblk, file, m_pdata->m_blk.prevSib);
		fblk.nextSib = m_pdata->m_blk.nextSib;
		HDB::writeBlock(fblk, file, m_pdata->m_blk.prevSib);
	}
	// If it has a parent, insure parent doesn't contain it's offset
	if (m_pdata->m_blk.parent > 0)
	{
		// Read parent block
		HDB::readBlock(fblk, file, m_pdata->m_blk.parent);
		bool changed = false;
		// If this was the first child in the list, then update the
		// first child pointer in the parent block
		if (fblk.firstChild == m_pdata->m_offset)
		{
			changed = true;
			fblk.firstChild = m_pdata->m_blk.nextSib;
		}
		// If this was the last child in the list, then update the
		// last child pointer in the parent block
		if (fblk.lastChild == m_pdata->m_offset)
		{
			changed = true;
			fblk.lastChild = m_pdata->m_blk.prevSib;
		}
		// If any offsets changed in the parent block, then update the parent
		if (changed)
		{
			HDB::writeBlock(fblk, file, m_pdata->m_blk.parent);
		}
	}
	else
	{
		// Must be a root node
		if (pdb->getFirstRootOffSet() == m_pdata->m_offset)
		{
			pdb->setFirstRootOffSet(file, m_pdata->m_blk.nextSib);
		}
		if (pdb->getLastRootOffset() == m_pdata->m_offset)
		{
			pdb->setLastRootOffset(file, m_pdata->m_blk.prevSib);
		}
	}
	// Add block to free list
	pdb->addBlockToFreeList(file, m_pdata->m_blk, m_pdata->m_offset);
	// Remove the index entry for this node
	hdl.removeIndexEntry(m_pdata->m_key.c_str());
	m_pdata->m_offset = -1;
	m_pdata->m_blk.isFree = true;
	m_pdata->m_blk.parent = -1;
	m_pdata->m_blk.firstChild = -1;
	m_pdata->m_blk.lastChild = -1;
	m_pdata->m_blk.prevSib = -1;
	m_pdata->m_blk.nextSib = -1;
	m_pdata->m_blk.size = 0;
	hdl.registerWrite();
	return true;
}
コード例 #15
0
ファイル: Block.cpp プロジェクト: huangyajie/cocos2dx
void Block::clean()
{
    if(index < 0)
        removeBlock();
}
コード例 #16
0
static virt_ptr<MEMExpHeapBlock>
createUsedBlockFromFreeBlock(virt_ptr<MEMExpHeap> heap,
                             virt_ptr<MEMExpHeapBlock> freeBlock,
                             uint32_t size,
                             uint32_t alignment,
                             MEMExpHeapDirection dir)
{
   auto expHeapAttribs = heap->attribs.value();
   auto freeBlockAttribs = freeBlock->attribs.value();

   auto freeBlockPrev = freeBlock->prev;
   auto freeMemStart = getBlockMemStart(freeBlock);
   auto freeMemEnd = getBlockMemEnd(freeBlock);

   // Free blocks should never have alignment...
   decaf_check(!freeBlockAttribs.alignment());
   removeBlock(virt_addrof(heap->freeList), freeBlock);

   // Find where we are going to start
   auto alignedDataStart = virt_ptr<uint8_t> { };

   if (dir == MEMExpHeapDirection::FromStart) {
      alignedDataStart = align_up(freeMemStart + sizeof(MEMExpHeapBlock), alignment);
   } else if (dir == MEMExpHeapDirection::FromEnd) {
      alignedDataStart = align_down(freeMemEnd - size, alignment);
   } else {
      decaf_abort("Unexpected ExpHeap direction");
   }

   // Grab the block header pointer and validate everything is sane
   auto alignedBlock = virt_cast<MEMExpHeapBlock *>(alignedDataStart) - 1;
   decaf_check(alignedDataStart - sizeof(MEMExpHeapBlock) >= freeMemStart);
   decaf_check(alignedDataStart + size <= freeMemEnd);

   // Calculate the alignment waste
   auto topSpaceRemain = (alignedDataStart - freeMemStart) - sizeof(MEMExpHeapBlock);
   auto bottomSpaceRemain = static_cast<uint32_t>((freeMemEnd - alignedDataStart) - size);

   if (expHeapAttribs.reuseAlignSpace() || dir == MEMExpHeapDirection::FromEnd) {
      // If the user wants to reuse the alignment space, or we allocated from the bottom,
      //  we should try to release the top space back to the heap free list.
      if (topSpaceRemain > sizeof(MEMExpHeapBlock) + 4) {
         // We have enough room to put some of the memory back to the free list
         freeBlock = virt_cast<MEMExpHeapBlock *>(freeMemStart);
         freeBlock->attribs = MEMExpHeapBlockAttribs::get(0);
         freeBlock->blockSize = static_cast<uint32_t>(topSpaceRemain - sizeof(MEMExpHeapBlock));
         freeBlock->next = nullptr;
         freeBlock->prev = nullptr;
         freeBlock->tag = FreeTag;

         insertBlock(virt_addrof(heap->freeList), freeBlockPrev, freeBlock);
         topSpaceRemain = 0;
      }
   }

   if (expHeapAttribs.reuseAlignSpace() || dir == MEMExpHeapDirection::FromStart) {
      // If the user wants to reuse the alignment space, or we allocated from the top,
      //  we should try to release the bottom space back to the heap free list.
      if (bottomSpaceRemain > sizeof(MEMExpHeapBlock) + 4) {
         // We have enough room to put some of the memory back to the free list
         freeBlock = virt_cast<MEMExpHeapBlock *>(freeMemEnd - bottomSpaceRemain);
         freeBlock->attribs = MEMExpHeapBlockAttribs::get(0);
         freeBlock->blockSize = static_cast<uint32_t>(bottomSpaceRemain - sizeof(MEMExpHeapBlock));
         freeBlock->next = nullptr;
         freeBlock->prev = nullptr;
         freeBlock->tag = FreeTag;

         insertBlock(virt_addrof(heap->freeList), freeBlockPrev, freeBlock);
         bottomSpaceRemain = 0;
      }
   }

   // Update the structure with the new allocation
   alignedBlock->attribs = MEMExpHeapBlockAttribs::get(0)
      .alignment(static_cast<uint32_t>(topSpaceRemain))
      .allocDir(dir);
   alignedBlock->blockSize = size + bottomSpaceRemain;
   alignedBlock->prev = nullptr;
   alignedBlock->next = nullptr;
   alignedBlock->tag = UsedTag;

   insertBlock(virt_addrof(heap->usedList), nullptr, alignedBlock);

   if (heap->header.flags & MEMHeapFlags::ZeroAllocated) {
      memset(alignedDataStart, 0, size);
   } else if (heap->header.flags & MEMHeapFlags::DebugMode) {
      auto fillVal = MEMGetFillValForHeap(MEMHeapFillType::Allocated);
      memset(alignedDataStart, fillVal, size);
   }

   return alignedBlock;
}
コード例 #17
0
ファイル: gamescene.cpp プロジェクト: hellckt/DivineCraft
void GameScene::initGame()
{
    blockVertexShader=new QGLShader(QGLShader::Vertex);
    blockVertexShader->compileSourceFile(QLatin1String(":/res/divinecraft/shader/block.vsh"));
    blockFragmentShader=new QGLShader(QGLShader::Fragment);
    blockFragmentShader->compileSourceFile(QLatin1String(":/res/divinecraft/shader/block.fsh"));
    blockProgram=new QGLShaderProgram;
    blockProgram->addShader(blockVertexShader);
    blockProgram->addShader(blockFragmentShader);
    if(!blockProgram->link()){
        qWarning("Failed to compile and link shader program");
        qWarning("Vertex shader log:");
        qWarning() << blockVertexShader->log();
        qWarning() << blockFragmentShader->log();
        qWarning("Shader program log:");
        qWarning() << blockProgram->log();
        QMessageBox::warning(0,tr("错误"),tr("着色器程序加载失败造成游戏无法正常启动\n"
                                           "请联系开发者寻求解决方案"),QMessageBox::Ok);
        exit(1);
    }

    lineVertexShader=new QGLShader(QGLShader::Vertex);
    lineVertexShader->compileSourceFile(QLatin1String(":/res/divinecraft/shader/line.vsh"));
    lineFragmentShader=new QGLShader(QGLShader::Fragment);
    lineFragmentShader->compileSourceFile(QLatin1String(":/res/divinecraft/shader/line.fsh"));
    lineProgram=new QGLShaderProgram;
    lineProgram->addShader(lineVertexShader);
    lineProgram->addShader(lineFragmentShader);
    if(!lineProgram->link()){
        qWarning("Failed to compile and link shader program");
        qWarning("Vertex shader log:");
        qWarning() << lineVertexShader->log();
        qWarning() << lineFragmentShader->log();
        qWarning("Shader program log:");
        qWarning() << lineProgram->log();
        QMessageBox::warning(0,tr("错误"),tr("着色器程序加载失败造成游戏无法正常启动\n"
                                           "请联系开发者寻求解决方案"),QMessageBox::Ok);
        exit(1);
    }
    ////////////////////////////
    camera=new Camera(QVector3D(0,4,0),QPointF(180.0,0.0));

    world=new World;
    wThread=new QThread;
    world->moveToThread(wThread);
    connect(wThread,SIGNAL(finished()),world,SLOT(deleteLater()));              //线程被销毁的同时销毁world
    connect(this,SIGNAL(reloadWorld()),world,SLOT(forcedUpdateWorld()));                //强制进行世界刷新
    connect(camera,SIGNAL(cameraMove(QVector3D)),world,SLOT(changeCameraPosition(QVector3D)));          //连接camera移动与世界相机位移的槽
    connect(this,SIGNAL(resetRenderLen()),world,SLOT(updateWorld()));
    connect(this,SIGNAL(addBlock()),camera,SLOT(addBlock()));
    connect(this,SIGNAL(removeBlock()),camera,SLOT(removeBlock()));
    connect(world,SIGNAL(loadOver()),this,SLOT(loadOverSlot()));
    wThread->start();

    //    world->setMaxRenderLen(maxRenderLen);
    world->setWorldName("new_world");
    camera->setWorld(world);                                //传递世界指针
    ///////////////////////////
    //这里是一个规定的加载顺序,后步骤会依赖于前步骤
    world->loadBlockIndex();            //加载方块属性列表

    loadTexture();                      //加载纹理
    //======================
    line=new LineMesh(2);           //十字准心
    float lineLen=0.0004;
    line->addLine(QVector3D(-lineLen,0,-0.02),QVector3D(lineLen,0,-0.02));
    line->addLine(QVector3D(0,-lineLen,-0.02),QVector3D(0,lineLen,-0.02));

    lineQua=new LineMesh(12);           //被选方块的包围线框

    //=======================
    //数据面板
    dataPanel=new DataPanel(0,0,200,100);
    addItem(dataPanel);
    glFps=0;
    drawCount=0;
    dataPanel->setRenderLen(maxRenderLen);
    connect(camera,SIGNAL(getPositions(QVector3D,QVector3D)),this,SLOT(dataShowPosition(QVector3D,QVector3D)));
    //    dataPanel->hide();
    //背包物品栏
    backPackBar=new BackPackBar(this);
    hideBackPackBar();
    backPackBar->setWorld(world);               //传递world指针
    //物品栏
    itemBar=new ItemBar(this);
    connect(itemBar,SIGNAL(thingIndexChange(int)),camera,SLOT(setBlockId(int)));
    backPackBar->setPocket(itemBar);
    //=======================
    //消息面板
    messagePanel=new MessagePanel;
    addItem(messagePanel);
    //===========================
    //选项菜单
    opWidget=new OptionsWidget();
    opWidgetProxy=new QGraphicsProxyWidget(0);
    opWidgetProxy->setWidget(opWidget);
    this->addItem(opWidgetProxy);
    opWidgetProxy->hide();
    inOpWidget=false;

    connect(opWidget,SIGNAL(continueGame()),this,SLOT(continueGame()));
    connect(opWidget,SIGNAL(mouseLevelValueChange(int)),camera,SLOT(setMouseLevel(int)));
    connect(opWidget,SIGNAL(renderValueChange(int)),this,SLOT(setRenderLen(int)));
    connect(opWidget,SIGNAL(quitClick()),gView,SLOT(close()));
    //=============================
    loadSettings();
    camera->loadPosRot();                                   //加载位置视角信息
    setRenderLen(maxRenderLen);                     //设置渲染距离并刷新整个世界
    opWidget->setRenderLen(maxRenderLen);
    opWidget->setMouseLevel(camera->getMouseLevel());
}
コード例 #18
0
uint32_t
MEMResizeForMBlockExpHeap(MEMHeapHandle handle,
                          virt_ptr<void> ptr,
                          uint32_t size)
{
   auto heap = virt_cast<MEMExpHeap *>(handle);
   internal::HeapLock lock { virt_addrof(heap->header) };
   size = align_up(size, 4);

   auto block = getUsedMemBlock(ptr);

   if (size < block->blockSize) {
      auto releasedSpace = block->blockSize - size;

      if (releasedSpace > sizeof(MEMExpHeapBlock) + 0x4) {
         auto releasedMemEnd = getBlockMemEnd(block);
         auto releasedMemStart = releasedMemEnd - releasedSpace;

         block->blockSize -= releasedSpace;
         releaseMemory(heap, releasedMemStart, releasedMemEnd);
      }
   } else if (size > block->blockSize) {
      auto blockMemEnd = getBlockMemEnd(block);
      auto freeBlock = virt_ptr<MEMExpHeapBlock> { nullptr };

      for (auto i = heap->freeList.head; i; i = i->next) {
         auto freeBlockMemStart = getBlockMemStart(i);

         if (freeBlockMemStart == blockMemEnd) {
            freeBlock = i;
            break;
         }

         // Free list is sorted, so we only need to search a little bit
         if (freeBlockMemStart > blockMemEnd) {
            break;
         }
      }

      if (!freeBlock) {
         return 0;
      }

      // Grab the data we need from the free block
      auto freeBlockMemStart = getBlockMemStart(freeBlock);
      auto freeBlockMemEnd = getBlockMemEnd(freeBlock);
      auto freeMemSize = static_cast<uint32_t>(freeBlockMemEnd - freeBlockMemStart);

      // Drop the free block from the list of free regions
      removeBlock(virt_addrof(heap->freeList), freeBlock);

      // Adjust the sizing of the free area and the block
      auto newAllocSize = (size - block->blockSize);
      freeMemSize -= newAllocSize;
      block->blockSize = size;

      if (heap->header.flags & MEMHeapFlags::ZeroAllocated) {
         memset(freeBlockMemStart, 0, newAllocSize);
      } else if(heap->header.flags & MEMHeapFlags::DebugMode) {
         auto fillVal = MEMGetFillValForHeap(MEMHeapFillType::Allocated);
         memset(freeBlockMemStart, fillVal, newAllocSize);
      }

      // If we have enough room to create a new free block, lets release
      //  the memory back to the heap.  Otherwise we just tack the remainder
      //  onto the end of the block we resized.
      if (freeMemSize >= sizeof(MEMExpHeapBlock) + 0x4) {
         releaseMemory(heap, freeBlockMemEnd - freeMemSize, freeBlockMemEnd);
      } else {
         block->blockSize += freeMemSize;
      }
   }

   return block->blockSize;
}
コード例 #19
0
void DeleteBlockCommand::redo()
{
	removeBlock();
}