本文整理汇总了C++中IdMap::size方法的典型用法代码示例。如果您正苦于以下问题:C++ IdMap::size方法的具体用法?C++ IdMap::size怎么用?C++ IdMap::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IdMap
的用法示例。
在下文中一共展示了IdMap::size方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
std::ostream& operator<<(std::ostream &out, Entity &e)
{
const size_t type = e.type->getId();
out << "{";
if (type == EntityType::CUSTOM) {
out << "type:custom, ";
} else {
out << "type:" << type << ", ";
}
out << "expired:" << (e.expired ? "true" : "false") << ", ";
out << "visible:" << (e.visible ? "true" : "false") << ", ";
out << "enabled:" << (e.enabled ? "true" : "false") << ", ";
IdMap components = e.type->getComponents();
for (size_t i = 0; i < components.size(); i++) {
size_t componentId = components.getId(i);
size_t offset = components.getIndex(componentId);
ComponentBase *componentBase = e.type->getCore()->getComponent(componentId);
AnyMemory value = e.components.sub(offset, componentBase->defaultValue.getSize());
out << componentBase->name << ":" << value << ", ";
}
out << "controllers:{";
IdMap controllers = e.type->getControllers();
for (size_t i = 0; i < controllers.size(); i++) {
if (i > 0) {
out << ",";
}
out << controllers.getId(i);
}
out << "}}";
return out;
}
示例2: main
int main(int argc, char **argv)
{
IdMap idmap;
ValueMap valmap;
int permutations_size = 0;
// Call the parser
yyparse();
if (root == NULL) {
return 1;
}
// Find and print some information about identifiers
std::cout << root->prettyPrint() << std::endl;
find_identifiers(*root, idmap);
std::cout << "Found " << idmap.size() << " unique identifiers" << std::endl;
for (auto it = idmap.begin(); it != idmap.end(); ++it) {
std::cout << it->first << ": " << it->second.size() << " occurrences" << std::endl;
}
// Check how many boolean permutations we need to generate
if (idmap.size() <= 2) {
permutations_size = 2;
} else if (idmap.size() <= 4) {
permutations_size = 4;
} else {
std::cout << "More than 4 identifiers not supported yet." << std::endl;
return 2;
}
std::cout << "Generating a lut" << permutations_size << "." << std::endl;
// Bind each possible permutation and evaluate the function
std::cout << "0";
for(unsigned int i = 0; i < permutations_size * permutations_size; ++i) {
valmap = valmap_bind(idmap, i);
std::cout << evaluate(*root, valmap);
}
std::cout << std::endl;
return 0;
}
示例3: CalcMetrics
//
// CalcMetrics
// - Loop through the history and pre-calculate metrics used in the training
// - Also re-number the customer id's to fit in a fixed array
//
void Engine::CalcMetrics()
{
int i, cid;
IdItr itr;
wprintf(L"\nCalculating intermediate metrics\n");
// Process each row in the training set
for (i=0; i<m_nRatingCount; i++)
{
Data* rating = m_aRatings + i;
// Increment movie stats
m_aMovies[rating->MovieId].RatingCount++;
m_aMovies[rating->MovieId].RatingSum += rating->Rating;
// Add customers (using a map to re-number id's to array indexes)
itr = m_mCustIds.find(rating->CustId);
if (itr == m_mCustIds.end())
{
cid = 1 + (int)m_mCustIds.size();
// Reserve new id and add lookup
m_mCustIds[rating->CustId] = cid;
// Store off old sparse id for later
m_aCustomers[cid].CustomerId = rating->CustId;
// Init vars to zero
m_aCustomers[cid].RatingCount = 0;
m_aCustomers[cid].RatingSum = 0;
}
else
{
cid = itr->second;
}
// Swap sparse id for compact one
rating->CustId = cid;
m_aCustomers[cid].RatingCount++;
m_aCustomers[cid].RatingSum += rating->Rating;
}
// Do a follow-up loop to calc movie averages
for (i=0; i<MAX_MOVIES; i++)
{
Movie* movie = m_aMovies+i;
movie->RatingAvg = movie->RatingSum / (1.0 * movie->RatingCount);
movie->PseudoAvg = (3.23 * 25 + movie->RatingSum) / (25.0 + movie->RatingCount);
}
}
示例4: addEntityListToMapBasedOnBitSet
void addEntityListToMapBasedOnBitSet( EntityList *listener, const IdMap &indices, map<size_t,vector<EntityList*>> &vmap )
{
for (size_t i = 0; i < indices.size(); i++) {
size_t id = indices.getId(i);
auto iterator = vmap.find( id );
if (iterator == vmap.end()) {
vmap.insert({id, {listener}});
} else {
iterator.second.push_back(listener);
}
}
}
示例5: notifyListsInMap
void notifyListsInMap( Entity *e, const IdMap& indices, map<size_t,vector<EntityList*>> &vmap )
{
for (size_t i = 0; i < indices.size(); i++) {
size_t id = indices.getId(i);
auto iterator = vmap.find( id );
if (iterator != vmap.end()) {
for (auto &listener : iterator.second) {
listener.add( e );
}
}
}
}
示例6: doCombat
void RSPCombat::doCombat(std::map<uint32_t, IdSet> sides) {
Game* game = Game::getGame();
PlayerManager::Ptr playermanager = game->getPlayerManager();
ObjectManager* objectmanager = game->getObjectManager();
DesignStore::Ptr ds = game->getDesignStore();
const char * const rsp[] = {"rock", "scissors", "paper"};
IdSet listallobids;
IdSet listallplayerids;
std::map<uint32_t, std::vector<Combatant*> > fleetcache;
battlelogger.reset(new BattleXML::BattleLogger());
msgstrings.clear();
for(std::map<uint32_t, IdSet>::iterator itmap = sides.begin(); itmap != sides.end(); ++itmap) {
std::vector<Combatant*> pcombatant;
Player::Ptr player = playermanager->getPlayer(itmap->first);
battlelogger->startSide(player->getName());
IdSet theset = itmap->second;
for(IdSet::iterator itset = theset.begin(); itset != theset.end(); ++itset) {
listallobids.insert(*itset);
IGObject::Ptr obj = objectmanager->getObject (*itset);
objectcache[*itset] = obj;
if(obj->getType() == obT_Fleet) {
Fleet* f2 = (Fleet*)(obj->getObjectBehaviour());
IdMap shiplist = f2->getShips();
uint32_t damage = f2->getDamage();
for(IdMap::reverse_iterator itship = shiplist.rbegin(); itship != shiplist.rend(); ++itship) {
for(uint32_t i = 0; i < itship->second; i++) {
Combatant* f1 = new Combatant();
f1->setOwner(itmap->first);
f1->setObject(obj->getID());
f1->setShipType(itship->first);
uint32_t mydamage = damage / std::max(1U, (unsigned int)(shiplist.size() - i));
f1->setDamage(mydamage);
damage -= mydamage;
std::string type = ds->getDesign(itship->first)->getName();
f1->setBattleXmlType(type);
f1->setBattleXmlId(str(boost::format("%1%-%2%-%3%") % type % obj->getID() % i));
f1->setBattleXmlName(str(boost::format("%1%'s %2%, %3% %4%") % player->getName() % obj->getName() % type % i));
battlelogger->addCombatant(f1);
pcombatant.push_back(f1);
}
}
} else {
int shipcount = 2;
int homeplanetid = game->getResourceManager()->getResourceDescription("Home Planet")->getResourceType();
if(((Planet*)(obj->getObjectBehaviour()))->getResource(homeplanetid) == 1) {
//three more for home planets
shipcount += 3;
}
for(int i = 0; i < shipcount; i++) {
Combatant* f1 = new Combatant();
f1->setOwner(itmap->first);
f1->setObject(obj->getID());
f1->setShipType(0);
f1->setBattleXmlType("planet");
f1->setBattleXmlId(str(boost::format("planet-%1%-%2%") % obj->getID() % i));
f1->setBattleXmlName(str(boost::format("%1%'s colony on %2%, Defense battery %3%") % player->getName() % obj->getName() % i));
battlelogger->addCombatant(f1);
pcombatant.push_back(f1);
}
}
}
listallplayerids.insert(itmap->first);
battlelogger->endSide();
//sort combatant list by ship type, descending
sort(pcombatant.begin(), pcombatant.end(), CombatantSorter());
fleetcache[itmap->first] = pcombatant;
}
for(std::set<uint32_t>::iterator itplayer = listallplayerids.begin(); itplayer != listallplayerids.end(); ++itplayer) {
msgstrings[*itplayer] = "";
}
Random* random = Game::getGame()->getRandom();
Logger::getLogger()->debug("Combat start");
while(fleetcache.size() >= 2) {
battlelogger->startRound();
uint32_t pos1, pos2;
if(fleetcache.size() == 2) {
pos1 = 0;
pos2 = 1;
} else {
pos1 = pos2 = random->getInRange(0U, ((uint32_t)(fleetcache.size() - 1)));
while(pos2 == pos1) {
pos2 = random->getInRange(0U, ((uint32_t)(fleetcache.size() - 1)));
}
}
std::map<uint32_t, std::vector<Combatant*> >::iterator itpa = fleetcache.begin();
advance(itpa, pos1);
std::map<uint32_t, std::vector<Combatant*> >::iterator itpb = fleetcache.begin();
advance(itpb, pos2);
//.........这里部分代码省略.........