示例#1
0
文件: lldi.c 项目: magouin/Corewar
void		ft_lldi(t_env *env, t_process *proc)
{
	t_list	*params;
	int		value;
	int		op_size;

	op_size = calculate_size(env->arena[proc->pc + 1], 3, 2);
	params = get_parameters(env, proc);
	if (count_t_param(params) != 3
			|| va(1, 1, 1, (t_param *)params->content) == -1
			|| va(1, 1, 0, (t_param *)params->next->content) == -1
			|| va(1, 0, 0, (t_param *)params->next->next->content) == -1)
	{
		proc->pc = ft_mod((proc->pc + op_size + 2) % MEM_SIZE);
		ft_free(params);
		return ;
	}
	value = ft_getnumber(env->arena, proc->pc
				+ (((t_param *)params->content)->real_value
				+ ((t_param *)params->next->content)->real_value), 4);
	proc->reg[((t_param *)params->next->next->content)->value - 1] = value;
	if (env->flags->v && env->flags->verbose->show_operations)
		verb_lldi(params, proc);
	proc->pc = ft_mod((proc->pc + op_size + 2) % MEM_SIZE);
	proc->carry = (value == 0) ? 1 : 0;
	ft_free(params);
}
示例#2
0
bool DictList::init_list(const SingleCharItem *scis, size_t scis_num,
                         const LemmaEntry *lemma_arr, size_t lemma_num) {
  if (NULL == scis || 0 == scis_num || NULL == lemma_arr || 0 == lemma_num)
    return false;

  initialized_ = false;

  if (NULL != buf_)
    free(buf_);

  // calculate the size
  size_t buf_size = calculate_size(lemma_arr, lemma_num);
  if (0 == buf_size)
    return false;

  if (!alloc_resource(buf_size, scis_num))
    return false;

  fill_scis(scis, scis_num);

  // Copy the related content from the array to inner buffer
  fill_list(lemma_arr, lemma_num);

  initialized_ = true;
  return true;
}
示例#3
0
文件: ld.c 项目: magouin/Corewar
void			ft_ld(t_env *env, t_process *proc)
{
	t_list	*params;
	int		op_size;
	t_param **param;

	params = get_parameters(env, proc);
	op_size = calculate_size(env->arena[(proc->pc + 1) % MEM_SIZE], 2, 4);
	if (!(param = check_params(params)))
	{
		proc->pc = ft_mod((proc->pc + op_size + 2) % MEM_SIZE);
		ft_free(params);
		return ;
	}
	proc->carry = 0;
	if (param[0]->type == IND_CODE)
		proc->reg[param[1]->value - 1] = ft_getnumber(env->arena
			, (proc->pc + param[0]->value % IDX_MOD) % MEM_SIZE, 4);
	else
		proc->reg[param[1]->value - 1] = param[0]->value;
	if (env->flags->v && env->flags->verbose->show_operations)
		verb_ld(proc, param);
	proc->pc = ft_mod((proc->pc + op_size + 2) % MEM_SIZE);
	if (proc->reg[param[1]->value - 1] == 0)
		proc->carry = 1;
	ft_free(params);
	free(param);
}
示例#4
0
文件: sub.c 项目: magouin/Corewar
void			ft_sub(t_env *env, t_process *proc)
{
	t_list	*params;
	t_param	**param;
	int		op_size;

	params = get_parameters(env, proc);
	op_size = calculate_size(env->arena[(proc->pc + 1) % MEM_SIZE], 3, 4);
	if (!(param = check_params(params)))
	{
		proc->pc = ft_mod((proc->pc + op_size + 2) % MEM_SIZE);
		ft_free(params);
		return ;
	}
	proc->carry = 0;
	proc->reg[param[2]->value - 1] = param[0]->real_value
		- param[1]->real_value;
	if (env->flags->v && env->flags->verbose->show_operations)
		verb_sub(env, proc);
	proc->pc = ft_mod((proc->pc + op_size + 2) % MEM_SIZE);
	if (proc->reg[param[2]->value - 1] == 0)
		proc->carry = 1;
	ft_free(params);
	free(param);
}
示例#5
0
button::button(CVideo& video, const std::string& label, button::TYPE type,
               std::string button_image_name, SPACE_CONSUMPTION spacing, const bool auto_join)
	: widget(video, auto_join), type_(type), label_(label),
	  image_(NULL), pressedImage_(NULL), activeImage_(NULL), pressedActiveImage_(NULL),
	  button_(true), state_(NORMAL), pressed_(false),
	  spacing_(spacing), base_height_(0), base_width_(0)
{
	if(button_image_name.empty() && type == TYPE_PRESS) {
		button_image_name = "button";
	} else if(button_image_name.empty() && type == TYPE_CHECK) {
		button_image_name = "checkbox";
	}

	const std::string button_image_file = "buttons/" + button_image_name + ".png";
	surface button_image(image::get_image(button_image_file));
	surface pressed_image(image::get_image("buttons/" + button_image_name + "-pressed.png"));
	surface active_image(image::get_image("buttons/" + button_image_name + "-active.png"));
	surface pressed_active_image;

	if (pressed_image.null())
		pressed_image.assign(button_image);

	if (active_image.null())
		active_image.assign(button_image);

	if (type == TYPE_CHECK) {
		pressed_active_image.assign(image::get_image("buttons/" + button_image_name + "-active-pressed.png"));
		if (pressed_active_image.null())
			pressed_active_image.assign(pressed_image);
	}

	if (button_image.null()) {
		ERR_DP << "error initializing button!\n";
		throw error();
	}

	base_height_ = button_image->h;
	base_width_ = button_image->w;

	if (type_ != TYPE_IMAGE){
		set_label(label);
	}

	if(type == TYPE_PRESS) {
		image_.assign(scale_surface(button_image,location().w,location().h));
		pressedImage_.assign(scale_surface(pressed_image,location().w,location().h));
		activeImage_.assign(scale_surface(active_image,location().w,location().h));
	} else {
		image_.assign(scale_surface(button_image,button_image->w,button_image->h));
		pressedImage_.assign(scale_surface(pressed_image,button_image->w,button_image->h));
		activeImage_.assign(scale_surface(active_image,button_image->w,button_image->h));
		if (type == TYPE_CHECK)
			pressedActiveImage_.assign(scale_surface(pressed_active_image, button_image->w, button_image->h));
	}

	if (type_ == TYPE_IMAGE){
		calculate_size();
	}
}
示例#6
0
 LBData(const par::communicator& comm, unsigned int s) :
         size(par::comm_world().size()), cut(0),
         bin(par::comm_world().size()),
         new_size(par::comm_world().size()),
         send(0), recv(0),
         sendcounts(par::comm_world().size()),
         recvcounts(par::comm_world().size()),
         sdispls(par::comm_world().size()),
         rdispls(par::comm_world().size()) {
         calculate_size(comm, s);
 }
