void ttFillWithCurrentBlock(tetris_table* t) { block* b = t->next_block[0]; for (uint16_t s = 0; s < blockSize(b); ++s) { position p = blockPosition(b, s); p.x += t->currentPos.x; p.y += t->currentPos.y; if (p.x < t->size.x && p.y < t->size.y && p.x >= 0 && p.y >= 0) { t->tab[p.y][p.x].type = blockType(b); t->tab[p.y][p.x].empty = 0; } } }
// // Make the passed-in variable information become a member of the // global uniform block. If this doesn't exist yet, make it. // void TParseContextBase::growGlobalUniformBlock(TSourceLoc& loc, TType& memberType, TString& memberName) { // make the global block, if not yet made if (globalUniformBlock == nullptr) { TString& blockName = *NewPoolTString(getGlobalUniformBlockName()); TQualifier blockQualifier; blockQualifier.clear(); blockQualifier.storage = EvqUniform; TType blockType(new TTypeList, blockName, blockQualifier); TString* instanceName = NewPoolTString(""); globalUniformBlock = new TVariable(instanceName, blockType, true); firstNewMember = 0; } // add the requested member as a member to the block TType* type = new TType; type->shallowCopy(memberType); type->setFieldName(memberName); TTypeLoc typeLoc = {type, loc}; globalUniformBlock->getType().getWritableStruct()->push_back(typeLoc); }
// // Make the passed-in variable information become a member of the // global uniform block. If this doesn't exist yet, make it. // void TParseContextBase::growGlobalUniformBlock(const TSourceLoc& loc, TType& memberType, const TString& memberName, TTypeList* typeList) { // Make the global block, if not yet made. if (globalUniformBlock == nullptr) { TQualifier blockQualifier; blockQualifier.clear(); blockQualifier.storage = EvqUniform; TType blockType(new TTypeList, *NewPoolTString(getGlobalUniformBlockName()), blockQualifier); setUniformBlockDefaults(blockType); globalUniformBlock = new TVariable(NewPoolTString(""), blockType, true); firstNewMember = 0; } // Update with binding and set globalUniformBlock->getWritableType().getQualifier().layoutBinding = globalUniformBinding; globalUniformBlock->getWritableType().getQualifier().layoutSet = globalUniformSet; // Add the requested member as a member to the global block. TType* type = new TType; type->shallowCopy(memberType); type->setFieldName(memberName); if (typeList) type->setStruct(typeList); TTypeLoc typeLoc = {type, loc}; globalUniformBlock->getType().getWritableStruct()->push_back(typeLoc); // Insert into the symbol table. if (firstNewMember == 0) { // This is the first request; we need a normal symbol table insert if (symbolTable.insert(*globalUniformBlock)) trackLinkage(*globalUniformBlock); else error(loc, "failed to insert the global constant buffer", "uniform", ""); } else { // This is a follow-on request; we need to amend the first insert symbolTable.amend(*globalUniformBlock, firstNewMember); } ++firstNewMember; }
char ttStep(tetris_table* t, const control* c, uint32_t *points_var) { if (c->rot == dir_left && ttCanTurn(t, 0)) blockRotate(t->next_block[0], 0); else if (c->rot == dir_right && ttCanTurn(t, 1)) blockRotate(t->next_block[0], 1); if (c->mov == dir_left && ttCanMove(t, 0)) --t->currentPos.x; else if (c->mov == dir_right && ttCanMove(t, 1)) ++t->currentPos.x; if (c->doStep) { if (ttCanMoveDown(t)) ++t->currentPos.y; else { ttFillWithCurrentBlock(t); *points_var += blockType(t->next_block[0]); ttNewNextBlock(t); ttResetCurrentPosition(t); uint32_t p = ttCleanFilledLines(t); if (p > 0) { uint32_t v = 1; for (uint16_t k = 0; k < p; ++k) v *= 2; *points_var += 100*v; } if (!t->tab[0][t->currentPos.x].empty) return 1; } } return 0; }
void MapEditor::writeTerrainToFile(std::string filename){ std::string posString; std::string output; std::ofstream terrainfile(filename); if (terrainfile.is_open()){ for (Terrains::size_type i = 0; i < mTerrains.size(); i++){ terrainfile << std::endl; // Inserts typename into output followed by '-' switch (mTerrains[i]->getType()){ case Terrain::BLOCK0: output.push_back('B'); output.push_back('0'); // Push what type of block it is for (int i1 = 0; i1 < blockType(mTerrains[i]).size(); i1++) { output.push_back(blockType(mTerrains[i])[i1]); } break; case Terrain::BLOCK0WALLJUMP: output.push_back('B'); output.push_back('W'); // Push what type of block it is for (int i1 = 0; i1 < blockType(mTerrains[i]).size(); i1++) { output.push_back(blockType(mTerrains[i])[i1]); } break; case Terrain::BLOCK0ICY: output.push_back('B'); output.push_back('I'); // Push what type of block it is for (int i1 = 0; i1 < blockType(mTerrains[i]).size(); i1++) { output.push_back(blockType(mTerrains[i])[i1]); } break; case Terrain::SPIKES: output.push_back('S'); output.push_back('0'); // Push what rot is has output.push_back(mTerrains[i]->getTileType()); break; case Terrain::BLOCKGOAL: output.push_back('G'); output.push_back('0'); break; case Terrain::EVENT: output.push_back('E'); output.push_back('V'); output.push_back(mTerrains[i]->getTileType()); posString = MapEditor::floatToString(mTerrains[i]->getWidth()); for (std::string::size_type iS = 0; iS < posString.size(); iS++) { output.push_back(posString[iS]); } output.push_back(','); posString = MapEditor::floatToString(mTerrains[i]->getHeight()); for (std::string::size_type iS = 0; iS < posString.size(); iS++) { output.push_back(posString[iS]); } break; case Terrain::MEATBALLSPAWNER: output.push_back('M'); output.push_back('0'); break; default: break; } output.push_back('|'); // Inserts xpos into output followed by a ',' posString = MapEditor::floatToString(mTerrains[i]->getPos().x + mTerrains[i]->getOffset().x); for (std::string::size_type iS = 0; iS < posString.size(); iS++){ output.push_back(posString[iS]); } output.push_back(','); // Inserts ypos into output posString = MapEditor::floatToString(mTerrains[i]->getPos().y + mTerrains[i]->getOffset().y); for (std::string::size_type iS = 0; iS < posString.size(); iS++){ output.push_back(posString[iS]); } // Writes output into file terrainfile << output; // output.clear(); posString.clear(); } } terrainfile.close(); }