Пример #1
0
struct hash *get_cache(void)
{
    struct hash *graph;
    struct stat st;

    if (stat(cache_filename(), &st) == -1)
        graph = init_cache();
    else
        graph = load_cache(cache_filename());

    if (!graph)
        exit(EXIT_FAILURE);

    return graph;
}
Пример #2
0
int	write_cache_file(const movie_data& md)
// Write a cache file for the given movie.
{
	// Open cache file.
	tu_string	cache_filename(md.m_filename);
	cache_filename += ".gsc";
	tu_file	out(cache_filename.c_str(), "wb");	// "gsc" == "gameswf cache"
	if (out.get_error() == TU_FILE_NO_ERROR)
	{
		// Write out the data.
		gameswf::cache_options	opt;
		md.m_movie->output_cached_data(&out, opt);
		if (out.get_error() == TU_FILE_NO_ERROR)
		{
			printf(
				"wrote '%s'\n",
				cache_filename.c_str());
		}
		else
		{
			fprintf(stderr, "error: write failure to '%s'\n", cache_filename.c_str());
		}
	}
	else
	{
		fprintf(stderr, "error: can't open '%s' for cache file output\n", cache_filename.c_str());
		return 1;
	}

	// // xxx temp debug code: dump cached data to stdout
	// tu_file	tu_stdout(stdout, false);
	// tu_stdout.copy_from(&cached_data);

	return 0;
}
Пример #3
0
static int bee_dep_remove(int argc, char *argv[])
{
    int i, c, help, print;
    struct hash *graph;
    char *pkg;
    struct option long_options[] = {
        {"help",  0, &help,  1},
        {"print", 0, &print, 1},
        {0, 0, 0, 0}
    };

    help = print = 0;

    while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) {
        switch (c) {
            case '?':
                usage_remove();
                return 1;
        }
    }

    if (help) {
        usage_remove();
        return 0;
    }

    if (optind == argc) {
        fprintf(stderr, "bee-dep: pkgname needed\n");
        return 1;
    }

    graph = get_cache();

    for (i = optind; i < argc; i++) {
        pkg = argv[i];

        if (print && print_removable(graph, pkg)) {
            hash_free(graph);
            return 1;
        }

        if (remove_package(graph, pkg)) {
            hash_free(graph);
            return 1;
        }
    }

    if (save_cache(graph, cache_filename())) {
        hash_free(graph);
        return 1;
    }

    hash_free(graph);
    return 0;
}
Пример #4
0
void BKE_simulate_ocean_cache(struct OceanCache *och, int frame)
{
	char string[FILE_MAX];
	int f = frame;

	/* ibufs array is zero based, but filenames are based on frame numbers */
	/* still need to clamp frame numbers to valid range of images on disk though */
	CLAMP(frame, och->start, och->end);
	f = frame - och->start; /* shift to 0 based */

	/* if image is already loaded in mem, return */
	if (och->ibufs_disp[f] != NULL) return;

	/* use default color spaces since we know for sure cache files were saved with default settings too */

	cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_DISPLACE);
	och->ibufs_disp[f] = IMB_loadiffname(string, 0, NULL);
#if 0
	if (och->ibufs_disp[f] == NULL)
		printf("error loading %s\n", string);
	else
		printf("loaded cache %s\n", string);
#endif

	cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_FOAM);
	och->ibufs_foam[f] = IMB_loadiffname(string, 0, NULL);
#if 0
	if (och->ibufs_foam[f] == NULL)
		printf("error loading %s\n", string);
	else
		printf("loaded cache %s\n", string);
#endif

	cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_NORMAL);
	och->ibufs_norm[f] = IMB_loadiffname(string, 0, NULL);
#if 0
	if (och->ibufs_norm[f] == NULL)
		printf("error loading %s\n", string);
	else
		printf("loaded cache %s\n", string);