示例#7
0
        void change_comm(const par::communicator& comm, unsigned int s) {
                const unsigned int num_proc = comm.size();
                size.resize(num_proc);
                bin.resize(num_proc);
                new_size.resize(num_proc);
                sendcounts.resize(num_proc);
                recvcounts.resize(num_proc);
                sdispls.resize(num_proc);
                rdispls.resize(num_proc);

                calculate_size(comm, s);
        }
示例#8
0
void
DjVuFileCache::set_max_size(int xmax_size)
{
   DEBUG_MSG("DjVuFileCache::set_max_size(): resizing to " << xmax_size << "\n");
   DEBUG_MAKE_INDENT(3);

   GCriticalSectionLock lock(&class_lock);
   
   max_size=xmax_size;
   cur_size=calculate_size();

   if (max_size>=0) clear_to_size(enabled ? max_size : 0);
}
示例#9
0
void button::set_label(const std::string& val)
{
	label_ = val;

	//if we have a list of items, use the first one that isn't an image
	if (std::find(label_.begin(), label_.end(), COLUMN_SEPARATOR) != label_.end()) {
		const std::vector<std::string>& items = utils::split(label_, COLUMN_SEPARATOR);
		const std::vector<std::string>::const_iterator i = std::find_if(items.begin(),items.end(),not_image);
		if(i != items.end()) {
			label_ = *i;
		}
	}

	calculate_size();

	set_dirty(true);
}
示例#10
0
int BufferCollection::encode(int version, BufferVec* bufs) const {
  if (version != 1 && version != 2) return -1;

  int value_size = sizeof(uint16_t) + calculate_size(version);
  int buf_size = sizeof(int32_t) + value_size;

  Buffer buf(buf_size);

  int pos = 0;
  pos = buf.encode_int32(pos, value_size);
  pos = buf.encode_uint16(pos, is_map_ ? bufs_.size() / 2 : bufs_.size());

  encode(version, buf.data() + pos);

  bufs->push_back(buf);

  return buf_size;
}
示例#11
0
/**
 * @name	core_tick
 * @brief	moves the game forward by a single tick, defined by a time delta of
 *			last tick to this tick
 * @param	dt - (int) elapsed time from last tick to this tick in milliseconds
 * @retval	NONE
 */
