bool MeshLayersDistFromPatch::updateFace
 (
     const polyMesh& mesh,
     const label thisFaceI,
     const label neighbourCellI,
     const MeshLayersDistFromPatch& neighbourInfo,
     const scalar tol
 )
     {
         if(!valid()) {
             if(!blocked()) {
                 dist_=1+neighbourInfo.dist();
                 return true;
             } else {
                 return false;
             }
         } else {
             const scalar nd=1+neighbourInfo.dist();
             if(nd<dist_) {
                 dist_=nd;
                 return true;
             } else {
                 return false;
             }
         }
     }
void GamePanelControl::activatePanel(GamePanel *panel, bool activate)
{
  bool block = panel->isBlocking();
  QList<GamePanel*> &list = block ? activeBlockingPanels : activeNonBlockingPanels;

  if (activate)
  {
    if (activePanels.contains(panel))
      return;

    if (list.isEmpty() && block)
      emit blocked();

    list.append(panel);
    activePanels.append(panel);
  }
  else
  {
    if (!activePanels.contains(panel))
      return;

    list.removeAll(panel);
    activePanels.removeAll(panel);

    if (!block && list.isEmpty())
      emit unblocked();
  }
}
Пример #3
0
bool QXmppUserBlacklistManager::handleStanza(const QDomElement &element)
{
  if (element.tagName() != "iq")
    return false;
    
  // XEP-0191: Blocking Command
  if (QXmppUserBlacklistIq::isUserBlacklistIq(element))
  {
    QXmppUserBlacklistIq blockListIq;
    blockListIq.parse(element);
    emit blacklistReceived(blockListIq.blocklist());
    return true;
  } else if (QXmppUserBlacklistBlockIq::isUserBlacklistBlockIq(element))
  {
    QXmppUserBlacklistBlockIq blockIq;
    blockIq.parse(element);
    emit blocked(blockIq.jid());
    return true;
  } else if (QXmppUserBlacklistUnblockIq::isUserBlacklistUnblockIq(element))
  {
    QXmppUserBlacklistUnblockIq unblockIq;
    unblockIq.parse(element);
    emit unblocked(unblockIq.jid());
    return true;
  }

  return false;
}
Пример #4
0
/**
 * Creates object new_op in direction dir or if that is blocked, beneath
 * the player (op).
 * @param op Who is casting.
 * @param new_op Object to insert.
 * @param dir Direction to insert into. Can be 0.
 * @return Direction that the object was actually placed in. */
int cast_create_obj(object *op, object *new_op, int dir)
{
	mapstruct *mt;
	int xt, yt;

	xt = op->x + freearr_x[dir];
	yt = op->y + freearr_y[dir];

	if (!(mt = get_map_from_coord(op->map, &xt, &yt)))
	{
		return 0;
	}

	if (dir && blocked(op, mt, xt, yt, op->terrain_flag))
	{
		new_draw_info(NDI_UNIQUE, op, "Something is in the way.\nYou cast it at your feet.");
		dir = 0;
	}

	xt = op->x + freearr_x[dir];
	yt = op->y + freearr_y[dir];

	if (!(mt = get_map_from_coord(op->map, &xt, &yt)))
	{
		return 0;
	}

	new_op->x = xt;
	new_op->y = yt;
	new_op->map = mt;
	insert_ob_in_map(new_op, mt, op, 0);
	return dir;
}
Пример #5
0
 void synchronized_await(Mutex& mtx, CondVar& cv) {
     CPPA_REQUIRE(!closed());
     if (try_block()) {
         std::unique_lock<Mutex> guard(mtx);
         while (blocked()) cv.wait(guard);
     }
 }
Пример #6
0
void SslClient::establish(const QString& host, quint16 port)
{
    threadLock_  = new QMutex();
    threadEvent_ = new QWaitCondition();

    QMutexLocker blocked(threadLock_);
    host_ = host;
    port_ = port;

    start();
    threadEvent_->wait(threadLock_);

    if(ssl_.isNull() || running_ == false)
        Q_ASSERT_X(ssl_.isNull() || running_ == false, "SslClient::establish", "Cannot start SslClient's thread");

    connect(ssl_.data(), SIGNAL(stateChanged(QAbstractSocket::SocketState)), 
            this, SLOT(socketStateChanged(QAbstractSocket::SocketState)), Qt::DirectConnection);
    connect(ssl_.data(), SIGNAL(encrypted()), 
            this, SLOT(socketEncrypted()), Qt::DirectConnection);
    connect(ssl_.data(), SIGNAL(error(QAbstractSocket::SocketError)), 
            this, SLOT(socketError(QAbstractSocket::SocketError)), Qt::DirectConnection);
    connect(ssl_.data(), SIGNAL(sslErrors(QList<QSslError>)), 
            this, SLOT(sslErrors(QList<QSslError>)), Qt::DirectConnection);
    connect(ssl_.data(), SIGNAL(readyRead()), 
            this, SLOT(socketReadyRead()), Qt::DirectConnection);

    ConfigureForLMAX();
}
Пример #7
0
void move_zombies( game g ) {
    creature Z = g->ZombieListHead;
    while( Z != NULL ) {
        chr z = Z->Character;
        if( ! z->alert ) {
            int check = randint(-1,1);
            if( check == 0 ) {
                mvrel( z, randint( -1, 1 ), 0 );    
            } else if( check ==1 ) {
                mvrel( z, 0, randint( -1, 1 ) );    
            }
        } else {
            int dx = g->pc->pos->x - z->pos->x;
            int dy = g->pc->pos->y - z->pos->y;

            // Axis 0 will be horizontal, axis 1 is vertical.
            int axis = randint( 0, 1 );
            if( abs( dx ) > abs( dy ) ) {
                axis = 0;
            } else if( abs( dx ) < abs( dy ) ) {
                axis = 1;
            }
            int h_blocked = blocked(g->arena, z->pos->y, z->pos->x + 2*(dx >= 0) - 1);
            int v_blocked = blocked(g->arena, z->pos->y + 2*(dy >= 0) - 1, z->pos->x);
            if(h_blocked && !v_blocked) axis = 1;
            if(v_blocked && !h_blocked) axis = 0;

            int dir = 0;
            if( axis == 0 ) { // move along x-axis.
                if( dx >= 0 ) {
                    dir = 1;
                } else {
                    dir = -1;
                }
                mvrel( z, 0, dir );
            } else {
                if( dy >= 0 ) {
                    dir = 1;
                } else {
                    dir = -1;
                }
                mvrel( z, dir, 0 );
            }
        }
        Z = Z->Next;
    }
}
Пример #8
0
 void incr(F&& f)
 {
   incr();
   if (blocked())
   {
     f(*this);
   }
 }
