示例#1
0
static int
mergestates(int v)
{	State *a, *b;
	int m, cnt=0;

	if (tl_verbose)
		return 0;

	do {
		m = 0; cnt++;
		for (a = never; a; a = a->nxt)
		{	if (v && !a->reachable) continue;

			if (a->redundant) continue; /* 3.3.10 */

			for (b = a->nxt; b; b = b->nxt)
			{	if (v && !b->reachable) continue;

				if (b->redundant) continue; /* 3.3.10 */

				if (all_trans_match(a, b))
				{	m++;
					if (tl_verbose)
					{	printf("%d: state %s equals state %s\n",
						cnt, a->name->name, b->name->name);
						showtrans(a);
						printf("==\n");
						showtrans(b);
					}
					retarget(a->name->name, b->name->name);
					if (!strncmp(a->name->name, "accept", 6)
					&&  Max_Red == 0)
					{	char buf[64];
						sprintf(buf, "T0%s", &(a->name->name[6]));
						retarget(buf, b->name->name);
					}
					break;
				}
#if 0
				else if (tl_verbose)
				{	printf("\n%d: state %s differs from state %s [%d,%d]\n",
						cnt, a->name->name, b->name->name,
						a->accepting, b->accepting);
					showtrans(a);
					printf("==\n");
					showtrans(b);
					printf("\n");
				}
#endif
		}	}
	} while (m && cnt < 10);
	return cnt-1;
}
示例#2
0
static int
buckyballs(void)
{	State *a, *b, *c, *d;
	int m, cnt=0;

	do {
		m = 0; cnt++;
		for (a = never; a; a = a->nxt)
		{	if (!a->reachable) continue;

			if (a->redundant) continue;

			for (b = a->nxt; b; b = b->nxt)
			{	if (!b->reachable) continue;

				if (b->redundant) continue;

				if (all_bucky(a, b))
				{	m++;
					if (tl_verbose)
					{	printf("%s bucky match %s\n",
						a->name->name, b->name->name);
					}

					if (a->accepting && !b->accepting)
					{	if (strcmp(b->name->name, "T0_init") == 0)
						{	c = a; d = b;
							b->accepting = 1;
						} else
						{	c = b; d = a;
						}
					} else
					{	c = a; d = b;
					}

					retarget(c->name->name, d->name->name);
					if (!strncmp(c->name->name, "accept", 6)
					&&  Max_Red == 0)
					{	char buf[64];
						sprintf(buf, "T0%s", &(c->name->name[6]));
						retarget(buf, d->name->name);
					}
					break;
				}
		}	}
	} while (m && cnt < 10);
	return cnt-1;
}
示例#3
0
int main(void) {
	for (int i=0; i<3; i++) {
		set_output(DDRB, led[i]);
	}

	uint8_t tick = 0;
	while(1) {
		for (int i=0; i<3; i++) {
			if (tick < current[i]) {
				output_high(PORTB, led[i]);
			} else {
				output_low(PORTB, led[i]);
			}
		}
		tick = (tick+1)%256;
		if (tick == 0) {
			if (reached()) {
				retarget();
			} else {
				approach();
			}
		}
	}
	return 0;
}
示例#4
0
void Monster::updateRetargeting(Duration elapsedTime) {
	assert(elapsedTime >= Duration::zero());

	if (_retargetDelay <= Duration::zero()) {
		return;
	}

	if (attackedCreature == nullptr) {
		return;
	}

	if (hasMaster()) {
		return;
	}

	if (elapsedTime >= _retargetDelay) {
		_retargetDelay = _type->retargetInterval;

		if (_type->retargetChance < random_range(1, 100)) {
			return;
		}

		retarget();
	}
	else {
		_retargetDelay -= elapsedTime;
	}
}
示例#5
0
//------------------------------------------------------------------------------
//!
RCP<SkeletalAnimation>
Puppeteer::retarget(
   SkeletalAnimation* srcAnim,
   Skeleton*          dstSkel
)
{
   return retarget( srcAnim->skeleton(), dstSkel, srcAnim, false );
}
示例#6
0
void Monster::updateTarget() {
	if (hasMaster()) {
		target(_master->getAttackedCreature());
	}
	else {
		CreatureP attackedCreature = this->attackedCreature;
		if (attackedCreature == nullptr || !canAttack(*attackedCreature)) {
			retarget();
		}
		else {
			// retarget if target is out of sight + we cannot walk there
			auto& game = server.game();
			if (!game.isSightClear(getPosition(), attackedCreature->getPosition(), true)) {
				FindPathParams parameters;
				getPathSearchParams(attackedCreature.get(), parameters);

				DirectionRoute route;
				if (!server.game().getPathToEx(this, attackedCreature->getPosition(), route, parameters)) {
					retarget();
				}
			}
		}
	}
}
示例#7
0
文件: GCEdge.hpp 项目: edzer/cxxr
	GCEdge<T>& operator=(T* newtarget)
	{
	    retarget(newtarget);
	    return *this;
	}
