Beispiel #1
0
/*
* The main procedure is similar to the main found in ARITH1E.C. It has
* to initialize the coder and the model. It then sits in a loop reading
* input symbols and encoding them. One difference is that every 256
* symbols a compression check is performed. If the compression ratio
* falls below 10%, a flush character is encoded. This flushes the encod
* ing model, and will cause the decoder to flush its model when the 
* file is being expanded. The second difference is that each symbol is
* repeatedly encoded until a successful encoding occurs. When trying to
* encode a character in a particular order, the model may have to
* transmit an ESCAPE character. If this is the case, the character has
* to be retransmitted using a lower order. This process repeats until a
* successful match is found of the symbol in a particular context.
* Usually this means going down no further than the order -1 model.
* However, the FLUSH and DONE symbols drop back to the order -2 model.
*
*/
void CompressFile(FILE *input,BIT_FILE *output,int argc,char *argv[])
{
 SYMBOL s;
 int c;
 int escaped;
 int flush = 0;
 long int text_count = 0;
 initialize_options( argc, argv );
 initialize_model();
 initialize_arithmetic_encoder();
 for ( ; ; ) {
 if ( ( ++text_count & 0x0ff ) == 0 )
 	flush = check_compression( input, output );
 if ( !flush )
 	c = getc( input );
 else
 	c = FLUSH;
 if ( c == EOF )
 	c = DONE;
 do {
	 escaped = convert_int_to_symbol( c, &s);
	 encode_symbol( output, &s );
 } while ( escaped );
 if ( c == DONE )
 	break;
 if ( c == FLUSH ) {
	 flush_model();
	 flush = 0;
 }
 update_model( c );
 add_character_to_model( c );
 }
 flush_arithmetic_encoder( output );
}
/**
 * @brief Fills the fields from the existing entity.
 */
