[Bf-committers] [12490] branches/cloth/blender/source/ blender: Merged pointcache from particles branch, but is not used in the moment

GSR gsr.b3d at infernal-iceberg.com
Wed Nov 7 21:58:20 CET 2007


Hi,
daniel.genrich at gmx.net (2007-11-06 at 1044.09 +0100):
> Log Message:
> -----------
> Merged pointcache from particles branch, but is not used in the moment
[...]
> +	if (pcm->mode == ePointCache_Read) {
> +		fp = PTCache_id_fopen((ID *)ob, 'w', G.scene->r.cfra, stack_index);
> +		if (!fp) return;
> +		for (mv=mvert, i=0; i<totvert; mv++, i++) {
> +			fwrite(&mv->co, sizeof(float), 3, fp);
> +		}
> +		fclose(fp);
> +	} else if (pcm->mode == ePointCache_Write) {
> +		float pt[3];
> +		fp = PTCache_id_fopen((ID *)ob, 'r', G.scene->r.cfra, stack_index);
> +		if (!fp) return;
> +		for (mv=mvert, i=0; i<totvert; mv++, i++) {
> +			float *co = vertexCos[i];
> +			if ((fread(co, sizeof(float), 3, fp)) != 3) {
> +				break;
> +			}
> +		}
> +		fclose(fp);

Read mode writes and write mode reads? I am missing a vital detail?
Was this tested? Does this come from a non fixed or just discarded SVN
revision?

> +FILE *PTCache_id_fopen(struct ID *id, char mode, int cfra, int stack_index)
> +{
> +	/* mode is same as fopen's modes */
> +	FILE *fp;
> +	char filename[(FILE_MAXDIR+FILE_MAXFILE)*2];
> +
> +	PTCache_id_filename(id, filename, cfra, stack_index, 1, 1);
> +
> +	if (mode=='r') {
> +		if (!BLI_exists(filename)) {
> +			printf("Error, file does not exist '%s'\n", filename);
> +			return NULL;
> +		}
> + 		fp = fopen(filename, "rb");
> +	} else if (mode=='w') {
> +		BLI_make_existing_file(filename); /* will create the dir if needs be, same as //textures is created */
> +		fp = fopen(filename, "wb");
> +	}

The function name hints fopen, but the fopen calls add to the mode
supplied (and others are ignored)? Why not just fully follow fopen
semantics (so a, a+, a+b, etc can be used)? Or if the semantics are
different (for example if nothing else than read and write being
required and allowed), avoid the cryptic mode, the fopen ref and use
something not so misleading. Then it would also be nice to provide
matching ops for close, read, write, seek, etc (so gzip can be used
later, ie).

GSR
 


More information about the Bf-committers mailing list