本文整理汇总了C++中IdMap类的典型用法代码示例。如果您正苦于以下问题:C++ IdMap类的具体用法?C++ IdMap怎么用?C++ IdMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IdMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addDesign
bool DesignStore::addDesign(Design::Ptr d){
d->setDesignId(next_designid++);
//check components all come from this category
IdMap cl = d->getComponents();
Player::Ptr player = Game::getGame()->getPlayerManager()->getPlayer(d->getOwner());
PlayerView::Ptr playerview = player->getPlayerView();
for(IdMap::iterator itcurr = cl.begin();
itcurr != cl.end(); ++itcurr){
if(!(playerview->isUsableComponent(itcurr->first)))
return false;
std::map<uint32_t, Component::Ptr>::iterator itcomp = components.find(itcurr->first);
if(itcomp == components.end())
return false;
getComponent(itcurr->first)->setInUse();
}
d->eval();
designs[d->getId()] = d;
getCategory(d->getCategoryId())->doAddDesign(d);
if(d->isValid()){
playerview->addUsableDesign(d->getId());
}else{
playerview->addVisibleDesign( DesignView::Ptr( new DesignView( d->getId(), true )) );
}
Game::getGame()->getPlayerManager()->updatePlayer(player->getID());
Game::getGame()->getPersistence()->saveDesign(d);
return true;
}
示例2: doOrder
bool UnloadArmament::doOrder(IGObject::Ptr ob){
Fleet* fleet = dynamic_cast<Fleet*>(ob->getObjectBehaviour());
ObjectManager* obman = Game::getGame()->getObjectManager();
ObjectTypeManager* otman = Game::getGame()->getObjectTypeManager();
ResourceManager::Ptr resman = Game::getGame()->getResourceManager();
std::set<uint32_t>objs = obman->getObjectsByPos(fleet->getPosition(), 10000);
IGObject::Ptr planetObj;
Planet* planet;
for (std::set<uint32_t>::const_iterator itcurr = objs.begin(); itcurr != objs.end(); ++itcurr) {
if (obman->getObject(*itcurr)->getType() == otman->getObjectTypeByName("Planet")) {
planetObj = obman->getObject(*itcurr);
planet = dynamic_cast<Planet*>(planetObj->getObjectBehaviour());
Logger::getLogger()->debug("UnloadArmaments::doOrder Found Planet %s for Unload Armaments Order", planetObj->getName().c_str());
const uint32_t factoryType = resman->getResourceDescription("Factories")->getResourceType();
IdMap weapontype = weaponlist->getList();
for(IdMap::iterator weaponit = weapontype.begin(); weaponit != weapontype.end(); ++weaponit) {
if (planet->removeResource(factoryType, 1)) {
if (fleet->removeResource(weaponit->first, weaponit->second)) {
Logger::getLogger()->debug("UnloadArmaments::doOrder success, adding to resource %d: #:%d", weaponit->first, weaponit->second);
planet->addResource(weaponit->first, weaponit->second);
planetObj->touchModTime();
return true;
}
} else {
turns = 1;
return true;
}
}
}
}
return false;
}
示例3: valmap_bind
ValueMap valmap_bind(IdMap &id, unsigned int code) {
ValueMap valmap;
unsigned int mask = 1;
for (auto it = id.begin(); it != id.end(); ++it, mask <<= 1) {
valmap[it->first] = (code & mask) == mask;
}
return valmap;
}
示例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: InitActorNumsFromMapinfo
void InitActorNumsFromMapinfo()
{
DoomEdMap.Clear();
IdMap::Iterator it(DoomEdFromMapinfo);
IdMap::Pair *pair;
int error = 0;
while (it.NextPair(pair))
{
PClassActor *cls = NULL;
if (pair->Value.classname != NAME_None)
{
cls = PClass::FindActor(pair->Value.classname);
if (cls == NULL)
{
Printf(TEXTCOLOR_RED "Script error, \"%s\" line %d:\nUnknown actor class %s\n",
pair->Value.filename.GetChars(), pair->Value.linenum, pair->Value.classname.GetChars());
error++;
}
}
FDoomEdEntry ent;
ent.Type = cls;
ent.Special = pair->Value.special;
ent.ArgsDefined = pair->Value.argsdefined;
ent.NoSkillFlags = pair->Value.noskillflags;
memcpy(ent.Args, pair->Value.args, sizeof(ent.Args));
DoomEdMap.Insert(pair->Key, ent);
}
if (error > 0)
{
I_Error("%d unknown actor classes found", error);
}
DoomEdFromMapinfo.Clear(); // we do not need this any longer
}
示例7: logCycle
void
FunctionDefinitionRecursion::determineCycles(const Model& m)
{
IdIter it;
IdRange range;
IdList variables;
IdMap logged;
std::string id;
variables.clear();
/* create a list of variables that are cycles ie (x, x) */
for (it = mIdMap.begin(); it != mIdMap.end(); it++)
{
if ((*it).first == (*it).second)
{
id = (*it).first;
if (!variables.contains(id))
{
variables.append(id);
}
}
}
/* loop thru other dependencies for each; if the dependent is also
* in the list then this is the cycle
* keep a record of logged dependencies to avoid logging twice
*/
for (unsigned int n = 0; n < variables.size(); n++)
{
id = variables.at((int)n);
range = mIdMap.equal_range(id);
for (it = range.first; it != range.second; it++)
{
if (((*it).second != id)
&& (variables.contains((*it).second))
&& !alreadyExistsInMap(logged,
pair<const std::string, std::string>(id, (*it).second))
&& !alreadyExistsInMap(logged,
pair<const std::string, std::string>((*it).second, id)))
{
logCycle(m.getFunctionDefinition(id), m.getFunctionDefinition((*it).second));
logged.insert(pair<const std::string, std::string>(id, (*it).second));
}
}
}
}
示例8:
bool
FunctionDefinitionRecursion::alreadyExistsInMap(IdMap map,
pair<const std::string, std::string> dependency)
{
bool exists = false;
IdIter it;
for (it = map.begin(); it != map.end(); it++)
{
if (((*it).first == dependency.first)
&& ((*it).second == dependency.second))
exists = true;
}
return exists;
}
示例9:
bool
ExtModelReferenceCycles::alreadyExistsInMap(IdMap map,
pair<const std::string, std::string> dependency)
{
bool exists = false;
IdIter it;
for (it = map.begin(); it != map.end(); it++)
{
if (((*it).first == dependency.first)
&& ((*it).second == dependency.second))
exists = true;
}
return exists;
}
示例10: inputFrame
void Build::inputFrame(InputFrame::Ptr f, uint32_t playerid)
{
Order::inputFrame(f, playerid);
Player::Ptr player = Game::getGame()->getPlayerManager()->getPlayer(playerid);
DesignStore::Ptr ds = Game::getGame()->getDesignStore();
uint32_t bldTmPropID = ds->getPropertyByName( "BuildTime");
IdMap fleettype = fleetlist->getList();
uint32_t usedshipres = 0;
for(IdMap::iterator itcurr = fleettype.begin();
itcurr != fleettype.end(); ++itcurr) {
uint32_t type = itcurr->first;
uint32_t number = itcurr->second; // number to build
if(player->getPlayerView()->isUsableDesign(type) && number >= 0){
Design::Ptr design = ds->getDesign(type);
usedshipres += (int)(ceil(number * design->getPropertyValue(bldTmPropID)));
design->addUnderConstruction(number);
ds->designCountsUpdated(design);
}else{
throw FrameException( fec_FrameError, "The requested design was not valid.");
}
}
if(usedshipres == 0 && !fleettype.empty()){
throw FrameException( fec_FrameError, "To build was empty...");
}
resources[1] = usedshipres;
if(fleetname->getString().length() == 0){
fleetname->setString("A Fleet");
}
}
示例11: modifyDesign
bool DesignStore::modifyDesign(Design::Ptr d){
Design::Ptr current = designs[d->getId()];
if(!current || current->getOwner() != d->getOwner() || current->getNumExist() != 0 || current->getInUse() != 0)
return false;
Player::Ptr player = Game::getGame()->getPlayerManager()->getPlayer(d->getOwner());
PlayerView::Ptr playerview = player->getPlayerView();
playerview->removeUsableDesign(d->getId());
IdMap cl = current->getComponents();
for(IdMap::iterator itcurr = cl.begin(); itcurr != cl.end(); ++itcurr){
components[itcurr->first]->setInUse(false);
}
for(IdMap::iterator itcurr = cl.begin(); itcurr != cl.end(); ++itcurr){
if(!(playerview->isUsableComponent(itcurr->first)))
return false;
std::map<uint32_t, Component::Ptr>::iterator itcomp = components.find(itcurr->first);
if(itcomp == components.end())
return false;
itcomp->second->setInUse();
}
d->eval();
bool rtv;
if(getCategory(d->getCategoryId())->doModifyDesign(d)){
designs[d->getId()] = d;
rtv = true;
}else{
d = current;
rtv = false;
}
if(d->isValid()){
playerview->addUsableDesign(d->getId());
}
Game::getGame()->getPlayerManager()->updatePlayer(player->getID());
Game::getGame()->getPersistence()->updateDesign(d);
return rtv;
}
示例12:
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;
}
示例13: 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;
}
示例14: doOrder
bool Build::doOrder(IGObject::Ptr ob)
{
Planet* planet = static_cast<Planet*>(ob->getObjectBehaviour());
uint32_t usedshipres = resources[1];
if(usedshipres == 0)
return true;
int ownerid = planet->getOwner();
if(ownerid == 0){
//currently not owned by anyone, just forget about it
return true;
}
planet->addResource(1, 1);
if(planet->removeResource(1, usedshipres)){
//create fleet
Game* game = Game::getGame();
IGObject::Ptr fleet = game->getObjectManager()->createNewObject();
game->getObjectTypeManager()->setupObject(fleet, game->getObjectTypeManager()->getObjectTypeByName("Fleet"));
//add fleet to container
fleet->addToParent(ob->getID());
fleet->setName(fleetname->getString().c_str());
Fleet * thefleet = ((Fleet*)(fleet->getObjectBehaviour()));
thefleet->setSize(2);
thefleet->setOwner(ownerid); // set ownerid
thefleet->setPosition(planet->getPosition());
thefleet->setVelocity(Vector3d(0LL, 0ll, 0ll));
uint32_t queueid = Game::getGame()->getOrderManager()->addOrderQueue(fleet->getID(), ownerid);
OrderQueueObjectParam* oqop = static_cast<OrderQueueObjectParam*>(fleet->getParameterByType(obpT_Order_Queue));
oqop->setQueueId(queueid);
thefleet->setDefaultOrderTypes();
thefleet->setIcon("common/object-icons/ship");
thefleet->setMedia("common-2d/foreign/vegastrike/ship-small/" + ((MiniSec*)(game->getRuleset()))->getFleetMediaNames()->getName());
//set ship type
IdMap fleettype = fleetlist->getList();
for(IdMap::iterator itcurr = fleettype.begin(); itcurr != fleettype.end(); ++itcurr){
thefleet->addShips(itcurr->first, itcurr->second);
Design::Ptr design = Game::getGame()->getDesignStore()->getDesign(itcurr->first);
design->addComplete(itcurr->second);
Game::getGame()->getDesignStore()->designCountsUpdated(design);
}
//add fleet to universe
Game::getGame()->getObjectManager()->addObject(fleet);
Game::getGame()->getPlayerManager()->getPlayer(ownerid)->getPlayerView()->addOwnedObject(fleet->getID());
Message::Ptr msg( new Message() );
msg->setSubject("Build Fleet order complete");
msg->setBody(std::string("The construction of your new fleet \"") + fleetname->getString() + "\" is complete.");
msg->addReference(rst_Action_Order, rsorav_Completion);
msg->addReference(rst_Object, fleet->getID());
msg->addReference(rst_Object, ob->getID());
Game::getGame()->getPlayerManager()->getPlayer(ownerid)->postToBoard(msg);
return true;
}
return false;
}
示例15: msg
bool Colonise::doOrder(IGObject::Ptr ob){
//if not close, move
IGObject::Ptr target = Game::getGame()->getObjectManager()->getObject(ob->getParent());
if(target == NULL || target->getType() != Game::getGame()->getObjectTypeManager()->getObjectTypeByName("Planet")){
Logger::getLogger()->debug("Object(%d)->Colonise->doOrder(): Target was not valid.", ob->getID());
Game::getGame()->getObjectManager()->doneWithObject(ob->getParent());
Message::Ptr msg( new Message() );
msg->setSubject("Colonise order canceled");
msg->setBody("Not at a planet, colonisation canceled");
msg->addReference(rst_Action_Order, rsorav_Canceled);
msg->addReference(rst_Object, ob->getID());
Game::getGame()->getPlayerManager()->getPlayer(((Fleet*)(ob->getObjectBehaviour()))->getOwner())->postToBoard(msg);
return true;
}
Fleet* fleet = (Fleet*)(ob->getObjectBehaviour());
Planet* planet = (Planet*)(target->getObjectBehaviour());
Message::Ptr msg( new Message() );
msg->addReference(rst_Object, ob->getID());
msg->addReference(rst_Object, target->getID());
if(planet->getOwner() != fleet->getOwner()){
if(planet->getOwner() != 0){
Logger::getLogger()->debug("Object(%d)->Colonise->doOrder(): Planet already owned.",
ob->getID());
msg->setSubject("Colonisation failed");
msg->setBody("The planet you tried to colonise, is already owned by someone else.");
msg->addReference(rst_Action_Order, rsorav_Canceled);
}else{
DesignStore::Ptr ds = Game::getGame()->getDesignStore();
int shiptype = 0;
int shiphp = 2000000;
IdMap ships = fleet->getShips();
uint32_t colonisePropID = ds->getPropertyByName( "Colonise");
uint32_t armorPropID = ds->getPropertyByName( "Armour");
for(IdMap::iterator itcurr = ships.begin();
itcurr != ships.end(); ++itcurr){
Design::Ptr design = ds->getDesign(itcurr->first);
if(design->getPropertyValue(colonisePropID) != 0.0 && shiphp > (int)design->getPropertyValue(armorPropID)){
shiptype = itcurr->first;
shiphp = (int)design->getPropertyValue(armorPropID);
}
}
Logger::getLogger()->debug("Object(%d)->Colonise->doOrder(): shiptype %d",
ob->getID(), shiptype);
if(shiptype != 0){
uint32_t oldowner = planet->getOwner();
planet->setOwner(fleet->getOwner());
Game::getGame()->getPlayerManager()->getPlayer(fleet->getOwner())->getPlayerView()->addOwnedObject(target->getID());
uint32_t queueid = static_cast<OrderQueueObjectParam*>(target->getParameterByType(obpT_Order_Queue))->getQueueId();
OrderQueue::Ptr queue = Game::getGame()->getOrderManager()->getOrderQueue(queueid);
queue->removeOwner(oldowner);
queue->addOwner(fleet->getOwner());
fleet->removeShips(shiptype, 1);
msg->setSubject("Colonised planet");
msg->setBody("You have colonised a planet!");
msg->addReference(rst_Action_Order, rsorav_Completion);
}else{
msg->setSubject("Colonisation failed");
msg->setBody("Your fleet did not have a frigate to colonise the planet");
msg->addReference(rst_Action_Order, rsorav_Invalid);
}
if(fleet->totalShips() == 0){
Game::getGame()->getObjectManager()->scheduleRemoveObject(ob->getID());
Game::getGame()->getPlayerManager()->getPlayer(fleet->getOwner())->getPlayerView()->removeOwnedObject(ob->getID());
}
}
}else{
Logger::getLogger()->debug("Object(%d)->Colonise->doOrder(): Was already owned by the player!",
ob->getID());
msg->setSubject("Colonisation failed");
msg->setBody("You already own the planet you tried to colonise");
msg->addReference(rst_Action_Order, rsorav_Canceled);
}
Game::getGame()->getPlayerManager()->getPlayer(fleet->getOwner())->postToBoard(msg);
Game::getGame()->getObjectManager()->doneWithObject(target->getID());
return true;
}