void EditEntityDialog::initialize() {

  initialize_simple_booleans();
  initialize_simple_integers();
  initialize_simple_strings();

  initialize_behavior();
  initialize_breed();
  initialize_damage_on_enemies();
  initialize_destination();
  initialize_destination_map();
  initialize_direction();
  initialize_font();
  initialize_ground();
  initialize_layer();
  initialize_maximum_moves();
  initialize_model();
  initialize_name();
  initialize_opening_method();
  initialize_rank();
  initialize_savegame_variable();
  initialize_size();
  initialize_sound();
  initialize_sprite();
  initialize_subtype();
  initialize_transition();
  initialize_treasure();
  initialize_type();
  initialize_weight();
  initialize_xy();

  adjustSize();
}
Beispiel #3
0
inline bool process_terrain(Memory *memory, TerrainChunk *chunk, int detail_level) {
  Model *model = chunk->models + detail_level;

  if (model->state == AssetState::INITIALIZED) {
    return false;
  }

  if (model->state == AssetState::HAS_DATA) {
    initialize_model(model);
    return true;
  }

  if (platform.queue_has_free_spot(memory->main_queue)) {
    if (model->state == AssetState::EMPTY) {
      auto *work = (GenerateGrountWorkData*)(malloc(sizeof(GenerateGrountWorkData)));
      work->chunk = chunk;
      work->detail_level = detail_level;

      platform.add_work(memory->main_queue, generate_ground_work, work);

      return true;
    }
  }

  return true;
}
Beispiel #4
0
/*
* The main loop for expansion is very similar to the expansion
* routine used in the simpler compression program, ARITH1E.C. The
* routine first has to initialize the the arithmetic coder and the
* model. The decompression loop differs in a couple of respect.
* First of all, it handles the special ESCAPE character, by
* removing them from the input bit stream but just throwing them
* away otherwise. Secondly, it handles the special FLUSH character.
* Once the main decoding loop is done, the cleanup code is called,
* and the program exits.
*
*/
void ExpandFile(BIT_FILE *input,FILE *output,int argc,char *argv[])
{
 SYMBOL s;
 int c;
 int count;
 initialize_options( argc, argv );
 initialize_model();
 initialize_arithmetic_decoder( input );
 for ( ; ; ) {
	 do {
	 get_symbol_scale( &s );
	 count = get_current_count( &s );
	 c = convert_symbol_to_int( count, &s );
	 remove_symbol_from_stream( input, &s );
	 } while ( c == ESCAPE );
	 if ( c == DONE )
	 	break;
	 if ( c != FLUSH )
	 	putc( (char) c, output );
	 else
	 	flush_model();
	 update_model( c );
	 add_character_to_model( c );
 }
}
Beispiel #5
0
lsh::lsh(uint64_t base_num)
    : base_num_(base_num) {
  if (base_num == 0) {
    throw JUBATUS_EXCEPTION(common::exception::runtime_error("base_num == 0"));
  }
  initialize_model();
}
Beispiel #6
0
lsh::lsh(uint64_t hash_num)
    : hash_num_(hash_num) {
  if (!(1 <= hash_num)) {
    throw JUBATUS_EXCEPTION(
        common::invalid_parameter("1 <= hash_num"));
  }
  initialize_model();
}
Beispiel #7
0
lsh::lsh(const config& config)
    : hash_num_(config.hash_num) {

  if (!(1 <= config.hash_num)) {
    throw JUBATUS_EXCEPTION(
        common::invalid_parameter("1 <= hash_num"));
  }

  initialize_model();
}
Beispiel #8
0
int
main (int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *vbox;
    GtkWidget *scrolled_window;
    GtkWidget *tree_view;
    GtkWidget *hbox;
    GtkWidget *button;
    GtkTreePath *path;

    gtk_init (&argc, &argv);

    path = gtk_tree_path_new_from_string ("80");
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "Reflow test");
    g_signal_connect (window, "destroy", gtk_main_quit, NULL);
    vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
    gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
    gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("Incremental Reflow Test"), FALSE, FALSE, 0);
    gtk_container_add (GTK_CONTAINER (window), vbox);
    scrolled_window = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
                                    GTK_POLICY_AUTOMATIC,
                                    GTK_POLICY_AUTOMATIC);
    gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);

    initialize_model ();
    tree_view = gtk_tree_view_new_with_model (model);
    gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), path, NULL, TRUE, 0.5, 0.0);
    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
    gtk_tree_selection_select_path (selection, path);
    gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
    gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
            -1,
            NULL,
            gtk_cell_renderer_text_new (),
            "text", TEXT_COLUMN,
            NULL);
    gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
    hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
    gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
    button = gtk_button_new_with_mnemonic ("<b>_Futz!!</b>");
    gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
    gtk_label_set_use_markup (GTK_LABEL (gtk_bin_get_child (GTK_BIN (button))), TRUE);
    g_signal_connect (button, "clicked", G_CALLBACK (futz), NULL);
    g_signal_connect (button, "realize", G_CALLBACK (gtk_widget_grab_focus), NULL);
    gtk_window_set_default_size (GTK_WINDOW (window), 300, 400);
    gtk_widget_show_all (window);
    gdk_threads_add_timeout (1000, (GSourceFunc) futz, NULL);
    gtk_main ();
    return 0;
}
Beispiel #9
0
void init_common(AVCodecContext *avctx, MscCodecContext *mscContext) {

	ff_dsputil_init(&mscContext->dsp, avctx);

	mscContext->mb_width   = (avctx->width  + 15) / 16;
	mscContext->mb_height  = (avctx->height + 15) / 16;

	initialize_model(&mscContext->arithModelIndexCodingModel, 4);
	initialize_model(&mscContext->lastZeroCodingModel, 6);
	/*
	 * Initialize arithmetic coder models. First model: arithModels[0],
	 * can store 0, 1 values (2^1). Second one arithModels[1], 0, 1, 2, 3
	 * (2^2) and so on.
	 */
	for (int i = 0; i < 10; ++i) {
		initialize_model(&mscContext->arithModels[i], i + 1);
		mscContext->arithModelAddValue[i] = pow(2, i) - 1;
	}

	mscContext->referenceFrame = avcodec_alloc_frame();
	if (!mscContext->referenceFrame) {
		av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
	}
}
Beispiel #10
0
lsh::lsh()
    : hash_num_(DEFAULT_HASH_NUM) {
  initialize_model();
}
Beispiel #11
0
/* ==== */
static void
initialize_wl(void)
{
  int bins,fnlen=512;
  char *res_string=NULL;
  double low,high,lo,hi,hmin,hmax,erange,*range = NULL;
  
  srand(time(NULL));
  if(wanglandau_opt.verbose){
    printf("[[initialize_wl()]]\n");
  }
  /* assign function pointers */
  initialize_model = initialize_RNA;  /* for RNA */
  pre_process_model  = pre_process_RNA;
  post_process_model = post_process_RNA;
  
  /* set energy paramters for current model; compute mfe */
  initialize_model(wanglandau_opt.sequence); 

  range = (double*)calloc((wanglandau_opt.bins+1), sizeof(double));
  assert(range!=NULL);

  /* initialize histograms */
  hmin=mfe;
  if(wanglandau_opt.res_given){ /* determine histogram ranges manually */
    int i;
    range[0]=mfe;
    for(i=1;i<=wanglandau_opt.bins;i++){
      range[i]=range[i-1]+wanglandau_opt.res;
    }
    if(wanglandau_opt.verbose){
      /* info output */
      fprintf(stderr,"#allocating %lu bins of width %g\n",
	      wanglandau_opt.bins,wanglandau_opt.res);
      /* fprintf(stderr,"#histogram ranges:\n #");
	 for(i=0;i<=wanglandau_opt.bins;i++){
	 fprintf(stderr, "%6.2f ",range[i]);
      
      }
      fprintf(stderr,"\n");
      */
    }
  
    if(wanglandau_opt.max_given){
      hmax=wanglandau_opt.max;
    }
    else{
      wanglandau_opt.max=range[wanglandau_opt.bins]; /* the last element */
      hmax=wanglandau_opt.max;
    }
    h = gsl_histogram_alloc(wanglandau_opt.bins);
    g = gsl_histogram_alloc(wanglandau_opt.bins);
    s = gsl_histogram_alloc(wanglandau_opt.bins);
    gsl_histogram_set_ranges(h,range,(wanglandau_opt.bins+1));
    gsl_histogram_set_ranges(g,range,(wanglandau_opt.bins+1));
    gsl_histogram_set_ranges(s,range,(wanglandau_opt.bins+1));
  }
  else{  /* determine histogram ranges automatically */
    if(wanglandau_opt.max_given){
      hmax = wanglandau_opt.max;
    }
    else{
      hmax=20*fabs(mfe);
    }
    h = ini_histogram_uniform(wanglandau_opt.bins,hmin,hmax);
    g = ini_histogram_uniform(wanglandau_opt.bins,hmin,hmax);
    s = ini_histogram_uniform(wanglandau_opt.bins,hmin,hmax);
  }
  fprintf (stderr, "# sampling energy range is %6.2f - %6.2f\n",
	   hmin,hmax);
  free(range);
  
  /* get the energy range up to which we will compute true DOS via
     RNAsubopt */
  gsl_histogram_get_range(s,0,&lo,&hi);
  low = lo;
  gsl_histogram_get_range(s,(wanglandau_opt.truedosbins-1),&lo,&hi);
  high = hi;
  wanglandau_opt.erange=(float)fabs(mfe-high+0.01);
  if(wanglandau_opt.verbose){
    printf("Using true DOS for bins 0-%d: (%6.3g -- %6.3g) wl_opt.erange=%6.3f\n",
	   (wanglandau_opt.truedosbins-1),low,high,wanglandau_opt.erange);
  }
  
  /* prepare gsl random-number generation */
  (void) clock_gettime(CLOCK_REALTIME, &ts);
  if(wanglandau_opt.seed_given){
    seed = wanglandau_opt.seed;
  }
  else {
    seed =   ts.tv_sec ^ ts.tv_nsec;
  }
  fprintf(stderr, "initializing random seed: %d\n",seed);
  gsl_rng_env_setup();
  r = gsl_rng_alloc (gsl_rng_mt19937);
  gsl_rng_set( r, seed );
  /* end gsl */

  /* make prefix for output */
  out_prefix = (char*)calloc(fnlen, sizeof(char));
  res_string = (char*)calloc(16, sizeof(char));
  sprintf(res_string,"%3.1f", wanglandau_opt.res);
  strcpy(out_prefix, wanglandau_opt.basename); strcat(out_prefix, ".res");
  strcat(out_prefix, res_string); strcat(out_prefix, ".");
  free(res_string);
  return;
}
Beispiel #12
0
/* We first try to grab the global lock in read mode to check whether the model
 * was loaded or not (this is very likely to have been already loaded). If the
 * model was not loaded yet, we take the lock in write mode, and if the model
 * is still not loaded once we have the lock, we do load it.  */