void core_tick(int dt) {
	if (js_ready) {
		core_timer_tick(dt);
		js_tick(dt);
	}

	// Tick the texture manager (load pending textures)
	texture_manager_tick(texture_manager_get());
	/*
	 * we need to wait 2 frames before removing the preloader after we get the
	 * core_hide_preloader call from JS.  Only on the second frame after the
	 * callback are the images that were preloaded actually drawn.
	 */

	if (show_preload || preload_hide_frame_count < 2) {
		//if we've gotten the core_hide_preloader cb, start counting frames
		if (!show_preload) {
			preload_hide_frame_count++;
		}

		texture_2d *tex = texture_manager_get_texture(texture_manager_get(), "loading.png");

		if (tex && tex->loaded) {
			if (do_sizing) {
				calculate_size(tex);
				do_sizing = false;
			}

			context_2d *ctx = context_2d_get_onscreen(tealeaf_canvas_get());
			context_2d_loadIdentity(ctx);
			context_2d_clear(ctx);
			context_2d_drawImage(ctx, 0, "loading.png", &tex_size, &size, 0);
			// we're the first, last, and only thing to draw, so flush the buffer
			context_2d_flush(ctx);
		}
	}

    // check the gl error and send it to java to be logged
    if (js_ready) {
        core_check_gl_error();
    }
}
示例#12
0
void
DjVuFileCache::del_file(const DjVuFile * file)
{
   DEBUG_MSG("DjVuFileCache::del_file(): Removing an item from cache\n");
   DEBUG_MAKE_INDENT(3);

   GCriticalSectionLock lock(&class_lock);

   for(GPosition pos=list;pos;++pos)
      if (list[pos]->get_file()==file)
      {
	 GP<DjVuFile> file=list[pos]->get_file();
	 cur_size-=list[pos]->get_size();
	 list.del(pos);
	 file_deleted(file);
	 break;
      }
   if (cur_size<0) cur_size=calculate_size();
   DEBUG_MSG("current cache size=" << cur_size << "\n");
}
示例#13
0
static void apply_size_penalty(struct list *bundle_info)
{
	struct bundle_result *b;
	struct list *ptr;

	ptr = list_head(results);

	while (ptr) {
		b = ptr->data;
		ptr = ptr->next;

		/* unsee all bundles before calculating size */
		unsee_bundle_results(bundle_info);
		/* calculate bundle size for recursive includes */
		b->size = calculate_size(b->bundle_name, bundle_info, b->is_tracked);
		/* Arbitrarily assign a score penalty based on how large the bundle is.
		 * This is set to negative 1/10th of the bundle size. */
		b->score -= (0.01 * b->size);
	}
}
示例#14
0
/* recursively calculate size from a complete list of bundle_result structs */
static long calculate_size(char *bname, struct list *bundle_info, bool installed)
{
	struct list *ptr;
	struct bundle_result *bi;
	long size = 0;
	ptr = list_head(bundle_info);
	while (ptr) {
		bi = ptr->data;
		ptr = ptr->next;
		if (bi->seen || strcmp(bname, bi->bundle_name) != 0) {
			continue;
		}

		/* If installed is true the initial call to this recursive
		 * function was for an installed bundle. In this case we want
		 * to calculate the contentsize of all included bundles (we
		 * know they are all installed already) so we can report the
		 * total installed size on the system.
		 *
		 * Otherwise only add the contentsize of bundles not already
		 * installed on the system. */
		if (installed || !is_tracked_bundle(bname)) {
			size += bi->topsize;
			bi->seen = true;
		}

		/* add bundle sizes for includes as well */
		struct list *ptr2;
		ptr2 = list_head(bi->includes);
		while (ptr2) {
			char *inc = NULL;
			inc = ptr2->data;
			ptr2 = ptr2->next;
			/* recursively add included sizes */
			size += calculate_size(inc, bundle_info, installed);
		}
	}

	return size;
}
示例#15
0
文件: button.cpp 项目: gb056/wesnoth
void button::set_label(const std::string& val)
{
	label_text_ = val;

	//if we have a list of items, use the first one that isn't an image
	if (std::find(label_text_.begin(), label_text_.end(), COLUMN_SEPARATOR) != label_text_.end()) {
		const std::vector<std::string>& items = utils::split(label_text_, COLUMN_SEPARATOR);
		const std::vector<std::string>::const_iterator i = std::find_if(items.begin(),items.end(),not_image);
		if(i != items.end()) {
			label_text_ = *i;
		}
	}

	calculate_size();
#ifdef SDL_GPU
	font::ttext text;
	text.set_text(label_text_, false);
	label_image_ = text.render_as_texture();
#endif

	set_dirty(true);
}
示例#16
0
文件: chelper.c 项目: queer1/forge
main (int argc, char **argv) {
  char *params[10], *lodevice;
  char *prefix, *fname, *mountpoint;
  pid_t pid, cluster_size=0;
  int status,opt=0,q=0;
  long size=0;

#ifdef PATH  
  if (strlen(PATH) > MAX_PATH_LENGTH) {
    fprintf(stderr, "too long PATH\n");
    exit(1);
  }
  prefix = malloc(sizeof(char)*strlen(PATH)+1);
  if (prefix == NULL) {
    perror(PNAME);
    exit(1);
  }
  strcpy (prefix,PATH);
#else
#error "must define PATH"
#endif

#ifdef MOUNTPOINT
  if (strlen(MOUNTPOINT) > MAX_PATH_LENGTH) {
    fprintf(stderr, "too long MOUNTPOINT\n");
    exit(1);
  }
  mountpoint = malloc(sizeof(char)*strlen(MOUNTPOINT)+1);
  if (mountpoint == NULL) {
    perror(PNAME);
    exit(1);
  }
  strcpy (mountpoint,MOUNTPOINT);
  sanitize_path(mountpoint);
#else
#error "must define MOUNTPOINT"
#endif

  if (argc < 2) {
    fprintf(stderr,"Usage: %s [create fstype size cluster_size name [clean | random] filename | attach fstype filename | detach]\n", PNAME);
    exit(1);
  }

  if (strcmp(argv[1], "create") == 0) {
    if (argc < 2) {
      fprintf(stderr,"Usage: %s create ntfs|FAT16 ...\n", PNAME);
      exit(1);
    }
    if (strcmp(argv[2], "ntfs") == 0) {
      if (argc != 8) {
	fprintf(stderr,"Usage: %s create fstype size cluster_size name [clean | random] filename\n", PNAME);
	exit(1);
      }
      /* freopen("/dev/null","w",stderr);*/
      if (strlen(argv[3]) > 12) {
	fprintf(stderr,"Too long size parameter\n");
	exit(1);
      }
      size = calculate_size(argv[3]);
      if (strlen(argv[7]) > MAX_PATH_LENGTH) {
	fprintf(stderr, "Too long parameter %s\n", argv[7]);
	exit(1);
      }
      fname = malloc(sizeof(char)*strlen(argv[7])+1);
      if (fname == NULL) {
	perror(PNAME);
	exit(1);
      }
      strcpy(fname, argv[7]);
      if ((atoi(argv[4]) < 1 || atoi (argv[4]) > 32) || atoi(argv[4]) & 1) {
	fprintf(stderr,"Cluster size must be a multiple of 2 and max 32\n");
	exit(1);
      }
      cluster_size = atoi(argv[4])*512;

      /* Generally we could be more allowing here but use the same routine
	 for reasons of pure laziness. 
	 Technically only white space, ?, *, " and ' should be really 
	 frowned upon here 
      */
      sanitize_path(argv[5]);
      if (strlen(argv[5]) > 20) {
	fprintf(stderr, "too long parameter %s", argv[5]);
	exit(1);
      }
      if (strcmp(argv[6], "random") == 0) {
	create_file(prefix, fname, size, C_RANDOM);
      } 
      else {
	create_file(prefix, fname, size, C_ZERO);
      }
      create_ntfs_filesystem(prefix, fname, argv[5], cluster_size);
      exit(0);
    }
    if ((strcmp(argv[2], "FAT16") == 0) || (strcmp(argv[2],"FAT32") == 0) || (strcmp(argv[2], "FAT12") == 0) || 
	(strcmp(argv[2], "GENERICFAT") == 0)) {
      if (argc != 9) {
	fprintf(stderr,"Usage: %s create FAT16|FAT12|FAT32 size cluster_size sector_size name [clean | random] filename\n", PNAME);
	exit(1);
      }
      /* freopen("/dev/null","w",stderr);*/
      if (strlen(argv[3]) > 12) {
	fprintf(stderr,"Too long size parameter\n");
	exit(1);
      }
      size = calculate_size(argv[3]);
      if (strlen(argv[8]) > MAX_PATH_LENGTH) {
	fprintf(stderr, "Too long parameter %s\n", argv[8]);
	exit(1);
      }
      fname = malloc(sizeof(char)*strlen(argv[7])+1);
      if (fname == NULL) {
	perror(PNAME);
	exit(1);
      }
      strcpy(fname, argv[8]);
      if ((atoi(argv[4]) < 1 || atoi (argv[4]) > 32) || atoi(argv[4]) & 1) {
	fprintf(stderr,"Cluster size must be a multiple of 2 and max 32\n");
	exit(1);
      }
      cluster_size = atoi(argv[4])*512;
      if ((atoi(argv[5]) < 512 || atoi (argv[5]) > 32768) || (atoi(argv[5]) & (atoi(argv[5])-1))) {
	fprintf(stderr,"Sector size must be a multiple of 512, max 32768 and a power of two\n");
	exit(1);
      }
      /* Generally we could be more allowing here but use the same routine
	 for reasons of pure laziness. 
	 Technically only white space, ?, *, " and ' should be really 
	 frowned upon here 
      */
      sanitize_path(argv[6]);
      if (strlen(argv[6]) > 11) {
	fprintf(stderr, "too long parameter %s (max 11 chars)\n", argv[6]);
	exit(1);
      }

      if (strcmp(argv[7], "random") == 0) {
	create_file(prefix, fname, size, C_RANDOM);
      } 
      else {
	create_file(prefix, fname, size, C_ZERO);
      }

      create_fat_filesystem(prefix, argv[2], fname, argv[6], atoi(argv[5]),argv[4]);
      exit(0);
    }
    else {
      fprintf(stderr, "Unknown file system type %s\n", argv[2]);
      exit(1);
    }
  }    


  
  /* Attach */
  if (strcmp(argv[1], "attach") == 0) {
    if (argc != 4) {
      fprintf(stderr,"Usage: %s attach fstype filename\n", PNAME);
      exit(1);
    }
    if (strlen(argv[3]) > MAX_PATH_LENGTH) {
      fprintf(stderr, "Too long parameter %s\n", argv[3]);
      exit(1);
    }
    fname = malloc(sizeof(char)*strlen(argv[3])+1);
    if (fname == NULL) {
      perror(PNAME);
      exit(1);
    }
    strcpy(fname, argv[3]);
    lodevice = attach_file(prefix,fname);
    if (lodevice) {
      if (strcmp(argv[2],"ntfs") == 0) {
	q = mount_ntfs_filesystem(lodevice);
	if (q != 0) 
	  detach_device(lodevice);
	exit(q);
      }
      if (strncmp(argv[2], "FAT",3 ) == 0) {
	q = mount_fat_filesystem(lodevice);
	if (q != 0)
	  detach_device(lodevice);
	exit(q);
      }
      else {
	fprintf(stderr, "unknown file system type %s\n", argv[2]);
	detach_device(lodevice);
	exit(1);
      }
    }
    else
      fprintf (stderr, "Cannot find loopback device\n");
    exit(0);
  }
  
  /* detach */
  if (strcmp(argv[1], "detach") == 0) {
    freopen("/dev/null","w",stderr);
    exit(detach_image());
  }
  fprintf(stderr,"Usage: %s [create fstype size cluster_size name [clean | random] filename | attach fstype filename | detach]\n", PNAME);  
  exit(1);
}
示例#17
0
 static std::size_t round_size(std::size_t orig_size)
 {
    std::size_t pow, frc;
    return calculate_size(orig_size, pow, frc);
 }
