void Hero::findVisibleTiles() { m_visible.clear(); std::set<point> marked; std::queue<point> open_list; point start(posToTile(m_x), posToTile(m_y)); open_list.push(start); while (!open_list.empty()) { point loc = open_list.front(); open_list.pop(); if (tileDistance(start, loc) < 5) { m_seen.at(loc.second).at(loc.first) = true; m_visible.insert(loc); } for (int i = 0; i < 4; ++i) { point new_loc(loc.first + Utils::directions[i].first, loc.second + Utils::directions[i].second); if (new_loc.first >= 0 && new_loc.first < m_seen.size() && new_loc.second >= 0 && new_loc.second < m_seen.at(0).size()) { if (tileDistance(start, new_loc) < 5 && marked.find(new_loc) == marked.end()) { open_list.push(new_loc); marked.insert(new_loc); } } } } }
/* * Replace mount point with a reference to an error filesystem. * The mount point (struct mntfs) is NOT discarded, * the caller must do it if it wants to _before_ calling this function. */ void assign_error_mntfs(am_node *mp) { int error; dlog("assign_error_mntfs"); if (mp->am_al == NULL) { plog(XLOG_ERROR, "%s: Can't assign error", __func__); return; } /* * Save the old error code */ error = mp->am_error; if (error <= 0) error = mp->am_al->al_mnt->mf_error; /* * Allocate a new error reference */ free_loc(mp->am_al); mp->am_al = new_loc(); /* * Put back the error code */ mp->am_al->al_mnt->mf_error = error; mp->am_al->al_mnt->mf_flags |= MFF_ERROR; /* * Zero the error in the mount point */ mp->am_error = 0; }
void Paddle::move_ball(){ if( ball != nullptr){ glm::vec2 ball_loc = ball->get_location(); glm::vec2 ball_dim = ball->get_dimensions(); glm::vec2 new_loc( location.x +dimensions.x/2 - ball_dim.x/2, location.y - ball_dim.x ); ball->change_location(new_loc); } }
static void pass_three(struct level *lev, schar bg_typ, schar fg_typ) { int i, j; short count, dr; for (i = 1; i <= WIDTH; i++) for (j = 1; j < HEIGHT; j++) { for (count = 0, dr = 0; dr < 8; dr++) if (get_map (lev, i + dirs[dr * 2], j + dirs[(dr * 2) + 1], bg_typ) == fg_typ) count++; if (count < 3) new_loc(i, j) = bg_typ; else new_loc(i, j) = get_map(lev, i, j, bg_typ); } for (i = 1; i <= WIDTH; i++) for (j = 1; j < HEIGHT; j++) lev->locations[i][j].typ = new_loc(i, j); }
STATIC_OVL void pass_three(schar bg_typ, schar fg_typ) { register int i,j; short count, dr; for(i=2; i<=WIDTH; i++) for(j=1; j<HEIGHT; j++) { for(count=0, dr=0; dr < 8; dr++) if(get_map(i+dirs[dr*2], j+dirs[(dr*2)+1], bg_typ) == fg_typ) count++; if (count < 3) new_loc(i,j) = bg_typ; else new_loc(i,j) = get_map(i,j, bg_typ); } for(i=2; i<=WIDTH; i++) for(j=1; j<HEIGHT; j++) if (new_loc(i,j) < MAX_TYPE) levl[i][j].typ = new_loc(i,j); }
/* * Pick a file system to try mounting and * do that in the background if necessary * For each location: discard previous mount location if required fetch next mount location if the filesystem failed to be mounted then this_error = error from filesystem goto failed if the filesystem is mounting or unmounting then goto retry; if the fileserver is down then this_error = EIO continue; if the filesystem is already mounted break fi this_error = initialize mount point if no error on this mount and mount is delayed then this_error = -1 fi if this_error < 0 then retry = true fi if no error on this mount then if mount in background then run mount in background return -1 else this_error = mount in foreground fi fi if an error occurred on this mount then update stats save error in mount point fi endfor */ static int amfs_bgmount(struct continuation *cp) { am_node *mp = cp->mp; am_loc *loc; mntfs *mf; int this_error = -1; /* Per-mount error */ int hard_error = -1; /* Cumulative per-node error */ if (mp->am_al) free_loc(mp->am_al); /* * Try to mount each location. * At the end: * hard_error == 0 indicates something was mounted. * hard_error > 0 indicates everything failed with a hard error * hard_error < 0 indicates nothing could be mounted now */ for (mp->am_al = *cp->al; *cp->al; cp->al++, mp->am_al = *cp->al) { am_ops *p; loc = dup_loc(mp->am_al); mf = loc->al_mnt; p = mf->mf_ops; if (hard_error < 0) hard_error = this_error; this_error = 0; if (mf->mf_error > 0) { this_error = mf->mf_error; goto failed; } if (mf->mf_flags & (MFF_MOUNTING | MFF_UNMOUNTING)) { /* * Still mounting - retry later */ dlog("mount of \"%s\" already pending", mf->mf_info); goto retry; } if (FSRV_ISDOWN(mf->mf_server)) { /* * Would just mount from the same place * as a hung mount - so give up */ dlog("%s is already hung - giving up", mf->mf_server->fs_host); this_error = EIO; goto failed; } XFREE(mp->am_link); mp->am_link = NULL; if (loc->al_fo && loc->al_fo->opt_sublink && loc->al_fo->opt_sublink[0]) mp->am_link = xstrdup(loc->al_fo->opt_sublink); /* * Will usually need to play around with the mount nodes * file attribute structure. This must be done here. * Try and get things initialized, even if the fileserver * is not known to be up. In the common case this will * progress things faster. */ /* * Fill in attribute fields. */ if (mf->mf_fsflags & FS_DIRECTORY) mk_fattr(&mp->am_fattr, NFDIR); else mk_fattr(&mp->am_fattr, NFLNK); if (mf->mf_flags & MFF_MOUNTED) { dlog("duplicate mount of \"%s\" ...", mf->mf_info); /* * Skip initial processing of the mountpoint if already mounted. * This could happen if we have multiple sublinks into the same f/s, * or if we are restarting an already-mounted filesystem. */ goto already_mounted; } if (mf->mf_fo && mf->mf_fo->fs_mtab) { plog(XLOG_MAP, "Trying mount of %s on %s fstype %s mount_type %s", mf->mf_fo->fs_mtab, mf->mf_mount, p->fs_type, mp->am_flags & AMF_AUTOFS ? "autofs" : "non-autofs"); } if (p->fs_init && !(mf->mf_flags & MFF_RESTART)) this_error = p->fs_init(mf); if (this_error > 0) goto failed; if (this_error < 0) goto retry; if (loc->al_fo && loc->al_fo->opt_delay) { /* * If there is a delay timer on the location * then don't try to mount if the timer * has not expired. */ int i = atoi(loc->al_fo->opt_delay); time_t now = clocktime(NULL); if (i > 0 && now < (cp->start + i)) { dlog("Mount of %s delayed by %lds", mf->mf_mount, (long) (i - now + cp->start)); goto retry; } } /* * If the directory is not yet made and it needs to be made, then make it! */ if (!(mf->mf_flags & MFF_MKMNT) && mf->mf_fsflags & FS_MKMNT) { plog(XLOG_INFO, "creating mountpoint directory '%s'", mf->mf_mount); this_error = mkdirs(mf->mf_mount, 0555); if (this_error) { plog(XLOG_ERROR, "mkdirs failed: %s", strerror(this_error)); goto failed; } mf->mf_flags |= MFF_MKMNT; } #ifdef HAVE_FS_AUTOFS if (mf->mf_flags & MFF_IS_AUTOFS) if ((this_error = autofs_get_fh(mp))) goto failed; #endif /* HAVE_FS_AUTOFS */ already_mounted: mf->mf_flags |= MFF_MOUNTING; if (mf->mf_fsflags & FS_MBACKGROUND) { dlog("backgrounding mount of \"%s\"", mf->mf_mount); if (cp->callout) { untimeout(cp->callout); cp->callout = 0; } /* actually run the task, backgrounding as necessary */ run_task(mount_node, (opaque_t) mp, amfs_cont, (opaque_t) cp); return -1; } else { dlog("foreground mount of \"%s\" ...", mf->mf_mount); this_error = mount_node((opaque_t) mp); } mf->mf_flags &= ~MFF_MOUNTING; if (this_error > 0) goto failed; if (this_error == 0) { am_mounted(mp); break; /* Success */ } retry: if (!cp->retry) continue; dlog("will retry ...\n"); /* * Arrange that amfs_bgmount is called * after anything else happens. */ dlog("Arranging to retry mount of %s", mp->am_path); sched_task(amfs_retry, (opaque_t) cp, get_mntfs_wchan(mf)); if (cp->callout) untimeout(cp->callout); cp->callout = timeout(RETRY_INTERVAL, wakeup, (opaque_t) get_mntfs_wchan(mf)); mp->am_ttl = clocktime(NULL) + RETRY_INTERVAL; /* * Not done yet - so don't return anything */ return -1; failed: if (!FSRV_ISDOWN(mf->mf_server)) { /* mark the mount as failed unless the server is down */ amd_stats.d_merr++; mf->mf_error = this_error; mf->mf_flags |= MFF_ERROR; #ifdef HAVE_FS_AUTOFS if (mp->am_autofs_fh) autofs_release_fh(mp); #endif /* HAVE_FS_AUTOFS */ if (mf->mf_flags & MFF_MKMNT) { rmdirs(mf->mf_mount); mf->mf_flags &= ~MFF_MKMNT; } } /* * Wakeup anything waiting for this mount */ wakeup(get_mntfs_wchan(mf)); free_loc(loc); /* continue */ } /* * If we get here, then either the mount succeeded or * there is no more mount information available. */ if (this_error) { if (mp->am_al) free_loc(mp->am_al); mp->am_al = loc = new_loc(); mf = loc->al_mnt; #ifdef HAVE_FS_AUTOFS if (mp->am_flags & AMF_AUTOFS) autofs_mount_failed(mp); else #endif /* HAVE_FS_AUTOFS */ nfs_quick_reply(mp, this_error); if (hard_error <= 0) hard_error = this_error; if (hard_error < 0) hard_error = ETIMEDOUT; /* * Set a small(ish) timeout on an error node if * the error was not a time out. */ switch (hard_error) { case ETIMEDOUT: case EWOULDBLOCK: case EIO: mp->am_timeo = 17; break; default: mp->am_timeo = 5; break; } new_ttl(mp); } else { mf = loc->al_mnt; /* * Wakeup anything waiting for this mount */ wakeup(get_mntfs_wchan(mf)); hard_error = 0; } /* * Make sure that the error value in the mntfs has a * reasonable value. */ if (mf->mf_error < 0) { mf->mf_error = hard_error; if (hard_error) mf->mf_flags |= MFF_ERROR; } /* * In any case we don't need the continuation any more */ free_continuation(cp); return hard_error; }
static am_loc * amfs_lookup_one_location(am_node *new_mp, mntfs *mf, char *ivec, char *def_opts, char *pfname) { am_ops *p; am_opts *fs_opts; am_loc *new_al; mntfs *new_mf; char *mp_dir = NULL; #ifdef HAVE_FS_AUTOFS int on_autofs = 1; #endif /* HAVE_FS_AUTOFS */ /* match the operators */ /* * although we alloc the fs_opts here, the pointer is 'owned' by the am_loc and will * be free'd on destruction of the am_loc. If we don't allocate a loc, then we need * to free this. */ fs_opts = CALLOC(am_opts); p = ops_match(fs_opts, ivec, def_opts, new_mp->am_path, pfname, mf->mf_info); #ifdef HAVE_FS_AUTOFS /* XXX: this should be factored out into an autofs-specific function */ if (new_mp->am_flags & AMF_AUTOFS) { /* ignore user-provided fs if we're using autofs */ if (fs_opts->opt_sublink && fs_opts->opt_sublink[0]) { /* * For sublinks we need to use a hack with autofs: * mount the filesystem on the original opt_fs (which is NOT an * autofs mountpoint) and symlink (or lofs-mount) to it from * the autofs mountpoint. */ on_autofs = 0; mp_dir = fs_opts->opt_fs; } else { if (p->autofs_fs_flags & FS_ON_AUTOFS) { mp_dir = new_mp->am_path; } else { mp_dir = fs_opts->opt_fs; on_autofs = 0; } } } else #endif /* HAVE_FS_AUTOFS */ mp_dir = fs_opts->opt_fs; /* * Find or allocate a filesystem for this node. * we search for a matching backend share, since * we will construct our own al_loc to handle * any customisations for this usage. */ new_mf = find_mntfs(p, fs_opts, mp_dir, fs_opts->fs_mtab, def_opts, fs_opts->opt_opts, fs_opts->opt_remopts); /* * See whether this is a real filesystem */ p = new_mf->mf_ops; if (p == &amfs_error_ops) { plog(XLOG_MAP, "Map entry %s for %s did not match", ivec, new_mp->am_path); free_mntfs(new_mf); free_opts(fs_opts); XFREE(fs_opts); return NULL; } dlog("Got a hit with %s", p->fs_type); new_al = new_loc(); free_mntfs(new_al->al_mnt); new_al->al_mnt = new_mf; new_al->al_fo = fs_opts; /* now the loc is in charge of free'ing this mem */ #ifdef HAVE_FS_AUTOFS if (new_mp->am_flags & AMF_AUTOFS && on_autofs) { new_mf->mf_flags |= MFF_ON_AUTOFS; new_mf->mf_fsflags = new_mf->mf_ops->autofs_fs_flags; } /* * A new filesystem is an autofs filesystems if: * 1. it claims it can be one (has the FS_AUTOFS flag) * 2. autofs is enabled system-wide * 3. either has an autofs parent, * or it is explicitly requested to be autofs. */ if (new_mf->mf_ops->autofs_fs_flags & FS_AUTOFS && amd_use_autofs && ((mf->mf_flags & MFF_IS_AUTOFS) || (new_mf->mf_fo && new_mf->mf_fo->opt_mount_type && STREQ(new_mf->mf_fo->opt_mount_type, "autofs")))) new_mf->mf_flags |= MFF_IS_AUTOFS; #endif /* HAVE_FS_AUTOFS */ return new_al; }