Example #1
0
File: cat.c Project: esheldon/misc
struct cat* cat_new(size_t n, int64 nside) 
{
    struct cat* cat = alloc_or_die(sizeof(struct cat), "catalog struct");

    cat->pts = alloc_or_die(n*sizeof(struct point),"points");
    cat->size = n;
    cat->hpix = hpix_new(nside);

    return cat;
}
Example #2
0
struct item* create_sll(void)
{
    struct item *sll = alloc_or_die();
    struct item *now = sll;

    // NOTE: running this on bare metal may cause the machine to swap a bit
    int i;
    for (i = 1; 0 < i; ++i) {
        now->next = alloc_or_die();
        now = now->next;
    }

    return sll;
}
Example #3
0
struct point_hash* point_hash_new(int64 hpixid) {
    struct point_hash* pth = 
        alloc_or_die(sizeof(struct point_hash),"hash entry");
    pth->points = vector_new(0,sizeof(struct point*));
    pth->hpixid=hpixid;
    return pth;
}
Example #4
0
struct point_hash* point_hash_new(int64 hpixid) {
    struct point_hash* pth = 
        alloc_or_die(sizeof(struct point_hash),"hash entry");
    pth->points = ptrstack_new(0);
    pth->hpixid=hpixid;
    return pth;
}
Example #5
0
struct item* create_sll_head(void)
{
    struct item *head = alloc_or_die();
    head->head = head;
    head->next = NULL;
    return head;
}
Example #6
0
struct item* alloc_and_zero(void)
{
    struct item *pi = alloc_or_die();
    pi->next = NULL;
    pi->prev = NULL;

    return pi;
}
Example #7
0
filter_state* filter_state_alloc(void) {
	int i;
        filter_state* s = alloc_or_die(filter_state);
	s->prev_mac = 0;
	for(i=0;i<FILTER_ORDER_MAX;++i)
		s->xprev[i] = 0;
	return s;
}
Example #8
0
struct item* create_sll(void)
{
    struct item *head = create_sll_head();
    struct item *sll = head;

    // NOTE: running this on bare metal may cause the machine to swap a bit
    int i;
    for (i = 0; i < 1024; ++i) {
        sll->next = alloc_or_die();
        sll->next->head = head;
        sll->next->next = NULL;

        sll = sll->next;
    }

    return head;
}
Example #9
0
struct item* create_sll_item(struct item *next) {
    struct item *pi = alloc_or_die();
    pi->next = next;
    return pi;
}
Example #10
0
static filter* filter_alloc(void) {
	filter* f = alloc_or_die(filter);
	return f;
}
Example #11
0
int sdlwindow_video_window_create(running_machine *machine, int index, sdl_monitor_info *monitor, const sdl_window_config *config)
{
	sdl_window_info *window;
	worker_param *wp = malloc(sizeof(worker_param));
	char option[20];
	int result;

	ASSERT_MAIN_THREAD();

	clear_worker_param(wp);

	// allocate a new window object
	window = alloc_or_die(sdl_window_info);
	memset(window, 0, sizeof(*window));
	window->maxwidth = config->width;
	window->maxheight = config->height;
	window->depth = config->depth;
	window->refresh = config->refresh;
	window->monitor = monitor;
	window->machine = machine;
	window->index = index;
	
	//FIXME: these should be per_window in config-> or even better a bit set
	window->fullscreen = !video_config.windowed;
	window->prescale = video_config.prescale;
	window->prescale_effect = video_config.prescale_effect;
	window->scale_mode = video_config.scale_mode;

	// set the initial maximized state
	// FIXME: Does not belong here
	window->startmaximized = options_get_bool(mame_options(), SDLOPTION_MAXIMIZE);

	if (!window->fullscreen)
	{
		window->windowed_width = config->width;
		window->windowed_height = config->height;
	}
  	window->totalColors = config->totalColors;

	// add us to the list
	*last_window_ptr = window;
	last_window_ptr = &window->next;

	draw.attach(&draw, window);
	
	// create an event that we can use to skip blitting
	window->rendered_event = osd_event_alloc(FALSE, TRUE);

	// load the layout
	window->target = render_target_alloc(machine, NULL, FALSE);
	if (window->target == NULL)
		goto error;

	// set the specific view				    
	sprintf(option, SDLOPTION_VIEW("%d"), index);
	set_starting_view(machine, index, window, options_get_string(mame_options(), option));

	// make the window title
	if (video_config.numscreens == 1)
		sprintf(window->title, APPNAME ": %s [%s]", machine->gamedrv->description, machine->gamedrv->name);
	else
		sprintf(window->title, APPNAME ": %s [%s] - Screen %d", machine->gamedrv->description, machine->gamedrv->name, index);

	wp->window = window;

	if (multithreading_enabled)
	{
		osd_work_item *wi;		
		
		wi = osd_work_item_queue(work_queue, &complete_create_wt, (void *) wp, 0);
		sdlwindow_sync();
		result = *((int *) (osd_work_item_result)(wi));
		osd_work_item_release(wi);
	} 
	else
		result = *((int *) complete_create_wt((void *) wp, 0));

	// handle error conditions
	if (result == 1)
		goto error;

	return 0;

error:
	sdlwindow_video_window_destroy(machine, window);
	return 1;
}
Example #12
0
struct cat* read_cat(const char* fname, int64 nside, double radius_arcsec, int verbose) {

