コード例 #1
0
ファイル: testapp.c プロジェクト: h4xxel/libdarnit
int compression_test() {
	/* COmpressed writes test */
	DARNIT_FILE *f;
	char bzval[64];

	f = d_file_open("test.bz2", "wb+");
	d_file_write_compressed(f, "Fiskpinnar", strlen("Fiskpinnar") + 1);
	d_file_write("Fiskpinnar", strlen("Fiskpinnar") + 1, f);
	d_file_close(f);
	f = d_file_open("test.bz2", "rb");
	d_file_read_compressed(f, bzval, strlen("Fiskpinnar") + 1);
	if (strcmp(bzval, "Fiskpinnar")) {
		fprintf(stderr, "Compression test failed\n");
		return 0;
	}
	
	d_file_read(bzval, strlen("Fiskpinnar") + 1, f);
	if (strcmp(bzval, "Fiskpinnar")) {
		fprintf(stderr, "Post-compression test failed\n");
		return 0;
	}
	
	fprintf(stderr, "Compression test passed\n");
	return 1;
}
コード例 #2
0
ファイル: fontgen.c プロジェクト: ysei/dentata-beta
bool loadv0font(d_file_t *fp, d_font_t *fnt)
{
    int i, j;
    byte k, l;

    fnt->desc.w = d_file_getword(fp);
    fnt->desc.h = d_file_getword(fp);
    fnt->desc.bpp = 1;
    fnt->desc.alpha = 1;
    fnt->desc.paletted = false;
    fnt->desc.cspace = RGB;
    fnt->start = d_file_getbyte(fp);
    fnt->nchars = d_file_getbyte(fp);
    fnt->chars = d_memory_new(sizeof(d_image_t *)*fnt->nchars);
    if(fnt->chars == NULL) return failure;

    for(i = 0; i < fnt->nchars; i++) {
        fnt->chars[i] = d_image_new(fnt->desc);
        if(fnt->chars[i] == NULL) return failure;
        d_file_read(fp, fnt->chars[i]->data, fnt->desc.h);
        for(j = 0; j < fnt->desc.h; j++) {
            /* Unfortunately, this mess exists because the bits are
             * in exactly the wrong order for our purposes. */
            for(k = 0, l = 0; k < 8; k++) {
                l |= ((fnt->chars[i]->data[j]&(1<<k))>>k)<<(7-k);
            }
            fnt->chars[i]->data[j] = l;
        }
        d_memory_copy(fnt->chars[i]->alpha, fnt->chars[i]->data,
                      fnt->desc.h);
    }

    return success;
}
コード例 #3
0
ファイル: map.c プロジェクト: slaeshjag/Muon
MAP *map_load(const char *filename) {
	MAP *map;
	DARNIT_FILE *f_ts;
	if(d_fs_mount(filename))
		return NULL;
	if(!(map=malloc(sizeof(MAP)))) {
		d_fs_unmount(filename);
		return NULL;
	}
	if(!(map->stringtable=malloc(sizeof(MAP_PROPERTY)))) {
		free(map);
		d_fs_unmount(filename);
		return NULL;
	}
	if(!(map->map=d_map_load("mapdata/map.ldmz"))) {
		free(map->stringtable);
		free(map);
		d_fs_unmount(filename);
		return NULL;
	}
	if(!(f_ts=d_file_open(d_map_prop(map->map->prop, "tileset"), "rb")))
		if(!(f_ts=fopen("res/default.png", "rb"))) {
			free(map->stringtable);
			free(map);
			d_fs_unmount(filename);
			return NULL;
		}
	
	map->stringtable->key="tileset";
	map->stringtable->value="mapdata/default.png";
	map->stringtable->next=NULL;
	
	d_file_seek(f_ts, 0, SEEK_END);
	map->tilesheet_size=d_file_tell(f_ts);
	map->tilesheet=malloc(map->tilesheet_size);
	d_file_seek(f_ts, 0, SEEK_SET);
	d_file_read(map->tilesheet, map->tilesheet_size, f_ts);
	d_file_close(f_ts);
	d_fs_unmount(filename);
	map->w=map->map->layer->tile_w*map->map->layer->tilemap->w;
	map->h=map->map->layer->tile_h*map->map->layer->tilemap->h;
	sprintf(map->sizestring, "%ix%i", map->map->layer->tilemap->w, map->map->layer->tilemap->h);
	map_prop_set_or_add(map, "size", map->sizestring);
	
	map_prop_set_or_add(map, "name", d_map_prop(map->map->prop, "name"));
	map_prop_set_or_add(map, "version", d_map_prop(map->map->prop, "version"));
	map_prop_set_or_add(map, "author", d_map_prop(map->map->prop, "author"));
	map_prop_set_or_add(map, "max_players", d_map_prop(map->map->prop, "max_players"));
	return map;
}
コード例 #4
0
ファイル: map.c プロジェクト: slaeshjag/Muon
MAP *map_new(unsigned int width, unsigned int height, unsigned int terrain_layers, DARNIT_TILESHEET *ts) {
	int i, j;
	int tile_w, tile_h;
	int fail=0;
	DARNIT_MAP *d_map=NULL;
	DARNIT_MAP_LAYER *layer=NULL;
	MAP *map;
	DARNIT_FILE *f_ts;
	if(!(map=malloc(sizeof(MAP))))
		return NULL;
	
	if(!(ts&&terrain_layers&&(d_map=malloc(sizeof(DARNIT_MAP)))&&(layer=malloc((terrain_layers+2)*sizeof(DARNIT_MAP_LAYER))))) {
		free(d_map);
		free(layer);
		return NULL;
	}
	
	d_map->layer=layer;
	*((unsigned int *) &d_map->layers)=terrain_layers+2;
	d_map->object=NULL;
	*((unsigned int *) &d_map->objects)=0;
	d_map->prop=NULL;
	d_map->stringdata=NULL;
	d_map->stringrefs=NULL;
	
	d_render_tilesheet_geometrics(ts, NULL, NULL, &tile_w, &tile_h);
	for(i=0; i<terrain_layers+2; i++) {
		/*This is needed to at least null all tilemaps so we can free them i one fails*/
		if(!(fail|=!(layer[i].tilemap=d_tilemap_new(0xFFF, ts, 0xFFF, width, height)))) {
			for(j=0; j<width*height; j++)
				layer[i].tilemap->data[j]=i==terrain_layers+1?1:144*(!i);
			d_tilemap_recalc(layer[i].tilemap);
		}
		layer[i].ts=ts;
		layer[i].offset_x=0;
		layer[i].offset_y=0;
		layer[i].tile_w=tile_w;
		layer[i].tile_h=tile_h;
	}
	if(fail) {
		for(i=0; i<terrain_layers+2; i++)
			d_tilemap_free(layer[i].tilemap);
		free(d_map);
		free(layer);
		return NULL;
	}
	
	d_map_camera_move(d_map, 0, 0);
	
	map->map=d_map;
	map->stringtable=malloc(sizeof(MAP_PROPERTY));
	map->stringtable->key="tileset";
	map->stringtable->value="mapdata/default.png";
	map->stringtable->next=NULL;
	
	map->w=width*tile_w;
	map->h=height*tile_h;
	sprintf(map->sizestring, "%ix%i", width, height);
	map_prop_set_or_add(map, "size", map->sizestring);
	
	if(!(f_ts=d_file_open("res/default.png", "rb"))) {
		map->tilesheet=NULL;
		map_close(map);
		return NULL;
	}
	d_file_seek(f_ts, 0, SEEK_END);
	map->tilesheet_size=d_file_tell(f_ts);
	map->tilesheet=malloc(map->tilesheet_size);
	d_file_seek(f_ts, 0, SEEK_SET);
	d_file_read(map->tilesheet, map->tilesheet_size, f_ts);
	d_file_close(f_ts);
	
	return map;
}