void GameMap::createStructures() { //read structure data from tmx file auto ob_group = _tile_map->getObjectGroup("structures"); CCASSERT(ob_group, "no object group structures"); for (auto iter = std::begin(ob_group->getObjects()); iter != std::end(ob_group->getObjects()); iter++) { float width = iter->asValueMap()["width"].asFloat(); float height = iter->asValueMap()["height"].asFloat(); float x = iter->asValueMap()["x"].asFloat() + width * 0.5f; float y = iter->asValueMap()["y"].asFloat() - getSizeY() + _tile_map->getTileSize().height + height * 1.5f; float mx = iter->asValueMap()["marginX"].asFloat(); float my = iter->asValueMap()["marginY"].asFloat(); std::string name = iter->asValueMap()["name"].asString(); float radius = iter->asValueMap()["radius"].asFloat(); bool shadow = iter->asValueMap()["shadow"].asBool(); _structures.emplace_back( Structure::create( _game_world, new geometry::Circle(Vec2(x, y) - Vec2(mx, my), radius), name, Vec2(x, y), radius)); } }
void DeletedAtShutdown::deleteAll() { // make a local copy of the array, so it can't get into a loop if something // creates another DeletedAtShutdown object during its destructor. Array <DeletedAtShutdown*> localCopy; { const SpinLock::ScopedLockType sl (deletedAtShutdownLock); localCopy = getObjects(); } for (int i = localCopy.size(); --i >= 0;) { JUCE_TRY { DeletedAtShutdown* deletee = localCopy.getUnchecked(i); // double-check that it's not already been deleted during another object's destructor. { const SpinLock::ScopedLockType sl (deletedAtShutdownLock); if (! getObjects().contains (deletee)) deletee = nullptr; } delete deletee; } JUCE_CATCH_EXCEPTION } // if no objects got re-created during shutdown, this should have been emptied by their // destructors jassert (getObjects().size() == 0); getObjects().clear(); // just to make sure the array doesn't have any memory still allocated }
/// returns empty vector if not all handles can be converted to objects std::vector<WorkspaceObject> WorkspaceObjectOrder_Impl::sortedObjects(const std::vector<Handle>& handles) const { if (isDirectOrder()) { // easier to sort handles HandleVector sorted = sort(handles); return getObjects(sorted); } else { // easier to sort objects, and have to get them anyway WorkspaceObjectVector objects = getObjects(handles); return sort(objects); } }
void GameMap::createCollisionAreas() { auto ob_group = _tile_map->getObjectGroup("structures_no_image"); CCASSERT(ob_group, "no object group (structures_no_image)"); for (auto iter = std::begin(ob_group->getObjects()); iter != std::end(ob_group->getObjects()); iter++) { float width = iter->asValueMap()["width"].asFloat(); float height = iter->asValueMap()["height"].asFloat(); float x = iter->asValueMap()["x"].asFloat(); float y = iter->asValueMap()["y"].asFloat() - getSizeY() + _tile_map->getTileSize().height; std::string type = iter->asValueMap()["type"].asString(); if (type == "Polygon") { ValueVector points = iter->asValueMap()["polylinePoints"].asValueVector(); std::vector<cocos2d::Vec2> poly; for (int i = 0; i < points.size(); i++) { ValueMap a = points[i].asValueMap(); float xy = a["x"].asFloat(); float yy = a["y"].asFloat(); poly.push_back(cocos2d::Vec2(xy + x, y - yy)); } poly.pop_back(); geometry::Circle min_circle = geometry::enclosingCircleNaive(poly); _collision_areas.emplace_back( CollisionArea::create( _game_world, new geometry::Polygon(poly), min_circle.origin, min_circle.radius)); } else if (type == "Circle") { float radius = width / 2; _collision_areas.emplace_back( CollisionArea::create( _game_world, new geometry::Circle(Vec2(x + width * 0.5f, y + height * 0.5f), radius), Vec2(x + width * 0.5f, y + height * 0.5f), radius)); } } }
void GameMap::createGraph() { //SparseGraph uses special mechanism in addChild, //then the index will be changed after insert. //So we have to remember them. std::map<int, int> index_change_map; auto node_group = _tile_map->getObjectGroup("nodes"); for (auto iter = std::begin(node_group->getObjects()); iter != std::end(node_group->getObjects()); iter++) { int index = iter->asValueMap()["index"].asInt(); int extra = iter->asValueMap()["extra"].asInt(); float x = iter->asValueMap()["x"].asFloat(); float y = iter->asValueMap()["y"].asFloat() - getSizeY() + _tile_map->getTileSize().height; int real_index = (*_nav_graph).getNextFreeNodeIndex(); (*_nav_graph).addNode(NavGraph::Node(real_index, cocos2d::Vec2(x, y))); index_change_map.insert(std::make_pair(index, real_index)); } auto edge_group = _tile_map->getObjectGroup("edges"); for (auto iter = std::begin(edge_group->getObjects()); iter != std::end(edge_group->getObjects()); iter++) { int from = iter->asValueMap()["from"].asInt(); int to = iter->asValueMap()["to"].asInt(); int flag = iter->asValueMap()["flag"].asInt(); int real_from = index_change_map[from]; int real_to = index_change_map[to]; //calculate the distance to this node cocos2d::Vec2 pos_from_node = (*_nav_graph).getNode(real_from).getPos(); cocos2d::Vec2 pos_to_node = (*_nav_graph).getNode(real_to).getPos(); double dist = (pos_from_node - pos_to_node).getLength(); //this neighbour is okay so it can be added NavGraph::Edge new_edge(real_from, real_to, dist); (*_nav_graph).addEdge(new_edge); //if graph is not a diagraph then an edge needs to be added going //in the other direction if (!(*_nav_graph).isDigraph()) { NavGraph::Edge new_edge(real_to, real_from, dist); (*_nav_graph).addEdge(new_edge); } } }
void DocumentApi::configureLayerAsBackground(LayerImage* layer) { // Add undoers. DocumentUndo* undo = m_document->getUndo(); if (undo->isEnabled()) { m_undoers->pushUndoer(new undoers::SetLayerFlags(getObjects(), layer)); m_undoers->pushUndoer(new undoers::SetLayerName(getObjects(), layer)); m_undoers->pushUndoer(new undoers::MoveLayer(getObjects(), layer)); } // Do the action. layer->configureAsBackground(); }
//============================================================================= bool Inventory::itemExist(uint32 familyId, uint32 typeId) { bool found = false; ObjectIDList::iterator invObjectIt = getObjects()->begin(); // Items inside inventory and child objects. while (invObjectIt != getObjects()->end()) { Object* object = getObjectById(*invObjectIt); Item* item = dynamic_cast<Item*>(object); if (item) { if ((item->getItemFamily() == familyId) && (item->getItemType() == typeId)) { found = true; break; } } invObjectIt++; } if (!found) { // Items equipped by the player. PlayerObject* player = dynamic_cast<PlayerObject*>(gWorldManager->getObjectById(this->getParentId())); if(!player) return found; ObjectList* objList = player->getEquipManager()->getEquippedObjects(); ObjectList::iterator equippedObjectIt = objList->begin(); while (equippedObjectIt != objList->end()) { Object* object = (*equippedObjectIt); Item* item = dynamic_cast<Item*>(object); if (item) { if ((item->getItemFamily() == familyId) && (item->getItemType() == typeId)) { found = true; break; } } equippedObjectIt++; } delete objList; } return found; }
void TMXIsoObjectsTest::onDraw() { kmMat4 oldMat; kmGLGetMatrix(KM_GL_MODELVIEW, &oldMat); kmGLLoadMatrix(&_modelViewTransform); auto map = (TMXTiledMap*) getChildByTag(kTagTileMap); auto group = map->getObjectGroup("Object Group 1"); auto& objects = group->getObjects(); for (auto& obj : objects) { ValueMap& dict = obj.asValueMap(); float x = dict["x"].asFloat(); float y = dict["y"].asFloat(); float width = dict["width"].asFloat(); float height = dict["height"].asFloat(); glLineWidth(3); DrawPrimitives::drawLine( Point(x,y), Point(x+width,y) ); DrawPrimitives::drawLine( Point(x+width,y), Point(x+width,y+height) ); DrawPrimitives::drawLine( Point(x+width,y+height), Point(x,y+height) ); DrawPrimitives::drawLine( Point(x,y+height), Point(x,y) ); glLineWidth(1); } kmGLLoadMatrix(&oldMat); }
void TiledMapLoader::loadNamedFactories(cocos2d::TMXTiledMap& map) { for (auto& arrayElement : map.getObjectGroups()) { auto objectGroup = dynamic_cast<TMXObjectGroup*>(arrayElement); if (!objectGroup) { continue; } for (auto& value : objectGroup->getObjects()) { auto valueMap = value.asValueMap(); if (valueMap.empty()) continue; if (!valueMap.count("name")) { continue; } auto name = valueMap["name"].asString(); if (!nameFactories.count(name)) { continue; } Configuration config{valueMap, objectGroup->getGroupName(), map, box2dContainer}; for (auto& callback : nameFactories.at(name)) { callback(config); } } } }
void ForegroundProcessor::segmentForegroundSlow(Frame & frame) { //record demo threshMap(frame.foreground, threshval); //Threshold at threshval frame.foreground.copyTo(frame.demoImage(Range(0, frame.image.rows), Range(0, frame.image.cols))); if (shadows) { suppressShadows(frame, minArea, minQuotient); } //record demo frame.foreground.copyTo(frame.demoImage(Range(0, frame.image.rows), Range(frame.image.cols, frame.image.cols*2))); //Remove gray pixels threshMap(frame.foreground, threshval); distanceFilter(frame, minDist); dilateBinMap(frame.foreground, iterations); //record demo frame.foreground.copyTo(frame.demoImage(Range(frame.image.rows, frame.image.rows*2), Range(0, frame.image.cols))); getObjects(frame); return; }
void ExecQueryResponseHandler::transfer(void) { CIMExecQueryResponseMessage & msg = *static_cast<CIMExecQueryResponseMessage *>(getResponse()); msg.cimObjects = getObjects(); }
int main(int argc, char *argv[]) { char *iim, *idb, * oim; ObjectDB newobjs, known; Image im; if (argc != 4) { fprintf(stderr, "usage: %s <input labeled image> <input database> <output image>", argv[0]); } iim=argv[1]; idb=argv[2]; oim=argv[3]; readImage(&im, iim); readDatabase(&known, idb); /* get the database of known objects */ makeODB(&newobjs, getColors(&im)); /* create the database for the input image */ getObjects(&im, &newobjs); /* fill the database for the input image */ filterObjects(&im, &newobjs, &known); /* find known objects in the database and throw away those unknown */ drawLines(&im, &newobjs); /* draw lines in the input image */ writeImage(&im, oim); /* write the output image */ free(newobjs.objs); free(known.objs); free(im.data); return 0; }
void TMXIsoObjectsTest::onDraw(const Mat4 &transform, bool transformUpdated) { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); auto map = (TMXTiledMap*) getChildByTag(kTagTileMap); auto pos = map->getPosition(); auto group = map->getObjectGroup("Object Group 1"); auto& objects = group->getObjects(); for (auto& obj : objects) { ValueMap& dict = obj.asValueMap(); float x = dict["x"].asFloat(); float y = dict["y"].asFloat(); float width = dict["width"].asFloat(); float height = dict["height"].asFloat(); glLineWidth(3); DrawPrimitives::drawLine( pos + Vec2(x,y), pos + Vec2(x+width,y) ); DrawPrimitives::drawLine( pos + Vec2(x+width,y), pos + Vec2(x+width,y+height) ); DrawPrimitives::drawLine( pos + Vec2(x+width,y+height), pos + Vec2(x,y+height) ); DrawPrimitives::drawLine( pos + Vec2(x,y+height), pos + Vec2(x,y) ); glLineWidth(1); } director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void EnumerateInstanceNamesResponseHandler::transfer(void) { CIMEnumerateInstanceNamesResponseMessage & msg = *static_cast<CIMEnumerateInstanceNamesResponseMessage *>(getResponse()); msg.instanceNames = getObjects(); }
bool CObjTreePlugin::srvGetObjectsInSphere(srs_env_model::GetObjectsInSphere::Request &req, srs_env_model::GetObjectsInSphere::Response &res) { objtree::FilterSphere filter(req.position.x, req.position.y, req.position.z, req.radius); getObjects(&filter, res.object_ids); return true; }
bool CObjTreePlugin::srvGetObjectsInHalfspace(srs_env_model::GetObjectsInHalfspace::Request &req, srs_env_model::GetObjectsInHalfspace::Response &res) { objtree::FilterPlane filter(req.position.x, req.position.y, req.position.z, req.normal.x, req.normal.y, req.normal.z); getObjects(&filter, res.object_ids); return true; }
bool CObjTreePlugin::srvGetObjectsInBox(srs_env_model::GetObjectsInBox::Request &req, srs_env_model::GetObjectsInBox::Response &res) { objtree::FilterBox filter(objtree::Box(req.position.x, req.position.y, req.position.z, req.size.x, req.size.y, req.size.z)); getObjects(&filter, res.object_ids); return true; }
void ReferenceNamesResponseHandler::transfer(void) { CIMReferenceNamesResponseMessage & msg = *static_cast<CIMReferenceNamesResponseMessage *>(getResponse()); msg.objectNames = getObjects(); }
void AssociatorNamesResponseHandler::transfer(void) { CIMAssociatorNamesResponseMessage & msg = *static_cast<CIMAssociatorNamesResponseMessage *>(getResponse()); msg.objectNames = getObjects(); }
int main(int argc, char *argv[]) { char *ifname, *odname, *ofname; ObjectDB odb; Image im; if (argc < 4) { fprintf(stderr, "usage: %s <input labeled image> <output database> <output image>", argv[0]); return 1; } ifname=argv[1]; odname=argv[2]; ofname=argv[3]; readImage(&im, ifname); makeODB(&odb, getColors(&im)); getObjects(&im, &odb); writeDatabase(&odb, odname); drawLines(&im, &odb); writeImage(&im, ofname); free(odb.objs); free(im.data); return 0; }
void FormSegmentator::analyze(QList<Component> &objects, QList<Component> &edges) { uniteComponents(); objects = getObjects(); edges = getEdges(); return; }
void TeAbstractTheme::setStatusForItemsAddedByPointing(vector<string>& itemVec) { unsigned int i; string oid, item; //----------------------------------------------------------------------- // Set the pointing status for the input items //----------------------------------------------------------------------- for (i = 0; i < itemVec.size(); ++i) { item = itemVec[i]; if (itemStatusMap_[item] == TeDEFAULT) itemStatusMap_[item] = TePOINTED; else if (objStatusMap_[item] == TeQUERIED) itemStatusMap_[item] = TePOINTED_QUERIED; } //----------------------------------------------------------------------- // Set the pointing status for the objects associated to the input items //----------------------------------------------------------------------- set<string> oidSet = getObjects(itemVec); set<string>::iterator setIt; for (setIt = oidSet.begin(); setIt != oidSet.end(); ++setIt) { oid = *setIt; if (objStatusMap_[oid] == TeDEFAULT) objStatusMap_[oid] = TePOINTED; else if (objStatusMap_[oid] == TeQUERIED) objStatusMap_[oid] = TePOINTED_QUERIED; } }
//------------------------------------------------------------------ // // TMXGIDObjectsTestNew // //------------------------------------------------------------------ TMXGIDObjectsTestNew::TMXGIDObjectsTestNew() { auto map = cocos2d::experimental::TMXTiledMap::create("TileMaps/test-object-layer.tmx"); addChild(map, -1, kTagTileMap); Size CC_UNUSED s = map->getContentSize(); CCLOG("Contentsize: %f, %f", s.width, s.height); CCLOG("----> Iterating over all the group objets"); auto drawNode = DrawNode::create(); Color4F color(1.0, 1.0, 1.0, 1.0); auto group = map->getObjectGroup("Object Layer 1"); auto objects = group->getObjects(); for (auto& obj : objects) { ValueMap& dict = obj.asValueMap(); float x = dict["x"].asFloat(); float y = dict["y"].asFloat(); float width = dict["width"].asFloat(); float height = dict["height"].asFloat(); drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color); drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color); drawNode->drawLine(Vec2(x + width,y + height), Vec2(x,y + height), color); drawNode->drawLine(Vec2(x,y + height), Vec2(x,y), color); } map->addChild(drawNode, 10); }
TMXIsoObjectsTestNew::TMXIsoObjectsTestNew() { auto map = cocos2d::experimental::TMXTiledMap::create("TileMaps/iso-test-objectgroup.tmx"); addChild(map, -1, kTagTileMap); Size CC_UNUSED s = map->getContentSize(); CCLOG("ContentSize: %f, %f", s.width,s.height); auto group = map->getObjectGroup("Object Group 1"); auto& objects = group->getObjects(); Value objectsVal = Value(objects); CCLOG("%s", objectsVal.getDescription().c_str()); auto drawNode = DrawNode::create(); Color4F color(1.0, 1.0, 1.0, 1.0); for (auto& obj : objects) { ValueMap& dict = obj.asValueMap(); float x = dict["x"].asFloat(); float y = dict["y"].asFloat(); float width = dict["width"].asFloat(); float height = dict["height"].asFloat(); drawNode->drawLine(Vec2(x, y), Vec2(x + width, y), color); drawNode->drawLine(Vec2(x + width, y), Vec2(x + width, y + height), color); drawNode->drawLine(Vec2(x + width,y + height), Vec2(x,y + height), color); drawNode->drawLine(Vec2(x,y + height), Vec2(x,y), color); } map->addChild(drawNode, 10); }
void UndoHistory::runUndo(Direction direction) { UndoersStack* undoers = ((direction == UndoDirection)? m_undoers: m_redoers); UndoersStack* redoers = ((direction == RedoDirection)? m_undoers: m_redoers); int level = 0; do { const char* itemLabel = NULL; Undoer* undoer = undoers->popUndoer(UndoersStack::PopFromHead); if (!undoer) break; Modification itemModification = DoesntModifyDocument; itemModification = undoer->getModification(); undoer->revert(getObjects(), redoers); if (undoer->isOpenGroup()) level++; else if (undoer->isCloseGroup()) level--; // Delete the undoer undoer->dispose(); // Adjust m_diffCount (just one time, when the level backs to zero) if (level == 0 && itemModification == ModifyDocument) { if (direction == UndoDirection) m_diffCount--; else if (direction == RedoDirection) m_diffCount++; } } while (level); }
UndoTransaction::UndoTransaction(Context* context, const char* label, undo::Modification modification) : m_context(context) , m_label(label) , m_modification(modification) { ASSERT(label != NULL); DocumentLocation location = m_context->getActiveLocation(); m_document = location.document(); m_sprite = location.sprite(); m_undo = m_document->getUndo(); m_closed = false; m_committed = false; m_enabledFlag = m_undo->isEnabled(); if (isEnabled()) { SpritePosition position(m_sprite->layerToIndex(location.layer()), location.frame()); m_undo->pushUndoer(new undoers::OpenGroup(getObjects(), m_label, m_modification, m_sprite, position)); } }
void SaveLoad::readEntry(SavegameType *type, EntityIndex *entity, uint32 *val, bool keepIndex) { #define LOAD_ENTRY(name, func, val) { \ uint32 _prevPosition = (uint32)_savegame->pos(); \ func; \ uint32 _count = (uint32)_savegame->pos() - _prevPosition; \ debugC(kLastExpressDebugSavegame, "Savegame: Reading " #name ": %d bytes", _count); \ if (_count != val) \ error("SaveLoad::readEntry: Number of bytes read (%d) differ from expected count (%d)", _count, val); \ } #define LOAD_ENTRY_ONLY(name, func) { \ uint32 _prevPosition = (uint32)_savegame->pos(); \ func; \ uint32 _count = (uint32)_savegame->pos() - _prevPosition; \ debugC(kLastExpressDebugSavegame, "Savegame: Reading " #name ": %d bytes", _count); \ } if (!type || !entity || !val) error("SaveLoad::readEntry: Invalid parameters passed!"); // Load entry header SavegameEntryHeader entry; Common::Serializer ser(_savegame, NULL); entry.saveLoadWithSerializer(ser); if (!entry.isValid()) error("SaveLoad::readEntry: entry header is invalid!"); // Init type, entity & value *type = entry.type; *val = entry.value; // Save position uint32 originalPosition = (uint32)_savegame->pos(); // Load game data LOAD_ENTRY("entity index", ser.syncAsUint32LE(*entity), 4); LOAD_ENTRY("state", getState()->saveLoadWithSerializer(ser), 4 + 4 + 4 + 4 + 1 + 4 + 4); LOAD_ENTRY("selected item", getInventory()->saveSelectedItem(ser), 4); LOAD_ENTRY("positions", getEntities()->savePositions(ser), 4 * 1000); LOAD_ENTRY("compartments", getEntities()->saveCompartments(ser), 4 * 16 * 2); LOAD_ENTRY("progress", getProgress().saveLoadWithSerializer(ser), 4 * 128); LOAD_ENTRY("events", getState()->syncEvents(ser), 512); LOAD_ENTRY("inventory", getInventory()->saveLoadWithSerializer(ser), 7 * 32); LOAD_ENTRY("objects", getObjects()->saveLoadWithSerializer(ser), 5 * 128); LOAD_ENTRY("entities", getEntities()->saveLoadWithSerializer(ser), 1262 * 40); LOAD_ENTRY_ONLY("sound", getSound()->saveLoadWithSerializer(ser)); LOAD_ENTRY_ONLY("savepoints", getSavePoints()->saveLoadWithSerializer(ser)); // Update chapter getProgress().chapter = entry.chapter; // Skip padding uint32 offset = _savegame->pos() - originalPosition; if (offset & 0xF) { _savegame->seek((~offset & 0xF) + 1, SEEK_SET); } }
void DocumentApi::deselectMask() { DocumentUndo* undo = m_document->getUndo(); if (undo->isEnabled()) m_undoers->pushUndoer(new undoers::SetMask(getObjects(), m_document)); m_document->setMaskVisible(false); }
void FourTree::getObjects(std::vector<Entity *>& entities, Entity *ptr, std::vector<sf::FloatRect>& finalIndexesWorldBound) { sf::FloatRect boundingRect = ptr->comp<BoxCollisionComponent>()->getTransfromedRect(); sf::Vector2f ptrPosition = ptr->comp<TransformableComponent>()->getWorldPosition(true); getObjects(entities, ptrPosition, boundingRect, finalIndexesWorldBound); }
bp::dict getObjectsPython(const bp::list& object_ids) { std::map<std::string, moveit_msgs::CollisionObject> objs = getObjects(py_bindings_tools::stringFromList(object_ids)); std::map<std::string, std::string> ser_objs; for (std::map<std::string, moveit_msgs::CollisionObject>::const_iterator it = objs.begin(); it != objs.end(); ++it) ser_objs[it->first] = py_bindings_tools::serializeMsg(it->second); return py_bindings_tools::dictFromType(ser_objs); }