    int barsize=70;

    FILE* fptr=open_file(fname);


    size_t nlines=countlines(fptr);
    if (verbose) wlog("    found %lu lines\n", nlines);
    rewind(fptr);

    struct cat* cat = alloc_or_die(sizeof(struct cat), "catalog struct");

    double radius_radians=0;
    if (radius_arcsec <= 0) {
        cat->radius_in_file=1;
        cat->cos_radius = alloc_or_die(nlines*sizeof(double), "cos_radius array");
    } else {
        cat->radius_in_file=0;
        cat->cos_radius = alloc_or_die(sizeof(double), "cos_radius");

        radius_radians = radius_arcsec/3600.*D2R;
        cat->cos_radius[0] = cos(radius_radians);
    }

    cat->hpix=NULL;
    cat->tree=NULL;

    cat->pts = alloc_or_die(nlines*sizeof(struct point),"points");
    cat->size = nlines;

    if (verbose) wlog("    creating hpix\n");
    cat->hpix = hpix_new(nside);

    if (verbose) {
        wlog("    reading and building tree\n");
        repeat_char('.', barsize); wlog("\n");
    }

    double ra=0, dec=0;
    struct i64stack* listpix = i64stack_new(0);

    // this will produce a more balanced tree across the whole sky
    int64 half_npix=cat->hpix->npix/2;

    size_t count=0;
    struct point* pt = &cat->pts[0];
    for (size_t i=0; i<cat->size; i++) {
        if (2 != fscanf(fptr, "%lf %lf", &ra, &dec)) {
            wlog("expected to read point at line %lu\n", i);
            exit(EXIT_FAILURE);
        }
        if (cat->radius_in_file) {
            if (1 != fscanf(fptr, "%lf", &radius_arcsec)) {
                wlog("expected to read radius at line %lu\n", i);
                exit(EXIT_FAILURE);
            }
            radius_radians = radius_arcsec/3600.*D2R;
            cat->cos_radius[i] = cos(radius_radians);
        }

        hpix_eq2xyz(ra,dec,&pt->x,&pt->y,&pt->z);

        hpix_disc_intersect(cat->hpix, pt->x, pt->y, pt->z, radius_radians, 
                            listpix);

        int64* ptr=listpix->data;
        while (ptr < listpix->data + listpix->size) {
            tree_insert(&cat->tree, (*ptr)-half_npix, count);
            ptr++;
        }

        pt++;
        count++;
        if (verbose) incr_bar(i+1, cat->size, barsize, '=');
    }
    listpix=i64stack_delete(listpix);

    if (verbose) wlog("\n");

    if (count != nlines) {
        wlog("expected %lu lines but read %lu\n", nlines, count);
        exit(EXIT_FAILURE);
    }

    if (verbose)
        wlog("fullest node has %lu members\n", tree_most_members(cat->tree));

    fclose(fptr);
    return cat;
}