コード例 #1
0
ファイル: MapScript.cpp プロジェクト: AngledStream/OpenXcom
/**
 * Gets a random map block from a given terrain, using either the groups or the blocks defined.
 * @param terrain the terrain to pick a block from.
 * @return Pointer to a randomly chosen map block, given the options available.
 */
MapBlock *MapScript::getNextBlock(RuleTerrain *terrain)
{
	if (_blocks.empty())
	{
		return terrain->getRandomMapBlock(_sizeX * 10, _sizeY * 10, getGroupNumber());
	}
	int result = getBlockNumber();
	if (result < (int)(terrain->getMapBlocks()->size()) && result != MT_UNDEFINED)
	{
		return terrain->getMapBlocks()->at((size_t)(result));
	}
	return 0;
}
コード例 #2
0
ファイル: ObjFileParser.cpp プロジェクト: NevilX/assimp
// -------------------------------------------------------------------
//	File parsing method.
void ObjFileParser::parseFile()
{
	if (m_DataIt == m_DataItEnd)
		return;

	while (m_DataIt != m_DataItEnd)
	{
		switch (*m_DataIt)
		{
		case 'v': // Parse a vertex texture coordinate
			{
				++m_DataIt;
				if (*m_DataIt == ' ' || *m_DataIt == '\t') {
					// read in vertex definition
					getVector3(m_pModel->m_Vertices);
				} else if (*m_DataIt == 't') {
					// read in texture coordinate ( 2D or 3D )
                    ++m_DataIt;
                    getVector( m_pModel->m_TextureCoord );
				} else if (*m_DataIt == 'n') {
					// Read in normal vector definition
					++m_DataIt;
					getVector3( m_pModel->m_Normals );
				}
			}
			break;

		case 'p': // Parse a face, line or point statement
		case 'l':
		case 'f':
			{
				getFace(*m_DataIt == 'f' ? aiPrimitiveType_POLYGON : (*m_DataIt == 'l' 
					? aiPrimitiveType_LINE : aiPrimitiveType_POINT));
			}
			break;

		case '#': // Parse a comment
			{
				getComment();
			}
			break;

		case 'u': // Parse a material desc. setter
			{
				getMaterialDesc();
			}
			break;

		case 'm': // Parse a material library or merging group ('mg')
			{
				if (*(m_DataIt + 1) == 'g')
					getGroupNumberAndResolution();
				else
					getMaterialLib();
			}
			break;

		case 'g': // Parse group name
			{
				getGroupName();
			}
			break;

		case 's': // Parse group number
			{
				getGroupNumber();
			}
			break;

		case 'o': // Parse object name
			{
				getObjectName();
			}
			break;
		
		default:
			{
				m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
			}
			break;
		}
	}
}
コード例 #3
0
ファイル: ObjFileParser.cpp プロジェクト: macieks/uberengine
// -------------------------------------------------------------------
void ObjFileParser::parseFile()
{
	if (m_DataIt == m_DataItEnd)
		return;

	while (m_DataIt != m_DataItEnd)
	{
		switch (*m_DataIt)
		{
		case 'v': // Parse a vertex texture coordinate
			{
				++m_DataIt;
				if (*m_DataIt == ' ')
				{
					// Read in vertex definition
					getVector3(m_pModel->m_Vertices);
				}
				else if (*m_DataIt == 't')
				{
					// Read in texture coordinate (2D)
					++m_DataIt;
					getVector2(m_pModel->m_TextureCoord);
				}
				else if (*m_DataIt == 'n')
				{
					// Read in normal vector definition
					++m_DataIt;
					getVector3( m_pModel->m_Normals );
				}
			}
			break;

		case 'f': // Parse a face
			{
				getFace();
			}
			break;

		case '#': // Parse a comment
			{
				getComment();
			}
			break;

		case 'u': // Parse a material desc. setter
			{
				getMaterialDesc();
			}
			break;

		case 'm': // Parse a material library
			{
				getMaterialLib();
			}
			break;

		case 'g': // Parse group name
			{
				getGroupName();
			}
			break;

		case 's': // Parse group number
			{
				getGroupNumber();
			}
			break;

		case 'o': // Parse object name
			{
				getObjectName();
			}
			break;
		
		default:
			{
				m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
			}
			break;
		}
	}
}
コード例 #4
0
ファイル: ObjFileParser.cpp プロジェクト: RSATom/Qt
// -------------------------------------------------------------------
//  File parsing method.
void ObjFileParser::parseFile()
{
    if (m_DataIt == m_DataItEnd)
        return;

    // only update every 100KB or it'll be too slow
    const unsigned int updateProgressEveryBytes = 100 * 1024;
    unsigned int progressCounter = 0;
    const unsigned int bytesToProcess = std::distance(m_DataIt, m_DataItEnd);
    const unsigned int progressTotal = 3 * bytesToProcess;
    const unsigned int progressOffset = bytesToProcess;
    unsigned int processed = 0;

    DataArrayIt lastDataIt = m_DataIt;

    while (m_DataIt != m_DataItEnd)
    {
        // Handle progress reporting
        processed += std::distance(lastDataIt, m_DataIt);
        lastDataIt = m_DataIt;
        if (processed > (progressCounter * updateProgressEveryBytes))
        {
            progressCounter++;
            m_progress->UpdateFileRead(progressOffset + processed*2, progressTotal);
        }

        // parse line
        switch (*m_DataIt)
        {
        case 'v': // Parse a vertex texture coordinate
            {
                ++m_DataIt;
                if (*m_DataIt == ' ' || *m_DataIt == '\t') {
                    size_t numComponents = getNumComponentsInLine();
                    if (numComponents == 3) {
                        // read in vertex definition
                        getVector3(m_pModel->m_Vertices);
                    } else if (numComponents == 6) {
                        // read vertex and vertex-color
                        getTwoVectors3(m_pModel->m_Vertices, m_pModel->m_VertexColors);
                    }
                } else if (*m_DataIt == 't') {
                    // read in texture coordinate ( 2D or 3D )
                                        ++m_DataIt;
                                        getVector( m_pModel->m_TextureCoord );
                } else if (*m_DataIt == 'n') {
                    // Read in normal vector definition
                    ++m_DataIt;
                    getVector3( m_pModel->m_Normals );
                }
            }
            break;

        case 'p': // Parse a face, line or point statement
        case 'l':
        case 'f':
            {
                getFace(*m_DataIt == 'f' ? aiPrimitiveType_POLYGON : (*m_DataIt == 'l'
                    ? aiPrimitiveType_LINE : aiPrimitiveType_POINT));
            }
            break;

        case '#': // Parse a comment
            {
                getComment();
            }
            break;

        case 'u': // Parse a material desc. setter
            {
                getMaterialDesc();
            }
            break;

        case 'm': // Parse a material library or merging group ('mg')
            {
                if (*(m_DataIt + 1) == 'g')
                    getGroupNumberAndResolution();
                else
                    getMaterialLib();
            }
            break;

        case 'g': // Parse group name
            {
                getGroupName();
            }
            break;

        case 's': // Parse group number
            {
                getGroupNumber();
            }
            break;

        case 'o': // Parse object name
            {
                getObjectName();
            }
            break;

        default:
            {
                m_DataIt = skipLine<DataArrayIt>( m_DataIt, m_DataItEnd, m_uiLine );
            }
            break;
        }
    }
}
コード例 #5
0
ファイル: RankingMngr.cpp プロジェクト: Foorgol/QTournament
  ERR RankingMngr::updateRankingsAfterMatchResultChange(const Match& ma, const MatchScore& oldScore, bool skipSorting) const
  {
    if (ma.getState() != STAT_MA_FINISHED) return WRONG_STATE;

    Category cat = ma.getCategory();
    int catId = cat.getId();
    int firstRoundToModify = ma.getMatchGroup().getRound();

    // determine the score differences (delta) for each affected player pair
    MatchScore newScore = *(ma.getScore());  // is guaranteed to be != nullptr
    tuple<int, int, int> deltaMatches_P1{0,0,0};  // to be added to PlayerPair1
    tuple<int, int, int> deltaMatches_P2{0,0,0};  // to be added to PlayerPair2

    int oldWinner = oldScore.getWinner();
    int newWinner = newScore.getWinner();
    if ((oldWinner == 0) && (newWinner == 1))
    {
      deltaMatches_P1 = tuple<int, int, int>{1, 0, -1};
      deltaMatches_P2 = tuple<int, int, int>{0, 1, -1};
    }
    if ((oldWinner == 0) && (newWinner == 2))
    {
      deltaMatches_P1 = tuple<int, int, int>{0, 1, -1};
      deltaMatches_P2 = tuple<int, int, int>{1, 0, -1};
    }
    if ((oldWinner == 1) && (newWinner == 0))
    {
      deltaMatches_P1 = tuple<int, int, int>{-1, 0, 1};
      deltaMatches_P2 = tuple<int, int, int>{0, -1, 1};
    }
    if ((oldWinner == 2) && (newWinner == 0))
    {
      deltaMatches_P1 = tuple<int, int, int>{0, -1, 1};
      deltaMatches_P2 = tuple<int, int, int>{-1, 0, 1};
    }
    if ((oldWinner == 1) && (newWinner == 2))
    {
      deltaMatches_P1 = tuple<int, int, int>{-1, 1, 0};
      deltaMatches_P2 = tuple<int, int, int>{1, -1, 0};
    }
    if ((oldWinner == 2) && (newWinner == 1))
    {
      deltaMatches_P1 = tuple<int, int, int>{1, -1, 0};
      deltaMatches_P2 = tuple<int, int, int>{-1, 1, 0};
    }

    tuple<int, int> gameSumOld = oldScore.getGameSum();
    tuple<int, int> gameSumNew = newScore.getGameSum();
    int gamesTotalOld = get<0>(gameSumOld) + get<1>(gameSumOld);
    int gamesTotalNew = get<0>(gameSumNew) + get<1>(gameSumNew);

    int deltaWonGamesP1 = -get<0>(gameSumOld) + get<0>(gameSumNew);
    int deltaLostGamesP1 = -(gamesTotalOld - get<0>(gameSumOld)) + (gamesTotalNew - get<0>(gameSumNew));
    int deltaWonGamesP2 = -get<1>(gameSumOld) + get<1>(gameSumNew);
    int deltaLostGamesP2 = -(gamesTotalOld - get<1>(gameSumOld)) + (gamesTotalNew - get<1>(gameSumNew));
    tuple<int, int> deltaGames_P1{deltaWonGamesP1, deltaLostGamesP1};  // to be added to PlayerPair1
    tuple<int, int> deltaGames_P2{deltaWonGamesP2, deltaLostGamesP2};  // to be added to PlayerPair2

    tuple<int, int> scoreSumOld = oldScore.getScoreSum();
    tuple<int, int> scoreSumNew = newScore.getScoreSum();
    int oldWonPoints_P1 = get<0>(scoreSumOld);
    int newWonPoints_P1 = get<0>(scoreSumNew);
    int deltaWonPoints_P1 = newWonPoints_P1 - oldWonPoints_P1;
    int oldLostPoints_P1 = oldScore.getPointsSum() - oldWonPoints_P1;
    int newLostPoints_P1 = newScore.getPointsSum() - newWonPoints_P1;
    int deltaLostPoints_P1 = newLostPoints_P1 - oldLostPoints_P1;
    tuple<int, int> deltaPoints_P1{deltaWonPoints_P1, deltaLostPoints_P1};
    tuple<int, int> deltaPoints_P2{deltaLostPoints_P1, deltaWonPoints_P1};

    // determine who actually is P1 and P2
    int pp1Id = ma.getPlayerPair1().getPairId();
    int pp2Id = ma.getPlayerPair2().getPairId();

    // find the first entry to modify

    // derive the group number of the affected ranking entries
    //
    // we may only modify subsequent entries with the same
    // group number as the initial number. Thus, we prevent
    // a modification of e.g. the ranking entries in a KO-phase
    // after we started modifications in the round robin phase.
    //
    // we get the group number from the first entry of the
    // first player pair to be modified
    WhereClause w;
    w.addIntCol(RA_CAT_REF, catId);
    w.addIntCol(RA_PAIR_REF, pp1Id);
    w.addIntCol(RA_ROUND, firstRoundToModify);
    auto re = getSingleObjectByWhereClause<RankingEntry>(w);
    if (re == nullptr) return OK;  // no ranking entries yet
    int grpNum = re->getGroupNumber();

    //
    // a helper function that does the actual modification
    //
    auto doMod = [&](int pairId, const tuple<int, int, int>& matchDelta,
                     const tuple<int, int>& gamesDelta, const tuple<int, int>& pointsDelta)
    {
      // let's build a where clause that captures all entries
      // to modified
      w.clear();
      w.addIntCol(RA_CAT_REF, catId);
      w.addIntCol(RA_PAIR_REF, pairId);
      w.addIntCol(RA_ROUND, ">=", firstRoundToModify);
      if (grpNum > 0)
      {
        w.addIntCol(RA_GRP_NUM, grpNum);   // a dedicated group number (1, 2, 3...)
      } else {
        w.addIntCol(RA_GRP_NUM, "<", 0);   // a functional number (iteration, quarter finals, ...)
      }
      DbTab::CachingRowIterator it = tab->getRowsByWhereClause(w);
      while (!(it.isEnd()))
      {
        TabRow r = *it;

        vector<tuple <string, int>> colDelta = {
          {RA_MATCHES_WON, get<0>(matchDelta)},
          {RA_MATCHES_LOST, get<1>(matchDelta)},
          {RA_MATCHES_DRAW, get<2>(matchDelta)},
          {RA_GAMES_WON, get<0>(gamesDelta)},
          {RA_GAMES_LOST, get<1>(gamesDelta)},
          {RA_POINTS_WON, get<0>(pointsDelta)},
          {RA_POINTS_LOST, get<1>(pointsDelta)},
        };

        for (const tuple<string, int>& cd : colDelta)
        {
          int dbErr;
          int oldVal = r.getInt(get<0>(cd));
          r.update(get<0>(cd), oldVal + get<1>(cd), &dbErr);
          if (dbErr != SQLITE_DONE) return false;
        }

        ++it;
      }

      return true;
    };
    //------------------------- end of helper func -------------------

    // lock the database before writing
    DbLockHolder lh{db, DatabaseAccessRoles::MainThread};

    // start a new transaction to make sure that
    // the database remains consistent in case something goes wrong
    bool isDbErr;
    auto tg = db->acquireTransactionGuard(false, &isDbErr);
    if (isDbErr) return DATABASE_ERROR;

    // modify the ranking entries
    bool isOkay = doMod(pp1Id, deltaMatches_P1, deltaGames_P1, deltaPoints_P1);
    if (!isOkay)
    {
      return DATABASE_ERROR; // triggers implicit rollback through tg's dtor
    }
    isOkay = doMod(pp2Id, deltaMatches_P2, deltaGames_P2, deltaPoints_P2);
    if (!isOkay)
    {
      return DATABASE_ERROR;  // triggers implicit rollback through tg's dtor
    }

    // now we have to re-sort the entries, round by round
    // UNLESS the caller decided to skip the sorting.
    //
    // skipping the sorting (and thus assigning ranks) is only
    // usefull in bracket matches where ranks are not derived
    // from points but from bracket logic
    if (!skipSorting)
    {
      auto specializedCat = cat.convertToSpecializedObject();
      auto lessThanFunc = specializedCat->getLessThanFunction();
      int round = firstRoundToModify;
      while (true)
      {
        w.clear();
        w.addIntCol(RA_CAT_REF, catId);
        w.addIntCol(RA_ROUND, round);
        w.addIntCol(RA_GRP_NUM, grpNum);

        // get the ranking entries
        RankingEntryList rankList = getObjectsByWhereClause<RankingEntry>(w);
        if (rankList.empty()) break;   // no more rounds to modify

        // call the standard sorting algorithm
        std::sort(rankList.begin(), rankList.end(), lessThanFunc);

        // write the sort results back to the database
        int rank = 1;
        for (RankingEntry re : rankList)
        {
          re.row.update(RA_RANK, rank);
          ++rank;
        }

        ++round;
      }
    }

    // Done. Finish the transaction
    isOkay = tg ? tg->commit() : true;
    return isOkay ? OK : DATABASE_ERROR;
  }
