Пример #1
0
void MapModel::refresh(float dt){
	//@debug modify label.
		{
			char buffer[70];
			sprintf(buffer, "str = %d,\nmag = %d,\n food = %d", PlayerManager::getInstance()->getCurPlayer()->getLstr(), PlayerManager::getInstance()->getCurPlayer()->getGmag(), PlayerManager::getInstance()->getCurPlayer()->getFood());
			//getlblResourcePos()->setString(buffer);
		}
	//@debug modify label.
		{
			char buffer[70];
			sprintf(buffer, "player uid= atk:%s def:%s cur:%s", PlayerManager::getInstance()->getAtkPlayer()->getUID().c_str(), PlayerManager::getInstance()->getDefPlayer()->getUID().c_str(), PlayerManager::getInstance()->getCurPlayer()->getUID().c_str());
			//getlblPlayerPos()->setString(buffer);
		}

	if (_selSprite){
		if (_selGroups->getPositionX() < BORDER_PIXEL)
			slide(Vec2(SLIDE_RATE, 0));
		if (_selGroups->getPositionX() >= _mapContent.width - BORDER_PIXEL)
			slide(Vec2(-SLIDE_RATE, 0));
		if (_selGroups->getPositionY() < BORDER_PIXEL)
			slide(Vec2(0, SLIDE_RATE));
		if (_selGroups->getPositionY() >= _mapContent.height - BORDER_PIXEL)
			slide(Vec2(0, -SLIDE_RATE));
	}

	for (int i = 0; i < SZ(_movableSprites); i++){
		auto troop = _movableSprites.at(i);
		if (PlayerManager::getInstance()->getCurPlayer()->canAddTroop(i + 1))
			troop->setOpacity(255);
		else
			troop->setOpacity(20);
	}
}
Пример #2
0
/**
 * If tile borders empty space, moves tile and returns true, else
 * returns false.
 */
bool move(int tile)
{
    // linear search for tile, record row & col position
    // if tile is not found, return false (with -1 as flag)
    int tile_row = -1;
    int tile_col = -1;
    for (int i = 0; i < d; i++)
    {
        for (int j = 0; j < d; j++)
        {
            if (board[i][j] == tile)
            {
                tile_row = i;
                tile_col = j;
            }
        }
    }
    if (tile_row == -1 || tile_col == -1)
    {
        return false;
    }

    /* The logic in this next part may be a bit dense, but
     * it works on the comparison of the four variables:
     * the row and col of the blank tile, and the row and
     * col of the user's tile.
     *
     * If one dimention is the same, and the other dimention
     * is off by one, then the tiles are adjacent. Otherwise,
     * they are not adjacent.
     */

    // checks if either the row or the col is the same
    if (tile_row == blank_row || tile_col == blank_col)
    {
        // this will evaluate to false if the tiles are in the same row
        if (tile_row == (blank_row - 1) || tile_row == (blank_row + 1))
        {
            // if tile is in the same col and one-off row from blank
            slide(tile, tile_row, tile_col);
            return true;
        }
        // this will evalute to false if the tiles are in the same col
        else if (tile_col == (blank_col - 1) || tile_col == (blank_col + 1))
        {
            // if tile is in the same row and one-off col from blank
            slide(tile, tile_row, tile_col);
            return true;
        }
    }
    // if the tile is not in the same row or the same col
    return false;
}
Пример #3
0
void Pony48Engine::move(direction dir)
{
	m_fLastMovedSec = getSeconds();
	m_bHasBoredVox = false;
	clearBoardAnimations();	//Wipe out any movement animations that are still playing
	bool moved = false;
	while(slide(dir))	//Slide as far as we can
		moved = true;
	moved = join(dir) || moved;	//Join once
	while(slide(dir))	//Slide again!
		moved = true;
	if(moved)
		placenew();	//Create a new tile if we've successfully moved
}
Пример #4
0
void MapModel::tryTouchMoved(){
	Point translation = _touchLocation - _oldTouchLocation;

	if (_prevCursurOutside){
		_selGroups->setPosition(_touchLocation);
		_prevCursurOutside = false;
	}

	if (_selSprite){
		_selGroups->setPosition(_selGroups->getPosition() + translation);

		//@debug modify label.
		char buffer[30];
		sprintf(buffer, "x:%.1f, y:%.1f", _touchLocationInGameLayer.x, _touchLocationInGameLayer.y);
		//getlblCursorPos()->setString(buffer);

		int isBuildableLevel = canBuildOnTilePosition(_touchLocationInGameLayer);
		if (~isBuildableLevel)
			_selSprite->setOpacity(200);
		else
			_selSprite->setOpacity(50);
	}
	else{
		slide(translation);
	}
}
Пример #5
0
void Character::update(InputManager& inputManager, b2World* world) {

#ifdef __WIN32__
	if (inputManager.isKeyPressed(SDLK_UP)) {
		jump();
	}

	if (inputManager.isKeyPressed(SDLK_DOWN)) {
		slide();
	}

	if (inputManager.isKeyReleased(SDLK_UP)) {
		fall();
	}

	if (inputManager.isKeyReleased(SDLK_DOWN)) {
		stopSlide();
	}

#endif

#ifdef __ANDROID__
	if (inputManager.isKeyPressed(SDL_FINGERDOWN)) {
		jump();
}
#endif
}
Пример #6
0
void Camera :: zoom(double value)
{
	distance += value;
	if( distance <= 0.0 ) {
		distance = 0.001;
	}
	slide(0.0, 0.0, value);
}
Пример #7
0
    bool get(HFONT hFont, Item &item)
    {
	int n = find(hFont);
	if (n < 0)
	    return false;
	item = mItems[n];
	slide(n);
	return true;
    }
 double next(int val) {
     // window already max size, slide
     if (maxWindowSize == window.size()) {
         slide(val);
     } else {
         growWindowRight(val);
     }
     return currentWindowAverage;
 }
Пример #9
0
void AddressBarWidget::initialize()
	{	
	// Connecting necessary Signals to Slots
	connect(iSlidingTimer, SIGNAL(timeout()), this, SLOT(slideTick()));
	connect(ui.SlidePushButton, SIGNAL(clicked()), this, SLOT(propagateSlideClicked()));
	connect(ui.SlidePushButton, SIGNAL(clicked()), this, SLOT(slide()));
	// Connecting internal Signals with external ones
	connect(ui.GoStopPushButton, SIGNAL(clicked()), this, SIGNAL(goClicked()));
	connect(ui.ReloadPushButton, SIGNAL(clicked()), this, SIGNAL(reloadClicked()));
	}
Пример #10
0
    bool setNumSlides(size_t numSlides)
    {
        bool result = false;

        // only need to apply (numSlides % num-gpus-y) slides
        for (size_t i = 0; i < (numSlides % dims[1]); ++i)
            result = slide();

        return result;
    }
Пример #11
0
void	resetAll(){		//Stops all motors and resets all sensors
	drive(0);
	intake(0,0);
	arm(0,0);
	slide(0,0);
	wait1Msec(400);
	clearDriveEncoders();
	clearSlideEncoder();
	SensorValue[in6] = 0;
}
Пример #12
0
    void put(const Item& item)
    {
	int n = find(item.hFont);
	if (n < 0)
	    n = mSize - 1;
	if (mItems[n].pTextFormat != item.pTextFormat)
	{
	    SafeRelease(&mItems[n].pTextFormat);
	    item.pTextFormat->AddRef();
	}
	mItems[n] = item;
	slide(n);
    }
