void TilesetLevelLayer::updateVisibleArea(const LevelLayerInfo& layerInfo, const LevelMap& map) { // subtract 1 tile to adjust for coordinate conversion // add max pillar height to bottom corners to avoid clipping pillars constexpr static auto maxPillarHeight = 256.f; sf::Vector2f TL{ layerInfo.visibleRect.left - (float)layerInfo.tileWidth, layerInfo.visibleRect.top - (float)layerInfo.tileHeight }; sf::Vector2f TR{ TL.x + layerInfo.visibleRect.width + layerInfo.tileWidth, TL.y }; sf::Vector2f BL{ TL.x, TL.y + layerInfo.visibleRect.height + maxPillarHeight + layerInfo.tileHeight }; sf::Vector2f BR{ TR.x, BL.y }; auto mapTL = map.toMapCoord(TL, layerInfo.blockWidth, layerInfo.blockHeight); auto mapTR = map.toMapCoord(TR, layerInfo.blockWidth, layerInfo.blockHeight); auto mapBL = map.toMapCoord(BL, layerInfo.blockWidth, layerInfo.blockHeight); auto mapBR = map.toMapCoord(BR, layerInfo.blockWidth, layerInfo.blockHeight); visibleStart.x = (int32_t)mapTL.x; visibleEnd.x = (int32_t)mapBR.x; visibleStart.y = (int32_t)mapTR.y; visibleEnd.y = (int32_t)mapBL.y; }
std::pair<typename Graph::vertex_descriptor,int> generateLevelsFromGraphProper( const Graph& g , LevelMap& levels , ParentMap& parents , typename Graph::vertex_descriptor * rootPtr ) { // Now to determine the root node typename Graph::vertex_iterator v , vend; tie(v,vend) = vertices( g.boostGraph() ); typename Graph::vertex_descriptor root; if ( !rootPtr ) { // Init mins and find root if none was given int min = sumDOS( g , *v ); root = *v; int ctr = 1; std::cerr << std::setw(8) << ctr << std::flush; for (; v!=vend; ++v ) { int sum = sumDOS( g , *v ); if ( sum < min ) { min = sum; root=*v; } std::cerr << "\b\b\b\b\b\b\b\b" << std::setw(8) << ++ctr << std::flush; } } else { root = *rootPtr; } // The node with the most edges is at root //tie( root , count ) = getVertexWMostEdges( mst ); // Generate a breadth first level map setLevelMapFromMST( g , levels , parents , root ); int maxL = 0; for ( typename LevelMap::const_iterator i=levels.begin(); i!=levels.end(); ++i ) { maxL = (int) GraphDetail::mmax<long>( *i ,maxL ); } // Return the descriptor to the one that started it all // with the total level count return std::make_pair(root,maxL); }
void setLevelMapFromMST( const Graph& mst , LevelMap& lm , ParentMap& parents , typename Graph::vertex_descriptor root ) { const typename Graph::boost_graph& mst_bg = mst.boostGraph(); lm.clear(); lm.resize( num_vertices(mst_bg) ); parents.clear(); parents.resize( num_vertices(mst_bg) ); lm[root] = 0; // Source or root Node parents[root] = -1; // Root has no parent breadth_first_search( mst_bg , root , boost::visitor(record_levels(lm,parents))); }
MojErr MojLogEngine::configure(const MojObject& conf, const MojChar* name) { MojAssert(name); MojErr err = MojErrNone; MojLogger::Level defaultLevel = MojLogger::LevelDefault; MojAutoPtr<MojLogAppender> appender; LevelMap levels; // validate entire configuration before we apply any changes MojObject logConf; if (conf.get(LogKey, logConf)) { // appender MojObject obj; if (logConf.get(AppenderKey, obj)) { err = createAppender(obj, name, appender); MojErrCheck(err); } // levels if (logConf.get(LevelsKey, obj)) { // configure loggers MojString str; for (MojObject::ConstIterator i = obj.begin(); i != obj.end(); ++i) { MojLogger::Level level = MojLogger::LevelNone; err = i.value().stringValue(str); MojErrCheck(err); err = MojLogger::levelFromString(str, level); MojErrCheck(err); if (i.key() == DefaultKey) { defaultLevel = level; } else { err = levels.put(i.key(), level); MojErrCheck(err); } } } } // apply changes MojThreadGuard guard(m_mutex); // update name err = m_name.assign(name); MojErrCheck(err); // update appender updateAppender(appender); // update levels m_levels = levels; m_defaultLogger.level(defaultLevel); updateLoggers(); return MojErrNone; }
bool Player::MapPosition(LevelMap& map, const PairFloat& pos) { drawPosA = map.toDrawCoord(mapPosition); drawPosB = map.toDrawCoord(pos); bool success = false; if (mapPosition != pos) { success = updateMapPositionBack(map, pos); } if (success == true || map.isMapCoordValid(pos) == true) { updateDrawPosition(map); } return success; }
// TODO: Items should get their positions from the level file void World::InitLevelObjects() { RemoveAIEntities(); LevelMap map = levels[currentLevelIdx].GetMap(); // Inits monsters auto monsterTiles = map.GetTilesForLogicalSprite(TILE_MONSTER); for (auto monster = monsterTiles.begin(); monster != monsterTiles.end(); ++monster) { CreateMonster(monster->position); } // Inits items // TODO: Needs refactoring! auto itemPair = itemsForLevel.find(currentLevelIdx + 1); // We use indices corresponding to the // level files' names if (itemPair != itemsForLevel.end()) { auto itemFileNames = itemPair->second; for (auto itemFileName = itemFileNames.begin(); itemFileName != itemFileNames.end(); ++itemFileName) { // Magnificent loading takes place!!! InitItemFromFile((*itemFileName)); } } auto shrinePair = shrinesForLevel.find(currentLevelIdx + 1); if (shrinePair != shrinesForLevel.end()) { auto shrineFileNames = shrinePair->second; for (auto shrineFileName = shrineFileNames.begin(); shrineFileName != shrineFileNames.end(); ++shrineFileName) { // Magnificent loading takes place!!! InitItemFromFile((*shrineFileName)); } } // Inits boss if (map.HasTileWithLogicalSprite(TILE_BOSS)) { CreateBoss(map.GetTilesForLogicalSprite(TILE_BOSS)[0].position); // TODO: Unsafe. Make better. } levels[currentLevelIdx].RemoveWorldSpecificTiles(); }
unsigned long compute_levels (TypeInfo const& ti, unsigned long cur, LevelMap& map) { unsigned long ret = cur; if (map.find (ti) == map.end () || map[ti] < cur) map[ti] = cur; for (TypeInfo::BaseIterator i = ti.begin_base (); i != ti.end_base (); i++) { unsigned long t = compute_levels (i->type_info (), cur + 1, map); if (t > ret) ret = t; } return ret; }
void Dispatcher:: dispatch (SyntaxTree::NodePtr const& n) { LevelMap levels; unsigned long max = compute_levels (n->type_info (), 0, levels); //cerr << "starting dispatch process for " // << n->type_info ().type_id () << " with " // << max << " levels" << endl; for (unsigned long l = 0; l < max + 1; l++) { TypeInfoSet dispatched; for (LevelMap::const_iterator i = levels.begin (); i != levels.end (); i++) { if (i->second == l) { TraversalMap::const_iterator v = traversal_map_.find (i->first.type_id ()); if (v != traversal_map_.end () && !(v->second.suppressed)) { //cerr << "dispatching traverser for " // << n->type_info ().type_id () << " as " // << i->first.type_id () << endl; v->second.traverser->traverse (n); flatten_tree (i->first, dispatched); } } } // Remove traversed types from level map. for (TypeInfoSet::const_iterator i = dispatched.begin (); i != dispatched.end (); i++) { levels.erase (*i); } } }
bool Player::move(LevelMap& map, const PairFloat& pos) { if (mapPosition == pos || playerStatus == PlayerStatus::Dead || map.isMapCoordValid(pos) == false) { return false; } clearWalkPath(); setStandAnimation(); playerStatus = PlayerStatus::Stand; resetAnimationTime(); drawPosA = drawPosB = map.toDrawCoord(pos); bool success = updateMapPositionBack(map, pos); if (success == true) { updateDrawPosition(map); } return success; }
MapSearchNode::MapSearchNode(const LevelMap& map, int16_t x_, int16_t y_, const PlayerDirection& direction_) noexcept : x(x_), y(y_), direction(direction_) { if (map.isMapCoordValid(x_, y_) == true) { cost = map[x_][y_].Passable() ? NodePassable : NodeNotPassable; } else { cost = NodeInvalid; } }
void Dispatcher:: dispatch (SyntaxTree::Node* n) { LevelMap levels; unsigned long max = compute_levels (n->type_info (), 0, levels); for (unsigned long l = 0; l < max + 1; l++) { TypeInfoSet dispatched; for (LevelMap::const_iterator i = levels.begin (); i != levels.end (); i++) { if (i->second == l) { TraversalMap::const_iterator v = traversal_map_.find (i->first.type_id ()); if (v != traversal_map_.end ()) { v->second->traverse (n); flatten_tree (i->first, dispatched); } } } // Remove traversed types from level map. for (TypeInfoSet::const_iterator i = dispatched.begin (); i != dispatched.end (); i++) { levels.erase (*i); } } }
std::pair<typename Graph::vertex_descriptor,int> generateLevelsFromGraph( const Graph& g , LevelMap& levels , ParentMap& parents , typename Graph::vertex_descriptor * rootPtr , Graph& mst , bool useOriginalWeights ) { using namespace boost; Graph newGraph( g ); // First issue is to weight the nodes if desired if ( ! useOriginalWeights ) generateWeightMapFromNegativeAdjacentVertexCount( newGraph ); // Now to make a tree based on these weights setMSTFromGraph( newGraph , mst ); // Now to determine the root node typename Graph::vertex_iterator v , vend; tie(v,vend) = vertices( mst.boostGraph() ); typename Graph::vertex_descriptor root, v1, v2; if ( !rootPtr ) { // linear time algorithm to find the root by Ying Wang ([email protected]) int i, k, n = mst.vertexCount(); vector <typename Graph::vertex_descriptor> queue(n+1); int *ccount, *d; long long tot = 0, min, *a; typename Graph::out_edge_iterator ee1,ee2; int p, q; queue[p = q = 0] = *v; a = new long long[n+1]; ccount = new int[n+1]; d = new int[n+1]; for(i = 0; i <= n; i++) ccount[i] = 1, d[i] = -1, a[i] = 0; d[ *v ] = 0; const typename Graph::boost_graph& bg = mst.boostGraph(); for(; p<=q; p++) { v1 = queue[p]; tie(ee1, ee2) = out_edges(v1, bg); for(; ee1 != ee2; ee1++) { v2 = target(*ee1, bg); if (d[v2] == -1) queue[++q] = v2, tot += (d[v2] = d[v1] + 1); } } a[ *v ] = min = tot; root = *v; for(k = q; k >= 0; k--) { v1 = queue[k]; tie(ee1, ee2) = out_edges(v1, bg); for(; ee1 != ee2; ee1++) { v2 = target(*ee1, bg); if (d[v2] > d[v1]) { ccount[v1] += ccount[v2]; } } } for(k = 0; k <= q; k++) { v1 = queue[k]; tie(ee1, ee2) = out_edges(v1, bg); for(; ee1 != ee2; ee1++) { v2 = target(*ee1, bg); if (d[v2] > d[v1]) { a[v2] = a[v1] - ccount[v2] + (n - ccount[v2]); if (a[v2] < min) root = v2, min = a[v2]; } } } delete []a; delete []d; delete []ccount; cerr << "root finding done!" << endl; } else { root = *rootPtr; } // The node with the most edges is at root //tie( root , count ) = getVertexWMostEdges( mst ); // Generate a breadth first level map setLevelMapFromMST( mst , levels , parents , root ); int maxL = 0; for ( typename LevelMap::const_iterator i=levels.begin(); i!=levels.end(); ++i ) { maxL = (int) GraphDetail::mmax<long>( *i ,maxL ); } // Return the descriptor to the one that started it all // with the total level count return std::make_pair(root,maxL); }