示例#18
0
文件: tramp.c 项目: Alkarex/mono
MonoPIFunc
mono_arch_create_trampoline (MonoMethodSignature *sig, gboolean string_ctor)
{
	unsigned int *p;
	unsigned int *buffer;
	MonoType* param;

	int i, pos;
	int alpharegs;
	int hasthis;
	int STACK_SIZE;
	int BUFFER_SIZE;
	int simple_type;
	int regbase;
	
	// Set up basic stuff.  like has this.	
	hasthis = !!sig->hasthis;
	alpharegs = AXP_GENERAL_REGS - hasthis;
	regbase  = hasthis?alpha_a1:alpha_a0 ;
	
	// Make a ballpark estimate for now.
	calculate_size( sig, &BUFFER_SIZE, &STACK_SIZE );
	
	// convert to the correct number of bytes.
	BUFFER_SIZE = BUFFER_SIZE * 4;

	
	// allocate.	
	buffer = p = (unsigned int *)malloc(BUFFER_SIZE);
	memset( buffer, 0, BUFFER_SIZE );
	pos = 8 * (sig->param_count - alpharegs - 1);
	
	// Ok, start creating this thing.
	p = emit_prolog( p, STACK_SIZE, hasthis );

	// copy everything into the correct register/stack space
	for (i = sig->param_count; --i >= 0; ) 
	{
		param = sig->params [i];
		
		if( param->byref )
		{
			if( i >= alpharegs )
			{
				// load into temp register, then store on the stack 
				alpha_ldq( p, alpha_t1, alpha_t0, ARG_LOC( i ));
				alpha_stq( p, alpha_t1, alpha_sp, pos );
				pos -= 8;
			}
			else
			{
				// load into register
				alpha_ldq( p, (regbase + i), alpha_t0, ARG_LOC( i ) );
			}
		}
		else
		{
			simple_type = param->type;
			if( simple_type == MONO_TYPE_VALUETYPE )
			{
                        	if (param->data.klass->enumtype)
                                	simple_type = param->data.klass->enum_basetype->type;
                        }
			
			switch (simple_type) 
			{
			case MONO_TYPE_VOID:
				break;
			case MONO_TYPE_BOOLEAN:
			case MONO_TYPE_CHAR:
			case MONO_TYPE_I1:
			case MONO_TYPE_U1:
			case MONO_TYPE_I2:
			case MONO_TYPE_U2:
			case MONO_TYPE_I4:
			case MONO_TYPE_U4:
				// 4 bytes - need to sign-extend (stackvals are not extended)
				if( i >= alpharegs )
				{
					// load into temp register, then store on the stack
					alpha_ldl( p, alpha_t1, alpha_t0, ARG_LOC( i ) );
					alpha_stq( p, alpha_t1, alpha_sp, pos );
					pos -= 8;
				}
				else
				{
					// load into register
					alpha_ldl( p, (regbase + i), alpha_t0, (ARG_LOC(i)) );
				}
				break;
			case MONO_TYPE_I:
			case MONO_TYPE_U:
			case MONO_TYPE_PTR:
			case MONO_TYPE_CLASS:
			case MONO_TYPE_OBJECT:
			case MONO_TYPE_SZARRAY:
			case MONO_TYPE_STRING:
			case MONO_TYPE_I8:
				// 8 bytes
				if( i >= alpharegs )
				{
					// load into temp register, then store on the stack
					alpha_ldq( p, alpha_t1, alpha_t0, ARG_LOC( i ) );
					alpha_stq( p, alpha_t1, alpha_sp, pos );
					pos -= 8;
				}
				else
				{
					// load into register
					alpha_ldq( p, (regbase + i), alpha_t0, ARG_LOC(i) );
				}
				break;
			case MONO_TYPE_R4:
			case MONO_TYPE_R8:
				/*
				// floating point... Maybe this does the correct thing.
				if( i > alpharegs )
				{
					alpha_ldq( p, alpha_t1, alpha_t0, ARG_LOC( i ) );
					alpha_cpys( p, alpha_ft1, alpha_ft1, alpha_ft2 );
					alpha_stt( p, alpha_ft2, alpha_sp, pos );
					pos -= 8;
				}
				else
				{
					alpha_ldq( p, alpha_t1, alpha_t0, ARG_LOC(i) );
					alpha_cpys( p, alpha_ft1, alpha_ft1, alpha_fa0 + i + hasthis );
				}
				break;
				*/
			case MONO_TYPE_VALUETYPE:
				g_error ("Not implemented: ValueType as parameter to delegate." );
				break;
			default:
				g_error( "Not implemented: 0x%x.", simple_type );
				break;	
			}
		}
	}
	
	// Now call the function and store the return parameter.
	p = emit_call( p, STACK_SIZE );
	p = emit_store_return_default( p, STACK_SIZE );
	p = emit_epilog( p, STACK_SIZE );

	if( p > buffer + BUFFER_SIZE )
		g_error( "Buffer overflow: got 0x%lx, expected <=0x%x.", (long)(p-buffer), BUFFER_SIZE );

	/* flush instruction cache to see trampoline code */
	asm volatile("imb":::"memory");
	
	return (MonoPIFunc)buffer;
}
示例#19
0
void
DjVuFileCache::clear_to_size(int size)
{
   DEBUG_MSG("DjVuFileCache::clear_to_size(): dropping cache size to " << size << "\n");
   DEBUG_MAKE_INDENT(3);

   GCriticalSectionLock lock(&class_lock);
   
   if (size==0)
   {
      list.empty();
      cur_size=0;
   } else
      if (list.size()>20)
      {
	    // More than 20 elements in the cache: use qsort to
	    // sort them before picking up the oldest
	 GTArray<void *> item_arr(list.size()-1);
	 GPosition pos;
	 int i;
	 for(pos=list, i=0;pos;++pos, i++)
	 {
	    GP<Item> item=list[pos];
	    item->list_pos=pos;
	    item_arr[i]=item;
	 }

	 qsort(&item_arr[0], item_arr.size(), sizeof(item_arr[0]), Item::qsort_func);

	 for(i=0;i<item_arr.size() && cur_size>(int) size;i++)
	 {
	    Item * item=(Item *) item_arr[i];
	    cur_size-=item->get_size();
	    GP<DjVuFile> file=item->file;
	    list.del(item->list_pos);
	    file_cleared(file);
	    if (cur_size<=0) cur_size=calculate_size();
	 }
      } else
      {
	    // Less than 20 elements: no reason to presort
	 while(cur_size>(int) size)
	 {
	    if (!list.size())
	    {
		  // Oops. Discrepancy due to an item changed its size
	       cur_size=0;
	       break;
	    }

	       // Remove the oldest cache item
	    GPosition oldest_pos=list;
	    GPosition pos=list;
	    for(++pos;pos;++pos)
	       if (list[pos]->get_time()<list[oldest_pos]->get_time())
		  oldest_pos=pos;
	    cur_size-=list[oldest_pos]->get_size();
	    GP<DjVuFile> file=list[oldest_pos]->file;
	    list.del(oldest_pos);
	    file_cleared(file);

	       // cur_size *may* become negative because items may change their
	       // size after they've been added to the cache
	    if (cur_size<=0) cur_size=calculate_size();
	 }
      }
   
   DEBUG_MSG("done: current cache size=" << cur_size << "\n");
}
示例#20
0
/**
 * @name	core_tick
 * @brief	moves the game forward by a single tick, defined by a time delta of
 *			last tick to this tick
 * @param	dt - (int) elapsed time from last tick to this tick in milliseconds
 * @retval	NONE
 */
