int directory_walk(struct directory *directory, int (*forEachSong)(struct song *, void *), int (*forEachDir)(struct directory *, void *), void *data) { struct dirvec *dv = &directory->children; int err = 0; size_t j; if (forEachDir && (err = forEachDir(directory, data)) < 0) return err; if (forEachSong) { err = songvec_for_each(&directory->songs, forEachSong, data); if (err < 0) return err; } for (j = 0; err >= 0 && j < dv->nr; ++j) err = directory_walk(dv->base[j], forEachSong, forEachDir, data); return err; }
void Feeler::feelSurroundings(const DirVecMap& dirs) { _feelable.clear(); forEachDir(dirs, [&](Direction dir){ char posSym = home()->grid.charAt(pos() + dirs.at(dir)); _feelable.insert(CharDirPair(posSym, dir)); }); }
int Feeler::numberOfSurrounding(Vec2 pos, const DirVecMap& dirs, const CharArr& conditions) { int things = 0; forEachDir(dirs, [&](Direction dir){ for (int i = 0; i < conditions.size(); i++) { if (home()->grid.charAt(pos + dirs.at(dir)) == conditions.at(i)) ++things; } }); return things; }