Пример #13
0
/* main loop */
int
main(void)
{
	input_line = (char *)malloc(6 * sizeof(char));

	led_setperm();

	set_time = 200000;

	while (strncmp(input_line, "quit", 4) != 0)
	{
		input_line = readline("Led Control> ");

		/* I know instruction parsing is really lame :/ */
		if (!strncmp(input_line, "help", 4))
			help();
		if (!strncmp(input_line, "ledon", 5))
			ledon();
		if (!strncmp(input_line, "ledoff", 6))
			ledoff();
		if (!strncmp(input_line, "settime", 7))
			settime();
		if (!strncmp(input_line, "volume", 6))
			volume();
		if (!strncmp(input_line, "bin", 3))
			bin();
		if (!strncmp(input_line, "slide", 5))
			slide();
		if (!strncmp(input_line, "blink", 5))
			blink();
		if (!strncmp(input_line, "bislide", 7))
			bislide();
		if (!strncmp(input_line, "biblink", 7))
			biblink();
		if (!strncmp(input_line, "grow", 4))
			grow();
		if (!strncmp(input_line, "center", 6))
			center();
		if (!strncmp(input_line, "side", 4))
			side();
		if (!strncmp(input_line, "biside", 6))
			biside();
		if (!strncmp(input_line, "demo", 4))
			demo();
	}

	led_off_all();

	exit(0);
}
Пример #14
0
void
unicorn::SlidingStackedWidget::animationDoneSlot(void)
{
    setCurrentIndex( m_next );
    widget(m_now)->hide();
    widget(m_now)->move(m_pnow);
    m_active = false;

    // animate again if they changed index while we were animating
    if ( m_index != currentIndex() )
        slide( m_index );
    else
        emit animationFinished();
}
Пример #15
0
void AddressBarWidget::setLoadingStarted()
	{
	if ( !isFullyVisible() )
		{
		// Slide down if it's not already visible
		slide();
		}
	ui.BusyLoadingChaseWidget->setAnimated(true);
	ui.BusyLoadingChaseWidget->show();
	ui.LoadingProgressBar->show();
	
	// Set to show the "Stop" Icon
	setStopIcon();
	}
btVector3 slideOnCollision( const btVector3& fromPosition, const btVector3& toPosition, const btVector3& hitNormal )
{
    btVector3 moveDirection = toPosition - fromPosition;
    btScalar moveLength = moveDirection.length();

    if( moveLength <= btScalar( SIMD_EPSILON ) )
        return toPosition;

    moveDirection.normalize();

    btVector3 reflectDir = reflect( moveDirection, hitNormal );
    reflectDir.normalize();

    return fromPosition + slide( reflectDir, hitNormal ) * moveLength;
}
Пример #17
0
void NavigationBarWidget::initialize()
	{
	// Connecting necessary Signals to Slots
	connect(iSlidingTimer, SIGNAL(timeout()), this, SLOT(slideTick()));
	connect(ui.SlidePushButton, SIGNAL(clicked()), this, SLOT(propagateSlideClicked()));
	connect(ui.SlidePushButton, SIGNAL(clicked()), this, SLOT(slide()));
	// Attaching Signals and Slots for Zooming
	connect(ui.ZoomInPushButton, SIGNAL(clicked()), this, SLOT(zoomIn()));
	connect(ui.ZoomOutPushButton, SIGNAL(clicked()), this, SLOT(zoomOut()));
	// Connecting internal Signals with external ones, for encapsulation
	connect(ui.BackPushButton, SIGNAL(clicked()), this, SIGNAL(backClicked()));
	connect(ui.ForwardPushButton, SIGNAL(clicked()), this, SIGNAL(forwardClicked()));
	connect(ui.HomePushButton, SIGNAL(clicked()), this, SIGNAL(homeClicked()));
	connect(ui.ZoomSlider, SIGNAL(valueChanged(int)), this, SIGNAL(zoomLevelChanged(int)));
	}