コード例 #6
0
ファイル: ext2fsutil.c プロジェクト: Vvnesaa/fsck
void ext2fsutilTest(int start, int length) {
	struct ext2_super_block x;
	getSuperBlock(start, &x);
	int groupNum = getGroupNumber(&x);
	int blockSize = EXT2_BLOCK_SIZE(&x);
	struct ext2_group_desc groupDescs[MAX_GROUP_NUM];
	getGroupDescs(start, groupDescs, groupNum);
	unsigned char *blockBitmap = malloc(blockSize * groupNum + 1);
	getBlockBitmap(start, groupDescs, groupNum, blockBitmap, blockSize);
	unsigned char *inodeBitmap = malloc(blockSize * groupNum + 1);
	getInodeBitmap(start, groupDescs, groupNum, inodeBitmap, blockSize);
	struct ext2_inode *inodeTable = malloc(sizeof(struct ext2_inode) * x.s_inodes_per_group * groupNum);
	getInodeTable(start, &x, groupDescs, groupNum, inodeTable, blockSize);
	unsigned char *buf = malloc(inodeTable[localNo(EXT2_ROOT_INO)].i_size);
	getData(start, inodeTable + 1, blockSize, buf);
	AnalyzeDir(inodeTable + 1, buf);
	
/*	struct ext2_inode *inode;
	//we already know /lion is on inode 4017
	inode = inodeTable + 4016;
	printf("%d\n", isDirectory(inode));
	unsigned char *lionbuf = malloc(inode->i_size);
	getData(start, inode, blockSize, lionbuf);
	AnalyzeDir(inode, lionbuf);

	//we already know /lion/tigers is on inode 4018
	inode = inodeTable + 4017;
	printf("%d\n", isDirectory(inode));
	unsigned char *tigersbuf= malloc(inode->i_size);
	getData(start, inode, blockSize, tigersbuf);
	AnalyzeDir(inode, tigersbuf);

	//we already know /lion/tigers/bears is on inode 4019
	inode = inodeTable + 4018;
	printf("%d\n", isDirectory(inode));
	unsigned char *bearsbuf= malloc(inode->i_size);
	getData(start, inode, blockSize, bearsbuf);
	AnalyzeDir(inode, bearsbuf);
	
	//we already know /lion/tigers/bears/ohmy.txt is on inode 4021
	inode = inodeTable + 4020;
	printf("%d\n", isDirectory(inode)); 
	unsigned char *txtbuf= malloc(inode->i_size);
	getData(start, inode, blockSize, txtbuf);
	//printf("%s", txtbuf);
	printf("%d\n", isBlockBitmapSet(localNo(inode->i_block[0]), blockBitmap, groupNum, blockSize, &x));

	free(txtbuf); 
	free(bearsbuf);	
	free(tigersbuf);
	free(lionbuf); */

/*	struct ext2_inode *inode;
	//we already know /oz/tornado/glinda is on inode 30 
	inode = inodeTable + 29;
	printf("%d\n", isSymbolicLink(inode));
	printf("%d %d %d %d\n", inode->i_size, inode->i_blocks, inode->i_block[0], inode->i_block[1]);
	int i;
	for (i = 0; i < inode->i_size; ++i)
		printf("%c", ((unsigned char *)inode->i_block)[i]);
	printf("\n");
//	unsigned char *ozbuf = malloc(inode->i_size);
//	getData(start, inode, blockSize, ozbuf);
//	printf("%s\n", ozbuf);
//	AnalyzeDir(inode, ozbuf);
	
//	free(ozbuf);
*/
	free(buf);
	free(blockBitmap);
	free(inodeBitmap);
}