Пример #9
0
Файл: tank.cpp Проект: zkl/Gear
void Tank::move()
{
	int x = _x, y = _y;
	if(_direction == DIR_LEFT)
		_x -= _speed;
	else if(_direction == DIR_RIGHT)
		_x += _speed;
	else if(_direction == DIR_UP)
		_y -= _speed;
	else if(_direction == DIR_DOWN)
		_y += _speed;

	if(x < 0 || y < 0)
	{
		assert(x >= 0);
		assert(y >= 0);
		printf("Tank::move -> Error Position");
	}

	if(_explorer)
	{
		if(blocked())
		{
			_x = x;
			_y = y;
		}
		else
		{
			int position = 0;
			if(_direction == DIR_UP || _direction == DIR_LEFT)
				position = _tilemap->convertPositionFromCoordinate(_x, _y);
			else
				position = _tilemap->convertPositionFromCoordinate(_x+15, _y+15);

			Tank* tank = (Tank*)_tilemap->getObjectLayer()->getObject(position);
			if((tank != this && tank != 0))
			{
				_x = x;
				_y = y;
			}
			else
			{
				this->markObjectOnMap(_x, _y, this);
			}
		}
	}

	_explorer = false;
	if(_x%_tilemap->tilewidth() == 0 && _y%_tilemap->tileheight() == 0)
	{
		_explorer = true;
		_moving   = false;

		this->markObjectOnMap(x, y, 0);
		this->markObjectOnMap(_x, _y, this);
	}
}
Пример #10
0
void SslClient::stop()
{
    running_ = false;
    {
        QMutexLocker blocked(threadLock_);
        exit();
    }
    wait();
}
Пример #11
0
void SslClient::run()
{
    Q_ASSERT_X(running_==0,"SslClient::run", "Thread object reuse");
    Q_ASSERT_X(ssl_.isNull(),"SslClient::run", "Socket object reuse");

    ssl_.reset(new QSslSocket(this));
    ssl_->connectToHostEncrypted(host_,port_);

    running_ = true;
    threadEvent_->wakeOne();

    { QMutexLocker blocked(threadLock_); }
    QThread::exec();

    QMutexLocker blocked(threadLock_);
    ssl_->close();
    ssl_.reset();
}
 void synchronized_await(Mutex& mtx, CondVar& cv) {
   CAF_ASSERT(! closed());
   if (! can_fetch_more() && try_block()) {
     std::unique_lock<Mutex> guard(mtx);
     while (blocked()) {
       cv.wait(guard);
     }
   }
 }
Пример #13
0
int Block::fall(Block*** grid)
{
    cdebug << "Entering Block::fall()\n";
    mask.y += BLOCK_WIDTH;

    if (!blocked((const Block***)grid) )
    {
        return 0;
    }
    cdebug << "Blocked!\n";
    return 1;
}
Пример #14
0
/*
 * Function: move (Smiley's Basic Function)
 * Walk one step depending on the current direction.
 */
void move(){
	printf("[Smiley] move\n");

	if(blocked())	printErrorAndExit(BLOCKED);
	switch(Facing){
		case EAST:	PosC++;	break;
		case NORTH:	PosR--;	break;
		case WEST:	PosC--;	break;
		case SOUTH:	PosR++;	break;
	}
	//print out the current status
	printMapAndWalls();
}
Пример #15
0
// ---------------------------------------------------------------------------
// Setup the object to scan the next directory
// ---------------------------------------------------------------------------
//
TBool CMPXFolderScanner::SetupNextDriveToScanL()
    {
    MPX_DEBUG1("CMPXFolderScanner::SetupNextDriveToScanL <---");
    
    TBool done(EFalse);
    TBool blocked(EFalse);
    // Scan next drive
    while( iDrivesToScan.Count() && !iDirQueue.Count() )
        {
        TPath path = iDrivesToScan[0];

        MPX_DEBUG1( "CMPXFolderScanner::SetupNextDriveToScanL path blocked?" );
        blocked = iObserver.IsPathBlockedL( path );
        MPX_DEBUG2( "CMPXFolderScanner::SetupNextDriveToScanL path blocked %i",
                    blocked );

        // If there was something to scan
        if( !blocked )
            {
            CDirQueueEntry* newEntry = CDirQueueEntry::NewL( path );
            TInt err = newEntry->iDir.Open( iFs,
                                            path,
                                            KEntryAttNormal | KEntryAttDir );
            if ( err == KErrNone )
                {
                CDirQueueEntry::PushL( iDirQueue, newEntry );
                // Inform Observer of the new drive that we are scanning
                iObserver.HandleOpenDriveL( ::ExtractDrive(iDrivesToScan[0]),
                                            iDrivesToScan[0] );
                }
            else
                {
                delete newEntry;
                }
            }

        // Remove the 0th element
        iDrivesToScan.Remove(0);
        iDrivesToScan.Compress();

        }

    if ( !iDirQueue.Count() )
        {
        done = ETrue;
        }
    
    
    MPX_DEBUG1("CMPXFolderScanner::SetupNextDriveToScanL --->");
    return done;
    }
Пример #16
0
 bool synchronized_await(Mutex& mtx, CondVar& cv, const TimePoint& timeout) {
   CAF_ASSERT(!closed());
   if (try_block()) {
     std::unique_lock<Mutex> guard(mtx);
     while (blocked()) {
       if (cv.wait_until(guard, timeout) == std::cv_status::timeout) {
         // if we're unable to set the queue from blocked to empty,
         // than there's a new element in the list
         return !try_unblock();
       }
     }
   }
   return true;
 }