JSBool facSlider(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
  int32_t val=4;
      diaElemSlider slide(&val,"foo", 0,10);
      
      diaElem *elems[]={&slide   };
  if(diaFactoryRun("Test Slider",1,elems))
  {
    *rval = BOOLEAN_TO_JSVAL(1);
    
  }else
    *rval = BOOLEAN_TO_JSVAL(0);
  
  return JS_TRUE;
}
Пример #19
0
static void *Symbol(const mach_header_xx *mach, const char *name) {
    const struct symtab_command *stp(NULL);
    forlc (command, mach, LC_SYMTAB, struct symtab_command)
        stp = command;
    if (stp == NULL)
        return NULL;

    size_t slide(_not(size_t));
    const nlist_xx *symbols(NULL);
    const char *strings(NULL);

    forlc (segment, mach, LC_SEGMENT_XX, segment_command_xx) {
        if (segment->fileoff == 0)
            slide = reinterpret_cast<size_t>(mach) - segment->vmaddr;
        if (stp->symoff >= segment->fileoff && stp->symoff < segment->fileoff + segment->filesize)
            symbols = reinterpret_cast<const nlist_xx *>(stp->symoff - segment->fileoff + segment->vmaddr + slide);
        if (stp->stroff >= segment->fileoff && stp->stroff < segment->fileoff + segment->filesize)
            strings = reinterpret_cast<const char *>(stp->stroff - segment->fileoff + segment->vmaddr + slide);
    }

    if (slide == _not(size_t) || symbols == NULL || strings == NULL)
        return NULL;

    for (size_t i(0); i != stp->nsyms; ++i) {
        const nlist_xx *symbol(&symbols[i]);
        if (symbol->n_un.n_strx == 0 || (symbol->n_type & N_STAB) != 0)
            continue;

        const char *nambuf(strings + symbol->n_un.n_strx);
        if ($strcmp(name, nambuf) != 0)
            continue;

        uintptr_t value(symbol->n_value);
        if (value == 0)
            continue;

        value += slide;
        return reinterpret_cast<void *>(value);
    }

    return NULL;
}
Пример #20
0
void timedriver()
{   int i, algnum, numtests, start, clicks;
    while (scanf("%d %d %d %d", &algnum, &numtests, &n, &rotdist) != EOF) {
        initx();
        start = clock();
        for (i = 0; i < numtests; i++) {
            if (algnum == 1)
                revrot(rotdist, n);
            else if (algnum == 2)
                jugglerot(rotdist, n);
            else if (algnum == 22)
                jugglerot2(rotdist, n);
            else if (algnum == 3)
                gcdrot(rotdist, n);
            else if (algnum == 4)
                slide(rotdist, n);
        }
        clicks = clock() - start;
        printf("%d\t%d\t%d\t%d\t%d\t%g\n",
            algnum, numtests, n, rotdist, clicks,
            1e9*clicks/((float) CLOCKS_PER_SEC*n*numtests));
    }
}
Пример #21
0
void BrowserWindow::initialize()
{
    m_homeView = new HomeView(this);
    m_browserView = new BrowserView(this);

    m_homeView->hide();
    m_homeView->resize(size());
    m_homeView->move(0, 0);

    m_browserView->hide();
    m_browserView->resize(size());
    m_browserView->move(0, 0);

    connect(m_homeView, SIGNAL(addressEntered(QString)), SLOT(gotoAddress(QString)));
    connect(m_homeView, SIGNAL(urlActivated(QUrl)), SLOT(navigate(QUrl)));

    connect(m_browserView, SIGNAL(menuButtonClicked()), SLOT(showHomeView()));

    m_homeView->setVisible(false);
    m_browserView->setVisible(false);
    slide(0);

    connect(m_timeLine, SIGNAL(frameChanged(int)), SLOT(slide(int)));
}
Пример #22
0
void GMachine::execute(GEnvironment& environment)
{
	const std::vector<GInstruction>& code = environment.combinator->instructions;
	StackFrame<Address>& stack = environment.stack;

	for (size_t index = 0; index < code.size(); index++)
	{
		const GInstruction& instruction = code[index];
		switch (instruction.op)
		{
		case GOP::ALLOC:
			{
				for (int i = 0; i < instruction.value; i++)
				{
					heap.push_back(Node(nullptr));
					environment.stack.push(Address::indirection(&heap.back()));
				}
			}
			break;
		case GOP::EVAL:
			{
				static SuperCombinator unwind { "__uniwnd", Type(), 0, std::vector<GInstruction>{ GInstruction(GOP::UNWIND) } };
				GEnvironment child = environment.child(&unwind);
				child.stack.push(environment.stack.top());
				execute(child);
				environment.stack.top() = child.stack.top();
			}
			break;
		case GOP::MKAP:
			{
				Address func = environment.stack.top();
				environment.stack.pop();
				Address arg = environment.stack.top();
				heap.push_back(Node(func, arg));
				environment.stack.top() = Address::application(&heap.back());
			}
			break;
		case GOP::PACK:
			{
				int tag = instruction.value & (0xFFFF);//Low two bytes
				int arity = instruction.value >> 16;//High two bytes
				heap.push_back(Node(tag, new Address[arity+1]));
				Node& ctor = heap.back();
				for (int ii = 0; ii < arity; ii++)
				{
					ctor.constructor.arguments[ii] = stack.pop();
				}
				ctor.constructor.arguments[arity + 1] = Address::indirection(nullptr);//Use as end of this constructor
				stack.push(Address::constructor(&ctor));
			}
			break;
		case GOP::SPLIT:
			{
				Address top = stack.pop();
				assert(top.getType() == CONSTRUCTOR);
				ConstructorNode& ctor = top.getNode()->constructor;
				for (int ii = 0; ii < instruction.value; ii++)
				{
					assert(ctor.arguments[ii].getType() != NodeType::INDIRECTION || ctor.arguments[ii].getNode() != nullptr);
					stack.push(ctor.arguments[ii]);
				}
			}
			break;
		case GOP::CASEJUMP:
			{
				Address top = stack.top();
				assert(top.getType() == CONSTRUCTOR);
				ConstructorNode& ctor = top.getNode()->constructor;
				if (ctor.tag != instruction.value)
					index++;//Skip the next instruction which is the jump instruction
			}
			break;
		case GOP::JUMP:
			index = instruction.value - 1;
			break;
		case GOP::POP:
			for (int i = 0; i < instruction.value; i++)
			{
				environment.stack.pop();
			}
			break;
		case GOP::PUSH:
			{
				Address addr = environment.stack[instruction.value];
				environment.stack.push(addr);
			}
			break;
		case GOP::PUSH_DICTIONARY_MEMBER:
			{
				assert(stack.base().getType() == NodeType::CONSTRUCTOR);//Must be instance dictionary
				ConstructorNode& ctor = stack.base().getNode()->constructor;
				Address& func = ctor.arguments[instruction.value];
				stack.push(func);
			}
			break;
		case GOP::PUSH_GLOBAL:
			{
				Address addr = globals.at(instruction.value);
				environment.stack.push(addr);
			}
			break;
		case GOP::PUSH_INT:
			{
				heap.push_back(Node(instruction.value));
				environment.stack.push(Address::number(&heap.back()));
			}
			break;
		case GOP::PUSH_DOUBLE:
			{
				heap.push_back(Node(instruction.doubleValue));
				environment.stack.push(Address::numberDouble(&heap.back()));
			}
			break;
		case GOP::SLIDE:
			{
				slide(environment, instruction);
			}
			break;
		case GOP::UNWIND:
			{
				Address top = environment.stack.top();
				switch (top.getType())
				{
				case NUMBER:
					break;
				case APPLICATION:
					{
						Node& n = *top.getNode();
						environment.stack.push(n.apply.func);
						--index;//Redo the unwind instruction
					}
					break;
				case FUNCTION_POINTER:
					{
						int arity = top.getNode()->function.args;
						if (stack.stackSize() - 1 < size_t(arity))
						{
							while (stack.stackSize() > 1)
							{
								stack.pop();
							}
						}
						else
						{
							size_t ii = environment.stack.stackSize() - arity - 1;
							for (; ii < environment.stack.stackSize() - 1; ii++)
							{
								Address& addr = environment.stack[ii];
								assert(addr.getType() == APPLICATION);
								addr = addr.getNode()->apply.arg;
							}
							t_ffi_func func = top.getNode()->function.ptr;
							assert(func != nullptr);
							StackFrame<Address> newStack = stack.makeChildFrame(arity + 1);
							func(this, &newStack);
							Address result = newStack.top();
							for (int i = 0; i < arity; i++)
								environment.stack.pop();
							environment.stack.push(result);
						}
					}
					break;
				case GLOBAL:
					{
						SuperCombinator* comb = top.getNode()->global;
						if (environment.stack.stackSize() - 1 < size_t(comb->arity))
						{
							while (stack.stackSize() > 1)
							{
								stack.pop();
							}
						}
						else
						{
							//Before calling the function, replace all applications on the stack with the actual arguments
							//This gives faster access to a functions arguments when using PUSH
							size_t ii = environment.stack.stackSize() - comb->arity - 1;
							for (; ii < environment.stack.stackSize() - 1; ii++)
							{
								Address& addr = environment.stack[ii];
								assert(addr.getType() == APPLICATION);
								addr = addr.getNode()->apply.arg;
							}

							GEnvironment child = environment.child(comb);
							if (debug)
							{
								std::cerr << "Executing function '" << comb->name << "'" << std::endl;
								std::cerr << "Arguments { ";
								for (size_t i = 0; i < child.stack.stackSize(); i++)
								{
									std::cerr << child.stack[i];
								}
								std::cerr << " }" << std::endl;
							}
							execute(child);
							Address result = child.stack.top();
							for (int i = 0; i < comb->arity; i++)
								environment.stack.pop();
							environment.stack.push(result);
						}
					}
					break;
				case INDIRECTION:
					{
						environment.stack.top() = top.getNode()->indirection;
						--index;//Redo the unwind instruction
					}
					break;
				default:
					break;
				}
			}
			break;
		case GOP::UPDATE:
			{
				Address top = environment.stack.top();
				heap.push_back(Node(top));
				environment.stack[instruction.value] = Address::indirection(&heap.back());
			}
			break;
#define BINOP2(op, opname) \
		case GOP:: opname:\
			{\
			Address rhs = environment.stack.pop(); \
			Address lhs = environment.stack.top(); \
			int result = lhs.getNode()->number op rhs.getNode()->number; \
			heap.push_back(Node(result)); \
			environment.stack.top() = Address::number(&heap.back()); \
			}\
            break;
#define BINOP(f, name) case GOP:: name: binopInt<f>(environment, heap); break;

			BINOP(add<int>, ADD)
			BINOP(subtract<int>, SUBTRACT)
			BINOP(multiply<int>, MULTIPLY)
			BINOP(divide<int>, DIVIDE)
			BINOP(remainder<int>, REMAINDER)
			
#define BINOP_DOUBLE(f, name) case GOP:: name: binopDouble<f>(environment, heap); break;

			BINOP_DOUBLE(add<double>, ADD_DOUBLE)
			BINOP_DOUBLE(subtract<double>, SUBTRACT_DOUBLE)
			BINOP_DOUBLE(multiply<double>, MULTIPLY_DOUBLE)
			BINOP_DOUBLE(divide<double>, DIVIDE_DOUBLE)

#undef BINOP_DOUBLE
		case GOP::NEGATE:
			{
				Address x = environment.stack.top();
				heap.push_back(Node(-x.getNode()->number));
				environment.stack.top() = Address::number(&heap.back());
			}
			break;

			BINOP2(== , COMPARE_EQ)
			BINOP2(!= , COMPARE_NEQ)
			BINOP2(> , COMPARE_GT)
			BINOP2(>=, COMPARE_GE)
			BINOP2(< , COMPARE_LT)
			BINOP2(<=, COMPARE_LE)

#undef BINOP
#undef BINOP2

		default:
			std::cout << "Unimplemented instruction " << int(code[index].op) << std::endl;
			break;
		}
	}
	if (debug)
	{
		std::cerr << "Returning '" << stack.top() << "' from '" << environment.combinator->name << "'" << std::endl;
	}
}
Пример #23
0
/**
 * \brief Take a packet received over the 802.15.4 link, and send it
 * out over ethernet, performing any translations needed.
 */