#endif
}
Пример #5
0
void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(void *, float progress, int *cancel),
                    void *update_cb_data)
{
	/* note: some of these values remain uninitialized unless certain options
	 * are enabled, take care that BKE_ocean_eval_ij() initializes a member
	 * before use - campbell */
	OceanResult ocr;

	ImageFormatData imf = {0};

	int f, i = 0, x, y, cancel = 0;
	float progress;

	ImBuf *ibuf_foam, *ibuf_disp, *ibuf_normal;
	float *prev_foam;
	int res_x = och->resolution_x;
	int res_y = och->resolution_y;
	char string[FILE_MAX];

	if (!o) return;

	if (o->_do_jacobian) prev_foam = MEM_callocN(res_x * res_y * sizeof(float), "previous frame foam bake data");
	else prev_foam = NULL;

	BLI_srand(0);

	/* setup image format */
	imf.imtype = R_IMF_IMTYPE_OPENEXR;
	imf.depth =  R_IMF_CHAN_DEPTH_16;
	imf.exr_codec = R_IMF_EXR_CODEC_ZIP;

	for (f = och->start, i = 0; f <= och->end; f++, i++) {

		/* create a new imbuf to store image for this frame */
		ibuf_foam = IMB_allocImBuf(res_x, res_y, 32, IB_rectfloat);
		ibuf_disp = IMB_allocImBuf(res_x, res_y, 32, IB_rectfloat);
		ibuf_normal = IMB_allocImBuf(res_x, res_y, 32, IB_rectfloat);

		BKE_simulate_ocean(o, och->time[i], och->wave_scale, och->chop_amount);

		/* add new foam */
		for (y = 0; y < res_y; y++) {
			for (x = 0; x < res_x; x++) {

				BKE_ocean_eval_ij(o, &ocr, x, y);

				/* add to the image */
				rgb_to_rgba_unit_alpha(&ibuf_disp->rect_float[4 * (res_x * y + x)], ocr.disp);

				if (o->_do_jacobian) {
					/* TODO, cleanup unused code - campbell */

					float /*r, */ /* UNUSED */ pr = 0.0f, foam_result;
					float neg_disp, neg_eplus;

					ocr.foam = BKE_ocean_jminus_to_foam(ocr.Jminus, och->foam_coverage);

					/* accumulate previous value for this cell */
					if (i > 0) {
						pr = prev_foam[res_x * y + x];
					}

					/* r = BLI_frand(); */ /* UNUSED */ /* randomly reduce foam */

					/* pr = pr * och->foam_fade; */		/* overall fade */

					/* remember ocean coord sys is Y up!
					 * break up the foam where height (Y) is low (wave valley), and X and Z displacement is greatest
					 */

#if 0
					vec[0] = ocr.disp[0];
					vec[1] = ocr.disp[2];
					hor_stretch = len_v2(vec);
					CLAMP(hor_stretch, 0.0, 1.0);
#endif

					neg_disp = ocr.disp[1] < 0.0f ? 1.0f + ocr.disp[1] : 1.0f;
					neg_disp = neg_disp < 0.0f ? 0.0f : neg_disp;

					/* foam, 'ocr.Eplus' only initialized with do_jacobian */
					neg_eplus = ocr.Eplus[2] < 0.0f ? 1.0f + ocr.Eplus[2] : 1.0f;
					neg_eplus = neg_eplus < 0.0f ? 0.0f : neg_eplus;

#if 0
					if (ocr.disp[1] < 0.0 || r > och->foam_fade)
						pr *= och->foam_fade;


					pr = pr * (1.0 - hor_stretch) * ocr.disp[1];
					pr = pr * neg_disp * neg_eplus;
#endif

					if (pr < 1.0f)
						pr *= pr;

					pr *= och->foam_fade * (0.75f + neg_eplus * 0.25f);

					/* A full clamping should not be needed! */
					foam_result = min_ff(pr + ocr.foam, 1.0f);

					prev_foam[res_x * y + x] = foam_result;

					/*foam_result = min_ff(foam_result, 1.0f); */

					value_to_rgba_unit_alpha(&ibuf_foam->rect_float[4 * (res_x * y + x)], foam_result);
				}

				if (o->_do_normals) {
					rgb_to_rgba_unit_alpha(&ibuf_normal->rect_float[4 * (res_x * y + x)], ocr.normal);
				}
			}
		}

		/* write the images */
		cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_DISPLACE);
		if (0 == BKE_imbuf_write(ibuf_disp, string, &imf))
			printf("Cannot save Displacement File Output to %s\n", string);

		if (o->_do_jacobian) {
			cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_FOAM);
			if (0 == BKE_imbuf_write(ibuf_foam, string, &imf))
				printf("Cannot save Foam File Output to %s\n", string);
		}

		if (o->_do_normals) {
			cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_NORMAL);
			if (0 == BKE_imbuf_write(ibuf_normal, string, &imf))
				printf("Cannot save Normal File Output to %s\n", string);
		}

		IMB_freeImBuf(ibuf_disp);
		IMB_freeImBuf(ibuf_foam);
		IMB_freeImBuf(ibuf_normal);

		progress = (f - och->start) / (float)och->duration;

		update_cb(update_cb_data, progress, &cancel);

		if (cancel) {
			if (prev_foam) MEM_freeN(prev_foam);
			return;
		}
	}

	if (prev_foam) MEM_freeN(prev_foam);
	och->baked = 1;
}
Пример #6
0
static int bee_dep_update(int argc, char *argv[])
{
    int c, help;
    char *pkg;
    char path[PATH_MAX + 1];
    struct hash *graph;
    struct stat st;
    struct option long_options[] = {
        {"help", 0, &help, 1},
        {0, 0, 0, 0}
    };

    help = 0;

    while ((c = getopt_long(argc, argv, "", long_options, NULL)) != -1) {
        switch (c) {
            case '?':
                usage_update();
                return 1;
        }
    }

    if (help) {
        usage_update();
        return 0;
    }

    if (argc == 1) {
        graph = get_cache();

        if (update_cache(graph) || save_cache(graph, cache_filename())) {
            hash_free(graph);
            return 1;
        }

        hash_free(graph);
        return 0;
    }

    if (argc < 2) {
        fprintf(stderr, "bee-dep: pkgname needed\n");
        return 1;
    }

    if (argc > 2) {
        fprintf(stderr, "bee-dep: too many arguments\n");
        return 1;
    }

    pkg = argv[1];

    if (sprintf(path, "%s/%s/DEPENDENCIES", bee_metadir(), pkg) < 0) {
        perror("bee-dep: sprintf");
        return 1;
    }

    graph = get_cache();

    if (stat(path, &st) != -1) {
        if (hash_search(graph, pkg)) {
            hash_free(graph);
            return 0;
        }

        if (graph_insert_nodes(graph, path)) {
            hash_free(graph);
            return 1;
        }
    } else {
        if (remove_package(graph, pkg)) {
            hash_free(graph);
            return 1;
        }
    }

    if (save_cache(graph, cache_filename())) {
        hash_free(graph);
        return 1;
    }

    hash_free(graph);
    return 0;
}
Пример #7
0
static struct hash *init_cache(void)
{
    struct dirent **package;
    int i, pkg_cnt;
    char path[PATH_MAX + 1];
    struct stat st;
    struct hash *graph;

