Esempio n. 1
0
static void align_polygon_model_data(polymodel *pm)
{
	int chunk_len;
	int total_correction = 0;
	chunk cur_ch;
	chunk ch_list[MAX_CHUNKS];
	int no_chunks = 0;
	int tmp_size = pm->model_data_size + SHIFT_SPACE;
	RAIIdmem<uint8_t[]> tmp;
	MALLOC(tmp, uint8_t[], tmp_size); // where we build the aligned version of pm->model_data

	Assert(tmp != NULL);
	//start with first chunk (is always aligned!)
	const uint8_t *cur_old = pm->model_data.get();
	auto cur_new = tmp.get();
	chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
	memcpy(cur_new, cur_old, chunk_len);
	while (no_chunks > 0) {
		int first_index = get_first_chunks_index(ch_list, no_chunks);
		cur_ch = ch_list[first_index];
		// remove first chunk from array:
		no_chunks--;
		for (int i = first_index; i < no_chunks; i++)
			ch_list[i] = ch_list[i + 1];
		// if (new) address unaligned:
		const uintptr_t u = reinterpret_cast<uintptr_t>(new_dest(cur_ch));
		if (u % 4L != 0) {
			// calculate how much to move to be aligned
			short to_shift = 4 - u % 4L;
			// correct chunks' addresses
			cur_ch.correction += to_shift;
			for (int i = 0; i < no_chunks; i++)
				ch_list[i].correction += to_shift;
			total_correction += to_shift;
			Assert(reinterpret_cast<uintptr_t>(new_dest(cur_ch)) % 4L == 0);
			Assert(total_correction <= SHIFT_SPACE); // if you get this, increase SHIFT_SPACE
		}
		//write (corrected) chunk for current chunk:
		*(reinterpret_cast<short *>(cur_ch.new_base + cur_ch.offset))
		  = INTEL_SHORT(static_cast<short>(cur_ch.correction + GET_INTEL_SHORT(cur_ch.old_base + cur_ch.offset)));
		//write (correctly aligned) chunk:
		cur_old = old_dest(cur_ch);
		cur_new = new_dest(cur_ch);
		chunk_len = get_chunks(cur_old, cur_new, ch_list, &no_chunks);
		memcpy(cur_new, cur_old, chunk_len);
		//correct submodel_ptr's for pm, too
		for (int i = 0; i < MAX_SUBMODELS; i++)
			if (&pm->model_data[pm->submodel_ptrs[i]] >= cur_old
			    && &pm->model_data[pm->submodel_ptrs[i]] < cur_old + chunk_len)
				pm->submodel_ptrs[i] += (cur_new - tmp.get()) - (cur_old - pm->model_data.get());
 	}
	pm->model_data_size += total_correction;
	pm->model_data = make_unique<ubyte[]>(pm->model_data_size);
	Assert(pm->model_data != NULL);
	memcpy(pm->model_data.get(), tmp.get(), pm->model_data_size);
}
Esempio n. 2
0
void receive_frameinfo_packet(ubyte *data, frame_info *info)
{
	int loc = 0;
	
	info->type = data[loc];									loc++;
	/*3 bytes of padding */									loc += 3;
	
	info->numpackets = GET_INTEL_INT(&data[loc]);			loc += 4;
	info->obj_pos.x = GET_INTEL_INT(&data[loc]);			loc += 4;	
	info->obj_pos.y = GET_INTEL_INT(&data[loc]);			loc += 4;	
	info->obj_pos.z = GET_INTEL_INT(&data[loc]);			loc += 4;	
	
	info->obj_orient.rvec.x = GET_INTEL_INT(&data[loc]);	loc += 4;			
	info->obj_orient.rvec.y = GET_INTEL_INT(&data[loc]);	loc += 4;			
	info->obj_orient.rvec.z = GET_INTEL_INT(&data[loc]);	loc += 4;			
	info->obj_orient.uvec.x = GET_INTEL_INT(&data[loc]);	loc += 4;			
	info->obj_orient.uvec.y = GET_INTEL_INT(&data[loc]);	loc += 4;			
	info->obj_orient.uvec.z = GET_INTEL_INT(&data[loc]);	loc += 4;			
	info->obj_orient.fvec.x = GET_INTEL_INT(&data[loc]);	loc += 4;			
	info->obj_orient.fvec.y = GET_INTEL_INT(&data[loc]);	loc += 4;			
	info->obj_orient.fvec.z = GET_INTEL_INT(&data[loc]);	loc += 4;			
	
	info->phys_velocity.x = GET_INTEL_INT(&data[loc]);		loc += 4;		
	info->phys_velocity.y = GET_INTEL_INT(&data[loc]);		loc += 4;				
	info->phys_velocity.z = GET_INTEL_INT(&data[loc]);		loc += 4;				
	
	info->phys_rotvel.x = GET_INTEL_INT(&data[loc]);		loc += 4;				
	info->phys_rotvel.y = GET_INTEL_INT(&data[loc]);		loc += 4;				
	info->phys_rotvel.z = GET_INTEL_INT(&data[loc]);		loc += 4;				
	
	info->obj_segnum = GET_INTEL_SHORT(&data[loc]);			loc += 2;		
	info->data_size = GET_INTEL_SHORT(&data[loc]);			loc += 2;		
	info->playernum = data[loc];							loc++;
	info->obj_render_type = data[loc];						loc++;
	info->level_num = data[loc];							loc++;
	memcpy(info->data, &data[loc], info->data_size);		loc += info->data_size;
}
Esempio n. 3
0
static uint8_t *new_dest(const chunk &o) // return where chunk is (in aligned struct)
{
	return GET_INTEL_SHORT(&o.old_base[o.offset]) + o.new_base + o.correction;
}
Esempio n. 4
0
static const uint8_t *old_dest(const chunk &o) // return where chunk is (in unaligned struct)
{
	return GET_INTEL_SHORT(&o.old_base[o.offset]) + o.old_base;
}