void mac_LowpanToEthernet(void)
{
#if !RF230BB && !RF212BB
  parsed_frame = sicslowmac_get_frame();
#endif

  //Setup generic ethernet stuff
  ETHBUF(uip_buf)->type = uip_htons(UIP_ETHTYPE_IPV6);

  //Check for broadcast message
  
#if RF230BB || RF212BB
  if(rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER), &rimeaddr_null)) {
//  if(rimeaddr_cmp((const rimeaddr_t *)destAddr, &rimeaddr_null)) {
#else
  if(  ( parsed_frame->fcf->destAddrMode == SHORTADDRMODE) &&
       ( parsed_frame->dest_addr->addr16 == 0xffff) ) {
#endif
    ETHBUF(uip_buf)->dest.addr[0] = 0x33;
    ETHBUF(uip_buf)->dest.addr[1] = 0x33;

#if UIP_CONF_IPV6
    ETHBUF(uip_buf)->dest.addr[2] = UIP_IP_BUF->destipaddr.u8[12];
    ETHBUF(uip_buf)->dest.addr[3] = UIP_IP_BUF->destipaddr.u8[13];
    ETHBUF(uip_buf)->dest.addr[4] = UIP_IP_BUF->destipaddr.u8[14];
    ETHBUF(uip_buf)->dest.addr[5] = UIP_IP_BUF->destipaddr.u8[15];
#else
	//Not intended to be functional, but allows ip4 build without errors.
    ETHBUF(uip_buf)->dest.addr[2] = UIP_IP_BUF->destipaddr.u8[0];
    ETHBUF(uip_buf)->dest.addr[3] = UIP_IP_BUF->destipaddr.u8[1];
    ETHBUF(uip_buf)->dest.addr[4] = UIP_IP_BUF->destipaddr.u8[2];
    ETHBUF(uip_buf)->dest.addr[5] = UIP_IP_BUF->destipaddr.u8[3];
#endif
  } else {
	//Otherwise we have a real address
	mac_createEthernetAddr((uint8_t *) &(ETHBUF(uip_buf)->dest.addr[0]),
                        (uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_RECEIVER));
  }

#if !UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
  //Source ethernet depends on node
  if(!mac_createEthernetAddr(
    (uint8_t *) &(ETHBUF(uip_buf)->src.addr[0]),
    (uip_lladdr_t *)packetbuf_addr(PACKETBUF_ADDR_SENDER)
  ))
#endif

  {
    mac_createDefaultEthernetAddr((uint8_t *) &(ETHBUF(uip_buf)->src.addr[0]));
  }

  //We only do address translation in network mode!
  if (usbstick_mode.translate) {
    //Some IP packets have link layer in them, need to change them around!
    mac_translateIPLinkLayer(ll_8023_type);
  }
 
#if UIP_CONF_IPV6_RPL
/* We won't play ping-pong with the host! */
    if(uip_ipaddr_cmp(&last_sender, &UIP_IP_BUF->srcipaddr)) {
        PRINTF("siclow_ethernet: Destination off-link but no route\n");
        uip_len=0;
        return;
    }
#endif

  PRINTF("Low2Eth: Sending packet to ethernet\n\r");

  uip_len += UIP_LLH_LEN;
  if (usbstick_mode.raw == 0)
	  usb_eth_send(uip_buf, uip_len, 1);
#if !RF230BB && !RF212BB
  usb_eth_stat.rxok++;
#endif
  uip_len = 0;
}

/**
 * \brief Translate IP packet's possible link-layer addresses, passing
 *        the message to the appropriate higher level function for this
 *        packet (aka: ICMP)
 * \param target The target we want to end up with - either ll_8023_type
 *        for ethernet, or ll_802154_type for 802.15.4
 * \return    Returns how successful the translation was
 * \retval 0  Addresses, if present, were translated.
 * \retval <0 Negative return values indicate various errors, as defined
 *            by the higher level function.
 */
int8_t mac_translateIPLinkLayer(lltype_t target)
{

#if UIP_LLADDR_LEN == 8
  if (UIP_IP_BUF->proto == UIP_PROTO_ICMP6) {
    PRINTF("eth2low: ICMP Message detected\n\r");
    return mac_translateIcmpLinkLayer(target);
  }
  return 0;
#else
  return 1;
#endif

}

#include "net/uip-icmp6.h"
#include "net/uip-nd6.h"

typedef struct {
  uint8_t type;
  uint8_t length;
  uint8_t data[16];
} icmp_opts_t;

#define UIP_ICMP_BUF     ((struct uip_icmp_hdr *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN])
#define UIP_ICMP_OPTS(x) ((icmp_opts_t *)&uip_buf[UIP_LLH_LEN + UIP_IPH_LEN + x])

void slide(uint8_t * data, uint8_t length, int16_t slide);

/**
 * \brief Translate the link-layer (L2) addresses in an ICMP packet.
 *        This will just be NA/NS/RA/RS packets currently.
 * \param target The target we want to end up with - either ll_8023_type
 *        for ethernet, or ll_802154_type for 802.15.4
 * \return       Returns how successful the translation was
 * \retval 0     Addresses, if present, were translated.
 * \retval -1    ICMP message was unknown type, nothing done.
 * \retval -2    ICMP Length does not make sense?
 * \retval -3    Unknown 'target' type
 */