    if (stat(bee_metadir(), &st) == -1)
        return NULL;

    if ((pkg_cnt = scandir(bee_metadir(), &package, 0, alphasort)) < 0) {
        perror("bee-dep: init_cache: scandir");
        return NULL;
    }

    graph = hash_new();

    /* skip . and .. */
    free(package[0]);
    free(package[1]);

    for (i = 2; i < pkg_cnt; i++) {
        sprintf(path, "%s/%s", bee_metadir(), package[i]->d_name);

        if (stat(path, &st) == -1) {
            perror("bee-dep: init_cache: stat");
            hash_free(graph);
            return NULL;
        }

        if (S_ISDIR(st.st_mode)) {
            strcat(path, "/DEPENDENCIES");

            if (stat(path, &st) == -1) {
                fprintf(stderr,
                        "bee-dep: init_cache: missing "
                        "DEPENDENCIES file for package \"%s\"\n",
                        package[i]->d_name);
                hash_free(graph);
                return NULL;
            }

            if (graph_insert_nodes(graph, path)) {
                hash_free(graph);
                return NULL;
            }
        }

        free(package[i]);
    }

    free(package);

    if (save_cache(graph, cache_filename())) {
        hash_free(graph);
        return NULL;
    }

    return graph;
}
Пример #8
0
movie_definition*	player::create_movie(const char* filename)
{
    assert(filename);

    // Is the movie already in the library?
    if (s_use_cached_movie_def)
    {
        gc_ptr<character_def>	m;
        get_chardef_library()->get(filename, &m);
        if (m != NULL)
        {
            // Return cached movie.
            return cast_to<movie_definition>(m.get_ptr());
        }
    }

    if (s_opener_function == NULL)
    {
        // Don't even have a way to open the file.
        log_error("error: no file opener function; can't create movie.	"
                  "See gameswf::register_file_opener_callback\n");
        return NULL;
    }

    tu_file* in = s_opener_function(filename);
    if (in == NULL)
    {
        log_error("failed to open '%s'; can't create movie.\n", filename);
        return NULL;
    }
    else if (in->get_error())
    {
        log_error("error: file opener can't open '%s'\n", filename);
        delete in;
        return NULL;
    }

    ensure_loaders_registered();

    movie_def_impl*	m = new movie_def_impl(this, DO_LOAD_BITMAPS, DO_LOAD_FONT_SHAPES);

    if (s_use_cached_movie_def)
    {
        get_chardef_library()->add(filename, m);
    }

    m->read(in);

    // "in" will be deleted after termination of the loader thread
    //	delete in;

    if (m && s_use_cache_files)
    {
        // Try to load a .gsc file.
        tu_string	cache_filename(filename);
        cache_filename += ".gsc";
        tu_file*	cache_in = s_opener_function(cache_filename.c_str());
        if (cache_in == NULL
                || cache_in->get_error() != TU_FILE_NO_ERROR)
        {
            // Can't open cache file; don't sweat it.
            IF_VERBOSE_PARSE(log_msg("note: couldn't open cache file '%s'\n", cache_filename.c_str()));
        }
        else
        {
            // Load the cached data.
            m->input_cached_data(cache_in);
        }

        delete cache_in;
    }

    return m;
}