void MultiBlockMeshFactory::buildElements(stk::ParallelMachine parallelMach,STK_Interface & mesh) const
{
   mesh.beginModification();

   if(machRank_==0) {
      buildBlock(parallelMach,0,0,mesh);
   }
   else if(machRank_==1) {
      buildBlock(parallelMach,0,1,mesh);
   }
   else TEUCHOS_ASSERT(false);

   mesh.endModification();
}
void SculptMeshFactory::buildElements(stk_classic::ParallelMachine parallelMach,STK_Interface & mesh) const
{
   struct MeshStorageStruct *mss = get_sculpt_mesh();
   int num_blocks  = mss->num_elem_blk;
  

   int *block_id = new int[num_blocks];
   //char ** element_types = new std::string[num_blocks];
   int *elements = new int[num_blocks];
   int *nodes_per_element = new int[num_blocks];
   int *element_attributes = new int[num_blocks];
   int **elmt_node_linkage = new int*[num_blocks];

   for(int b = 0; b < num_blocks; b++){
      block_id[b] = mss->block_id[b];
    //  element_types[b] = mss->element_types[b];
      elements[b] = mss->elements[b];
      nodes_per_element[b] = mss->nodes_per_element[b];
      element_attributes[b] = mss->element_attributes[b];
   }


   int elm_start = 1;
   mesh.beginModification();
   // build each block
   for(int ib=0;ib<num_blocks;ib++) {
     buildBlock(parallelMach,mesh, ib, block_id, elm_start, elements, nodes_per_element, element_attributes, elmt_node_linkage );
     elm_start += elements[ib];
   }
   mesh.endModification();
}
void LineMeshFactory::buildElements(stk::ParallelMachine parallelMach,STK_Interface & mesh) const
{
   mesh.beginModification();
      // build each block
      for(int xBlock=0;xBlock<xBlocks_;xBlock++) {
         buildBlock(parallelMach,xBlock,mesh);
      }
   mesh.endModification();
}
void CubeTetMeshFactory::buildElements(stk_classic::ParallelMachine parallelMach,STK_Interface & mesh) const
{
   mesh.beginModification();
      // build each block
      for(int xBlock=0;xBlock<xBlocks_;xBlock++) {
         for(int yBlock=0;yBlock<yBlocks_;yBlock++) {
            for(int zBlock=0;zBlock<zBlocks_;zBlock++) {
               buildBlock(parallelMach,xBlock,yBlock,zBlock,mesh);
            }
         }
      }
   mesh.endModification();
}
Exemple #5
0
static void buildAllBlocks()
{
    auto e = mapVec.end();
    auto i = mapVec.begin();
    while(i!=e) {

        const Map *map = gCurMap = &(*(i++));
        const uint8_t *end = map->size + map->p;
        const uint8_t *p = map->p;

        startMap(p);

            while(1) {
                if(unlikely(end<=p)) break;
                bool done = buildBlock(p, end);
                if(done) break;
            }

        endMap(p);
    }
}
// make sure that all the desired data is in place and then copy the data into MAX_BUFFER_SIZEd buffer
U32 LLTemplateMessageBuilder::buildMessage(
	U8* buffer,
	U32 buffer_size,
	U8 offset_to_data)
{
	// basic algorithm is to loop through the various pieces, building
	// size and offset info if we encounter a -1 for mSize at any
	// point that variable wasn't given data

	// do we have a current message?
	if (!mCurrentSMessageTemplate)
	{
		llerrs << "newMessage not called prior to buildMessage" << llendl;
		return 0;
	}

	// leave room for flags, packet sequence #, and data offset
	// information.
	buffer[PHL_OFFSET] = offset_to_data;
	U32 result = LL_PACKET_ID_SIZE;

	// encode message number and adjust total_offset
	if (mCurrentSMessageTemplate->mFrequency == MFT_HIGH)
	{
// old, endian-dependant way
//		memcpy(&buffer[result], &mCurrentMessageTemplate->mMessageNumber, sizeof(U8));

// new, independant way
		buffer[result] = (U8)mCurrentSMessageTemplate->mMessageNumber;
		result += sizeof(U8);
	}
	else if (mCurrentSMessageTemplate->mFrequency == MFT_MEDIUM)
	{
		U8 temp = 255;
		memcpy(&buffer[result], &temp, sizeof(U8));  /*Flawfinder: ignore*/
		result += sizeof(U8);

		// mask off unsightly bits
		temp = mCurrentSMessageTemplate->mMessageNumber & 255;
		memcpy(&buffer[result], &temp, sizeof(U8));  /*Flawfinder: ignore*/
		result += sizeof(U8);
	}
	else if (mCurrentSMessageTemplate->mFrequency == MFT_LOW)
	{
		U8 temp = 255;
		U16  message_num;
		memcpy(&buffer[result], &temp, sizeof(U8));  /*Flawfinder: ignore*/
		result += sizeof(U8);
		memcpy(&buffer[result], &temp, sizeof(U8));  /*Flawfinder: ignore*/
		result += sizeof(U8);

		// mask off unsightly bits
		message_num = mCurrentSMessageTemplate->mMessageNumber & 0xFFFF;

	    // convert to network byte order
		message_num = htons(message_num);
		memcpy(&buffer[result], &message_num, sizeof(U16)); /*Flawfinder: ignore*/
		result += sizeof(U16);
	}
	else
	{
		llerrs << "unexpected message frequency in buildMessage" << llendl;
		return 0;
	}

	// fast forward through the offset and build the message
	result += offset_to_data;
	for(LLMessageTemplate::message_block_map_t::const_iterator
			iter = mCurrentSMessageTemplate->mMemberBlocks.begin(),
			end = mCurrentSMessageTemplate->mMemberBlocks.end();
		 iter != end;
		++iter)
	{
		result += buildBlock(buffer + result, buffer_size - result, *iter, mCurrentSMessageData);
	}
	mbSBuilt = TRUE;

	return result;
}
Exemple #7
0
///=============================================================================
static void* processChunk(void* ThreadInfoPtr){
	// Get pointer to the thread info struct
    sm2obj::threadInfoStruct* threadInfo = static_cast<sm2obj::threadInfoStruct*>(ThreadInfoPtr);
    // Lock this thread
    threadInfo->mut.lock();
    // Get chunk pointer
    sm2obj::chunkInfoStruct* chunk = threadInfo->chunkPtr;

    // Load chunk from file
    uint32_t chunkData[16][16][16];
    if(!sm2obj::loadTempChunk(threadInfo->tempFolder, chunk->fileIndex, &chunkData[0][0][0])){
        ffw::logError() << "Error loading chunk file index: " << chunk->fileIndex;
        threadInfo->mut.unlock();
        return NULL;
    }

    // Reset buffer A
    threadInfo->chunkBufferA.indicesCount = 0;
    threadInfo->chunkBufferA.verticesCount = 0;
    threadInfo->chunkBufferA.indicesOffset = 0;

    // Build blocks by looking through all XYZ positions in chunk
    ffw::vec3i posRel;
    for(posRel.z = 0; posRel.z < 16; posRel.z++){
        for(posRel.y = 0; posRel.y < 16; posRel.y++){
            for(posRel.x = 0; posRel.x < 16; posRel.x++){
                if(chunkData[posRel.z][posRel.y][posRel.x] == 0)continue;

                buildBlock(posRel, chunk->pos, chunk->posFile, chunkData, &threadInfo->chunkBufferA, threadInfo->blockInfo);

            }
        }
    }

    // Reset buffer B
    threadInfo->chunkBufferB.indicesCount = 0;
    threadInfo->chunkBufferB.verticesCount = 0;
    threadInfo->chunkBufferB.indicesOffset = 0;

    // Filter polygons that occupies same space
    removeDuplicatedFaces(&threadInfo->chunkBufferA, &threadInfo->chunkBufferB);

    // Now the data is in buffer B
    // We will use buffer A as a output
    threadInfo->chunkBufferA.indicesCount = 0;
    threadInfo->chunkBufferA.verticesCount = 0;
    threadInfo->chunkBufferA.indicesOffset = 0;

    // Remove duplicated vertices
    removeDuplicatedVertices(&threadInfo->chunkBufferB, &threadInfo->chunkBufferA);

    // Transform vertices
    ffw::vec3f translation(-8.0f, -8.0f, -8.0f);
    //ffw::vec3f dockOffset = threadInfo->entityPtr->dockModule - ffw::vec3f(8.0f, 8.0f, 8.0f);
    //translation -= dockOffset;

    /*ffw::mat4 m;
    ffw::vec3f globalPos;

    sm2obj::entityInfoStruct* entity = threadInfo->entityPtr;
    std::vector<sm2obj::entityInfoStruct*> entityStack;
    while(entity != NULL){
        entityStack.push_back(entity);
        entity = entity->parent;
    }

    if(entityStack.size() > 0){
        for(int i = entityStack.size()-1; i >= 0; i--){
            m.rotate(entityStack[i]->orientation);
        }
    }

    ffw::mat4 mr;
    entity = threadInfo->entityPtr;
    while(entity != NULL){

        ffw::vec3f pos = (entity->pos - ffw::vec3f(8.0f, 8.0f, 8.0f));
        ffw::vec3f dockModule;
        ffw::vec3f offset = entity->dockOffset;
        //std::cout << "pos: " << pos << std::endl;
        //std::cout << "dockOffset: " << offset << std::endl;

        //ffw::vec4f v;
        ffw::mat4 rr;
        constructRotation(entity, &rr);

        entity = entity->parent;

        if(entity != NULL){
            dockModule = (entity->dockModule - ffw::vec3f(8.0f, 8.0f, 8.0f));
            ffw::mat4 mr;

            constructRotation(entity, &mr);

            ffw::vec4f v;
            v.x = pos.x;
            v.y = pos.y;
            v.z = pos.z;
            v = mr * v;
            pos.x = v.x;
            pos.y = v.y;
            pos.z = v.z;

            v.x = offset.x;
            v.y = offset.y;
            v.z = offset.z;
            v.w = 1.0f;
            v = mr * v;
            offset.x = v.x;
            offset.y = v.y;
            offset.z = v.z;

            v.x = dockModule.x;
            v.y = dockModule.y;
            v.z = dockModule.z;
            v.w = 1.0f;
            v = mr * v;
            dockModule.x = v.x;
            dockModule.y = v.y;
            dockModule.z = v.z;
        }
        globalPos -= dockModule;
        globalPos += pos + offset;
    }*/

    for(uint32_t i = 0; i < threadInfo->chunkBufferA.verticesCount; i++){
        threadInfo->chunkBufferA.vertices[i] += translation;
        /*ffw::vec4f v;

        v.x = threadInfo->chunkBufferA.vertices[i].x;
        v.y = threadInfo->chunkBufferA.vertices[i].y;
        v.z = threadInfo->chunkBufferA.vertices[i].z;
        v.w = 1.0f;
        v = m * v;
        threadInfo->chunkBufferA.vertices[i].x = v.x;
        threadInfo->chunkBufferA.vertices[i].y = v.y;
        threadInfo->chunkBufferA.vertices[i].z = v.z;
        threadInfo->chunkBufferA.vertices[i] += globalPos;*/
    }

    // Now the data is in buffer A
    // Save it to temp file
    saveRawBlocks(threadInfo->tempFolder, &threadInfo->chunkBufferA, chunk->fileIndex);

    ffw::logSuccess() << "Chunk index: " << chunk->fileIndex << " exported!";

    // Unlock this thread
    threadInfo->mut.unlock();
    return NULL;
}
Exemple #8
0
void Game::update() {
	// block - platform collision
	for (auto block : extraBlocks) {
		if (selected != block) {
			block->applyGravity(*physics);
			for (auto platform : platforms) {
				if (platform->isColliding(*block)) {
					block->applyAntiGravity(*physics);
					break;
				}
			}
		}
	}

	// block - block collision
	for (std::list<std::shared_ptr<GameObject>>::iterator it = extraBlocks.begin(); it != extraBlocks.end(); ) {
		std::shared_ptr<GameObject> tmp = *it;
		for (std::list<std::shared_ptr<GameObject>>::iterator iter = ++it ; iter != extraBlocks.end(); ++iter) {
			if (tmp->isColliding(*(*iter))) {
				tmp->applyAntiGravity(*physics);
				break;
			}
		}
	}

	// player - platform collision
	if (!god) {
		bool death = true;

		for (auto plat : platforms) {
			if (player->isColliding(*plat)) {
				death = false;
				break;
			}
		}

		if (death)
			currentCutScene = CutScene::PLAYER_DEATH;
	}

	// handle player's grabbed cube
	buildBlock();

	// every five seconds destroy a platform
	if (worldTimer.getElapsed() >= 5 * __SECOND) {
		killPlatform();
		worldTimer.measure();
	}

	if (mainBlocks.size() == currentLevel->width * currentLevel->height) {	// TODO: optimize
		player->addScore(SCORE_PER_STEP);
		nextStep();
	}

	if (player->isColliding(*prize)) {	// player reached prize aka end of level
		player->addScore(SCORE_PER_LEVEL);
		currentCutScene = CutScene::LEVEL_END;
	}

	crosshair->setCenter(player->getCenter() + Vector3f(0, 1.0f, 0) + player->getDirection() * 2.0f);
	crosshair->setRotate(player->getVerAngle(), -player->getHorAngle(), -player->getVerAngle());
}
/* setup */
ENTRYPOINT void 
init_topBlock (ModeInfo *mi)
{
  topBlockSTATE *tb;
  int wire = MI_IS_WIREFRAME(mi);

  if (!tbs) {
    tbs = (topBlockSTATE *)
      calloc (MI_NUM_SCREENS(mi), sizeof (topBlockSTATE));
    if (!tbs) abort();
  }

  tb = &tbs[MI_SCREEN(mi)];

  tb->glx_context = init_GL(mi);

  reshape_topBlock (mi, MI_WIDTH(mi), MI_HEIGHT(mi));

/*	if (wire) { drawNipples=False; }*/
  tb->numFallingBlocks=0;

	if (size>10) { size = 10; }
	if (size<1) { size = 2; }
	tb->carpetWidth = 8 * size;
	tb->carpetLength = tb->carpetWidth;
  
  maxFalling*=size;

	if (spawn<4) { spawn=4; }
	if (spawn>1000) { spawn=1000; }

	if (rotateSpeed<1) {rotateSpeed=1; }
	if (rotateSpeed>1000) {rotateSpeed=1000;}
  rotateSpeed /= 100;

	if (resolution<4) {resolution=4;}
	if (resolution>20) {resolution=20;}
  resolution*=2;

	if (maxColors<1) {maxColors=1;}
	if (maxColors>8) {maxColors=8;}

	if (dropSpeed<1) {dropSpeed=1;}
	if (dropSpeed>9) {dropSpeed=9;} /* 10+ produces blocks that can pass through each other */
  
	dropSpeed = 80/dropSpeed;
	dropSpeed = (blockHeight/dropSpeed); 

  reshape_topBlock (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
  glClearDepth(1.0f);
  if (!wire) {
    GLfloat pos[4] = {10.0, 10.0, 1.0, 0.0};
    GLfloat amb[4] = {0.1, 0.1, 0.1, 1.0};
    GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0};
    GLfloat spc[4] = {0.0, 1.0, 1.0, 1.0};

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glLightfv(GL_LIGHT0, GL_POSITION, pos);
    glLightfv(GL_LIGHT0, GL_AMBIENT,  amb); 
    glLightfv(GL_LIGHT0, GL_DIFFUSE,  dif);
    glLightfv(GL_LIGHT0, GL_SPECULAR, spc); 
  }
	glDepthFunc(GL_LEQUAL);
  glEnable(GL_DEPTH_TEST);
  glDisable(GL_CULL_FACE); /* all objects exhibit a reverse side */
  glCullFace(GL_BACK); 

	if (drawBlob) {
    buildBlobBlock(mi); 
	} else {
	  buildBlock(mi);		/* build the display list holding the simple block */
	}
  buildCarpet(mi);		/* build the base */
	tb->highest=0;
	tb->highestFalling=0;
	tb->eyeLine=tb->highest;
	tb->eyeX=0;
	tb->eyeY=0;
	tb->eyeZ=0;
	tb->followMode=0;
  if (follow) {
    tb->plusheight=100;
    camZ=camZ-60;
  } else {
    tb->rotation=random() % 360;
    tb->eyeY=10;
    tb->plusheight=30;
  }
	tb->followRadius=0;
  /* override camera settings */
  if (override) {
    tb->plusheight=100;
    drawCarpet=False;
    camX=0;
    camY=1;
    camZ=0;
    tb->eyeX=-1;
    tb->eyeY=20;
    tb->eyeZ=0;
  }
  tb->trackball = gltrackball_init ();
}