Пример #17
0
// Only run this on the rust stack
void
rust_task::yield(bool *killed) {
    if (must_fail_from_being_killed()) {
        I(thread, !blocked());
        *killed = true;
    }

    // Return to the scheduler.
    ctx.next->swap(ctx);

    if (must_fail_from_being_killed()) {
        *killed = true;
    }
}
Пример #18
0
double *call_blocked(int n_layers, int n_points, double *x2, double *y2, double r2){
    int n;

    // generate the planet grid
    double **planet = generate_planet(n_layers);

    double *output = malloc(sizeof(double) * n_points);

    for (n = 0; n < n_points; n++) {
        output[n] = blocked(planet,n_layers,x2[n],y2[n],r2);
    }

    free(planet);

    return output;
}
Пример #19
0
// given a state, find the value (of end states only)
int AB_Pruning::value(State& s){

	int value = 0;

	value = row_win(s); // check if a pawn is in opposite row

	if (value == 0){
		value = all_gone(s);// all opponent pawns are gone
	}
	if (value == 0){
		value = blocked(s);// there are no more moves
	}
	// give extra value to states eliminating opponent pawns
	value += attack(s);

	return value;
}// close value
Пример #20
0
  size_t pri_synchronized_reset(Mutex& mtx, CondVar& cv)
  {
    ACTX_ASSERTS(!blocked());
    auto c = reset();
    if (c != 0)
    {
      return c;
    }

    std::unique_lock<Mutex> guard{mtx};
    block();
    auto _ = gsl::finally([this]() {unblock(); });
    c = reset();
    while (c == 0)
    {
      cv.wait(guard);
      c = reset();
    }

    return c;
  }
    bool FloodFillData::updateFace
    (
        const polyMesh&,
        const label thisFaceI,
        const FloodFillData& neighbourInfo,
        const scalar tol
#ifdef FOAM_FACECELLWAVE_HAS_TRACKINGDATA
        ,TrackingData &td
#endif
    )
        {
            if(!valid(TRACKDATA)) {
                if(!blocked()) {
                    val_=target_;
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
Пример #22
0
void
rust_task::kill() {
    scoped_lock with(kill_lock);

    if (dead()) {
        // Task is already dead, can't kill what's already dead.
        fail_parent();
    }

    // Note the distinction here: kill() is when you're in an upcall
    // from task A and want to force-fail task B, you do B->kill().
    // If you want to fail yourself you do self->fail().
    LOG(this, task, "killing task %s @0x%" PRIxPTR, name, this);
    // When the task next goes to yield or resume it will fail
    killed = true;
    // Unblock the task so it can unwind.

    if (blocked()) {
        wakeup(cond);
    }

    LOG(this, task, "preparing to unwind task: 0x%" PRIxPTR, this);
}
Пример #23
0
        virtual BSONObj generateSection( const BSONElement& configElement ) const {
            BSONObjBuilder t;

            t.append( "totalTime" , (long long)(1000 * ( curTimeMillis64() - _started ) ) );

            // SERVER-14978: Need to report the global lock statistics somehow
            //
            // t.append( "lockTime" , qlk.stats.getTimeLocked( 'W' ) );

            // This returns the blocked lock states
            {
                BSONObjBuilder ttt( t.subobjStart( "currentQueue" ) );

                LockerAggregator blocked(true);
                getGlobalEnvironment()->forEachOperationContext(&blocked);

                ttt.append("total", blocked.numReadLocked + blocked.numWriteLocked);
                ttt.append("readers", blocked.numReadLocked);
                ttt.append("writers", blocked.numWriteLocked);
                ttt.done();
            }

            // This returns all the active clients (including those holding locks)
            {
                BSONObjBuilder ttt( t.subobjStart( "activeClients" ) );

                LockerAggregator active(false);
                getGlobalEnvironment()->forEachOperationContext(&active);

                ttt.append("total", active.numReadLocked + active.numWriteLocked);
                ttt.append("readers", active.numReadLocked);
                ttt.append("writers", active.numWriteLocked);
                ttt.done();
            }

            return t.obj();
        }
 bool MeshLayersDistFromPatch::updateFace
 (
     const polyMesh&,
     const label thisFaceI,
     const MeshLayersDistFromPatch& neighbourInfo,
     const scalar tol
 )
     {
         if(!valid()) {
             if(!blocked()) {
                 dist_=neighbourInfo.dist();
                 return true;
             } else {
                 return false;
             }
         } else {
             if(dist()>neighbourInfo.dist()) {
                 dist_=neighbourInfo.dist();
                 return true;
             } else {
                 return false;
             }
         }
     }
Пример #25
0
int AttachGalley(OBJECT hd, OBJECT *inners, OBJECT *suspend_pt)
{ OBJECT hd_index;		/* the index of hd in the enclosing galley   */
  OBJECT hd_inners;		/* inner galleys of hd, if unsized           */
  OBJECT dest;			/* the target @Galley hd empties into        */
  OBJECT dest_index;		/* the index of dest                         */
  OBJECT target;		/* the target indefinite containing dest     */
  OBJECT target_index;		/* the index of target                       */
  OBJECT target_galley;		/* the body of target, made into a galley    */
  OBJECT tg_inners;		/* inner galleys of target_galley            */
  BOOLEAN need_precedes = FALSE;/* true if destination lies before galley    */
  OBJECT recs;			/* list of recursive definite objects        */
  OBJECT link, y = nilobj;	/* for scanning through the components of hd */
  CONSTRAINT c;			/* temporary variable holding a constraint   */
  OBJECT env, n1, tmp, zlink, z, sym;	/* placeholders and temporaries	     */
  BOOLEAN was_sized;		/* true if sized(hd) initially               */
  int dim;			/* the galley direction                      */
  FULL_LENGTH perp_back, perp_fwd;
  OBJECT why, junk;

  debug2(DGA, D, "[ AttachGalley(Galley %s into %s)",
	SymName(actual(hd)), SymName(whereto(hd)));
  ifdebug(DGA, DD, DebugGalley(hd, nilobj, 4));
  assert( Up(hd) != hd, "AttachGalley: no index!" );
  Parent(hd_index, Up(hd));
  assert( type(hd_index) == UNATTACHED, "AttachGalley: not UNATTACHED!" );
  hd_inners = tg_inners = nilobj;
  was_sized = sized(hd);
  dim = gall_dir(hd);

  for(;;)
  {
    /*************************************************************************/
    /*                                                                       */
    /*  Search for a destination for hd.  If hd is unsized, search for       */
    /*  inner galleys preceding it first of all, then for receptive objects  */
    /*  following it, possibly in inner galleys.  If no luck, exit.          */
    /*  If hd is sized, search only for receptive objects in the current     */
    /*  galley below the current spot, and fail if cannot find any.          */
    /*                                                                       */
    /*************************************************************************/

    sym = whereto(hd);
    if( sized(hd) )
    {
      /* sized galley case: search on from current spot */
      target_index = SearchGalley(Up(hd_index), sym, TRUE, FALSE, TRUE, TRUE);
      if( target_index == nilobj )
      {	
	/* search failed to find any new target, so kill the galley */
	for( link = Down(hd); link != hd; link = NextDown(link) )
	{ Child(y, link);
	  if( type(y) == SPLIT )  Child(y, DownDim(y, dim));
	  if( is_definite(type(y)) )  break;
	}
	if( link != hd )
	  Error(19, 1, "galley %s deleted from here (no target)",
	    WARN, &fpos(y), SymName(actual(hd)));
	if( hd_inners != nilobj )  DisposeObject(hd_inners), hd_inners=nilobj;
	if( tg_inners != nilobj )  DisposeObject(tg_inners), tg_inners=nilobj;
	KillGalley(hd, FALSE);
	*inners = nilobj;
	debug0(DGA, D, "] AttachGalley returning ATTACH_KILLED");
	return ATTACH_KILLED;
      }
      else if( actual(actual(target_index)) == InputSym )
      {
	/* search found input object, so suspend on that */
	DeleteNode(hd_index);
	Link(target_index, hd);
	*inners = nilobj;
	debug0(DGA, D, "] AttachGalley returning ATTACH_INPUT");
	return ATTACH_INPUT;
      }

    }
    else /* unsized galley, either backwards or normal */
    {
      if( foll_or_prec(hd) == GALL_PREC )
      {	target_index= SearchGalley(Up(hd_index), sym, FALSE, TRUE,TRUE,FALSE);
	need_precedes = FALSE;
      }
      else
      {	target_index = SearchGalley(Up(hd_index), sym, FALSE,TRUE,FALSE,FALSE);
	need_precedes = (target_index != nilobj);
	if( target_index == nilobj )
	  target_index = SearchGalley(Up(hd_index), sym, TRUE,TRUE,TRUE,FALSE);
      }

      /* if no luck, exit without error */
      if( target_index == nilobj )
      {	*inners = nilobj;
	debug0(DGA, D, "] AttachGalley returning ATTACH_NOTARGET");
	return ATTACH_NOTARGET;
      }
    }
    assert( type(target_index) == RECEPTIVE, "AttachGalley: target_index!" );
    target = actual(target_index);
    assert( type(target) == CLOSURE, "AttachGalley: target!" );

    /* set target_galley to the expanded value of target */
    debug1(DYY, D, "[ EnterErrorBlock(FALSE) (expanding target %s)",
      SymName(actual(target)));
    EnterErrorBlock(FALSE);
    New(target_galley, HEAD);
    force_gall(target_galley) = FALSE;
    enclose_obj(target_galley) = limiter(target_galley) = nilobj;
    ClearHeaders(target_galley);
    opt_components(target_galley) = opt_constraints(target_galley) = nilobj;
    gall_dir(target_galley) = external_hor(target) ? COLM : ROWM;
    FposCopy(fpos(target_galley), fpos(target));
    actual(target_galley) = actual(target);
    whereto(target_galley) = ready_galls(target_galley) = nilobj;
    foll_or_prec(target_galley) = GALL_FOLL;
    must_expand(target_galley) = FALSE;
    sized(target_galley) = FALSE;

    /* get perpendicular constraint (none if horizontal galley) */
    if( dim == ROWM )
    {
      Constrained(target, &c, 1-dim, &junk);
      if( !constrained(c) )
        Error(19, 2, "receptive symbol %s has unconstrained width",
	  FATAL, &fpos(target), SymName(actual(target)));
      debug2(DSC, DD, "Constrained( %s, 1-dim ) = %s",
	EchoObject(target), EchoConstraint(&c));
      if( !FitsConstraint(0, 0, c) )
      { debug0(DGA, D, "  reject: target_galley horizontal constraint is -1");
	y = nilobj;
        goto REJECT;
      }
    }
    else /* actually unused */
      SetConstraint(c, MAX_FULL_LENGTH, MAX_FULL_LENGTH, MAX_FULL_LENGTH);

    debug1(DGA, DDD, "  expanding %s", EchoObject(target));
    tmp = CopyObject(target, no_fpos);
    Link(target_galley, tmp);
    env = DetachEnv(tmp);
    debug4(DGM, D, "  external_ver(%s) = %s, external_hor(%s) = %s",
      SymName(actual(target)), bool(external_ver(target)),
      SymName(actual(target)), bool(external_hor(target)));
    SizeGalley(target_galley, env,
	external_ver(target) || external_hor(target),
	threaded(target), non_blocking(target_index),
	trigger_externs(target_index), &save_style(target),
	&c, whereto(hd), &dest_index, &recs, &tg_inners,
	enclose_obj(hd) != nilobj ? CopyObject(enclose_obj(hd), no_fpos):nilobj);
    debug1(DGA, DD, "  SizeGalley tg_inners: %s", DebugInnersNames(tg_inners));
    if( recs != nilobj )  ExpandRecursives(recs);
    dest = actual(dest_index);
    if( underline(dest) == UNDER_UNDEF )  underline(dest) = UNDER_OFF;

    /* verify that hd satisfies any horizontal constraint on dest */
    if( dim == ROWM )
    {
      debug1(DGA, DDD, "  checking hor fit of hd in %s",SymName(actual(dest)));
      Constrained(dest, &c, 1-dim, &junk);
      debug3(DSC, DD, "Constrained( %s, %s ) = %s",
	EchoObject(dest), dimen(1-dim), EchoConstraint(&c));
      assert( constrained(c), "AttachGalley: dest unconstrained!" );
      if( !FitsConstraint(0, 0, c) )
      { debug0(DGA, D, "  reject: hd horizontal constraint is -1");
	y = nilobj;
        goto REJECT;
      }
    }

    /* manifest and size the galley if not done yet */
    if( !sized(hd) )
    {
      debug2(DYY, D, "[ EnterErrorBlock(TRUE) (sizing galley %s into %s)",
	SymName(actual(hd)), SymName(whereto(hd)));
      EnterErrorBlock(TRUE);
      n1 = nilobj;
      Child(y, Down(hd));
      env = DetachEnv(y);
      /*** threaded() only defined in ROWM case
      SizeGalley(hd, env, TRUE, threaded(dest), non_blocking(target_index),
	TRUE, &save_style(dest), &c, nilobj, &n1, &recs, &hd_inners);
      *** */
      SizeGalley(hd, env, TRUE, dim == ROWM ? threaded(dest) : FALSE,
	non_blocking(target_index), TRUE, &save_style(dest), &c, nilobj,
	&n1, &recs, &hd_inners, nilobj);
      debug1(DGA,DD,"  SizeGalley hd_inners: %s", DebugInnersNames(hd_inners));
      if( recs != nilobj )  ExpandRecursives(recs);
      if( need_precedes )		/* need an ordering constraint */
      {	OBJECT index1, index2;
        New(index1, PRECEDES);
	New(index2, FOLLOWS);
	blocked(index2) = FALSE;
	tmp = MakeWord(WORD, STR_EMPTY, no_fpos);
	Link(index1, tmp);  Link(index2, tmp);
	Link(Up(hd_index), index1);
	Link(Down(hd), index2);
	debug0(DGA, D, "  inserting PRECEDES and FOLLOWS");
      }
      LeaveErrorBlock(TRUE);
      debug0(DYY, D, "] LeaveErrorBlock(TRUE) (finished sizing galley)");
    }

    if( dim == ROWM )
    { if( !FitsConstraint(back(hd, 1-dim), fwd(hd, 1-dim), c) )
      { debug3(DGA, D, "  reject: hd %s,%s does not fit target_galley %s",
	  EchoLength(back(hd, 1-dim)), EchoLength(fwd(hd, 1-dim)),
	  EchoConstraint(&c));
        Error(19, 3, "too little horizontal space for galley %s at %s",
	  WARN, &fpos(hd), SymName(actual(hd)), SymName(actual(dest)));
        goto REJECT;
      }
    }

    /* check status of first component of hd */
    debug0(DGA, DDD, "  now ready to attach; hd =");
    ifdebug(DGA, DDD, DebugObject(hd));
    for( link = Down(hd);  link != hd;  link = NextDown(link) )
    {
      Child(y, link);
      debug1(DGA, DDD, "  examining %s", EchoIndex(y));
      if( type(y) == SPLIT )  Child(y, DownDim(y, dim));
      switch( type(y) )
      {

	case EXPAND_IND:
	case SCALE_IND:
	case COVER_IND:
	case GALL_PREC:
	case GALL_FOLL:
	case GALL_FOLL_OR_PREC:
	case GALL_TARG:
	case CROSS_PREC:
	case CROSS_FOLL:
	case CROSS_FOLL_OR_PREC:
	case CROSS_TARG:
	case PAGE_LABEL_IND:
	    
	  break;


	case PRECEDES:
	case UNATTACHED:
	    
	  if( was_sized )
	  { /* SizeGalley was not called, so hd_inners was not set by it */
	    if( hd_inners == nilobj )  New(hd_inners, ACAT);
	    Link(hd_inners, y);
	  }
	  break;


	case RECEPTIVE:

	  goto SUSPEND;


	case RECEIVING:
	    
	  goto SUSPEND;


	case FOLLOWS:
	    
	  Child(tmp, Down(y));
	  if( Up(tmp) == LastUp(tmp) )
	  { link = pred(link, CHILD);
	    debug0(DGA, DD, "  disposing FOLLOWS");
	    DisposeChild(NextDown(link));
	    break;
	  }
	  Parent(tmp, Up(tmp));
	  assert(type(tmp) == PRECEDES, "Attach: PRECEDES!");
	  switch( CheckComponentOrder(tmp, target_index) )
	  {
	    case CLEAR:		DeleteNode(tmp);
				link = pred(link, CHILD);
				DisposeChild(NextDown(link));
				break;

	    case PROMOTE:	break;

	    case BLOCK:		debug0(DGA, DD, "CheckContraint: BLOCK");
				goto SUSPEND;

	    case CLOSE:		debug0(DGA, D, "  reject: CheckContraint");
				goto REJECT;
	  }
	  break;


	case GAP_OBJ:

	  underline(y) = underline(dest);
	  if( !join(gap(y)) )  seen_nojoin(hd) = TRUE;
	  break;


	case BEGIN_HEADER:
	case END_HEADER:
	case SET_HEADER:
	case CLEAR_HEADER:

	  /* do nothing until actually promoted out of here */
	  underline(y) = underline(dest);
	  break;


	case CLOSURE:
	case CROSS:
	case FORCE_CROSS:
	case NULL_CLOS:
	case PAGE_LABEL:

	  underline(y) = underline(dest);
	  break;


	case WORD:
	case QWORD:
	case ONE_COL:
	case ONE_ROW:
	case WIDE:
	case HIGH:
	case HSHIFT:
	case VSHIFT:
	case HMIRROR:
	case VMIRROR:
	case HSCALE:
	case VSCALE:
	case HCOVER:
	case VCOVER:
	case HCONTRACT:
	case VCONTRACT:
	case HLIMITED:
	case VLIMITED:
	case HEXPAND:
	case VEXPAND:
	case START_HVSPAN:
	case START_HSPAN:
	case START_VSPAN:
	case HSPAN:
	case VSPAN:
	case ROTATE:
	case BACKGROUND:
	case SCALE:
	case KERN_SHRINK:
	case INCGRAPHIC:
	case SINCGRAPHIC:
	case PLAIN_GRAPHIC:
	case GRAPHIC:
	case LINK_SOURCE:
	case LINK_DEST:
	case LINK_DEST_NULL:
	case LINK_URL:
	case ACAT:
	case HCAT:
	case VCAT:
	case ROW_THR:
	case COL_THR:
	    

	  underline(y) = underline(dest);
	  if( dim == ROWM )
	  {
	    /* make sure y is not joined to a target below (vertical only) */
	    for( zlink = NextDown(link); zlink != hd; zlink = NextDown(zlink) )
	    { Child(z, zlink);
	      switch( type(z) )
	      {
	        case RECEPTIVE:
		
		  if( non_blocking(z) )
		  { zlink = PrevDown(zlink);
		    DeleteNode(z);
		  }
		  else
		  { y = z;
		    goto SUSPEND;
		  }
		  break;


	        case RECEIVING:
		
		  if( non_blocking(z) )
		  { zlink = PrevDown(zlink);
		    while( Down(z) != z )
		    { Child(tmp, Down(y));
		      if( opt_components(tmp) != nilobj )
		      { DisposeObject(opt_components(tmp));
		        opt_components(tmp) = nilobj;
		        debug3(DOG, D, "AttachGalley(%s) de-optimizing %s %s",
			  SymName(actual(hd)), SymName(actual(tmp)), "(join)");
		      }
		      DetachGalley(tmp);
		      KillGalley(tmp, FALSE);
		    }
		    DeleteNode(z);
		  }
		  else
		  { y = z;
		    goto SUSPEND;
		  }
		  break;


	        case GAP_OBJ:
		
		  if( !join(gap(z)) )  zlink = PrevDown(hd);
		  break;


	        default:	break;
	      }
	    }

	    /* if HCAT, try vertical hyphenation (vertical galleys only) */
	    if( type(y) == HCAT )  VerticalHyphenate(y);
	  }


	  /* check availability of parallel space for the first component */
	  why = nilobj;
	  Constrained(dest, &c, dim, &why);
	  debug3(DGF, DD, "  dest parallel Constrained(%s, %s) = %s",
	    EchoObject(dest), dimen(dim), EchoConstraint(&c));
	  if( !FitsConstraint(back(y, dim), fwd(y, dim), c) )
	  { BOOLEAN scaled;

	    /* if forcing galley doesn't fit, try scaling first component */
	    scaled = FALSE;
	    if( force_gall(hd) && size(y, dim) > 0 )
	    { int scale_factor;
	      scale_factor = ScaleToConstraint(back(y,dim), fwd(y,dim), &c);
	      if( scale_factor > 0.5 * SF )
	      {	char num1[20], num2[20];
		sprintf(num1, "%.1fc", (float) size(y, dim) / CM);
		sprintf(num2, "%.1fc", (float) bfc(c) / CM);
		if( dim == ROWM )
		  Error(19, 4, "%s object too high for %s space; %s inserted",
		    WARN, &fpos(y), num1, num2, KW_SCALE);
		else
		  Error(19, 5, "%s object too wide for %s space; %s inserted",
		    WARN, &fpos(y), num1, num2, KW_SCALE);
		y = InterposeScale(y, scale_factor, dim);
		scaled = TRUE;
	      }
	    }

	    /* otherwise we must reject, and warn the user */
	    if( !scaled )
	    { char num1[20], num2[20];
	      debug3(DGA, D, "  reject: vsize %s,%s in %s; y=",
		EchoLength(back(y, dim)), EchoLength(fwd(y, dim)),
		EchoConstraint(&c));
	      ifdebug(DGA, D, DebugObject(y));
	      if( size(y, dim) > 0 )
	      { sprintf(num1, "%.1fc", (float) size(y, dim) / CM);
	        sprintf(num2, "%.1fc", (float) bfc(c) / CM);
	        if( dim == ROWM )
		  Error(19, 12, "%s object too high for %s space; will try elsewhere",
		    WARN, &fpos(y), num1, num2);
	        else
		  Error(19, 13, "%s object too wide for %s space; will try elsewhere",
		    WARN, &fpos(y), num1, num2);
	      }
	      goto REJECT;
	    }

	  }

	  /* check availability of perpendicular space for first component */
	  if( dim == ROWM )
	  { perp_back = back(hd, 1-dim);  perp_fwd = fwd(hd, 1-dim);
	  }
	  else
	  { perp_back = back(y, 1-dim);  perp_fwd = fwd(y, 1-dim);
	  }
	  Constrained(dest, &c, 1-dim, &junk);
	  debug3(DGF, DD, "  dest perpendicular Constrained(%s, %s) = %s",
	    EchoObject(dest), dimen(1-dim), EchoConstraint(&c));
	  if( !FitsConstraint(perp_back, perp_fwd, c) )
	  { BOOLEAN scaled;

	    /* if forcing galley doesn't fit, try scaling first component */
	    scaled = FALSE;
	    if( force_gall(hd) && perp_back + perp_fwd > 0 )
	    { int scale_factor;
	      scale_factor = ScaleToConstraint(perp_back, perp_fwd, &c);
	      if( scale_factor > 0.5 * SF )
	      {	char num1[20], num2[20];
		sprintf(num1, "%.1fc", (float) (perp_back + perp_fwd) / CM);
		sprintf(num2, "%.1fc", (float) bfc(c) / CM);
		if( 1-dim == ROWM )
		  Error(19, 6, "%s object too high for %s space; %s inserted",
		    WARN, &fpos(y), num1, num2, KW_SCALE);
		else
		  Error(19, 7, "%s object too wide for %s space; %s inserted",
		    WARN, &fpos(y), num1, num2, KW_SCALE);
		y = InterposeScale(y, scale_factor, 1-dim);
		scaled = TRUE;
	      }
	    }

	    /* otherwise we must reject, and warn the user */
	    if( !scaled )
	    {
	      debug3(DGA, D, "  reject: vsize %s,%s in %s; y=",
		EchoLength(perp_back), EchoLength(perp_fwd),
		EchoConstraint(&c));
	      ifdebug(DGA, D, DebugObject(y));
	      goto REJECT;
	    }

	  }

	  /* dest seems OK, so perform its size adjustments */
	  debug0(DSA, D, "calling AdjustSize from AttachGalley (a)");
	  AdjustSize(dest, back(y, dim), fwd(y, dim), dim);
	  debug0(DSA, D, "calling AdjustSize from AttachGalley (b)");
	  AdjustSize(dest, perp_back, perp_fwd, 1-dim);


	  /* now check parallel space for target_galley in target */
	  Constrained(target, &c, dim, &why);
	  debug3(DGF, DD, "  target parallel Constrained(%s, %s) = %s",
	    EchoObject(target), dimen(dim), EchoConstraint(&c));
	  Child(z, LastDown(target_galley));  /* works in all cases? */
	  assert( !is_index(type(z)), "AttachGalley: is_index(z)!" );
	  assert( back(z, dim)>=0 && fwd(z, dim)>=0, "AttachGalley: z size!" );
	  if( !FitsConstraint(back(z, dim), fwd(z, dim), c) )
	  { BOOLEAN scaled;

	    debug2(DGA, D, "  why     = %d %s", (int) why, EchoObject(why));
	    debug2(DGA, D, "  limiter = %d %s", (int) limiter(hd),
	      EchoObject(limiter(hd)));

	    /* if forcing galley doesn't fit, try scaling z */
	    scaled = FALSE;
	    if( force_gall(hd) && size(z, dim) > 0 && limiter(hd) != why )
	    { int scale_factor;
	      scale_factor = ScaleToConstraint(back(z,dim), fwd(z,dim), &c);
	      if( scale_factor > 0.5 * SF )
	      {	char num1[20], num2[20];
		sprintf(num1, "%.1fc", (float) size(z, dim) / CM);
		sprintf(num2, "%.1fc", (float) bfc(c) / CM);
		if( dim == ROWM )
		  Error(19, 8, "%s object too high for %s space; %s inserted",
		    WARN, &fpos(y), num1, num2, KW_SCALE);
		else
		  Error(19, 9, "%s object too wide for %s space; %s inserted",
		    WARN, &fpos(y), num1, num2, KW_SCALE);
		z = InterposeWideOrHigh(z, dim);
		z = InterposeScale(z, scale_factor, dim);
		scaled = TRUE;
	      }
	    }

	    if( !scaled )
	    { char num1[20], num2[20];
	      limiter(hd) = why;
	      debug3(DGA, D, "  set limiter(%s) = %d %s", SymName(actual(hd)),
		(int) limiter(hd), EchoObject(limiter(hd)));
	      debug3(DGA, D, "  reject: size was %s,%s in %s; y =",
		EchoLength(back(z, dim)), EchoLength(fwd(z, dim)),
		EchoConstraint(&c));
	      ifdebug(DGA, D, DebugObject(y));
	      if( size(z, dim) > 0 )
	      { sprintf(num1, "%.1fc", (float) size(z, dim) / CM);
	        sprintf(num2, "%.1fc", (float) bfc(c) / CM);
	        if( dim == ROWM )
		  Error(19, 14, "%s object too high for %s space; will try elsewhere",
		    WARN, &fpos(y), num1, num2);
	        else
		  Error(19, 15, "%s object too wide for %s space; will try elsewhere",
		    WARN, &fpos(y), num1, num2);
	      }
	      goto REJECT;
	    }
	  }
	  limiter(hd) = why;
	  debug3(DGA, D, "  set limiter(%s) = %d %s", SymName(actual(hd)),
	    (int) limiter(hd), EchoObject(limiter(hd)));

	  /* now check perpendicular space for target_galley in target */
	  Constrained(target, &c, 1-dim, &junk);
	  debug3(DGF, DD, "  target perpendicular Constrained(%s, %s) = %s",
	    EchoObject(target), dimen(1-dim), EchoConstraint(&c));
	  Child(z, LastDown(target_galley));  /* works in all cases? */
	  assert( !is_index(type(z)), "AttachGalley: is_index(z)!" );
	  assert( back(z, 1-dim)>=0 && fwd(z, 1-dim)>=0,
	    "AttachGalley: z size (perpendicular)!" );
	  if( !FitsConstraint(back(z, 1-dim), fwd(z, 1-dim), c) )
	  { BOOLEAN scaled;

	    /* if forcing galley doesn't fit, try scaling z */
	    scaled = FALSE;
	    if( force_gall(hd) && size(z, 1-dim) > 0 )
	    { int scale_factor;
	      scale_factor = ScaleToConstraint(back(z,1-dim), fwd(z,1-dim), &c);
	      if( scale_factor > 0.5 * SF )
	      {	char num1[20], num2[20];
		sprintf(num1, "%.1fc", (float) size(z, 1-dim) / CM);
		sprintf(num2, "%.1fc", (float) bfc(c) / CM);
		if( 1-dim == ROWM )
		  Error(19, 10, "%s object too high for %s space; %s inserted",
		    WARN, &fpos(y), num1, num2, KW_SCALE);
		else
		  Error(19, 11, "%s object too wide for %s space; %s inserted",
		    WARN, &fpos(y), num1, num2, KW_SCALE);
		z = InterposeWideOrHigh(z, 1-dim);
		z = InterposeScale(z, scale_factor, 1-dim);
		scaled = TRUE;
	      }
	    }

	    if( !scaled )
	    {
	      debug3(DGA, D, "  reject: size was %s,%s in %s; y =",
		EchoLength(back(z, 1-dim)), EchoLength(fwd(z, 1-dim)),
		EchoConstraint(&c));
	      ifdebug(DGA, D, DebugObject(y));
	      goto REJECT;
	    }
	  }

	  /* target seems OK, so adjust sizes and accept */
	  if( external_hor(target) )
	  {
	    /* don't adjust any sizes, none to adjust */
	    debug0(DSA, D, "not calling AdjustSize from AttachGalley (c)");
	  }
	  else if( external_ver(target) )
	  {
	    /* adjust perp size only, to galley size */
	    debug0(DSA, D, "calling AdjustSize from AttachGalley (d)");
	    AdjustSize(target, back(target_galley, 1-dim),
	      fwd(target_galley, 1-dim), 1-dim);
	  }
	  else
	  {
	    /* adjust both directions, using z (last component) */
	    Child(z, LastDown(target_galley));
	    debug0(DSA, D, "AttachGalley AdjustSize using z =");
	    ifdebug(DSA, D, DebugObject(z));
	    debug0(DSA, D, "calling AdjustSize from AttachGalley (e)");
	    AdjustSize(target, back(z, dim), fwd(z, dim), dim);
	    debug0(DSA, D, "calling AdjustSize from AttachGalley (f)");
	    AdjustSize(target, back(z, 1-dim), fwd(z, 1-dim), 1-dim);
	  }

	  goto ACCEPT;


	default:
	    
	  assert1(FALSE, "AttachGalley:", Image(type(y)));
	  break;

      } /* end switch */
    } /* end for */

    /* null galley: promote whole galley without expanding the target */
    debug0(DGA, D, "  null galley");
    if( tg_inners != nilobj )  DisposeObject(tg_inners), tg_inners = nilobj;
    DisposeObject(target_galley);
    LeaveErrorBlock(FALSE);
    debug0(DYY, D, "] LeaveErrorBlock(FALSE) (null galley)");

    /* kill off any null objects within the galley, then transfer it */
    /* don't use Promote() since it does extra unwanted things here  */
    for( link = Down(hd);  link != hd;  link = NextDown(link) )
    { Child(y, link);
      switch( type(y) )
      {

	case GAP_OBJ:
	case CLOSURE:
	case CROSS:
	case FORCE_CROSS:
	case NULL_CLOS:
	case PAGE_LABEL:
	
	  link = PrevDown(link);
	  debug1(DGA, D, "  null galley, disposing %s", Image(type(y)));
	  DisposeChild(NextDown(link));
	  break;

	
	default:
	
	  break;
      }
    }
    TransferLinks(NextDown(hd), hd, Up(target_index));

    /* attach hd temporarily to target_index */
    MoveLink(Up(hd), target_index, PARENT);
    assert( type(hd_index) == UNATTACHED, "AttachGalley: type(hd_index)!" );
    DeleteNode(hd_index);

    /* return; only hd_inners needs to be flushed now */
    *inners = hd_inners;
    debug0(DGA, D, "] AttachGalley returning ATTACH_NULL");
    return ATTACH_NULL;


    REJECT:
	
      /* reject first component */
      /* debug1(DGA, D, "  reject %s", EchoObject(y)); */
      debug0(DGA, D, "  reject first component");
      LeaveErrorBlock(TRUE);
      debug0(DYY, D, "] LeaveErrorBlock(TRUE) (REJECT)");
      if( tg_inners != nilobj )  DisposeObject(tg_inners), tg_inners = nilobj;
      DisposeObject(target_galley);
      if( foll_or_prec(hd) == GALL_PREC && !sized(hd) )
      {
	/* move to just before the failed target */
	MoveLink(Up(hd_index), Up(target_index), PARENT);
      }
      else
      {
	/* move to just after the failed target */
	MoveLink(Up(hd_index), NextDown(Up(target_index)), PARENT);
      }
      continue;


    SUSPEND:
	
      /* suspend at first component */
      debug1(DGA, D, "  suspend %s", EchoIndex(y));
      blocked(y) = TRUE;
      LeaveErrorBlock(FALSE);
      debug0(DYY, D, "] LeaveErrorBlock(FALSE) (SUSPEND)");
      if( tg_inners != nilobj )  DisposeObject(tg_inners), tg_inners = nilobj;
      DisposeObject(target_galley);
      MoveLink(Up(hd_index), Up(target_index), PARENT);
      if( was_sized )
      { /* nothing new to flush if suspending and already sized */
	if( hd_inners != nilobj )  DisposeObject(hd_inners), hd_inners=nilobj;
	*inners = nilobj;
      }
      else
      { /* flush newly discovered inners if not sized before */
	*inners = hd_inners;
      }
      debug0(DGA, D, "] AttachGalley returning ATTACH_SUSPEND");
      *suspend_pt = y;
      return ATTACH_SUSPEND;


    ACCEPT:
	
      /* accept first component; now committed to the attach */
      debug3(DGA, D, "  accept %s %s %s", Image(type(y)), EchoObject(y),
	EchoFilePos(&fpos(y)));
      LeaveErrorBlock(TRUE);
      debug0(DYY, D, "] LeaveErrorBlock(TRUE) (ACCEPT)");

      /* attach hd to dest */
      MoveLink(Up(hd), dest_index, PARENT);
      assert( type(hd_index) == UNATTACHED, "AttachGalley: type(hd_index)!" );
      DeleteNode(hd_index);

      /* move first component of hd into dest */
      /* nb Interpose must be done after all AdjustSize calls */
      if( dim == ROWM && !external_ver(dest) )
	Interpose(dest, VCAT, hd, y);
      else if( dim == COLM && !external_hor(dest) )
      { Interpose(dest, ACAT, y, y);
	Parent(junk, Up(dest));
	assert( type(junk) == ACAT, "AttachGalley: type(junk) != ACAT!" );
	StyleCopy(save_style(junk), save_style(dest));
	adjust_cat(junk) = padjust(save_style(junk));
      }
      debug1(DGS, D, "calling Promote(hd, %s) from AttachGalley/ACCEPT",
	link == hd ? "hd" : "NextDown(link)");
      Promote(hd, link == hd ? hd : NextDown(link), dest_index, TRUE);

      /* move target_galley into target */
      /* nb Interpose must be done after all AdjustSize calls */
      if( !(external_ver(target) || external_hor(target)) )
      {	Child(z, LastDown(target_galley));
	Interpose(target, VCAT, z, z);
      }
      debug0(DGS, D, "calling Promote(target_galley) from AttachGalley/ACCEPT");
      Promote(target_galley, target_galley, target_index, TRUE);
      DeleteNode(target_galley);
      assert(Down(target_index)==target_index, "AttachGalley: target_ind");
      if( blocked(target_index) )  blocked(dest_index) = TRUE;
      DeleteNode(target_index);

      /* return; both tg_inners and hd_inners need to be flushed now;        */
      /* if was_sized, hd_inners contains the inners of the first component; */
      /* otherwise it contains the inners of all components, from SizeGalley */
      if( tg_inners == nilobj ) *inners = hd_inners;
      else if( hd_inners == nilobj ) *inners = tg_inners;
      else
      {	TransferLinks(Down(hd_inners), hd_inners, tg_inners);
	DeleteNode(hd_inners);
	*inners = tg_inners;
      }
      debug0(DGA, D, "] AttachGalley returning ATTACH_ACCEPT");
      ifdebug(DGA, D,
	if( dim == COLM && !external_hor(dest) )
	{ OBJECT z;
	  Parent(z, Up(dest));
	  debug2(DGA, D, "  COLM dest_encl on exit = %s %s",
	    Image(type(z)), EchoObject(z));
	}
      )
      return ATTACH_ACCEPT;

  } /* end for */
Пример #26
0
 bool nolock_nograb_blocked() const
 {
   return nolock_nograb_connected() == false || blocked();
 }
Пример #27
0
bool Generic_map::blocked(Tripoint p)
{
  return blocked(p.x, p.y, p.z);
}
Пример #28
0
bool Generic_map::blocked(Point p)
{
  return blocked(p.x, p.y);
}
Пример #29
0
void obliqueangle_engine::render(level_ptr level, boost::shared_ptr<image_operations> oper)
{
  pos_t iw, ih;
  part_c.get_obliqueangle_limits(iw, ih);
  
  BlockRotation b_r(s, level->get_blocks());
  BlockRotation b_d(s, level->get_data());
  BlockRotation bl_r(s, level->get_blocklight());
  BlockRotation sl_r(s, level->get_skylight());
  BlockRotation hm_r(s, level->get_heightmap());

  pos_t bmt = iw * ih;
  
  boost::scoped_array<bool> blocked(new bool[bmt]);
  memset(blocked.get(), 0x0, sizeof(bool) * bmt);
  
  oper->set_limits(iw + 1, ih);
  
  for (int z = mc::MapZ - 1; z >= 0; z--) {
    for (int x = mc::MapX - 1; x >= 0; x--) {
      bool cave_initial = true;
      bool hell_initial = true;
      bool hell_solid = true;
      
      hm_r.set_xz(x, z);
      b_r.set_xz(x, z);
      b_d.set_xz(x, z);
      bl_r.set_xz(x, z);
      sl_r.set_xz(x, z);
      
      int hmval = hm_r.get8();
      
      if (s.hellmode) {
        for (int y = s.top; y >= s.bottom && hell_solid; y--) { hell_solid = !is_open(b_r.get8(y)); }
      }
      
      for (int y = s.top; y >= s.bottom; y--) {
        int bt = b_r.get8(y);
        
        if (s.cavemode && cave_ignore_block(s, y, bt, b_r, cave_initial)) {
          continue;
        }
        
        if (s.hellmode && !hell_solid && hell_ignore_block(s, y, bt, b_r, hell_initial)) {
          continue;
        }
        
        if (s.excludes[bt]) {
          continue;
        }
        
        point p(x, y, z);
        
        pos_t px, py;
        part_c.project_obliqueangle(p, px, py);
        
        color top, side;
        if (bt == mc::Wool) {
          int md = b_d.get4(y);
          top = mc::WoolColor[md];
          side = mc::WoolColor[md];
        } else if ((bt == mc::Step) || (bt == mc::DoubleStep)) {
          int md = b_d.get4(y);
          top = mc::StepColor[md];
          side = mc::StepColor[md];
        } else {
          top = mc::MaterialColor[bt];
          side = mc::MaterialSideColor[bt];
        }
        
        if (mc::MaterialModes[bt] == mc::Block) {
          int bp = px + iw * py;
          
          if (blocked[bp]) {
            continue;
          }
          
          blocked[bp] = top.is_opaque();
        }
        
        int bl = bl_r.get4(y + 1);
        
        apply_shading(s, bl, sl_r.get4(y + 1), hmval, y, top);
        apply_shading(s, bl, -1, hmval, y, side);
        
        switch(mc::MaterialModes[bt]) {
        case mc::Block:
          oper->add_pixel(px, py, top);
          oper->add_pixel(px + 1, py, top);
          oper->add_pixel(px, py + 1, side);
          
          side.lighten(0x20);
          oper->add_pixel(px + 1, py + 1, side);
          break;
        case mc::HalfBlock:
          oper->add_pixel(px, py + 1, top);
          oper->add_pixel(px + 1, py + 1, top);
          break;
        case mc::TorchBlock:
          oper->add_pixel(px, py, top);

          top.lighten(0x20);
          top.a -= 0xb0;
          oper->add_pixel(px - 1, py, top);
          oper->add_pixel(px + 2, py, top);
          oper->add_pixel(px, py - 1, top);
          oper->add_pixel(px, py + 1, top);
          
          oper->add_pixel(px, py + 1, side);
          break;
        }
      }
    }
  }
}
Пример #30
0
double *lightcurve(int n_layers, int n_points, double *t, double tc, double per, double a, double inc, double ecc, double omega, double a_rs, double rp,double u1, double u2,int brightness_model,double *brightness_params,double *stellar_teffs,double *stellar_fluxes,int nstars, int eclipse,int use_filter, int n_wvls, double **wvl_grid, double *lo_2d, double *la_2d, double **T_2d){
    int n,j;
    double phase,lambda0,phi0;
    double *coords;
    double p_blocked, p_bright,phase_z,phase_dz,phase_dt;
    double star_bright;
    double star_surface_bright;
    double **bb_g;
    double *ypp;
    double **y1_grid;
    double **y2_grid;
    double **y12_grid;



    double r2 = 1.0/rp; //invert planet radius ratio - planets always have radius 1 in this code

    double c = 299792458.0;
    
    int n_bb_seg = 100; // number of blackbody segments in wavelength
    double T_start =0;
    double T_end =10000;
    int n_temps=100; // number of blackbody temperature segments

    double *output = malloc(sizeof(double) * n_points);

    // generate the planet grid

    double **planet = generate_planet(n_layers);

    double *transit_coords = separation_of_centers(tc,tc,per,a,inc,ecc,omega,a_rs,r2);

    double transit_z = transit_coords[3];

    star_bright = 1.0;
    star_surface_bright = star_bright/(M_PI*pow(r2,2));

    // brightness model 1 is the Xi 2016 model, requires a stellar temperature
    if(brightness_model == 1 || brightness_model == 3 || brightness_model == 4 || brightness_model == 6 || brightness_model == 8|| brightness_model == 10|| brightness_model == 11|| brightness_model == 12 || brightness_model == 14){
        double l1 = brightness_params[1];
        double l2 = brightness_params[2];
        double star_T =brightness_params[0];
        double ypval;
        double yppval;

//        star_bright = bb_flux(l1,l2,star_T,n_bb_seg);

        ypp = spline_cubic_set( nstars, stellar_teffs, stellar_fluxes, 0, 0, 0, 0 );
        star_surface_bright = spline_cubic_val( nstars, stellar_teffs, stellar_fluxes, ypp, star_T, &ypval, &yppval);
        free(ypp);


        star_bright = star_surface_bright*M_PI*pow(r2,2);

    // also requires the precomputation of the blackbody interpolation grid
        bb_g = bb_grid(l1, l2, T_start, T_end,n_temps,n_bb_seg,use_filter, n_wvls, wvl_grid);

    }
//    printf("bb_g init 2 %f\n",bb_g[0][1]);
    free(coords);

    int nearest = 0;

    if(brightness_model == 12){
        nearest = brightness_params[5];
        y1_grid = malloc(sizeof(double) * (int) brightness_params[3]); // dynamic `array (size 4) of pointers to int`
        for (int i = 0; i < (int) brightness_params[3]; ++i) {
          y1_grid[i] = malloc(sizeof(double) * (int) brightness_params[4]);
        }
        y2_grid = malloc(sizeof(double) * (int) brightness_params[3]); // dynamic `array (size 4) of pointers to int`
        for (int i = 0; i < (int) brightness_params[3]; ++i) {
          y2_grid[i] = malloc(sizeof(double) * (int) brightness_params[4]);
        }
        y12_grid = malloc(sizeof(double) * (int) brightness_params[3]); // dynamic `array (size 4) of pointers to int`
        for (int i = 0; i < (int) brightness_params[3]; ++i) {
          y12_grid[i] = malloc(sizeof(double) * (int) brightness_params[4]);
        }
        bcugrid(lo_2d, la_2d, T_2d, y1_grid, y2_grid, y12_grid, (int) brightness_params[3],(int) brightness_params[4]);
    }

    if(brightness_model == 13){
        nearest = brightness_params[2];
        y1_grid = malloc(sizeof(double) * (int) brightness_params[0]); // dynamic `array (size 4) of pointers to int`
        for (int i = 0; i < (int) brightness_params[0]; ++i) {
          y1_grid[i] = malloc(sizeof(double) * (int) brightness_params[1]);
        }
        y2_grid = malloc(sizeof(double) * (int) brightness_params[0]); // dynamic `array (size 4) of pointers to int`
        for (int i = 0; i < (int) brightness_params[0]; ++i) {
          y2_grid[i] = malloc(sizeof(double) * (int) brightness_params[1]);
        }
        y12_grid = malloc(sizeof(double) * (int) brightness_params[0]); // dynamic `array (size 4) of pointers to int`
        for (int i = 0; i < (int) brightness_params[0]; ++i) {
          y12_grid[i] = malloc(sizeof(double) * (int) brightness_params[1]);
        }
        bcugrid(lo_2d, la_2d, T_2d, y1_grid, y2_grid, y12_grid, (int) brightness_params[0],(int) brightness_params[1]);
    }


    for (n = 0; n < n_points; n++) {

//        printf("star bright %f\n",star_surface_bright);


        double *old_coords = separation_of_centers(t[n],tc,per,a,inc,ecc,omega,a_rs,r2);

        phase = calc_phase(t[n],tc,per);

        // make correction for finite light travel speed

        phase_z = old_coords[3];
        phase_dz = transit_z-phase_z;
        phase_dt = (phase_dz/c)/(3600.0*24.0);

        double *substellar = calc_substellar(phase,old_coords);

        lambda0 = substellar[0];
        phi0 = substellar[1];

        free(old_coords);
        free(substellar);

        double *coords = separation_of_centers(t[n]-phase_dt,tc,per,a,inc,ecc,omega,a_rs,r2);

        double t_dist = sqrt(pow(coords[0],2) + pow(coords[1],2) + pow(coords[2],2));

        if(t_dist < (r2+1)){
            printf("IMPROPERLY SPECIFIED PARAMETERS, PLANET IS INSIDE STAR! ABORT!\n");
            exit(0);
            return output;
        }

//        printf("bb_g 3 %f\n",bb_g[0][1]);

        map_model(planet,n_layers,lambda0,phi0,u1,u2,brightness_model,brightness_params,bb_g,star_surface_bright,lo_2d,la_2d,T_2d,y1_grid,y2_grid,y12_grid);

        p_bright = 0.0;
        for (j = 0; j < pow(n_layers,2); j++) {
            p_bright = p_bright + planet[j][16]*planet[j][15];
        }

        if(coords[2] < 0 && eclipse == 1){
            p_blocked = blocked(planet,n_layers,coords[0],coords[1],r2);
        }
        else{
            // PRIMARY TRANSIT SHOULD GO IN HERE!
            p_blocked = 0.0;
        }
        output[n] = (star_bright + p_bright - p_blocked)/star_bright;
//        output[n] = p_bright/star_bright;

        free(coords);

    }

    int n_segments = pow(n_layers,2);
    for (int i = 0; i < n_segments; ++i) {
      free(planet[i]);
    }
    free(planet);
    free(coords);
    free(transit_coords);

    if(brightness_model == 1 || brightness_model == 3 || brightness_model == 4 || brightness_model == 6 || brightness_model == 8|| brightness_model == 10 || brightness_model == 11|| brightness_model == 12 || brightness_model == 14){
        for (int j = 0; j < 4; ++j) {
          free(bb_g[j]);
        }
        free(bb_g);
    }

    if(brightness_model == 12){
        for (int i = 0; i < (int) brightness_params[3]; ++i) {
          free(y1_grid[i]);
          free(y2_grid[i]);
          free(y12_grid[i]);
          // each i-th pointer is now pointing to dynamic array (size 10) of actual int values
        }
        free(y1_grid);
        free(y2_grid);
        free(y12_grid);
    }

    if(brightness_model == 13){
        for (int i = 0; i < (int) brightness_params[0]; ++i) {
          free(y1_grid[i]);
          free(y2_grid[i]);
          free(y12_grid[i]);
          // each i-th pointer is now pointing to dynamic array (size 10) of actual int values
        }
        free(y1_grid);
        free(y2_grid);
        free(y12_grid);
    }

    return output;
}