int8_t mac_translateIcmpLinkLayer(lltype_t target)
{
  uint16_t icmp_opt_offset = 0;
  int16_t len = UIP_IP_BUF->len[1] | (UIP_IP_BUF->len[0] << 8);

  uint16_t iplen;

  uint8_t i;

  int16_t sizechange;

  uint8_t llbuf[16];

  //Figure out offset to start of options
  switch(UIP_ICMP_BUF->type) {
    case ICMP6_NS:
    case ICMP6_NA:
      icmp_opt_offset = 24;
      break;

    case ICMP6_RS:
      icmp_opt_offset = 8;
      break;

    case ICMP6_RA:
      icmp_opt_offset = 16;
      break;

    case ICMP6_REDIRECT:
      icmp_opt_offset = 40;
      break;

      /** Things without link-layer */
    case ICMP6_DST_UNREACH:
    case ICMP6_PACKET_TOO_BIG:
    case ICMP6_TIME_EXCEEDED:	
    case ICMP6_PARAM_PROB:
    case ICMP6_ECHO_REQUEST:  
    case ICMP6_ECHO_REPLY: 
      return 0;
      break;

    default:
      return -1;
  }

  //Figure out length of options
  len -= icmp_opt_offset;

  //Sanity check
  if (len < 8) return -2; 

  //While we have options to do...
  while (len >= 8){
    
    //If we have one of these, we have something useful!
    if (((UIP_ICMP_OPTS(icmp_opt_offset)->type) == UIP_ND6_OPT_SLLAO) || 
        ((UIP_ICMP_OPTS(icmp_opt_offset)->type) == UIP_ND6_OPT_TLLAO) ) {
      
      /* Shrinking the buffer may thrash things, so we store the old
         link-layer address */
      for(i = 0; i < (UIP_ICMP_OPTS(icmp_opt_offset)->length*8 - 2); i++) {
        llbuf[i] = UIP_ICMP_OPTS(icmp_opt_offset)->data[i];
      }

      //Shrink/grow buffer as needed
      if (target == ll_802154_type) {
        //Current is 802.3, Hence current link-layer option is 6 extra bytes
        sizechange = 8;
        slide(UIP_ICMP_OPTS(icmp_opt_offset)->data + 6, len - 6, sizechange);
      } else if (target == ll_8023_type) {
        /* Current is 802.15.4, Hence current link-layer option is 14 extra
         * bytes.
         * (Actual LL is 8 bytes, but total option length is in multiples of
         * 8 Bytes, hence 8 + 2 = 10. Closest is 16 bytes, then 16 bytes for
         * total optional length - 2 bytes for type + length leaves 14 )
         */
        sizechange = -8;
        slide(UIP_ICMP_OPTS(icmp_opt_offset)->data + 14, len - 14, sizechange);
      } else {
        return -3; //Uh-oh!
      }
      
      //Translate addresses
      if (target == ll_802154_type) {
        mac_createSicslowpanLongAddr(llbuf, (uip_lladdr_t *)UIP_ICMP_OPTS(icmp_opt_offset)->data);
      } else {
#if !UIP_CONF_SIMPLE_JACKDAW_ADDR_TRANS
        if(!mac_createEthernetAddr(UIP_ICMP_OPTS(icmp_opt_offset)->data, (uip_lladdr_t *)llbuf))
#endif
            mac_createDefaultEthernetAddr(UIP_ICMP_OPTS(icmp_opt_offset)->data);
      }
      
      //Adjust the length
      if (target == ll_802154_type) {
        UIP_ICMP_OPTS(icmp_opt_offset)->length = 2;
      } else {
        UIP_ICMP_OPTS(icmp_opt_offset)->length = 1;
      }

      //Adjust the IP header length, as well as uIP length
      iplen = UIP_IP_BUF->len[1] | (UIP_IP_BUF->len[0]<<8);
      iplen += sizechange;
      len += sizechange;
      
      UIP_IP_BUF->len[1] = (uint8_t)iplen;
      UIP_IP_BUF->len[0] = (uint8_t)(iplen >> 8);

      uip_len += sizechange;

      //We broke ICMP checksum, be sure to fix that
      UIP_ICMP_BUF->icmpchksum = 0;
#if UIP_CONF_IPV6   //allow non ipv6 builds
      UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();
#endif

      //Finally set up next run in while loop
      len -= 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
      icmp_opt_offset += 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
    } else {
	  
      //Not an option we care about, ignore it
      len -= 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
	      
      //This shouldn't happen!
      if (UIP_ICMP_OPTS(icmp_opt_offset)->length == 0) {
        PRINTF("Option in ND packet has length zero, error?\n\r");
        len = 0;
      }

      icmp_opt_offset += 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
      
    } //If ICMP_OPT is one we care about
   
  } //while(len >= 8)
Пример #24
0
// Routine which actually does the drawing
void cbRenderScene( void )
{
    char buf[80]; // For our strings.

    // Enables, disables or otherwise adjusts as
    // appropriate for our current settings.

    if (Texture_On)
    {
        glEnable(GL_TEXTURE_RECTANGLE_ARB);
//      glEnable(GL_TEXTURE_RECTANGLE_NV);
    }
    else
    {
        glDisable(GL_TEXTURE_RECTANGLE_ARB);
//      glDisable(GL_TEXTURE_RECTANGLE_NV);
    }
    if (Light_On)
        glEnable(GL_LIGHTING);
    else
        glDisable(GL_LIGHTING);

    if (Alpha_Add)
        glBlendFunc(GL_SRC_ALPHA,GL_ONE);
    else
        glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

    // If we're blending, we don't want z-buffering.
    if (Blend_On)
    {
        glDisable(GL_DEPTH_TEST);
        glEnable(GL_BLEND);
    }
    else
        glEnable(GL_DEPTH_TEST);

    if (Filtering_On) {
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,
                        GL_LINEAR_MIPMAP_LINEAR);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    } else {
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,
                        GL_NEAREST_MIPMAP_NEAREST);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
    }


    // Need to manipulate the ModelView matrix to move our model around.
    glMatrixMode(GL_MODELVIEW);

    // Reset to 0,0,0; no rotation, no scaling.
    glLoadIdentity();

    // Clear the color and depth buffers.
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    if (state) //is false for the selection portion, then turns to true for the remainder of the program
    {
        // Move the object back from the screen.
        glTranslatef(X_Cam,Y_Cam,Z_Off);

        // Rotate the calculated amount.
        glRotatef(X_Rot,1.0f,0.0f,0.0f);
        glRotatef(Y_Rot,0.0f,1.0f,0.0f);
        glRotatef(Z_Rot,0.0f,0.0f,1.0f);

        int i;

        for(i=0; i < NUM_PIC; i++)
        {
            glPushMatrix();
            glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texture[i]);
            switch(Render_mode)
            {
            case 0:
                glTranslatef(offset_on*(offset*i*offset_delta)+offset_off*(offset*i),0.0f,0.0f);
                strcpy(Render_string, "Additive");
                break;
            case 1:
                glTranslatef(offset*offset_delta*slide(i),0.0f,0.0f);
                strcpy(Render_string, "Slide");
                break;
            case 2:
                glTranslatef(0.0f,-offset*offset_delta*2*i,0.0f);
                strcpy(Render_string, "3D");
                break;
            case 3:
                glTranslatef(offset*offset_delta*i,-offset*offset_delta*2*i,0.0f);
                strcpy(Render_string, "3D & Additive");
                break;
            case 4:
                glTranslatef(offset*offset_delta*slide(i),-offset*offset_delta*2*i,0.0f);
                strcpy(Render_string, "3D & Slide");
                break;
            default:
                break;
            }
            glBegin(GL_QUADS);
            glColor4f(0.8f, 0.8f, 0.8f, (1.0f/(i+1)) );

            glTexCoord2f(0.0f, 0.0f);
            glVertex3f(0.0f-wid[i]/40.0f, i/10.0f,0.0f-hei[i]/40.0f);

            glTexCoord2f(wid[i], 0.0f);
            glVertex3f(wid[i]/40.0f, i/10.0f,0.0f-hei[i]/40.0f);

            glTexCoord2f(wid[i], hei[i]);
            glVertex3f(wid[i]/40.0f, i/10.0f,hei[i]/40.0f);

            glTexCoord2f(0.0f, hei[i]);
            glVertex3f(0.0f-wid[i]/40.0f, i/10.0f,hei[i]/40.0f);

            glEnd();
            glPopMatrix();
        }

    }
    // Lit or textured text looks awful.
    glDisable(GL_TEXTURE_RECTANGLE_ARB);
    glDisable(GL_LIGHTING);

    // We don't want depth-testing either.
    glDisable(GL_DEPTH_TEST);

    // Move back to the origin (for the text, below).
    glLoadIdentity();

    // We need to change the projection matrix for the text rendering.
    glMatrixMode(GL_PROJECTION);

    // But we like our current view too; so we save it here.
    glPushMatrix();

    // Now we set up a new projection for the text.
    glLoadIdentity();
    glOrtho(0,Window_Width,0,Window_Height,-1.0,1.0);

    if (Text_on)
    {
        // But, for fun, let's make the text partially transparent too.
        glColor4f(0.6,1.0,0.6,.85);

        // Render our various display mode settings.
//   sprintf(buf,"Mode: %s", TexModesStr[Curr_TexMode]);

        sprintf(buf,"Blend: %s", Blend_On ? "Yes" : "No" );
        glRasterPos2i(2,2);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,buf);

        sprintf(buf,"Light: %s", Light_On ? "Yes" : "No");
        glRasterPos2i(2,14);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,buf);

        sprintf(buf,"Mode: %d, %s", Render_mode, Render_string);
        glRasterPos2i(2,26);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,buf);

        sprintf(buf,"X: %s", offset_on ? "Fast" : "Slow");
        glRasterPos2i(2,38);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,buf);

        sprintf(buf,"O: Turn off text display");
        glRasterPos2i(2,50);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,buf);

        sprintf(buf,"P: Print screen");
        glRasterPos2i(2,62);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,buf);

        sprintf(buf,"I/U: Macro Print screen");
        glRasterPos2i(2,74);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,buf);

        sprintf(buf,"Y/T: Macro Rotate/ Print screen");
        glRasterPos2i(2,86);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,buf);

        sprintf(buf,"R: Reset View");
        glRasterPos2i(2,98);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,buf);
        // Now we want to render the calulated FPS at the top.

        // To ease, simply translate up.  Note we're working in screen
        // pixels in this projection.

        glTranslatef(6.0f,Window_Height - 14,0.0f);

        // Make sure we can read the FPS section by first placing a
        // dark, mostly opaque backdrop rectangle.
        glColor4f(0.2,0.2,0.2,0.75);

        glBegin(GL_QUADS);
        glVertex3f(  0.0f, -16.0f, 0.0f);
        glVertex3f(  0.0f, -4.0f, 0.0f);
        glVertex3f(140.0f, -4.0f, 0.0f);
        glVertex3f(140.0f, -16.0f, 0.0f);
        glEnd();

        glColor4f(0.9,0.2,0.2,.75);
        sprintf(buf,"FPS: %f F: %2d", FrameRate, FrameCount);
        glRasterPos2i(6,-16);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,buf);
        glLoadIdentity();
        glOrtho(0,Window_Width,0,Window_Height,-1.0,1.0);
    }

    glTranslatef(6.0f,Window_Height - 14,0.0f);

    glBegin(GL_QUADS);
    glColor4f(.75,.75,.75,1.0);
    glVertex3f(-6, -4, 0);
    glVertex3f(-6, 14, 0);
    glVertex3f(Window_Width, 14, 0);
    glVertex3f(Window_Width, -4, 0);
    glEnd();

    glBegin(GL_LINES);
    glColor4f(0,0,0,1.0);
    glVertex3f(Window_Width-7, -4, 0);
    glVertex3f(-6, -4, 0);
    glEnd();

    switch(menu_selected)
    {
    case 0:
        break;
    case 1: //File menu
        glBegin(GL_QUADS); //draw drop-down menu
        glColor4f(.04,.14,.39,.8);
        glVertex3f(  -2.0f, -4.0f, 0);
        glVertex3f(  -2.0f, 13.0f, 0);
        glVertex3f(  25.0f, 13.0f, 0);
        glVertex3f(  25.0f, -4.0f, 0);

        glColor4f(.75,.75,.75,1.0);
        glVertex3f(-2, -38, 0);
        glVertex3f(-2, -4, 0);
        glVertex3f(98, -4, 0);
        glVertex3f(98, -38, 0);
        glEnd();

        glColor4f(0,0,0,1);
        if(file[0])
        {
            glBegin(GL_QUADS); //draw blue selection box
            glColor4f(.04,.14,.39,.8);
            glVertex3f(  -1.0f, -5.0f, 0);
            glVertex3f(  -1.0f, -20.0f, 0);
            glVertex3f(  97.0f, -20.0f, 0);
            glVertex3f(  97.0f, -5.0f, 0);
            glEnd();
            glColor4f(1,1,1,1);
        }
        glRasterPos2i(2, -16);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"Open      Ctrl+O");
        glBegin(GL_LINES); //draw light grey divider
        glColor4f(.6,.6,.6,1);
        glVertex3f(-1,-22,0);
        glVertex3f(99,-22,0);
        glEnd();
        //begin next menu entry
        glColor4f(0,0,0,1);
        if(file[1])
        {
            glBegin(GL_QUADS);
            glColor4f(.04,.14,.39,.8);
            glVertex3f(  -1.0f, -23.0f, 0);
            glVertex3f(  -1.0f, -36.0f, 0);
            glVertex3f(  97.0f, -36.0f, 0);
            glVertex3f(  97.0f, -23.0f, 0);
            glEnd();
            glColor4f(1,1,1,1);
        }
        glRasterPos2i(2, -34);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"Exit               Q");
        break;
    case 2: //Edit
        glBegin(GL_QUADS);
        glColor4f(.04,.14,.39,.8);
        glVertex3f(  28.0f, -4.0f, 0);
        glVertex3f(  28.0f, 13.0f, 0);
        glVertex3f(  54.0f, 13.0f, 0);
        glVertex3f(  54.0f, -4.0f, 0);

        glColor4f(.75,.75,.75,1.0);
        glVertex3f(28, -8, 0);
        glVertex3f(28, -4, 0);
        glVertex3f(77, -4, 0);
        glVertex3f(77, -8, 0);
        glEnd();
        break;
    case 3: //View
        glBegin(GL_QUADS);
        glColor4f(.04,.14,.39,.8);
        glVertex3f(  58.0f, -4.0f, 0);
        glVertex3f(  58.0f, 13.0f, 0);
        glVertex3f(  92.0f, 13.0f, 0);
        glVertex3f(  92.0f, -4.0f, 0);

        glColor4f(.75,.75,.75,1.0);
        glVertex3f(58, -122, 0);
        glVertex3f(58, -4, 0);
        glVertex3f(164, -4, 0);
        glVertex3f(164, -122, 0);
        glEnd();

        glColor4f(0,0,0,1);
        if(view[0])
        {
            glBegin(GL_QUADS);
            glColor4f(.04,.14,.39,.8);
            glVertex3f(  59.0f, -5.0f, 0);
            glVertex3f(  59.0f, -19.0f, 0);
            glVertex3f(  163.0f, -19.0f, 0);
            glVertex3f(  163.0f, -5.0f, 0);
            glEnd();
            glColor4f(1,1,1,1);
        }
        glRasterPos2i(62, -16);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"Zoom in      PgUp");
        glColor4f(0,0,0,1);
        if(view[1])
        {
            glBegin(GL_QUADS);
            glColor4f(.04,.14,.39,.8);
            glVertex3f(  59.0f, -34.0f, 0);
            glVertex3f(  59.0f, -19.0f, 0);
            glVertex3f(  163.0f, -19.0f, 0);
            glVertex3f(  163.0f, -34.0f, 0);
            glEnd();
            glColor4f(1,1,1,1);
        }
        glRasterPos2i(62, -30);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"Zoom out    PgDn");
        glColor4f(0,0,0,1);
        if(view[2])
        {
            glBegin(GL_QUADS);
            glColor4f(.04,.14,.39,.8);
            glVertex3f(  59.0f, -34.0f, 0);
            glVertex3f(  59.0f, -49.0f, 0);
            glVertex3f(  163.0f, -49.0f, 0);
            glVertex3f(  163.0f, -34.0f, 0);
            glEnd();
            glColor4f(1,1,1,1);
        }
        glRasterPos2i(62, -44);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"Reset view       R");
        glBegin(GL_LINES);
        glColor4f(.6,.6,.6,1);
        glVertex3f(59,-50,0);
        glVertex3f(163,-50,0);
        glEnd();
        glColor4f(0,0,0,1);
        glRasterPos2i(62, -62);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"Set mode:");
        glColor4f(0,0,0,1);
        if(view[3])
        {
            glBegin(GL_QUADS);
            glColor4f(.04,.14,.39,.8);
            glVertex3f(  59.0f, -65.0f, 0);
            glVertex3f(  59.0f, -79.0f, 0);
            glVertex3f(  163.0f, -79.0f, 0);
            glVertex3f(  163.0f, -65.0f, 0);
            glEnd();
            glColor4f(1,1,1,1);
        }
        glRasterPos2i(110, -76);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"  Default");
        glColor4f(0,0,0,1);
        if(view[4])
        {
            glBegin(GL_QUADS);
            glColor4f(.04,.14,.39,.8);
            glVertex3f(  59.0f, -92.0f, 0);
            glVertex3f(  59.0f, -79.0f, 0);
            glVertex3f(  163.0f, -79.0f, 0);
            glVertex3f(  163.0f, -92.0f, 0);
            glEnd();
            glColor4f(1,1,1,1);
        }
        glRasterPos2i(110, -89);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"     Slide");
        glColor4f(0,0,0,1);
        if(view[5])
        {
            glBegin(GL_QUADS);
            glColor4f(.04,.14,.39,.8);
            glVertex3f(  59.0f, -92.0f, 0);
            glVertex3f(  59.0f, -107.0f, 0);
            glVertex3f(  163.0f, -107.0f, 0);
            glVertex3f(  163.0f, -92.0f, 0);
            glEnd();
            glColor4f(1,1,1,1);
        }
        glRasterPos2i(110, -104);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"        3D");
        glColor4f(0,0,0,1);
        if(view[6])
        {
            glBegin(GL_QUADS);
            glColor4f(.04,.14,.39,.8);
            glVertex3f(  59.0f, -120.0f, 0);
            glVertex3f(  59.0f, -107.0f, 0);
            glVertex3f(  163.0f, -107.0f, 0);
            glVertex3f(  163.0f, -120.0f, 0);
            glEnd();
            glColor4f(1,1,1,1);
        }
        glRasterPos2i(110, -117);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"3D Slide");

        break;
    case 4: //Help
        glBegin(GL_QUADS);
        glColor4f(.04,.14,.39,.8);
        glVertex3f(  94.0f, -4.0f, 0);
        glVertex3f(  94.0f, 13.0f, 0);
        glVertex3f(  128.0f, 13.0f, 0);
        glVertex3f(  128.0f, -4.0f, 0);

        glColor4f(.75,.75,.75,1.0);
        glVertex3f(94, -22, 0);
        glVertex3f(94, -4, 0);
        glVertex3f(174, -4, 0);
        glVertex3f(174, -22, 0);
        glEnd();

        glColor4f(0,0,0,1);
        if(help[0])
        {
            glBegin(GL_QUADS);
            glColor4f(.04,.14,.39,.8);
            glVertex3f(  95.0f, -5.0f, 0);
            glVertex3f(  95.0f, -20.0f, 0);
            glVertex3f(  173.0f, -20.0f, 0);
            glVertex3f(  173.0f, -5.0f, 0);
            glEnd();
            glColor4f(1,1,1,1);
        }
        glRasterPos2i(98, -16);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"About");
        break;
    default:
        menu_selected = 0;
        break;
    }

    glColor4f(0,0,0,1);
    glRasterPos2i(2, 1);
    ourPrintString(GLUT_BITMAP_HELVETICA_12,"File");
    if(menu_selected == 1) //write over it in white
    {
        glColor4f(1,1,1,1);
        glRasterPos2i(2, 1);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"File");
    }
    glRasterPos2i(2, 1);
    ourPrintString(GLUT_BITMAP_HELVETICA_12,"_");
    glColor4f(0,0,0,1);
    glRasterPos2i(31, 1);
    ourPrintString(GLUT_BITMAP_HELVETICA_12, "Edit");
    if(menu_selected == 2)
    {
        glColor4f(1,1,1,1);
        glRasterPos2i(31, 1);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"Edit");
    }
    glRasterPos2i(31, 1);
    ourPrintString(GLUT_BITMAP_HELVETICA_12,"_");
    glColor4f(0,0,0,1);
    glRasterPos2i(61, 1);
    ourPrintString(GLUT_BITMAP_HELVETICA_12, "View");
    if(menu_selected == 3)
    {
        glColor4f(1,1,1,1);
        glRasterPos2i(61, 1);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"View");
    }
    glRasterPos2i(61, 1);
    ourPrintString(GLUT_BITMAP_HELVETICA_12,"_");
    glColor4f(0,0,0,1);
    glRasterPos2i(97, 1);
    ourPrintString(GLUT_BITMAP_HELVETICA_12, "Help");
    if(menu_selected == 4)
    {
        glColor4f(1,1,1,1);
        glRasterPos2i(97, 1);
        ourPrintString(GLUT_BITMAP_HELVETICA_12,"Help");
    }
    glRasterPos2i(97, 1);
    ourPrintString(GLUT_BITMAP_HELVETICA_12,"_");



    // Done with this special projection matrix.  Throw it away.
    glPopMatrix();


    // All done drawing.  Let's show it.
    glutSwapBuffers();


    // And collect our statistics.
    ourDoFPS();
}
Пример #25
0
void merge_path_operation::merge_inside (svg_path *path, svg_path_geom_iterator dest, svg_path_geom_iterator src)
{
  /// if it is the same subpath, just close it
  if (&dest.subpath () == &src.subpath ())
    {
      auto &elements = dest.subpath ().elements ();
      auto &front_elem = elements.front ();
      auto &back_elem = elements.back ();
      if (elements.size () > 1 && front_elem.point == back_elem.point)
        {
          front_elem.c1 = back_elem.c1;

          svg_path_geom_iterator last_segment_point (*path->get_geom (), dest.get_subpath_index (), dest.subpath ().last_point ());
          size_t point_index = last_segment_point.point_index ();
          path->get_node_type ()->erase (path->get_node_type ()->begin () + point_index);
          elements.pop_back ();
        }
      dest.subpath ().set_closed (true);
      return;
    }

  /// else merge two subpaths

  // if dest is subpath begin, prepend src
  vector<single_path_point> &dest_subpath = dest.subpath ().elements (), &src_subpath = src.subpath ().elements ();
  if (src_subpath.size () > 0)
    {
      svg_path_geom *geom = path->get_geom ();
      auto line_segment = path->get_is_line_segment ();
      auto node_types = path->get_node_type ();
      auto line_begin = line_segment->begin ();
      auto node_type_begin = node_types->begin ();
      int dest_subpath_index = (int)dest.get_subpath_index ();
      int src_subpath_index = (int)src.get_subpath_index ();
      auto src_begin_it = geom->subpath_begin (src_subpath_index);
      auto dst_begin_it = geom->subpath_begin (dest_subpath_index);

      if (dest.get_subpath_point () == 0)
        {
          if (src.get_subpath_point () == 0)
            path->reverse_subpath ((int)src.get_subpath_index ());

          slide (line_begin + src_begin_it.segment_index (cp_type::RIGHT), line_begin + src_begin_it.segment_index (cp_type::RIGHT) + src.subpath ().total_segments (),
                 line_begin + dst_begin_it.segment_index (cp_type::RIGHT));
          slide (node_type_begin + src_begin_it.point_index (), node_type_begin + src_begin_it.point_index () + src.subpath ().total_points (),
                 node_type_begin + dst_begin_it.point_index ());

          node_types->erase (node_type_begin + src_begin_it.point_index () + src.subpath ().total_points () - 1);
          dest_subpath.insert (dest_subpath.begin (), src_subpath.begin (), src_subpath.end () - 1);

        }
      else
        {
          /// reverse src if necessary
          if (src.get_subpath_point () != 0)
            path->reverse_subpath ((int)src.get_subpath_index ());

          slide (line_begin + src_begin_it.segment_index (cp_type::RIGHT), line_begin + src_begin_it.segment_index (cp_type::RIGHT) + src.subpath ().total_segments (),
                 line_begin + dst_begin_it.segment_index (cp_type::RIGHT) + dest.subpath ().total_segments ());

          slide (node_type_begin + src_begin_it.point_index (), node_type_begin + src_begin_it.point_index () + src.subpath ().total_points (),
                 node_type_begin + dst_begin_it.point_index () + dest.subpath ().total_points ());

          node_types->erase (node_type_begin + src_begin_it.point_index ());
          dest_subpath.insert (dest_subpath.end (), src_subpath.begin () + 1, src_subpath.end ());

        }
    }

  auto & subpath = path->get_geom ()->subpath ();
  subpath.erase (subpath.begin () + src.get_subpath_index ());
}
Пример #26
0
/**
 * \brief Translate the link-layer (L2) addresses in an ICMP packet.
 *        This will just be NA/NS/RA/RS packets currently.
 * \param target The target we want to end up with - either ll_8023_type
 *        for ethernet, or ll_802154_type for 802.15.4
 * \return       Returns how successful the translation was
 * \retval 0     Addresses, if present, were translated.
 * \retval -1    ICMP message was unknown type, nothing done.
 * \retval -2    ICMP Length does not make sense?
 * \retval -3    Unknown 'target' type
 */
