Exemple #1
0
void swap_polygon_model_data(ubyte *data)
{
	int i;
	short n;
	g3s_uvl *uvl_val;
	ubyte *p = data;

	short_swap(wp(p));

	while (w(p) != OP_EOF) {
		switch (w(p)) {
			case OP_DEFPOINTS:
				short_swap(wp(p + 2));
				n = w(p+2);
				for (i = 0; i < n; i++)
					vms_vector_swap(vp((p + 4) + (i * sizeof(vms_vector))));
				p += n*sizeof(struct vms_vector) + 4;
				break;

			case OP_DEFP_START:
				short_swap(wp(p + 2));
				short_swap(wp(p + 4));
				n = w(p+2);
				for (i = 0; i < n; i++)
					vms_vector_swap(vp((p + 8) + (i * sizeof(vms_vector))));
				p += n*sizeof(struct vms_vector) + 8;
				break;

			case OP_FLATPOLY:
				short_swap(wp(p+2));
				n = w(p+2);
				vms_vector_swap(vp(p + 4));
				vms_vector_swap(vp(p + 16));
				short_swap(wp(p+28));
				for (i=0; i < n; i++)
					short_swap(wp(p + 30 + (i * 2)));
				p += 30 + ((n&~1)+1)*2;
				break;

			case OP_TMAPPOLY:
				short_swap(wp(p+2));
				n = w(p+2);
				vms_vector_swap(vp(p + 4));
				vms_vector_swap(vp(p + 16));
				for (i=0;i<n;i++) {
					uvl_val = (g3s_uvl *)((p+30+((n&~1)+1)*2) + (i * sizeof(g3s_uvl)));
					fix_swap(&uvl_val->u);
					fix_swap(&uvl_val->v);
				}
				short_swap(wp(p+28));
				for (i=0;i<n;i++)
					short_swap(wp(p + 30 + (i * 2)));
				p += 30 + ((n&~1)+1)*2 + n*12;
				break;

			case OP_SORTNORM:
				vms_vector_swap(vp(p + 4));
				vms_vector_swap(vp(p + 16));
				short_swap(wp(p + 28));
				short_swap(wp(p + 30));
				swap_polygon_model_data(p + w(p+28));
				swap_polygon_model_data(p + w(p+30));
				p += 32;
				break;

			case OP_RODBM:
				vms_vector_swap(vp(p + 20));
				vms_vector_swap(vp(p + 4));
				short_swap(wp(p+2));
				fix_swap(fp(p + 16));
				fix_swap(fp(p + 32));
				p+=36;
				break;

			case OP_SUBCALL:
				short_swap(wp(p+2));
				vms_vector_swap(vp(p+4));
				short_swap(wp(p+16));
				swap_polygon_model_data(p + w(p+16));
				p += 20;
				break;

			case OP_GLOW:
				short_swap(wp(p + 2));
				p += 4;
				break;

			default:
				Error("invalid polygon model\n"); //Int3();
		}
		short_swap(wp(p));
	}
}
Exemple #2
0
void swap_polygon_model_data(ubyte *data) {
	int i;
	short n;
	g3s_uvl *uvl_val;
	ubyte *p = data;

	short_swap(wp(p));

	while (w(p) != OP_EOF) {
		switch (w(p)) {
		case OP_DEFPOINTS:
			short_swap(wp(p + 2));
			n = w(p + 2);
			for (i = 0; i < n; i++)
				vms_vector_swap(vp((p + 4) + (i * sizeof(vms_vector))));
			p += n*sizeof(struct vms_vector) + 4;
			break;

		case OP_DEFP_START:
			short_swap(wp(p + 2));
			short_swap(wp(p + 4));
			n = w(p + 2);
			for (i = 0; i < n; i++)
				vms_vector_swap(vp((p + 8) + (i * sizeof(vms_vector))));
			p += n*sizeof(struct vms_vector) + 8;
			break;

		case OP_FLATPOLY:
			short_swap(wp(p + 2));
			n = w(p + 2);
			vms_vector_swap(vp(p + 4));
			vms_vector_swap(vp(p + 16));
			short_swap(wp(p + 28));
			// swap the colors 0 and 255 here!!!!
			if (w(p + 28) == 0)
				w(p + 28) = 255;
			else if (w(p + 28) == 255)
				w(p + 28) = 0;
			for (i = 0; i < n; i++)
				short_swap(wp(p + 30 + (i * 2)));
			p += 30 + ((n&~1) + 1) * 2;
			break;

		case OP_TMAPPOLY:
			short_swap(wp(p + 2));
			n = w(p + 2);
			vms_vector_swap(vp(p + 4));
			vms_vector_swap(vp(p + 16));
			for (i = 0; i<n; i++) {
				uvl_val = (g3s_uvl *)((p + 30 + ((n&~1) + 1) * 2) + (i * sizeof(g3s_uvl)));
				uvl_val->u = (fix)swapint((int)uvl_val->u);
				uvl_val->v = (fix)swapint((int)uvl_val->v);
			}
			short_swap(wp(p + 28));
			for (i = 0; i<n; i++)
				short_swap(wp(p + 30 + (i * 2)));
			p += 30 + ((n&~1) + 1) * 2 + n * 12;
			break;

		case OP_SORTNORM:
			vms_vector_swap(vp(p + 4));
			vms_vector_swap(vp(p + 16));
			short_swap(wp(p + 28));
			short_swap(wp(p + 30));
			swap_polygon_model_data(p + w(p + 28));
			swap_polygon_model_data(p + w(p + 30));
			p += 32;
			break;

		case OP_RODBM:
			vms_vector_swap(vp(p + 20));
			vms_vector_swap(vp(p + 4));
			short_swap(wp(p + 2));
			*((int *)(p + 16)) = swapint(*((int *)(p + 16)));
			*((int *)(p + 32)) = swapint(*((int *)(p + 32)));
			p += 36;
			break;

		case OP_SUBCALL:
			short_swap(wp(p + 2));
			vms_vector_swap(vp(p + 4));
			short_swap(wp(p + 16));
			swap_polygon_model_data(p + w(p + 16));
			p += 20;
			break;

		case OP_GLOW:
			short_swap(wp(p + 2));
			p += 4;
			break;

		default:
			Int3();
		}
		short_swap(wp(p));
	}
}