예제 #1
0
파일: plr.cpp 프로젝트: sobczyk/fs2open
void pilotfile::plr_read_controls()
{
    int idx, list_size, list_axis;
    short id1, id2, id3;
    int axi, inv;

    list_size = (int)cfread_ushort(cfp);
    for (idx = 0; idx < list_size; idx++) {
        id1 = cfread_short(cfp);
        id2 = cfread_short(cfp);
        id3 = cfread_short(cfp);	// unused, at the moment

        if (idx < CCFG_MAX) {
            Control_config[idx].key_id = id1;
            Control_config[idx].joy_id = id2;
        }
    }

    list_axis = cfread_int(cfp);
    for (idx = 0; idx < list_axis; idx++) {
        axi = cfread_int(cfp);
        inv = cfread_int(cfp);

        if (idx < NUM_JOY_AXIS_ACTIONS) {
            Axis_map_to[idx] = axi;
            Invert_axis[idx] = inv;
        }
    }
}
void pilotfile_convert::plr_import_controls()
{
	int idx;
	config_item con;

	unsigned char num_controls = cfread_ubyte(cfp);

	if ( !num_controls ) {
		return;
	}

	// it may be less than 118, but it shouldn't be more than 118
	if (num_controls > 118) {
		throw "Data check failure in controls!";
	}

	plr->controls.reserve(num_controls);

	for (idx = 0; idx < num_controls; idx++) {
		con.key_id = cfread_short(cfp);

		if (con.key_id == 255) {
			con.key_id = -1;
		}

		con.joy_id = cfread_short(cfp);

		if (con.joy_id == 255) {
			con.joy_id = -1;
		}

		plr->controls.push_back( con );
	}
}
예제 #3
0
void pilotfile::csg_read_controls()
{
	int idx, list_size;
	short id1, id2, id3 __UNUSED;

	list_size = (int)cfread_ushort(cfp);

	for (idx = 0; idx < list_size; idx++) {
		id1 = cfread_short(cfp);
		id2 = cfread_short(cfp);
		id3 = cfread_short(cfp);	// unused, at the moment

		if (idx < CCFG_MAX) {
			Control_config[idx].key_id = id1;
			Control_config[idx].joy_id = id2;
		}
	}
}
size_t pilot::BinaryFileHandler::startArrayRead(const char*, bool short_index) {
	Assertion(!_in_array, "Array nesting is not supported!");

	_in_array = true;
	if (short_index) {
		return (size_t) cfread_short(_cfp);
	} else {
		return (size_t) cfread_int(_cfp);
	}
}
// -----------------------------------------------------------------------------
//	anim_read_header()
//
// Read the header of a .ani file.  Below is the format of a .ani header
//
//	#bytes		|	description
//	2			|	obsolete, kept for compatibility with old versions
//	2			|	version number
//	2			|	fps
//	1			|	transparent red value
//  1			|	transparent green value
//	1			|	transparent blue value
//	2			|	width
//	2			|	height
//	2			|	number of frames
//	1			|	packer code
//	763			|	palette
//	2			|	number of key frames
//	2			|	key frame number	}		repeats
//	4			|	key frame offset	}		repeats
//	4			|	compressed data length
//
void anim_read_header(anim *ptr, CFILE *fp)
{
	ptr->width = cfread_short(fp);
	// If first 2 bytes are zero, this means we are using a new format, which includes
	// a version, and fps values. This is only done since a version number was not included
	// in the original header.

	// default
	Color_xparent.red = 0;
	Color_xparent.green = 255;
	Color_xparent.blue = 0;

	if ( ptr->width == 0 ) {
		ptr->version = cfread_short(fp);
		ptr->fps = cfread_short(fp);

		// version 2 added a custom transparency color
		if ( ptr->version >= 2 ) {
			cfread(&Color_xparent.red, 1, 1, fp);
			cfread(&Color_xparent.green, 1, 1, fp);
			cfread(&Color_xparent.blue, 1, 1, fp);
		}

		ptr->width = cfread_short(fp);
	}
	else {
		ptr->version = 0;
		ptr->fps = 30;
	}
	
	ptr->height = cfread_short(fp);

#ifndef NDEBUG
	// get size of ani compared to power of 2
	int r, floor_pow;
	r = ptr->height;
	floor_pow = 0;
	
	while(r >= 2) {
		r /= 2;
		floor_pow++;
	}

	int floor_size = (int) pow(2.0, floor_pow);
	int diff = ptr->height - floor_size;
	float waste = 100.0f * float((floor_size - diff))/(2.0f *(float)floor_size);

	if (diff != 0) {
		if (ptr->height > 16) {
			mprintf(("ANI %s with size %dx%d (%.1f%% wasted)\n", ptr->name, ptr->width, ptr->height, waste));
		}
	}
#endif

	ptr->total_frames = cfread_short(fp);
	ptr->packer_code = cfread_ubyte(fp);
	cfread(&ptr->palette, 256, 3, fp);
	ptr->num_keys = cfread_short(fp);

	// store xparent colors
	ptr->xparent_r = Color_xparent.red;
	ptr->xparent_g = Color_xparent.green;
	ptr->xparent_b = Color_xparent.blue;

	if(ptr->total_frames == ptr->num_keys){
		ptr->flags |= ANF_ALL_KEYFRAMES;
	}
}
std::int16_t pilot::BinaryFileHandler::readShort(const char*) {
	return cfread_short(_cfp);
}