Exemplo n.º 1
0
address_mask address_mask::operator<<(std::size_t n)const
{
    assert(n <= 32);
    address_mask new_mask(0);
    new_mask.m_value = (m_value << n) & address::UPPER_LIMIT;
    return new_mask;
}
Exemplo n.º 2
0
void game_display::new_turn()
{
	const time_of_day& tod = resources::tod_manager->get_time_of_day();

	if( !first_turn_) {
		const time_of_day& old_tod = resources::tod_manager->get_previous_time_of_day();

		if(old_tod.image_mask != tod.image_mask) {
			surface old_mask(image::get_image(old_tod.image_mask,image::SCALED_TO_HEX));
			surface new_mask(image::get_image(tod.image_mask,image::SCALED_TO_HEX));

			const int niterations = static_cast<int>(10/turbo_speed());
			const int frame_time = 30;
			const int starting_ticks = SDL_GetTicks();
			for(int i = 0; i != niterations; ++i) {

				if(old_mask != nullptr) {
					const fixed_t proportion = ftofxp(1.0) - fxpdiv(i,niterations);
					adjust_surface_alpha(old_mask, proportion);
					tod_hex_mask1.assign(old_mask);
				}

				if(new_mask != nullptr) {
					const fixed_t proportion = fxpdiv(i,niterations);
					adjust_surface_alpha(new_mask, proportion);
					tod_hex_mask2.assign(new_mask);
				}

				invalidate_all();

				const int cur_ticks = SDL_GetTicks();
				const int wanted_ticks = starting_ticks + i*frame_time;
				if(cur_ticks < wanted_ticks) {
					SDL_Delay(wanted_ticks - cur_ticks);
				}
			}
		}

		tod_hex_mask1.assign(nullptr);
		tod_hex_mask2.assign(nullptr);
	}

	first_turn_ = false;

	display::update_tod();

	invalidate_all();
}
Exemplo n.º 3
0
address_prefix address_prefix::common_prefix(const address_prefix & first, const address_prefix & second)
{
    int n = std::min(first.m_mask.bits(), second.m_mask.bits());
    int common_mask_bits = n;
    for(int i = 1; i <= n; i++)
    {
        address_mask mask_i(i);
        if((first.m_addr_prefix & mask_i) != (second.m_addr_prefix & mask_i))
        {
            common_mask_bits = i - 1;
            break;
        }
    }
    address_mask new_mask(common_mask_bits);
    return address_prefix(first.m_addr_prefix & new_mask, new_mask);
}
Exemplo n.º 4
0
  /**
   * [working thread]
   */
  virtual void onJob()
  {
    UndoTransaction undoTransaction(m_writer.context(), "Rotate Canvas");
    DocumentApi api = m_document->getApi();

    // get all sprite cels
    CelList cels;
    m_sprite->getCels(cels);

    // for each cel...
    for (CelIterator it = cels.begin(); it != cels.end(); ++it) {
      Cel* cel = *it;
      Image* image = m_sprite->getStock()->getImage(cel->getImage());

      // change it location
      switch (m_angle) {
        case 180:
          api.setCelPosition(m_sprite, cel,
                             m_sprite->getWidth() - cel->getX() - image->getWidth(),
                             m_sprite->getHeight() - cel->getY() - image->getHeight());
          break;
        case 90:
          api.setCelPosition(m_sprite, cel,
                             m_sprite->getHeight() - cel->getY() - image->getHeight(),
                             cel->getX());
          break;
        case -90:
          api.setCelPosition(m_sprite, cel,
                             cel->getY(),
                             m_sprite->getWidth() - cel->getX() - image->getWidth());
          break;
      }
    }

    // for each stock's image
    for (int i=0; i<m_sprite->getStock()->size(); ++i) {
      Image* image = m_sprite->getStock()->getImage(i);
      if (!image)
        continue;

      // rotate the image
      Image* new_image = Image::create(image->getPixelFormat(),
                                       m_angle == 180 ? image->getWidth(): image->getHeight(),
                                       m_angle == 180 ? image->getHeight(): image->getWidth());
      raster::rotate_image(image, new_image, m_angle);

      api.replaceStockImage(m_sprite, i, new_image);

      jobProgress((float)i / m_sprite->getStock()->size());

      // cancel all the operation?
      if (isCanceled())
        return;        // UndoTransaction destructor will undo all operations
    }

    // rotate mask
    if (m_document->isMaskVisible()) {
      Mask* origMask = m_document->getMask();
      base::UniquePtr<Mask> new_mask(new Mask());
      const gfx::Rect& origBounds = origMask->getBounds();
      int x = 0, y = 0;

      switch (m_angle) {
        case 180:
          x = m_sprite->getWidth() - origBounds.x - origBounds.w;
          y = m_sprite->getHeight() - origBounds.y - origBounds.h;
          break;
        case 90:
          x = m_sprite->getHeight() - origBounds.y - origBounds.h;
          y = origBounds.x;
          break;
        case -90:
          x = origBounds.y;
          y = m_sprite->getWidth() - origBounds.x - origBounds.w;
          break;
      }

      // create the new rotated mask
      new_mask->replace(x, y,
                        m_angle == 180 ? origBounds.w: origBounds.h,
                        m_angle == 180 ? origBounds.h: origBounds.w);
      raster::rotate_image(origMask->getBitmap(), new_mask->getBitmap(), m_angle);

      // Copy new mask
      api.copyToCurrentMask(new_mask);

      // Regenerate mask
      m_document->resetTransformation();
      m_document->generateMaskBoundaries();
    }

    // change the sprite's size
    if (m_angle != 180)
      api.setSpriteSize(m_sprite, m_sprite->getHeight(), m_sprite->getWidth());

    // commit changes
    undoTransaction.commit();
  }