static void load_history_based_model(struct starpu_perfmodel_t *model, unsigned scan_history)
{

    STARPU_ASSERT(model);
    STARPU_ASSERT(model->symbol);

    int already_loaded;

    PTHREAD_RWLOCK_RDLOCK(&registered_models_rwlock);
    already_loaded = model->is_loaded;
    PTHREAD_RWLOCK_UNLOCK(&registered_models_rwlock);

    if (already_loaded)
        return;

    /* The model is still not loaded so we grab the lock in write mode, and
     * if it's not loaded once we have the lock, we do load it. */

    PTHREAD_RWLOCK_WRLOCK(&registered_models_rwlock);

    /* Was the model initialized since the previous test ? */
    if (model->is_loaded)
    {
        PTHREAD_RWLOCK_UNLOCK(&registered_models_rwlock);
        return;
    }

    PTHREAD_RWLOCK_INIT(&model->model_rwlock, NULL);

    PTHREAD_RWLOCK_WRLOCK(&model->model_rwlock);

    /* make sure the performance model directory exists (or create it) */
    _starpu_create_sampling_directory_if_needed();

    /*
     * We need to keep track of all the model that were opened so that we can
     * possibly update them at runtime termination ...
     */
    _starpu_register_model(model);

    char path[256];
    get_model_path(model, path, 256);

    _STARPU_DEBUG("Opening performance model file %s for model %s ... ", path, model->symbol);

    unsigned calibrate_flag = _starpu_get_calibrate_flag();
    model->benchmarking = calibrate_flag;

    /* try to open an existing file and load it */
    int res;
    res = access(path, F_OK);
    if (res == 0) {
        if (calibrate_flag == 2)
        {
            /* The user specified that the performance model should
             * be overwritten, so we don't load the existing file !
             * */
            _STARPU_DEBUG("Overwrite existing file\n");
            initialize_model(model);
        }
        else {
            /* We load the available file */
            _STARPU_DEBUG("File exists\n");
            FILE *f;
            f = fopen(path, "r");
            STARPU_ASSERT(f);

            parse_model_file(f, model, scan_history);

            fclose(f);
        }
    }
    else {
        _STARPU_DEBUG("File does not exists\n");
        if (!calibrate_flag) {
            _STARPU_DISP("Warning: model %s is not calibrated, forcing calibration for this run. Use the STARPU_CALIBRATE environment variable to control this.\n", model->symbol);
            _starpu_set_calibrate_flag(1);
            model->benchmarking = 1;
        }
        initialize_model(model);
    }

    model->is_loaded = 1;

    PTHREAD_RWLOCK_UNLOCK(&model->model_rwlock);

    PTHREAD_RWLOCK_UNLOCK(&registered_models_rwlock);
}
Beispiel #13
0
/*
    Purpose: animate and run the game with the clock
    Input  : a char length pointer to the frame buffer and a long length pointer to the frame buffer
    Returns: nothing, but constantly runs the game and its functions
    Assume : nothing
*/
void animate_main(char *base,long *iBase)
{
    long *back,*temp;

    int musicCounter = 0;
    int enMisCount = 0;
    int plMisCount = 0;
    int x,y = 0;
    long clock;
    long newClock;
    int mouseClicked = 0;
    unsigned short mouseX,mouseY;
    int i= 0,j = 0,k = 0,l = 0;
    int randX,randY,randX2;
    int fire = 0;
    int s = 0;
    int done = 0;
	int render = 0;

    struct missile friendlyMis[NUM_MISSILES];
    struct missile enemyMis[NUM_MISSILES];
    struct explosion explosions[NUM_EXPLOSIONS];
    struct missile_Silo silo;
    struct city city1;
    struct city city2;
    struct city city3;
    struct city city4;
    struct city city5;
    struct city city6;
    int *music = get_music();
    
	
	Vector original_Vector;
	/*start the music*/
	stop_sound();
    start_music();
    
	/*init ther model*/
	initialize_model(&city1,&city2,&city3,&city4,&city5,&city6,&silo,friendlyMis,enemyMis,explosions);

	/*create the backbuffer*/
    back = (long *)(buffer + (256 -((long)&buffer)%256));
    
	init_VBL_ISR(original_Vector);
	
	
	
	while(done == 0)
    {
        /*random values for enemy missiles*/

        randX = rand() % BORDER_RIGHT + 16;
        randX2 = rand() % BORDER_RIGHT + 16;
        randY = rand() % GROUND_LEVEL - 200;

        /* needs to fire a player missile at the mouse click coordinates */
        if (mouseClicked == TRUE)
        {                     /* process on input */
            if (k > NUM_MISSILES-1)
            {
                k = 0;
            }
            if (friendlyMis[k].destroyed == TRUE)
            {
                friendlyMis[k].destroyed = FALSE;
                friendlyMis[k].currentY = GROUND_LEVEL-20;
                friendly_Missile_Fired(mouseX,mouseY, &friendlyMis[k],MISSILE_SILO_FIRING_POINT);
                missile_fired_sound();
                k++;
            }
        }

        clock = clockGet();

        if (clock != newClock)
        {                      /* process on clock change */
            fire++;
            if(fire == MISSILE_FIRED_TIME)
            {
                enemyMis[j].destroyed = FALSE;
                enemy_Missile_Fired(randX, GROUND_LEVEL, &enemyMis[j],randX2);
                j++;
                if(fire == MISSILE_FIRED_TIME)
                {
                    fire = 0;
                }
                if (j == NUM_MISSILES-1)
                {
                    j = 0;
                }
            }

            mouseClicked = get_mouse_pos(&mouseX,&mouseY);

			
			if(render == 1)
			{
				render_main(back, city1, city2, city3, city4, city5, city6, silo, enemyMis,friendlyMis, explosions,mouseX,mouseY,render);
			}
			
			
			
			
			
			/* T */
            temp = iBase;
            iBase = back;
            back = temp;

            /* wait for sync and then set the screen to the current buffer */
            set_video_base_wrap((char *)iBase);

            /* process missiles
               might need to change to be able to handle more */
            for (i = 0; i < NUM_MISSILES; i++)
            {
                if (enemyMis[i].destroyed == FALSE && explosions[i].exists == FALSE)
                {
                    processEnemyMissiles(&enemyMis[i],&explosions[i],clock,ENEMY_SPEED);
                }
                if (friendlyMis[i].destroyed == FALSE && explosions[i+NUM_MISSILES].exists == FALSE)
                {
                    processEnemyMissiles(&friendlyMis[i],&explosions[i+NUM_MISSILES],clock,FRIENDLY_SPEED);
                }
            }
            /* process explosions
               might need to change to be able to handle more */
            for (i = 0; i < NUM_EXPLOSIONS; i++)
            {
                if (explosions[i].exists == TRUE)
                {
                    processExplosions(&explosions[i]);
                }
            }
            /* process missile -> explosion collisions */
            for (i = NUM_MISSILES; i < NUM_EXPLOSIONS; i++)
            {
                if (explosions[i].exists == TRUE)
                {
                    processCollisions(friendlyMis,enemyMis,explosions[i]);
                }
            }
            /* process explosion -> city explosions */
            for (i = 0; i < NUM_MISSILES; i++)
            {
                if (explosions[i].hit_city != FALSE)
                {
                    city_collision(explosions[i].hit_city,&city1,&city2,&city3,&city4,&city5,&city6);
                }
            }
            if (musicCounter < SONG_LENGTH){
                if (fire % 4 == 0)
                {
                    play_music(music[musicCounter]);
                    musicCounter++;
                }
            }
            else
            {
                musicCounter = 0;
            }
        }
        newClock = clockGet();
        done = game_over(city1,city2,city3,city4,city5,city6);
    }
    stop_sound();
}
Beispiel #14
0
lsh::lsh()
    : base_num_(DEFAULT_BASE_NUM) {
  initialize_model();
}
Beispiel #15
0
lsh::lsh(const config& config)
    : base_num_(config.hash_num) {
  initialize_model();
}