void core_tick(int dt) {
	if (js_ready) {
		core_timer_tick(dt);
		js_tick(dt);
	}

	// Tick the texture manager (load pending textures)
	texture_manager_tick(texture_manager_get());
	/*
	 * we need to wait 2 frames before removing the preloader after we get the
	 * core_hide_preloader call from JS.  Only on the second frame after the
	 * callback are the images that were preloaded actually drawn.
	 */

	if (show_preload || preload_hide_frame_count < 2) {
		//if we've gotten the core_hide_preloader cb, start counting frames
		if (!show_preload) {
			preload_hide_frame_count++;

			// May have never loaded the splash image, so hide splash here too
			device_hide_splash();
		}

		// If splash is defined,
		const char *splash = config_get_splash();
		if (splash) {
			texture_2d *tex = texture_manager_get_texture(texture_manager_get(), splash);
			if (!tex) {
				tex = texture_manager_load_texture(texture_manager_get(), splash);
			}

			if (tex && tex->loaded) {
				if (do_sizing) {
					// Calculate rotation
					tealeaf_canvas *canvas = tealeaf_canvas_get();
					int canvas_width = canvas->framebuffer_width;
					int canvas_height = canvas->framebuffer_height;
					rotate = canvas_width > canvas_height;
					rotate ^= tex->originalWidth > tex->originalHeight;

					calculate_size(tex, rotate);
					do_sizing = false;
				}

				context_2d *ctx = context_2d_get_onscreen(tealeaf_canvas_get());
				context_2d_loadIdentity(ctx);
				context_2d_clear(ctx);
				if (rotate) {
					context_2d_save(ctx);
					context_2d_translate(ctx, size.y + (size.height)/2.f/tex->scale, size.x + (size.width)/2.f/tex->scale);
					context_2d_rotate(ctx, (tex->originalWidth > tex->originalHeight)? -3.14f/2.f : 3.14f/2.f);
					context_2d_translate(ctx, -size.x -(size.width)/2.f/tex->scale, -size.y - (size.height)/2.f/tex->scale);
				}
				context_2d_setGlobalCompositeOperation(ctx, source_over);
				context_2d_drawImage(ctx, 0, splash, &tex_size, &size);
				if (rotate) {
					context_2d_restore(ctx);
				}
				// we're the first, last, and only thing to draw, so flush the buffer
				context_2d_flush(ctx);

				device_hide_splash();
			}
		}
	}

    // check the gl error and send it to java to be logged
    if (js_ready) {
        core_check_gl_error();
    }
}
示例#21
0
文件: button.cpp 项目: AI0867/wesnoth
void button::load_images() {

	std::string size_postfix;

	switch (location().h) {
		case 25:
			size_postfix = "_25";
			break;
		case 30:
			size_postfix = "_30";
			break;
		case 60:
			size_postfix = "_60";
			break;
		default:
			break;
	}

	surface button_image(image::get_image(button_image_name_ + ".png" + button_image_path_suffix_));
	surface pressed_image(image::get_image(button_image_name_ + "-pressed.png"+ button_image_path_suffix_));
	surface active_image(image::get_image(button_image_name_ + "-active.png"+ button_image_path_suffix_));
	surface disabled_image;
	if (file_exists(game_config::path + "/images/" + button_image_name_ + "-disabled.png"+ button_image_path_suffix_))
		disabled_image.assign((image::get_image(button_image_name_ + "-disabled.png"+ button_image_path_suffix_)));
	surface pressed_disabled_image, pressed_active_image, touched_image;

	if (!button_overlay_image_name_.empty()) {
		overlayImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + ".png"+ button_image_path_suffix_));
		overlayPressedImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-pressed.png"+ button_image_path_suffix_));

		if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-active.png"+ button_image_path_suffix_))
			overlayActiveImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-active.png"+ button_image_path_suffix_));

		if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled.png"+ button_image_path_suffix_))
			overlayDisabledImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-disabled.png"+ button_image_path_suffix_));
		if (overlayDisabledImage_.null())
			overlayDisabledImage_ = image::get_image(button_overlay_image_name_ + size_postfix + ".png~GS()" + button_image_path_suffix_);

		if (file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_))
			overlayPressedDisabledImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_));
		if (overlayPressedDisabledImage_.null())
			overlayPressedDisabledImage_ = image::get_image(button_overlay_image_name_ + size_postfix + "-pressed.png~GS()"+ button_image_path_suffix_);
	} else {
		overlayImage_.assign(NULL);
	}

	if (disabled_image == NULL) {
		disabled_image = image::get_image(button_image_name_ + ".png~GS()" + button_image_path_suffix_);
	}

	if (pressed_image.null())
		pressed_image.assign(button_image);

	if (active_image.null())
		active_image.assign(button_image);

	if (type_ == TYPE_CHECK || type_ == TYPE_RADIO) {
		touched_image.assign(image::get_image(button_image_name_ + "-touched.png"+ button_image_path_suffix_));
		if (touched_image.null())
			touched_image.assign(pressed_image);

		pressed_active_image.assign(image::get_image(button_image_name_ + "-active-pressed.png"+ button_image_path_suffix_));
		if (pressed_active_image.null())
			pressed_active_image.assign(pressed_image);

		if (file_exists(game_config::path + "/images/" + button_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_))
			pressed_disabled_image.assign(image::get_image(button_image_name_ + "-disabled-pressed.png"+ button_image_path_suffix_));
		if (pressed_disabled_image.null())
			pressed_disabled_image = image::get_image(button_image_name_ + "-pressed.png~GS()"+ button_image_path_suffix_);
	}

	if (button_image.null()) {
		ERR_DP << "error initializing button!\n";
		throw error();
	}

	base_height_ = button_image->h;
	base_width_ = button_image->w;

	if (type_ != TYPE_IMAGE) {
		set_label(label_);
	}

	if(type_ == TYPE_PRESS || type_ == TYPE_TURBO) {
		image_.assign(scale_surface(button_image,location().w,location().h));
		pressedImage_.assign(scale_surface(pressed_image,location().w,location().h));
		activeImage_.assign(scale_surface(active_image,location().w,location().h));
		disabledImage_.assign(scale_surface(disabled_image,location().w,location().h));
	} else {
		image_.assign(scale_surface(button_image,button_image->w,button_image->h));
		activeImage_.assign(scale_surface(active_image,button_image->w,button_image->h));
		disabledImage_.assign(scale_surface(disabled_image,button_image->w,button_image->h));
		pressedImage_.assign(scale_surface(pressed_image,button_image->w,button_image->h));
		if (type_ == TYPE_CHECK || type_ == TYPE_RADIO) {
			pressedDisabledImage_.assign(scale_surface(pressed_disabled_image,button_image->w,button_image->h));
			pressedActiveImage_.assign(scale_surface(pressed_active_image, button_image->w, button_image->h));
			touchedImage_.assign(scale_surface(touched_image, button_image->w, button_image->h));
		}
	}

	if (type_ == TYPE_IMAGE){
		calculate_size();
	}
}
示例#22
0
文件: button.cpp 项目: gb056/wesnoth
void button::load_images() {

	std::string size_postfix;

	switch (location().h) {
		case 25:
			size_postfix = "_25";
			break;
		case 30:
			size_postfix = "_30";
			break;
		case 60:
			size_postfix = "_60";
			break;
		default:
			break;
	}
#ifdef SDL_GPU
	sdl::timage button_image(image::get_texture(button_image_name_ + ".png" + button_image_path_suffix_));
	sdl::timage pressed_image(image::get_texture(button_image_name_ + "-pressed.png"+ button_image_path_suffix_));
	sdl::timage active_image(image::get_texture(button_image_name_ + "-active.png"+ button_image_path_suffix_));
	sdl::timage disabled_image;
	if (filesystem::file_exists(game_config::path + "/images/" + button_image_name_ + "-disabled.png"))
		disabled_image = image::get_texture(button_image_name_ + "-disabled.png"+ button_image_path_suffix_);
	sdl::timage pressed_disabled_image, pressed_active_image, touched_image;

	if (!button_overlay_image_name_.empty()) {
		overlayImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + ".png"+ button_image_path_suffix_);
		overlayPressedImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-pressed.png"+ button_image_path_suffix_);

		if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-active.png"))
			overlayActiveImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-active.png"+ button_image_path_suffix_);

		if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled.png"))
			overlayDisabledImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-disabled.png"+ button_image_path_suffix_);
		if (overlayDisabledImage_.null())
			overlayDisabledImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + ".png~GS()" + button_image_path_suffix_);

		if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled-pressed.png"))
			overlayPressedDisabledImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-disabled-pressed.png");
		if (overlayPressedDisabledImage_.null())
			overlayPressedDisabledImage_ = image::get_texture(button_overlay_image_name_ + size_postfix + "-pressed.png~GS()"+ button_image_path_suffix_);
	} else {
		overlayImage_ = sdl::timage();
	}

	if (disabled_image.null()) {
		disabled_image = image::get_texture(button_image_name_ + ".png~GS()" + button_image_path_suffix_);
	}

	if (pressed_image.null())
		pressed_image = button_image;

	if (active_image.null())
		active_image = button_image;

	if (type_ == TYPE_CHECK || type_ == TYPE_RADIO) {
		touched_image = image::get_texture(button_image_name_ + "-touched.png"+ button_image_path_suffix_);
		if (touched_image.null())
			touched_image = pressed_image;

		pressed_active_image = (image::get_texture(button_image_name_ + "-active-pressed.png"+ button_image_path_suffix_));
		if (pressed_active_image.null())
			pressed_active_image = pressed_image;

		if (filesystem::file_exists(game_config::path + "/images/" + button_image_name_ + size_postfix + "-disabled-pressed.png"))
			pressed_disabled_image = image::get_texture(button_image_name_ + "-disabled-pressed.png"+ button_image_path_suffix_);
		if (pressed_disabled_image.null())
			pressed_disabled_image = image::get_texture(button_image_name_ + "-pressed.png~GS()"+ button_image_path_suffix_);
	}

	if (button_image.null()) {
		ERR_DP << "error initializing button!" << std::endl;
		throw error();
	}

	base_height_ = button_image.height();
	base_width_ = button_image.width();

	if (type_ != TYPE_IMAGE) {
		set_label(label_text_);
	}

	image_ = button_image;
	pressedImage_ = pressed_image;
	activeImage_ = active_image;
	disabledImage_ = disabled_image;
	if (type_ == TYPE_CHECK || type_ == TYPE_RADIO) {
		pressedDisabledImage_ = pressed_disabled_image;
		pressedActiveImage_ = pressed_active_image;
		touchedImage_ = touched_image;
	}

	if (type_ == TYPE_IMAGE){
		calculate_size();
	}