示例#8
0
文件: GCEdge.hpp 项目: edzer/cxxr
	GCEdge<T>& operator=(const GCEdge<T>& source)
	{
	    retarget(source);
	    return *this;
	}
示例#9
0
void
Splot_EnemyFleet::drawGL ()
{
  glColor4f (1.0, 1.0, 1.0, 1.0);

  State_t& state = SPLOT_STATE_SINGLETON::instance ()->get ();
  int num = 0;
  float szx;
  Splot_EnemyAircraft* current = inherited::free_list_;
  while (current)
  {
    num++;

    glBindTexture (GL_TEXTURE_2D, shipTex_[(int)current->type_]);
    glColor4f (1.0, 1.0, 1.0, 1.0);
    glPushMatrix();
    glTranslatef (current->position_[0],
                  current->position_[1],
                  current->position_[2]);
    glBegin (GL_TRIANGLE_STRIP);
    glTexCoord2f (1.0, 0.0); glVertex3f ( current->size_[0],  current->size_[1], 0.0);
    glTexCoord2f (0.0, 0.0); glVertex3f (-current->size_[0],  current->size_[1], 0.0);
    glTexCoord2f (1.0, 1.0); glVertex3f ( current->size_[0], -current->size_[1], 0.0);
    glTexCoord2f (0.0, 1.0); glVertex3f (-current->size_[0], -current->size_[1], 0.0);
    glEnd ();
    glPopMatrix ();
  
    switch (current->type_)
    {
      case ENEMYAIRCRAFT_STRAIGHT:
        if (current->preFire_)
        {
          glBlendFunc (GL_SRC_ALPHA, GL_ONE);
          glBindTexture (GL_TEXTURE_2D, extraTex_[ENEMYAIRCRAFT_STRAIGHT]);
          glColor4f (1.0, 1.0, 1.0, current->preFire_);
          szx = 0.55F*current->preFire_;
          glPushMatrix ();
          glTranslatef (current->position_[0],
                        current->position_[1]-0.9F,
                        current->position_[2]);
          glRotatef ((float)IRAND, 0.0, 0.0, 1.0);
          drawQuad (szx, szx+0.1F);
          glPopMatrix ();
          glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
          glColor4f (1.0, 1.0, 1.0, 1.0);
        } // end IF
        if (!((current->age_-192)%256))
          retarget (ENEMYAIRCRAFT_GNAT, state.player);
        break;
      case ENEMYAIRCRAFT_OMNI:
        glColor4f (1.0, 0.0, 0.0, 1.0);
        glBindTexture (GL_TEXTURE_2D, extraTex_[ENEMYAIRCRAFT_OMNI]);
        glPushMatrix ();
        glTranslatef (current->position_[0],
                      current->position_[1],
                      current->position_[2]);
        glRotatef ((float)-(current->age_*8), 0.0F, 0.0F, 1.0F);
        drawQuad (current->size_[0], current->size_[1]);
        glPopMatrix ();
        glColor4f (1.0F, 1.0F, 1.0F, 1.0F);
        break;
      case ENEMYAIRCRAFT_RAYGUN:
        break;
      case ENEMYAIRCRAFT_TANK:
        if (current->preFire_)
        {
          glBlendFunc (GL_SRC_ALPHA, GL_ONE);
          glBindTexture (GL_TEXTURE_2D, extraTex_[ENEMYAIRCRAFT_TANK]);
          glColor4f (1.0F, 1.0F, 1.0F, current->preFire_);
          glPushMatrix ();
          glTranslatef (current->position_[0],
                        current->position_[1]-0.63F,
                        current->position_[2]); //NOTE: offset is ~szy*0.3
          glRotatef ((float)IRAND, 0.0, 0.0, 1.0);
          szx = 0.4F+0.6F*current->preFire_;
          drawQuad (szx, szx);
          glPopMatrix ();
          glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
          glColor4f (1.0, 1.0, 1.0, 1.0);
        } // end IF
        break;
      case ENEMYAIRCRAFT_GNAT:
        break;
      case ENEMYAIRCRAFT_BOSS_0:
        if (current->preFire_)
        {
          glBlendFunc (GL_SRC_ALPHA, GL_ONE);
          glBindTexture (GL_TEXTURE_2D, extraTex_[ENEMYAIRCRAFT_BOSS_0]);
          glColor4f (1.0F, 1.0F, 1.0F, current->preFire_);
          szx = 0.4F+0.6F*current->preFire_;
          glPushMatrix ();
          glTranslatef (current->position_[0]+1.1F,
                        current->position_[1]-0.4F,
                        current->position_[2]);
          glRotatef ((float)IRAND, 0.0, 0.0, 1.0);
          drawQuad (szx, szx);
          glPopMatrix ();
          glPushMatrix ();
          glTranslatef (current->position_[0]-1.1F,
                        current->position_[1]-0.4F,
                        current->position_[2]);
          glRotatef ((float)IRAND, 0.0, 0.0, 1.0);
          drawQuad (szx, szx);
          glPopMatrix ();
          glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
          glColor4f (1.0, 1.0, 1.0, 1.0);
        } // end IF
        break;
      case ENEMYAIRCRAFT_BOSS_1:
        if (current->preFire_)
        {
          glBlendFunc (GL_SRC_ALPHA, GL_ONE);
          glBindTexture (GL_TEXTURE_2D, extraTex_[ENEMYAIRCRAFT_BOSS_1]);
          glColor4f (1.0F, 1.0F, 1.0F, current->preFire_);
          szx = 0.9F*current->preFire_;
          if (current->shootSwap_)
          {
            glPushMatrix ();
            glTranslatef (current->position_[0]-1.22F,
                          current->position_[1]-1.22F,
                          current->position_[2]);
            glRotatef ((float)IRAND, 0.0, 0.0, 1.0);
            drawQuad (szx, szx);
            drawQuad (szx+0.2F, szx+0.2F);
            glPopMatrix ();
          } // end IF
          else
          {
            glPushMatrix ();
            glTranslatef (current->position_[0]+0.55F,
                          current->position_[1]-1.7F,
                          current->position_[2]);
            glRotatef ((float)IRAND, 0.0, 0.0, 1.0);
            drawQuad (szx, szx);
            drawQuad (szx+0.3F, szx+0.3F);
            glPopMatrix ();
          } // end ELSE
          glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
          glColor4f (1.0, 1.0, 1.0, 1.0);
        } // end IF
        if (!((current->age_-272)%256))
          retarget(ENEMYAIRCRAFT_GNAT, state.player);
        break;
      default:
        ACE_DEBUG ((LM_ERROR,
                    ACE_TEXT ("invalid/unknown enemy aircraft type (was: %d), continuing\n"),
                    current->type_));
        break;
    } // end SWITCH
    current = current->get_next ();
  } // end WHILE

//  const Configuration_t& configuration =
//    SPLOT_CONFIGURATION_SINGLETON::instance ()->get ();
//  if (configuration.debug && num)
//    ACE_DEBUG ((LM_DEBUG,
//                ACE_TEXT ("# enemies on screen: %d\n"),
//                num));
}
示例#10
0
static int udp_send(struct socket *sock, const char *message, int len,
		    int flags, const struct sockaddr *dest_addr, int dest_len)
{
    struct udp_data *udp_data= (struct udp_data *)sock->data;
    IO_Rec txrecs[3];
    struct sockaddr_in *laddr= (struct sockaddr_in *)&(sock->laddr);
    struct sockaddr_in *raddr= (struct sockaddr_in *)&(sock->raddr);
    int i;
    uint32_t nrecs;
    pktcx_t *pktcx;

    TRC(eprintf("udp_send: entered\n"));

    MU_LOCK(&sock->lock);

    if(sock->state != SS_CONNECTED) /* stack needs building */
    {
	if (dest_addr)
	{
	    *raddr = *(struct sockaddr_in *)dest_addr;
	}
	else
	{
	    MU_RELEASE(&sock->lock);
	    return -1; /* ENOTCONN or summit */
	}

	TRC(eprintf("udp_send: building stack\n"));
	build_stack(udp_data, laddr, NULL);
	sock->state = SS_CONNECTED;

	/* now target it */
	TRC(eprintf("udp_send: retargeting to %I:%d\n",
		    raddr->sin_addr, raddr->sin_port));
	if(!retarget(udp_data, laddr, raddr)) {
	    TRC(eprintf("...retarget failed\n"));
	    /* ARP failed */
	    MU_RELEASE(&sock->lock);
	    return -1; /* EHOSTDOWN or sim */
	}
    }
    else
    {
	struct sockaddr_in *daddr = (struct sockaddr_in *)dest_addr;

	TRC(eprintf("udp_send: stack already built\n"));
	if (daddr->sin_addr.s_addr == raddr->sin_addr.s_addr
	    && daddr->sin_port == raddr->sin_port)
	{
	    TRC(eprintf("... and targeted correctly\n"));
	}
	else
	{
	    TRC(eprintf("... but incorrectly targeted; retargeting\n"));
	    /* retarget stack for this destination */
	    if(!retarget(udp_data, laddr, daddr)) {
		/* ARP failed */
		MU_RELEASE(&sock->lock);
		return -1; /* EHOSTDOWN or sim */
	    }
	    *raddr = *daddr;
	    TRC(eprintf("udp_send: retargeted stack\n"));
	}
    }

    /* done with global state, now need the acquire the receive resource
     * lock */
    MU_RELEASE(&sock->lock);
    MU_LOCK(&sock->txlock);

    /* organise mem for headers */
    txrecs[0].len  = udp_data->head;
    txrecs[0].base = udp_data->txbuf;

    /* 
    ** XXX SMH: for the moment, we must copy the data to be transmitted
    ** onto a heap which is readable by the driver domain. This is not, 
    ** however, the most efficient way one can imagine doing transmit.
    ** Some alternatives that should be investigated are:
       a) make the driver enter kernel mode s.t. it can read the data.
          This is essentially what used to happen before coz drivers
	  ran in kernel mode the entire time. 
       b) map the clients data readable to the driver domain on the fly.
          This would require some way of getting hold of the stretch
	  containing the message buffer, and might be a very bad idea
	  indeed coz lots of other stuff would be mapped too.
       c) force clients to give us data which is readable by the driver
          pdom. This is trickier than it sounds since in general clients
	  won't know the pdom of the driver for the interface upon which
	  their message will eventually be transmitted. Though we could
	  arrange for all network drivers to be in the same pdom (!?!).
    ** Even apart from those considerations, this temporary solution should
    ** be modified s.t. the mallocing is done out of band, or not at all
    ** [i.e. perhaps have a stretch, not a heap, and then can just memcpy
    **  to the start of this. requires some locking though ;-]
    */
    txrecs[1].len  = len;
    if(!(txrecs[1].base = Heap$Malloc(udp_data->txheap, len))) {
	eprintf("udp_send: failed to malloc txrec buf!\n"); 
	MU_RELEASE(&sock->txlock); 
	return -1;   /* error */
    }
    memcpy((char *)txrecs[1].base, message, len);

    if(!(pktcx = Heap$Calloc(udp_data->txheap, sizeof(pktcx_t), 1))) {
	eprintf("udp_send: failed to malloc packet context!\n"); 
	Heap$Free(udp_data->txheap, txrecs[1].base);
	MU_RELEASE(&sock->txlock); 
	return -1;   /* error */
    }

    pktcx->ri_nrecs = 2;
    for(i=0; i<2; i++)
	pktcx->ri_recs[i] = txrecs[i];

    TRC(eprintf("udp_send: About to IO$PutPkt...\n"));


    if (!IO$PutPkt(udp_data->txio, 2, txrecs, (word_t)pktcx, FOREVER))
    {
	txrecs[1].len = -1;  /* error */
	goto out;
    }

    /* pick up the tx buffer from the driver */
    do {
	IO$GetPkt(udp_data->txio, 2, txrecs, NOW() + SECONDS(10),
		  &nrecs, (word_t*)&pktcx);
	if (nrecs == 0) {
	    printf("udp_send: timeout recovering tx buffers\n");
	} else {
	    if (nrecs != 2)
	    {
		printf("udp_send: didn't recover enough tx buffers (%d!=3)\n",
		       nrecs);
	    }
	}
    } while(nrecs != 2);
    if (!pktcx)
	printf("udp_send: didn't get packet context back?\n");
    if (pktcx && pktcx->error)
	printf("udp_send: error %d sending\n", pktcx->error);

out:
    Heap$Free(udp_data->txheap, txrecs[1].base);
    Heap$Free(udp_data->txheap, pktcx);

    MU_RELEASE(&sock->txlock);

    return txrecs[1].len;
}
示例#11
0
文件: DAP42.c 项目: edwardcwang/dap42
int main(void) {
    if (DFU_AVAILABLE) {
        DFU_maybe_jump_to_bootloader();
    }

    clock_setup();
    tick_setup(1000);
    gpio_setup();
    led_num(0);

    if (CDC_AVAILABLE) {
        console_setup(DEFAULT_BAUDRATE);
    }

    if (SEMIHOSTING) {
        initialise_monitor_handles();
    }
    else if (VCDC_AVAILABLE) {
        retarget(STDOUT_FILENO, VIRTUAL_USART);
        retarget(STDERR_FILENO, VIRTUAL_USART);
    } else if (CDC_AVAILABLE) {
        retarget(STDOUT_FILENO, CONSOLE_USART);
        retarget(STDERR_FILENO, CONSOLE_USART);
    }
    
    led_num(1);

    {
        char serial[USB_SERIAL_NUM_LENGTH+1];
        desig_get_unique_id_as_string(serial, USB_SERIAL_NUM_LENGTH+1);
        cmp_set_usb_serial_number(serial);
    }

    usbd_device* usbd_dev = cmp_usb_setup();
    DAP_app_setup(usbd_dev, &on_dfu_request);

    if (CDC_AVAILABLE) {
        cdc_uart_app_setup(usbd_dev, &on_usb_activity, &on_usb_activity);
    }

    if (VCDC_AVAILABLE) {
        vcdc_app_setup(usbd_dev, &on_usb_activity, &on_usb_activity);
    }

    if (DFU_AVAILABLE) {
        dfu_setup(usbd_dev, &on_dfu_request);
    }

    tick_start();

    /* Enable the watchdog to enable DFU recovery from bad firmware images */
    iwdg_set_period_ms(1000);
    iwdg_start();

    while (1) {
        iwdg_reset();
        usbd_poll(usbd_dev);

        if (CDC_AVAILABLE) {
            cdc_uart_app_update();
        }

        if (VCDC_AVAILABLE) {
            vcdc_app_update();
        }

        // Handle DAP
        bool dap_active = DAP_app_update();
        if (dap_active) {
            usb_timer = 1000;
        } else if (do_reset_to_dfu && DFU_AVAILABLE) {
            /* Blink 3 times to indicate reset */
            int x;
            for (x=0; x < 3; x++) {
                iwdg_reset();
                led_num(7);
                wait_ms(150);
                led_num(0);
                wait_ms(150);
                iwdg_reset();
            }

            DFU_reset_and_jump_to_bootloader();
        }

        if (usb_timer > 0) {
            usb_timer--;
            LED_ACTIVITY_OUT(1);
        } else {
            LED_ACTIVITY_OUT(0);
        }
    }

    return 0;
}