static int8_t
mac_translateIcmpLinkLayer(lltype_t target)
{
    uint16_t icmp_opt_offset=0,
             sizechange,
             iplen;
    int16_t  len = UIP_IP_BUF->len[1] | (UIP_IP_BUF->len[0] << 8);
    uint8_t  i,
             llbuf[6];

    // Figure out offset to start of options
    switch(UIP_ICMP_BUF->type) {
    case ICMP6_NS:
    case ICMP6_NA:
        icmp_opt_offset = 24;
        break;

    case ICMP6_RS:
        icmp_opt_offset = 8;
        break;

    case ICMP6_RA:
        icmp_opt_offset = 16;
        break;

    case ICMP6_REDIRECT:
        icmp_opt_offset = 40;
        break;

    /** Things without link-layer */
    case ICMP6_DST_UNREACH:
    case ICMP6_PACKET_TOO_BIG:
    case ICMP6_TIME_EXCEEDED:
    case ICMP6_PARAM_PROB:
    case ICMP6_ECHO_REQUEST:
    case ICMP6_ECHO_REPLY:
        return 0;
        break;

    default:
        return -1;
    }

    // Figure out length of options
    len -= icmp_opt_offset;

    // Sanity check
    if (len < 8) return -2;

    // While we have options to do...
    while (len >= 8)
    {
        // If we have one of these, we have something useful!
        if (((UIP_ICMP_OPTS(icmp_opt_offset)->type) == UIP_ND6_OPT_SLLAO) ||
                ((UIP_ICMP_OPTS(icmp_opt_offset)->type) == UIP_ND6_OPT_TLLAO) )
        {
            /* Shrinking the buffer may thrash things, so we store the old
               link-layer address */
            for(i=0; i<(UIP_ICMP_OPTS(icmp_opt_offset)->length*8 - 2); i++)
            {
                llbuf[i] = UIP_ICMP_OPTS(icmp_opt_offset)->data[i];
            }

            // Shrink/grow buffer as needed
            if (target == ll_802154_type)
            {
                // Current is 802.3, Hence current link-layer option is 6 extra bytes
                sizechange = 8;
                slide(UIP_ICMP_OPTS(icmp_opt_offset)->data + 6, len - 6, sizechange);
            }
            else if (target == ll_8023_type)
            {
                /* Current is 802.15.4, Hence current link-layer option is 14 extra
                 * bytes.
                 * (Actual LL is 8 bytes, but total option length is in multiples of
                 * 8 Bytes, hence 8 + 2 = 10. Closest is 16 bytes, then 16 bytes for
                 * total optional length - 2 bytes for type + length leaves 14 )
                 */
                sizechange = -8;
                slide(UIP_ICMP_OPTS(icmp_opt_offset)->data + 14, len - 14, sizechange);
            }
            else
            {
                return -3; //Uh-oh!
            }

            // Translate addresses
            if (target == ll_802154_type)
                mac_createSicslowpanLongAddr(llbuf, (uip_lladdr_t *)UIP_ICMP_OPTS(icmp_opt_offset)->data);
            else
                mac_createEthernetAddr(UIP_ICMP_OPTS(icmp_opt_offset)->data, (uip_lladdr_t *)llbuf);

            // adjust the length
            if (target == ll_802154_type)
                UIP_ICMP_OPTS(icmp_opt_offset)->length = 2;
            else
                UIP_ICMP_OPTS(icmp_opt_offset)->length = 1;

            // Adjust the IP header length, as well as uIP length
            iplen = UIP_IP_BUF->len[1] | (UIP_IP_BUF->len[0]<<8);
            iplen += sizechange;
            len += sizechange;

            UIP_IP_BUF->len[1] = (uint8_t)iplen;
            UIP_IP_BUF->len[0] = (uint8_t)(iplen >> 8);

            uip_len += sizechange;

            // We broke ICMP checksum, be sure to fix that
            UIP_ICMP_BUF->icmpchksum = 0;
            UIP_ICMP_BUF->icmpchksum = ~uip_icmp6chksum();

            // Finally set up next run in while loop
            len -= 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
            icmp_opt_offset += 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
        }
        else
        {
            // Not an option we care about, ignore it
            len -= 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;

            // This shouldn't happen!
            if (UIP_ICMP_OPTS(icmp_opt_offset)->length == 0)
                len = 0;

            icmp_opt_offset += 8 * UIP_ICMP_OPTS(icmp_opt_offset)->length;
        }
    }
void IncomeDataThread::run() {
	//Receiving Record data from the server.
	//std::cout << "IDT_RUN" << std::endl;
	char buff[2048];
	while (fd >= 0) {
		int temp1, readLen;
		read(fd, &temp1, 4);
		//memcpy(&temp1,buff,4);
		//std::cout << temp1 << std::endl;
		char fn[temp1 + 1];
		read(fd, fn, temp1);
		fn[temp1] = '\0';
		read(fd, &temp1, 4);
		//memcpy(&temp1,buff,4);
		emit recordHeader(temp1, QString::fromLatin1(fn));

		int slideCount = temp1;
		for (int i = 0; i < slideCount; i++) {
			int animCount;
			int noteLen;
			read(fd, &animCount, 4);
			//memcpy(&animCount,buff,4);
			read(fd, &noteLen, 4);
			if (noteLen != 0) {
				char note[noteLen + 1];
				int offset = 0;
				int remain = noteLen;
				while (remain) {
					if (remain < 2048)
						readLen = read(fd, buff, remain);
					else
						readLen = read(fd, buff, 2048);
					memcpy(note + offset, buff, readLen);
					offset += readLen;
					remain -= readLen;
				}
				note[noteLen] = '\0';
				emit slide(i, animCount, QString::fromLatin1(note));
			} else
				emit slide(i, animCount, QString::fromLatin1('\0'));
		}

		emit received();

		QDir dir;
		dir.rmpath("data/image/tempData");
		dir.mkpath("data/image/tempData");
		//dir.mkpath("app/native/assets/images/temp");
		//dir.mkpath("images/tempData");
		QString first("data/image/tempData/s");
		//QString first("app/native/assets/images/temp/s");
		QString last(".png");

		for (int i = 0; i < slideCount; i++) {
			int fileLen;
			read(fd, &fileLen, 4);
			std::cout << fileLen << std::endl;
			//char bufk[fileLen];
			char *bufk = (char*)malloc(fileLen);
			int remain = fileLen;
			int offset = 0;

			/*readLen = read(fd,bufk,fileLen);
			std::cout<<readLen<<std::endl;
			return;*/

			while (remain) {
				if (remain < 2048)
					readLen = read(fd, buff, remain);
				else
					readLen = read(fd, buff, 2048);
				memcpy(bufk + offset, buff, readLen);
				offset += readLen;
				remain -= readLen;
				std::cout<<remain<<std::endl;
				//usleep(1);
			}
			QByteArray ba(bufk, fileLen);
			QImage file = QImage::fromData(ba, "PNG");
			QString no;
			no.setNum(i + 1);
			file.save(first + no + last, "PNG");
			free(bufk);
			//usleep(700000);
			//ba.clear();
		}

		/*long fileLen;
		 read(fd, &fileLen, 8);
		 std::cout << fileLen << std::endl;
		 char bufk[(int) fileLen];
		 int remain = (int) fileLen;
		 int offset = 0;
		 int count = 0;
		 while (remain) {
		 if (remain < 2048)
		 readLen = read(fd, buff, remain);
		 else
		 readLen = read(fd, buff, 2048);
		 memcpy(bufk + offset, buff, readLen);
		 offset += readLen;
		 count += readLen;
		 remain -= readLen;
		 }*/
		//std::cout << count << std::endl;
		//QDir dir;
		//std::cout<<dir.currentPath().toStdString()<<std::endl;
		//dir.mkpath("data/image/tempData");
		/*QFile textfile("data/files/text/newfile.txt");
		 textfile.open(QIODevice::WriteOnly | QIODevice::Text);
		 QTextStream out(&textfile);
		 out << "This is a text file\n";
		 textfile.close();*/

		//QFile file("data/image/tempData/s2.png");
		//QByteArray ba(bufk, (int) fileLen);
		//QImage file = QImage::fromData(ba, "PNG");
		//file.save("data/image/tempData/s2.png", "PNG");
		//file.open(QIODevice::WriteOnly);
		//QDataStream out(&file);
		//out.writeBytes(bufk,(int)fileLen);
		//out<<bufk;
		//file.save(QIODevice::WriteOnly,"PNG");
		/*ofstream outfile;
		 outfile.open("data/images/tempData/s1.png");
		 outfile.write(bufk,(int)fileLen);
		 outfile.close();*/

		/////////Read PNG file
		//Not yet implement.*/
	}
}
Пример #28
0
int main(int argc, char *argv[]) {
	FILE *fp;
	char d;
	int m[100], q[10], n, i, j;

	if (argc != 2) {
		printf("Usage: %s [FILE]\n", argv[0]);
		return 1;
	}
	fp = fopen(*++argv, "r");
	while ((d = getc(fp)) != EOF) {
		switch (d) {
		case 'R':
			fseek(fp, 6, SEEK_CUR);
			break;
		case 'L':
		case 'D':
			fseek(fp, 5, SEEK_CUR);
			break;
		case 'U':
			fseek(fp, 3, SEEK_CUR);
		}
		fscanf(fp, "%d; ", &n);
		for (i = 0; i < n * n; i++)
			fscanf(fp, "%d%*c", &m[i]);
		for (i = 0; i < n; i++) {
			switch (d) {
			case 'L':
				for (j = 0; j < n; j++)
					q[j] = m[i * n + j];
				slide(q, n);
				for (j = 0; j < n; j++)
					m[i * n + j] = q[j];
				break;
			case 'R':
				for (j = 0; j < n; j++)
					q[n - 1 - j] = m[i * n + j];
				slide(q, n);
				for (j = 0; j < n; j++)
					m[i * n + j] = q[n - 1 - j];
				break;
			case 'U':
				for (j = 0; j < n; j++)
					q[j] = m[j * n + i];
				slide(q, n);
				for (j = 0; j < n; j++)
					m[j * n + i] = q[j];
				break;
			case 'D':
				for (j = 0; j < n; j++)
					q[n - 1 - j] = m[j * n + i];
				slide(q, n);
				for (j = 0; j < n; j++)
					m[j * n + i] = q[n - 1 - j];
			}
		}
		for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				if (j > 0)
					putchar(' ');
				printf("%d", m[i * n + j]);
			}
			if (i < n - 1)
				putchar('|');
		}
		putchar('\n');
	}
	return 0;
}
void
NowPlayingStackedWidget::showNothingPlaying()
{
    slide( 0 );
}
void
NowPlayingStackedWidget::showNowPlaying()
{
    slide( 1 );
}