예제 #1
0
파일: lfunc.c 프로젝트: iVideo/weishao
UpVal *luaF_findupval (lua_State *L, StkId level) {
  global_State *g = G(L);
  GCObject **pp = &L->openupval;
  UpVal *p;
  UpVal *uv;
  while (*pp != NULL && (p = gco2uv(*pp))->v >= level) {
    GCObject *o = obj2gco(p);
    lua_assert(p->v != &p->u.value);
    lua_assert(!isold(o) || isold(obj2gco(L)));
    if (p->v == level) {  /* found a corresponding upvalue? */
      if (isdead(g, o))  /* is it dead? */
        changewhite(o);  /* resurrect it */
      return p;
    }
    pp = &p->next;
  }
  /* not found: create a new one */
  uv = &luaC_newobj(L, LUA_TUPVAL, sizeof(UpVal), pp, 0)->uv;
  uv->v = level;  /* current value lives in the stack */
  uv->u.l.prev = &g->uvhead;  /* double link it in `uvhead' list */
  uv->u.l.next = g->uvhead.u.l.next;
  uv->u.l.next->u.l.prev = uv;
  g->uvhead.u.l.next = uv;
  lua_assert(uv->u.l.next->u.l.prev == uv && uv->u.l.prev->u.l.next == uv);
  return uv;
}
예제 #2
0
/*
 * Move to a particular position and see if we hit a mine.
 * If not, then count the number of mines adjacent to us so it can be seen.
 * If we are stepping onto a location where we remembered a mine is at,
 * then don't do it.  Moving is only allowed to old locations, or to
 * locations adjacent to old ones.
 */
static void
movetopos(POS newpos)
{
    POS		fixpos;		/* position to fix up */
    CELL		cell;		/* current cell */
    GR_COUNT	count;		/* count of cells */
    GR_COUNT	i;		/* index for neighbors */

    if ((newpos < 0) || (newpos >= (FULLSIZE * FULLSIZE)) || !playing)
        return;

    cell = board[newpos];

    if (isedge(cell) || (isseen(cell)) || isold(cell))
        return;

    count = isold(cell);
    for (i = 0; i < 8; i++)
        if (isold(board[newpos + steptable[i]]))
            count++;

    if (count <= 0)
        return;

    cell = (cell & F_FLAGS) | F_OLD;
    steps++;

    PRINTSTEPS;

    if (ismine(cell)) {		/* we hit a mine */
        legs--;
        board[newpos] = (F_REMEMBER | F_MINE);
        cell = (F_EMPTY | F_OLD);
        board[newpos] = cell;
        drawbomb(newpos, redgc, GR_TRUE);
        clearcell(newpos);
        setcursor();
        for (i = 0; i < 8; i++) {
            fixpos = newpos + steptable[i];
            if (isold(board[fixpos])) {
                board[fixpos]--;
                drawcell(fixpos);
            }
        }
        drawstatus();
    }

    count = 0;
    for (i = 0; i < 8; i++)
        if (ismine(board[newpos + steptable[i]]))
            count++;
    board[newpos] = cell | (count + '0');

    drawcell(newpos);

    if ((legs <= 0) || (newpos == boardpos(size,size)))
        gameover();
}
예제 #3
0
/*
 * Draw a cell on the board.
 */
static void
drawcell(POS pos)
{
    GR_COORD	x;
    GR_COORD	y;
    GR_SIZE		chwidth;
    GR_SIZE		chheight;
    GR_SIZE		chbase;
    CELL		cell;
    GR_CHAR		ch;

    cell = board[pos];
    if (!isknown(cell))
        return;

    ch = displaychar(cell);
    if (ch == F_WRONG) {
        drawbomb(pos, greengc, GR_FALSE);
        return;
    }

    if (isold(cell)) {
        clearcell(pos);
        cellcenter(pos, &x, &y);
        GrGetGCTextSize(boardgc, &ch, 1, GR_TFASCII, &chwidth,
                        &chheight, &chbase);
        GrText(boardwid, boardgc, x - chwidth / 2 + 1,
               y + chheight / 2, &ch, 1, GR_TFBOTTOM);
        return;
    }

    drawbomb(pos, redgc, GR_FALSE);
}
예제 #4
0
파일: lgc.c 프로젝트: crazii/mameplus
static GCObject *udata2finalize (global_State *g) {
	GCObject *o = g->tobefnz;  /* get first element */
	lua_assert(isfinalized(o));
	g->tobefnz = gch(o)->next;  /* remove it from 'tobefnz' list */
	gch(o)->next = g->allgc;  /* return it to 'allgc' list */
	g->allgc = o;
	resetbit(gch(o)->marked, SEPARATED);  /* mark that it is not in 'tobefnz' */
	lua_assert(!isold(o));  /* see MOVE OLD rule */
	if (!keepinvariantout(g))  /* not keeping invariant? */
	makewhite(g, o);  /* "sweep" object */
	return o;
}