#else
	surface button_image(image::get_image(button_image_name_ + ".png" + button_image_path_suffix_));
	surface pressed_image(image::get_image(button_image_name_ + "-pressed.png"+ button_image_path_suffix_));
	surface active_image(image::get_image(button_image_name_ + "-active.png"+ button_image_path_suffix_));
	surface disabled_image;
	if (filesystem::file_exists(game_config::path + "/images/" + button_image_name_ + "-disabled.png"))
		disabled_image.assign((image::get_image(button_image_name_ + "-disabled.png"+ button_image_path_suffix_)));
	surface pressed_disabled_image, pressed_active_image, touched_image;

	if (!button_overlay_image_name_.empty()) {
		overlayImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + ".png"+ button_image_path_suffix_));
		overlayPressedImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-pressed.png"+ button_image_path_suffix_));

		if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-active.png"))
			overlayActiveImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-active.png"+ button_image_path_suffix_));

		if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled.png"))
			overlayDisabledImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-disabled.png"+ button_image_path_suffix_));
		if (overlayDisabledImage_.null())
			overlayDisabledImage_ = image::get_image(button_overlay_image_name_ + size_postfix + ".png~GS()" + button_image_path_suffix_);

		if (filesystem::file_exists(game_config::path + "/images/" + button_overlay_image_name_ + size_postfix + "-disabled-pressed.png"))
			overlayPressedDisabledImage_.assign(image::get_image(button_overlay_image_name_ + size_postfix + "-disabled-pressed.png"+ button_image_path_suffix_));
		if (overlayPressedDisabledImage_.null())
			overlayPressedDisabledImage_ = image::get_image(button_overlay_image_name_ + size_postfix + "-pressed.png~GS()"+ button_image_path_suffix_);
	} else {
		overlayImage_.assign(NULL);
	}

	if (disabled_image == NULL) {
		disabled_image = image::get_image(button_image_name_ + ".png~GS()" + button_image_path_suffix_);
	}

	if (pressed_image.null())
		pressed_image.assign(button_image);

	if (active_image.null())
		active_image.assign(button_image);

	if (type_ == TYPE_CHECK || type_ == TYPE_RADIO) {
		touched_image.assign(image::get_image(button_image_name_ + "-touched.png"+ button_image_path_suffix_));
		if (touched_image.null())
			touched_image.assign(pressed_image);

		pressed_active_image.assign(image::get_image(button_image_name_ + "-active-pressed.png"+ button_image_path_suffix_));
		if (pressed_active_image.null())
			pressed_active_image.assign(pressed_image);

		if (filesystem::file_exists(game_config::path + "/images/" + button_image_name_ + size_postfix + "-disabled-pressed.png"))
			pressed_disabled_image.assign(image::get_image(button_image_name_ + "-disabled-pressed.png"+ button_image_path_suffix_));
		if (pressed_disabled_image.null())
			pressed_disabled_image = image::get_image(button_image_name_ + "-pressed.png~GS()"+ button_image_path_suffix_);
	}

	if (button_image.null()) {
		std::string err_msg = "error initializing button images! file name: ";
		err_msg += button_image_name_;
		err_msg += ".png";
		ERR_DP << err_msg << std::endl;
		throw game::error(err_msg);
	}

	base_height_ = button_image->h;
	base_width_ = button_image->w;

	if (type_ != TYPE_IMAGE) {
		set_label(label_text_);
	}

	if(type_ == TYPE_PRESS || type_ == TYPE_TURBO) {
		image_.assign(scale_surface(button_image,location().w,location().h));
		pressedImage_.assign(scale_surface(pressed_image,location().w,location().h));
		activeImage_.assign(scale_surface(active_image,location().w,location().h));
		disabledImage_.assign(scale_surface(disabled_image,location().w,location().h));
	} else {
		image_.assign(scale_surface(button_image,button_image->w,button_image->h));
		activeImage_.assign(scale_surface(active_image,button_image->w,button_image->h));
		disabledImage_.assign(scale_surface(disabled_image,button_image->w,button_image->h));
		pressedImage_.assign(scale_surface(pressed_image,button_image->w,button_image->h));
		if (type_ == TYPE_CHECK || type_ == TYPE_RADIO) {
			pressedDisabledImage_.assign(scale_surface(pressed_disabled_image,button_image->w,button_image->h));
			pressedActiveImage_.assign(scale_surface(pressed_active_image, button_image->w, button_image->h));
			touchedImage_.assign(scale_surface(touched_image, button_image->w, button_image->h));
		}
	}

	if (type_ == TYPE_IMAGE){
		calculate_size();
	}
#endif
}