Exemplo n.º 5
0
int				main(int ac, char **av)
{
	// t_num		**list;
	t_num								*one;
	t_mask								*nmask;
	t_mask								**lmask;
	t_env								*e;
	int									*pl;
	register unsigned long int 			acc;
	register unsigned long int 	upper_lim;
	register unsigned long int 	lower_lim;
	// int			i;
	// printf("IN\n");
	// if (ac == 2)
	// 	if (!init_all(e, 100))
	// 		mlx_loop(e->mlx);
	acc = 1;
	pl = (int *)malloc(sizeof(int) * 6544);
	pl[0] = 1;

	{
		// i = 0;
		e = (t_env *)malloc(sizeof(t_env));

		e->loa = new_num_list(atoi(av[3]));
		maxtree = atoi(av[4]);
		fdout = open(av[5], O_CREAT|O_WRONLY|O_APPEND, 777);
		lenu64 = strlen(av[1]) + 2;
		one = (e->loa[1]);
		lmask = (t_mask **)malloc(sizeof(t_mask *) * 6544);
		nmask = (t_mask *)malloc(sizeof(t_mask ));
		nmask->n = one->n;
		nmask->prev = NULL;
		nmask->next = NULL;
		nmask->l = NULL;
		nmask->r = NULL;
		(*lmask) = nmask;
		int i = 1;
		while ((one = one->next))
		{
				pl[i] = one->n;
			i++;
			// printf("N: %d\n", nmask->n);
			nmask = new_mask(nmask, one->n);
		}
		pl[i] = 0;
		// (*lmask) = nmask->next;
		nmask = lmask[0];
		// while ((nmask = nmask->next))
		{
			// printf("N: %d\n", nmask->n);
		}
		// i = 0;
		// while (pl[i])
		// 	printf("%d\n", pl[i++]);
		// nmask = lmask[0]->next;
		nmask->n = 1;
		// printf("mask: %d\n", nmask->n);		
		// printf("mask2: %d\n", nmask->next->n);		
		// printf("mask3: %d\n", nmask->next->next->n);	
		{
			// pl += 9;
			// acc = 1938;
		}
		long int margin = atol(av[2]);
		unsigned long int target = atol(av[1]);
		lower_lim = (unsigned long int)(margin);
		upper_lim = (unsigned long int)(target);
		// lower_lim = (unsigned long int)(target - margin);
		// upper_lim = (unsigned long int)(target + margin);
		// unsigned long int lim


		// printf("Margin: %ld\n", margin);
		// printf("TARGET:%ld\n", target);
		// printf("GAP Range:%ld\n", upper_lim - lower_lim);
		// printf("Lower Limit:%ld\n", lower_lim);
		// printf("Upper Limit:%ld\n", upper_lim);
		// printf("Start %d\n", (int)getpid());
		// extern long int mingap;
		mingap = (long int *)malloc(sizeof(long int) * 1000);
		// mingap[0] = -1;
		new_level(pl, acc, upper_lim, lower_lim, 0);
		// curse_mask_tab(pl, acc, upper_lim, lower_lim);

		// curse_mask(nmask, acc);

		// printf("IN!\n");
		// one = (*list);
		// while (((*list) = (*list)->next) )//&& i < atoi(av[1]))
		// {
		// 	// printf("ZERO0: %lx\n", (long)(one));
		// 	// printf("ZERO0: %lx\n", (long)(one->next));
		// 	// if ((*list)->s->n == 0 || (*list)->s->n > 96)
		// 	{		
		// 		printf("%d\t", (int)((*list)->n));
		// 		printf("%d\n", (int)((*list)->m));
		// 		// printf("\t= \t%d   \t\t* ", (int)((*list)->l->n));
		// 		// printf("\t%d\n", (int)((*list)->s->n));
		// 	}
		// 	// printf("adr: \t\t%lx\n", (long)(*list));
		// 	i++;
		// }
		// free(list);
	}
	free(e);
	// int i = 0;
	// while (mingap[i])
	// 	printf("MinGap FINAL: %ld\n", mingap[i++]);
	return (0);
}
Exemplo n.º 6
0
static int parse_mask( Lexer* lexer, cfx2_Mask** mask_ptr )
{
    cfx2_Mask* mask;
    Token tok;
    int error;

    error = lexer_read( lexer, &tok );

    if ( error )
        return error;

    /*
        If the mask begins with an '*', it is either followed by a string
        (a right-piece mask) or is actually no a mask at all
    */
    if ( tok.type == T_asterisk )
    {
        /* drop the '*' token and peek at the next one */
        error = lexer_get_current( lexer, &tok );

        /* it is a pure text token - we've got a right-piece mask */
        if ( !error && tok.type == T_text && !is_keyword( &tok ) )
        {
            error = lexer_read( lexer, &tok );

            if ( error )
                return error;

            mask = new_mask( tok.text, cfx2_piece_right );
            lexer_delete_token( &tok );

            *mask_ptr = mask;
            return mask ? cfx2_ok : cfx2_alloc_error;
        }
        else if ( error && error != cfx2_EOF )
            return error;

        *mask_ptr = 0;
        return cfx2_ok;
    }
    /*
        If the mask begins with a string, it is either followed by an '*'
        (a left-piece mask) or is a full-name mask
    */
    else if ( tok.type == T_text )
    {
        /* can not drop the old token yet, gonna need it */
        Token next;

        error = lexer_get_current( lexer, &next );

        /* an '*' - we've got a left-piece mask */
        if ( !error && next.type == T_asterisk )
        {
            error = lexer_read( lexer, &next );

            if ( error )
            {
                lexer_delete_token( &tok );
                return error;
            }

            mask = new_mask( tok.text, cfx2_piece_left );
            lexer_delete_token( &tok );

            *mask_ptr = mask;
            return mask ? cfx2_ok : cfx2_alloc_error;
        }
        else if ( error && error != cfx2_EOF )
        {
            lexer_delete_token( &tok );
            return error;
        }

        /* a full-name mask */
        mask = new_mask( tok.text, cfx2_piece_full );
        lexer_delete_token( &tok );

        *mask_ptr = mask;
        return mask ? cfx2_ok : cfx2_alloc_error;
    }

    error = cfx2_syntax_error;
    lexer->input->handle_error( lexer->input, error, lexer->line, "Expected mask near TODO" );
    return error;
}
Exemplo n.º 7
0
  // [working thread]
  virtual void onJob()
  {
    Transaction transaction(m_writer.context(), "Rotate Canvas");
    DocumentApi api = m_document->getApi(transaction);

    // 1) Rotate cel positions
    for (Cel* cel : m_cels) {
      Image* image = cel->image();
      if (!image)
        continue;

      switch (m_angle) {
        case 180:
          api.setCelPosition(m_sprite, cel,
            m_sprite->width() - cel->x() - image->width(),
            m_sprite->height() - cel->y() - image->height());
          break;
        case 90:
          api.setCelPosition(m_sprite, cel,
            m_sprite->height() - cel->y() - image->height(),
            cel->x());
          break;
        case -90:
          api.setCelPosition(m_sprite, cel,
            cel->y(),
            m_sprite->width() - cel->x() - image->width());
          break;
      }
    }

    // 2) Rotate images
    int i = 0;
    for (Cel* cel : m_cels) {
      Image* image = cel->image();
      if (image) {
        ImageRef new_image(Image::create(image->pixelFormat(),
            m_angle == 180 ? image->width(): image->height(),
            m_angle == 180 ? image->height(): image->width()));
        doc::rotate_image(image, new_image.get(), m_angle);

        api.replaceImage(m_sprite, cel->imageRef(), new_image);
      }

      jobProgress((float)i / m_cels.size());
      ++i;

      // cancel all the operation?
      if (isCanceled())
        return;        // Transaction destructor will undo all operations
    }

    // rotate mask
    if (m_document->isMaskVisible()) {
      Mask* origMask = m_document->mask();
      base::UniquePtr<Mask> new_mask(new Mask());
      const gfx::Rect& origBounds = origMask->bounds();
      int x = 0, y = 0;

      switch (m_angle) {
        case 180:
          x = m_sprite->width() - origBounds.x - origBounds.w;
          y = m_sprite->height() - origBounds.y - origBounds.h;
          break;
        case 90:
          x = m_sprite->height() - origBounds.y - origBounds.h;
          y = origBounds.x;
          break;
        case -90:
          x = origBounds.y;
          y = m_sprite->width() - origBounds.x - origBounds.w;
          break;
      }

      // create the new rotated mask
      new_mask->replace(
        gfx::Rect(x, y,
          m_angle == 180 ? origBounds.w: origBounds.h,
          m_angle == 180 ? origBounds.h: origBounds.w));
      doc::rotate_image(origMask->bitmap(), new_mask->bitmap(), m_angle);

      // Copy new mask
      api.copyToCurrentMask(new_mask);

      // Regenerate mask
      m_document->resetTransformation();
      m_document->generateMaskBoundaries();
    }

    // change the sprite's size
    if (m_rotateSprite && m_angle != 180)
      api.setSpriteSize(m_sprite, m_sprite->height(), m_sprite->width());

    // commit changes
    transaction.commit();
  }